]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branches 'release', 'asus', 'sony-laptop' and 'thinkpad' into release
authorLen Brown <len.brown@intel.com>
Thu, 7 Feb 2008 08:07:35 +0000 (03:07 -0500)
committerLen Brown <len.brown@intel.com>
Thu, 7 Feb 2008 08:07:35 +0000 (03:07 -0500)
1964 files changed:
CREDITS
Documentation/00-INDEX
Documentation/ABI/testing/sysfs-bus-usb
Documentation/BUG-HUNTING
Documentation/DocBook/kernel-api.tmpl
Documentation/DocBook/kernel-locking.tmpl
Documentation/DocBook/s390-drivers.tmpl
Documentation/Smack.txt [new file with mode: 0644]
Documentation/SubmittingPatches
Documentation/arm/Sharp-LH/IOBarrier
Documentation/debugging-modules.txt
Documentation/driver-model/platform.txt
Documentation/fb/deferred_io.txt
Documentation/feature-removal-schedule.txt
Documentation/filesystems/configfs/configfs.txt
Documentation/filesystems/porting
Documentation/filesystems/proc.txt
Documentation/filesystems/ramfs-rootfs-initramfs.txt
Documentation/filesystems/relay.txt
Documentation/frv/README.txt [moved from Documentation/fujitsu/frv/README.txt with 100% similarity]
Documentation/frv/atomic-ops.txt [moved from Documentation/fujitsu/frv/atomic-ops.txt with 100% similarity]
Documentation/frv/booting.txt [moved from Documentation/fujitsu/frv/booting.txt with 98% similarity]
Documentation/frv/clock.txt [moved from Documentation/fujitsu/frv/clock.txt with 100% similarity]
Documentation/frv/configuring.txt [moved from Documentation/fujitsu/frv/configuring.txt with 100% similarity]
Documentation/frv/features.txt [moved from Documentation/fujitsu/frv/features.txt with 100% similarity]
Documentation/frv/gdbinit [moved from Documentation/fujitsu/frv/gdbinit with 100% similarity]
Documentation/frv/gdbstub.txt [moved from Documentation/fujitsu/frv/gdbstub.txt with 100% similarity]
Documentation/frv/kernel-ABI.txt [moved from Documentation/fujitsu/frv/kernel-ABI.txt with 100% similarity]
Documentation/frv/mmu-layout.txt [moved from Documentation/fujitsu/frv/mmu-layout.txt with 100% similarity]
Documentation/gpio.txt
Documentation/i2c/chips/pca9539
Documentation/ia64/aliasing-test.c
Documentation/ide/ChangeLog.ide-tape.1995-2002 [new file with mode: 0644]
Documentation/ide/ide-tape.txt [new file with mode: 0644]
Documentation/initrd.txt
Documentation/ja_JP/stable_kernel_rules.txt [new file with mode: 0644]
Documentation/kernel-parameters.txt
Documentation/kprobes.txt
Documentation/kref.txt
Documentation/lguest/lguest.c
Documentation/md.txt
Documentation/networking/decnet.txt
Documentation/pci.txt
Documentation/pcmcia/driver-changes.txt
Documentation/pm_qos_interface.txt [new file with mode: 0644]
Documentation/power/basic-pm-debugging.txt
Documentation/power/devices.txt
Documentation/power/drivers-testing.txt
Documentation/power/notifiers.txt
Documentation/power/userland-swsusp.txt
Documentation/power_supply_class.txt
Documentation/rtc.txt
Documentation/smp.txt [deleted file]
Documentation/sysctl/fs.txt
Documentation/sysctl/vm.txt
Documentation/unaligned-memory-access.txt [new file with mode: 0644]
Documentation/usb/gadget_printer.txt [new file with mode: 0644]
Documentation/usb/iuu_phoenix.txt [new file with mode: 0644]
Documentation/w1/masters/00-INDEX
Documentation/w1/masters/w1-gpio [new file with mode: 0644]
Documentation/x86_64/00-INDEX [new file with mode: 0644]
MAINTAINERS
Makefile
arch/Kconfig [new file with mode: 0644]
arch/alpha/Kconfig
arch/alpha/Kconfig.debug
arch/alpha/defconfig
arch/alpha/kernel/osf_sys.c
arch/alpha/kernel/pci-noop.c
arch/alpha/kernel/pci_iommu.c
arch/alpha/kernel/setup.c
arch/alpha/kernel/smp.c
arch/alpha/kernel/systbls.S
arch/arm/Kconfig
arch/arm/Kconfig.instrumentation [deleted file]
arch/arm/common/time-acorn.c
arch/arm/configs/ixp4xx_defconfig
arch/arm/kernel/Makefile
arch/arm/kernel/atags.c [new file with mode: 0644]
arch/arm/kernel/atags.h [new file with mode: 0644]
arch/arm/kernel/calls.S
arch/arm/kernel/machine_kexec.c
arch/arm/kernel/relocate_kernel.S
arch/arm/kernel/setup.c
arch/arm/kernel/smp.c
arch/arm/mach-at91/Kconfig
arch/arm/mach-at91/at91sam926x_time.c
arch/arm/mach-at91/board-sam9261ek.c
arch/arm/mach-at91/board-sam9263ek.c
arch/arm/mach-at91/generic.h
arch/arm/mach-at91/gpio.c
arch/arm/mach-at91/pm.c
arch/arm/mach-ixp4xx/Kconfig
arch/arm/mach-ixp4xx/Makefile
arch/arm/mach-ixp4xx/dsmg600-power.c [deleted file]
arch/arm/mach-ixp4xx/dsmg600-setup.c
arch/arm/mach-ixp4xx/ixdp425-setup.c
arch/arm/mach-ixp4xx/ixp4xx_npe.c [new file with mode: 0644]
arch/arm/mach-ixp4xx/ixp4xx_qmgr.c [new file with mode: 0644]
arch/arm/mach-ixp4xx/nas100d-power.c [deleted file]
arch/arm/mach-ixp4xx/nas100d-setup.c
arch/arm/mach-ixp4xx/nslu2-power.c [deleted file]
arch/arm/mach-ixp4xx/nslu2-setup.c
arch/arm/mach-pxa/Makefile
arch/arm/mach-pxa/cm-x270.c
arch/arm/mach-pxa/corgi_ssp.c
arch/arm/mach-pxa/devices.c
arch/arm/mach-pxa/generic.c
arch/arm/mach-pxa/generic.h
arch/arm/mach-pxa/gpio.c [new file with mode: 0644]
arch/arm/mach-pxa/irq.c
arch/arm/mach-pxa/mfp.c
arch/arm/mach-pxa/pcm027.c
arch/arm/mach-pxa/poodle.c
arch/arm/mach-pxa/pxa25x.c
arch/arm/mach-pxa/pxa27x.c
arch/arm/mach-pxa/pxa3xx.c
arch/arm/mach-pxa/sleep.S
arch/arm/mach-pxa/smemc.c [new file with mode: 0644]
arch/arm/mach-pxa/spitz.c
arch/arm/mach-pxa/tosa.c
arch/arm/mach-realview/Kconfig
arch/arm/mach-realview/Makefile
arch/arm/mach-realview/core.c
arch/arm/mach-realview/core.h
arch/arm/mach-realview/localtimer.c
arch/arm/mach-realview/platsmp.c
arch/arm/mach-realview/realview_eb.c
arch/arm/mach-rpc/riscpc.c
arch/arm/mach-sa1100/collie_pm.c
arch/arm/mach-sa1100/generic.c
arch/arm/mm/ioremap.c
arch/arm/mm/pgd.c
arch/arm/plat-iop/time.c
arch/arm/plat-s3c24xx/irq.c
arch/arm/plat-s3c24xx/time.c
arch/avr32/Kconfig
arch/avr32/kernel/syscall_table.S
arch/avr32/lib/delay.c
arch/avr32/mach-at32ap/pio.c
arch/avr32/mach-at32ap/pio.h
arch/blackfin/Kconfig
arch/blackfin/mach-bf527/boards/ezkit.c
arch/blackfin/mach-bf533/boards/H8606.c
arch/blackfin/mach-bf533/boards/cm_bf533.c
arch/blackfin/mach-bf533/boards/ezkit.c
arch/blackfin/mach-bf533/boards/stamp.c
arch/blackfin/mach-bf537/boards/cm_bf537.c
arch/blackfin/mach-bf537/boards/generic_board.c
arch/blackfin/mach-bf537/boards/minotaur.c
arch/blackfin/mach-bf537/boards/stamp.c
arch/blackfin/mach-bf561/boards/cm_bf561.c
arch/blackfin/mach-bf561/boards/ezkit.c
arch/blackfin/mach-common/entry.S
arch/cris/Kconfig
arch/cris/arch-v10/Kconfig
arch/cris/arch-v10/drivers/Kconfig
arch/cris/arch-v10/kernel/entry.S
arch/cris/arch-v32/Kconfig
arch/cris/arch-v32/drivers/Kconfig
arch/cris/arch-v32/drivers/pci/dma.c
arch/frv/Kconfig
arch/frv/kernel/entry.S
arch/frv/kernel/setup.c
arch/frv/kernel/vmlinux.lds.S
arch/frv/lib/atomic-ops.S
arch/frv/mm/mmu-context.c
arch/frv/mm/pgalloc.c
arch/h8300/Kconfig
arch/h8300/kernel/irq.c
arch/h8300/platform/h8s/ints.c
arch/ia64/Kconfig
arch/ia64/hp/common/sba_iommu.c
arch/ia64/ia32/ia32_support.c
arch/ia64/kernel/efi.c
arch/ia64/kernel/entry.S
arch/ia64/kernel/fsyscall_gtod_data.h
arch/ia64/kernel/ia64_ksyms.c
arch/ia64/kernel/kprobes.c
arch/ia64/kernel/mca.c
arch/ia64/kernel/mca_asm.S
arch/ia64/kernel/mca_drv.c
arch/ia64/kernel/mca_drv.h
arch/ia64/kernel/mca_drv_asm.S
arch/ia64/kernel/perfmon.c
arch/ia64/kernel/sal.c
arch/ia64/kernel/setup.c
arch/ia64/kernel/smpboot.c
arch/ia64/kernel/traps.c
arch/ia64/kernel/unaligned.c
arch/ia64/mm/fault.c
arch/ia64/sn/kernel/sn2/sn2_smp.c
arch/ia64/sn/kernel/sn2/sn_hwperf.c
arch/ia64/sn/pci/pcibr/pcibr_provider.c
arch/m32r/Kconfig
arch/m32r/boot/compressed/m32r_sio.c
arch/m32r/kernel/ptrace.c
arch/m32r/kernel/syscall_table.S
arch/m68k/Kconfig
arch/m68k/Makefile
arch/m68k/amiga/Makefile
arch/m68k/amiga/amiga_ksyms.c [deleted file]
arch/m68k/amiga/amisound.c
arch/m68k/amiga/chipram.c
arch/m68k/amiga/cia.c
arch/m68k/amiga/config.c
arch/m68k/amiga/pcmcia.c
arch/m68k/atari/Makefile
arch/m68k/atari/ataints.c
arch/m68k/atari/atari_ksyms.c [deleted file]
arch/m68k/atari/atasound.c
arch/m68k/atari/config.c
arch/m68k/atari/debug.c
arch/m68k/atari/hades-pci.c
arch/m68k/atari/stdma.c
arch/m68k/atari/stram.c
arch/m68k/configs/mac_defconfig
arch/m68k/hp300/Makefile
arch/m68k/hp300/ksyms.c [deleted file]
arch/m68k/kernel/entry.S
arch/m68k/mac/Makefile
arch/m68k/mac/config.c
arch/m68k/mac/mac_ksyms.c [deleted file]
arch/m68k/mac/via.c
arch/m68k/mvme16x/Makefile
arch/m68k/mvme16x/config.c
arch/m68k/mvme16x/mvme16x_ksyms.c [deleted file]
arch/m68knommu/Kconfig
arch/m68knommu/Kconfig.debug
arch/m68knommu/defconfig
arch/m68knommu/kernel/m68k_ksyms.c
arch/m68knommu/kernel/setup.c
arch/m68knommu/kernel/syscalltable.S
arch/m68knommu/lib/memcpy.c
arch/mips/Kconfig
arch/mips/au1000/common/gpio.c
arch/mips/au1000/mtx-1/board_setup.c
arch/mips/kernel/binfmt_elfn32.c
arch/mips/kernel/binfmt_elfo32.c
arch/mips/kernel/kspd.c
arch/mips/kernel/scall32-o32.S
arch/mips/kernel/scall64-64.S
arch/mips/kernel/scall64-n32.S
arch/mips/kernel/scall64-o32.S
arch/mips/kernel/setup.c
arch/mips/kernel/smp.c
arch/mips/kernel/smtc.c
arch/mips/kernel/sysirix.c
arch/mips/mm/c-r4k.c
arch/mips/sgi-ip27/ip27-hubio.c
arch/parisc/Kconfig
arch/parisc/Kconfig.debug
arch/parisc/configs/a500_defconfig
arch/parisc/kernel/cache.c
arch/parisc/kernel/hardware.c
arch/parisc/kernel/signal.c
arch/powerpc/Kconfig
arch/powerpc/kernel/dma_64.c
arch/powerpc/kernel/iommu.c
arch/powerpc/kernel/time.c
arch/powerpc/mm/pgtable_32.c
arch/powerpc/platforms/52xx/lite5200_pm.c
arch/powerpc/platforms/iseries/iommu.c
arch/powerpc/platforms/powermac/cpufreq_32.c
arch/ppc/8260_io/enet.c
arch/ppc/8260_io/fcc_enet.c
arch/ppc/Kconfig
arch/ppc/kernel/vmlinux.lds.S
arch/ppc/mm/pgtable.c
arch/ppc/platforms/prep_setup.c
arch/s390/Kconfig
arch/s390/Kconfig.debug
arch/s390/kernel/compat_wrapper.S
arch/s390/kernel/entry.S
arch/s390/kernel/entry64.S
arch/s390/kernel/ipl.c
arch/s390/kernel/setup.c
arch/s390/kernel/smp.c
arch/s390/kernel/stacktrace.c
arch/s390/kernel/syscalls.S
arch/s390/kernel/traps.c
arch/s390/kernel/vmlinux.lds.S
arch/s390/mm/init.c
arch/s390/mm/vmem.c
arch/sh/Kconfig
arch/sh/boards/landisk/setup.c
arch/sh/boards/lboxre2/setup.c
arch/sh/boards/renesas/r7780rp/setup.c
arch/sh/boards/renesas/rts7751r2d/setup.c
arch/sh/boards/renesas/sdk7780/setup.c
arch/sh/boards/se/7722/setup.c
arch/sh/drivers/pci/Kconfig
arch/sh/kernel/syscalls_32.S
arch/sh/kernel/syscalls_64.S
arch/sparc/Kconfig
arch/sparc/kernel/ioport.c
arch/sparc/kernel/sun4d_smp.c
arch/sparc/kernel/sun4m_smp.c
arch/sparc/kernel/systbls.S
arch/sparc64/Kconfig
arch/sparc64/defconfig
arch/sparc64/kernel/Makefile
arch/sparc64/kernel/iommu.c
arch/sparc64/kernel/iommu_common.c [deleted file]
arch/sparc64/kernel/iommu_common.h
arch/sparc64/kernel/pci_sun4v.c
arch/sparc64/kernel/smp.c
arch/sparc64/kernel/sparc64_ksyms.c
arch/sparc64/kernel/systbls.S
arch/sparc64/kernel/time.c
arch/sparc64/solaris/fs.c
arch/sparc64/solaris/timod.c
arch/um/Kconfig
arch/um/Kconfig.char
arch/um/Kconfig.debug
arch/um/Kconfig.net
arch/um/Makefile
arch/um/Makefile-tt [deleted file]
arch/um/defconfig
arch/um/drivers/line.c
arch/um/drivers/mconsole_kern.c
arch/um/drivers/mconsole_user.c
arch/um/drivers/net_kern.c
arch/um/drivers/net_user.c
arch/um/drivers/port_kern.c
arch/um/drivers/random.c
arch/um/drivers/slip_user.c
arch/um/drivers/slirp_user.c
arch/um/drivers/ssl.c
arch/um/drivers/stdio_console.c
arch/um/drivers/ubd_kern.c
arch/um/drivers/ubd_user.c
arch/um/drivers/vde_user.c
arch/um/include/arch.h
arch/um/include/as-layout.h
arch/um/include/chan_user.h
arch/um/include/common-offsets.h
arch/um/include/init.h
arch/um/include/irq_user.h
arch/um/include/kern_util.h
arch/um/include/mem_user.h
arch/um/include/misc_constants.h [deleted file]
arch/um/include/os.h
arch/um/include/ptrace_user.h
arch/um/include/registers.h
arch/um/include/signal_kern.h [deleted file]
arch/um/include/skas/mode-skas.h [deleted file]
arch/um/include/sysdep-i386/syscalls.h
arch/um/include/sysdep-x86_64/kernel-offsets.h
arch/um/include/sysdep-x86_64/syscalls.h
arch/um/include/um_mmu.h
arch/um/include/um_uaccess.h
arch/um/kernel/exec.c
arch/um/kernel/exitcode.c
arch/um/kernel/gmon_syms.c
arch/um/kernel/gprof_syms.c
arch/um/kernel/initrd.c
arch/um/kernel/irq.c
arch/um/kernel/ksyms.c
arch/um/kernel/mem.c
arch/um/kernel/physmem.c
arch/um/kernel/process.c
arch/um/kernel/reboot.c
arch/um/kernel/sigio.c
arch/um/kernel/signal.c
arch/um/kernel/skas/clone.c
arch/um/kernel/skas/mmu.c
arch/um/kernel/skas/process.c
arch/um/kernel/skas/syscall.c
arch/um/kernel/skas/uaccess.c
arch/um/kernel/smp.c
arch/um/kernel/syscall.c
arch/um/kernel/sysrq.c
arch/um/kernel/time.c
arch/um/kernel/tlb.c
arch/um/kernel/trap.c
arch/um/kernel/uaccess.c
arch/um/kernel/um_arch.c
arch/um/kernel/umid.c
arch/um/os-Linux/Makefile
arch/um/os-Linux/aio.c
arch/um/os-Linux/drivers/ethertap_user.c
arch/um/os-Linux/drivers/tuntap_user.c
arch/um/os-Linux/file.c
arch/um/os-Linux/helper.c
arch/um/os-Linux/irq.c
arch/um/os-Linux/main.c
arch/um/os-Linux/mem.c
arch/um/os-Linux/process.c
arch/um/os-Linux/registers.c
arch/um/os-Linux/sigio.c
arch/um/os-Linux/signal.c
arch/um/os-Linux/skas/Makefile
arch/um/os-Linux/skas/process.c
arch/um/os-Linux/skas/trap.c [deleted file]
arch/um/os-Linux/start_up.c
arch/um/os-Linux/trap.c [deleted file]
arch/um/os-Linux/tty.c
arch/um/os-Linux/tty_log.c
arch/um/os-Linux/util.c
arch/um/sys-i386/bug.c
arch/um/sys-i386/bugs.c
arch/um/sys-i386/ldt.c
arch/um/sys-i386/ptrace.c
arch/um/sys-i386/ptrace_user.c
arch/um/sys-i386/signal.c
arch/um/sys-i386/stub.S
arch/um/sys-i386/stub_segv.c
arch/um/sys-i386/sys_call_table.S
arch/um/sys-i386/tls.c
arch/um/sys-ppc/Makefile
arch/um/sys-x86_64/bug.c
arch/um/sys-x86_64/bugs.c
arch/um/sys-x86_64/ptrace.c
arch/um/sys-x86_64/ptrace_user.c
arch/um/sys-x86_64/signal.c
arch/um/sys-x86_64/stub.S
arch/um/sys-x86_64/stub_segv.c
arch/um/sys-x86_64/syscall_table.c
arch/um/sys-x86_64/syscalls.c
arch/um/sys-x86_64/sysrq.c
arch/um/sys-x86_64/um_module.c
arch/v850/Kconfig
arch/x86/Kconfig
arch/x86/Kconfig.debug
arch/x86/Makefile
arch/x86/boot/Makefile
arch/x86/boot/compressed/Makefile
arch/x86/boot/compressed/head_64.S
arch/x86/boot/cpu.c
arch/x86/boot/mkcpustr.c [new file with mode: 0644]
arch/x86/ia32/ia32entry.S
arch/x86/kernel/Makefile
arch/x86/kernel/cpu/Makefile
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/cpu.h
arch/x86/kernel/cpu/cpufreq/powernow-k8.c
arch/x86/kernel/cpu/cyrix.c
arch/x86/kernel/cpu/feature_names.c [new file with mode: 0644]
arch/x86/kernel/cpu/intel.c
arch/x86/kernel/cpu/mtrr/cyrix.c
arch/x86/kernel/cpu/mtrr/main.c
arch/x86/kernel/cpu/mtrr/mtrr.h
arch/x86/kernel/cpu/proc.c
arch/x86/kernel/cpuid.c
arch/x86/kernel/efi.c
arch/x86/kernel/efi_64.c
arch/x86/kernel/entry_64.S
arch/x86/kernel/head_64.S
arch/x86/kernel/ldt.c
arch/x86/kernel/msr.c
arch/x86/kernel/pci-calgary_64.c
arch/x86/kernel/pci-gart_64.c
arch/x86/kernel/process_32.c
arch/x86/kernel/ptrace.c
arch/x86/kernel/quirks.c
arch/x86/kernel/setup_64.c
arch/x86/kernel/smpboot_32.c
arch/x86/kernel/suspend_64.c
arch/x86/kernel/syscall_table_32.S
arch/x86/kernel/test_nx.c
arch/x86/kernel/trampoline_32.S
arch/x86/kernel/trampoline_64.S
arch/x86/kernel/traps_32.c
arch/x86/kernel/vmi_32.c
arch/x86/kvm/Kconfig
arch/x86/kvm/x86.c
arch/x86/lib/Makefile
arch/x86/lib/bitops_32.c
arch/x86/lib/bitops_64.c
arch/x86/lib/bitstr_64.c [deleted file]
arch/x86/lib/delay_32.c
arch/x86/lib/delay_64.c
arch/x86/lib/mmx_32.c
arch/x86/lib/usercopy_32.c
arch/x86/lib/usercopy_64.c
arch/x86/mach-voyager/voyager_smp.c
arch/x86/mm/fault.c
arch/x86/mm/init_32.c
arch/x86/mm/init_64.c
arch/x86/mm/ioremap.c
arch/x86/mm/numa_64.c
arch/x86/mm/pageattr-test.c
arch/x86/mm/pageattr.c
arch/x86/mm/pgtable_32.c
arch/x86/pci/fixup.c
arch/x86/pci/i386.c
arch/x86/pci/numa.c
arch/xtensa/Kconfig
arch/xtensa/kernel/time.c
crypto/async_tx/async_memcpy.c
crypto/async_tx/async_memset.c
crypto/async_tx/async_tx.c
crypto/async_tx/async_xor.c
drivers/Kconfig
drivers/Makefile
drivers/acpi/asus_acpi.c
drivers/acpi/battery.c
drivers/acpi/hardware/hwsleep.c
drivers/acpi/processor_idle.c
drivers/acpi/scan.c
drivers/acpi/sleep/main.c
drivers/acpi/sleep/sleep.h
drivers/acpi/utilities/utresrc.c
drivers/ata/ahci.c
drivers/ata/ata_piix.c
drivers/ata/libata-core.c
drivers/ata/pata_at32.c
drivers/ata/pata_cs5520.c
drivers/ata/pata_efar.c
drivers/ata/pata_it8213.c
drivers/ata/pata_of_platform.c
drivers/ata/pata_platform.c
drivers/ata/pata_sis.c
drivers/ata/sata_fsl.c
drivers/ata/sata_inic162x.c
drivers/ata/sata_mv.c
drivers/ata/sata_nv.c
drivers/ata/sata_via.c
drivers/base/Makefile
drivers/base/core.c
drivers/base/cpu.c
drivers/base/dmapool.c [deleted file]
drivers/base/driver.c
drivers/base/power/Makefile
drivers/base/power/main.c
drivers/base/power/power.h
drivers/block/Kconfig
drivers/block/ataflop.c
drivers/block/cciss.c
drivers/block/cciss_scsi.c
drivers/block/loop.c
drivers/block/paride/pt.c
drivers/block/pktcdvd.c
drivers/block/rd.c
drivers/block/ub.c
drivers/block/virtio_blk.c
drivers/bluetooth/bpa10x.c
drivers/bluetooth/bt3c_cs.c
drivers/bluetooth/btsdio.c
drivers/bluetooth/btuart_cs.c
drivers/bluetooth/hci_usb.c
drivers/cdrom/cdrom.c
drivers/char/Kconfig
drivers/char/agp/agp.h
drivers/char/agp/alpha-agp.c
drivers/char/agp/amd-k7-agp.c
drivers/char/agp/backend.c
drivers/char/agp/compat_ioctl.c
drivers/char/agp/compat_ioctl.h
drivers/char/agp/frontend.c
drivers/char/agp/generic.c
drivers/char/agp/intel-agp.c
drivers/char/drm/drm_vm.c
drivers/char/drm/r300_reg.h
drivers/char/drm/via_dma.c
drivers/char/efirtc.c
drivers/char/epca.c
drivers/char/hangcheck-timer.c
drivers/char/hvc_console.c
drivers/char/hvcs.c
drivers/char/hw_random/core.c
drivers/char/hw_random/via-rng.c
drivers/char/i8k.c
drivers/char/ip2/i2lib.c
drivers/char/ip2/ip2main.c
drivers/char/ip27-rtc.c
drivers/char/ipmi/ipmi_msghandler.c
drivers/char/lp.c
drivers/char/misc.c
drivers/char/mspec.c
drivers/char/mxser.c
drivers/char/mxser_new.c
drivers/char/n_tty.c
drivers/char/nozomi.c
drivers/char/pcmcia/cm4000_cs.c
drivers/char/pcmcia/synclink_cs.c
drivers/char/random.c
drivers/char/riscom8.c
drivers/char/ser_a2232.c
drivers/char/synclink.c
drivers/char/synclink_gt.c
drivers/char/synclinkmp.c
drivers/char/toshiba.c
drivers/char/tpm/tpm.c
drivers/char/tpm/tpm.h
drivers/char/tpm/tpm_infineon.c
drivers/char/tty_io.c
drivers/char/virtio_console.c
drivers/char/vt.c
drivers/cpuidle/cpuidle.c
drivers/cpuidle/governors/ladder.c
drivers/cpuidle/governors/menu.c
drivers/dio/dio-driver.c
drivers/dio/dio.c
drivers/dma/Kconfig
drivers/dma/dmaengine.c
drivers/dma/ioat_dma.c
drivers/dma/iop-adma.c
drivers/edac/edac_pci.c
drivers/edac/i5000_edac.c
drivers/firmware/dcdbas.c
drivers/firmware/dmi-id.c
drivers/firmware/edd.c
drivers/gpio/Kconfig [new file with mode: 0644]
drivers/gpio/Makefile [new file with mode: 0644]
drivers/gpio/gpiolib.c [new file with mode: 0644]
drivers/gpio/mcp23s08.c [new file with mode: 0644]
drivers/gpio/pca953x.c [new file with mode: 0644]
drivers/gpio/pcf857x.c [new file with mode: 0644]
drivers/i2c/busses/scx200_acb.c
drivers/i2c/chips/Kconfig
drivers/ide/Kconfig
drivers/ide/arm/Makefile
drivers/ide/arm/bast-ide.c
drivers/ide/arm/icside.c
drivers/ide/arm/ide_arm.c
drivers/ide/arm/palm_bk3710.c [new file with mode: 0644]
drivers/ide/arm/rapide.c
drivers/ide/cris/ide-cris.c
drivers/ide/h8300/ide-h8300.c
drivers/ide/ide-acpi.c
drivers/ide/ide-cd.c
drivers/ide/ide-dma.c
drivers/ide/ide-floppy.c
drivers/ide/ide-generic.c
drivers/ide/ide-io.c
drivers/ide/ide-iops.c
drivers/ide/ide-lib.c
drivers/ide/ide-pnp.c
drivers/ide/ide-probe.c
drivers/ide/ide-proc.c
drivers/ide/ide-tape.c
drivers/ide/ide-taskfile.c
drivers/ide/ide-timing.h
drivers/ide/ide.c
drivers/ide/legacy/ali14xx.c
drivers/ide/legacy/buddha.c
drivers/ide/legacy/dtc2278.c
drivers/ide/legacy/falconide.c
drivers/ide/legacy/gayle.c
drivers/ide/legacy/hd.c
drivers/ide/legacy/ht6560b.c
drivers/ide/legacy/ide-cs.c
drivers/ide/legacy/ide_platform.c
drivers/ide/legacy/macide.c
drivers/ide/legacy/q40ide.c
drivers/ide/legacy/qd65xx.c
drivers/ide/legacy/umc8672.c
drivers/ide/mips/au1xxx-ide.c
drivers/ide/mips/swarm.c
drivers/ide/pci/Makefile
drivers/ide/pci/aec62xx.c
drivers/ide/pci/alim15x3.c
drivers/ide/pci/amd74xx.c
drivers/ide/pci/atiixp.c
drivers/ide/pci/cmd640.c
drivers/ide/pci/cmd64x.c
drivers/ide/pci/cs5520.c
drivers/ide/pci/cs5530.c
drivers/ide/pci/cs5535.c
drivers/ide/pci/cy82c693.c
drivers/ide/pci/delkin_cb.c
drivers/ide/pci/generic.c
drivers/ide/pci/hpt34x.c
drivers/ide/pci/hpt366.c
drivers/ide/pci/it8213.c
drivers/ide/pci/it821x.c
drivers/ide/pci/jmicron.c
drivers/ide/pci/ns87415.c
drivers/ide/pci/opti621.c
drivers/ide/pci/pdc202xx_new.c
drivers/ide/pci/pdc202xx_old.c
drivers/ide/pci/piix.c
drivers/ide/pci/rz1000.c
drivers/ide/pci/sc1200.c
drivers/ide/pci/scc_pata.c
drivers/ide/pci/serverworks.c
drivers/ide/pci/sgiioc4.c
drivers/ide/pci/siimage.c
drivers/ide/pci/sis5513.c
drivers/ide/pci/sl82c105.c
drivers/ide/pci/slc90e66.c
drivers/ide/pci/tc86c001.c
drivers/ide/pci/triflex.c
drivers/ide/pci/trm290.c
drivers/ide/pci/via82cxxx.c
drivers/ide/ppc/mpc8xx.c
drivers/ide/ppc/pmac.c
drivers/ide/setup-pci.c
drivers/ieee1394/sbp2.c
drivers/infiniband/Kconfig
drivers/infiniband/Makefile
drivers/infiniband/core/cm.c
drivers/infiniband/core/fmr_pool.c
drivers/infiniband/hw/ehca/ehca_classes.h
drivers/infiniband/hw/ehca/ehca_irq.c
drivers/infiniband/hw/ehca/ehca_iverbs.h
drivers/infiniband/hw/ehca/ehca_main.c
drivers/infiniband/hw/ehca/ehca_reqs.c
drivers/infiniband/hw/ehca/ehca_sqp.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mthca/mthca_cmd.c
drivers/infiniband/hw/mthca/mthca_main.c
drivers/infiniband/hw/mthca/mthca_mr.c
drivers/infiniband/hw/mthca/mthca_provider.c
drivers/infiniband/hw/mthca/mthca_qp.c
drivers/infiniband/hw/mthca/mthca_srq.c
drivers/infiniband/hw/nes/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/nes/Makefile [new file with mode: 0644]
drivers/infiniband/hw/nes/nes.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_cm.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_cm.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_context.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_hw.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_hw.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_nic.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_user.h [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_utils.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_verbs.c [new file with mode: 0644]
drivers/infiniband/hw/nes/nes_verbs.h [new file with mode: 0644]
drivers/infiniband/ulp/ipoib/ipoib_main.c
drivers/infiniband/ulp/srp/ib_srp.c
drivers/infiniband/ulp/srp/ib_srp.h
drivers/input/gameport/gameport.c
drivers/input/keyboard/bf54x-keys.c
drivers/input/keyboard/jornada720_kbd.c
drivers/input/serio/gscps2.c
drivers/input/touchscreen/h3600_ts_input.c
drivers/isdn/act2000/module.c
drivers/isdn/gigaset/asyncdata.c
drivers/isdn/gigaset/bas-gigaset.c
drivers/isdn/gigaset/common.c
drivers/isdn/gigaset/ev-layer.c
drivers/isdn/gigaset/gigaset.h
drivers/isdn/gigaset/interface.c
drivers/isdn/gigaset/isocdata.c
drivers/isdn/gigaset/ser-gigaset.c
drivers/isdn/gigaset/usb-gigaset.c
drivers/isdn/hardware/eicon/debug.c
drivers/isdn/hardware/eicon/debuglib.c
drivers/isdn/hardware/eicon/debuglib.h
drivers/isdn/hardware/eicon/di.c
drivers/isdn/hardware/eicon/diva.c
drivers/isdn/hardware/eicon/message.c
drivers/isdn/hisax/avm_pci.c
drivers/isdn/hysdn/hycapi.c
drivers/isdn/i4l/isdn_tty.c
drivers/isdn/i4l/isdn_ttyfax.c
drivers/isdn/icn/icn.c
drivers/isdn/isdnloop/isdnloop.c
drivers/leds/led-class.c
drivers/lguest/lguest_device.c
drivers/macintosh/adb.c
drivers/macintosh/mediabay.c
drivers/macintosh/smu.c
drivers/macintosh/via-macii.c
drivers/md/bitmap.c
drivers/md/faulty.c
drivers/md/linear.c
drivers/md/md.c
drivers/md/mktables.c
drivers/md/multipath.c
drivers/md/raid0.c
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid5.c
drivers/md/raid6test/test.c
drivers/media/common/saa7146_core.c
drivers/media/dvb/dvb-core/dvb_net.c
drivers/media/video/Makefile
drivers/media/video/bt8xx/bttv-cards.c
drivers/media/video/indycam.c
drivers/media/video/mt20xx.c
drivers/media/video/pvrusb2/pvrusb2.h
drivers/media/video/pwc/pwc-if.c
drivers/media/video/tea6420.c
drivers/media/video/tvmixer.c [deleted file]
drivers/media/video/usbvideo/quickcam_messenger.c
drivers/media/video/usbvision/usbvision-video.c
drivers/media/video/vpx3220.c
drivers/media/video/zoran_card.c
drivers/media/video/zr36050.c
drivers/media/video/zr36060.c
drivers/message/fusion/lsi/mpi_log_sas.h
drivers/message/fusion/mptctl.c
drivers/message/fusion/mptscsih.c
drivers/message/i2o/iop.c
drivers/misc/asus-laptop.c
drivers/misc/fujitsu-laptop.c
drivers/misc/lkdtm.c
drivers/misc/msi-laptop.c
drivers/misc/phantom.c
drivers/misc/sony-laptop.c
drivers/mtd/devices/block2mtd.c
drivers/mtd/devices/doc2000.c
drivers/mtd/devices/phram.c
drivers/mtd/maps/mtx-1_flash.c
drivers/mtd/nand/autcpu12.c
drivers/mtd/nand/bf5xx_nand.c
drivers/mtd/nand/cs553x_nand.c
drivers/mtd/nand/edb7312.c
drivers/mtd/nand/nand_base.c
drivers/mtd/nand/nandsim.c
drivers/mtd/nand/s3c2410.c
drivers/mtd/nand/sharpsl.c
drivers/mtd/nftlmount.c
drivers/net/Kconfig
drivers/net/arm/at91_ether.c
drivers/net/ax88796.c
drivers/net/bfin_mac.c
drivers/net/bfin_mac.h
drivers/net/bonding/bond_main.c
drivers/net/bonding/bonding.h
drivers/net/cxgb3/cxgb3_offload.c
drivers/net/cxgb3/mc5.c
drivers/net/cxgb3/sge.c
drivers/net/cxgb3/t3_hw.c
drivers/net/e100.c
drivers/net/e1000/e1000_main.c
drivers/net/e1000e/defines.h
drivers/net/e1000e/ethtool.c
drivers/net/e1000e/netdev.c
drivers/net/eexpress.c
drivers/net/ehea/ehea.h
drivers/net/ehea/ehea_ethtool.c
drivers/net/ehea/ehea_hw.h
drivers/net/ehea/ehea_main.c
drivers/net/ehea/ehea_phyp.c
drivers/net/ehea/ehea_phyp.h
drivers/net/ehea/ehea_qmr.c
drivers/net/ehea/ehea_qmr.h
drivers/net/forcedeth.c
drivers/net/gianfar_mii.c
drivers/net/hamradio/dmascc.c
drivers/net/ibmlana.c
drivers/net/igb/igb_main.c
drivers/net/irda/ali-ircc.h
drivers/net/irda/nsc-ircc.h
drivers/net/irda/via-ircc.h
drivers/net/iseries_veth.c
drivers/net/ixgbe/ixgbe.h
drivers/net/ixgbe/ixgbe_ethtool.c
drivers/net/ixgbe/ixgbe_main.c
drivers/net/lib8390.c
drivers/net/macb.c
drivers/net/mipsnet.c
drivers/net/mipsnet.h [deleted file]
drivers/net/mlx4/fw.c
drivers/net/mlx4/fw.h
drivers/net/mlx4/main.c
drivers/net/mlx4/mr.c
drivers/net/mv643xx_eth.c
drivers/net/natsemi.c
drivers/net/pasemi_mac.c
drivers/net/pasemi_mac.h
drivers/net/pci-skeleton.c
drivers/net/pcmcia/3c574_cs.c
drivers/net/pcmcia/3c589_cs.c
drivers/net/pcmcia/axnet_cs.c
drivers/net/pcmcia/fmvj18x_cs.c
drivers/net/pcmcia/nmclan_cs.c
drivers/net/pcmcia/pcnet_cs.c
drivers/net/pcmcia/smc91c92_cs.c
drivers/net/pcmcia/xirc2ps_cs.c
drivers/net/phy/Kconfig
drivers/net/phy/Makefile
drivers/net/phy/broadcom.c
drivers/net/phy/mdio_bus.c
drivers/net/phy/phy.c
drivers/net/phy/phy_device.c
drivers/net/phy/realtek.c [new file with mode: 0644]
drivers/net/pppol2tp.c
drivers/net/s2io.c
drivers/net/s2io.h
drivers/net/sis190.c
drivers/net/skfp/ess.c
drivers/net/skfp/fplustm.c
drivers/net/skfp/hwmtm.c
drivers/net/sky2.c
drivers/net/sky2.h
drivers/net/sunbmac.c
drivers/net/sunqe.c
drivers/net/sunvnet.c
drivers/net/tlan.c
drivers/net/tokenring/abyss.c
drivers/net/tokenring/abyss.h
drivers/net/tokenring/madgemc.c
drivers/net/tokenring/madgemc.h
drivers/net/tokenring/olympic.c
drivers/net/tokenring/proteon.c
drivers/net/tokenring/skisa.c
drivers/net/tokenring/tms380tr.c
drivers/net/tokenring/tms380tr.h
drivers/net/tokenring/tmspci.c
drivers/net/tulip/xircom_cb.c
drivers/net/tun.c
drivers/net/ucc_geth.c
drivers/net/ucc_geth_mii.c
drivers/net/usb/rtl8150.c
drivers/net/via-rhine.c
drivers/net/via-velocity.c
drivers/net/via-velocity.h
drivers/net/virtio_net.c
drivers/net/wan/cycx_drv.c
drivers/net/wan/hdlc.c
drivers/net/wan/hdlc_cisco.c
drivers/net/wan/hdlc_fr.c
drivers/net/wan/hdlc_ppp.c
drivers/net/wan/hdlc_raw.c
drivers/net/wan/hdlc_raw_eth.c
drivers/net/wan/hdlc_x25.c
drivers/net/wireless/ath5k/base.c
drivers/net/wireless/b43/b43.h
drivers/net/wireless/b43/dma.c
drivers/net/wireless/b43/dma.h
drivers/net/wireless/b43/leds.c
drivers/net/wireless/b43/main.c
drivers/net/wireless/b43legacy/dma.c
drivers/net/wireless/b43legacy/main.c
drivers/net/wireless/b43legacy/pio.c
drivers/net/wireless/b43legacy/xmit.c
drivers/net/wireless/b43legacy/xmit.h
drivers/net/wireless/ipw2100.c
drivers/net/wireless/iwlwifi/iwl-3945.c
drivers/net/wireless/iwlwifi/iwl-4965.c
drivers/net/wireless/iwlwifi/iwl-helpers.h
drivers/net/wireless/iwlwifi/iwl3945-base.c
drivers/net/wireless/iwlwifi/iwl4965-base.c
drivers/net/wireless/libertas/scan.c
drivers/net/wireless/netwave_cs.c
drivers/net/wireless/wavelan_cs.c
drivers/nubus/Makefile
drivers/nubus/nubus.c
drivers/nubus/nubus_syms.c [deleted file]
drivers/nubus/proc.c
drivers/parisc/ccio-dma.c
drivers/parisc/hppb.c
drivers/parisc/iommu-helpers.h
drivers/parisc/sba_iommu.c
drivers/parport/parport_pc.c
drivers/parport/parport_serial.c
drivers/parport/probe.c
drivers/pci/Makefile
drivers/pci/bus.c
drivers/pci/dmar.c
drivers/pci/hotplug-pci.c [new file with mode: 0644]
drivers/pci/hotplug/Kconfig
drivers/pci/hotplug/Makefile
drivers/pci/hotplug/acpiphp.h
drivers/pci/hotplug/acpiphp_glue.c
drivers/pci/hotplug/fakephp.c
drivers/pci/hotplug/ibmphp_core.c
drivers/pci/hotplug/pci_hotplug_core.c
drivers/pci/hotplug/pciehp.h
drivers/pci/hotplug/pciehp_core.c
drivers/pci/hotplug/pciehp_ctrl.c
drivers/pci/hotplug/pciehp_hpc.c
drivers/pci/hotplug/pciehp_pci.c
drivers/pci/hotplug/rpaphp.h
drivers/pci/hotplug/rpaphp_pci.c
drivers/pci/hotplug/rpaphp_slot.c
drivers/pci/hotplug/shpchp_hpc.c
drivers/pci/intel-iommu.c
drivers/pci/intel-iommu.h
drivers/pci/iova.c
drivers/pci/iova.h
drivers/pci/msi.c
drivers/pci/pci-acpi.c
drivers/pci/pci-driver.c
drivers/pci/pci-sysfs.c
drivers/pci/pci.c
drivers/pci/pci.h
drivers/pci/pcie/aer/aerdrv_acpi.c
drivers/pci/pcie/portdrv_core.c
drivers/pci/probe.c
drivers/pci/proc.c
drivers/pci/quirks.c
drivers/pci/remove.c
drivers/pci/rom.c
drivers/pci/setup-bus.c
drivers/pci/setup-res.c
drivers/pci/syscall.c
drivers/pcmcia/at91_cf.c
drivers/pcmcia/cardbus.c
drivers/pcmcia/ds.c
drivers/pcmcia/i82092.c
drivers/pcmcia/i82365.c
drivers/pcmcia/m32r_cfc.c
drivers/pcmcia/m32r_pcc.c
drivers/pcmcia/m8xx_pcmcia.c
drivers/pcmcia/pcmcia_resource.c
drivers/pcmcia/rsrc_nonstatic.c
drivers/pcmcia/sa1100_jornada720.c
drivers/pcmcia/tcic.c
drivers/pnp/driver.c
drivers/pnp/interface.c
drivers/pnp/manager.c
drivers/pnp/pnpacpi/rsparser.c
drivers/pnp/pnpbios/core.c
drivers/pnp/pnpbios/rsparser.c
drivers/pnp/quirks.c
drivers/power/apm_power.c
drivers/power/olpc_battery.c
drivers/power/pda_power.c
drivers/power/power_supply_leds.c
drivers/power/power_supply_sysfs.c
drivers/ps3/ps3av.c
drivers/rtc/Kconfig
drivers/rtc/Makefile
drivers/rtc/rtc-at91sam9.c [new file with mode: 0644]
drivers/rtc/rtc-bfin.c
drivers/rtc/rtc-cmos.c
drivers/rtc/rtc-dev.c
drivers/rtc/rtc-ds1302.c [new file with mode: 0644]
drivers/rtc/rtc-ds1307.c
drivers/rtc/rtc-ds1511.c [new file with mode: 0644]
drivers/rtc/rtc-pcf8583.c
drivers/rtc/rtc-r9701.c [new file with mode: 0644]
drivers/rtc/rtc-s3c.c
drivers/rtc/rtc-sa1100.c
drivers/rtc/rtc-sysfs.c
drivers/s390/block/dasd.c
drivers/s390/block/dasd_3990_erp.c
drivers/s390/block/dcssblk.c
drivers/s390/char/sclp_tty.c
drivers/s390/char/sclp_vt220.c
drivers/s390/cio/ccwgroup.c
drivers/s390/cio/chsc.c
drivers/s390/cio/device_id.c
drivers/s390/sysinfo.c
drivers/scsi/NCR53C9x.h
drivers/scsi/a2091.c
drivers/scsi/a3000.c
drivers/scsi/aacraid/linit.c
drivers/scsi/aha1542.c
drivers/scsi/aic7xxx/Makefile
drivers/scsi/aic7xxx/aic79xx_inline.h
drivers/scsi/aic7xxx/aic79xx_osm.c
drivers/scsi/aic7xxx/aic79xx_pci.c
drivers/scsi/aic7xxx/aic7xxx_inline.h
drivers/scsi/aic7xxx/aic7xxx_osm.c
drivers/scsi/aic7xxx_old.c
drivers/scsi/gvp11.c
drivers/scsi/ibmvscsi/ibmvstgt.c
drivers/scsi/ide-scsi.c
drivers/scsi/ipr.c
drivers/scsi/ips.c
drivers/scsi/lpfc/lpfc.h
drivers/scsi/lpfc/lpfc_init.c
drivers/scsi/lpfc/lpfc_mbox.c
drivers/scsi/megaraid/megaraid_mbox.c
drivers/scsi/megaraid/megaraid_sas.c
drivers/scsi/pcmcia/fdomain_stub.c
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_gs.c
drivers/scsi/qla2xxx/qla_os.c
drivers/scsi/qla4xxx/ql4_def.h
drivers/scsi/qla4xxx/ql4_init.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_tgt_lib.c
drivers/scsi/scsi_transport_sas.c
drivers/serial/21285.c
drivers/serial/8250.c
drivers/serial/8250_pci.c
drivers/serial/8250_pnp.c
drivers/serial/Kconfig
drivers/serial/Makefile
drivers/serial/atmel_serial.c
drivers/serial/cpm_uart/cpm_uart_core.c
drivers/serial/dz.c
drivers/serial/icom.h
drivers/serial/imx.c
drivers/serial/mcf.c
drivers/serial/mpsc.c
drivers/serial/mux.c
drivers/serial/s3c2410.c
drivers/serial/sc26xx.c [new file with mode: 0644]
drivers/serial/serial_core.c
drivers/serial/serial_cs.c
drivers/serial/uartlite.c
drivers/spi/Kconfig
drivers/spi/Makefile
drivers/spi/atmel_spi.c
drivers/spi/omap2_mcspi.c
drivers/spi/pxa2xx_spi.c
drivers/spi/spi.c
drivers/spi/spi_bfin5xx.c
drivers/spi/spi_imx.c
drivers/spi/spi_s3c24xx.c
drivers/spi/spi_s3c24xx_gpio.c
drivers/spi/spi_sh_sci.c [new file with mode: 0644]
drivers/ssb/b43_pci_bridge.c
drivers/uio/uio.c
drivers/usb/Kconfig
drivers/usb/atm/Kconfig
drivers/usb/atm/ueagle-atm.c
drivers/usb/class/cdc-acm.c
drivers/usb/class/cdc-acm.h
drivers/usb/core/Kconfig
drivers/usb/core/buffer.c
drivers/usb/core/config.c
drivers/usb/core/devices.c
drivers/usb/core/devio.c
drivers/usb/core/driver.c
drivers/usb/core/file.c
drivers/usb/core/hcd-pci.c
drivers/usb/core/hcd.c
drivers/usb/core/hcd.h
drivers/usb/core/hub.c
drivers/usb/core/hub.h
drivers/usb/core/inode.c
drivers/usb/core/message.c
drivers/usb/core/notify.c
drivers/usb/core/otg_whitelist.h
drivers/usb/core/sysfs.c
drivers/usb/core/urb.c
drivers/usb/core/usb.c
drivers/usb/core/usb.h
drivers/usb/gadget/Kconfig
drivers/usb/gadget/Makefile
drivers/usb/gadget/amd5536udc.c
drivers/usb/gadget/at91_udc.c
drivers/usb/gadget/at91_udc.h
drivers/usb/gadget/atmel_usba_udc.c
drivers/usb/gadget/atmel_usba_udc.h
drivers/usb/gadget/dummy_hcd.c
drivers/usb/gadget/ether.c
drivers/usb/gadget/file_storage.c
drivers/usb/gadget/fsl_usb2_udc.c
drivers/usb/gadget/fsl_usb2_udc.h
drivers/usb/gadget/gmidi.c
drivers/usb/gadget/goku_udc.c
drivers/usb/gadget/inode.c
drivers/usb/gadget/lh7a40x_udc.c
drivers/usb/gadget/m66592-udc.c
drivers/usb/gadget/m66592-udc.h
drivers/usb/gadget/net2280.c
drivers/usb/gadget/omap_udc.c
drivers/usb/gadget/omap_udc.h
drivers/usb/gadget/printer.c [new file with mode: 0644]
drivers/usb/gadget/pxa2xx_udc.c
drivers/usb/gadget/pxa2xx_udc.h
drivers/usb/gadget/rndis.c
drivers/usb/gadget/s3c2410_udc.c
drivers/usb/gadget/serial.c
drivers/usb/gadget/zero.c
drivers/usb/host/Kconfig
drivers/usb/host/ehci-au1xxx.c
drivers/usb/host/ehci-dbg.c
drivers/usb/host/ehci-fsl.c
drivers/usb/host/ehci-hcd.c
drivers/usb/host/ehci-hub.c
drivers/usb/host/ehci-ixp4xx.c [new file with mode: 0644]
drivers/usb/host/ehci-orion.c [new file with mode: 0644]
drivers/usb/host/ehci-pci.c
drivers/usb/host/ehci-ppc-of.c [new file with mode: 0644]
drivers/usb/host/ehci-ppc-soc.c
drivers/usb/host/ehci-ps3.c
drivers/usb/host/ehci-q.c
drivers/usb/host/ehci-sched.c
drivers/usb/host/ehci.h
drivers/usb/host/isp116x-hcd.c
drivers/usb/host/ohci-at91.c
drivers/usb/host/ohci-dbg.c
drivers/usb/host/ohci-hcd.c
drivers/usb/host/ohci-sh.c [new file with mode: 0644]
drivers/usb/host/ohci-sm501.c [new file with mode: 0644]
drivers/usb/host/ohci.h
drivers/usb/host/pci-quirks.c
drivers/usb/host/r8a66597.h
drivers/usb/image/mdc800.c
drivers/usb/misc/cypress_cy7c63.c
drivers/usb/misc/iowarrior.c
drivers/usb/misc/legousbtower.c
drivers/usb/misc/sisusbvga/sisusb.c
drivers/usb/misc/sisusbvga/sisusb.h
drivers/usb/misc/usbtest.c
drivers/usb/mon/mon_bin.c
drivers/usb/serial/Kconfig
drivers/usb/serial/Makefile
drivers/usb/serial/airprime.c
drivers/usb/serial/ark3116.c
drivers/usb/serial/belkin_sa.c
drivers/usb/serial/console.c
drivers/usb/serial/cp2101.c
drivers/usb/serial/cyberjack.c
drivers/usb/serial/cypress_m8.c
drivers/usb/serial/digi_acceleport.c
drivers/usb/serial/ezusb.c
drivers/usb/serial/ftdi_sio.c
drivers/usb/serial/ftdi_sio.h
drivers/usb/serial/garmin_gps.c
drivers/usb/serial/generic.c
drivers/usb/serial/io_edgeport.c
drivers/usb/serial/io_ti.c
drivers/usb/serial/iuu_phoenix.c [new file with mode: 0644]
drivers/usb/serial/iuu_phoenix.h [new file with mode: 0644]
drivers/usb/serial/keyspan.c
drivers/usb/serial/keyspan_pda.c
drivers/usb/serial/kl5kusb105.c
drivers/usb/serial/kobil_sct.c
drivers/usb/serial/mct_u232.c
drivers/usb/serial/mct_u232.h
drivers/usb/serial/mos7720.c
drivers/usb/serial/mos7840.c
drivers/usb/serial/option.c
drivers/usb/serial/oti6858.c
drivers/usb/serial/pl2303.c
drivers/usb/serial/pl2303.h
drivers/usb/serial/sierra.c
drivers/usb/serial/ti_usb_3410_5052.c
drivers/usb/serial/usb-serial.c
drivers/usb/serial/visor.c
drivers/usb/serial/whiteheat.c
drivers/usb/storage/initializers.c
drivers/usb/storage/isd200.c
drivers/usb/storage/unusual_devs.h
drivers/video/atmel_lcdfb.c
drivers/video/aty/radeon_pm.c
drivers/video/backlight/Kconfig
drivers/video/bf54x-lq043fb.c
drivers/video/console/bitblit.c
drivers/video/console/fbcon.c
drivers/video/console/fbcon.h
drivers/video/console/fbcon_ccw.c
drivers/video/console/fbcon_cw.c
drivers/video/console/fbcon_ud.c
drivers/video/console/fonts.c
drivers/video/console/tileblit.c
drivers/video/console/vgacon.c
drivers/video/cyblafb.c
drivers/video/fb_defio.c
drivers/video/fb_draw.h
drivers/video/fbmon.c
drivers/video/geode/lxfb_core.c
drivers/video/hpfb.c
drivers/video/i810/i810_main.c
drivers/video/igafb.c
drivers/video/intelfb/intelfb.h
drivers/video/intelfb/intelfbhw.c
drivers/video/neofb.c
drivers/video/nvidia/nvidia.c
drivers/video/omap/lcdc.c
drivers/video/pm2fb.c
drivers/video/pm3fb.c
drivers/video/pmag-aa-fb.c
drivers/video/ps3fb.c
drivers/video/s3c2410fb.c
drivers/video/s3c2410fb.h
drivers/video/sis/sis.h
drivers/video/sis/sis_main.c
drivers/video/sm501fb.c
drivers/video/tdfxfb.c
drivers/video/uvesafb.c
drivers/video/vermilion/vermilion.c
drivers/virtio/Kconfig
drivers/virtio/Makefile
drivers/virtio/virtio.c
drivers/virtio/virtio_balloon.c [new file with mode: 0644]
drivers/virtio/virtio_pci.c [new file with mode: 0644]
drivers/virtio/virtio_ring.c
drivers/w1/masters/Kconfig
drivers/w1/masters/Makefile
drivers/w1/masters/w1-gpio.c [new file with mode: 0644]
drivers/w1/slaves/w1_therm.c
drivers/w1/w1.c
drivers/watchdog/shwdt.c
fs/9p/fid.c
fs/9p/v9fs.c
fs/9p/v9fs.h
fs/9p/vfs_file.c
fs/9p/vfs_inode.c
fs/Kconfig
fs/befs/btree.c
fs/befs/datastream.c
fs/binfmt_elf.c
fs/block_dev.c
fs/buffer.c
fs/cifs/inode.c
fs/compat.c
fs/dcache.c
fs/direct-io.c
fs/dquot.c
fs/ecryptfs/crypto.c
fs/ecryptfs/ecryptfs_kernel.h
fs/ecryptfs/file.c
fs/ecryptfs/inode.c
fs/ecryptfs/keystore.c
fs/ecryptfs/main.c
fs/ecryptfs/mmap.c
fs/ecryptfs/read_write.c
fs/ecryptfs/super.c
fs/eventfd.c
fs/eventpoll.c
fs/exec.c
fs/ext2/balloc.c
fs/ext2/dir.c
fs/ext2/ext2.h
fs/ext2/file.c
fs/ext2/inode.c
fs/ext2/ioctl.c
fs/ext2/super.c
fs/ext3/balloc.c
fs/ext3/inode.c
fs/ext3/namei.c
fs/ext3/super.c
fs/ext4/balloc.c
fs/ext4/inode.c
fs/ext4/super.c
fs/fat/file.c
fs/fat/inode.c
fs/fat/misc.c
fs/file.c
fs/freevxfs/vxfs_dir.h
fs/freevxfs/vxfs_immed.c
fs/fs-writeback.c
fs/fuse/dev.c
fs/fuse/dir.c
fs/fuse/file.c
fs/fuse/fuse_i.h
fs/fuse/inode.c
fs/gfs2/bmap.c
fs/gfs2/ops_address.c
fs/gfs2/recovery.c
fs/hfs/bfind.c
fs/hfs/brec.c
fs/hfs/btree.c
fs/hfs/hfs.h
fs/hfs/super.c
fs/hostfs/hostfs_user.c
fs/hugetlbfs/inode.c
fs/inotify.c
fs/inotify_user.c
fs/jbd/journal.c
fs/jbd/recovery.c
fs/jbd2/recovery.c
fs/jffs2/readinode.c
fs/jfs/jfs_xtree.c
fs/libfs.c
fs/lockd/host.c
fs/lockd/svc.c
fs/lockd/svc4proc.c
fs/lockd/svclock.c
fs/lockd/svcproc.c
fs/lockd/svcsubs.c
fs/locks.c
fs/mpage.c
fs/namei.c
fs/namespace.c
fs/ncpfs/inode.c
fs/ncpfs/mmap.c
fs/nfs/callback.c
fs/nfs/read.c
fs/nfs/write.c
fs/nfsd/auth.c
fs/nfsd/auth.h [moved from include/linux/nfsd/auth.h with 87% similarity]
fs/nfsd/export.c
fs/nfsd/nfs2acl.c
fs/nfsd/nfs3xdr.c
fs/nfsd/nfs4callback.c
fs/nfsd/nfs4idmap.c
fs/nfsd/nfs4proc.c
fs/nfsd/nfs4state.c
fs/nfsd/nfs4xdr.c
fs/nfsd/nfscache.c
fs/nfsd/nfsctl.c
fs/nfsd/nfsfh.c
fs/nfsd/nfssvc.c
fs/nfsd/nfsxdr.c
fs/nfsd/vfs.c
fs/ntfs/aops.c
fs/ntfs/compress.c
fs/ntfs/file.c
fs/ntfs/malloc.h
fs/ocfs2/alloc.c
fs/ocfs2/aops.c
fs/ocfs2/dir.c
fs/ocfs2/ocfs1_fs_compat.h
fs/ocfs2/suballoc.c
fs/partitions/Kconfig
fs/pnode.c
fs/proc/array.c
fs/proc/base.c
fs/proc/internal.h
fs/proc/kcore.c
fs/proc/proc_misc.c
fs/proc/task_mmu.c
fs/reiserfs/bitmap.c
fs/reiserfs/inode.c
fs/reiserfs/prints.c
fs/reiserfs/xattr.c
fs/select.c
fs/signalfd.c
fs/smbfs/inode.c
fs/smbfs/sock.c
fs/timerfd.c
fs/utimes.c
fs/xattr.c
fs/xfs/linux-2.6/kmem.c
fs/xfs/linux-2.6/xfs_buf.c
fs/xfs/linux-2.6/xfs_lrw.c
include/acpi/acpixf.h
include/acpi/processor.h
include/asm-alpha/atomic.h
include/asm-alpha/pci.h
include/asm-alpha/pgalloc.h
include/asm-alpha/tlb.h
include/asm-alpha/tlbflush.h
include/asm-alpha/unistd.h
include/asm-arm/arch-at91/at91_mci.h
include/asm-arm/arch-at91/at91rm9200.h
include/asm-arm/arch-at91/at91sam9260.h
include/asm-arm/arch-at91/at91sam9261.h
include/asm-arm/arch-at91/at91sam9263.h
include/asm-arm/arch-at91/at91sam9rl.h
include/asm-arm/arch-at91/board.h
include/asm-arm/arch-at91/uncompress.h
include/asm-arm/arch-iop13xx/adma.h
include/asm-arm/arch-ixp4xx/cpu.h
include/asm-arm/arch-ixp4xx/dsmg600.h
include/asm-arm/arch-ixp4xx/hardware.h
include/asm-arm/arch-ixp4xx/io.h
include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
include/asm-arm/arch-ixp4xx/nas100d.h
include/asm-arm/arch-ixp4xx/npe.h [new file with mode: 0644]
include/asm-arm/arch-ixp4xx/nslu2.h
include/asm-arm/arch-ixp4xx/platform.h
include/asm-arm/arch-ixp4xx/qmgr.h [new file with mode: 0644]
include/asm-arm/arch-ixp4xx/uncompress.h
include/asm-arm/arch-pxa/gpio.h
include/asm-arm/arch-pxa/pxa-regs.h
include/asm-arm/arch-pxa/pxa3xx-regs.h
include/asm-arm/arch-realview/board-eb.h [new file with mode: 0644]
include/asm-arm/arch-realview/entry-macro.S
include/asm-arm/arch-realview/hardware.h
include/asm-arm/arch-realview/irqs.h
include/asm-arm/arch-realview/platform.h
include/asm-arm/arch-realview/scu.h
include/asm-arm/arch-realview/uncompress.h
include/asm-arm/arch-s3c2410/regs-lcd.h
include/asm-arm/arch-s3c2410/spi-gpio.h
include/asm-arm/arch-s3c2410/spi.h
include/asm-arm/arch-versatile/irqs.h
include/asm-arm/hardware/arm_twd.h
include/asm-arm/hardware/iop3xx-adma.h
include/asm-arm/hardware/it8152.h
include/asm-arm/kexec.h
include/asm-arm/mach/udc_pxa2xx.h
include/asm-arm/pgalloc.h
include/asm-arm/smp.h
include/asm-arm/tlb.h
include/asm-avr32/arch-at32ap/at32ap700x.h
include/asm-avr32/arch-at32ap/gpio.h
include/asm-avr32/arch-at32ap/irq.h
include/asm-avr32/delay.h
include/asm-avr32/pgalloc.h
include/asm-avr32/timex.h
include/asm-avr32/unistd.h
include/asm-blackfin/io.h
include/asm-cris/bitops.h
include/asm-cris/pgalloc.h
include/asm-frv/atomic.h
include/asm-frv/bitops.h
include/asm-frv/cacheflush.h
include/asm-frv/dma-mapping.h
include/asm-frv/highmem.h
include/asm-frv/mem-layout.h
include/asm-frv/page.h
include/asm-frv/pgalloc.h
include/asm-frv/pgtable.h
include/asm-frv/scatterlist.h
include/asm-frv/unistd.h
include/asm-generic/4level-fixup.h
include/asm-generic/cputime.h
include/asm-generic/gpio.h
include/asm-generic/pgtable-nopmd.h
include/asm-generic/pgtable-nopud.h
include/asm-generic/rtc.h
include/asm-generic/sections.h
include/asm-generic/tlb.h
include/asm-h8300/io.h
include/asm-h8300/virtconvert.h
include/asm-ia64/bitops.h
include/asm-ia64/compat.h
include/asm-ia64/gcc_intrin.h
include/asm-ia64/mca.h
include/asm-ia64/mca_asm.h
include/asm-ia64/pgalloc.h
include/asm-ia64/processor.h
include/asm-ia64/sal.h
include/asm-m32r/delay.h
include/asm-m32r/irq.h
include/asm-m32r/m32700ut/m32700ut_pld.h
include/asm-m32r/pgalloc.h
include/asm-m32r/unistd.h
include/asm-m68k/macintosh.h
include/asm-m68k/motorola_pgalloc.h
include/asm-m68k/pgtable.h
include/asm-m68k/sun3_pgalloc.h
include/asm-m68knommu/bitops.h
include/asm-m68knommu/commproc.h
include/asm-m68knommu/delay.h
include/asm-m68knommu/io.h
include/asm-m68knommu/m5249sim.h
include/asm-m68knommu/m5307sim.h
include/asm-m68knommu/m5407sim.h
include/asm-m68knommu/m68360_regs.h
include/asm-m68knommu/mcfne.h
include/asm-m68knommu/mcfsim.h
include/asm-m68knommu/mcftimer.h
include/asm-m68knommu/mcfuart.h
include/asm-m68knommu/system.h
include/asm-mips/compat.h
include/asm-mips/mach-excite/excite_fpga.h
include/asm-mips/mach-wrppmc/mach-gt64120.h
include/asm-mips/pgalloc.h
include/asm-mips/processor.h
include/asm-mips/sgi/ip22.h
include/asm-mips/sn/sn0/hubio.h
include/asm-parisc/compat.h
include/asm-parisc/elf.h
include/asm-parisc/linkage.h
include/asm-parisc/pgalloc.h
include/asm-parisc/processor.h
include/asm-parisc/tlb.h
include/asm-parisc/vga.h
include/asm-powerpc/compat.h
include/asm-powerpc/cputime.h
include/asm-powerpc/dma.h
include/asm-powerpc/iommu.h
include/asm-powerpc/mediabay.h
include/asm-powerpc/nvram.h
include/asm-powerpc/paca.h
include/asm-powerpc/pgalloc-32.h
include/asm-powerpc/pgalloc-64.h
include/asm-powerpc/processor.h
include/asm-powerpc/ps3av.h
include/asm-powerpc/systbl.h
include/asm-ppc/pgalloc.h
include/asm-s390/bitops.h
include/asm-s390/cacheflush.h
include/asm-s390/ccwgroup.h
include/asm-s390/compat.h
include/asm-s390/cputime.h
include/asm-s390/pgalloc.h
include/asm-s390/pgtable.h
include/asm-s390/processor.h
include/asm-s390/tlb.h
include/asm-sh/delay.h
include/asm-sh/pgalloc.h
include/asm-sh/unistd_32.h
include/asm-sh/unistd_64.h
include/asm-sparc/pgalloc.h
include/asm-sparc/unistd.h
include/asm-sparc64/compat.h
include/asm-sparc64/io.h
include/asm-sparc64/pgalloc.h
include/asm-sparc64/timex.h
include/asm-sparc64/tlb.h
include/asm-sparc64/unistd.h
include/asm-um/a.out.h
include/asm-um/current.h
include/asm-um/elf-i386.h
include/asm-um/elf-x86_64.h
include/asm-um/fixmap.h
include/asm-um/ldt.h
include/asm-um/linkage.h
include/asm-um/mmu_context.h
include/asm-um/page.h
include/asm-um/param.h
include/asm-um/pgalloc.h
include/asm-um/pgtable-2level.h
include/asm-um/pgtable-3level.h
include/asm-um/pgtable.h
include/asm-um/processor-generic.h
include/asm-um/processor-i386.h
include/asm-um/thread_info.h
include/asm-um/tlb.h
include/asm-um/uaccess.h
include/asm-v850/io.h
include/asm-x86/asm.h
include/asm-x86/bitops_64.h
include/asm-x86/bugs.h
include/asm-x86/compat.h
include/asm-x86/cpufeature.h
include/asm-x86/delay.h
include/asm-x86/efi.h
include/asm-x86/futex.h
include/asm-x86/highmem.h
include/asm-x86/hw_irq_32.h
include/asm-x86/i387.h
include/asm-x86/io_32.h
include/asm-x86/mach-numaq/mach_apic.h
include/asm-x86/mach-voyager/do_timer.h
include/asm-x86/msr.h
include/asm-x86/page.h
include/asm-x86/page_64.h
include/asm-x86/pgalloc_32.h
include/asm-x86/pgalloc_64.h
include/asm-x86/pgtable-3level.h
include/asm-x86/pgtable.h
include/asm-x86/pgtable_32.h
include/asm-x86/pgtable_64.h
include/asm-x86/string_32.h
include/asm-x86/system.h
include/asm-x86/timex.h
include/asm-x86/uaccess_32.h
include/asm-x86/uaccess_64.h
include/asm-x86/unistd_32.h
include/asm-x86/unistd_64.h
include/asm-x86/vm86.h
include/asm-xtensa/pgalloc.h
include/asm-xtensa/tlb.h
include/linux/Kbuild
include/linux/ac97_codec.h
include/linux/acct.h
include/linux/agp_backend.h
include/linux/agpgart.h
include/linux/async_tx.h
include/linux/ata_platform.h [moved from include/linux/pata_platform.h with 75% similarity]
include/linux/atmel_serial.h [moved from drivers/serial/atmel_serial.h with 99% similarity]
include/linux/capability.h
include/linux/chio.h
include/linux/compat.h
include/linux/cpuidle.h
include/linux/cyclades.h
include/linux/cycx_x25.h
include/linux/dccp.h
include/linux/device.h
include/linux/dma-mapping.h
include/linux/dmaengine.h
include/linux/ethtool.h
include/linux/fs.h
include/linux/fsnotify.h
include/linux/gfp.h
include/linux/hash.h
include/linux/hdlc.h
include/linux/hdreg.h
include/linux/highmem.h
include/linux/hrtimer.h
include/linux/hw_random.h
include/linux/i2c/pca953x.h [new file with mode: 0644]
include/linux/i2c/pcf857x.h [new file with mode: 0644]
include/linux/ide.h
include/linux/ieee80211.h
include/linux/if_vlan.h
include/linux/init.h
include/linux/init_task.h
include/linux/interrupt.h
include/linux/iommu-helper.h [new file with mode: 0644]
include/linux/isdn.h
include/linux/jbd.h
include/linux/kernel.h
include/linux/kprobes.h
include/linux/latency.h [deleted file]
include/linux/leds.h
include/linux/lguest_launcher.h
include/linux/libata.h
include/linux/llc.h
include/linux/lockd/lockd.h
include/linux/lockd/xdr.h
include/linux/log2.h
include/linux/loop.h
include/linux/lp.h
include/linux/miscdevice.h
include/linux/mm.h
include/linux/mmzone.h
include/linux/mod_devicetable.h
include/linux/nfsd/Kbuild
include/linux/nfsd/cache.h
include/linux/nfsd/export.h
include/linux/nfsd/nfsd.h
include/linux/nfsd/syscall.h
include/linux/nfsd/xdr.h
include/linux/nfsd/xdr3.h
include/linux/nfsd/xdr4.h
include/linux/nfsd_idmap.h
include/linux/notifier.h
include/linux/nubus.h
include/linux/page-flags.h
include/linux/pci-acpi.h
include/linux/pci.h
include/linux/pci_ids.h
include/linux/pda_power.h
include/linux/percpu.h
include/linux/phy.h
include/linux/pkt_cls.h
include/linux/pm.h
include/linux/pm_qos_params.h [new file with mode: 0644]
include/linux/pnp.h
include/linux/power_supply.h
include/linux/prctl.h
include/linux/proc_fs.h
include/linux/ptrace.h
include/linux/radix-tree.h
include/linux/raid/bitmap.h
include/linux/raid/md_k.h
include/linux/rcupdate.h
include/linux/reboot.h
include/linux/reiserfs_fs_sb.h
include/linux/rtnetlink.h
include/linux/sched.h
include/linux/security.h
include/linux/serial_8250.h
include/linux/signal.h
include/linux/signalfd.h
include/linux/skbuff.h
include/linux/slub_def.h
include/linux/sm501-regs.h
include/linux/sm501.h
include/linux/sonypi.h
include/linux/spi/mcp23s08.h [new file with mode: 0644]
include/linux/spinlock_api_up.h
include/linux/ssb/ssb.h
include/linux/sunrpc/cache.h
include/linux/sunrpc/debug.h
include/linux/sunrpc/svc.h
include/linux/sunrpc/svc_rdma.h [new file with mode: 0644]
include/linux/sunrpc/svc_xprt.h [new file with mode: 0644]
include/linux/sunrpc/svcsock.h
include/linux/sunrpc/xdr.h
include/linux/suspend.h
include/linux/suspend_ioctls.h [new file with mode: 0644]
include/linux/swap.h
include/linux/swapops.h
include/linux/syscalls.h
include/linux/sysctl.h
include/linux/tc_ematch/tc_em_meta.h
include/linux/timex.h
include/linux/tty.h
include/linux/usb.h
include/linux/usb/Kbuild
include/linux/usb/audio.h
include/linux/usb/cdc.h
include/linux/usb/g_printer.h [new file with mode: 0644]
include/linux/usb/gadget.h
include/linux/usb/gadgetfs.h
include/linux/usb/iowarrior.h
include/linux/usb/isp116x.h
include/linux/usb/midi.h
include/linux/usb/net2280.h
include/linux/usb/otg.h
include/linux/usb/serial.h
include/linux/usb/sl811.h
include/linux/usb_usual.h
include/linux/usbdevice_fs.h
include/linux/virtio.h
include/linux/virtio_balloon.h [new file with mode: 0644]
include/linux/virtio_blk.h
include/linux/virtio_config.h
include/linux/virtio_net.h
include/linux/virtio_pci.h [new file with mode: 0644]
include/linux/virtio_ring.h
include/linux/vmalloc.h
include/linux/vt_kern.h
include/linux/w1-gpio.h [new file with mode: 0644]
include/linux/wait.h
include/linux/wireless.h
include/linux/writeback.h
include/linux/xattr.h
include/media/rds.h
include/net/9p/9p.h
include/net/9p/client.h
include/net/9p/conn.h [deleted file]
include/net/9p/transport.h
include/net/if_inet6.h
include/net/inet6_hashtables.h
include/net/inet_connection_sock.h
include/net/inet_hashtables.h
include/net/inet_timewait_sock.h
include/net/ip_fib.h
include/net/ipv6.h
include/net/netlabel.h
include/net/sock.h
include/pcmcia/cs.h
include/pcmcia/cs_types.h
include/pcmcia/ss.h
include/scsi/scsi_transport_fc.h
include/video/atmel_lcdc.h
init/Kconfig
init/calibrate.c
init/do_mounts.c
init/initramfs.c
init/main.c
ipc/msg.c
ipc/sem.c
ipc/shm.c
ipc/util.c
kernel/Kconfig.instrumentation [deleted file]
kernel/Makefile
kernel/capability.c
kernel/exit.c
kernel/fork.c
kernel/hrtimer.c
kernel/kallsyms.c
kernel/kprobes.c
kernel/latency.c [deleted file]
kernel/notifier.c
kernel/params.c
kernel/pm_qos_params.c [new file with mode: 0644]
kernel/posix-timers.c
kernel/power/Kconfig
kernel/power/disk.c
kernel/power/main.c
kernel/power/power.h
kernel/power/snapshot.c
kernel/power/swap.c
kernel/power/swsusp.c
kernel/power/user.c
kernel/printk.c
kernel/ptrace.c
kernel/relay.c
kernel/signal.c
kernel/softlockup.c
kernel/srcu.c
kernel/stop_machine.c
kernel/sys.c
kernel/sys_ni.c
kernel/sysctl.c
kernel/sysctl_check.c
kernel/test_kprobes.c
kernel/time.c
kernel/time/clocksource.c
kernel/timer.c
lib/Kconfig.debug
lib/Makefile
lib/crc32.c
lib/extable.c
lib/iommu-helper.c [new file with mode: 0644]
lib/kobject.c
lib/radix-tree.c
lib/smp_processor_id.c
lib/swiotlb.c
lib/zlib_deflate/defutil.h
mm/Makefile
mm/allocpercpu.c
mm/dmapool.c [new file with mode: 0644]
mm/fadvise.c
mm/filemap.c
mm/filemap_xip.c
mm/fremap.c
mm/highmem.c
mm/hugetlb.c
mm/internal.h
mm/memory.c
mm/memory_hotplug.c
mm/migrate.c
mm/mmap.c
mm/nommu.c
mm/oom_kill.c
mm/page-writeback.c
mm/page_alloc.c
mm/page_io.c
mm/pagewalk.c [new file with mode: 0644]
mm/rmap.c
mm/shmem.c
mm/slob.c
mm/slub.c
mm/sparse.c
mm/swap.c
mm/swap_state.c
mm/swapfile.c
mm/tiny-shmem.c
mm/truncate.c
mm/vmalloc.c
mm/vmstat.c
net/9p/Makefile
net/9p/client.c
net/9p/fcprint.c
net/9p/mod.c
net/9p/mux.c [deleted file]
net/9p/trans_fd.c
net/9p/trans_virtio.c
net/9p/util.c
net/bluetooth/hidp/core.c
net/bluetooth/rfcomm/tty.c
net/core/net_namespace.c
net/core/rtnetlink.c
net/core/skbuff.c
net/dccp/dccp.h
net/dccp/ipv4.c
net/dccp/ipv6.c
net/dccp/proto.c
net/ipv4/cipso_ipv4.c
net/ipv4/fib_trie.c
net/ipv4/icmp.c
net/ipv4/inet_connection_sock.c
net/ipv4/inet_hashtables.c
net/ipv4/ipvs/ip_vs_wrr.c
net/ipv4/tcp.c
net/ipv4/tcp_ipv4.c
net/ipv4/xfrm4_mode_beet.c
net/ipv6/icmp.c
net/ipv6/inet6_hashtables.c
net/ipv6/tcp_ipv6.c
net/mac80211/Kconfig
net/mac80211/ieee80211.c
net/mac80211/rc80211_pid_algo.c
net/mac80211/rc80211_simple.c
net/mac80211/rx.c
net/netlabel/netlabel_cipso_v4.c
net/netlabel/netlabel_cipso_v4.h
net/netlabel/netlabel_domainhash.h
net/netlabel/netlabel_kapi.c
net/rfkill/rfkill.c
net/sched/cls_flow.c
net/sched/em_meta.c
net/sctp/auth.c
net/sctp/sm_statefuns.c
net/sunrpc/Makefile
net/sunrpc/auth_gss/svcauth_gss.c
net/sunrpc/cache.c
net/sunrpc/stats.c
net/sunrpc/sunrpc_syms.c
net/sunrpc/svc.c
net/sunrpc/svc_xprt.c [new file with mode: 0644]
net/sunrpc/svcauth.c
net/sunrpc/svcauth_unix.c
net/sunrpc/svcsock.c
net/sunrpc/sysctl.c
net/sunrpc/xdr.c
net/sunrpc/xprtrdma/Makefile
net/sunrpc/xprtrdma/svc_rdma.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_marshal.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_sendto.c [new file with mode: 0644]
net/sunrpc/xprtrdma/svc_rdma_transport.c [new file with mode: 0644]
scripts/checkstack.pl
scripts/kallsyms.c
scripts/kconfig/mconf.c
scripts/kconfig/menu.c
scripts/mod/file2alias.c
scripts/mod/modpost.c
scripts/setlocalversion [changed mode: 0644->0755]
security/Kconfig
security/Makefile
security/commoncap.c
security/dummy.c
security/security.c
security/selinux/hooks.c
security/selinux/include/security.h
security/selinux/ss/services.c
security/smack/Kconfig [new file with mode: 0644]
security/smack/Makefile [new file with mode: 0644]
security/smack/smack.h [new file with mode: 0644]
security/smack/smack_access.c [new file with mode: 0644]
security/smack/smack_lsm.c [new file with mode: 0644]
security/smack/smackfs.c [new file with mode: 0644]
sound/core/pcm_native.c
sound/oss/Makefile
sound/oss/ac97_codec.c
sound/oss/btaudio.c [deleted file]
sound/oss/cs4232.c [deleted file]
sound/oss/dmasound/Kconfig
sound/oss/dmasound/dmasound_paula.c
sound/oss/i810_audio.c [deleted file]
sound/oss/pss.c
sound/oss/sb_common.c
sound/oss/trident.c
sound/oss/via82cxxx_audio.c [deleted file]
sound/usb/usx2y/usX2Yhwdep.c
sound/usb/usx2y/usx2yhwdeppcm.c

diff --git a/CREDITS b/CREDITS
index edff310dbe531a6f9c2da88578c605f099e79bfc..da0a56e23beeca7512d80c762425c4fedfaf45b8 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -508,12 +508,8 @@ D: REINER SCT cyberJack pinpad/e-com USB chipcard reader driver
 S: Germany
 
 N: Adrian Bunk
-E: bunk@stusta.de
 P: 1024D/4F12B400  B29C E71E FE19 6755 5C8A  84D4 99FC EA98 4F12 B400
 D: misc kernel hacking and testing
-S: Grasmeierstrasse 11
-S: 80805 Muenchen
-S: Germany
 
 N: Ray Burr
 E: ryb@nightmare.com
@@ -1124,6 +1120,9 @@ S: 1150 Ringwood Court
 S: San Jose, California 95131
 S: USA
 
+N: Adam Fritzler
+E: mid@zigamorph.net
+
 N: Fernando Fuganti
 E: fuganti@conectiva.com.br
 E: fuganti@netbank.com.br
index c3014df066c4e3ee61b12397cb6e964131630427..40ac7759c3bb5342edf9168153edbf1f1ff05e79 100644 (file)
@@ -154,7 +154,7 @@ firmware_class/
        - request_firmware() hotplug interface info.
 floppy.txt
        - notes and driver options for the floppy disk driver.
-fujitsu/
+frv/
        - Fujitsu FR-V Linux documentation.
 gpio.txt
        - overview of GPIO (General Purpose Input/Output) access conventions.
@@ -364,8 +364,6 @@ sharedsubtree.txt
        - a description of shared subtrees for namespaces.
 smart-config.txt
        - description of the Smart Config makefile feature.
-smp.txt
-       - a few notes on symmetric multi-processing.
 sony-laptop.txt
        - Sony Notebook Control Driver (SNC) Readme.
 sonypi.txt
index 9734577d171154630f49be83779863ef875d6b7e..11a3c1682cecb87e16514249d6877a18608ccf01 100644 (file)
@@ -52,3 +52,36 @@ Description:
                facility is inherently dangerous, it is disabled by default
                for all devices except hubs.  For more information, see
                Documentation/usb/persist.txt.
+
+What:          /sys/bus/usb/device/.../power/connected_duration
+Date:          January 2008
+KernelVersion: 2.6.25
+Contact:       Sarah Sharp <sarah.a.sharp@intel.com>
+Description:
+               If CONFIG_PM and CONFIG_USB_SUSPEND are enabled, then this file
+               is present.  When read, it returns the total time (in msec)
+               that the USB device has been connected to the machine.  This
+               file is read-only.
+Users:
+               PowerTOP <power@bughost.org>
+               http://www.lesswatts.org/projects/powertop/
+
+What:          /sys/bus/usb/device/.../power/active_duration
+Date:          January 2008
+KernelVersion: 2.6.25
+Contact:       Sarah Sharp <sarah.a.sharp@intel.com>
+Description:
+               If CONFIG_PM and CONFIG_USB_SUSPEND are enabled, then this file
+               is present.  When read, it returns the total time (in msec)
+               that the USB device has been active, i.e. not in a suspended
+               state.  This file is read-only.
+
+               Tools can use this file and the connected_duration file to
+               compute the percentage of time that a device has been active.
+               For example,
+               echo $((100 * `cat active_duration` / `cat connected_duration`))
+               will give an integer percentage.  Note that this does not
+               account for counter wrap.
+Users:
+               PowerTOP <power@bughost.org>
+               http://www.lesswatts.org/projects/powertop/
index 35f5bd243336aeb1927f42483e26fa7586bcb205..65022a87bf17902f9e04fe5ecff611a41ffaf4d8 100644 (file)
@@ -53,7 +53,7 @@ Finding it the old way
 
 [Sat Mar  2 10:32:33 PST 1996 KERNEL_BUG-HOWTO lm@sgi.com (Larry McVoy)]
 
-This is how to track down a bug if you know nothing about kernel hacking.  
+This is how to track down a bug if you know nothing about kernel hacking.
 It's a brute force approach but it works pretty well.
 
 You need:
@@ -66,12 +66,12 @@ You will then do:
 
         . Rebuild a revision that you believe works, install, and verify that.
         . Do a binary search over the kernels to figure out which one
-          introduced the bug.  I.e., suppose 1.3.28 didn't have the bug, but 
+          introduced the bug.  I.e., suppose 1.3.28 didn't have the bug, but
           you know that 1.3.69 does.  Pick a kernel in the middle and build
           that, like 1.3.50.  Build & test; if it works, pick the mid point
           between .50 and .69, else the mid point between .28 and .50.
         . You'll narrow it down to the kernel that introduced the bug.  You
-          can probably do better than this but it gets tricky.  
+          can probably do better than this but it gets tricky.
 
         . Narrow it down to a subdirectory
 
@@ -81,27 +81,27 @@ You will then do:
             directories:
 
                 Copy the non-working directory next to the working directory
-                as "dir.63".  
+                as "dir.63".
                 One directory at time, try moving the working directory to
-                "dir.62" and mv dir.63 dir"time, try 
+                "dir.62" and mv dir.63 dir"time, try
 
                         mv dir dir.62
                         mv dir.63 dir
                         find dir -name '*.[oa]' -print | xargs rm -f
 
                 And then rebuild and retest.  Assuming that all related
-                changes were contained in the sub directory, this should 
-                isolate the change to a directory.  
+                changes were contained in the sub directory, this should
+                isolate the change to a directory.
 
                 Problems: changes in header files may have occurred; I've
-                found in my case that they were self explanatory - you may 
+                found in my case that they were self explanatory - you may
                 or may not want to give up when that happens.
 
         . Narrow it down to a file
 
           - You can apply the same technique to each file in the directory,
-            hoping that the changes in that file are self contained.  
-            
+            hoping that the changes in that file are self contained.
+
         . Narrow it down to a routine
 
           - You can take the old file and the new file and manually create
@@ -130,7 +130,7 @@ You will then do:
             that makes the difference.
 
 Finally, you take all the info that you have, kernel revisions, bug
-description, the extent to which you have narrowed it down, and pass 
+description, the extent to which you have narrowed it down, and pass
 that off to whomever you believe is the maintainer of that section.
 A post to linux.dev.kernel isn't such a bad idea if you've done some
 work to narrow it down.
@@ -214,6 +214,23 @@ And recompile the kernel with CONFIG_DEBUG_INFO enabled:
   gdb vmlinux
   (gdb) p vt_ioctl
   (gdb) l *(0x<address of vt_ioctl> + 0xda8)
+or, as one command
+  (gdb) l *(vt_ioctl + 0xda8)
+
+If you have a call trace, such as :-
+>Call Trace:
+> [<ffffffff8802c8e9>] :jbd:log_wait_commit+0xa3/0xf5
+> [<ffffffff810482d9>] autoremove_wake_function+0x0/0x2e
+> [<ffffffff8802770b>] :jbd:journal_stop+0x1be/0x1ee
+> ...
+this shows the problem in the :jbd: module. You can load that module in gdb
+and list the relevant code.
+  gdb fs/jbd/jbd.ko
+  (gdb) p log_wait_commit
+  (gdb) l *(0x<address> + 0xa3)
+or
+  (gdb) l *(log_wait_commit + 0xa3)
+
 
 Another very useful option of the Kernel Hacking section in menuconfig is
 Debug memory allocations. This will help you see whether data has been
index 77436d735013f37195750aec890f7db57a1b130d..059aaf20951a3bb54a4604084b2b33d70d306af2 100644 (file)
@@ -165,6 +165,7 @@ X!Ilib/string.c
 !Emm/vmalloc.c
 !Imm/page_alloc.c
 !Emm/mempool.c
+!Emm/dmapool.c
 !Emm/page-writeback.c
 !Emm/truncate.c
      </sect1>
@@ -371,7 +372,6 @@ X!Iinclude/linux/device.h
 !Edrivers/base/class.c
 !Edrivers/base/firmware_class.c
 !Edrivers/base/transport_class.c
-!Edrivers/base/dmapool.c
 <!-- Cannot be included, because
      attribute_container_add_class_device_adapter
  and attribute_container_classdev_to_container
index 01825ee7db64031878c6c9e647cd698547c9d558..2e9d6b41f034594b3b1af87c97ab1da81f5caccd 100644 (file)
@@ -717,7 +717,7 @@ used, and when it gets full, throws out the least used one.
     <para>
 For our first example, we assume that all operations are in user
 context (ie. from system calls), so we can sleep.  This means we can
-use a semaphore to protect the cache and all the objects within
+use a mutex to protect the cache and all the objects within
 it.  Here's the code:
     </para>
 
@@ -725,7 +725,7 @@ it.  Here's the code:
 #include &lt;linux/list.h&gt;
 #include &lt;linux/slab.h&gt;
 #include &lt;linux/string.h&gt;
-#include &lt;asm/semaphore.h&gt;
+#include &lt;linux/mutex.h&gt;
 #include &lt;asm/errno.h&gt;
 
 struct object
@@ -737,7 +737,7 @@ struct object
 };
 
 /* Protects the cache, cache_num, and the objects within it */
-static DECLARE_MUTEX(cache_lock);
+static DEFINE_MUTEX(cache_lock);
 static LIST_HEAD(cache);
 static unsigned int cache_num = 0;
 #define MAX_CACHE_SIZE 10
@@ -789,17 +789,17 @@ int cache_add(int id, const char *name)
         obj-&gt;id = id;
         obj-&gt;popularity = 0;
 
-        down(&amp;cache_lock);
+        mutex_lock(&amp;cache_lock);
         __cache_add(obj);
-        up(&amp;cache_lock);
+        mutex_unlock(&amp;cache_lock);
         return 0;
 }
 
 void cache_delete(int id)
 {
-        down(&amp;cache_lock);
+        mutex_lock(&amp;cache_lock);
         __cache_delete(__cache_find(id));
-        up(&amp;cache_lock);
+        mutex_unlock(&amp;cache_lock);
 }
 
 int cache_find(int id, char *name)
@@ -807,13 +807,13 @@ int cache_find(int id, char *name)
         struct object *obj;
         int ret = -ENOENT;
 
-        down(&amp;cache_lock);
+        mutex_lock(&amp;cache_lock);
         obj = __cache_find(id);
         if (obj) {
                 ret = 0;
                 strcpy(name, obj-&gt;name);
         }
-        up(&amp;cache_lock);
+        mutex_unlock(&amp;cache_lock);
         return ret;
 }
 </programlisting>
@@ -853,7 +853,7 @@ The change is shown below, in standard patch format: the
          int popularity;
  };
 
--static DECLARE_MUTEX(cache_lock);
+-static DEFINE_MUTEX(cache_lock);
 +static spinlock_t cache_lock = SPIN_LOCK_UNLOCKED;
  static LIST_HEAD(cache);
  static unsigned int cache_num = 0;
@@ -870,22 +870,22 @@ The change is shown below, in standard patch format: the
          obj-&gt;id = id;
          obj-&gt;popularity = 0;
 
--        down(&amp;cache_lock);
+-        mutex_lock(&amp;cache_lock);
 +        spin_lock_irqsave(&amp;cache_lock, flags);
          __cache_add(obj);
--        up(&amp;cache_lock);
+-        mutex_unlock(&amp;cache_lock);
 +        spin_unlock_irqrestore(&amp;cache_lock, flags);
          return 0;
  }
 
  void cache_delete(int id)
  {
--        down(&amp;cache_lock);
+-        mutex_lock(&amp;cache_lock);
 +        unsigned long flags;
 +
 +        spin_lock_irqsave(&amp;cache_lock, flags);
          __cache_delete(__cache_find(id));
--        up(&amp;cache_lock);
+-        mutex_unlock(&amp;cache_lock);
 +        spin_unlock_irqrestore(&amp;cache_lock, flags);
  }
 
@@ -895,14 +895,14 @@ The change is shown below, in standard patch format: the
          int ret = -ENOENT;
 +        unsigned long flags;
 
--        down(&amp;cache_lock);
+-        mutex_lock(&amp;cache_lock);
 +        spin_lock_irqsave(&amp;cache_lock, flags);
          obj = __cache_find(id);
          if (obj) {
                  ret = 0;
                  strcpy(name, obj-&gt;name);
          }
--        up(&amp;cache_lock);
+-        mutex_unlock(&amp;cache_lock);
 +        spin_unlock_irqrestore(&amp;cache_lock, flags);
          return ret;
  }
index 3d2f31b99dd9f081b2a3032d5551c153eb60ab0f..4acc73240a6d536ef044bf1dfc5a2abd6ae4296f 100644 (file)
@@ -59,7 +59,7 @@
    <title>Introduction</title>
   <para>
     This document describes the interfaces available for device drivers that
-    drive s390 based channel attached devices. This includes interfaces for
+    drive s390 based channel attached I/O devices. This includes interfaces for
     interaction with the hardware and interfaces for interacting with the
     common driver core. Those interfaces are provided by the s390 common I/O
     layer.
        The ccw bus typically contains the majority of devices available to
        a s390 system. Named after the channel command word (ccw), the basic
        command structure used to address its devices, the ccw bus contains
-       so-called channel attached devices. They are addressed via subchannels,
-       visible on the css bus. A device driver, however, will never interact
-       with the subchannel directly, but only via the device on the ccw bus,
+       so-called channel attached devices. They are addressed via I/O
+       subchannels, visible on the css bus. A device driver for
+       channel-attached devices, however, will never interact  with the
+       subchannel directly, but only via the I/O device on the ccw bus,
        the ccw device.
   </para>
     <sect1 id="channelIO">
 !Iinclude/asm-s390/ccwdev.h
 !Edrivers/s390/cio/device.c
 !Edrivers/s390/cio/device_ops.c
-!Edrivers/s390/cio/airq.c
     </sect1>
     <sect1 id="cmf">
      <title>The channel-measurement facility</title>
    </sect1>
   </chapter>
 
+  <chapter id="genericinterfaces">
+   <title>Generic interfaces</title>
+  <para>
+       Some interfaces are available to other drivers that do not necessarily
+       have anything to do with the busses described above, but still are
+       indirectly using basic infrastructure in the common I/O layer.
+       One example is the support for adapter interrupts.
+  </para>
+!Edrivers/s390/cio/airq.c
+  </chapter>
+
 </book>
diff --git a/Documentation/Smack.txt b/Documentation/Smack.txt
new file mode 100644 (file)
index 0000000..989c2fc
--- /dev/null
@@ -0,0 +1,493 @@
+
+
+    "Good for you, you've decided to clean the elevator!"
+    - The Elevator, from Dark Star
+
+Smack is the the Simplified Mandatory Access Control Kernel.
+Smack is a kernel based implementation of mandatory access
+control that includes simplicity in its primary design goals.
+
+Smack is not the only Mandatory Access Control scheme
+available for Linux. Those new to Mandatory Access Control
+are encouraged to compare Smack with the other mechanisms
+available to determine which is best suited to the problem
+at hand.
+
+Smack consists of three major components:
+    - The kernel
+    - A start-up script and a few modified applications
+    - Configuration data
+
+The kernel component of Smack is implemented as a Linux
+Security Modules (LSM) module. It requires netlabel and
+works best with file systems that support extended attributes,
+although xattr support is not strictly required.
+It is safe to run a Smack kernel under a "vanilla" distribution.
+Smack kernels use the CIPSO IP option. Some network
+configurations are intolerant of IP options and can impede
+access to systems that use them as Smack does.
+
+The startup script etc-init.d-smack should be installed
+in /etc/init.d/smack and should be invoked early in the
+start-up process. On Fedora rc5.d/S02smack is recommended.
+This script ensures that certain devices have the correct
+Smack attributes and loads the Smack configuration if
+any is defined. This script invokes two programs that
+ensure configuration data is properly formatted. These
+programs are /usr/sbin/smackload and /usr/sin/smackcipso.
+The system will run just fine without these programs,
+but it will be difficult to set access rules properly.
+
+A version of "ls" that provides a "-M" option to display
+Smack labels on long listing is available.
+
+A hacked version of sshd that allows network logins by users
+with specific Smack labels is available. This version does
+not work for scp. You must set the /etc/ssh/sshd_config
+line:
+   UsePrivilegeSeparation no
+
+The format of /etc/smack/usr is:
+
+   username smack
+
+In keeping with the intent of Smack, configuration data is
+minimal and not strictly required. The most important
+configuration step is mounting the smackfs pseudo filesystem.
+
+Add this line to /etc/fstab:
+
+    smackfs /smack smackfs smackfsdef=* 0 0
+
+and create the /smack directory for mounting.
+
+Smack uses extended attributes (xattrs) to store file labels.
+The command to set a Smack label on a file is:
+
+    # attr -S -s SMACK64 -V "value" path
+
+NOTE: Smack labels are limited to 23 characters. The attr command
+      does not enforce this restriction and can be used to set
+      invalid Smack labels on files.
+
+If you don't do anything special all users will get the floor ("_")
+label when they log in. If you do want to log in via the hacked ssh
+at other labels use the attr command to set the smack value on the
+home directory and it's contents.
+
+You can add access rules in /etc/smack/accesses. They take the form:
+
+    subjectlabel objectlabel access
+
+access is a combination of the letters rwxa which specify the
+kind of access permitted a subject with subjectlabel on an
+object with objectlabel. If there is no rule no access is allowed.
+
+A process can see the smack label it is running with by
+reading /proc/self/attr/current. A privileged process can
+set the process smack by writing there.
+
+Look for additional programs on http://schaufler-ca.com
+
+From the Smack Whitepaper:
+
+The Simplified Mandatory Access Control Kernel
+
+Casey Schaufler
+casey@schaufler-ca.com
+
+Mandatory Access Control
+
+Computer systems employ a variety of schemes to constrain how information is
+shared among the people and services using the machine. Some of these schemes
+allow the program or user to decide what other programs or users are allowed
+access to pieces of data. These schemes are called discretionary access
+control mechanisms because the access control is specified at the discretion
+of the user. Other schemes do not leave the decision regarding what a user or
+program can access up to users or programs. These schemes are called mandatory
+access control mechanisms because you don't have a choice regarding the users
+or programs that have access to pieces of data.
+
+Bell & LaPadula
+
+From the middle of the 1980's until the turn of the century Mandatory Access
+Control (MAC) was very closely associated with the Bell & LaPadula security
+model, a mathematical description of the United States Department of Defense
+policy for marking paper documents. MAC in this form enjoyed a following
+within the Capital Beltway and Scandinavian supercomputer centers but was
+often sited as failing to address general needs.
+
+Domain Type Enforcement
+
+Around the turn of the century Domain Type Enforcement (DTE) became popular.
+This scheme organizes users, programs, and data into domains that are
+protected from each other. This scheme has been widely deployed as a component
+of popular Linux distributions. The administrative overhead required to
+maintain this scheme and the detailed understanding of the whole system
+necessary to provide a secure domain mapping leads to the scheme being
+disabled or used in limited ways in the majority of cases.
+
+Smack
+
+Smack is a Mandatory Access Control mechanism designed to provide useful MAC
+while avoiding the pitfalls of its predecessors. The limitations of Bell &
+LaPadula are addressed by providing a scheme whereby access can be controlled
+according to the requirements of the system and its purpose rather than those
+imposed by an arcane government policy. The complexity of Domain Type
+Enforcement and avoided by defining access controls in terms of the access
+modes already in use.
+
+Smack Terminology
+
+The jargon used to talk about Smack will be familiar to those who have dealt
+with other MAC systems and shouldn't be too difficult for the uninitiated to
+pick up. There are four terms that are used in a specific way and that are
+especially important:
+
+       Subject: A subject is an active entity on the computer system.
+       On Smack a subject is a task, which is in turn the basic unit
+       of execution.
+
+       Object: An object is a passive entity on the computer system.
+       On Smack files of all types, IPC, and tasks can be objects.
+
+       Access: Any attempt by a subject to put information into or get
+       information from an object is an access.
+
+       Label: Data that identifies the Mandatory Access Control
+       characteristics of a subject or an object.
+
+These definitions are consistent with the traditional use in the security
+community. There are also some terms from Linux that are likely to crop up:
+
+       Capability: A task that possesses a capability has permission to
+       violate an aspect of the system security policy, as identified by
+       the specific capability. A task that possesses one or more
+       capabilities is a privileged task, whereas a task with no
+       capabilities is an unprivileged task.
+
+       Privilege: A task that is allowed to violate the system security
+       policy is said to have privilege. As of this writing a task can
+       have privilege either by possessing capabilities or by having an
+       effective user of root.
+
+Smack Basics
+
+Smack is an extension to a Linux system. It enforces additional restrictions
+on what subjects can access which objects, based on the labels attached to
+each of the subject and the object.
+
+Labels
+
+Smack labels are ASCII character strings, one to twenty-three characters in
+length. Single character labels using special characters, that being anything
+other than a letter or digit, are reserved for use by the Smack development
+team. Smack labels are unstructured, case sensitive, and the only operation
+ever performed on them is comparison for equality. Smack labels cannot
+contain unprintable characters or the "/" (slash) character.
+
+There are some predefined labels:
+
+       _ Pronounced "floor", a single underscore character.
+       ^ Pronounced "hat", a single circumflex character.
+       * Pronounced "star", a single asterisk character.
+       ? Pronounced "huh", a single question mark character.
+
+Every task on a Smack system is assigned a label. System tasks, such as
+init(8) and systems daemons, are run with the floor ("_") label. User tasks
+are assigned labels according to the specification found in the
+/etc/smack/user configuration file.
+
+Access Rules
+
+Smack uses the traditional access modes of Linux. These modes are read,
+execute, write, and occasionally append. There are a few cases where the
+access mode may not be obvious. These include:
+
+       Signals: A signal is a write operation from the subject task to
+       the object task.
+       Internet Domain IPC: Transmission of a packet is considered a
+       write operation from the source task to the destination task.
+
+Smack restricts access based on the label attached to a subject and the label
+attached to the object it is trying to access. The rules enforced are, in
+order:
+
+       1. Any access requested by a task labeled "*" is denied.
+       2. A read or execute access requested by a task labeled "^"
+          is permitted.
+       3. A read or execute access requested on an object labeled "_"
+          is permitted.
+       4. Any access requested on an object labeled "*" is permitted.
+       5. Any access requested by a task on an object with the same
+          label is permitted.
+       6. Any access requested that is explicitly defined in the loaded
+          rule set is permitted.
+       7. Any other access is denied.
+
+Smack Access Rules
+
+With the isolation provided by Smack access separation is simple. There are
+many interesting cases where limited access by subjects to objects with
+different labels is desired. One example is the familiar spy model of
+sensitivity, where a scientist working on a highly classified project would be
+able to read documents of lower classifications and anything she writes will
+be "born" highly classified. To accommodate such schemes Smack includes a
+mechanism for specifying rules allowing access between labels.
+
+Access Rule Format
+
+The format of an access rule is:
+
+       subject-label object-label access
+
+Where subject-label is the Smack label of the task, object-label is the Smack
+label of the thing being accessed, and access is a string specifying the sort
+of access allowed. The Smack labels are limited to 23 characters. The access
+specification is searched for letters that describe access modes:
+
+       a: indicates that append access should be granted.
+       r: indicates that read access should be granted.
+       w: indicates that write access should be granted.
+       x: indicates that execute access should be granted.
+
+Uppercase values for the specification letters are allowed as well.
+Access mode specifications can be in any order. Examples of acceptable rules
+are:
+
+       TopSecret Secret  rx
+       Secret    Unclass R
+       Manager   Game    x
+       User      HR      w
+       New       Old     rRrRr
+       Closed    Off     -
+
+Examples of unacceptable rules are:
+
+       Top Secret Secret     rx
+       Ace        Ace        r
+       Odd        spells     waxbeans
+
+Spaces are not allowed in labels. Since a subject always has access to files
+with the same label specifying a rule for that case is pointless. Only
+valid letters (rwxaRWXA) and the dash ('-') character are allowed in
+access specifications. The dash is a placeholder, so "a-r" is the same
+as "ar". A lone dash is used to specify that no access should be allowed.
+
+Applying Access Rules
+
+The developers of Linux rarely define new sorts of things, usually importing
+schemes and concepts from other systems. Most often, the other systems are
+variants of Unix. Unix has many endearing properties, but consistency of
+access control models is not one of them. Smack strives to treat accesses as
+uniformly as is sensible while keeping with the spirit of the underlying
+mechanism.
+
+File system objects including files, directories, named pipes, symbolic links,
+and devices require access permissions that closely match those used by mode
+bit access. To open a file for reading read access is required on the file. To
+search a directory requires execute access. Creating a file with write access
+requires both read and write access on the containing directory. Deleting a
+file requires read and write access to the file and to the containing
+directory. It is possible that a user may be able to see that a file exists
+but not any of its attributes by the circumstance of having read access to the
+containing directory but not to the differently labeled file. This is an
+artifact of the file name being data in the directory, not a part of the file.
+
+IPC objects, message queues, semaphore sets, and memory segments exist in flat
+namespaces and access requests are only required to match the object in
+question.
+
+Process objects reflect tasks on the system and the Smack label used to access
+them is the same Smack label that the task would use for its own access
+attempts. Sending a signal via the kill() system call is a write operation
+from the signaler to the recipient. Debugging a process requires both reading
+and writing. Creating a new task is an internal operation that results in two
+tasks with identical Smack labels and requires no access checks.
+
+Sockets are data structures attached to processes and sending a packet from
+one process to another requires that the sender have write access to the
+receiver. The receiver is not required to have read access to the sender.
+
+Setting Access Rules
+
+The configuration file /etc/smack/accesses contains the rules to be set at
+system startup. The contents are written to the special file /smack/load.
+Rules can be written to /smack/load at any time and take effect immediately.
+For any pair of subject and object labels there can be only one rule, with the
+most recently specified overriding any earlier specification.
+
+The program smackload is provided to ensure data is formatted
+properly when written to /smack/load. This program reads lines
+of the form
+
+    subjectlabel objectlabel mode.
+
+Task Attribute
+
+The Smack label of a process can be read from /proc/<pid>/attr/current. A
+process can read its own Smack label from /proc/self/attr/current. A
+privileged process can change its own Smack label by writing to
+/proc/self/attr/current but not the label of another process.
+
+File Attribute
+
+The Smack label of a filesystem object is stored as an extended attribute
+named SMACK64 on the file. This attribute is in the security namespace. It can
+only be changed by a process with privilege.
+
+Privilege
+
+A process with CAP_MAC_OVERRIDE is privileged.
+
+Smack Networking
+
+As mentioned before, Smack enforces access control on network protocol
+transmissions. Every packet sent by a Smack process is tagged with its Smack
+label. This is done by adding a CIPSO tag to the header of the IP packet. Each
+packet received is expected to have a CIPSO tag that identifies the label and
+if it lacks such a tag the network ambient label is assumed. Before the packet
+is delivered a check is made to determine that a subject with the label on the
+packet has write access to the receiving process and if that is not the case
+the packet is dropped.
+
+CIPSO Configuration
+
+It is normally unnecessary to specify the CIPSO configuration. The default
+values used by the system handle all internal cases. Smack will compose CIPSO
+label values to match the Smack labels being used without administrative
+intervention. Unlabeled packets that come into the system will be given the
+ambient label.
+
+Smack requires configuration in the case where packets from a system that is
+not smack that speaks CIPSO may be encountered. Usually this will be a Trusted
+Solaris system, but there are other, less widely deployed systems out there.
+CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level,
+and a category set with each packet. The DOI is intended to identify a group
+of systems that use compatible labeling schemes, and the DOI specified on the
+smack system must match that of the remote system or packets will be
+discarded. The DOI is 3 by default. The value can be read from /smack/doi and
+can be changed by writing to /smack/doi.
+
+The label and category set are mapped to a Smack label as defined in
+/etc/smack/cipso.
+
+A Smack/CIPSO mapping has the form:
+
+       smack level [category [category]*]
+
+Smack does not expect the level or category sets to be related in any
+particular way and does not assume or assign accesses based on them. Some
+examples of mappings:
+
+       TopSecret 7
+       TS:A,B    7 1 2
+       SecBDE    5 2 4 6
+       RAFTERS   7 12 26
+
+The ":" and "," characters are permitted in a Smack label but have no special
+meaning.
+
+The mapping of Smack labels to CIPSO values is defined by writing to
+/smack/cipso. Again, the format of data written to this special file
+is highly restrictive, so the program smackcipso is provided to
+ensure the writes are done properly. This program takes mappings
+on the standard input and sends them to /smack/cipso properly.
+
+In addition to explicit mappings Smack supports direct CIPSO mappings. One
+CIPSO level is used to indicate that the category set passed in the packet is
+in fact an encoding of the Smack label. The level used is 250 by default. The
+value can be read from /smack/direct and changed by writing to /smack/direct.
+
+Socket Attributes
+
+There are two attributes that are associated with sockets. These attributes
+can only be set by privileged tasks, but any task can read them for their own
+sockets.
+
+       SMACK64IPIN: The Smack label of the task object. A privileged
+       program that will enforce policy may set this to the star label.
+
+       SMACK64IPOUT: The Smack label transmitted with outgoing packets.
+       A privileged program may set this to match the label of another
+       task with which it hopes to communicate.
+
+Writing Applications for Smack
+
+There are three sorts of applications that will run on a Smack system. How an
+application interacts with Smack will determine what it will have to do to
+work properly under Smack.
+
+Smack Ignorant Applications
+
+By far the majority of applications have no reason whatever to care about the
+unique properties of Smack. Since invoking a program has no impact on the
+Smack label associated with the process the only concern likely to arise is
+whether the process has execute access to the program.
+
+Smack Relevant Applications
+
+Some programs can be improved by teaching them about Smack, but do not make
+any security decisions themselves. The utility ls(1) is one example of such a
+program.
+
+Smack Enforcing Applications
+
+These are special programs that not only know about Smack, but participate in
+the enforcement of system policy. In most cases these are the programs that
+set up user sessions. There are also network services that provide information
+to processes running with various labels.
+
+File System Interfaces
+
+Smack maintains labels on file system objects using extended attributes. The
+Smack label of a file, directory, or other file system object can be obtained
+using getxattr(2).
+
+       len = getxattr("/", "security.SMACK64", value, sizeof (value));
+
+will put the Smack label of the root directory into value. A privileged
+process can set the Smack label of a file system object with setxattr(2).
+
+       len = strlen("Rubble");
+       rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0);
+
+will set the Smack label of /foo to "Rubble" if the program has appropriate
+privilege.
+
+Socket Interfaces
+
+The socket attributes can be read using fgetxattr(2).
+
+A privileged process can set the Smack label of outgoing packets with
+fsetxattr(2).
+
+       len = strlen("Rubble");
+       rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0);
+
+will set the Smack label "Rubble" on packets going out from the socket if the
+program has appropriate privilege.
+
+       rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0);
+
+will set the Smack label "*" as the object label against which incoming
+packets will be checked if the program has appropriate privilege.
+
+Administration
+
+Smack supports some mount options:
+
+       smackfsdef=label: specifies the label to give files that lack
+       the Smack label extended attribute.
+
+       smackfsroot=label: specifies the label to assign the root of the
+       file system if it lacks the Smack extended attribute.
+
+       smackfshat=label: specifies a label that must have read access to
+       all labels set on the filesystem. Not yet enforced.
+
+       smackfsfloor=label: specifies a label to which all labels set on the
+       filesystem must have read access. Not yet enforced.
+
+These mount options apply to all file system types.
+
index 681e2b36195c98ea5271b76383b3a574b190b04f..08a1ed1cb5d84192d4b1e3e0eec3cf058dfded73 100644 (file)
@@ -220,20 +220,8 @@ decreasing the likelihood of your MIME-attached change being accepted.
 Exception:  If your mailer is mangling patches then someone may ask
 you to re-send them using MIME.
 
-
-WARNING: Some mailers like Mozilla send your messages with
----- message header ----
-Content-Type: text/plain; charset=us-ascii; format=flowed
----- message header ----
-The problem is that "format=flowed" makes some of the mailers
-on receiving side to replace TABs with spaces and do similar
-changes. Thus the patches from you can look corrupted.
-
-To fix this just make your mozilla defaults/pref/mailnews.js file to look like:
-pref("mailnews.send_plaintext_flowed", false); // RFC 2646=======
-pref("mailnews.display.disable_format_flowed_support", true);
-
-
+See Documentation/email-clients.txt for hints about configuring
+your e-mail client so that it sends your patches untouched.
 
 8) E-mail size.
 
index c0d8853672dc9e533e4be07c573c5e2918331038..2e953e228f4d7295d4f847cf531fb1719cc64a35 100644 (file)
@@ -32,7 +32,7 @@ BARRIER IO before the access to the SMC chip because the AEN latch
 only needs occurs after the SMC IO write cycle.  The routines that
 implement this work-around make an additional concession which is to
 disable interrupts during the IO sequence.  Other hardware devices
-(the LogicPD CPLD) have registers in the same the physical memory
+(the LogicPD CPLD) have registers in the same physical memory
 region as the SMC chip.  An interrupt might allow an access to one of
 those registers while SMC IO is being performed.
 
index 24029f65fc94a0096a2116b1c893c6258cb843a7..172ad4aec493cbe9a9db3b6193a43d8794b231e6 100644 (file)
@@ -16,3 +16,7 @@ echo 'echo "$@" >> /tmp/modprobe.log' >> /tmp/modprobe
 echo 'exec /sbin/modprobe "$@"' >> /tmp/modprobe
 chmod a+x /tmp/modprobe
 echo /tmp/modprobe > /proc/sys/kernel/modprobe
+
+Note that the above applies only when the *kernel* is requesting
+that the module be loaded -- it won't have any effect if that module
+is being loaded explicitly using "modprobe" from userspace.
index 2a97320ee17f1d1b1c5a9b1efc138bbea4631f0e..83009fdcbbc8ee2de932cb4713dbb44734eab4b0 100644 (file)
@@ -122,15 +122,15 @@ None the less, there are some APIs to support such legacy drivers.  Avoid
 using these calls except with such hotplug-deficient drivers.
 
        struct platform_device *platform_device_alloc(
-                       char *name, unsigned id);
+                       const char *name, int id);
 
 You can use platform_device_alloc() to dynamically allocate a device, which
 you will then initialize with resources and platform_device_register().
 A better solution is usually:
 
        struct platform_device *platform_device_register_simple(
-                       char *name, unsigned id,
-                       struct resource *res, unsigned nres);
+                       const char *name, int id,
+                       struct resource *res, unsigned int nres);
 
 You can use platform_device_register_simple() as a one-step call to allocate
 and register a device.
index 63883a892120e125be75db301e1c49322c1c7a71..74832837025032dcd0f4ee21a665b3a59612b701 100644 (file)
@@ -7,10 +7,10 @@ IO. The following example may be a useful explanation of how one such setup
 works:
 
 - userspace app like Xfbdev mmaps framebuffer
-- deferred IO and driver sets up nopage and page_mkwrite handlers
+- deferred IO and driver sets up fault and page_mkwrite handlers
 - userspace app tries to write to mmaped vaddress
-- we get pagefault and reach nopage handler
-- nopage handler finds and returns physical page
+- we get pagefault and reach fault handler
+- fault handler finds and returns physical page
 - we get page_mkwrite where we add this page to a list
 - schedule a workqueue task to be run after a delay
 - app continues writing to that page with no additional cost. this is
index 181bff00516784e3b4bc0c8a7f2b94ed47b76e70..68ce1300a3609f9a5e0061cf61c0a5f3c05f80fe 100644 (file)
@@ -156,22 +156,6 @@ Who:       Arjan van de Ven <arjan@linux.intel.com>
 
 ---------------------------
 
-What:  USB driver API moves to EXPORT_SYMBOL_GPL
-When:  February 2008
-Files: include/linux/usb.h, drivers/usb/core/driver.c
-Why:   The USB subsystem has changed a lot over time, and it has been
-       possible to create userspace USB drivers using usbfs/libusb/gadgetfs
-       that operate as fast as the USB bus allows.  Because of this, the USB
-       subsystem will not be allowing closed source kernel drivers to
-       register with it, after this grace period is over.  If anyone needs
-       any help in converting their closed source drivers over to use the
-       userspace filesystems, please contact the
-       linux-usb-devel@lists.sourceforge.net mailing list, and the developers
-       there will be glad to help you out.
-Who:   Greg Kroah-Hartman <gregkh@suse.de>
-
----------------------------
-
 What:  vm_ops.nopage
 When:  Soon, provided in-kernel callers have been converted
 Why:   This interface is replaced by vm_ops.fault, but it has been around
@@ -224,13 +208,6 @@ Who:       Randy Dunlap <randy.dunlap@oracle.com>
 
 ---------------------------
 
-What:  drivers depending on OSS_OBSOLETE
-When:  options in 2.6.23, code in 2.6.25
-Why:   obsolete OSS drivers
-Who:   Adrian Bunk <bunk@stusta.de>
-
----------------------------
-
 What: libata spindown skipping and warning
 When: Dec 2008
 Why:  Some halt(8) implementations synchronize caches for and spin
index d1b98257d00063db10075d54180b7497bcc99d41..44c97e6accb2655faed63b52e4bc63848571a7ab 100644 (file)
@@ -377,7 +377,7 @@ more explicit to have a method whereby userspace sees this divergence.
 Rather than have a group where some items behave differently than
 others, configfs provides a method whereby one or many subgroups are
 automatically created inside the parent at its creation.  Thus,
-mkdir("parent) results in "parent", "parent/subgroup1", up through
+mkdir("parent") results in "parent", "parent/subgroup1", up through
 "parent/subgroupN".  Items of type 1 can now be created in
 "parent/subgroup1", and items of type N can be created in
 "parent/subgroupN".
index dac45c92d872b977312372210243ffa318ad08cb..0f33c77bc14b2695f6ebb1d70c464bee674c7c33 100644 (file)
@@ -1,6 +1,6 @@
 Changes since 2.5.0:
 
---- 
+---
 [recommended]
 
 New helpers: sb_bread(), sb_getblk(), sb_find_get_block(), set_bh(),
@@ -10,7 +10,7 @@ Use them.
 
 (sb_find_get_block() replaces 2.4's get_hash_table())
 
---- 
+---
 [recommended]
 
 New methods: ->alloc_inode() and ->destroy_inode().
@@ -28,7 +28,7 @@ Declare
 
 Use FOO_I(inode) instead of &inode->u.foo_inode_i;
 
-Add foo_alloc_inode() and foo_destory_inode() - the former should allocate
+Add foo_alloc_inode() and foo_destroy_inode() - the former should allocate
 foo_inode_info and return the address of ->vfs_inode, the latter should free
 FOO_I(inode) (see in-tree filesystems for examples).
 
index 194c8f35132065496048f8ae0bd80b688240d96c..5681e2fa1496167e6f876b6dab39e9605597a117 100644 (file)
@@ -216,6 +216,7 @@ Table 1-3: Contents of the stat files (as of 2.6.22-rc3)
   priority      priority level
   nice          nice level
   num_threads   number of threads
+  it_real_value        (obsolete, always 0)
   start_time    time the process started after system boot
   vsize         virtual memory size
   rss           resident set memory size
@@ -1028,6 +1029,14 @@ nr_inodes
 Denotes the  number  of  inodes the system has allocated. This number will
 grow and shrink dynamically.
 
+nr_open
+-------
+
+Denotes the maximum number of file-handles a process can
+allocate. Default value is 1024*1024 (1048576) which should be
+enough for most machines. Actual limit depends on RLIMIT_NOFILE
+resource limit.
+
 nr_free_inodes
 --------------
 
@@ -1314,13 +1323,28 @@ for writeout by the pdflush daemons.  It is expressed in 100'ths of a second.
 Data which has been dirty in-memory for longer than this interval will be
 written out next time a pdflush daemon wakes up.
 
+highmem_is_dirtyable
+--------------------
+
+Only present if CONFIG_HIGHMEM is set.
+
+This defaults to 0 (false), meaning that the ratios set above are calculated
+as a percentage of lowmem only.  This protects against excessive scanning
+in page reclaim, swapping and general VM distress.
+
+Setting this to 1 can be useful on 32 bit machines where you want to make
+random changes within an MMAPed file that is larger than your available
+lowmem without causing large quantities of random IO.  Is is safe if the
+behavior of all programs running on the machine is known and memory will
+not be otherwise stressed.
+
 legacy_va_layout
 ----------------
 
 If non-zero, this sysctl disables the new 32-bit mmap mmap layout - the kernel
 will use the legacy (2.4) layout for all processes.
 
-lower_zone_protection
+lowmem_reserve_ratio
 ---------------------
 
 For some specialised workloads on highmem machines it is dangerous for
@@ -1340,25 +1364,71 @@ captured into pinned user memory.
 mechanism will also defend that region from allocations which could use
 highmem or lowmem).
 
-The `lower_zone_protection' tunable determines how aggressive the kernel is
-in defending these lower zones.  The default value is zero - no
-protection at all.
+The `lowmem_reserve_ratio' tunable determines how aggressive the kernel is
+in defending these lower zones.
 
 If you have a machine which uses highmem or ISA DMA and your
 applications are using mlock(), or if you are running with no swap then
-you probably should increase the lower_zone_protection setting.
-
-The units of this tunable are fairly vague.  It is approximately equal
-to "megabytes," so setting lower_zone_protection=100 will protect around 100
-megabytes of the lowmem zone from user allocations.  It will also make
-those 100 megabytes unavailable for use by applications and by
-pagecache, so there is a cost.
-
-The effects of this tunable may be observed by monitoring
-/proc/meminfo:LowFree.  Write a single huge file and observe the point
-at which LowFree ceases to fall.
-
-A reasonable value for lower_zone_protection is 100.
+you probably should change the lowmem_reserve_ratio setting.
+
+The lowmem_reserve_ratio is an array. You can see them by reading this file.
+-
+% cat /proc/sys/vm/lowmem_reserve_ratio
+256     256     32
+-
+Note: # of this elements is one fewer than number of zones. Because the highest
+      zone's value is not necessary for following calculation.
+
+But, these values are not used directly. The kernel calculates # of protection
+pages for each zones from them. These are shown as array of protection pages
+in /proc/zoneinfo like followings. (This is an example of x86-64 box).
+Each zone has an array of protection pages like this.
+
+-
+Node 0, zone      DMA
+  pages free     1355
+        min      3
+        low      3
+        high     4
+       :
+       :
+    numa_other   0
+        protection: (0, 2004, 2004, 2004)
+       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+  pagesets
+    cpu: 0 pcp: 0
+        :
+-
+These protections are added to score to judge whether this zone should be used
+for page allocation or should be reclaimed.
+
+In this example, if normal pages (index=2) are required to this DMA zone and
+pages_high is used for watermark, the kernel judges this zone should not be
+used because pages_free(1355) is smaller than watermark + protection[2]
+(4 + 2004 = 2008). If this protection value is 0, this zone would be used for
+normal page requirement. If requirement is DMA zone(index=0), protection[0]
+(=0) is used.
+
+zone[i]'s protection[j] is calculated by following exprssion.
+
+(i < j):
+  zone[i]->protection[j]
+  = (total sums of present_pages from zone[i+1] to zone[j] on the node)
+    / lowmem_reserve_ratio[i];
+(i = j):
+   (should not be protected. = 0;
+(i > j):
+   (not necessary, but looks 0)
+
+The default values of lowmem_reserve_ratio[i] are
+    256 (if zone[i] means DMA or DMA32 zone)
+    32  (others).
+As above expression, they are reciprocal number of ratio.
+256 means 1/256. # of protection pages becomes about "0.39%" of total present
+pages of higher zones on the node.
+
+If you would like to protect more pages, smaller values are effective.
+The minimum value is 1 (1/1 -> 100%).
 
 page-cluster
 ------------
index 339c6a4f220ec036a7bc681d512ef65982dcdcef..7be232b44ee4602f74dc0b75ed66d150c23a6aaf 100644 (file)
@@ -118,7 +118,7 @@ All this differs from the old initrd in several ways:
     with the new root (cd /newmount; mount --move . /; chroot .), attach
     stdin/stdout/stderr to the new /dev/console, and exec the new init.
 
-    Since this is a remarkably persnickity process (and involves deleting
+    Since this is a remarkably persnickety process (and involves deleting
     commands before you can run them), the klibc package introduced a helper
     program (utils/run_init.c) to do all this for you.  Most other packages
     (such as busybox) have named this command "switch_root".
index 18d23f9a18c74663e1a7cbcc07232e7879945c5e..094f2d2f38b1a5571283ee745aa494c12b12808c 100644 (file)
@@ -140,7 +140,7 @@ close()     decrements the channel buffer's refcount.  When the refcount
 In order for a user application to make use of relay files, the
 host filesystem must be mounted.  For example,
 
-       mount -t debugfs debugfs /debug
+       mount -t debugfs debugfs /sys/kernel/debug
 
 NOTE:   the host filesystem doesn't need to be mounted for kernel
        clients to create or use channels - it only needs to be
similarity index 98%
rename from Documentation/fujitsu/frv/booting.txt
rename to Documentation/frv/booting.txt
index 4e229056ef2261b79ac3ab40ef59820da16b0cf9..ace200b7c2140145c457ee86ce7f02b532c85e87 100644 (file)
@@ -177,5 +177,5 @@ separated by spaces:
   (*) vdc=...
 
       This option configures the MB93493 companion chip visual display
-      driver. Please see Documentation/fujitsu/mb93493/vdc.txt for more
+      driver. Please see Documentation/frv/mb93493/vdc.txt for more
       information.
index 6bc2ba215df9a3eb4b41ff6f987e5fa294e47250..8da724e2a0ff795d450e8b0b7b61118d7bf604a6 100644 (file)
@@ -32,7 +32,7 @@ The exact capabilities of GPIOs vary between systems.  Common options:
   - Input values are likewise readable (1, 0).  Some chips support readback
     of pins configured as "output", which is very useful in such "wire-OR"
     cases (to support bidirectional signaling).  GPIO controllers may have
-    input de-glitch logic, sometimes with software controls.
+    input de-glitch/debounce logic, sometimes with software controls.
 
   - Inputs can often be used as IRQ signals, often edge triggered but
     sometimes level triggered.  Such IRQs may be configurable as system
@@ -60,10 +60,13 @@ used on a board that's wired differently.  Only least-common-denominator
 functionality can be very portable.  Other features are platform-specific,
 and that can be critical for glue logic.
 
-Plus, this doesn't define an implementation framework, just an interface.
+Plus, this doesn't require any implementation framework, just an interface.
 One platform might implement it as simple inline functions accessing chip
 registers; another might implement it by delegating through abstractions
-used for several very different kinds of GPIO controller.
+used for several very different kinds of GPIO controller.  (There is some
+optional code supporting such an implementation strategy, described later
+in this document, but drivers acting as clients to the GPIO interface must
+not care how it's implemented.)
 
 That said, if the convention is supported on their platform, drivers should
 use it when possible.  Platforms should declare GENERIC_GPIO support in
@@ -121,6 +124,11 @@ before tasking is enabled, as part of early board setup.
 For output GPIOs, the value provided becomes the initial output value.
 This helps avoid signal glitching during system startup.
 
+For compatibility with legacy interfaces to GPIOs, setting the direction
+of a GPIO implicitly requests that GPIO (see below) if it has not been
+requested already.  That compatibility may be removed in the future;
+explicitly requesting GPIOs is strongly preferred.
+
 Setting the direction can fail if the GPIO number is invalid, or when
 that particular GPIO can't be used in that mode.  It's generally a bad
 idea to rely on boot firmware to have set the direction correctly, since
@@ -133,6 +141,7 @@ Spinlock-Safe GPIO access
 -------------------------
 Most GPIO controllers can be accessed with memory read/write instructions.
 That doesn't need to sleep, and can safely be done from inside IRQ handlers.
+(That includes hardirq contexts on RT kernels.)
 
 Use these calls to access such GPIOs:
 
@@ -145,7 +154,7 @@ Use these calls to access such GPIOs:
 The values are boolean, zero for low, nonzero for high.  When reading the
 value of an output pin, the value returned should be what's seen on the
 pin ... that won't always match the specified output value, because of
-issues including wire-OR and output latencies.
+issues including open-drain signaling and output latencies.
 
 The get/set calls have no error returns because "invalid GPIO" should have
 been reported earlier from gpio_direction_*().  However, note that not all
@@ -170,7 +179,8 @@ get to the head of a queue to transmit a command and get its response.
 This requires sleeping, which can't be done from inside IRQ handlers.
 
 Platforms that support this type of GPIO distinguish them from other GPIOs
-by returning nonzero from this call:
+by returning nonzero from this call (which requires a valid GPIO number,
+either explicitly or implicitly requested):
 
        int gpio_cansleep(unsigned gpio);
 
@@ -209,8 +219,11 @@ before tasking is enabled, as part of early board setup.
 These calls serve two basic purposes.  One is marking the signals which
 are actually in use as GPIOs, for better diagnostics; systems may have
 several hundred potential GPIOs, but often only a dozen are used on any
-given board.  Another is to catch conflicts between drivers, reporting
-errors when drivers wrongly think they have exclusive use of that signal.
+given board.  Another is to catch conflicts, identifying errors when
+(a) two or more drivers wrongly think they have exclusive use of that
+signal, or (b) something wrongly believes it's safe to remove drivers
+needed to manage a signal that's in active use.  That is, requesting a
+GPIO can serve as a kind of lock.
 
 These two calls are optional because not not all current Linux platforms
 offer such functionality in their GPIO support; a valid implementation
@@ -223,6 +236,9 @@ Note that requesting a GPIO does NOT cause it to be configured in any
 way; it just marks that GPIO as in use.  Separate code must handle any
 pin setup (e.g. controlling which pin the GPIO uses, pullup/pulldown).
 
+Also note that it's your responsibility to have stopped using a GPIO
+before you free it.
+
 
 GPIOs mapped to IRQs
 --------------------
@@ -238,7 +254,7 @@ map between them using calls like:
 
 Those return either the corresponding number in the other namespace, or
 else a negative errno code if the mapping can't be done.  (For example,
-some GPIOs can't used as IRQs.)  It is an unchecked error to use a GPIO
+some GPIOs can't be used as IRQs.)  It is an unchecked error to use a GPIO
 number that wasn't set up as an input using gpio_direction_input(), or
 to use an IRQ number that didn't originally come from gpio_to_irq().
 
@@ -299,17 +315,110 @@ Related to multiplexing is configuration and enabling of the pullups or
 pulldowns integrated on some platforms.  Not all platforms support them,
 or support them in the same way; and any given board might use external
 pullups (or pulldowns) so that the on-chip ones should not be used.
+(When a circuit needs 5 kOhm, on-chip 100 kOhm resistors won't do.)
 
 There are other system-specific mechanisms that are not specified here,
 like the aforementioned options for input de-glitching and wire-OR output.
 Hardware may support reading or writing GPIOs in gangs, but that's usually
 configuration dependent:  for GPIOs sharing the same bank.  (GPIOs are
 commonly grouped in banks of 16 or 32, with a given SOC having several such
-banks.)  Some systems can trigger IRQs from output GPIOs.  Code relying on
-such mechanisms will necessarily be nonportable.
+banks.)  Some systems can trigger IRQs from output GPIOs, or read values
+from pins not managed as GPIOs.  Code relying on such mechanisms will
+necessarily be nonportable.
 
-Dynamic definition of GPIOs is not currently supported; for example, as
+Dynamic definition of GPIOs is not currently standard; for example, as
 a side effect of configuring an add-on board with some GPIO expanders.
 
 These calls are purely for kernel space, but a userspace API could be built
-on top of it.
+on top of them.
+
+
+GPIO implementor's framework (OPTIONAL)
+=======================================
+As noted earlier, there is an optional implementation framework making it
+easier for platforms to support different kinds of GPIO controller using
+the same programming interface.
+
+As a debugging aid, if debugfs is available a /sys/kernel/debug/gpio file
+will be found there.  That will list all the controllers registered through
+this framework, and the state of the GPIOs currently in use.
+
+
+Controller Drivers: gpio_chip
+-----------------------------
+In this framework each GPIO controller is packaged as a "struct gpio_chip"
+with information common to each controller of that type:
+
+ - methods to establish GPIO direction
+ - methods used to access GPIO values
+ - flag saying whether calls to its methods may sleep
+ - optional debugfs dump method (showing extra state like pullup config)
+ - label for diagnostics
+
+There is also per-instance data, which may come from device.platform_data:
+the number of its first GPIO, and how many GPIOs it exposes.
+
+The code implementing a gpio_chip should support multiple instances of the
+controller, possibly using the driver model.  That code will configure each
+gpio_chip and issue gpiochip_add().  Removing a GPIO controller should be
+rare; use gpiochip_remove() when it is unavoidable.
+
+Most often a gpio_chip is part of an instance-specific structure with state
+not exposed by the GPIO interfaces, such as addressing, power management,
+and more.  Chips such as codecs will have complex non-GPIO state,
+
+Any debugfs dump method should normally ignore signals which haven't been
+requested as GPIOs.  They can use gpiochip_is_requested(), which returns
+either NULL or the label associated with that GPIO when it was requested.
+
+
+Platform Support
+----------------
+To support this framework, a platform's Kconfig will "select HAVE_GPIO_LIB"
+and arrange that its <asm/gpio.h> includes <asm-generic/gpio.h> and defines
+three functions: gpio_get_value(), gpio_set_value(), and gpio_cansleep().
+They may also want to provide a custom value for ARCH_NR_GPIOS.
+
+Trivial implementations of those functions can directly use framework
+code, which always dispatches through the gpio_chip:
+
+  #define gpio_get_value       __gpio_get_value
+  #define gpio_set_value       __gpio_set_value
+  #define gpio_cansleep                __gpio_cansleep
+
+Fancier implementations could instead define those as inline functions with
+logic optimizing access to specific SOC-based GPIOs.  For example, if the
+referenced GPIO is the constant "12", getting or setting its value could
+cost as little as two or three instructions, never sleeping.  When such an
+optimization is not possible those calls must delegate to the framework
+code, costing at least a few dozen instructions.  For bitbanged I/O, such
+instruction savings can be significant.
+
+For SOCs, platform-specific code defines and registers gpio_chip instances
+for each bank of on-chip GPIOs.  Those GPIOs should be numbered/labeled to
+match chip vendor documentation, and directly match board schematics.  They
+may well start at zero and go up to a platform-specific limit.  Such GPIOs
+are normally integrated into platform initialization to make them always be
+available, from arch_initcall() or earlier; they can often serve as IRQs.
+
+
+Board Support
+-------------
+For external GPIO controllers -- such as I2C or SPI expanders, ASICs, multi
+function devices, FPGAs or CPLDs -- most often board-specific code handles
+registering controller devices and ensures that their drivers know what GPIO
+numbers to use with gpiochip_add().  Their numbers often start right after
+platform-specific GPIOs.
+
+For example, board setup code could create structures identifying the range
+of GPIOs that chip will expose, and passes them to each GPIO expander chip
+using platform_data.  Then the chip driver's probe() routine could pass that
+data to gpiochip_add().
+
+Initialization order can be important.  For example, when a device relies on
+an I2C-based GPIO, its probe() routine should only be called after that GPIO
+becomes available.  That may mean the device should not be registered until
+calls for that GPIO can work.  One way to address such dependencies is for
+such gpio_chip controllers to provide setup() and teardown() callbacks to
+board specific code; those board specific callbacks would register devices
+once all the necessary resources are available.
index c4fce6a135374377bcd5d6aa2277c25f5811914f..1d81c530c4a584f15e25ad85e31e57693acfff6f 100644 (file)
@@ -1,6 +1,9 @@
 Kernel driver pca9539
 =====================
 
+NOTE: this driver is deprecated and will be dropped soon, use
+drivers/gpio/pca9539.c instead.
+
 Supported chips:
   * Philips PCA9539
     Prefix: 'pca9539'
index 773a814d409361767da369070d2d7e5267536c16..d23610fb2ff9e0560580bf4332bc81ea0a249326 100644 (file)
@@ -16,6 +16,7 @@
 #include <fcntl.h>
 #include <fnmatch.h>
 #include <string.h>
+#include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -65,7 +66,7 @@ int scan_tree(char *path, char *file, off_t offset, size_t length, int touch)
 {
        struct dirent **namelist;
        char *name, *path2;
-       int i, n, r, rc, result = 0;
+       int i, n, r, rc = 0, result = 0;
        struct stat buf;
 
        n = scandir(path, &namelist, 0, alphasort);
@@ -113,7 +114,7 @@ skip:
                free(namelist[i]);
        }
        free(namelist);
-       return rc;
+       return result;
 }
 
 char buf[1024];
@@ -149,7 +150,7 @@ int scan_rom(char *path, char *file)
 {
        struct dirent **namelist;
        char *name, *path2;
-       int i, n, r, rc, result = 0;
+       int i, n, r, rc = 0, result = 0;
        struct stat buf;
 
        n = scandir(path, &namelist, 0, alphasort);
@@ -180,7 +181,7 @@ int scan_rom(char *path, char *file)
                         * important thing is that no MCA happened.
                         */
                        if (rc > 0)
-                               fprintf(stderr, "PASS: %s read %ld bytes\n", path2, rc);
+                               fprintf(stderr, "PASS: %s read %d bytes\n", path2, rc);
                        else {
                                fprintf(stderr, "PASS: %s not readable\n", path2);
                                return rc;
@@ -201,10 +202,10 @@ skip:
                free(namelist[i]);
        }
        free(namelist);
-       return rc;
+       return result;
 }
 
-int main()
+int main(void)
 {
        int rc;
 
@@ -256,4 +257,6 @@ int main()
        scan_tree("/proc/bus/pci", "??.?", 0xA0000, 0x20000, 0);
        scan_tree("/proc/bus/pci", "??.?", 0xC0000, 0x40000, 1);
        scan_tree("/proc/bus/pci", "??.?", 0, 1024*1024, 0);
+
+       return rc;
 }
diff --git a/Documentation/ide/ChangeLog.ide-tape.1995-2002 b/Documentation/ide/ChangeLog.ide-tape.1995-2002
new file mode 100644 (file)
index 0000000..877fac8
--- /dev/null
@@ -0,0 +1,257 @@
+/*
+ * Ver 0.1   Nov  1 95   Pre-working code :-)
+ * Ver 0.2   Nov 23 95   A short backup (few megabytes) and restore procedure
+ *                        was successful ! (Using tar cvf ... on the block
+ *                        device interface).
+ *                       A longer backup resulted in major swapping, bad
+ *                        overall Linux performance and eventually failed as
+ *                        we received non serial read-ahead requests from the
+ *                        buffer cache.
+ * Ver 0.3   Nov 28 95   Long backups are now possible, thanks to the
+ *                        character device interface. Linux's responsiveness
+ *                        and performance doesn't seem to be much affected
+ *                        from the background backup procedure.
+ *                       Some general mtio.h magnetic tape operations are
+ *                        now supported by our character device. As a result,
+ *                        popular tape utilities are starting to work with
+ *                        ide tapes :-)
+ *                       The following configurations were tested:
+ *                       1. An IDE ATAPI TAPE shares the same interface
+ *                        and irq with an IDE ATAPI CDROM.
+ *                       2. An IDE ATAPI TAPE shares the same interface
+ *                        and irq with a normal IDE disk.
+ *                        Both configurations seemed to work just fine !
+ *                        However, to be on the safe side, it is meanwhile
+ *                        recommended to give the IDE TAPE its own interface
+ *                        and irq.
+ *                       The one thing which needs to be done here is to
+ *                        add a "request postpone" feature to ide.c,
+ *                        so that we won't have to wait for the tape to finish
+ *                        performing a long media access (DSC) request (such
+ *                        as a rewind) before we can access the other device
+ *                        on the same interface. This effect doesn't disturb
+ *                        normal operation most of the time because read/write
+ *                        requests are relatively fast, and once we are
+ *                        performing one tape r/w request, a lot of requests
+ *                        from the other device can be queued and ide.c will
+ *                       service all of them after this single tape request.
+ * Ver 1.0   Dec 11 95   Integrated into Linux 1.3.46 development tree.
+ *                       On each read / write request, we now ask the drive
+ *                        if we can transfer a constant number of bytes
+ *                        (a parameter of the drive) only to its buffers,
+ *                        without causing actual media access. If we can't,
+ *                        we just wait until we can by polling the DSC bit.
+ *                        This ensures that while we are not transferring
+ *                        more bytes than the constant referred to above, the
+ *                        interrupt latency will not become too high and
+ *                        we won't cause an interrupt timeout, as happened
+ *                        occasionally in the previous version.
+ *                       While polling for DSC, the current request is
+ *                        postponed and ide.c is free to handle requests from
+ *                        the other device. This is handled transparently to
+ *                        ide.c. The hwgroup locking method which was used
+ *                        in the previous version was removed.
+ *                       Use of new general features which are provided by
+ *                        ide.c for use with atapi devices.
+ *                        (Programming done by Mark Lord)
+ *                       Few potential bug fixes (Again, suggested by Mark)
+ *                       Single character device data transfers are now
+ *                        not limited in size, as they were before.
+ *                       We are asking the tape about its recommended
+ *                        transfer unit and send a larger data transfer
+ *                        as several transfers of the above size.
+ *                        For best results, use an integral number of this
+ *                        basic unit (which is shown during driver
+ *                        initialization). I will soon add an ioctl to get
+ *                        this important parameter.
+ *                       Our data transfer buffer is allocated on startup,
+ *                        rather than before each data transfer. This should
+ *                        ensure that we will indeed have a data buffer.
+ * Ver 1.1   Dec 14 95   Fixed random problems which occurred when the tape
+ *                        shared an interface with another device.
+ *                        (poll_for_dsc was a complete mess).
+ *                       Removed some old (non-active) code which had
+ *                        to do with supporting buffer cache originated
+ *                        requests.
+ *                       The block device interface can now be opened, so
+ *                        that general ide driver features like the unmask
+ *                        interrupts flag can be selected with an ioctl.
+ *                        This is the only use of the block device interface.
+ *                       New fast pipelined operation mode (currently only on
+ *                        writes). When using the pipelined mode, the
+ *                        throughput can potentially reach the maximum
+ *                        tape supported throughput, regardless of the
+ *                        user backup program. On my tape drive, it sometimes
+ *                        boosted performance by a factor of 2. Pipelined
+ *                        mode is enabled by default, but since it has a few
+ *                        downfalls as well, you may want to disable it.
+ *                        A short explanation of the pipelined operation mode
+ *                        is available below.
+ * Ver 1.2   Jan  1 96   Eliminated pipelined mode race condition.
+ *                       Added pipeline read mode. As a result, restores
+ *                        are now as fast as backups.
+ *                       Optimized shared interface behavior. The new behavior
+ *                        typically results in better IDE bus efficiency and
+ *                        higher tape throughput.
+ *                       Pre-calculation of the expected read/write request
+ *                        service time, based on the tape's parameters. In
+ *                        the pipelined operation mode, this allows us to
+ *                        adjust our polling frequency to a much lower value,
+ *                        and thus to dramatically reduce our load on Linux,
+ *                        without any decrease in performance.
+ *                       Implemented additional mtio.h operations.
+ *                       The recommended user block size is returned by
+ *                        the MTIOCGET ioctl.
+ *                       Additional minor changes.
+ * Ver 1.3   Feb  9 96   Fixed pipelined read mode bug which prevented the
+ *                        use of some block sizes during a restore procedure.
+ *                       The character device interface will now present a
+ *                        continuous view of the media - any mix of block sizes
+ *                        during a backup/restore procedure is supported. The
+ *                        driver will buffer the requests internally and
+ *                        convert them to the tape's recommended transfer
+ *                        unit, making performance almost independent of the
+ *                        chosen user block size.
+ *                       Some improvements in error recovery.
+ *                       By cooperating with ide-dma.c, bus mastering DMA can
+ *                        now sometimes be used with IDE tape drives as well.
+ *                        Bus mastering DMA has the potential to dramatically
+ *                        reduce the CPU's overhead when accessing the device,
+ *                        and can be enabled by using hdparm -d1 on the tape's
+ *                        block device interface. For more info, read the
+ *                        comments in ide-dma.c.
+ * Ver 1.4   Mar 13 96   Fixed serialize support.
+ * Ver 1.5   Apr 12 96   Fixed shared interface operation, broken in 1.3.85.
+ *                       Fixed pipelined read mode inefficiency.
+ *                       Fixed nasty null dereferencing bug.
+ * Ver 1.6   Aug 16 96   Fixed FPU usage in the driver.
+ *                       Fixed end of media bug.
+ * Ver 1.7   Sep 10 96   Minor changes for the CONNER CTT8000-A model.
+ * Ver 1.8   Sep 26 96   Attempt to find a better balance between good
+ *                        interactive response and high system throughput.
+ * Ver 1.9   Nov  5 96   Automatically cross encountered filemarks rather
+ *                        than requiring an explicit FSF command.
+ *                       Abort pending requests at end of media.
+ *                       MTTELL was sometimes returning incorrect results.
+ *                       Return the real block size in the MTIOCGET ioctl.
+ *                       Some error recovery bug fixes.
+ * Ver 1.10  Nov  5 96   Major reorganization.
+ *                       Reduced CPU overhead a bit by eliminating internal
+ *                        bounce buffers.
+ *                       Added module support.
+ *                       Added multiple tape drives support.
+ *                       Added partition support.
+ *                       Rewrote DSC handling.
+ *                       Some portability fixes.
+ *                       Removed ide-tape.h.
+ *                       Additional minor changes.
+ * Ver 1.11  Dec  2 96   Bug fix in previous DSC timeout handling.
+ *                       Use ide_stall_queue() for DSC overlap.
+ *                       Use the maximum speed rather than the current speed
+ *                        to compute the request service time.
+ * Ver 1.12  Dec  7 97   Fix random memory overwriting and/or last block data
+ *                        corruption, which could occur if the total number
+ *                        of bytes written to the tape was not an integral
+ *                        number of tape blocks.
+ *                       Add support for INTERRUPT DRQ devices.
+ * Ver 1.13  Jan  2 98   Add "speed == 0" work-around for HP COLORADO 5GB
+ * Ver 1.14  Dec 30 98   Partial fixes for the Sony/AIWA tape drives.
+ *                       Replace cli()/sti() with hwgroup spinlocks.
+ * Ver 1.15  Mar 25 99   Fix SMP race condition by replacing hwgroup
+ *                        spinlock with private per-tape spinlock.
+ * Ver 1.16  Sep  1 99   Add OnStream tape support.
+ *                       Abort read pipeline on EOD.
+ *                       Wait for the tape to become ready in case it returns
+ *                        "in the process of becoming ready" on open().
+ *                       Fix zero padding of the last written block in
+ *                        case the tape block size is larger than PAGE_SIZE.
+ *                       Decrease the default disconnection time to tn.
+ * Ver 1.16e Oct  3 99   Minor fixes.
+ * Ver 1.16e1 Oct 13 99  Patches by Arnold Niessen,
+ *                          niessen@iae.nl / arnold.niessen@philips.com
+ *                   GO-1)  Undefined code in idetape_read_position
+ *                             according to Gadi's email
+ *                   AJN-1) Minor fix asc == 11 should be asc == 0x11
+ *                               in idetape_issue_packet_command (did effect
+ *                               debugging output only)
+ *                   AJN-2) Added more debugging output, and
+ *                              added ide-tape: where missing. I would also
+ *                             like to add tape->name where possible
+ *                   AJN-3) Added different debug_level's
+ *                              via /proc/ide/hdc/settings
+ *                             "debug_level" determines amount of debugging output;
+ *                             can be changed using /proc/ide/hdx/settings
+ *                             0 : almost no debugging output
+ *                             1 : 0+output errors only
+ *                             2 : 1+output all sensekey/asc
+ *                             3 : 2+follow all chrdev related procedures
+ *                             4 : 3+follow all procedures
+ *                             5 : 4+include pc_stack rq_stack info
+ *                             6 : 5+USE_COUNT updates
+ *                   AJN-4) Fixed timeout for retension in idetape_queue_pc_tail
+ *                             from 5 to 10 minutes
+ *                   AJN-5) Changed maximum number of blocks to skip when
+ *                              reading tapes with multiple consecutive write
+ *                              errors from 100 to 1000 in idetape_get_logical_blk
+ *                   Proposed changes to code:
+ *                   1) output "logical_blk_num" via /proc
+ *                   2) output "current_operation" via /proc
+ *                   3) Either solve or document the fact that `mt rewind' is
+ *                      required after reading from /dev/nhtx to be
+ *                     able to rmmod the idetape module;
+ *                     Also, sometimes an application finishes but the
+ *                     device remains `busy' for some time. Same cause ?
+ *                   Proposed changes to release-notes:
+ *                  4) write a simple `quickstart' section in the
+ *                      release notes; I volunteer if you don't want to
+ *                  5) include a pointer to video4linux in the doc
+ *                      to stimulate video applications
+ *                   6) release notes lines 331 and 362: explain what happens
+ *                     if the application data rate is higher than 1100 KB/s;
+ *                     similar approach to lower-than-500 kB/s ?
+ *                  7) 6.6 Comparison; wouldn't it be better to allow different
+ *                     strategies for read and write ?
+ *                     Wouldn't it be better to control the tape buffer
+ *                     contents instead of the bandwidth ?
+ *                  8) line 536: replace will by would (if I understand
+ *                     this section correctly, a hypothetical and unwanted situation
+ *                      is being described)
+ * Ver 1.16f Dec 15 99   Change place of the secondary OnStream header frames.
+ * Ver 1.17  Nov 2000 / Jan 2001  Marcel Mol, marcel@mesa.nl
+ *                     - Add idetape_onstream_mode_sense_tape_parameter_page
+ *                       function to get tape capacity in frames: tape->capacity.
+ *                     - Add support for DI-50 drives( or any DI- drive).
+ *                     - 'workaround' for read error/blank block around block 3000.
+ *                     - Implement Early warning for end of media for Onstream.
+ *                     - Cosmetic code changes for readability.
+ *                     - Idetape_position_tape should not use SKIP bit during
+ *                       Onstream read recovery.
+ *                     - Add capacity, logical_blk_num and first/last_frame_position
+ *                       to /proc/ide/hd?/settings.
+ *                     - Module use count was gone in the Linux 2.4 driver.
+ * Ver 1.17a Apr 2001 Willem Riede osst@riede.org
+ *                     - Get drive's actual block size from mode sense block descriptor
+ *                     - Limit size of pipeline
+ * Ver 1.17b Oct 2002   Alan Stern <stern@rowland.harvard.edu>
+ *                     Changed IDETAPE_MIN_PIPELINE_STAGES to 1 and actually used
+ *                      it in the code!
+ *                     Actually removed aborted stages in idetape_abort_pipeline
+ *                      instead of just changing the command code.
+ *                     Made the transfer byte count for Request Sense equal to the
+ *                      actual length of the data transfer.
+ *                     Changed handling of partial data transfers: they do not
+ *                      cause DMA errors.
+ *                     Moved initiation of DMA transfers to the correct place.
+ *                     Removed reference to unallocated memory.
+ *                     Made __idetape_discard_read_pipeline return the number of
+ *                      sectors skipped, not the number of stages.
+ *                     Replaced errant kfree() calls with __idetape_kfree_stage().
+ *                     Fixed off-by-one error in testing the pipeline length.
+ *                     Fixed handling of filemarks in the read pipeline.
+ *                     Small code optimization for MTBSF and MTBSFM ioctls.
+ *                     Don't try to unlock the door during device close if is
+ *                      already unlocked!
+ *                     Cosmetic fixes to miscellaneous debugging output messages.
+ *                     Set the minimum /proc/ide/hd?/settings values for "pipeline",
+ *                      "pipeline_min", and "pipeline_max" to 1.
+ */
diff --git a/Documentation/ide/ide-tape.txt b/Documentation/ide/ide-tape.txt
new file mode 100644 (file)
index 0000000..658f271
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * IDE ATAPI streaming tape driver.
+ *
+ * This driver is a part of the Linux ide driver.
+ *
+ * The driver, in co-operation with ide.c, basically traverses the
+ * request-list for the block device interface. The character device
+ * interface, on the other hand, creates new requests, adds them
+ * to the request-list of the block device, and waits for their completion.
+ *
+ * Pipelined operation mode is now supported on both reads and writes.
+ *
+ * The block device major and minor numbers are determined from the
+ * tape's relative position in the ide interfaces, as explained in ide.c.
+ *
+ * The character device interface consists of the following devices:
+ *
+ * ht0         major 37, minor 0       first  IDE tape, rewind on close.
+ * ht1         major 37, minor 1       second IDE tape, rewind on close.
+ * ...
+ * nht0                major 37, minor 128     first  IDE tape, no rewind on close.
+ * nht1                major 37, minor 129     second IDE tape, no rewind on close.
+ * ...
+ *
+ * The general magnetic tape commands compatible interface, as defined by
+ * include/linux/mtio.h, is accessible through the character device.
+ *
+ * General ide driver configuration options, such as the interrupt-unmask
+ * flag, can be configured by issuing an ioctl to the block device interface,
+ * as any other ide device.
+ *
+ * Our own ide-tape ioctl's can be issued to either the block device or
+ * the character device interface.
+ *
+ * Maximal throughput with minimal bus load will usually be achieved in the
+ * following scenario:
+ *
+ *     1.      ide-tape is operating in the pipelined operation mode.
+ *     2.      No buffering is performed by the user backup program.
+ *
+ * Testing was done with a 2 GB CONNER CTMA 4000 IDE ATAPI Streaming Tape Drive.
+ *
+ * Here are some words from the first releases of hd.c, which are quoted
+ * in ide.c and apply here as well:
+ *
+ * | Special care is recommended.  Have Fun!
+ *
+ *
+ * An overview of the pipelined operation mode.
+ *
+ * In the pipelined write mode, we will usually just add requests to our
+ * pipeline and return immediately, before we even start to service them. The
+ * user program will then have enough time to prepare the next request while
+ * we are still busy servicing previous requests. In the pipelined read mode,
+ * the situation is similar - we add read-ahead requests into the pipeline,
+ * before the user even requested them.
+ *
+ * The pipeline can be viewed as a "safety net" which will be activated when
+ * the system load is high and prevents the user backup program from keeping up
+ * with the current tape speed. At this point, the pipeline will get
+ * shorter and shorter but the tape will still be streaming at the same speed.
+ * Assuming we have enough pipeline stages, the system load will hopefully
+ * decrease before the pipeline is completely empty, and the backup program
+ * will be able to "catch up" and refill the pipeline again.
+ *
+ * When using the pipelined mode, it would be best to disable any type of
+ * buffering done by the user program, as ide-tape already provides all the
+ * benefits in the kernel, where it can be done in a more efficient way.
+ * As we will usually not block the user program on a request, the most
+ * efficient user code will then be a simple read-write-read-... cycle.
+ * Any additional logic will usually just slow down the backup process.
+ *
+ * Using the pipelined mode, I get a constant over 400 KBps throughput,
+ * which seems to be the maximum throughput supported by my tape.
+ *
+ * However, there are some downfalls:
+ *
+ *     1.      We use memory (for data buffers) in proportional to the number
+ *             of pipeline stages (each stage is about 26 KB with my tape).
+ *     2.      In the pipelined write mode, we cheat and postpone error codes
+ *             to the user task. In read mode, the actual tape position
+ *             will be a bit further than the last requested block.
+ *
+ * Concerning (1):
+ *
+ *     1.      We allocate stages dynamically only when we need them. When
+ *             we don't need them, we don't consume additional memory. In
+ *             case we can't allocate stages, we just manage without them
+ *             (at the expense of decreased throughput) so when Linux is
+ *             tight in memory, we will not pose additional difficulties.
+ *
+ *     2.      The maximum number of stages (which is, in fact, the maximum
+ *             amount of memory) which we allocate is limited by the compile
+ *             time parameter IDETAPE_MAX_PIPELINE_STAGES.
+ *
+ *     3.      The maximum number of stages is a controlled parameter - We
+ *             don't start from the user defined maximum number of stages
+ *             but from the lower IDETAPE_MIN_PIPELINE_STAGES (again, we
+ *             will not even allocate this amount of stages if the user
+ *             program can't handle the speed). We then implement a feedback
+ *             loop which checks if the pipeline is empty, and if it is, we
+ *             increase the maximum number of stages as necessary until we
+ *             reach the optimum value which just manages to keep the tape
+ *             busy with minimum allocated memory or until we reach
+ *             IDETAPE_MAX_PIPELINE_STAGES.
+ *
+ * Concerning (2):
+ *
+ *     In pipelined write mode, ide-tape can not return accurate error codes
+ *     to the user program since we usually just add the request to the
+ *      pipeline without waiting for it to be serviced. In case an error
+ *      occurs, I will report it on the next user request.
+ *
+ *     In the pipelined read mode, subsequent read requests or forward
+ *     filemark spacing will perform correctly, as we preserve all blocks
+ *     and filemarks which we encountered during our excess read-ahead.
+ *
+ *     For accurate tape positioning and error reporting, disabling
+ *     pipelined mode might be the best option.
+ *
+ * You can enable/disable/tune the pipelined operation mode by adjusting
+ * the compile time parameters below.
+ *
+ *
+ *     Possible improvements.
+ *
+ *     1.      Support for the ATAPI overlap protocol.
+ *
+ *             In order to maximize bus throughput, we currently use the DSC
+ *             overlap method which enables ide.c to service requests from the
+ *             other device while the tape is busy executing a command. The
+ *             DSC overlap method involves polling the tape's status register
+ *             for the DSC bit, and servicing the other device while the tape
+ *             isn't ready.
+ *
+ *             In the current QIC development standard (December 1995),
+ *             it is recommended that new tape drives will *in addition*
+ *             implement the ATAPI overlap protocol, which is used for the
+ *             same purpose - efficient use of the IDE bus, but is interrupt
+ *             driven and thus has much less CPU overhead.
+ *
+ *             ATAPI overlap is likely to be supported in most new ATAPI
+ *             devices, including new ATAPI cdroms, and thus provides us
+ *             a method by which we can achieve higher throughput when
+ *             sharing a (fast) ATA-2 disk with any (slow) new ATAPI device.
+ */
index 74f68b35f7c161d0e6efe9a0822a8e45e6f49b49..1ba84f3584e3022e952647ce7420894f01d8349e 100644 (file)
@@ -85,7 +85,7 @@ involve special block devices or loopbacks; you merely create a directory on
 disk with the desired initrd content, cd to that directory, and run (as an
 example):
 
-find . | cpio --quiet -c -o | gzip -9 -n > /boot/imagefile.img
+find . | cpio --quiet -H newc -o | gzip -9 -n > /boot/imagefile.img
 
 Examining the contents of an existing image file is just as simple:
 
diff --git a/Documentation/ja_JP/stable_kernel_rules.txt b/Documentation/ja_JP/stable_kernel_rules.txt
new file mode 100644 (file)
index 0000000..17d8751
--- /dev/null
@@ -0,0 +1,79 @@
+NOTE:
+This is Japanese translated version of "Documentation/stable_kernel_rules.txt".
+This one is maintained by Tsugikazu Shibata <tshibata@ab.jp.nec.com>
+and JF Project team <www.linux.or.jp/JF>.
+If you find difference with original file or problem in translation,
+please contact maintainer of this file or JF project.
+
+Please also note that purpose of this file is easier to read for non
+English natives and do no intended to fork. So, if you have any
+comment or update of this file, please try to update Original(English)
+file at first.
+
+==================================
+ã\81\93ã\82\8cã\81¯ã\80\81
+linux-2.6.24/Documentation/stable_kernel_rules.txt
+ã\81®å\92\8c訳ã\81§ã\81\99ã\80\82
+
+翻訳å\9b£ä½\93ï¼\9a JF Ã£\83\97ã\83­ã\82¸ã\82§ã\82¯ã\83\88 < http://www.linux.or.jp/JF/ >
+翻訳æ\97¥ï¼\9a 2007/12/30
+翻訳è\80\85ï¼\9a Tsugikazu Shibata <tshibata at ab dot jp dot nec dot com>
+æ ¡æ­£è\80\85ï¼\9a Ã¦Â­Â¦Ã¤Âº\95伸å\85\89ã\81\95ã\82\93ã\80\81<takei at webmasters dot gr dot jp>
+         Ã£\81\8bã\81­ã\81\93ã\81\95ã\82\93 (Seiji Kaneko) <skaneko at a2 dot mbn dot or dot jp>
+         Ã¥Â°\8fæ\9e\97 Ã©\9b\85Ã¥\85¸ã\81\95ã\82\93 (Masanori Kobayasi) <zap03216 at nifty dot ne dot jp>
+         Ã©\87\8eÃ¥\8f£ã\81\95ã\82\93 (Kenji Noguchi) <tokyo246 at gmail dot com>
+         Ã§Â¥\9e宮信太é\83\8eã\81\95ã\82\93 <jin at libjingu dot jp>
+==================================
+
+ã\81\9aã\81£ã\81¨ç\9f¥ã\82\8aã\81\9fã\81\8bã\81£ã\81\9f Linux 2.6 -stable Ã£\83ªã\83ªã\83¼ã\82¹ã\81®å\85¨ã\81¦
+
+"-stable" Ã£\83\84ã\83ªã\83¼ã\81«ã\81©ã\81®ã\82\88ã\81\86ã\81ªç¨®é¡\9eã\81®ã\83\91ã\83\83ã\83\81ã\81\8cÃ¥\8f\97ã\81\91Ã¥\85¥ã\82\8cã\82\89ã\82\8cã\82\8bã\81\8bã\80\81ã\81©ã\81®ã\82\88ã\81\86ã\81ª
+ã\82\82ã\81®ã\81\8cå\8f\97ã\81\91å\85¥ã\82\8cã\82\89ã\82\8cã\81ªã\81\84ã\81\8bã\80\81ã\81«ã\81¤ã\81\84ã\81¦ã\81®è¦\8få\89\87-
+
+ - Ã¦\98\8eã\82\89ã\81\8bã\81«æ­£ã\81\97ã\81\8fã\80\81ã\83\86ã\82¹ã\83\88ã\81\95ã\82\8cã\81¦ã\81\84ã\82\8bã\82\82ã\81®ã\81§ã\81ªã\81\91ã\82\8cã\81°ã\81ªã\82\89ã\81ªã\81\84ã\80\82
+ - Ã¦\96\87è\84\88(å¤\89æ\9b´è¡\8cã\81®å\89\8då¾\8c)ã\82\92Ã¥\90«ã\82\81ã\81¦ 100 Ã¨Â¡\8cã\82\88ã\82\8a大ã\81\8dã\81\8fã\81¦ã\81¯ã\81\84ã\81\91ã\81ªã\81\84ã\80\82
+ - Ã£\81\9fã\81 ä¸\80Ã¥\80\8bã\81®ã\81\93ã\81¨ã\81 ã\81\91ã\82\92修正ã\81\97ã\81¦ã\81\84ã\82\8bã\81¹ã\81\8dã\80\82
+ - Ã§\9a\86ã\82\92æ\82©ã\81¾ã\81\9bã\81¦ã\81\84ã\82\8bæ\9c\89©ã\81®ã\83\90ã\82°ã\82\92修正ã\81\97ã\81ªã\81\91ã\82\8cã\81°ã\81ªã\82\89ã\81ªã\81\84ã\80\82("ã\81\93ã\82\8cã\81¯ã\83\90ã\82°ã\81§
+   Ã£\81\82ã\82\8bã\81\8bã\82\82ã\81\97ã\82\8cã\81ªã\81\84ã\81\8c..." Ã£\81®ã\82\88ã\81\86ã\81ªã\82\82ã\81®ã\81§ã\81¯ã\81ªã\81\84)
+ - Ã£\83\93ã\83«ã\83\89ã\82¨ã\83©ã\83¼(CONFIG_BROKENã\81«ã\81ªã\81£ã\81¦ã\81\84ã\82\8bã\82\82ã\81®ã\82\92é\99¤ã\81\8f), oops, Ã£\83\8fã\83³ã\82°ã\80\81ã\83\87ã\83¼
+   Ã£\82¿ç ´å£\8aã\80\81ç\8f¾å®\9fã\81®ã\82ȋ\82­ã\83¥ã\83ªã\83\86ã\82£å\95\8fé¡\8cã\80\81ã\81\9dã\81®ä»\96 "ã\81\82ã\81\82ã\80\81ã\81\93ã\82\8cã\81¯ã\83\80ã\83¡ã\81 ã\81­"ã\81¨ã\81\84ã\81\86
+   Ã£\82\88ã\81\86ã\81ªã\82\82ã\81®ã\82\92修正ã\81\97ã\81ªã\81\91ã\82\8cã\81°ã\81ªã\82\89ã\81ªã\81\84ã\80\82ç\9f­ã\81\8fè¨\80ã\81\88ã\81°ã\80\81é\87\8d大ã\81ªå\95\8fé¡\8cã\80\82
+ - Ã£\81©ã\81®ã\82\88ã\81\86ã\81«ç«¶å\90\88ç\8a¶æ\85\8bã\81\8cç\99ºç\94\9fã\81\99ã\82\8bã\81\8bã\81®èª¬æ\98\8eã\82\82ä¸\80ç·\92ã\81«æ\9b¸ã\81\8bã\82\8cã\81¦ã\81\84ã\81ªã\81\84é\99\90ã\82\8aã\80\81
+   "ç\90\86è«\96ç\9a\84ã\81«ã\81¯ç«¶å\90\88ç\8a¶æ\85\8bã\81«ã\81ªã\82\8b"ã\82\88ã\81\86ã\81ªã\82\82ã\81®ã\81¯ä¸\8dÃ¥\8f¯ã\80\82
+ - Ã£\81\84ã\81\8bã\81ªã\82\8bäº\9bç´°ã\81ªä¿®æ­£ã\82\82Ã¥\90«ã\82\81ã\82\8bã\81\93ã\81¨ã\81¯ã\81§ã\81\8dã\81ªã\81\84ã\80\82(ã\82¹ã\83\9aã\83«ã\81®ä¿®æ­£ã\80\81空ç\99½ã\81®ã\82¯ã\83ªã\83¼
+   Ã£\83³ã\82¢ã\83\83ã\83\97ã\81ªã\81©)
+ - Ã¥Â¯Â¾Ã¥Â¿\9cã\81\99ã\82\8bã\82µã\83\96ã\82·ã\82¹ã\83\86ã\83 ã\83¡ã\83³ã\83\86ã\83\8aã\81\8cÃ¥\8f\97ã\81\91Ã¥\85¥ã\82\8cã\81\9fã\82\82ã\81®ã\81§ã\81ªã\81\91ã\82\8cã\81°ã\81ªã\82\89ã\81ªã\81\84ã\80\82
+ - Documentation/SubmittingPatches Ã£\81®è¦\8fÃ¥\89\87ã\81«å¾\93ã\81£ã\81\9fã\82\82ã\81®ã\81§ã\81ªã\81\91ã\82\8cã\81°ã\81ªã\82\89ã\81ªã\81\84ã\80\82
+
+-stable Ã£\83\84ã\83ªã\83¼ã\81«ã\83\91ã\83\83ã\83\81ã\82\92é\80\81ä»\98ã\81\99ã\82\8bæ\89\8bç¶\9aã\81\8d-
+
+ - Ã¤Â¸\8aè¨\98ã\81®è¦\8fÃ¥\89\87ã\81«å¾\93ã\81£ã\81¦ã\81\84ã\82\8bã\81\8bã\82\92確èª\8dã\81\97ã\81\9få¾\8cã\81«ã\80\81stable@kernel.org Ã£\81«ã\83\91ã\83\83ã\83\81
+   Ã£\82\92é\80\81ã\82\8bã\80\82
+ - Ã©\80\81ä¿¡è\80\85ã\81¯ã\83\91ã\83\83ã\83\81ã\81\8cã\82­ã\83¥ã\83¼ã\81«å\8f\97ã\81\91ä»\98ã\81\91ã\82\89ã\82\8cã\81\9fé\9a\9bã\81«ã\81¯ ACK Ã£\82\92ã\80\81Ã¥\8d´ä¸\8bã\81\95ã\82\8cã\81\9få ´å\90\88
+   Ã£\81«ã\81¯ NAK Ã£\82\92Ã¥\8f\97ã\81\91Ã¥\8f\96ã\82\8bã\80\82ã\81\93ã\81®å\8f\8då¿\9cã\81¯é\96\8bç\99ºè\80\85ã\81\9fã\81¡ã\81®ã\82¹ã\82±ã\82¸ã\83¥ã\83¼ã\83«ã\81«ã\82\88ã\81£ã\81¦ã\80\81æ\95°
+   Ã¦\97¥ã\81\8bã\81\8bã\82\8bå ´å\90\88ã\81\8cã\81\82ã\82\8bã\80\82
+ - Ã£\82\82ã\81\97Ã¥\8f\97ã\81\91Ã¥\8f\96ã\82\89ã\82\8cã\81\9fã\82\89ã\80\81ã\83\91ã\83\83ã\83\81ã\81¯ä»\96ã\81®é\96\8bç\99ºè\80\85ã\81\9fã\81¡ã\81®ã\83‹\83\93ã\83¥ã\83¼ã\81®ã\81\9fã\82\81ã\81«
+   -stable Ã£\82­ã\83¥ã\83¼ã\81«è¿½å\8a ã\81\95ã\82\8cã\82\8bã\80\82
+ - Ã£\82ȋ\82­ã\83¥ã\83ªã\83\86ã\82£ã\83\91ã\83\83ã\83\81ã\81¯ã\81\93ã\81®ã\82¨ã\82¤ã\83ªã\82¢ã\82¹ (stable@kernel.org) Ã£\81«é\80\81ã\82\89ã\82\8cã\82\8bã\81¹
+   Ã£\81\8dã\81§ã\81¯ã\81ªã\81\8fã\80\81代ã\82\8fã\82\8aã\81« security@kernel.org Ã£\81®ã\82¢ã\83\89ã\83‹\82¹ã\81«é\80\81ã\82\89ã\82\8cã\82\8bã\80\82
+
+ã\83¬ã\83\93ã\83¥ã\83¼ã\82µã\82¤ã\82¯ã\83«-
+
+ - -stable Ã£\83¡ã\83³ã\83\86ã\83\8aã\81\8cã\83‹\83\93ã\83¥ã\83¼ã\82µã\82¤ã\82¯ã\83«ã\82\92決ã\82\81ã\82\8bã\81¨ã\81\8dã\80\81ã\83\91ã\83\83ã\83\81ã\81¯ã\83‹\83\93ã\83¥ã\83¼å§\94
+   Ã¥\93¡ä¼\9aã\81¨ã\83\91ã\83\83ã\83\81ã\81\8cå½±é\9f¿ã\81\99ã\82\8bé \98Ã¥\9f\9fã\81®ã\83¡ã\83³ã\83\86ã\83\8a(æ\8f\90ä¾\9bè\80\85ã\81\8cã\81\9dã\81®é \98Ã¥\9f\9fã\81®ã\83¡ã\83³ã\83\86ã\83\8aã\81§ç\84¡
+   Ã£\81\84é\99\90ã\82\8a)ã\81«é\80\81ã\82\89ã\82\8cã\80\81linux-kernel Ã£\83¡ã\83¼ã\83ªã\83³ã\82°ã\83ªã\82¹ã\83\88ã\81«CCã\81\95ã\82\8cã\82\8bã\80\82
+ - Ã£\83‹\83\93ã\83¥ã\83¼å§\94Ã¥\93¡ä¼\9aã\81¯ 48æ\99\82é\96\93ã\81®é\96\93ã\81« ACK Ã£\81\8b NAK Ã£\82\92Ã¥\87ºã\81\99ã\80\82
+ - Ã£\82\82ã\81\97ã\83\91ã\83\83ã\83\81ã\81\8cå§\94Ã¥\93¡ä¼\9aã\81®ã\83¡ã\83³ã\83\90ã\81\8bã\82\89Ã¥\8d´ä¸\8bã\82\8cã\82\8bã\81\8bã\80\81ã\83¡ã\83³ã\83\86ã\83\8aé\81\94ã\82\84ã\83¡ã\83³ã\83\90ã\81\8cæ°\97ä»\98
+   Ã£\81\8bã\81ªã\81\8bã\81£ã\81\9fÃ¥\95\8fé¡\8cã\81\8cæ\8c\81ã\81¡ã\81\82ã\81\8cã\82\8aã\80\81linux-kernel Ã£\83¡ã\83³ã\83\90ã\81\8cã\83\91ã\83\83ã\83\81ã\81«ç\95°è­°ã\82\92Ã¥\94±ã\81\88
+   Ã£\81\9få ´å\90\88ã\81«ã\81¯ã\80\81ã\83\91ã\83\83ã\83\81ã\81¯ã\82­ã\83¥ã\83¼ã\81\8bã\82\89Ã¥\89\8aé\99¤ã\81\95ã\82\8cã\82\8bã\80\82
+ - Ã£\83‹\83\93ã\83¥ã\83¼ã\82µã\82¤ã\82¯ã\83«ã\81®æ\9c\80å¾\8cã\81«ã\80\81ACK Ã£\82\92Ã¥\8f\97ã\81\91ã\81\9fã\83\91ã\83\83ã\83\81ã\81¯æ\9c\80æ\96°ã\81® -stable Ã£\83ªã\83ªã\83¼
+   Ã£\82¹ã\81«è¿½å\8a ã\81\95ã\82\8cã\80\81ã\81\9dã\81®å¾\8cã\81«æ\96°ã\81\97ã\81\84 -stable Ã£\83ªã\83ªã\83¼ã\82¹ã\81\8cè¡\8cã\82\8fã\82\8cã\82\8bã\80\82
+ - Ã£\82ȋ\82­ã\83¥ã\83ªã\83\86ã\82£ã\83\91ã\83\83ã\83\81ã\81¯ã\80\81é\80\9a常ã\81®ã\83‹\83\93ã\83¥ã\83¼ã\82µã\82¤ã\82¯ã\83«ã\82\92é\80\9aã\82\89ã\81\9aã\80\81ã\82ȋ\82­ã\83¥ã\83ªã\83\86ã\82£
+   Ã£\82«ã\83¼ã\83\8dã\83«ã\83\81ã\83¼ã\83 ã\81\8bã\82\89ç\9b´æ\8eÂ¥ -stable Ã£\83\84ã\83ªã\83¼ã\81«å\8f\97ã\81\91ä»\98ã\81\91ã\82\89ã\82\8cã\82\8bã\80\82
+   Ã£\81\93ã\81®æ\89\8bç¶\9aã\81\8dã\81®è©³ç´°ã\81«ã\81¤ã\81\84ã\81¦ã\81¯ kernel security Ã£\83\81ã\83¼ã\83 ã\81«å\95\8fã\81\84Ã¥\90\88ã\82\8fã\81\9bã\82\8bã\81\93ã\81¨ã\80\82
+
+ã\83¬ã\83\93ã\83¥ã\83¼å§\94å\93¡ä¼\9a-
+
+ - Ã£\81\93ã\81®å§\94Ã¥\93¡ä¼\9aã\81¯ã\80\81ã\81\93ã\81®ã\82¿ã\82¹ã\82¯ã\81«ã\81¤ã\81\84ã\81¦æ´»å\8b\95ã\81\99ã\82\8bå¤\9aã\81\8fã\81®ã\83\9cã\83©ã\83³ã\83\86ã\82£ã\82¢ã\81¨ã\80\81å°\91æ\95°ã\81®
+   Ã©\9d\9eã\83\9cã\83©ã\83³ã\83\86ã\82£ã\82¢ã\81®ã\82«ã\83¼ã\83\8dã\83«é\96\8bç\99ºè\80\85é\81\94ã\81§æ§\8bæ\88\90ã\81\95ã\82\8cã\81¦ã\81\84ã\82\8bã\80\82
+
index 92c40d174355505555642cbe3a0ea137881dcbd4..8fd5aa40585ff8419cc730104079ddd61b5ccb8e 100644 (file)
@@ -168,6 +168,11 @@ and is between 256 and 4096 characters. It is defined in the file
        acpi_irq_isa=   [HW,ACPI] If irq_balance, mark listed IRQs used by ISA
                        Format: <irq>,<irq>...
 
+       acpi_new_pts_ordering [HW,ACPI]
+                       Enforce the ACPI 2.0 ordering of the _PTS control
+                       method wrt putting devices into low power states
+                       default: pre ACPI 2.0 ordering of _PTS
+
        acpi_no_auto_ssdt       [HW,ACPI] Disable automatic loading of SSDT
 
        acpi_os_name=   [HW,ACPI] Tell ACPI BIOS the name of the OS
@@ -544,7 +549,7 @@ and is between 256 and 4096 characters. It is defined in the file
                        1 will print _a lot_ more information - normally
                        only useful to kernel developers.
 
-       decnet=         [HW,NET]
+       decnet.addr=    [HW,NET]
                        Format: <area>[,<node>]
                        See also Documentation/networking/decnet.txt.
 
@@ -775,6 +780,9 @@ and is between 256 and 4096 characters. It is defined in the file
                        loop use the MONITOR/MWAIT idle loop anyways. Performance should be the same
                        as idle=poll.
 
+       ide-pci-generic.all-generic-ide [HW] (E)IDE subsystem
+                       Claim all unknown PCI IDE storage controllers.
+
        ignore_loglevel [KNL]
                        Ignore loglevel setting - this will print /all/
                        kernel messages to the console. Useful for debugging.
@@ -1556,14 +1564,17 @@ and is between 256 and 4096 characters. It is defined in the file
        ramdisk_size=   [RAM] Sizes of RAM disks in kilobytes
                        See Documentation/ramdisk.txt.
 
-       rcu.blimit=     [KNL,BOOT] Set maximum number of finished
-                       RCU callbacks to process in one batch.
+       rcupdate.blimit=        [KNL,BOOT]
+                       Set maximum number of finished RCU callbacks to process
+                       in one batch.
 
-       rcu.qhimark=    [KNL,BOOT] Set threshold of queued
+       rcupdate.qhimark=       [KNL,BOOT]
+                       Set threshold of queued
                        RCU callbacks over which batch limiting is disabled.
 
-       rcu.qlowmark=   [KNL,BOOT] Set threshold of queued
-                       RCU callbacks below which batch limiting is re-enabled.
+       rcupdate.qlowmark=      [KNL,BOOT]
+                       Set threshold of queued RCU callbacks below which
+                       batch limiting is re-enabled.
 
        rdinit=         [KNL]
                        Format: <full_path>
@@ -1883,9 +1894,6 @@ and is between 256 and 4096 characters. It is defined in the file
        st=             [HW,SCSI] SCSI tape parameters (buffers, etc.)
                        See Documentation/scsi/st.txt.
 
-       st0x=           [HW,SCSI]
-                       See header of drivers/scsi/seagate.c.
-
        sti=            [PARISC,HW]
                        Format: <num>
                        Set the STI (builtin display/keyboard on the HP-PARISC
@@ -1970,9 +1978,6 @@ and is between 256 and 4096 characters. It is defined in the file
        tipar.delay=    [HW,PPT]
                        Set inter-bit delay in microseconds (default 10).
 
-       tmc8xx=         [HW,SCSI]
-                       See header of drivers/scsi/seagate.c.
-
        tmscsim=        [HW,SCSI]
                        See comment before function dc390_setup() in
                        drivers/scsi/tmscsim.c.
index 53a63890aea49a9def4240e426ddce1db32439c8..30c101761d0d54f532122e8a804d376de2aa61d8 100644 (file)
@@ -96,7 +96,9 @@ or in registers (e.g., for x86_64 or for an i386 fastcall function).
 The jprobe will work in either case, so long as the handler's
 prototype matches that of the probed function.
 
-1.3 How Does a Return Probe Work?
+1.3 Return Probes
+
+1.3.1 How Does a Return Probe Work?
 
 When you call register_kretprobe(), Kprobes establishes a kprobe at
 the entry to the function.  When the probed function is called and this
@@ -107,9 +109,9 @@ At boot time, Kprobes registers a kprobe at the trampoline.
 
 When the probed function executes its return instruction, control
 passes to the trampoline and that probe is hit.  Kprobes' trampoline
-handler calls the user-specified handler associated with the kretprobe,
-then sets the saved instruction pointer to the saved return address,
-and that's where execution resumes upon return from the trap.
+handler calls the user-specified return handler associated with the
+kretprobe, then sets the saved instruction pointer to the saved return
+address, and that's where execution resumes upon return from the trap.
 
 While the probed function is executing, its return address is
 stored in an object of type kretprobe_instance.  Before calling
@@ -131,6 +133,30 @@ zero when the return probe is registered, and is incremented every
 time the probed function is entered but there is no kretprobe_instance
 object available for establishing the return probe.
 
+1.3.2 Kretprobe entry-handler
+
+Kretprobes also provides an optional user-specified handler which runs
+on function entry. This handler is specified by setting the entry_handler
+field of the kretprobe struct. Whenever the kprobe placed by kretprobe at the
+function entry is hit, the user-defined entry_handler, if any, is invoked.
+If the entry_handler returns 0 (success) then a corresponding return handler
+is guaranteed to be called upon function return. If the entry_handler
+returns a non-zero error then Kprobes leaves the return address as is, and
+the kretprobe has no further effect for that particular function instance.
+
+Multiple entry and return handler invocations are matched using the unique
+kretprobe_instance object associated with them. Additionally, a user
+may also specify per return-instance private data to be part of each
+kretprobe_instance object. This is especially useful when sharing private
+data between corresponding user entry and return handlers. The size of each
+private data object can be specified at kretprobe registration time by
+setting the data_size field of the kretprobe struct. This data can be
+accessed through the data field of each kretprobe_instance object.
+
+In case probed function is entered but there is no kretprobe_instance
+object available, then in addition to incrementing the nmissed count,
+the user entry_handler invocation is also skipped.
+
 2. Architectures Supported
 
 Kprobes, jprobes, and return probes are implemented on the following
@@ -274,6 +300,8 @@ of interest:
 - ret_addr: the return address
 - rp: points to the corresponding kretprobe object
 - task: points to the corresponding task struct
+- data: points to per return-instance private data; see "Kretprobe
+       entry-handler" for details.
 
 The regs_return_value(regs) macro provides a simple abstraction to
 extract the return value from the appropriate register as defined by
@@ -556,23 +584,52 @@ report failed calls to sys_open().
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/kprobes.h>
+#include <linux/ktime.h>
+
+/* per-instance private data */
+struct my_data {
+       ktime_t entry_stamp;
+};
 
 static const char *probed_func = "sys_open";
 
-/* Return-probe handler: If the probed function fails, log the return value. */
-static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
+/* Timestamp function entry. */
+static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       struct my_data *data;
+
+       if(!current->mm)
+               return 1; /* skip kernel threads */
+
+       data = (struct my_data *)ri->data;
+       data->entry_stamp = ktime_get();
+       return 0;
+}
+
+/* If the probed function failed, log the return value and duration.
+ * Duration may turn out to be zero consistently, depending upon the
+ * granularity of time accounting on the platform. */
+static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
 {
        int retval = regs_return_value(regs);
+       struct my_data *data = (struct my_data *)ri->data;
+       s64 delta;
+       ktime_t now;
+
        if (retval < 0) {
-               printk("%s returns %d\n", probed_func, retval);
+               now = ktime_get();
+               delta = ktime_to_ns(ktime_sub(now, data->entry_stamp));
+               printk("%s: return val = %d (duration = %lld ns)\n",
+                      probed_func, retval, delta);
        }
        return 0;
 }
 
 static struct kretprobe my_kretprobe = {
-       .handler = ret_handler,
-       /* Probe up to 20 instances concurrently. */
-       .maxactive = 20
+       .handler = return_handler,
+       .entry_handler = entry_handler,
+       .data_size = sizeof(struct my_data),
+       .maxactive = 20, /* probe up to 20 instances concurrently */
 };
 
 static int __init kretprobe_init(void)
@@ -584,7 +641,7 @@ static int __init kretprobe_init(void)
                printk("register_kretprobe failed, returned %d\n", ret);
                return -1;
        }
-       printk("Planted return probe at %p\n", my_kretprobe.kp.addr);
+       printk("Kretprobe active on %s\n", my_kretprobe.kp.symbol_name);
        return 0;
 }
 
@@ -594,7 +651,7 @@ static void __exit kretprobe_exit(void)
        printk("kretprobe unregistered\n");
        /* nmissed > 0 suggests that maxactive was set too low. */
        printk("Missed probing %d instances of %s\n",
-               my_kretprobe.nmissed, probed_func);
+              my_kretprobe.nmissed, probed_func);
 }
 
 module_init(kretprobe_init)
index f38b59d00c63a1a635983eaee2278c40b6f744a6..130b6e87aa7ed04af9d3504acecfd7dc0e07ccfc 100644 (file)
@@ -141,10 +141,10 @@ The last rule (rule 3) is the nastiest one to handle.  Say, for
 instance, you have a list of items that are each kref-ed, and you wish
 to get the first one.  You can't just pull the first item off the list
 and kref_get() it.  That violates rule 3 because you are not already
-holding a valid pointer.  You must add locks or semaphores.  For
-instance:
+holding a valid pointer.  You must add a mutex (or some other lock).
+For instance:
 
-static DECLARE_MUTEX(sem);
+static DEFINE_MUTEX(mutex);
 static LIST_HEAD(q);
 struct my_data
 {
@@ -155,12 +155,12 @@ struct my_data
 static struct my_data *get_entry()
 {
        struct my_data *entry = NULL;
-       down(&sem);
+       mutex_lock(&mutex);
        if (!list_empty(&q)) {
                entry = container_of(q.next, struct my_q_entry, link);
                kref_get(&entry->refcount);
        }
-       up(&sem);
+       mutex_unlock(&mutex);
        return entry;
 }
 
@@ -174,9 +174,9 @@ static void release_entry(struct kref *ref)
 
 static void put_entry(struct my_data *entry)
 {
-       down(&sem);
+       mutex_lock(&mutex);
        kref_put(&entry->refcount, release_entry);
-       up(&sem);
+       mutex_unlock(&mutex);
 }
 
 The kref_put() return value is useful if you do not want to hold the
@@ -191,13 +191,13 @@ static void release_entry(struct kref *ref)
 
 static void put_entry(struct my_data *entry)
 {
-       down(&sem);
+       mutex_lock(&mutex);
        if (kref_put(&entry->refcount, release_entry)) {
                list_del(&entry->link);
-               up(&sem);
+               mutex_unlock(&mutex);
                kfree(entry);
        } else
-               up(&sem);
+               mutex_unlock(&mutex);
 }
 
 This is really more useful if you have to call other routines as part
index 6c8a2386cd50d150fb58844324c40fbb8685bb8c..0f23d67f958ff5b6ee96a0248fdd2c9b9ab65586 100644 (file)
@@ -34,6 +34,8 @@
 #include <zlib.h>
 #include <assert.h>
 #include <sched.h>
+#include <limits.h>
+#include <stddef.h>
 #include "linux/lguest_launcher.h"
 #include "linux/virtio_config.h"
 #include "linux/virtio_net.h"
@@ -99,13 +101,11 @@ struct device_list
        /* The descriptor page for the devices. */
        u8 *descpage;
 
-       /* The tail of the last descriptor. */
-       unsigned int desc_used;
-
        /* A single linked list of devices. */
        struct device *dev;
-       /* ... And an end pointer so we can easily append new devices */
-       struct device **lastdev;
+       /* And a pointer to the last device for easy append and also for
+        * configuration appending. */
+       struct device *lastdev;
 };
 
 /* The list of Guest devices, based on command line arguments. */
@@ -191,7 +191,14 @@ static void *_convert(struct iovec *iov, size_t size, size_t align,
 #define cpu_to_le64(v64) (v64)
 #define le16_to_cpu(v16) (v16)
 #define le32_to_cpu(v32) (v32)
-#define le64_to_cpu(v32) (v64)
+#define le64_to_cpu(v64) (v64)
+
+/* The device virtqueue descriptors are followed by feature bitmasks. */
+static u8 *get_feature_bits(struct device *dev)
+{
+       return (u8 *)(dev->desc + 1)
+               + dev->desc->num_vq * sizeof(struct lguest_vqconfig);
+}
 
 /*L:100 The Launcher code itself takes us out into userspace, that scary place
  * where pointers run wild and free!  Unfortunately, like most userspace
@@ -914,21 +921,58 @@ static void enable_fd(int fd, struct virtqueue *vq)
        write(waker_fd, &vq->dev->fd, sizeof(vq->dev->fd));
 }
 
+/* Resetting a device is fairly easy. */
+static void reset_device(struct device *dev)
+{
+       struct virtqueue *vq;
+
+       verbose("Resetting device %s\n", dev->name);
+       /* Clear the status. */
+       dev->desc->status = 0;
+
+       /* Clear any features they've acked. */
+       memset(get_feature_bits(dev) + dev->desc->feature_len, 0,
+              dev->desc->feature_len);
+
+       /* Zero out the virtqueues. */
+       for (vq = dev->vq; vq; vq = vq->next) {
+               memset(vq->vring.desc, 0,
+                      vring_size(vq->config.num, getpagesize()));
+               vq->last_avail_idx = 0;
+       }
+}
+
 /* This is the generic routine we call when the Guest uses LHCALL_NOTIFY. */
 static void handle_output(int fd, unsigned long addr)
 {
        struct device *i;
        struct virtqueue *vq;
 
-       /* Check each virtqueue. */
+       /* Check each device and virtqueue. */
        for (i = devices.dev; i; i = i->next) {
+               /* Notifications to device descriptors reset the device. */
+               if (from_guest_phys(addr) == i->desc) {
+                       reset_device(i);
+                       return;
+               }
+
+               /* Notifications to virtqueues mean output has occurred. */
                for (vq = i->vq; vq; vq = vq->next) {
-                       if (vq->config.pfn == addr/getpagesize()
-                           && vq->handle_output) {
-                               verbose("Output to %s\n", vq->dev->name);
-                               vq->handle_output(fd, vq);
+                       if (vq->config.pfn != addr/getpagesize())
+                               continue;
+
+                       /* Guest should acknowledge (and set features!)  before
+                        * using the device. */
+                       if (i->desc->status == 0) {
+                               warnx("%s gave early output", i->name);
                                return;
                        }
+
+                       if (strcmp(vq->dev->name, "console") != 0)
+                               verbose("Output to %s\n", vq->dev->name);
+                       if (vq->handle_output)
+                               vq->handle_output(fd, vq);
+                       return;
                }
        }
 
@@ -986,54 +1030,44 @@ static void handle_input(int fd)
  *
  * All devices need a descriptor so the Guest knows it exists, and a "struct
  * device" so the Launcher can keep track of it.  We have common helper
- * routines to allocate them.
- *
- * This routine allocates a new "struct lguest_device_desc" from descriptor
- * table just above the Guest's normal memory.  It returns a pointer to that
- * descriptor. */
-static struct lguest_device_desc *new_dev_desc(u16 type)
-{
-       struct lguest_device_desc *d;
+ * routines to allocate and manage them. */
 
-       /* We only have one page for all the descriptors. */
-       if (devices.desc_used + sizeof(*d) > getpagesize())
-               errx(1, "Too many devices");
-
-       /* We don't need to set config_len or status: page is 0 already. */
-       d = (void *)devices.descpage + devices.desc_used;
-       d->type = type;
-       devices.desc_used += sizeof(*d);
-
-       return d;
+/* The layout of the device page is a "struct lguest_device_desc" followed by a
+ * number of virtqueue descriptors, then two sets of feature bits, then an
+ * array of configuration bytes.  This routine returns the configuration
+ * pointer. */
+static u8 *device_config(const struct device *dev)
+{
+       return (void *)(dev->desc + 1)
+               + dev->desc->num_vq * sizeof(struct lguest_vqconfig)
+               + dev->desc->feature_len * 2;
 }
 
-/* Each device descriptor is followed by some configuration information.
- * Each configuration field looks like: u8 type, u8 len, [... len bytes...].
- *
- * This routine adds a new field to an existing device's descriptor.  It only
- * works for the last device, but that's OK because that's how we use it. */
-static void add_desc_field(struct device *dev, u8 type, u8 len, const void *c)
+/* This routine allocates a new "struct lguest_device_desc" from descriptor
+ * table page just above the Guest's normal memory.  It returns a pointer to
+ * that descriptor. */
+static struct lguest_device_desc *new_dev_desc(u16 type)
 {
-       /* This is the last descriptor, right? */
-       assert(devices.descpage + devices.desc_used
-              == (u8 *)(dev->desc + 1) + dev->desc->config_len);
+       struct lguest_device_desc d = { .type = type };
+       void *p;
 
-       /* We only have one page of device descriptions. */
-       if (devices.desc_used + 2 + len > getpagesize())
-               errx(1, "Too many devices");
+       /* Figure out where the next device config is, based on the last one. */
+       if (devices.lastdev)
+               p = device_config(devices.lastdev)
+                       + devices.lastdev->desc->config_len;
+       else
+               p = devices.descpage;
 
-       /* Copy in the new config header: type then length. */
-       devices.descpage[devices.desc_used++] = type;
-       devices.descpage[devices.desc_used++] = len;
-       memcpy(devices.descpage + devices.desc_used, c, len);
-       devices.desc_used += len;
+       /* We only have one page for all the descriptors. */
+       if (p + sizeof(d) > (void *)devices.descpage + getpagesize())
+               errx(1, "Too many devices");
 
-       /* Update the device descriptor length: two byte head then data. */
-       dev->desc->config_len += 2 + len;
+       /* p might not be aligned, so we memcpy in. */
+       return memcpy(p, &d, sizeof(d));
 }
 
-/* This routine adds a virtqueue to a device.  We specify how many descriptors
- * the virtqueue is to have. */
+/* Each device descriptor is followed by the description of its virtqueues.  We
+ * specify how many descriptors the virtqueue is to have. */
 static void add_virtqueue(struct device *dev, unsigned int num_descs,
                          void (*handle_output)(int fd, struct virtqueue *me))
 {
@@ -1059,9 +1093,15 @@ static void add_virtqueue(struct device *dev, unsigned int num_descs,
        /* Initialize the vring. */
        vring_init(&vq->vring, num_descs, p, getpagesize());
 
-       /* Add the configuration information to this device's descriptor. */
-       add_desc_field(dev, VIRTIO_CONFIG_F_VIRTQUEUE,
-                      sizeof(vq->config), &vq->config);
+       /* Append virtqueue to this device's descriptor.  We use
+        * device_config() to get the end of the device's current virtqueues;
+        * we check that we haven't added any config or feature information
+        * yet, otherwise we'd be overwriting them. */
+       assert(dev->desc->config_len == 0 && dev->desc->feature_len == 0);
+       memcpy(device_config(dev), &vq->config, sizeof(vq->config));
+       dev->desc->num_vq++;
+
+       verbose("Virtqueue page %#lx\n", to_guest_phys(p));
 
        /* Add to tail of list, so dev->vq is first vq, dev->vq->next is
         * second.  */
@@ -1072,11 +1112,41 @@ static void add_virtqueue(struct device *dev, unsigned int num_descs,
         * virtqueue. */
        vq->handle_output = handle_output;
 
-       /* Set the "Don't Notify Me" flag if we don't have a handler */
+       /* As an optimization, set the advisory "Don't Notify Me" flag if we
+        * don't have a handler */
        if (!handle_output)
                vq->vring.used->flags = VRING_USED_F_NO_NOTIFY;
 }
 
+/* The first half of the feature bitmask is for us to advertise features.  The
+ * second half if for the Guest to accept features. */
+static void add_feature(struct device *dev, unsigned bit)
+{
+       u8 *features = get_feature_bits(dev);
+
+       /* We can't extend the feature bits once we've added config bytes */
+       if (dev->desc->feature_len <= bit / CHAR_BIT) {
+               assert(dev->desc->config_len == 0);
+               dev->desc->feature_len = (bit / CHAR_BIT) + 1;
+       }
+
+       features[bit / CHAR_BIT] |= (1 << (bit % CHAR_BIT));
+}
+
+/* This routine sets the configuration fields for an existing device's
+ * descriptor.  It only works for the last device, but that's OK because that's
+ * how we use it. */
+static void set_config(struct device *dev, unsigned len, const void *conf)
+{
+       /* Check we haven't overflowed our single page. */
+       if (device_config(dev) + len > devices.descpage + getpagesize())
+               errx(1, "Too many devices");
+
+       /* Copy in the config information, and store the length. */
+       memcpy(device_config(dev), conf, len);
+       dev->desc->config_len = len;
+}
+
 /* This routine does all the creation and setup of a new device, including
  * calling new_dev_desc() to allocate the descriptor and device memory. */
 static struct device *new_device(const char *name, u16 type, int fd,
@@ -1084,14 +1154,6 @@ static struct device *new_device(const char *name, u16 type, int fd,
 {
        struct device *dev = malloc(sizeof(*dev));
 
-       /* Append to device list.  Prepending to a single-linked list is
-        * easier, but the user expects the devices to be arranged on the bus
-        * in command-line order.  The first network device on the command line
-        * is eth0, the first block device /dev/vda, etc. */
-       *devices.lastdev = dev;
-       dev->next = NULL;
-       devices.lastdev = &dev->next;
-
        /* Now we populate the fields one at a time. */
        dev->fd = fd;
        /* If we have an input handler for this file descriptor, then we add it
@@ -1102,6 +1164,17 @@ static struct device *new_device(const char *name, u16 type, int fd,
        dev->handle_input = handle_input;
        dev->name = name;
        dev->vq = NULL;
+
+       /* Append to device list.  Prepending to a single-linked list is
+        * easier, but the user expects the devices to be arranged on the bus
+        * in command-line order.  The first network device on the command line
+        * is eth0, the first block device /dev/vda, etc. */
+       if (devices.lastdev)
+               devices.lastdev->next = dev;
+       else
+               devices.dev = dev;
+       devices.lastdev = dev;
+
        return dev;
 }
 
@@ -1226,7 +1299,7 @@ static void setup_tun_net(const char *arg)
        int netfd, ipfd;
        u32 ip;
        const char *br_name = NULL;
-       u8 hwaddr[6];
+       struct virtio_net_config conf;
 
        /* We open the /dev/net/tun device and tell it we want a tap device.  A
         * tap device is like a tun device, only somehow different.  To tell
@@ -1265,12 +1338,13 @@ static void setup_tun_net(const char *arg)
                ip = str2ip(arg);
 
        /* Set up the tun device, and get the mac address for the interface. */
-       configure_device(ipfd, ifr.ifr_name, ip, hwaddr);
+       configure_device(ipfd, ifr.ifr_name, ip, conf.mac);
 
        /* Tell Guest what MAC address to use. */
-       add_desc_field(dev, VIRTIO_CONFIG_NET_MAC_F, sizeof(hwaddr), hwaddr);
+       add_feature(dev, VIRTIO_NET_F_MAC);
+       set_config(dev, sizeof(conf), &conf);
 
-       /* We don't seed the socket any more; setup is done. */
+       /* We don't need the socket any more; setup is done. */
        close(ipfd);
 
        verbose("device %u: tun net %u.%u.%u.%u\n",
@@ -1458,8 +1532,7 @@ static void setup_block_file(const char *filename)
        struct device *dev;
        struct vblk_info *vblk;
        void *stack;
-       u64 cap;
-       unsigned int val;
+       struct virtio_blk_config conf;
 
        /* This is the pipe the I/O thread will use to tell us I/O is done. */
        pipe(p);
@@ -1477,14 +1550,18 @@ static void setup_block_file(const char *filename)
        vblk->fd = open_or_die(filename, O_RDWR|O_LARGEFILE);
        vblk->len = lseek64(vblk->fd, 0, SEEK_END);
 
+       /* We support barriers. */
+       add_feature(dev, VIRTIO_BLK_F_BARRIER);
+
        /* Tell Guest how many sectors this device has. */
-       cap = cpu_to_le64(vblk->len / 512);
-       add_desc_field(dev, VIRTIO_CONFIG_BLK_F_CAPACITY, sizeof(cap), &cap);
+       conf.capacity = cpu_to_le64(vblk->len / 512);
 
        /* Tell Guest not to put in too many descriptors at once: two are used
         * for the in and out elements. */
-       val = cpu_to_le32(VIRTQUEUE_NUM - 2);
-       add_desc_field(dev, VIRTIO_CONFIG_BLK_F_SEG_MAX, sizeof(val), &val);
+       add_feature(dev, VIRTIO_BLK_F_SEG_MAX);
+       conf.seg_max = cpu_to_le32(VIRTQUEUE_NUM - 2);
+
+       set_config(dev, sizeof(conf), &conf);
 
        /* The I/O thread writes to this end of the pipe when done. */
        vblk->done_fd = p[1];
@@ -1505,7 +1582,7 @@ static void setup_block_file(const char *filename)
        close(vblk->workpipe[0]);
 
        verbose("device %u: virtblock %llu sectors\n",
-               devices.device_num, cap);
+               devices.device_num, le64_to_cpu(conf.capacity));
 }
 /* That's the end of device setup. :*/
 
@@ -1610,12 +1687,12 @@ int main(int argc, char *argv[])
        /* First we initialize the device list.  Since console and network
         * device receive input from a file descriptor, we keep an fdset
         * (infds) and the maximum fd number (max_infd) with the head of the
-        * list.  We also keep a pointer to the last device, for easy appending
-        * to the list.  Finally, we keep the next interrupt number to hand out
-        * (1: remember that 0 is used by the timer). */
+        * list.  We also keep a pointer to the last device.  Finally, we keep
+        * the next interrupt number to hand out (1: remember that 0 is used by
+        * the timer). */
        FD_ZERO(&devices.infds);
        devices.max_infd = -1;
-       devices.lastdev = &devices.dev;
+       devices.lastdev = NULL;
        devices.next_irq = 1;
 
        cpu_id = 0;
index 5818628207b5ec8b5f32ed6d727857f5f6dcbbec..396cdd982c26505ee39a577a64a7fb2c7472985e 100644 (file)
@@ -416,6 +416,16 @@ also have
      sectors in total that could need to be processed.  The two
      numbers are separated by a '/'  thus effectively showing one
      value, a fraction of the process that is complete.
+     A 'select' on this attribute will return when resync completes,
+     when it reaches the current sync_max (below) and possibly at
+     other times.
+
+   sync_max
+     This is a number of sectors at which point a resync/recovery
+     process will pause.  When a resync is active, the value can
+     only ever be increased, never decreased.  The value of 'max'
+     effectively disables the limit.
+
 
    sync_speed
      This shows the current actual speed, in K/sec, of the current
index badb7480ea6282904d7ff648629262fa0f632a97..d8968958d839ddb7d94a317c8ac83918c66a2b63 100644 (file)
@@ -60,7 +60,7 @@ operation of the local communications in any other way though.
 
 The kernel command line takes options looking like the following:
 
-    decnet=1,2
+    decnet.addr=1,2
 
 the two numbers are the node address 1,2 = 1.2 For 2.2.xx kernels
 and early 2.3.xx kernels, you must use a comma when specifying the
index 7754f5aea4e9b0bdd62280fb4f9fe88b23dce3fc..72b20c63959651ce7be7dad2f2e854c983f660e0 100644 (file)
@@ -274,8 +274,6 @@ the PCI device by calling pci_enable_device(). This will:
        o allocate an IRQ (if BIOS did not).
 
 NOTE: pci_enable_device() can fail! Check the return value.
-NOTE2: Also see pci_enable_device_bars() below. Drivers can
-    attempt to enable only a subset of BARs they need.
 
 [ OS BUG: we don't check resource allocations before enabling those
   resources. The sequence would make more sense if we called
@@ -605,40 +603,7 @@ device lists. This is still possible but discouraged.
 
 
 
-10. pci_enable_device_bars() and Legacy I/O Port space
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Large servers may not be able to provide I/O port resources to all PCI
-devices. I/O Port space is only 64KB on Intel Architecture[1] and is
-likely also fragmented since the I/O base register of PCI-to-PCI
-bridge will usually be aligned to a 4KB boundary[2]. On such systems,
-pci_enable_device() and pci_request_region() will fail when
-attempting to enable I/O Port regions that don't have I/O Port
-resources assigned.
-
-Fortunately, many PCI devices which request I/O Port resources also
-provide access to the same registers via MMIO BARs. These devices can
-be handled without using I/O port space and the drivers typically
-offer a CONFIG_ option to only use MMIO regions
-(e.g. CONFIG_TULIP_MMIO). PCI devices typically provide I/O port
-interface for legacy OSes and will work when I/O port resources are not
-assigned. The "PCI Local Bus Specification Revision 3.0" discusses
-this on p.44, "IMPLEMENTATION NOTE".
-
-If your PCI device driver doesn't need I/O port resources assigned to
-I/O Port BARs, you should use pci_enable_device_bars() instead of
-pci_enable_device() in order not to enable I/O port regions for the
-corresponding devices. In addition, you should use
-pci_request_selected_regions() and pci_release_selected_regions()
-instead of pci_request_regions()/pci_release_regions() in order not to
-request/release I/O port regions for the corresponding devices.
-
-[1] Some systems support 64KB I/O port space per PCI segment.
-[2] Some PCI-to-PCI bridges support optional 1KB aligned I/O base.
-
-
-
-11. MMIO Space and "Write Posting"
+10. MMIO Space and "Write Posting"
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Converting a driver from using I/O Port space to using MMIO space
index 4739c5c3face33164587d55749eb3f2f98c3674d..96f155e687506096e0f694591aa3b9fd722e4a48 100644 (file)
@@ -33,8 +33,8 @@ This file details changes in 2.6 which affect PCMCIA card driver authors:
    and can be used (e.g. for SET_NETDEV_DEV) by using
    handle_to_dev(client_handle_t * handle).
 
-* Convert internal I/O port addresses to unsigned long (as of 2.6.11)
-   ioaddr_t should be replaced by kio_addr_t in PCMCIA card drivers.
+* Convert internal I/O port addresses to unsigned int (as of 2.6.11)
+   ioaddr_t should be replaced by unsigned int in PCMCIA card drivers.
 
 * irq_mask and irq_list parameters (as of 2.6.11)
    The irq_mask and irq_list parameters should no longer be used in
diff --git a/Documentation/pm_qos_interface.txt b/Documentation/pm_qos_interface.txt
new file mode 100644 (file)
index 0000000..49adb1a
--- /dev/null
@@ -0,0 +1,59 @@
+PM quality of Service interface.
+
+This interface provides a kernel and user mode interface for registering
+performance expectations by drivers, subsystems and user space applications on
+one of the parameters.
+
+Currently we have {cpu_dma_latency, network_latency, network_throughput} as the
+initial set of pm_qos parameters.
+
+The infrastructure exposes multiple misc device nodes one per implemented
+parameter.  The set of parameters implement is defined by pm_qos_power_init()
+and pm_qos_params.h.  This is done because having the available parameters
+being runtime configurable or changeable from a driver was seen as too easy to
+abuse.
+
+For each parameter a list of performance requirements is maintained along with
+an aggregated target value.  The aggregated target value is updated with
+changes to the requirement list or elements of the list.  Typically the
+aggregated target value is simply the max or min of the requirement values held
+in the parameter list elements.
+
+From kernel mode the use of this interface is simple:
+pm_qos_add_requirement(param_id, name, target_value):
+Will insert a named element in the list for that identified PM_QOS parameter
+with the target value.  Upon change to this list the new target is recomputed
+and any registered notifiers are called only if the target value is now
+different.
+
+pm_qos_update_requirement(param_id, name, new_target_value):
+Will search the list identified by the param_id for the named list element and
+then update its target value, calling the notification tree if the aggregated
+target is changed.  with that name is already registered.
+
+pm_qos_remove_requirement(param_id, name):
+Will search the identified list for the named element and remove it, after
+removal it will update the aggregate target and call the notification tree if
+the target was changed as a result of removing the named requirement.
+
+
+From user mode:
+Only processes can register a pm_qos requirement.  To provide for automatic
+cleanup for process the interface requires the process to register its
+parameter requirements in the following way:
+
+To register the default pm_qos target for the specific parameter, the process
+must open one of /dev/[cpu_dma_latency, network_latency, network_throughput]
+
+As long as the device node is held open that process has a registered
+requirement on the parameter.  The name of the requirement is "process_<PID>"
+derived from the current->pid from within the open system call.
+
+To change the requested target value the process needs to write a s32 value to
+the open device node.  This translates to a pm_qos_update_requirement call.
+
+To remove the user mode request for a target value simply close the device
+node.
+
+
+
index 57aef2f6e0de6ad30673d8ce34a5430dc59ec5ab..1555001bc73394dbed7fccbc9a10917671e403e1 100644 (file)
-Debugging suspend and resume
+Debugging hibernation and suspend
        (C) 2007 Rafael J. Wysocki <rjw@sisk.pl>, GPL
 
-1. Testing suspend to disk (STD)
+1. Testing hibernation (aka suspend to disk or STD)
 
-To verify that the STD works, you can try to suspend in the "reboot" mode:
+To check if hibernation works, you can try to hibernate in the "reboot" mode:
 
 # echo reboot > /sys/power/disk
 # echo disk > /sys/power/state
 
-and the system should suspend, reboot, resume and get back to the command prompt
-where you have started the transition.  If that happens, the STD is most likely
-to work correctly, but you need to repeat the test at least a couple of times in
-a row for confidence.  This is necessary, because some problems only show up on
-a second attempt at suspending and resuming the system.  You should also test
-the "platform" and "shutdown" modes of suspend:
+and the system should create a hibernation image, reboot, resume and get back to
+the command prompt where you have started the transition.  If that happens,
+hibernation is most likely to work correctly.  Still, you need to repeat the
+test at least a couple of times in a row for confidence.  [This is necessary,
+because some problems only show up on a second attempt at suspending and
+resuming the system.]  Moreover, hibernating in the "reboot" and "shutdown"
+modes causes the PM core to skip some platform-related callbacks which on ACPI
+systems might be necessary to make hibernation work.  Thus, if you machine fails
+to hibernate or resume in the "reboot" mode, you should try the "platform" mode:
 
 # echo platform > /sys/power/disk
 # echo disk > /sys/power/state
 
-or
+which is the default and recommended mode of hibernation.
+
+Unfortunately, the "platform" mode of hibernation does not work on some systems
+with broken BIOSes.  In such cases the "shutdown" mode of hibernation might
+work:
 
 # echo shutdown > /sys/power/disk
 # echo disk > /sys/power/state
 
-in which cases you will have to press the power button to make the system
-resume.  If that does not work, you will need to identify what goes wrong.
+(it is similar to the "reboot" mode, but it requires you to press the power
+button to make the system resume).
+
+If neither "platform" nor "shutdown" hibernation mode works, you will need to
+identify what goes wrong.
+
+a) Test modes of hibernation
+
+To find out why hibernation fails on your system, you can use a special testing
+facility available if the kernel is compiled with CONFIG_PM_DEBUG set.  Then,
+there is the file /sys/power/pm_test that can be used to make the hibernation
+core run in a test mode.  There are 5 test modes available:
+
+freezer
+- test the freezing of processes
+
+devices
+- test the freezing of processes and suspending of devices
 
-a) Test mode of STD
+platform
+- test the freezing of processes, suspending of devices and platform
+  global control methods(*)
 
-To verify if there are any drivers that cause problems you can run the STD
-in the test mode:
+processors
+- test the freezing of processes, suspending of devices, platform
+  global control methods(*) and the disabling of nonboot CPUs
 
-# echo test > /sys/power/disk
+core
+- test the freezing of processes, suspending of devices, platform global
+  control methods(*), the disabling of nonboot CPUs and suspending of
+  platform/system devices
+
+(*) the platform global control methods are only available on ACPI systems
+    and are only tested if the hibernation mode is set to "platform"
+
+To use one of them it is necessary to write the corresponding string to
+/sys/power/pm_test (eg. "devices" to test the freezing of processes and
+suspending devices) and issue the standard hibernation commands.  For example,
+to use the "devices" test mode along with the "platform" mode of hibernation,
+you should do the following:
+
+# echo devices > /sys/power/pm_test
+# echo platform > /sys/power/disk
 # echo disk > /sys/power/state
 
-in which case the system should freeze tasks, suspend devices, disable nonboot
-CPUs (if any), wait for 5 seconds, enable nonboot CPUs, resume devices, thaw
-tasks and return to your command prompt.  If that fails, most likely there is
-a driver that fails to either suspend or resume (in the latter case the system
-may hang or be unstable after the test, so please take that into consideration).
-To find this driver, you can carry out a binary search according to the rules:
+Then, the kernel will try to freeze processes, suspend devices, wait 5 seconds,
+resume devices and thaw processes.  If "platform" is written to
+/sys/power/pm_test , then after suspending devices the kernel will additionally
+invoke the global control methods (eg. ACPI global control methods) used to
+prepare the platform firmware for hibernation.  Next, it will wait 5 seconds and
+invoke the platform (eg. ACPI) global methods used to cancel hibernation etc.
+
+Writing "none" to /sys/power/pm_test causes the kernel to switch to the normal
+hibernation/suspend operations.  Also, when open for reading, /sys/power/pm_test
+contains a space-separated list of all available tests (including "none" that
+represents the normal functionality) in which the current test level is
+indicated by square brackets.
+
+Generally, as you can see, each test level is more "invasive" than the previous
+one and the "core" level tests the hardware and drivers as deeply as possible
+without creating a hibernation image.  Obviously, if the "devices" test fails,
+the "platform" test will fail as well and so on.  Thus, as a rule of thumb, you
+should try the test modes starting from "freezer", through "devices", "platform"
+and "processors" up to "core" (repeat the test on each level a couple of times
+to make sure that any random factors are avoided).
+
+If the "freezer" test fails, there is a task that cannot be frozen (in that case
+it usually is possible to identify the offending task by analysing the output of
+dmesg obtained after the failing test).  Failure at this level usually means
+that there is a problem with the tasks freezer subsystem that should be
+reported.
+
+If the "devices" test fails, most likely there is a driver that cannot suspend
+or resume its device (in the latter case the system may hang or become unstable
+after the test, so please take that into consideration).  To find this driver,
+you can carry out a binary search according to the rules:
 - if the test fails, unload a half of the drivers currently loaded and repeat
 (that would probably involve rebooting the system, so always note what drivers
 have been loaded before the test),
@@ -47,23 +113,46 @@ have been loaded before the test),
 recently and repeat.
 
 Once you have found the failing driver (there can be more than just one of
-them), you have to unload it every time before the STD transition.  In that case
-please make sure to report the problem with the driver.
-
-It is also possible that a cycle can still fail after you have unloaded
-all modules. In that case, you would want to look in your kernel configuration
-for the drivers that can be compiled as modules (testing again with them as
-modules), and possibly also try boot time options such as "noapic" or "noacpi".
+them), you have to unload it every time before hibernation.  In that case please
+make sure to report the problem with the driver.
+
+It is also possible that the "devices" test will still fail after you have
+unloaded all modules. In that case, you may want to look in your kernel
+configuration for the drivers that can be compiled as modules (and test again
+with these drivers compiled as modules).  You may also try to use some special
+kernel command line options such as "noapic", "noacpi" or even "acpi=off".
+
+If the "platform" test fails, there is a problem with the handling of the
+platform (eg. ACPI) firmware on your system.  In that case the "platform" mode
+of hibernation is not likely to work.  You can try the "shutdown" mode, but that
+is rather a poor man's workaround.
+
+If the "processors" test fails, the disabling/enabling of nonboot CPUs does not
+work (of course, this only may be an issue on SMP systems) and the problem
+should be reported.  In that case you can also try to switch the nonboot CPUs
+off and on using the /sys/devices/system/cpu/cpu*/online sysfs attributes and
+see if that works.
+
+If the "core" test fails, which means that suspending of the system/platform
+devices has failed (these devices are suspended on one CPU with interrupts off),
+the problem is most probably hardware-related and serious, so it should be
+reported.
+
+A failure of any of the "platform", "processors" or "core" tests may cause your
+system to hang or become unstable, so please beware.  Such a failure usually
+indicates a serious problem that very well may be related to the hardware, but
+please report it anyway.
 
 b) Testing minimal configuration
 
-If the test mode of STD works, you can boot the system with "init=/bin/bash"
-and attempt to suspend in the "reboot", "shutdown" and "platform" modes.  If
-that does not work, there probably is a problem with a driver statically
-compiled into the kernel and you can try to compile more drivers as modules,
-so that they can be tested individually.  Otherwise, there is a problem with a
-modular driver and you can find it by loading a half of the modules you normally
-use and binary searching in accordance with the algorithm:
+If all of the hibernation test modes work, you can boot the system with the
+"init=/bin/bash" command line parameter and attempt to hibernate in the
+"reboot", "shutdown" and "platform" modes.  If that does not work, there
+probably is a problem with a driver statically compiled into the kernel and you
+can try to compile more drivers as modules, so that they can be tested
+individually.  Otherwise, there is a problem with a modular driver and you can
+find it by loading a half of the modules you normally use and binary searching
+in accordance with the algorithm:
 - if there are n modules loaded and the attempt to suspend and resume fails,
 unload n/2 of the modules and try again (that would probably involve rebooting
 the system),
@@ -71,19 +160,19 @@ the system),
 load n/2 modules more and try again.
 
 Again, if you find the offending module(s), it(they) must be unloaded every time
-before the STD transition, and please report the problem with it(them).
+before hibernation, and please report the problem with it(them).
 
 c) Advanced debugging
 
-In case the STD does not work on your system even in the minimal configuration
-and compiling more drivers as modules is not practical or some modules cannot
-be unloaded, you can use one of the more advanced debugging techniques to find
-the problem.  First, if there is a serial port in your box, you can boot the
-kernel with the 'no_console_suspend' parameter and try to log kernel
-messages using the serial console.  This may provide you with some information
-about the reasons of the suspend (resume) failure.  Alternatively, it may be
-possible to use a FireWire port for debugging with firescope
-(ftp://ftp.firstfloor.org/pub/ak/firescope/).  On i386 it is also possible to
+In case that hibernation does not work on your system even in the minimal
+configuration and compiling more drivers as modules is not practical or some
+modules cannot be unloaded, you can use one of the more advanced debugging
+techniques to find the problem.  First, if there is a serial port in your box,
+you can boot the kernel with the 'no_console_suspend' parameter and try to log
+kernel messages using the serial console.  This may provide you with some
+information about the reasons of the suspend (resume) failure.  Alternatively,
+it may be possible to use a FireWire port for debugging with firescope
+(ftp://ftp.firstfloor.org/pub/ak/firescope/).  On x86 it is also possible to
 use the PM_TRACE mechanism documented in Documentation/s2ram.txt .
 
 2. Testing suspend to RAM (STR)
@@ -91,16 +180,25 @@ use the PM_TRACE mechanism documented in Documentation/s2ram.txt .
 To verify that the STR works, it is generally more convenient to use the s2ram
 tool available from http://suspend.sf.net and documented at
 http://en.opensuse.org/s2ram .  However, before doing that it is recommended to
-carry out the procedure described in section 1.
-
-Assume you have resolved the problems with the STD and you have found some
-failing drivers.  These drivers are also likely to fail during the STR or
-during the resume, so it is better to unload them every time before the STR
-transition.  Now, you can follow the instructions at
-http://en.opensuse.org/s2ram to test the system, but if it does not work
-"out of the box", you may need to boot it with "init=/bin/bash" and test
-s2ram in the minimal configuration.  In that case, you may be able to search
-for failing drivers by following the procedure analogous to the one described in
-1b).  If you find some failing drivers, you will have to unload them every time
-before the STR transition (ie. before you run s2ram), and please report the
-problems with them.
+carry out STR testing using the facility described in section 1.
+
+Namely, after writing "freezer", "devices", "platform", "processors", or "core"
+into /sys/power/pm_test (available if the kernel is compiled with
+CONFIG_PM_DEBUG set) the suspend code will work in the test mode corresponding
+to given string.  The STR test modes are defined in the same way as for
+hibernation, so please refer to Section 1 for more information about them.  In
+particular, the "core" test allows you to test everything except for the actual
+invocation of the platform firmware in order to put the system into the sleep
+state.
+
+Among other things, the testing with the help of /sys/power/pm_test may allow
+you to identify drivers that fail to suspend or resume their devices.  They
+should be unloaded every time before an STR transition.
+
+Next, you can follow the instructions at http://en.opensuse.org/s2ram to test
+the system, but if it does not work "out of the box", you may need to boot it
+with "init=/bin/bash" and test s2ram in the minimal configuration.  In that
+case, you may be able to search for failing drivers by following the procedure
+analogous to the one described in section 1.  If you find some failing drivers,
+you will have to unload them every time before an STR transition (ie. before
+you run s2ram), and please report the problems with them.
index d0e79d5820a5e7a7237f36a1cb5776ec589552d8..c53d263619194f7e04719e0a7250944b0134d598 100644 (file)
@@ -502,52 +502,3 @@ If the CPU can have a "cpufreq" driver, there also may be opportunities
 to shift to lower voltage settings and reduce the power cost of executing
 a given number of instructions.  (Without voltage adjustment, it's rare
 for cpufreq to save much power; the cost-per-instruction must go down.)
-
-
-/sys/devices/.../power/state files
-==================================
-For now you can also test some of this functionality using sysfs.
-
-       DEPRECATED:  USE "power/state" ONLY FOR DRIVER TESTING, AND
-       AVOID USING dev->power.power_state IN DRIVERS.
-
-       THESE WILL BE REMOVED.  IF THE "power/state" FILE GETS REPLACED,
-       IT WILL BECOME SOMETHING COUPLED TO THE BUS OR DRIVER.
-
-In each device's directory, there is a 'power' directory, which contains
-at least a 'state' file.  The value of this field is effectively boolean,
-PM_EVENT_ON or PM_EVENT_SUSPEND.
-
-   *   Reading from this file displays a value corresponding to
-       the power.power_state.event field.  All nonzero values are
-       displayed as "2", corresponding to a low power state; zero
-       is displayed as "0", corresponding to normal operation.
-
-   *   Writing to this file initiates a transition using the
-       specified event code number; only '0', '2', and '3' are
-       accepted (without a newline); '2' and '3' are both
-       mapped to PM_EVENT_SUSPEND.
-
-On writes, the PM core relies on that recorded event code and the device/bus
-capabilities to determine whether it uses a partial suspend() or resume()
-sequence to change things so that the recorded event corresponds to the
-numeric parameter.
-
-   -   If the bus requires the irqs-disabled suspend_late()/resume_early()
-       phases, writes fail because those operations are not supported here.
-
-   -   If the recorded value is the expected value, nothing is done.
-
-   -   If the recorded value is nonzero, the device is partially resumed,
-       using the bus.resume() and/or class.resume() methods.
-
-   -   If the target value is nonzero, the device is partially suspended,
-       using the class.suspend() and/or bus.suspend() methods and the
-       PM_EVENT_SUSPEND message.
-
-Drivers have no way to tell whether their suspend() and resume() calls
-have come through the sysfs power/state file or as part of entering a
-system sleep state, except that when accessed through sysfs the normal
-parent/child sequencing rules are ignored.  Drivers (such as bus, bridge,
-or hub drivers) which expose child devices may need to enforce those rules
-on their own.
index e4bdcaee24e46e6805caf0e0a9edfc9d57638402..7f7a737f7f9fd785deacaf4f3aaaf56d87a21c11 100644 (file)
@@ -6,9 +6,9 @@ Testing suspend and resume support in device drivers
 Unfortunately, to effectively test the support for the system-wide suspend and
 resume transitions in a driver, it is necessary to suspend and resume a fully
 functional system with this driver loaded.  Moreover, that should be done
-several times, preferably several times in a row, and separately for the suspend
-to disk (STD) and the suspend to RAM (STR) transitions, because each of these
-cases involves different ordering of operations and different interactions with
+several times, preferably several times in a row, and separately for hibernation
+(aka suspend to disk or STD) and suspend to RAM (STR), because each of these
+cases involves slightly different operations and different interactions with
 the machine's BIOS.
 
 Of course, for this purpose the test system has to be known to suspend and
@@ -22,20 +22,24 @@ for more information about the debugging of suspend/resume functionality.
 Once you have resolved the suspend/resume-related problems with your test system
 without the new driver, you are ready to test it:
 
-a) Build the driver as a module, load it and try the STD in the test mode (see:
-Documents/power/basic-pm-debugging.txt, 1a)).
+a) Build the driver as a module, load it and try the test modes of hibernation
+   (see: Documents/power/basic-pm-debugging.txt, 1).
 
-b) Load the driver and attempt to suspend to disk in the "reboot", "shutdown"
-and "platform" modes (see: Documents/power/basic-pm-debugging.txt, 1).
+b) Load the driver and attempt to hibernate in the "reboot", "shutdown" and
+   "platform" modes (see: Documents/power/basic-pm-debugging.txt, 1).
 
-c) Compile the driver directly into the kernel and try the STD in the test mode.
+c) Compile the driver directly into the kernel and try the test modes of
+   hibernation.
 
-d) Attempt to suspend to disk with the driver compiled directly into the kernel
-in the "reboot", "shutdown" and "platform" modes.
+d) Attempt to hibernate with the driver compiled directly into the kernel
+   in the "reboot", "shutdown" and "platform" modes.
 
-e) Attempt to suspend to RAM using the s2ram tool with the driver loaded (see:
-Documents/power/basic-pm-debugging.txt, 2).  As far as the STR tests are
-concerned, it should not matter whether or not the driver is built as a module.
+e) Try the test modes of suspend (see: Documents/power/basic-pm-debugging.txt,
+   2).  [As far as the STR tests are concerned, it should not matter whether or
+   not the driver is built as a module.]
+
+f) Attempt to suspend to RAM using the s2ram tool with the driver loaded
+   (see: Documents/power/basic-pm-debugging.txt, 2).
 
 Each of the above tests should be repeated several times and the STD tests
 should be mixed with the STR tests.  If any of them fails, the driver cannot be
index 9293e4bc857c6bb7a049b8951c97ee42ab306d9c..ae1b7ec07684bad822171767bba66fc9798cc204 100644 (file)
@@ -28,6 +28,14 @@ PM_POST_HIBERNATION  The system memory state has been restored from a
                        hibernation.  Device drivers' .resume() callbacks have
                        been executed and tasks have been thawed.
 
+PM_RESTORE_PREPARE     The system is going to restore a hibernation image.
+                       If all goes well the restored kernel will issue a
+                       PM_POST_HIBERNATION notification.
+
+PM_POST_RESTORE                An error occurred during the hibernation restore.
+                       Device drivers' .resume() callbacks have been executed
+                       and tasks have been thawed.
+
 PM_SUSPEND_PREPARE     The system is preparing for a suspend.
 
 PM_POST_SUSPEND                The system has just resumed or an error occured during
index e00c6cf09e85aad17e587f0ac9d19d0a543a4cad..7b99636564c8cbc608ff6fb1a24b883c254bf8e3 100644 (file)
@@ -14,7 +14,7 @@ are going to develop your own suspend/resume utilities.
 
 The interface consists of a character device providing the open(),
 release(), read(), and write() operations as well as several ioctl()
-commands defined in kernel/power/power.h.  The major and minor
+commands defined in include/linux/suspend_ioctls.h .  The major and minor
 numbers of the device are, respectively, 10 and 231, and they can
 be read from /sys/class/misc/snapshot/dev.
 
@@ -27,17 +27,17 @@ once at a time.
 The ioctl() commands recognized by the device are:
 
 SNAPSHOT_FREEZE - freeze user space processes (the current process is
-       not frozen); this is required for SNAPSHOT_ATOMIC_SNAPSHOT
+       not frozen); this is required for SNAPSHOT_CREATE_IMAGE
        and SNAPSHOT_ATOMIC_RESTORE to succeed
 
 SNAPSHOT_UNFREEZE - thaw user space processes frozen by SNAPSHOT_FREEZE
 
-SNAPSHOT_ATOMIC_SNAPSHOT - create a snapshot of the system memory; the
+SNAPSHOT_CREATE_IMAGE - create a snapshot of the system memory; the
        last argument of ioctl() should be a pointer to an int variable,
        the value of which will indicate whether the call returned after
        creating the snapshot (1) or after restoring the system memory state
        from it (0) (after resume the system finds itself finishing the
-       SNAPSHOT_ATOMIC_SNAPSHOT ioctl() again); after the snapshot
+       SNAPSHOT_CREATE_IMAGE ioctl() again); after the snapshot
        has been created the read() operation can be used to transfer
        it out of the kernel
 
@@ -49,39 +49,37 @@ SNAPSHOT_ATOMIC_RESTORE - restore the system memory state from the
 
 SNAPSHOT_FREE - free memory allocated for the snapshot image
 
-SNAPSHOT_SET_IMAGE_SIZE - set the preferred maximum size of the image
+SNAPSHOT_PREF_IMAGE_SIZE - set the preferred maximum size of the image
        (the kernel will do its best to ensure the image size will not exceed
        this number, but if it turns out to be impossible, the kernel will
        create the smallest image possible)
 
-SNAPSHOT_AVAIL_SWAP - return the amount of available swap in bytes (the last
-       argument should be a pointer to an unsigned int variable that will
+SNAPSHOT_GET_IMAGE_SIZE - return the actual size of the hibernation image
+
+SNAPSHOT_AVAIL_SWAP_SIZE - return the amount of available swap in bytes (the
+       last argument should be a pointer to an unsigned int variable that will
        contain the result if the call is successful).
 
-SNAPSHOT_GET_SWAP_PAGE - allocate a swap page from the resume partition
+SNAPSHOT_ALLOC_SWAP_PAGE - allocate a swap page from the resume partition
        (the last argument should be a pointer to a loff_t variable that
        will contain the swap page offset if the call is successful)
 
-SNAPSHOT_FREE_SWAP_PAGES - free all swap pages allocated with
-       SNAPSHOT_GET_SWAP_PAGE
-
-SNAPSHOT_SET_SWAP_FILE - set the resume partition (the last ioctl() argument
-       should specify the device's major and minor numbers in the old
-       two-byte format, as returned by the stat() function in the .st_rdev
-       member of the stat structure)
+SNAPSHOT_FREE_SWAP_PAGES - free all swap pages allocated by
+       SNAPSHOT_ALLOC_SWAP_PAGE
 
 SNAPSHOT_SET_SWAP_AREA - set the resume partition and the offset (in <PAGE_SIZE>
        units) from the beginning of the partition at which the swap header is
        located (the last ioctl() argument should point to a struct
-       resume_swap_area, as defined in kernel/power/power.h, containing the
-       resume device specification, as for the SNAPSHOT_SET_SWAP_FILE ioctl(),
-       and the offset); for swap partitions the offset is always 0, but it is
-       different to zero for swap files (please see
-       Documentation/swsusp-and-swap-files.txt for details).
-       The SNAPSHOT_SET_SWAP_AREA ioctl() is considered as a replacement for
-       SNAPSHOT_SET_SWAP_FILE which is regarded as obsolete.   It is
-       recommended to always use this call, because the code to set the resume
-       partition may be removed from future kernels
+       resume_swap_area, as defined in kernel/power/suspend_ioctls.h,
+       containing the resume device specification and the offset); for swap
+       partitions the offset is always 0, but it is different from zero for
+       swap files (see Documentation/swsusp-and-swap-files.txt for details).
+
+SNAPSHOT_PLATFORM_SUPPORT - enable/disable the hibernation platform support,
+       depending on the argument value (enable, if the argument is nonzero)
+
+SNAPSHOT_POWER_OFF - make the kernel transition the system to the hibernation
+       state (eg. ACPI S4) using the platform (eg. ACPI) driver
 
 SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to
        immediately enter the suspend-to-RAM state, so this call must always
@@ -93,24 +91,6 @@ SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to
        to resume the system from RAM if there's enough battery power or restore
        its state on the basis of the saved suspend image otherwise)
 
-SNAPSHOT_PMOPS - enable the usage of the hibernation_ops->prepare,
-       hibernate_ops->enter and hibernation_ops->finish methods (the in-kernel
-       swsusp knows these as the "platform method") which are needed on many
-       machines to (among others) speed up the resume by letting the BIOS skip
-       some steps or to let the system recognise the correct state of the
-       hardware after the resume (in particular on many machines this ensures
-       that unplugged AC adapters get correctly detected and that kacpid does
-       not run wild after the resume).  The last ioctl() argument can take one
-       of the three values, defined in kernel/power/power.h:
-       PMOPS_PREPARE - make the kernel carry out the
-               hibernation_ops->prepare() operation
-       PMOPS_ENTER - make the kernel power off the system by calling
-               hibernation_ops->enter()
-       PMOPS_FINISH - make the kernel carry out the
-               hibernation_ops->finish() operation
-       Note that the actual constants are misnamed because they surface
-       internal kernel implementation details that have changed.
-
 The device's read() operation can be used to transfer the snapshot image from
 the kernel.  It has the following limitations:
 - you cannot read() more than one virtual memory page at a time
@@ -122,7 +102,7 @@ The device's write() operation is used for uploading the system memory snapshot
 into the kernel.  It has the same limitations as the read() operation.
 
 The release() operation frees all memory allocated for the snapshot image
-and all swap pages allocated with SNAPSHOT_GET_SWAP_PAGE (if any).
+and all swap pages allocated with SNAPSHOT_ALLOC_SWAP_PAGE (if any).
 Thus it is not necessary to use either SNAPSHOT_FREE or
 SNAPSHOT_FREE_SWAP_PAGES before closing the device (in fact it will also
 unfreeze user space processes frozen by SNAPSHOT_UNFREEZE if they are
@@ -133,16 +113,12 @@ snapshot image from/to the kernel will use a swap parition, called the resume
 partition, or a swap file as storage space (if a swap file is used, the resume
 partition is the partition that holds this file).  However, this is not really
 required, as they can use, for example, a special (blank) suspend partition or
-a file on a partition that is unmounted before SNAPSHOT_ATOMIC_SNAPSHOT and
+a file on a partition that is unmounted before SNAPSHOT_CREATE_IMAGE and
 mounted afterwards.
 
-These utilities SHOULD NOT make any assumptions regarding the ordering of
-data within the snapshot image, except for the image header that MAY be
-assumed to start with an swsusp_info structure, as specified in
-kernel/power/power.h.  This structure MAY be used by the userland utilities
-to obtain some information about the snapshot image, such as the size
-of the snapshot image, including the metadata and the header itself,
-contained in the .size member of swsusp_info.
+These utilities MUST NOT make any assumptions regarding the ordering of
+data within the snapshot image.  The contents of the image are entirely owned
+by the kernel and its structure may be changed in future kernel releases.
 
 The snapshot image MUST be written to the kernel unaltered (ie. all of the image
 data, metadata and header MUST be written in _exactly_ the same amount, form
@@ -159,7 +135,7 @@ means, such as checksums, to ensure the integrity of the snapshot image.
 The suspending and resuming utilities MUST lock themselves in memory,
 preferrably using mlockall(), before calling SNAPSHOT_FREEZE.
 
-The suspending utility MUST check the value stored by SNAPSHOT_ATOMIC_SNAPSHOT
+The suspending utility MUST check the value stored by SNAPSHOT_CREATE_IMAGE
 in the memory location pointed to by the last argument of ioctl() and proceed
 in accordance with it:
 1.     If the value is 1 (ie. the system memory snapshot has just been
@@ -173,7 +149,7 @@ in accordance with it:
                image has been saved.
        (b)     The suspending utility SHOULD NOT attempt to perform any
                file system operations (including reads) on the file systems
-               that were mounted before SNAPSHOT_ATOMIC_SNAPSHOT has been
+               that were mounted before SNAPSHOT_CREATE_IMAGE has been
                called.  However, it MAY mount a file system that was not
                mounted at that time and perform some operations on it (eg.
                use it for saving the image).
index 9758cf433c0660f7f971f3958c5ffddbcb1a884a..a8686e5a68579fc207d4c12e59246d7aee58ffcd 100644 (file)
@@ -87,6 +87,10 @@ batteries use voltage for very approximated calculation of capacity.
 Battery driver also can use this attribute just to inform userspace
 about maximal and minimal voltage thresholds of a given battery.
 
+VOLTAGE_MAX, VOLTAGE_MIN - same as _DESIGN voltage values except that
+these ones should be used if hardware could only guess (measure and
+retain) the thresholds of a given power supply.
+
 CHARGE_FULL_DESIGN, CHARGE_EMPTY_DESIGN - design charge values, when
 battery considered full/empty.
 
@@ -100,8 +104,6 @@ age)". I.e. these attributes represents real thresholds, not design values.
 ENERGY_FULL, ENERGY_EMPTY - same as above but for energy.
 
 CAPACITY - capacity in percents.
-CAPACITY_LEVEL - capacity level. This corresponds to
-POWER_SUPPLY_CAPACITY_LEVEL_*.
 
 TEMP - temperature of the power supply.
 TEMP_AMBIENT - ambient temperature.
index e20b19c1b60da04b95cfc62a0cec57428a53bb12..8deffcd68cb8d3fc2737279e780a28bee3726f57 100644 (file)
@@ -182,8 +182,8 @@ driver returns ENOIOCTLCMD.  Some common examples:
        since the frequency is stored in the irq_freq member of the rtc_device
        structure.  Your driver needs to initialize the irq_freq member during
        init.  Make sure you check the requested frequency is in range of your
-       hardware in the irq_set_freq function.  If you cannot actually change
-       the frequency, just return -ENOTTY.
+       hardware in the irq_set_freq function.  If it isn't, return -EINVAL.  If
+       you cannot actually change the frequency, do not define irq_set_freq.
 
 If all else fails, check out the rtc-test.c driver!
 
@@ -268,8 +268,8 @@ int main(int argc, char **argv)
                /* This read will block */
                retval = read(fd, &data, sizeof(unsigned long));
                if (retval == -1) {
-                       perror("read");
-                       exit(errno);
+                       perror("read");
+                       exit(errno);
                }
                fprintf(stderr, " %d",i);
                fflush(stderr);
@@ -326,11 +326,11 @@ test_READ:
                rtc_tm.tm_sec %= 60;
                rtc_tm.tm_min++;
        }
-       if  (rtc_tm.tm_min == 60) {
+       if (rtc_tm.tm_min == 60) {
                rtc_tm.tm_min = 0;
                rtc_tm.tm_hour++;
        }
-       if  (rtc_tm.tm_hour == 24)
+       if (rtc_tm.tm_hour == 24)
                rtc_tm.tm_hour = 0;
 
        retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
@@ -407,8 +407,8 @@ test_PIE:
                                        "\n...Periodic IRQ rate is fixed\n");
                                goto done;
                        }
-                       perror("RTC_IRQP_SET ioctl");
-                       exit(errno);
+                       perror("RTC_IRQP_SET ioctl");
+                       exit(errno);
                }
 
                fprintf(stderr, "\n%ldHz:\t", tmp);
@@ -417,27 +417,27 @@ test_PIE:
                /* Enable periodic interrupts */
                retval = ioctl(fd, RTC_PIE_ON, 0);
                if (retval == -1) {
-                       perror("RTC_PIE_ON ioctl");
-                       exit(errno);
+                       perror("RTC_PIE_ON ioctl");
+                       exit(errno);
                }
 
                for (i=1; i<21; i++) {
-                       /* This blocks */
-                       retval = read(fd, &data, sizeof(unsigned long));
-                       if (retval == -1) {
-                                      perror("read");
-                                      exit(errno);
-                       }
-                       fprintf(stderr, " %d",i);
-                       fflush(stderr);
-                       irqcount++;
+                       /* This blocks */
+                       retval = read(fd, &data, sizeof(unsigned long));
+                       if (retval == -1) {
+                               perror("read");
+                               exit(errno);
+                       }
+                       fprintf(stderr, " %d",i);
+                       fflush(stderr);
+                       irqcount++;
                }
 
                /* Disable periodic interrupts */
                retval = ioctl(fd, RTC_PIE_OFF, 0);
                if (retval == -1) {
-                       perror("RTC_PIE_OFF ioctl");
-                       exit(errno);
+                       perror("RTC_PIE_OFF ioctl");
+                       exit(errno);
                }
        }
 
diff --git a/Documentation/smp.txt b/Documentation/smp.txt
deleted file mode 100644 (file)
index 82fc50b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-To set up SMP
-
-Configure the kernel and answer Y to CONFIG_SMP.
-
-If you are using LILO, it is handy to have both SMP and non-SMP
-kernel images on hand. Edit /etc/lilo.conf to create an entry
-for another kernel image called "linux-smp" or something.
-
-The next time you compile the kernel, when running a SMP kernel,
-edit linux/Makefile and change "MAKE=make" to "MAKE=make -jN"
-(where N = number of CPU + 1, or if you have tons of memory/swap
- you can just use "-j" without a number). Feel free to experiment
-with this one.
-
-Of course you should time how long each build takes :-)
-Example:
-   make config
-   time -v sh -c 'make clean install modules modules_install'
-
-If you are using some Compaq MP compliant machines you will need to set
-the operating system in the BIOS settings to "Unixware" - don't ask me
-why Compaqs don't work otherwise.
index aa986a35e9945071abed471776565a2cf4644787..f99254327ae59b59971d979b38cc083d3ac096e5 100644 (file)
@@ -23,6 +23,7 @@ Currently, these files are in /proc/sys/fs:
 - inode-max
 - inode-nr
 - inode-state
+- nr_open
 - overflowuid
 - overflowgid
 - suid_dumpable
@@ -91,6 +92,15 @@ usage of file handles and you don't need to increase the maximum.
 
 ==============================================================
 
+nr_open:
+
+This denotes the maximum number of file-handles a process can
+allocate. Default value is 1024*1024 (1048576) which should be
+enough for most machines. Actual limit depends on RLIMIT_NOFILE
+resource limit.
+
+==============================================================
+
 inode-max, inode-nr & inode-state:
 
 As with file handles, the kernel allocates the inode structures
index 6f31f0a247d03137b85955bf59d06a666e34b1a0..24eac1bc735d733df28901555eefe36217d5dd2a 100644 (file)
@@ -22,6 +22,7 @@ Currently, these files are in /proc/sys/vm:
 - dirty_background_ratio
 - dirty_expire_centisecs
 - dirty_writeback_centisecs
+- highmem_is_dirtyable   (only if CONFIG_HIGHMEM set)
 - max_map_count
 - min_free_kbytes
 - laptop_mode
@@ -40,9 +41,9 @@ Currently, these files are in /proc/sys/vm:
 ==============================================================
 
 dirty_ratio, dirty_background_ratio, dirty_expire_centisecs,
-dirty_writeback_centisecs, vfs_cache_pressure, laptop_mode,
-block_dump, swap_token_timeout, drop-caches,
-hugepages_treat_as_movable:
+dirty_writeback_centisecs, highmem_is_dirtyable,
+vfs_cache_pressure, laptop_mode, block_dump, swap_token_timeout,
+drop-caches, hugepages_treat_as_movable:
 
 See Documentation/filesystems/proc.txt
 
diff --git a/Documentation/unaligned-memory-access.txt b/Documentation/unaligned-memory-access.txt
new file mode 100644 (file)
index 0000000..6223eac
--- /dev/null
@@ -0,0 +1,226 @@
+UNALIGNED MEMORY ACCESSES
+=========================
+
+Linux runs on a wide variety of architectures which have varying behaviour
+when it comes to memory access. This document presents some details about
+unaligned accesses, why you need to write code that doesn't cause them,
+and how to write such code!
+
+
+The definition of an unaligned access
+=====================================
+
+Unaligned memory accesses occur when you try to read N bytes of data starting
+from an address that is not evenly divisible by N (i.e. addr % N != 0).
+For example, reading 4 bytes of data from address 0x10004 is fine, but
+reading 4 bytes of data from address 0x10005 would be an unaligned memory
+access.
+
+The above may seem a little vague, as memory access can happen in different
+ways. The context here is at the machine code level: certain instructions read
+or write a number of bytes to or from memory (e.g. movb, movw, movl in x86
+assembly). As will become clear, it is relatively easy to spot C statements
+which will compile to multiple-byte memory access instructions, namely when
+dealing with types such as u16, u32 and u64.
+
+
+Natural alignment
+=================
+
+The rule mentioned above forms what we refer to as natural alignment:
+When accessing N bytes of memory, the base memory address must be evenly
+divisible by N, i.e. addr % N == 0.
+
+When writing code, assume the target architecture has natural alignment
+requirements.
+
+In reality, only a few architectures require natural alignment on all sizes
+of memory access. However, we must consider ALL supported architectures;
+writing code that satisfies natural alignment requirements is the easiest way
+to achieve full portability.
+
+
+Why unaligned access is bad
+===========================
+
+The effects of performing an unaligned memory access vary from architecture
+to architecture. It would be easy to write a whole document on the differences
+here; a summary of the common scenarios is presented below:
+
+ - Some architectures are able to perform unaligned memory accesses
+   transparently, but there is usually a significant performance cost.
+ - Some architectures raise processor exceptions when unaligned accesses
+   happen. The exception handler is able to correct the unaligned access,
+   at significant cost to performance.
+ - Some architectures raise processor exceptions when unaligned accesses
+   happen, but the exceptions do not contain enough information for the
+   unaligned access to be corrected.
+ - Some architectures are not capable of unaligned memory access, but will
+   silently perform a different memory access to the one that was requested,
+   resulting a a subtle code bug that is hard to detect!
+
+It should be obvious from the above that if your code causes unaligned
+memory accesses to happen, your code will not work correctly on certain
+platforms and will cause performance problems on others.
+
+
+Code that does not cause unaligned access
+=========================================
+
+At first, the concepts above may seem a little hard to relate to actual
+coding practice. After all, you don't have a great deal of control over
+memory addresses of certain variables, etc.
+
+Fortunately things are not too complex, as in most cases, the compiler
+ensures that things will work for you. For example, take the following
+structure:
+
+       struct foo {
+               u16 field1;
+               u32 field2;
+               u8 field3;
+       };
+
+Let us assume that an instance of the above structure resides in memory
+starting at address 0x10000. With a basic level of understanding, it would
+not be unreasonable to expect that accessing field2 would cause an unaligned
+access. You'd be expecting field2 to be located at offset 2 bytes into the
+structure, i.e. address 0x10002, but that address is not evenly divisible
+by 4 (remember, we're reading a 4 byte value here).
+
+Fortunately, the compiler understands the alignment constraints, so in the
+above case it would insert 2 bytes of padding in between field1 and field2.
+Therefore, for standard structure types you can always rely on the compiler
+to pad structures so that accesses to fields are suitably aligned (assuming
+you do not cast the field to a type of different length).
+
+Similarly, you can also rely on the compiler to align variables and function
+parameters to a naturally aligned scheme, based on the size of the type of
+the variable.
+
+At this point, it should be clear that accessing a single byte (u8 or char)
+will never cause an unaligned access, because all memory addresses are evenly
+divisible by one.
+
+On a related topic, with the above considerations in mind you may observe
+that you could reorder the fields in the structure in order to place fields
+where padding would otherwise be inserted, and hence reduce the overall
+resident memory size of structure instances. The optimal layout of the
+above example is:
+
+       struct foo {
+               u32 field2;
+               u16 field1;
+               u8 field3;
+       };
+
+For a natural alignment scheme, the compiler would only have to add a single
+byte of padding at the end of the structure. This padding is added in order
+to satisfy alignment constraints for arrays of these structures.
+
+Another point worth mentioning is the use of __attribute__((packed)) on a
+structure type. This GCC-specific attribute tells the compiler never to
+insert any padding within structures, useful when you want to use a C struct
+to represent some data that comes in a fixed arrangement 'off the wire'.
+
+You might be inclined to believe that usage of this attribute can easily
+lead to unaligned accesses when accessing fields that do not satisfy
+architectural alignment requirements. However, again, the compiler is aware
+of the alignment constraints and will generate extra instructions to perform
+the memory access in a way that does not cause unaligned access. Of course,
+the extra instructions obviously cause a loss in performance compared to the
+non-packed case, so the packed attribute should only be used when avoiding
+structure padding is of importance.
+
+
+Code that causes unaligned access
+=================================
+
+With the above in mind, let's move onto a real life example of a function
+that can cause an unaligned memory access. The following function adapted
+from include/linux/etherdevice.h is an optimized routine to compare two
+ethernet MAC addresses for equality.
+
+unsigned int compare_ether_addr(const u8 *addr1, const u8 *addr2)
+{
+       const u16 *a = (const u16 *) addr1;
+       const u16 *b = (const u16 *) addr2;
+       return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
+}
+
+In the above function, the reference to a[0] causes 2 bytes (16 bits) to
+be read from memory starting at address addr1. Think about what would happen
+if addr1 was an odd address such as 0x10003. (Hint: it'd be an unaligned
+access.)
+
+Despite the potential unaligned access problems with the above function, it
+is included in the kernel anyway but is understood to only work on
+16-bit-aligned addresses. It is up to the caller to ensure this alignment or
+not use this function at all. This alignment-unsafe function is still useful
+as it is a decent optimization for the cases when you can ensure alignment,
+which is true almost all of the time in ethernet networking context.
+
+
+Here is another example of some code that could cause unaligned accesses:
+       void myfunc(u8 *data, u32 value)
+       {
+               [...]
+               *((u32 *) data) = cpu_to_le32(value);
+               [...]
+       }
+
+This code will cause unaligned accesses every time the data parameter points
+to an address that is not evenly divisible by 4.
+
+In summary, the 2 main scenarios where you may run into unaligned access
+problems involve:
+ 1. Casting variables to types of different lengths
+ 2. Pointer arithmetic followed by access to at least 2 bytes of data
+
+
+Avoiding unaligned accesses
+===========================
+
+The easiest way to avoid unaligned access is to use the get_unaligned() and
+put_unaligned() macros provided by the <asm/unaligned.h> header file.
+
+Going back to an earlier example of code that potentially causes unaligned
+access:
+
+       void myfunc(u8 *data, u32 value)
+       {
+               [...]
+               *((u32 *) data) = cpu_to_le32(value);
+               [...]
+       }
+
+To avoid the unaligned memory access, you would rewrite it as follows:
+
+       void myfunc(u8 *data, u32 value)
+       {
+               [...]
+               value = cpu_to_le32(value);
+               put_unaligned(value, (u32 *) data);
+               [...]
+       }
+
+The get_unaligned() macro works similarly. Assuming 'data' is a pointer to
+memory and you wish to avoid unaligned access, its usage is as follows:
+
+       u32 value = get_unaligned((u32 *) data);
+
+These macros work work for memory accesses of any length (not just 32 bits as
+in the examples above). Be aware that when compared to standard access of
+aligned memory, using these macros to access unaligned memory can be costly in
+terms of performance.
+
+If use of such macros is not convenient, another option is to use memcpy(),
+where the source or destination (or both) are of type u8* or unsigned char*.
+Due to the byte-wise nature of this operation, unaligned accesses are avoided.
+
+--
+Author: Daniel Drake <dsd@gentoo.org>
+With help from: Alan Cox, Avuton Olrich, Heikki Orsila, Jan Engelhardt,
+Johannes Berg, Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock,
+Uli Kunitz, Vadim Lobanov
+
diff --git a/Documentation/usb/gadget_printer.txt b/Documentation/usb/gadget_printer.txt
new file mode 100644 (file)
index 0000000..ad995bf
--- /dev/null
@@ -0,0 +1,510 @@
+
+                       Linux USB Printer Gadget Driver
+                                 06/04/2007
+
+              Copyright (C) 2007 Craig W. Nadler <craig@nadler.us>
+
+
+
+GENERAL
+=======
+
+This driver may be used if you are writing printer firmware using Linux as
+the embedded OS. This driver has nothing to do with using a printer with
+your Linux host system.
+
+You will need a USB device controller and a Linux driver for it that accepts
+a gadget / "device class" driver using the Linux USB Gadget API. After the
+USB device controller driver is loaded then load the printer gadget driver.
+This will present a printer interface to the USB Host that your USB Device
+port is connected to.
+
+This driver is structured for printer firmware that runs in user mode. The
+user mode printer firmware will read and write data from the kernel mode
+printer gadget driver using a device file. The printer returns a printer status
+byte when the USB HOST sends a device request to get the printer status.  The
+user space firmware can read or write this status byte using a device file
+/dev/g_printer . Both blocking and non-blocking read/write calls are supported.
+
+
+
+
+HOWTO USE THIS DRIVER
+=====================
+
+To load the USB device controller driver and the printer gadget driver. The
+following example uses the Netchip 2280 USB device controller driver:
+
+modprobe net2280
+modprobe g_printer
+
+
+The follow command line parameter can be used when loading the printer gadget
+(ex: modprobe g_printer idVendor=0x0525 idProduct=0xa4a8 ):
+
+idVendor - This is the Vendor ID used in the device descriptor. The default is
+       the Netchip vendor id 0x0525. YOU MUST CHANGE TO YOUR OWN VENDOR ID
+       BEFORE RELEASING A PRODUCT. If you plan to release a product and don't
+       already have a Vendor ID please see www.usb.org for details on how to
+       get one.
+
+idProduct - This is the Product ID used in the device descriptor. The default
+       is 0xa4a8, you should change this to an ID that's not used by any of
+       your other USB products if you have any. It would be a good idea to
+       start numbering your products starting with say 0x0001.
+
+bcdDevice - This is the version number of your product. It would be a good idea
+       to put your firmware version here.
+
+iManufacturer - A string containing the name of the Vendor.
+
+iProduct - A string containing the Product Name.
+
+iSerialNum - A string containing the Serial Number. This should be changed for
+       each unit of your product.
+
+iPNPstring -  The PNP ID string used for this printer. You will want to set
+       either on the command line or hard code the PNP ID string used for
+       your printer product.
+
+qlen - The number of 8k buffers to use per endpoint. The default is 10, you
+       should tune this for your product. You may also want to tune the
+       size of each buffer for your product.
+
+
+
+
+USING THE EXAMPLE CODE
+======================
+
+This example code talks to stdout, instead of a print engine.
+
+To compile the test code below:
+
+1) save it to a file called prn_example.c
+2) compile the code with the follow command:
+        gcc prn_example.c -o prn_example
+
+
+
+To read printer data from the host to stdout:
+
+       # prn_example -read_data
+
+
+To write printer data from a file (data_file) to the host:
+
+       # cat data_file | prn_example -write_data
+
+
+To get the current printer status for the gadget driver:
+
+       # prn_example -get_status
+
+       Printer status is:
+            Printer is NOT Selected
+            Paper is Out
+            Printer OK
+
+
+To set printer to Selected/On-line:
+
+       # prn_example -selected
+
+
+To set printer to Not Selected/Off-line:
+
+       # prn_example -not_selected
+
+
+To set paper status to paper out:
+
+       # prn_example -paper_out
+
+
+To set paper status to paper loaded:
+
+       # prn_example -paper_loaded
+
+
+To set error status to printer OK:
+
+       # prn_example -no_error
+
+
+To set error status to ERROR:
+
+       # prn_example -error
+
+
+
+
+EXAMPLE CODE
+============
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <linux/poll.h>
+#include <sys/ioctl.h>
+#include <linux/usb/g_printer.h>
+
+#define PRINTER_FILE                   "/dev/g_printer"
+#define BUF_SIZE                       512
+
+
+/*
+ * 'usage()' - Show program usage.
+ */
+
+static void
+usage(const char *option)              /* I - Option string or NULL */
+{
+       if (option) {
+               fprintf(stderr,"prn_example: Unknown option \"%s\"!\n",
+                               option);
+       }
+
+       fputs("\n", stderr);
+       fputs("Usage: prn_example -[options]\n", stderr);
+       fputs("Options:\n", stderr);
+       fputs("\n", stderr);
+       fputs("-get_status    Get the current printer status.\n", stderr);
+       fputs("-selected      Set the selected status to selected.\n", stderr);
+       fputs("-not_selected  Set the selected status to NOT selected.\n",
+                       stderr);
+       fputs("-error         Set the error status to error.\n", stderr);
+       fputs("-no_error      Set the error status to NO error.\n", stderr);
+       fputs("-paper_out     Set the paper status to paper out.\n", stderr);
+       fputs("-paper_loaded  Set the paper status to paper loaded.\n",
+                       stderr);
+       fputs("-read_data     Read printer data from driver.\n", stderr);
+       fputs("-write_data    Write printer sata to driver.\n", stderr);
+       fputs("-NB_read_data  (Non-Blocking) Read printer data from driver.\n",
+                       stderr);
+       fputs("\n\n", stderr);
+
+       exit(1);
+}
+
+
+static int
+read_printer_data()
+{
+       struct pollfd   fd[1];
+
+       /* Open device file for printer gadget. */
+       fd[0].fd = open(PRINTER_FILE, O_RDWR);
+       if (fd[0].fd < 0) {
+               printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE);
+               close(fd[0].fd);
+               return(-1);
+       }
+
+       fd[0].events = POLLIN | POLLRDNORM;
+
+       while (1) {
+               static char buf[BUF_SIZE];
+               int bytes_read;
+               int retval;
+
+               /* Wait for up to 1 second for data. */
+               retval = poll(fd, 1, 1000);
+
+               if (retval && (fd[0].revents & POLLRDNORM)) {
+
+                       /* Read data from printer gadget driver. */
+                       bytes_read = read(fd[0].fd, buf, BUF_SIZE);
+
+                       if (bytes_read < 0) {
+                               printf("Error %d reading from %s\n",
+                                               fd[0].fd, PRINTER_FILE);
+                               close(fd[0].fd);
+                               return(-1);
+                       } else if (bytes_read > 0) {
+                               /* Write data to standard OUTPUT (stdout). */
+                               fwrite(buf, 1, bytes_read, stdout);
+                               fflush(stdout);
+                       }
+
+               }
+
+       }
+
+       /* Close the device file. */
+       close(fd[0].fd);
+
+       return 0;
+}
+
+
+static int
+write_printer_data()
+{
+       struct pollfd   fd[1];
+
+       /* Open device file for printer gadget. */
+       fd[0].fd = open (PRINTER_FILE, O_RDWR);
+       if (fd[0].fd < 0) {
+               printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE);
+               close(fd[0].fd);
+               return(-1);
+       }
+
+       fd[0].events = POLLOUT | POLLWRNORM;
+
+       while (1) {
+               int retval;
+               static char buf[BUF_SIZE];
+               /* Read data from standard INPUT (stdin). */
+               int bytes_read = fread(buf, 1, BUF_SIZE, stdin);
+
+               if (!bytes_read) {
+                       break;
+               }
+
+               while (bytes_read) {
+
+                       /* Wait for up to 1 second to sent data. */
+                       retval = poll(fd, 1, 1000);
+
+                       /* Write data to printer gadget driver. */
+                       if (retval && (fd[0].revents & POLLWRNORM)) {
+                               retval = write(fd[0].fd, buf, bytes_read);
+                               if (retval < 0) {
+                                       printf("Error %d writing to %s\n",
+                                                       fd[0].fd,
+                                                       PRINTER_FILE);
+                                       close(fd[0].fd);
+                                       return(-1);
+                               } else {
+                                       bytes_read -= retval;
+                               }
+
+                       }
+
+               }
+
+       }
+
+       /* Wait until the data has been sent. */
+       fsync(fd[0].fd);
+
+       /* Close the device file. */
+       close(fd[0].fd);
+
+       return 0;
+}
+
+
+static int
+read_NB_printer_data()
+{
+       int             fd;
+       static char     buf[BUF_SIZE];
+       int             bytes_read;
+
+       /* Open device file for printer gadget. */
+       fd = open(PRINTER_FILE, O_RDWR|O_NONBLOCK);
+       if (fd < 0) {
+               printf("Error %d opening %s\n", fd, PRINTER_FILE);
+               close(fd);
+               return(-1);
+       }
+
+       while (1) {
+               /* Read data from printer gadget driver. */
+               bytes_read = read(fd, buf, BUF_SIZE);
+               if (bytes_read <= 0) {
+                       break;
+               }
+
+               /* Write data to standard OUTPUT (stdout). */
+               fwrite(buf, 1, bytes_read, stdout);
+               fflush(stdout);
+       }
+
+       /* Close the device file. */
+       close(fd);
+
+       return 0;
+}
+
+
+static int
+get_printer_status()
+{
+       int     retval;
+       int     fd;
+
+       /* Open device file for printer gadget. */
+       fd = open(PRINTER_FILE, O_RDWR);
+       if (fd < 0) {
+               printf("Error %d opening %s\n", fd, PRINTER_FILE);
+               close(fd);
+               return(-1);
+       }
+
+       /* Make the IOCTL call. */
+       retval = ioctl(fd, GADGET_GET_PRINTER_STATUS);
+       if (retval < 0) {
+               fprintf(stderr, "ERROR: Failed to set printer status\n");
+               return(-1);
+       }
+
+       /* Close the device file. */
+       close(fd);
+
+       return(retval);
+}
+
+
+static int
+set_printer_status(unsigned char buf, int clear_printer_status_bit)
+{
+       int     retval;
+       int     fd;
+
+       retval = get_printer_status();
+       if (retval < 0) {
+               fprintf(stderr, "ERROR: Failed to get printer status\n");
+               return(-1);
+       }
+
+       /* Open device file for printer gadget. */
+       fd = open(PRINTER_FILE, O_RDWR);
+
+       if (fd < 0) {
+               printf("Error %d opening %s\n", fd, PRINTER_FILE);
+               close(fd);
+               return(-1);
+       }
+
+       if (clear_printer_status_bit) {
+               retval &= ~buf;
+       } else {
+               retval |= buf;
+       }
+
+       /* Make the IOCTL call. */
+       if (ioctl(fd, GADGET_SET_PRINTER_STATUS, (unsigned char)retval)) {
+               fprintf(stderr, "ERROR: Failed to set printer status\n");
+               return(-1);
+       }
+
+       /* Close the device file. */
+       close(fd);
+
+       return 0;
+}
+
+
+static int
+display_printer_status()
+{
+       char    printer_status;
+
+       printer_status = get_printer_status();
+       if (printer_status < 0) {
+               fprintf(stderr, "ERROR: Failed to get printer status\n");
+               return(-1);
+       }
+
+       printf("Printer status is:\n");
+       if (printer_status & PRINTER_SELECTED) {
+               printf("     Printer is Selected\n");
+       } else {
+               printf("     Printer is NOT Selected\n");
+       }
+       if (printer_status & PRINTER_PAPER_EMPTY) {
+               printf("     Paper is Out\n");
+       } else {
+               printf("     Paper is Loaded\n");
+       }
+       if (printer_status & PRINTER_NOT_ERROR) {
+               printf("     Printer OK\n");
+       } else {
+               printf("     Printer ERROR\n");
+       }
+
+       return(0);
+}
+
+
+int
+main(int  argc, char *argv[])
+{
+       int     i;              /* Looping var */
+       int     retval = 0;
+
+       /* No Args */
+       if (argc == 1) {
+               usage(0);
+               exit(0);
+       }
+
+       for (i = 1; i < argc && !retval; i ++) {
+
+               if (argv[i][0] != '-') {
+                       continue;
+               }
+
+               if (!strcmp(argv[i], "-get_status")) {
+                       if (display_printer_status()) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-paper_loaded")) {
+                       if (set_printer_status(PRINTER_PAPER_EMPTY, 1)) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-paper_out")) {
+                       if (set_printer_status(PRINTER_PAPER_EMPTY, 0)) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-selected")) {
+                       if (set_printer_status(PRINTER_SELECTED, 0)) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-not_selected")) {
+                       if (set_printer_status(PRINTER_SELECTED, 1)) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-error")) {
+                       if (set_printer_status(PRINTER_NOT_ERROR, 1)) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-no_error")) {
+                       if (set_printer_status(PRINTER_NOT_ERROR, 0)) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-read_data")) {
+                       if (read_printer_data()) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-write_data")) {
+                       if (write_printer_data()) {
+                               retval = 1;
+                       }
+
+               } else if (!strcmp(argv[i], "-NB_read_data")) {
+                       if (read_NB_printer_data()) {
+                               retval = 1;
+                       }
+
+               } else {
+                       usage(argv[i]);
+                       retval = 1;
+               }
+       }
+
+       exit(retval);
+}
diff --git a/Documentation/usb/iuu_phoenix.txt b/Documentation/usb/iuu_phoenix.txt
new file mode 100644 (file)
index 0000000..e5f0480
--- /dev/null
@@ -0,0 +1,84 @@
+Infinity Usb Unlimited Readme
+-----------------------------
+
+Hi all,
+
+
+This module provide a serial interface to use your
+IUU unit in phoenix mode. Loading this module will
+bring a ttyUSB[0-x] interface. This driver must be
+used by your favorite application to pilot the IUU
+
+This driver is still in beta stage, so bugs can
+occur and your system may freeze. As far I now,
+I never had any problem with it, but I'm not a real
+guru, so don't blame me if your system is unstable
+
+You can plug more than one IUU. Every unit will
+have his own device file(/dev/ttyUSB0,/dev/ttyUSB1,...)
+
+
+
+How to tune the reader speed ?
+
+ A few parameters can be used at load time
+ To use parameters, just unload the module if it is
+ already loaded and use modprobe iuu_phoenix param=value.
+ In case of prebuilt module, use the command
+ insmod iuu_phoenix param=value.
+
+ Example:
+
+ modprobe iuu_phoenix clockmode=3
+
+ The parameters are:
+
+ parm:           clockmode:1=3Mhz579,2=3Mhz680,3=6Mhz (int)
+ parm:           boost:overclock boost percent 100 to 500 (int)
+ parm:           cdmode:Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, 4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING (int)
+ parm:           xmas:xmas color enabled or not (bool)
+ parm:           debug:Debug enabled or not (bool)
+
+-  clockmode will provide 3 different base settings commonly adopted by
+   different software:
+       1. 3Mhz579
+       2. 3Mhz680
+       3. 6Mhz
+
+-  boost provide a way to overclock the reader ( my favorite :-)  )
+   For example to have best performance than a simple clockmode=3, try this:
+
+      modprobe boost=195
+
+   This will put the reader in a base of 3Mhz579 but boosted a 195 % !
+   the real clock will be now : 6979050 Hz ( 6Mhz979 ) and will increase
+   the speed to a score 10 to 20% better than the simple clockmode=3 !!!
+
+
+-  cdmode permit to setup the signal used to inform the userland ( ioctl answer )
+   if the card is present or not. Eight signals are possible.
+
+-  xmas is completely useless except for your eyes. This is one of my friend who was
+   so sad to have a nice device like the iuu without seeing all color range available.
+   So I have added this option to permit him to see a lot of color ( each activity change the color
+   and the frequency randomly )
+
+-  debug will produce a lot of debugging messages...
+
+
+ Last notes:
+
+ Don't worry about the serial settings, the serial emulation
+ is an abstraction, so use any speed or parity setting will
+ work. ( This will not change anything ).Later I will perhaps
+ use this settings to deduce de boost but is that feature
+ really necessary ?
+ The autodetect feature used is the serial CD. If that doesn't
+ work for your software, disable detection mechanism in it.
+
+
+ Have fun !
+
+ Alain Degreffe
+
+ eczema(at)ecze.com
index 752613c4cea2b5e7951b8cd661996745c2b0a1c4..7b0ceaaad7af916ab0ed24d2e8ed05738bd830e0 100644 (file)
@@ -4,3 +4,5 @@ ds2482
        - The Maxim/Dallas Semiconductor DS2482 provides 1-wire busses.
 ds2490
        - The Maxim/Dallas Semiconductor DS2490 builds USB <-> W1 bridges.
+w1-gpio
+       - GPIO 1-wire bus master driver.
diff --git a/Documentation/w1/masters/w1-gpio b/Documentation/w1/masters/w1-gpio
new file mode 100644 (file)
index 0000000..af5d3b4
--- /dev/null
@@ -0,0 +1,33 @@
+Kernel driver w1-gpio
+=====================
+
+Author: Ville Syrjala <syrjala@sci.fi>
+
+
+Description
+-----------
+
+GPIO 1-wire bus master driver. The driver uses the GPIO API to control the
+wire and the GPIO pin can be specified using platform data.
+
+
+Example (mach-at91)
+-------------------
+
+#include <linux/w1-gpio.h>
+
+static struct w1_gpio_platform_data foo_w1_gpio_pdata = {
+       .pin            = AT91_PIN_PB20,
+       .is_open_drain  = 1,
+};
+
+static struct platform_device foo_w1_device = {
+       .name                   = "w1-gpio",
+       .id                     = -1,
+       .dev.platform_data      = &foo_w1_gpio_pdata,
+};
+
+...
+       at91_set_GPIO_periph(foo_w1_gpio_pdata.pin, 1);
+       at91_set_multi_drive(foo_w1_gpio_pdata.pin, 1);
+       platform_device_register(&foo_w1_device);
diff --git a/Documentation/x86_64/00-INDEX b/Documentation/x86_64/00-INDEX
new file mode 100644 (file)
index 0000000..92fc20a
--- /dev/null
@@ -0,0 +1,16 @@
+00-INDEX
+       - This file
+boot-options.txt
+       - AMD64-specific boot options.
+cpu-hotplug-spec
+       - Firmware support for CPU hotplug under Linux/x86-64
+fake-numa-for-cpusets
+       - Using numa=fake and CPUSets for Resource Management
+kernel-stacks
+       - Context-specific per-processor interrupt stacks.
+machinecheck
+       - Configurable sysfs parameters for the x86-64 machine check code.
+mm.txt
+       - Memory layout of x86-64 (4 level page tables, 46 bits physical).
+uefi.txt
+       - Booting Linux via Unified Extensible Firmware Interface.
index 91082e60d2897df6675edad92af8105a2979a19a..0885aa2b095a44b3cd66567f80f50aab75ce6d95 100644 (file)
@@ -84,13 +84,6 @@ S: Status, one of the following:
                        it has been replaced by a better system and you
                        should be using that.
 
-3C359 NETWORK DRIVER
-P:     Mike Phillips
-M:     mikep@linuxtr.net
-L:     netdev@vger.kernel.org
-W:     http://www.linuxtr.net
-S:     Maintained
-
 3C505 NETWORK DRIVER
 P:     Philip Blundell
 M:     philb@gnu.org
@@ -345,13 +338,12 @@ S:        Maintained for 2.4; PCI support for 2.6.
 AMD GEODE CS5536 USB DEVICE CONTROLLER DRIVER
 P:     Thomas Dahlmann
 M:     thomas.dahlmann@amd.com
-L:     info-linux@geode.amd.com
+L:     info-linux@geode.amd.com        (subscribers-only)
 S:     Supported
 
 AMD GEODE PROCESSOR/CHIPSET SUPPORT
 P:     Jordan Crouse
-M:     info-linux@geode.amd.com
-L:     info-linux@geode.amd.com
+L:     info-linux@geode.amd.com        (subscribers-only)
 W:     http://www.amd.com/us-en/ConnectivitySolutions/TechnicalResources/0,,50_2334_2452_11363,00.html
 S:     Supported
 
@@ -848,6 +840,12 @@ L: linux-kernel@vger.kernel.org
 T:     git kernel.org:/pub/scm/linux/kernel/git/axboe/linux-2.6-block.git
 S:     Maintained
 
+BLOCK2MTD DRIVER
+P:     Joern Engel
+M:     joern@lazybastard.org
+L:     linux-mtd@lists.infradead.org
+S:     Maintained
+
 BLUETOOTH SUBSYSTEM
 P:     Marcel Holtmann
 M:     marcel@holtmann.org
@@ -939,8 +937,6 @@ M:  maxk@qualcomm.com
 S:     Maintained
 
 BONDING DRIVER
-P:     Chad Tindel
-M:     ctindel@users.sourceforge.net
 P:     Jay Vosburgh
 M:     fubar@us.ibm.com
 L:     bonding-devel@lists.sourceforge.net
@@ -2247,7 +2243,7 @@ P:        J. Bruce Fields
 M:     bfields@fieldses.org
 P:     Neil Brown
 M:     neilb@suse.de
-L:     nfs@lists.sourceforge.net
+L:     linux-nfs@vger.kernel.org
 W:     http://nfs.sourceforge.net/
 S:     Supported
 
@@ -2258,6 +2254,15 @@ L:       kvm-devel@lists.sourceforge.net
 W:     kvm.sourceforge.net
 S:     Supported
 
+KERNEL VIRTUAL MACHINE For Itanium(KVM/IA64)
+P:     Anthony Xu
+M:     anthony.xu@intel.com
+P:     Xiantao Zhang
+M:     xiantao.zhang@intel.com
+L:     kvm-ia64-devel@lists.sourceforge.net
+W:     kvm.sourceforge.net
+S:     Supported
+
 KEXEC
 P:     Eric Biederman
 M:     ebiederm@xmission.com
@@ -2690,6 +2695,16 @@ M:       James.Bottomley@HansenPartnership.com
 L:     linux-scsi@vger.kernel.org
 S:     Maintained
 
+NETEFFECT IWARP RNIC DRIVER (IW_NES)
+P:     Faisal Latif
+M:     flatif@neteffect.com
+P:     Glenn Streiff
+M:     gstreiff@neteffect.com
+L:     general@lists.openfabrics.org
+W:     http://www.neteffect.com
+S:     Supported
+F:     drivers/infiniband/hw/nes/
+
 NETEM NETWORK EMULATOR
 P:     Stephen Hemminger
 M:     shemminger@linux-foundation.org
@@ -2864,15 +2879,6 @@ L:       ocfs2-devel@oss.oracle.com
 W:     http://oss.oracle.com/projects/ocfs2/
 S:     Supported
 
-OLYMPIC NETWORK DRIVER
-P:     Peter De Shrijver
-M:     p2@ace.ulyssis.student.kuleuven.ac.be
-P:     Mike Phillips
-M:     mikep@linuxtr.net
-L:     netdev@vger.kernel.org
-W:     http://www.linuxtr.net
-S:     Maintained
-
 OMNIKEY CARDMAN 4000 DRIVER
 P:     Harald Welte
 M:     laforge@gnumonks.org
@@ -3030,8 +3036,8 @@ L:        linux-abi-devel@lists.sourceforge.net
 S:     Maintained
 
 PHRAM MTD DRIVER
-P:     Jörn Engel
-M:     joern@wh.fh-wedel.de
+P:     Joern Engel
+M:     joern@lazybastard.org
 L:     linux-mtd@lists.infradead.org
 S:     Maintained
 
@@ -3053,7 +3059,6 @@ M:        cbou@mail.ru
 P:     David Woodhouse
 M:     dwmw2@infradead.org
 L:     linux-kernel@vger.kernel.org
-L:     kernel-discuss@handhelds.org
 T:     git git.infradead.org/battery-2.6.git
 S:     Maintained
 
@@ -3196,7 +3201,7 @@ S:        Maintained
 
 RAYLINK/WEBGEAR 802.11 WIRELESS LAN DRIVER
 P:     Corey Thomas
-M:     corey@world.std.com
+M:     coreythomas@charter.net
 L:     linux-wireless@vger.kernel.org
 S:     Maintained
 
@@ -3219,6 +3224,12 @@ M:       mporter@kernel.crashing.org
 L:     linux-kernel@vger.kernel.org
 S:     Maintained
 
+RDC R-321X SoC
+P:     Florian Fainelli
+M:     florian.fainelli@telecomint.eu
+L:     linux-kernel@vger.kernel.org
+S:     Maintained
+
 RDC R6040 FAST ETHERNET DRIVER
 P:     Florian Fainelli
 M:     florian.fainelli@telecomint.eu
@@ -3789,13 +3800,6 @@ L:       tlan-devel@lists.sourceforge.net (subscribers-only)
 W:     http://sourceforge.net/projects/tlan/
 S:     Maintained
 
-TOKEN-RING NETWORK DRIVER
-P:     Mike Phillips
-M:     mikep@linuxtr.net
-L:     netdev@vger.kernel.org
-W:     http://www.linuxtr.net
-S:     Maintained
-
 TOSHIBA ACPI EXTRAS DRIVER
 P:     John Belmonte
 M:     toshiba_acpi@memebeam.org
@@ -3816,18 +3820,9 @@ L:       linux-kernel@vger.kernel.org
 S:     Maintained
 
 TRIVIAL PATCHES
-P:     Adrian Bunk
+P:     Jesper Juhl
 M:     trivial@kernel.org
 L:     linux-kernel@vger.kernel.org
-W:     http://www.kernel.org/pub/linux/kernel/people/bunk/trivial/
-T:     git kernel.org:/pub/scm/linux/kernel/git/bunk/trivial.git
-S:     Maintained
-
-TMS380 TOKEN-RING NETWORK DRIVER
-P:     Adam Fritzler
-M:     mid@auk.cx
-L:     linux-tr@linuxtr.net
-W:     http://www.auk.cx/tms380tr/
 S:     Maintained
 
 TULIP NETWORK DRIVER
@@ -3872,6 +3867,12 @@ M:       oliver@neukum.name
 L:     linux-usb@vger.kernel.org
 S:     Maintained
 
+USB AUERSWALD DRIVER
+P:     Wolfgang Muees
+M:     wolfgang@iksw-muees.de
+L:      linux-usb@vger.kernel.org
+S:     Maintained
+
 USB BLOCK DRIVER (UB ub)
 P:     Pete Zaitcev
 M:     zaitcev@redhat.com
@@ -4022,12 +4023,6 @@ S:       Maintained
 W:     http://geocities.com/i0xox0i
 W:     http://firstlight.net/cvs
 
-USB AUERSWALD DRIVER
-P:     Wolfgang Muees
-M:     wolfgang@iksw-muees.de
-L:      linux-usb@vger.kernel.org
-S:     Maintained
-
 USB SERIAL EMPEG EMPEG-CAR MARK I/II DRIVER
 P:     Gary Brubaker
 M:     xavyer@ix.netcom.com
index 0f84c742ed0e1c8363d27121fb2ce563fb582bc7..89f2d8b5136d72efcc0bd761cd3ba37ab956718f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1484,7 +1484,7 @@ kernelversion:
 # Single targets
 # ---------------------------------------------------------------------------
 # Single targets are compatible with:
-# - build whith mixed source and output
+# - build with mixed source and output
 # - build with separate output dir 'make O=...'
 # - external modules
 #
diff --git a/arch/Kconfig b/arch/Kconfig
new file mode 100644 (file)
index 0000000..3d72dc3
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# General architecture dependent options
+#
+
+config OPROFILE
+       tristate "OProfile system profiling (EXPERIMENTAL)"
+       depends on PROFILING
+       depends on HAVE_OPROFILE
+       help
+         OProfile is a profiling system capable of profiling the
+         whole system, include the kernel, kernel modules, libraries,
+         and applications.
+
+         If unsure, say N.
+
+config HAVE_OPROFILE
+       def_bool n
+
+config KPROBES
+       bool "Kprobes"
+       depends on KALLSYMS && MODULES
+       depends on HAVE_KPROBES
+       help
+         Kprobes allows you to trap at almost any kernel address and
+         execute a callback function.  register_kprobe() establishes
+         a probepoint and specifies the callback.  Kprobes is useful
+         for kernel debugging, non-intrusive instrumentation and testing.
+         If in doubt, say "N".
+
+config HAVE_KPROBES
+       def_bool n
index 4c002ba37e5076fe726826e3a2a73deb29d25176..01b10ab588a630b36c0290448ffa53d29bf03dfc 100644 (file)
@@ -5,6 +5,7 @@
 config ALPHA
        bool
        default y
+       select HAVE_OPROFILE
        help
          The Alpha is a 64-bit general-purpose processor designed and
          marketed by the Digital Equipment Corporation of blessed memory,
@@ -318,11 +319,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 config PCI_DOMAINS
        bool
        default y
@@ -536,8 +532,8 @@ config SMP
          singleprocessor machines. On a singleprocessor machine, the kernel
          will run faster if you say N here.
 
-         See also the <file:Documentation/smp.txt>, and the SMP-HOWTO
-         available at <http://www.tldp.org/docs.html#howto>.
+         See also the SMP-HOWTO available at
+         <http://www.tldp.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
 
@@ -654,8 +650,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/alpha/Kconfig.debug"
 
 # DUMMY_CONSOLE may be defined in drivers/video/console/Kconfig
index f45f28cc10da94e24c4add02315f950f9787ec37..3f6265f2d9d4749a032bb28e325622bc92d81a1f 100644 (file)
@@ -7,15 +7,6 @@ config EARLY_PRINTK
        depends on ALPHA_GENERIC || ALPHA_SRM
        default y
 
-config DEBUG_RWLOCK
-       bool "Read-write spinlock debugging"
-       depends on DEBUG_KERNEL
-       help
-         If you say Y here then read-write lock processing will count how many
-         times it has tried to get the lock and issue an error message after
-         too many attempts.  If you suspect a rwlock problem or a kernel
-         hacker asks for this option then say Y.  Otherwise say N.
-
 config ALPHA_LEGACY_START_ADDRESS
        bool "Legacy kernel start address"
        depends on ALPHA_GENERIC
index 6da9c3dbde448fd38f737560bb919f0eb8186022..e43f68fd66b0d5fae206f3935492938f33e48941 100644 (file)
@@ -882,7 +882,6 @@ CONFIG_MAGIC_SYSRQ=y
 # CONFIG_DEBUG_SPINLOCK is not set
 CONFIG_DEBUG_INFO=y
 CONFIG_EARLY_PRINTK=y
-# CONFIG_DEBUG_RWLOCK is not set
 # CONFIG_DEBUG_SEMAPHORE is not set
 CONFIG_ALPHA_LEGACY_START_ADDRESS=y
 CONFIG_MATHEMU=y
index 6413c5f232264dbc9b165489396dbb6987d42351..72f9a619a66d8055b03df676979b0645879c7160 100644 (file)
@@ -430,7 +430,7 @@ sys_getpagesize(void)
 asmlinkage unsigned long
 sys_getdtablesize(void)
 {
-       return NR_OPEN;
+       return sysctl_nr_open;
 }
 
 /*
index 468b76ce66a1304e4eeddc48663effbe8545f83e..8ac08311f5a51bd765145b461b76864f550d38f1 100644 (file)
@@ -165,7 +165,7 @@ dma_alloc_coherent(struct device *dev, size_t size,
        ret = (void *)__get_free_pages(gfp, get_order(size));
        if (ret) {
                memset(ret, 0, size);
-               *dma_handle = virt_to_bus(ret);
+               *dma_handle = virt_to_phys(ret);
        }
        return ret;
 }
@@ -184,7 +184,7 @@ dma_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
 
                BUG_ON(!sg_page(sg));
                va = sg_virt(sg);
-               sg_dma_address(sg) = (dma_addr_t)virt_to_bus(va);
+               sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va);
                sg_dma_len(sg) = sg->length;
        }
 
index 2d00a08d3f0811d0f7b819475d6f858828d88496..26d3789dfdd0420bc4e7ce496995138b1decda14 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/bootmem.h>
 #include <linux/scatterlist.h>
 #include <linux/log2.h>
+#include <linux/dma-mapping.h>
 
 #include <asm/io.h>
 #include <asm/hwrpb.h>
@@ -470,22 +471,29 @@ EXPORT_SYMBOL(pci_free_consistent);
 #define SG_ENT_PHYS_ADDRESS(SG) __pa(SG_ENT_VIRT_ADDRESS(SG))
 
 static void
-sg_classify(struct scatterlist *sg, struct scatterlist *end, int virt_ok)
+sg_classify(struct device *dev, struct scatterlist *sg, struct scatterlist *end,
+           int virt_ok)
 {
        unsigned long next_paddr;
        struct scatterlist *leader;
        long leader_flag, leader_length;
+       unsigned int max_seg_size;
 
        leader = sg;
        leader_flag = 0;
        leader_length = leader->length;
        next_paddr = SG_ENT_PHYS_ADDRESS(leader) + leader_length;
 
+       /* we will not marge sg without device. */
+       max_seg_size = dev ? dma_get_max_seg_size(dev) : 0;
        for (++sg; sg < end; ++sg) {
                unsigned long addr, len;
                addr = SG_ENT_PHYS_ADDRESS(sg);
                len = sg->length;
 
+               if (leader_length + len > max_seg_size)
+                       goto new_segment;
+
                if (next_paddr == addr) {
                        sg->dma_address = -1;
                        leader_length += len;
@@ -494,6 +502,7 @@ sg_classify(struct scatterlist *sg, struct scatterlist *end, int virt_ok)
                        leader_flag = 1;
                        leader_length += len;
                } else {
+new_segment:
                        leader->dma_address = leader_flag;
                        leader->dma_length = leader_length;
                        leader = sg;
@@ -512,7 +521,7 @@ sg_classify(struct scatterlist *sg, struct scatterlist *end, int virt_ok)
    in the blanks.  */
 
 static int
-sg_fill(struct scatterlist *leader, struct scatterlist *end,
+sg_fill(struct device *dev, struct scatterlist *leader, struct scatterlist *end,
        struct scatterlist *out, struct pci_iommu_arena *arena,
        dma_addr_t max_dma, int dac_allowed)
 {
@@ -562,8 +571,8 @@ sg_fill(struct scatterlist *leader, struct scatterlist *end,
 
                /* Otherwise, break up the remaining virtually contiguous
                   hunks into individual direct maps and retry.  */
-               sg_classify(leader, end, 0);
-               return sg_fill(leader, end, out, arena, max_dma, dac_allowed);
+               sg_classify(dev, leader, end, 0);
+               return sg_fill(dev, leader, end, out, arena, max_dma, dac_allowed);
        }
 
        out->dma_address = arena->dma_base + dma_ofs*PAGE_SIZE + paddr;
@@ -619,12 +628,15 @@ pci_map_sg(struct pci_dev *pdev, struct scatterlist *sg, int nents,
        struct pci_iommu_arena *arena;
        dma_addr_t max_dma;
        int dac_allowed;
+       struct device *dev;
 
        if (direction == PCI_DMA_NONE)
                BUG();
 
        dac_allowed = pdev ? pci_dac_dma_supported(pdev, pdev->dma_mask) : 0;
 
+       dev = pdev ? &pdev->dev : NULL;
+
        /* Fast path single entry scatterlists.  */
        if (nents == 1) {
                sg->dma_length = sg->length;
@@ -638,7 +650,7 @@ pci_map_sg(struct pci_dev *pdev, struct scatterlist *sg, int nents,
        end = sg + nents;
 
        /* First, prepare information about the entries.  */
-       sg_classify(sg, end, alpha_mv.mv_pci_tbi != 0);
+       sg_classify(dev, sg, end, alpha_mv.mv_pci_tbi != 0);
 
        /* Second, figure out where we're going to map things.  */
        if (alpha_mv.mv_pci_tbi) {
@@ -658,7 +670,7 @@ pci_map_sg(struct pci_dev *pdev, struct scatterlist *sg, int nents,
        for (out = sg; sg < end; ++sg) {
                if ((int) sg->dma_address < 0)
                        continue;
-               if (sg_fill(sg, end, out, arena, max_dma, dac_allowed) < 0)
+               if (sg_fill(dev, sg, end, out, arena, max_dma, dac_allowed) < 0)
                        goto error;
                out++;
        }
index bd5e68cd61e84fb440bd0a618b6c90019d48fb75..beff6297f788a029aa7423bc2a615915a764126d 100644 (file)
@@ -58,7 +58,6 @@ static struct notifier_block alpha_panic_block = {
 #include <asm/system.h>
 #include <asm/hwrpb.h>
 #include <asm/dma.h>
-#include <asm/io.h>
 #include <asm/mmu_context.h>
 #include <asm/console.h>
 
index f4ab233201b296013c7c45511a953838d29226d8..63c2073401ee5ce9bf75cbe90f28bffb88cc8375 100644 (file)
@@ -77,10 +77,6 @@ int smp_num_probed;          /* Internal processor count */
 int smp_num_cpus = 1;          /* Number that came online.  */
 EXPORT_SYMBOL(smp_num_cpus);
 
-extern void calibrate_delay(void);
-
-\f
-
 /*
  * Called by both boot and secondaries to move global data into
  *  per-processor storage.
index 79de99e32c35f91ad2fcebc0ab8513bc5fd612d7..ba914af18c4f30cc60d915277a04c9865d68308c 100644 (file)
@@ -495,7 +495,7 @@ sys_call_table:
        .quad sys_epoll_pwait
        .quad sys_utimensat                     /* 475 */
        .quad sys_signalfd
-       .quad sys_timerfd
+       .quad sys_ni_syscall
        .quad sys_eventfd
 
        .size sys_call_table, . - sys_call_table
index 77201d3f7479ccc65bf2e454fa310be75580a49b..e19e7744e366a3a8d14bbb7aa7fb5ab4d0d13986 100644 (file)
@@ -10,6 +10,8 @@ config ARM
        default y
        select RTC_LIB
        select SYS_SUPPORTS_APM_EMULATION
+       select HAVE_OPROFILE
+       select HAVE_KPROBES if (!XIP_KERNEL)
        help
          The ARM series is a line of low-power-consumption RISC chip designs
          licensed by ARM Ltd and targeted at embedded applications and
@@ -33,6 +35,11 @@ config GENERIC_CLOCKEVENTS
        bool
        default n
 
+config GENERIC_CLOCKEVENTS_BROADCAST
+       bool
+       depends on GENERIC_CLOCKEVENTS
+       default y if SMP && !LOCAL_TIMERS
+
 config MMU
        bool
        default y
@@ -135,6 +142,23 @@ config FIQ
 config ARCH_MTD_XIP
        bool
 
+if OPROFILE
+
+config OPROFILE_ARMV6
+       def_bool y
+       depends on CPU_V6 && !SMP
+       select OPROFILE_ARM11_CORE
+
+config OPROFILE_MPCORE
+       def_bool y
+       depends on CPU_V6 && SMP
+       select OPROFILE_ARM11_CORE
+
+config OPROFILE_ARM11_CORE
+       bool
+
+endif
+
 config VECTORS_BASE
        hex
        default 0xffff0000 if MMU || CPU_HIGH_VECTOR
@@ -168,6 +192,8 @@ config ARCH_REALVIEW
        bool "ARM Ltd. RealView family"
        select ARM_AMBA
        select ICST307
+       select GENERIC_TIME
+       select GENERIC_CLOCKEVENTS
        help
          This enables support for ARM Ltd RealView boards.
 
@@ -359,6 +385,7 @@ config ARCH_PXA
        depends on MMU
        select ARCH_MTD_XIP
        select GENERIC_GPIO
+       select HAVE_GPIO_LIB
        select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select TICK_ONESHOT
@@ -577,11 +604,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 config PCI_SYSCALL
        def_bool PCI
 
@@ -609,7 +631,7 @@ source "kernel/time/Kconfig"
 
 config SMP
        bool "Symmetric Multi-Processing (EXPERIMENTAL)"
-       depends on EXPERIMENTAL && REALVIEW_MPCORE
+       depends on EXPERIMENTAL && REALVIEW_EB_ARM11MP
        help
          This enables support for systems with more than one CPU. If you have
          a system with only one CPU, like most personal computers, say N. If
@@ -621,8 +643,7 @@ config SMP
          processor machines. On a single processor machine, the kernel will
          run faster if you say N here.
 
-         See also the <file:Documentation/smp.txt>,
-         <file:Documentation/i386/IO-APIC.txt>,
+         See also <file:Documentation/i386/IO-APIC.txt>,
          <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available at
          <http://www.linuxdoc.org/docs.html#howto>.
 
@@ -643,7 +664,7 @@ config HOTPLUG_CPU
 
 config LOCAL_TIMERS
        bool "Use local timer interrupts"
-       depends on SMP && REALVIEW_MPCORE
+       depends on SMP && REALVIEW_EB_ARM11MP
        default y
        help
          Enable support for local timers on SMP platforms, rather then the
@@ -899,6 +920,13 @@ config KEXEC
          initially work for you.  It may help to enable device hotplugging
          support.
 
+config ATAGS_PROC
+       bool "Export atags in procfs"
+       default n
+       help
+         Should the atags used to boot the kernel be exported in an "atags"
+         file in procfs. Useful with kexec.
+
 endmenu
 
 if (ARCH_SA1100 || ARCH_INTEGRATOR || ARCH_OMAP || ARCH_IMX || ARCH_PXA)
@@ -1035,6 +1063,9 @@ menu "Power management options"
 
 source "kernel/power/Kconfig"
 
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+
 endmenu
 
 source "net/Kconfig"
@@ -1092,6 +1123,8 @@ source "drivers/i2c/Kconfig"
 
 source "drivers/spi/Kconfig"
 
+source "drivers/gpio/Kconfig"
+
 source "drivers/w1/Kconfig"
 
 source "drivers/power/Kconfig"
@@ -1130,8 +1163,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "arch/arm/Kconfig.instrumentation"
-
 source "arch/arm/Kconfig.debug"
 
 source "security/Kconfig"
diff --git a/arch/arm/Kconfig.instrumentation b/arch/arm/Kconfig.instrumentation
deleted file mode 100644 (file)
index 453ad8e..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-menuconfig INSTRUMENTATION
-       bool "Instrumentation Support"
-       default y
-       ---help---
-         Say Y here to get to see options related to performance measurement,
-         system-wide debugging, and testing. This option alone does not add any
-         kernel code.
-
-         If you say N, all options in this submenu will be skipped and
-         disabled. If you're trying to debug the kernel itself, go see the
-         Kernel Hacking menu.
-
-if INSTRUMENTATION
-
-config PROFILING
-       bool "Profiling support (EXPERIMENTAL)"
-       help
-         Say Y here to enable the extended profiling support mechanisms used
-         by profilers such as OProfile.
-
-config OPROFILE
-       tristate "OProfile system profiling (EXPERIMENTAL)"
-       depends on PROFILING && !UML
-       help
-         OProfile is a profiling system capable of profiling the
-         whole system, include the kernel, kernel modules, libraries,
-         and applications.
-
-         If unsure, say N.
-
-config OPROFILE_ARMV6
-       bool
-       depends on OPROFILE && CPU_V6 && !SMP
-       default y
-       select OPROFILE_ARM11_CORE
-
-config OPROFILE_MPCORE
-       bool
-       depends on OPROFILE && CPU_V6 && SMP
-       default y
-       select OPROFILE_ARM11_CORE
-
-config OPROFILE_ARM11_CORE
-       bool
-
-config KPROBES
-       bool "Kprobes"
-       depends on KALLSYMS && MODULES && !UML && !XIP_KERNEL
-       help
-         Kprobes allows you to trap at almost any kernel address and
-         execute a callback function.  register_kprobe() establishes
-         a probepoint and specifies the callback.  Kprobes is useful
-         for kernel debugging, non-intrusive instrumentation and testing.
-         If in doubt, say "N".
-
-config MARKERS
-       bool "Activate markers"
-       help
-         Place an empty function call at each marker site. Can be
-         dynamically changed for a probe function.
-
-endif # INSTRUMENTATION
index 34038eccbba9e478b3bfb75ec283e289fee63cb2..d544da4147310954c6013e37863e786ece6ff312 100644 (file)
@@ -69,9 +69,7 @@ void __init ioctime_init(void)
 static irqreturn_t
 ioc_timer_interrupt(int irq, void *dev_id)
 {
-       write_seqlock(&xtime_lock);
        timer_tick();
-       write_sequnlock(&xtime_lock);
        return IRQ_HANDLED;
 }
 
index db850a5689eb52c9438853877175aa26f38365e8..efa0485d2f7ec10eb01ed26b47b3180e3a66e47e 100644 (file)
@@ -1,69 +1,96 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.15
-# Tue Jan  3 03:20:40 2006
+# Linux kernel version: 2.6.24
+# Sun Jan 27 07:33:38 2008
 #
 CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
 CONFIG_MMU=y
-CONFIG_UID16=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 
 #
-# Code maturity level options
+# General setup
 #
 CONFIG_EXPERIMENTAL=y
-CONFIG_CLEAN_COMPILE=y
 CONFIG_BROKEN_ON_SMP=y
 CONFIG_INIT_ENV_ARG_LIMIT=32
-
-#
-# General setup
-#
 CONFIG_LOCALVERSION=""
 CONFIG_LOCALVERSION_AUTO=y
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 CONFIG_BSD_PROCESS_ACCT=y
 # CONFIG_BSD_PROCESS_ACCT_V3 is not set
-CONFIG_SYSCTL=y
+# CONFIG_TASKSTATS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
 # CONFIG_AUDIT is not set
-# CONFIG_HOTPLUG is not set
-CONFIG_KOBJECT_UEVENT=y
 # CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_FAIR_USER_SCHED=y
+# CONFIG_FAIR_CGROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+# CONFIG_RELAY is not set
+CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
 CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
 CONFIG_KALLSYMS=y
 # CONFIG_KALLSYMS_ALL is not set
 # CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
 CONFIG_PRINTK=y
 CONFIG_BUG=y
+CONFIG_ELF_CORE=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
 CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_EVENTFD=y
 CONFIG_SHMEM=y
-CONFIG_CC_ALIGN_FUNCTIONS=0
-CONFIG_CC_ALIGN_LABELS=0
-CONFIG_CC_ALIGN_LOOPS=0
-CONFIG_CC_ALIGN_JUMPS=0
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLUB_DEBUG=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
 # CONFIG_TINY_SHMEM is not set
 CONFIG_BASE_SMALL=0
-
-#
-# Loadable module support
-#
 CONFIG_MODULES=y
 # CONFIG_MODULE_UNLOAD is not set
-CONFIG_OBSOLETE_MODPARM=y
 CONFIG_MODVERSIONS=y
 # CONFIG_MODULE_SRCVERSION_ALL is not set
 CONFIG_KMOD=y
-
-#
-# Block layer
-#
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
 
 #
 # IO Schedulers
@@ -81,28 +108,39 @@ CONFIG_DEFAULT_IOSCHED="anticipatory"
 #
 # System Type
 #
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
 # CONFIG_ARCH_CLPS7500 is not set
 # CONFIG_ARCH_CLPS711X is not set
 # CONFIG_ARCH_CO285 is not set
 # CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
 # CONFIG_ARCH_FOOTBRIDGE is not set
-# CONFIG_ARCH_INTEGRATOR is not set
-# CONFIG_ARCH_IOP3XX is not set
-CONFIG_ARCH_IXP4XX=y
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
 # CONFIG_ARCH_IXP2000 is not set
+CONFIG_ARCH_IXP4XX=y
 # CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_PNX4008 is not set
 # CONFIG_ARCH_PXA is not set
 # CONFIG_ARCH_RPC is not set
 # CONFIG_ARCH_SA1100 is not set
 # CONFIG_ARCH_S3C2410 is not set
 # CONFIG_ARCH_SHARK is not set
 # CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
 # CONFIG_ARCH_OMAP is not set
-# CONFIG_ARCH_VERSATILE is not set
-# CONFIG_ARCH_REALVIEW is not set
-# CONFIG_ARCH_IMX is not set
-# CONFIG_ARCH_H720X is not set
-# CONFIG_ARCH_AAEC2000 is not set
 CONFIG_ARCH_SUPPORTS_BIG_ENDIAN=y
 
 #
@@ -112,8 +150,12 @@ CONFIG_ARCH_SUPPORTS_BIG_ENDIAN=y
 #
 # IXP4xx Platforms
 #
-CONFIG_ARCH_AVILA=y
+CONFIG_MACH_NSLU2=y
+CONFIG_MACH_AVILA=y
+CONFIG_MACH_LOFT=y
 CONFIG_ARCH_ADI_COYOTE=y
+CONFIG_MACH_GATEWAY7001=y
+CONFIG_MACH_WG302V2=y
 CONFIG_ARCH_IXDP425=y
 CONFIG_MACH_IXDPG425=y
 CONFIG_MACH_IXDP465=y
@@ -121,15 +163,27 @@ CONFIG_MACH_KIXRP435=y
 CONFIG_ARCH_IXCDP1100=y
 CONFIG_ARCH_PRPMC1100=y
 CONFIG_MACH_NAS100D=y
+CONFIG_MACH_DSMG600=y
 CONFIG_ARCH_IXDP4XX=y
 CONFIG_CPU_IXP46X=y
 CONFIG_CPU_IXP43X=y
-# CONFIG_MACH_GTWX5715 is not set
+CONFIG_MACH_GTWX5715=y
 
 #
 # IXP4xx Options
 #
+CONFIG_DMABOUNCE=y
 # CONFIG_IXP4XX_INDIRECT_PCI is not set
+CONFIG_IXP4XX_QMGR=y
+CONFIG_IXP4XX_NPE=y
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
 
 #
 # Processor Type
@@ -140,33 +194,40 @@ CONFIG_CPU_32v5=y
 CONFIG_CPU_ABRT_EV5T=y
 CONFIG_CPU_CACHE_VIVT=y
 CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
 
 #
 # Processor Features
 #
 # CONFIG_ARM_THUMB is not set
 CONFIG_CPU_BIG_ENDIAN=y
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_OUTER_CACHE is not set
+# CONFIG_IWMMXT is not set
 CONFIG_XSCALE_PMU=y
-CONFIG_DMABOUNCE=y
 
 #
 # Bus support
 #
-CONFIG_ISA_DMA_API=y
 CONFIG_PCI=y
-CONFIG_PCI_LEGACY_PROC=y
+CONFIG_PCI_SYSCALL=y
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_DEBUG is not set
-
-#
-# PCCARD (PCMCIA/CardBus) support
-#
 # CONFIG_PCCARD is not set
 
 #
 # Kernel Features
 #
+# CONFIG_TICK_ONESHOT is not set
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
 CONFIG_SELECT_MEMORY_MODEL=y
 CONFIG_FLATMEM_MANUAL=y
@@ -175,7 +236,12 @@ CONFIG_FLATMEM_MANUAL=y
 CONFIG_FLATMEM=y
 CONFIG_FLAT_NODE_MEM_MAP=y
 # CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
 CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
 CONFIG_ALIGNMENT_TRAP=y
 
 #
@@ -185,6 +251,7 @@ CONFIG_ZBOOT_ROM_TEXT=0x0
 CONFIG_ZBOOT_ROM_BSS=0x0
 CONFIG_CMDLINE="console=ttyS0,115200 ip=bootp root=/dev/nfs"
 # CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
 
 #
 # Floating point emulation
@@ -203,13 +270,12 @@ CONFIG_FPE_NWFPE=y
 CONFIG_BINFMT_ELF=y
 # CONFIG_BINFMT_AOUT is not set
 # CONFIG_BINFMT_MISC is not set
-# CONFIG_ARTHUR is not set
 
 #
 # Power management options
 #
 # CONFIG_PM is not set
-# CONFIG_APM is not set
+CONFIG_SUSPEND_UP_POSSIBLE=y
 
 #
 # Networking
@@ -219,11 +285,13 @@ CONFIG_NET=y
 #
 # Networking options
 #
-CONFIG_PACKET=m
+CONFIG_PACKET=y
 CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 CONFIG_IP_MULTICAST=y
@@ -232,9 +300,7 @@ CONFIG_ASK_IP_FIB_HASH=y
 # CONFIG_IP_FIB_TRIE is not set
 CONFIG_IP_FIB_HASH=y
 CONFIG_IP_MULTIPLE_TABLES=y
-CONFIG_IP_ROUTE_FWMARK=y
 CONFIG_IP_ROUTE_MULTIPATH=y
-# CONFIG_IP_ROUTE_MULTIPATH_CACHED is not set
 CONFIG_IP_ROUTE_VERBOSE=y
 CONFIG_IP_PNP=y
 CONFIG_IP_PNP_DHCP=y
@@ -251,15 +317,18 @@ CONFIG_SYN_COOKIES=y
 # CONFIG_INET_AH is not set
 # CONFIG_INET_ESP is not set
 # CONFIG_INET_IPCOMP is not set
-CONFIG_INET_TUNNEL=m
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_XFRM_MODE_TRANSPORT=y
+CONFIG_INET_XFRM_MODE_TUNNEL=y
+CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
 CONFIG_INET_DIAG=y
 CONFIG_INET_TCP_DIAG=y
 # CONFIG_TCP_CONG_ADVANCED is not set
-CONFIG_TCP_CONG_BIC=y
-
-#
-# IP: Virtual Server Configuration
-#
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
 CONFIG_IP_VS=m
 CONFIG_IP_VS_DEBUG=y
 CONFIG_IP_VS_TAB_BITS=12
@@ -290,6 +359,9 @@ CONFIG_IP_VS_SH=m
 # IPVS application helper
 #
 # CONFIG_IPV6 is not set
+# CONFIG_INET6_XFRM_TUNNEL is not set
+# CONFIG_INET6_TUNNEL is not set
+# CONFIG_NETWORK_SECMARK is not set
 CONFIG_NETFILTER=y
 # CONFIG_NETFILTER_DEBUG is not set
 CONFIG_BRIDGE_NETFILTER=y
@@ -298,70 +370,57 @@ CONFIG_BRIDGE_NETFILTER=y
 # Core Netfilter Configuration
 #
 # CONFIG_NETFILTER_NETLINK is not set
+# CONFIG_NF_CONNTRACK_ENABLED is not set
+# CONFIG_NF_CONNTRACK is not set
+CONFIG_NETFILTER_XTABLES=m
+# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
+# CONFIG_NETFILTER_XT_TARGET_DSCP is not set
+# CONFIG_NETFILTER_XT_TARGET_MARK is not set
+# CONFIG_NETFILTER_XT_TARGET_NFQUEUE is not set
+# CONFIG_NETFILTER_XT_TARGET_NFLOG is not set
+# CONFIG_NETFILTER_XT_TARGET_TCPMSS is not set
+# CONFIG_NETFILTER_XT_MATCH_COMMENT is not set
+# CONFIG_NETFILTER_XT_MATCH_DCCP is not set
+# CONFIG_NETFILTER_XT_MATCH_DSCP is not set
+# CONFIG_NETFILTER_XT_MATCH_ESP is not set
+# CONFIG_NETFILTER_XT_MATCH_LENGTH is not set
+# CONFIG_NETFILTER_XT_MATCH_LIMIT is not set
+# CONFIG_NETFILTER_XT_MATCH_MAC is not set
+# CONFIG_NETFILTER_XT_MATCH_MARK is not set
+# CONFIG_NETFILTER_XT_MATCH_POLICY is not set
+# CONFIG_NETFILTER_XT_MATCH_MULTIPORT is not set
+# CONFIG_NETFILTER_XT_MATCH_PHYSDEV is not set
+# CONFIG_NETFILTER_XT_MATCH_PKTTYPE is not set
+# CONFIG_NETFILTER_XT_MATCH_QUOTA is not set
+# CONFIG_NETFILTER_XT_MATCH_REALM is not set
+# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
+# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
+# CONFIG_NETFILTER_XT_MATCH_STRING is not set
+# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
+# CONFIG_NETFILTER_XT_MATCH_TIME is not set
+# CONFIG_NETFILTER_XT_MATCH_U32 is not set
+# CONFIG_NETFILTER_XT_MATCH_HASHLIMIT is not set
 
 #
 # IP: Netfilter Configuration
 #
-CONFIG_IP_NF_CONNTRACK=m
-# CONFIG_IP_NF_CT_ACCT is not set
-# CONFIG_IP_NF_CONNTRACK_MARK is not set
-# CONFIG_IP_NF_CONNTRACK_EVENTS is not set
-# CONFIG_IP_NF_CT_PROTO_SCTP is not set
-CONFIG_IP_NF_FTP=m
-CONFIG_IP_NF_IRC=m
-# CONFIG_IP_NF_NETBIOS_NS is not set
-# CONFIG_IP_NF_TFTP is not set
-# CONFIG_IP_NF_AMANDA is not set
-# CONFIG_IP_NF_PPTP is not set
 CONFIG_IP_NF_QUEUE=m
 CONFIG_IP_NF_IPTABLES=m
-CONFIG_IP_NF_MATCH_LIMIT=m
 # CONFIG_IP_NF_MATCH_IPRANGE is not set
-CONFIG_IP_NF_MATCH_MAC=m
-# CONFIG_IP_NF_MATCH_PKTTYPE is not set
-CONFIG_IP_NF_MATCH_MARK=m
-CONFIG_IP_NF_MATCH_MULTIPORT=m
 CONFIG_IP_NF_MATCH_TOS=m
 # CONFIG_IP_NF_MATCH_RECENT is not set
 # CONFIG_IP_NF_MATCH_ECN is not set
-# CONFIG_IP_NF_MATCH_DSCP is not set
-CONFIG_IP_NF_MATCH_AH_ESP=m
-CONFIG_IP_NF_MATCH_LENGTH=m
+# CONFIG_IP_NF_MATCH_AH is not set
 CONFIG_IP_NF_MATCH_TTL=m
-CONFIG_IP_NF_MATCH_TCPMSS=m
-# CONFIG_IP_NF_MATCH_HELPER is not set
-CONFIG_IP_NF_MATCH_STATE=m
-# CONFIG_IP_NF_MATCH_CONNTRACK is not set
 CONFIG_IP_NF_MATCH_OWNER=m
-# CONFIG_IP_NF_MATCH_PHYSDEV is not set
 # CONFIG_IP_NF_MATCH_ADDRTYPE is not set
-# CONFIG_IP_NF_MATCH_REALM is not set
-# CONFIG_IP_NF_MATCH_SCTP is not set
-# CONFIG_IP_NF_MATCH_DCCP is not set
-# CONFIG_IP_NF_MATCH_COMMENT is not set
-# CONFIG_IP_NF_MATCH_HASHLIMIT is not set
-# CONFIG_IP_NF_MATCH_STRING is not set
 CONFIG_IP_NF_FILTER=m
 CONFIG_IP_NF_TARGET_REJECT=m
 CONFIG_IP_NF_TARGET_LOG=m
 CONFIG_IP_NF_TARGET_ULOG=m
-CONFIG_IP_NF_TARGET_TCPMSS=m
-# CONFIG_IP_NF_TARGET_NFQUEUE is not set
-CONFIG_IP_NF_NAT=m
-CONFIG_IP_NF_NAT_NEEDED=y
-CONFIG_IP_NF_TARGET_MASQUERADE=m
-CONFIG_IP_NF_TARGET_REDIRECT=m
-# CONFIG_IP_NF_TARGET_NETMAP is not set
-# CONFIG_IP_NF_TARGET_SAME is not set
-CONFIG_IP_NF_NAT_SNMP_BASIC=m
-CONFIG_IP_NF_NAT_IRC=m
-CONFIG_IP_NF_NAT_FTP=m
 CONFIG_IP_NF_MANGLE=m
 CONFIG_IP_NF_TARGET_TOS=m
 # CONFIG_IP_NF_TARGET_ECN is not set
-# CONFIG_IP_NF_TARGET_DSCP is not set
-CONFIG_IP_NF_TARGET_MARK=m
-# CONFIG_IP_NF_TARGET_CLASSIFY is not set
 # CONFIG_IP_NF_TARGET_TTL is not set
 # CONFIG_IP_NF_RAW is not set
 CONFIG_IP_NF_ARPTABLES=m
@@ -372,16 +431,9 @@ CONFIG_IP_NF_ARPFILTER=m
 # Bridge: Netfilter Configuration
 #
 # CONFIG_BRIDGE_NF_EBTABLES is not set
-
-#
-# DCCP Configuration (EXPERIMENTAL)
-#
 # CONFIG_IP_DCCP is not set
-
-#
-# SCTP Configuration (EXPERIMENTAL)
-#
 # CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
 CONFIG_ATM=y
 CONFIG_ATM_CLIP=y
 # CONFIG_ATM_CLIP_NO_ICMP is not set
@@ -397,25 +449,17 @@ CONFIG_LLC=m
 CONFIG_IPX=m
 # CONFIG_IPX_INTERN is not set
 CONFIG_ATALK=m
-CONFIG_DEV_APPLETALK=y
+CONFIG_DEV_APPLETALK=m
 CONFIG_IPDDP=m
 CONFIG_IPDDP_ENCAP=y
 CONFIG_IPDDP_DECAP=y
 CONFIG_X25=m
 CONFIG_LAPB=m
-# CONFIG_NET_DIVERT is not set
 CONFIG_ECONET=m
 CONFIG_ECONET_AUNUDP=y
 CONFIG_ECONET_NATIVE=y
 CONFIG_WAN_ROUTER=m
-
-#
-# QoS and/or fair queueing
-#
 CONFIG_NET_SCHED=y
-CONFIG_NET_SCH_CLK_JIFFIES=y
-# CONFIG_NET_SCH_CLK_GETTIMEOFDAY is not set
-# CONFIG_NET_SCH_CLK_CPU is not set
 
 #
 # Queueing/Scheduling
@@ -425,6 +469,7 @@ CONFIG_NET_SCH_HTB=m
 # CONFIG_NET_SCH_HFSC is not set
 # CONFIG_NET_SCH_ATM is not set
 CONFIG_NET_SCH_PRIO=m
+# CONFIG_NET_SCH_RR is not set
 CONFIG_NET_SCH_RED=m
 CONFIG_NET_SCH_SFQ=m
 CONFIG_NET_SCH_TEQL=m
@@ -449,10 +494,17 @@ CONFIG_NET_CLS_U32=m
 CONFIG_NET_CLS_RSVP=m
 CONFIG_NET_CLS_RSVP6=m
 # CONFIG_NET_EMATCH is not set
-# CONFIG_NET_CLS_ACT is not set
+CONFIG_NET_CLS_ACT=y
+CONFIG_NET_ACT_POLICE=y
+# CONFIG_NET_ACT_GACT is not set
+# CONFIG_NET_ACT_MIRRED is not set
+# CONFIG_NET_ACT_IPT is not set
+# CONFIG_NET_ACT_NAT is not set
+# CONFIG_NET_ACT_PEDIT is not set
+# CONFIG_NET_ACT_SIMP is not set
 CONFIG_NET_CLS_POLICE=y
 # CONFIG_NET_CLS_IND is not set
-CONFIG_NET_ESTIMATOR=y
+CONFIG_NET_SCH_FIFO=y
 
 #
 # Network testing
@@ -461,7 +513,18 @@ CONFIG_NET_PKTGEN=m
 # CONFIG_HAMRADIO is not set
 # CONFIG_IRDA is not set
 # CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+CONFIG_FIB_RULES=y
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
 # CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
 
 #
 # Device Drivers
@@ -470,19 +533,14 @@ CONFIG_NET_PKTGEN=m
 #
 # Generic Driver Options
 #
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
 CONFIG_STANDALONE=y
 CONFIG_PREVENT_FIRMWARE_BUILD=y
-# CONFIG_FW_LOADER is not set
+CONFIG_FW_LOADER=y
 # CONFIG_DEBUG_DRIVER is not set
-
-#
-# Connector - unified userspace <-> kernelspace linker
-#
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
 # CONFIG_CONNECTOR is not set
-
-#
-# Memory Technology Devices (MTD)
-#
 CONFIG_MTD=y
 # CONFIG_MTD_DEBUG is not set
 # CONFIG_MTD_CONCAT is not set
@@ -498,11 +556,14 @@ CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
 # User Modules And Translation Layers
 #
 CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
 CONFIG_MTD_BLOCK=y
 # CONFIG_FTL is not set
 # CONFIG_NFTL is not set
 # CONFIG_INFTL is not set
 # CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
 
 #
 # RAM/ROM/Flash chip drivers
@@ -528,7 +589,6 @@ CONFIG_MTD_CFI_UTIL=y
 # CONFIG_MTD_RAM is not set
 # CONFIG_MTD_ROM is not set
 # CONFIG_MTD_ABSENT is not set
-# CONFIG_MTD_XIP is not set
 
 #
 # Mapping drivers for chip access
@@ -538,6 +598,7 @@ CONFIG_MTD_COMPLEX_MAPPINGS=y
 # CONFIG_MTD_ARM_INTEGRATOR is not set
 CONFIG_MTD_IXP4XX=y
 # CONFIG_MTD_PCI is not set
+# CONFIG_MTD_INTEL_VR_NOR is not set
 # CONFIG_MTD_PLATRAM is not set
 
 #
@@ -547,7 +608,6 @@ CONFIG_MTD_IXP4XX=y
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_PHRAM is not set
 # CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_BLKMTD is not set
 # CONFIG_MTD_BLOCK2MTD is not set
 
 #
@@ -556,33 +616,24 @@ CONFIG_MTD_IXP4XX=y
 # CONFIG_MTD_DOC2000 is not set
 # CONFIG_MTD_DOC2001 is not set
 # CONFIG_MTD_DOC2001PLUS is not set
-
-#
-# NAND Flash Device Drivers
-#
 CONFIG_MTD_NAND=m
 # CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
 CONFIG_MTD_NAND_IDS=m
 # CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_CAFE is not set
 # CONFIG_MTD_NAND_NANDSIM is not set
-
-#
-# OneNAND Flash Device Drivers
-#
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
 # CONFIG_MTD_ONENAND is not set
 
 #
-# Parallel port support
+# UBI - Unsorted block images
 #
+# CONFIG_MTD_UBI is not set
 # CONFIG_PARPORT is not set
-
-#
-# Plug and Play support
-#
-
-#
-# Block devices
-#
+CONFIG_BLK_DEV=y
 # CONFIG_BLK_CPQ_DA is not set
 # CONFIG_BLK_CPQ_CISS_DA is not set
 # CONFIG_BLK_DEV_DAC960 is not set
@@ -592,17 +643,20 @@ CONFIG_BLK_DEV_LOOP=y
 # CONFIG_BLK_DEV_CRYPTOLOOP is not set
 # CONFIG_BLK_DEV_NBD is not set
 # CONFIG_BLK_DEV_SX8 is not set
+# CONFIG_BLK_DEV_UB is not set
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=8192
-CONFIG_BLK_DEV_INITRD=y
+CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
-
-#
-# ATA/ATAPI/MFM/RLL support
-#
+CONFIG_MISC_DEVICES=y
+# CONFIG_PHANTOM is not set
+# CONFIG_EEPROM_93CX6 is not set
+# CONFIG_SGI_IOC4 is not set
+# CONFIG_TIFM_CORE is not set
 CONFIG_IDE=y
+CONFIG_IDE_MAX_HWIFS=4
 CONFIG_BLK_DEV_IDE=y
 
 #
@@ -614,24 +668,28 @@ CONFIG_BLK_DEV_IDEDISK=y
 # CONFIG_BLK_DEV_IDECD is not set
 # CONFIG_BLK_DEV_IDETAPE is not set
 # CONFIG_BLK_DEV_IDEFLOPPY is not set
+# CONFIG_BLK_DEV_IDESCSI is not set
 # CONFIG_IDE_TASK_IOCTL is not set
+CONFIG_IDE_PROC_FS=y
 
 #
 # IDE chipset support/bugfixes
 #
 CONFIG_IDE_GENERIC=y
+# CONFIG_BLK_DEV_PLATFORM is not set
+
+#
+# PCI IDE chipsets support
+#
 CONFIG_BLK_DEV_IDEPCI=y
 # CONFIG_IDEPCI_SHARE_IRQ is not set
+CONFIG_IDEPCI_PCIBUS_ORDER=y
 # CONFIG_BLK_DEV_OFFBOARD is not set
 # CONFIG_BLK_DEV_GENERIC is not set
 # CONFIG_BLK_DEV_OPTI621 is not set
-# CONFIG_BLK_DEV_SL82C105 is not set
 CONFIG_BLK_DEV_IDEDMA_PCI=y
-# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
-# CONFIG_IDEDMA_PCI_AUTO is not set
 # CONFIG_BLK_DEV_AEC62XX is not set
 # CONFIG_BLK_DEV_ALI15X3 is not set
-# CONFIG_BLK_DEV_AMD74XX is not set
 CONFIG_BLK_DEV_CMD64X=y
 # CONFIG_BLK_DEV_TRIFLEX is not set
 # CONFIG_BLK_DEV_CY82C693 is not set
@@ -639,93 +697,163 @@ CONFIG_BLK_DEV_CMD64X=y
 # CONFIG_BLK_DEV_CS5530 is not set
 # CONFIG_BLK_DEV_HPT34X is not set
 CONFIG_BLK_DEV_HPT366=y
+# CONFIG_BLK_DEV_JMICRON is not set
 # CONFIG_BLK_DEV_SC1200 is not set
 # CONFIG_BLK_DEV_PIIX is not set
+# CONFIG_BLK_DEV_IT8213 is not set
 # CONFIG_BLK_DEV_IT821X is not set
 # CONFIG_BLK_DEV_NS87415 is not set
 # CONFIG_BLK_DEV_PDC202XX_OLD is not set
 CONFIG_BLK_DEV_PDC202XX_NEW=y
-# CONFIG_PDC202XX_FORCE is not set
 # CONFIG_BLK_DEV_SVWKS is not set
 # CONFIG_BLK_DEV_SIIMAGE is not set
+# CONFIG_BLK_DEV_SL82C105 is not set
 # CONFIG_BLK_DEV_SLC90E66 is not set
 # CONFIG_BLK_DEV_TRM290 is not set
 # CONFIG_BLK_DEV_VIA82CXXX is not set
+# CONFIG_BLK_DEV_TC86C001 is not set
 # CONFIG_IDE_ARM is not set
 CONFIG_BLK_DEV_IDEDMA=y
-# CONFIG_IDEDMA_IVB is not set
-# CONFIG_IDEDMA_AUTO is not set
+CONFIG_IDE_ARCH_OBSOLETE_INIT=y
 # CONFIG_BLK_DEV_HD is not set
 
 #
 # SCSI device support
 #
 # CONFIG_RAID_ATTRS is not set
-# CONFIG_SCSI is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_SCSI_PROC_FS is not set
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+# CONFIG_SCSI_LOWLEVEL is not set
+CONFIG_ATA=y
+# CONFIG_ATA_NONSTANDARD is not set
+# CONFIG_SATA_AHCI is not set
+# CONFIG_SATA_SVW is not set
+# CONFIG_ATA_PIIX is not set
+# CONFIG_SATA_MV is not set
+# CONFIG_SATA_NV is not set
+# CONFIG_PDC_ADMA is not set
+# CONFIG_SATA_QSTOR is not set
+# CONFIG_SATA_PROMISE is not set
+# CONFIG_SATA_SX4 is not set
+# CONFIG_SATA_SIL is not set
+# CONFIG_SATA_SIL24 is not set
+# CONFIG_SATA_SIS is not set
+# CONFIG_SATA_ULI is not set
+# CONFIG_SATA_VIA is not set
+# CONFIG_SATA_VITESSE is not set
+# CONFIG_SATA_INIC162X is not set
+# CONFIG_PATA_ALI is not set
+# CONFIG_PATA_AMD is not set
+CONFIG_PATA_ARTOP=y
+# CONFIG_PATA_ATIIXP is not set
+# CONFIG_PATA_CMD640_PCI is not set
+# CONFIG_PATA_CMD64X is not set
+# CONFIG_PATA_CS5520 is not set
+# CONFIG_PATA_CS5530 is not set
+# CONFIG_PATA_CYPRESS is not set
+# CONFIG_PATA_EFAR is not set
+# CONFIG_ATA_GENERIC is not set
+# CONFIG_PATA_HPT366 is not set
+# CONFIG_PATA_HPT37X is not set
+# CONFIG_PATA_HPT3X2N is not set
+# CONFIG_PATA_HPT3X3 is not set
+# CONFIG_PATA_IT821X is not set
+# CONFIG_PATA_IT8213 is not set
+# CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_TRIFLEX is not set
+# CONFIG_PATA_MARVELL is not set
+# CONFIG_PATA_MPIIX is not set
+# CONFIG_PATA_OLDPIIX is not set
+# CONFIG_PATA_NETCELL is not set
+# CONFIG_PATA_NS87410 is not set
+# CONFIG_PATA_NS87415 is not set
+# CONFIG_PATA_OPTI is not set
+# CONFIG_PATA_OPTIDMA is not set
+# CONFIG_PATA_PDC_OLD is not set
+# CONFIG_PATA_RADISYS is not set
+# CONFIG_PATA_RZ1000 is not set
+# CONFIG_PATA_SC1200 is not set
+# CONFIG_PATA_SERVERWORKS is not set
+# CONFIG_PATA_PDC2027X is not set
+# CONFIG_PATA_SIL680 is not set
+# CONFIG_PATA_SIS is not set
+# CONFIG_PATA_VIA is not set
+# CONFIG_PATA_WINBOND is not set
+# CONFIG_PATA_PLATFORM is not set
+CONFIG_PATA_IXP4XX_CF=y
 # CONFIG_MD is not set
-
-#
-# Fusion MPT device support
-#
 # CONFIG_FUSION is not set
 
 #
 # IEEE 1394 (FireWire) support
 #
+# CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
-
-#
-# I2O device support
-#
 # CONFIG_I2O is not set
-
-#
-# Network device support
-#
 CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_IFB is not set
 CONFIG_DUMMY=y
 # CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
 # CONFIG_EQUALIZER is not set
 # CONFIG_TUN is not set
-
-#
-# ARCnet devices
-#
+# CONFIG_VETH is not set
 # CONFIG_ARCNET is not set
-
-#
-# PHY device support
-#
 # CONFIG_PHYLIB is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
 CONFIG_NET_ETHERNET=y
 CONFIG_MII=y
+CONFIG_IXP4XX_ETH=y
+# CONFIG_AX88796 is not set
 # CONFIG_HAPPYMEAL is not set
 # CONFIG_SUNGEM is not set
 # CONFIG_CASSINI is not set
 # CONFIG_NET_VENDOR_3COM is not set
 # CONFIG_SMC91X is not set
 # CONFIG_DM9000 is not set
-
-#
-# Tulip family network device support
-#
 # CONFIG_NET_TULIP is not set
 # CONFIG_HP100 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
 CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
-# CONFIG_DGRS is not set
 CONFIG_EEPRO100=y
 # CONFIG_E100 is not set
 # CONFIG_FEALNX is not set
@@ -738,93 +866,76 @@ CONFIG_EEPRO100=y
 # CONFIG_SUNDANCE is not set
 # CONFIG_TLAN is not set
 # CONFIG_VIA_RHINE is not set
-
-#
-# Ethernet (1000 Mbit)
-#
+# CONFIG_SC92031 is not set
+CONFIG_NETDEV_1000=y
 # CONFIG_ACENIC is not set
 # CONFIG_DL2K is not set
 # CONFIG_E1000 is not set
+# CONFIG_E1000E is not set
+# CONFIG_IP1000 is not set
 # CONFIG_NS83820 is not set
 # CONFIG_HAMACHI is not set
 # CONFIG_YELLOWFIN is not set
 # CONFIG_R8169 is not set
 # CONFIG_SIS190 is not set
 # CONFIG_SKGE is not set
+# CONFIG_SKY2 is not set
 # CONFIG_SK98LIN is not set
 # CONFIG_VIA_VELOCITY is not set
 # CONFIG_TIGON3 is not set
 # CONFIG_BNX2 is not set
-
-#
-# Ethernet (10000 Mbit)
-#
+# CONFIG_QLA3XXX is not set
+# CONFIG_ATL1 is not set
+CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
+# CONFIG_CHELSIO_T3 is not set
+# CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
 # CONFIG_S2IO is not set
-
-#
-# Token Ring devices
-#
+# CONFIG_MYRI10GE is not set
+# CONFIG_NETXEN_NIC is not set
+# CONFIG_NIU is not set
+# CONFIG_MLX4_CORE is not set
+# CONFIG_TEHUTI is not set
 # CONFIG_TR is not set
 
 #
-# Wireless LAN (non-hamradio)
-#
-CONFIG_NET_RADIO=y
-
-#
-# Obsolete Wireless cards support (pre-802.11)
-#
-# CONFIG_STRIP is not set
-
-#
-# Wireless 802.11b ISA/PCI cards support
-#
-# CONFIG_AIRO is not set
-CONFIG_HERMES=y
-# CONFIG_PLX_HERMES is not set
-# CONFIG_TMD_HERMES is not set
-# CONFIG_NORTEL_HERMES is not set
-CONFIG_PCI_HERMES=y
-# CONFIG_ATMEL is not set
-
-#
-# Prism GT/Duette 802.11(a/b/g) PCI/Cardbus support
+# Wireless LAN
 #
-# CONFIG_PRISM54 is not set
-# CONFIG_HOSTAP is not set
-CONFIG_NET_WIRELESS=y
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
 
 #
-# Wan interfaces
+# USB Network Adapters
 #
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
 CONFIG_WAN=y
-# CONFIG_DSCC4 is not set
 # CONFIG_LANMEDIA is not set
-# CONFIG_SYNCLINK_SYNCPPP is not set
 CONFIG_HDLC=m
-CONFIG_HDLC_RAW=y
+CONFIG_HDLC_RAW=m
 # CONFIG_HDLC_RAW_ETH is not set
-CONFIG_HDLC_CISCO=y
-CONFIG_HDLC_FR=y
-CONFIG_HDLC_PPP=y
-CONFIG_HDLC_X25=y
+CONFIG_HDLC_CISCO=m
+CONFIG_HDLC_FR=m
+CONFIG_HDLC_PPP=m
+CONFIG_HDLC_X25=m
 # CONFIG_PCI200SYN is not set
 # CONFIG_WANXL is not set
 # CONFIG_PC300 is not set
+# CONFIG_PC300TOO is not set
 # CONFIG_FARSYNC is not set
+# CONFIG_DSCC4 is not set
+# CONFIG_IXP4XX_HSS is not set
 CONFIG_DLCI=m
-CONFIG_DLCI_COUNT=24
 CONFIG_DLCI_MAX=8
-CONFIG_WAN_ROUTER_DRIVERS=y
+CONFIG_WAN_ROUTER_DRIVERS=m
 # CONFIG_CYCLADES_SYNC is not set
 # CONFIG_LAPBETHER is not set
 # CONFIG_X25_ASY is not set
-
-#
-# ATM drivers
-#
+CONFIG_ATM_DRIVERS=y
 # CONFIG_ATM_DUMMY is not set
 CONFIG_ATM_TCP=m
 # CONFIG_ATM_LANAI is not set
@@ -842,20 +953,19 @@ CONFIG_ATM_TCP=m
 # CONFIG_HIPPI is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
+# CONFIG_NET_FC is not set
 # CONFIG_SHAPER is not set
 # CONFIG_NETCONSOLE is not set
 # CONFIG_NETPOLL is not set
 # CONFIG_NET_POLL_CONTROLLER is not set
-
-#
-# ISDN subsystem
-#
 # CONFIG_ISDN is not set
 
 #
 # Input device support
 #
 CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
 
 #
 # Userland interfaces
@@ -865,7 +975,6 @@ CONFIG_INPUT_MOUSEDEV_PSAUX=y
 CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
 CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
 # CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_TSDEV is not set
 # CONFIG_INPUT_EVDEV is not set
 # CONFIG_INPUT_EVBUG is not set
 
@@ -875,8 +984,16 @@ CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
 # CONFIG_INPUT_KEYBOARD is not set
 # CONFIG_INPUT_MOUSE is not set
 # CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
 # CONFIG_INPUT_TOUCHSCREEN is not set
-# CONFIG_INPUT_MISC is not set
+CONFIG_INPUT_MISC=y
+CONFIG_INPUT_IXP4XX_BEEPER=y
+# CONFIG_INPUT_ATI_REMOTE is not set
+# CONFIG_INPUT_ATI_REMOTE2 is not set
+# CONFIG_INPUT_KEYSPAN_REMOTE is not set
+# CONFIG_INPUT_POWERMATE is not set
+# CONFIG_INPUT_YEALINK is not set
+# CONFIG_INPUT_UINPUT is not set
 
 #
 # Hardware I/O ports
@@ -895,7 +1012,9 @@ CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
 #
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_PCI=y
 CONFIG_SERIAL_8250_NR_UARTS=2
+CONFIG_SERIAL_8250_RUNTIME_UARTS=2
 # CONFIG_SERIAL_8250_EXTENDED is not set
 
 #
@@ -907,51 +1026,17 @@ CONFIG_SERIAL_CORE_CONSOLE=y
 CONFIG_UNIX98_PTYS=y
 CONFIG_LEGACY_PTYS=y
 CONFIG_LEGACY_PTY_COUNT=256
-
-#
-# IPMI
-#
 # CONFIG_IPMI_HANDLER is not set
-
-#
-# Watchdog Cards
-#
-CONFIG_WATCHDOG=y
-# CONFIG_WATCHDOG_NOWAYOUT is not set
-
-#
-# Watchdog Device Drivers
-#
-# CONFIG_SOFT_WATCHDOG is not set
-CONFIG_IXP4XX_WATCHDOG=y
-
-#
-# PCI-based Watchdog Cards
-#
-# CONFIG_PCIPCWATCHDOG is not set
-# CONFIG_WDTPCI is not set
+CONFIG_HW_RANDOM=m
+CONFIG_HW_RANDOM_IXP4XX=m
 # CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_DTLK is not set
 # CONFIG_R3964 is not set
 # CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_DRM is not set
 # CONFIG_RAW_DRIVER is not set
-
-#
-# TPM devices
-#
 # CONFIG_TCG_TPM is not set
-# CONFIG_TELCLOCK is not set
-
-#
-# I2C support
-#
+CONFIG_DEVPORT=y
 CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
 CONFIG_I2C_CHARDEV=y
 
 #
@@ -969,57 +1054,68 @@ CONFIG_I2C_ALGOBIT=y
 # CONFIG_I2C_ALI15X3 is not set
 # CONFIG_I2C_AMD756 is not set
 # CONFIG_I2C_AMD8111 is not set
+# CONFIG_I2C_GPIO is not set
 # CONFIG_I2C_I801 is not set
 # CONFIG_I2C_I810 is not set
 # CONFIG_I2C_PIIX4 is not set
 # CONFIG_I2C_IOP3XX is not set
 CONFIG_I2C_IXP4XX=y
 # CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_PARPORT_LIGHT is not set
 # CONFIG_I2C_PROSAVAGE is not set
 # CONFIG_I2C_SAVAGE4 is not set
-# CONFIG_SCx200_ACB is not set
+# CONFIG_I2C_SIMTEC is not set
 # CONFIG_I2C_SIS5595 is not set
 # CONFIG_I2C_SIS630 is not set
 # CONFIG_I2C_SIS96X is not set
+# CONFIG_I2C_TAOS_EVM is not set
 # CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
 # CONFIG_I2C_VIA is not set
 # CONFIG_I2C_VIAPRO is not set
 # CONFIG_I2C_VOODOO3 is not set
-# CONFIG_I2C_PCA_ISA is not set
 
 #
 # Miscellaneous I2C Chip support
 #
 # CONFIG_SENSORS_DS1337 is not set
 # CONFIG_SENSORS_DS1374 is not set
+# CONFIG_DS1682 is not set
 CONFIG_SENSORS_EEPROM=y
 # CONFIG_SENSORS_PCF8574 is not set
 # CONFIG_SENSORS_PCA9539 is not set
 # CONFIG_SENSORS_PCF8591 is not set
-# CONFIG_SENSORS_RTC8564 is not set
 # CONFIG_SENSORS_MAX6875 is not set
-# CONFIG_RTC_X1205_I2C is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
 # CONFIG_I2C_DEBUG_CHIP is not set
 
 #
-# Hardware Monitoring support
+# SPI support
 #
+# CONFIG_SPI is not set
+# CONFIG_SPI_MASTER is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
 CONFIG_HWMON=y
 # CONFIG_HWMON_VID is not set
+# CONFIG_SENSORS_AD7418 is not set
 # CONFIG_SENSORS_ADM1021 is not set
 # CONFIG_SENSORS_ADM1025 is not set
 # CONFIG_SENSORS_ADM1026 is not set
+# CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
-# CONFIG_SENSORS_ASB100 is not set
+# CONFIG_SENSORS_ADT7470 is not set
 # CONFIG_SENSORS_ATXP1 is not set
 # CONFIG_SENSORS_DS1621 is not set
-# CONFIG_SENSORS_FSCHER is not set
-# CONFIG_SENSORS_FSCPOS is not set
+# CONFIG_SENSORS_I5K_AMB is not set
+# CONFIG_SENSORS_F71805F is not set
+# CONFIG_SENSORS_F71882FG is not set
+# CONFIG_SENSORS_F75375S is not set
 # CONFIG_SENSORS_GL518SM is not set
 # CONFIG_SENSORS_GL520SM is not set
 # CONFIG_SENSORS_IT87 is not set
@@ -1033,67 +1129,268 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_LM87 is not set
 # CONFIG_SENSORS_LM90 is not set
 # CONFIG_SENSORS_LM92 is not set
+# CONFIG_SENSORS_LM93 is not set
 # CONFIG_SENSORS_MAX1619 is not set
+# CONFIG_SENSORS_MAX6650 is not set
 # CONFIG_SENSORS_PC87360 is not set
+# CONFIG_SENSORS_PC87427 is not set
 # CONFIG_SENSORS_SIS5595 is not set
+# CONFIG_SENSORS_DME1737 is not set
 # CONFIG_SENSORS_SMSC47M1 is not set
+# CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
+# CONFIG_SENSORS_THMC50 is not set
 # CONFIG_SENSORS_VIA686A is not set
+# CONFIG_SENSORS_VT1211 is not set
+# CONFIG_SENSORS_VT8231 is not set
 # CONFIG_SENSORS_W83781D is not set
+# CONFIG_SENSORS_W83791D is not set
 # CONFIG_SENSORS_W83792D is not set
+# CONFIG_SENSORS_W83793 is not set
 # CONFIG_SENSORS_W83L785TS is not set
 # CONFIG_SENSORS_W83627HF is not set
 # CONFIG_SENSORS_W83627EHF is not set
 # CONFIG_HWMON_DEBUG_CHIP is not set
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
 
 #
-# Misc devices
+# Watchdog Device Drivers
 #
+# CONFIG_SOFT_WATCHDOG is not set
+CONFIG_IXP4XX_WATCHDOG=y
 
 #
-# Multimedia Capabilities Port drivers
+# PCI-based Watchdog Cards
 #
+# CONFIG_PCIPCWATCHDOG is not set
+# CONFIG_WDTPCI is not set
 
 #
-# Multimedia devices
+# USB-based Watchdog Cards
 #
-# CONFIG_VIDEO_DEV is not set
+# CONFIG_USBPCWATCHDOG is not set
 
 #
-# Digital Video Broadcasting Devices
+# Sonics Silicon Backplane
 #
-# CONFIG_DVB is not set
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+CONFIG_DAB=y
+# CONFIG_USB_DABUSB is not set
 
 #
 # Graphics support
 #
+# CONFIG_DRM is not set
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
 # CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
 
 #
 # Sound
 #
 # CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
 
 #
-# USB support
+# USB Input Devices
 #
+CONFIG_USB_HID=y
+# CONFIG_USB_HIDINPUT_POWERBOOK is not set
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_SUPPORT=y
 CONFIG_USB_ARCH_HAS_HCD=y
 CONFIG_USB_ARCH_HAS_OHCI=y
-# CONFIG_USB is not set
+CONFIG_USB_ARCH_HAS_EHCI=y
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+# CONFIG_USB_DEVICE_CLASS is not set
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_OTG is not set
+
+#
+# USB Host Controller Drivers
+#
+CONFIG_USB_EHCI_HCD=y
+# CONFIG_USB_EHCI_SPLIT_ISO is not set
+# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
+# CONFIG_USB_EHCI_TT_NEWSCHED is not set
+# CONFIG_USB_ISP116X_HCD is not set
+CONFIG_USB_OHCI_HCD=y
+# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
+# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+CONFIG_USB_UHCI_HCD=y
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
 
 #
 # NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
 #
 
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+# CONFIG_USB_MON is not set
+
+#
+# USB port drivers
+#
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_SISUSBVGA is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+
+#
+# USB DSL modem support
+#
+# CONFIG_USB_ATM is not set
+
 #
 # USB Gadget Support
 #
 # CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
 
 #
-# MMC/SD Card support
+# LED drivers
+#
+# CONFIG_LEDS_IXP4XX is not set
+CONFIG_LEDS_GPIO=y
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_LEDS_TRIGGER_TIMER=y
+CONFIG_LEDS_TRIGGER_IDE_DISK=y
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# I2C RTC drivers
+#
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+CONFIG_RTC_DRV_X1205=y
+CONFIG_RTC_DRV_PCF8563=y
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+
+#
+# SPI RTC drivers
+#
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
 #
-# CONFIG_MMC is not set
 
 #
 # File systems
@@ -1107,16 +1404,19 @@ CONFIG_EXT3_FS=y
 CONFIG_EXT3_FS_XATTR=y
 CONFIG_EXT3_FS_POSIX_ACL=y
 # CONFIG_EXT3_FS_SECURITY is not set
+# CONFIG_EXT4DEV_FS is not set
 CONFIG_JBD=y
-# CONFIG_JBD_DEBUG is not set
 CONFIG_FS_MBCACHE=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 CONFIG_FS_POSIX_ACL=y
 # CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_OCFS2_FS is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_ROMFS_FS is not set
 CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
 CONFIG_DNOTIFY=y
 # CONFIG_AUTOFS_FS is not set
@@ -1140,11 +1440,12 @@ CONFIG_DNOTIFY=y
 # Pseudo filesystems
 #
 CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
 CONFIG_SYSFS=y
 CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
 # CONFIG_HUGETLB_PAGE is not set
-CONFIG_RAMFS=y
-# CONFIG_RELAYFS_FS is not set
+# CONFIG_CONFIGFS_FS is not set
 
 #
 # Miscellaneous filesystems
@@ -1156,13 +1457,15 @@ CONFIG_RAMFS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
 CONFIG_JFFS2_FS=y
 CONFIG_JFFS2_FS_DEBUG=0
 CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
 # CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
 # CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
 CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
 # CONFIG_CRAMFS is not set
@@ -1171,10 +1474,7 @@ CONFIG_JFFS2_RTIME=y
 # CONFIG_QNX4FS_FS is not set
 # CONFIG_SYSV_FS is not set
 # CONFIG_UFS_FS is not set
-
-#
-# Network File Systems
-#
+CONFIG_NETWORK_FILESYSTEMS=y
 CONFIG_NFS_FS=y
 CONFIG_NFS_V3=y
 # CONFIG_NFS_V3_ACL is not set
@@ -1186,6 +1486,7 @@ CONFIG_LOCKD=y
 CONFIG_LOCKD_V4=y
 CONFIG_NFS_COMMON=y
 CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
@@ -1193,7 +1494,6 @@ CONFIG_SUNRPC=y
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
 # CONFIG_AFS_FS is not set
-# CONFIG_9P_FS is not set
 
 #
 # Partition Types
@@ -1213,37 +1513,53 @@ CONFIG_MSDOS_PARTITION=y
 # CONFIG_SGI_PARTITION is not set
 # CONFIG_ULTRIX_PARTITION is not set
 # CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
 # CONFIG_EFI_PARTITION is not set
-
-#
-# Native Language Support
-#
+# CONFIG_SYSV68_PARTITION is not set
 # CONFIG_NLS is not set
-
-#
-# Profiling support
-#
+# CONFIG_DLM is not set
+CONFIG_INSTRUMENTATION=y
 # CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
 
 #
 # Kernel hacking
 #
 # CONFIG_PRINTK_TIME is not set
-CONFIG_DEBUG_KERNEL=y
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
 CONFIG_MAGIC_SYSRQ=y
-CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
 CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
 # CONFIG_SCHEDSTATS is not set
-# CONFIG_DEBUG_SLAB is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
 # CONFIG_DEBUG_KOBJECT is not set
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_INFO is not set
-# CONFIG_DEBUG_FS is not set
 # CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
 CONFIG_FRAME_POINTER=y
+CONFIG_FORCED_INLINING=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
 # CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_SAMPLES is not set
 # CONFIG_DEBUG_USER is not set
 CONFIG_DEBUG_ERRORS=y
 CONFIG_DEBUG_LL=y
@@ -1254,22 +1570,22 @@ CONFIG_DEBUG_LL=y
 #
 # CONFIG_KEYS is not set
 # CONFIG_SECURITY is not set
-
-#
-# Cryptographic options
-#
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
 # CONFIG_CRYPTO is not set
 
-#
-# Hardware crypto devices
-#
-
 #
 # Library routines
 #
+CONFIG_BITREVERSE=y
 # CONFIG_CRC_CCITT is not set
 # CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
 CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
 # CONFIG_LIBCRC32C is not set
 CONFIG_ZLIB_INFLATE=y
 CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index faa7619211534c541f61e370985cf1480f247f52..00d44c6fbfe94be02a5c2aaa0aad6388aaa960a9 100644 (file)
@@ -20,6 +20,7 @@ obj-$(CONFIG_PCI)             += bios32.o isa.o
 obj-$(CONFIG_SMP)              += smp.o
 obj-$(CONFIG_KEXEC)            += machine_kexec.o relocate_kernel.o
 obj-$(CONFIG_KPROBES)          += kprobes.o kprobes-decode.o
+obj-$(CONFIG_ATAGS_PROC)       += atags.o
 obj-$(CONFIG_OABI_COMPAT)      += sys_oabi-compat.o
 
 obj-$(CONFIG_CRUNCH)           += crunch.o crunch-bits.o
diff --git a/arch/arm/kernel/atags.c b/arch/arm/kernel/atags.c
new file mode 100644 (file)
index 0000000..e2e934c
--- /dev/null
@@ -0,0 +1,86 @@
+#include <linux/slab.h>
+#include <linux/kexec.h>
+#include <linux/proc_fs.h>
+#include <asm/setup.h>
+#include <asm/types.h>
+#include <asm/page.h>
+
+struct buffer {
+       size_t size;
+       char *data;
+};
+static struct buffer tags_buffer;
+
+static int
+read_buffer(char* page, char** start, off_t off, int count,
+       int* eof, void* data)
+{
+       struct buffer *buffer = (struct buffer *)data;
+
+       if (off >= buffer->size) {
+               *eof = 1;
+               return 0;
+       }
+
+       count = min((int) (buffer->size - off), count);
+
+       memcpy(page, &buffer->data[off], count);
+
+       return count;
+}
+
+
+static int
+create_proc_entries(void)
+{
+       struct proc_dir_entry* tags_entry;
+
+       tags_entry = create_proc_read_entry("atags", 0400, &proc_root, read_buffer, &tags_buffer);
+       if (!tags_entry)
+               return -ENOMEM;
+
+       return 0;
+}
+
+
+static char __initdata atags_copy_buf[KEXEC_BOOT_PARAMS_SIZE];
+static char __initdata *atags_copy;
+
+void __init save_atags(const struct tag *tags)
+{
+       atags_copy = atags_copy_buf;
+       memcpy(atags_copy, tags, KEXEC_BOOT_PARAMS_SIZE);
+}
+
+
+static int __init init_atags_procfs(void)
+{
+       struct tag *tag;
+       int error;
+
+       if (!atags_copy) {
+               printk(KERN_WARNING "Exporting ATAGs: No saved tags found\n");
+               return -EIO;
+       }
+
+       for (tag = (struct tag *) atags_copy; tag->hdr.size; tag = tag_next(tag))
+               ;
+
+       tags_buffer.size = ((char *) tag - atags_copy) + sizeof(tag->hdr);
+       tags_buffer.data = kmalloc(tags_buffer.size, GFP_KERNEL);
+       if (tags_buffer.data == NULL)
+               return -ENOMEM;
+       memcpy(tags_buffer.data, atags_copy, tags_buffer.size);
+
+       error = create_proc_entries();
+       if (error) {
+               printk(KERN_ERR "Exporting ATAGs: not enough memory\n");
+               kfree(tags_buffer.data);
+               tags_buffer.size = 0;
+               tags_buffer.data = NULL;
+       }
+
+       return error;
+}
+
+arch_initcall(init_atags_procfs);
diff --git a/arch/arm/kernel/atags.h b/arch/arm/kernel/atags.h
new file mode 100644 (file)
index 0000000..e5f028d
--- /dev/null
@@ -0,0 +1,5 @@
+#ifdef CONFIG_ATAGS_PROC
+extern void save_atags(struct tag *tags);
+#else
+static inline void save_atags(struct tag *tags) { }
+#endif
index cecf658e362514e56fc0a56084ece50da5d8a0d2..283e14fff993dde1881b005aa6dbb1598e359780 100644 (file)
                CALL(sys_kexec_load)
                CALL(sys_utimensat)
                CALL(sys_signalfd)
-/* 350 */      CALL(sys_timerfd)
+/* 350 */      CALL(sys_ni_syscall)
                CALL(sys_eventfd)
                CALL(sys_fallocate)
 #ifndef syscalls_counted
index 863c66454f2b44ab82b0be5f55755df471153f5b..db8f54a3451f4f4fd0a8d8bf6dee963374d81db1 100644 (file)
@@ -21,6 +21,7 @@ extern void setup_mm_for_reboot(char mode);
 extern unsigned long kexec_start_address;
 extern unsigned long kexec_indirection_page;
 extern unsigned long kexec_mach_type;
+extern unsigned long kexec_boot_atags;
 
 /*
  * Provide a dummy crash_notes definition while crash dump arrives to arm.
@@ -62,6 +63,7 @@ void machine_kexec(struct kimage *image)
        kexec_start_address = image->start;
        kexec_indirection_page = page_list;
        kexec_mach_type = machine_arch_type;
+       kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
 
        /* copy our kernel relocation code to the control code page */
        memcpy(reboot_code_buffer,
index 062c111c572feb9bc223ea08399e931f67613c10..61930eb0902941030e3e180aca40f6f82697e39e 100644 (file)
@@ -7,23 +7,6 @@
        .globl relocate_new_kernel
 relocate_new_kernel:
 
-       /* Move boot params back to where the kernel expects them */
-
-       ldr     r0,kexec_boot_params_address
-       teq     r0,#0
-       beq     8f
-
-       ldr     r1,kexec_boot_params_copy
-       mov     r6,#KEXEC_BOOT_PARAMS_SIZE/4
-7:
-       ldr     r5,[r1],#4
-       str     r5,[r0],#4
-       subs    r6,r6,#1
-       bne     7b
-
-8:
-       /* Boot params moved, now go on with the kernel */
-
        ldr     r0,kexec_indirection_page
        ldr     r1,kexec_start_address
 
@@ -67,7 +50,7 @@ relocate_new_kernel:
        mov lr,r1
        mov r0,#0
        ldr r1,kexec_mach_type
-       ldr r2,kexec_boot_params_address
+       ldr r2,kexec_boot_atags
        mov pc,lr
 
        .globl kexec_start_address
@@ -82,14 +65,9 @@ kexec_indirection_page:
 kexec_mach_type:
        .long   0x0
 
-       /* phy addr where new kernel will expect to find boot params */
-       .globl kexec_boot_params_address
-kexec_boot_params_address:
-       .long   0x0
-
-       /* phy addr where old kernel put a copy of orig boot params */
-       .globl kexec_boot_params_copy
-kexec_boot_params_copy:
+       /* phy addr of the atags for the new kernel */
+       .globl kexec_boot_atags
+kexec_boot_atags:
        .long   0x0
 
 relocate_new_kernel_end:
index bf56eb337df16a9bc5d7c9033023202ba466cccc..d3941a7b0455cf632cc3ae066ade8fbad7124f2c 100644 (file)
@@ -24,7 +24,6 @@
 #include <linux/interrupt.h>
 #include <linux/smp.h>
 #include <linux/fs.h>
-#include <linux/kexec.h>
 
 #include <asm/cpu.h>
 #include <asm/elf.h>
@@ -39,6 +38,7 @@
 #include <asm/mach/time.h>
 
 #include "compat.h"
+#include "atags.h"
 
 #ifndef MEM_SIZE
 #define MEM_SIZE       (16*1024*1024)
@@ -62,6 +62,7 @@ extern int root_mountflags;
 extern void _stext, _text, _etext, __data_start, _edata, _end;
 
 unsigned int processor_id;
+EXPORT_SYMBOL(processor_id);
 unsigned int __machine_arch_type;
 EXPORT_SYMBOL(__machine_arch_type);
 
@@ -784,23 +785,6 @@ static int __init customize_machine(void)
 }
 arch_initcall(customize_machine);
 
-#ifdef CONFIG_KEXEC
-
-/* Physical addr of where the boot params should be for this machine */
-extern unsigned long kexec_boot_params_address;
-
-/* Physical addr of the buffer into which the boot params are copied */
-extern unsigned long kexec_boot_params_copy;
-
-/* Pointer to the boot params buffer, for manipulation and display */
-unsigned long kexec_boot_params;
-EXPORT_SYMBOL(kexec_boot_params);
-
-/* The buffer itself - make sure it is sized correctly */
-static unsigned long kexec_boot_params_buf[(KEXEC_BOOT_PARAMS_SIZE + 3) / 4];
-
-#endif
-
 void __init setup_arch(char **cmdline_p)
 {
        struct tag *tags = (struct tag *)&init_tags;
@@ -819,18 +803,6 @@ void __init setup_arch(char **cmdline_p)
        else if (mdesc->boot_params)
                tags = phys_to_virt(mdesc->boot_params);
 
-#ifdef CONFIG_KEXEC
-       kexec_boot_params_copy = virt_to_phys(kexec_boot_params_buf);
-       kexec_boot_params = (unsigned long)kexec_boot_params_buf;
-       if (__atags_pointer) {
-               kexec_boot_params_address = __atags_pointer;
-               memcpy((void *)kexec_boot_params, tags, KEXEC_BOOT_PARAMS_SIZE);
-       } else if (mdesc->boot_params) {
-               kexec_boot_params_address = mdesc->boot_params;
-               memcpy((void *)kexec_boot_params, tags, KEXEC_BOOT_PARAMS_SIZE);
-       }
-#endif
-
        /*
         * If we have the old style parameters, convert them to
         * a tag list.
@@ -846,6 +818,7 @@ void __init setup_arch(char **cmdline_p)
        if (tags->hdr.tag == ATAG_CORE) {
                if (meminfo.nr_banks != 0)
                        squash_mem_tags(tags);
+               save_atags(tags);
                parse_tags(tags);
        }
 
index eafbb2b05eb8a2cb7f78a522053f16e4cf70f574..eefae1de334cabbb94ec07e0c85d2ac01795282f 100644 (file)
@@ -150,7 +150,7 @@ int __cpuinit __cpu_up(unsigned int cpu)
        secondary_data.pgdir = 0;
 
        *pmd_offset(pgd, PHYS_OFFSET) = __pmd(0);
-       pgd_free(pgd);
+       pgd_free(&init_mm, pgd);
 
        if (ret) {
                printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
@@ -290,6 +290,11 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
        local_irq_enable();
        local_fiq_enable();
 
+       /*
+        * Setup local timer for this CPU.
+        */
+       local_timer_setup(cpu);
+
        calibrate_delay();
 
        smp_store_cpu_info(cpu);
@@ -299,11 +304,6 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
         */
        cpu_set(cpu, cpu_online_map);
 
-       /*
-        * Setup local timer for this CPU.
-        */
-       local_timer_setup(cpu);
-
        /*
         * OK, it's off to the idle thread for us
         */
@@ -454,6 +454,27 @@ int smp_call_function(void (*func)(void *info), void *info, int retry,
 }
 EXPORT_SYMBOL_GPL(smp_call_function);
 
+int smp_call_function_single(int cpu, void (*func)(void *info), void *info,
+                            int retry, int wait)
+{
+       /* prevent preemption and reschedule on another processor */
+       int current_cpu = get_cpu();
+       int ret = 0;
+
+       if (cpu == current_cpu) {
+               local_irq_disable();
+               func(info);
+               local_irq_enable();
+       } else
+               ret = smp_call_function_on_cpu(func, info, retry, wait,
+                                              cpumask_of_cpu(cpu));
+
+       put_cpu();
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(smp_call_function_single);
+
 void show_ipi_list(struct seq_file *p)
 {
        unsigned int cpu;
@@ -481,8 +502,7 @@ void show_local_irqs(struct seq_file *p)
 static void ipi_timer(void)
 {
        irq_enter();
-       profile_tick(CPU_PROFILING);
-       update_process_times(user_mode(get_irq_regs()));
+       local_timer_interrupt();
        irq_exit();
 }
 
@@ -621,6 +641,11 @@ void smp_send_timer(void)
        send_ipi_message(mask, IPI_TIMER);
 }
 
+void smp_timer_broadcast(cpumask_t mask)
+{
+       send_ipi_message(mask, IPI_TIMER);
+}
+
 void smp_send_stop(void)
 {
        cpumask_t mask = cpu_online_map;
index 5b0422cdde76e7504010d8b4a8971ef3d0ca7455..074dcd5d9a7ef185d4f81d80538f5744fa440e89 100644 (file)
@@ -253,6 +253,36 @@ config AT91_TIMER_HZ
          system clock (of at least several MHz), rounding is less of a
          problem so it can be safer to use a decimal values like 100.
 
+choice
+       prompt "Select a UART for early kernel messages"
+
+config AT91_EARLY_DBGU
+       bool "DBGU"
+
+config AT91_EARLY_USART0
+       bool "USART0"
+
+config AT91_EARLY_USART1
+       bool "USART1"
+
+config AT91_EARLY_USART2
+       bool "USART2"
+       depends on ! ARCH_AT91X40
+
+config AT91_EARLY_USART3
+       bool "USART3"
+       depends on (ARCH_AT91RM9200 || ARCH_AT91SAM9RL || ARCH_AT91SAM9260)
+
+config AT91_EARLY_USART4
+       bool "USART4"
+       depends on ARCH_AT91SAM9260
+
+config AT91_EARLY_USART5
+       bool "USART5"
+       depends on ARCH_AT91SAM9260
+
+endchoice
+
 endmenu
 
 endif
index 5c090c9442f5ee1ba43f6783a417a7ee0c194190..e38d237709928d2e17fc5f2fb693d96e05bdc050 100644 (file)
@@ -49,8 +49,6 @@ static irqreturn_t at91sam926x_timer_interrupt(int irq, void *dev_id)
        volatile long nr_ticks;
 
        if (at91_sys_read(AT91_PIT_SR) & AT91_PIT_PITS) {       /* This is a shared interrupt */
-               write_seqlock(&xtime_lock);
-
                /* Get number to ticks performed before interrupt and clear PIT interrupt */
                nr_ticks = PIT_PICNT(at91_sys_read(AT91_PIT_PIVR));
                do {
@@ -58,7 +56,6 @@ static irqreturn_t at91sam926x_timer_interrupt(int irq, void *dev_id)
                        nr_ticks--;
                } while (nr_ticks);
 
-               write_sequnlock(&xtime_lock);
                return IRQ_HANDLED;
        } else
                return IRQ_NONE;                /* not handled */
index aa29ea58ca09ee9b99286b78a022264d800c71bc..0ce38dfa6ebe3cdc1e3140a9cc030b99707feb24 100644 (file)
@@ -383,6 +383,7 @@ static void at91_lcdc_tft_power_control(int on)
 }
 
 static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
+       .lcdcon_is_backlight            = true,
        .default_bpp                    = 16,
        .default_dmacon                 = ATMEL_LCDC_DMAEN,
        .default_lcdcon2                = AT91SAM9261_DEFAULT_TFT_LCDCON2,
index f09347a86e7116c31d59c43468b1b749b8adba85..38313abef657d0a01684634c3aaf43eba6e82c2b 100644 (file)
@@ -253,6 +253,7 @@ static void at91_lcdc_power_control(int on)
 
 /* Driver datas */
 static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
+       .lcdcon_is_backlight            = true,
        .default_bpp                    = 16,
        .default_dmacon                 = ATMEL_LCDC_DMAEN,
        .default_lcdcon2                = AT91SAM9263_DEFAULT_LCDCON2,
index b5daf7f5e011a797cc6b88f75ae9b9170a451174..7b9ce7a336b0ad897ec21fe0ff956598e8f5a867 100644 (file)
@@ -47,6 +47,9 @@ extern void at91_irq_resume(void);
 #define AT91RM9200_BGA         4       /* AT91RM9200 BGA package has 4 banks */
 
 struct at91_gpio_bank {
+       unsigned chipbase;              /* bank's first GPIO number */
+       void __iomem *regbase;          /* base of register bank */
+       struct at91_gpio_bank *next;    /* bank sharing same IRQ/clock/... */
        unsigned short id;              /* peripheral ID */
        unsigned long offset;           /* offset from system peripheral base */
        struct clk *clock;              /* associated clock */
index 6aeddd68d8af040e048489d4ebff70fa94a79663..f629c2b5f0c544bbec401964e6f7c13550e1e851 100644 (file)
@@ -33,12 +33,10 @@ static int gpio_banks;
 
 static inline void __iomem *pin_to_controller(unsigned pin)
 {
-       void __iomem *sys_base = (void __iomem *) AT91_VA_BASE_SYS;
-
        pin -= PIN_BASE;
        pin /= 32;
        if (likely(pin < gpio_banks))
-               return sys_base + gpio[pin].offset;
+               return gpio[pin].regbase;
 
        return NULL;
 }
@@ -294,11 +292,11 @@ void at91_gpio_suspend(void)
        int i;
 
        for (i = 0; i < gpio_banks; i++) {
-               u32 pio = gpio[i].offset;
+               void __iomem    *pio = gpio[i].regbase;
 
-               backups[i] = at91_sys_read(pio + PIO_IMR);
-               at91_sys_write(pio + PIO_IDR, backups[i]);
-               at91_sys_write(pio + PIO_IER, wakeups[i]);
+               backups[i] = __raw_readl(pio + PIO_IMR);
+               __raw_writel(backups[i], pio + PIO_IDR);
+               __raw_writel(wakeups[i], pio + PIO_IER);
 
                if (!wakeups[i])
                        clk_disable(gpio[i].clock);
@@ -315,13 +313,13 @@ void at91_gpio_resume(void)
        int i;
 
        for (i = 0; i < gpio_banks; i++) {
-               u32 pio = gpio[i].offset;
+               void __iomem    *pio = gpio[i].regbase;
 
                if (!wakeups[i])
                        clk_enable(gpio[i].clock);
 
-               at91_sys_write(pio + PIO_IDR, wakeups[i]);
-               at91_sys_write(pio + PIO_IER, backups[i]);
+               __raw_writel(wakeups[i], pio + PIO_IDR);
+               __raw_writel(backups[i], pio + PIO_IER);
        }
 }
 
@@ -361,7 +359,13 @@ static void gpio_irq_unmask(unsigned pin)
 
 static int gpio_irq_type(unsigned pin, unsigned type)
 {
-       return (type == IRQT_BOTHEDGE) ? 0 : -EINVAL;
+       switch (type) {
+       case IRQ_TYPE_NONE:
+       case IRQ_TYPE_EDGE_BOTH:
+               return 0;
+       default:
+               return -EINVAL;
+       }
 }
 
 static struct irq_chip gpio_irqchip = {
@@ -376,20 +380,30 @@ static void gpio_irq_handler(unsigned irq, struct irq_desc *desc)
 {
        unsigned        pin;
        struct irq_desc *gpio;
+       struct at91_gpio_bank *bank;
        void __iomem    *pio;
        u32             isr;
 
-       pio = get_irq_chip_data(irq);
+       bank = get_irq_chip_data(irq);
+       pio = bank->regbase;
 
        /* temporarily mask (level sensitive) parent IRQ */
        desc->chip->ack(irq);
        for (;;) {
-               /* reading ISR acks the pending (edge triggered) GPIO interrupt */
+               /* Reading ISR acks pending (edge triggered) GPIO interrupts.
+                * When there none are pending, we're finished unless we need
+                * to process multiple banks (like ID_PIOCDE on sam9263).
+                */
                isr = __raw_readl(pio + PIO_ISR) & __raw_readl(pio + PIO_IMR);
-               if (!isr)
-                       break;
+               if (!isr) {
+                       if (!bank->next)
+                               break;
+                       bank = bank->next;
+                       pio = bank->regbase;
+                       continue;
+               }
 
-               pin = (unsigned) get_irq_data(irq);
+               pin = bank->chipbase;
                gpio = &irq_desc[pin];
 
                while (isr) {
@@ -481,24 +495,21 @@ postcore_initcall(at91_gpio_debugfs_init);
  */
 void __init at91_gpio_irq_setup(void)
 {
-       unsigned        pioc, pin;
+       unsigned                pioc, pin;
+       struct at91_gpio_bank   *this, *prev;
 
-       for (pioc = 0, pin = PIN_BASE;
-                       pioc < gpio_banks;
-                       pioc++) {
-               void __iomem    *controller;
-               unsigned        id = gpio[pioc].id;
+       for (pioc = 0, pin = PIN_BASE, this = gpio, prev = NULL;
+                       pioc++ < gpio_banks;
+                       prev = this, this++) {
+               unsigned        id = this->id;
                unsigned        i;
 
-               clk_enable(gpio[pioc].clock);   /* enable PIO controller's clock */
-
-               controller = (void __iomem *) AT91_VA_BASE_SYS + gpio[pioc].offset;
-               __raw_writel(~0, controller + PIO_IDR);
+               /* enable PIO controller's clock */
+               clk_enable(this->clock);
 
-               set_irq_data(id, (void *) pin);
-               set_irq_chip_data(id, controller);
+               __raw_writel(~0, this->regbase + PIO_IDR);
 
-               for (i = 0; i < 32; i++, pin++) {
+               for (i = 0, pin = this->chipbase; i < 32; i++, pin++) {
                        /*
                         * Can use the "simple" and not "edge" handler since it's
                         * shorter, and the AIC handles interrupts sanely.
@@ -508,6 +519,14 @@ void __init at91_gpio_irq_setup(void)
                        set_irq_flags(pin, IRQF_VALID);
                }
 
+               /* The toplevel handler handles one bank of GPIOs, except
+                * AT91SAM9263_ID_PIOCDE handles three... PIOC is first in
+                * the list, so we only set up that handler.
+                */
+               if (prev && prev->next == this)
+                       continue;
+
+               set_irq_chip_data(id, this);
                set_irq_chained_handler(id, gpio_irq_handler);
        }
        pr_info("AT91: %d gpio irqs in %d banks\n", pin - PIN_BASE, gpio_banks);
@@ -518,8 +537,20 @@ void __init at91_gpio_irq_setup(void)
  */
 void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks)
 {
+       unsigned                i;
+       struct at91_gpio_bank   *last;
+
        BUG_ON(nr_banks > MAX_GPIO_BANKS);
 
        gpio = data;
        gpio_banks = nr_banks;
+
+       for (i = 0, last = NULL; i < nr_banks; i++, last = data, data++) {
+               data->chipbase = PIN_BASE + i * 32;
+               data->regbase = data->offset + (void __iomem *)AT91_VA_BASE_SYS;
+
+               /* AT91SAM9263_ID_PIOCDE groups PIOC, PIOD, PIOE */
+               if (last && last->id == data->id)
+                       last->next = data;
+       }
 }
index 4b120cc361359760a542eaea0825365bba5e6b33..a67defd504387a2fc610be020695323947b60333 100644 (file)
@@ -52,7 +52,7 @@ static suspend_state_t target_state;
 /*
  * Called after processes are frozen, but before we shutdown devices.
  */
-static int at91_pm_set_target(suspend_state_t state)
+static int at91_pm_begin(suspend_state_t state)
 {
        target_state = state;
        return 0;
@@ -202,11 +202,20 @@ error:
        return 0;
 }
 
+/*
+ * Called right prior to thawing processes.
+ */
+static void at91_pm_end(void)
+{
+       target_state = PM_SUSPEND_ON;
+}
+
 
 static struct platform_suspend_ops at91_pm_ops ={
-       .valid          = at91_pm_valid_state,
-       .set_target     = at91_pm_set_target,
-       .enter          = at91_pm_enter,
+       .valid  = at91_pm_valid_state,
+       .begin  = at91_pm_begin,
+       .enter  = at91_pm_enter,
+       .end    = at91_pm_end,
 };
 
 static int __init at91_pm_init(void)
index 61b2dfcb89d623dd401cd8226ec2d66bbf939690..e774447c059285e27edb9c2612f7c116218ad486 100644 (file)
@@ -189,6 +189,20 @@ config IXP4XX_INDIRECT_PCI
          need to use the indirect method instead. If you don't know
          what you need, leave this option unselected.
 
+config IXP4XX_QMGR
+       tristate "IXP4xx Queue Manager support"
+       help
+         This driver supports IXP4xx built-in hardware queue manager
+         and is automatically selected by Ethernet and HSS drivers.
+
+config IXP4XX_NPE
+       tristate "IXP4xx Network Processor Engine support"
+       select HOTPLUG
+       select FW_LOADER
+       help
+         This driver supports IXP4xx built-in network coprocessors
+         and is automatically selected by Ethernet and HSS drivers.
+
 endmenu
 
 endif
index 77e00ade558589297aaa425558958a66a61fbffb..c1956882c48b0043a1944a2a5810bd0ed3cb5656 100644 (file)
@@ -23,10 +23,12 @@ obj-$(CONFIG_MACH_AVILA)    += avila-setup.o
 obj-$(CONFIG_MACH_IXDPG425)    += coyote-setup.o
 obj-$(CONFIG_ARCH_ADI_COYOTE)  += coyote-setup.o
 obj-$(CONFIG_MACH_GTWX5715)    += gtwx5715-setup.o
-obj-$(CONFIG_MACH_NSLU2)       += nslu2-setup.o nslu2-power.o
-obj-$(CONFIG_MACH_NAS100D)     += nas100d-setup.o nas100d-power.o
-obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o dsmg600-power.o
+obj-$(CONFIG_MACH_NSLU2)       += nslu2-setup.o
+obj-$(CONFIG_MACH_NAS100D)     += nas100d-setup.o
+obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o
 obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
 obj-$(CONFIG_MACH_WG302V2)     += wg302v2-setup.o
 
 obj-$(CONFIG_PCI)              += $(obj-pci-$(CONFIG_PCI)) common-pci.o
+obj-$(CONFIG_IXP4XX_QMGR)      += ixp4xx_qmgr.o
+obj-$(CONFIG_IXP4XX_NPE)       += ixp4xx_npe.o
diff --git a/arch/arm/mach-ixp4xx/dsmg600-power.c b/arch/arm/mach-ixp4xx/dsmg600-power.c
deleted file mode 100644 (file)
index 3471787..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * arch/arm/mach-ixp4xx/dsmg600-power.c
- *
- * DSM-G600 Power/Reset driver
- * Author: Michael Westerhof <mwester@dls.net>
- *
- * Based on nslu2-power.c
- *  Copyright (C) 2005 Tower Technologies
- *  Author: Alessandro Zummo <a.zummo@towertech.it>
- *
- * which was based on nslu2-io.c
- *  Copyright (C) 2004 Karen Spearel
- *
- * Maintainers: http://www.nslu2-linux.org/
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
-
-#include <linux/module.h>
-#include <linux/reboot.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/jiffies.h>
-#include <linux/timer.h>
-
-#include <asm/mach-types.h>
-
-extern void ctrl_alt_del(void);
-
-/* This is used to make sure the power-button pusher is serious.  The button
- * must be held until the value of this counter reaches zero.
- */
-static volatile int power_button_countdown;
-
-/* Must hold the button down for at least this many counts to be processed */
-#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
-
-static void dsmg600_power_handler(unsigned long data);
-static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
-
-static void dsmg600_power_handler(unsigned long data)
-{
-       /* This routine is called twice per second to check the
-        * state of the power button.
-        */
-
-       if (*IXP4XX_GPIO_GPINR & DSMG600_PB_BM) {
-
-               /* IO Pin is 1 (button pushed) */
-               if (power_button_countdown == 0) {
-                       /* Signal init to do the ctrlaltdel action, this will bypass
-                        * init if it hasn't started and do a kernel_restart.
-                        */
-                       ctrl_alt_del();
-
-                       /* Change the state of the power LED to "blink" */
-                       gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
-               }
-               power_button_countdown--;
-
-       } else {
-               power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
-       }
-
-       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
-}
-
-static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
-{
-       /* This is the paper-clip reset, it shuts the machine down directly. */
-       machine_power_off();
-
-       return IRQ_HANDLED;
-}
-
-static int __init dsmg600_power_init(void)
-{
-       if (!(machine_is_dsmg600()))
-               return 0;
-
-       if (request_irq(DSMG600_RB_IRQ, &dsmg600_reset_handler,
-               IRQF_DISABLED | IRQF_TRIGGER_LOW, "DSM-G600 reset button",
-               NULL) < 0) {
-
-               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
-                       DSMG600_RB_IRQ);
-
-               return -EIO;
-       }
-
-       /* The power button on the D-Link DSM-G600 is on GPIO 15, but
-        * it cannot handle interrupts on that GPIO line.  So we'll
-        * have to poll it with a kernel timer.
-        */
-
-       /* Make sure that the power button GPIO is set up as an input */
-       gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
-
-       /* Set the initial value for the power button IRQ handler */
-       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
-
-       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
-
-       return 0;
-}
-
-static void __exit dsmg600_power_exit(void)
-{
-       if (!(machine_is_dsmg600()))
-               return;
-
-       del_timer_sync(&dsmg600_power_timer);
-
-       free_irq(DSMG600_RB_IRQ, NULL);
-}
-
-module_init(dsmg600_power_init);
-module_exit(dsmg600_power_exit);
-
-MODULE_AUTHOR("Michael Westerhof <mwester@dls.net>");
-MODULE_DESCRIPTION("DSM-G600 Power/Reset driver");
-MODULE_LICENSE("GPL");
index c473d408aa7c10b64ab3cf4ee8156c45a2833946..688659668bdf12156627f7780057ae76c6e9b5fb 100644 (file)
@@ -1,25 +1,37 @@
 /*
  * DSM-G600 board-setup
  *
+ * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
  * Copyright (C) 2006 Tower Technologies
- * Author: Alessandro Zummo <a.zummo@towertech.it>
  *
- * based ixdp425-setup.c:
+ * based on ixdp425-setup.c:
  *      Copyright (C) 2003-2004 MontaVista Software, Inc.
+ * based on nslu2-power.c:
+ *     Copyright (C) 2005 Tower Technologies
+ * based on nslu2-io.c:
+ *     Copyright (C) 2004 Karen Spearel
  *
  * Author: Alessandro Zummo <a.zummo@towertech.it>
+ * Author: Michael Westerhof <mwester@dls.net>
+ * Author: Rod Whitby <rod@whitby.id.au>
  * Maintainers: http://www.nslu2-linux.org/
  */
 
-#include <linux/kernel.h>
+#include <linux/irq.h>
+#include <linux/jiffies.h>
+#include <linux/timer.h>
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
+#include <linux/leds.h>
+#include <linux/reboot.h>
+#include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/flash.h>
 #include <asm/mach/time.h>
+#include <asm/gpio.h>
 
 static struct flash_platform_data dsmg600_flash_data = {
        .map_name               = "cfi_probe",
@@ -51,29 +63,34 @@ static struct platform_device dsmg600_i2c_gpio = {
        },
 };
 
-#ifdef CONFIG_LEDS_CLASS
-static struct resource dsmg600_led_resources[] = {
+static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
+       {
+               I2C_BOARD_INFO("rtc-pcf8563", 0x51),
+       },
+};
+
+static struct gpio_led dsmg600_led_pins[] = {
        {
-               .name           = "power",
-               .start          = DSMG600_LED_PWR_GPIO,
-               .end            = DSMG600_LED_PWR_GPIO,
-               .flags          = IXP4XX_GPIO_HIGH,
+               .name           = "power",
+               .gpio           = DSMG600_LED_PWR_GPIO,
        },
        {
-               .name           = "wlan",
-               .start          = DSMG600_LED_WLAN_GPIO,
-               .end            = DSMG600_LED_WLAN_GPIO,
-               .flags          = IXP4XX_GPIO_LOW,
+               .name           = "wlan",
+               .gpio           = DSMG600_LED_WLAN_GPIO,
+               .active_low     = true,
        },
 };
 
+static struct gpio_led_platform_data dsmg600_led_data = {
+       .num_leds               = ARRAY_SIZE(dsmg600_led_pins),
+       .leds                   = dsmg600_led_pins,
+};
+
 static struct platform_device dsmg600_leds = {
-        .name                   = "IXP4XX-GPIO-LED",
-        .id                     = -1,
-        .num_resources          = ARRAY_SIZE(dsmg600_led_resources),
-        .resource               = dsmg600_led_resources,
+       .name                   = "leds-gpio",
+       .id                     = -1,
+       .dev.platform_data      = &dsmg600_led_data,
 };
-#endif
 
 static struct resource dsmg600_uart_resources[] = {
        {
@@ -121,6 +138,7 @@ static struct platform_device dsmg600_uart = {
 static struct platform_device *dsmg600_devices[] __initdata = {
        &dsmg600_i2c_gpio,
        &dsmg600_flash,
+       &dsmg600_leds,
 };
 
 static void dsmg600_power_off(void)
@@ -132,6 +150,57 @@ static void dsmg600_power_off(void)
        gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
 }
 
+/* This is used to make sure the power-button pusher is serious.  The button
+ * must be held until the value of this counter reaches zero.
+ */
+static int power_button_countdown;
+
+/* Must hold the button down for at least this many counts to be processed */
+#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
+
+static void dsmg600_power_handler(unsigned long data);
+static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
+
+static void dsmg600_power_handler(unsigned long data)
+{
+       /* This routine is called twice per second to check the
+        * state of the power button.
+        */
+
+       if (gpio_get_value(DSMG600_PB_GPIO)) {
+
+               /* IO Pin is 1 (button pushed) */
+               if (power_button_countdown > 0)
+                       power_button_countdown--;
+
+       } else {
+
+               /* Done on button release, to allow for auto-power-on mods. */
+               if (power_button_countdown == 0) {
+                       /* Signal init to do the ctrlaltdel action,
+                        * this will bypass init if it hasn't started
+                        * and do a kernel_restart.
+                        */
+                       ctrl_alt_del();
+
+                       /* Change the state of the power LED to "blink" */
+                       gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
+               } else {
+                       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
+               }
+       }
+
+       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
+}
+
+static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
+{
+       /* This is the paper-clip reset, it shuts the machine down directly. */
+       machine_power_off();
+
+       return IRQ_HANDLED;
+}
+
 static void __init dsmg600_timer_init(void)
 {
     /* The xtal on this machine is non-standard. */
@@ -156,7 +225,8 @@ static void __init dsmg600_init(void)
        dsmg600_flash_resource.end =
                IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
 
-       pm_power_off = dsmg600_power_off;
+       i2c_register_board_info(0, dsmg600_i2c_board_info,
+                               ARRAY_SIZE(dsmg600_i2c_board_info));
 
        /* The UART is required on the DSM-G600 (Redboot cannot use the
         * NIC) -- do it here so that it does *not* get removed if
@@ -166,10 +236,28 @@ static void __init dsmg600_init(void)
 
        platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
 
-#ifdef CONFIG_LEDS_CLASS
-        /* We don't care whether or not this works. */
-        (void)platform_device_register(&dsmg600_leds);
-#endif
+       pm_power_off = dsmg600_power_off;
+
+       if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
+               IRQF_DISABLED | IRQF_TRIGGER_LOW,
+               "DSM-G600 reset button", NULL) < 0) {
+
+               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
+                       gpio_to_irq(DSMG600_RB_GPIO));
+       }
+
+       /* The power button on the D-Link DSM-G600 is on GPIO 15, but
+        * it cannot handle interrupts on that GPIO line.  So we'll
+        * have to poll it with a kernel timer.
+        */
+
+       /* Make sure that the power button GPIO is set up as an input */
+       gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
+
+       /* Set the initial value for the power button IRQ handler */
+       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
+
+       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
 }
 
 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
index e89070da28bfb73afa135f6819a64ca0ec0d4549..44584afb34a3778ff70615f7954d9cf24cfd1a83 100644 (file)
@@ -177,6 +177,31 @@ static struct platform_device ixdp425_uart = {
        .resource               = ixdp425_uart_resources
 };
 
+/* Built-in 10/100 Ethernet MAC interfaces */
+static struct eth_plat_info ixdp425_plat_eth[] = {
+       {
+               .phy            = 0,
+               .rxq            = 3,
+               .txreadyq       = 20,
+       }, {
+               .phy            = 1,
+               .rxq            = 4,
+               .txreadyq       = 21,
+       }
+};
+
+static struct platform_device ixdp425_eth[] = {
+       {
+               .name                   = "ixp4xx_eth",
+               .id                     = IXP4XX_ETH_NPEB,
+               .dev.platform_data      = ixdp425_plat_eth,
+       }, {
+               .name                   = "ixp4xx_eth",
+               .id                     = IXP4XX_ETH_NPEC,
+               .dev.platform_data      = ixdp425_plat_eth + 1,
+       }
+};
+
 static struct platform_device *ixdp425_devices[] __initdata = {
        &ixdp425_i2c_gpio,
        &ixdp425_flash,
@@ -184,7 +209,9 @@ static struct platform_device *ixdp425_devices[] __initdata = {
     defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
        &ixdp425_flash_nand,
 #endif
-       &ixdp425_uart
+       &ixdp425_uart,
+       &ixdp425_eth[0],
+       &ixdp425_eth[1],
 };
 
 static void __init ixdp425_init(void)
diff --git a/arch/arm/mach-ixp4xx/ixp4xx_npe.c b/arch/arm/mach-ixp4xx/ixp4xx_npe.c
new file mode 100644 (file)
index 0000000..83c137e
--- /dev/null
@@ -0,0 +1,741 @@
+/*
+ * Intel IXP4xx Network Processor Engine driver for Linux
+ *
+ * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ * The code is based on publicly available information:
+ * - Intel IXP4xx Developer's Manual and other e-papers
+ * - Intel IXP400 Access Library Software (BSD license)
+ * - previous works by Christian Hohnstaedt <chohnstaedt@innominate.com>
+ *   Thanks, Christian.
+ */
+
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/firmware.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <asm/arch/npe.h>
+
+#define DEBUG_MSG                      0
+#define DEBUG_FW                       0
+
+#define NPE_COUNT                      3
+#define MAX_RETRIES                    1000    /* microseconds */
+#define NPE_42X_DATA_SIZE              0x800   /* in dwords */
+#define NPE_46X_DATA_SIZE              0x1000
+#define NPE_A_42X_INSTR_SIZE           0x1000
+#define NPE_B_AND_C_42X_INSTR_SIZE     0x800
+#define NPE_46X_INSTR_SIZE             0x1000
+#define REGS_SIZE                      0x1000
+
+#define NPE_PHYS_REG                   32
+
+#define FW_MAGIC                       0xFEEDF00D
+#define FW_BLOCK_TYPE_INSTR            0x0
+#define FW_BLOCK_TYPE_DATA             0x1
+#define FW_BLOCK_TYPE_EOF              0xF
+
+/* NPE exec status (read) and command (write) */
+#define CMD_NPE_STEP                   0x01
+#define CMD_NPE_START                  0x02
+#define CMD_NPE_STOP                   0x03
+#define CMD_NPE_CLR_PIPE               0x04
+#define CMD_CLR_PROFILE_CNT            0x0C
+#define CMD_RD_INS_MEM                 0x10 /* instruction memory */
+#define CMD_WR_INS_MEM                 0x11
+#define CMD_RD_DATA_MEM                        0x12 /* data memory */
+#define CMD_WR_DATA_MEM                        0x13
+#define CMD_RD_ECS_REG                 0x14 /* exec access register */
+#define CMD_WR_ECS_REG                 0x15
+
+#define STAT_RUN                       0x80000000
+#define STAT_STOP                      0x40000000
+#define STAT_CLEAR                     0x20000000
+#define STAT_ECS_K                     0x00800000 /* pipeline clean */
+
+#define NPE_STEVT                      0x1B
+#define NPE_STARTPC                    0x1C
+#define NPE_REGMAP                     0x1E
+#define NPE_CINDEX                     0x1F
+
+#define INSTR_WR_REG_SHORT             0x0000C000
+#define INSTR_WR_REG_BYTE              0x00004000
+#define INSTR_RD_FIFO                  0x0F888220
+#define INSTR_RESET_MBOX               0x0FAC8210
+
+#define ECS_BG_CTXT_REG_0              0x00 /* Background Executing Context */
+#define ECS_BG_CTXT_REG_1              0x01 /*         Stack level */
+#define ECS_BG_CTXT_REG_2              0x02
+#define ECS_PRI_1_CTXT_REG_0           0x04 /* Priority 1 Executing Context */
+#define ECS_PRI_1_CTXT_REG_1           0x05 /*         Stack level */
+#define ECS_PRI_1_CTXT_REG_2           0x06
+#define ECS_PRI_2_CTXT_REG_0           0x08 /* Priority 2 Executing Context */
+#define ECS_PRI_2_CTXT_REG_1           0x09 /*         Stack level */
+#define ECS_PRI_2_CTXT_REG_2           0x0A
+#define ECS_DBG_CTXT_REG_0             0x0C /* Debug Executing Context */
+#define ECS_DBG_CTXT_REG_1             0x0D /*         Stack level */
+#define ECS_DBG_CTXT_REG_2             0x0E
+#define ECS_INSTRUCT_REG               0x11 /* NPE Instruction Register */
+
+#define ECS_REG_0_ACTIVE               0x80000000 /* all levels */
+#define ECS_REG_0_NEXTPC_MASK          0x1FFF0000 /* BG/PRI1/PRI2 levels */
+#define ECS_REG_0_LDUR_BITS            8
+#define ECS_REG_0_LDUR_MASK            0x00000700 /* all levels */
+#define ECS_REG_1_CCTXT_BITS           16
+#define ECS_REG_1_CCTXT_MASK           0x000F0000 /* all levels */
+#define ECS_REG_1_SELCTXT_BITS         0
+#define ECS_REG_1_SELCTXT_MASK         0x0000000F /* all levels */
+#define ECS_DBG_REG_2_IF               0x00100000 /* debug level */
+#define ECS_DBG_REG_2_IE               0x00080000 /* debug level */
+
+/* NPE watchpoint_fifo register bit */
+#define WFIFO_VALID                    0x80000000
+
+/* NPE messaging_status register bit definitions */
+#define MSGSTAT_OFNE   0x00010000 /* OutFifoNotEmpty */
+#define MSGSTAT_IFNF   0x00020000 /* InFifoNotFull */
+#define MSGSTAT_OFNF   0x00040000 /* OutFifoNotFull */
+#define MSGSTAT_IFNE   0x00080000 /* InFifoNotEmpty */
+#define MSGSTAT_MBINT  0x00100000 /* Mailbox interrupt */
+#define MSGSTAT_IFINT  0x00200000 /* InFifo interrupt */
+#define MSGSTAT_OFINT  0x00400000 /* OutFifo interrupt */
+#define MSGSTAT_WFINT  0x00800000 /* WatchFifo interrupt */
+
+/* NPE messaging_control register bit definitions */
+#define MSGCTL_OUT_FIFO                        0x00010000 /* enable output FIFO */
+#define MSGCTL_IN_FIFO                 0x00020000 /* enable input FIFO */
+#define MSGCTL_OUT_FIFO_WRITE          0x01000000 /* enable FIFO + WRITE */
+#define MSGCTL_IN_FIFO_WRITE           0x02000000
+
+/* NPE mailbox_status value for reset */
+#define RESET_MBOX_STAT                        0x0000F0F0
+
+const char *npe_names[] = { "NPE-A", "NPE-B", "NPE-C" };
+
+#define print_npe(pri, npe, fmt, ...)                                  \
+       printk(pri "%s: " fmt, npe_name(npe), ## __VA_ARGS__)
+
+#if DEBUG_MSG
+#define debug_msg(npe, fmt, ...)                                       \
+       print_npe(KERN_DEBUG, npe, fmt, ## __VA_ARGS__)
+#else
+#define debug_msg(npe, fmt, ...)
+#endif
+
+static struct {
+       u32 reg, val;
+} ecs_reset[] = {
+       { ECS_BG_CTXT_REG_0,    0xA0000000 },
+       { ECS_BG_CTXT_REG_1,    0x01000000 },
+       { ECS_BG_CTXT_REG_2,    0x00008000 },
+       { ECS_PRI_1_CTXT_REG_0, 0x20000080 },
+       { ECS_PRI_1_CTXT_REG_1, 0x01000000 },
+       { ECS_PRI_1_CTXT_REG_2, 0x00008000 },
+       { ECS_PRI_2_CTXT_REG_0, 0x20000080 },
+       { ECS_PRI_2_CTXT_REG_1, 0x01000000 },
+       { ECS_PRI_2_CTXT_REG_2, 0x00008000 },
+       { ECS_DBG_CTXT_REG_0,   0x20000000 },
+       { ECS_DBG_CTXT_REG_1,   0x00000000 },
+       { ECS_DBG_CTXT_REG_2,   0x001E0000 },
+       { ECS_INSTRUCT_REG,     0x1003C00F },
+};
+
+static struct npe npe_tab[NPE_COUNT] = {
+       {
+               .id     = 0,
+               .regs   = (struct npe_regs __iomem *)IXP4XX_NPEA_BASE_VIRT,
+               .regs_phys = IXP4XX_NPEA_BASE_PHYS,
+       }, {
+               .id     = 1,
+               .regs   = (struct npe_regs __iomem *)IXP4XX_NPEB_BASE_VIRT,
+               .regs_phys = IXP4XX_NPEB_BASE_PHYS,
+       }, {
+               .id     = 2,
+               .regs   = (struct npe_regs __iomem *)IXP4XX_NPEC_BASE_VIRT,
+               .regs_phys = IXP4XX_NPEC_BASE_PHYS,
+       }
+};
+
+int npe_running(struct npe *npe)
+{
+       return (__raw_readl(&npe->regs->exec_status_cmd) & STAT_RUN) != 0;
+}
+
+static void npe_cmd_write(struct npe *npe, u32 addr, int cmd, u32 data)
+{
+       __raw_writel(data, &npe->regs->exec_data);
+       __raw_writel(addr, &npe->regs->exec_addr);
+       __raw_writel(cmd, &npe->regs->exec_status_cmd);
+}
+
+static u32 npe_cmd_read(struct npe *npe, u32 addr, int cmd)
+{
+       __raw_writel(addr, &npe->regs->exec_addr);
+       __raw_writel(cmd, &npe->regs->exec_status_cmd);
+       /* Iintroduce extra read cycles after issuing read command to NPE
+          so that we read the register after the NPE has updated it.
+          This is to overcome race condition between XScale and NPE */
+       __raw_readl(&npe->regs->exec_data);
+       __raw_readl(&npe->regs->exec_data);
+       return __raw_readl(&npe->regs->exec_data);
+}
+
+static void npe_clear_active(struct npe *npe, u32 reg)
+{
+       u32 val = npe_cmd_read(npe, reg, CMD_RD_ECS_REG);
+       npe_cmd_write(npe, reg, CMD_WR_ECS_REG, val & ~ECS_REG_0_ACTIVE);
+}
+
+static void npe_start(struct npe *npe)
+{
+       /* ensure only Background Context Stack Level is active */
+       npe_clear_active(npe, ECS_PRI_1_CTXT_REG_0);
+       npe_clear_active(npe, ECS_PRI_2_CTXT_REG_0);
+       npe_clear_active(npe, ECS_DBG_CTXT_REG_0);
+
+       __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
+       __raw_writel(CMD_NPE_START, &npe->regs->exec_status_cmd);
+}
+
+static void npe_stop(struct npe *npe)
+{
+       __raw_writel(CMD_NPE_STOP, &npe->regs->exec_status_cmd);
+       __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd); /*FIXME?*/
+}
+
+static int __must_check npe_debug_instr(struct npe *npe, u32 instr, u32 ctx,
+                                       u32 ldur)
+{
+       u32 wc;
+       int i;
+
+       /* set the Active bit, and the LDUR, in the debug level */
+       npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG,
+                     ECS_REG_0_ACTIVE | (ldur << ECS_REG_0_LDUR_BITS));
+
+       /* set CCTXT at ECS DEBUG L3 to specify in which context to execute
+          the instruction, and set SELCTXT at ECS DEBUG Level to specify
+          which context store to access.
+          Debug ECS Level Reg 1 has form 0x000n000n, where n = context number
+       */
+       npe_cmd_write(npe, ECS_DBG_CTXT_REG_1, CMD_WR_ECS_REG,
+                     (ctx << ECS_REG_1_CCTXT_BITS) |
+                     (ctx << ECS_REG_1_SELCTXT_BITS));
+
+       /* clear the pipeline */
+       __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
+
+       /* load NPE instruction into the instruction register */
+       npe_cmd_write(npe, ECS_INSTRUCT_REG, CMD_WR_ECS_REG, instr);
+
+       /* we need this value later to wait for completion of NPE execution
+          step */
+       wc = __raw_readl(&npe->regs->watch_count);
+
+       /* issue a Step One command via the Execution Control register */
+       __raw_writel(CMD_NPE_STEP, &npe->regs->exec_status_cmd);
+
+       /* Watch Count register increments when NPE completes an instruction */
+       for (i = 0; i < MAX_RETRIES; i++) {
+               if (wc != __raw_readl(&npe->regs->watch_count))
+                       return 0;
+               udelay(1);
+       }
+
+       print_npe(KERN_ERR, npe, "reset: npe_debug_instr(): timeout\n");
+       return -ETIMEDOUT;
+}
+
+static int __must_check npe_logical_reg_write8(struct npe *npe, u32 addr,
+                                              u8 val, u32 ctx)
+{
+       /* here we build the NPE assembler instruction: mov8 d0, #0 */
+       u32 instr = INSTR_WR_REG_BYTE | /* OpCode */
+               addr << 9 |             /* base Operand */
+               (val & 0x1F) << 4 |     /* lower 5 bits to immediate data */
+               (val & ~0x1F) << (18 - 5);/* higher 3 bits to CoProc instr. */
+       return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
+}
+
+static int __must_check npe_logical_reg_write16(struct npe *npe, u32 addr,
+                                               u16 val, u32 ctx)
+{
+       /* here we build the NPE assembler instruction: mov16 d0, #0 */
+       u32 instr = INSTR_WR_REG_SHORT | /* OpCode */
+               addr << 9 |             /* base Operand */
+               (val & 0x1F) << 4 |     /* lower 5 bits to immediate data */
+               (val & ~0x1F) << (18 - 5);/* higher 11 bits to CoProc instr. */
+       return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
+}
+
+static int __must_check npe_logical_reg_write32(struct npe *npe, u32 addr,
+                                               u32 val, u32 ctx)
+{
+       /* write in 16 bit steps first the high and then the low value */
+       if (npe_logical_reg_write16(npe, addr, val >> 16, ctx))
+               return -ETIMEDOUT;
+       return npe_logical_reg_write16(npe, addr + 2, val & 0xFFFF, ctx);
+}
+
+static int npe_reset(struct npe *npe)
+{
+       u32 val, ctl, exec_count, ctx_reg2;
+       int i;
+
+       ctl = (__raw_readl(&npe->regs->messaging_control) | 0x3F000000) &
+               0x3F3FFFFF;
+
+       /* disable parity interrupt */
+       __raw_writel(ctl & 0x3F00FFFF, &npe->regs->messaging_control);
+
+       /* pre exec - debug instruction */
+       /* turn off the halt bit by clearing Execution Count register. */
+       exec_count = __raw_readl(&npe->regs->exec_count);
+       __raw_writel(0, &npe->regs->exec_count);
+       /* ensure that IF and IE are on (temporarily), so that we don't end up
+          stepping forever */
+       ctx_reg2 = npe_cmd_read(npe, ECS_DBG_CTXT_REG_2, CMD_RD_ECS_REG);
+       npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2 |
+                     ECS_DBG_REG_2_IF | ECS_DBG_REG_2_IE);
+
+       /* clear the FIFOs */
+       while (__raw_readl(&npe->regs->watchpoint_fifo) & WFIFO_VALID)
+               ;
+       while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE)
+               /* read from the outFIFO until empty */
+               print_npe(KERN_DEBUG, npe, "npe_reset: read FIFO = 0x%X\n",
+                         __raw_readl(&npe->regs->in_out_fifo));
+
+       while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)
+               /* step execution of the NPE intruction to read inFIFO using
+                  the Debug Executing Context stack */
+               if (npe_debug_instr(npe, INSTR_RD_FIFO, 0, 0))
+                       return -ETIMEDOUT;
+
+       /* reset the mailbox reg from the XScale side */
+       __raw_writel(RESET_MBOX_STAT, &npe->regs->mailbox_status);
+       /* from NPE side */
+       if (npe_debug_instr(npe, INSTR_RESET_MBOX, 0, 0))
+               return -ETIMEDOUT;
+
+       /* Reset the physical registers in the NPE register file */
+       for (val = 0; val < NPE_PHYS_REG; val++) {
+               if (npe_logical_reg_write16(npe, NPE_REGMAP, val >> 1, 0))
+                       return -ETIMEDOUT;
+               /* address is either 0 or 4 */
+               if (npe_logical_reg_write32(npe, (val & 1) * 4, 0, 0))
+                       return -ETIMEDOUT;
+       }
+
+       /* Reset the context store = each context's Context Store registers */
+
+       /* Context 0 has no STARTPC. Instead, this value is used to set NextPC
+          for Background ECS, to set where NPE starts executing code */
+       val = npe_cmd_read(npe, ECS_BG_CTXT_REG_0, CMD_RD_ECS_REG);
+       val &= ~ECS_REG_0_NEXTPC_MASK;
+       val |= (0 /* NextPC */ << 16) & ECS_REG_0_NEXTPC_MASK;
+       npe_cmd_write(npe, ECS_BG_CTXT_REG_0, CMD_WR_ECS_REG, val);
+
+       for (i = 0; i < 16; i++) {
+               if (i) {        /* Context 0 has no STEVT nor STARTPC */
+                       /* STEVT = off, 0x80 */
+                       if (npe_logical_reg_write8(npe, NPE_STEVT, 0x80, i))
+                               return -ETIMEDOUT;
+                       if (npe_logical_reg_write16(npe, NPE_STARTPC, 0, i))
+                               return -ETIMEDOUT;
+               }
+               /* REGMAP = d0->p0, d8->p2, d16->p4 */
+               if (npe_logical_reg_write16(npe, NPE_REGMAP, 0x820, i))
+                       return -ETIMEDOUT;
+               if (npe_logical_reg_write8(npe, NPE_CINDEX, 0, i))
+                       return -ETIMEDOUT;
+       }
+
+       /* post exec */
+       /* clear active bit in debug level */
+       npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG, 0);
+       /* clear the pipeline */
+       __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
+       /* restore previous values */
+       __raw_writel(exec_count, &npe->regs->exec_count);
+       npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2);
+
+       /* write reset values to Execution Context Stack registers */
+       for (val = 0; val < ARRAY_SIZE(ecs_reset); val++)
+               npe_cmd_write(npe, ecs_reset[val].reg, CMD_WR_ECS_REG,
+                             ecs_reset[val].val);
+
+       /* clear the profile counter */
+       __raw_writel(CMD_CLR_PROFILE_CNT, &npe->regs->exec_status_cmd);
+
+       __raw_writel(0, &npe->regs->exec_count);
+       __raw_writel(0, &npe->regs->action_points[0]);
+       __raw_writel(0, &npe->regs->action_points[1]);
+       __raw_writel(0, &npe->regs->action_points[2]);
+       __raw_writel(0, &npe->regs->action_points[3]);
+       __raw_writel(0, &npe->regs->watch_count);
+
+       val = ixp4xx_read_feature_bits();
+       /* reset the NPE */
+       ixp4xx_write_feature_bits(val &
+                                 ~(IXP4XX_FEATURE_RESET_NPEA << npe->id));
+       for (i = 0; i < MAX_RETRIES; i++) {
+               if (!(ixp4xx_read_feature_bits() &
+                     (IXP4XX_FEATURE_RESET_NPEA << npe->id)))
+                       break;  /* reset completed */
+               udelay(1);
+       }
+       if (i == MAX_RETRIES)
+               return -ETIMEDOUT;
+
+       /* deassert reset */
+       ixp4xx_write_feature_bits(val |
+                                 (IXP4XX_FEATURE_RESET_NPEA << npe->id));
+       for (i = 0; i < MAX_RETRIES; i++) {
+               if (ixp4xx_read_feature_bits() &
+                   (IXP4XX_FEATURE_RESET_NPEA << npe->id))
+                       break;  /* NPE is back alive */
+               udelay(1);
+       }
+       if (i == MAX_RETRIES)
+               return -ETIMEDOUT;
+
+       npe_stop(npe);
+
+       /* restore NPE configuration bus Control Register - parity settings */
+       __raw_writel(ctl, &npe->regs->messaging_control);
+       return 0;
+}
+
+
+int npe_send_message(struct npe *npe, const void *msg, const char *what)
+{
+       const u32 *send = msg;
+       int cycles = 0;
+
+       debug_msg(npe, "Trying to send message %s [%08X:%08X]\n",
+                 what, send[0], send[1]);
+
+       if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE) {
+               debug_msg(npe, "NPE input FIFO not empty\n");
+               return -EIO;
+       }
+
+       __raw_writel(send[0], &npe->regs->in_out_fifo);
+
+       if (!(__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNF)) {
+               debug_msg(npe, "NPE input FIFO full\n");
+               return -EIO;
+       }
+
+       __raw_writel(send[1], &npe->regs->in_out_fifo);
+
+       while ((cycles < MAX_RETRIES) &&
+              (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)) {
+               udelay(1);
+               cycles++;
+       }
+
+       if (cycles == MAX_RETRIES) {
+               debug_msg(npe, "Timeout sending message\n");
+               return -ETIMEDOUT;
+       }
+
+       debug_msg(npe, "Sending a message took %i cycles\n", cycles);
+       return 0;
+}
+
+int npe_recv_message(struct npe *npe, void *msg, const char *what)
+{
+       u32 *recv = msg;
+       int cycles = 0, cnt = 0;
+
+       debug_msg(npe, "Trying to receive message %s\n", what);
+
+       while (cycles < MAX_RETRIES) {
+               if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE) {
+                       recv[cnt++] = __raw_readl(&npe->regs->in_out_fifo);
+                       if (cnt == 2)
+                               break;
+               } else {
+                       udelay(1);
+                       cycles++;
+               }
+       }
+
+       switch(cnt) {
+       case 1:
+               debug_msg(npe, "Received [%08X]\n", recv[0]);
+               break;
+       case 2:
+               debug_msg(npe, "Received [%08X:%08X]\n", recv[0], recv[1]);
+               break;
+       }
+
+       if (cycles == MAX_RETRIES) {
+               debug_msg(npe, "Timeout waiting for message\n");
+               return -ETIMEDOUT;
+       }
+
+       debug_msg(npe, "Receiving a message took %i cycles\n", cycles);
+       return 0;
+}
+
+int npe_send_recv_message(struct npe *npe, void *msg, const char *what)
+{
+       int result;
+       u32 *send = msg, recv[2];
+
+       if ((result = npe_send_message(npe, msg, what)) != 0)
+               return result;
+       if ((result = npe_recv_message(npe, recv, what)) != 0)
+               return result;
+
+       if ((recv[0] != send[0]) || (recv[1] != send[1])) {
+               debug_msg(npe, "Message %s: unexpected message received\n",
+                         what);
+               return -EIO;
+       }
+       return 0;
+}
+
+
+int npe_load_firmware(struct npe *npe, const char *name, struct device *dev)
+{
+       const struct firmware *fw_entry;
+
+       struct dl_block {
+               u32 type;
+               u32 offset;
+       } *blk;
+
+       struct dl_image {
+               u32 magic;
+               u32 id;
+               u32 size;
+               union {
+                       u32 data[0];
+                       struct dl_block blocks[0];
+               };
+       } *image;
+
+       struct dl_codeblock {
+               u32 npe_addr;
+               u32 size;
+               u32 data[0];
+       } *cb;
+
+       int i, j, err, data_size, instr_size, blocks, table_end;
+       u32 cmd;
+
+       if ((err = request_firmware(&fw_entry, name, dev)) != 0)
+               return err;
+
+       err = -EINVAL;
+       if (fw_entry->size < sizeof(struct dl_image)) {
+               print_npe(KERN_ERR, npe, "incomplete firmware file\n");
+               goto err;
+       }
+       image = (struct dl_image*)fw_entry->data;
+
+#if DEBUG_FW
+       print_npe(KERN_DEBUG, npe, "firmware: %08X %08X %08X (0x%X bytes)\n",
+                 image->magic, image->id, image->size, image->size * 4);
+#endif
+
+       if (image->magic == swab32(FW_MAGIC)) { /* swapped file */
+               image->id = swab32(image->id);
+               image->size = swab32(image->size);
+       } else if (image->magic != FW_MAGIC) {
+               print_npe(KERN_ERR, npe, "bad firmware file magic: 0x%X\n",
+                         image->magic);
+               goto err;
+       }
+       if ((image->size * 4 + sizeof(struct dl_image)) != fw_entry->size) {
+               print_npe(KERN_ERR, npe,
+                         "inconsistent size of firmware file\n");
+               goto err;
+       }
+       if (((image->id >> 24) & 0xF /* NPE ID */) != npe->id) {
+               print_npe(KERN_ERR, npe, "firmware file NPE ID mismatch\n");
+               goto err;
+       }
+       if (image->magic == swab32(FW_MAGIC))
+               for (i = 0; i < image->size; i++)
+                       image->data[i] = swab32(image->data[i]);
+
+       if (!cpu_is_ixp46x() && ((image->id >> 28) & 0xF /* device ID */)) {
+               print_npe(KERN_INFO, npe, "IXP46x firmware ignored on "
+                         "IXP42x\n");
+               goto err;
+       }
+
+       if (npe_running(npe)) {
+               print_npe(KERN_INFO, npe, "unable to load firmware, NPE is "
+                         "already running\n");
+               err = -EBUSY;
+               goto err;
+       }
+#if 0
+       npe_stop(npe);
+       npe_reset(npe);
+#endif
+
+       print_npe(KERN_INFO, npe, "firmware functionality 0x%X, "
+                 "revision 0x%X:%X\n", (image->id >> 16) & 0xFF,
+                 (image->id >> 8) & 0xFF, image->id & 0xFF);
+
+       if (!cpu_is_ixp46x()) {
+               if (!npe->id)
+                       instr_size = NPE_A_42X_INSTR_SIZE;
+               else
+                       instr_size = NPE_B_AND_C_42X_INSTR_SIZE;
+               data_size = NPE_42X_DATA_SIZE;
+       } else {
+               instr_size = NPE_46X_INSTR_SIZE;
+               data_size = NPE_46X_DATA_SIZE;
+       }
+
+       for (blocks = 0; blocks * sizeof(struct dl_block) / 4 < image->size;
+            blocks++)
+               if (image->blocks[blocks].type == FW_BLOCK_TYPE_EOF)
+                       break;
+       if (blocks * sizeof(struct dl_block) / 4 >= image->size) {
+               print_npe(KERN_INFO, npe, "firmware EOF block marker not "
+                         "found\n");
+               goto err;
+       }
+
+#if DEBUG_FW
+       print_npe(KERN_DEBUG, npe, "%i firmware blocks found\n", blocks);
+#endif
+
+       table_end = blocks * sizeof(struct dl_block) / 4 + 1 /* EOF marker */;
+       for (i = 0, blk = image->blocks; i < blocks; i++, blk++) {
+               if (blk->offset > image->size - sizeof(struct dl_codeblock) / 4
+                   || blk->offset < table_end) {
+                       print_npe(KERN_INFO, npe, "invalid offset 0x%X of "
+                                 "firmware block #%i\n", blk->offset, i);
+                       goto err;
+               }
+
+               cb = (struct dl_codeblock*)&image->data[blk->offset];
+               if (blk->type == FW_BLOCK_TYPE_INSTR) {
+                       if (cb->npe_addr + cb->size > instr_size)
+                               goto too_big;
+                       cmd = CMD_WR_INS_MEM;
+               } else if (blk->type == FW_BLOCK_TYPE_DATA) {
+                       if (cb->npe_addr + cb->size > data_size)
+                               goto too_big;
+                       cmd = CMD_WR_DATA_MEM;
+               } else {
+                       print_npe(KERN_INFO, npe, "invalid firmware block #%i "
+                                 "type 0x%X\n", i, blk->type);
+                       goto err;
+               }
+               if (blk->offset + sizeof(*cb) / 4 + cb->size > image->size) {
+                       print_npe(KERN_INFO, npe, "firmware block #%i doesn't "
+                                 "fit in firmware image: type %c, start 0x%X,"
+                                 " length 0x%X\n", i,
+                                 blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
+                                 cb->npe_addr, cb->size);
+                       goto err;
+               }
+
+               for (j = 0; j < cb->size; j++)
+                       npe_cmd_write(npe, cb->npe_addr + j, cmd, cb->data[j]);
+       }
+
+       npe_start(npe);
+       if (!npe_running(npe))
+               print_npe(KERN_ERR, npe, "unable to start\n");
+       release_firmware(fw_entry);
+       return 0;
+
+too_big:
+       print_npe(KERN_INFO, npe, "firmware block #%i doesn't fit in NPE "
+                 "memory: type %c, start 0x%X, length 0x%X\n", i,
+                 blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
+                 cb->npe_addr, cb->size);
+err:
+       release_firmware(fw_entry);
+       return err;
+}
+
+
+struct npe *npe_request(int id)
+{
+       if (id < NPE_COUNT)
+               if (npe_tab[id].valid)
+                       if (try_module_get(THIS_MODULE))
+                               return &npe_tab[id];
+       return NULL;
+}
+
+void npe_release(struct npe *npe)
+{
+       module_put(THIS_MODULE);
+}
+
+
+static int __init npe_init_module(void)
+{
+
+       int i, found = 0;
+
+       for (i = 0; i < NPE_COUNT; i++) {
+               struct npe *npe = &npe_tab[i];
+               if (!(ixp4xx_read_feature_bits() &
+                     (IXP4XX_FEATURE_RESET_NPEA << i)))
+                       continue; /* NPE already disabled or not present */
+               if (!(npe->mem_res = request_mem_region(npe->regs_phys,
+                                                       REGS_SIZE,
+                                                       npe_name(npe)))) {
+                       print_npe(KERN_ERR, npe,
+                                 "failed to request memory region\n");
+                       continue;
+               }
+
+               if (npe_reset(npe))
+                       continue;
+               npe->valid = 1;
+               found++;
+       }
+
+       if (!found)
+               return -ENOSYS;
+       return 0;
+}
+
+static void __exit npe_cleanup_module(void)
+{
+       int i;
+
+       for (i = 0; i < NPE_COUNT; i++)
+               if (npe_tab[i].mem_res) {
+                       npe_reset(&npe_tab[i]);
+                       release_resource(npe_tab[i].mem_res);
+               }
+}
+
+module_init(npe_init_module);
+module_exit(npe_cleanup_module);
+
+MODULE_AUTHOR("Krzysztof Halasa");
+MODULE_LICENSE("GPL v2");
+
+EXPORT_SYMBOL(npe_names);
+EXPORT_SYMBOL(npe_running);
+EXPORT_SYMBOL(npe_request);
+EXPORT_SYMBOL(npe_release);
+EXPORT_SYMBOL(npe_load_firmware);
+EXPORT_SYMBOL(npe_send_message);
+EXPORT_SYMBOL(npe_recv_message);
+EXPORT_SYMBOL(npe_send_recv_message);
diff --git a/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c b/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
new file mode 100644 (file)
index 0000000..e833013
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * Intel IXP4xx Queue Manager driver for Linux
+ *
+ * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <asm/arch/qmgr.h>
+
+#define DEBUG          0
+
+struct qmgr_regs __iomem *qmgr_regs;
+static struct resource *mem_res;
+static spinlock_t qmgr_lock;
+static u32 used_sram_bitmap[4]; /* 128 16-dword pages */
+static void (*irq_handlers[HALF_QUEUES])(void *pdev);
+static void *irq_pdevs[HALF_QUEUES];
+
+void qmgr_set_irq(unsigned int queue, int src,
+                 void (*handler)(void *pdev), void *pdev)
+{
+       u32 __iomem *reg = &qmgr_regs->irqsrc[queue / 8]; /* 8 queues / u32 */
+       int bit = (queue % 8) * 4; /* 3 bits + 1 reserved bit per queue */
+       unsigned long flags;
+
+       src &= 7;
+       spin_lock_irqsave(&qmgr_lock, flags);
+       __raw_writel((__raw_readl(reg) & ~(7 << bit)) | (src << bit), reg);
+       irq_handlers[queue] = handler;
+       irq_pdevs[queue] = pdev;
+       spin_unlock_irqrestore(&qmgr_lock, flags);
+}
+
+
+static irqreturn_t qmgr_irq1(int irq, void *pdev)
+{
+       int i;
+       u32 val = __raw_readl(&qmgr_regs->irqstat[0]);
+       __raw_writel(val, &qmgr_regs->irqstat[0]); /* ACK */
+
+       for (i = 0; i < HALF_QUEUES; i++)
+               if (val & (1 << i))
+                       irq_handlers[i](irq_pdevs[i]);
+
+       return val ? IRQ_HANDLED : 0;
+}
+
+
+void qmgr_enable_irq(unsigned int queue)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&qmgr_lock, flags);
+       __raw_writel(__raw_readl(&qmgr_regs->irqen[0]) | (1 << queue),
+                    &qmgr_regs->irqen[0]);
+       spin_unlock_irqrestore(&qmgr_lock, flags);
+}
+
+void qmgr_disable_irq(unsigned int queue)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&qmgr_lock, flags);
+       __raw_writel(__raw_readl(&qmgr_regs->irqen[0]) & ~(1 << queue),
+                    &qmgr_regs->irqen[0]);
+       spin_unlock_irqrestore(&qmgr_lock, flags);
+}
+
+static inline void shift_mask(u32 *mask)
+{
+       mask[3] = mask[3] << 1 | mask[2] >> 31;
+       mask[2] = mask[2] << 1 | mask[1] >> 31;
+       mask[1] = mask[1] << 1 | mask[0] >> 31;
+       mask[0] <<= 1;
+}
+
+int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
+                      unsigned int nearly_empty_watermark,
+                      unsigned int nearly_full_watermark)
+{
+       u32 cfg, addr = 0, mask[4]; /* in 16-dwords */
+       int err;
+
+       if (queue >= HALF_QUEUES)
+               return -ERANGE;
+
+       if ((nearly_empty_watermark | nearly_full_watermark) & ~7)
+               return -EINVAL;
+
+       switch (len) {
+       case  16:
+               cfg = 0 << 24;
+               mask[0] = 0x1;
+               break;
+       case  32:
+               cfg = 1 << 24;
+               mask[0] = 0x3;
+               break;
+       case  64:
+               cfg = 2 << 24;
+               mask[0] = 0xF;
+               break;
+       case 128:
+               cfg = 3 << 24;
+               mask[0] = 0xFF;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       cfg |= nearly_empty_watermark << 26;
+       cfg |= nearly_full_watermark << 29;
+       len /= 16;              /* in 16-dwords: 1, 2, 4 or 8 */
+       mask[1] = mask[2] = mask[3] = 0;
+
+       if (!try_module_get(THIS_MODULE))
+               return -ENODEV;
+
+       spin_lock_irq(&qmgr_lock);
+       if (__raw_readl(&qmgr_regs->sram[queue])) {
+               err = -EBUSY;
+               goto err;
+       }
+
+       while (1) {
+               if (!(used_sram_bitmap[0] & mask[0]) &&
+                   !(used_sram_bitmap[1] & mask[1]) &&
+                   !(used_sram_bitmap[2] & mask[2]) &&
+                   !(used_sram_bitmap[3] & mask[3]))
+                       break; /* found free space */
+
+               addr++;
+               shift_mask(mask);
+               if (addr + len > ARRAY_SIZE(qmgr_regs->sram)) {
+                       printk(KERN_ERR "qmgr: no free SRAM space for"
+                              " queue %i\n", queue);
+                       err = -ENOMEM;
+                       goto err;
+               }
+       }
+
+       used_sram_bitmap[0] |= mask[0];
+       used_sram_bitmap[1] |= mask[1];
+       used_sram_bitmap[2] |= mask[2];
+       used_sram_bitmap[3] |= mask[3];
+       __raw_writel(cfg | (addr << 14), &qmgr_regs->sram[queue]);
+       spin_unlock_irq(&qmgr_lock);
+
+#if DEBUG
+       printk(KERN_DEBUG "qmgr: requested queue %i, addr = 0x%02X\n",
+              queue, addr);
+#endif
+       return 0;
+
+err:
+       spin_unlock_irq(&qmgr_lock);
+       module_put(THIS_MODULE);
+       return err;
+}
+
+void qmgr_release_queue(unsigned int queue)
+{
+       u32 cfg, addr, mask[4];
+
+       BUG_ON(queue >= HALF_QUEUES); /* not in valid range */
+
+       spin_lock_irq(&qmgr_lock);
+       cfg = __raw_readl(&qmgr_regs->sram[queue]);
+       addr = (cfg >> 14) & 0xFF;
+
+       BUG_ON(!addr);          /* not requested */
+
+       switch ((cfg >> 24) & 3) {
+       case 0: mask[0] = 0x1; break;
+       case 1: mask[0] = 0x3; break;
+       case 2: mask[0] = 0xF; break;
+       case 3: mask[0] = 0xFF; break;
+       }
+
+       while (addr--)
+               shift_mask(mask);
+
+       __raw_writel(0, &qmgr_regs->sram[queue]);
+
+       used_sram_bitmap[0] &= ~mask[0];
+       used_sram_bitmap[1] &= ~mask[1];
+       used_sram_bitmap[2] &= ~mask[2];
+       used_sram_bitmap[3] &= ~mask[3];
+       irq_handlers[queue] = NULL; /* catch IRQ bugs */
+       spin_unlock_irq(&qmgr_lock);
+
+       module_put(THIS_MODULE);
+#if DEBUG
+       printk(KERN_DEBUG "qmgr: released queue %i\n", queue);
+#endif
+}
+
+static int qmgr_init(void)
+{
+       int i, err;
+       mem_res = request_mem_region(IXP4XX_QMGR_BASE_PHYS,
+                                    IXP4XX_QMGR_REGION_SIZE,
+                                    "IXP4xx Queue Manager");
+       if (mem_res == NULL)
+               return -EBUSY;
+
+       qmgr_regs = ioremap(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
+       if (qmgr_regs == NULL) {
+               err = -ENOMEM;
+               goto error_map;
+       }
+
+       /* reset qmgr registers */
+       for (i = 0; i < 4; i++) {
+               __raw_writel(0x33333333, &qmgr_regs->stat1[i]);
+               __raw_writel(0, &qmgr_regs->irqsrc[i]);
+       }
+       for (i = 0; i < 2; i++) {
+               __raw_writel(0, &qmgr_regs->stat2[i]);
+               __raw_writel(0xFFFFFFFF, &qmgr_regs->irqstat[i]); /* clear */
+               __raw_writel(0, &qmgr_regs->irqen[i]);
+       }
+
+       for (i = 0; i < QUEUES; i++)
+               __raw_writel(0, &qmgr_regs->sram[i]);
+
+       err = request_irq(IRQ_IXP4XX_QM1, qmgr_irq1, 0,
+                         "IXP4xx Queue Manager", NULL);
+       if (err) {
+               printk(KERN_ERR "qmgr: failed to request IRQ%i\n",
+                      IRQ_IXP4XX_QM1);
+               goto error_irq;
+       }
+
+       used_sram_bitmap[0] = 0xF; /* 4 first pages reserved for config */
+       spin_lock_init(&qmgr_lock);
+
+       printk(KERN_INFO "IXP4xx Queue Manager initialized.\n");
+       return 0;
+
+error_irq:
+       iounmap(qmgr_regs);
+error_map:
+       release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
+       return err;
+}
+
+static void qmgr_remove(void)
+{
+       free_irq(IRQ_IXP4XX_QM1, NULL);
+       synchronize_irq(IRQ_IXP4XX_QM1);
+       iounmap(qmgr_regs);
+       release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
+}
+
+module_init(qmgr_init);
+module_exit(qmgr_remove);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Krzysztof Halasa");
+
+EXPORT_SYMBOL(qmgr_regs);
+EXPORT_SYMBOL(qmgr_set_irq);
+EXPORT_SYMBOL(qmgr_enable_irq);
+EXPORT_SYMBOL(qmgr_disable_irq);
+EXPORT_SYMBOL(qmgr_request_queue);
+EXPORT_SYMBOL(qmgr_release_queue);
diff --git a/arch/arm/mach-ixp4xx/nas100d-power.c b/arch/arm/mach-ixp4xx/nas100d-power.c
deleted file mode 100644 (file)
index 29aa98d..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * arch/arm/mach-ixp4xx/nas100d-power.c
- *
- * NAS 100d Power/Reset driver
- *
- * Copyright (C) 2005 Tower Technologies
- *
- * based on nas100d-io.c
- *  Copyright (C) 2004 Karen Spearel
- *
- * Author: Alessandro Zummo <a.zummo@towertech.it>
- * Maintainers: http://www.nslu2-linux.org/
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
-
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/module.h>
-#include <linux/reboot.h>
-
-#include <asm/mach-types.h>
-
-static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
-{
-       /* Signal init to do the ctrlaltdel action, this will bypass init if
-        * it hasn't started and do a kernel_restart.
-        */
-       ctrl_alt_del();
-
-       return IRQ_HANDLED;
-}
-
-static int __init nas100d_power_init(void)
-{
-       if (!(machine_is_nas100d()))
-               return 0;
-
-       set_irq_type(NAS100D_RB_IRQ, IRQT_LOW);
-
-       if (request_irq(NAS100D_RB_IRQ, &nas100d_reset_handler,
-               IRQF_DISABLED, "NAS100D reset button", NULL) < 0) {
-
-               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
-                       NAS100D_RB_IRQ);
-
-               return -EIO;
-       }
-
-       return 0;
-}
-
-static void __exit nas100d_power_exit(void)
-{
-       if (!(machine_is_nas100d()))
-               return;
-
-       free_irq(NAS100D_RB_IRQ, NULL);
-}
-
-module_init(nas100d_power_init);
-module_exit(nas100d_power_exit);
-
-MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
-MODULE_DESCRIPTION("NAS100D Power/Reset driver");
-MODULE_LICENSE("GPL");
index 54d884fb2517a5207b2b5699d5b89e936917d6c1..4cecae84837b37309039280122ed726356d6ab5c 100644 (file)
@@ -3,8 +3,14 @@
  *
  * NAS 100d board-setup
  *
- * based ixdp425-setup.c:
+ * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
+ *
+ * based on ixdp425-setup.c:
  *      Copyright (C) 2003-2004 MontaVista Software, Inc.
+ * based on nas100d-power.c:
+ *     Copyright (C) 2005 Tower Technologies
+ * based on nas100d-io.c
+ *     Copyright (C) 2004 Karen Spearel
  *
  * Author: Alessandro Zummo <a.zummo@towertech.it>
  * Author: Rod Whitby <rod@whitby.id.au>
  *
  */
 
-#include <linux/kernel.h>
+#include <linux/if_ether.h>
+#include <linux/irq.h>
+#include <linux/jiffies.h>
+#include <linux/timer.h>
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
 #include <linux/leds.h>
+#include <linux/reboot.h>
+#include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/flash.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
 
 static struct flash_platform_data nas100d_flash_data = {
        .map_name               = "cfi_probe",
@@ -39,35 +52,40 @@ static struct platform_device nas100d_flash = {
        .resource               = &nas100d_flash_resource,
 };
 
-#ifdef CONFIG_LEDS_IXP4XX
-static struct resource nas100d_led_resources[] = {
+static struct i2c_board_info __initdata nas100d_i2c_board_info [] = {
+       {
+               I2C_BOARD_INFO("rtc-pcf8563", 0x51),
+       },
+};
+
+static struct gpio_led nas100d_led_pins[] = {
        {
                .name           = "wlan",   /* green led */
-               .start          = 0,
-               .end            = 0,
-               .flags          = IXP4XX_GPIO_LOW,
+               .gpio           = NAS100D_LED_WLAN_GPIO,
+               .active_low     = true,
        },
        {
-               .name           = "ready",  /* blue power led (off is flashing!) */
-               .start          = 15,
-               .end            = 15,
-               .flags          = IXP4XX_GPIO_LOW,
+               .name           = "power",  /* blue power led (off=flashing) */
+               .gpio           = NAS100D_LED_PWR_GPIO,
+               .active_low     = true,
        },
        {
                .name           = "disk",   /* yellow led */
-               .start          = 3,
-               .end            = 3,
-               .flags          = IXP4XX_GPIO_LOW,
+               .gpio           = NAS100D_LED_DISK_GPIO,
+               .active_low     = true,
        },
 };
 
+static struct gpio_led_platform_data nas100d_led_data = {
+       .num_leds               = ARRAY_SIZE(nas100d_led_pins),
+       .leds                   = nas100d_led_pins,
+};
+
 static struct platform_device nas100d_leds = {
-       .name                   = "IXP4XX-GPIO-LED",
+       .name                   = "leds-gpio",
        .id                     = -1,
-       .num_resources          = ARRAY_SIZE(nas100d_led_resources),
-       .resource               = nas100d_led_resources,
+       .dev.platform_data      = &nas100d_led_data,
 };
-#endif
 
 static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = {
        .sda_pin                = NAS100D_SDA_PIN,
@@ -125,12 +143,28 @@ static struct platform_device nas100d_uart = {
        .resource               = nas100d_uart_resources,
 };
 
+/* Built-in 10/100 Ethernet MAC interfaces */
+static struct eth_plat_info nas100d_plat_eth[] = {
+       {
+               .phy            = 0,
+               .rxq            = 3,
+               .txreadyq       = 20,
+       }
+};
+
+static struct platform_device nas100d_eth[] = {
+       {
+               .name                   = "ixp4xx_eth",
+               .id                     = IXP4XX_ETH_NPEB,
+               .dev.platform_data      = nas100d_plat_eth,
+       }
+};
+
 static struct platform_device *nas100d_devices[] __initdata = {
        &nas100d_i2c_gpio,
        &nas100d_flash,
-#ifdef CONFIG_LEDS_IXP4XX
        &nas100d_leds,
-#endif
+       &nas100d_eth[0],
 };
 
 static void nas100d_power_off(void)
@@ -144,8 +178,63 @@ static void nas100d_power_off(void)
        gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH);
 }
 
+/* This is used to make sure the power-button pusher is serious.  The button
+ * must be held until the value of this counter reaches zero.
+ */
+static int power_button_countdown;
+
+/* Must hold the button down for at least this many counts to be processed */
+#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
+
+static void nas100d_power_handler(unsigned long data);
+static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
+
+static void nas100d_power_handler(unsigned long data)
+{
+       /* This routine is called twice per second to check the
+        * state of the power button.
+        */
+
+       if (gpio_get_value(NAS100D_PB_GPIO)) {
+
+               /* IO Pin is 1 (button pushed) */
+               if (power_button_countdown > 0)
+                       power_button_countdown--;
+
+       } else {
+
+               /* Done on button release, to allow for auto-power-on mods. */
+               if (power_button_countdown == 0) {
+                       /* Signal init to do the ctrlaltdel action,
+                        * this will bypass init if it hasn't started
+                        * and do a kernel_restart.
+                        */
+                       ctrl_alt_del();
+
+                       /* Change the state of the power LED to "blink" */
+                       gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
+               } else {
+                       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
+               }
+       }
+
+       mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
+}
+
+static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
+{
+       /* This is the paper-clip reset, it shuts the machine down directly. */
+       machine_power_off();
+
+       return IRQ_HANDLED;
+}
+
 static void __init nas100d_init(void)
 {
+       DECLARE_MAC_BUF(mac_buf);
+       uint8_t __iomem *f;
+       int i;
+
        ixp4xx_sys_init();
 
        /* gpio 14 and 15 are _not_ clocks */
@@ -155,7 +244,8 @@ static void __init nas100d_init(void)
        nas100d_flash_resource.end =
                IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
 
-       pm_power_off = nas100d_power_off;
+       i2c_register_board_info(0, nas100d_i2c_board_info,
+                               ARRAY_SIZE(nas100d_i2c_board_info));
 
        /*
         * This is only useful on a modified machine, but it is valuable
@@ -165,6 +255,48 @@ static void __init nas100d_init(void)
        (void)platform_device_register(&nas100d_uart);
 
        platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
+
+       pm_power_off = nas100d_power_off;
+
+       if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
+               IRQF_DISABLED | IRQF_TRIGGER_LOW,
+               "NAS100D reset button", NULL) < 0) {
+
+               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
+                       gpio_to_irq(NAS100D_RB_GPIO));
+       }
+
+       /* The power button on the Iomega NAS100d is on GPIO 14, but
+        * it cannot handle interrupts on that GPIO line.  So we'll
+        * have to poll it with a kernel timer.
+        */
+
+       /* Make sure that the power button GPIO is set up as an input */
+       gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
+
+       /* Set the initial value for the power button IRQ handler */
+       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
+
+       mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
+
+       /*
+        * Map in a portion of the flash and read the MAC address.
+        * Since it is stored in BE in the flash itself, we need to
+        * byteswap it if we're in LE mode.
+        */
+       f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);
+       if (f) {
+               for (i = 0; i < 6; i++)
+#ifdef __ARMEB__
+                       nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i);
+#else
+                       nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3));
+#endif
+               iounmap(f);
+       }
+       printk(KERN_INFO "NAS100D: Using MAC address %s for port 0\n",
+              print_mac(mac_buf, nas100d_plat_eth[0].hwaddr));
+
 }
 
 MACHINE_START(NAS100D, "Iomega NAS 100d")
diff --git a/arch/arm/mach-ixp4xx/nslu2-power.c b/arch/arm/mach-ixp4xx/nslu2-power.c
deleted file mode 100644 (file)
index 6f10dc2..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * arch/arm/mach-ixp4xx/nslu2-power.c
- *
- * NSLU2 Power/Reset driver
- *
- * Copyright (C) 2005 Tower Technologies
- *
- * based on nslu2-io.c
- *  Copyright (C) 2004 Karen Spearel
- *
- * Author: Alessandro Zummo <a.zummo@towertech.it>
- * Maintainers: http://www.nslu2-linux.org/
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
-
-#include <linux/module.h>
-#include <linux/reboot.h>
-#include <linux/irq.h>
-#include <linux/interrupt.h>
-
-#include <asm/mach-types.h>
-
-static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
-{
-       /* Signal init to do the ctrlaltdel action, this will bypass init if
-        * it hasn't started and do a kernel_restart.
-        */
-       ctrl_alt_del();
-
-       return IRQ_HANDLED;
-}
-
-static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
-{
-       /* This is the paper-clip reset, it shuts the machine down directly.
-        */
-       machine_power_off();
-
-       return IRQ_HANDLED;
-}
-
-static int __init nslu2_power_init(void)
-{
-       if (!(machine_is_nslu2()))
-               return 0;
-
-       *IXP4XX_GPIO_GPISR = 0x20400000;        /* read the 2 irqs to clr */
-
-       set_irq_type(NSLU2_RB_IRQ, IRQT_LOW);
-       set_irq_type(NSLU2_PB_IRQ, IRQT_HIGH);
-
-       if (request_irq(NSLU2_RB_IRQ, &nslu2_reset_handler,
-               IRQF_DISABLED, "NSLU2 reset button", NULL) < 0) {
-
-               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
-                       NSLU2_RB_IRQ);
-
-               return -EIO;
-       }
-
-       if (request_irq(NSLU2_PB_IRQ, &nslu2_power_handler,
-               IRQF_DISABLED, "NSLU2 power button", NULL) < 0) {
-
-               printk(KERN_DEBUG "Power Button IRQ %d not available\n",
-                       NSLU2_PB_IRQ);
-
-               return -EIO;
-       }
-
-       return 0;
-}
-
-static void __exit nslu2_power_exit(void)
-{
-       if (!(machine_is_nslu2()))
-               return;
-
-       free_irq(NSLU2_RB_IRQ, NULL);
-       free_irq(NSLU2_PB_IRQ, NULL);
-}
-
-module_init(nslu2_power_init);
-module_exit(nslu2_power_exit);
-
-MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
-MODULE_DESCRIPTION("NSLU2 Power/Reset driver");
-MODULE_LICENSE("GPL");
index 77277d27fcc51bef387520c3fea32d88cf7b3f22..acaebcbce53a07319cade57fb80f5bdbb8543ea1 100644 (file)
@@ -3,27 +3,35 @@
  *
  * NSLU2 board-setup
  *
- * based ixdp425-setup.c:
+ * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
+ *
+ * based on ixdp425-setup.c:
  *      Copyright (C) 2003-2004 MontaVista Software, Inc.
+ * based on nslu2-power.c:
+ *     Copyright (C) 2005 Tower Technologies
  *
  * Author: Mark Rakes <mrakes at mac.com>
  * Author: Rod Whitby <rod@whitby.id.au>
+ * Author: Alessandro Zummo <a.zummo@towertech.it>
  * Maintainers: http://www.nslu2-linux.org/
  *
- * Fixed missing init_time in MACHINE_START kas11 10/22/04
- * Changed to conform to new style __init ixdp425 kas11 10/22/04
  */
 
-#include <linux/kernel.h>
+#include <linux/if_ether.h>
+#include <linux/irq.h>
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
 #include <linux/leds.h>
+#include <linux/reboot.h>
+#include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/flash.h>
 #include <asm/mach/time.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
 
 static struct flash_platform_data nslu2_flash_data = {
        .map_name               = "cfi_probe",
@@ -47,41 +55,43 @@ static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = {
        .scl_pin                = NSLU2_SCL_PIN,
 };
 
-#ifdef CONFIG_LEDS_IXP4XX
-static struct resource nslu2_led_resources[] = {
+static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
+       {
+               I2C_BOARD_INFO("rtc-x1205", 0x6f),
+       },
+};
+
+static struct gpio_led nslu2_led_pins[] = {
        {
                .name           = "ready",  /* green led */
-               .start          = NSLU2_LED_GRN_GPIO,
-               .end            = NSLU2_LED_GRN_GPIO,
-               .flags          = IXP4XX_GPIO_HIGH,
+               .gpio           = NSLU2_LED_GRN_GPIO,
        },
        {
                .name           = "status", /* red led */
-               .start          = NSLU2_LED_RED_GPIO,
-               .end            = NSLU2_LED_RED_GPIO,
-               .flags          = IXP4XX_GPIO_HIGH,
+               .gpio           = NSLU2_LED_RED_GPIO,
        },
        {
                .name           = "disk-1",
-               .start          = NSLU2_LED_DISK1_GPIO,
-               .end            = NSLU2_LED_DISK1_GPIO,
-               .flags          = IXP4XX_GPIO_LOW,
+               .gpio           = NSLU2_LED_DISK1_GPIO,
+               .active_low     = true,
        },
        {
                .name           = "disk-2",
-               .start          = NSLU2_LED_DISK2_GPIO,
-               .end            = NSLU2_LED_DISK2_GPIO,
-               .flags          = IXP4XX_GPIO_LOW,
+               .gpio           = NSLU2_LED_DISK2_GPIO,
+               .active_low     = true,
        },
 };
 
+static struct gpio_led_platform_data nslu2_led_data = {
+       .num_leds               = ARRAY_SIZE(nslu2_led_pins),
+       .leds                   = nslu2_led_pins,
+};
+
 static struct platform_device nslu2_leds = {
-       .name                   = "IXP4XX-GPIO-LED",
+       .name                   = "leds-gpio",
        .id                     = -1,
-       .num_resources          = ARRAY_SIZE(nslu2_led_resources),
-       .resource               = nslu2_led_resources,
+       .dev.platform_data      = &nslu2_led_data,
 };
-#endif
 
 static struct platform_device nslu2_i2c_gpio = {
        .name                   = "i2c-gpio",
@@ -140,13 +150,29 @@ static struct platform_device nslu2_uart = {
        .resource               = nslu2_uart_resources,
 };
 
+/* Built-in 10/100 Ethernet MAC interfaces */
+static struct eth_plat_info nslu2_plat_eth[] = {
+       {
+               .phy            = 1,
+               .rxq            = 3,
+               .txreadyq       = 20,
+       }
+};
+
+static struct platform_device nslu2_eth[] = {
+       {
+               .name                   = "ixp4xx_eth",
+               .id                     = IXP4XX_ETH_NPEB,
+               .dev.platform_data      = nslu2_plat_eth,
+       }
+};
+
 static struct platform_device *nslu2_devices[] __initdata = {
        &nslu2_i2c_gpio,
        &nslu2_flash,
        &nslu2_beeper,
-#ifdef CONFIG_LEDS_IXP4XX
        &nslu2_leds,
-#endif
+       &nslu2_eth[0],
 };
 
 static void nslu2_power_off(void)
@@ -160,6 +186,25 @@ static void nslu2_power_off(void)
        gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH);
 }
 
+static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
+{
+       /* Signal init to do the ctrlaltdel action, this will bypass init if
+        * it hasn't started and do a kernel_restart.
+        */
+       ctrl_alt_del();
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
+{
+       /* This is the paper-clip reset, it shuts the machine down directly.
+        */
+       machine_power_off();
+
+       return IRQ_HANDLED;
+}
+
 static void __init nslu2_timer_init(void)
 {
     /* The xtal on this machine is non-standard. */
@@ -175,13 +220,18 @@ static struct sys_timer nslu2_timer = {
 
 static void __init nslu2_init(void)
 {
+       DECLARE_MAC_BUF(mac_buf);
+       uint8_t __iomem *f;
+       int i;
+
        ixp4xx_sys_init();
 
        nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
        nslu2_flash_resource.end =
                IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
 
-       pm_power_off = nslu2_power_off;
+       i2c_register_board_info(0, nslu2_i2c_board_info,
+                               ARRAY_SIZE(nslu2_i2c_board_info));
 
        /*
         * This is only useful on a modified machine, but it is valuable
@@ -191,6 +241,43 @@ static void __init nslu2_init(void)
        (void)platform_device_register(&nslu2_uart);
 
        platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
+
+       pm_power_off = nslu2_power_off;
+
+       if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
+               IRQF_DISABLED | IRQF_TRIGGER_LOW,
+               "NSLU2 reset button", NULL) < 0) {
+
+               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
+                       gpio_to_irq(NSLU2_RB_GPIO));
+       }
+
+       if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
+               IRQF_DISABLED | IRQF_TRIGGER_HIGH,
+               "NSLU2 power button", NULL) < 0) {
+
+               printk(KERN_DEBUG "Power Button IRQ %d not available\n",
+                       gpio_to_irq(NSLU2_PB_GPIO));
+       }
+
+       /*
+        * Map in a portion of the flash and read the MAC address.
+        * Since it is stored in BE in the flash itself, we need to
+        * byteswap it if we're in LE mode.
+        */
+       f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
+       if (f) {
+               for (i = 0; i < 6; i++)
+#ifdef __ARMEB__
+                       nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
+#else
+                       nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
+#endif
+               iounmap(f);
+       }
+       printk(KERN_INFO "NSLU2: Using MAC address %s for port 0\n",
+              print_mac(mac_buf, nslu2_plat_eth[0].hwaddr));
+
 }
 
 MACHINE_START(NSLU2, "Linksys NSLU2")
index b5c916c0747d68867b34325eebc576a86f5fad0b..6e0c4f5b5ae663526a9daf2750149f7f6fe2b89b 100644 (file)
@@ -3,10 +3,11 @@
 #
 
 # Common support (must be linked before board specific support)
-obj-y                          += clock.o devices.o generic.o irq.o dma.o time.o
+obj-y                          += clock.o devices.o generic.o irq.o dma.o \
+                                  time.o gpio.o
 obj-$(CONFIG_PXA25x)           += pxa25x.o
 obj-$(CONFIG_PXA27x)           += pxa27x.o
-obj-$(CONFIG_PXA3xx)           += pxa3xx.o mfp.o
+obj-$(CONFIG_PXA3xx)           += pxa3xx.o mfp.o smemc.o
 obj-$(CONFIG_CPU_PXA300)       += pxa300.o
 obj-$(CONFIG_CPU_PXA320)       += pxa320.o
 
index 28cfd71c032d2bf533621ef6f3503968e6668f7c..6012177a29a35b5afb0227c8f0d31bd95ed0f81c 100644 (file)
@@ -29,6 +29,7 @@
 #include <asm/mach/map.h>
 
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxafb.h>
 #include <asm/arch/ohci.h>
 #include <asm/arch/mmc.h>
index efba65edcd51af287077294659b9564dae19417b..31706224a04c07a58e4c6e91a99a703ff5ff6f12 100644 (file)
@@ -32,7 +32,7 @@ static struct corgissp_machinfo *ssp_machinfo;
 /*
  * There are three devices connected to the SSP interface:
  *   1. A touchscreen controller (TI ADS7846 compatible)
- *   2. An LCD contoller (with some Backlight functionality)
+ *   2. An LCD controller (with some Backlight functionality)
  *   3. A battery monitoring IC (Maxim MAX1111)
  *
  * Each device uses a different speed/mode of communication.
index 50ff453ad3707453051ce1703bed2a519a7c4df4..bfccb80ac8eff129d62aaccd02469fbec7b504de 100644 (file)
@@ -10,6 +10,7 @@
 #include <asm/arch/mmc.h>
 #include <asm/arch/irda.h>
 #include <asm/arch/i2c.h>
+#include <asm/arch/ohci.h>
 
 #include "devices.h"
 
index 698aeec529617e4098db8e30ee1e4d9a4d56cf48..80721c610d41dee16f74ebdbeb72bb4c3be2b7cf 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/ioport.h>
 #include <linux/pm.h>
 #include <linux/string.h>
+#include <linux/sysdev.h>
 
 #include <asm/hardware.h>
 #include <asm/irq.h>
@@ -31,7 +32,6 @@
 #include <asm/mach/map.h>
 
 #include <asm/arch/pxa-regs.h>
-#include <asm/arch/gpio.h>
 
 #include "generic.h"
 
@@ -65,97 +65,6 @@ unsigned int get_memclk_frequency_10khz(void)
 }
 EXPORT_SYMBOL(get_memclk_frequency_10khz);
 
-/*
- * Handy function to set GPIO alternate functions
- */
-int pxa_last_gpio;
-
-int pxa_gpio_mode(int gpio_mode)
-{
-       unsigned long flags;
-       int gpio = gpio_mode & GPIO_MD_MASK_NR;
-       int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
-       int gafr;
-
-       if (gpio > pxa_last_gpio)
-               return -EINVAL;
-
-       local_irq_save(flags);
-       if (gpio_mode & GPIO_DFLT_LOW)
-               GPCR(gpio) = GPIO_bit(gpio);
-       else if (gpio_mode & GPIO_DFLT_HIGH)
-               GPSR(gpio) = GPIO_bit(gpio);
-       if (gpio_mode & GPIO_MD_MASK_DIR)
-               GPDR(gpio) |= GPIO_bit(gpio);
-       else
-               GPDR(gpio) &= ~GPIO_bit(gpio);
-       gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
-       GAFR(gpio) = gafr |  (fn  << (((gpio) & 0xf)*2));
-       local_irq_restore(flags);
-
-       return 0;
-}
-
-EXPORT_SYMBOL(pxa_gpio_mode);
-
-int gpio_direction_input(unsigned gpio)
-{
-       unsigned long flags;
-       u32 mask;
-
-       if (gpio > pxa_last_gpio)
-               return -EINVAL;
-
-       mask = GPIO_bit(gpio);
-       local_irq_save(flags);
-       GPDR(gpio) &= ~mask;
-       local_irq_restore(flags);
-
-       return 0;
-}
-EXPORT_SYMBOL(gpio_direction_input);
-
-int gpio_direction_output(unsigned gpio, int value)
-{
-       unsigned long flags;
-       u32 mask;
-
-       if (gpio > pxa_last_gpio)
-               return -EINVAL;
-
-       mask = GPIO_bit(gpio);
-       local_irq_save(flags);
-       if (value)
-               GPSR(gpio) = mask;
-       else
-               GPCR(gpio) = mask;
-       GPDR(gpio) |= mask;
-       local_irq_restore(flags);
-
-       return 0;
-}
-EXPORT_SYMBOL(gpio_direction_output);
-
-/*
- * Return GPIO level
- */
-int pxa_gpio_get_value(unsigned gpio)
-{
-       return __gpio_get_value(gpio);
-}
-
-EXPORT_SYMBOL(pxa_gpio_get_value);
-
-/*
- * Set output GPIO level
- */
-void pxa_gpio_set_value(unsigned gpio, int value)
-{
-       __gpio_set_value(gpio, value);
-}
-
-EXPORT_SYMBOL(pxa_gpio_set_value);
-
 /*
  * Routine to safely enable or disable a clock in the CKEN
  */
@@ -171,7 +80,6 @@ void __pxa_set_cken(int clock, int enable)
 
        local_irq_restore(flags);
 }
-
 EXPORT_SYMBOL(__pxa_set_cken);
 
 /*
@@ -226,3 +134,59 @@ void __init pxa_map_io(void)
        iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
        get_clk_frequency_khz(1);
 }
+
+#ifdef CONFIG_PM
+
+static unsigned long saved_gplr[4];
+static unsigned long saved_gpdr[4];
+static unsigned long saved_grer[4];
+static unsigned long saved_gfer[4];
+
+static int pxa_gpio_suspend(struct sys_device *dev, pm_message_t state)
+{
+       int i, gpio;
+
+       for (gpio = 0, i = 0; gpio < pxa_last_gpio; gpio += 32, i++) {
+               saved_gplr[i] = GPLR(gpio);
+               saved_gpdr[i] = GPDR(gpio);
+               saved_grer[i] = GRER(gpio);
+               saved_gfer[i] = GFER(gpio);
+
+               /* Clear GPIO transition detect bits */
+               GEDR(gpio) = GEDR(gpio);
+       }
+       return 0;
+}
+
+static int pxa_gpio_resume(struct sys_device *dev)
+{
+       int i, gpio;
+
+       for (gpio = 0, i = 0; gpio < pxa_last_gpio; gpio += 32, i++) {
+               /* restore level with set/clear */
+               GPSR(gpio) = saved_gplr[i];
+               GPCR(gpio) = ~saved_gplr[i];
+
+               GRER(gpio) = saved_grer[i];
+               GFER(gpio) = saved_gfer[i];
+               GPDR(gpio) = saved_gpdr[i];
+       }
+       return 0;
+}
+#else
+#define pxa_gpio_suspend       NULL
+#define pxa_gpio_resume                NULL
+#endif
+
+struct sysdev_class pxa_gpio_sysclass = {
+       .name           = "gpio",
+       .suspend        = pxa_gpio_suspend,
+       .resume         = pxa_gpio_resume,
+};
+
+static int __init pxa_gpio_init(void)
+{
+       return sysdev_class_register(&pxa_gpio_sysclass);
+}
+
+core_initcall(pxa_gpio_init);
index b30f240a16c798756e8e350142e9c92da65126c3..b3d10b0e52a01478055cf4e26b5f312d49d52b65 100644 (file)
@@ -16,6 +16,7 @@ extern void __init pxa_init_irq_low(void);
 extern void __init pxa_init_irq_high(void);
 extern void __init pxa_init_irq_gpio(int gpio_nr);
 extern void __init pxa_init_irq_set_wake(int (*set_wake)(unsigned int, unsigned int));
+extern void __init pxa_init_gpio(int gpio_nr);
 extern void __init pxa25x_init_irq(void);
 extern void __init pxa27x_init_irq(void);
 extern void __init pxa3xx_init_irq(void);
@@ -52,3 +53,6 @@ extern unsigned pxa3xx_get_memclk_frequency_10khz(void);
 #define pxa3xx_get_clk_frequency_khz(x)                (0)
 #define pxa3xx_get_memclk_frequency_10khz()    (0)
 #endif
+
+extern struct sysdev_class pxa_irq_sysclass;
+extern struct sysdev_class pxa_gpio_sysclass;
diff --git a/arch/arm/mach-pxa/gpio.c b/arch/arm/mach-pxa/gpio.c
new file mode 100644 (file)
index 0000000..8638dd7
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ *  linux/arch/arm/mach-pxa/gpio.c
+ *
+ *  Generic PXA GPIO handling
+ *
+ *  Author:    Nicolas Pitre
+ *  Created:   Jun 15, 2001
+ *  Copyright: MontaVista Software Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+
+#include <asm/gpio.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/arch/pxa-regs.h>
+
+#include "generic.h"
+
+
+struct pxa_gpio_chip {
+       struct gpio_chip chip;
+       void __iomem     *regbase;
+};
+
+int pxa_last_gpio;
+
+/*
+ * Configure pins for GPIO or other functions
+ */
+int pxa_gpio_mode(int gpio_mode)
+{
+       unsigned long flags;
+       int gpio = gpio_mode & GPIO_MD_MASK_NR;
+       int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
+       int gafr;
+
+       if (gpio > pxa_last_gpio)
+               return -EINVAL;
+
+       local_irq_save(flags);
+       if (gpio_mode & GPIO_DFLT_LOW)
+               GPCR(gpio) = GPIO_bit(gpio);
+       else if (gpio_mode & GPIO_DFLT_HIGH)
+               GPSR(gpio) = GPIO_bit(gpio);
+       if (gpio_mode & GPIO_MD_MASK_DIR)
+               GPDR(gpio) |= GPIO_bit(gpio);
+       else
+               GPDR(gpio) &= ~GPIO_bit(gpio);
+       gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
+       GAFR(gpio) = gafr |  (fn  << (((gpio) & 0xf)*2));
+       local_irq_restore(flags);
+
+       return 0;
+}
+EXPORT_SYMBOL(pxa_gpio_mode);
+
+static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+       unsigned long        flags;
+       u32                  mask = 1 << offset;
+       u32                  value;
+       struct pxa_gpio_chip *pxa;
+       void __iomem         *gpdr;
+
+       pxa = container_of(chip, struct pxa_gpio_chip, chip);
+       gpdr = pxa->regbase + GPDR_OFFSET;
+       local_irq_save(flags);
+       value = __raw_readl(gpdr);
+       value &= ~mask;
+       __raw_writel(value, gpdr);
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+static int pxa_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value)
+{
+       unsigned long        flags;
+       u32                  mask = 1 << offset;
+       u32                  tmp;
+       struct pxa_gpio_chip *pxa;
+       void __iomem         *gpdr;
+
+       pxa = container_of(chip, struct pxa_gpio_chip, chip);
+       __raw_writel(mask,
+                       pxa->regbase + (value ? GPSR_OFFSET : GPCR_OFFSET));
+       gpdr = pxa->regbase + GPDR_OFFSET;
+       local_irq_save(flags);
+       tmp = __raw_readl(gpdr);
+       tmp |= mask;
+       __raw_writel(tmp, gpdr);
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+/*
+ * Return GPIO level
+ */
+static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+       u32                  mask = 1 << offset;
+       struct pxa_gpio_chip *pxa;
+
+       pxa = container_of(chip, struct pxa_gpio_chip, chip);
+       return __raw_readl(pxa->regbase + GPLR_OFFSET) & mask;
+}
+
+/*
+ * Set output GPIO level
+ */
+static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+       u32                  mask = 1 << offset;
+       struct pxa_gpio_chip *pxa;
+
+       pxa = container_of(chip, struct pxa_gpio_chip, chip);
+
+       if (value)
+               __raw_writel(mask, pxa->regbase + GPSR_OFFSET);
+       else
+               __raw_writel(mask, pxa->regbase + GPCR_OFFSET);
+}
+
+static struct pxa_gpio_chip pxa_gpio_chip[] = {
+       [0] = {
+               .regbase = GPIO0_BASE,
+               .chip = {
+                       .label            = "gpio-0",
+                       .direction_input  = pxa_gpio_direction_input,
+                       .direction_output = pxa_gpio_direction_output,
+                       .get              = pxa_gpio_get,
+                       .set              = pxa_gpio_set,
+                       .base             = 0,
+                       .ngpio            = 32,
+               },
+       },
+       [1] = {
+               .regbase = GPIO1_BASE,
+               .chip = {
+                       .label            = "gpio-1",
+                       .direction_input  = pxa_gpio_direction_input,
+                       .direction_output = pxa_gpio_direction_output,
+                       .get              = pxa_gpio_get,
+                       .set              = pxa_gpio_set,
+                       .base             = 32,
+                       .ngpio            = 32,
+               },
+       },
+       [2] = {
+               .regbase = GPIO2_BASE,
+               .chip = {
+                       .label            = "gpio-2",
+                       .direction_input  = pxa_gpio_direction_input,
+                       .direction_output = pxa_gpio_direction_output,
+                       .get              = pxa_gpio_get,
+                       .set              = pxa_gpio_set,
+                       .base             = 64,
+                       .ngpio            = 32, /* 21 for PXA25x */
+               },
+       },
+#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
+       [3] = {
+               .regbase = GPIO3_BASE,
+               .chip = {
+                       .label            = "gpio-3",
+                       .direction_input  = pxa_gpio_direction_input,
+                       .direction_output = pxa_gpio_direction_output,
+                       .get              = pxa_gpio_get,
+                       .set              = pxa_gpio_set,
+                       .base             = 96,
+                       .ngpio            = 32,
+               },
+       },
+#endif
+};
+
+void __init pxa_init_gpio(int gpio_nr)
+{
+       int i;
+
+       /* add a GPIO chip for each register bank.
+        * the last PXA25x register only contains 21 GPIOs
+        */
+       for (i = 0; i < gpio_nr; i += 32) {
+               if (i+32 > gpio_nr)
+                       pxa_gpio_chip[i/32].chip.ngpio = gpio_nr - i;
+               gpiochip_add(&pxa_gpio_chip[i/32].chip);
+       }
+}
index 07acb45b16ea83ac26be925293943a1f14def698..36c6a68beca26e1fa895d6ebb2373bd4bdd0eed6 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
+#include <linux/sysdev.h>
 
 #include <asm/hardware.h>
 #include <asm/irq.h>
@@ -310,6 +311,8 @@ void __init pxa_init_irq_gpio(int gpio_nr)
        /* Install handler for GPIO>=2 edge detect interrupts */
        set_irq_chip(IRQ_GPIO_2_x, &pxa_internal_chip_low);
        set_irq_chained_handler(IRQ_GPIO_2_x, pxa_gpio_demux_handler);
+
+       pxa_init_gpio(gpio_nr);
 }
 
 void __init pxa_init_irq_set_wake(int (*set_wake)(unsigned int, unsigned int))
@@ -321,3 +324,64 @@ void __init pxa_init_irq_set_wake(int (*set_wake)(unsigned int, unsigned int))
        pxa_low_gpio_chip.set_wake = set_wake;
        pxa_muxed_gpio_chip.set_wake = set_wake;
 }
+
+#ifdef CONFIG_PM
+static unsigned long saved_icmr[2];
+
+static int pxa_irq_suspend(struct sys_device *dev, pm_message_t state)
+{
+       switch (dev->id) {
+       case 0:
+               saved_icmr[0] = ICMR;
+               ICMR = 0;
+               break;
+#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
+       case 1:
+               saved_icmr[1] = ICMR2;
+               ICMR2 = 0;
+               break;
+#endif
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int pxa_irq_resume(struct sys_device *dev)
+{
+       switch (dev->id) {
+       case 0:
+               ICMR = saved_icmr[0];
+               ICLR = 0;
+               ICCR = 1;
+               break;
+#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
+       case 1:
+               ICMR2 = saved_icmr[1];
+               ICLR2 = 0;
+               break;
+#endif
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+#else
+#define pxa_irq_suspend                NULL
+#define pxa_irq_resume         NULL
+#endif
+
+struct sysdev_class pxa_irq_sysclass = {
+       .name           = "irq",
+       .suspend        = pxa_irq_suspend,
+       .resume         = pxa_irq_resume,
+};
+
+static int __init pxa_irq_init(void)
+{
+       return sysdev_class_register(&pxa_irq_sysclass);
+}
+
+core_initcall(pxa_irq_init);
index ec1b2d8f61c475db0cbd7b7690b3a8522247e11b..f5809adce298219a46f077d7234dd0a99cf952e3 100644 (file)
@@ -22,6 +22,7 @@
 #include <asm/hardware.h>
 #include <asm/arch/mfp.h>
 #include <asm/arch/mfp-pxa3xx.h>
+#include <asm/arch/pxa3xx-regs.h>
 
 /* mfp_spin_lock is used to ensure that MFP register configuration
  * (most likely a read-modify-write operation) is atomic, and that
@@ -223,11 +224,19 @@ static int pxa3xx_mfp_resume(struct sys_device *d)
                struct pxa3xx_mfp_pin *p = &mfp_table[pin];
                __mfp_config_run(p);
        }
+
+       /* clear RDH bit when MFP settings are restored
+        *
+        * NOTE: the last 3 bits DxS are write-1-to-clear so carefully
+        * preserve them here in case they will be referenced later
+        */
+       ASCR &= ~(ASCR_RDH | ASCR_D1S | ASCR_D2S | ASCR_D3S);
+
        return 0;
 }
 
 static struct sysdev_class mfp_sysclass = {
-       set_kset_name("mfp"),
+       .name           = "mfp",
        .suspend        = pxa3xx_mfp_suspend,
        .resume         = pxa3xx_mfp_resume,
 };
index 540c3bba5f9a8663b508835b0894065015acfc43..c14696b9979dfbaba3e218ab082f3a1d0f77b0d5 100644 (file)
@@ -29,6 +29,7 @@
 #include <asm/mach/arch.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx_spi.h>
 #include <asm/arch/pcm027.h>
 #include "generic.h"
index dd54496083cb2d7b89471d53a3e10ec6eb249cff..209eabf0ed3e60917ae29d72c5316efd54cfc8db 100644 (file)
@@ -164,7 +164,7 @@ static struct resource poodlets_resources[] = {
        },
 };
 
-static unsigned long poodle_get_hsync_len(void)
+static unsigned long poodle_get_hsync_invperiod(void)
 {
        return 0;
 }
@@ -174,9 +174,9 @@ static void poodle_null_hsync(void)
 }
 
 static struct corgits_machinfo  poodle_ts_machinfo = {
-       .get_hsync_len   = poodle_get_hsync_len,
-       .put_hsync       = poodle_null_hsync,
-       .wait_hsync      = poodle_null_hsync,
+       .get_hsync_invperiod    = poodle_get_hsync_invperiod,
+       .put_hsync              = poodle_null_hsync,
+       .wait_hsync             = poodle_null_hsync,
 };
 
 static struct platform_device poodle_ts_device = {
index ddd05bf78e022b0952ca06fafc30a2293d770fdf..599e53fcc2c5abb7b039269e506dd8d2d71aeaff 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/suspend.h>
+#include <linux/sysdev.h>
 
 #include <asm/hardware.h>
 #include <asm/arch/irqs.h>
@@ -141,11 +142,6 @@ static struct clk pxa25x_clks[] = {
 #define SAVE(x)                sleep_save[SLEEP_SAVE_##x] = x
 #define RESTORE(x)     x = sleep_save[SLEEP_SAVE_##x]
 
-#define RESTORE_GPLEVEL(n) do { \
-       GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
-       GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
-} while (0)
-
 /*
  * List of global PXA peripheral registers to preserve.
  * More ones like CP and general purpose register values are preserved
@@ -153,10 +149,6 @@ static struct clk pxa25x_clks[] = {
  */
 enum { SLEEP_SAVE_START = 0,
 
-       SLEEP_SAVE_GPLR0, SLEEP_SAVE_GPLR1, SLEEP_SAVE_GPLR2,
-       SLEEP_SAVE_GPDR0, SLEEP_SAVE_GPDR1, SLEEP_SAVE_GPDR2,
-       SLEEP_SAVE_GRER0, SLEEP_SAVE_GRER1, SLEEP_SAVE_GRER2,
-       SLEEP_SAVE_GFER0, SLEEP_SAVE_GFER1, SLEEP_SAVE_GFER2,
        SLEEP_SAVE_PGSR0, SLEEP_SAVE_PGSR1, SLEEP_SAVE_PGSR2,
 
        SLEEP_SAVE_GAFR0_L, SLEEP_SAVE_GAFR0_U,
@@ -165,7 +157,6 @@ enum {      SLEEP_SAVE_START = 0,
 
        SLEEP_SAVE_PSTR,
 
-       SLEEP_SAVE_ICMR,
        SLEEP_SAVE_CKEN,
 
        SLEEP_SAVE_SIZE
@@ -174,17 +165,12 @@ enum {    SLEEP_SAVE_START = 0,
 
 static void pxa25x_cpu_pm_save(unsigned long *sleep_save)
 {
-       SAVE(GPLR0); SAVE(GPLR1); SAVE(GPLR2);
-       SAVE(GPDR0); SAVE(GPDR1); SAVE(GPDR2);
-       SAVE(GRER0); SAVE(GRER1); SAVE(GRER2);
-       SAVE(GFER0); SAVE(GFER1); SAVE(GFER2);
        SAVE(PGSR0); SAVE(PGSR1); SAVE(PGSR2);
 
        SAVE(GAFR0_L); SAVE(GAFR0_U);
        SAVE(GAFR1_L); SAVE(GAFR1_U);
        SAVE(GAFR2_L); SAVE(GAFR2_U);
 
-       SAVE(ICMR); ICMR = 0;
        SAVE(CKEN);
        SAVE(PSTR);
 
@@ -198,22 +184,14 @@ static void pxa25x_cpu_pm_restore(unsigned long *sleep_save)
        PSPR = 0;
 
        /* restore registers */
-       RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1); RESTORE_GPLEVEL(2);
-       RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2);
        RESTORE(GAFR0_L); RESTORE(GAFR0_U);
        RESTORE(GAFR1_L); RESTORE(GAFR1_U);
        RESTORE(GAFR2_L); RESTORE(GAFR2_U);
-       RESTORE(GRER0); RESTORE(GRER1); RESTORE(GRER2);
-       RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2);
        RESTORE(PGSR0); RESTORE(PGSR1); RESTORE(PGSR2);
 
        PSSR = PSSR_RDH | PSSR_PH;
 
        RESTORE(CKEN);
-
-       ICLR = 0;
-       ICCR = 1;
-       RESTORE(ICMR);
        RESTORE(PSTR);
 }
 
@@ -304,9 +282,17 @@ static struct platform_device *pxa25x_devices[] __initdata = {
        &pxa25x_device_assp,
 };
 
+static struct sys_device pxa25x_sysdev[] = {
+       {
+               .cls    = &pxa_irq_sysclass,
+       }, {
+               .cls    = &pxa_gpio_sysclass,
+       },
+};
+
 static int __init pxa25x_init(void)
 {
-       int ret = 0;
+       int i, ret = 0;
 
        /* Only add HWUART for PXA255/26x; PXA210/250/27x do not have it. */
        if (cpu_is_pxa25x())
@@ -320,9 +306,18 @@ static int __init pxa25x_init(void)
 
                pxa25x_init_pm();
 
+               for (i = 0; i < ARRAY_SIZE(pxa25x_sysdev); i++) {
+                       ret = sysdev_register(&pxa25x_sysdev[i]);
+                       if (ret)
+                               pr_err("failed to register sysdev[%d]\n", i);
+               }
+
                ret = platform_add_devices(pxa25x_devices,
                                           ARRAY_SIZE(pxa25x_devices));
+               if (ret)
+                       return ret;
        }
+
        /* Only add HWUART for PXA255/26x; PXA210/250/27x do not have it. */
        if (cpu_is_pxa25x())
                ret = platform_device_register(&pxa_device_hwuart);
index 96cf274ec7cbb7fa9a59c2f48263a06ae791f06f..46a951c3e5a0097e5c280bda04bbca0cf4936fb2 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/suspend.h>
 #include <linux/platform_device.h>
+#include <linux/sysdev.h>
 
 #include <asm/hardware.h>
 #include <asm/irq.h>
@@ -171,11 +172,6 @@ static struct clk pxa27x_clks[] = {
 #define SAVE(x)                sleep_save[SLEEP_SAVE_##x] = x
 #define RESTORE(x)     x = sleep_save[SLEEP_SAVE_##x]
 
-#define RESTORE_GPLEVEL(n) do { \
-       GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
-       GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
-} while (0)
-
 /*
  * List of global PXA peripheral registers to preserve.
  * More ones like CP and general purpose register values are preserved
@@ -183,10 +179,6 @@ static struct clk pxa27x_clks[] = {
  */
 enum { SLEEP_SAVE_START = 0,
 
-       SLEEP_SAVE_GPLR0, SLEEP_SAVE_GPLR1, SLEEP_SAVE_GPLR2, SLEEP_SAVE_GPLR3,
-       SLEEP_SAVE_GPDR0, SLEEP_SAVE_GPDR1, SLEEP_SAVE_GPDR2, SLEEP_SAVE_GPDR3,
-       SLEEP_SAVE_GRER0, SLEEP_SAVE_GRER1, SLEEP_SAVE_GRER2, SLEEP_SAVE_GRER3,
-       SLEEP_SAVE_GFER0, SLEEP_SAVE_GFER1, SLEEP_SAVE_GFER2, SLEEP_SAVE_GFER3,
        SLEEP_SAVE_PGSR0, SLEEP_SAVE_PGSR1, SLEEP_SAVE_PGSR2, SLEEP_SAVE_PGSR3,
 
        SLEEP_SAVE_GAFR0_L, SLEEP_SAVE_GAFR0_U,
@@ -196,7 +188,6 @@ enum {      SLEEP_SAVE_START = 0,
 
        SLEEP_SAVE_PSTR,
 
-       SLEEP_SAVE_ICMR,
        SLEEP_SAVE_CKEN,
 
        SLEEP_SAVE_MDREFR,
@@ -208,10 +199,6 @@ enum {     SLEEP_SAVE_START = 0,
 
 void pxa27x_cpu_pm_save(unsigned long *sleep_save)
 {
-       SAVE(GPLR0); SAVE(GPLR1); SAVE(GPLR2); SAVE(GPLR3);
-       SAVE(GPDR0); SAVE(GPDR1); SAVE(GPDR2); SAVE(GPDR3);
-       SAVE(GRER0); SAVE(GRER1); SAVE(GRER2); SAVE(GRER3);
-       SAVE(GFER0); SAVE(GFER1); SAVE(GFER2); SAVE(GFER3);
        SAVE(PGSR0); SAVE(PGSR1); SAVE(PGSR2); SAVE(PGSR3);
 
        SAVE(GAFR0_L); SAVE(GAFR0_U);
@@ -223,12 +210,8 @@ void pxa27x_cpu_pm_save(unsigned long *sleep_save)
        SAVE(PWER); SAVE(PCFR); SAVE(PRER);
        SAVE(PFER); SAVE(PKWR);
 
-       SAVE(ICMR); ICMR = 0;
        SAVE(CKEN);
        SAVE(PSTR);
-
-       /* Clear GPIO transition detect bits */
-       GEDR0 = GEDR0; GEDR1 = GEDR1; GEDR2 = GEDR2; GEDR3 = GEDR3;
 }
 
 void pxa27x_cpu_pm_restore(unsigned long *sleep_save)
@@ -237,15 +220,10 @@ void pxa27x_cpu_pm_restore(unsigned long *sleep_save)
        PSPR = 0;
 
        /* restore registers */
-       RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1);
-       RESTORE_GPLEVEL(2); RESTORE_GPLEVEL(3);
-       RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2); RESTORE(GPDR3);
        RESTORE(GAFR0_L); RESTORE(GAFR0_U);
        RESTORE(GAFR1_L); RESTORE(GAFR1_U);
        RESTORE(GAFR2_L); RESTORE(GAFR2_U);
        RESTORE(GAFR3_L); RESTORE(GAFR3_U);
-       RESTORE(GRER0); RESTORE(GRER1); RESTORE(GRER2); RESTORE(GRER3);
-       RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2); RESTORE(GFER3);
        RESTORE(PGSR0); RESTORE(PGSR1); RESTORE(PGSR2); RESTORE(PGSR3);
 
        RESTORE(MDREFR);
@@ -256,9 +234,6 @@ void pxa27x_cpu_pm_restore(unsigned long *sleep_save)
 
        RESTORE(CKEN);
 
-       ICLR = 0;
-       ICCR = 1;
-       RESTORE(ICMR);
        RESTORE(PSTR);
 }
 
@@ -409,9 +384,22 @@ static struct platform_device *devices[] __initdata = {
        &pxa27x_device_ssp3,
 };
 
+static struct sys_device pxa27x_sysdev[] = {
+       {
+               .id     = 0,
+               .cls    = &pxa_irq_sysclass,
+       }, {
+               .id     = 1,
+               .cls    = &pxa_irq_sysclass,
+       }, {
+               .cls    = &pxa_gpio_sysclass,
+       },
+};
+
 static int __init pxa27x_init(void)
 {
-       int ret = 0;
+       int i, ret = 0;
+
        if (cpu_is_pxa27x()) {
                clks_register(pxa27x_clks, ARRAY_SIZE(pxa27x_clks));
 
@@ -420,8 +408,15 @@ static int __init pxa27x_init(void)
 
                pxa27x_init_pm();
 
+               for (i = 0; i < ARRAY_SIZE(pxa27x_sysdev); i++) {
+                       ret = sysdev_register(&pxa27x_sysdev[i]);
+                       if (ret)
+                               pr_err("failed to register sysdev[%d]\n", i);
+               }
+
                ret = platform_add_devices(devices, ARRAY_SIZE(devices));
        }
+
        return ret;
 }
 
index 5cbf057a1b32f4ce2c6f05d137efad8f086d0c74..e47e67c11afe65dfbc10f234c1dbfe8dc636cf32 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/irq.h>
 #include <linux/io.h>
+#include <linux/sysdev.h>
 
 #include <asm/hardware.h>
 #include <asm/arch/pxa3xx-regs.h>
@@ -39,6 +40,7 @@
 #define RO_CLK         60000000
 
 #define ACCR_D0CS      (1 << 26)
+#define ACCR_PCCE      (1 << 11)
 
 /* crystal frequency to static memory controller multiplier (SMCFS) */
 static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
@@ -203,7 +205,6 @@ static struct clk pxa3xx_clks[] = {
 };
 
 #ifdef CONFIG_PM
-#define SLEEP_SAVE_SIZE        4
 
 #define ISRAM_START    0x5c000000
 #define ISRAM_SIZE     SZ_256K
@@ -211,25 +212,29 @@ static struct clk pxa3xx_clks[] = {
 static void __iomem *sram;
 static unsigned long wakeup_src;
 
-static void pxa3xx_cpu_pm_save(unsigned long *sleep_save)
-{
-       pr_debug("PM: CKENA=%08x CKENB=%08x\n", CKENA, CKENB);
+#define SAVE(x)                sleep_save[SLEEP_SAVE_##x] = x
+#define RESTORE(x)     x = sleep_save[SLEEP_SAVE_##x]
 
-       if (CKENA & (1 << CKEN_USBH)) {
-               printk(KERN_ERR "PM: USB host clock not stopped?\n");
-               CKENA &= ~(1 << CKEN_USBH);
-       }
-//     CKENA |= 1 << (CKEN_ISC & 31);
+enum { SLEEP_SAVE_START = 0,
+       SLEEP_SAVE_CKENA,
+       SLEEP_SAVE_CKENB,
+       SLEEP_SAVE_ACCR,
 
-       /*
-        * Low power modes require the HSIO2 clock to be enabled.
-        */
-       CKENB |= 1 << (CKEN_HSIO2 & 31);
+       SLEEP_SAVE_SIZE,
+};
+
+static void pxa3xx_cpu_pm_save(unsigned long *sleep_save)
+{
+       SAVE(CKENA);
+       SAVE(CKENB);
+       SAVE(ACCR);
 }
 
 static void pxa3xx_cpu_pm_restore(unsigned long *sleep_save)
 {
-       CKENB &= ~(1 << (CKEN_HSIO2 & 31));
+       RESTORE(ACCR);
+       RESTORE(CKENA);
+       RESTORE(CKENB);
 }
 
 /*
@@ -265,6 +270,46 @@ static void pxa3xx_cpu_standby(unsigned int pwrmode)
        printk("PM: AD2D0SR=%08x ASCR=%08x\n", AD2D0SR, ASCR);
 }
 
+/*
+ * NOTE:  currently, the OBM (OEM Boot Module) binary comes along with
+ * PXA3xx development kits assumes that the resuming process continues
+ * with the address stored within the first 4 bytes of SDRAM. The PSPR
+ * register is used privately by BootROM and OBM, and _must_ be set to
+ * 0x5c014000 for the moment.
+ */
+static void pxa3xx_cpu_pm_suspend(void)
+{
+       volatile unsigned long *p = (volatile void *)0xc0000000;
+       unsigned long saved_data = *p;
+
+       extern void pxa3xx_cpu_suspend(void);
+       extern void pxa3xx_cpu_resume(void);
+
+       /* resuming from D2 requires the HSIO2/BOOT/TPM clocks enabled */
+       CKENA |= (1 << CKEN_BOOT) | (1 << CKEN_TPM);
+       CKENB |= 1 << (CKEN_HSIO2 & 0x1f);
+
+       /* clear and setup wakeup source */
+       AD3SR = ~0;
+       AD3ER = wakeup_src;
+       ASCR = ASCR;
+       ARSR = ARSR;
+
+       PCFR |= (1u << 13);                     /* L1_DIS */
+       PCFR &= ~((1u << 12) | (1u << 1));      /* L0_EN | SL_ROD */
+
+       PSPR = 0x5c014000;
+
+       /* overwrite with the resume address */
+       *p = virt_to_phys(pxa3xx_cpu_resume);
+
+       pxa3xx_cpu_suspend();
+
+       *p = saved_data;
+
+       AD3ER = 0;
+}
+
 static void pxa3xx_cpu_pm_enter(suspend_state_t state)
 {
        /*
@@ -279,6 +324,7 @@ static void pxa3xx_cpu_pm_enter(suspend_state_t state)
                break;
 
        case PM_SUSPEND_MEM:
+               pxa3xx_cpu_pm_suspend();
                break;
        }
 }
@@ -452,9 +498,21 @@ static struct platform_device *devices[] __initdata = {
        &pxa3xx_device_ssp4,
 };
 
+static struct sys_device pxa3xx_sysdev[] = {
+       {
+               .id     = 0,
+               .cls    = &pxa_irq_sysclass,
+       }, {
+               .id     = 1,
+               .cls    = &pxa_irq_sysclass,
+       }, {
+               .cls    = &pxa_gpio_sysclass,
+       },
+};
+
 static int __init pxa3xx_init(void)
 {
-       int ret = 0;
+       int i, ret = 0;
 
        if (cpu_is_pxa3xx()) {
                clks_register(pxa3xx_clks, ARRAY_SIZE(pxa3xx_clks));
@@ -464,9 +522,16 @@ static int __init pxa3xx_init(void)
 
                pxa3xx_init_pm();
 
-               return platform_add_devices(devices, ARRAY_SIZE(devices));
+               for (i = 0; i < ARRAY_SIZE(pxa3xx_sysdev); i++) {
+                       ret = sysdev_register(&pxa3xx_sysdev[i]);
+                       if (ret)
+                               pr_err("failed to register sysdev[%d]\n", i);
+               }
+
+               ret = platform_add_devices(devices, ARRAY_SIZE(devices));
        }
-       return 0;
+
+       return ret;
 }
 
 subsys_initcall(pxa3xx_init);
index 14bb4a93ea524e814c481e2b42123727471580b9..784716eb7fc5735a3e6b6209223508984013819f 100644 (file)
@@ -50,6 +50,108 @@ pxa_cpu_save_sp:
        str     r0, [r1]
        ldr     pc, [sp], #4
 
+#ifdef CONFIG_PXA3xx
+/*
+ * pxa3xx_cpu_suspend() - forces CPU into sleep state (S2D3C4)
+ *
+ * NOTE:  unfortunately, pxa_cpu_save_cp can not be reused here since
+ * the auxiliary control register address is different between pxa3xx
+ * and pxa{25x,27x}
+ */
+
+ENTRY(pxa3xx_cpu_suspend)
+
+#ifndef CONFIG_IWMMXT
+       mra     r2, r3, acc0
+#endif
+       stmfd   sp!, {r2 - r12, lr}     @ save registers on stack
+
+       mrc     p14, 0, r3, c6, c0, 0           @ clock configuration, for turbo mode
+       mrc     p15, 0, r4, c15, c1, 0          @ CP access reg
+       mrc     p15, 0, r5, c13, c0, 0          @ PID
+       mrc     p15, 0, r6, c3, c0, 0           @ domain ID
+       mrc     p15, 0, r7, c2, c0, 0           @ translation table base addr
+       mrc     p15, 0, r8, c1, c0, 1           @ auxiliary control reg
+       mrc     p15, 0, r9, c1, c0, 0           @ control reg
+
+       bic     r3, r3, #2                      @ clear frequency change bit
+
+       @ store them plus current virtual stack ptr on stack
+       mov     r10, sp
+       stmfd   sp!, {r3 - r10}
+
+       @ store physical address of stack pointer
+       mov     r0, sp
+       bl      sleep_phys_sp
+       ldr     r1, =sleep_save_sp
+       str     r0, [r1]
+
+       @ clean data cache
+       bl      xsc3_flush_kern_cache_all
+
+       mov     r0, #0x06               @ S2D3C4 mode
+       mcr     p14, 0, r0, c7, c0, 0   @ enter sleep
+
+20:    b       20b                     @ waiting for sleep
+
+       .data
+       .align 5
+/*
+ * pxa3xx_cpu_resume
+ */
+
+ENTRY(pxa3xx_cpu_resume)
+
+       mov     r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE   @ set SVC, irqs off
+       msr     cpsr_c, r0
+
+       ldr     r0, sleep_save_sp               @ stack phys addr
+       ldmfd   r0, {r3 - r9, sp}               @ CP regs + virt stack ptr
+
+       mov     r1, #0
+       mcr     p15, 0, r1, c7, c7, 0           @ invalidate I & D caches, BTB
+       mcr     p15, 0, r1, c7, c10, 4          @ drain write (&fill) buffer
+       mcr     p15, 0, r1, c7, c5, 4           @ flush prefetch buffer
+       mcr     p15, 0, r1, c8, c7, 0           @ invalidate I & D TLBs
+
+       mcr     p14, 0, r3, c6, c0, 0           @ clock configuration, turbo mode.
+       mcr     p15, 0, r4, c15, c1, 0          @ CP access reg
+       mcr     p15, 0, r5, c13, c0, 0          @ PID
+       mcr     p15, 0, r6, c3, c0, 0           @ domain ID
+       mcr     p15, 0, r7, c2, c0, 0           @ translation table base addr
+       mcr     p15, 0, r8, c1, c0, 1           @ auxiliary control reg
+
+       @ temporarily map resume_turn_on_mmu into the page table,
+       @ otherwise prefetch abort occurs after MMU is turned on
+       mov     r1, r7
+       bic     r1, r1, #0x00ff
+       bic     r1, r1, #0x3f00
+       ldr     r2, =0x542e
+
+       adr     r3, resume_turn_on_mmu
+       mov     r3, r3, lsr #20
+       orr     r4, r2, r3, lsl #20
+       ldr     r5, [r1, r3, lsl #2]
+       str     r4, [r1, r3, lsl #2]
+
+       @ Mapping page table address in the page table
+       mov     r6, r1, lsr #20
+       orr     r7, r2, r6, lsl #20
+       ldr     r8, [r1, r6, lsl #2]
+       str     r7, [r1, r6, lsl #2]
+
+       ldr     r2, =pxa3xx_resume_after_mmu    @ absolute virtual address
+       b       resume_turn_on_mmu              @ cache align execution
+
+       .text
+pxa3xx_resume_after_mmu:
+       /* restore the temporary mapping */
+       str     r5, [r1, r3, lsl #2]
+       str     r8, [r1, r6, lsl #2]
+       b       resume_after_mmu
+
+#endif /* CONFIG_PXA3xx */
+
 #ifdef CONFIG_PXA27x
 /*
  * pxa27x_cpu_suspend()
diff --git a/arch/arm/mach-pxa/smemc.c b/arch/arm/mach-pxa/smemc.c
new file mode 100644 (file)
index 0000000..ad346ad
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Static Memory Controller
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/sysdev.h>
+
+#define SMEMC_PHYS_BASE        (0x4A000000)
+#define SMEMC_PHYS_SIZE        (0x90)
+
+#define MSC0           (0x08)  /* Static Memory Controller Register 0 */
+#define MSC1           (0x0C)  /* Static Memory Controller Register 1 */
+#define SXCNFG         (0x1C)  /* Synchronous Static Memory Control Register */
+#define MEMCLKCFG      (0x68)  /* Clock Configuration */
+#define CSADRCFG0      (0x80)  /* Address Configuration Register for CS0 */
+#define CSADRCFG1      (0x84)  /* Address Configuration Register for CS1 */
+#define CSADRCFG2      (0x88)  /* Address Configuration Register for CS2 */
+#define CSADRCFG3      (0x8C)  /* Address Configuration Register for CS3 */
+
+#ifdef CONFIG_PM
+static void __iomem *smemc_mmio_base;
+
+static unsigned long msc[2];
+static unsigned long sxcnfg, memclkcfg;
+static unsigned long csadrcfg[4];
+
+static int pxa3xx_smemc_suspend(struct sys_device *dev, pm_message_t state)
+{
+       msc[0] = __raw_readl(smemc_mmio_base + MSC0);
+       msc[1] = __raw_readl(smemc_mmio_base + MSC1);
+       sxcnfg = __raw_readl(smemc_mmio_base + SXCNFG);
+       memclkcfg = __raw_readl(smemc_mmio_base + MEMCLKCFG);
+       csadrcfg[0] = __raw_readl(smemc_mmio_base + CSADRCFG0);
+       csadrcfg[1] = __raw_readl(smemc_mmio_base + CSADRCFG1);
+       csadrcfg[2] = __raw_readl(smemc_mmio_base + CSADRCFG2);
+       csadrcfg[3] = __raw_readl(smemc_mmio_base + CSADRCFG3);
+
+       return 0;
+}
+
+static int pxa3xx_smemc_resume(struct sys_device *dev)
+{
+       __raw_writel(msc[0], smemc_mmio_base + MSC0);
+       __raw_writel(msc[1], smemc_mmio_base + MSC1);
+       __raw_writel(sxcnfg, smemc_mmio_base + SXCNFG);
+       __raw_writel(memclkcfg, smemc_mmio_base + MEMCLKCFG);
+       __raw_writel(csadrcfg[0], smemc_mmio_base + CSADRCFG0);
+       __raw_writel(csadrcfg[1], smemc_mmio_base + CSADRCFG1);
+       __raw_writel(csadrcfg[2], smemc_mmio_base + CSADRCFG2);
+       __raw_writel(csadrcfg[3], smemc_mmio_base + CSADRCFG3);
+
+       return 0;
+}
+
+static struct sysdev_class smemc_sysclass = {
+       .name           = "smemc",
+       .suspend        = pxa3xx_smemc_suspend,
+       .resume         = pxa3xx_smemc_resume,
+};
+
+static struct sys_device smemc_sysdev = {
+       .id             = 0,
+       .cls            = &smemc_sysclass,
+};
+
+static int __init smemc_init(void)
+{
+       int ret = 0;
+
+       if (cpu_is_pxa3xx()) {
+               smemc_mmio_base = ioremap(SMEMC_PHYS_BASE, SMEMC_PHYS_SIZE);
+               if (smemc_mmio_base == NULL)
+                       return -ENODEV;
+
+               ret = sysdev_class_register(&smemc_sysclass);
+               if (ret)
+                       return ret;
+
+               ret = sysdev_register(&smemc_sysdev);
+       }
+
+       return ret;
+}
+subsys_initcall(smemc_init);
+#endif
index 5078edeadf9637ef0be1ca626e0043a0a3dcebc8..9e7773fca01cf391abbe3ccf79e841c8f9f0ab47 100644 (file)
@@ -36,6 +36,7 @@
 #include <asm/mach/irq.h>
 
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/irda.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/ohci.h>
index 1919756900f48daa9c12d64508a218a86f330f75..9b26fa5edad69200756d02384cdfcb941e8911d7 100644 (file)
@@ -29,6 +29,7 @@
 #include <asm/irq.h>
 #include <asm/system.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/irda.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/udc.h>
@@ -157,15 +158,10 @@ static void tosa_udc_command(int cmd)
        }
 }
 
-static int tosa_udc_is_connected(void)
-{
-       return ((GPLR(TOSA_GPIO_USB_IN) & GPIO_bit(TOSA_GPIO_USB_IN)) == 0);
-}
-
-
 static struct pxa2xx_udc_mach_info udc_info __initdata = {
        .udc_command            = tosa_udc_command,
-       .udc_is_connected       = tosa_udc_is_connected,
+       .gpio_vbus              = TOSA_GPIO_USB_IN,
+       .gpio_vbus_inverted     = 1,
 };
 
 /*
index 35156ca39df77e6a62414f30f879119e12b513df..39b3bb7f1020b35725ead58c7d5e051ce8ce0170 100644 (file)
@@ -7,24 +7,21 @@ config MACH_REALVIEW_EB
        help
          Include support for the ARM(R) RealView Emulation Baseboard platform.
 
-config REALVIEW_MPCORE
-       bool "Support MPcore tile"
+config REALVIEW_EB_ARM11MP
+       bool "Support ARM11MPCore tile"
        depends on MACH_REALVIEW_EB
        select CACHE_L2X0
        help
-         Enable support for the MPCore tile on the Realview platform.
-         Since there are device address and interrupt differences, a
-         kernel built with this option enabled is not compatible with
-         other tiles.
+         Enable support for the ARM11MPCore tile on the Realview platform.
 
-config REALVIEW_MPCORE_REVB
-       bool "Support MPcore RevB tile"
-       depends on REALVIEW_MPCORE
+config REALVIEW_EB_ARM11MP_REVB
+       bool "Support ARM11MPCore RevB tile"
+       depends on REALVIEW_EB_ARM11MP
        default n
        help
-         Enable support for the MPCore RevB tile on the Realview platform.
-         Since there are device address differences, a
+         Enable support for the ARM11MPCore RevB tile on the Realview
+         platform. Since there are device address differences, a
          kernel built with this option enabled is not compatible with
-         other tiles.
+         other revisions of the ARM11MPCore tile.
 
 endmenu
index 36e76ba937fc031286eeb4fa7acf46b13e37cd64..ca1e390c3c28795f3873bc8249e3eb3c74a8f078 100644 (file)
@@ -4,6 +4,5 @@
 
 obj-y                                  := core.o clock.o
 obj-$(CONFIG_MACH_REALVIEW_EB)         += realview_eb.o
-obj-$(CONFIG_SMP)                      += platsmp.o headsmp.o
+obj-$(CONFIG_SMP)                      += platsmp.o headsmp.o localtimer.o
 obj-$(CONFIG_HOTPLUG_CPU)              += hotplug.o
-obj-$(CONFIG_LOCAL_TIMERS)             += localtimer.o
index 61d70218f1e8adc60aee99d0e044700cb2fe6fd2..98aefc9f4df3bb3b81e6237b900a61d3930429fb 100644 (file)
@@ -25,6 +25,8 @@
 #include <linux/interrupt.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/clcd.h>
+#include <linux/clocksource.h>
+#include <linux/clockchips.h>
 
 #include <asm/system.h>
 #include <asm/hardware.h>
@@ -37,7 +39,6 @@
 #include <asm/mach/arch.h>
 #include <asm/mach/flash.h>
 #include <asm/mach/irq.h>
-#include <asm/mach/time.h>
 #include <asm/mach/map.h>
 #include <asm/mach/mmc.h>
 
@@ -48,6 +49,9 @@
 
 #define REALVIEW_REFCOUNTER    (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
 
+/* used by entry-macro.S */
+void __iomem *gic_cpu_base_addr;
+
 /*
  * This is the RealView sched_clock implementation.  This has
  * a resolution of 41.7ns, and a maximum value of about 179s.
@@ -121,26 +125,6 @@ struct platform_device realview_flash_device = {
        .resource               = &realview_flash_resource,
 };
 
-static struct resource realview_smc91x_resources[] = {
-       [0] = {
-               .start          = REALVIEW_ETH_BASE,
-               .end            = REALVIEW_ETH_BASE + SZ_64K - 1,
-               .flags          = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start          = IRQ_ETH,
-               .end            = IRQ_ETH,
-               .flags          = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device realview_smc91x_device = {
-       .name           = "smc91x",
-       .id             = 0,
-       .num_resources  = ARRAY_SIZE(realview_smc91x_resources),
-       .resource       = realview_smc91x_resources,
-};
-
 static struct resource realview_i2c_resource = {
        .start          = REALVIEW_I2C_BASE,
        .end            = REALVIEW_I2C_BASE + SZ_4K - 1,
@@ -484,45 +468,64 @@ void realview_leds_event(led_event_t ledevt)
 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
 #endif
 
-/*
- * Returns number of ms since last clock interrupt.  Note that interrupts
- * will have been disabled by do_gettimeoffset()
- */
-static unsigned long realview_gettimeoffset(void)
+static void timer_set_mode(enum clock_event_mode mode,
+                          struct clock_event_device *clk)
 {
-       unsigned long ticks1, ticks2, status;
+       unsigned long ctrl;
 
-       /*
-        * Get the current number of ticks.  Note that there is a race
-        * condition between us reading the timer and checking for
-        * an interrupt.  We get around this by ensuring that the
-        * counter has not reloaded between our two reads.
-        */
-       ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
-       do {
-               ticks1 = ticks2;
-               status = __raw_readl(__io_address(REALVIEW_GIC_DIST_BASE + GIC_DIST_PENDING_SET)
-                                    + ((IRQ_TIMERINT0_1 >> 5) << 2));
-               ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
-       } while (ticks2 > ticks1);
+       switch(mode) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
 
-       /*
-        * Number of ticks since last interrupt.
-        */
-       ticks1 = TIMER_RELOAD - ticks2;
+               ctrl = TIMER_CTRL_PERIODIC;
+               ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
+               break;
+       case CLOCK_EVT_MODE_ONESHOT:
+               /* period set, and timer enabled in 'next_event' hook */
+               ctrl = TIMER_CTRL_ONESHOT;
+               ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
+               break;
+       case CLOCK_EVT_MODE_UNUSED:
+       case CLOCK_EVT_MODE_SHUTDOWN:
+       default:
+               ctrl = 0;
+       }
 
-       /*
-        * Interrupt pending?  If so, we've reloaded once already.
-        *
-        * FIXME: Need to check this is effectively timer 0 that expires
-        */
-       if (status & IRQMASK_TIMERINT0_1)
-               ticks1 += TIMER_RELOAD;
+       writel(ctrl, TIMER0_VA_BASE + TIMER_CTRL);
+}
 
-       /*
-        * Convert the ticks to usecs
-        */
-       return TICKS2USECS(ticks1);
+static int timer_set_next_event(unsigned long evt,
+                               struct clock_event_device *unused)
+{
+       unsigned long ctrl = readl(TIMER0_VA_BASE + TIMER_CTRL);
+
+       writel(evt, TIMER0_VA_BASE + TIMER_LOAD);
+       writel(ctrl | TIMER_CTRL_ENABLE, TIMER0_VA_BASE + TIMER_CTRL);
+
+       return 0;
+}
+
+static struct clock_event_device timer0_clockevent =    {
+       .name           = "timer0",
+       .shift          = 32,
+       .features       = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
+       .set_mode       = timer_set_mode,
+       .set_next_event = timer_set_next_event,
+       .rating         = 300,
+       .cpumask        = CPU_MASK_ALL,
+};
+
+static void __init realview_clockevents_init(unsigned int timer_irq)
+{
+       timer0_clockevent.irq = timer_irq;
+       timer0_clockevent.mult =
+               div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
+       timer0_clockevent.max_delta_ns =
+               clockevent_delta2ns(0xffffffff, &timer0_clockevent);
+       timer0_clockevent.min_delta_ns =
+               clockevent_delta2ns(0xf, &timer0_clockevent);
+
+       clockevents_register_device(&timer0_clockevent);
 }
 
 /*
@@ -530,15 +533,12 @@ static unsigned long realview_gettimeoffset(void)
  */
 static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
 {
-       // ...clear the interrupt
+       struct clock_event_device *evt = &timer0_clockevent;
+
+       /* clear the interrupt */
        writel(1, TIMER0_VA_BASE + TIMER_INTCLR);
 
-       timer_tick();
-
-#if defined(CONFIG_SMP) && !defined(CONFIG_LOCAL_TIMERS)
-       smp_send_timer();
-       update_process_times(user_mode(get_irq_regs()));
-#endif
+       evt->event_handler(evt);
 
        return IRQ_HANDLED;
 }
@@ -549,13 +549,49 @@ static struct irqaction realview_timer_irq = {
        .handler        = realview_timer_interrupt,
 };
 
+static cycle_t realview_get_cycles(void)
+{
+       return ~readl(TIMER3_VA_BASE + TIMER_VALUE);
+}
+
+static struct clocksource clocksource_realview = {
+       .name   = "timer3",
+       .rating = 200,
+       .read   = realview_get_cycles,
+       .mask   = CLOCKSOURCE_MASK(32),
+       .shift  = 20,
+       .flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static void __init realview_clocksource_init(void)
+{
+       /* setup timer 0 as free-running clocksource */
+       writel(0, TIMER3_VA_BASE + TIMER_CTRL);
+       writel(0xffffffff, TIMER3_VA_BASE + TIMER_LOAD);
+       writel(0xffffffff, TIMER3_VA_BASE + TIMER_VALUE);
+       writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
+               TIMER3_VA_BASE + TIMER_CTRL);
+
+       clocksource_realview.mult =
+               clocksource_khz2mult(1000, clocksource_realview.shift);
+       clocksource_register(&clocksource_realview);
+}
+
 /*
- * Set up timer interrupt, and return the current time in seconds.
+ * Set up the clock source and clock events devices
  */
-static void __init realview_timer_init(void)
+void __init realview_timer_init(unsigned int timer_irq)
 {
        u32 val;
 
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+       /*
+        * The dummy clock device has to be registered before the main device
+        * so that the latter will broadcast the clock events
+        */
+       local_timer_setup(smp_processor_id());
+#endif
+
        /* 
         * set clock frequency: 
         *      REALVIEW_REFCLK is 32KHz
@@ -576,18 +612,11 @@ static void __init realview_timer_init(void)
        writel(0, TIMER2_VA_BASE + TIMER_CTRL);
        writel(0, TIMER3_VA_BASE + TIMER_CTRL);
 
-       writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
-       writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_VALUE);
-       writel(TIMER_DIVISOR | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC |
-              TIMER_CTRL_IE, TIMER0_VA_BASE + TIMER_CTRL);
-
        /* 
         * Make irqs happen for the system timer
         */
-       setup_irq(IRQ_TIMERINT0_1, &realview_timer_irq);
-}
+       setup_irq(timer_irq, &realview_timer_irq);
 
-struct sys_timer realview_timer = {
-       .init           = realview_timer_init,
-       .offset         = realview_gettimeoffset,
-};
+       realview_clocksource_init();
+       realview_clockevents_init(timer_irq);
+}
index 2b53420f9c1b41181c82e77120acd336bcdcd823..492a14c0d604baa39e8234f51e3b215aca41004e 100644 (file)
@@ -27,8 +27,6 @@
 #include <asm/leds.h>
 #include <asm/io.h>
 
-extern struct sys_timer realview_timer;
-
 #define AMBA_DEVICE(name,busid,base,plat)                      \
 static struct amba_device name##_device = {                    \
        .dev            = {                                     \
@@ -38,7 +36,7 @@ static struct amba_device name##_device = {                   \
        },                                                      \
        .res            = {                                     \
                .start  = REALVIEW_##base##_BASE,               \
-               .end    = (REALVIEW_##base##_BASE) + SZ_4K - 1,\
+               .end    = (REALVIEW_##base##_BASE) + SZ_4K - 1, \
                .flags  = IORESOURCE_MEM,                       \
        },                                                      \
        .dma_mask       = ~0,                                   \
@@ -46,74 +44,19 @@ static struct amba_device name##_device = {                 \
        /* .dma         = base##_DMA,*/                         \
 }
 
-/*
- * These devices are connected via the core APB bridge
- */
-#define GPIO2_IRQ      { IRQ_GPIOINT2, NO_IRQ }
-#define GPIO2_DMA      { 0, 0 }
-#define GPIO3_IRQ      { IRQ_GPIOINT3, NO_IRQ }
-#define GPIO3_DMA      { 0, 0 }
-
-#define AACI_IRQ       { IRQ_AACI, NO_IRQ }
-#define AACI_DMA       { 0x80, 0x81 }
-#define MMCI0_IRQ      { IRQ_MMCI0A,IRQ_MMCI0B }
-#define MMCI0_DMA      { 0x84, 0 }
-#define KMI0_IRQ       { IRQ_KMI0, NO_IRQ }
-#define KMI0_DMA       { 0, 0 }
-#define KMI1_IRQ       { IRQ_KMI1, NO_IRQ }
-#define KMI1_DMA       { 0, 0 }
-
-/*
- * These devices are connected directly to the multi-layer AHB switch
- */
-#define SMC_IRQ                { NO_IRQ, NO_IRQ }
-#define SMC_DMA                { 0, 0 }
-#define MPMC_IRQ       { NO_IRQ, NO_IRQ }
-#define MPMC_DMA       { 0, 0 }
-#define CLCD_IRQ       { IRQ_CLCDINT, NO_IRQ }
-#define CLCD_DMA       { 0, 0 }
-#define DMAC_IRQ       { IRQ_DMAINT, NO_IRQ }
-#define DMAC_DMA       { 0, 0 }
-
-/*
- * These devices are connected via the core APB bridge
- */
-#define SCTL_IRQ       { NO_IRQ, NO_IRQ }
-#define SCTL_DMA       { 0, 0 }
-#define WATCHDOG_IRQ   { IRQ_WDOGINT, NO_IRQ }
-#define WATCHDOG_DMA   { 0, 0 }
-#define GPIO0_IRQ      { IRQ_GPIOINT0, NO_IRQ }
-#define GPIO0_DMA      { 0, 0 }
-#define GPIO1_IRQ      { IRQ_GPIOINT1, NO_IRQ }
-#define GPIO1_DMA      { 0, 0 }
-#define RTC_IRQ                { IRQ_RTCINT, NO_IRQ }
-#define RTC_DMA                { 0, 0 }
-
-/*
- * These devices are connected via the DMA APB bridge
- */
-#define SCI_IRQ                { IRQ_SCIINT, NO_IRQ }
-#define SCI_DMA                { 7, 6 }
-#define UART0_IRQ      { IRQ_UARTINT0, NO_IRQ }
-#define UART0_DMA      { 15, 14 }
-#define UART1_IRQ      { IRQ_UARTINT1, NO_IRQ }
-#define UART1_DMA      { 13, 12 }
-#define UART2_IRQ      { IRQ_UARTINT2, NO_IRQ }
-#define UART2_DMA      { 11, 10 }
-#define UART3_IRQ      { IRQ_UART3, NO_IRQ }
-#define UART3_DMA      { 0x86, 0x87 }
-#define SSP_IRQ                { IRQ_SSPINT, NO_IRQ }
-#define SSP_DMA                { 9, 8 }
-
-
 extern struct platform_device realview_flash_device;
-extern struct platform_device realview_smc91x_device;
 extern struct platform_device realview_i2c_device;
 extern struct mmc_platform_data realview_mmc0_plat_data;
 extern struct mmc_platform_data realview_mmc1_plat_data;
 extern struct clk realview_clcd_clk;
 extern struct clcd_board clcd_plat_data;
+extern void __iomem *gic_cpu_base_addr;
+#ifdef CONFIG_LOCAL_TIMERS
+extern void __iomem *twd_base_addr;
+extern unsigned int twd_size;
+#endif
 
 extern void realview_leds_event(led_event_t ledevt);
+extern void realview_timer_init(unsigned int timer_irq);
 
 #endif
index c7bdf04ab094d1f82f2afbb52c204154cf0dfef4..50604360479fa9d3d8ecace270aba49f8f8454e2 100644 (file)
 #include <linux/device.h>
 #include <linux/smp.h>
 #include <linux/jiffies.h>
+#include <linux/percpu.h>
+#include <linux/clockchips.h>
+#include <linux/irq.h>
 
-#include <asm/mach/time.h>
 #include <asm/hardware/arm_twd.h>
 #include <asm/hardware/gic.h>
 #include <asm/hardware.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 
-#define TWD_BASE(cpu)  (__io_address(REALVIEW_TWD_BASE) + \
-                        ((cpu) * REALVIEW_TWD_SIZE))
+static DEFINE_PER_CPU(struct clock_event_device, local_clockevent);
+
+/*
+ * Used on SMP for either the local timer or IPI_TIMER
+ */
+void local_timer_interrupt(void)
+{
+       struct clock_event_device *clk = &__get_cpu_var(local_clockevent);
+
+       clk->event_handler(clk);
+}
+
+#ifdef CONFIG_LOCAL_TIMERS
+
+#define TWD_BASE(cpu)  (twd_base_addr + (cpu) * twd_size)
+
+/* set up by the platform code */
+void __iomem *twd_base_addr;
+unsigned int twd_size;
 
 static unsigned long mpcore_timer_rate;
 
+static void local_timer_set_mode(enum clock_event_mode mode,
+                                struct clock_event_device *clk)
+{
+       void __iomem *base = TWD_BASE(smp_processor_id());
+       unsigned long ctrl;
+
+       switch(mode) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               /* timer load already set up */
+               ctrl = TWD_TIMER_CONTROL_ENABLE | TWD_TIMER_CONTROL_IT_ENABLE
+                       | TWD_TIMER_CONTROL_PERIODIC;
+               break;
+       case CLOCK_EVT_MODE_ONESHOT:
+               /* period set, and timer enabled in 'next_event' hook */
+               ctrl = TWD_TIMER_CONTROL_IT_ENABLE | TWD_TIMER_CONTROL_ONESHOT;
+               break;
+       case CLOCK_EVT_MODE_UNUSED:
+       case CLOCK_EVT_MODE_SHUTDOWN:
+       default:
+               ctrl = 0;
+       }
+
+       __raw_writel(ctrl, base + TWD_TIMER_CONTROL);
+}
+
+static int local_timer_set_next_event(unsigned long evt,
+                                     struct clock_event_device *unused)
+{
+       void __iomem *base = TWD_BASE(smp_processor_id());
+       unsigned long ctrl = __raw_readl(base + TWD_TIMER_CONTROL);
+
+       __raw_writel(evt, base + TWD_TIMER_COUNTER);
+       __raw_writel(ctrl | TWD_TIMER_CONTROL_ENABLE, base + TWD_TIMER_CONTROL);
+
+       return 0;
+}
+
 /*
  * local_timer_ack: checks for a local timer interrupt.
  *
@@ -45,12 +101,11 @@ int local_timer_ack(void)
        return 0;
 }
 
-void __cpuinit local_timer_setup(unsigned int cpu)
+static void __cpuinit twd_calibrate_rate(unsigned int cpu)
 {
        void __iomem *base = TWD_BASE(cpu);
-       unsigned int load, offset;
+       unsigned long load, count;
        u64 waitjiffies;
-       unsigned int count;
 
        /*
         * If this is the first time round, we need to work out how fast
@@ -88,36 +143,36 @@ void __cpuinit local_timer_setup(unsigned int cpu)
        load = mpcore_timer_rate / HZ;
 
        __raw_writel(load, base + TWD_TIMER_LOAD);
-       __raw_writel(0x7,  base + TWD_TIMER_CONTROL);
-
-       /*
-        * Now maneuver our local tick into the right part of the jiffy.
-        * Start by working out where within the tick our local timer
-        * interrupt should go.
-        */
-       offset = ((mpcore_timer_rate / HZ) / (NR_CPUS + 1)) * (cpu + 1);
-
-       /*
-        * gettimeoffset() will return a number of us since the last tick.
-        * Convert this number of us to a local timer tick count.
-        * Be careful of integer overflow whilst keeping maximum precision.
-        *
-        * with HZ=100 and 1MHz (fpga) ~ 1GHz processor:
-        * load = 1 ~ 10,000
-        * mpcore_timer_rate/10000 = 100 ~ 100,000
-        *
-        * so the multiply value will be less than 10^9 always.
-        */
-       load = (system_timer->offset() * (mpcore_timer_rate / 10000)) / 100;
-
-       /* Add on our offset to get the load value */
-       load = (load + offset) % (mpcore_timer_rate / HZ);
+}
 
-       __raw_writel(load, base + TWD_TIMER_COUNTER);
+/*
+ * Setup the local clock events for a CPU.
+ */
+void __cpuinit local_timer_setup(unsigned int cpu)
+{
+       struct clock_event_device *clk = &per_cpu(local_clockevent, cpu);
+       unsigned long flags;
+
+       twd_calibrate_rate(cpu);
+
+       clk->name               = "local_timer";
+       clk->features           = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
+       clk->rating             = 350;
+       clk->set_mode           = local_timer_set_mode;
+       clk->set_next_event     = local_timer_set_next_event;
+       clk->irq                = IRQ_LOCALTIMER;
+       clk->cpumask            = cpumask_of_cpu(cpu);
+       clk->shift              = 20;
+       clk->mult               = div_sc(mpcore_timer_rate, NSEC_PER_SEC, clk->shift);
+       clk->max_delta_ns       = clockevent_delta2ns(0xffffffff, clk);
+       clk->min_delta_ns       = clockevent_delta2ns(0xf, clk);
 
        /* Make sure our local interrupt controller has this enabled */
-       __raw_writel(1 << IRQ_LOCALTIMER,
-                    __io_address(REALVIEW_GIC_DIST_BASE) + GIC_DIST_ENABLE_SET);
+       local_irq_save(flags);
+       get_irq_chip(IRQ_LOCALTIMER)->unmask(IRQ_LOCALTIMER);
+       local_irq_restore(flags);
+
+       clockevents_register_device(clk);
 }
 
 /*
@@ -127,3 +182,26 @@ void __cpuexit local_timer_stop(unsigned int cpu)
 {
        __raw_writel(0, TWD_BASE(cpu) + TWD_TIMER_CONTROL);
 }
+
+#else  /* CONFIG_LOCAL_TIMERS */
+
+static void dummy_timer_set_mode(enum clock_event_mode mode,
+                                struct clock_event_device *clk)
+{
+}
+
+void __cpuinit local_timer_setup(unsigned int cpu)
+{
+       struct clock_event_device *clk = &per_cpu(local_clockevent, cpu);
+
+       clk->name               = "dummy_timer";
+       clk->features           = CLOCK_EVT_FEAT_DUMMY;
+       clk->rating             = 200;
+       clk->set_mode           = dummy_timer_set_mode;
+       clk->broadcast          = smp_timer_broadcast;
+       clk->cpumask            = cpumask_of_cpu(cpu);
+
+       clockevents_register_device(clk);
+}
+
+#endif /* !CONFIG_LOCAL_TIMERS */
index fce3596f9950a6aea5d8489d9d674a99759ad7b0..de2b7159557dd56c56eb5f673124cc263f0bfa6d 100644 (file)
@@ -18,6 +18,7 @@
 #include <asm/hardware/arm_scu.h>
 #include <asm/hardware.h>
 #include <asm/io.h>
+#include <asm/mach-types.h>
 
 extern void realview_secondary_startup(void);
 
@@ -31,9 +32,13 @@ static unsigned int __init get_core_count(void)
 {
        unsigned int ncores;
 
-       ncores = __raw_readl(__io_address(REALVIEW_MPCORE_SCU_BASE) + SCU_CONFIG);
+       if (machine_is_realview_eb() && core_tile_eb11mp()) {
+               ncores = __raw_readl(__io_address(REALVIEW_EB11MP_SCU_BASE) + SCU_CONFIG);
+               ncores = (ncores & 0x03) + 1;
+       } else
+               ncores = 1;
 
-       return (ncores & 0x03) + 1;
+       return ncores;
 }
 
 static DEFINE_SPINLOCK(boot_lock);
@@ -52,7 +57,7 @@ void __cpuinit platform_secondary_init(unsigned int cpu)
         * core (e.g. timer irq), then they will not have been enabled
         * for us: do so
         */
-       gic_cpu_init(0, __io_address(REALVIEW_GIC_CPU_BASE));
+       gic_cpu_init(0, __io_address(REALVIEW_EB11MP_GIC_CPU_BASE));
 
        /*
         * let the primary processor know we're out of the
@@ -187,10 +192,15 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
        if (max_cpus > ncores)
                max_cpus = ncores;
 
+#ifdef CONFIG_LOCAL_TIMERS
        /*
-        * Enable the local timer for primary CPU
+        * Enable the local timer for primary CPU. If the device is
+        * dummy (!CONFIG_LOCAL_TIMERS), it was already registers in
+        * realview_timer_init
         */
-       local_timer_setup(cpu);
+       if (machine_is_realview_eb() && core_tile_eb11mp())
+               local_timer_setup(cpu);
+#endif
 
        /*
         * Initialise the present map, which describes the set of CPUs
index ecec2f85c4cd12624f178e5ee46af887cc93d0c0..60d9eb810246f23957597695566de56af573750e 100644 (file)
@@ -36,7 +36,9 @@
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 #include <asm/mach/mmc.h>
+#include <asm/mach/time.h>
 
+#include <asm/arch/board-eb.h>
 #include <asm/arch/irqs.h>
 
 #include "core.h"
@@ -58,26 +60,7 @@ static struct map_desc realview_eb_io_desc[] __initdata = {
                .pfn            = __phys_to_pfn(REALVIEW_GIC_DIST_BASE),
                .length         = SZ_4K,
                .type           = MT_DEVICE,
-       },
-#ifdef CONFIG_REALVIEW_MPCORE
-       {
-               .virtual        = IO_ADDRESS(REALVIEW_GIC1_CPU_BASE),
-               .pfn            = __phys_to_pfn(REALVIEW_GIC1_CPU_BASE),
-               .length         = SZ_4K,
-               .type           = MT_DEVICE,
        }, {
-               .virtual        = IO_ADDRESS(REALVIEW_GIC1_DIST_BASE),
-               .pfn            = __phys_to_pfn(REALVIEW_GIC1_DIST_BASE),
-               .length         = SZ_4K,
-               .type           = MT_DEVICE,
-       }, {
-               .virtual        = IO_ADDRESS(REALVIEW_MPCORE_L220_BASE),
-               .pfn            = __phys_to_pfn(REALVIEW_MPCORE_L220_BASE),
-               .length         = SZ_8K,
-               .type           = MT_DEVICE,
-       },
-#endif
-       {
                .virtual        = IO_ADDRESS(REALVIEW_SCTL_BASE),
                .pfn            = __phys_to_pfn(REALVIEW_SCTL_BASE),
                .length         = SZ_4K,
@@ -103,11 +86,95 @@ static struct map_desc realview_eb_io_desc[] __initdata = {
 #endif
 };
 
+static struct map_desc realview_eb11mp_io_desc[] __initdata = {
+       {
+               .virtual        = IO_ADDRESS(REALVIEW_EB11MP_GIC_CPU_BASE),
+               .pfn            = __phys_to_pfn(REALVIEW_EB11MP_GIC_CPU_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = IO_ADDRESS(REALVIEW_EB11MP_GIC_DIST_BASE),
+               .pfn            = __phys_to_pfn(REALVIEW_EB11MP_GIC_DIST_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = IO_ADDRESS(REALVIEW_EB11MP_L220_BASE),
+               .pfn            = __phys_to_pfn(REALVIEW_EB11MP_L220_BASE),
+               .length         = SZ_8K,
+               .type           = MT_DEVICE,
+       }
+};
+
 static void __init realview_eb_map_io(void)
 {
        iotable_init(realview_eb_io_desc, ARRAY_SIZE(realview_eb_io_desc));
+       if (core_tile_eb11mp())
+               iotable_init(realview_eb11mp_io_desc, ARRAY_SIZE(realview_eb11mp_io_desc));
 }
 
+/*
+ * RealView EB AMBA devices
+ */
+
+/*
+ * These devices are connected via the core APB bridge
+ */
+#define GPIO2_IRQ      { IRQ_EB_GPIO2, NO_IRQ }
+#define GPIO2_DMA      { 0, 0 }
+#define GPIO3_IRQ      { IRQ_EB_GPIO3, NO_IRQ }
+#define GPIO3_DMA      { 0, 0 }
+
+#define AACI_IRQ       { IRQ_EB_AACI, NO_IRQ }
+#define AACI_DMA       { 0x80, 0x81 }
+#define MMCI0_IRQ      { IRQ_EB_MMCI0A, IRQ_EB_MMCI0B }
+#define MMCI0_DMA      { 0x84, 0 }
+#define KMI0_IRQ       { IRQ_EB_KMI0, NO_IRQ }
+#define KMI0_DMA       { 0, 0 }
+#define KMI1_IRQ       { IRQ_EB_KMI1, NO_IRQ }
+#define KMI1_DMA       { 0, 0 }
+
+/*
+ * These devices are connected directly to the multi-layer AHB switch
+ */
+#define SMC_IRQ                { NO_IRQ, NO_IRQ }
+#define SMC_DMA                { 0, 0 }
+#define MPMC_IRQ       { NO_IRQ, NO_IRQ }
+#define MPMC_DMA       { 0, 0 }
+#define CLCD_IRQ       { IRQ_EB_CLCD, NO_IRQ }
+#define CLCD_DMA       { 0, 0 }
+#define DMAC_IRQ       { IRQ_EB_DMA, NO_IRQ }
+#define DMAC_DMA       { 0, 0 }
+
+/*
+ * These devices are connected via the core APB bridge
+ */
+#define SCTL_IRQ       { NO_IRQ, NO_IRQ }
+#define SCTL_DMA       { 0, 0 }
+#define WATCHDOG_IRQ   { IRQ_EB_WDOG, NO_IRQ }
+#define WATCHDOG_DMA   { 0, 0 }
+#define GPIO0_IRQ      { IRQ_EB_GPIO0, NO_IRQ }
+#define GPIO0_DMA      { 0, 0 }
+#define GPIO1_IRQ      { IRQ_EB_GPIO1, NO_IRQ }
+#define GPIO1_DMA      { 0, 0 }
+#define RTC_IRQ                { IRQ_EB_RTC, NO_IRQ }
+#define RTC_DMA                { 0, 0 }
+
+/*
+ * These devices are connected via the DMA APB bridge
+ */
+#define SCI_IRQ                { IRQ_EB_SCI, NO_IRQ }
+#define SCI_DMA                { 7, 6 }
+#define UART0_IRQ      { IRQ_EB_UART0, NO_IRQ }
+#define UART0_DMA      { 15, 14 }
+#define UART1_IRQ      { IRQ_EB_UART1, NO_IRQ }
+#define UART1_DMA      { 13, 12 }
+#define UART2_IRQ      { IRQ_EB_UART2, NO_IRQ }
+#define UART2_DMA      { 11, 10 }
+#define UART3_IRQ      { IRQ_EB_UART3, NO_IRQ }
+#define UART3_DMA      { 0x86, 0x87 }
+#define SSP_IRQ                { IRQ_EB_SSP, NO_IRQ }
+#define SSP_DMA                { 9, 8 }
+
 /* FPGA Primecells */
 AMBA_DEVICE(aaci,  "fpga:04", AACI,     NULL);
 AMBA_DEVICE(mmc0,  "fpga:05", MMCI0,    &realview_mmc0_plat_data);
@@ -153,38 +220,127 @@ static struct amba_device *amba_devs[] __initdata = {
        &kmi1_device,
 };
 
+/*
+ * RealView EB platform devices
+ */
+
+static struct resource realview_eb_smc91x_resources[] = {
+       [0] = {
+               .start          = REALVIEW_ETH_BASE,
+               .end            = REALVIEW_ETH_BASE + SZ_64K - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start          = IRQ_EB_ETH,
+               .end            = IRQ_EB_ETH,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device realview_eb_smc91x_device = {
+       .name           = "smc91x",
+       .id             = 0,
+       .num_resources  = ARRAY_SIZE(realview_eb_smc91x_resources),
+       .resource       = realview_eb_smc91x_resources,
+};
+
 static void __init gic_init_irq(void)
 {
-#ifdef CONFIG_REALVIEW_MPCORE
-       unsigned int pldctrl;
-       writel(0x0000a05f, __io_address(REALVIEW_SYS_LOCK));
-       pldctrl = readl(__io_address(REALVIEW_SYS_BASE) + REALVIEW_MPCORE_SYS_PLD_CTRL1);
-       pldctrl |= 0x00800000;  /* New irq mode */
-       writel(pldctrl, __io_address(REALVIEW_SYS_BASE) + REALVIEW_MPCORE_SYS_PLD_CTRL1);
-       writel(0x00000000, __io_address(REALVIEW_SYS_LOCK));
+       if (core_tile_eb11mp()) {
+               unsigned int pldctrl;
+
+               /* new irq mode */
+               writel(0x0000a05f, __io_address(REALVIEW_SYS_LOCK));
+               pldctrl = readl(__io_address(REALVIEW_SYS_BASE) + REALVIEW_EB11MP_SYS_PLD_CTRL1);
+               pldctrl |= 0x00800000;
+               writel(pldctrl, __io_address(REALVIEW_SYS_BASE) + REALVIEW_EB11MP_SYS_PLD_CTRL1);
+               writel(0x00000000, __io_address(REALVIEW_SYS_LOCK));
+
+               /* core tile GIC, primary */
+               gic_cpu_base_addr = __io_address(REALVIEW_EB11MP_GIC_CPU_BASE);
+               gic_dist_init(0, __io_address(REALVIEW_EB11MP_GIC_DIST_BASE), 29);
+               gic_cpu_init(0, gic_cpu_base_addr);
+
+#ifndef CONFIG_REALVIEW_EB_ARM11MP_REVB
+               /* board GIC, secondary */
+               gic_dist_init(1, __io_address(REALVIEW_GIC_DIST_BASE), 64);
+               gic_cpu_init(1, __io_address(REALVIEW_GIC_CPU_BASE));
+               gic_cascade_irq(1, IRQ_EB11MP_EB_IRQ1);
 #endif
-       gic_dist_init(0, __io_address(REALVIEW_GIC_DIST_BASE), 29);
-       gic_cpu_init(0, __io_address(REALVIEW_GIC_CPU_BASE));
-#if defined(CONFIG_REALVIEW_MPCORE) && !defined(CONFIG_REALVIEW_MPCORE_REVB)
-       gic_dist_init(1, __io_address(REALVIEW_GIC1_DIST_BASE), 64);
-       gic_cpu_init(1, __io_address(REALVIEW_GIC1_CPU_BASE));
-       gic_cascade_irq(1, IRQ_EB_IRQ1);
+       } else {
+               /* board GIC, primary */
+               gic_cpu_base_addr = __io_address(REALVIEW_GIC_CPU_BASE);
+               gic_dist_init(0, __io_address(REALVIEW_GIC_DIST_BASE), 29);
+               gic_cpu_init(0, gic_cpu_base_addr);
+       }
+}
+
+/*
+ * Fix up the IRQ numbers for the RealView EB/ARM11MPCore tile
+ */
+static void realview_eb11mp_fixup(void)
+{
+       /* AMBA devices */
+       dmac_device.irq[0]      = IRQ_EB11MP_DMA;
+       uart0_device.irq[0]     = IRQ_EB11MP_UART0;
+       uart1_device.irq[0]     = IRQ_EB11MP_UART1;
+       uart2_device.irq[0]     = IRQ_EB11MP_UART2;
+       uart3_device.irq[0]     = IRQ_EB11MP_UART3;
+       clcd_device.irq[0]      = IRQ_EB11MP_CLCD;
+       wdog_device.irq[0]      = IRQ_EB11MP_WDOG;
+       gpio0_device.irq[0]     = IRQ_EB11MP_GPIO0;
+       gpio1_device.irq[0]     = IRQ_EB11MP_GPIO1;
+       gpio2_device.irq[0]     = IRQ_EB11MP_GPIO2;
+       rtc_device.irq[0]       = IRQ_EB11MP_RTC;
+       sci0_device.irq[0]      = IRQ_EB11MP_SCI;
+       ssp0_device.irq[0]      = IRQ_EB11MP_SSP;
+       aaci_device.irq[0]      = IRQ_EB11MP_AACI;
+       mmc0_device.irq[0]      = IRQ_EB11MP_MMCI0A;
+       mmc0_device.irq[1]      = IRQ_EB11MP_MMCI0B;
+       kmi0_device.irq[0]      = IRQ_EB11MP_KMI0;
+       kmi1_device.irq[0]      = IRQ_EB11MP_KMI1;
+
+       /* platform devices */
+       realview_eb_smc91x_resources[1].start   = IRQ_EB11MP_ETH;
+       realview_eb_smc91x_resources[1].end     = IRQ_EB11MP_ETH;
+}
+
+static void __init realview_eb_timer_init(void)
+{
+       unsigned int timer_irq;
+
+       if (core_tile_eb11mp()) {
+#ifdef CONFIG_LOCAL_TIMERS
+               twd_base_addr = __io_address(REALVIEW_EB11MP_TWD_BASE);
+               twd_size = REALVIEW_EB11MP_TWD_SIZE;
 #endif
+               timer_irq = IRQ_EB11MP_TIMER0_1;
+       } else
+               timer_irq = IRQ_EB_TIMER0_1;
+
+       realview_timer_init(timer_irq);
 }
 
+static struct sys_timer realview_eb_timer = {
+       .init           = realview_eb_timer_init,
+};
+
 static void __init realview_eb_init(void)
 {
        int i;
 
-#ifdef CONFIG_REALVIEW_MPCORE
-       /* 1MB (128KB/way), 8-way associativity, evmon/parity/share enabled
-        * Bits:  .... ...0 0111 1001 0000 .... .... .... */
-       l2x0_init(__io_address(REALVIEW_MPCORE_L220_BASE), 0x00790000, 0xfe000fff);
-#endif
+       if (core_tile_eb11mp()) {
+               realview_eb11mp_fixup();
+
+               /* 1MB (128KB/way), 8-way associativity, evmon/parity/share enabled
+                * Bits:  .... ...0 0111 1001 0000 .... .... .... */
+               l2x0_init(__io_address(REALVIEW_EB11MP_L220_BASE), 0x00790000, 0xfe000fff);
+       }
+
        clk_register(&realview_clcd_clk);
 
        platform_device_register(&realview_flash_device);
-       platform_device_register(&realview_smc91x_device);
+       platform_device_register(&realview_eb_smc91x_device);
        platform_device_register(&realview_i2c_device);
 
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
@@ -204,6 +360,6 @@ MACHINE_START(REALVIEW_EB, "ARM-RealView EB")
        .boot_params    = 0x00000100,
        .map_io         = realview_eb_map_io,
        .init_irq       = gic_init_irq,
-       .timer          = &realview_timer,
+       .timer          = &realview_eb_timer,
        .init_machine   = realview_eb_init,
 MACHINE_END
index a454451c97c36ea77ee9abb2a74e6b9f99ff0f6e..eca558c6bf5d1d121b18e89e68279c3f99c0706b 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/serial_8250.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 
 #include <asm/elf.h>
 #include <asm/io.h>
index 1e25b1d19fce7e7f537269a5df27a27584be8b3d..94620be7bfac15ba366c90bca5bac761b98146ed 100644 (file)
@@ -165,7 +165,7 @@ int collie_read_temp(void)
 
        ucb1x00_adc_enable(ucb);
        ucb1x00_io_write(ucb, COLLIE_TC35143_GPIO_TMP_ON, 0);
-       /* >1010 = battery removed, 460 = 22C ?, higer = lower temp ? */
+       /* >1010 = battery removed, 460 = 22C ?, higher = lower temp ? */
        voltage = ucb1x00_adc_read(ucb, UCB_ADC_INP_AD0, UCB_SYNC);
        ucb1x00_io_write(ucb, 0, COLLIE_TC35143_GPIO_TMP_ON);
        ucb1x00_adc_disable(ucb);
index 9e13c8358ea7c0cc4a111f2a86977f9dd19109ea..5c84c604ed86d1fc5b68c89ab802d1713aa2311d 100644 (file)
@@ -470,7 +470,7 @@ void __init sa1110_mb_disable(void)
  * If the system is going to use the SA-1111 DMA engines, set up
  * the memory bus request/grant pins.
  */
-void __init sa1110_mb_enable(void)
+void __devinit sa1110_mb_enable(void)
 {
        unsigned long flags;
 
index 75952779ce1991f68114dcbeef6a188c4c47d027..303a7ff6bfd2eeb3120164d9cc185e0973d600de 100644 (file)
@@ -162,7 +162,7 @@ static void unmap_area_sections(unsigned long virt, unsigned long size)
                         * Free the page table, if there was one.
                         */
                        if ((pmd_val(pmd) & PMD_TYPE_MASK) == PMD_TYPE_TABLE)
-                               pte_free_kernel(pmd_page_vaddr(pmd));
+                               pte_free_kernel(&init_mm, pmd_page_vaddr(pmd));
                }
 
                addr += PGDIR_SIZE;
index 50b9aed6000d8ede02f5df0175df8c8aa7e85c65..500c9610ab3085094ec48d012610b4f557136ec1 100644 (file)
@@ -65,14 +65,14 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
        return new_pgd;
 
 no_pte:
-       pmd_free(new_pmd);
+       pmd_free(mm, new_pmd);
 no_pmd:
        free_pages((unsigned long)new_pgd, 2);
 no_pgd:
        return NULL;
 }
 
-void free_pgd_slow(pgd_t *pgd)
+void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd)
 {
        pmd_t *pmd;
        struct page *pte;
@@ -94,8 +94,8 @@ void free_pgd_slow(pgd_t *pgd)
        pmd_clear(pmd);
        dec_zone_page_state(virt_to_page((unsigned long *)pgd), NR_PAGETABLE);
        pte_lock_deinit(pte);
-       pte_free(pte);
-       pmd_free(pmd);
+       pte_free(mm, pte);
+       pmd_free(mm, pmd);
 free:
        free_pages((unsigned long) pgd, 2);
 }
index ba3d21d8fba34c4c458a2d80b660e258ca06a2b3..6fe481ff4fdfe5230093846292a3725c98fb57e5 100644 (file)
@@ -57,8 +57,6 @@ unsigned long iop_gettimeoffset(void)
 static irqreturn_t
 iop_timer_interrupt(int irq, void *dev_id)
 {
-       write_seqlock(&xtime_lock);
-
        write_tisr(1);
 
        while ((signed long)(next_jiffy_time - read_tcr1())
@@ -67,8 +65,6 @@ iop_timer_interrupt(int irq, void *dev_id)
                next_jiffy_time -= ticks_per_jiffy;
        }
 
-       write_sequnlock(&xtime_lock);
-
        return IRQ_HANDLED;
 }
 
index d486f5112569bcd66721b892b128f49ddf016126..ae2c5d7efc9dc411cc1488840bee40d8b648a456 100644 (file)
@@ -47,7 +47,7 @@
  *               Mark IRQ_LCD valid
  *
  *   25-Jul-2005  Ben Dooks
- *               Split the S3C2440 IRQ code to seperate file
+ *               Split the S3C2440 IRQ code to separate file
 */
 
 #include <linux/init.h>
index 2ec1daaa0e537a6aed01f4aa62f5d7551ad3e8b8..766473b3f98b6bf2d8b4ae61af4254949d9431fb 100644 (file)
@@ -130,9 +130,7 @@ static unsigned long s3c2410_gettimeoffset (void)
 static irqreturn_t
 s3c2410_timer_interrupt(int irq, void *dev_id)
 {
-       write_seqlock(&xtime_lock);
        timer_tick();
-       write_sequnlock(&xtime_lock);
        return IRQ_HANDLED;
 }
 
index e34e2c9c94cb5b678eeae91929682ab081c7e661..28e0caf4156ca68bb066d8300fd1947264e28037 100644 (file)
@@ -10,6 +10,8 @@ config AVR32
        # With EMBEDDED=n, we get lots of stuff automatically selected
        # that we usually don't need on AVR32.
        select EMBEDDED
+       select HAVE_OPROFILE
+       select HAVE_KPROBES
        help
          AVR32 is a high-performance 32-bit RISC microprocessor core,
          designed for cost-sensitive embedded applications, with particular
@@ -54,9 +56,6 @@ config ARCH_HAS_ILOG2_U32
 config ARCH_HAS_ILOG2_U64
        def_bool n
 
-config ARCH_SUPPORTS_OPROFILE
-       def_bool y
-
 config GENERIC_HWEIGHT
        def_bool y
 
@@ -83,6 +82,7 @@ config PLATFORM_AT32AP
        select SUBARCH_AVR32B
        select MMU
        select PERFORMANCE_COUNTERS
+       select HAVE_GPIO_LIB
 
 #
 # CPU types
@@ -236,8 +236,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/avr32/Kconfig.debug"
 
 source "security/Kconfig"
index 75c81f2dd0b3a623fb19722dc961bd99e788ccc3..478bda4c4a09a9ac57f119b4c8529d970cbc48e2 100644 (file)
@@ -293,6 +293,6 @@ sys_call_table:
        .long   sys_shmctl
        .long   sys_utimensat
        .long   sys_signalfd
-       .long   sys_timerfd             /* 280 */
+       .long   sys_ni_syscall          /* 280, was sys_timerfd */
        .long   sys_eventfd
        .long   sys_ni_syscall          /* r8 is saturated at nr_syscalls */
index b3bc0b56e2c6506849de3ba758aae262f552f477..9aa8800830f396b8ef4fb79a4186b1f9b95dc60a 100644 (file)
 
 #include <linux/delay.h>
 #include <linux/module.h>
+#include <linux/timex.h>
 #include <linux/param.h>
 #include <linux/types.h>
+#include <linux/init.h>
 
 #include <asm/processor.h>
 #include <asm/sysreg.h>
 
-int read_current_timer(unsigned long *timer_value)
+int __devinit read_current_timer(unsigned long *timer_value)
 {
        *timer_value = sysreg_read(COUNT);
        return 0;
index d61a02da898cd68bd08316474ee2c2762dfd8036..38a8fa31c0b5c8de591ae8f39a08c2e90d2a862b 100644 (file)
 #define MAX_NR_PIO_DEVICES             8
 
 struct pio_device {
+       struct gpio_chip chip;
        void __iomem *regs;
        const struct platform_device *pdev;
        struct clk *clk;
        u32 pinmux_mask;
-       u32 gpio_mask;
        char name[8];
 };
 
@@ -64,7 +64,8 @@ void __init at32_select_periph(unsigned int pin, unsigned int periph,
                goto fail;
        }
 
-       if (unlikely(test_and_set_bit(pin_index, &pio->pinmux_mask))) {
+       if (unlikely(test_and_set_bit(pin_index, &pio->pinmux_mask)
+                        || gpiochip_is_requested(&pio->chip, pin_index))) {
                printk("%s: pin %u is busy\n", pio->name, pin_index);
                goto fail;
        }
@@ -79,9 +80,6 @@ void __init at32_select_periph(unsigned int pin, unsigned int periph,
        if (!(flags & AT32_GPIOF_PULLUP))
                pio_writel(pio, PUDR, mask);
 
-       /* gpio_request NOT allowed */
-       set_bit(pin_index, &pio->gpio_mask);
-
        return;
 
 fail:
@@ -130,9 +128,6 @@ void __init at32_select_gpio(unsigned int pin, unsigned long flags)
 
        pio_writel(pio, PER, mask);
 
-       /* gpio_request now allowed */
-       clear_bit(pin_index, &pio->gpio_mask);
-
        return;
 
 fail:
@@ -166,96 +161,50 @@ fail:
 
 /* GPIO API */
 
-int gpio_request(unsigned int gpio, const char *label)
+static int direction_input(struct gpio_chip *chip, unsigned offset)
 {
-       struct pio_device *pio;
-       unsigned int pin;
-
-       pio = gpio_to_pio(gpio);
-       if (!pio)
-               return -ENODEV;
+       struct pio_device *pio = container_of(chip, struct pio_device, chip);
+       u32 mask = 1 << offset;
 
-       pin = gpio & 0x1f;
-       if (test_and_set_bit(pin, &pio->gpio_mask))
-               return -EBUSY;
+       if (!(pio_readl(pio, PSR) & mask))
+               return -EINVAL;
 
+       pio_writel(pio, ODR, mask);
        return 0;
 }
-EXPORT_SYMBOL(gpio_request);
 
-void gpio_free(unsigned int gpio)
+static int gpio_get(struct gpio_chip *chip, unsigned offset)
 {
-       struct pio_device *pio;
-       unsigned int pin;
+       struct pio_device *pio = container_of(chip, struct pio_device, chip);
 
-       pio = gpio_to_pio(gpio);
-       if (!pio) {
-               printk(KERN_ERR
-                      "gpio: attempted to free invalid pin %u\n", gpio);
-               return;
-       }
-
-       pin = gpio & 0x1f;
-       if (!test_and_clear_bit(pin, &pio->gpio_mask))
-               printk(KERN_ERR "gpio: freeing free or non-gpio pin %s-%u\n",
-                      pio->name, pin);
+       return (pio_readl(pio, PDSR) >> offset) & 1;
 }
-EXPORT_SYMBOL(gpio_free);
 
-int gpio_direction_input(unsigned int gpio)
-{
-       struct pio_device *pio;
-       unsigned int pin;
-
-       pio = gpio_to_pio(gpio);
-       if (!pio)
-               return -ENODEV;
-
-       pin = gpio & 0x1f;
-       pio_writel(pio, ODR, 1 << pin);
-
-       return 0;
-}
-EXPORT_SYMBOL(gpio_direction_input);
+static void gpio_set(struct gpio_chip *chip, unsigned offset, int value);
 
-int gpio_direction_output(unsigned int gpio, int value)
+static int direction_output(struct gpio_chip *chip, unsigned offset, int value)
 {
-       struct pio_device *pio;
-       unsigned int pin;
-
-       pio = gpio_to_pio(gpio);
-       if (!pio)
-               return -ENODEV;
+       struct pio_device *pio = container_of(chip, struct pio_device, chip);
+       u32 mask = 1 << offset;
 
-       gpio_set_value(gpio, value);
-
-       pin = gpio & 0x1f;
-       pio_writel(pio, OER, 1 << pin);
+       if (!(pio_readl(pio, PSR) & mask))
+               return -EINVAL;
 
+       gpio_set(chip, offset, value);
+       pio_writel(pio, OER, mask);
        return 0;
 }
-EXPORT_SYMBOL(gpio_direction_output);
 
-int gpio_get_value(unsigned int gpio)
+static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 {
-       struct pio_device *pio = &pio_dev[gpio >> 5];
+       struct pio_device *pio = container_of(chip, struct pio_device, chip);
+       u32 mask = 1 << offset;
 
-       return (pio_readl(pio, PDSR) >> (gpio & 0x1f)) & 1;
-}
-EXPORT_SYMBOL(gpio_get_value);
-
-void gpio_set_value(unsigned int gpio, int value)
-{
-       struct pio_device *pio = &pio_dev[gpio >> 5];
-       u32 mask;
-
-       mask = 1 << (gpio & 0x1f);
        if (value)
                pio_writel(pio, SODR, mask);
        else
                pio_writel(pio, CODR, mask);
 }
-EXPORT_SYMBOL(gpio_set_value);
 
 /*--------------------------------------------------------------------------*/
 
@@ -337,6 +286,63 @@ gpio_irq_setup(struct pio_device *pio, int irq, int gpio_irq)
        set_irq_chained_handler(irq, gpio_irq_handler);
 }
 
+/*--------------------------------------------------------------------------*/
+
+#ifdef CONFIG_DEBUG_FS
+
+#include <linux/seq_file.h>
+
+/*
+ * This shows more info than the generic gpio dump code:
+ * pullups, deglitching, open drain drive.
+ */
+static void pio_bank_show(struct seq_file *s, struct gpio_chip *chip)
+{
+       struct pio_device *pio = container_of(chip, struct pio_device, chip);
+       u32                     psr, osr, imr, pdsr, pusr, ifsr, mdsr;
+       unsigned                i;
+       u32                     mask;
+       char                    bank;
+
+       psr = pio_readl(pio, PSR);
+       osr = pio_readl(pio, OSR);
+       imr = pio_readl(pio, IMR);
+       pdsr = pio_readl(pio, PDSR);
+       pusr = pio_readl(pio, PUSR);
+       ifsr = pio_readl(pio, IFSR);
+       mdsr = pio_readl(pio, MDSR);
+
+       bank = 'A' + pio->pdev->id;
+
+       for (i = 0, mask = 1; i < 32; i++, mask <<= 1) {
+               const char *label;
+
+               label = gpiochip_is_requested(chip, i);
+               if (!label)
+                       continue;
+
+               seq_printf(s, " gpio-%-3d P%c%-2d (%-12s) %s %s %s",
+                       chip->base + i, bank, i,
+                       label,
+                       (osr & mask) ? "out" : "in ",
+                       (mask & pdsr) ? "hi" : "lo",
+                       (mask & pusr) ? "  " : "up");
+               if (ifsr & mask)
+                       seq_printf(s, " deglitch");
+               if ((osr & mdsr) & mask)
+                       seq_printf(s, " open-drain");
+               if (imr & mask)
+                       seq_printf(s, " irq-%d edge-both",
+                               gpio_to_irq(chip->base + i));
+               seq_printf(s, "\n");
+       }
+}
+
+#else
+#define pio_bank_show  NULL
+#endif
+
+
 /*--------------------------------------------------------------------------*/
 
 static int __init pio_probe(struct platform_device *pdev)
@@ -349,6 +355,18 @@ static int __init pio_probe(struct platform_device *pdev)
        pio = &pio_dev[pdev->id];
        BUG_ON(!pio->regs);
 
+       pio->chip.label = pio->name;
+       pio->chip.base = pdev->id * 32;
+       pio->chip.ngpio = 32;
+
+       pio->chip.direction_input = direction_input;
+       pio->chip.get = gpio_get;
+       pio->chip.direction_output = direction_output;
+       pio->chip.set = gpio_set;
+       pio->chip.dbg_show = pio_bank_show;
+
+       gpiochip_add(&pio->chip);
+
        gpio_irq_setup(pio, irq, gpio_irq_base);
 
        platform_set_drvdata(pdev, pio);
@@ -406,12 +424,6 @@ void __init at32_init_pio(struct platform_device *pdev)
        pio->pdev = pdev;
        pio->regs = ioremap(regs->start, regs->end - regs->start + 1);
 
-       /*
-        * request_gpio() is only valid for pins that have been
-        * explicitly configured as GPIO and not previously requested
-        */
-       pio->gpio_mask = ~0UL;
-
        /* start with irqs disabled and acked */
        pio_writel(pio, IDR, ~0UL);
        (void) pio_readl(pio, ISR);
index 50fa3aca32c58c23f471469e2def0c02767b2491..7795116a483af37707a66ae57c1f1da49e59a41a 100644 (file)
@@ -19,7 +19,7 @@
 #define PIO_OSR                                0x0018
 #define PIO_IFER                               0x0020
 #define PIO_IFDR                               0x0024
-#define PIO_ISFR                               0x0028
+#define PIO_IFSR                               0x0028
 #define PIO_SODR                               0x0030
 #define PIO_CODR                               0x0034
 #define PIO_ODSR                               0x0038
index fc7ca86ac8bf91627a627539da062d65da16a383..ba21e33b8b1ff2047a078dd3f418d8b4a794be8d 100644 (file)
@@ -24,6 +24,7 @@ config RWSEM_XCHGADD_ALGORITHM
 config BLACKFIN
        bool
        default y
+       select HAVE_OPROFILE
 
 config ZONE_DMA
        bool
@@ -898,6 +899,10 @@ endmenu
 menu "Power management options"
 source "kernel/power/Kconfig"
 
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+       depends on !SMP
+
 choice
        prompt "Select PM Wakeup Event Source"
        default PM_WAKEUP_GPIO_BY_SIC_IWR
@@ -969,8 +974,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/blackfin/Kconfig.debug"
 
 source "security/Kconfig"
index f8c411a24af79e6767c0f834a1daf6d0b4f5f61c..1795aab79064c1ce468cd92d053bc46b0fd7f430 100644 (file)
@@ -37,7 +37,7 @@
 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
 #include <linux/usb/isp1362.h>
 #endif
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/usb/sl811.h>
index a72c7a620fa1ddbf0dc228e441700aa64f7c156f..97378b0a975308047004fb89eb2768038968597f 100644 (file)
@@ -38,7 +38,7 @@
 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
 #include <linux/usb/isp1362.h>
 #endif
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 
 #include <asm/dma.h>
index 21df2f3754975b44ae60746ebe93ddbcfcee7ad6..886f260d9359f35b9e754ecab4eccccbd35ceb94 100644 (file)
@@ -34,7 +34,7 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
 #include <linux/usb/isp1362.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <asm/dma.h>
 #include <asm/bfin5xx_spi.h>
index c37dd45c8803fad0817b0eef3e47433e57264a3b..4026c2f3ab4e19e1d9558028b98575bcb7095acc 100644 (file)
@@ -35,7 +35,7 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
 #include <linux/usb/isp1362.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <asm/dma.h>
 #include <asm/bfin5xx_spi.h>
index ac52b040b336f13fafee8bda080479880c146b5f..0185350feacc165768899bd959a4cd946549a53b 100644 (file)
@@ -38,7 +38,7 @@
 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
 #include <linux/usb/isp1362.h>
 #endif
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <asm/dma.h>
 #include <asm/bfin5xx_spi.h>
index 8703b67d5ec66c95af77c7b2e8773a05fd279041..f7c1f964f13b1a42d38bd14e81dfe5f4c70ca12c 100644 (file)
@@ -36,7 +36,7 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
 #include <linux/usb/isp1362.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <asm/dma.h>
 #include <asm/bfin5xx_spi.h>
index 3e52f3f5bd5888b7aa0e0d0c7b10242531a011ec..8a3397db1d212ec35dc10b08d71bc0d1026c494a 100644 (file)
@@ -38,7 +38,7 @@
 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
 #include <linux/usb/isp1362.h>
 #endif
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/usb/sl811.h>
index b8bbba85af536286e34e6f17cf23e4760e08d70b..d71e0be339212c752a14aeea214ee7d1b72f654f 100644 (file)
@@ -10,7 +10,7 @@
 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
 #include <linux/usb_isp1362.h>
 #endif
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/usb_sl811.h>
index 772541548b7623d4e0fd2871fe053471559e206c..119e6ea833848a6b8498a48babf1bd668d718d2b 100644 (file)
@@ -38,7 +38,7 @@
 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
 #include <linux/usb/isp1362.h>
 #endif
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/usb/sl811.h>
index 3a79a9061bdc8309cf6f53e0c3af637068270954..bf9e738a7c6451938a3254039e324c68cc71ff85 100644 (file)
@@ -34,7 +34,7 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
 #include <linux/usb/isp1362.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/irq.h>
 #include <asm/dma.h>
 #include <asm/bfin5xx_spi.h>
index 7601c3be1b5c3a70256d8d7d3af091261a7a88d6..ed863ce9a2d8c13042160d0cba4d4bc7288f5291 100644 (file)
@@ -35,7 +35,7 @@
 #include <linux/spi/spi.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <asm/dma.h>
 #include <asm/bfin5xx_spi.h>
 #include <asm/portmux.h>
index 56ff51bc8c21c8a761dc75f334b9a00f223754a4..fdd9bf43361edf9c31eae8fc19a5bdbdb2666b06 100644 (file)
@@ -1373,7 +1373,7 @@ ENTRY(_sys_call_table)
        .long _sys_epoll_pwait
        .long _sys_utimensat
        .long _sys_signalfd
-       .long _sys_timerfd
+       .long _sys_ni_syscall
        .long _sys_eventfd      /* 350 */
        .long _sys_pread64
        .long _sys_pwrite64
index 222da1501f47c0e81508996e8f74ec7c5ff21353..27b082ac7f11e25e8d6b292b54af2c932f259217 100644 (file)
@@ -150,6 +150,7 @@ config ETRAX_FLASH_BUSWIDTH
          Width in bytes of the Flash bus (1, 2 or 4). Is usually 2.
 
 source arch/cris/arch-v10/Kconfig
+source arch/cris/arch-v32/Kconfig
 
 endmenu
 
@@ -157,8 +158,8 @@ source "net/Kconfig"
 
 # bring in ETRAX built-in drivers
 menu "Drivers for built-in interfaces"
-# arch/cris/arch is a symlink to correct arch (arch-v10 or arch-v32)
-source arch/cris/arch/drivers/Kconfig
+source arch/cris/arch-v10/drivers/Kconfig
+source arch/cris/arch-v32/drivers/Kconfig
 
 endmenu
 
@@ -213,8 +214,6 @@ source "drivers/pci/Kconfig"
 
 source "drivers/usb/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/cris/Kconfig.debug"
 
 source "security/Kconfig"
index f1ce6f64401dd45c4e375a466146790f53aeb8eb..1d61faec77cd0b01241462104bf1747e3b6a508d 100644 (file)
@@ -1,3 +1,5 @@
+if ETRAX_ARCH_V10
+
 # ETRAX 100LX v1 has a MMU "feature" requiring a low mapping
 config CRIS_LOW_MAP
        bool
@@ -451,3 +453,5 @@ config ETRAX_POWERBUTTON_BIT
        default "25"
        help
          Configure where power button is connected.
+
+endif
index e3c0f29281496781f948b6e14414e53aea75eaab..96740ef497d4237ebffc65ffb79afe8a1bdc5f4c 100644 (file)
@@ -1,3 +1,5 @@
+if ETRAX_ARCH_V10
+
 config ETRAX_ETHERNET
        bool "Ethernet support"
        depends on ETRAX_ARCH_V10
@@ -806,3 +808,5 @@ config ETRAX_DS1302_TRICKLE_CHARGE
          1 = 2kohm, 2 = 4kohm, 3 = 4kohm
          4 = 1 diode, 8 = 2 diodes
          Allowed values are (increasing current): 0, 11, 10, 9, 7, 6, 5
+
+endif
index ec62c951fa3cc37a1dd709609cd1a9bfa669ef1a..d1361dc119e24d76b3042bd7b70fcb91bdde205a 100644 (file)
@@ -1167,7 +1167,7 @@ sys_call_table:
        .long sys_epoll_pwait
        .long sys_utimensat             /* 320 */
        .long sys_signalfd
-       .long sys_timerfd
+       .long sys_ni_syscall
        .long sys_eventfd
        .long sys_fallocate
 
index 4f79d8ed3e1c451ec122f0b29f93549f9cb3e166..d8acaa920e1c0de92bfc5cfe34be843e11c56563 100644 (file)
@@ -1,3 +1,5 @@
+if ETRAX_ARCH_V32
+
 config ETRAX_DRAM_VIRTUAL_BASE
        hex
        depends on ETRAX_ARCH_V32
@@ -294,3 +296,5 @@ config ETRAX_DEF_GIO_PE_OUT
        help
          Configures the initial data for the general port E bits.  Most
          products should use 00000 here.
+
+endif
index 9bccb5e2a9607b399245f3a42f9c558d325e16bd..c329cce2a0c3c28a5bff0e18587d8dc8f1ce2e14 100644 (file)
@@ -1,3 +1,5 @@
+if ETRAX_ARCH_V32
+
 config ETRAX_ETHERNET
        bool "Ethernet support"
        depends on ETRAX_ARCH_V32
@@ -610,3 +612,5 @@ config ETRAX_STREAMCOPROC
        help
          This option enables a driver for the stream co-processor
          for cryptographic operations.
+
+endif
index 66f9500fbc027609b5d431b89c702015e9913b4c..e0364654fc447f2a4eae7756a28d84775b7654a0 100644 (file)
@@ -93,7 +93,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
 
        dev->dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL);
        if (!dev->dma_mem)
-               goto out;
+               goto iounmap_out;
        dev->dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
        if (!dev->dma_mem->bitmap)
                goto free1_out;
@@ -110,6 +110,8 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
 
  free1_out:
        kfree(dev->dma_mem);
+ iounmap_out:
+       iounmap(mem_base);
  out:
        return 0;
 }
index 43153e767bb1ab548f1edc52bb755233b38830c3..96f7d70f4473681dc3f155b31c00215a55267257 100644 (file)
@@ -79,7 +79,7 @@ config FRV_OUTOFLINE_ATOMIC_OPS
          Setting this option causes the FR-V atomic operations to be mostly
          implemented out-of-line.
 
-         See Documentation/fujitsu/frv/atomic-ops.txt for more information.
+         See Documentation/frv/atomic-ops.txt for more information.
 
 config HIGHMEM
        bool "High memory support"
@@ -138,6 +138,15 @@ config UCPAGE_OFFSET_C0000000
 
 endchoice
 
+config PAGE_OFFSET
+       hex
+       default 0x20000000 if UCPAGE_OFFSET_20000000
+       default 0x40000000 if UCPAGE_OFFSET_40000000
+       default 0x60000000 if UCPAGE_OFFSET_60000000
+       default 0x80000000 if UCPAGE_OFFSET_80000000
+       default 0xA0000000 if UCPAGE_OFFSET_A0000000
+       default 0xC0000000
+
 config PROTECT_KERNEL
        bool "Protect core kernel against userspace"
        depends on !MMU
@@ -322,11 +331,6 @@ config PCI
          onboard. If you have one of these boards and you wish to use the PCI
          facilities, say Y here.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 config RESERVE_DMA_COHERENT
        bool "Reserve DMA coherent memory"
        depends on PCI && !MMU
@@ -357,6 +361,11 @@ source "drivers/pcmcia/Kconfig"
 #        should probably wait a while.
 
 menu "Power management options"
+
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+       depends on !SMP
+
 source kernel/power/Kconfig
 endmenu
 
@@ -375,8 +384,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/frv/Kconfig.debug"
 
 source "security/Kconfig"
index f926c70947764ef108d5d3da1bddd44a364e9e14..ca6a345b87e401f7309e89c0a41702a91f38a35d 100644 (file)
@@ -253,7 +253,7 @@ __entry_kernel_external_interrupt_reentry:
        andi.p          gr5,#~PSR_ET,gr5
 
        # set CCCR.CC3 to Undefined to abort atomic-modify completion inside the kernel
-       # - for an explanation of how it works, see: Documentation/fujitsu/frv/atomic-ops.txt
+       # - for an explanation of how it works, see: Documentation/frv/atomic-ops.txt
        andi            gr25,#~0xc0,gr25
 
        sti             gr20,@(gr28,#REG_TBR)
@@ -445,7 +445,7 @@ __entry_kernel_softprog_interrupt_reentry:
        sti             gr22,@(sp,#REG_SP)
 
        # set CCCR.CC3 to Undefined to abort atomic-modify completion inside the kernel
-       # - for an explanation of how it works, see: Documentation/fujitsu/frv/atomic-ops.txt
+       # - for an explanation of how it works, see: Documentation/frv/atomic-ops.txt
        movsg           cccr,gr20
        andi            gr20,#~0xc0,gr20
        movgs           gr20,cccr
@@ -1494,7 +1494,7 @@ sys_call_table:
        .long sys_epoll_pwait
        .long sys_utimensat             /* 320 */
        .long sys_signalfd
-       .long sys_timerfd
+       .long sys_ni_syscall
        .long sys_eventfd
        .long sys_fallocate
 
index a74c08786b21a8500067c2b442cb08b0b2c41daf..b38ae1fc15fd701728d67e30e37d7370a146a2ce 100644 (file)
@@ -708,7 +708,7 @@ static void __init reserve_dma_coherent(void)
 /*
  * calibrate the delay loop
  */
-void __init calibrate_delay(void)
+void __cpuinit calibrate_delay(void)
 {
        loops_per_jiffy = __delay_loops_MHz * (1000000 / HZ);
 
index f42b328b1dd0475e1af868308cdc000c89d40942..ef7527b8b0c77fabca307e5a0f614386d162c8ac 100644 (file)
@@ -13,7 +13,7 @@ ENTRY(_start)
 
 jiffies = jiffies_64 + 4;
 
-__page_offset = 0xc0000000;            /* start of area covered by struct pages */
+__page_offset = CONFIG_PAGE_OFFSET;    /* start of area covered by struct pages */
 __kernel_image_start = __page_offset;  /* address at which kernel image resides */
 
 SECTIONS
index 545cd325ac577d00c9ef96dc3f73fc97d24d44fe..ee0ac905fb08ac271139ecd12de58e9fc9b61366 100644 (file)
@@ -1,7 +1,7 @@
 /* atomic-ops.S: kernel atomic operations
  *
  * For an explanation of how atomic ops work in this arch, see:
- *   Documentation/fujitsu/frv/atomic-ops.txt
+ *   Documentation/frv/atomic-ops.txt
  *
  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  * Written by David Howells (dhowells@redhat.com)
index 1530a4111e6d743345ff379d191ba7d6df06e9a3..81757d55a5b592fed1e38281edc0cbb6a256dff7 100644 (file)
@@ -181,7 +181,7 @@ int cxn_pin_by_pid(pid_t pid)
 
        /* get a handle on the mm_struct */
        read_lock(&tasklist_lock);
-       tsk = find_task_by_pid(pid);
+       tsk = find_task_by_vpid(pid);
        if (tsk) {
                ret = -EINVAL;
 
index 7787c3cc52c6923d58e305b4ae10c4e3ab6b87e1..1a2e5c8d03a9c7e639ab354705a08cb0916bb443 100644 (file)
@@ -140,7 +140,7 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
        return pgd;
 }
 
-void pgd_free(pgd_t *pgd)
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        /* in the non-PAE case, clear_page_tables() clears user pgd entries */
        quicklist_free(0, pgd_dtor, pgd);
index ff6a8712bd6d8c3f59f7724050d9793a22db3fcf..dc61222e11207b1d802481aa4dfdd4fd788e20b8 100644 (file)
@@ -223,8 +223,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/h8300/Kconfig.debug"
 
 source "security/Kconfig"
index 8dec4dd57b4e06ff44f26da88a0f9d89d8b954da..5a1b4cfea05b37660fbf54d57016bb06e67be6e7 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/random.h>
 #include <linux/bootmem.h>
 #include <linux/irq.h>
+#include <linux/interrupt.h>
 
 #include <asm/system.h>
 #include <asm/traps.h>
index 551fd5f30d826ae0a25ab015100c18d9d0b3d4c4..ac10b9783850aa1473bd13c463af1e4eac021708 100644 (file)
@@ -121,7 +121,7 @@ void __init init_IRQ(void)
                printk("virtual vector at 0x%08lx\n",(unsigned long)ramvec);
 
 #if defined(CONFIG_GDB_DEBUG)
-       /* save orignal break vector */
+       /* save original break vector */
        break_vec = ramvec[TRAP3_VEC];
 #else
        break_vec = VECTOR(trace_break);
index c9307c99a1dc26977399b955f9436f9898afca72..b0de1132dfc02e0537c381b66be30d507daee2f5 100644 (file)
@@ -15,6 +15,8 @@ config IA64
        select ACPI if (!IA64_HP_SIM)
        select PM if (!IA64_HP_SIM)
        select ARCH_SUPPORTS_MSI
+       select HAVE_OPROFILE
+       select HAVE_KPROBES
        default y
        help
          The Itanium Processor Family is Intel's 64-bit successor to
@@ -283,8 +285,8 @@ config SMP
          single processor systems.  On a single processor system, the kernel
          will run faster if you say N here.
 
-         See also the <file:Documentation/smp.txt> and the SMP-HOWTO
-         available at <http://www.tldp.org/docs.html#howto>.
+         See also the SMP-HOWTO available at
+         <http://www.tldp.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
 
@@ -600,8 +602,6 @@ config IRQ_PER_CPU
 
 source "arch/ia64/hp/sim/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/ia64/Kconfig.debug"
 
 source "security/Kconfig"
index 45bf04eb7d705c2371d8907e8ec13cc7ab5d6be5..a94445422cc65d895eb76e4a417897bf067556d9 100644 (file)
@@ -1265,7 +1265,7 @@ sba_fill_pdir(
  * the sglist do both.
  */
 static SBA_INLINE int
-sba_coalesce_chunks( struct ioc *ioc,
+sba_coalesce_chunks(struct ioc *ioc, struct device *dev,
        struct scatterlist *startsg,
        int nents)
 {
@@ -1275,6 +1275,7 @@ sba_coalesce_chunks( struct ioc *ioc,
        struct scatterlist *dma_sg;        /* next DMA stream head */
        unsigned long dma_offset, dma_len; /* start/len of DMA stream */
        int n_mappings = 0;
+       unsigned int max_seg_size = dma_get_max_seg_size(dev);
 
        while (nents > 0) {
                unsigned long vaddr = (unsigned long) sba_sg_address(startsg);
@@ -1314,6 +1315,9 @@ sba_coalesce_chunks( struct ioc *ioc,
                            > DMA_CHUNK_SIZE)
                                break;
 
+                       if (dma_len + startsg->length > max_seg_size)
+                               break;
+
                        /*
                        ** Then look for virtually contiguous blocks.
                        **
@@ -1441,7 +1445,7 @@ int sba_map_sg(struct device *dev, struct scatterlist *sglist, int nents, int di
        ** w/o this association, we wouldn't have coherent DMA!
        ** Access to the virtual address is what forces a two pass algorithm.
        */
-       coalesced = sba_coalesce_chunks(ioc, sglist, nents);
+       coalesced = sba_coalesce_chunks(ioc, dev, sglist, nents);
 
        /*
        ** Program the I/O Pdir
@@ -1871,7 +1875,7 @@ ioc_show(struct seq_file *s, void *v)
        return 0;
 }
 
-static struct seq_operations ioc_seq_ops = {
+static const struct seq_operations ioc_seq_ops = {
        .start = ioc_start,
        .next  = ioc_next,
        .stop  = ioc_stop,
index d1d50cd1c38a700318a02ab3678a7bb16eca743d..896b1ebbfb268381bc87eb2e766e9c75e7d75f84 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "ia32priv.h"
 
-extern void die_if_kernel (char *str, struct pt_regs *regs, long err);
+extern int die_if_kernel (char *str, struct pt_regs *regs, long err);
 
 struct exec_domain ia32_exec_domain;
 struct page *ia32_shared_page[NR_CPUS];
@@ -217,7 +217,8 @@ ia32_bad_interrupt (unsigned long int_num, struct pt_regs *regs)
 {
        siginfo_t siginfo;
 
-       die_if_kernel("Bad IA-32 interrupt", regs, int_num);
+       if (die_if_kernel("Bad IA-32 interrupt", regs, int_num))
+               return;
 
        siginfo.si_signo = SIGTRAP;
        siginfo.si_errno = int_num;     /* XXX is it OK to abuse si_errno like this? */
index 242d7934112009340e36724787477bffcda63175..919070a9aed7184c87ea43d83855963bb170d40e 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * Extensible Firmware Interface
  *
- * Based on Extensible Firmware Interface Specification version 0.9 April 30, 1999
+ * Based on Extensible Firmware Interface Specification version 0.9
+ * April 30, 1999
  *
  * Copyright (C) 1999 VA Linux Systems
  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
@@ -48,145 +49,157 @@ static unsigned long mem_limit = ~0UL, max_addr = ~0UL, min_addr = 0UL;
 
 #define efi_call_virt(f, args...)      (*(f))(args)
 
-#define STUB_GET_TIME(prefix, adjust_arg)                                                        \
-static efi_status_t                                                                              \
-prefix##_get_time (efi_time_t *tm, efi_time_cap_t *tc)                                           \
-{                                                                                                \
-       struct ia64_fpreg fr[6];                                                                  \
-       efi_time_cap_t *atc = NULL;                                                               \
-       efi_status_t ret;                                                                         \
-                                                                                                 \
-       if (tc)                                                                                   \
-               atc = adjust_arg(tc);                                                             \
-       ia64_save_scratch_fpregs(fr);                                                             \
-       ret = efi_call_##prefix((efi_get_time_t *) __va(runtime->get_time), adjust_arg(tm), atc); \
-       ia64_load_scratch_fpregs(fr);                                                             \
-       return ret;                                                                               \
+#define STUB_GET_TIME(prefix, adjust_arg)                                     \
+static efi_status_t                                                           \
+prefix##_get_time (efi_time_t *tm, efi_time_cap_t *tc)                        \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_time_cap_t *atc = NULL;                                            \
+       efi_status_t ret;                                                      \
+                                                                              \
+       if (tc)                                                                \
+               atc = adjust_arg(tc);                                          \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix((efi_get_time_t *) __va(runtime->get_time),    \
+                               adjust_arg(tm), atc);                          \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_SET_TIME(prefix, adjust_arg)                                                      \
-static efi_status_t                                                                            \
-prefix##_set_time (efi_time_t *tm)                                                             \
-{                                                                                              \
-       struct ia64_fpreg fr[6];                                                                \
-       efi_status_t ret;                                                                       \
-                                                                                               \
-       ia64_save_scratch_fpregs(fr);                                                           \
-       ret = efi_call_##prefix((efi_set_time_t *) __va(runtime->set_time), adjust_arg(tm));    \
-       ia64_load_scratch_fpregs(fr);                                                           \
-       return ret;                                                                             \
+#define STUB_SET_TIME(prefix, adjust_arg)                                     \
+static efi_status_t                                                           \
+prefix##_set_time (efi_time_t *tm)                                            \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_status_t ret;                                                      \
+                                                                              \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix((efi_set_time_t *) __va(runtime->set_time),    \
+                               adjust_arg(tm));                               \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_GET_WAKEUP_TIME(prefix, adjust_arg)                                               \
-static efi_status_t                                                                            \
-prefix##_get_wakeup_time (efi_bool_t *enabled, efi_bool_t *pending, efi_time_t *tm)            \
-{                                                                                              \
-       struct ia64_fpreg fr[6];                                                                \
-       efi_status_t ret;                                                                       \
-                                                                                               \
-       ia64_save_scratch_fpregs(fr);                                                           \
-       ret = efi_call_##prefix((efi_get_wakeup_time_t *) __va(runtime->get_wakeup_time),       \
-                               adjust_arg(enabled), adjust_arg(pending), adjust_arg(tm));      \
-       ia64_load_scratch_fpregs(fr);                                                           \
-       return ret;                                                                             \
+#define STUB_GET_WAKEUP_TIME(prefix, adjust_arg)                              \
+static efi_status_t                                                           \
+prefix##_get_wakeup_time (efi_bool_t *enabled, efi_bool_t *pending,           \
+                         efi_time_t *tm)                                      \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_status_t ret;                                                      \
+                                                                              \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix(                                               \
+               (efi_get_wakeup_time_t *) __va(runtime->get_wakeup_time),      \
+               adjust_arg(enabled), adjust_arg(pending), adjust_arg(tm));     \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_SET_WAKEUP_TIME(prefix, adjust_arg)                                               \
-static efi_status_t                                                                            \
-prefix##_set_wakeup_time (efi_bool_t enabled, efi_time_t *tm)                                  \
-{                                                                                              \
-       struct ia64_fpreg fr[6];                                                                \
-       efi_time_t *atm = NULL;                                                                 \
-       efi_status_t ret;                                                                       \
-                                                                                               \
-       if (tm)                                                                                 \
-               atm = adjust_arg(tm);                                                           \
-       ia64_save_scratch_fpregs(fr);                                                           \
-       ret = efi_call_##prefix((efi_set_wakeup_time_t *) __va(runtime->set_wakeup_time),       \
-                               enabled, atm);                                                  \
-       ia64_load_scratch_fpregs(fr);                                                           \
-       return ret;                                                                             \
+#define STUB_SET_WAKEUP_TIME(prefix, adjust_arg)                              \
+static efi_status_t                                                           \
+prefix##_set_wakeup_time (efi_bool_t enabled, efi_time_t *tm)                 \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_time_t *atm = NULL;                                                \
+       efi_status_t ret;                                                      \
+                                                                              \
+       if (tm)                                                                \
+               atm = adjust_arg(tm);                                          \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix(                                               \
+               (efi_set_wakeup_time_t *) __va(runtime->set_wakeup_time),      \
+               enabled, atm);                                                 \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_GET_VARIABLE(prefix, adjust_arg)                                          \
-static efi_status_t                                                                    \
-prefix##_get_variable (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,              \
-                      unsigned long *data_size, void *data)                            \
-{                                                                                      \
-       struct ia64_fpreg fr[6];                                                        \
-       u32 *aattr = NULL;                                                                      \
-       efi_status_t ret;                                                               \
-                                                                                       \
-       if (attr)                                                                       \
-               aattr = adjust_arg(attr);                                               \
-       ia64_save_scratch_fpregs(fr);                                                   \
-       ret = efi_call_##prefix((efi_get_variable_t *) __va(runtime->get_variable),     \
-                               adjust_arg(name), adjust_arg(vendor), aattr,            \
-                               adjust_arg(data_size), adjust_arg(data));               \
-       ia64_load_scratch_fpregs(fr);                                                   \
-       return ret;                                                                     \
+#define STUB_GET_VARIABLE(prefix, adjust_arg)                                 \
+static efi_status_t                                                           \
+prefix##_get_variable (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,      \
+                      unsigned long *data_size, void *data)                   \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       u32 *aattr = NULL;                                                     \
+       efi_status_t ret;                                                      \
+                                                                              \
+       if (attr)                                                              \
+               aattr = adjust_arg(attr);                                      \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix(                                               \
+               (efi_get_variable_t *) __va(runtime->get_variable),            \
+               adjust_arg(name), adjust_arg(vendor), aattr,                   \
+               adjust_arg(data_size), adjust_arg(data));                      \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_GET_NEXT_VARIABLE(prefix, adjust_arg)                                             \
-static efi_status_t                                                                            \
-prefix##_get_next_variable (unsigned long *name_size, efi_char16_t *name, efi_guid_t *vendor)  \
-{                                                                                              \
-       struct ia64_fpreg fr[6];                                                                \
-       efi_status_t ret;                                                                       \
-                                                                                               \
-       ia64_save_scratch_fpregs(fr);                                                           \
-       ret = efi_call_##prefix((efi_get_next_variable_t *) __va(runtime->get_next_variable),   \
-                               adjust_arg(name_size), adjust_arg(name), adjust_arg(vendor));   \
-       ia64_load_scratch_fpregs(fr);                                                           \
-       return ret;                                                                             \
+#define STUB_GET_NEXT_VARIABLE(prefix, adjust_arg)                            \
+static efi_status_t                                                           \
+prefix##_get_next_variable (unsigned long *name_size, efi_char16_t *name,      \
+                           efi_guid_t *vendor)                                \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_status_t ret;                                                      \
+                                                                              \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix(                                               \
+               (efi_get_next_variable_t *) __va(runtime->get_next_variable),  \
+               adjust_arg(name_size), adjust_arg(name), adjust_arg(vendor));  \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_SET_VARIABLE(prefix, adjust_arg)                                          \
-static efi_status_t                                                                    \
-prefix##_set_variable (efi_char16_t *name, efi_guid_t *vendor, unsigned long attr,     \
-                      unsigned long data_size, void *data)                             \
-{                                                                                      \
-       struct ia64_fpreg fr[6];                                                        \
-       efi_status_t ret;                                                               \
-                                                                                       \
-       ia64_save_scratch_fpregs(fr);                                                   \
-       ret = efi_call_##prefix((efi_set_variable_t *) __va(runtime->set_variable),     \
-                               adjust_arg(name), adjust_arg(vendor), attr, data_size,  \
-                               adjust_arg(data));                                      \
-       ia64_load_scratch_fpregs(fr);                                                   \
-       return ret;                                                                     \
+#define STUB_SET_VARIABLE(prefix, adjust_arg)                                 \
+static efi_status_t                                                           \
+prefix##_set_variable (efi_char16_t *name, efi_guid_t *vendor,                \
+                      unsigned long attr, unsigned long data_size,            \
+                      void *data)                                             \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_status_t ret;                                                      \
+                                                                              \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix(                                               \
+               (efi_set_variable_t *) __va(runtime->set_variable),            \
+               adjust_arg(name), adjust_arg(vendor), attr, data_size,         \
+               adjust_arg(data));                                             \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_GET_NEXT_HIGH_MONO_COUNT(prefix, adjust_arg)                                      \
-static efi_status_t                                                                            \
-prefix##_get_next_high_mono_count (u32 *count)                                                 \
-{                                                                                              \
-       struct ia64_fpreg fr[6];                                                                \
-       efi_status_t ret;                                                                       \
-                                                                                               \
-       ia64_save_scratch_fpregs(fr);                                                           \
-       ret = efi_call_##prefix((efi_get_next_high_mono_count_t *)                              \
-                               __va(runtime->get_next_high_mono_count), adjust_arg(count));    \
-       ia64_load_scratch_fpregs(fr);                                                           \
-       return ret;                                                                             \
+#define STUB_GET_NEXT_HIGH_MONO_COUNT(prefix, adjust_arg)                     \
+static efi_status_t                                                           \
+prefix##_get_next_high_mono_count (u32 *count)                                \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_status_t ret;                                                      \
+                                                                              \
+       ia64_save_scratch_fpregs(fr);                                          \
+       ret = efi_call_##prefix((efi_get_next_high_mono_count_t *)             \
+                               __va(runtime->get_next_high_mono_count),       \
+                               adjust_arg(count));                            \
+       ia64_load_scratch_fpregs(fr);                                          \
+       return ret;                                                            \
 }
 
-#define STUB_RESET_SYSTEM(prefix, adjust_arg)                                  \
-static void                                                                    \
-prefix##_reset_system (int reset_type, efi_status_t status,                    \
-                      unsigned long data_size, efi_char16_t *data)             \
-{                                                                              \
-       struct ia64_fpreg fr[6];                                                \
-       efi_char16_t *adata = NULL;                                             \
-                                                                               \
-       if (data)                                                               \
-               adata = adjust_arg(data);                                       \
-                                                                               \
-       ia64_save_scratch_fpregs(fr);                                           \
-       efi_call_##prefix((efi_reset_system_t *) __va(runtime->reset_system),   \
-                         reset_type, status, data_size, adata);                \
-       /* should not return, but just in case... */                            \
-       ia64_load_scratch_fpregs(fr);                                           \
+#define STUB_RESET_SYSTEM(prefix, adjust_arg)                                 \
+static void                                                                   \
+prefix##_reset_system (int reset_type, efi_status_t status,                   \
+                      unsigned long data_size, efi_char16_t *data)            \
+{                                                                             \
+       struct ia64_fpreg fr[6];                                               \
+       efi_char16_t *adata = NULL;                                            \
+                                                                              \
+       if (data)                                                              \
+               adata = adjust_arg(data);                                      \
+                                                                              \
+       ia64_save_scratch_fpregs(fr);                                          \
+       efi_call_##prefix(                                                     \
+               (efi_reset_system_t *) __va(runtime->reset_system),            \
+               reset_type, status, data_size, adata);                         \
+       /* should not return, but just in case... */                           \
+       ia64_load_scratch_fpregs(fr);                                          \
 }
 
 #define phys_ptr(arg)  ((__typeof__(arg)) ia64_tpa(arg))
@@ -223,7 +236,8 @@ efi_gettimeofday (struct timespec *ts)
                return;
        }
 
-       ts->tv_sec = mktime(tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second);
+       ts->tv_sec = mktime(tm.year, tm.month, tm.day,
+                           tm.hour, tm.minute, tm.second);
        ts->tv_nsec = tm.nanosecond;
 }
 
@@ -297,8 +311,8 @@ walk (efi_freemem_callback_t callback, void *arg, u64 attr)
 }
 
 /*
- * Walks the EFI memory map and calls CALLBACK once for each EFI memory descriptor that
- * has memory that is available for OS use.
+ * Walk the EFI memory map and call CALLBACK once for each EFI memory
+ * descriptor that has memory that is available for OS use.
  */
 void
 efi_memmap_walk (efi_freemem_callback_t callback, void *arg)
@@ -307,8 +321,8 @@ efi_memmap_walk (efi_freemem_callback_t callback, void *arg)
 }
 
 /*
- * Walks the EFI memory map and calls CALLBACK once for each EFI memory descriptor that
- * has memory that is available for uncached allocator.
+ * Walk the EFI memory map and call CALLBACK once for each EFI memory
+ * descriptor that has memory that is available for uncached allocator.
  */
 void
 efi_memmap_walk_uc (efi_freemem_callback_t callback, void *arg)
@@ -317,11 +331,10 @@ efi_memmap_walk_uc (efi_freemem_callback_t callback, void *arg)
 }
 
 /*
- * Look for the PAL_CODE region reported by EFI and maps it using an
+ * Look for the PAL_CODE region reported by EFI and map it using an
  * ITR to enable safe PAL calls in virtual mode.  See IA-64 Processor
  * Abstraction Layer chapter 11 in ADAG
  */
-
 void *
 efi_get_pal_addr (void)
 {
@@ -341,45 +354,47 @@ efi_get_pal_addr (void)
                        continue;
 
                if (++pal_code_count > 1) {
-                       printk(KERN_ERR "Too many EFI Pal Code memory ranges, dropped @ %lx\n",
-                              md->phys_addr);
+                       printk(KERN_ERR "Too many EFI Pal Code memory ranges, "
+                              "dropped @ %lx\n", md->phys_addr);
                        continue;
                }
                /*
-                * The only ITLB entry in region 7 that is used is the one installed by
-                * __start().  That entry covers a 64MB range.
+                * The only ITLB entry in region 7 that is used is the one
+                * installed by __start().  That entry covers a 64MB range.
                 */
                mask  = ~((1 << KERNEL_TR_PAGE_SHIFT) - 1);
                vaddr = PAGE_OFFSET + md->phys_addr;
 
                /*
-                * We must check that the PAL mapping won't overlap with the kernel
-                * mapping.
+                * We must check that the PAL mapping won't overlap with the
+                * kernel mapping.
                 *
-                * PAL code is guaranteed to be aligned on a power of 2 between 4k and
-                * 256KB and that only one ITR is needed to map it. This implies that the
-                * PAL code is always aligned on its size, i.e., the closest matching page
-                * size supported by the TLB. Therefore PAL code is guaranteed never to
-                * cross a 64MB unless it is bigger than 64MB (very unlikely!).  So for
-                * now the following test is enough to determine whether or not we need a
-                * dedicated ITR for the PAL code.
+                * PAL code is guaranteed to be aligned on a power of 2 between
+                * 4k and 256KB and that only one ITR is needed to map it. This
+                * implies that the PAL code is always aligned on its size,
+                * i.e., the closest matching page size supported by the TLB.
+                * Therefore PAL code is guaranteed never to cross a 64MB unless
+                * it is bigger than 64MB (very unlikely!).  So for now the
+                * following test is enough to determine whether or not we need
+                * a dedicated ITR for the PAL code.
                 */
                if ((vaddr & mask) == (KERNEL_START & mask)) {
-                       printk(KERN_INFO "%s: no need to install ITR for PAL code\n",
-                              __FUNCTION__);
+                       printk(KERN_INFO "%s: no need to install ITR for "
+                              "PAL code\n", __FUNCTION__);
                        continue;
                }
 
                if (efi_md_size(md) > IA64_GRANULE_SIZE)
-                       panic("Woah!  PAL code size bigger than a granule!");
+                       panic("Whoa!  PAL code size bigger than a granule!");
 
 #if EFI_DEBUG
                mask  = ~((1 << IA64_GRANULE_SHIFT) - 1);
 
-               printk(KERN_INFO "CPU %d: mapping PAL code [0x%lx-0x%lx) into [0x%lx-0x%lx)\n",
-                       smp_processor_id(), md->phys_addr,
-                       md->phys_addr + efi_md_size(md),
-                       vaddr & mask, (vaddr & mask) + IA64_GRANULE_SIZE);
+               printk(KERN_INFO "CPU %d: mapping PAL code "
+                       "[0x%lx-0x%lx) into [0x%lx-0x%lx)\n",
+                       smp_processor_id(), md->phys_addr,
+                       md->phys_addr + efi_md_size(md),
+                       vaddr & mask, (vaddr & mask) + IA64_GRANULE_SIZE);
 #endif
                return __va(md->phys_addr);
        }
@@ -401,11 +416,11 @@ efi_map_pal_code (void)
         * Cannot write to CRx with PSR.ic=1
         */
        psr = ia64_clear_ic();
-       ia64_itr(0x1, IA64_TR_PALCODE, GRANULEROUNDDOWN((unsigned long) pal_vaddr),
+       ia64_itr(0x1, IA64_TR_PALCODE,
+                GRANULEROUNDDOWN((unsigned long) pal_vaddr),
                 pte_val(pfn_pte(__pa(pal_vaddr) >> PAGE_SHIFT, PAGE_KERNEL)),
                 IA64_GRANULE_SHIFT);
        ia64_set_psr(psr);              /* restore psr */
-       ia64_srlz_i();
 }
 
 void __init
@@ -418,7 +433,10 @@ efi_init (void)
        char *cp, vendor[100] = "unknown";
        int i;
 
-       /* it's too early to be able to use the standard kernel command line support... */
+       /*
+        * It's too early to be able to use the standard kernel command line
+        * support...
+        */
        for (cp = boot_command_line; *cp; ) {
                if (memcmp(cp, "mem=", 4) == 0) {
                        mem_limit = memparse(cp + 4, &cp);
@@ -434,9 +452,11 @@ efi_init (void)
                }
        }
        if (min_addr != 0UL)
-               printk(KERN_INFO "Ignoring memory below %luMB\n", min_addr >> 20);
+               printk(KERN_INFO "Ignoring memory below %luMB\n",
+                      min_addr >> 20);
        if (max_addr != ~0UL)
-               printk(KERN_INFO "Ignoring memory above %luMB\n", max_addr >> 20);
+               printk(KERN_INFO "Ignoring memory above %luMB\n",
+                      max_addr >> 20);
 
        efi.systab = __va(ia64_boot_param->efi_systab);
 
@@ -444,9 +464,9 @@ efi_init (void)
         * Verify the EFI Table
         */
        if (efi.systab == NULL)
-               panic("Woah! Can't find EFI system table.\n");
+               panic("Whoa! Can't find EFI system table.\n");
        if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
-               panic("Woah! EFI system table signature incorrect\n");
+               panic("Whoa! EFI system table signature incorrect\n");
        if ((efi.systab->hdr.revision >> 16) == 0)
                printk(KERN_WARNING "Warning: EFI system table version "
                       "%d.%02d, expected 1.00 or greater\n",
@@ -464,7 +484,8 @@ efi_init (void)
        }
 
        printk(KERN_INFO "EFI v%u.%.02u by %s:",
-              efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff, vendor);
+              efi.systab->hdr.revision >> 16,
+              efi.systab->hdr.revision & 0xffff, vendor);
 
        efi.mps        = EFI_INVALID_TABLE_ADDR;
        efi.acpi       = EFI_INVALID_TABLE_ADDR;
@@ -519,9 +540,12 @@ efi_init (void)
                efi_memory_desc_t *md;
                void *p;
 
-               for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
+               for (i = 0, p = efi_map_start; p < efi_map_end;
+                    ++i, p += efi_desc_size)
+               {
                        md = p;
-                       printk("mem%02u: type=%u, attr=0x%lx, range=[0x%016lx-0x%016lx) (%luMB)\n",
+                       printk("mem%02u: type=%u, attr=0x%lx, "
+                              "range=[0x%016lx-0x%016lx) (%luMB)\n",
                               i, md->type, md->attribute, md->phys_addr,
                               md->phys_addr + efi_md_size(md),
                               md->num_pages >> (20 - EFI_PAGE_SHIFT));
@@ -549,8 +573,8 @@ efi_enter_virtual_mode (void)
                md = p;
                if (md->attribute & EFI_MEMORY_RUNTIME) {
                        /*
-                        * Some descriptors have multiple bits set, so the order of
-                        * the tests is relevant.
+                        * Some descriptors have multiple bits set, so the
+                        * order of the tests is relevant.
                         */
                        if (md->attribute & EFI_MEMORY_WB) {
                                md->virt_addr = (u64) __va(md->phys_addr);
@@ -558,21 +582,26 @@ efi_enter_virtual_mode (void)
                                md->virt_addr = (u64) ioremap(md->phys_addr, 0);
                        } else if (md->attribute & EFI_MEMORY_WC) {
 #if 0
-                               md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P
-                                                                          | _PAGE_D
-                                                                          | _PAGE_MA_WC
-                                                                          | _PAGE_PL_0
-                                                                          | _PAGE_AR_RW));
+                               md->virt_addr = ia64_remap(md->phys_addr,
+                                                          (_PAGE_A |
+                                                           _PAGE_P |
+                                                           _PAGE_D |
+                                                           _PAGE_MA_WC |
+                                                           _PAGE_PL_0 |
+                                                           _PAGE_AR_RW));
 #else
                                printk(KERN_INFO "EFI_MEMORY_WC mapping\n");
                                md->virt_addr = (u64) ioremap(md->phys_addr, 0);
 #endif
                        } else if (md->attribute & EFI_MEMORY_WT) {
 #if 0
-                               md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P
-                                                                          | _PAGE_D | _PAGE_MA_WT
-                                                                          | _PAGE_PL_0
-                                                                          | _PAGE_AR_RW));
+                               md->virt_addr = ia64_remap(md->phys_addr,
+                                                          (_PAGE_A |
+                                                           _PAGE_P |
+                                                           _PAGE_D |
+                                                           _PAGE_MA_WT |
+                                                           _PAGE_PL_0 |
+                                                           _PAGE_AR_RW));
 #else
                                printk(KERN_INFO "EFI_MEMORY_WT mapping\n");
                                md->virt_addr = (u64) ioremap(md->phys_addr, 0);
@@ -583,16 +612,18 @@ efi_enter_virtual_mode (void)
 
        status = efi_call_phys(__va(runtime->set_virtual_address_map),
                               ia64_boot_param->efi_memmap_size,
-                              efi_desc_size, ia64_boot_param->efi_memdesc_version,
+                              efi_desc_size,
+                              ia64_boot_param->efi_memdesc_version,
                               ia64_boot_param->efi_memmap);
        if (status != EFI_SUCCESS) {
-               printk(KERN_WARNING "warning: unable to switch EFI into virtual mode "
-                      "(status=%lu)\n", status);
+               printk(KERN_WARNING "warning: unable to switch EFI into "
+                      "virtual mode (status=%lu)\n", status);
                return;
        }
 
        /*
-        * Now that EFI is in virtual mode, we call the EFI functions more efficiently:
+        * Now that EFI is in virtual mode, we call the EFI functions more
+        * efficiently:
         */
        efi.get_time = virt_get_time;
        efi.set_time = virt_set_time;
@@ -606,8 +637,8 @@ efi_enter_virtual_mode (void)
 }
 
 /*
- * Walk the EFI memory map looking for the I/O port range.  There can only be one entry of
- * this type, other I/O port ranges should be described via ACPI.
+ * Walk the EFI memory map looking for the I/O port range.  There can only be
+ * one entry of this type, other I/O port ranges should be described via ACPI.
  */
 u64
 efi_get_iobase (void)
@@ -678,7 +709,6 @@ efi_memmap_intersects (unsigned long phys_addr, unsigned long size)
 
        for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
                md = p;
-
                if (md->phys_addr < end && efi_md_end(md) > phys_addr)
                        return 1;
        }
@@ -731,7 +761,7 @@ efi_mem_attribute (unsigned long phys_addr, unsigned long size)
                if (!md || (md->attribute & ~EFI_MEMORY_RUNTIME) != attr)
                        return 0;
        } while (md);
-       return 0;
+       return 0;       /* never reached */
 }
 
 u64
@@ -767,7 +797,7 @@ kern_mem_attribute (unsigned long phys_addr, unsigned long size)
                if (!md || md->attribute != attr)
                        return 0;
        } while (md);
-       return 0;
+       return 0;       /* never reached */
 }
 EXPORT_SYMBOL(kern_mem_attribute);
 
@@ -883,7 +913,7 @@ efi_uart_console_only(void)
                                return 1;
                        uart = 0;
                }
-               hdr = (struct efi_generic_dev_path *) ((u8 *) hdr + hdr->length);
+               hdr = (struct efi_generic_dev_path *)((u8 *) hdr + hdr->length);
        }
        printk(KERN_ERR "Malformed %s value\n", name);
        return 0;
@@ -921,10 +951,12 @@ find_memmap_space (void)
                if (!efi_wb(md)) {
                        continue;
                }
-               if (pmd == NULL || !efi_wb(pmd) || efi_md_end(pmd) != md->phys_addr) {
+               if (pmd == NULL || !efi_wb(pmd) ||
+                   efi_md_end(pmd) != md->phys_addr) {
                        contig_low = GRANULEROUNDUP(md->phys_addr);
                        contig_high = efi_md_end(md);
-                       for (q = p + efi_desc_size; q < efi_map_end; q += efi_desc_size) {
+                       for (q = p + efi_desc_size; q < efi_map_end;
+                            q += efi_desc_size) {
                                check_md = q;
                                if (!efi_wb(check_md))
                                        break;
@@ -988,8 +1020,9 @@ efi_memmap_init(unsigned long *s, unsigned long *e)
        for (p = efi_map_start; p < efi_map_end; pmd = md, p += efi_desc_size) {
                md = p;
                if (!efi_wb(md)) {
-                       if (efi_uc(md) && (md->type == EFI_CONVENTIONAL_MEMORY ||
-                                          md->type == EFI_BOOT_SERVICES_DATA)) {
+                       if (efi_uc(md) &&
+                           (md->type == EFI_CONVENTIONAL_MEMORY ||
+                            md->type == EFI_BOOT_SERVICES_DATA)) {
                                k->attribute = EFI_MEMORY_UC;
                                k->start = md->phys_addr;
                                k->num_pages = md->num_pages;
@@ -997,10 +1030,12 @@ efi_memmap_init(unsigned long *s, unsigned long *e)
                        }
                        continue;
                }
-               if (pmd == NULL || !efi_wb(pmd) || efi_md_end(pmd) != md->phys_addr) {
+               if (pmd == NULL || !efi_wb(pmd) ||
+                   efi_md_end(pmd) != md->phys_addr) {
                        contig_low = GRANULEROUNDUP(md->phys_addr);
                        contig_high = efi_md_end(md);
-                       for (q = p + efi_desc_size; q < efi_map_end; q += efi_desc_size) {
+                       for (q = p + efi_desc_size; q < efi_map_end;
+                            q += efi_desc_size) {
                                check_md = q;
                                if (!efi_wb(check_md))
                                        break;
@@ -1025,13 +1060,17 @@ efi_memmap_init(unsigned long *s, unsigned long *e)
                if (md->phys_addr < contig_low) {
                        lim = min(efi_md_end(md), contig_low);
                        if (efi_uc(md)) {
-                               if (k > kern_memmap && (k-1)->attribute == EFI_MEMORY_UC &&
+                               if (k > kern_memmap &&
+                                   (k-1)->attribute == EFI_MEMORY_UC &&
                                    kmd_end(k-1) == md->phys_addr) {
-                                       (k-1)->num_pages += (lim - md->phys_addr) >> EFI_PAGE_SHIFT;
+                                       (k-1)->num_pages +=
+                                               (lim - md->phys_addr)
+                                               >> EFI_PAGE_SHIFT;
                                } else {
                                        k->attribute = EFI_MEMORY_UC;
                                        k->start = md->phys_addr;
-                                       k->num_pages = (lim - md->phys_addr) >> EFI_PAGE_SHIFT;
+                                       k->num_pages = (lim - md->phys_addr)
+                                               >> EFI_PAGE_SHIFT;
                                        k++;
                                }
                        }
@@ -1049,7 +1088,8 @@ efi_memmap_init(unsigned long *s, unsigned long *e)
                                } else {
                                        k->attribute = EFI_MEMORY_UC;
                                        k->start = lim;
-                                       k->num_pages = (efi_md_end(md) - lim) >> EFI_PAGE_SHIFT;
+                                       k->num_pages = (efi_md_end(md) - lim)
+                                               >> EFI_PAGE_SHIFT;
                                        k++;
                                }
                        }
@@ -1151,8 +1191,10 @@ efi_initialize_iomem_resources(struct resource *code_resource,
                                break;
                }
 
-               if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
-                       printk(KERN_ERR "failed to alocate resource for iomem\n");
+               if ((res = kzalloc(sizeof(struct resource),
+                                  GFP_KERNEL)) == NULL) {
+                       printk(KERN_ERR
+                              "failed to allocate resource for iomem\n");
                        return;
                }
 
@@ -1187,44 +1229,44 @@ efi_initialize_iomem_resources(struct resource *code_resource,
    rsvd_regions are sorted
  */
 unsigned long __init
-kdump_find_rsvd_region (unsigned long size,
-               struct rsvd_region *r, int n)
+kdump_find_rsvd_region (unsigned long size, struct rsvd_region *r, int n)
 {
-  int i;
-  u64 start, end;
-  u64 alignment = 1UL << _PAGE_SIZE_64M;
-  void *efi_map_start, *efi_map_end, *p;
-  efi_memory_desc_t *md;
-  u64 efi_desc_size;
-
-  efi_map_start = __va(ia64_boot_param->efi_memmap);
-  efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
-  efi_desc_size = ia64_boot_param->efi_memdesc_size;
-
-  for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
-         md = p;
-         if (!efi_wb(md))
-                 continue;
-         start = ALIGN(md->phys_addr, alignment);
-         end = efi_md_end(md);
-         for (i = 0; i < n; i++) {
-               if (__pa(r[i].start) >= start && __pa(r[i].end) < end) {
-                       if (__pa(r[i].start) > start + size)
-                               return start;
-                       start = ALIGN(__pa(r[i].end), alignment);
-                       if (i < n-1 && __pa(r[i+1].start) < start + size)
-                               continue;
-                       else
-                               break;
+       int i;
+       u64 start, end;
+       u64 alignment = 1UL << _PAGE_SIZE_64M;
+       void *efi_map_start, *efi_map_end, *p;
+       efi_memory_desc_t *md;
+       u64 efi_desc_size;
+
+       efi_map_start = __va(ia64_boot_param->efi_memmap);
+       efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
+       efi_desc_size = ia64_boot_param->efi_memdesc_size;
+
+       for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
+               md = p;
+               if (!efi_wb(md))
+                       continue;
+               start = ALIGN(md->phys_addr, alignment);
+               end = efi_md_end(md);
+               for (i = 0; i < n; i++) {
+                       if (__pa(r[i].start) >= start && __pa(r[i].end) < end) {
+                               if (__pa(r[i].start) > start + size)
+                                       return start;
+                               start = ALIGN(__pa(r[i].end), alignment);
+                               if (i < n-1 &&
+                                   __pa(r[i+1].start) < start + size)
+                                       continue;
+                               else
+                                       break;
+                       }
                }
-         }
-         if (end > start + size)
-               return start;
-  }
-
-  printk(KERN_WARNING "Cannot reserve 0x%lx byte of memory for crashdump\n",
-       size);
-  return ~0UL;
+               if (end > start + size)
+                       return start;
+       }
+
+       printk(KERN_WARNING
+              "Cannot reserve 0x%lx byte of memory for crashdump\n", size);
+       return ~0UL;
 }
 #endif
 
index c36f43c9460094cfa72f9f5f73839965481c53fa..f5d3efbfbeda425c8fbe1810f3cadf4dcd72bb9d 100644 (file)
@@ -1586,7 +1586,7 @@ sys_call_table:
        data8 sys_epoll_pwait                   // 1305
        data8 sys_utimensat
        data8 sys_signalfd
-       data8 sys_timerfd
+       data8 sys_ni_syscall
        data8 sys_eventfd
 
        .org sys_call_table + 8*NR_syscalls     // guard against failures to increase NR_syscalls
index 490dab55fba34ea730f9d002858394ab24dd28a0..57d2ee6c83e1e637cd5c587f165834f980fb38a7 100644 (file)
@@ -14,10 +14,10 @@ struct fsyscall_gtod_data_t {
        u32             clk_shift;
        void            *clk_fsys_mmio;
        cycle_t         clk_cycle_last;
-} __attribute__ ((aligned (L1_CACHE_BYTES)));
+} ____cacheline_aligned;
 
 struct itc_jitter_data_t {
        int             itc_jitter;
        cycle_t         itc_lastcycle;
-} __attribute__ ((aligned (L1_CACHE_BYTES)));
+} ____cacheline_aligned;
 
index c3b4412ccc676a85ee76fb0c3a0a436c85b85f68..8e7193d55528754a4ab4553084501056c16790b1 100644 (file)
@@ -12,6 +12,9 @@ EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(strlen);
 
+#include<asm/pgtable.h>
+EXPORT_SYMBOL_GPL(empty_zero_page);
+
 #include <asm/checksum.h>
 EXPORT_SYMBOL(ip_fast_csum);           /* hand-coded assembly */
 EXPORT_SYMBOL(csum_ipv6_magic);
index fc4d2676264f363d766ce4d9b6c5f76176fd4cb4..b618487cdc858b836cee4adb044579bb5cb716f4 100644 (file)
@@ -381,9 +381,10 @@ static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
 static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
 {
        unsigned int i;
-       i = atomic_sub_return(1, &kcb->prev_kprobe_index);
-       __get_cpu_var(current_kprobe) = kcb->prev_kprobe[i].kp;
-       kcb->kprobe_status = kcb->prev_kprobe[i].status;
+       i = atomic_read(&kcb->prev_kprobe_index);
+       __get_cpu_var(current_kprobe) = kcb->prev_kprobe[i-1].kp;
+       kcb->kprobe_status = kcb->prev_kprobe[i-1].status;
+       atomic_sub(1, &kcb->prev_kprobe_index);
 }
 
 static void __kprobes set_current_kprobe(struct kprobe *p,
index 6dbf5919d2d0e7600b9bf9d9fc7f7f7116bb04a8..846e7e036b13c6e717039ccbfd79964cc9063fb0 100644 (file)
@@ -2,61 +2,69 @@
  * File:       mca.c
  * Purpose:    Generic MCA handling layer
  *
- * Updated for latest kernel
  * Copyright (C) 2003 Hewlett-Packard Co
  *     David Mosberger-Tang <davidm@hpl.hp.com>
  *
  * Copyright (C) 2002 Dell Inc.
- * Copyright (C) Matt Domsch (Matt_Domsch@dell.com)
+ * Copyright (C) Matt Domsch <Matt_Domsch@dell.com>
  *
  * Copyright (C) 2002 Intel
- * Copyright (C) Jenna Hall (jenna.s.hall@intel.com)
+ * Copyright (C) Jenna Hall <jenna.s.hall@intel.com>
  *
  * Copyright (C) 2001 Intel
- * Copyright (C) Fred Lewis (frederick.v.lewis@intel.com)
+ * Copyright (C) Fred Lewis <frederick.v.lewis@intel.com>
  *
  * Copyright (C) 2000 Intel
- * Copyright (C) Chuck Fleckenstein (cfleck@co.intel.com)
+ * Copyright (C) Chuck Fleckenstein <cfleck@co.intel.com>
  *
  * Copyright (C) 1999, 2004 Silicon Graphics, Inc.
- * Copyright (C) Vijay Chander(vijay@engr.sgi.com)
+ * Copyright (C) Vijay Chander <vijay@engr.sgi.com>
  *
- * 03/04/15 D. Mosberger Added INIT backtrace support.
- * 02/03/25 M. Domsch  GUID cleanups
+ * Copyright (C) 2006 FUJITSU LIMITED
+ * Copyright (C) Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
  *
- * 02/01/04 J. Hall    Aligned MCA stack to 16 bytes, added platform vs. CPU
- *                     error flag, set SAL default return values, changed
- *                     error record structure to linked list, added init call
- *                     to sal_get_state_info_size().
+ * 2000-03-29 Chuck Fleckenstein <cfleck@co.intel.com>
+ *           Fixed PAL/SAL update issues, began MCA bug fixes, logging issues,
+ *           added min save state dump, added INIT handler.
  *
- * 01/01/03 F. Lewis    Added setup of CMCI and CPEI IRQs, logging of corrected
- *                      platform errors, completed code for logging of
- *                      corrected & uncorrected machine check errors, and
- *                      updated for conformance with Nov. 2000 revision of the
- *                      SAL 3.0 spec.
- * 00/03/29 C. Fleckenstein  Fixed PAL/SAL update issues, began MCA bug fixes, logging issues,
- *                           added min save state dump, added INIT handler.
+ * 2001-01-03 Fred Lewis <frederick.v.lewis@intel.com>
+ *           Added setup of CMCI and CPEI IRQs, logging of corrected platform
+ *           errors, completed code for logging of corrected & uncorrected
+ *           machine check errors, and updated for conformance with Nov. 2000
+ *           revision of the SAL 3.0 spec.
+ *
+ * 2002-01-04 Jenna Hall <jenna.s.hall@intel.com>
+ *           Aligned MCA stack to 16 bytes, added platform vs. CPU error flag,
+ *           set SAL default return values, changed error record structure to
+ *           linked list, added init call to sal_get_state_info_size().
+ *
+ * 2002-03-25 Matt Domsch <Matt_Domsch@dell.com>
+ *           GUID cleanups.
+ *
+ * 2003-04-15 David Mosberger-Tang <davidm@hpl.hp.com>
+ *           Added INIT backtrace support.
  *
  * 2003-12-08 Keith Owens <kaos@sgi.com>
- *            smp_call_function() must not be called from interrupt context (can
- *            deadlock on tasklist_lock).  Use keventd to call smp_call_function().
+ *           smp_call_function() must not be called from interrupt context
+ *           (can deadlock on tasklist_lock).
+ *           Use keventd to call smp_call_function().
  *
  * 2004-02-01 Keith Owens <kaos@sgi.com>
- *            Avoid deadlock when using printk() for MCA and INIT records.
- *            Delete all record printing code, moved to salinfo_decode in user space.
- *            Mark variables and functions static where possible.
- *            Delete dead variables and functions.
- *            Reorder to remove the need for forward declarations and to consolidate
- *            related code.
+ *           Avoid deadlock when using printk() for MCA and INIT records.
+ *           Delete all record printing code, moved to salinfo_decode in user
+ *           space.  Mark variables and functions static where possible.
+ *           Delete dead variables and functions.  Reorder to remove the need
+ *           for forward declarations and to consolidate related code.
  *
  * 2005-08-12 Keith Owens <kaos@sgi.com>
- *           Convert MCA/INIT handlers to use per event stacks and SAL/OS state.
+ *           Convert MCA/INIT handlers to use per event stacks and SAL/OS
+ *           state.
  *
  * 2005-10-07 Keith Owens <kaos@sgi.com>
  *           Add notify_die() hooks.
  *
  * 2006-09-15 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
- *           Add printing support for MCA/INIT.
+ *           Add printing support for MCA/INIT.
  *
  * 2007-04-27 Russ Anderson <rja@sgi.com>
  *           Support multiple cpus going through OS_MCA in the same event.
index 0f5965fcdf85133fbf0c455f714dcbea091eea2d..8bc7d259e0c646313c56e8ac6ee22a8319b81370 100644 (file)
@@ -1,24 +1,28 @@
-//
-// assembly portion of the IA64 MCA handling
-//
-// Mods by cfleck to integrate into kernel build
-// 00/03/15 davidm Added various stop bits to get a clean compile
-//
-// 00/03/29 cfleck Added code to save INIT handoff state in pt_regs format, switch to temp
-//                kstack, switch modes, jump to C INIT handler
-//
-// 02/01/04 J.Hall <jenna.s.hall@intel.com>
-//                Before entering virtual mode code:
-//                1. Check for TLB CPU error
-//                2. Restore current thread pointer to kr6
-//                3. Move stack ptr 16 bytes to conform to C calling convention
-//
-// 04/11/12 Russ Anderson <rja@sgi.com>
-//                Added per cpu MCA/INIT stack save areas.
-//
-// 12/08/05 Keith Owens <kaos@sgi.com>
-//                Use per cpu MCA/INIT stacks for all data.
-//
+/*
+ * File:       mca_asm.S
+ * Purpose:    assembly portion of the IA64 MCA handling
+ *
+ * Mods by cfleck to integrate into kernel build
+ *
+ * 2000-03-15 David Mosberger-Tang <davidm@hpl.hp.com>
+ *             Added various stop bits to get a clean compile
+ *
+ * 2000-03-29 Chuck Fleckenstein <cfleck@co.intel.com>
+ *             Added code to save INIT handoff state in pt_regs format,
+ *             switch to temp kstack, switch modes, jump to C INIT handler
+ *
+ * 2002-01-04 J.Hall <jenna.s.hall@intel.com>
+ *             Before entering virtual mode code:
+ *              1. Check for TLB CPU error
+ *              2. Restore current thread pointer to kr6
+ *              3. Move stack ptr 16 bytes to conform to C calling convention
+ *
+ * 2004-11-12 Russ Anderson <rja@sgi.com>
+ *             Added per cpu MCA/INIT stack save areas.
+ *
+ * 2005-12-08 Keith Owens <kaos@sgi.com>
+ *             Use per cpu MCA/INIT stacks for all data.
+ */
 #include <linux/threads.h>
 
 #include <asm/asmmacro.h>
index aba813c2c150670e808078a4e5866096f523a3db..fab1d21a4f2c1cfe4443aa8812518d4a6bfeaeb6 100644 (file)
@@ -3,7 +3,7 @@
  * Purpose:    Generic MCA handling layer
  *
  * Copyright (C) 2004 FUJITSU LIMITED
- * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
+ * Copyright (C) 2004 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
  * Copyright (C) 2005 Silicon Graphics, Inc
  * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
  * Copyright (C) 2006 Russ Anderson <rja@sgi.com>
index 485e34d0b199333c3ff763f1c22c919628b09575..53b8ecb5b4b9de8b6c08e1a78acdd7ef2a47697c 100644 (file)
@@ -3,7 +3,7 @@
  * Purpose:    Define helpers for Generic MCA handling
  *
  * Copyright (C) 2004 FUJITSU LIMITED
- * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
+ * Copyright (C) 2004 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
  */
 /*
  * Processor error section:
index 3bccb06c8d216cc1439c0f0081e6bacce2668035..767ac2c20d16a1eb28c9a7ec9a6ecea140740a15 100644 (file)
@@ -3,7 +3,7 @@
  * Purpose:     Assembly portion of Generic MCA handling
  *
  * Copyright (C) 2004 FUJITSU LIMITED
- * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
+ * Copyright (C) 2004 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
  */
 #include <linux/threads.h>
 
index 5ae177f557d884dfe75607f6bc55cfb2fe3657a0..78acd9fe97e98263b0cfc431d9b37a71aa594a19 100644 (file)
@@ -2654,11 +2654,11 @@ pfm_get_task(pfm_context_t *ctx, pid_t pid, struct task_struct **task)
        /* XXX: need to add more checks here */
        if (pid < 2) return -EPERM;
 
-       if (pid != current->pid) {
+       if (pid != task_pid_vnr(current)) {
 
                read_lock(&tasklist_lock);
 
-               p = find_task_by_pid(pid);
+               p = find_task_by_vpid(pid);
 
                /* make sure task cannot go away while we operate on it */
                if (p) get_task_struct(p);
@@ -5795,7 +5795,7 @@ pfm_proc_show(struct seq_file *m, void *v)
        return 0;
 }
 
-struct seq_operations pfm_seq_ops = {
+const struct seq_operations pfm_seq_ops = {
        .start =        pfm_proc_start,
        .next =         pfm_proc_next,
        .stop =         pfm_proc_stop,
index 27c2ef445a565abb1cb62c8ae8ff983a4ca6f2fc..f44fe8412162c55b73b80663d8bb3e8d4d3d50a9 100644 (file)
@@ -284,6 +284,7 @@ ia64_sal_cache_flush (u64 cache_type)
        SAL_CALL(isrv, SAL_CACHE_FLUSH, cache_type, 0, 0, 0, 0, 0, 0);
        return isrv.status;
 }
+EXPORT_SYMBOL_GPL(ia64_sal_cache_flush);
 
 void __init
 ia64_sal_init (struct ia64_sal_systab *systab)
@@ -372,3 +373,16 @@ ia64_sal_oemcall_reentrant(struct ia64_sal_retval *isrvp, u64 oemfunc,
        return 0;
 }
 EXPORT_SYMBOL(ia64_sal_oemcall_reentrant);
+
+long
+ia64_sal_freq_base (unsigned long which, unsigned long *ticks_per_second,
+                   unsigned long *drift_info)
+{
+       struct ia64_sal_retval isrv;
+
+       SAL_CALL(isrv, SAL_FREQ_BASE, which, 0, 0, 0, 0, 0, 0);
+       *ticks_per_second = isrv.v0;
+       *drift_info = isrv.v1;
+       return isrv.status;
+}
+EXPORT_SYMBOL_GPL(ia64_sal_freq_base);
index 86028c69861e23373b1162fc20607a858da3b3e3..ebd1a09f32016b870ccb758dac93f1ade566f866 100644 (file)
@@ -654,7 +654,7 @@ c_stop (struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start =        c_start,
        .next =         c_next,
        .stop =         c_stop,
index f0fc4d8465ad172cc9f4f0ce4215de85b3b3a09a..32ee5979a042c35e120ea1bc9fa0acd49bb411c8 100644 (file)
@@ -120,7 +120,6 @@ static volatile unsigned long go[SLAVE + 1];
 
 #define DEBUG_ITC_SYNC 0
 
-extern void __devinit calibrate_delay (void);
 extern void start_ap (void);
 extern unsigned long ia64_iobase;
 
@@ -477,7 +476,7 @@ start_secondary (void *unused)
        return 0;
 }
 
-struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
+struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
 {
        return NULL;
 }
@@ -767,17 +766,6 @@ void __cpu_die(unsigned int cpu)
        }
        printk(KERN_ERR "CPU %u didn't die...\n", cpu);
 }
-#else /* !CONFIG_HOTPLUG_CPU */
-int __cpu_disable(void)
-{
-       return -ENOSYS;
-}
-
-void __cpu_die(unsigned int cpu)
-{
-       /* We said "no" in __cpu_disable */
-       BUG();
-}
 #endif /* CONFIG_HOTPLUG_CPU */
 
 void
index 78d65cb947d29c4fb763c346efed30a307130bfc..f0cda765e681d1252347675d45f582f8ab470b65 100644 (file)
@@ -35,7 +35,7 @@ trap_init (void)
                fpswa_interface = __va(ia64_boot_param->fpswa);
 }
 
-void
+int
 die (const char *str, struct pt_regs *regs, long err)
 {
        static struct {
@@ -62,8 +62,11 @@ die (const char *str, struct pt_regs *regs, long err)
        if (++die.lock_owner_depth < 3) {
                printk("%s[%d]: %s %ld [%d]\n",
                current->comm, task_pid_nr(current), str, err, ++die_counter);
-               (void) notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
-               show_regs(regs);
+               if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
+                   != NOTIFY_STOP)
+                       show_regs(regs);
+               else
+                       regs = NULL;
        } else
                printk(KERN_ERR "Recursive die() failure, output suppressed\n");
 
@@ -72,17 +75,22 @@ die (const char *str, struct pt_regs *regs, long err)
        add_taint(TAINT_DIE);
        spin_unlock_irq(&die.lock);
 
+       if (!regs)
+               return 1;
+
        if (panic_on_oops)
                panic("Fatal exception");
 
        do_exit(SIGSEGV);
+       return 0;
 }
 
-void
+int
 die_if_kernel (char *str, struct pt_regs *regs, long err)
 {
        if (!user_mode(regs))
-               die(str, regs, err);
+               return die(str, regs, err);
+       return 0;
 }
 
 void
@@ -102,7 +110,8 @@ __kprobes ia64_bad_break (unsigned long break_num, struct pt_regs *regs)
                if (notify_die(DIE_BREAK, "break 0", regs, break_num, TRAP_BRKPT, SIGTRAP)
                                == NOTIFY_STOP)
                        return;
-               die_if_kernel("bugcheck!", regs, break_num);
+               if (die_if_kernel("bugcheck!", regs, break_num))
+                       return;
                sig = SIGILL; code = ILL_ILLOPC;
                break;
 
@@ -155,8 +164,9 @@ __kprobes ia64_bad_break (unsigned long break_num, struct pt_regs *regs)
                break;
 
              default:
-               if (break_num < 0x40000 || break_num > 0x100000)
-                       die_if_kernel("Bad break", regs, break_num);
+               if ((break_num < 0x40000 || break_num > 0x100000)
+                   && die_if_kernel("Bad break", regs, break_num))
+                       return;
 
                if (break_num < 0x80000) {
                        sig = SIGILL; code = __ILL_BREAK;
@@ -402,14 +412,15 @@ ia64_illegal_op_fault (unsigned long ec, long arg1, long arg2, long arg3,
 #endif
 
        sprintf(buf, "IA-64 Illegal operation fault");
-       die_if_kernel(buf, &regs, 0);
+       rv.fkt = 0;
+       if (die_if_kernel(buf, &regs, 0))
+               return rv;
 
        memset(&si, 0, sizeof(si));
        si.si_signo = SIGILL;
        si.si_code = ILL_ILLOPC;
        si.si_addr = (void __user *) (regs.cr_iip + ia64_psr(&regs)->ri);
        force_sig_info(SIGILL, &si, current);
-       rv.fkt = 0;
        return rv;
 }
 
@@ -644,6 +655,6 @@ ia64_fault (unsigned long vector, unsigned long isr, unsigned long ifa,
                sprintf(buf, "Fault %lu", vector);
                break;
        }
-       die_if_kernel(buf, &regs, error);
-       force_sig(SIGILL, current);
+       if (!die_if_kernel(buf, &regs, error))
+               force_sig(SIGILL, current);
 }
index f6a1aeb742b3827acce249f7e5c84137678be1e6..52f70bbc192a6faa68ad87bd76bde20b37a6bb73 100644 (file)
@@ -23,7 +23,7 @@
 #include <asm/uaccess.h>
 #include <asm/unaligned.h>
 
-extern void die_if_kernel(char *str, struct pt_regs *regs, long err);
+extern int die_if_kernel(char *str, struct pt_regs *regs, long err);
 
 #undef DEBUG_UNALIGNED_TRAP
 
@@ -675,8 +675,9 @@ emulate_load_updates (update_t type, load_store_t ld, struct pt_regs *regs, unsi
         */
        if (ld.x6_op == 1 || ld.x6_op == 3) {
                printk(KERN_ERR "%s: register update on speculative load, error\n", __FUNCTION__);
-               die_if_kernel("unaligned reference on speculative load with register update\n",
-                             regs, 30);
+               if (die_if_kernel("unaligned reference on speculative load with register update\n",
+                                 regs, 30))
+                       return;
        }
 
 
@@ -1317,7 +1318,8 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
 
        if (ia64_psr(regs)->be) {
                /* we don't support big-endian accesses */
-               die_if_kernel("big-endian unaligned accesses are not supported", regs, 0);
+               if (die_if_kernel("big-endian unaligned accesses are not supported", regs, 0))
+                       return;
                goto force_sigbus;
        }
 
@@ -1534,7 +1536,8 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
                        ia64_handle_exception(regs, eh);
                        goto done;
                }
-               die_if_kernel("error during unaligned kernel access\n", regs, ret);
+               if (die_if_kernel("error during unaligned kernel access\n", regs, ret))
+                       return;
                /* NOT_REACHED */
        }
   force_sigbus:
index 7571076a16a1991742af9f502b2113f7d9bd35a4..3e69881648a35ea1b91536b52eeb9387de9fd8d6 100644 (file)
@@ -16,7 +16,7 @@
 #include <asm/system.h>
 #include <asm/uaccess.h>
 
-extern void die (char *, struct pt_regs *, long);
+extern int die(char *, struct pt_regs *, long);
 
 #ifdef CONFIG_KPROBES
 static inline int notify_page_fault(struct pt_regs *regs, int trap)
@@ -267,9 +267,11 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
        else
                printk(KERN_ALERT "Unable to handle kernel paging request at "
                       "virtual address %016lx\n", address);
-       die("Oops", regs, isr);
+       if (die("Oops", regs, isr))
+               regs = NULL;
        bust_spinlocks(0);
-       do_exit(SIGKILL);
+       if (regs)
+               do_exit(SIGKILL);
        return;
 
   out_of_memory:
index f3c69329e14538934de9c983b422bb9dc52f763a..dfc6bf1c7b412084a6a3038a6b2bb35fb0c1da7d 100644 (file)
@@ -523,7 +523,7 @@ static ssize_t sn2_ptc_proc_write(struct file *file, const char __user *user, si
        return count;
 }
 
-static struct seq_operations sn2_ptc_seq_ops = {
+static const struct seq_operations sn2_ptc_seq_ops = {
        .start = sn2_ptc_seq_start,
        .next = sn2_ptc_seq_next,
        .stop = sn2_ptc_seq_stop,
index 1a8e49607f114e7febdcaa51913bf54527893617..4b0d1538e7e5586450fd2fe39c363af2768bdc35 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/smp_lock.h>
 #include <linux/nodemask.h>
 #include <linux/smp.h>
+#include <linux/mutex.h>
 
 #include <asm/processor.h>
 #include <asm/topology.h>
@@ -50,7 +51,7 @@ static void *sn_hwperf_salheap = NULL;
 static int sn_hwperf_obj_cnt = 0;
 static nasid_t sn_hwperf_master_nasid = INVALID_NASID;
 static int sn_hwperf_init(void);
-static DECLARE_MUTEX(sn_hwperf_init_mutex);
+static DEFINE_MUTEX(sn_hwperf_init_mutex);
 
 #define cnode_possible(n)      ((n) < num_cnodes)
 
@@ -577,7 +578,7 @@ static void sn_topology_stop(struct seq_file *m, void *v)
 /*
  * /proc/sgi_sn/sn_topology, read-only using seq_file
  */
-static struct seq_operations sn_topology_seq_ops = {
+static const struct seq_operations sn_topology_seq_ops = {
        .start = sn_topology_start,
        .next = sn_topology_next,
        .stop = sn_topology_stop,
@@ -884,10 +885,10 @@ static int sn_hwperf_init(void)
        int e = 0;
 
        /* single threaded, once-only initialization */
-       down(&sn_hwperf_init_mutex);
+       mutex_lock(&sn_hwperf_init_mutex);
 
        if (sn_hwperf_salheap) {
-               up(&sn_hwperf_init_mutex);
+               mutex_unlock(&sn_hwperf_init_mutex);
                return e;
        }
 
@@ -936,7 +937,7 @@ out:
                sn_hwperf_salheap = NULL;
                sn_hwperf_obj_cnt = 0;
        }
-       up(&sn_hwperf_init_mutex);
+       mutex_unlock(&sn_hwperf_init_mutex);
        return e;
 }
 
index ab3eaf85fe4d40d3a273ca101e132574f21e74bf..2c676cc05418a76f60a3d888cad8eb9006347de6 100644 (file)
@@ -100,11 +100,11 @@ u16 sn_ioboard_to_pci_bus(struct pci_bus *pci_bus)
 static irqreturn_t
 pcibr_error_intr_handler(int irq, void *arg)
 {
-       struct pcibus_info *soft = (struct pcibus_info *)arg;
+       struct pcibus_info *soft = arg;
 
-       if (sal_pcibr_error_interrupt(soft) < 0) {
+       if (sal_pcibr_error_interrupt(soft) < 0)
                panic("pcibr_error_intr_handler(): Fatal Bridge Error");
-       }
+
        return IRQ_HANDLED;
 }
 
index f7237c5f531e511806133f0223ecd48edb0399ab..795180b8fd8e6199e56d118fec12f09a3079eb35 100644 (file)
@@ -8,6 +8,7 @@ mainmenu "Linux/M32R Kernel Configuration"
 config M32R
        bool
        default y
+       select HAVE_OPROFILE
 
 config SBUS
        bool
@@ -302,8 +303,7 @@ config SMP
          Y to "Enhanced Real Time Clock Support", below. The "Advanced Power
          Management" code will be disabled if you say Y here.
 
-         See also the <file:Documentation/smp.txt>,
-         and the SMP-HOWTO available at
+         See also the SMP-HOWTO available at
          <http://www.linuxdoc.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
@@ -359,11 +359,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.linuxdoc.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 choice
        prompt "PCI access mode"
        depends on PCI
@@ -431,8 +426,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/m32r/Kconfig.debug"
 
 source "security/Kconfig"
index ee3c8be12fa0efba5244d5c1f1b393760f131e89..01d877c6868f05e5a8fb72639a980cd4b7ef66dc 100644 (file)
@@ -17,7 +17,7 @@ static int puts(const char *s)
        return 0;
 }
 
-#if defined(CONFIG_PLAT_M32700UT_Alpha) || defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT)
+#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT)
 #include <asm/m32r.h>
 #include <asm/io.h>
 
@@ -52,7 +52,7 @@ static void putc(char c)
        }
        *BOOT_SIO0TXB = c;
 }
-#else /* !(CONFIG_PLAT_M32700UT_Alpha) && !(CONFIG_PLAT_M32700UT) */
+#else /* !(CONFIG_PLAT_M32700UT) */
 #if defined(CONFIG_PLAT_MAPPI2)
 #define SIO0STS        (volatile unsigned short *)(0xa0efd000 + 14)
 #define SIO0TXB        (volatile unsigned short *)(0xa0efd000 + 30)
index ed4d0756c5dbd0abd84a39bd4b0c43cf20118aea..9aa615d3a5b24372cdd1a193ee7869cd4c5ce78e 100644 (file)
@@ -476,7 +476,7 @@ unregister_debug_trap(struct task_struct *child, unsigned long addr,
                return 0;
        }
 
-       /* Recover orignal instruction code. */
+       /* Recover original instruction code. */
        *code = p->insn[i];
 
        /* Shift debug trap entries. */
index 95aa79874847135989d141c7aa6bf52f3a3ed2cf..aa3bf4cfab37cd8b0f999ba5211baeef6ebae3c3 100644 (file)
@@ -321,6 +321,6 @@ ENTRY(sys_call_table)
        .long sys_epoll_pwait
        .long sys_utimensat             /* 320 */
        .long sys_signalfd
-       .long sys_timerfd
+       .long sys_ni_syscall
        .long sys_eventfd
        .long sys_fallocate
index 01dee84f840ac72608dae4fe0ea4997b3e911f81..ffabd01c45eb1e4309680210cd30821cf4591864 100644 (file)
@@ -145,11 +145,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 config MAC
        bool "Macintosh support"
        depends on !MMU_SUN3
@@ -582,20 +577,6 @@ config MAC_HID
        depends on INPUT_ADBHID
        default y
 
-config MAC_ADBKEYCODES
-       bool "Support for ADB raw keycodes"
-       depends on INPUT_ADBHID
-       help
-         This provides support for sending raw ADB keycodes to console
-         devices.  This is the default up to 2.4.0, but in future this may be
-         phased out in favor of generic Linux keycodes.  If you say Y here,
-         you can dynamically switch via the
-         /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes
-         sysctl and with the "keyboard_sends_linux_keycodes=" kernel
-         argument.
-
-         If unsure, say Y here.
-
 config ADB_KEYBOARD
        bool "Support for ADB keyboard (old driver)"
        depends on MAC && !INPUT_ADBHID
@@ -683,8 +664,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/m68k/Kconfig.debug"
 
 source "security/Kconfig"
index 4a1bd44ff162734a2864bf5c2ebc71a6b64c459f..2cba605cb59d16814bd5685ae4797a15459d1759 100644 (file)
 # Copyright (C) 1994 by Hamish Macdonald
 #
 
-# test for cross compiling
-COMPILE_ARCH = $(shell uname -m)
-
 # override top level makefile
 AS += -m68020
 LDFLAGS := -m m68kelf
 LDFLAGS_MODULE += -T $(srctree)/arch/m68k/kernel/module.lds
-ifneq ($(COMPILE_ARCH),$(ARCH))
-       # prefix for cross-compiling binaries
-       CROSS_COMPILE = m68k-linux-gnu-
+ifneq ($(SUBARCH),$(ARCH))
+       ifeq ($(CROSS_COMPILE),)
+               CROSS_COMPILE := $(call cc-cross-prefix, \
+                       m68k-linux-gnu- m68k-linux- m68k-unknown-linux-gnu-)
+       endif
 endif
 
 ifdef CONFIG_SUN3
index 8b415651edee270475bc4fea87cad9b0d099e0b1..6a0d7650f980fcdcbd5d5ab3b4547f4120bc65b8 100644 (file)
@@ -2,6 +2,6 @@
 # Makefile for Linux arch/m68k/amiga source directory
 #
 
-obj-y          := config.o amiints.o cia.o chipram.o amisound.o amiga_ksyms.o
+obj-y          := config.o amiints.o cia.o chipram.o amisound.o
 
 obj-$(CONFIG_AMIGA_PCMCIA)     += pcmcia.o
diff --git a/arch/m68k/amiga/amiga_ksyms.c b/arch/m68k/amiga/amiga_ksyms.c
deleted file mode 100644 (file)
index 7fdcf6b..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <linux/module.h>
-#include <linux/types.h>
-#include <asm/ptrace.h>
-#include <asm/amigahw.h>
-#include <asm/amigaints.h>
-#include <asm/amipcmcia.h>
-
-extern volatile u_short amiga_audio_min_period;
-extern u_short amiga_audio_period;
-
-/*
- * Add things here when you find the need for it.
- */
-EXPORT_SYMBOL(amiga_model);
-EXPORT_SYMBOL(amiga_chipset);
-EXPORT_SYMBOL(amiga_hw_present);
-EXPORT_SYMBOL(amiga_eclock);
-EXPORT_SYMBOL(amiga_colorclock);
-EXPORT_SYMBOL(amiga_chip_alloc);
-EXPORT_SYMBOL(amiga_chip_free);
-EXPORT_SYMBOL(amiga_chip_avail);
-EXPORT_SYMBOL(amiga_chip_size);
-EXPORT_SYMBOL(amiga_audio_period);
-EXPORT_SYMBOL(amiga_audio_min_period);
-
-#ifdef CONFIG_AMIGA_PCMCIA
-  EXPORT_SYMBOL(pcmcia_reset);
-  EXPORT_SYMBOL(pcmcia_copy_tuple);
-  EXPORT_SYMBOL(pcmcia_program_voltage);
-  EXPORT_SYMBOL(pcmcia_access_speed);
-  EXPORT_SYMBOL(pcmcia_write_enable);
-  EXPORT_SYMBOL(pcmcia_write_disable);
-#endif
index 1f5bfb58429783be182e8aad94d2a5f94eb28d7d..61e5c54625aeee7dd2a3a206e38051c6430ea0bd 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/string.h>
+#include <linux/module.h>
 
 #include <asm/system.h>
 #include <asm/amigahw.h>
@@ -21,7 +22,7 @@ static const signed char sine_data[] = {
        0,  39,  75,  103,  121,  127,  121,  103,  75,  39,
        0, -39, -75, -103, -121, -127, -121, -103, -75, -39
 };
-#define DATA_SIZE      (sizeof(sine_data)/sizeof(sine_data[0]))
+#define DATA_SIZE      ARRAY_SIZE(sine_data)
 
 #define custom amiga_custom
 
@@ -31,6 +32,7 @@ static const signed char sine_data[] = {
      */
 
 volatile unsigned short amiga_audio_min_period = 124; /* Default for pre-OCS */
+EXPORT_SYMBOL(amiga_audio_min_period);
 
 #define MAX_PERIOD     (65535)
 
@@ -40,6 +42,7 @@ volatile unsigned short amiga_audio_min_period = 124; /* Default for pre-OCS */
      */
 
 unsigned short amiga_audio_period = MAX_PERIOD;
+EXPORT_SYMBOL(amiga_audio_period);
 
 static unsigned long clock_constant;
 
index fa015d80161701ccf3e8a390f8e373e072ba08f8..cbe36538af47be5cd2914fe7172ad2ea0f96c026 100644 (file)
 #include <linux/ioport.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/module.h>
+
 #include <asm/page.h>
 #include <asm/amigahw.h>
 
 unsigned long amiga_chip_size;
+EXPORT_SYMBOL(amiga_chip_size);
 
 static struct resource chipram_res = {
     .name = "Chip RAM", .start = CHIP_PHYSADDR
@@ -29,12 +32,10 @@ void __init amiga_chip_init(void)
     if (!AMIGAHW_PRESENT(CHIP_RAM))
        return;
 
-#ifndef CONFIG_APUS_FAST_EXCEPT
     /*
      *  Remove the first 4 pages where PPC exception handlers will be located
      */
     amiga_chip_size -= 0x4000;
-#endif
     chipram_res.end = amiga_chip_size-1;
     request_resource(&iomem_resource, &chipram_res);
 
@@ -67,6 +68,7 @@ void *amiga_chip_alloc(unsigned long size, const char *name)
 #endif
     return (void *)ZTWO_VADDR(res->start);
 }
+EXPORT_SYMBOL(amiga_chip_alloc);
 
 
     /*
@@ -120,6 +122,7 @@ void amiga_chip_free(void *ptr)
     }
     printk("amiga_chip_free: trying to free nonexistent region at %p\n", ptr);
 }
+EXPORT_SYMBOL(amiga_chip_free);
 
 
 unsigned long amiga_chip_avail(void)
@@ -129,3 +132,5 @@ unsigned long amiga_chip_avail(void)
 #endif
        return chipavail;
 }
+EXPORT_SYMBOL(amiga_chip_avail);
+
index c4a4ffd45bc0feeb68c8f84ff3332e1ac7bc4dd9..343fab49bd9a751435ae710bd4e848c9b6abd6ec 100644 (file)
@@ -84,7 +84,7 @@ unsigned char cia_able_irq(struct ciabase *base, unsigned char mask)
 
 static irqreturn_t cia_handler(int irq, void *dev_id)
 {
-       struct ciabase *base = (struct ciabase *)dev_id;
+       struct ciabase *base = dev_id;
        int mach_irq;
        unsigned char ints;
 
index 35748531327dac74710c653017395b73348014fc..50f5daab46b7b53ecb282fc50a6e8bad8f3df2df 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/zorro.h>
+#include <linux/module.h>
 
 #include <asm/bootinfo.h>
 #include <asm/setup.h>
 #include <asm/io.h>
 
 unsigned long amiga_model;
+EXPORT_SYMBOL(amiga_model);
+
 unsigned long amiga_eclock;
+EXPORT_SYMBOL(amiga_eclock);
+
 unsigned long amiga_masterclock;
+
 unsigned long amiga_colorclock;
+EXPORT_SYMBOL(amiga_colorclock);
+
 unsigned long amiga_chipset;
+EXPORT_SYMBOL(amiga_chipset);
+
 unsigned char amiga_vblank;
 unsigned char amiga_psfreq;
+
 struct amiga_hw_present amiga_hw_present;
+EXPORT_SYMBOL(amiga_hw_present);
 
 static char s_a500[] __initdata = "A500";
 static char s_a500p[] __initdata = "A500+";
index 186662ca1a89dd0603d8df5e9865b9d62dddbb32..7106f0c3639bc105ca18fc2cfb777717be7727e5 100644 (file)
@@ -15,6 +15,8 @@
 #include <linux/types.h>
 #include <linux/jiffies.h>
 #include <linux/timer.h>
+#include <linux/module.h>
+
 #include <asm/amigayle.h>
 #include <asm/amipcmcia.h>
 
@@ -30,6 +32,7 @@ void pcmcia_reset(void)
        while (time_before(jiffies, reset_start_time + 1*HZ/100));
        b = gayle_reset;
 }
+EXPORT_SYMBOL(pcmcia_reset);
 
 
 /* copy a tuple, including tuple header. return nb bytes copied */
@@ -61,6 +64,7 @@ int pcmcia_copy_tuple(unsigned char tuple_id, void *tuple, int max_len)
 
        return 0;
 }
+EXPORT_SYMBOL(pcmcia_copy_tuple);
 
 void pcmcia_program_voltage(int voltage)
 {
@@ -84,6 +88,7 @@ void pcmcia_program_voltage(int voltage)
        gayle.config = cfg_byte;
 
 }
+EXPORT_SYMBOL(pcmcia_program_voltage);
 
 void pcmcia_access_speed(int speed)
 {
@@ -101,13 +106,17 @@ void pcmcia_access_speed(int speed)
        cfg_byte = (cfg_byte & 0xf3) | s;
        gayle.config = cfg_byte;
 }
+EXPORT_SYMBOL(pcmcia_access_speed);
 
 void pcmcia_write_enable(void)
 {
        gayle.cardstatus = GAYLE_CS_WR|GAYLE_CS_DA;
 }
+EXPORT_SYMBOL(pcmcia_write_enable);
 
 void pcmcia_write_disable(void)
 {
        gayle.cardstatus = 0;
 }
+EXPORT_SYMBOL(pcmcia_write_disable);
+
index 2cb86191f0aab653f2449b7df16af28346d96d54..2cd905efe63abb15572d653fd6ee71b485c952b3 100644 (file)
@@ -3,7 +3,7 @@
 #
 
 obj-y          := config.o time.o debug.o ataints.o stdma.o \
-                       atasound.o stram.o atari_ksyms.o
+                       atasound.o stram.o
 
 ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_HADES)    += hades-pci.o
index b85ca22024c1bbf2655ad75151e6ea795ec98b6f..b45593a60bddf67bfdb57e611ded063f3b386993 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
+#include <linux/module.h>
 
 #include <asm/system.h>
 #include <asm/traps.h>
@@ -446,6 +447,7 @@ unsigned long atari_register_vme_int(void)
        free_vme_vec_bitmap |= 1 << i;
        return VME_SOURCE_BASE + i;
 }
+EXPORT_SYMBOL(atari_register_vme_int);
 
 
 void atari_unregister_vme_int(unsigned long irq)
@@ -455,5 +457,6 @@ void atari_unregister_vme_int(unsigned long irq)
                free_vme_vec_bitmap &= ~(1 << irq);
        }
 }
+EXPORT_SYMBOL(atari_unregister_vme_int);
 
 
diff --git a/arch/m68k/atari/atari_ksyms.c b/arch/m68k/atari/atari_ksyms.c
deleted file mode 100644 (file)
index a047571..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <linux/module.h>
-
-#include <asm/ptrace.h>
-#include <asm/traps.h>
-#include <asm/atarihw.h>
-#include <asm/atariints.h>
-#include <asm/atarikb.h>
-#include <asm/atari_joystick.h>
-#include <asm/atari_stdma.h>
-#include <asm/atari_stram.h>
-
-extern void atari_microwire_cmd( int cmd );
-extern int atari_MFP_init_done;
-extern int atari_SCC_init_done;
-extern int atari_SCC_reset_done;
-
-EXPORT_SYMBOL(atari_mch_cookie);
-EXPORT_SYMBOL(atari_mch_type);
-EXPORT_SYMBOL(atari_hw_present);
-EXPORT_SYMBOL(atari_switches);
-EXPORT_SYMBOL(atari_dont_touch_floppy_select);
-EXPORT_SYMBOL(atari_register_vme_int);
-EXPORT_SYMBOL(atari_unregister_vme_int);
-EXPORT_SYMBOL(stdma_lock);
-EXPORT_SYMBOL(stdma_release);
-EXPORT_SYMBOL(stdma_others_waiting);
-EXPORT_SYMBOL(stdma_islocked);
-EXPORT_SYMBOL(atari_stram_alloc);
-EXPORT_SYMBOL(atari_stram_free);
-
-EXPORT_SYMBOL(atari_MFP_init_done);
-EXPORT_SYMBOL(atari_SCC_init_done);
-EXPORT_SYMBOL(atari_SCC_reset_done);
-
-EXPORT_SYMBOL(atari_microwire_cmd);
index ee04250eb56bdd38b05724a5e45bb5a518792a61..d266fe89c125e2297fa595140154ac9d2d7cf9a2 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/fcntl.h>
 #include <linux/errno.h>
 #include <linux/mm.h>
+#include <linux/module.h>
 
 #include <asm/atarihw.h>
 #include <asm/system.h>
@@ -43,6 +44,7 @@ void atari_microwire_cmd (int cmd)
        while( tt_microwire.mask != 0x7ff)
                ;
 }
+EXPORT_SYMBOL(atari_microwire_cmd);
 
 
 /* PSG base frequency */
index e40e5dcaa347ab3d0e87dab1a99e0d86d846e479..5945e15055582821ee0b1adcab4d640c8d3b1b56 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/delay.h>
 #include <linux/ioport.h>
 #include <linux/vt_kern.h>
+#include <linux/module.h>
 
 #include <asm/bootinfo.h>
 #include <asm/setup.h>
 #include <asm/io.h>
 
 u_long atari_mch_cookie;
+EXPORT_SYMBOL(atari_mch_cookie);
+
 u_long atari_mch_type;
+EXPORT_SYMBOL(atari_mch_type);
+
 struct atari_hw_present atari_hw_present;
+EXPORT_SYMBOL(atari_hw_present);
+
 u_long atari_switches;
+EXPORT_SYMBOL(atari_switches);
+
 int atari_dont_touch_floppy_select;
+EXPORT_SYMBOL(atari_dont_touch_floppy_select);
+
 int atari_rtc_year_offset;
 
 /* local function prototypes */
index fbeed8c8ecbcfb3df43932f06a442729ddd42fab..043ddbc61c7b1f2c63038a4de7bfd188f2b0ef9c 100644 (file)
 #include <linux/console.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/module.h>
 
 #include <asm/atarihw.h>
 #include <asm/atariints.h>
 
 /* Flag that Modem1 port is already initialized and used */
 int atari_MFP_init_done;
+EXPORT_SYMBOL(atari_MFP_init_done);
+
 /* Flag that Modem1 port is already initialized and used */
 int atari_SCC_init_done;
+EXPORT_SYMBOL(atari_SCC_init_done);
+
 /* Can be set somewhere, if a SCC master reset has already be done and should
  * not be repeated; used by kgdb */
 int atari_SCC_reset_done;
+EXPORT_SYMBOL(atari_SCC_reset_done);
 
 static struct console atari_console_driver = {
        .name   = "debug",
index bee2b1443e368763d9473bc86894b3ed0b60a5b2..2bbabc00870875caf7de565327f26317fe050a66 100644 (file)
@@ -376,8 +376,8 @@ struct pci_bus_info * __init init_hades_pci(void)
         */
 
        bus = kzalloc(sizeof(struct pci_bus_info), GFP_KERNEL);
-       if (!bus)
-               return NULL;
+       if (unlikely(!bus))
+               goto iounmap_base_virt;
 
        /*
         * Claim resources. The m68k has no separate I/O space, both
@@ -385,43 +385,25 @@ struct pci_bus_info * __init init_hades_pci(void)
         * the I/O resources are requested in memory space as well.
         */
 
-       if (request_resource(&iomem_resource, &config_space) != 0)
-       {
-               kfree(bus);
-               return NULL;
-       }
+       if (unlikely(request_resource(&iomem_resource, &config_space) != 0))
+               goto free_bus;
 
-       if (request_resource(&iomem_resource, &io_space) != 0)
-       {
-               release_resource(&config_space);
-               kfree(bus);
-               return NULL;
-       }
+       if (unlikely(request_resource(&iomem_resource, &io_space) != 0))
+               goto release_config_space;
 
        bus->mem_space.start = HADES_MEM_BASE;
        bus->mem_space.end = HADES_MEM_BASE + HADES_MEM_SIZE - 1;
        bus->mem_space.name = pci_mem_name;
 #if 1
-       if (request_resource(&iomem_resource, &bus->mem_space) != 0)
-       {
-               release_resource(&io_space);
-               release_resource(&config_space);
-               kfree(bus);
-               return NULL;
-       }
+       if (unlikely(request_resource(&iomem_resource, &bus->mem_space) != 0))
+               goto release_io_space;
 #endif
        bus->io_space.start = pci_io_base_virt;
        bus->io_space.end = pci_io_base_virt + HADES_VIRT_IO_SIZE - 1;
        bus->io_space.name = pci_io_name;
 #if 1
-       if (request_resource(&ioport_resource, &bus->io_space) != 0)
-       {
-               release_resource(&bus->mem_space);
-               release_resource(&io_space);
-               release_resource(&config_space);
-               kfree(bus);
-               return NULL;
-       }
+       if (unlikely(request_resource(&ioport_resource, &bus->io_space) != 0))
+               goto release_bus_mem_space;
 #endif
        /*
         * Set hardware dependent functions.
@@ -438,5 +420,21 @@ struct pci_bus_info * __init init_hades_pci(void)
        tt_mfp.active_edge &= ~0x27;
 
        return bus;
+
+release_bus_mem_space:
+       release_resource(&bus->mem_space);
+release_io_space:
+       release_resource(&io_space);
+release_config_space:
+       release_resource(&config_space);
+free_bus:
+       kfree(bus);
+iounmap_base_virt:
+       iounmap((void *)pci_io_base_virt);
+
+       for (i = 0; i < N_SLOTS; i++)
+               iounmap((void *)pci_conf_base_virt[i]);
+
+       return NULL;
 }
 #endif
index ab3fd5202b2477c5624e4a23fbac11f78e7063bb..d1bd029a34ac612acfe5b04936a8dab1821ce2de 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/wait.h>
+#include <linux/module.h>
 
 #include <asm/atari_stdma.h>
 #include <asm/atariints.h>
@@ -91,6 +92,7 @@ void stdma_lock(irq_handler_t handler, void *data)
        stdma_isr_data = data;
        local_irq_restore(flags);
 }
+EXPORT_SYMBOL(stdma_lock);
 
 
 /*
@@ -117,6 +119,7 @@ void stdma_release(void)
 
        local_irq_restore(flags);
 }
+EXPORT_SYMBOL(stdma_release);
 
 
 /*
@@ -134,6 +137,7 @@ int stdma_others_waiting(void)
 {
        return waitqueue_active(&stdma_wait);
 }
+EXPORT_SYMBOL(stdma_others_waiting);
 
 
 /*
@@ -155,6 +159,7 @@ int stdma_islocked(void)
 {
        return stdma_locked;
 }
+EXPORT_SYMBOL(stdma_islocked);
 
 
 /*
index bf4588cbe3711bca7125a1d1167541ec76fe0531..8dda6515887affd45d33a55981329f5125eda9ba 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/bootmem.h>
 #include <linux/mount.h>
 #include <linux/blkdev.h>
+#include <linux/module.h>
 
 #include <asm/setup.h>
 #include <asm/machdep.h>
@@ -208,6 +209,7 @@ void *atari_stram_alloc(long size, const char *owner)
        }
        return( addr );
 }
+EXPORT_SYMBOL(atari_stram_alloc);
 
 void atari_stram_free( void *addr )
 
@@ -237,6 +239,7 @@ void atari_stram_free( void *addr )
        printk( KERN_ERR "atari_stram_free: cannot free block at %p "
                        "(called from %p)\n", addr, __builtin_return_address(0) );
 }
+EXPORT_SYMBOL(atari_stram_free);
 
 \f
 /* ------------------------------------------------------------------------ */
index 15b80abfe94a53e2462926f26d2417bed1113ceb..ff9dffa5b860c35f4458d6fc6cb8e82b922940fd 100644 (file)
@@ -678,7 +678,6 @@ CONFIG_LOGO_MAC_CLUT224=y
 #
 CONFIG_MAC_SCC=y
 CONFIG_MAC_HID=y
-CONFIG_MAC_ADBKEYCODES=y
 CONFIG_SERIAL_CONSOLE=y
 
 #
index 288b9c67c9bf4a19f024ff892ce3f7a24d91ac63..96d4244c82fd269c8b52506c4c097a7856631dcc 100644 (file)
@@ -2,4 +2,4 @@
 # Makefile for Linux arch/m68k/hp300 source directory
 #
 
-obj-y          := ksyms.o config.o time.o reboot.o
+obj-y          := config.o time.o reboot.o
diff --git a/arch/m68k/hp300/ksyms.c b/arch/m68k/hp300/ksyms.c
deleted file mode 100644 (file)
index 8202830..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- *  linux/arch/m68k/hp300/ksyms.c
- *
- *  Copyright (C) 1998 Philip Blundell <philb@gnu.org>
- *
- *  This file contains the HP300-specific kernel symbols.  None yet. :-)
- */
-
-#include <linux/module.h>
index 918f5dbeaef6c32dcea4aba039298a93ca99b2be..6dfa3b3c0e2a737d0b128e33cc1e6965e1aa8d00 100644 (file)
@@ -742,7 +742,7 @@ sys_call_table:
        .long sys_epoll_pwait           /* 315 */
        .long sys_utimensat
        .long sys_signalfd
-       .long sys_timerfd
+       .long sys_ni_syscall
        .long sys_eventfd
        .long sys_fallocate             /* 320 */
 
index 995a09d912f57abe14dd0367096913c2177c9a58..1d265ba365ad37fd58a6617cdd90986395606048 100644 (file)
@@ -3,4 +3,4 @@
 #
 
 obj-y          := config.o bootparse.o macints.o iop.o via.o oss.o psc.o \
-                       baboon.o macboing.o debug.o misc.o mac_ksyms.o
+                       baboon.o macboing.o debug.o misc.o
index 01b468b9392ec68cb1aade95d598adb06a51cdc5..735a49b4b9366b0345db8cc954a824e4b0ff5cb1 100644 (file)
@@ -58,8 +58,6 @@ extern struct mem_info m68k_memory[NUM_MEMINFO];
 
 extern struct mem_info m68k_ramdisk;
 
-extern char m68k_command_line[CL_SIZE];
-
 void *mac_env;                                 /* Loaded by the boot asm */
 
 /* The phys. video addr. - might be bogus on some machines */
diff --git a/arch/m68k/mac/mac_ksyms.c b/arch/m68k/mac/mac_ksyms.c
deleted file mode 100644 (file)
index 6e37ceb..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <linux/module.h>
-#include <asm/ptrace.h>
-#include <asm/traps.h>
-
-/* Says whether we're using A/UX interrupts or not */
-extern int via_alt_mapping;
-
-EXPORT_SYMBOL(via_alt_mapping);
index 8df270e950fabead2b0f0a2f2cf247d6fb02c41b..fa485df4160e7f7298359642de3cebde58196ab0 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/ide.h>
+#include <linux/module.h>
 
 #include <asm/bootinfo.h>
 #include <asm/macintosh.h>
@@ -41,7 +42,9 @@ volatile __u8 *via1, *via2;
 /* See note in mac_via.h about how this is possibly not useful */
 volatile long *via_memory_bogon=(long *)&via_memory_bogon;
 #endif
-int rbv_present, via_alt_mapping;
+int rbv_present;
+int via_alt_mapping;
+EXPORT_SYMBOL(via_alt_mapping);
 __u8 rbv_clear;
 
 /*
index 950e82f216408d889a493ccd275fb356624acbfe..edb3f6e6ee6acbfe6d3a4912595553a3c212d570 100644 (file)
@@ -2,4 +2,4 @@
 # Makefile for Linux arch/m68k/mvme16x source directory
 #
 
-obj-y          := config.o rtc.o mvme16x_ksyms.o
+obj-y          := config.o rtc.o
index daa7851614013c385b7c9f4660120f716849d39b..24cbc3030454aed4a76e847cfed91f415d8fc33b 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/genhd.h>
 #include <linux/rtc.h>
 #include <linux/interrupt.h>
+#include <linux/module.h>
 
 #include <asm/bootinfo.h>
 #include <asm/system.h>
@@ -58,6 +59,7 @@ static irq_handler_t tick_handler;
 
 
 unsigned short mvme16x_config;
+EXPORT_SYMBOL(mvme16x_config);
 
 
 int mvme16x_parse_bootinfo(const struct bi_record *bi)
diff --git a/arch/m68k/mvme16x/mvme16x_ksyms.c b/arch/m68k/mvme16x/mvme16x_ksyms.c
deleted file mode 100644 (file)
index 4a8a363..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <linux/module.h>
-#include <linux/types.h>
-#include <asm/ptrace.h>
-#include <asm/mvme16xhw.h>
-
-EXPORT_SYMBOL(mvme16x_config);
index bd9213749ac27e228e6ac2dc07603bca7ef2f70a..6abbbb8aac5ebc733f7e4eb8cc8df3df6ef3959c 100644 (file)
@@ -711,8 +711,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/m68knommu/Kconfig.debug"
 
 source "security/Kconfig"
index 9ff47bd09aee0027362a2dbcd75194add548fab9..ed6d9a83bfdb79399547124794efd2bdef17138d 100644 (file)
@@ -21,13 +21,6 @@ config BOOTPARAM_STRING
        default 'console=ttyS0,19200'
        depends on BOOTPARAM
 
-config DUMPTOFLASH
-       bool "Panic/Dump to FLASH"
-       depends on COLDFIRE
-       help
-         Dump any panic of trap output into a flash memory segment
-         for later analysis.
-
 config NO_KERNEL_MSG
        bool "Suppress Kernel BUG Messages"
        help
index 5a0ecaaee3b08132b89c5e9a67b43510e959dae9..648113075f9722cf0be3c657c7fc28554d533028 100644 (file)
@@ -597,7 +597,6 @@ CONFIG_MSDOS_PARTITION=y
 # CONFIG_FULLDEBUG is not set
 # CONFIG_HIGHPROFILE is not set
 # CONFIG_BOOTPARAM is not set
-# CONFIG_DUMPTOFLASH is not set
 # CONFIG_NO_KERNEL_MSG is not set
 # CONFIG_BDM_DISABLE is not set
 
index f795062aba1e31760b659ce0c3d065078eceeaf5..53fad149028277b8d68c554969c679faed524734 100644 (file)
@@ -24,14 +24,6 @@ extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);
 EXPORT_SYMBOL(__ioremap);
 EXPORT_SYMBOL(iounmap);
 EXPORT_SYMBOL(dump_fpu);
-EXPORT_SYMBOL(strnlen);
-EXPORT_SYMBOL(strrchr);
-EXPORT_SYMBOL(strstr);
-EXPORT_SYMBOL(strchr);
-EXPORT_SYMBOL(strcat);
-EXPORT_SYMBOL(strlen);
-EXPORT_SYMBOL(strcmp);
-EXPORT_SYMBOL(strncmp);
 
 EXPORT_SYMBOL(ip_fast_csum);
 
@@ -46,9 +38,6 @@ EXPORT_SYMBOL(csum_partial_copy_nocheck);
    it's OK to leave it out of version control.  */
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memset);
-EXPORT_SYMBOL(memcmp);
-EXPORT_SYMBOL(memscan);
-EXPORT_SYMBOL(memmove);
 
 EXPORT_SYMBOL(__down_failed);
 EXPORT_SYMBOL(__down_failed_interruptible);
index 332345d7675d878f85ab53714927e68140807368..81507c53d4a9b7cfce58de6bc0f4ee8f07bbccae 100644 (file)
@@ -64,9 +64,6 @@ void (*mach_power_off)(void);
 #ifdef CONFIG_M68VZ328
        #define CPU "MC68VZ328"
 #endif
-#ifdef CONFIG_M68332
-       #define CPU "MC68332"
-#endif
 #ifdef CONFIG_M68360
        #define CPU "MC68360"
 #endif
index 9620093514bcb51533ce958bebd9156e45fd7318..1b02b88200680c8ebbec377d4c67b56622bc1595 100644 (file)
@@ -336,7 +336,7 @@ ENTRY(sys_call_table)
        .long sys_epoll_pwait           /* 315 */
        .long sys_utimensat
        .long sys_signalfd
-       .long sys_timerfd
+       .long sys_ni_syscall
        .long sys_eventfd
        .long sys_fallocate             /* 320 */
 
index 0d5577569e4c7230b42db6ebcfe7968ce24f6474..b50dbcad47464534688b7414997d488e4ba721bd 100644 (file)
@@ -1,6 +1,5 @@
 
 #include <linux/types.h>
-#include <linux/autoconf.h>
 
 void * memcpy(void * to, const void * from, size_t n)
 {
index 4fad0a34b9974d31f16b5e1e6a8bb6e3c067e710..ec78a5762e9ec3be6a23630413c4f81a5f6b0fe9 100644 (file)
@@ -1,6 +1,7 @@
 config MIPS
        bool
        default y
+       select HAVE_OPROFILE
        # Horrible source of confusion.  Die, die, die ...
        select EMBEDDED
        select RTC_LIB
@@ -1754,8 +1755,8 @@ config SMP
          People using multiprocessor machines who say Y here should also say
          Y to "Enhanced Real Time Clock Support", below.
 
-         See also the <file:Documentation/smp.txt> and the SMP-HOWTO
-         available at <http://www.tldp.org/docs.html#howto>.
+         See also the SMP-HOWTO available at
+         <http://www.tldp.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
 
@@ -1961,11 +1962,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, or VESA. If you have PCI,
          say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 config PCI_DOMAINS
        bool
 
@@ -2086,6 +2082,10 @@ endmenu
 
 menu "Power management options"
 
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+       depends on !SMP
+
 source "kernel/power/Kconfig"
 
 endmenu
@@ -2096,8 +2096,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/mips/Kconfig.debug"
 
 source "security/Kconfig"
index 8527856aec45c2c36dff1a15b83ef2d12ca97571..0b658f1db4cedde3021e4eea3916091b36e4ab87 100644 (file)
@@ -27,7 +27,6 @@
  *     others have a second one : GPIO2
  */
 
-#include <linux/autoconf.h>
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/types.h>
index abfc4bcddf7a4569d7783f5de5603cb1f6e88a6a..310d5dff89fca6347f34ce38e112dbf2116a87f6 100644 (file)
@@ -99,7 +99,7 @@ mtx1_pci_idsel(unsigned int devsel, int assert)
 #endif
 
        if (assert && devsel != 0) {
-               // supress signal to cardbus
+               // suppress signal to cardbus
                au_writel( 0x00000002, SYS_OUTPUTCLR ); // set EXT_IO3 OFF
        }
        else {
index 9b34238d41c09d7a91887469fc3ff02eef223704..77db3473deabfc20c97acb99d89dbd77c96b9170 100644 (file)
@@ -98,7 +98,7 @@ static __inline__ void
 jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
 {
        /*
-        * Convert jiffies to nanoseconds and seperate with
+        * Convert jiffies to nanoseconds and separate with
         * one divide.
         */
        u64 nsec = (u64)jiffies * TICK_NSEC;
index da41eac195ca0197b332824205cd47e31d4231b9..08f4cd781ee33cc5ac695fed9705a33e7e507e65 100644 (file)
@@ -100,7 +100,7 @@ static inline void
 jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
 {
        /*
-        * Convert jiffies to nanoseconds and seperate with
+        * Convert jiffies to nanoseconds and separate with
         * one divide.
         */
        u64 nsec = (u64)jiffies * TICK_NSEC;
index f6704ab16306a91b5b2b654d3dcc312b5a437648..998c4efcce88df4acb15485d529badd73a0782eb 100644 (file)
@@ -221,7 +221,7 @@ void sp_work_handle_request(void)
                }
        }
 
-       /* Run the syscall at the priviledge of the user who loaded the
+       /* Run the syscall at the privilege of the user who loaded the
           SP program */
 
        if (vpe_getuid(tclimit))
index 82480a1717d892eb6b07db692055c643851c0e44..f798139e888e144943870740b20b9cb812ef0543 100644 (file)
@@ -660,7 +660,7 @@ einval:     li      v0, -EINVAL
        sys     sys_ioprio_get          2       /* 4315 */
        sys     sys_utimensat           4
        sys     sys_signalfd            3
-       sys     sys_timerfd             4
+       sys     sys_ni_syscall          0
        sys     sys_eventfd             1
        sys     sys_fallocate           6       /* 4320 */
        .endm
index c2c10876da2e2a85d4ad9299111bddf004fb58f6..a626be6baea38e477ca76a444bb8326979cec1ae 100644 (file)
@@ -475,7 +475,7 @@ sys_call_table:
        PTR     sys_ioprio_get
        PTR     sys_utimensat                   /* 5275 */
        PTR     sys_signalfd
-       PTR     sys_timerfd
+       PTR     sys_ni_syscall
        PTR     sys_eventfd
        PTR     sys_fallocate
        .size   sys_call_table,.-sys_call_table
index 01993ec3368b5344caabcca54f8b1bc75e7641bc..9d5bcaf1b3890e35ba92a1ccbba03d2ec42f41ea 100644 (file)
@@ -401,7 +401,7 @@ EXPORT(sysn32_call_table)
        PTR     sys_ioprio_get
        PTR     compat_sys_utimensat
        PTR     compat_sys_signalfd             /* 5280 */
-       PTR     compat_sys_timerfd
+       PTR     sys_ni_syscall
        PTR     sys_eventfd
        PTR     sys_fallocate
        .size   sysn32_call_table,.-sysn32_call_table
index dd68afce7da5782dc0f59766b04eb3afcb7eb647..fd2019c1ec2d65e9a9532ece52a60828025090bf 100644 (file)
@@ -523,7 +523,7 @@ sys_call_table:
        PTR     sys_ioprio_get                  /* 4315 */
        PTR     compat_sys_utimensat
        PTR     compat_sys_signalfd
-       PTR     compat_sys_timerfd
+       PTR     sys_ni_syscall
        PTR     sys_eventfd
        PTR     sys32_fallocate                 /* 4320 */
        .size   sys_call_table,.-sys_call_table
index 269c252d956f42c1d74ec85162af510c3e986141..c032409cba9b50b7df4bfad7988dd26ad0d00213 100644 (file)
@@ -424,13 +424,13 @@ static void __init bootmem_init(void)
 #endif /* CONFIG_SGI_IP27 */
 
 /*
- * arch_mem_init - initialize memory managment subsystem
+ * arch_mem_init - initialize memory management subsystem
  *
  *  o plat_mem_setup() detects the memory configuration and will record detected
  *    memory areas using add_memory_region.
  *
  * At this stage the memory configuration of the system is known to the
- * kernel but generic memory managment system is still entirely uninitialized.
+ * kernel but generic memory management system is still entirely uninitialized.
  *
  *  o bootmem_init()
  *  o sparse_init()
index 1e5dfc28294a48efac28259fc610c37db4b257e0..9d41dab90a809732e1c2eab6ed234e989d5637cd 100644 (file)
@@ -52,7 +52,6 @@ int __cpu_logical_map[NR_CPUS];               /* Map logical to physical */
 EXPORT_SYMBOL(phys_cpu_present_map);
 EXPORT_SYMBOL(cpu_online_map);
 
-extern void __init calibrate_delay(void);
 extern void cpu_idle(void);
 
 /* Number of TCs (or siblings in Intel speak) per CPU core */
index 85f700e581316df1a2e4d735e89a767d89fddd12..b42e71c711199a4f169f717e8467240b8ebbae57 100644 (file)
@@ -65,7 +65,7 @@ asiduse smtc_live_asid[MAX_SMTC_TLBS][MAX_SMTC_ASIDS];
 static atomic_t ipi_timer_latch[NR_CPUS];
 
 /*
- * Number of InterProcessor Interupt (IPI) message buffers to allocate
+ * Number of InterProcessor Interrupt (IPI) message buffers to allocate
  */
 
 #define IPIBUF_PER_CPU 4
@@ -780,7 +780,7 @@ void smtc_send_ipi(int cpu, int type, unsigned int action)
        if (cpu_data[cpu].vpe_id != cpu_data[smp_processor_id()].vpe_id) {
                if (type == SMTC_CLOCK_TICK)
                        atomic_inc(&ipi_timer_latch[cpu]);
-               /* If not on same VPE, enqueue and send cross-VPE interupt */
+               /* If not on same VPE, enqueue and send cross-VPE interrupt */
                smtc_ipi_nq(&IPIQ[cpu], pipi);
                LOCK_CORE_PRA();
                settc(cpu_data[cpu].tc_id);
@@ -1063,7 +1063,7 @@ static void setup_cross_vpe_interrupts(unsigned int nvpe)
                return;
 
        if (!cpu_has_vint)
-               panic("SMTC Kernel requires Vectored Interupt support");
+               panic("SMTC Kernel requires Vectored Interrupt support");
 
        set_vi_handler(MIPS_CPU_IPI_IRQ, ipi_irq_dispatch);
 
index 4c477c7ff74a1388c21a85392ed19ac7033cbeec..22fd41e946b28c3d9e2a8a853c4951bcada5b629 100644 (file)
@@ -356,7 +356,7 @@ asmlinkage int irix_syssgi(struct pt_regs *regs)
                        retval = NGROUPS_MAX;
                        goto out;
                case 5:
-                       retval = NR_OPEN;
+                       retval = sysctl_nr_open;
                        goto out;
                case 6:
                        retval = 1;
index 02bd180f0e02748354383af23352900da6d1b02b..53ec05267a98190739ac454d217f4e12a9f34e90 100644 (file)
@@ -1101,7 +1101,7 @@ static void __init setup_scache(void)
        /*
         * Do the probing thing on R4000SC and R4400SC processors.  Other
         * processors don't have a S-cache that would be relevant to the
-        * Linux memory managment.
+        * Linux memory management.
         */
        switch (c->cputype) {
        case CPU_R4000SC:
index 524b371f9397ae2bff5eb527614666c866f31343..a1fa4abb3f6a719ad0122a0861f3b2d659d293a4 100644 (file)
@@ -168,7 +168,7 @@ static void hub_set_piomode(nasid_t nasid)
 }
 
 /*
- * hub_pio_init  -  PIO-related hub initalization
+ * hub_pio_init  -  PIO-related hub initialization
  *
  * @hub:       hubinfo structure for our hub
  */
index 2b649c46631c14fb07d408dd3bad2e0869a8dae6..028d8a0fdbfd2b3213c183a5f6a371211fe55833 100644 (file)
@@ -7,6 +7,7 @@ mainmenu "Linux/PA-RISC Kernel Configuration"
 
 config PARISC
        def_bool y
+       select HAVE_OPROFILE
        help
          The PA-RISC microprocessor is designed by Hewlett-Packard and used
          in many of their workstations & servers (HP9000 700 and 800 series,
@@ -205,9 +206,8 @@ config SMP
          singleprocessor machines. On a singleprocessor machine, the kernel
          will run faster if you say N here.
 
-         See also the <file:Documentation/smp.txt>,
-         <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available
-         at <http://www.tldp.org/docs.html#howto>.
+         See also <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO
+         available at <http://www.tldp.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
 
@@ -272,8 +272,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/parisc/Kconfig.debug"
 
 source "security/Kconfig"
index 9166bd1172675c2cbadd1c80de98042005e6c30b..bc989e522a045c17ca4514478b7cb5ef9d77fc4d 100644 (file)
@@ -2,15 +2,6 @@ menu "Kernel hacking"
 
 source "lib/Kconfig.debug"
 
-config DEBUG_RWLOCK
-        bool "Read-write spinlock debugging"
-        depends on DEBUG_KERNEL && SMP
-        help
-          If you say Y here then read-write lock processing will count how many
-          times it has tried to get the lock and issue an error message after
-          too many attempts.  If you suspect a rwlock problem or a kernel
-          hacker asks for this option then say Y.  Otherwise say N.
-
 config DEBUG_RODATA
        bool "Write protect kernel read-only data structures"
        depends on DEBUG_KERNEL
index ea071218a3ed2cf68b4e1e98e7fa91ac2355101b..ddacc72e38fb8e92b1bac2a1d5cc30743924f75d 100644 (file)
@@ -1050,7 +1050,6 @@ CONFIG_SCHED_DEBUG=y
 CONFIG_FORCED_INLINING=y
 # CONFIG_RCU_TORTURE_TEST is not set
 # CONFIG_FAULT_INJECTION is not set
-# CONFIG_DEBUG_RWLOCK is not set
 # CONFIG_DEBUG_RODATA is not set
 
 #
index 395bbce649937e627315a3d3796a17fb2fe256f8..e10d25d2d9c935b6049d16a81a5efc02903018b2 100644 (file)
@@ -305,7 +305,7 @@ flush_user_cache_page_non_current(struct vm_area_struct *vma,
        /* save the current process space and pgd */
        unsigned long space = mfsp(3), pgd = mfctl(25);
 
-       /* we don't mind taking interrups since they may not
+       /* we don't mind taking interrupts since they may not
         * do anything with user space, but we can't
         * be preempted here */
        preempt_disable();
index 04848b2b381c40c8cc10e387281baf66dfc9c3c6..84b9611a92285b8edcbab9fffc20fdbca6662d7c 100644 (file)
@@ -1187,7 +1187,7 @@ static struct hp_hardware hp_hardware_list[] __devinitdata = {
        {HPHW_FIO, 0x005, 0x000A9, 0x00, "AllegroLow Core PCI USB KB"}, 
        {HPHW_FIO, 0x006, 0x000A9, 0x00, "AllegroHigh Core PCI SuperIO RS-232"}, 
        {HPHW_FIO, 0x006, 0x000A9, 0x00, "AllegroHigh Core PCI USB KB"}, 
-       {HPHW_FIO, 0x007, 0x000A9, 0x0, "Miscelaneous PCI Plug-in"}, 
+       {HPHW_FIO, 0x007, 0x000A9, 0x0, "Miscellaneous PCI Plug-in"},
        {HPHW_FIO, 0x00A, 0x000A9, 0x0, "Lego 360 Core PCI SuperIO RS-232"}, 
        {HPHW_FIO, 0x00A, 0x000A9, 0x0, "Lego 360 Core PCI USB KB"}, 
        {HPHW_FIO, 0x004, 0x00320, 0x0, "Metheus Frame Buffer"}, 
index 2ce3806f02e1989d5157ac9c9a3a037f40a384fc..58fccc96d0035362aaada7b17521c1346bb15a61 100644 (file)
@@ -333,7 +333,7 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
        flush_user_icache_range((unsigned long) &frame->tramp[0],
                           (unsigned long) &frame->tramp[TRAMP_SIZE]);
 
-       /* TRAMP Words 0-4, Lenght 5 = SIGRESTARTBLOCK_TRAMP
+       /* TRAMP Words 0-4, Length 5 = SIGRESTARTBLOCK_TRAMP
         * TRAMP Words 5-9, Length 4 = SIGRETURN_TRAMP
         * So the SIGRETURN_TRAMP is at the end of SIGRESTARTBLOCK_TRAMP
         */
index 9c44af3db8d9e542f88f4c1c3df3caee21c447f0..cf030b00441507166720db089caf700cd3691181 100644 (file)
@@ -87,6 +87,8 @@ config ARCH_NO_VIRT_TO_BUS
 config PPC
        bool
        default y
+       select HAVE_OPROFILE
+       select HAVE_KPROBES
 
 config EARLY_PRINTK
        bool
@@ -151,11 +153,25 @@ config DEFAULT_UIMAGE
 config REDBOOT
        bool
 
-config PPC64_SWSUSP
+config HIBERNATE_32
        bool
-       depends on PPC64 && (BROKEN || (PPC_PMAC64 && EXPERIMENTAL))
+       depends on (PPC_PMAC && !SMP) || BROKEN
        default y
 
+config HIBERNATE_64
+       bool
+       depends on BROKEN || (PPC_PMAC64 && EXPERIMENTAL)
+       default y
+
+config ARCH_HIBERNATION_POSSIBLE
+       bool
+       depends on (PPC64 && HIBERNATE_64) || (PPC32 && HIBERNATE_32)
+       default y
+
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+       depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200
+
 config PPC_DCR_NATIVE
        bool
        default n
@@ -240,6 +256,9 @@ config IOMMU_VMERGE
 
          Most drivers don't have this problem; it is safe to say Y here.
 
+config IOMMU_HELPER
+       def_bool PPC64
+
 config HOTPLUG_CPU
        bool "Support for enabling/disabling CPUs"
        depends on SMP && HOTPLUG && EXPERIMENTAL && (PPC_PSERIES || PPC_PMAC)
@@ -391,6 +410,10 @@ config CMDLINE
          most cases you will need to specify the root device here.
 
 if !44x || BROKEN
+config ARCH_WANTS_FREEZER_CONTROL
+       def_bool y
+       depends on ADB_PMU
+
 source kernel/power/Kconfig
 endif
 
@@ -695,8 +718,6 @@ source "arch/powerpc/sysdev/qe_lib/Kconfig"
 
 source "lib/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/powerpc/Kconfig.debug"
 
 source "security/Kconfig"
index 84239076a5b8e8092e7ad2d607ba16b0e0cff7a9..3a317cb0636a4f572790982648b65c077bb84b30 100644 (file)
@@ -31,8 +31,8 @@ static inline unsigned long device_to_mask(struct device *dev)
 static void *dma_iommu_alloc_coherent(struct device *dev, size_t size,
                                      dma_addr_t *dma_handle, gfp_t flag)
 {
-       return iommu_alloc_coherent(dev->archdata.dma_data, size, dma_handle,
-                                   device_to_mask(dev), flag,
+       return iommu_alloc_coherent(dev, dev->archdata.dma_data, size,
+                                   dma_handle, device_to_mask(dev), flag,
                                    dev->archdata.numa_node);
 }
 
@@ -52,7 +52,7 @@ static dma_addr_t dma_iommu_map_single(struct device *dev, void *vaddr,
                                       size_t size,
                                       enum dma_data_direction direction)
 {
-       return iommu_map_single(dev->archdata.dma_data, vaddr, size,
+       return iommu_map_single(dev, dev->archdata.dma_data, vaddr, size,
                                device_to_mask(dev), direction);
 }
 
@@ -68,7 +68,7 @@ static void dma_iommu_unmap_single(struct device *dev, dma_addr_t dma_handle,
 static int dma_iommu_map_sg(struct device *dev, struct scatterlist *sglist,
                            int nelems, enum dma_data_direction direction)
 {
-       return iommu_map_sg(dev->archdata.dma_data, sglist, nelems,
+       return iommu_map_sg(dev, sglist, nelems,
                            device_to_mask(dev), direction);
 }
 
index a3c406aca6643d04ed6a7351086bfa0d1a4b2738..8f1f4e539c4bdfe57d9c5a1c1fe2232f9370062f 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/string.h>
 #include <linux/dma-mapping.h>
 #include <linux/bitops.h>
+#include <linux/iommu-helper.h>
 #include <asm/io.h>
 #include <asm/prom.h>
 #include <asm/iommu.h>
@@ -81,17 +82,19 @@ static int __init setup_iommu(char *str)
 __setup("protect4gb=", setup_protect4gb);
 __setup("iommu=", setup_iommu);
 
-static unsigned long iommu_range_alloc(struct iommu_table *tbl,
+static unsigned long iommu_range_alloc(struct device *dev,
+                                      struct iommu_table *tbl,
                                        unsigned long npages,
                                        unsigned long *handle,
                                        unsigned long mask,
                                        unsigned int align_order)
 { 
-       unsigned long n, end, i, start;
+       unsigned long n, end, start;
        unsigned long limit;
        int largealloc = npages > 15;
        int pass = 0;
        unsigned long align_mask;
+       unsigned long boundary_size;
 
        align_mask = 0xffffffffffffffffl >> (64 - align_order);
 
@@ -136,14 +139,17 @@ static unsigned long iommu_range_alloc(struct iommu_table *tbl,
                        start &= mask;
        }
 
-       n = find_next_zero_bit(tbl->it_map, limit, start);
-
-       /* Align allocation */
-       n = (n + align_mask) & ~align_mask;
-
-       end = n + npages;
+       if (dev)
+               boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
+                                     1 << IOMMU_PAGE_SHIFT);
+       else
+               boundary_size = ALIGN(1UL << 32, 1 << IOMMU_PAGE_SHIFT);
+       /* 4GB boundary for iseries_hv_alloc and iseries_hv_map */
 
-       if (unlikely(end >= limit)) {
+       n = iommu_area_alloc(tbl->it_map, limit, start, npages,
+                            tbl->it_offset, boundary_size >> IOMMU_PAGE_SHIFT,
+                            align_mask);
+       if (n == -1) {
                if (likely(pass < 2)) {
                        /* First failure, just rescan the half of the table.
                         * Second failure, rescan the other half of the table.
@@ -158,14 +164,7 @@ static unsigned long iommu_range_alloc(struct iommu_table *tbl,
                }
        }
 
-       for (i = n; i < end; i++)
-               if (test_bit(i, tbl->it_map)) {
-                       start = i+1;
-                       goto again;
-               }
-
-       for (i = n; i < end; i++)
-               __set_bit(i, tbl->it_map);
+       end = n + npages;
 
        /* Bump the hint to a new block for small allocs. */
        if (largealloc) {
@@ -184,16 +183,17 @@ static unsigned long iommu_range_alloc(struct iommu_table *tbl,
        return n;
 }
 
-static dma_addr_t iommu_alloc(struct iommu_table *tbl, void *page,
-                      unsigned int npages, enum dma_data_direction direction,
-                      unsigned long mask, unsigned int align_order)
+static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
+                             void *page, unsigned int npages,
+                             enum dma_data_direction direction,
+                             unsigned long mask, unsigned int align_order)
 {
        unsigned long entry, flags;
        dma_addr_t ret = DMA_ERROR_CODE;
 
        spin_lock_irqsave(&(tbl->it_lock), flags);
 
-       entry = iommu_range_alloc(tbl, npages, NULL, mask, align_order);
+       entry = iommu_range_alloc(dev, tbl, npages, NULL, mask, align_order);
 
        if (unlikely(entry == DMA_ERROR_CODE)) {
                spin_unlock_irqrestore(&(tbl->it_lock), flags);
@@ -224,7 +224,6 @@ static void __iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
                         unsigned int npages)
 {
        unsigned long entry, free_entry;
-       unsigned long i;
 
        entry = dma_addr >> IOMMU_PAGE_SHIFT;
        free_entry = entry - tbl->it_offset;
@@ -246,9 +245,7 @@ static void __iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
        }
 
        ppc_md.tce_free(tbl, entry, npages);
-       
-       for (i = 0; i < npages; i++)
-               __clear_bit(free_entry+i, tbl->it_map);
+       iommu_area_free(tbl->it_map, free_entry, npages);
 }
 
 static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
@@ -270,16 +267,18 @@ static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
        spin_unlock_irqrestore(&(tbl->it_lock), flags);
 }
 
-int iommu_map_sg(struct iommu_table *tbl, struct scatterlist *sglist,
+int iommu_map_sg(struct device *dev, struct scatterlist *sglist,
                 int nelems, unsigned long mask,
                 enum dma_data_direction direction)
 {
+       struct iommu_table *tbl = dev->archdata.dma_data;
        dma_addr_t dma_next = 0, dma_addr;
        unsigned long flags;
        struct scatterlist *s, *outs, *segstart;
        int outcount, incount, i;
        unsigned int align;
        unsigned long handle;
+       unsigned int max_seg_size;
 
        BUG_ON(direction == DMA_NONE);
 
@@ -298,6 +297,7 @@ int iommu_map_sg(struct iommu_table *tbl, struct scatterlist *sglist,
 
        spin_lock_irqsave(&(tbl->it_lock), flags);
 
+       max_seg_size = dma_get_max_seg_size(dev);
        for_each_sg(sglist, s, nelems, i) {
                unsigned long vaddr, npages, entry, slen;
 
@@ -314,7 +314,7 @@ int iommu_map_sg(struct iommu_table *tbl, struct scatterlist *sglist,
                if (IOMMU_PAGE_SHIFT < PAGE_SHIFT && slen >= PAGE_SIZE &&
                    (vaddr & ~PAGE_MASK) == 0)
                        align = PAGE_SHIFT - IOMMU_PAGE_SHIFT;
-               entry = iommu_range_alloc(tbl, npages, &handle,
+               entry = iommu_range_alloc(dev, tbl, npages, &handle,
                                          mask >> IOMMU_PAGE_SHIFT, align);
 
                DBG("  - vaddr: %lx, size: %lx\n", vaddr, slen);
@@ -344,7 +344,8 @@ int iommu_map_sg(struct iommu_table *tbl, struct scatterlist *sglist,
                        /* We cannot merge if:
                         * - allocated dma_addr isn't contiguous to previous allocation
                         */
-                       if (novmerge || (dma_addr != dma_next)) {
+                       if (novmerge || (dma_addr != dma_next) ||
+                           (outs->dma_length + s->length > max_seg_size)) {
                                /* Can't merge: create a new segment */
                                segstart = s;
                                outcount++;
@@ -452,9 +453,6 @@ void iommu_unmap_sg(struct iommu_table *tbl, struct scatterlist *sglist,
 struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 {
        unsigned long sz;
-       unsigned long start_index, end_index;
-       unsigned long entries_per_4g;
-       unsigned long index;
        static int welcomed = 0;
        struct page *page;
 
@@ -476,6 +474,7 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
 
 #ifdef CONFIG_CRASH_DUMP
        if (ppc_md.tce_get) {
+               unsigned long index;
                unsigned long tceval;
                unsigned long tcecount = 0;
 
@@ -506,23 +505,6 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
        ppc_md.tce_free(tbl, tbl->it_offset, tbl->it_size);
 #endif
 
-       /*
-        * DMA cannot cross 4 GB boundary.  Mark last entry of each 4
-        * GB chunk as reserved.
-        */
-       if (protect4gb) {
-               entries_per_4g = 0x100000000l >> IOMMU_PAGE_SHIFT;
-
-               /* Mark the last bit before a 4GB boundary as used */
-               start_index = tbl->it_offset | (entries_per_4g - 1);
-               start_index -= tbl->it_offset;
-
-               end_index = tbl->it_size;
-
-               for (index = start_index; index < end_index - 1; index += entries_per_4g)
-                       __set_bit(index, tbl->it_map);
-       }
-
        if (!welcomed) {
                printk(KERN_INFO "IOMMU table initialized, virtual merging %s\n",
                       novmerge ? "disabled" : "enabled");
@@ -570,9 +552,9 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
  * need not be page aligned, the dma_addr_t returned will point to the same
  * byte within the page as vaddr.
  */
-dma_addr_t iommu_map_single(struct iommu_table *tbl, void *vaddr,
-               size_t size, unsigned long mask,
-               enum dma_data_direction direction)
+dma_addr_t iommu_map_single(struct device *dev, struct iommu_table *tbl,
+                           void *vaddr, size_t size, unsigned long mask,
+                           enum dma_data_direction direction)
 {
        dma_addr_t dma_handle = DMA_ERROR_CODE;
        unsigned long uaddr;
@@ -589,7 +571,7 @@ dma_addr_t iommu_map_single(struct iommu_table *tbl, void *vaddr,
                    ((unsigned long)vaddr & ~PAGE_MASK) == 0)
                        align = PAGE_SHIFT - IOMMU_PAGE_SHIFT;
 
-               dma_handle = iommu_alloc(tbl, vaddr, npages, direction,
+               dma_handle = iommu_alloc(dev, tbl, vaddr, npages, direction,
                                         mask >> IOMMU_PAGE_SHIFT, align);
                if (dma_handle == DMA_ERROR_CODE) {
                        if (printk_ratelimit())  {
@@ -621,8 +603,9 @@ void iommu_unmap_single(struct iommu_table *tbl, dma_addr_t dma_handle,
  * Returns the virtual address of the buffer and sets dma_handle
  * to the dma address (mapping) of the first page.
  */
-void *iommu_alloc_coherent(struct iommu_table *tbl, size_t size,
-               dma_addr_t *dma_handle, unsigned long mask, gfp_t flag, int node)
+void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
+                          size_t size, dma_addr_t *dma_handle,
+                          unsigned long mask, gfp_t flag, int node)
 {
        void *ret = NULL;
        dma_addr_t mapping;
@@ -656,7 +639,7 @@ void *iommu_alloc_coherent(struct iommu_table *tbl, size_t size,
        /* Set up tces to cover the allocated range */
        nio_pages = size >> IOMMU_PAGE_SHIFT;
        io_order = get_iommu_order(size);
-       mapping = iommu_alloc(tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
+       mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
                              mask >> IOMMU_PAGE_SHIFT, io_order);
        if (mapping == DMA_ERROR_CODE) {
                free_pages((unsigned long)ret, order);
index 5cd3db5cae415198653a8d1a4e4bce846a7a40ef..3b26fbd6bec9ee4978ff6430ce1ef27a55723089 100644 (file)
@@ -66,6 +66,7 @@
 #include <asm/smp.h>
 #include <asm/vdso_datapage.h>
 #include <asm/firmware.h>
+#include <asm/cputime.h>
 #ifdef CONFIG_PPC_ISERIES
 #include <asm/iseries/it_lp_queue.h>
 #include <asm/iseries/hv_call_xm.h>
@@ -189,6 +190,8 @@ u64 __cputime_sec_factor;
 EXPORT_SYMBOL(__cputime_sec_factor);
 u64 __cputime_clockt_factor;
 EXPORT_SYMBOL(__cputime_clockt_factor);
+DEFINE_PER_CPU(unsigned long, cputime_last_delta);
+DEFINE_PER_CPU(unsigned long, cputime_scaled_last_delta);
 
 static void calc_cputime_factors(void)
 {
@@ -257,8 +260,8 @@ void account_system_vtime(struct task_struct *tsk)
        }
        account_system_time(tsk, 0, delta);
        account_system_time_scaled(tsk, deltascaled);
-       get_paca()->purrdelta = delta;
-       get_paca()->spurrdelta = deltascaled;
+       per_cpu(cputime_last_delta, smp_processor_id()) = delta;
+       per_cpu(cputime_scaled_last_delta, smp_processor_id()) = deltascaled;
        local_irq_restore(flags);
 }
 
@@ -276,10 +279,7 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
        get_paca()->user_time = 0;
        account_user_time(tsk, utime);
 
-       /* Estimate the scaled utime by scaling the real utime based
-        * on the last spurr to purr ratio */
-       utimescaled = utime * get_paca()->spurrdelta / get_paca()->purrdelta;
-       get_paca()->spurrdelta = get_paca()->purrdelta = 0;
+       utimescaled = cputime_to_scaled(utime);
        account_user_time_scaled(tsk, utimescaled);
 }
 
index 64488723162a371b05f0148f8f54a413f428eed8..f80f90c4d58be2b277dd6bb6d602b43678b6dbad 100644 (file)
@@ -86,7 +86,7 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
        return ret;
 }
 
-void pgd_free(pgd_t *pgd)
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_pages((unsigned long)pgd, PGDIR_ORDER);
 }
@@ -123,7 +123,7 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
        return ptepage;
 }
 
-void pte_free_kernel(pte_t *pte)
+void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
 #ifdef CONFIG_SMP
        hash_page_sync();
@@ -131,7 +131,7 @@ void pte_free_kernel(pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-void pte_free(struct page *ptepage)
+void pte_free(struct mm_struct *mm, struct page *ptepage)
 {
 #ifdef CONFIG_SMP
        hash_page_sync();
index c0f13e8deb0b482936528761e040fd8fd026e048..41c7fd91e99e5836cbaef5c7d6803334bc37a206 100644 (file)
@@ -31,7 +31,7 @@ static int lite5200_pm_valid(suspend_state_t state)
        }
 }
 
-static int lite5200_pm_set_target(suspend_state_t state)
+static int lite5200_pm_begin(suspend_state_t state)
 {
        if (lite5200_pm_valid(state)) {
                lite5200_pm_target_state = state;
@@ -219,12 +219,18 @@ static void lite5200_pm_finish(void)
                mpc52xx_pm_finish();
 }
 
+static void lite5200_pm_end(void)
+{
+       lite5200_pm_target_state = PM_SUSPEND_ON;
+}
+
 static struct platform_suspend_ops lite5200_pm_ops = {
        .valid          = lite5200_pm_valid,
-       .set_target     = lite5200_pm_set_target,
+       .begin          = lite5200_pm_begin,
        .prepare        = lite5200_pm_prepare,
        .enter          = lite5200_pm_enter,
        .finish         = lite5200_pm_finish,
+       .end            = lite5200_pm_end,
 };
 
 int __init lite5200_pm_init(void)
index 6a0c6f6675cdf0d3dce57eda11ae7009ebb77e58..11fa3c772ed567f8ba907b024dc3ef8010713777 100644 (file)
@@ -199,7 +199,7 @@ static struct iommu_table vio_iommu_table;
 
 void *iseries_hv_alloc(size_t size, dma_addr_t *dma_handle, gfp_t flag)
 {
-       return iommu_alloc_coherent(&vio_iommu_table, size, dma_handle,
+       return iommu_alloc_coherent(NULL, &vio_iommu_table, size, dma_handle,
                                DMA_32BIT_MASK, flag, -1);
 }
 EXPORT_SYMBOL_GPL(iseries_hv_alloc);
@@ -213,7 +213,7 @@ EXPORT_SYMBOL_GPL(iseries_hv_free);
 dma_addr_t iseries_hv_map(void *vaddr, size_t size,
                        enum dma_data_direction direction)
 {
-       return iommu_map_single(&vio_iommu_table, vaddr, size,
+       return iommu_map_single(NULL, &vio_iommu_table, vaddr, size,
                                DMA_32BIT_MASK, direction);
 }
 
index c04abcc28a7a88060a9cb6be50922c9ef41bd4a9..792d3ce8112e0778425cfc1f3531db3fb8e69776 100644 (file)
@@ -113,8 +113,6 @@ static inline void debug_calc_bogomips(void)
         * result. We backup/restore the value to avoid affecting the
         * core cpufreq framework's own calculation.
         */
-       extern void calibrate_delay(void);
-
        unsigned long save_lpj = loops_per_jiffy;
        calibrate_delay();
        loops_per_jiffy = save_lpj;
index 25ef55bacd99e50545caf74b8a493b15622425a6..ec1defea9c1e4885fe974722c8dc8cb00d45eac3 100644 (file)
@@ -418,7 +418,7 @@ scc_enet_rx(struct net_device *dev)
        struct  sk_buff *skb;
        ushort  pkt_len;
 
-       cep = (struct scc_enet_private *)dev->priv;
+       cep = dev->priv;
 
        /* First, grab all of the stats for the incoming packet.
         * These get messed up if we get called due to a busy condition.
index a3a27dafff1fc73fc3d1ebc777213fc3a9819598..bcc3aa9d04f397fa62f7ef83fef80262c2eba942 100644 (file)
@@ -682,7 +682,7 @@ fcc_enet_rx(struct net_device *dev)
        struct  sk_buff *skb;
        ushort  pkt_len;
 
-       cep = (struct fcc_enet_private *)dev->priv;
+       cep = dev->priv;
 
        /* First, grab all of the stats for the incoming packet.
         * These get messed up if we get called due to a busy condition.
index db5934cdafb3b9fd603317e53789a8e5230001db..531156f8919ca5e4877f1835a14a303a232496ae 100644 (file)
@@ -42,6 +42,8 @@ config GENERIC_CALIBRATE_DELAY
 config PPC
        bool
        default y
+       select HAVE_OPROFILE
+       select HAVE_KPROBES
 
 config PPC32
        bool
@@ -1256,8 +1258,6 @@ endmenu
 
 source "lib/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/ppc/Kconfig.debug"
 
 source "security/Kconfig"
index 52b64fcbdfc50d493a76bef799400e2365cdd15e..8a24bc47eb6cc76f52496d0efd9417f827c0c586 100644 (file)
@@ -143,11 +143,6 @@ SECTIONS
 
   . = ALIGN(4096);
   __init_end = .;
-
-  . = ALIGN(4096);
-  _sextratext = .;
-  _eextratext = .;
-
   __bss_start = .;
   .bss       :
   {
index fadacfd188068e70a787c623cfe81b9a5581f15a..409fcaa4994a598736ec082218dacde0709f2d9a 100644 (file)
@@ -74,7 +74,7 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
        return ret;
 }
 
-void pgd_free(pgd_t *pgd)
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_pages((unsigned long)pgd, PGDIR_ORDER);
 }
@@ -111,7 +111,7 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
        return ptepage;
 }
 
-void pte_free_kernel(pte_t *pte)
+void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
 #ifdef CONFIG_SMP
        hash_page_sync();
@@ -119,7 +119,7 @@ void pte_free_kernel(pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-void pte_free(struct page *ptepage)
+void pte_free(struct mm_struct *mm, struct page *ptepage)
 {
 #ifdef CONFIG_SMP
        hash_page_sync();
index 3c56654bfc6f28580a42a7e4cc4a043dcd8e300d..38449855d5ffbede401cf147a5d8af8a76abc086 100644 (file)
@@ -91,20 +91,11 @@ extern void prep_tiger1_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi
 #define cached_21      (((char *)(ppc_cached_irq_mask))[3])
 #define cached_A1      (((char *)(ppc_cached_irq_mask))[2])
 
-#ifdef CONFIG_SOUND_CS4232
-long ppc_cs4232_dma, ppc_cs4232_dma2;
-#endif
-
 extern PTE *Hash, *Hash_end;
 extern unsigned long Hash_size, Hash_mask;
 extern int probingmem;
 extern unsigned long loops_per_jiffy;
 
-#ifdef CONFIG_SOUND_CS4232
-EXPORT_SYMBOL(ppc_cs4232_dma);
-EXPORT_SYMBOL(ppc_cs4232_dma2);
-#endif
-
 /* useful ISA ports */
 #define PREP_SYSCTL    0x81c
 /* present in the IBM reference design; possibly identical in Mot boxes: */
@@ -569,74 +560,6 @@ prep_show_percpuinfo(struct seq_file *m, int i)
        return 0;
 }
 
-#ifdef CONFIG_SOUND_CS4232
-static long __init masktoint(unsigned int i)
-{
-       int t = -1;
-       while (i >> ++t)
-               ;
-       return (t-1);
-}
-
-/*
- * ppc_cs4232_dma and ppc_cs4232_dma2 are used in include/asm/dma.h
- * to distinguish sound dma-channels from others. This is because
- * blocksize on 16 bit dma-channels 5,6,7 is 128k, but
- * the cs4232.c uses 64k like on 8 bit dma-channels 0,1,2,3
- */
-
-static void __init prep_init_sound(void)
-{
-       PPC_DEVICE *audiodevice = NULL;
-
-       /*
-        * Get the needed resource information from residual data.
-        *
-        */
-       if (have_residual_data)
-               audiodevice = residual_find_device(~0, NULL,
-                               MultimediaController, AudioController, -1, 0);
-
-       if (audiodevice != NULL) {
-               PnP_TAG_PACKET *pkt;
-
-               pkt = PnP_find_packet((unsigned char *)&res->DevicePnPHeap[audiodevice->AllocatedOffset],
-                               S5_Packet, 0);
-               if (pkt != NULL)
-                       ppc_cs4232_dma = masktoint(pkt->S5_Pack.DMAMask);
-               pkt = PnP_find_packet((unsigned char*)&res->DevicePnPHeap[audiodevice->AllocatedOffset],
-                               S5_Packet, 1);
-               if (pkt != NULL)
-                       ppc_cs4232_dma2 = masktoint(pkt->S5_Pack.DMAMask);
-       }
-
-       /*
-        * These are the PReP specs' defaults for the cs4231.  We use these
-        * as fallback incase we don't have residual data.
-        * At least the IBM Thinkpad 850 with IDE DMA Channels at 6 and 7
-        * will use the other values.
-        */
-       if (audiodevice == NULL) {
-               switch (_prep_type) {
-               case _PREP_IBM:
-                       ppc_cs4232_dma = 1;
-                       ppc_cs4232_dma2 = -1;
-                       break;
-               default:
-                       ppc_cs4232_dma = 6;
-                       ppc_cs4232_dma2 = 7;
-               }
-       }
-
-       /*
-        * Find a way to push this information to the cs4232 driver
-        * Give it out with printk, when not in cmd_line?
-        * Append it to cmd_line and boot_command_line?
-        * Format is cs4232=io,irq,dma,dma2
-        */
-}
-#endif /* CONFIG_SOUND_CS4232 */
-
 /*
  * Fill out screen_info according to the residual data. This allows us to use
  * at least vesafb.
@@ -898,10 +821,6 @@ prep_setup_arch(void)
                }
        }
 
-#ifdef CONFIG_SOUND_CS4232
-       prep_init_sound();
-#endif /* CONFIG_SOUND_CS4232 */
-
        prep_init_vesa();
 
        switch (_prep_type) {
index 6ef54d27fc001720f738aa3f066e15497503c064..92a4f7b4323a54e0f23453e714e0a7c714bab632 100644 (file)
@@ -16,6 +16,9 @@ config LOCKDEP_SUPPORT
 config STACKTRACE_SUPPORT
        def_bool y
 
+config HAVE_LATENCYTOP_SUPPORT
+       def_bool y
+
 config RWSEM_GENERIC_SPINLOCK
        bool
 
@@ -47,10 +50,17 @@ config NO_IOMEM
 config NO_DMA
        def_bool y
 
+config GENERIC_LOCKBREAK
+       bool
+       default y
+       depends on SMP && PREEMPT
+
 mainmenu "Linux Kernel Configuration"
 
 config S390
        def_bool y
+       select HAVE_OPROFILE
+       select HAVE_KPROBES
 
 source "init/Kconfig"
 
@@ -81,8 +91,8 @@ config SMP
          singleprocessor machines. On a singleprocessor machine, the kernel
          will run faster if you say N here.
 
-         See also the <file:Documentation/smp.txt> and the SMP-HOWTO
-         available at <http://www.tldp.org/docs.html#howto>.
+         See also the SMP-HOWTO available at
+         <http://www.tldp.org/docs.html#howto>.
 
          Even if you don't know what to do here, say Y.
 
@@ -526,8 +536,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/s390/Kconfig.debug"
 
 source "security/Kconfig"
index 2283933a9a93eef48b2de37aefe944540af03ff4..4599fa06bd82a759d322dcd25a85bbfb6edfb369 100644 (file)
@@ -6,4 +6,12 @@ config TRACE_IRQFLAGS_SUPPORT
 
 source "lib/Kconfig.debug"
 
+config DEBUG_PAGEALLOC
+       bool "Debug page memory allocations"
+       depends on DEBUG_KERNEL
+       help
+         Unmap pages from the kernel linear mapping after free_pages().
+         This results in a slowdown, but helps to find certain types of
+         memory corruptions.
+
 endmenu
index 6ee1bedbd1bf85f020edfcf9b2c37457208ba1b7..062c3d4c0394b48f4e8bbea8306bc538a03c2758 100644 (file)
@@ -1698,14 +1698,6 @@ compat_sys_signalfd_wrapper:
        llgfr   %r4,%r4                 # compat_size_t
        jg      compat_sys_signalfd
 
-       .globl  compat_sys_timerfd_wrapper
-compat_sys_timerfd_wrapper:
-       lgfr    %r2,%r2                 # int
-       lgfr    %r3,%r3                 # int
-       lgfr    %r4,%r4                 # int
-       llgtr   %r5,%r5                 # struct compat_itimerspec *
-       jg      compat_sys_timerfd
-
        .globl  sys_eventfd_wrapper
 sys_eventfd_wrapper:
        llgfr   %r2,%r2                 # unsigned int
index 1a6dac8df6fb1942a96418ad4d76014be051bdda..6766e37fe8ea01955da640895bd2068358f660d6 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/sys.h>
 #include <linux/linkage.h>
+#include <linux/init.h>
 #include <asm/cache.h>
 #include <asm/lowcore.h>
 #include <asm/errno.h>
@@ -830,9 +831,7 @@ mcck_return:
  * Restart interruption handler, kick starter for additional CPUs
  */
 #ifdef CONFIG_SMP
-#ifndef CONFIG_HOTPLUG_CPU
-       .section .init.text,"ax"
-#endif
+       __CPUINIT
        .globl restart_int_handler
 restart_int_handler:
        l       %r15,__LC_SAVE_AREA+60  # load ksp
@@ -845,9 +844,7 @@ restart_int_handler:
        br      %r14                    # branch to start_secondary
 restart_addr:
        .long   start_secondary
-#ifndef CONFIG_HOTPLUG_CPU
        .previous
-#endif
 #else
 /*
  * If we do not run with SMP enabled, let the new CPU crash ...
index a3e47b893f079ca812c54b727f4b3dd4b2a6a6c2..efde6e178f6c22733322ac6c5048cdfed8c7e28b 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/sys.h>
 #include <linux/linkage.h>
+#include <linux/init.h>
 #include <asm/cache.h>
 #include <asm/lowcore.h>
 #include <asm/errno.h>
@@ -801,9 +802,7 @@ mcck_return:
  * Restart interruption handler, kick starter for additional CPUs
  */
 #ifdef CONFIG_SMP
-#ifndef CONFIG_HOTPLUG_CPU
-       .section .init.text,"ax"
-#endif
+       __CPUINIT
        .globl restart_int_handler
 restart_int_handler:
        lg      %r15,__LC_SAVE_AREA+120 # load ksp
@@ -814,9 +813,7 @@ restart_int_handler:
        lmg     %r6,%r15,__SF_GPRS(%r15) # load registers from clone
        stosm   __SF_EMPTY(%r15),0x04   # now we can turn dat on
        jg      start_secondary
-#ifndef CONFIG_HOTPLUG_CPU
        .previous
-#endif
 #else
 /*
  * If we do not run with SMP enabled, let the new CPU crash ...
index db28cca81fef75ec6c1ffcec76c14218dff80d34..60acdc266db177fab528d5cedea72829a1cbe939 100644 (file)
@@ -439,7 +439,7 @@ static void ipl_run(struct shutdown_trigger *trigger)
                reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
 }
 
-static int ipl_init(void)
+static int __init ipl_init(void)
 {
        int rc;
 
@@ -471,8 +471,11 @@ out:
        return 0;
 }
 
-static struct shutdown_action ipl_action = {SHUTDOWN_ACTION_IPL_STR, ipl_run,
-                                           ipl_init};
+static struct shutdown_action __refdata ipl_action = {
+       .name   = SHUTDOWN_ACTION_IPL_STR,
+       .fn     = ipl_run,
+       .init   = ipl_init,
+};
 
 /*
  * reipl shutdown action: Reboot Linux on shutdown.
@@ -792,7 +795,7 @@ static int __init reipl_fcp_init(void)
        return 0;
 }
 
-static int reipl_init(void)
+static int __init reipl_init(void)
 {
        int rc;
 
@@ -819,8 +822,11 @@ static int reipl_init(void)
        return 0;
 }
 
-static struct shutdown_action reipl_action = {SHUTDOWN_ACTION_REIPL_STR,
-                                             reipl_run, reipl_init};
+static struct shutdown_action __refdata reipl_action = {
+       .name   = SHUTDOWN_ACTION_REIPL_STR,
+       .fn     = reipl_run,
+       .init   = reipl_init,
+};
 
 /*
  * dump shutdown action: Dump Linux on shutdown.
@@ -998,7 +1004,7 @@ static int __init dump_fcp_init(void)
        return 0;
 }
 
-static int dump_init(void)
+static int __init dump_init(void)
 {
        int rc;
 
@@ -1020,8 +1026,11 @@ static int dump_init(void)
        return 0;
 }
 
-static struct shutdown_action dump_action = {SHUTDOWN_ACTION_DUMP_STR,
-                                            dump_run, dump_init};
+static struct shutdown_action __refdata dump_action = {
+       .name   = SHUTDOWN_ACTION_DUMP_STR,
+       .fn     = dump_run,
+       .init   = dump_init,
+};
 
 /*
  * vmcmd shutdown action: Trigger vm command on shutdown.
index 766c783bd7a726e25c8a9f0ba243067a1a296344..29ae165d174931b0d7b1775e3690c1be23d5c8f9 100644 (file)
@@ -77,7 +77,7 @@ unsigned long machine_flags = 0;
 unsigned long elf_hwcap = 0;
 char elf_platform[ELF_PLATFORM_SIZE];
 
-struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
+struct mem_chunk __meminitdata memory_chunk[MEMORY_CHUNKS];
 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
 static unsigned long __initdata memory_end;
 
@@ -145,7 +145,7 @@ __setup("condev=", condev_setup);
 
 static int __init conmode_setup(char *str)
 {
-#if defined(CONFIG_SCLP_CONSOLE)
+#if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
        if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
                 SET_CONSOLE_SCLP;
 #endif
@@ -183,7 +183,7 @@ static void __init conmode_default(void)
                 */
                cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
                if (ptr == NULL) {
-#if defined(CONFIG_SCLP_CONSOLE)
+#if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
                        SET_CONSOLE_SCLP;
 #endif
                        return;
@@ -193,7 +193,7 @@ static void __init conmode_default(void)
                        SET_CONSOLE_3270;
 #elif defined(CONFIG_TN3215_CONSOLE)
                        SET_CONSOLE_3215;
-#elif defined(CONFIG_SCLP_CONSOLE)
+#elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
                        SET_CONSOLE_SCLP;
 #endif
                } else if (strncmp(ptr + 8, "3215", 4) == 0) {
@@ -201,7 +201,7 @@ static void __init conmode_default(void)
                        SET_CONSOLE_3215;
 #elif defined(CONFIG_TN3270_CONSOLE)
                        SET_CONSOLE_3270;
-#elif defined(CONFIG_SCLP_CONSOLE)
+#elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
                        SET_CONSOLE_SCLP;
 #endif
                }
@@ -212,7 +212,7 @@ static void __init conmode_default(void)
                SET_CONSOLE_3270;
 #endif
        } else {
-#if defined(CONFIG_SCLP_CONSOLE)
+#if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
                SET_CONSOLE_SCLP;
 #endif
        }
@@ -528,7 +528,7 @@ static void __init setup_memory_end(void)
        memory_size = 0;
        memory_end &= PAGE_MASK;
 
-       max_mem = memory_end ? min(VMALLOC_START, memory_end) : VMALLOC_START;
+       max_mem = memory_end ? min(VMEM_MAX_PHYS, memory_end) : VMEM_MAX_PHYS;
        memory_end = min(max_mem, memory_end);
 
        /*
index aa37fa154512eb2323064bf2c9dc7ba44ec6be8e..85060659fb123d491227d849963dad292e13eeab 100644 (file)
@@ -225,12 +225,11 @@ EXPORT_SYMBOL(smp_call_function_single);
  * You must not call this function with disabled interrupts or from a
  * hardware interrupt handler or from a bottom half handler.
  */
-int
-smp_call_function_mask(cpumask_t mask,
-                       void (*func)(void *), void *info,
-                       int wait)
+int smp_call_function_mask(cpumask_t mask, void (*func)(void *), void *info,
+                          int wait)
 {
        preempt_disable();
+       cpu_clear(smp_processor_id(), mask);
        __smp_call_function_map(func, info, 0, wait, mask);
        preempt_enable();
        return 0;
@@ -1008,7 +1007,7 @@ static struct notifier_block __cpuinitdata smp_cpu_nb = {
        .notifier_call = smp_cpu_notify,
 };
 
-static int smp_add_present_cpu(int cpu)
+static int __devinit smp_add_present_cpu(int cpu)
 {
        struct cpu *c = &per_cpu(cpu_devices, cpu);
        struct sys_device *s = &c->sysdev;
@@ -1036,8 +1035,8 @@ out:
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
-static ssize_t rescan_store(struct sys_device *dev, const char *buf,
-                           size_t count)
+static ssize_t __ref rescan_store(struct sys_device *dev,
+                                 const char *buf, size_t count)
 {
        cpumask_t newcpus;
        int cpu;
index da692472996449fa6daa83e79a56273f56ac4be8..85e46a5d0e0801d9880987cd2595a06391231401 100644 (file)
@@ -14,7 +14,8 @@
 static unsigned long save_context_stack(struct stack_trace *trace,
                                        unsigned long sp,
                                        unsigned long low,
-                                       unsigned long high)
+                                       unsigned long high,
+                                       int savesched)
 {
        struct stack_frame *sf;
        struct pt_regs *regs;
@@ -47,10 +48,12 @@ static unsigned long save_context_stack(struct stack_trace *trace,
                        return sp;
                regs = (struct pt_regs *)sp;
                addr = regs->psw.addr & PSW_ADDR_INSN;
-               if (!trace->skip)
-                       trace->entries[trace->nr_entries++] = addr;
-               else
-                       trace->skip--;
+               if (savesched || !in_sched_functions(addr)) {
+                       if (!trace->skip)
+                               trace->entries[trace->nr_entries++] = addr;
+                       else
+                               trace->skip--;
+               }
                if (trace->nr_entries >= trace->max_entries)
                        return sp;
                low = sp;
@@ -66,15 +69,27 @@ void save_stack_trace(struct stack_trace *trace)
        orig_sp = sp & PSW_ADDR_INSN;
        new_sp = save_context_stack(trace, orig_sp,
                                    S390_lowcore.panic_stack - PAGE_SIZE,
-                                   S390_lowcore.panic_stack);
+                                   S390_lowcore.panic_stack, 1);
        if (new_sp != orig_sp)
                return;
        new_sp = save_context_stack(trace, new_sp,
                                    S390_lowcore.async_stack - ASYNC_SIZE,
-                                   S390_lowcore.async_stack);
+                                   S390_lowcore.async_stack, 1);
        if (new_sp != orig_sp)
                return;
        save_context_stack(trace, new_sp,
                           S390_lowcore.thread_info,
-                          S390_lowcore.thread_info + THREAD_SIZE);
+                          S390_lowcore.thread_info + THREAD_SIZE, 1);
+}
+
+void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+{
+       unsigned long sp, low, high;
+
+       sp = tsk->thread.ksp & PSW_ADDR_INSN;
+       low = (unsigned long) task_stack_page(tsk);
+       high = (unsigned long) task_pt_regs(tsk);
+       save_context_stack(trace, sp, low, high, 0);
+       if (trace->nr_entries < trace->max_entries)
+               trace->entries[trace->nr_entries++] = ULONG_MAX;
 }
index 9e26ed9fe4e73ee5301519ada6c2a602efdef2b6..25eac7802fc4dba21980e643fc6fc2f0b76081bf 100644 (file)
@@ -325,5 +325,5 @@ SYSCALL(sys_utimes,sys_utimes,compat_sys_utimes_wrapper)
 SYSCALL(s390_fallocate,sys_fallocate,sys_fallocate_wrapper)
 SYSCALL(sys_utimensat,sys_utimensat,compat_sys_utimensat_wrapper)      /* 315 */
 SYSCALL(sys_signalfd,sys_signalfd,compat_sys_signalfd_wrapper)
-SYSCALL(sys_timerfd,sys_timerfd,compat_sys_timerfd_wrapper)
+NI_SYSCALL                                             /* 317 old sys_timer_fd */
 SYSCALL(sys_eventfd,sys_eventfd,sys_eventfd_wrapper)
index 52b8342c6bf265e9facd1e18a4f3512d56c2357a..1a2fdb6991df0e6905c8640c71025d8ca54c1bf6 100644 (file)
@@ -271,7 +271,10 @@ void die(const char * str, struct pt_regs * regs, long err)
        printk("PREEMPT ");
 #endif
 #ifdef CONFIG_SMP
-       printk("SMP");
+       printk("SMP ");
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+       printk("DEBUG_PAGEALLOC");
 #endif
        printk("\n");
        notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
index 7d43c3cd3ef35880b5b0fd5a5fbb08b33a51e605..b4607155e8d0b930c98b8a913d050a08d47b9e4a 100644 (file)
@@ -35,7 +35,7 @@ SECTIONS
                KPROBES_TEXT
                *(.fixup)
                *(.gnu.warning)
-       } = 0x0700
+       } :text = 0x0700
 
        _etext = .;             /* End of text section */
 
index b234bb4a6da7545d5ab8b5ed7387fb7b3c25b994..983ec6ec0e7cc6c85800eea42068196a5fbdbc28 100644 (file)
@@ -167,6 +167,33 @@ void __init mem_init(void)
               PFN_ALIGN((unsigned long)&_eshared) - 1);
 }
 
+#ifdef CONFIG_DEBUG_PAGEALLOC
+void kernel_map_pages(struct page *page, int numpages, int enable)
+{
+       pgd_t *pgd;
+       pud_t *pud;
+       pmd_t *pmd;
+       pte_t *pte;
+       unsigned long address;
+       int i;
+
+       for (i = 0; i < numpages; i++) {
+               address = page_to_phys(page + i);
+               pgd = pgd_offset_k(address);
+               pud = pud_offset(pgd, address);
+               pmd = pmd_offset(pud, address);
+               pte = pte_offset_kernel(pmd, address);
+               if (!enable) {
+                       ptep_invalidate(address, pte);
+                       continue;
+               }
+               *pte = mk_pte_phys(address, __pgprot(_PAGE_TYPE_RW));
+               /* Flush cpu write queue. */
+               mb();
+       }
+}
+#endif
+
 void free_initmem(void)
 {
         unsigned long addr;
index 79d13a166a3dac765df9c7af68c18b0cf58bd253..7c1287ccf78864fee054865ef9afd97193497d93 100644 (file)
@@ -62,7 +62,7 @@ void __meminit memmap_init(unsigned long size, int nid, unsigned long zone,
        }
 }
 
-static void __init_refok *vmem_alloc_pages(unsigned int order)
+static void __ref *vmem_alloc_pages(unsigned int order)
 {
        if (slab_is_available())
                return (void *)__get_free_pages(GFP_KERNEL, order);
@@ -250,7 +250,7 @@ static int insert_memory_segment(struct memory_segment *seg)
 {
        struct memory_segment *tmp;
 
-       if (seg->start + seg->size >= VMALLOC_START ||
+       if (seg->start + seg->size >= VMEM_MAX_PHYS ||
            seg->start + seg->size < seg->start)
                return -ERANGE;
 
@@ -360,7 +360,6 @@ void __init vmem_map_init(void)
 {
        int i;
 
-       BUILD_BUG_ON((unsigned long)VMEM_MAP + VMEM_MAP_SIZE > VMEM_MAP_MAX);
        NODE_DATA(0)->node_mem_map = VMEM_MAP;
        for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++)
                vmem_add_mem(memory_chunk[i].addr, memory_chunk[i].size);
index 1cd9c8fd927d8dd20fba363aeea28718d4562328..1c3a90835c7e00caf0cb6960c4da7a75f603ea51 100644 (file)
@@ -8,6 +8,7 @@ mainmenu "Linux/SuperH Kernel Configuration"
 config SUPERH
        def_bool y
        select EMBEDDED
+       select HAVE_OPROFILE
        help
          The SuperH is a RISC processor targeted for use in embedded systems
          and consumer electronics; it was also used in the Sega Dreamcast
@@ -672,9 +673,8 @@ config SMP
          People using multiprocessor machines who say Y here should also say
          Y to "Enhanced Real Time Clock Support", below.
 
-         See also the <file:Documentation/smp.txt>,
-         <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available
-         at <http://www.tldp.org/docs.html#howto>.
+         See also <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO
+         available at <http://www.tldp.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
 
@@ -882,6 +882,10 @@ endmenu
 menu "Power management options (EXPERIMENTAL)"
 depends on EXPERIMENTAL && SYS_SUPPORTS_PM
 
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+       depends on !SMP
+
 source kernel/power/Kconfig
 
 endmenu
@@ -892,8 +896,6 @@ source "drivers/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/sh/Kconfig.debug"
 
 source "security/Kconfig"
index eda71763ecc5281c1173012d9767a18f7300c580..2b708ec7255868981874b87354fae33661529376 100644 (file)
@@ -14,7 +14,7 @@
  */
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/pm.h>
 #include <linux/mm.h>
 #include <asm/machvec.h>
index 9c830fdc411b346b056ed2b5885bcae750adcc26..c74440d38ee974aa40482ed5a2af56334f25e9a1 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <asm/machvec.h>
 #include <asm/addrspace.h>
 #include <asm/lboxre2.h>
index a43b47726f545539467a8325c845648cea01b300..f7a8d5c9d510577f085f0ac3f96bcf5ffeb10cc7 100644 (file)
@@ -15,7 +15,7 @@
  */
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/types.h>
 #include <net/ax88796.h>
 #include <asm/machvec.h>
index 3452b072addece1706a68720e48c32bd52e83c54..a0ef81b7de3743e42c6933dc5f2e82481f0f89c6 100644 (file)
@@ -10,7 +10,7 @@
  */
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/serial_8250.h>
 #include <linux/sm501.h>
 #include <linux/sm501-regs.h>
index 5df32f2018703a557ed7fc63b39d565f6d8457aa..acc5932587f11ad994793d1f5d6941b2aa8bcdc3 100644 (file)
@@ -11,7 +11,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/platform_device.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <asm/machvec.h>
 #include <asm/sdk7780.h>
 #include <asm/heartbeat.h>
index eb97dca5b736c4fce596c74c55476ace350b3424..b1a3d9d0172f50678c5add2c1388bb5094afbcf2 100644 (file)
@@ -12,7 +12,7 @@
  */
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <asm/machvec.h>
 #include <asm/se7722.h>
 #include <asm/io.h>
index fbc6f2c8649fa72f17c3c1157871a043a1ee38de..7e816ededed762db82b04ce39b7bc2b449e9f769 100644 (file)
@@ -6,11 +6,6 @@ config PCI
          bus system, i.e. the way the CPU talks to the other stuff inside
          your box. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 config SH_PCIDMA_NONCOHERENT
        bool "Cache and PCI noncoherent"
        depends on PCI
index 10bec45415ba0c09f856533418f1775e4e94eb96..719e127a7c05921be389465d2630c6821700603d 100644 (file)
@@ -338,6 +338,6 @@ ENTRY(sys_call_table)
        .long sys_epoll_pwait
        .long sys_utimensat             /* 320 */
        .long sys_signalfd
-       .long sys_timerfd
+       .long sys_ni_syscall
        .long sys_eventfd
        .long sys_fallocate
index 98a93efe36911a040084565d4ce09936b06b2ff7..12c7340356ae4bb78819e83cf8fa11fef0939217 100644 (file)
@@ -376,6 +376,6 @@ sys_call_table:
        .long sys_epoll_pwait
        .long sys_utimensat
        .long sys_signalfd
-       .long sys_timerfd               /* 350 */
+       .long sys_ni_syscall            /* 350 */
        .long sys_eventfd
        .long sys_fallocate
index 527adc808ad6c8609bc81581d49bcceec1ceb0aa..99f8971716d2226a53a27c3e5c19e99c32b6f135 100644 (file)
@@ -48,9 +48,8 @@ config SMP
          Y to "Enhanced Real Time Clock Support", below. The "Advanced Power
          Management" code will be disabled if you say Y here.
 
-         See also the <file:Documentation/smp.txt>,
-         <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available at
-         <http://www.tldp.org/docs.html#howto>.
+         See also <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO
+         available at <http://www.tldp.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
 
@@ -63,6 +62,7 @@ config NR_CPUS
 config SPARC
        bool
        default y
+       select HAVE_OPROFILE
 
 # Identify this as a Sparc32 build
 config SPARC32
@@ -320,8 +320,6 @@ endmenu
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/sparc/Kconfig.debug"
 
 source "security/Kconfig"
index 97aa50d1e4ae053c2d61776d5880c820a2d38635..ad0ede24ca1d80e6e826d9e5eaee7f37bd391d36 100644 (file)
@@ -305,7 +305,7 @@ void *sbus_alloc_consistent(struct sbus_dev *sdev, long len, u32 *dma_addrp)
        struct resource *res;
        int order;
 
-       /* XXX why are some lenghts signed, others unsigned? */
+       /* XXX why are some lengths signed, others unsigned? */
        if (len <= 0) {
                return NULL;
        }
@@ -393,7 +393,7 @@ void sbus_free_consistent(struct sbus_dev *sdev, long n, void *p, u32 ba)
  */
 dma_addr_t sbus_map_single(struct sbus_dev *sdev, void *va, size_t len, int direction)
 {
-       /* XXX why are some lenghts signed, others unsigned? */
+       /* XXX why are some lengths signed, others unsigned? */
        if (len <= 0) {
                return 0;
        }
index 89a6de95070c761d0fe3237bc89a49f2063fc1fb..0def48158c7d165ca34688a51053205372e79cf4 100644 (file)
 #include <linux/mm.h>
 #include <linux/swap.h>
 #include <linux/profile.h>
+#include <linux/delay.h>
 
 #include <asm/ptrace.h>
 #include <asm/atomic.h>
 #include <asm/irq_regs.h>
 
-#include <asm/delay.h>
 #include <asm/irq.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
@@ -41,8 +41,6 @@
 
 extern ctxd_t *srmmu_ctx_table_phys;
 
-extern void calibrate_delay(void);
-
 static volatile int smp_processors_ready = 0;
 static int smp_highest_cpu;
 extern volatile unsigned long cpu_callin_map[NR_CPUS];
index 730eb5796f8edb98b83332e4a9099996ca1e3083..0b94072671623287c6c819fb4f405b18a0bb7038 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/mm.h>
 #include <linux/swap.h>
 #include <linux/profile.h>
+#include <linux/delay.h>
+
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
 #include <asm/irq_regs.h>
@@ -23,7 +25,6 @@
 #include <asm/ptrace.h>
 #include <asm/atomic.h>
 
-#include <asm/delay.h>
 #include <asm/irq.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
@@ -39,8 +40,6 @@
 
 extern ctxd_t *srmmu_ctx_table_phys;
 
-extern void calibrate_delay(void);
-
 extern volatile unsigned long cpu_callin_map[NR_CPUS];
 extern unsigned char boot_cpu_id;
 
index 55722840859c89c15df7dc32409cdd902fb7c376..9064485dc40be66266882a5fd3a13531344610d1 100644 (file)
@@ -79,7 +79,8 @@ sys_call_table:
 /*295*/        .long sys_fchmodat, sys_faccessat, sys_pselect6, sys_ppoll, sys_unshare
 /*300*/        .long sys_set_robust_list, sys_get_robust_list, sys_migrate_pages, sys_mbind, sys_get_mempolicy
 /*305*/        .long sys_set_mempolicy, sys_kexec_load, sys_move_pages, sys_getcpu, sys_epoll_pwait
-/*310*/        .long sys_utimensat, sys_signalfd, sys_timerfd, sys_eventfd, sys_fallocate
+/*310*/        .long sys_utimensat, sys_signalfd, sys_timerfd_create, sys_eventfd, sys_fallocate
+/*315*/        .long sys_timerfd_settime, sys_timerfd_gettime
 
 #ifdef CONFIG_SUNOS_EMUL
        /* Now the SunOS syscall table. */
@@ -197,6 +198,7 @@ sunos_sys_table:
        .long sunos_nosys, sunos_nosys, sunos_nosys
        .long sunos_nosys
 /*310*/        .long sunos_nosys, sunos_nosys, sunos_nosys
-       .long sunos_nosys, sunos_nosys
+       .long sunos_nosys, sunos_nosys, sunos_nosys
+       .long sunos_nosys
 
 #endif
index 73fc05d0bfad4aa9662bd27e5b63da23527800ae..a8c6366f05a1b416ddbfd3a28c2e31b6d333a05d 100644 (file)
@@ -8,6 +8,8 @@ mainmenu "Linux/UltraSPARC Kernel Configuration"
 config SPARC
        bool
        default y
+       select HAVE_OPROFILE
+       select HAVE_KPROBES
 
 config SPARC64
        bool
@@ -166,9 +168,8 @@ config SMP
          Y to "Enhanced Real Time Clock Support", below. The "Advanced Power
          Management" code will be disabled if you say Y here.
 
-         See also the <file:Documentation/smp.txt>,
-         <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available at
-         <http://www.tldp.org/docs.html#howto>.
+         See also <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO
+         available at <http://www.tldp.org/docs.html#howto>.
 
          If you don't know what to do here, say N.
 
@@ -351,11 +352,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 config PCI_DOMAINS
        def_bool PCI
 
@@ -470,8 +466,6 @@ source "drivers/sbus/char/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/sparc64/Kconfig.debug"
 
 source "security/Kconfig"
index f62d9f6c5e2a8d45519b1dba2a454e1faa718d1a..833d74b2b1923faa08e95c3604f2bbb5a7dddb86 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.24-rc4
-# Tue Dec  4 00:37:59 2007
+# Linux kernel version: 2.6.24
+# Tue Feb  5 17:28:19 2008
 #
 CONFIG_SPARC=y
 CONFIG_SPARC64=y
@@ -17,6 +17,7 @@ CONFIG_ARCH_MAY_HAVE_PC_FDC=y
 # CONFIG_ARCH_HAS_ILOG2_U32 is not set
 # CONFIG_ARCH_HAS_ILOG2_U64 is not set
 CONFIG_AUDIT_ARCH=y
+CONFIG_HAVE_SETUP_PER_CPU_AREA=y
 CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_OF=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
@@ -30,13 +31,15 @@ CONFIG_HZ_100=y
 # CONFIG_HZ_300 is not set
 # CONFIG_HZ_1000 is not set
 CONFIG_HZ=100
+# CONFIG_SCHED_HRTICK is not set
+CONFIG_HOTPLUG_CPU=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 
 #
 # General setup
 #
 CONFIG_EXPERIMENTAL=y
-CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
 CONFIG_INIT_ENV_ARG_LIMIT=32
 CONFIG_LOCALVERSION=""
 # CONFIG_LOCALVERSION_AUTO is not set
@@ -76,6 +79,7 @@ CONFIG_FUTEX=y
 CONFIG_ANON_INODES=y
 CONFIG_EPOLL=y
 CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
 CONFIG_EVENTFD=y
 CONFIG_SHMEM=y
 CONFIG_VM_EVENT_COUNTERS=y
@@ -83,6 +87,14 @@ CONFIG_SLUB_DEBUG=y
 # CONFIG_SLAB is not set
 CONFIG_SLUB=y
 # CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+# CONFIG_MARKERS is not set
+CONFIG_OPROFILE=m
+CONFIG_HAVE_OPROFILE=y
+CONFIG_KPROBES=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
 CONFIG_RT_MUTEXES=y
 # CONFIG_TINY_SHMEM is not set
 CONFIG_BASE_SMALL=0
@@ -92,6 +104,7 @@ CONFIG_MODULE_FORCE_UNLOAD=y
 CONFIG_MODVERSIONS=y
 CONFIG_MODULE_SRCVERSION_ALL=y
 CONFIG_KMOD=y
+CONFIG_STOP_MACHINE=y
 CONFIG_BLOCK=y
 CONFIG_BLK_DEV_IO_TRACE=y
 CONFIG_BLK_DEV_BSG=y
@@ -109,6 +122,8 @@ CONFIG_DEFAULT_AS=y
 # CONFIG_DEFAULT_CFQ is not set
 # CONFIG_DEFAULT_NOOP is not set
 CONFIG_DEFAULT_IOSCHED="anticipatory"
+CONFIG_CLASSIC_RCU=y
+# CONFIG_PREEMPT_RCU is not set
 CONFIG_SYSVIPC_COMPAT=y
 CONFIG_GENERIC_HARDIRQS=y
 
@@ -119,7 +134,8 @@ CONFIG_TICK_ONESHOT=y
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
-# CONFIG_SMP is not set
+CONFIG_SMP=y
+CONFIG_NR_CPUS=64
 # CONFIG_CPU_FREQ is not set
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_FIND_NEXT_BIT=y
@@ -169,9 +185,12 @@ CONFIG_BINFMT_ELF32=y
 CONFIG_BINFMT_ELF=y
 CONFIG_BINFMT_MISC=m
 CONFIG_SOLARIS_EMUL=y
+CONFIG_SCHED_SMT=y
+CONFIG_SCHED_MC=y
 # CONFIG_PREEMPT_NONE is not set
 CONFIG_PREEMPT_VOLUNTARY=y
 # CONFIG_PREEMPT is not set
+# CONFIG_RCU_TRACE is not set
 # CONFIG_CMDLINE_BOOL is not set
 
 #
@@ -189,6 +208,7 @@ CONFIG_XFRM=y
 CONFIG_XFRM_USER=m
 # CONFIG_XFRM_SUB_POLICY is not set
 CONFIG_XFRM_MIGRATE=y
+# CONFIG_XFRM_STATISTICS is not set
 CONFIG_NET_KEY=m
 CONFIG_NET_KEY_MIGRATE=y
 CONFIG_INET=y
@@ -249,9 +269,9 @@ CONFIG_IP_DCCP_ACKVEC=y
 CONFIG_IP_DCCP_CCID2=m
 # CONFIG_IP_DCCP_CCID2_DEBUG is not set
 CONFIG_IP_DCCP_CCID3=m
-CONFIG_IP_DCCP_TFRC_LIB=m
 # CONFIG_IP_DCCP_CCID3_DEBUG is not set
 CONFIG_IP_DCCP_CCID3_RTO=100
+CONFIG_IP_DCCP_TFRC_LIB=m
 
 #
 # DCCP Kernel Hacking
@@ -279,6 +299,7 @@ CONFIG_VLAN_8021Q=m
 CONFIG_NET_PKTGEN=m
 CONFIG_NET_TCPPROBE=m
 # CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
 # CONFIG_IRDA is not set
 # CONFIG_BT is not set
 # CONFIG_AF_RXRPC is not set
@@ -343,6 +364,7 @@ CONFIG_BLK_DEV_IDE=y
 CONFIG_BLK_DEV_IDEDISK=y
 # CONFIG_IDEDISK_MULTI_MODE is not set
 CONFIG_BLK_DEV_IDECD=y
+CONFIG_BLK_DEV_IDECD_VERBOSE_ERRORS=y
 # CONFIG_BLK_DEV_IDETAPE is not set
 # CONFIG_BLK_DEV_IDEFLOPPY is not set
 # CONFIG_BLK_DEV_IDESCSI is not set
@@ -359,7 +381,6 @@ CONFIG_IDE_GENERIC=y
 # PCI IDE chipsets support
 #
 CONFIG_BLK_DEV_IDEPCI=y
-# CONFIG_IDEPCI_SHARE_IRQ is not set
 CONFIG_IDEPCI_PCIBUS_ORDER=y
 # CONFIG_BLK_DEV_GENERIC is not set
 # CONFIG_BLK_DEV_OPTI621 is not set
@@ -389,7 +410,6 @@ CONFIG_BLK_DEV_ALI15X3=y
 # CONFIG_BLK_DEV_TRM290 is not set
 # CONFIG_BLK_DEV_VIA82CXXX is not set
 # CONFIG_BLK_DEV_TC86C001 is not set
-# CONFIG_IDE_ARM is not set
 CONFIG_BLK_DEV_IDEDMA=y
 CONFIG_IDE_ARCH_OBSOLETE_INIT=y
 # CONFIG_BLK_DEV_HD is not set
@@ -501,7 +521,6 @@ CONFIG_NETDEVICES=y
 # CONFIG_EQUALIZER is not set
 # CONFIG_TUN is not set
 # CONFIG_VETH is not set
-# CONFIG_IP1000 is not set
 # CONFIG_ARCNET is not set
 # CONFIG_PHYLIB is not set
 CONFIG_NET_ETHERNET=y
@@ -533,6 +552,7 @@ CONFIG_NET_PCI=y
 # CONFIG_NE2K_PCI is not set
 # CONFIG_8139CP is not set
 # CONFIG_8139TOO is not set
+# CONFIG_R6040 is not set
 # CONFIG_SIS900 is not set
 # CONFIG_EPIC100 is not set
 # CONFIG_SUNDANCE is not set
@@ -545,6 +565,9 @@ CONFIG_E1000=m
 CONFIG_E1000_NAPI=y
 # CONFIG_E1000_DISABLE_PACKET_SPLIT is not set
 # CONFIG_E1000E is not set
+# CONFIG_E1000E_ENABLED is not set
+# CONFIG_IP1000 is not set
+# CONFIG_IGB is not set
 # CONFIG_MYRI_SBUS is not set
 # CONFIG_NS83820 is not set
 # CONFIG_HAMACHI is not set
@@ -570,6 +593,7 @@ CONFIG_NETDEV_10000=y
 CONFIG_NIU=m
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
+# CONFIG_BNX2X is not set
 # CONFIG_TR is not set
 
 #
@@ -602,7 +626,6 @@ CONFIG_PPPOE=m
 # CONFIG_SLIP is not set
 CONFIG_SLHC=m
 # CONFIG_NET_FC is not set
-# CONFIG_SHAPER is not set
 # CONFIG_NETCONSOLE is not set
 # CONFIG_NETPOLL is not set
 # CONFIG_NET_POLL_CONTROLLER is not set
@@ -679,6 +702,7 @@ CONFIG_VT_CONSOLE=y
 CONFIG_HW_CONSOLE=y
 # CONFIG_VT_HW_CONSOLE_BINDING is not set
 # CONFIG_SERIAL_NONSTANDARD is not set
+# CONFIG_NOZOMI is not set
 
 #
 # Serial drivers
@@ -747,13 +771,13 @@ CONFIG_I2C_ALGOBIT=y
 #
 # Miscellaneous I2C Chip support
 #
-# CONFIG_SENSORS_DS1337 is not set
-# CONFIG_SENSORS_DS1374 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_SENSORS_EEPROM is not set
 # CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
 # CONFIG_SENSORS_PCA9539 is not set
 # CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_TPS65010 is not set
 # CONFIG_SENSORS_MAX6875 is not set
 # CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
@@ -990,6 +1014,7 @@ CONFIG_SND_ALI5451=m
 # CONFIG_SND_BT87X is not set
 # CONFIG_SND_CA0106 is not set
 # CONFIG_SND_CMIPCI is not set
+# CONFIG_SND_OXYGEN is not set
 # CONFIG_SND_CS4281 is not set
 # CONFIG_SND_CS46XX is not set
 # CONFIG_SND_DARLA20 is not set
@@ -1014,6 +1039,7 @@ CONFIG_SND_ALI5451=m
 # CONFIG_SND_HDA_INTEL is not set
 # CONFIG_SND_HDSP is not set
 # CONFIG_SND_HDSPM is not set
+# CONFIG_SND_HIFIER is not set
 # CONFIG_SND_ICE1712 is not set
 # CONFIG_SND_ICE1724 is not set
 # CONFIG_SND_INTEL8X0 is not set
@@ -1031,6 +1057,7 @@ CONFIG_SND_ALI5451=m
 # CONFIG_SND_TRIDENT is not set
 # CONFIG_SND_VIA82XX is not set
 # CONFIG_SND_VIA82XX_MODEM is not set
+# CONFIG_SND_VIRTUOSO is not set
 # CONFIG_SND_VX222 is not set
 # CONFIG_SND_YMFPCI is not set
 # CONFIG_SND_AC97_POWER_SAVE is not set
@@ -1057,6 +1084,10 @@ CONFIG_SND_SUN_CS4231=m
 # SoC Audio support for SuperH
 #
 
+#
+# ALSA SoC audio for Freescale SOCs
+#
+
 #
 # Open Sound System
 #
@@ -1080,6 +1111,7 @@ CONFIG_USB_ARCH_HAS_OHCI=y
 CONFIG_USB_ARCH_HAS_EHCI=y
 CONFIG_USB=y
 # CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
 
 #
 # Miscellaneous USB options
@@ -1093,7 +1125,6 @@ CONFIG_USB_DEVICEFS=y
 # USB Host Controller Drivers
 #
 CONFIG_USB_EHCI_HCD=m
-# CONFIG_USB_EHCI_SPLIT_ISO is not set
 # CONFIG_USB_EHCI_ROOT_HUB_TT is not set
 # CONFIG_USB_EHCI_TT_NEWSCHED is not set
 # CONFIG_USB_ISP116X_HCD is not set
@@ -1143,10 +1174,6 @@ CONFIG_USB_STORAGE=m
 #
 # USB port drivers
 #
-
-#
-# USB Serial Converter support
-#
 # CONFIG_USB_SERIAL is not set
 
 #
@@ -1172,14 +1199,6 @@ CONFIG_USB_STORAGE=m
 # CONFIG_USB_TRANCEVIBRATOR is not set
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
-
-#
-# USB DSL modem support
-#
-
-#
-# USB Gadget Support
-#
 # CONFIG_USB_GADGET is not set
 # CONFIG_MMC is not set
 # CONFIG_NEW_LEDS is not set
@@ -1332,11 +1351,6 @@ CONFIG_NLS_DEFAULT="iso8859-1"
 # CONFIG_NLS_KOI8_U is not set
 # CONFIG_NLS_UTF8 is not set
 # CONFIG_DLM is not set
-CONFIG_INSTRUMENTATION=y
-CONFIG_PROFILING=y
-CONFIG_OPROFILE=m
-CONFIG_KPROBES=y
-# CONFIG_MARKERS is not set
 
 #
 # Kernel hacking
@@ -1374,6 +1388,8 @@ CONFIG_DEBUG_BUGVERBOSE=y
 CONFIG_FORCED_INLINING=y
 # CONFIG_BOOT_PRINTK_DELAY is not set
 # CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_KPROBES_SANITY_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
 # CONFIG_SAMPLES is not set
@@ -1396,8 +1412,9 @@ CONFIG_ASYNC_MEMCPY=m
 CONFIG_ASYNC_XOR=m
 CONFIG_CRYPTO=y
 CONFIG_CRYPTO_ALGAPI=y
-CONFIG_CRYPTO_AEAD=m
+CONFIG_CRYPTO_AEAD=y
 CONFIG_CRYPTO_BLKCIPHER=y
+# CONFIG_CRYPTO_SEQIV is not set
 CONFIG_CRYPTO_HASH=y
 CONFIG_CRYPTO_MANAGER=y
 CONFIG_CRYPTO_HMAC=y
@@ -1416,6 +1433,9 @@ CONFIG_CRYPTO_CBC=y
 CONFIG_CRYPTO_PCBC=m
 CONFIG_CRYPTO_LRW=m
 CONFIG_CRYPTO_XTS=m
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_CCM is not set
 # CONFIG_CRYPTO_CRYPTD is not set
 CONFIG_CRYPTO_DES=y
 CONFIG_CRYPTO_FCRYPT=m
@@ -1431,13 +1451,16 @@ CONFIG_CRYPTO_ARC4=m
 CONFIG_CRYPTO_KHAZAD=m
 CONFIG_CRYPTO_ANUBIS=m
 CONFIG_CRYPTO_SEED=m
+# CONFIG_CRYPTO_SALSA20 is not set
 CONFIG_CRYPTO_DEFLATE=y
 CONFIG_CRYPTO_MICHAEL_MIC=m
 CONFIG_CRYPTO_CRC32C=m
 CONFIG_CRYPTO_CAMELLIA=m
 CONFIG_CRYPTO_TEST=m
 CONFIG_CRYPTO_AUTHENC=m
+# CONFIG_CRYPTO_LZO is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_CRYPTO_DEV_HIFN_795X is not set
 
 #
 # Library routines
index ef50d217432f151f1ab3ed6e701d3ed2281c9afd..4b78b24ef413744c579d935355f6a3c0c0d06cda 100644 (file)
@@ -11,7 +11,7 @@ obj-y         := process.o setup.o cpu.o idprom.o \
                   traps.o auxio.o una_asm.o sysfs.o iommu.o \
                   irq.o ptrace.o time.o sys_sparc.o signal.o \
                   unaligned.o central.o pci.o starfire.o semaphore.o \
-                  power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \
+                  power.o sbus.o sparc64_ksyms.o chmc.o \
                   visemul.o prom.o of_device.o hvapi.o sstate.o mdesc.o
 
 obj-$(CONFIG_STACKTRACE) += stacktrace.o
index 070a4846c0cb7d7dcb06be192bcd8879733f5112..5623a4d59dff0a642ca0e468527214d9b456384a 100644 (file)
@@ -472,94 +472,15 @@ static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr,
        spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
-#define SG_ENT_PHYS_ADDRESS(SG)        (__pa(sg_virt((SG))))
-
-static void fill_sg(iopte_t *iopte, struct scatterlist *sg,
-                   int nused, int nelems,
-                   unsigned long iopte_protection)
-{
-       struct scatterlist *dma_sg = sg;
-       int i;
-
-       for (i = 0; i < nused; i++) {
-               unsigned long pteval = ~0UL;
-               u32 dma_npages;
-
-               dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) +
-                             dma_sg->dma_length +
-                             ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
-               do {
-                       unsigned long offset;
-                       signed int len;
-
-                       /* If we are here, we know we have at least one
-                        * more page to map.  So walk forward until we
-                        * hit a page crossing, and begin creating new
-                        * mappings from that spot.
-                        */
-                       for (;;) {
-                               unsigned long tmp;
-
-                               tmp = SG_ENT_PHYS_ADDRESS(sg);
-                               len = sg->length;
-                               if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) {
-                                       pteval = tmp & IO_PAGE_MASK;
-                                       offset = tmp & (IO_PAGE_SIZE - 1UL);
-                                       break;
-                               }
-                               if (((tmp ^ (tmp + len - 1UL)) >> IO_PAGE_SHIFT) != 0UL) {
-                                       pteval = (tmp + IO_PAGE_SIZE) & IO_PAGE_MASK;
-                                       offset = 0UL;
-                                       len -= (IO_PAGE_SIZE - (tmp & (IO_PAGE_SIZE - 1UL)));
-                                       break;
-                               }
-                               sg = sg_next(sg);
-                               nelems--;
-                       }
-
-                       pteval = iopte_protection | (pteval & IOPTE_PAGE);
-                       while (len > 0) {
-                               *iopte++ = __iopte(pteval);
-                               pteval += IO_PAGE_SIZE;
-                               len -= (IO_PAGE_SIZE - offset);
-                               offset = 0;
-                               dma_npages--;
-                       }
-
-                       pteval = (pteval & IOPTE_PAGE) + len;
-                       sg = sg_next(sg);
-                       nelems--;
-
-                       /* Skip over any tail mappings we've fully mapped,
-                        * adjusting pteval along the way.  Stop when we
-                        * detect a page crossing event.
-                        */
-                       while (nelems &&
-                              (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
-                              (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
-                              ((pteval ^
-                                (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
-                               pteval += sg->length;
-                               sg = sg_next(sg);
-                               nelems--;
-                       }
-                       if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
-                               pteval = ~0UL;
-               } while (dma_npages != 0);
-               dma_sg = sg_next(dma_sg);
-       }
-}
-
 static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
                         int nelems, enum dma_data_direction direction)
 {
-       struct iommu *iommu;
+       unsigned long flags, ctx, i, npages, iopte_protection;
+       struct scatterlist *sg;
        struct strbuf *strbuf;
-       unsigned long flags, ctx, npages, iopte_protection;
+       struct iommu *iommu;
        iopte_t *base;
        u32 dma_base;
-       struct scatterlist *sgtmp;
-       int used;
 
        /* Fast path single entry scatterlists. */
        if (nelems == 1) {
@@ -578,11 +499,7 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
        if (unlikely(direction == DMA_NONE))
                goto bad_no_ctx;
 
-       /* Step 1: Prepare scatter list. */
-
-       npages = prepare_sg(sglist, nelems);
-
-       /* Step 2: Allocate a cluster and context, if necessary. */
+       npages = calc_npages(sglist, nelems);
 
        spin_lock_irqsave(&iommu->lock, flags);
 
@@ -599,18 +516,6 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
        dma_base = iommu->page_table_map_base +
                ((base - iommu->page_table) << IO_PAGE_SHIFT);
 
-       /* Step 3: Normalize DMA addresses. */
-       used = nelems;
-
-       sgtmp = sglist;
-       while (used && sgtmp->dma_length) {
-               sgtmp->dma_address += dma_base;
-               sgtmp = sg_next(sgtmp);
-               used--;
-       }
-       used = nelems - used;
-
-       /* Step 4: Create the mappings. */
        if (strbuf->strbuf_enabled)
                iopte_protection = IOPTE_STREAMING(ctx);
        else
@@ -618,13 +523,27 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
        if (direction != DMA_TO_DEVICE)
                iopte_protection |= IOPTE_WRITE;
 
-       fill_sg(base, sglist, used, nelems, iopte_protection);
+       for_each_sg(sglist, sg, nelems, i) {
+               unsigned long paddr = SG_ENT_PHYS_ADDRESS(sg);
+               unsigned long slen = sg->length;
+               unsigned long this_npages;
 
-#ifdef VERIFY_SG
-       verify_sglist(sglist, nelems, base, npages);
-#endif
+               this_npages = iommu_num_pages(paddr, slen);
 
-       return used;
+               sg->dma_address = dma_base | (paddr & ~IO_PAGE_MASK);
+               sg->dma_length = slen;
+
+               paddr &= IO_PAGE_MASK;
+               while (this_npages--) {
+                       iopte_val(*base) = iopte_protection | paddr;
+
+                       base++;
+                       paddr += IO_PAGE_SIZE;
+                       dma_base += IO_PAGE_SIZE;
+               }
+       }
+
+       return nelems;
 
 bad:
        iommu_free_ctx(iommu, ctx);
@@ -637,11 +556,10 @@ bad_no_ctx:
 static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist,
                            int nelems, enum dma_data_direction direction)
 {
-       struct iommu *iommu;
+       unsigned long flags, ctx, i, npages;
        struct strbuf *strbuf;
+       struct iommu *iommu;
        iopte_t *base;
-       unsigned long flags, ctx, i, npages;
-       struct scatterlist *sg, *sgprv;
        u32 bus_addr;
 
        if (unlikely(direction == DMA_NONE)) {
@@ -654,15 +572,7 @@ static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist,
 
        bus_addr = sglist->dma_address & IO_PAGE_MASK;
 
-       sgprv = NULL;
-       for_each_sg(sglist, sg, nelems, i) {
-               if (sg->dma_length == 0)
-                       break;
-               sgprv = sg;
-       }
-
-       npages = (IO_PAGE_ALIGN(sgprv->dma_address + sgprv->dma_length) -
-                 bus_addr) >> IO_PAGE_SHIFT;
+       npages = calc_npages(sglist, nelems);
 
        base = iommu->page_table +
                ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
diff --git a/arch/sparc64/kernel/iommu_common.c b/arch/sparc64/kernel/iommu_common.c
deleted file mode 100644 (file)
index efd5dff..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/* $Id: iommu_common.c,v 1.9 2001/12/17 07:05:09 davem Exp $
- * iommu_common.c: UltraSparc SBUS/PCI common iommu code.
- *
- * Copyright (C) 1999 David S. Miller (davem@redhat.com)
- */
-
-#include "iommu_common.h"
-
-/* You are _strongly_ advised to enable the following debugging code
- * any time you make changes to the sg code below, run it for a while
- * with filesystems mounted read-only before buying the farm... -DaveM
- */
-
-#ifdef VERIFY_SG
-static int verify_lengths(struct scatterlist *sglist, int nents, int npages)
-{
-       int sg_len, dma_len;
-       int i, pgcount;
-       struct scatterlist *sg;
-
-       sg_len = 0;
-       for_each_sg(sglist, sg, nents, i)
-               sg_len += sg->length;
-
-       dma_len = 0;
-       for_each_sg(sglist, sg, nents, i) {
-               if (!sg->dma_length)
-                       break;
-               dma_len += sg->dma_length;
-       }
-
-       if (sg_len != dma_len) {
-               printk("verify_lengths: Error, different, sg[%d] dma[%d]\n",
-                      sg_len, dma_len);
-               return -1;
-       }
-
-       pgcount = 0;
-       for_each_sg(sglist, sg, nents, i) {
-               unsigned long start, end;
-
-               if (!sg->dma_length)
-                       break;
-
-               start = sg->dma_address;
-               start = start & IO_PAGE_MASK;
-
-               end = sg->dma_address + sg->dma_length;
-               end = (end + (IO_PAGE_SIZE - 1)) & IO_PAGE_MASK;
-
-               pgcount += ((end - start) >> IO_PAGE_SHIFT);
-       }
-
-       if (pgcount != npages) {
-               printk("verify_lengths: Error, page count wrong, "
-                      "npages[%d] pgcount[%d]\n",
-                      npages, pgcount);
-               return -1;
-       }
-
-       /* This test passes... */
-       return 0;
-}
-
-static int verify_one_map(struct scatterlist *dma_sg, struct scatterlist **__sg, int nents, iopte_t **__iopte)
-{
-       struct scatterlist *sg = *__sg;
-       iopte_t *iopte = *__iopte;
-       u32 dlen = dma_sg->dma_length;
-       u32 daddr;
-       unsigned int sglen;
-       unsigned long sgaddr;
-
-       daddr = dma_sg->dma_address;
-       sglen = sg->length;
-       sgaddr = (unsigned long) sg_virt(sg);
-       while (dlen > 0) {
-               unsigned long paddr;
-
-               /* SG and DMA_SG must begin at the same sub-page boundary. */
-               if ((sgaddr & ~IO_PAGE_MASK) != (daddr & ~IO_PAGE_MASK)) {
-                       printk("verify_one_map: Wrong start offset "
-                              "sg[%08lx] dma[%08x]\n",
-                              sgaddr, daddr);
-                       nents = -1;
-                       goto out;
-               }
-
-               /* Verify the IOPTE points to the right page. */
-               paddr = iopte_val(*iopte) & IOPTE_PAGE;
-               if ((paddr + PAGE_OFFSET) != (sgaddr & IO_PAGE_MASK)) {
-                       printk("verify_one_map: IOPTE[%08lx] maps the "
-                              "wrong page, should be [%08lx]\n",
-                              iopte_val(*iopte), (sgaddr & IO_PAGE_MASK) - PAGE_OFFSET);
-                       nents = -1;
-                       goto out;
-               }
-
-               /* If this SG crosses a page, adjust to that next page
-                * boundary and loop.
-                */
-               if ((sgaddr & IO_PAGE_MASK) ^ ((sgaddr + sglen - 1) & IO_PAGE_MASK)) {
-                       unsigned long next_page, diff;
-
-                       next_page = (sgaddr + IO_PAGE_SIZE) & IO_PAGE_MASK;
-                       diff = next_page - sgaddr;
-                       sgaddr += diff;
-                       daddr += diff;
-                       sglen -= diff;
-                       dlen -= diff;
-                       if (dlen > 0)
-                               iopte++;
-                       continue;
-               }
-
-               /* SG wholly consumed within this page. */
-               daddr += sglen;
-               dlen -= sglen;
-
-               if (dlen > 0 && ((daddr & ~IO_PAGE_MASK) == 0))
-                       iopte++;
-
-               sg = sg_next(sg);
-               if (--nents <= 0)
-                       break;
-               sgaddr = (unsigned long) sg_virt(sg);
-               sglen = sg->length;
-       }
-       if (dlen < 0) {
-               /* Transfer overrun, big problems. */
-               printk("verify_one_map: Transfer overrun by %d bytes.\n",
-                      -dlen);
-               nents = -1;
-       } else {
-               /* Advance to next dma_sg implies that the next iopte will
-                * begin it.
-                */
-               iopte++;
-       }
-
-out:
-       *__sg = sg;
-       *__iopte = iopte;
-       return nents;
-}
-
-static int verify_maps(struct scatterlist *sg, int nents, iopte_t *iopte)
-{
-       struct scatterlist *dma_sg = sg;
-       struct scatterlist *orig_dma_sg = dma_sg;
-       int orig_nents = nents;
-
-       for (;;) {
-               nents = verify_one_map(dma_sg, &sg, nents, &iopte);
-               if (nents <= 0)
-                       break;
-               dma_sg = sg_next(dma_sg);
-               if (dma_sg->dma_length == 0)
-                       break;
-       }
-
-       if (nents > 0) {
-               printk("verify_maps: dma maps consumed by some sgs remain (%d)\n",
-                      nents);
-               return -1;
-       }
-
-       if (nents < 0) {
-               printk("verify_maps: Error, messed up mappings, "
-                      "at sg %d dma_sg %d\n",
-                      (int) (orig_nents + nents), (int) (dma_sg - orig_dma_sg));
-               return -1;
-       }
-
-       /* This test passes... */
-       return 0;
-}
-
-void verify_sglist(struct scatterlist *sglist, int nents, iopte_t *iopte, int npages)
-{
-       struct scatterlist *sg;
-
-       if (verify_lengths(sglist, nents, npages) < 0 ||
-           verify_maps(sglist, nents, iopte) < 0) {
-               int i;
-
-               printk("verify_sglist: Crap, messed up mappings, dumping, iodma at ");
-               printk("%016lx.\n", sglist->dma_address & IO_PAGE_MASK);
-
-               for_each_sg(sglist, sg, nents, i) {
-                       printk("sg(%d): page_addr(%p) off(%x) length(%x) "
-                              "dma_address[%016x] dma_length[%016x]\n",
-                              i,
-                              page_address(sg_page(sg)), sg->offset,
-                              sg->length,
-                              sg->dma_address, sg->dma_length);
-               }
-       }
-
-       /* Seems to be ok */
-}
-#endif
-
-unsigned long prepare_sg(struct scatterlist *sg, int nents)
-{
-       struct scatterlist *dma_sg = sg;
-       unsigned long prev;
-       u32 dent_addr, dent_len;
-
-       prev  = (unsigned long) sg_virt(sg);
-       prev += (unsigned long) (dent_len = sg->length);
-       dent_addr = (u32) ((unsigned long)(sg_virt(sg)) & (IO_PAGE_SIZE - 1UL));
-       while (--nents) {
-               unsigned long addr;
-
-               sg = sg_next(sg);
-               addr = (unsigned long) sg_virt(sg);
-               if (! VCONTIG(prev, addr)) {
-                       dma_sg->dma_address = dent_addr;
-                       dma_sg->dma_length = dent_len;
-                       dma_sg = sg_next(dma_sg);
-
-                       dent_addr = ((dent_addr +
-                                     dent_len +
-                                     (IO_PAGE_SIZE - 1UL)) >> IO_PAGE_SHIFT);
-                       dent_addr <<= IO_PAGE_SHIFT;
-                       dent_addr += addr & (IO_PAGE_SIZE - 1UL);
-                       dent_len = 0;
-               }
-               dent_len += sg->length;
-               prev = addr + sg->length;
-       }
-       dma_sg->dma_address = dent_addr;
-       dma_sg->dma_length = dent_len;
-
-       if (dma_sg != sg) {
-               dma_sg = sg_next(dma_sg);
-               dma_sg->dma_length = 0;
-       }
-
-       return ((unsigned long) dent_addr +
-               (unsigned long) dent_len +
-               (IO_PAGE_SIZE - 1UL)) >> IO_PAGE_SHIFT;
-}
index 75b5a58145227aa8aabea141d3e2190757bbda23..4b5cafa2877a4330b6f3f23d46be309009f2a2cc 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/scatterlist.h>
+#include <linux/device.h>
 
 #include <asm/iommu.h>
 #include <asm/scatterlist.h>
  */
 #define IOMMU_PAGE_SHIFT               13
 
+#define SG_ENT_PHYS_ADDRESS(SG)        (__pa(sg_virt((SG))))
+
+static inline unsigned long iommu_num_pages(unsigned long vaddr,
+                                           unsigned long slen)
+{
+       unsigned long npages;
+
+       npages = IO_PAGE_ALIGN(vaddr + slen) - (vaddr & IO_PAGE_MASK);
+       npages >>= IO_PAGE_SHIFT;
+
+       return npages;
+}
+
+static inline unsigned long calc_npages(struct scatterlist *sglist, int nelems)
+{
+       unsigned long i, npages = 0;
+       struct scatterlist *sg;
+
+       for_each_sg(sglist, sg, nelems, i) {
+               unsigned long paddr = SG_ENT_PHYS_ADDRESS(sg);
+               npages += iommu_num_pages(paddr, sg->length);
+       }
+
+       return npages;
+}
+
 /* You are _strongly_ advised to enable the following debugging code
  * any time you make changes to the sg code below, run it for a while
  * with filesystems mounted read-only before buying the farm... -DaveM
@@ -46,4 +73,4 @@ extern void verify_sglist(struct scatterlist *sg, int nents, iopte_t *iopte, int
 #define VCONTIG(__X, __Y)      (((__X) == (__Y)) || \
                                 (((__X) | (__Y)) << (64UL - PAGE_SHIFT)) == 0UL)
 
-extern unsigned long prepare_sg(struct scatterlist *sg, int nents);
+extern unsigned long prepare_sg(struct device *dev, struct scatterlist *sg, int nents);
index 1aa8e044b1057c5d8a2d34ae56447787faac4773..61baf8dc095e2d2631e7958b4473d419524e47d9 100644 (file)
@@ -365,113 +365,14 @@ static void dma_4v_unmap_single(struct device *dev, dma_addr_t bus_addr,
        spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
-#define SG_ENT_PHYS_ADDRESS(SG)        (__pa(sg_virt((SG))))
-
-static long fill_sg(long entry, struct device *dev,
-                   struct scatterlist *sg,
-                   int nused, int nelems, unsigned long prot)
-{
-       struct scatterlist *dma_sg = sg;
-       unsigned long flags;
-       int i;
-
-       local_irq_save(flags);
-
-       iommu_batch_start(dev, prot, entry);
-
-       for (i = 0; i < nused; i++) {
-               unsigned long pteval = ~0UL;
-               u32 dma_npages;
-
-               dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) +
-                             dma_sg->dma_length +
-                             ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
-               do {
-                       unsigned long offset;
-                       signed int len;
-
-                       /* If we are here, we know we have at least one
-                        * more page to map.  So walk forward until we
-                        * hit a page crossing, and begin creating new
-                        * mappings from that spot.
-                        */
-                       for (;;) {
-                               unsigned long tmp;
-
-                               tmp = SG_ENT_PHYS_ADDRESS(sg);
-                               len = sg->length;
-                               if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) {
-                                       pteval = tmp & IO_PAGE_MASK;
-                                       offset = tmp & (IO_PAGE_SIZE - 1UL);
-                                       break;
-                               }
-                               if (((tmp ^ (tmp + len - 1UL)) >> IO_PAGE_SHIFT) != 0UL) {
-                                       pteval = (tmp + IO_PAGE_SIZE) & IO_PAGE_MASK;
-                                       offset = 0UL;
-                                       len -= (IO_PAGE_SIZE - (tmp & (IO_PAGE_SIZE - 1UL)));
-                                       break;
-                               }
-                               sg = sg_next(sg);
-                               nelems--;
-                       }
-
-                       pteval = (pteval & IOPTE_PAGE);
-                       while (len > 0) {
-                               long err;
-
-                               err = iommu_batch_add(pteval);
-                               if (unlikely(err < 0L))
-                                       goto iommu_map_failed;
-
-                               pteval += IO_PAGE_SIZE;
-                               len -= (IO_PAGE_SIZE - offset);
-                               offset = 0;
-                               dma_npages--;
-                       }
-
-                       pteval = (pteval & IOPTE_PAGE) + len;
-                       sg = sg_next(sg);
-                       nelems--;
-
-                       /* Skip over any tail mappings we've fully mapped,
-                        * adjusting pteval along the way.  Stop when we
-                        * detect a page crossing event.
-                        */
-                       while (nelems &&
-                              (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
-                              (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
-                              ((pteval ^
-                                (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
-                               pteval += sg->length;
-                               sg = sg_next(sg);
-                               nelems--;
-                       }
-                       if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
-                               pteval = ~0UL;
-               } while (dma_npages != 0);
-               dma_sg = sg_next(dma_sg);
-       }
-
-       if (unlikely(iommu_batch_end() < 0L))
-               goto iommu_map_failed;
-
-       local_irq_restore(flags);
-       return 0;
-
-iommu_map_failed:
-       local_irq_restore(flags);
-       return -1L;
-}
-
 static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
                         int nelems, enum dma_data_direction direction)
 {
+       unsigned long flags, npages, i, prot;
+       struct scatterlist *sg;
        struct iommu *iommu;
-       unsigned long flags, npages, prot;
-       u32 dma_base;
-       struct scatterlist *sgtmp;
        long entry, err;
-       int used;
+       u32 dma_base;
 
        /* Fast path single entry scatterlists. */
        if (nelems == 1) {
@@ -489,10 +390,8 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
        if (unlikely(direction == DMA_NONE))
                goto bad;
 
-       /* Step 1: Prepare scatter list. */
-       npages = prepare_sg(sglist, nelems);
+       npages = calc_npages(sglist, nelems);
 
-       /* Step 2: Allocate a cluster and context, if necessary. */
        spin_lock_irqsave(&iommu->lock, flags);
        entry = arena_alloc(&iommu->arena, npages);
        spin_unlock_irqrestore(&iommu->lock, flags);
@@ -503,27 +402,45 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
        dma_base = iommu->page_table_map_base +
                (entry << IO_PAGE_SHIFT);
 
-       /* Step 3: Normalize DMA addresses. */
-       used = nelems;
-
-       sgtmp = sglist;
-       while (used && sgtmp->dma_length) {
-               sgtmp->dma_address += dma_base;
-               sgtmp = sg_next(sgtmp);
-               used--;
-       }
-       used = nelems - used;
-
-       /* Step 4: Create the mappings. */
        prot = HV_PCI_MAP_ATTR_READ;
        if (direction != DMA_TO_DEVICE)
                prot |= HV_PCI_MAP_ATTR_WRITE;
 
-       err = fill_sg(entry, dev, sglist, used, nelems, prot);
+       local_irq_save(flags);
+
+       iommu_batch_start(dev, prot, entry);
+
+       for_each_sg(sglist, sg, nelems, i) {
+               unsigned long paddr = SG_ENT_PHYS_ADDRESS(sg);
+               unsigned long slen = sg->length;
+               unsigned long this_npages;
+
+               this_npages = iommu_num_pages(paddr, slen);
+
+               sg->dma_address = dma_base | (paddr & ~IO_PAGE_MASK);
+               sg->dma_length = slen;
+
+               paddr &= IO_PAGE_MASK;
+               while (this_npages--) {
+                       err = iommu_batch_add(paddr);
+                       if (unlikely(err < 0L)) {
+                               local_irq_restore(flags);
+                               goto iommu_map_failed;
+                       }
+
+                       paddr += IO_PAGE_SIZE;
+                       dma_base += IO_PAGE_SIZE;
+               }
+       }
+
+       err = iommu_batch_end();
+
+       local_irq_restore(flags);
+
        if (unlikely(err < 0L))
                goto iommu_map_failed;
 
-       return used;
+       return nelems;
 
 bad:
        if (printk_ratelimit())
@@ -541,12 +458,11 @@ iommu_map_failed:
 static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
                            int nelems, enum dma_data_direction direction)
 {
+       unsigned long flags, npages;
        struct pci_pbm_info *pbm;
+       u32 devhandle, bus_addr;
        struct iommu *iommu;
-       unsigned long flags, i, npages;
-       struct scatterlist *sg, *sgprv;
        long entry;
-       u32 devhandle, bus_addr;
 
        if (unlikely(direction == DMA_NONE)) {
                if (printk_ratelimit())
@@ -558,16 +474,8 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
        devhandle = pbm->devhandle;
        
        bus_addr = sglist->dma_address & IO_PAGE_MASK;
-       sgprv = NULL;
-       for_each_sg(sglist, sg, nelems, i) {
-               if (sg->dma_length == 0)
-                       break;
-
-               sgprv = sg;
-       }
 
-       npages = (IO_PAGE_ALIGN(sgprv->dma_address + sgprv->dma_length) -
-                 bus_addr) >> IO_PAGE_SHIFT;
+       npages = calc_npages(sglist, nelems);
 
        entry = ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
 
@@ -625,8 +533,8 @@ static void __init pci_sun4v_scan_bus(struct pci_pbm_info *pbm)
        /* XXX register error interrupt handlers XXX */
 }
 
-static unsigned long probe_existing_entries(struct pci_pbm_info *pbm,
-                                           struct iommu *iommu)
+static unsigned long __init probe_existing_entries(struct pci_pbm_info *pbm,
+                                                  struct iommu *iommu)
 {
        struct iommu_arena *arena = &iommu->arena;
        unsigned long i, cnt = 0;
@@ -653,7 +561,7 @@ static unsigned long probe_existing_entries(struct pci_pbm_info *pbm,
        return cnt;
 }
 
-static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
+static void __init pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
 {
        struct iommu *iommu = pbm->iommu;
        struct property *prop;
index c39944927f1ac7f39f8ddb36671216ca6c2c0162..a8052b76df41b3c15694493cd7e92df7d9b8d1bb 100644 (file)
@@ -46,8 +46,6 @@
 #include <asm/ldc.h>
 #include <asm/hypervisor.h>
 
-extern void calibrate_delay(void);
-
 int sparc64_multi_core __read_mostly;
 
 cpumask_t cpu_possible_map __read_mostly = CPU_MASK_NONE;
index 60765e314bd8624dfb1dd94329fd2fb0f59ad7f9..8649635d6d74f67e2b184903c3c1d3241fe3c47b 100644 (file)
@@ -277,6 +277,7 @@ EXPORT_SYMBOL(sys_getpid);
 EXPORT_SYMBOL(sys_geteuid);
 EXPORT_SYMBOL(sys_getuid);
 EXPORT_SYMBOL(sys_getegid);
+EXPORT_SYMBOL(sysctl_nr_open);
 EXPORT_SYMBOL(sys_getgid);
 EXPORT_SYMBOL(svr4_getcontext);
 EXPORT_SYMBOL(svr4_setcontext);
index 06d10907d8cee77ed3111a2b87a2a5c6e0bd98cb..adc62f490f368f494e1543d7d7485f39098ae41b 100644 (file)
@@ -80,7 +80,8 @@ sys_call_table32:
        .word sys_fchmodat, sys_faccessat, compat_sys_pselect6, compat_sys_ppoll, sys_unshare
 /*300*/        .word compat_sys_set_robust_list, compat_sys_get_robust_list, compat_sys_migrate_pages, compat_sys_mbind, compat_sys_get_mempolicy
        .word compat_sys_set_mempolicy, compat_sys_kexec_load, compat_sys_move_pages, sys_getcpu, compat_sys_epoll_pwait
-/*310*/        .word compat_sys_utimensat, compat_sys_signalfd, compat_sys_timerfd, sys_eventfd, compat_sys_fallocate
+/*310*/        .word compat_sys_utimensat, compat_sys_signalfd, sys_timerfd_create, sys_eventfd, compat_sys_fallocate
+       .word compat_sys_timerfd_settime, compat_sys_timerfd_gettime
 
 #endif /* CONFIG_COMPAT */
 
@@ -152,7 +153,8 @@ sys_call_table:
        .word sys_fchmodat, sys_faccessat, sys_pselect6, sys_ppoll, sys_unshare
 /*300*/        .word sys_set_robust_list, sys_get_robust_list, sys_migrate_pages, sys_mbind, sys_get_mempolicy
        .word sys_set_mempolicy, sys_kexec_load, sys_move_pages, sys_getcpu, sys_epoll_pwait
-/*310*/        .word sys_utimensat, sys_signalfd, sys_timerfd, sys_eventfd, sys_fallocate
+/*310*/        .word sys_utimensat, sys_signalfd, sys_timerfd_create, sys_eventfd, sys_fallocate
+       .word sys_timerfd_settime, sys_timerfd_gettime
 
 #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
     defined(CONFIG_SOLARIS_EMUL_MODULE)
@@ -271,6 +273,7 @@ sunos_sys_table:
        .word sunos_nosys, sunos_nosys, sunos_nosys
        .word sunos_nosys
 /*310*/        .word sunos_nosys, sunos_nosys, sunos_nosys
-       .word sunos_nosys, sunos_nosys
+       .word sunos_nosys, sunos_nosys, sunos_nosys
+       .word sunos_nosys
 
 #endif
index 4352ee4d8dac32863bd588f47ce91ad5f2d8859c..d204f1ab1d4c25a62a5e01a03b3f8fe1ff4e85bf 100644 (file)
@@ -1707,6 +1707,11 @@ static void __exit rtc_mini_exit(void)
        misc_deregister(&rtc_mini_dev);
 }
 
+int __devinit read_current_timer(unsigned long *timer_val)
+{
+       *timer_val = tick_ops->get_tick();
+       return 0;
+}
 
 module_init(rtc_mini_init);
 module_exit(rtc_mini_exit);
index 61be597bf43037d3df41bd85997db373f7cbde61..9311bfe4f2f7e98cf6940782e26cabbbc5b4fd0f 100644 (file)
@@ -624,7 +624,7 @@ asmlinkage int solaris_ulimit(int cmd, int val)
        case 3: /* UL_GMEMLIM */
                return current->signal->rlim[RLIMIT_DATA].rlim_cur;
        case 4: /* UL_GDESLIM */
-               return NR_OPEN;
+               return sysctl_nr_open;
        }
        return -EINVAL;
 }
index a9d32ceabf26e5bed3c6cf2dc2810a2d94e2a07d..f53123c02c2b6b76f9b687bd1f675753d1342633 100644 (file)
@@ -859,7 +859,8 @@ asmlinkage int solaris_getmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
 
        SOLD("entry");
        lock_kernel();
-       if(fd >= NR_OPEN) goto out;
+       if (fd >= sysctl_nr_open)
+               goto out;
 
        fdt = files_fdtable(current->files);
        filp = fdt->fd[fd];
@@ -927,7 +928,8 @@ asmlinkage int solaris_putmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
 
        SOLD("entry");
        lock_kernel();
-       if(fd >= NR_OPEN) goto out;
+       if (fd >= sysctl_nr_open)
+               goto out;
 
        fdt = files_fdtable(current->files);
        filp = fdt->fd[fd];
index dd1689b814cb5a842c456a0337f66ec9db2dbe2e..99e51d059a02286bb0a80fc25c05f48f64d10058 100644 (file)
@@ -68,6 +68,10 @@ config IRQ_RELEASE_METHOD
        bool
        default y
 
+config HZ
+       int
+       default 100
+
 menu "UML-specific options"
 
 config STATIC_LINK
@@ -95,23 +99,6 @@ config LD_SCRIPT_DYN
        default y
        depends on !LD_SCRIPT_STATIC
 
-config NET
-       bool "Networking support"
-       help
-         Unless you really know what you are doing, you should say Y here.
-         The reason is that some programs need kernel networking support even
-         when running on a stand-alone machine that isn't connected to any
-         other computer. If you are upgrading from an older kernel, you
-         should consider updating your networking tools too because changes
-         in the kernel and the tools often go hand in hand. The tools are
-         contained in the package net-tools, the location and version number
-         of which are given in <file:Documentation/Changes>.
-
-         For a general introduction to Linux networking, it is highly
-         recommended to read the NET-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>.
-
-
 source "fs/Kconfig.binfmt"
 
 config HOSTFS
@@ -145,7 +132,7 @@ config HPPFS
          by removing or changing anything in /proc which gives away the
          identity of a UML.
 
-         See <http://user-mode-linux.sf.net/hppfs.html> for more information.
+         See <http://user-mode-linux.sf.net/old/hppfs.html> for more information.
 
          You only need this if you are setting up a UML honeypot.  Otherwise,
          it is safe to say 'N' here.
@@ -189,8 +176,7 @@ config MAGIC_SYSRQ
 config SMP
        bool "Symmetric multi-processing support (EXPERIMENTAL)"
        default n
-       #SMP_BROKEN is for x86_64.
-       depends on EXPERIMENTAL && (!SMP_BROKEN || (BROKEN && SMP_BROKEN))
+       depends on BROKEN
        help
          This option enables UML SMP support.
          It is NOT related to having a real SMP box. Not directly, at least.
@@ -289,6 +275,4 @@ config INPUT
        bool
        default n
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/um/Kconfig.debug"
index 9a78d354f0b40e104a9d5542926e3a6b75cf25e8..3a4b396d7979916177b30d5689b759d277eafe35 100644 (file)
@@ -18,7 +18,7 @@ config SSL
           lines on the UML that are usually made to show up on the host as
           ttys or ptys.
 
-          See <http://user-mode-linux.sourceforge.net/input.html> for more
+          See <http://user-mode-linux.sourceforge.net/old/input.html> for more
           information and command line examples of how to use this facility.
 
           Unless you have a specific reason for disabling this, say Y.
index 1f6462ffd3e8eebce195201308c6806b97375d48..8fce5e536b0fa7a268fb59657c7ddc3f99e5d568 100644 (file)
@@ -4,12 +4,12 @@ source "lib/Kconfig.debug"
 
 config GPROF
        bool "Enable gprof support"
-       depends on DEBUG_INFO
+       depends on DEBUG_INFO && FRAME_POINTER
        help
          This allows profiling of a User-Mode Linux kernel with the gprof
          utility.
 
-         See <http://user-mode-linux.sourceforge.net/gprof.html> for more
+         See <http://user-mode-linux.sourceforge.net/old/gprof.html> for more
          details.
 
          If you're involved in UML kernel development and want to use gprof,
@@ -22,7 +22,7 @@ config GCOV
          This option allows developers to retrieve coverage data from a UML
          session.
 
-         See <http://user-mode-linux.sourceforge.net/gprof.html> for more
+         See <http://user-mode-linux.sourceforge.net/old/gprof.html> for more
          details.
 
          If you're involved in UML kernel development and want to use gcov,
index 66e50026ade9bf6374fb9ddceacbb45db44b8cfa..9e9a4aaa703d60d77dc04aa6e8433bd2592a1f95 100644 (file)
@@ -14,7 +14,7 @@ config UML_NET
 
         For more information, including explanations of the networking and
         sample configurations, see
-        <http://user-mode-linux.sourceforge.net/networking.html>.
+        <http://user-mode-linux.sourceforge.net/old/networking.html>.
 
         If you'd like to be able to enable networking in the User-Mode
         linux environment, say Y; otherwise say N.  Note that you must
@@ -38,7 +38,7 @@ config UML_NET_ETHERTAP
         CONFIG_NETLINK_DEV configured as Y or M.
 
         For more information, see
-        <http://user-mode-linux.sourceforge.net/networking.html>  That site
+        <http://user-mode-linux.sourceforge.net/old/networking.html>  That site
         has examples of the UML command line to use to enable Ethertap
         networking.
 
@@ -72,7 +72,7 @@ config UML_NET_SLIP
         To use this, your host must support slip devices.
 
         For more information, see
-        <http://user-mode-linux.sourceforge.net/networking.html>.  That site
+        <http://user-mode-linux.sourceforge.net/old/networking.html>.
         has examples of the UML command line to use to enable slip
         networking, and details of a few quirks with it.
 
@@ -96,7 +96,7 @@ config UML_NET_DAEMON
         networking daemon on the host.
 
         For more information, see
-        <http://user-mode-linux.sourceforge.net/networking.html>  That site
+        <http://user-mode-linux.sourceforge.net/old/networking.html>  That site
         has examples of the UML command line to use to enable Daemon
         networking.
 
@@ -144,7 +144,7 @@ config UML_NET_MCAST
         To use this, your host kernel(s) must support IP Multicasting.
 
         For more information, see
-        <http://user-mode-linux.sourceforge.net/networking.html>  That site
+        <http://user-mode-linux.sourceforge.net/old/networking.html>  That site
         has examples of the UML command line to use to enable Multicast
         networking, and notes about the security of this approach.
 
@@ -165,7 +165,7 @@ config UML_NET_PCAP
        installed in order to build the pcap transport into UML.
 
         For more information, see
-        <http://user-mode-linux.sourceforge.net/networking.html>  That site
+        <http://user-mode-linux.sourceforge.net/old/networking.html>  That site
         has examples of the UML command line to use to enable this option.
 
        If you intend to use UML as a network monitor for the host, say
index ba6813a4aa3768952e54e927ee4f898589b6004a..cb4af9bf20747bf06b572c669589e1dd0d543c87 100644 (file)
@@ -49,7 +49,7 @@ SYS_DIR               := $(ARCH_DIR)/include/sysdep-$(SUBARCH)
 #
 # These apply to USER_CFLAGS to.
 
-KBUILD_CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\"    \
+KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
        $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap      \
        -Din6addr_loopback=kernel_in6addr_loopback \
        -Din6addr_any=kernel_in6addr_any
@@ -58,7 +58,7 @@ KBUILD_AFLAGS += $(ARCH_INCLUDE)
 
 USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
        $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
-       -D_FILE_OFFSET_BITS=64
+       $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64
 
 include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
 
@@ -130,7 +130,9 @@ CPPFLAGS_vmlinux.lds = -U$(SUBARCH) -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
 # The wrappers will select whether using "malloc" or the kernel allocator.
 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
 
-CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS)
+LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
+
+CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
 define cmd_vmlinux__
        $(CC) $(CFLAGS_vmlinux) -o $@ \
        -Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
@@ -158,7 +160,7 @@ ifneq ($(KBUILD_SRC),)
        $(Q)mkdir -p $(objtree)/include/asm-um
        $(Q)ln -fsn $(srctree)/include/asm-um/$(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $@
 else
-       $(Q)cd $(TOPDIR)/$(dir $@) ; \
+       $(Q)cd $(srctree)/$(dir $@) ; \
        ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@)
 endif
 
@@ -168,7 +170,7 @@ ifneq ($(KBUILD_SRC),)
        $(Q)mkdir -p $(objtree)/include/asm-um
        $(Q)ln -fsn $(srctree)/include/asm-$(HEADER_ARCH) include/asm-um/arch
 else
-       $(Q)cd $(TOPDIR)/include/asm-um && ln -fsn ../asm-$(HEADER_ARCH) arch
+       $(Q)cd $(srctree)/include/asm-um && ln -fsn ../asm-$(HEADER_ARCH) arch
 endif
 
 $(objtree)/$(ARCH_DIR)/include:
diff --git a/arch/um/Makefile-tt b/arch/um/Makefile-tt
deleted file mode 100644 (file)
index 03f7b10..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-# 
-# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
-# Licensed under the GPL
-#
-
index f609edede0657fe5cebb1641a8458cb66e9cdd96..86db2862f2226eea9fc6a94f0220bb8db0a48dff 100644 (file)
@@ -77,7 +77,7 @@ CONFIG_LD_SCRIPT_DYN=y
 CONFIG_NET=y
 CONFIG_BINFMT_ELF=y
 CONFIG_BINFMT_MISC=m
-# CONFIG_HOSTFS is not set
+CONFIG_HOSTFS=y
 # CONFIG_HPPFS is not set
 CONFIG_MCONSOLE=y
 CONFIG_MAGIC_SYSRQ=y
@@ -188,7 +188,7 @@ CONFIG_CON_CHAN="xterm"
 CONFIG_SSL_CHAN="pts"
 CONFIG_UNIX98_PTYS=y
 CONFIG_LEGACY_PTYS=y
-CONFIG_LEGACY_PTY_COUNT=256
+CONFIG_LEGACY_PTY_COUNT=32
 # CONFIG_WATCHDOG is not set
 CONFIG_UML_SOUND=m
 CONFIG_SOUND=m
@@ -508,7 +508,7 @@ CONFIG_DEBUG_KERNEL=y
 CONFIG_LOG_BUF_SHIFT=14
 CONFIG_DETECT_SOFTLOCKUP=y
 # CONFIG_SCHEDSTATS is not set
-CONFIG_DEBUG_SLAB=y
+# CONFIG_DEBUG_SLAB is not set
 # CONFIG_DEBUG_SLAB_LEAK is not set
 # CONFIG_DEBUG_MUTEXES is not set
 # CONFIG_DEBUG_SPINLOCK is not set
index 83bf15a3dda88472dc5aea5ade3353e3f772e0e2..2c898c4d6b6ae6b7864199e73ae2ec32db84f243 100644 (file)
@@ -8,6 +8,7 @@
 #include "chan_kern.h"
 #include "irq_kern.h"
 #include "irq_user.h"
+#include "kern_util.h"
 #include "os.h"
 
 #define LINE_BUFSIZE 4096
@@ -48,7 +49,7 @@ static int write_room(struct line *line)
        n = line->head - line->tail;
 
        if (n <= 0)
-               n = LINE_BUFSIZE + n; /* The other case */
+               n += LINE_BUFSIZE; /* The other case */
        return n - 1;
 }
 
@@ -58,17 +59,10 @@ int line_write_room(struct tty_struct *tty)
        unsigned long flags;
        int room;
 
-       if (tty->stopped)
-               return 0;
-
        spin_lock_irqsave(&line->lock, flags);
        room = write_room(line);
        spin_unlock_irqrestore(&line->lock, flags);
 
-       /*XXX: Warning to remove */
-       if (0 == room)
-               printk(KERN_DEBUG "%s: %s: no room left in buffer\n",
-                      __FUNCTION__,tty->name);
        return room;
 }
 
@@ -79,8 +73,7 @@ int line_chars_in_buffer(struct tty_struct *tty)
        int ret;
 
        spin_lock_irqsave(&line->lock, flags);
-
-       /*write_room subtracts 1 for the needed NULL, so we readd it.*/
+       /* write_room subtracts 1 for the needed NULL, so we readd it.*/
        ret = LINE_BUFSIZE - (write_room(line) + 1);
        spin_unlock_irqrestore(&line->lock, flags);
 
@@ -184,10 +177,6 @@ void line_flush_buffer(struct tty_struct *tty)
        unsigned long flags;
        int err;
 
-       /*XXX: copied from line_write, verify if it is correct!*/
-       if (tty->stopped)
-               return;
-
        spin_lock_irqsave(&line->lock, flags);
        err = flush_buffer(line);
        spin_unlock_irqrestore(&line->lock, flags);
@@ -213,9 +202,6 @@ int line_write(struct tty_struct *tty, const unsigned char *buf, int len)
        unsigned long flags;
        int n, ret = 0;
 
-       if (tty->stopped)
-               return 0;
-
        spin_lock_irqsave(&line->lock, flags);
        if (line->head != line->tail)
                ret = buffer_data(line, buf, len);
@@ -788,9 +774,11 @@ static irqreturn_t winch_interrupt(int irq, void *data)
        tty = winch->tty;
        if (tty != NULL) {
                line = tty->driver_data;
-               chan_window_size(&line->chan_list, &tty->winsize.ws_row,
-                                &tty->winsize.ws_col);
-               kill_pgrp(tty->pgrp, SIGWINCH, 1);
+               if (line != NULL) {
+                       chan_window_size(&line->chan_list, &tty->winsize.ws_row,
+                                        &tty->winsize.ws_col);
+                       kill_pgrp(tty->pgrp, SIGWINCH, 1);
+               }
        }
  out:
        if (winch->fd != -1)
index 0f3c7d14a6e32977d1731a7c46daa51e08182534..ebb265c07e4de008a17ecb0898febf419cb69042 100644 (file)
@@ -1,23 +1,25 @@
 /*
  * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
- * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Copyright (C) 2001 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include "linux/console.h"
-#include "linux/ctype.h"
-#include "linux/interrupt.h"
-#include "linux/list.h"
-#include "linux/mm.h"
-#include "linux/module.h"
-#include "linux/notifier.h"
-#include "linux/reboot.h"
-#include "linux/proc_fs.h"
-#include "linux/slab.h"
-#include "linux/syscalls.h"
-#include "linux/utsname.h"
-#include "linux/workqueue.h"
-#include "asm/uaccess.h"
+#include <linux/console.h>
+#include <linux/ctype.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+#include <linux/proc_fs.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/utsname.h>
+#include <linux/workqueue.h>
+#include <linux/mutex.h>
+#include <asm/uaccess.h>
+
 #include "init.h"
 #include "irq_kern.h"
 #include "irq_user.h"
@@ -305,7 +307,9 @@ void mconsole_stop(struct mc_request *req)
        deactivate_fd(req->originating_fd, MCONSOLE_IRQ);
        os_set_fd_block(req->originating_fd, 1);
        mconsole_reply(req, "stopped", 0, 0);
-       while (mconsole_get_request(req->originating_fd, req)) {
+       for (;;) {
+               if (!mconsole_get_request(req->originating_fd, req))
+                       continue;
                if (req->cmd->handler == mconsole_go)
                        break;
                if (req->cmd->handler == mconsole_stop) {
@@ -358,7 +362,7 @@ struct unplugged_pages {
        void *pages[UNPLUGGED_PER_PAGE];
 };
 
-static DECLARE_MUTEX(plug_mem_mutex);
+static DEFINE_MUTEX(plug_mem_mutex);
 static unsigned long long unplugged_pages_count = 0;
 static LIST_HEAD(unplugged_pages);
 static int unplug_index = UNPLUGGED_PER_PAGE;
@@ -394,7 +398,7 @@ static int mem_config(char *str, char **error_out)
 
        diff /= PAGE_SIZE;
 
-       down(&plug_mem_mutex);
+       mutex_lock(&plug_mem_mutex);
        for (i = 0; i < diff; i++) {
                struct unplugged_pages *unplugged;
                void *addr;
@@ -451,7 +455,7 @@ static int mem_config(char *str, char **error_out)
 
        err = 0;
 out_unlock:
-       up(&plug_mem_mutex);
+       mutex_unlock(&plug_mem_mutex);
 out:
        return err;
 }
@@ -741,7 +745,6 @@ void mconsole_stack(struct mc_request *req)
 {
        char *ptr = req->request.data;
        int pid_requested= -1;
-       struct task_struct *from = NULL;
        struct task_struct *to = NULL;
 
        /*
@@ -763,9 +766,7 @@ void mconsole_stack(struct mc_request *req)
                return;
        }
 
-       from = current;
-
-       to = find_task_by_pid(pid_requested);
+       to = find_task_by_pid_ns(pid_requested, &init_pid_ns);
        if ((to == NULL) || (pid_requested == 0)) {
                mconsole_reply(req, "Couldn't find that pid", 1, 0);
                return;
@@ -795,6 +796,8 @@ static int __init mconsole_init(void)
                printk(KERN_ERR "Failed to initialize management console\n");
                return 1;
        }
+       if (os_set_fd_block(sock, 0))
+               goto out;
 
        register_reboot_notifier(&reboot_notifier);
 
@@ -803,7 +806,7 @@ static int __init mconsole_init(void)
                             "mconsole", (void *)sock);
        if (err) {
                printk(KERN_ERR "Failed to get IRQ for management console\n");
-               return 1;
+               goto out;
        }
 
        if (notify_socket != NULL) {
@@ -819,6 +822,10 @@ static int __init mconsole_init(void)
        printk(KERN_INFO "mconsole (version %d) initialized on %s\n",
               MCONSOLE_VERSION, mconsole_socket_name);
        return 0;
+
+ out:
+       os_close_file(sock);
+       return 1;
 }
 
 __initcall(mconsole_init);
index 430c024a19b01d270e498df1867059c30661e315..13af2f03ed8479ac8f7f17ce4d7389120cdac297 100644 (file)
@@ -83,9 +83,8 @@ int mconsole_get_request(int fd, struct mc_request *req)
        int len;
 
        req->originlen = sizeof(req->origin);
-       req->len = recvfrom(fd, &req->request, sizeof(req->request),
-                           MSG_DONTWAIT, (struct sockaddr *) req->origin,
-                           &req->originlen);
+       req->len = recvfrom(fd, &req->request, sizeof(req->request), 0,
+                           (struct sockaddr *) req->origin, &req->originlen);
        if (req->len < 0)
                return 0;
 
index 3c6c44ca1ffa5785e1d6f34618628fc75cfea831..1e8f41a9951142e536e22312d25e106b1cf1297e 100644 (file)
@@ -318,7 +318,7 @@ static void setup_etheraddr(char *str, unsigned char *addr, char *name)
        if (str == NULL)
                goto random;
 
-       for (i = 0;i < 6; i++) {
+       for (i = 0; i < 6; i++) {
                addr[i] = simple_strtoul(str, &end, 16);
                if ((end == str) ||
                   ((*end != ':') && (*end != ',') && (*end != '\0'))) {
@@ -343,14 +343,13 @@ static void setup_etheraddr(char *str, unsigned char *addr, char *name)
        }
        if (!is_local_ether_addr(addr)) {
                printk(KERN_WARNING
-                      "Warning: attempt to assign a globally valid ethernet "
+                      "Warning: Assigning a globally valid ethernet "
                       "address to a device\n");
-               printk(KERN_WARNING "You should better enable the 2nd "
-                      "rightmost bit in the first byte of the MAC,\n");
+               printk(KERN_WARNING "You should set the 2nd rightmost bit in "
+                      "the first byte of the MAC,\n");
                printk(KERN_WARNING "i.e. %02x:%02x:%02x:%02x:%02x:%02x\n",
                       addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4],
                       addr[5]);
-               goto random;
        }
        return;
 
@@ -368,7 +367,6 @@ static struct platform_driver uml_net_driver = {
                .name  = DRIVER_NAME,
        },
 };
-static int driver_registered;
 
 static void net_device_release(struct device *dev)
 {
@@ -383,6 +381,12 @@ static void net_device_release(struct device *dev)
        free_netdev(netdev);
 }
 
+/*
+ * Ensures that platform_driver_register is called only once by
+ * eth_configure.  Will be set in an initcall.
+ */
+static int driver_registered;
+
 static void eth_configure(int n, void *init, char *mac,
                          struct transport *transport)
 {
index 29185cad9fff97328b8b3be7a4cf6dfba6130f47..abf2653f5517cbf6f65b851dd10455e7bc8e27e2 100644 (file)
@@ -201,7 +201,7 @@ static int change_tramp(char **argv, char *output, int output_len)
        close(fds[1]);
 
        if (pid > 0)
-               helper_wait(pid, 0, "change_tramp");
+               helper_wait(pid);
        return pid;
 }
 
index 330543b3129b5a7ac613e3566456eaf3ef50040c..19930081d3d8e93c42c7c0cf3d8be783ede5c304 100644 (file)
@@ -6,6 +6,7 @@
 #include "linux/completion.h"
 #include "linux/interrupt.h"
 #include "linux/list.h"
+#include "linux/mutex.h"
 #include "asm/atomic.h"
 #include "init.h"
 #include "irq_kern.h"
@@ -120,7 +121,7 @@ static int port_accept(struct port_list *port)
        return 0;
 }
 
-static DECLARE_MUTEX(ports_sem);
+static DEFINE_MUTEX(ports_mutex);
 static LIST_HEAD(ports);
 
 static void port_work_proc(struct work_struct *unused)
@@ -161,7 +162,7 @@ void *port_data(int port_num)
        struct port_dev *dev = NULL;
        int fd;
 
-       down(&ports_sem);
+       mutex_lock(&ports_mutex);
        list_for_each(ele, &ports) {
                port = list_entry(ele, struct port_list, list);
                if (port->port == port_num)
@@ -216,7 +217,7 @@ void *port_data(int port_num)
  out_free:
        kfree(port);
  out:
-       up(&ports_sem);
+       mutex_unlock(&ports_mutex);
        return dev;
 }
 
index e942e836f9954335651fc3c2b6587c2bd7d7e888..71f0959c15357b4587cd10c816d3eca1db1fbe92 100644 (file)
@@ -5,6 +5,7 @@
  * This software may be used and distributed according to the terms
  * of the GNU General Public License, incorporated herein by reference.
  */
+#include <linux/sched.h>
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/miscdevice.h>
index b8711e50da801582081409b2c1d43ce398c83b67..8b80505a3fb0117ed35676de600cce0b11b2f721 100644 (file)
@@ -109,7 +109,7 @@ static int slip_tramp(char **argv, int fd)
        read_output(fds[0], output, output_len);
        printk("%s", output);
 
-       err = helper_wait(pid, 0, argv[0]);
+       err = helper_wait(pid);
        close(fds[0]);
 
 out_free:
index 89c1be225fda5f23525f0799673ba37fe11b6483..a0ada8fec72ab5cde45462e3a2ed0311a0561e50 100644 (file)
@@ -98,7 +98,7 @@ static void slirp_close(int fd, void *data)
                       "(%d)\n", pri->pid, errno);
        }
 #endif
-       err = helper_wait(pri->pid, 1, "slirp_close");
+       err = helper_wait(pri->pid);
        if (err < 0)
                return;
 
index 875d60d0c6a25da5ab3694378dfe22fec4bf1004..f1786e64607f11d785ab333bbe46e6ba3c8d7f0e 100644 (file)
@@ -15,7 +15,6 @@
 #include "line.h"
 #include "ssl.h"
 #include "chan_kern.h"
-#include "kern_util.h"
 #include "kern.h"
 #include "init.h"
 #include "irq_user.h"
index 656036e90b196958d13e593bcff3180ebb4a25cd..cec0c33cdd395d6461783c2793a74e18acfc07b6 100644 (file)
@@ -22,7 +22,6 @@
 #include "stdio_console.h"
 #include "line.h"
 #include "chan_kern.h"
-#include "kern_util.h"
 #include "irq_user.h"
 #include "mconsole_kern.h"
 #include "init.h"
index 99f9f9605e9c53761ad03774a2e72606254a7cc1..be3a2797dac4ee054c3c4f5e44734d2d76ce85f7 100644 (file)
@@ -49,6 +49,7 @@
 #include "irq_user.h"
 #include "irq_kern.h"
 #include "ubd_user.h"
+#include "kern_util.h"
 #include "os.h"
 #include "mem.h"
 #include "mem_kern.h"
@@ -229,7 +230,7 @@ static int proc_ide_read_media(char *page, char **start, off_t off, int count,
        return len;
 }
 
-static void make_ide_entries(char *dev_name)
+static void make_ide_entries(const char *dev_name)
 {
        struct proc_dir_entry *dir, *ent;
        char name[64];
@@ -244,7 +245,7 @@ static void make_ide_entries(char *dev_name)
        ent->data = NULL;
        ent->read_proc = proc_ide_read_media;
        ent->write_proc = NULL;
-       sprintf(name,"ide0/%s", dev_name);
+       snprintf(name, sizeof(name), "ide0/%s", dev_name);
        proc_symlink(dev_name, proc_ide_root, name);
 }
 
@@ -437,7 +438,10 @@ __uml_help(ubd_setup,
 "    machine by running 'dd' on the device. <n> must be in the range\n"
 "    0 to 7. Appending an 'r' to the number will cause that device\n"
 "    to be mounted read-only. For example ubd1r=./ext_fs. Appending\n"
-"    an 's' will cause data to be written to disk on the host immediately.\n\n"
+"    an 's' will cause data to be written to disk on the host immediately.\n"
+"    'c' will cause the device to be treated as being shared between multiple\n"
+"    UMLs and file locking will be turned off - this is appropriate for a\n"
+"    cluster filesystem and inappropriate at almost all other times.\n\n"
 );
 
 static int udb_setup(char *str)
@@ -456,20 +460,6 @@ __uml_help(udb_setup,
 "    in the boot output.\n\n"
 );
 
-static int fakehd_set = 0;
-static int fakehd(char *str)
-{
-       printk(KERN_INFO "fakehd : Changing ubd name to \"hd\".\n");
-       fakehd_set = 1;
-       return 1;
-}
-
-__setup("fakehd", fakehd);
-__uml_help(fakehd,
-"fakehd\n"
-"    Change the ubd device name to \"hd\".\n\n"
-);
-
 static void do_ubd_request(struct request_queue * q);
 
 /* Only changed by ubd_init, which is an initcall. */
@@ -718,8 +708,10 @@ static int ubd_add(int n, char **error_out)
                ubd_disk_register(fake_major, ubd_dev->size, n,
                                  &fake_gendisk[n]);
 
-       /* perhaps this should also be under the "if (fake_major)" above */
-       /* using the fake_disk->disk_name and also the fakehd_set name */
+       /*
+        * Perhaps this should also be under the "if (fake_major)" above
+        * using the fake_disk->disk_name
+        */
        if (fake_ide)
                make_ide_entries(ubd_gendisk[n]->disk_name);
 
index 48fc7452bc1d11e3f3aad9c40c6983dac8526fc9..b591bb9c41dd83f4b72152c42c8ae70c60218698 100644 (file)
@@ -16,7 +16,6 @@
 #include <sys/mman.h>
 #include <sys/param.h>
 #include "asm/types.h"
-#include "kern_util.h"
 #include "user.h"
 #include "ubd_user.h"
 #include "os.h"
index d9941fe5f9316fef619fdc11aee4fb6cbbfde911..56533db25343129bcd60c152744966a2b84241cc 100644 (file)
@@ -80,7 +80,7 @@ void vde_init_libstuff(struct vde_data *vpri, struct vde_init *init)
 
        vpri->args = kmalloc(sizeof(struct vde_open_args), UM_GFP_KERNEL);
        if (vpri->args == NULL) {
-               printk(UM_KERN_ERR "vde_init_libstuff - vde_open_args"
+               printk(UM_KERN_ERR "vde_init_libstuff - vde_open_args "
                       "allocation failed");
                return;
        }
index 49c601ff2bac31955326a907938ccf6f4ff86b35..2de92a08a76bb7eaeb81fe408ee5bd1ced7ce0a7 100644 (file)
@@ -10,6 +10,6 @@
 
 extern void arch_check_bugs(void);
 extern int arch_fixup(unsigned long address, struct uml_pt_regs *regs);
-extern int arch_handle_signal(int sig, struct uml_pt_regs *regs);
+extern void arch_examine_signal(int sig, struct uml_pt_regs *regs);
 
 #endif
index a5cdf953e04a964569e9ea6f2912e9a9b9d6369a..606bb5c7fdf6a2714d68111cf96c0c7a72eed012 100644 (file)
 #include "kern_constants.h"
 
 /*
- * Assembly doesn't want any casting, but C does, so define these
- * without casts here, and define new symbols with casts inside the C
- * section.
+ * Stolen from linux/const.h, which can't be directly included since
+ * this is used in userspace code, which has no access to the kernel
+ * headers.  Changed to be suitable for adding casts to the start,
+ * rather than "UL" to the end.
  */
-#define ASM_STUB_CODE (UML_CONFIG_TOP_ADDR - 2 * UM_KERN_PAGE_SIZE)
-#define ASM_STUB_DATA (UML_CONFIG_TOP_ADDR - UM_KERN_PAGE_SIZE)
-#define ASM_STUB_START ASM_STUB_CODE
 
-/*
- * This file is included by the assembly stubs, which just want the
- * definitions above.
+/* Some constant macros are used in both assembler and
+ * C code.  Therefore we cannot annotate them always with
+ * 'UL' and other type specifiers unilaterally.  We
+ * use the following macros to deal with this.
  */
-#ifndef __ASSEMBLY__
 
-#define STUB_CODE ((unsigned long) ASM_STUB_CODE)
-#define STUB_DATA ((unsigned long) ASM_STUB_DATA)
-#define STUB_START ((unsigned long) ASM_STUB_START)
+#ifdef __ASSEMBLY__
+#define _AC(X, Y)      (Y)
+#else
+#define __AC(X, Y)     (X (Y))
+#define _AC(X, Y)      __AC(X, Y)
+#endif
+
+#define STUB_START _AC(, 0x100000)
+#define STUB_CODE _AC((unsigned long), STUB_START)
+#define STUB_DATA _AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
+#define STUB_END _AC((unsigned long), STUB_DATA + UM_KERN_PAGE_SIZE)
+
+#ifndef __ASSEMBLY__
 
 #include "sysdep/ptrace.h"
 
index 5a2263e05bb20cb62bf5b8f7eecc02cde8d324b6..9b9ced85b70378457479215c85558ebb25e05388 100644 (file)
@@ -48,7 +48,7 @@ extern void register_winch_irq(int fd, int tty_fd, int pid,
 #define __channel_help(fn, prefix) \
 __uml_help(fn, prefix "[0-9]*=<channel description>\n" \
 "    Attach a console or serial line to a host channel.  See\n" \
-"    http://user-mode-linux.sourceforge.net/input.html for a complete\n" \
+"    http://user-mode-linux.sourceforge.net/old/input.html for a complete\n" \
 "    description of this switch.\n\n" \
 );
 
index 0edab695ed4e3e665588435d6bb07074a1b692ad..b54bd35585c2d7c306dd6e6def01c2d958dc9d2b 100644 (file)
@@ -18,6 +18,7 @@ DEFINE_STR(UM_KERN_WARNING, KERN_WARNING);
 DEFINE_STR(UM_KERN_NOTICE, KERN_NOTICE);
 DEFINE_STR(UM_KERN_INFO, KERN_INFO);
 DEFINE_STR(UM_KERN_DEBUG, KERN_DEBUG);
+DEFINE_STR(UM_KERN_CONT, KERN_CONT);
 
 DEFINE(UM_ELF_CLASS, ELF_CLASS);
 DEFINE(UM_ELFCLASS32, ELFCLASS32);
index cebc6cae91903442235e8f4b4e782b71a5feb5c9..b00a95741d4115339db192cddf54a7ba1b977ab7 100644 (file)
 typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
+#ifndef __KERNEL__
+#ifndef __section
+# define __section(S) __attribute__ ((__section__(#S)))
+#endif
+
+#if __GNUC_MINOR__ >= 3
+# define __used                        __attribute__((__used__))
+#else
+# define __used                        __attribute__((__unused__))
+#endif
+
+#else
+#include <linux/compiler.h>
+#endif
 /* These are for everybody (although not all archs will actually
    discard it in modules) */
 #define __init         __section(.init.text)
@@ -127,14 +141,3 @@ extern struct uml_param __uml_setup_start, __uml_setup_end;
 #endif
 
 #endif /* _LINUX_UML_INIT_H */
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index 884a9c17eea08b55c87086958b5991a1b8b2f2e6..e60b31873de135ebd949723ca2cdc283deab31d3 100644 (file)
@@ -14,7 +14,6 @@ struct irq_fd {
        int fd;
        int type;
        int irq;
-       int pid;
        int events;
        int current_events;
 };
index 74ce8e5370a6f50666d565a8fb99f3bb11ba2675..3c341222d2525e740a5beda96fa09c8819d97323 100644 (file)
 #include "sysdep/ptrace.h"
 #include "sysdep/faultinfo.h"
 
-typedef void (*kern_hndl)(int, struct uml_pt_regs *);
-
-struct kern_handlers {
-       kern_hndl relay_signal;
-       kern_hndl winch;
-       kern_hndl bus_handler;
-       kern_hndl page_fault;
-       kern_hndl sigio_handler;
-       kern_hndl timer_handler;
-};
-
-extern const struct kern_handlers handlinfo_kern;
+extern int uml_exitcode;
 
 extern int ncpus;
-extern char *gdb_init;
 extern int kmalloc_ok;
-extern int jail;
-extern int nsyscalls;
 
-#define UML_ROUND_DOWN(addr) ((void *)(((unsigned long) addr) & PAGE_MASK))
 #define UML_ROUND_UP(addr) \
-       UML_ROUND_DOWN(((unsigned long) addr) + PAGE_SIZE - 1)
+       ((((unsigned long) addr) + PAGE_SIZE - 1) & PAGE_MASK)
 
-extern int kernel_fork(unsigned long flags, int (*fn)(void *), void * arg);
-extern int kernel_thread_proc(void *data);
-extern void syscall_segv(int sig);
-extern int current_pid(void);
 extern unsigned long alloc_stack(int order, int atomic);
+extern void free_stack(unsigned long stack, int order);
+
 extern int do_signal(void);
-extern int is_stack_fault(unsigned long sp);
+extern void copy_sc(struct uml_pt_regs *regs, void *from);
+extern void interrupt_end(void);
+extern void relay_signal(int sig, struct uml_pt_regs *regs);
+
 extern unsigned long segv(struct faultinfo fi, unsigned long ip,
                          int is_user, struct uml_pt_regs *regs);
 extern int handle_page_fault(unsigned long address, unsigned long ip,
                             int is_write, int is_user, int *code_out);
-extern void syscall_ready(void);
-extern void set_tracing(void *t, int tracing);
-extern int is_tracing(void *task);
-extern int segv_syscall(void);
-extern void kern_finish_exec(void *task, int new_pid, unsigned long stack);
-extern unsigned long page_mask(void);
-extern int need_finish_fork(void);
-extern void free_stack(unsigned long stack, int order);
-extern void add_input_request(int op, void (*proc)(int), void *arg);
-extern char *current_cmd(void);
-extern void timer_handler(int sig, struct uml_pt_regs *regs);
-extern int set_signals(int enable);
-extern int pid_to_processor_id(int pid);
-extern void deliver_signals(void *t);
-extern int next_trap_index(int max);
-extern void default_idle(void);
-extern void finish_fork(void);
-extern void paging_init(void);
-extern void init_flush_vm(void);
-extern void *syscall_sp(void *t);
-extern void syscall_trace(struct uml_pt_regs *regs, int entryexit);
+
 extern unsigned int do_IRQ(int irq, struct uml_pt_regs *regs);
-extern void interrupt_end(void);
-extern void initial_thread_cb(void (*proc)(void *), void *arg);
-extern int debugger_signal(int status, int pid);
-extern void debugger_parent_signal(int status, int pid);
-extern void child_signal(int pid, int status);
-extern int init_ptrace_proxy(int idle_pid, int startup, int stop);
-extern int init_parent_proxy(int pid);
-extern int singlestepping(void *t);
-extern void check_stack_overflow(void *ptr);
-extern void relay_signal(int sig, struct uml_pt_regs *regs);
-extern int user_context(unsigned long sp);
-extern void timer_irq(struct uml_pt_regs *regs);
-extern void do_uml_exitcalls(void);
-extern int attach_debugger(int idle_pid, int pid, int stop);
-extern int config_gdb(char *str);
-extern int remove_gdb(void);
-extern char *uml_strdup(char *string);
-extern void unprotect_kernel_mem(void);
-extern void protect_kernel_mem(void);
-extern void uml_cleanup(void);
-extern void lock_signalled_task(void *t);
-extern void IPI_handler(int cpu);
-extern int jail_setup(char *line, int *add);
-extern void *get_init_task(void);
-extern int clear_user_proc(void *buf, int size);
-extern int copy_to_user_proc(void *to, void *from, int size);
-extern int copy_from_user_proc(void *to, void *from, int size);
-extern int strlen_user_proc(char *str);
-extern long execute_syscall(void *r);
 extern int smp_sigio_handler(void);
-extern void *get_current(void);
-extern struct task_struct *get_task(int pid, int require);
-extern void machine_halt(void);
+extern void initial_thread_cb(void (*proc)(void *), void *arg);
 extern int is_syscall(unsigned long addr);
+extern void timer_handler(int sig, struct uml_pt_regs *regs);
 
-extern void free_irq(unsigned int, void *);
-extern int cpu(void);
+extern void timer_handler(int sig, struct uml_pt_regs *regs);
 
-extern void time_init_kern(void);
+extern int start_uml(void);
+extern void paging_init(void);
 
-/* Are we disallowed to sleep? Used to choose between GFP_KERNEL and GFP_ATOMIC. */
+extern void uml_cleanup(void);
+extern void do_uml_exitcalls(void);
+
+/*
+ * Are we disallowed to sleep? Used to choose between GFP_KERNEL and
+ * GFP_ATOMIC.
+ */
 extern int __cant_sleep(void);
-extern void sigio_handler(int sig, struct uml_pt_regs *regs);
-extern void copy_sc(struct uml_pt_regs *regs, void *from);
+extern void *get_current(void);
+extern int copy_from_user_proc(void *to, void *from, int size);
+extern int cpu(void);
+extern char *uml_strdup(const char *string);
+
 extern unsigned long to_irq_stack(unsigned long *mask_out);
-unsigned long from_irq_stack(int nested);
-extern int start_uml(void);
+extern unsigned long from_irq_stack(int nested);
+
+extern void syscall_trace(struct uml_pt_regs *regs, int entryexit);
+extern int singlestepping(void *t);
+
+extern void segv_handler(int sig, struct uml_pt_regs *regs);
+extern void bus_handler(int sig, struct uml_pt_regs *regs);
+extern void winch(int sig, struct uml_pt_regs *regs);
+extern void fatal_sigsegv(void) __attribute__ ((noreturn));
+
+
 #endif
index a54514d2cc3ab81aa9e4244bb9f36f99f622a5b5..46384acd547b7590bd75e4f564cf203327e2e522 100644 (file)
@@ -46,9 +46,6 @@ extern int iomem_size;
 
 #define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 << 22) - 1))
 
-extern unsigned long host_task_size;
-extern unsigned long task_size;
-
 extern int init_mem_user(void);
 extern void setup_memory(void *entry);
 extern unsigned long find_iomem(char *driver, unsigned long *len_out);
@@ -59,9 +56,7 @@ extern void setup_physmem(unsigned long start, unsigned long usable,
                          unsigned long len, unsigned long long highmem);
 extern void add_iomem(char *name, int fd, unsigned long size);
 extern unsigned long phys_offset(unsigned long phys);
-extern void unmap_physmem(void);
 extern void map_memory(unsigned long virt, unsigned long phys,
                       unsigned long len, int r, int w, int x);
-extern unsigned long get_kmem_end(void);
 
 #endif
diff --git a/arch/um/include/misc_constants.h b/arch/um/include/misc_constants.h
deleted file mode 100644 (file)
index 989bc08..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __MISC_CONSTANT_H_
-#define __MISC_CONSTANT_H_
-
-#include <user_constants.h>
-
-#endif
index 6f0d1c741bcad5660be289861c4b71e48c088af2..0b6b6273330392122c82dc1e9b845f5d03bff3b2 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <stdarg.h>
 #include "irq_user.h"
-#include "kern_util.h"
 #include "longjmp.h"
 #include "mm_id.h"
 #include "sysdep/tls.h"
@@ -128,33 +127,31 @@ static inline struct openflags of_cloexec(struct openflags flags)
 extern int os_stat_file(const char *file_name, struct uml_stat *buf);
 extern int os_stat_fd(const int fd, struct uml_stat *buf);
 extern int os_access(const char *file, int mode);
-extern int os_get_exec_close(int fd, int *close_on_exec);
 extern int os_set_exec_close(int fd);
 extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
 extern int os_get_ifname(int fd, char *namebuf);
 extern int os_set_slip(int fd);
-extern int os_set_owner(int fd, int pid);
 extern int os_mode_fd(int fd, int mode);
 
 extern int os_seek_file(int fd, unsigned long long offset);
-extern int os_open_file(char *file, struct openflags flags, int mode);
+extern int os_open_file(const char *file, struct openflags flags, int mode);
 extern int os_read_file(int fd, void *buf, int len);
 extern int os_write_file(int fd, const void *buf, int count);
-extern int os_file_size(char *file, unsigned long long *size_out);
-extern int os_file_modtime(char *file, unsigned long *modtime);
+extern int os_file_size(const char *file, unsigned long long *size_out);
+extern int os_file_modtime(const char *file, unsigned long *modtime);
 extern int os_pipe(int *fd, int stream, int close_on_exec);
-extern int os_set_fd_async(int fd, int owner);
+extern int os_set_fd_async(int fd);
 extern int os_clear_fd_async(int fd);
 extern int os_set_fd_block(int fd, int blocking);
 extern int os_accept_connection(int fd);
-extern int os_create_unix_socket(char *file, int len, int close_on_exec);
+extern int os_create_unix_socket(const char *file, int len, int close_on_exec);
 extern int os_shutdown_socket(int fd, int r, int w);
 extern void os_close_file(int fd);
 extern int os_rcv_fd(int fd, int *helper_pid_out);
 extern int create_unix_socket(char *file, int len, int close_on_exec);
-extern int os_connect_socket(char *name);
+extern int os_connect_socket(const char *name);
 extern int os_file_type(char *file);
-extern int os_file_mode(char *file, struct openflags *mode_out);
+extern int os_file_mode(const char *file, struct openflags *mode_out);
 extern int os_lock_file(int fd, int excl);
 extern void os_flush_stdout(void);
 extern int os_stat_filesystem(char *path, long *bsize_out,
@@ -168,14 +165,10 @@ extern int os_fchange_dir(int fd);
 
 /* start_up.c */
 extern void os_early_checks(void);
-extern int can_do_skas(void);
+extern void can_do_skas(void);
 extern void os_check_bugs(void);
 extern void check_host_supports_tls(int *supports_tls, int *tls_min);
 
-/* Make sure they are clear when running in TT mode. Required by
- * SEGV_MAYBE_FIXABLE */
-#define clear_can_do_skas() do { ptrace_faultinfo = proc_mm = 0; } while (0)
-
 /* mem.c */
 extern int create_mem_file(unsigned long long len);
 
@@ -214,7 +207,7 @@ extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
 extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv);
 extern int run_helper_thread(int (*proc)(void *), void *arg,
                             unsigned int flags, unsigned long *stack_out);
-extern int helper_wait(int pid, int nohang, char *pname);
+extern int helper_wait(int pid);
 
 
 /* tls.c */
@@ -237,16 +230,12 @@ extern void unblock_signals(void);
 extern int get_signals(void);
 extern int set_signals(int enable);
 
-/* trap.c */
-extern void os_fill_handlinfo(struct kern_handlers h);
-
 /* util.c */
 extern void stack_protections(unsigned long address);
 extern int raw(int fd);
 extern void setup_machinename(char *machine_out);
 extern void setup_hostinfo(char *buf, int len);
-extern int setjmp_wrapper(void (*proc)(void *, void *), ...);
-extern void os_dump_core(void);
+extern void os_dump_core(void) __attribute__ ((noreturn));
 
 /* time.c */
 extern void idle_sleep(unsigned long long nsecs);
@@ -275,11 +264,9 @@ extern int protect(struct mm_id * mm_idp, unsigned long addr,
 extern int is_skas_winch(int pid, int fd, void *data);
 extern int start_userspace(unsigned long stub_stack);
 extern int copy_context_skas0(unsigned long stack, int pid);
-extern void save_registers(int pid, struct uml_pt_regs *regs);
-extern void restore_registers(int pid, struct uml_pt_regs *regs);
 extern void userspace(struct uml_pt_regs *regs);
-extern void map_stub_pages(int fd, unsigned long code,
-                          unsigned long data, unsigned long stack);
+extern int map_stub_pages(int fd, unsigned long code, unsigned long data,
+                         unsigned long stack);
 extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));
 extern void switch_threads(jmp_buf *me, jmp_buf *you);
 extern int start_idle_thread(void *stack, jmp_buf *switch_buf);
@@ -298,16 +285,12 @@ extern void os_free_irq_later(struct irq_fd *active_fds,
 extern int os_get_pollfd(int i);
 extern void os_set_pollfd(int i, int fd);
 extern void os_set_ioignore(void);
-extern void init_irq_signals(int on_sigstack);
 
 /* sigio.c */
 extern int add_sigio_fd(int fd);
 extern int ignore_sigio_fd(int fd);
 extern void maybe_sigio_broken(int fd, int read);
 
-/* skas/trap */
-extern void sig_handler_common_skas(int sig, void *sc_ptr);
-
 /* sys-x86_64/prctl.c */
 extern int os_arch_prctl(int pid, int code, unsigned long *addr);
 
index f3450e6bc18d3d9bf63269ebebee186d73b28828..4bce6e0128895ddad042c7959526a0e9f67eaf92 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
 
 extern int ptrace_getregs(long pid, unsigned long *regs_out);
 extern int ptrace_setregs(long pid, unsigned long *regs_in);
-extern int ptrace_getfpregs(long pid, unsigned long *regs_out);
-extern int ptrace_setfpregs(long pid, unsigned long *regs);
-extern void arch_enter_kernel(void *task, int pid);
-extern void arch_leave_kernel(void *task, int pid);
-extern void ptrace_pokeuser(unsigned long addr, unsigned long data);
-
 
 /* syscall emulation path in ptrace */
 
@@ -54,7 +48,8 @@ extern int sysemu_supported;
        (((int[3][3] ) { \
                { PTRACE_SYSCALL, PTRACE_SYSCALL, PTRACE_SINGLESTEP }, \
                { PTRACE_SYSEMU, PTRACE_SYSEMU, PTRACE_SINGLESTEP }, \
-               { PTRACE_SYSEMU, PTRACE_SYSEMU_SINGLESTEP, PTRACE_SYSEMU_SINGLESTEP }}) \
+               { PTRACE_SYSEMU, PTRACE_SYSEMU_SINGLESTEP, \
+                 PTRACE_SYSEMU_SINGLESTEP } }) \
                [sysemu_mode][singlestep_mode])
 
 #endif
index 0e27406a43a4d24f311af678b10a71dbd51a6ffa..9ea1ae3c8f464d8c8b138eecf8d3694f238d32c5 100644 (file)
@@ -9,14 +9,13 @@
 #include "sysdep/ptrace.h"
 #include "sysdep/archsetjmp.h"
 
-extern void init_thread_registers(struct uml_pt_regs *to);
 extern int save_fp_registers(int pid, unsigned long *fp_regs);
 extern int restore_fp_registers(int pid, unsigned long *fp_regs);
 extern int save_fpx_registers(int pid, unsigned long *fp_regs);
 extern int restore_fpx_registers(int pid, unsigned long *fp_regs);
-extern void save_registers(int pid, struct uml_pt_regs *regs);
-extern void restore_registers(int pid, struct uml_pt_regs *regs);
-extern void init_registers(int pid);
+extern int save_registers(int pid, struct uml_pt_regs *regs);
+extern int restore_registers(int pid, struct uml_pt_regs *regs);
+extern int init_registers(int pid);
 extern void get_safe_registers(unsigned long *regs);
 extern unsigned long get_thread_reg(int reg, jmp_buf *buf);
 
diff --git a/arch/um/include/signal_kern.h b/arch/um/include/signal_kern.h
deleted file mode 100644 (file)
index aeb5d5a..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/* 
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
- * Licensed under the GPL
- */
-
-#ifndef __SIGNAL_KERN_H__
-#define __SIGNAL_KERN_H__
-
-extern int have_signals(void *t);
-
-#endif
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
diff --git a/arch/um/include/skas/mode-skas.h b/arch/um/include/skas/mode-skas.h
deleted file mode 100644 (file)
index e065feb..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
- * Licensed under the GPL
- */
-
-#ifndef __MODE_SKAS_H__
-#define __MODE_SKAS_H__
-
-extern void kill_off_processes_skas(void);
-
-#endif
index 57bd79efbee305887c0ac59cfa2504e3d6a1a2ba..905698197e35fc2f4fd612b0495bd846d3253a65 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2000 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -18,7 +18,8 @@ extern syscall_handler_t old_mmap_i386;
 extern syscall_handler_t *sys_call_table[];
 
 #define EXECUTE_SYSCALL(syscall, regs) \
-       ((long (*)(struct syscall_args)) (*sys_call_table[syscall]))(SYSCALL_ARGS(&regs->regs))
+       ((long (*)(struct syscall_args)) \
+        (*sys_call_table[syscall]))(SYSCALL_ARGS(&regs->regs))
 
 extern long sys_mmap2(unsigned long addr, unsigned long len,
                      unsigned long prot, unsigned long flags,
index c978b589df419abc42c818dba54012dcbc8fb3f6..a307237b7964394189e220673c160bddf08a6227 100644 (file)
 #define OFFSET(sym, str, mem) \
        DEFINE(sym, offsetof(struct str, mem));
 
-#define __NO_STUBS 1
-#undef __SYSCALL
-#undef _ASM_X86_64_UNISTD_H_
-#define __SYSCALL(nr, sym) [nr] = 1,
-static char syscalls[] = {
-#include <asm/arch/unistd.h>
-};
-
 void foo(void)
 {
 #include <common-offsets.h>
-DEFINE(UM_NR_syscall_max, sizeof(syscalls) - 1);
 }
index cf72256609e4ea29d42b331123b1db672c9c4899..7cfb0b085655b0554565a6178287d48951e76422 100644 (file)
@@ -30,6 +30,4 @@ extern long old_mmap(unsigned long addr, unsigned long len,
 extern syscall_handler_t sys_modify_ldt;
 extern syscall_handler_t sys_arch_prctl;
 
-#define NR_syscalls (UM_NR_syscall_max + 1)
-
 #endif
index 8855d8df512f6877a1e6d1534edbc29bd9275bbd..82865fcf6872eb0e7347d17ecd64cfc408240a02 100644 (file)
 
 typedef struct mm_context {
        struct mm_id id;
-       unsigned long last_page_table;
-#ifdef CONFIG_3_LEVEL_PGTABLES
-       unsigned long last_pmd;
-#endif
        struct uml_ldt ldt;
 } mm_context_t;
 
index fdfc06b85605a5bf709a3b7e3b369b49c766626c..2b6fc8e0f07137bdec6f6b5fcd166f9e79d4e0d6 100644 (file)
@@ -6,7 +6,9 @@
 #ifndef __ARCH_UM_UACCESS_H
 #define __ARCH_UM_UACCESS_H
 
-#include "asm/fixmap.h"
+#include <asm/elf.h>
+#include <asm/fixmap.h>
+#include "sysdep/archsetjmp.h"
 
 #define __under_task_size(addr, size) \
        (((unsigned long) (addr) < TASK_SIZE) && \
index 8196450451cd6332d6b76eb97bbb3b9ffc93a17f..76a62c0cb2bc89692e72df74a096df83f33487e5 100644 (file)
 void flush_thread(void)
 {
        void *data = NULL;
-       unsigned long end = proc_mm ? task_size : STUB_START;
        int ret;
 
        arch_flush_thread(&current->thread.arch);
 
-       ret = unmap(&current->mm->context.id, 0, end, 1, &data);
+       ret = unmap(&current->mm->context.id, 0, STUB_START, 0, &data);
+       ret = ret || unmap(&current->mm->context.id, STUB_END,
+                          TASK_SIZE - STUB_END, 1, &data);
        if (ret) {
                printk(KERN_ERR "flush_thread - clearing address space failed, "
                       "err = %d\n", ret);
index c716b5a6db13d9552a59e7f7ec5688229ca9bf0e..984f80e668ca5d7c85b3f8ae549dc13fa5aabe57 100644 (file)
@@ -1,15 +1,17 @@
 /*
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include "linux/kernel.h"
-#include "linux/init.h"
-#include "linux/ctype.h"
-#include "linux/proc_fs.h"
-#include "asm/uaccess.h"
+#include <linux/ctype.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/proc_fs.h>
+#include <linux/types.h>
+#include <asm/uaccess.h>
 
-/* If read and write race, the read will still atomically read a valid
+/*
+ * If read and write race, the read will still atomically read a valid
  * value.
  */
 int uml_exitcode = 0;
@@ -19,18 +21,19 @@ static int read_proc_exitcode(char *page, char **start, off_t off,
 {
        int len, val;
 
-       /* Save uml_exitcode in a local so that we don't need to guarantee
+       /*
+        * Save uml_exitcode in a local so that we don't need to guarantee
         * that sprintf accesses it atomically.
         */
        val = uml_exitcode;
        len = sprintf(page, "%d\n", val);
        len -= off;
-       if(len <= off+count)
+       if (len <= off+count)
                *eof = 1;
        *start = page + off;
-       if(len > count)
+       if (len > count)
                len = count;
-       if(len < 0)
+       if (len < 0)
                len = 0;
        return len;
 }
@@ -41,11 +44,11 @@ static int write_proc_exitcode(struct file *file, const char __user *buffer,
        char *end, buf[sizeof("nnnnn\0")];
        int tmp;
 
-       if(copy_from_user(buf, buffer, count))
+       if (copy_from_user(buf, buffer, count))
                return -EFAULT;
 
        tmp = simple_strtol(buf, &end, 0);
-       if((*end != '\0') && !isspace(*end))
+       if ((*end != '\0') && !isspace(*end))
                return -EINVAL;
 
        uml_exitcode = tmp;
@@ -57,7 +60,7 @@ static int make_proc_exitcode(void)
        struct proc_dir_entry *ent;
 
        ent = create_proc_entry("exitcode", 0600, &proc_root);
-       if(ent == NULL){
+       if (ent == NULL) {
                printk(KERN_WARNING "make_proc_exitcode : Failed to register "
                       "/proc/exitcode\n");
                return 0;
index 734f873cab12437885af0d61d7dfe3a902f1ae9b..72eccd2a41132daae3d3dd746901f8535913e290 100644 (file)
@@ -1,5 +1,5 @@
-/* 
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -8,12 +8,13 @@
 extern void __bb_init_func(void *)  __attribute__((weak));
 EXPORT_SYMBOL(__bb_init_func);
 
-/* This is defined (and referred to in profiling stub code) only by some GCC
+/*
+ * This is defined (and referred to in profiling stub code) only by some GCC
  * versions in libgcov.
  *
  * Since SuSE backported the fix, we cannot handle it depending on GCC version.
- * So, unconditionally export it. But also give it a weak declaration, which will
- * be overridden by any other one.
+ * So, unconditionally export it. But also give it a weak declaration, which
+ * will be overridden by any other one.
  */
 
 extern void __gcov_init(void *) __attribute__((weak));
index 9244f018d44cf981c478e32d65fbe18fd0492c4d..e2f043d0de6c80fd0050aedb0edf1748efbdb72b 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -7,14 +7,3 @@
 
 extern void mcount(void);
 EXPORT_SYMBOL(mcount);
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index 16dc43e9d940e305bfe2f42a9a5c35be05eb0a9c..fa015565001b6b46171149e073bfe2e828872566 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -7,7 +7,6 @@
 #include "linux/bootmem.h"
 #include "linux/initrd.h"
 #include "asm/types.h"
-#include "kern_util.h"
 #include "initrd.h"
 #include "init.h"
 #include "os.h"
@@ -21,18 +20,27 @@ static int __init read_initrd(void)
        long long size;
        int err;
 
-       if(initrd == NULL)
+       if (initrd == NULL)
                return 0;
 
        err = os_file_size(initrd, &size);
-       if(err)
+       if (err)
                return 0;
 
+       /*
+        * This is necessary because alloc_bootmem craps out if you
+        * ask for no memory.
+        */
+       if (size == 0) {
+               printk(KERN_ERR "\"%\" is a zero-size initrd\n");
+               return 0;
+       }
+
        area = alloc_bootmem(size);
-       if(area == NULL)
+       if (area == NULL)
                return 0;
 
-       if(load_initrd(initrd, area, size) == -1)
+       if (load_initrd(initrd, area, size) == -1)
                return 0;
 
        initrd_start = (unsigned long) area;
@@ -59,13 +67,15 @@ int load_initrd(char *filename, void *buf, int size)
        int fd, n;
 
        fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
-       if(fd < 0){
-               printk("Opening '%s' failed - err = %d\n", filename, -fd);
+       if (fd < 0) {
+               printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename,
+                      -fd);
                return -1;
        }
        n = os_read_file(fd, buf, size);
-       if(n != size){
-               printk("Read of %d bytes from '%s' failed, err = %d\n", size,
+       if (n != size) {
+               printk(KERN_ERR "Read of %d bytes from '%s' failed, "
+                      "err = %d\n", size,
                       filename, -n);
                return -1;
        }
index ba11ccd6a8a3f72e4ab641a5f79f21a740a1ad0a..91587f8db34019a1045c81159f120eb1bd69c1ce 100644 (file)
@@ -107,10 +107,9 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
        struct pollfd *tmp_pfd;
        struct irq_fd *new_fd, *irq_fd;
        unsigned long flags;
-       int pid, events, err, n;
+       int events, err, n;
 
-       pid = os_getpid();
-       err = os_set_fd_async(fd, pid);
+       err = os_set_fd_async(fd);
        if (err < 0)
                goto out;
 
@@ -127,7 +126,6 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
                                     .fd                = fd,
                                     .type              = type,
                                     .irq               = irq,
-                                    .pid               = pid,
                                     .events            = events,
                                     .current_events    = 0 } );
 
index 7c7142ba3bd7d4c4980b07df559d3524d0fd78be..5311ee93ede3851c3ad311d134f911ec9c483188 100644 (file)
@@ -18,15 +18,11 @@ EXPORT_SYMBOL(set_signals);
 EXPORT_SYMBOL(get_signals);
 EXPORT_SYMBOL(kernel_thread);
 EXPORT_SYMBOL(sys_waitpid);
-EXPORT_SYMBOL(task_size);
 EXPORT_SYMBOL(flush_tlb_range);
-EXPORT_SYMBOL(host_task_size);
 EXPORT_SYMBOL(arch_validate);
-EXPORT_SYMBOL(get_kmem_end);
 
 EXPORT_SYMBOL(high_physmem);
 EXPORT_SYMBOL(empty_zero_page);
-EXPORT_SYMBOL(um_virt_to_phys);
 EXPORT_SYMBOL(handle_page_fault);
 EXPORT_SYMBOL(find_iomem);
 
@@ -40,7 +36,6 @@ EXPORT_SYMBOL(uml_strdup);
 EXPORT_SYMBOL(os_stat_fd);
 EXPORT_SYMBOL(os_stat_file);
 EXPORT_SYMBOL(os_access);
-EXPORT_SYMBOL(os_get_exec_close);
 EXPORT_SYMBOL(os_set_exec_close);
 EXPORT_SYMBOL(os_getpid);
 EXPORT_SYMBOL(os_open_file);
index 59822dee438adfe53f373569f9b74d675726b56d..d872fdce1d7ec76e9d4b37782b2a9ac9dd108395 100644 (file)
@@ -1,49 +1,41 @@
 /*
- * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include "linux/stddef.h"
-#include "linux/kernel.h"
-#include "linux/mm.h"
-#include "linux/bootmem.h"
-#include "linux/swap.h"
-#include "linux/highmem.h"
-#include "linux/gfp.h"
-#include "asm/page.h"
-#include "asm/fixmap.h"
-#include "asm/pgalloc.h"
-#include "kern_util.h"
+#include <linux/stddef.h>
+#include <linux/bootmem.h>
+#include <linux/gfp.h>
+#include <linux/highmem.h>
+#include <linux/mm.h>
+#include <linux/swap.h>
+#include <asm/fixmap.h>
+#include <asm/page.h>
 #include "as-layout.h"
+#include "init.h"
 #include "kern.h"
+#include "kern_util.h"
 #include "mem_user.h"
-#include "um_uaccess.h"
 #include "os.h"
-#include "linux/types.h"
-#include "linux/string.h"
-#include "init.h"
-#include "kern_constants.h"
 
 /* allocated in paging_init, zeroed in mem_init, and unchanged thereafter */
 unsigned long *empty_zero_page = NULL;
 /* allocated in paging_init and unchanged thereafter */
 unsigned long *empty_bad_page = NULL;
+
+/*
+ * Initialized during boot, and readonly for initializing page tables
+ * afterwards
+ */
 pgd_t swapper_pg_dir[PTRS_PER_PGD];
+
+/* Initialized at boot time, and readonly after that */
 unsigned long long highmem;
 int kmalloc_ok = 0;
 
+/* Used during early boot */
 static unsigned long brk_end;
 
-void unmap_physmem(void)
-{
-       os_unmap_memory((void *) brk_end, uml_reserved - brk_end);
-}
-
-static void map_cb(void *unused)
-{
-       map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0);
-}
-
 #ifdef CONFIG_HIGHMEM
 static void setup_highmem(unsigned long highmem_start,
                          unsigned long highmem_len)
@@ -53,7 +45,7 @@ static void setup_highmem(unsigned long highmem_start,
        int i;
 
        highmem_pfn = __pa(highmem_start) >> PAGE_SHIFT;
-       for(i = 0; i < highmem_len >> PAGE_SHIFT; i++){
+       for (i = 0; i < highmem_len >> PAGE_SHIFT; i++) {
                page = &mem_map[highmem_pfn + i];
                ClearPageReserved(page);
                init_page_count(page);
@@ -65,14 +57,13 @@ static void setup_highmem(unsigned long highmem_start,
 void __init mem_init(void)
 {
        /* clear the zero-page */
-       memset((void *) empty_zero_page, 0, PAGE_SIZE);
+       memset(empty_zero_page, 0, PAGE_SIZE);
 
        /* Map in the area just after the brk now that kmalloc is about
         * to be turned on.
         */
        brk_end = (unsigned long) UML_ROUND_UP(sbrk(0));
-       map_cb(NULL);
-       initial_thread_cb(map_cb, NULL);
+       map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0);
        free_bootmem(__pa(brk_end), uml_reserved - brk_end);
        uml_reserved = brk_end;
 
@@ -85,7 +76,7 @@ void __init mem_init(void)
 #endif
        num_physpages = totalram_pages;
        max_pfn = totalram_pages;
-       printk(KERN_INFO "Memory: %luk available\n", 
+       printk(KERN_INFO "Memory: %luk available\n",
               (unsigned long) nr_free_pages() << (PAGE_SHIFT-10));
        kmalloc_ok = 1;
 
@@ -119,7 +110,7 @@ static void __init one_md_table_init(pud_t *pud)
 #endif
 }
 
-static void __init fixrange_init(unsigned long start, unsigned long end, 
+static void __init fixrange_init(unsigned long start, unsigned long end,
                                 pgd_t *pgd_base)
 {
        pgd_t *pgd;
@@ -138,7 +129,7 @@ static void __init fixrange_init(unsigned long start, unsigned long end,
                if (pud_none(*pud))
                        one_md_table_init(pud);
                pmd = pmd_offset(pud, vaddr);
-               for (; (j < PTRS_PER_PMD) && (vaddr != end); pmd++, j++) {
+               for (; (j < PTRS_PER_PMD) && (vaddr < end); pmd++, j++) {
                        one_page_table_init(pmd);
                        vaddr += PMD_SIZE;
                }
@@ -152,7 +143,7 @@ pgprot_t kmap_prot;
 
 #define kmap_get_fixmap_pte(vaddr)                                     \
        pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), (vaddr)),\
-                         (vaddr)), (vaddr))
+                                    (vaddr)), (vaddr))
 
 static void __init kmap_init(void)
 {
@@ -197,21 +188,23 @@ static void __init fixaddr_user_init( void)
        pud_t *pud;
        pmd_t *pmd;
        pte_t *pte;
-       unsigned long paddr, vaddr = FIXADDR_USER_START;
+       phys_t p;
+       unsigned long v, vaddr = FIXADDR_USER_START;
 
-       if (  ! size )
+       if (!size)
                return;
 
        fixrange_init( FIXADDR_USER_START, FIXADDR_USER_END, swapper_pg_dir);
-       paddr = (unsigned long)alloc_bootmem_low_pages( size);
-       memcpy( (void *)paddr, (void *)FIXADDR_USER_START, size);
-       paddr = __pa(paddr);
-       for ( ; size > 0; size-=PAGE_SIZE, vaddr+=PAGE_SIZE, paddr+=PAGE_SIZE){
+       v = (unsigned long) alloc_bootmem_low_pages(size);
+       memcpy((void *) v , (void *) FIXADDR_USER_START, size);
+       p = __pa(v);
+       for ( ; size > 0; size -= PAGE_SIZE, vaddr += PAGE_SIZE,
+                     p += PAGE_SIZE) {
                pgd = swapper_pg_dir + pgd_index(vaddr);
                pud = pud_offset(pgd, vaddr);
                pmd = pmd_offset(pud, vaddr);
                pte = pte_offset_kernel(pmd, vaddr);
-               pte_set_val( (*pte), paddr, PAGE_READONLY);
+               pte_set_val(*pte, p, PAGE_READONLY);
        }
 #endif
 }
@@ -223,7 +216,7 @@ void __init paging_init(void)
 
        empty_zero_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE);
        empty_bad_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE);
-       for(i = 0; i < ARRAY_SIZE(zones_size); i++)
+       for (i = 0; i < ARRAY_SIZE(zones_size); i++)
                zones_size[i] = 0;
 
        zones_size[ZONE_NORMAL] = (end_iomem >> PAGE_SHIFT) -
@@ -253,32 +246,33 @@ struct page *arch_validate(struct page *page, gfp_t mask, int order)
        int i;
 
  again:
-       if(page == NULL)
+       if (page == NULL)
                return page;
-       if(PageHighMem(page))
+       if (PageHighMem(page))
                return page;
 
        addr = (unsigned long) page_address(page);
-       for(i = 0; i < (1 << order); i++){
+       for (i = 0; i < (1 << order); i++) {
                current->thread.fault_addr = (void *) addr;
-               if(__do_copy_to_user((void __user *) addr, &zero,
+               if (__do_copy_to_user((void __user *) addr, &zero,
                                     sizeof(zero),
                                     &current->thread.fault_addr,
-                                    &current->thread.fault_catcher)){
-                       if(!(mask & __GFP_WAIT))
+                                    &current->thread.fault_catcher)) {
+                       if (!(mask & __GFP_WAIT))
                                return NULL;
                        else break;
                }
                addr += PAGE_SIZE;
        }
 
-       if(i == (1 << order))
+       if (i == (1 << order))
                return page;
        page = alloc_pages(mask, order);
        goto again;
 }
 
-/* This can't do anything because nothing in the kernel image can be freed
+/*
+ * This can't do anything because nothing in the kernel image can be freed
  * since it's not in kernel physical memory.
  */
 
@@ -290,8 +284,8 @@ void free_initmem(void)
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
        if (start < end)
-               printk ("Freeing initrd memory: %ldk freed\n", 
-                       (end - start) >> 10);
+               printk(KERN_INFO "Freeing initrd memory: %ldk freed\n",
+                      (end - start) >> 10);
        for (; start < end; start += PAGE_SIZE) {
                ClearPageReserved(virt_to_page(start));
                init_page_count(virt_to_page(start));
@@ -308,32 +302,31 @@ void show_mem(void)
        int highmem = 0;
        struct page *page;
 
-       printk("Mem-info:\n");
+       printk(KERN_INFO "Mem-info:\n");
        show_free_areas();
-       printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
+       printk(KERN_INFO "Free swap:       %6ldkB\n",
+              nr_swap_pages<<(PAGE_SHIFT-10));
        pfn = max_mapnr;
-       while(pfn-- > 0) {
+       while (pfn-- > 0) {
                page = pfn_to_page(pfn);
                total++;
-               if(PageHighMem(page))
+               if (PageHighMem(page))
                        highmem++;
-               if(PageReserved(page))
+               if (PageReserved(page))
                        reserved++;
-               else if(PageSwapCache(page))
+               else if (PageSwapCache(page))
                        cached++;
-               else if(page_count(page))
+               else if (page_count(page))
                        shared += page_count(page) - 1;
        }
-       printk("%d pages of RAM\n", total);
-       printk("%d pages of HIGHMEM\n", highmem);
-       printk("%d reserved pages\n", reserved);
-       printk("%d pages shared\n", shared);
-       printk("%d pages swap cached\n", cached);
+       printk(KERN_INFO "%d pages of RAM\n", total);
+       printk(KERN_INFO "%d pages of HIGHMEM\n", highmem);
+       printk(KERN_INFO "%d reserved pages\n", reserved);
+       printk(KERN_INFO "%d pages shared\n", shared);
+       printk(KERN_INFO "%d pages swap cached\n", cached);
 }
 
-/*
- * Allocate and free page tables.
- */
+/* Allocate and free page tables. */
 
 pgd_t *pgd_alloc(struct mm_struct *mm)
 {
@@ -341,14 +334,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
 
        if (pgd) {
                memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
-               memcpy(pgd + USER_PTRS_PER_PGD, 
-                      swapper_pg_dir + USER_PTRS_PER_PGD, 
+               memcpy(pgd + USER_PTRS_PER_PGD,
+                      swapper_pg_dir + USER_PTRS_PER_PGD,
                       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
        }
        return pgd;
 }
 
-void pgd_free(pgd_t *pgd)
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_page((unsigned long) pgd);
 }
@@ -368,3 +361,15 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
        pte = alloc_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
        return pte;
 }
+
+#ifdef CONFIG_3_LEVEL_PGTABLES
+pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
+{
+       pmd_t *pmd = (pmd_t *) __get_free_page(GFP_KERNEL);
+
+       if (pmd)
+               memset(pmd, 0, PAGE_SIZE);
+
+       return pmd;
+}
+#endif
index e66432f42485dad02584bb13a6bc28a626aa0814..9757085a022097fe1804373bfd8e498bd38b4991 100644 (file)
@@ -55,16 +55,6 @@ int __init init_maps(unsigned long physmem, unsigned long iomem,
        return 0;
 }
 
-/* Changed during early boot */
-static unsigned long kmem_top = 0;
-
-unsigned long get_kmem_end(void)
-{
-       if (kmem_top == 0)
-               kmem_top = host_task_size - 1024 * 1024;
-       return kmem_top;
-}
-
 void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
                int r, int w, int x)
 {
@@ -174,10 +164,10 @@ __uml_setup("iomem=", parse_iomem,
  * setup_iomem, both of which run during early boot.  Afterwards, it's
  * unchanged.
  */
-struct iomem_region *iomem_regions = NULL;
+struct iomem_region *iomem_regions;
 
-/* Initialized in parse_iomem */
-int iomem_size = 0;
+/* Initialized in parse_iomem and unchanged thereafter */
+int iomem_size;
 
 unsigned long find_iomem(char *driver, unsigned long *len_out)
 {
index 0eae00b3e58895054d69afd0876bedae0bd12631..c07961bedb75ea7a379176275022c3cca26bae53 100644 (file)
@@ -4,19 +4,21 @@
  * Licensed under the GPL
  */
 
-#include "linux/stddef.h"
-#include "linux/err.h"
-#include "linux/hardirq.h"
-#include "linux/mm.h"
-#include "linux/personality.h"
-#include "linux/proc_fs.h"
-#include "linux/ptrace.h"
-#include "linux/random.h"
-#include "linux/sched.h"
-#include "linux/tick.h"
-#include "linux/threads.h"
-#include "asm/pgtable.h"
-#include "asm/uaccess.h"
+#include <linux/stddef.h>
+#include <linux/err.h>
+#include <linux/hardirq.h>
+#include <linux/gfp.h>
+#include <linux/mm.h>
+#include <linux/personality.h>
+#include <linux/proc_fs.h>
+#include <linux/ptrace.h>
+#include <linux/random.h>
+#include <linux/sched.h>
+#include <linux/tick.h>
+#include <linux/threads.h>
+#include <asm/current.h>
+#include <asm/pgtable.h>
+#include <asm/uaccess.h>
 #include "as-layout.h"
 #include "kern_util.h"
 #include "os.h"
@@ -30,7 +32,7 @@
  */
 struct cpu_task cpu_tasks[NR_CPUS] = { [0 ... NR_CPUS - 1] = { -1, NULL } };
 
-static inline int external_pid(struct task_struct *task)
+static inline int external_pid(void)
 {
        /* FIXME: Need to look up userspace_pid by cpu */
        return userspace_pid[0];
@@ -40,7 +42,7 @@ int pid_to_processor_id(int pid)
 {
        int i;
 
-       for(i = 0; i < ncpus; i++) {
+       for (i = 0; i < ncpus; i++) {
                if (cpu_tasks[i].pid == pid)
                        return i;
        }
@@ -60,8 +62,6 @@ unsigned long alloc_stack(int order, int atomic)
        if (atomic)
                flags = GFP_ATOMIC;
        page = __get_free_pages(flags, order);
-       if (page == 0)
-               return 0;
 
        return page;
 }
@@ -80,15 +80,15 @@ int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
 static inline void set_current(struct task_struct *task)
 {
        cpu_tasks[task_thread_info(task)->cpu] = ((struct cpu_task)
-               { external_pid(task), task });
+               { external_pid(), task });
 }
 
-extern void arch_switch_to(struct task_struct *from, struct task_struct *to);
+extern void arch_switch_to(struct task_struct *to);
 
 void *_switch_to(void *prev, void *next, void *last)
 {
        struct task_struct *from = prev;
-       struct task_struct *to= next;
+       struct task_struct *to = next;
 
        to->thread.prev_sched = from;
        set_current(to);
@@ -99,13 +99,13 @@ void *_switch_to(void *prev, void *next, void *last)
                switch_threads(&from->thread.switch_buf,
                               &to->thread.switch_buf);
 
-               arch_switch_to(current->thread.prev_sched, current);
+               arch_switch_to(current);
 
                if (current->thread.saved_task)
                        show_regs(&(current->thread.regs));
-               next= current->thread.saved_task;
-               prev= current;
-       } while(current->thread.saved_task);
+               to = current->thread.saved_task;
+               from = current;
+       } while (current->thread.saved_task);
 
        return current->thread.prev_sched;
 
@@ -163,8 +163,6 @@ void new_thread_handler(void)
 void fork_handler(void)
 {
        force_flush_all();
-       if (current->thread.prev_sched == NULL)
-               panic("blech");
 
        schedule_tail(current->thread.prev_sched);
 
@@ -173,7 +171,7 @@ void fork_handler(void)
         * arch_switch_to isn't needed. We could want to apply this to
         * improve performance. -bb
         */
-       arch_switch_to(current->thread.prev_sched, current);
+       arch_switch_to(current);
 
        current->thread.prev_sched = NULL;
 
@@ -204,7 +202,7 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
                arch_copy_thread(&current->thread.arch, &p->thread.arch);
        }
        else {
-               init_thread_registers(&p->thread.regs.regs);
+               get_safe_registers(p->thread.regs.regs.gp);
                p->thread.request.u.thread = current->thread.request.u.thread;
                handler = new_thread_handler;
        }
@@ -237,7 +235,7 @@ void default_idle(void)
 {
        unsigned long long nsecs;
 
-       while(1) {
+       while (1) {
                /* endless idle loop with no priority at all */
 
                /*
@@ -256,53 +254,10 @@ void default_idle(void)
 
 void cpu_idle(void)
 {
-       cpu_tasks[current_thread->cpu].pid = os_getpid();
+       cpu_tasks[current_thread_info()->cpu].pid = os_getpid();
        default_idle();
 }
 
-void *um_virt_to_phys(struct task_struct *task, unsigned long addr,
-                     pte_t *pte_out)
-{
-       pgd_t *pgd;
-       pud_t *pud;
-       pmd_t *pmd;
-       pte_t *pte;
-       pte_t ptent;
-
-       if (task->mm == NULL)
-               return ERR_PTR(-EINVAL);
-       pgd = pgd_offset(task->mm, addr);
-       if (!pgd_present(*pgd))
-               return ERR_PTR(-EINVAL);
-
-       pud = pud_offset(pgd, addr);
-       if (!pud_present(*pud))
-               return ERR_PTR(-EINVAL);
-
-       pmd = pmd_offset(pud, addr);
-       if (!pmd_present(*pmd))
-               return ERR_PTR(-EINVAL);
-
-       pte = pte_offset_kernel(pmd, addr);
-       ptent = *pte;
-       if (!pte_present(ptent))
-               return ERR_PTR(-EINVAL);
-
-       if (pte_out != NULL)
-               *pte_out = ptent;
-       return (void *) (pte_val(ptent) & PAGE_MASK) + (addr & ~PAGE_MASK);
-}
-
-char *current_cmd(void)
-{
-#if defined(CONFIG_SMP) || defined(CONFIG_HIGHMEM)
-       return "(Unknown)";
-#else
-       void *addr = um_virt_to_phys(current, current->mm->arg_start, NULL);
-       return IS_ERR(addr) ? "(Unknown)": __va((unsigned long) addr);
-#endif
-}
-
 void dump_thread(struct pt_regs *regs, struct user *u)
 {
 }
@@ -317,7 +272,7 @@ int user_context(unsigned long sp)
        unsigned long stack;
 
        stack = sp & (PAGE_MASK << CONFIG_KERNEL_STACK_ORDER);
-       return stack != (unsigned long) current_thread;
+       return stack != (unsigned long) current_thread_info();
 }
 
 extern exitcall_t __uml_exitcall_begin, __uml_exitcall_end;
@@ -331,7 +286,7 @@ void do_uml_exitcalls(void)
                (*call)();
 }
 
-char *uml_strdup(char *string)
+char *uml_strdup(const char *string)
 {
        return kstrdup(string, GFP_KERNEL);
 }
@@ -359,7 +314,7 @@ int strlen_user_proc(char __user *str)
 int smp_sigio_handler(void)
 {
 #ifdef CONFIG_SMP
-       int cpu = current_thread->cpu;
+       int cpu = current_thread_info()->cpu;
        IPI_handler(cpu);
        if (cpu != 0)
                return 1;
@@ -369,7 +324,7 @@ int smp_sigio_handler(void)
 
 int cpu(void)
 {
-       return current_thread->cpu;
+       return current_thread_info()->cpu;
 }
 
 static atomic_t using_sysemu = ATOMIC_INIT(0);
@@ -435,7 +390,7 @@ int singlestepping(void * t)
 {
        struct task_struct *task = t ? t : current;
 
-       if ( ! (task->ptrace & PT_DTRACE) )
+       if (!(task->ptrace & PT_DTRACE))
                return 0;
 
        if (task->thread.singlestep_syscall)
@@ -459,3 +414,46 @@ unsigned long arch_align_stack(unsigned long sp)
        return sp & ~0xf;
 }
 #endif
+
+unsigned long get_wchan(struct task_struct *p)
+{
+       unsigned long stack_page, sp, ip;
+       bool seen_sched = 0;
+
+       if ((p == NULL) || (p == current) || (p->state == TASK_RUNNING))
+               return 0;
+
+       stack_page = (unsigned long) task_stack_page(p);
+       /* Bail if the process has no kernel stack for some reason */
+       if (stack_page == 0)
+               return 0;
+
+       sp = p->thread.switch_buf->JB_SP;
+       /*
+        * Bail if the stack pointer is below the bottom of the kernel
+        * stack for some reason
+        */
+       if (sp < stack_page)
+               return 0;
+
+       while (sp < stack_page + THREAD_SIZE) {
+               ip = *((unsigned long *) sp);
+               if (in_sched_functions(ip))
+                       /* Ignore everything until we're above the scheduler */
+                       seen_sched = 1;
+               else if (kernel_text_address(ip) && seen_sched)
+                       return ip;
+
+               sp += sizeof(unsigned long);
+       }
+
+       return 0;
+}
+
+int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
+{
+       int cpu = current_thread_info()->cpu;
+
+       return save_fp_registers(userspace_pid[cpu], (unsigned long *) fpu);
+}
+
index 04cebcf0679ff90e590b9374ed5c8a8b041acc1e..00197d3d21ec96daba38fe57b74db08183fc1310 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include "linux/sched.h"
+#include "kern_util.h"
 #include "os.h"
 #include "skas.h"
 
@@ -11,7 +12,7 @@ void (*pm_power_off)(void);
 
 static void kill_off_processes(void)
 {
-       if(proc_mm)
+       if (proc_mm)
                /*
                 * FIXME: need to loop over userspace_pids
                 */
@@ -21,8 +22,8 @@ static void kill_off_processes(void)
                int pid, me;
 
                me = os_getpid();
-               for_each_process(p){
-                       if(p->mm == NULL)
+               for_each_process(p) {
+                       if (p->mm == NULL)
                                continue;
 
                        pid = p->mm->context.id.u.pid;
index 89f9866a1354b8073cf5f015bd4b80e276b6e9a4..2b272b63b514c1508a83c3199d7a1b926d0c8c40 100644 (file)
@@ -1,18 +1,12 @@
 /*
- * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com)
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
  * Licensed under the GPL
  */
 
-#include "linux/kernel.h"
-#include "linux/list.h"
-#include "linux/slab.h"
-#include "linux/signal.h"
-#include "linux/interrupt.h"
-#include "init.h"
-#include "sigio.h"
-#include "irq_user.h"
+#include <linux/interrupt.h>
 #include "irq_kern.h"
 #include "os.h"
+#include "sigio.h"
 
 /* Protected by sigio_lock() called from write_sigio_workaround */
 static int sigio_irq_fd = -1;
@@ -33,9 +27,9 @@ int write_sigio_irq(int fd)
        err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
                             IRQF_DISABLED|IRQF_SAMPLE_RANDOM, "write sigio",
                             NULL);
-       if(err){
-               printk("write_sigio_irq : um_request_irq failed, err = %d\n",
-                      err);
+       if (err) {
+               printk(KERN_ERR "write_sigio_irq : um_request_irq failed, "
+                      "err = %d\n", err);
                return -1;
        }
        sigio_irq_fd = fd;
index 19cb97733937973737c8119ecc59a9ee021ae47a..b0fce720c4d08378afba4f642ec97b712ca482c3 100644 (file)
@@ -3,12 +3,12 @@
  * Licensed under the GPL
  */
 
-#include "linux/module.h"
-#include "linux/ptrace.h"
-#include "linux/sched.h"
-#include "asm/siginfo.h"
-#include "asm/signal.h"
-#include "asm/unistd.h"
+#include <linux/module.h>
+#include <linux/ptrace.h>
+#include <linux/sched.h>
+#include <asm/siginfo.h>
+#include <asm/signal.h>
+#include <asm/unistd.h>
 #include "frame_kern.h"
 #include "kern_util.h"
 #include "sigcontext.h"
@@ -36,7 +36,7 @@ static int handle_signal(struct pt_regs *regs, unsigned long signr,
        /* Did we come from a system call? */
        if (PT_REGS_SYSCALL_NR(regs) >= 0) {
                /* If so, check system call restarting.. */
-               switch(PT_REGS_SYSCALL_RET(regs)) {
+               switch (PT_REGS_SYSCALL_RET(regs)) {
                case -ERESTART_RESTARTBLOCK:
                case -ERESTARTNOHAND:
                        PT_REGS_SYSCALL_RET(regs) = -EINTR;
@@ -116,7 +116,7 @@ static int kern_do_signal(struct pt_regs *regs)
        /* Did we come from a system call? */
        if (!handled_sig && (PT_REGS_SYSCALL_NR(regs) >= 0)) {
                /* Restart the system call - no handlers present */
-               switch(PT_REGS_SYSCALL_RET(regs)) {
+               switch (PT_REGS_SYSCALL_RET(regs)) {
                case -ERESTARTNOHAND:
                case -ERESTARTSYS:
                case -ERESTARTNOINTR:
index 8d07a7acb909c707bd5ec4d0bcf3ce6d53045db1..2c8583c1a344df2003ee0f2371ca6ead0a085982 100644 (file)
@@ -1,17 +1,20 @@
-#include <sched.h>
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Licensed under the GPL
+ */
+
 #include <signal.h>
-#include <sys/mman.h>
-#include <sys/time.h>
+#include <sched.h>
 #include <asm/unistd.h>
+#include <sys/time.h>
 #include "as-layout.h"
+#include "kern_constants.h"
 #include "ptrace_user.h"
-#include "skas.h"
 #include "stub-data.h"
-#include "uml-config.h"
 #include "sysdep/stub.h"
-#include "kern_constants.h"
 
-/* This is in a separate file because it needs to be compiled with any
+/*
+ * This is in a separate file because it needs to be compiled with any
  * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
  *
  * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
@@ -26,25 +29,26 @@ stub_clone_handler(void)
 
        err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
                            STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
-       if(err != 0)
+       if (err != 0)
                goto out;
 
        err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
-       if(err)
+       if (err)
                goto out;
 
-       err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL, 
+       err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
                            (long) &data->timer, 0);
-       if(err)
+       if (err)
                goto out;
 
        remap_stack(data->fd, data->offset);
        goto done;
 
  out:
-       /* save current result. 
-        * Parent: pid; 
-        * child: retcode of mmap already saved and it jumps around this 
+       /*
+        * save current result.
+        * Parent: pid;
+        * child: retcode of mmap already saved and it jumps around this
         * assignment
         */
        data->err = err;
index f859ec306cd5ded54f4239bba0519d58eb52f2e3..78b3e9f69d57d6a81d9ac446e9f6edc16586e5fe 100644 (file)
@@ -34,33 +34,14 @@ static int init_stub_pte(struct mm_struct *mm, unsigned long proc,
        if (!pte)
                goto out_pte;
 
-       /*
-        * There's an interaction between the skas0 stub pages, stack
-        * randomization, and the BUG at the end of exit_mmap.  exit_mmap
-        * checks that the number of page tables freed is the same as had
-        * been allocated.  If the stack is on the last page table page,
-        * then the stack pte page will be freed, and if not, it won't.  To
-        * avoid having to know where the stack is, or if the process mapped
-        * something at the top of its address space for some other reason,
-        * we set TASK_SIZE to end at the start of the last page table.
-        * This keeps exit_mmap off the last page, but introduces a leak
-        * of that page.  So, we hang onto it here and free it in
-        * destroy_context_skas.
-        */
-
-       mm->context.last_page_table = pmd_page_vaddr(*pmd);
-#ifdef CONFIG_3_LEVEL_PGTABLES
-       mm->context.last_pmd = (unsigned long) __va(pud_val(*pud));
-#endif
-
        *pte = mk_pte(virt_to_page(kernel), __pgprot(_PAGE_PRESENT));
        *pte = pte_mkread(*pte);
        return 0;
 
  out_pmd:
-       pud_free(pud);
+       pud_free(mm, pud);
  out_pte:
-       pmd_free(pmd);
+       pmd_free(mm, pmd);
  out:
        return -ENOMEM;
 }
@@ -76,24 +57,6 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
                stack = get_zeroed_page(GFP_KERNEL);
                if (stack == 0)
                        goto out;
-
-               /*
-                * This zeros the entry that pgd_alloc didn't, needed since
-                * we are about to reinitialize it, and want mm.nr_ptes to
-                * be accurate.
-                */
-               mm->pgd[USER_PTRS_PER_PGD] = __pgd(0);
-
-               ret = init_stub_pte(mm, STUB_CODE,
-                                   (unsigned long) &__syscall_stub_start);
-               if (ret)
-                       goto out_free;
-
-               ret = init_stub_pte(mm, STUB_DATA, stack);
-               if (ret)
-                       goto out_free;
-
-               mm->nr_ptes--;
        }
 
        to_mm->id.stack = stack;
@@ -114,6 +77,11 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
                        to_mm->id.u.pid = copy_context_skas0(stack,
                                                             from_mm->id.u.pid);
                else to_mm->id.u.pid = start_userspace(stack);
+
+               if (to_mm->id.u.pid < 0) {
+                       ret = to_mm->id.u.pid;
+                       goto out_free;
+               }
        }
 
        ret = init_new_ldt(to_mm, from_mm);
@@ -132,24 +100,87 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
        return ret;
 }
 
+void arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
+{
+       struct page **pages;
+       int err, ret;
+
+       if (!skas_needs_stub)
+               return;
+
+       ret = init_stub_pte(mm, STUB_CODE,
+                           (unsigned long) &__syscall_stub_start);
+       if (ret)
+               goto out;
+
+       ret = init_stub_pte(mm, STUB_DATA, mm->context.id.stack);
+       if (ret)
+               goto out;
+
+       pages = kmalloc(2 * sizeof(struct page *), GFP_KERNEL);
+       if (pages == NULL) {
+               printk(KERN_ERR "arch_dup_mmap failed to allocate 2 page "
+                      "pointers\n");
+               goto out;
+       }
+
+       pages[0] = virt_to_page(&__syscall_stub_start);
+       pages[1] = virt_to_page(mm->context.id.stack);
+
+       /* dup_mmap already holds mmap_sem */
+       err = install_special_mapping(mm, STUB_START, STUB_END - STUB_START,
+                                     VM_READ | VM_MAYREAD | VM_EXEC |
+                                     VM_MAYEXEC | VM_DONTCOPY, pages);
+       if (err) {
+               printk(KERN_ERR "install_special_mapping returned %d\n", err);
+               goto out_free;
+       }
+       return;
+
+out_free:
+       kfree(pages);
+out:
+       force_sigsegv(SIGSEGV, current);
+}
+
+void arch_exit_mmap(struct mm_struct *mm)
+{
+       pte_t *pte;
+
+       pte = virt_to_pte(mm, STUB_CODE);
+       if (pte != NULL)
+               pte_clear(mm, STUB_CODE, pte);
+
+       pte = virt_to_pte(mm, STUB_DATA);
+       if (pte == NULL)
+               return;
+
+       pte_clear(mm, STUB_DATA, pte);
+}
+
 void destroy_context(struct mm_struct *mm)
 {
        struct mm_context *mmu = &mm->context;
 
        if (proc_mm)
                os_close_file(mmu->id.u.mm_fd);
-       else
+       else {
+               /*
+                * If init_new_context wasn't called, this will be
+                * zero, resulting in a kill(0), which will result in the
+                * whole UML suddenly dying.  Also, cover negative and
+                * 1 cases, since they shouldn't happen either.
+                */
+               if (mmu->id.u.pid < 2) {
+                       printk(KERN_ERR "corrupt mm_context - pid = %d\n",
+                              mmu->id.u.pid);
+                       return;
+               }
                os_kill_ptraced_process(mmu->id.u.pid, 1);
+       }
 
-       if (!proc_mm || !ptrace_faultinfo) {
+       if (skas_needs_stub)
                free_page(mmu->id.stack);
-               pte_lock_deinit(virt_to_page(mmu->last_page_table));
-               pte_free_kernel((pte_t *) mmu->last_page_table);
-               dec_zone_page_state(virt_to_page(mmu->last_page_table), NR_PAGETABLE);
-#ifdef CONFIG_3_LEVEL_PGTABLES
-               pmd_free((pmd_t *) mmu->last_pmd);
-#endif
-       }
 
        free_ldt(mmu);
 }
index fce389c2342f3d942cdae4d047edbb1f3a2bab50..2e9852c0d487449911fc289e3520a90e6306f9b9 100644 (file)
@@ -6,19 +6,25 @@
 #include "linux/init.h"
 #include "linux/sched.h"
 #include "as-layout.h"
+#include "kern.h"
 #include "os.h"
 #include "skas.h"
 
 int new_mm(unsigned long stack)
 {
-       int fd;
+       int fd, err;
 
        fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
        if (fd < 0)
                return fd;
 
-       if (skas_needs_stub)
-               map_stub_pages(fd, STUB_CODE, STUB_DATA, stack);
+       if (skas_needs_stub) {
+               err = map_stub_pages(fd, STUB_CODE, STUB_DATA, stack);
+               if (err) {
+                       os_close_file(fd);
+                       return err;
+               }
+       }
 
        return fd;
 }
@@ -49,8 +55,14 @@ int __init start_uml(void)
 {
        stack_protections((unsigned long) &cpu0_irqstack);
        set_sigstack(cpu0_irqstack, THREAD_SIZE);
-       if (proc_mm)
+       if (proc_mm) {
                userspace_pid[0] = start_userspace(0);
+               if (userspace_pid[0] < 0) {
+                       printf("start_uml - start_userspace returned %d\n",
+                              userspace_pid[0]);
+                       exit(1);
+               }
+       }
 
        init_new_thread_signals();
 
index 50b476f2b38df9096fee81a705ae4ef5e04b93e5..4e3b820bd2beaa477d6bc57b20dcae501f357db6 100644 (file)
@@ -9,6 +9,9 @@
 #include "sysdep/ptrace.h"
 #include "sysdep/syscalls.h"
 
+extern int syscall_table_size;
+#define NR_syscalls (syscall_table_size / sizeof(void *))
+
 void handle_syscall(struct uml_pt_regs *r)
 {
        struct pt_regs *regs = container_of(r, struct pt_regs, regs);
@@ -17,9 +20,6 @@ void handle_syscall(struct uml_pt_regs *r)
 
        syscall_trace(r, 0);
 
-       current->thread.nsyscalls++;
-       nsyscalls++;
-
        /*
         * This should go in the declaration of syscall, but when I do that,
         * strace -f -c bash -c 'ls ; ls' breaks, sometimes not tracing
index 1d8b119f2d0e12f9930b5f3092df793f8d5c1803..e22c96993db3b07545e107adb57f2ef1d8ddb608 100644 (file)
  * Licensed under the GPL
  */
 
-#include "linux/err.h"
-#include "linux/highmem.h"
-#include "linux/mm.h"
-#include "asm/current.h"
-#include "asm/page.h"
-#include "asm/pgtable.h"
+#include <linux/err.h>
+#include <linux/highmem.h>
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <asm/current.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
 #include "kern_util.h"
 #include "os.h"
 
-extern void *um_virt_to_phys(struct task_struct *task, unsigned long addr,
-                            pte_t *pte_out);
-
-static unsigned long maybe_map(unsigned long virt, int is_write)
+pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr)
 {
-       pte_t pte;
-       int err;
+       pgd_t *pgd;
+       pud_t *pud;
+       pmd_t *pmd;
+
+       if (mm == NULL)
+               return NULL;
+
+       pgd = pgd_offset(mm, addr);
+       if (!pgd_present(*pgd))
+               return NULL;
+
+       pud = pud_offset(pgd, addr);
+       if (!pud_present(*pud))
+               return NULL;
 
-       void *phys = um_virt_to_phys(current, virt, &pte);
-       int dummy_code;
+       pmd = pmd_offset(pud, addr);
+       if (!pmd_present(*pmd))
+               return NULL;
+
+       return pte_offset_kernel(pmd, addr);
+}
+
+static pte_t *maybe_map(unsigned long virt, int is_write)
+{
+       pte_t *pte = virt_to_pte(current->mm, virt);
+       int err, dummy_code;
 
-       if (IS_ERR(phys) || (is_write && !pte_write(pte))) {
+       if ((pte == NULL) || !pte_present(*pte) ||
+           (is_write && !pte_write(*pte))) {
                err = handle_page_fault(virt, 0, is_write, 1, &dummy_code);
                if (err)
-                       return -1UL;
-               phys = um_virt_to_phys(current, virt, NULL);
+                       return NULL;
+               pte = virt_to_pte(current->mm, virt);
        }
-       if (IS_ERR(phys))
-               phys = (void *) -1;
+       if (!pte_present(*pte))
+               pte = NULL;
 
-       return (unsigned long) phys;
+       return pte;
 }
 
 static int do_op_one_page(unsigned long addr, int len, int is_write,
                 int (*op)(unsigned long addr, int len, void *arg), void *arg)
 {
+       jmp_buf buf;
        struct page *page;
-       int n;
+       pte_t *pte;
+       int n, faulted;
 
-       addr = maybe_map(addr, is_write);
-       if (addr == -1UL)
+       pte = maybe_map(addr, is_write);
+       if (pte == NULL)
                return -1;
 
-       page = phys_to_page(addr);
+       page = pte_page(*pte);
        addr = (unsigned long) kmap_atomic(page, KM_UML_USERCOPY) +
                (addr & ~PAGE_MASK);
 
-       n = (*op)(addr, len, arg);
+       current->thread.fault_catcher = &buf;
+
+       faulted = UML_SETJMP(&buf);
+       if (faulted == 0)
+               n = (*op)(addr, len, arg);
+       else
+               n = -1;
+
+       current->thread.fault_catcher = NULL;
 
        kunmap_atomic(page, KM_UML_USERCOPY);
 
        return n;
 }
 
-static void do_buffer_op(void *jmpbuf, void *arg_ptr)
+static int buffer_op(unsigned long addr, int len, int is_write,
+                    int (*op)(unsigned long, int, void *), void *arg)
 {
-       va_list args;
-       unsigned long addr;
-       int len, is_write, size, remain, n;
-       int (*op)(unsigned long, int, void *);
-       void *arg;
-       int *res;
-
-       va_copy(args, *(va_list *)arg_ptr);
-       addr = va_arg(args, unsigned long);
-       len = va_arg(args, int);
-       is_write = va_arg(args, int);
-       op = va_arg(args, void *);
-       arg = va_arg(args, void *);
-       res = va_arg(args, int *);
-       va_end(args);
+       int size, remain, n;
+
        size = min(PAGE_ALIGN(addr) - addr, (unsigned long) len);
        remain = len;
 
-       current->thread.fault_catcher = jmpbuf;
        n = do_op_one_page(addr, size, is_write, op, arg);
        if (n != 0) {
-               *res = (n < 0 ? remain : 0);
+               remain = (n < 0 ? remain : 0);
                goto out;
        }
 
        addr += size;
        remain -= size;
-       if (remain == 0) {
-               *res = 0;
+       if (remain == 0)
                goto out;
-       }
 
-       while(addr < ((addr + remain) & PAGE_MASK)) {
+       while (addr < ((addr + remain) & PAGE_MASK)) {
                n = do_op_one_page(addr, PAGE_SIZE, is_write, op, arg);
                if (n != 0) {
-                       *res = (n < 0 ? remain : 0);
+                       remain = (n < 0 ? remain : 0);
                        goto out;
                }
 
                addr += PAGE_SIZE;
                remain -= PAGE_SIZE;
        }
-       if (remain == 0) {
-               *res = 0;
+       if (remain == 0)
                goto out;
-       }
 
        n = do_op_one_page(addr, remain, is_write, op, arg);
-       if (n != 0)
-               *res = (n < 0 ? remain : 0);
-       else *res = 0;
- out:
-       current->thread.fault_catcher = NULL;
-}
-
-static int buffer_op(unsigned long addr, int len, int is_write,
-                    int (*op)(unsigned long addr, int len, void *arg),
-                    void *arg)
-{
-       int faulted, res;
-
-       faulted = setjmp_wrapper(do_buffer_op, addr, len, is_write, op, arg,
-                                &res);
-       if (!faulted)
-               return res;
+       if (n != 0) {
+               remain = (n < 0 ? remain : 0);
+               goto out;
+       }
 
-       return addr + len - (unsigned long) current->thread.fault_addr;
+       return 0;
+ out:
+       return remain;
 }
 
 static int copy_chunk_from_user(unsigned long from, int len, void *arg)
index 36d89cf8d20b2b223bb04f08a5735cd2a76e08af..e1062ec36d4072cc1cc3cfa34232c67c81b59133 100644 (file)
@@ -21,7 +21,6 @@ DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
 #include "asm/smp.h"
 #include "asm/processor.h"
 #include "asm/spinlock.h"
-#include "kern_util.h"
 #include "kern.h"
 #include "irq_user.h"
 #include "os.h"
@@ -61,7 +60,7 @@ void smp_send_stop(void)
                        continue;
                os_write_file(cpu_data[i].ipi_pipe[1], "S", 1);
        }
-       printk(KERN_INFO "done\n");
+       printk(KERN_CONT "done\n");
 }
 
 static cpumask_t smp_commenced_mask = CPU_MASK_NONE;
@@ -75,8 +74,7 @@ static int idle_proc(void *cpup)
        if (err < 0)
                panic("CPU#%d failed to create IPI pipe, err = %d", cpu, -err);
 
-       os_set_fd_async(cpu_data[cpu].ipi_pipe[0],
-                    current->thread.mode.tt.extern_pid);
+       os_set_fd_async(cpu_data[cpu].ipi_pipe[0]);
 
        wmb();
        if (cpu_test_and_set(cpu, cpu_callin_map)) {
@@ -129,8 +127,7 @@ void smp_prepare_cpus(unsigned int maxcpus)
        if (err < 0)
                panic("CPU#0 failed to create IPI pipe, errno = %d", -err);
 
-       os_set_fd_async(cpu_data[me].ipi_pipe[0],
-                    current->thread.mode.tt.extern_pid);
+       os_set_fd_async(cpu_data[me].ipi_pipe[0]);
 
        for (cpu = 1; cpu < ncpus; cpu++) {
                printk(KERN_INFO "Booting processor %d...\n", cpu);
@@ -143,9 +140,8 @@ void smp_prepare_cpus(unsigned int maxcpus)
                while (waittime-- && !cpu_isset(cpu, cpu_callin_map))
                        cpu_relax();
 
-               if (cpu_isset(cpu, cpu_callin_map))
-                       printk(KERN_INFO "done\n");
-               else printk(KERN_INFO "failed\n");
+               printk(KERN_INFO "%s\n",
+                      cpu_isset(cpu, cpu_calling_map) ? "done" : "failed");
        }
 }
 
index b9d92b2089aed6cb0b3a5d67d0dafce8fd0051dc..9cffc628a37e0f9505f6da9a8283eaf0ee368e2f 100644 (file)
@@ -13,9 +13,6 @@
 #include "asm/uaccess.h"
 #include "asm/unistd.h"
 
-/*  Unlocked, I don't care if this is a bit off */
-int nsyscalls = 0;
-
 long sys_fork(void)
 {
        long ret;
index 93263571d813ecf7fc2b8e2212a91f13a621c3f5..56d43d0a39602b140d458f2f989779bc9512b66a 100644 (file)
@@ -1,38 +1,37 @@
-/* 
- * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include "linux/sched.h"
-#include "linux/kernel.h"
-#include "linux/module.h"
-#include "linux/kallsyms.h"
-#include "asm/page.h"
-#include "asm/processor.h"
+#include <linux/kallsyms.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
 #include "sysrq.h"
 
 /* Catch non-i386 SUBARCH's. */
 #if !defined(CONFIG_UML_X86) || defined(CONFIG_64BIT)
 void show_trace(struct task_struct *task, unsigned long * stack)
 {
-        unsigned long addr;
+       unsigned long addr;
 
-        if (!stack) {
+       if (!stack) {
                stack = (unsigned long*) &stack;
                WARN_ON(1);
        }
 
-        printk("Call Trace: \n");
-        while (((long) stack & (THREAD_SIZE-1)) != 0) {
-                addr = *stack;
+       printk(KERN_INFO "Call Trace: \n");
+       while (((long) stack & (THREAD_SIZE-1)) != 0) {
+               addr = *stack;
                if (__kernel_text_address(addr)) {
-                       printk("%08lx:  [<%08lx>]", (unsigned long) stack, addr);
-                       print_symbol(" %s", addr);
-                       printk("\n");
-                }
-                stack++;
-        }
-        printk("\n");
+                       printk(KERN_INFO "%08lx:  [<%08lx>]",
+                              (unsigned long) stack, addr);
+                       print_symbol(KERN_CONT " %s", addr);
+                       printk(KERN_CONT "\n");
+               }
+               stack++;
+       }
+       printk(KERN_INFO "\n");
 }
 #endif
 
@@ -67,14 +66,13 @@ void show_stack(struct task_struct *task, unsigned long *esp)
        }
 
        stack = esp;
-       for(i = 0; i < kstack_depth_to_print; i++) {
+       for (i = 0; i < kstack_depth_to_print; i++) {
                if (kstack_end(stack))
                        break;
                if (i && ((i % 8) == 0))
-                       printk("\n       ");
+                       printk("\n" KERN_INFO "       ");
                printk("%08lx ", *stack++);
        }
 
-       printk("Call Trace: \n");
        show_trace(task, esp);
 }
index 1ac746a9eae1aae17e7b715a70084f793560cd4b..e066e84493b129a23f7018ce09d145dddf14f97b 100644 (file)
@@ -3,12 +3,12 @@
  * Licensed under the GPL
  */
 
-#include "linux/clockchips.h"
-#include "linux/interrupt.h"
-#include "linux/jiffies.h"
-#include "linux/threads.h"
-#include "asm/irq.h"
-#include "asm/param.h"
+#include <linux/clockchips.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/threads.h>
+#include <asm/irq.h>
+#include <asm/param.h>
 #include "kern_util.h"
 #include "os.h"
 
@@ -32,7 +32,7 @@ void timer_handler(int sig, struct uml_pt_regs *regs)
 static void itimer_set_mode(enum clock_event_mode mode,
                            struct clock_event_device *evt)
 {
-       switch(mode) {
+       switch (mode) {
        case CLOCK_EVT_MODE_PERIODIC:
                set_interval();
                break;
index f4a0e407eee4d66e9fb8b62db6a3e36110d2854a..d175d0566af02d35acde18d805040c61a4bd29f2 100644 (file)
@@ -3,9 +3,10 @@
  * Licensed under the GPL
  */
 
-#include "linux/mm.h"
-#include "asm/pgtable.h"
-#include "asm/tlbflush.h"
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
 #include "as-layout.h"
 #include "mem_user.h"
 #include "os.h"
@@ -56,7 +57,7 @@ static int do_ops(struct host_vm_change *hvc, int end,
 
        for (i = 0; i < end && !ret; i++) {
                op = &hvc->ops[i];
-               switch(op->type) {
+               switch (op->type) {
                case MMAP:
                        ret = map(hvc->id, op->u.mmap.addr, op->u.mmap.len,
                                  op->u.mmap.prot, op->u.mmap.fd,
@@ -183,27 +184,30 @@ static inline int update_pte_range(pmd_t *pmd, unsigned long addr,
 
        pte = pte_offset_kernel(pmd, addr);
        do {
+               if ((addr >= STUB_START) && (addr < STUB_END))
+                       continue;
+
                r = pte_read(*pte);
                w = pte_write(*pte);
                x = pte_exec(*pte);
                if (!pte_young(*pte)) {
                        r = 0;
                        w = 0;
-               } else if (!pte_dirty(*pte)) {
+               } else if (!pte_dirty(*pte))
                        w = 0;
-               }
+
                prot = ((r ? UM_PROT_READ : 0) | (w ? UM_PROT_WRITE : 0) |
                        (x ? UM_PROT_EXEC : 0));
                if (hvc->force || pte_newpage(*pte)) {
                        if (pte_present(*pte))
                                ret = add_mmap(addr, pte_val(*pte) & PAGE_MASK,
                                               PAGE_SIZE, prot, hvc);
-                       else ret = add_munmap(addr, PAGE_SIZE, hvc);
-               }
-               else if (pte_newprot(*pte))
+                       else
+                               ret = add_munmap(addr, PAGE_SIZE, hvc);
+               else if (pte_newprot(*pte))
                        ret = add_mprotect(addr, PAGE_SIZE, prot, hvc);
                *pte = pte_mkuptodate(*pte);
-       } while (pte++, addr += PAGE_SIZE, ((addr != end) && !ret));
+       } while (pte++, addr += PAGE_SIZE, ((addr < end) && !ret));
        return ret;
 }
 
@@ -225,7 +229,7 @@ static inline int update_pmd_range(pud_t *pud, unsigned long addr,
                        }
                }
                else ret = update_pte_range(pmd, addr, next, hvc);
-       } while (pmd++, addr = next, ((addr != end) && !ret));
+       } while (pmd++, addr = next, ((addr < end) && !ret));
        return ret;
 }
 
@@ -247,7 +251,7 @@ static inline int update_pud_range(pgd_t *pgd, unsigned long addr,
                        }
                }
                else ret = update_pmd_range(pud, addr, next, hvc);
-       } while (pud++, addr = next, ((addr != end) && !ret));
+       } while (pud++, addr = next, ((addr < end) && !ret));
        return ret;
 }
 
@@ -270,7 +274,7 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
                        }
                }
                else ret = update_pud_range(pgd, addr, next, &hvc);
-       } while (pgd++, addr = next, ((addr != end_addr) && !ret));
+       } while (pgd++, addr = next, ((addr < end_addr) && !ret));
 
        if (!ret)
                ret = do_ops(&hvc, hvc.index, 1);
@@ -485,9 +489,6 @@ void __flush_tlb_one(unsigned long addr)
 static void fix_range(struct mm_struct *mm, unsigned long start_addr,
                      unsigned long end_addr, int force)
 {
-       if (!proc_mm && (end_addr > STUB_START))
-               end_addr = STUB_START;
-
        fix_range_common(mm, start_addr, end_addr, force);
 }
 
@@ -499,10 +500,9 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
        else fix_range(vma->vm_mm, start, end, 0);
 }
 
-void flush_tlb_mm(struct mm_struct *mm)
+void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
+                       unsigned long end)
 {
-       unsigned long end;
-
        /*
         * Don't bother flushing if this address space is about to be
         * destroyed.
@@ -510,8 +510,17 @@ void flush_tlb_mm(struct mm_struct *mm)
        if (atomic_read(&mm->mm_users) == 0)
                return;
 
-       end = proc_mm ? task_size : STUB_START;
-       fix_range(mm, 0, end, 0);
+       fix_range(mm, start, end, 0);
+}
+
+void flush_tlb_mm(struct mm_struct *mm)
+{
+       struct vm_area_struct *vma = mm->mmap;
+
+       while (vma != NULL) {
+               fix_range(mm, vma->vm_start, vma->vm_end, 0);
+               vma = vma->vm_next;
+       }
 }
 
 void force_flush_all(void)
index cb3321f8e0a91924167b0f83ea7f34c30df55080..44e4904194951f680f187fd4f6137ca289b9cab8 100644 (file)
@@ -13,6 +13,7 @@
 #include "as-layout.h"
 #include "kern_util.h"
 #include "os.h"
+#include "skas.h"
 #include "sysdep/sigcontext.h"
 
 /*
@@ -128,7 +129,19 @@ static void bad_segv(struct faultinfo fi, unsigned long ip)
        force_sig_info(SIGSEGV, &si, current);
 }
 
-static void segv_handler(int sig, struct uml_pt_regs *regs)
+void fatal_sigsegv(void)
+{
+       force_sigsegv(SIGSEGV, current);
+       do_signal();
+       /*
+        * This is to tell gcc that we're not returning - do_signal
+        * can, in general, return, but in this case, it's not, since
+        * we just got a fatal SIGSEGV queued.
+        */
+       os_dump_core();
+}
+
+void segv_handler(int sig, struct uml_pt_regs *regs)
 {
        struct faultinfo * fi = UPT_FAULTINFO(regs);
 
@@ -216,9 +229,6 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
 
 void relay_signal(int sig, struct uml_pt_regs *regs)
 {
-       if (arch_handle_signal(sig, regs))
-               return;
-
        if (!UPT_IS_USER(regs)) {
                if (sig == SIGBUS)
                        printk(KERN_ERR "Bus error - the host /dev/shm or /tmp "
@@ -226,31 +236,24 @@ void relay_signal(int sig, struct uml_pt_regs *regs)
                panic("Kernel mode signal %d", sig);
        }
 
+       arch_examine_signal(sig, regs);
+
        current->thread.arch.faultinfo = *UPT_FAULTINFO(regs);
        force_sig(sig, current);
 }
 
-static void bus_handler(int sig, struct uml_pt_regs *regs)
+void bus_handler(int sig, struct uml_pt_regs *regs)
 {
        if (current->thread.fault_catcher != NULL)
                UML_LONGJMP(current->thread.fault_catcher, 1);
        else relay_signal(sig, regs);
 }
 
-static void winch(int sig, struct uml_pt_regs *regs)
+void winch(int sig, struct uml_pt_regs *regs)
 {
        do_IRQ(WINCH_IRQ, regs);
 }
 
-const struct kern_handlers handlinfo_kern = {
-       .relay_signal = relay_signal,
-       .winch = winch,
-       .bus_handler = bus_handler,
-       .page_fault = segv_handler,
-       .sigio_handler = sigio_handler,
-       .timer_handler = timer_handler
-};
-
 void trap_init(void)
 {
 }
index d7436aacd26f0feeb88600770474912c9220522e..f0f4b040d7c51cb1b17e44402ce5be1b03ec8f40 100644 (file)
@@ -1,10 +1,11 @@
 /*
  * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-/* These are here rather than tt/uaccess.c because skas mode needs them in
+/*
+ * These are here rather than tt/uaccess.c because skas mode needs them in
  * order to do SIGBUS recovery when a tmpfs mount runs out of room.
  */
 
@@ -25,6 +26,8 @@ int __do_copy_to_user(void *to, const void *from, int n,
 
        fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
                               __do_copy, &faulted);
-       if(!faulted) return(0);
-       else return(n - (fault - (unsigned long) to));
+       if (!faulted)
+               return 0;
+       else
+               return n - (fault - (unsigned long) to);
 }
index f1c71393f57810feb8368b256f7dab7bf5111a43..468aba990dbd1652add865bb88f1006ece3a7d16 100644 (file)
@@ -3,22 +3,23 @@
  * Licensed under the GPL
  */
 
-#include "linux/delay.h"
-#include "linux/mm.h"
-#include "linux/module.h"
-#include "linux/seq_file.h"
-#include "linux/string.h"
-#include "linux/utsname.h"
-#include "asm/pgtable.h"
-#include "asm/processor.h"
-#include "asm/setup.h"
-#include "arch.h"
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+#include <linux/string.h>
+#include <linux/utsname.h>
+#include <asm/pgtable.h>
+#include <asm/processor.h>
+#include <asm/setup.h>
 #include "as-layout.h"
+#include "arch.h"
 #include "init.h"
 #include "kern.h"
+#include "kern_util.h"
 #include "mem_user.h"
 #include "os.h"
-#include "skas.h"
 
 #define DEFAULT_COMMAND_LINE "root=98:0"
 
@@ -100,8 +101,6 @@ const struct seq_operations cpuinfo_op = {
 };
 
 /* Set in linux_main */
-unsigned long host_task_size;
-unsigned long task_size;
 unsigned long uml_physmem;
 unsigned long uml_reserved; /* Also modified in mem_init */
 unsigned long start_vm;
@@ -197,20 +196,19 @@ __uml_setup("--help", Usage,
 "    Prints this message.\n\n"
 );
 
-static int __init uml_checksetup(char *line, int *add)
+static void __init uml_checksetup(char *line, int *add)
 {
        struct uml_param *p;
 
        p = &__uml_setup_start;
-       while(p < &__uml_setup_end) {
+       while (p < &__uml_setup_end) {
                int n;
 
                n = strlen(p->str);
                if (!strncmp(line, p->str, n) && p->setup_func(line + n, add))
-                       return 1;
+                       return;
                p++;
        }
-       return 0;
 }
 
 static void __init uml_postsetup(void)
@@ -218,13 +216,30 @@ static void __init uml_postsetup(void)
        initcall_t *p;
 
        p = &__uml_postsetup_start;
-       while(p < &__uml_postsetup_end) {
+       while (p < &__uml_postsetup_end) {
                (*p)();
                p++;
        }
        return;
 }
 
+static int panic_exit(struct notifier_block *self, unsigned long unused1,
+                     void *unused2)
+{
+       bust_spinlocks(1);
+       show_regs(&(current->thread.regs));
+       bust_spinlocks(0);
+       uml_exitcode = 1;
+       os_dump_core();
+       return 0;
+}
+
+static struct notifier_block panic_exit_notifier = {
+       .notifier_call          = panic_exit,
+       .next                   = NULL,
+       .priority               = 0
+};
+
 /* Set during early boot */
 unsigned long brk_start;
 unsigned long end_iomem;
@@ -234,20 +249,6 @@ EXPORT_SYMBOL(end_iomem);
 
 extern char __binary_start;
 
-static unsigned long set_task_sizes_skas(unsigned long *task_size_out)
-{
-       /* Round up to the nearest 4M */
-       unsigned long host_task_size = ROUND_4M((unsigned long)
-                                               &host_task_size);
-
-       if (!skas_needs_stub)
-               *task_size_out = host_task_size;
-       else
-               *task_size_out = STUB_START & PGDIR_MASK;
-
-       return host_task_size;
-}
-
 int __init linux_main(int argc, char **argv)
 {
        unsigned long avail, diff;
@@ -278,13 +279,6 @@ int __init linux_main(int argc, char **argv)
 
        printf("UML running in %s mode\n", mode);
 
-       host_task_size = set_task_sizes_skas(&task_size);
-
-       /*
-        * Setting up handlers to 'sig_info' struct
-        */
-       os_fill_handlinfo(handlinfo_kern);
-
        brk_start = (unsigned long) sbrk(0);
 
        /*
@@ -309,7 +303,7 @@ int __init linux_main(int argc, char **argv)
 
        highmem = 0;
        iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK;
-       max_physmem = get_kmem_end() - uml_physmem - iomem_size - MIN_VMALLOC;
+       max_physmem = CONFIG_TOP_ADDR - uml_physmem - iomem_size - MIN_VMALLOC;
 
        /*
         * Zones have to begin on a 1 << MAX_ORDER page boundary,
@@ -341,7 +335,7 @@ int __init linux_main(int argc, char **argv)
        }
 
        virtmem_size = physmem_size;
-       avail = get_kmem_end() - start_vm;
+       avail = CONFIG_TOP_ADDR - start_vm;
        if (physmem_size > avail)
                virtmem_size = avail;
        end_vm = start_vm + virtmem_size;
@@ -350,6 +344,9 @@ int __init linux_main(int argc, char **argv)
                printf("Kernel virtual memory size shrunk to %lu bytes\n",
                       virtmem_size);
 
+       atomic_notifier_chain_register(&panic_notifier_list,
+                                      &panic_exit_notifier);
+
        uml_postsetup();
 
        stack_protections((unsigned long) &init_thread_info);
@@ -358,29 +355,8 @@ int __init linux_main(int argc, char **argv)
        return start_uml();
 }
 
-extern int uml_exitcode;
-
-static int panic_exit(struct notifier_block *self, unsigned long unused1,
-                     void *unused2)
-{
-       bust_spinlocks(1);
-       show_regs(&(current->thread.regs));
-       bust_spinlocks(0);
-       uml_exitcode = 1;
-       os_dump_core();
-       return 0;
-}
-
-static struct notifier_block panic_exit_notifier = {
-       .notifier_call          = panic_exit,
-       .next                   = NULL,
-       .priority               = 0
-};
-
 void __init setup_arch(char **cmdline_p)
 {
-       atomic_notifier_chain_register(&panic_notifier_list,
-                       &panic_exit_notifier);
        paging_init();
        strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
        *cmdline_p = command_line;
index 039e16efcd5571a7a520f051cf5efa1c61c61b54..81e07e2be3ae540abb2715ca56824f02b79c6cea 100644 (file)
@@ -1,13 +1,12 @@
-/* 
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include "asm/errno.h"
+#include <asm/errno.h>
 #include "init.h"
-#include "os.h"
 #include "kern.h"
-#include "linux/kernel.h"
+#include "os.h"
 
 /* Changed by set_umid_arg */
 static int umid_inited = 0;
@@ -16,16 +15,16 @@ static int __init set_umid_arg(char *name, int *add)
 {
        int err;
 
-       if(umid_inited){
+       if (umid_inited) {
                printf("umid already set\n");
                return 0;
        }
 
        *add = 0;
        err = set_umid(name);
-       if(err == -EEXIST)
+       if (err == -EEXIST)
                printf("umid '%s' already in use\n", name);
-       else if(!err)
+       else if (!err)
                umid_inited = 1;
 
        return 0;
index 8e129af8170d2b7d7af03aee3e70957dc0f5835f..8a48d6a30064139fa28bcfc53a0897b046988a3b 100644 (file)
@@ -4,7 +4,7 @@
 #
 
 obj-y = aio.o elf_aux.o execvp.o file.o helper.o irq.o main.o mem.o process.o \
-       registers.o sigio.o signal.o start_up.o time.o trap.o tty.o uaccess.o \
+       registers.o sigio.o signal.o start_up.o time.o tty.o uaccess.o \
        umid.o tls.o user_syms.o util.o drivers/ sys-$(SUBARCH)/ skas/
 
 obj-$(CONFIG_TTY_LOG) += tty_log.o
@@ -12,7 +12,7 @@ user-objs-$(CONFIG_TTY_LOG) += tty_log.o
 
 USER_OBJS := $(user-objs-y) aio.o elf_aux.o execvp.o file.o helper.o irq.o \
        main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \
-       trap.o tty.o tls.o uaccess.o umid.o util.o
+       tty.o tls.o uaccess.o umid.o util.o
 
 CFLAGS_user_syms.o += -DSUBARCH_$(SUBARCH)
 
index 93dc0c80ebaf7d128f08125185a8ba65c5f6f770..b8d8c9ca8d4afa48d3374520615fc5fdf8c2d8df 100644 (file)
@@ -12,6 +12,7 @@
 #include "aio.h"
 #include "init.h"
 #include "kern_constants.h"
+#include "kern_util.h"
 #include "os.h"
 #include "user.h"
 
index 07ca0cb472acf40b1ed8976070e5f4e2ac2cba25..6fb0b174f538df06711bf0f5b779f62ea4eb1f63 100644 (file)
@@ -131,7 +131,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
        }
        if (c != 1) {
                printk(UM_KERN_ERR "etap_tramp : uml_net failed\n");
-               err = helper_wait(pid, 0, "uml_net");
+               err = helper_wait(pid);
        }
        return err;
 }
index 1037a3b6386ee95f4ff746f764fd1200dc5411f3..2448be03fd7a5018691d3656d963d934b604c810 100644 (file)
@@ -14,6 +14,7 @@
 #include <sys/wait.h>
 #include <sys/uio.h>
 #include "kern_constants.h"
+#include "kern_util.h"
 #include "os.h"
 #include "tuntap.h"
 #include "user.h"
@@ -107,7 +108,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
                       "errno = %d\n", errno);
                return err;
        }
-       helper_wait(pid, 0, "tuntap_open_tramp");
+       helper_wait(pid);
 
        cmsg = CMSG_FIRSTHDR(&msg);
        if (cmsg == NULL) {
@@ -148,7 +149,7 @@ static int tuntap_open(void *data)
                memset(&ifr, 0, sizeof(ifr));
                ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
                strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
-               if (ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0) {
+               if (ioctl(pri->fd, TUNSETIFF, &ifr) < 0) {
                        err = -errno;
                        printk(UM_KERN_ERR "TUNSETIFF failed, errno = %d\n",
                               errno);
index f834627586272b80c4702b499553ac24c296c9dd..b5afcfd0f8611dedd72bd3c58defddcd1e647035 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -8,18 +8,16 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
-#include <sys/uio.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/un.h>
+#include "kern_constants.h"
 #include "os.h"
 #include "user.h"
-#include "kern_util.h"
 
-static void copy_stat(struct uml_stat *dst, struct stat64 *src)
+static void copy_stat(struct uml_stat *dst, const struct stat64 *src)
 {
        *dst = ((struct uml_stat) {
                .ust_dev     = src->st_dev,     /* device */
@@ -43,10 +41,10 @@ int os_stat_fd(const int fd, struct uml_stat *ubuf)
        int err;
 
        CATCH_EINTR(err = fstat64(fd, &sbuf));
-       if(err < 0)
+       if (err < 0)
                return -errno;
 
-       if(ubuf != NULL)
+       if (ubuf != NULL)
                copy_stat(ubuf, &sbuf);
        return err;
 }
@@ -56,27 +54,26 @@ int os_stat_file(const char *file_name, struct uml_stat *ubuf)
        struct stat64 sbuf;
        int err;
 
-       do {
-               err = stat64(file_name, &sbuf);
-       } while((err < 0) && (errno == EINTR)) ;
-
-       if(err < 0)
+       CATCH_EINTR(err = stat64(file_name, &sbuf));
+       if (err < 0)
                return -errno;
 
-       if(ubuf != NULL)
+       if (ubuf != NULL)
                copy_stat(ubuf, &sbuf);
        return err;
 }
 
-int os_access(const charfile, int mode)
+int os_access(const char *file, int mode)
 {
        int amode, err;
 
-       amode=(mode&OS_ACC_R_OK ? R_OK : 0) | (mode&OS_ACC_W_OK ? W_OK : 0) |
-             (mode&OS_ACC_X_OK ? X_OK : 0) | (mode&OS_ACC_F_OK ? F_OK : 0) ;
+       amode = (mode & OS_ACC_R_OK ? R_OK : 0) |
+               (mode & OS_ACC_W_OK ? W_OK : 0) |
+               (mode & OS_ACC_X_OK ? X_OK : 0) |
+               (mode & OS_ACC_F_OK ? F_OK : 0);
 
        err = access(file, amode);
-       if(err < 0)
+       if (err < 0)
                return -errno;
 
        return 0;
@@ -88,7 +85,7 @@ int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
        int err;
 
        err = ioctl(fd, cmd, arg);
-       if(err < 0)
+       if (err < 0)
                return -errno;
 
        return err;
@@ -97,7 +94,7 @@ int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
 /* FIXME: ensure namebuf in os_get_if_name is big enough */
 int os_get_ifname(int fd, char* namebuf)
 {
-       if(ioctl(fd, SIOCGIFNAME, namebuf) < 0)
+       if (ioctl(fd, SIOCGIFNAME, namebuf) < 0)
                return -errno;
 
        return 0;
@@ -108,37 +105,22 @@ int os_set_slip(int fd)
        int disc, sencap;
 
        disc = N_SLIP;
-       if(ioctl(fd, TIOCSETD, &disc) < 0)
+       if (ioctl(fd, TIOCSETD, &disc) < 0)
                return -errno;
 
        sencap = 0;
-       if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0)
+       if (ioctl(fd, SIOCSIFENCAP, &sencap) < 0)
                return -errno;
 
        return 0;
 }
 
-int os_set_owner(int fd, int pid)
-{
-       if(fcntl(fd, F_SETOWN, pid) < 0){
-               int save_errno = errno;
-
-               if(fcntl(fd, F_GETOWN, 0) != pid)
-                       return -save_errno;
-       }
-
-       return 0;
-}
-
 int os_mode_fd(int fd, int mode)
 {
        int err;
 
-       do {
-               err = fchmod(fd, mode);
-       } while((err < 0) && (errno==EINTR)) ;
-
-       if(err < 0)
+       CATCH_EINTR(err = fchmod(fd, mode));
+       if (err < 0)
                return -errno;
 
        return 0;
@@ -150,64 +132,73 @@ int os_file_type(char *file)
        int err;
 
        err = os_stat_file(file, &buf);
-       if(err < 0)
+       if (err < 0)
                return err;
 
-       if(S_ISDIR(buf.ust_mode))
+       if (S_ISDIR(buf.ust_mode))
                return OS_TYPE_DIR;
-       else if(S_ISLNK(buf.ust_mode))
+       else if (S_ISLNK(buf.ust_mode))
                return OS_TYPE_SYMLINK;
-       else if(S_ISCHR(buf.ust_mode))
+       else if (S_ISCHR(buf.ust_mode))
                return OS_TYPE_CHARDEV;
-       else if(S_ISBLK(buf.ust_mode))
+       else if (S_ISBLK(buf.ust_mode))
                return OS_TYPE_BLOCKDEV;
-       else if(S_ISFIFO(buf.ust_mode))
+       else if (S_ISFIFO(buf.ust_mode))
                return OS_TYPE_FIFO;
-       else if(S_ISSOCK(buf.ust_mode))
+       else if (S_ISSOCK(buf.ust_mode))
                return OS_TYPE_SOCK;
        else return OS_TYPE_FILE;
 }
 
-int os_file_mode(char *file, struct openflags *mode_out)
+int os_file_mode(const char *file, struct openflags *mode_out)
 {
        int err;
 
        *mode_out = OPENFLAGS();
 
        err = access(file, W_OK);
-       if(err && (errno != EACCES))
+       if (err && (errno != EACCES))
                return -errno;
-       else if(!err)
+       else if (!err)
                *mode_out = of_write(*mode_out);
 
        err = access(file, R_OK);
-       if(err && (errno != EACCES))
+       if (err && (errno != EACCES))
                return -errno;
-       else if(!err)
+       else if (!err)
                *mode_out = of_read(*mode_out);
 
        return err;
 }
 
-int os_open_file(char *file, struct openflags flags, int mode)
+int os_open_file(const char *file, struct openflags flags, int mode)
 {
        int fd, err, f = 0;
 
-       if(flags.r && flags.w) f = O_RDWR;
-       else if(flags.r) f = O_RDONLY;
-       else if(flags.w) f = O_WRONLY;
+       if (flags.r && flags.w)
+               f = O_RDWR;
+       else if (flags.r)
+               f = O_RDONLY;
+       else if (flags.w)
+               f = O_WRONLY;
        else f = 0;
 
-       if(flags.s) f |= O_SYNC;
-       if(flags.c) f |= O_CREAT;
-       if(flags.t) f |= O_TRUNC;
-       if(flags.e) f |= O_EXCL;
+       if (flags.s)
+               f |= O_SYNC;
+       if (flags.c)
+               f |= O_CREAT;
+       if (flags.t)
+               f |= O_TRUNC;
+       if (flags.e)
+               f |= O_EXCL;
+       if (flags.a)
+               f |= O_APPEND;
 
        fd = open64(file, f, mode);
-       if(fd < 0)
+       if (fd < 0)
                return -errno;
 
-       if(flags.cl && fcntl(fd, F_SETFD, 1)){
+       if (flags.cl && fcntl(fd, F_SETFD, 1)) {
                err = -errno;
                close(fd);
                return err;
@@ -216,7 +207,7 @@ int os_open_file(char *file, struct openflags flags, int mode)
        return fd;
 }
 
-int os_connect_socket(char *name)
+int os_connect_socket(const char *name)
 {
        struct sockaddr_un sock;
        int fd, err;
@@ -225,13 +216,13 @@ int os_connect_socket(char *name)
        snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name);
 
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
-       if(fd < 0) {
+       if (fd < 0) {
                err = -errno;
                goto out;
        }
 
        err = connect(fd, (struct sockaddr *) &sock, sizeof(sock));
-       if(err) {
+       if (err) {
                err = -errno;
                goto out_close;
        }
@@ -254,7 +245,7 @@ int os_seek_file(int fd, unsigned long long offset)
        unsigned long long actual;
 
        actual = lseek64(fd, offset, SEEK_SET);
-       if(actual != offset)
+       if (actual != offset)
                return -errno;
        return 0;
 }
@@ -263,7 +254,7 @@ int os_read_file(int fd, void *buf, int len)
 {
        int n = read(fd, buf, len);
 
-       if(n < 0)
+       if (n < 0)
                return -errno;
        return n;
 }
@@ -272,37 +263,38 @@ int os_write_file(int fd, const void *buf, int len)
 {
        int n = write(fd, (void *) buf, len);
 
-       if(n < 0)
+       if (n < 0)
                return -errno;
        return n;
 }
 
-int os_file_size(char *file, unsigned long long *size_out)
+int os_file_size(const char *file, unsigned long long *size_out)
 {
        struct uml_stat buf;
        int err;
 
        err = os_stat_file(file, &buf);
-       if(err < 0){
-               printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
+       if (err < 0) {
+               printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file,
+                      -err);
                return err;
        }
 
-       if(S_ISBLK(buf.ust_mode)){
+       if (S_ISBLK(buf.ust_mode)) {
                int fd;
                long blocks;
 
                fd = open(file, O_RDONLY, 0);
-               if(fd < 0) {
+               if (fd < 0) {
                        err = -errno;
-                       printk("Couldn't open \"%s\", errno = %d\n", file,
-                              errno);
+                       printk(UM_KERN_ERR "Couldn't open \"%s\", "
+                              "errno = %d\n", file, errno);
                        return err;
                }
-               if(ioctl(fd, BLKGETSIZE, &blocks) < 0){
+               if (ioctl(fd, BLKGETSIZE, &blocks) < 0) {
                        err = -errno;
-                       printk("Couldn't get the block size of \"%s\", "
-                              "errno = %d\n", file, errno);
+                       printk(UM_KERN_ERR "Couldn't get the block size of "
+                              "\"%s\", errno = %d\n", file, errno);
                        close(fd);
                        return err;
                }
@@ -314,14 +306,15 @@ int os_file_size(char *file, unsigned long long *size_out)
        return 0;
 }
 
-int os_file_modtime(char *file, unsigned long *modtime)
+int os_file_modtime(const char *file, unsigned long *modtime)
 {
        struct uml_stat buf;
        int err;
 
        err = os_stat_file(file, &buf);
-       if(err < 0){
-               printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
+       if (err < 0) {
+               printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file,
+                      -err);
                return err;
        }
 
@@ -329,26 +322,13 @@ int os_file_modtime(char *file, unsigned long *modtime)
        return 0;
 }
 
-int os_get_exec_close(int fd, int *close_on_exec)
-{
-       int ret;
-
-       CATCH_EINTR(ret = fcntl(fd, F_GETFD));
-
-       if(ret < 0)
-               return -errno;
-
-       *close_on_exec = (ret & FD_CLOEXEC) ? 1 : 0;
-       return ret;
-}
-
 int os_set_exec_close(int fd)
 {
        int err;
 
        CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC));
 
-       if(err < 0)
+       if (err < 0)
                return -errno;
        return err;
 }
@@ -358,53 +338,51 @@ int os_pipe(int *fds, int stream, int close_on_exec)
        int err, type = stream ? SOCK_STREAM : SOCK_DGRAM;
 
        err = socketpair(AF_UNIX, type, 0, fds);
-       if(err < 0)
+       if (err < 0)
                return -errno;
 
-       if(!close_on_exec)
+       if (!close_on_exec)
                return 0;
 
        err = os_set_exec_close(fds[0]);
-       if(err < 0)
+       if (err < 0)
                goto error;
 
        err = os_set_exec_close(fds[1]);
-       if(err < 0)
+       if (err < 0)
                goto error;
 
        return 0;
 
  error:
-       printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err);
+       printk(UM_KERN_ERR "os_pipe : Setting FD_CLOEXEC failed, err = %d\n",
+              -err);
        close(fds[1]);
        close(fds[0]);
        return err;
 }
 
-int os_set_fd_async(int fd, int owner)
+int os_set_fd_async(int fd)
 {
-       int err;
+       int err, flags;
+
+       flags = fcntl(fd, F_GETFL);
+       if (flags < 0)
+               return -errno;
 
-       /* XXX This should do F_GETFL first */
-       if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){
+       flags |= O_ASYNC | O_NONBLOCK;
+       if (fcntl(fd, F_SETFL, flags) < 0) {
                err = -errno;
-               printk("os_set_fd_async : failed to set O_ASYNC and "
-                      "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno);
+               printk(UM_KERN_ERR "os_set_fd_async : failed to set O_ASYNC "
+                      "and O_NONBLOCK on fd # %d, errno = %d\n", fd, errno);
                return err;
        }
-#ifdef notdef
-       if(fcntl(fd, F_SETFD, 1) < 0){
-               printk("os_set_fd_async : Setting FD_CLOEXEC failed, "
-                      "errno = %d\n", errno);
-       }
-#endif
 
-       if((fcntl(fd, F_SETSIG, SIGIO) < 0) ||
-          (fcntl(fd, F_SETOWN, owner) < 0)){
+       if ((fcntl(fd, F_SETSIG, SIGIO) < 0) ||
+           (fcntl(fd, F_SETOWN, os_getpid()) < 0)) {
                err = -errno;
-               printk("os_set_fd_async : Failed to fcntl F_SETOWN "
-                      "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd,
-                      owner, errno);
+               printk(UM_KERN_ERR "os_set_fd_async : Failed to fcntl F_SETOWN "
+                      "(or F_SETSIG) fd %d, errno = %d\n", fd, errno);
                return err;
        }
 
@@ -413,10 +391,14 @@ int os_set_fd_async(int fd, int owner)
 
 int os_clear_fd_async(int fd)
 {
-       int flags = fcntl(fd, F_GETFL);
+       int flags;
+
+       flags = fcntl(fd, F_GETFL);
+       if (flags < 0)
+               return -errno;
 
        flags &= ~(O_ASYNC | O_NONBLOCK);
-       if(fcntl(fd, F_SETFL, flags) < 0)
+       if (fcntl(fd, F_SETFL, flags) < 0)
                return -errno;
        return 0;
 }
@@ -426,11 +408,15 @@ int os_set_fd_block(int fd, int blocking)
        int flags;
 
        flags = fcntl(fd, F_GETFL);
+       if (flags < 0)
+               return -errno;
 
-       if(blocking) flags &= ~O_NONBLOCK;
-       else flags |= O_NONBLOCK;
+       if (blocking)
+               flags &= ~O_NONBLOCK;
+       else
+               flags |= O_NONBLOCK;
 
-       if(fcntl(fd, F_SETFL, flags) < 0)
+       if (fcntl(fd, F_SETFL, flags) < 0)
                return -errno;
 
        return 0;
@@ -441,7 +427,7 @@ int os_accept_connection(int fd)
        int new;
 
        new = accept(fd, NULL, 0);
-       if(new < 0)
+       if (new < 0)
                return -errno;
        return new;
 }
@@ -462,15 +448,17 @@ int os_shutdown_socket(int fd, int r, int w)
 {
        int what, err;
 
-       if(r && w) what = SHUT_RDWR;
-       else if(r) what = SHUT_RD;
-       else if(w) what = SHUT_WR;
-       else {
-               printk("os_shutdown_socket : neither r or w was set\n");
+       if (r && w)
+               what = SHUT_RDWR;
+       else if (r)
+               what = SHUT_RD;
+       else if (w)
+               what = SHUT_WR;
+       else
                return -EINVAL;
-       }
+
        err = shutdown(fd, what);
-       if(err < 0)
+       if (err < 0)
                return -errno;
        return 0;
 }
@@ -494,19 +482,20 @@ int os_rcv_fd(int fd, int *helper_pid_out)
        msg.msg_flags = 0;
 
        n = recvmsg(fd, &msg, 0);
-       if(n < 0)
+       if (n < 0)
                return -errno;
-       else if(n != iov.iov_len)
+       else if (n != iov.iov_len)
                *helper_pid_out = -1;
 
        cmsg = CMSG_FIRSTHDR(&msg);
-       if(cmsg == NULL){
-               printk("rcv_fd didn't receive anything, error = %d\n", errno);
+       if (cmsg == NULL) {
+               printk(UM_KERN_ERR "rcv_fd didn't receive anything, "
+                      "error = %d\n", errno);
                return -1;
        }
-       if((cmsg->cmsg_level != SOL_SOCKET) ||
-          (cmsg->cmsg_type != SCM_RIGHTS)){
-               printk("rcv_fd didn't receive a descriptor\n");
+       if ((cmsg->cmsg_level != SOL_SOCKET) ||
+           (cmsg->cmsg_type != SCM_RIGHTS)) {
+               printk(UM_KERN_ERR "rcv_fd didn't receive a descriptor\n");
                return -1;
        }
 
@@ -514,29 +503,28 @@ int os_rcv_fd(int fd, int *helper_pid_out)
        return new;
 }
 
-int os_create_unix_socket(char *file, int len, int close_on_exec)
+int os_create_unix_socket(const char *file, int len, int close_on_exec)
 {
        struct sockaddr_un addr;
        int sock, err;
 
        sock = socket(PF_UNIX, SOCK_DGRAM, 0);
-       if(sock < 0)
+       if (sock < 0)
                return -errno;
 
-       if(close_on_exec) {
+       if (close_on_exec) {
                err = os_set_exec_close(sock);
-               if(err < 0)
-                       printk("create_unix_socket : close_on_exec failed, "
-                      "err = %d", -err);
+               if (err < 0)
+                       printk(UM_KERN_ERR "create_unix_socket : "
+                              "close_on_exec failed, err = %d", -err);
        }
 
        addr.sun_family = AF_UNIX;
 
-       /* XXX Be more careful about overflow */
        snprintf(addr.sun_path, len, "%s", file);
 
        err = bind(sock, (struct sockaddr *) &addr, sizeof(addr));
-       if(err < 0)
+       if (err < 0)
                return -errno;
 
        return sock;
@@ -557,17 +545,18 @@ int os_lock_file(int fd, int excl)
        int err, save;
 
        err = fcntl(fd, F_SETLK, &lock);
-       if(!err)
+       if (!err)
                goto out;
 
        save = -errno;
        err = fcntl(fd, F_GETLK, &lock);
-       if(err){
+       if (err) {
                err = -errno;
                goto out;
        }
 
-       printk("F_SETLK failed, file already locked by pid %d\n", lock.l_pid);
+       printk(UM_KERN_ERR "F_SETLK failed, file already locked by pid %d\n",
+              lock.l_pid);
        err = save;
  out:
        return err;
index fba3f0fefeef7ca78d3edd685f24e8d5d4c254bc..f4bd349d441222fb7c400ac63d8e7b8c390784a2 100644 (file)
@@ -1,22 +1,19 @@
 /*
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sched.h>
-#include <limits.h>
-#include <sys/signal.h>
-#include <sys/wait.h>
 #include <sys/socket.h>
-#include "user.h"
+#include <sys/wait.h>
+#include "kern_constants.h"
 #include "kern_util.h"
 #include "os.h"
 #include "um_malloc.h"
-#include "kern_constants.h"
+#include "user.h"
 
 struct helper_data {
        void (*pre_exec)(void*);
@@ -30,21 +27,19 @@ static int helper_child(void *arg)
 {
        struct helper_data *data = arg;
        char **argv = data->argv;
-       int errval;
+       int err;
 
        if (data->pre_exec != NULL)
                (*data->pre_exec)(data->pre_data);
-       errval = execvp_noalloc(data->buf, argv[0], argv);
-       printk("helper_child - execvp of '%s' failed - errno = %d\n", argv[0],
-              -errval);
-       write(data->fd, &errval, sizeof(errval));
-       kill(os_getpid(), SIGKILL);
+       err = execvp_noalloc(data->buf, argv[0], argv);
+
+       /* If the exec succeeds, we don't get here */
+       write(data->fd, &err, sizeof(err));
+
        return 0;
 }
 
-/* Returns either the pid of the child process we run or -E* on failure.
- * XXX The alloc_stack here breaks if this is called in the tracing thread, so
- * we need to receive a preallocated stack (a local buffer is ok). */
+/* Returns either the pid of the child process we run or -E* on failure. */
 int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
 {
        struct helper_data data;
@@ -58,14 +53,15 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
        ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
        if (ret < 0) {
                ret = -errno;
-               printk("run_helper : pipe failed, errno = %d\n", errno);
+               printk(UM_KERN_ERR "run_helper : pipe failed, errno = %d\n",
+                      errno);
                goto out_free;
        }
 
        ret = os_set_exec_close(fds[1]);
        if (ret < 0) {
-               printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n",
-                      -ret);
+               printk(UM_KERN_ERR "run_helper : setting FD_CLOEXEC failed, "
+                      "ret = %d\n", -ret);
                goto out_close;
        }
 
@@ -79,7 +75,8 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
        pid = clone(helper_child, (void *) sp, CLONE_VM, &data);
        if (pid < 0) {
                ret = -errno;
-               printk("run_helper : clone failed, errno = %d\n", errno);
+               printk(UM_KERN_ERR "run_helper : clone failed, errno = %d\n",
+                      errno);
                goto out_free2;
        }
 
@@ -96,10 +93,9 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
        } else {
                if (n < 0) {
                        n = -errno;
-                       printk("run_helper : read on pipe failed, ret = %d\n",
-                              -n);
+                       printk(UM_KERN_ERR "run_helper : read on pipe failed, "
+                              "ret = %d\n", -n);
                        ret = n;
-                       kill(pid, SIGKILL);
                }
                CATCH_EINTR(waitpid(pid, NULL, __WCLONE));
        }
@@ -129,50 +125,40 @@ int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
        pid = clone(proc, (void *) sp, flags, arg);
        if (pid < 0) {
                err = -errno;
-               printk("run_helper_thread : clone failed, errno = %d\n",
-                      errno);
+               printk(UM_KERN_ERR "run_helper_thread : clone failed, "
+                      "errno = %d\n", errno);
                return err;
        }
        if (stack_out == NULL) {
                CATCH_EINTR(pid = waitpid(pid, &status, __WCLONE));
                if (pid < 0) {
                        err = -errno;
-                       printk("run_helper_thread - wait failed, errno = %d\n",
-                              errno);
+                       printk(UM_KERN_ERR "run_helper_thread - wait failed, "
+                              "errno = %d\n", errno);
                        pid = err;
                }
                if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-                       printk("run_helper_thread - thread returned status "
-                              "0x%x\n", status);
+                       printk(UM_KERN_ERR "run_helper_thread - thread "
+                              "returned status 0x%x\n", status);
                free_stack(stack, 0);
        } else
                *stack_out = stack;
        return pid;
 }
 
-int helper_wait(int pid, int nohang, char *pname)
+int helper_wait(int pid)
 {
        int ret, status;
        int wflags = __WCLONE;
 
-       if (nohang)
-               wflags |= WNOHANG;
-
-       if (!pname)
-               pname = "helper_wait";
-
        CATCH_EINTR(ret = waitpid(pid, &status, wflags));
        if (ret < 0) {
-               printk(UM_KERN_ERR "%s : waitpid process %d failed, "
-                      "errno = %d\n", pname, pid, errno);
+               printk(UM_KERN_ERR "helper_wait : waitpid process %d failed, "
+                      "errno = %d\n", pid, errno);
                return -errno;
-       } else if (nohang && ret == 0) {
-               printk(UM_KERN_ERR "%s : process %d has not exited\n",
-                      pname, pid);
-               return -ECHILD;
        } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
-               printk(UM_KERN_ERR "%s : process %d didn't exit with "
-                      "status 0\n", pname, pid);
+               printk(UM_KERN_ERR "helper_wait : process %d exited with "
+                      "status 0x%x\n", pid, status);
                return -ECHILD;
        } else
                return 0;
index 6aa6f95d652491ab4e1161247febeaa1c91856c1..0348b975e81cb3a5a4d067a8f3b39c5d2db1fff5 100644 (file)
@@ -1,23 +1,19 @@
 /*
- * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
 #include <stdlib.h>
-#include <unistd.h>
 #include <errno.h>
+#include <poll.h>
 #include <signal.h>
 #include <string.h>
-#include <sys/poll.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include "kern_util.h"
-#include "user.h"
-#include "process.h"
-#include "sigio.h"
 #include "irq_user.h"
+#include "kern_constants.h"
 #include "os.h"
+#include "process.h"
 #include "um_malloc.h"
+#include "user.h"
 
 /*
  * Locked by irq_lock in arch/um/kernel/irq.c.  Changed by os_create_pollfd
@@ -36,7 +32,7 @@ int os_waiting_for_events(struct irq_fd *active_fds)
        if (n < 0) {
                err = -errno;
                if (errno != EINTR)
-                       printk("sigio_handler: os_waiting_for_events:"
+                       printk(UM_KERN_ERR "os_waiting_for_events:"
                               " poll returned %d, errno = %d\n", n, errno);
                return err;
        }
@@ -95,24 +91,26 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
                        struct irq_fd *old_fd = *prev;
                        if ((pollfds[i].fd != -1) &&
                            (pollfds[i].fd != (*prev)->fd)) {
-                               printk("os_free_irq_by_cb - mismatch between "
-                                      "active_fds and pollfds, fd %d vs %d\n",
+                               printk(UM_KERN_ERR "os_free_irq_by_cb - "
+                                      "mismatch between active_fds and "
+                                      "pollfds, fd %d vs %d\n",
                                       (*prev)->fd, pollfds[i].fd);
                                goto out;
                        }
 
                        pollfds_num--;
 
-                       /* This moves the *whole* array after pollfds[i]
+                       /*
+                        * This moves the *whole* array after pollfds[i]
                         * (though it doesn't spot as such)!
                         */
                        memmove(&pollfds[i], &pollfds[i + 1],
                               (pollfds_num - i) * sizeof(pollfds[0]));
-                       if(*last_irq_ptr2 == &old_fd->next)
+                       if (*last_irq_ptr2 == &old_fd->next)
                                *last_irq_ptr2 = prev;
 
                        *prev = (*prev)->next;
-                       if(old_fd->type == IRQ_WRITE)
+                       if (old_fd->type == IRQ_WRITE)
                                ignore_sigio_fd(old_fd->fd);
                        kfree(old_fd);
                        continue;
@@ -138,14 +136,3 @@ void os_set_ioignore(void)
 {
        signal(SIGIO, SIG_IGN);
 }
-
-void init_irq_signals(int on_sigstack)
-{
-       int flags;
-
-       flags = on_sigstack ? SA_ONSTACK : 0;
-
-       set_handler(SIGIO, (__sighandler_t) sig_handler, flags | SA_RESTART,
-                   SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1);
-       signal(SIGWINCH, SIG_IGN);
-}
index 82c3778627b8e91e448e969022c7b06e1a2241ab..abb9b0ffd9600402e770d93fce945c9b0295b98b 100644 (file)
@@ -73,7 +73,7 @@ static void install_fatal_handler(int sig)
        action.sa_handler = last_ditch_exit;
        if (sigaction(sig, &action, NULL) < 0) {
                printf("failed to install handler for signal %d - errno = %d\n",
-                      errno);
+                      sig, errno);
                exit(1);
        }
 }
@@ -92,7 +92,8 @@ static void setup_env_path(void)
         * just use the default + /usr/lib/uml
         */
        if (!old_path || (path_len = strlen(old_path)) == 0) {
-               putenv("PATH=:/bin:/usr/bin/" UML_LIB_PATH);
+               if (putenv("PATH=:/bin:/usr/bin/" UML_LIB_PATH))
+                       perror("couldn't putenv");
                return;
        }
 
@@ -100,15 +101,16 @@ static void setup_env_path(void)
        path_len += strlen("PATH=" UML_LIB_PATH) + 1;
        new_path = malloc(path_len);
        if (!new_path) {
-               perror("coudn't malloc to set a new PATH");
+               perror("couldn't malloc to set a new PATH");
                return;
        }
        snprintf(new_path, path_len, "PATH=%s" UML_LIB_PATH, old_path);
-       putenv(new_path);
+       if (putenv(new_path)) {
+               perror("couldn't putenv to set a new PATH");
+               free(new_path);
+       }
 }
 
-extern int uml_exitcode;
-
 extern void scan_elf_aux( char **envp);
 
 int __init main(int argc, char **argv, char **envp)
index 436f8d20b20f64de342c3b4a4c2fdef2d92dab2f..eedc2d88ef8a5a3d6b00e87e88a8a05e7c77ab89 100644 (file)
@@ -9,7 +9,6 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/statfs.h>
-#include "kern_util.h"
 #include "user.h"
 #include "mem_user.h"
 #include "init.h"
@@ -30,7 +29,7 @@ static char *tempdir = NULL;
 
 static void __init find_tempdir(void)
 {
-       char *dirs[] = { "TMP", "TEMP", "TMPDIR", NULL };
+       const char *dirs[] = { "TMP", "TEMP", "TMPDIR", NULL };
        int i;
        char *dir = NULL;
 
@@ -59,9 +58,10 @@ static void __init find_tempdir(void)
  * read the file as needed.  If there's an error, -errno is returned;
  * if the end of the file is reached, 0 is returned.
  */
-static int next(int fd, char *buf, int size, char c)
+static int next(int fd, char *buf, size_t size, char c)
 {
-       int n, len;
+       ssize_t n;
+       size_t len;
        char *ptr;
 
        while((ptr = strchr(buf, c)) == NULL){
@@ -172,13 +172,15 @@ int __init make_tempfile(const char *template, char **out_tempname,
 
        which_tmpdir();
        tempname = malloc(MAXPATHLEN);
+       if (!tempname)
+               goto out;
 
        find_tempdir();
        if (template[0] != '/')
                strcpy(tempname, tempdir);
        else
                tempname[0] = '\0';
-       strcat(tempname, template);
+       strncat(tempname, template, MAXPATHLEN-1-strlen(tempname));
        fd = mkstemp(tempname);
        if(fd < 0){
                fprintf(stderr, "open - cannot create %s: %s\n", tempname,
@@ -268,6 +270,7 @@ void __init check_tmpexec(void)
        if(addr == MAP_FAILED){
                err = errno;
                perror("failed");
+               close(fd);
                if(err == EPERM)
                        printf("%s must be not mounted noexec\n",tempdir);
                exit(1);
index bda5c3150d6c798254dd974e7780286971c8f6d7..abf6beae3df1bec14f60943754e54ba9e4d32f16 100644 (file)
@@ -249,7 +249,10 @@ void init_new_thread_signals(void)
                    SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1);
        signal(SIGHUP, SIG_IGN);
 
-       init_irq_signals(1);
+       set_handler(SIGIO, (__sighandler_t) sig_handler,
+                   SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGALRM,
+                   SIGVTALRM, -1);
+       signal(SIGWINCH, SIG_IGN);
 }
 
 int run_kernel_thread(int (*fn)(void *), void *arg, jmp_buf **jmp_ptr)
index a32ba6ab12112e3c6379d55588e538560512fb28..830fe6a1518ae71dfa4deef46727b6fd367fbb18 100644 (file)
@@ -8,47 +8,41 @@
 #include <string.h>
 #include <sys/ptrace.h>
 #include "sysdep/ptrace.h"
-#include "user.h"
 
-/* This is set once at boot time and not changed thereafter */
-
-static unsigned long exec_regs[MAX_REG_NR];
-
-void init_thread_registers(struct uml_pt_regs *to)
-{
-       memcpy(to->gp, exec_regs, sizeof(to->gp));
-}
-
-void save_registers(int pid, struct uml_pt_regs *regs)
+int save_registers(int pid, struct uml_pt_regs *regs)
 {
        int err;
 
        err = ptrace(PTRACE_GETREGS, pid, 0, regs->gp);
        if (err < 0)
-               panic("save_registers - saving registers failed, errno = %d\n",
-                     errno);
+               return -errno;
+       return 0;
 }
 
-void restore_registers(int pid, struct uml_pt_regs *regs)
+int restore_registers(int pid, struct uml_pt_regs *regs)
 {
        int err;
 
        err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp);
        if (err < 0)
-               panic("restore_registers - saving registers failed, "
-                     "errno = %d\n", errno);
+               return -errno;
+       return 0;
 }
 
-void init_registers(int pid)
+/* This is set once at boot time and not changed thereafter */
+
+static unsigned long exec_regs[MAX_REG_NR];
+
+int init_registers(int pid)
 {
        int err;
 
        err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
-       if (err)
-               panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
-                     errno);
+       if (err < 0)
+               return -errno;
 
        arch_init_registers(pid);
+       return 0;
 }
 
 void get_safe_registers(unsigned long *regs)
index dc03e9cccb630146c0d62504d5ff4ea5e2c14b50..abf47a7c4abd795c039f4c98136163819adb92a4 100644 (file)
@@ -1,34 +1,33 @@
 /*
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
 #include <unistd.h>
-#include <stdlib.h>
-#include <termios.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
 #include <pty.h>
+#include <sched.h>
 #include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
 #include <string.h>
-#include <sched.h>
-#include <sys/socket.h>
-#include <sys/poll.h>
-#include "init.h"
-#include "user.h"
+#include "kern_constants.h"
 #include "kern_util.h"
-#include "sigio.h"
+#include "init.h"
 #include "os.h"
+#include "sigio.h"
 #include "um_malloc.h"
-#include "init.h"
+#include "user.h"
 
-/* Protected by sigio_lock(), also used by sigio_cleanup, which is an
+/*
+ * Protected by sigio_lock(), also used by sigio_cleanup, which is an
  * exitcall.
  */
 static int write_sigio_pid = -1;
 static unsigned long write_sigio_stack;
 
-/* These arrays are initialized before the sigio thread is started, and
+/*
+ * These arrays are initialized before the sigio thread is started, and
  * the descriptors closed after it is killed.  So, it can't see them change.
  * On the UML side, they are changed under the sigio_lock.
  */
@@ -43,7 +42,8 @@ struct pollfds {
        int used;
 };
 
-/* Protected by sigio_lock().  Used by the sigio thread, but the UML thread
+/*
+ * Protected by sigio_lock().  Used by the sigio thread, but the UML thread
  * synchronizes with it.
  */
 static struct pollfds current_poll;
@@ -57,23 +57,26 @@ static int write_sigio_thread(void *unused)
        int i, n, respond_fd;
        char c;
 
-        signal(SIGWINCH, SIG_IGN);
+       signal(SIGWINCH, SIG_IGN);
        fds = &current_poll;
-       while(1){
+       while (1) {
                n = poll(fds->poll, fds->used, -1);
-               if(n < 0){
-                       if(errno == EINTR) continue;
-                       printk("write_sigio_thread : poll returned %d, "
-                              "errno = %d\n", n, errno);
+               if (n < 0) {
+                       if (errno == EINTR)
+                               continue;
+                       printk(UM_KERN_ERR "write_sigio_thread : poll returned "
+                              "%d, errno = %d\n", n, errno);
                }
-               for(i = 0; i < fds->used; i++){
+               for (i = 0; i < fds->used; i++) {
                        p = &fds->poll[i];
-                       if(p->revents == 0) continue;
-                       if(p->fd == sigio_private[1]){
+                       if (p->revents == 0)
+                               continue;
+                       if (p->fd == sigio_private[1]) {
                                CATCH_EINTR(n = read(sigio_private[1], &c,
                                                     sizeof(c)));
-                               if(n != sizeof(c))
-                                       printk("write_sigio_thread : "
+                               if (n != sizeof(c))
+                                       printk(UM_KERN_ERR
+                                              "write_sigio_thread : "
                                               "read on socket failed, "
                                               "err = %d\n", errno);
                                tmp = current_poll;
@@ -89,9 +92,10 @@ static int write_sigio_thread(void *unused)
                        }
 
                        CATCH_EINTR(n = write(respond_fd, &c, sizeof(c)));
-                       if(n != sizeof(c))
-                               printk("write_sigio_thread : write on socket "
-                                      "failed, err = %d\n", errno);
+                       if (n != sizeof(c))
+                               printk(UM_KERN_ERR "write_sigio_thread : "
+                                      "write on socket failed, err = %d\n",
+                                      errno);
                }
        }
 
@@ -102,12 +106,13 @@ static int need_poll(struct pollfds *polls, int n)
 {
        struct pollfd *new;
 
-       if(n <= polls->size)
+       if (n <= polls->size)
                return 0;
 
        new = kmalloc(n * sizeof(struct pollfd), UM_GFP_ATOMIC);
-       if(new == NULL){
-               printk("need_poll : failed to allocate new pollfds\n");
+       if (new == NULL) {
+               printk(UM_KERN_ERR "need_poll : failed to allocate new "
+                      "pollfds\n");
                return -ENOMEM;
        }
 
@@ -119,7 +124,8 @@ static int need_poll(struct pollfds *polls, int n)
        return 0;
 }
 
-/* Must be called with sigio_lock held, because it's needed by the marked
+/*
+ * Must be called with sigio_lock held, because it's needed by the marked
  * critical section.
  */
 static void update_thread(void)
@@ -129,15 +135,17 @@ static void update_thread(void)
        char c;
 
        flags = set_signals(0);
-       n = write(sigio_private[0], &c, sizeof(c));
-       if(n != sizeof(c)){
-               printk("update_thread : write failed, err = %d\n", errno);
+       CATCH_EINTR(n = write(sigio_private[0], &c, sizeof(c)));
+       if (n != sizeof(c)) {
+               printk(UM_KERN_ERR "update_thread : write failed, err = %d\n",
+                      errno);
                goto fail;
        }
 
        CATCH_EINTR(n = read(sigio_private[0], &c, sizeof(c)));
-       if(n != sizeof(c)){
-               printk("update_thread : read failed, err = %d\n", errno);
+       if (n != sizeof(c)) {
+               printk(UM_KERN_ERR "update_thread : read failed, err = %d\n",
+                      errno);
                goto fail;
        }
 
@@ -164,23 +172,23 @@ int add_sigio_fd(int fd)
        int err = 0, i, n;
 
        sigio_lock();
-       for(i = 0; i < all_sigio_fds.used; i++){
-               if(all_sigio_fds.poll[i].fd == fd)
+       for (i = 0; i < all_sigio_fds.used; i++) {
+               if (all_sigio_fds.poll[i].fd == fd)
                        break;
        }
-       if(i == all_sigio_fds.used)
+       if (i == all_sigio_fds.used)
                goto out;
 
        p = &all_sigio_fds.poll[i];
 
-       for(i = 0; i < current_poll.used; i++){
-               if(current_poll.poll[i].fd == fd)
+       for (i = 0; i < current_poll.used; i++) {
+               if (current_poll.poll[i].fd == fd)
                        goto out;
        }
 
        n = current_poll.used;
        err = need_poll(&next_poll, n + 1);
-       if(err)
+       if (err)
                goto out;
 
        memcpy(next_poll.poll, current_poll.poll,
@@ -198,27 +206,29 @@ int ignore_sigio_fd(int fd)
        struct pollfd *p;
        int err = 0, i, n = 0;
 
-       /* This is called from exitcalls elsewhere in UML - if
+       /*
+        * This is called from exitcalls elsewhere in UML - if
         * sigio_cleanup has already run, then update_thread will hang
         * or fail because the thread is no longer running.
         */
-       if(write_sigio_pid == -1)
+       if (write_sigio_pid == -1)
                return -EIO;
 
        sigio_lock();
-       for(i = 0; i < current_poll.used; i++){
-               if(current_poll.poll[i].fd == fd) break;
+       for (i = 0; i < current_poll.used; i++) {
+               if (current_poll.poll[i].fd == fd)
+                       break;
        }
-       if(i == current_poll.used)
+       if (i == current_poll.used)
                goto out;
 
        err = need_poll(&next_poll, current_poll.used - 1);
-       if(err)
+       if (err)
                goto out;
 
-       for(i = 0; i < current_poll.used; i++){
+       for (i = 0; i < current_poll.used; i++) {
                p = &current_poll.poll[i];
-               if(p->fd != fd)
+               if (p->fd != fd)
                        next_poll.poll[n++] = *p;
        }
        next_poll.used = current_poll.used - 1;
@@ -235,7 +245,8 @@ static struct pollfd *setup_initial_poll(int fd)
 
        p = kmalloc(sizeof(struct pollfd), UM_GFP_KERNEL);
        if (p == NULL) {
-               printk("setup_initial_poll : failed to allocate poll\n");
+               printk(UM_KERN_ERR "setup_initial_poll : failed to allocate "
+                      "poll\n");
                return NULL;
        }
        *p = ((struct pollfd) { .fd             = fd,
@@ -261,27 +272,29 @@ static void write_sigio_workaround(void)
                return;
 
        err = os_pipe(l_write_sigio_fds, 1, 1);
-       if(err < 0){
-               printk("write_sigio_workaround - os_pipe 1 failed, "
+       if (err < 0) {
+               printk(UM_KERN_ERR "write_sigio_workaround - os_pipe 1 failed, "
                       "err = %d\n", -err);
                return;
        }
        err = os_pipe(l_sigio_private, 1, 1);
-       if(err < 0){
-               printk("write_sigio_workaround - os_pipe 2 failed, "
+       if (err < 0) {
+               printk(UM_KERN_ERR "write_sigio_workaround - os_pipe 2 failed, "
                       "err = %d\n", -err);
                goto out_close1;
        }
 
        p = setup_initial_poll(l_sigio_private[1]);
-       if(!p)
+       if (!p)
                goto out_close2;
 
        sigio_lock();
 
-       /* Did we race? Don't try to optimize this, please, it's not so likely
-        * to happen, and no more than once at the boot. */
-       if(write_sigio_pid != -1)
+       /*
+        * Did we race? Don't try to optimize this, please, it's not so likely
+        * to happen, and no more than once at the boot.
+        */
+       if (write_sigio_pid != -1)
                goto out_free;
 
        current_poll = ((struct pollfds) { .poll        = p,
@@ -333,19 +346,19 @@ void maybe_sigio_broken(int fd, int read)
 {
        int err;
 
-       if(!isatty(fd))
+       if (!isatty(fd))
                return;
 
-       if((read || pty_output_sigio) && (!read || pty_close_sigio))
+       if ((read || pty_output_sigio) && (!read || pty_close_sigio))
                return;
 
        write_sigio_workaround();
 
        sigio_lock();
        err = need_poll(&all_sigio_fds, all_sigio_fds.used + 1);
-       if(err){
-               printk("maybe_sigio_broken - failed to add pollfd for "
-                      "descriptor %d\n", fd);
+       if (err) {
+               printk(UM_KERN_ERR "maybe_sigio_broken - failed to add pollfd "
+                      "for descriptor %d\n", fd);
                goto out;
        }
 
@@ -388,7 +401,7 @@ static void openpty_cb(void *arg)
        struct openpty_arg *info = arg;
 
        info->err = 0;
-       if(openpty(&info->master, &info->slave, NULL, NULL, NULL))
+       if (openpty(&info->master, &info->slave, NULL, NULL, NULL))
                info->err = -errno;
 }
 
@@ -397,17 +410,17 @@ static int async_pty(int master, int slave)
        int flags;
 
        flags = fcntl(master, F_GETFL);
-       if(flags < 0)
+       if (flags < 0)
                return -errno;
 
-       if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) ||
-          (fcntl(master, F_SETOWN, os_getpid()) < 0))
+       if ((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) ||
+           (fcntl(master, F_SETOWN, os_getpid()) < 0))
                return -errno;
 
-       if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0))
+       if ((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0))
                return -errno;
 
-       return(0);
+       return 0;
 }
 
 static void __init check_one_sigio(void (*proc)(int, int))
@@ -417,34 +430,49 @@ static void __init check_one_sigio(void (*proc)(int, int))
        int master, slave, err;
 
        initial_thread_cb(openpty_cb, &pty);
-       if(pty.err){
-               printk("openpty failed, errno = %d\n", -pty.err);
+       if (pty.err) {
+               printk(UM_KERN_ERR "check_one_sigio failed, errno = %d\n",
+                      -pty.err);
                return;
        }
 
        master = pty.master;
        slave = pty.slave;
 
-       if((master == -1) || (slave == -1)){
-               printk("openpty failed to allocate a pty\n");
+       if ((master == -1) || (slave == -1)) {
+               printk(UM_KERN_ERR "check_one_sigio failed to allocate a "
+                      "pty\n");
                return;
        }
 
        /* Not now, but complain so we now where we failed. */
        err = raw(master);
-       if (err < 0)
-               panic("check_sigio : __raw failed, errno = %d\n", -err);
+       if (err < 0) {
+               printk(UM_KERN_ERR "check_one_sigio : raw failed, errno = %d\n",
+                     -err);
+               return;
+       }
 
        err = async_pty(master, slave);
-       if(err < 0)
-               panic("tty_fds : sigio_async failed, err = %d\n", -err);
+       if (err < 0) {
+               printk(UM_KERN_ERR "check_one_sigio : sigio_async failed, "
+                      "err = %d\n", -err);
+               return;
+       }
+
+       if (sigaction(SIGIO, NULL, &old) < 0) {
+               printk(UM_KERN_ERR "check_one_sigio : sigaction 1 failed, "
+                      "errno = %d\n", errno);
+               return;
+       }
 
-       if(sigaction(SIGIO, NULL, &old) < 0)
-               panic("check_sigio : sigaction 1 failed, errno = %d\n", errno);
        new = old;
        new.sa_handler = handler;
-       if(sigaction(SIGIO, &new, NULL) < 0)
-               panic("check_sigio : sigaction 2 failed, errno = %d\n", errno);
+       if (sigaction(SIGIO, &new, NULL) < 0) {
+               printk(UM_KERN_ERR "check_one_sigio : sigaction 2 failed, "
+                      "errno = %d\n", errno);
+               return;
+       }
 
        got_sigio = 0;
        (*proc)(master, slave);
@@ -452,8 +480,9 @@ static void __init check_one_sigio(void (*proc)(int, int))
        close(master);
        close(slave);
 
-       if(sigaction(SIGIO, &old, NULL) < 0)
-               panic("check_sigio : sigaction 3 failed, errno = %d\n", errno);
+       if (sigaction(SIGIO, &old, NULL) < 0)
+               printk(UM_KERN_ERR "check_one_sigio : sigaction 3 failed, "
+                      "errno = %d\n", errno);
 }
 
 static void tty_output(int master, int slave)
@@ -461,42 +490,45 @@ static void tty_output(int master, int slave)
        int n;
        char buf[512];
 
-       printk("Checking that host ptys support output SIGIO...");
+       printk(UM_KERN_INFO "Checking that host ptys support output SIGIO...");
 
        memset(buf, 0, sizeof(buf));
 
-       while(write(master, buf, sizeof(buf)) > 0) ;
-       if(errno != EAGAIN)
-               panic("tty_output : write failed, errno = %d\n", errno);
-       while(((n = read(slave, buf, sizeof(buf))) > 0) && !got_sigio) ;
+       while (write(master, buf, sizeof(buf)) > 0) ;
+       if (errno != EAGAIN)
+               printk(UM_KERN_ERR "tty_output : write failed, errno = %d\n",
+                      errno);
+       while (((n = read(slave, buf, sizeof(buf))) > 0) && !got_sigio)
+               ;
 
-       if(got_sigio){
-               printk("Yes\n");
+       if (got_sigio) {
+               printk(UM_KERN_CONT "Yes\n");
                pty_output_sigio = 1;
-       }
-       else if(n == -EAGAIN)
-               printk("No, enabling workaround\n");
-       else panic("tty_output : read failed, err = %d\n", n);
+       } else if (n == -EAGAIN)
+               printk(UM_KERN_CONT "No, enabling workaround\n");
+       else
+               printk(UM_KERN_CONT "tty_output : read failed, err = %d\n", n);
 }
 
 static void tty_close(int master, int slave)
 {
-       printk("Checking that host ptys support SIGIO on close...");
+       printk(UM_KERN_INFO "Checking that host ptys support SIGIO on "
+              "close...");
 
        close(slave);
-       if(got_sigio){
-               printk("Yes\n");
+       if (got_sigio) {
+               printk(UM_KERN_CONT "Yes\n");
                pty_close_sigio = 1;
-       }
-       else printk("No, enabling workaround\n");
+       } else
+               printk(UM_KERN_CONT "No, enabling workaround\n");
 }
 
 void __init check_sigio(void)
 {
-       if((os_access("/dev/ptmx", OS_ACC_R_OK) < 0) &&
-          (os_access("/dev/ptyp0", OS_ACC_R_OK) < 0)){
-               printk("No pseudo-terminals available - skipping pty SIGIO "
-                      "check\n");
+       if ((access("/dev/ptmx", R_OK) < 0) &&
+           (access("/dev/ptyp0", R_OK) < 0)) {
+               printk(UM_KERN_WARNING "No pseudo-terminals available - "
+                      "skipping pty SIGIO check\n");
                return;
        }
        check_one_sigio(tty_output);
index e9800b0b5689b6abc750606ab886826709964e56..0fb0cc8d47577c34d842a25a75f2e477dfc6d2c3 100644 (file)
@@ -9,11 +9,47 @@
 #include <errno.h>
 #include <signal.h>
 #include <strings.h>
+#include "as-layout.h"
+#include "kern_util.h"
 #include "os.h"
 #include "sysdep/barrier.h"
 #include "sysdep/sigcontext.h"
 #include "user.h"
 
+/* Copied from linux/compiler-gcc.h since we can't include it directly */
+#define barrier() __asm__ __volatile__("": : :"memory")
+
+void (*sig_info[NSIG])(int, struct uml_pt_regs *) = {
+       [SIGTRAP]       = relay_signal,
+       [SIGFPE]        = relay_signal,
+       [SIGILL]        = relay_signal,
+       [SIGWINCH]      = winch,
+       [SIGBUS]        = bus_handler,
+       [SIGSEGV]       = segv_handler,
+       [SIGIO]         = sigio_handler,
+       [SIGVTALRM]     = timer_handler };
+
+static void sig_handler_common(int sig, struct sigcontext *sc)
+{
+       struct uml_pt_regs r;
+       int save_errno = errno;
+
+       r.is_user = 0;
+       if (sig == SIGSEGV) {
+               /* For segfaults, we want the data from the sigcontext. */
+               copy_sc(&r, sc);
+               GET_FAULTINFO_FROM_SC(r.faultinfo, sc);
+       }
+
+       /* enable signals if sig isn't IRQ signal */
+       if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGVTALRM))
+               unblock_signals();
+
+       (*sig_info[sig])(sig, &r);
+
+       errno = save_errno;
+}
+
 /*
  * These are the asynchronous signals.  SIGPROF is excluded because we want to
  * be able to profile all of UML, not just the non-critical sections.  If
 #define SIGVTALRM_BIT 1
 #define SIGVTALRM_MASK (1 << SIGVTALRM_BIT)
 
-/*
- * These are used by both the signal handlers and
- * block/unblock_signals.  I don't want modifications cached in a
- * register - they must go straight to memory.
- */
-static volatile int signals_enabled = 1;
-static volatile int pending = 0;
+static int signals_enabled;
+static unsigned int signals_pending;
 
 void sig_handler(int sig, struct sigcontext *sc)
 {
@@ -40,13 +71,13 @@ void sig_handler(int sig, struct sigcontext *sc)
 
        enabled = signals_enabled;
        if (!enabled && (sig == SIGIO)) {
-               pending |= SIGIO_MASK;
+               signals_pending |= SIGIO_MASK;
                return;
        }
 
        block_signals();
 
-       sig_handler_common_skas(sig, sc);
+       sig_handler_common(sig, sc);
 
        set_signals(enabled);
 }
@@ -68,7 +99,7 @@ void alarm_handler(int sig, struct sigcontext *sc)
 
        enabled = signals_enabled;
        if (!signals_enabled) {
-               pending |= SIGVTALRM_MASK;
+               signals_pending |= SIGVTALRM_MASK;
                return;
        }
 
@@ -94,16 +125,6 @@ void set_sigstack(void *sig_stack, int size)
                panic("enabling signal stack failed, errno = %d\n", errno);
 }
 
-void remove_sigstack(void)
-{
-       stack_t stack = ((stack_t) { .ss_flags  = SS_DISABLE,
-                                    .ss_sp     = NULL,
-                                    .ss_size   = 0 });
-
-       if (sigaltstack(&stack, NULL) != 0)
-               panic("disabling signal stack failed, errno = %d\n", errno);
-}
-
 void (*handlers[_NSIG])(int sig, struct sigcontext *sc);
 
 void handle_signal(int sig, struct sigcontext *sc)
@@ -166,6 +187,9 @@ void set_handler(int sig, void (*handler)(int), int flags, ...)
                sigaddset(&action.sa_mask, mask);
        va_end(ap);
 
+       if (sig == SIGSEGV)
+               flags |= SA_NODEFER;
+
        action.sa_flags = flags;
        action.sa_restorer = NULL;
        if (sigaction(sig, &action, NULL) < 0)
@@ -179,12 +203,14 @@ void set_handler(int sig, void (*handler)(int), int flags, ...)
 
 int change_sig(int signal, int on)
 {
-       sigset_t sigset, old;
+       sigset_t sigset;
 
        sigemptyset(&sigset);
        sigaddset(&sigset, signal);
-       sigprocmask(on ? SIG_UNBLOCK : SIG_BLOCK, &sigset, &old);
-       return !sigismember(&old, signal);
+       if (sigprocmask(on ? SIG_UNBLOCK : SIG_BLOCK, &sigset, NULL) < 0)
+               return -errno;
+
+       return 0;
 }
 
 void block_signals(void)
@@ -196,7 +222,7 @@ void block_signals(void)
         * This might matter if gcc figures out how to inline this and
         * decides to shuffle this code into the caller.
         */
-       mb();
+       barrier();
 }
 
 void unblock_signals(void)
@@ -209,36 +235,26 @@ void unblock_signals(void)
        /*
         * We loop because the IRQ handler returns with interrupts off.  So,
         * interrupts may have arrived and we need to re-enable them and
-        * recheck pending.
+        * recheck signals_pending.
         */
        while(1) {
                /*
                 * Save and reset save_pending after enabling signals.  This
-                * way, pending won't be changed while we're reading it.
+                * way, signals_pending won't be changed while we're reading it.
                 */
                signals_enabled = 1;
 
                /*
-                * Setting signals_enabled and reading pending must
+                * Setting signals_enabled and reading signals_pending must
                 * happen in this order.
                 */
-               mb();
-
-               save_pending = pending;
-               if (save_pending == 0) {
-                       /*
-                        * This must return with signals enabled, so
-                        * this barrier ensures that writes are
-                        * flushed out before the return.  This might
-                        * matter if gcc figures out how to inline
-                        * this (unlikely, given its size) and decides
-                        * to shuffle this code into the caller.
-                        */
-                       mb();
+               barrier();
+
+               save_pending = signals_pending;
+               if (save_pending == 0)
                        return;
-               }
 
-               pending = 0;
+               signals_pending = 0;
 
                /*
                 * We have pending interrupts, so disable signals, as the
@@ -254,7 +270,7 @@ void unblock_signals(void)
                 * back here.
                 */
                if (save_pending & SIGIO_MASK)
-                       sig_handler_common_skas(SIGIO, NULL);
+                       sig_handler_common(SIGIO, NULL);
 
                if (save_pending & SIGVTALRM_MASK)
                        real_alarm_handler(NULL);
index 5fd8d4dad66a123501d9aff333d9bef809bba881..d2ea3409e072e9818c3f643aa4b312caf351861d 100644 (file)
@@ -1,10 +1,10 @@
 #
-# Copyright (C) 2002 - 2004 Jeff Dike (jdike@addtoit.com)
+# Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
 # Licensed under the GPL
 #
 
-obj-y := mem.o process.o trap.o
+obj-y := mem.o process.o
 
-USER_OBJS := mem.o process.o trap.o
+USER_OBJS := $(obj-y)
 
 include arch/um/scripts/Makefile.rules
index e8b7a97e83d3eb8d75785b6a44e29492ae81efcf..d36c89c24a45c5df05a652f88dc26901577bb19b 100644 (file)
@@ -15,6 +15,7 @@
 #include "as-layout.h"
 #include "chan_user.h"
 #include "kern_constants.h"
+#include "kern_util.h"
 #include "mem.h"
 #include "os.h"
 #include "process.h"
@@ -37,27 +38,27 @@ int is_skas_winch(int pid, int fd, void *data)
 
 static int ptrace_dump_regs(int pid)
 {
-        unsigned long regs[MAX_REG_NR];
-        int i;
+       unsigned long regs[MAX_REG_NR];
+       int i;
 
-        if (ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
-                return -errno;
+       if (ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
+               return -errno;
 
        printk(UM_KERN_ERR "Stub registers -\n");
        for (i = 0; i < ARRAY_SIZE(regs); i++)
                printk(UM_KERN_ERR "\t%d - %lx\n", i, regs[i]);
 
-        return 0;
+       return 0;
 }
 
 /*
  * Signals that are OK to receive in the stub - we'll just continue it.
  * SIGWINCH will happen when UML is inside a detached screen.
  */
-#define STUB_SIG_MASK ((1 << SIGVTALRM) | (1 << SIGWINCH))
+#define STUB_SIG_MASK (1 << SIGVTALRM)
 
 /* Signals that the stub will finish with - anything else is an error */
-#define STUB_DONE_MASK ((1 << SIGUSR1) | (1 << SIGTRAP))
+#define STUB_DONE_MASK (1 << SIGTRAP)
 
 void wait_stub_done(int pid)
 {
@@ -72,9 +73,11 @@ void wait_stub_done(int pid)
                        break;
 
                err = ptrace(PTRACE_CONT, pid, 0, 0);
-               if (err)
-                       panic("wait_stub_done : continue failed, errno = %d\n",
-                             errno);
+               if (err) {
+                       printk(UM_KERN_ERR "wait_stub_done : continue failed, "
+                              "errno = %d\n", errno);
+                       fatal_sigsegv();
+               }
        }
 
        if (((1 << WSTOPSIG(status)) & STUB_DONE_MASK) != 0)
@@ -85,8 +88,10 @@ bad_wait:
        if (err)
                printk(UM_KERN_ERR "Failed to get registers from stub, "
                       "errno = %d\n", -err);
-       panic("wait_stub_done : failed to wait for SIGUSR1/SIGTRAP, pid = %d, "
-             "n = %d, errno = %d, status = 0x%x\n", pid, n, errno, status);
+       printk(UM_KERN_ERR "wait_stub_done : failed to wait for SIGTRAP, "
+              "pid = %d, n = %d, errno = %d, status = 0x%x\n", pid, n, errno,
+              status);
+       fatal_sigsegv();
 }
 
 extern unsigned long current_stub_stack(void);
@@ -97,9 +102,11 @@ void get_skas_faultinfo(int pid, struct faultinfo * fi)
 
        if (ptrace_faultinfo) {
                err = ptrace(PTRACE_FAULTINFO, pid, 0, fi);
-               if (err)
-                       panic("get_skas_faultinfo - PTRACE_FAULTINFO failed, "
-                             "errno = %d\n", errno);
+               if (err) {
+                       printk(UM_KERN_ERR "get_skas_faultinfo - "
+                              "PTRACE_FAULTINFO failed, errno = %d\n", errno);
+                       fatal_sigsegv();
+               }
 
                /* Special handling for i386, which has different structs */
                if (sizeof(struct ptrace_faultinfo) < sizeof(struct faultinfo))
@@ -109,9 +116,11 @@ void get_skas_faultinfo(int pid, struct faultinfo * fi)
        }
        else {
                err = ptrace(PTRACE_CONT, pid, 0, SIGSEGV);
-               if (err)
-                       panic("Failed to continue stub, pid = %d, errno = %d\n",
-                             pid, errno);
+               if (err) {
+                       printk(UM_KERN_ERR "Failed to continue stub, pid = %d, "
+                              "errno = %d\n", pid, errno);
+                       fatal_sigsegv();
+               }
                wait_stub_done(pid);
 
                /*
@@ -137,6 +146,9 @@ static void handle_trap(int pid, struct uml_pt_regs *regs,
 {
        int err, status;
 
+       if ((UPT_IP(regs) >= STUB_START) && (UPT_IP(regs) < STUB_END))
+               fatal_sigsegv();
+
        /* Mark this as a syscall */
        UPT_SYSCALL_NR(regs) = PT_SYSCALL_NR(regs->gp);
 
@@ -144,25 +156,31 @@ static void handle_trap(int pid, struct uml_pt_regs *regs,
        {
                err = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET,
                             __NR_getpid);
-               if (err < 0)
-                       panic("handle_trap - nullifying syscall failed, "
-                             "errno = %d\n", errno);
+               if (err < 0) {
+                       printk(UM_KERN_ERR "handle_trap - nullifying syscall "
+                              "failed, errno = %d\n", errno);
+                       fatal_sigsegv();
+               }
 
                err = ptrace(PTRACE_SYSCALL, pid, 0, 0);
-               if (err < 0)
-                       panic("handle_trap - continuing to end of syscall "
-                             "failed, errno = %d\n", errno);
+               if (err < 0) {
+                       printk(UM_KERN_ERR "handle_trap - continuing to end of "
+                              "syscall failed, errno = %d\n", errno);
+                       fatal_sigsegv();
+               }
 
                CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED | __WALL));
                if ((err < 0) || !WIFSTOPPED(status) ||
-                  (WSTOPSIG(status) != SIGTRAP + 0x80)) {
-                        err = ptrace_dump_regs(pid);
-                        if (err)
-                                printk(UM_KERN_ERR "Failed to get registers "
+                   (WSTOPSIG(status) != SIGTRAP + 0x80)) {
+                       err = ptrace_dump_regs(pid);
+                       if (err)
+                               printk(UM_KERN_ERR "Failed to get registers "
                                       "from process, errno = %d\n", -err);
-                       panic("handle_trap - failed to wait at end of syscall, "
-                             "errno = %d, status = %d\n", errno, status);
-                }
+                       printk(UM_KERN_ERR "handle_trap - failed to wait at "
+                              "end of syscall, errno = %d, status = %d\n",
+                              errno, status);
+                       fatal_sigsegv();
+               }
        }
 
        handle_syscall(regs);
@@ -178,10 +196,13 @@ static int userspace_tramp(void *stack)
        ptrace(PTRACE_TRACEME, 0, 0, 0);
 
        signal(SIGTERM, SIG_DFL);
+       signal(SIGWINCH, SIG_IGN);
        err = set_interval();
-       if (err)
-               panic("userspace_tramp - setting timer failed, errno = %d\n",
-                     err);
+       if (err) {
+               printk(UM_KERN_ERR "userspace_tramp - setting timer failed, "
+                      "errno = %d\n", err);
+               exit(1);
+       }
 
        if (!proc_mm) {
                /*
@@ -221,16 +242,14 @@ static int userspace_tramp(void *stack)
 
                set_sigstack((void *) STUB_DATA, UM_KERN_PAGE_SIZE);
                sigemptyset(&sa.sa_mask);
-               sigaddset(&sa.sa_mask, SIGIO);
-               sigaddset(&sa.sa_mask, SIGWINCH);
-               sigaddset(&sa.sa_mask, SIGVTALRM);
-               sigaddset(&sa.sa_mask, SIGUSR1);
-               sa.sa_flags = SA_ONSTACK;
+               sa.sa_flags = SA_ONSTACK | SA_NODEFER;
                sa.sa_handler = (void *) v;
                sa.sa_restorer = NULL;
-               if (sigaction(SIGSEGV, &sa, NULL) < 0)
-                       panic("userspace_tramp - setting SIGSEGV handler "
-                             "failed - errno = %d\n", errno);
+               if (sigaction(SIGSEGV, &sa, NULL) < 0) {
+                       printk(UM_KERN_ERR "userspace_tramp - setting SIGSEGV "
+                              "handler failed - errno = %d\n", errno);
+                       exit(1);
+               }
        }
 
        kill(os_getpid(), SIGSTOP);
@@ -246,13 +265,18 @@ int start_userspace(unsigned long stub_stack)
 {
        void *stack;
        unsigned long sp;
-       int pid, status, n, flags;
+       int pid, status, n, flags, err;
 
        stack = mmap(NULL, UM_KERN_PAGE_SIZE,
                     PROT_READ | PROT_WRITE | PROT_EXEC,
                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-       if (stack == MAP_FAILED)
-               panic("start_userspace : mmap failed, errno = %d", errno);
+       if (stack == MAP_FAILED) {
+               err = -errno;
+               printk(UM_KERN_ERR "start_userspace : mmap failed, "
+                      "errno = %d\n", errno);
+               return err;
+       }
+
        sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *);
 
        flags = CLONE_FILES;
@@ -262,29 +286,50 @@ int start_userspace(unsigned long stub_stack)
                flags |= SIGCHLD;
 
        pid = clone(userspace_tramp, (void *) sp, flags, (void *) stub_stack);
-       if (pid < 0)
-               panic("start_userspace : clone failed, errno = %d", errno);
+       if (pid < 0) {
+               err = -errno;
+               printk(UM_KERN_ERR "start_userspace : clone failed, "
+                      "errno = %d\n", errno);
+               return err;
+       }
 
        do {
                CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED | __WALL));
-               if (n < 0)
-                       panic("start_userspace : wait failed, errno = %d",
-                             errno);
+               if (n < 0) {
+                       err = -errno;
+                       printk(UM_KERN_ERR "start_userspace : wait failed, "
+                              "errno = %d\n", errno);
+                       goto out_kill;
+               }
        } while (WIFSTOPPED(status) && (WSTOPSIG(status) == SIGVTALRM));
 
-       if (!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP))
-               panic("start_userspace : expected SIGSTOP, got status = %d",
-                     status);
+       if (!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) {
+               err = -EINVAL;
+               printk(UM_KERN_ERR "start_userspace : expected SIGSTOP, got "
+                      "status = %d\n", status);
+               goto out_kill;
+       }
 
        if (ptrace(PTRACE_OLDSETOPTIONS, pid, NULL,
-                  (void *) PTRACE_O_TRACESYSGOOD) < 0)
-               panic("start_userspace : PTRACE_OLDSETOPTIONS failed, "
-                     "errno = %d\n", errno);
+                  (void *) PTRACE_O_TRACESYSGOOD) < 0) {
+               err = -errno;
+               printk(UM_KERN_ERR "start_userspace : PTRACE_OLDSETOPTIONS "
+                      "failed, errno = %d\n", errno);
+               goto out_kill;
+       }
 
-       if (munmap(stack, UM_KERN_PAGE_SIZE) < 0)
-               panic("start_userspace : munmap failed, errno = %d\n", errno);
+       if (munmap(stack, UM_KERN_PAGE_SIZE) < 0) {
+               err = -errno;
+               printk(UM_KERN_ERR "start_userspace : munmap failed, "
+                      "errno = %d\n", errno);
+               goto out_kill;
+       }
 
        return pid;
+
+ out_kill:
+       os_kill_ptraced_process(pid, 1);
+       return err;
 }
 
 void userspace(struct uml_pt_regs *regs)
@@ -302,7 +347,16 @@ void userspace(struct uml_pt_regs *regs)
        nsecs += os_nsecs();
 
        while (1) {
-               restore_registers(pid, regs);
+               /*
+                * This can legitimately fail if the process loads a
+                * bogus value into a segment register.  It will
+                * segfault and PTRACE_GETREGS will read that value
+                * out of the process.  However, PTRACE_SETREGS will
+                * fail.  In this case, there is nothing to do but
+                * just kill the process.
+                */
+               if (ptrace(PTRACE_SETREGS, pid, 0, regs->gp))
+                       fatal_sigsegv();
 
                /* Now we set local_using_sysemu to be used for one loop */
                local_using_sysemu = get_using_sysemu();
@@ -310,19 +364,26 @@ void userspace(struct uml_pt_regs *regs)
                op = SELECT_PTRACE_OPERATION(local_using_sysemu,
                                             singlestepping(NULL));
 
-               err = ptrace(op, pid, 0, 0);
-               if (err)
-                       panic("userspace - could not resume userspace process, "
-                             "pid=%d, ptrace operation = %d, errno = %d\n",
-                             pid, op, errno);
+               if (ptrace(op, pid, 0, 0)) {
+                       printk(UM_KERN_ERR "userspace - ptrace continue "
+                              "failed, op = %d, errno = %d\n", op, errno);
+                       fatal_sigsegv();
+               }
 
                CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED | __WALL));
-               if (err < 0)
-                       panic("userspace - waitpid failed, errno = %d\n",
-                             errno);
+               if (err < 0) {
+                       printk(UM_KERN_ERR "userspace - wait failed, "
+                              "errno = %d\n", errno);
+                       fatal_sigsegv();
+               }
 
                regs->is_user = 1;
-               save_registers(pid, regs);
+               if (ptrace(PTRACE_GETREGS, pid, 0, regs->gp)) {
+                       printk(UM_KERN_ERR "userspace - PTRACE_GETREGS failed, "
+                              "errno = %d\n", errno);
+                       fatal_sigsegv();
+               }
+
                UPT_SYSCALL_NR(regs) = -1; /* Assume: It's not a syscall */
 
                if (WIFSTOPPED(status)) {
@@ -345,7 +406,7 @@ void userspace(struct uml_pt_regs *regs)
                                break;
                        case SIGVTALRM:
                                now = os_nsecs();
-                               if(now < nsecs)
+                               if (now < nsecs)
                                        break;
                                block_signals();
                                (*sig_info[sig])(sig, regs);
@@ -368,6 +429,7 @@ void userspace(struct uml_pt_regs *regs)
                        default:
                                printk(UM_KERN_ERR "userspace - child stopped "
                                       "with signal %d\n", sig);
+                               fatal_sigsegv();
                        }
                        pid = userspace_pid[0];
                        interrupt_end();
@@ -419,9 +481,12 @@ int copy_context_skas0(unsigned long new_stack, int pid)
                                                     .it_interval = tv }) });
 
        err = ptrace_setregs(pid, thread_regs);
-       if (err < 0)
-               panic("copy_context_skas0 : PTRACE_SETREGS failed, "
-                     "pid = %d, errno = %d\n", pid, -err);
+       if (err < 0) {
+               err = -errno;
+               printk(UM_KERN_ERR "copy_context_skas0 : PTRACE_SETREGS "
+                      "failed, pid = %d, errno = %d\n", pid, -err);
+               return err;
+       }
 
        /* set a well known return code for detection of child write failure */
        child_data->err = 12345678;
@@ -431,31 +496,47 @@ int copy_context_skas0(unsigned long new_stack, int pid)
         * parent's stack, and check, if bad result.
         */
        err = ptrace(PTRACE_CONT, pid, 0, 0);
-       if (err)
-               panic("Failed to continue new process, pid = %d, "
-                     "errno = %d\n", pid, errno);
+       if (err) {
+               err = -errno;
+               printk(UM_KERN_ERR "Failed to continue new process, pid = %d, "
+                      "errno = %d\n", pid, errno);
+               return err;
+       }
+
        wait_stub_done(pid);
 
        pid = data->err;
-       if (pid < 0)
-               panic("copy_context_skas0 - stub-parent reports error %d\n",
-                     -pid);
+       if (pid < 0) {
+               printk(UM_KERN_ERR "copy_context_skas0 - stub-parent reports "
+                      "error %d\n", -pid);
+               return pid;
+       }
 
        /*
         * Wait, until child has finished too: read child's result from
         * child's stack and check it.
         */
        wait_stub_done(pid);
-       if (child_data->err != STUB_DATA)
-               panic("copy_context_skas0 - stub-child reports error %ld\n",
-                     child_data->err);
+       if (child_data->err != STUB_DATA) {
+               printk(UM_KERN_ERR "copy_context_skas0 - stub-child reports "
+                      "error %ld\n", child_data->err);
+               err = child_data->err;
+               goto out_kill;
+       }
 
        if (ptrace(PTRACE_OLDSETOPTIONS, pid, NULL,
-                  (void *)PTRACE_O_TRACESYSGOOD) < 0)
-               panic("copy_context_skas0 : PTRACE_OLDSETOPTIONS failed, "
-                     "errno = %d\n", errno);
+                  (void *)PTRACE_O_TRACESYSGOOD) < 0) {
+               err = -errno;
+               printk(UM_KERN_ERR "copy_context_skas0 : PTRACE_OLDSETOPTIONS "
+                      "failed, errno = %d\n", errno);
+               goto out_kill;
+       }
 
        return pid;
+
+ out_kill:
+       os_kill_ptraced_process(pid, 1);
+       return err;
 }
 
 /*
@@ -463,8 +544,8 @@ int copy_context_skas0(unsigned long new_stack, int pid)
  * available. Opening /proc/mm creates a new mm_context, which lacks
  * the stub-pages. Thus, we map them using /proc/mm-fd
  */
-void map_stub_pages(int fd, unsigned long code,
-                   unsigned long data, unsigned long stack)
+int map_stub_pages(int fd, unsigned long code, unsigned long data,
+                  unsigned long stack)
 {
        struct proc_mm_op mmop;
        int n;
@@ -488,8 +569,9 @@ void map_stub_pages(int fd, unsigned long code,
                printk(UM_KERN_ERR "mmap args - addr = 0x%lx, fd = %d, "
                       "offset = %llx\n", code, code_fd,
                       (unsigned long long) code_offset);
-               panic("map_stub_pages : /proc/mm map for code failed, "
-                     "err = %d\n", n);
+               printk(UM_KERN_ERR "map_stub_pages : /proc/mm map for code "
+                      "failed, err = %d\n", n);
+               return -n;
        }
 
        if (stack) {
@@ -507,10 +589,15 @@ void map_stub_pages(int fd, unsigned long code,
                                      .offset  = map_offset
                } } });
                CATCH_EINTR(n = write(fd, &mmop, sizeof(mmop)));
-               if (n != sizeof(mmop))
-                       panic("map_stub_pages : /proc/mm map for data failed, "
-                             "err = %d\n", errno);
+               if (n != sizeof(mmop)) {
+                       n = errno;
+                       printk(UM_KERN_ERR "map_stub_pages : /proc/mm map for "
+                              "data failed, err = %d\n", n);
+                       return -n;
+               }
        }
+
+       return 0;
 }
 
 void new_thread(void *stack, jmp_buf *buf, void (*handler)(void))
@@ -571,7 +658,9 @@ int start_idle_thread(void *stack, jmp_buf *switch_buf)
                kmalloc_ok = 0;
                return 1;
        default:
-               panic("Bad sigsetjmp return in start_idle_thread - %d\n", n);
+               printk(UM_KERN_ERR "Bad sigsetjmp return in "
+                      "start_idle_thread - %d\n", n);
+               fatal_sigsegv();
        }
        longjmp(*switch_buf, 1);
 }
@@ -614,9 +703,11 @@ void __switch_mm(struct mm_id *mm_idp)
        if (proc_mm) {
                err = ptrace(PTRACE_SWITCH_MM, userspace_pid[0], 0,
                             mm_idp->u.mm_fd);
-               if (err)
-                       panic("__switch_mm - PTRACE_SWITCH_MM failed, "
-                             "errno = %d\n", errno);
+               if (err) {
+                       printk(UM_KERN_ERR "__switch_mm - PTRACE_SWITCH_MM "
+                              "failed, errno = %d\n", errno);
+                       fatal_sigsegv();
+               }
        }
        else userspace_pid[0] = mm_idp->u.pid;
 }
diff --git a/arch/um/os-Linux/skas/trap.c b/arch/um/os-Linux/skas/trap.c
deleted file mode 100644 (file)
index 3b1b924..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
- * Licensed under the GPL
- */
-
-#if 0
-#include "kern_util.h"
-#include "skas.h"
-#include "ptrace_user.h"
-#include "sysdep/ptrace_user.h"
-#endif
-
-#include <errno.h>
-#include <signal.h>
-#include "sysdep/ptrace.h"
-#include "kern_constants.h"
-#include "as-layout.h"
-#include "os.h"
-#include "sigcontext.h"
-#include "task.h"
-
-static struct uml_pt_regs ksig_regs[UM_NR_CPUS];
-
-void sig_handler_common_skas(int sig, void *sc_ptr)
-{
-       struct sigcontext *sc = sc_ptr;
-       struct uml_pt_regs *r;
-       void (*handler)(int, struct uml_pt_regs *);
-       int save_user, save_errno = errno;
-
-       /*
-        * This is done because to allow SIGSEGV to be delivered inside a SEGV
-        * handler.  This can happen in copy_user, and if SEGV is disabled,
-        * the process will die.
-        * XXX Figure out why this is better than SA_NODEFER
-        */
-       if (sig == SIGSEGV) {
-               change_sig(SIGSEGV, 1);
-               /*
-                * For segfaults, we want the data from the
-                * sigcontext.  In this case, we don't want to mangle
-                * the process registers, so use a static set of
-                * registers.  For other signals, the process
-                * registers are OK.
-                */
-               r = &ksig_regs[cpu()];
-               copy_sc(r, sc_ptr);
-       }
-       else r = TASK_REGS(get_current());
-
-       save_user = r->is_user;
-       r->is_user = 0;
-       if ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
-           (sig == SIGILL) || (sig == SIGTRAP))
-               GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
-
-       change_sig(SIGUSR1, 1);
-
-       handler = sig_info[sig];
-
-       /* unblock SIGVTALRM, SIGIO if sig isn't IRQ signal */
-       if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGVTALRM))
-               unblock_signals();
-
-       handler(sig, r);
-
-       errno = save_errno;
-       r->is_user = save_user;
-}
index 7b81f6c08a5eddda2aaab95ac4df4f5fd729f88a..b616e15638fbc8c1aa5a8bdf710862715124de42 100644 (file)
@@ -60,10 +60,11 @@ static int ptrace_child(void)
                 * the UML code itself.
                 */
                ret = 2;
-       _exit(ret);
+
+       exit(ret);
 }
 
-static void fatal_perror(char *str)
+static void fatal_perror(const char *str)
 {
        perror(str);
        exit(1);
@@ -341,6 +342,8 @@ static void __init check_coredump_limit(void)
 
 void __init os_early_checks(void)
 {
+       int pid;
+
        /* Print out the core dump limits early */
        check_coredump_limit();
 
@@ -350,6 +353,11 @@ void __init os_early_checks(void)
         * kernel is running.
         */
        check_tmpexec();
+
+       pid = start_ptraced_child();
+       if (init_registers(pid))
+               fatal("Failed to initialize default registers");
+       stop_ptraced_child(pid, 1, 1);
 }
 
 static int __init noprocmm_cmd_param(char *str, int* add)
@@ -411,7 +419,6 @@ static inline void check_skas3_ptrace_faultinfo(void)
                        non_fatal("found\n");
        }
 
-       init_registers(pid);
        stop_ptraced_child(pid, 1, 1);
 }
 
@@ -466,7 +473,7 @@ static inline void check_skas3_proc_mm(void)
        else non_fatal("found\n");
 }
 
-int can_do_skas(void)
+void can_do_skas(void)
 {
        non_fatal("Checking for the skas3 patch in the host:\n");
 
@@ -476,8 +483,6 @@ int can_do_skas(void)
 
        if (!proc_mm || !ptrace_faultinfo || !ptrace_ldt)
                skas_needs_stub = 1;
-
-       return 1;
 }
 
 int __init parse_iomem(char *str, int *add)
diff --git a/arch/um/os-Linux/trap.c b/arch/um/os-Linux/trap.c
deleted file mode 100644 (file)
index 2a1c984..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
- * Licensed under the GPL
- */
-
-#include <signal.h>
-#include "os.h"
-#include "sysdep/ptrace.h"
-
-/* Initialized from linux_main() */
-void (*sig_info[NSIG])(int, struct uml_pt_regs *);
-
-void os_fill_handlinfo(struct kern_handlers h)
-{
-       sig_info[SIGTRAP] = h.relay_signal;
-       sig_info[SIGFPE] = h.relay_signal;
-       sig_info[SIGILL] = h.relay_signal;
-       sig_info[SIGWINCH] = h.winch;
-       sig_info[SIGBUS] = h.bus_handler;
-       sig_info[SIGSEGV] = h.page_fault;
-       sig_info[SIGIO] = h.sigio_handler;
-       sig_info[SIGVTALRM] = h.timer_handler;
-}
index 4cfdd18ea1efdd383e44405a4ddcf98642f0c43d..b09ff66a77eeaf7578d84df8839e2a2961813cd3 100644 (file)
@@ -1,13 +1,16 @@
-/* 
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
 #include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
+#include <fcntl.h>
+#include "kern_constants.h"
+#include "kern_util.h"
 #include "os.h"
 #include "user.h"
-#include "kern_util.h"
 
 struct grantpt_info {
        int fd;
@@ -26,36 +29,34 @@ static void grantpt_cb(void *arg)
 int get_pty(void)
 {
        struct grantpt_info info;
-       int fd;
-
-       fd = os_open_file("/dev/ptmx", of_rdwr(OPENFLAGS()), 0);
-       if(fd < 0){
-               printk("get_pty : Couldn't open /dev/ptmx - err = %d\n", -fd);
-               return(fd);
+       int fd, err;
+
+       fd = open("/dev/ptmx", O_RDWR);
+       if (fd < 0) {
+               err = -errno;
+               printk(UM_KERN_ERR "get_pty : Couldn't open /dev/ptmx - "
+                      "err = %d\n", errno);
+               return err;
        }
 
        info.fd = fd;
        initial_thread_cb(grantpt_cb, &info);
 
-       if(info.res < 0){
-               printk("get_pty : Couldn't grant pty - errno = %d\n", 
-                      -info.err);
-               return(-1);
+       if (info.res < 0) {
+               err = -info.err;
+               printk(UM_KERN_ERR "get_pty : Couldn't grant pty - "
+                      "errno = %d\n", -info.err);
+               goto out;
        }
-       if(unlockpt(fd) < 0){
-               printk("get_pty : Couldn't unlock pty - errno = %d\n", errno);
-               return(-1);
+
+       if (unlockpt(fd) < 0) {
+               err = -errno;
+               printk(UM_KERN_ERR "get_pty : Couldn't unlock pty - "
+                      "errno = %d\n", errno);
+               goto out;
        }
-       return(fd);
+       return fd;
+out:
+       close(fd);
+       return err;
 }
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index d11a55baa6bd59800860bd0acc822adf89b7ef6b..cc648e6fd3a2c1ecaa92196eeee145b65cc8c47f 100644 (file)
@@ -12,7 +12,6 @@
 #include <sys/time.h>
 #include "init.h"
 #include "user.h"
-#include "kern_util.h"
 #include "os.h"
 
 #define TTY_LOG_DIR "./"
index 3e058ce9ffb6cd044a8fbf5ff33883b46b649348..a6f31d476993cd0314c8c6adbf9dad0c7c796f15 100644 (file)
@@ -88,21 +88,6 @@ void setup_hostinfo(char *buf, int len)
                 host.release, host.version, host.machine);
 }
 
-int setjmp_wrapper(void (*proc)(void *, void *), ...)
-{
-       va_list args;
-       jmp_buf buf;
-       int n;
-
-       n = UML_SETJMP(&buf);
-       if(n == 0){
-               va_start(args, proc);
-               (*proc)(&buf, &args);
-       }
-       va_end(args);
-       return n;
-}
-
 void os_dump_core(void)
 {
        int pid;
index a4360b5207db9e6c2e49676522c168942ff5b7f2..8d4f273f1219b0aaab6d3fc24769d7dddb5ec4c4 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/uaccess.h>
+#include <asm/errno.h>
 
 /* Mostly copied from i386/x86_86 - eliminated the eip < PAGE_OFFSET because
  * that's not relevant in skas mode.
index 806895d73bcc1d9eec6495457c03ba2715f81871..a74442d1376213bc5ad41bf3eb11772a743cdeaa 100644 (file)
  * Licensed under the GPL
  */
 
-#include <errno.h>
 #include <signal.h>
-#include <string.h>
 #include "kern_constants.h"
-#include "os.h"
+#include "kern_util.h"
+#include "longjmp.h"
 #include "task.h"
 #include "user.h"
-
-#define MAXTOKEN 64
+#include "sysdep/ptrace.h"
 
 /* Set during early boot */
 int host_has_cmov = 1;
-int host_has_xmm = 0;
+static jmp_buf cmov_test_return;
 
-static char token(int fd, char *buf, int len, char stop)
+static void cmov_sigill_test_handler(int sig)
 {
-       int n;
-       char *ptr, *end, c;
-
-       ptr = buf;
-       end = &buf[len];
-       do {
-               n = os_read_file(fd, ptr, sizeof(*ptr));
-               c = *ptr++;
-               if (n != sizeof(*ptr)) {
-                       if (n == 0)
-                               return 0;
-                       printk(UM_KERN_ERR "Reading /proc/cpuinfo failed, "
-                              "err = %d\n", -n);
-                       if (n < 0)
-                               return n;
-                       else return -EIO;
-               }
-       } while ((c != '\n') && (c != stop) && (ptr < end));
-
-       if (ptr == end) {
-               printk(UM_KERN_ERR "Failed to find '%c' in /proc/cpuinfo\n",
-                      stop);
-               return -1;
-       }
-       *(ptr - 1) = '\0';
-       return c;
-}
-
-static int find_cpuinfo_line(int fd, char *key, char *scratch, int len)
-{
-       int n;
-       char c;
-
-       scratch[len - 1] = '\0';
-       while (1) {
-               c = token(fd, scratch, len - 1, ':');
-               if (c <= 0)
-                       return 0;
-               else if (c != ':') {
-                       printk(UM_KERN_ERR "Failed to find ':' in "
-                              "/proc/cpuinfo\n");
-                       return 0;
-               }
-
-               if (!strncmp(scratch, key, strlen(key)))
-                       return 1;
-
-               do {
-                       n = os_read_file(fd, &c, sizeof(c));
-                       if (n != sizeof(c)) {
-                               printk(UM_KERN_ERR "Failed to find newline in "
-                                      "/proc/cpuinfo, err = %d\n", -n);
-                               return 0;
-                       }
-               } while (c != '\n');
-       }
-       return 0;
+       host_has_cmov = 0;
+       longjmp(cmov_test_return, 1);
 }
 
-static int check_cpu_flag(char *feature, int *have_it)
-{
-       char buf[MAXTOKEN], c;
-       int fd, len = ARRAY_SIZE(buf);
-
-       printk(UM_KERN_INFO "Checking for host processor %s support...",
-              feature);
-       fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
-       if (fd < 0) {
-               printk(UM_KERN_ERR "Couldn't open /proc/cpuinfo, err = %d\n",
-                      -fd);
-               return 0;
-       }
-
-       *have_it = 0;
-       if (!find_cpuinfo_line(fd, "flags", buf, ARRAY_SIZE(buf)))
-               goto out;
-
-       c = token(fd, buf, len - 1, ' ');
-       if (c < 0)
-               goto out;
-       else if (c != ' ') {
-               printk(UM_KERN_ERR "Failed to find ' ' in /proc/cpuinfo\n");
-               goto out;
-       }
-
-       while (1) {
-               c = token(fd, buf, len - 1, ' ');
-               if (c < 0)
-                       goto out;
-               else if (c == '\n')
-                       break;
-
-               if (!strcmp(buf, feature)) {
-                       *have_it = 1;
-                       goto out;
-               }
-       }
- out:
-       if (*have_it == 0)
-               printk("No\n");
-       else if (*have_it == 1)
-               printk("Yes\n");
-       os_close_file(fd);
-       return 1;
-}
-
-#if 0 /*
-       * This doesn't work in tt mode, plus it's causing compilation problems
-       * for some people.
-       */
-static void disable_lcall(void)
+void arch_check_bugs(void)
 {
-       struct modify_ldt_ldt_s ldt;
-       int err;
+       struct sigaction old, new;
 
-       bzero(&ldt, sizeof(ldt));
-       ldt.entry_number = 7;
-       ldt.base_addr = 0;
-       ldt.limit = 0;
-       err = modify_ldt(1, &ldt, sizeof(ldt));
-       if (err)
-               printk(UM_KERN_ERR "Failed to disable lcall7 - errno = %d\n",
-                      errno);
-}
-#endif
+       printk(UM_KERN_INFO "Checking for host processor cmov support...");
+       new.sa_handler = cmov_sigill_test_handler;
 
-void arch_init_thread(void)
-{
-#if 0
-       disable_lcall();
-#endif
-}
+       /* Make sure that SIGILL is enabled after the handler longjmps back */
+       new.sa_flags = SA_NODEFER;
+       sigemptyset(&new.sa_mask);
+       sigaction(SIGILL, &new, &old);
 
-void arch_check_bugs(void)
-{
-       int have_it;
+       if (setjmp(cmov_test_return) == 0) {
+               unsigned long foo = 0;
+               __asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo));
+               printk(UM_KERN_CONT "Yes\n");
+       } else
+               printk(UM_KERN_CONT "No\n");
 
-       if (os_access("/proc/cpuinfo", OS_ACC_R_OK) < 0) {
-               printk(UM_KERN_ERR "/proc/cpuinfo not available - skipping CPU "
-                      "capability checks\n");
-               return;
-       }
-       if (check_cpu_flag("cmov", &have_it))
-               host_has_cmov = have_it;
-       if (check_cpu_flag("xmm", &have_it))
-               host_has_xmm = have_it;
+       sigaction(SIGILL, &old, &new);
 }
 
-int arch_handle_signal(int sig, struct uml_pt_regs *regs)
+void arch_examine_signal(int sig, struct uml_pt_regs *regs)
 {
        unsigned char tmp[2];
 
@@ -176,24 +52,25 @@ int arch_handle_signal(int sig, struct uml_pt_regs *regs)
         * SIGILL in init.
         */
        if ((sig != SIGILL) || (TASK_PID(get_current()) != 1))
-               return 0;
+               return;
+
+       if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2)) {
+               printk(UM_KERN_ERR "SIGILL in init, could not read "
+                      "instructions!\n");
+               return;
+       }
 
-       if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
-               panic("SIGILL in init, could not read instructions!\n");
        if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
-               return 0;
+               return;
 
        if (host_has_cmov == 0)
-               panic("SIGILL caused by cmov, which this processor doesn't "
-                     "implement, boot a filesystem compiled for older "
-                     "processors");
+               printk(UM_KERN_ERR "SIGILL caused by cmov, which this "
+                      "processor doesn't implement.  Boot a filesystem "
+                      "compiled for older processors");
        else if (host_has_cmov == 1)
-               panic("SIGILL caused by cmov, which this processor claims to "
-                     "implement");
-       else if (host_has_cmov == -1)
-               panic("SIGILL caused by cmov, couldn't tell if this processor "
-                     "implements it, boot a filesystem compiled for older "
-                     "processors");
-       else panic("Bad value for host_has_cmov (%d)", host_has_cmov);
-       return 0;
+               printk(UM_KERN_ERR "SIGILL caused by cmov, which this "
+                      "processor claims to implement");
+       else
+               printk(UM_KERN_ERR "Bad value for host_has_cmov (%d)",
+                       host_has_cmov);
 }
index 67c0958eb984266e7e59eaf682754b3c25746642..a34263e6b08d3cc2cedf5e87ed0083ef05288e0b 100644 (file)
@@ -3,8 +3,9 @@
  * Licensed under the GPL
  */
 
-#include "linux/mm.h"
-#include "asm/unistd.h"
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <asm/unistd.h>
 #include "os.h"
 #include "proc_mm.h"
 #include "skas.h"
@@ -146,7 +147,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount)
        if (ptrace_ldt)
                return read_ldt_from_host(ptr, bytecount);
 
-       down(&ldt->semaphore);
+       mutex_lock(&ldt->lock);
        if (ldt->entry_count <= LDT_DIRECT_ENTRIES) {
                size = LDT_ENTRY_SIZE*LDT_DIRECT_ENTRIES;
                if (size > bytecount)
@@ -170,7 +171,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount)
                        ptr += size;
                }
        }
-       up(&ldt->semaphore);
+       mutex_unlock(&ldt->lock);
 
        if (bytecount == 0 || err == -EFAULT)
                goto out;
@@ -228,7 +229,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int func)
        }
 
        if (!ptrace_ldt)
-               down(&ldt->semaphore);
+               mutex_lock(&ldt->lock);
 
        err = write_ldt_entry(mm_idp, func, &ldt_info, &addr, 1);
        if (err)
@@ -288,7 +289,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int func)
        err = 0;
 
 out_unlock:
-       up(&ldt->semaphore);
+       mutex_unlock(&ldt->lock);
 out:
        return err;
 }
@@ -395,7 +396,7 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm)
 
 
        if (!ptrace_ldt)
-               init_MUTEX(&new_mm->ldt.semaphore);
+               mutex_init(&new_mm->ldt.lock);
 
        if (!from_mm) {
                memset(&desc, 0, sizeof(desc));
@@ -455,7 +456,7 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm)
                 * i.e., we have to use the stub for modify_ldt, which
                 * can't handle the big read buffer of up to 64kB.
                 */
-               down(&from_mm->ldt.semaphore);
+               mutex_lock(&from_mm->ldt.lock);
                if (from_mm->ldt.entry_count <= LDT_DIRECT_ENTRIES)
                        memcpy(new_mm->ldt.u.entries, from_mm->ldt.u.entries,
                               sizeof(new_mm->ldt.u.entries));
@@ -474,7 +475,7 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm)
                        }
                }
                new_mm->ldt.entry_count = from_mm->ldt.entry_count;
-               up(&from_mm->ldt.semaphore);
+               mutex_unlock(&from_mm->ldt.lock);
        }
 
     out:
index bd3da8a61f645810bc7af9ec42a6db240379b778..6b4499906a6c96be3139a594681b7c632b8139c1 100644 (file)
@@ -8,11 +8,11 @@
 #include "asm/uaccess.h"
 #include "skas.h"
 
-extern int arch_switch_tls(struct task_struct *from, struct task_struct *to);
+extern int arch_switch_tls(struct task_struct *to);
 
-void arch_switch_to(struct task_struct *from, struct task_struct *to)
+void arch_switch_to(struct task_struct *to)
 {
-       int err = arch_switch_tls(from, to);
+       int err = arch_switch_tls(to);
        if (!err)
                return;
 
index 5cf97bc229b98a7b3e49c2f0ec576c460341d4ba..0b10c3e7402885ae69d471773d554c49b09dc51d 100644 (file)
@@ -19,17 +19,3 @@ int ptrace_setregs(long pid, unsigned long *regs)
                return -errno;
        return 0;
 }
-
-int ptrace_getfpregs(long pid, unsigned long *regs)
-{
-       if (ptrace(PTRACE_GETFPREGS, pid, 0, regs) < 0)
-               return -errno;
-       return 0;
-}
-
-int ptrace_setfpregs(long pid, unsigned long *regs)
-{
-       if (ptrace(PTRACE_SETFPREGS, pid, 0, regs) < 0)
-               return -errno;
-       return 0;
-}
index 19053d46cb60190421d818435af10bac6ce2bbfb..fd0c25ad6af3ecdbd03be96d1a9ee142ec8560e2 100644 (file)
@@ -168,12 +168,13 @@ static int copy_sc_from_user(struct pt_regs *regs,
                             struct sigcontext __user *from)
 {
        struct sigcontext sc;
-       int err;
+       int err, pid;
 
        err = copy_from_user(&sc, from, sizeof(sc));
        if (err)
                return err;
 
+       pid = userspace_pid[current_thread_info()->cpu];
        copy_sc(&regs->regs, &sc);
        if (have_fpx_regs) {
                struct user_fxsr_struct fpx;
@@ -187,8 +188,7 @@ static int copy_sc_from_user(struct pt_regs *regs,
                if (err)
                        return 1;
 
-               err = restore_fpx_registers(userspace_pid[current_thread->cpu],
-                                           (unsigned long *) &fpx);
+               err = restore_fpx_registers(pid, (unsigned long *) &fpx);
                if (err < 0) {
                        printk(KERN_ERR "copy_sc_from_user - "
                               "restore_fpx_registers failed, errno = %d\n",
@@ -204,8 +204,7 @@ static int copy_sc_from_user(struct pt_regs *regs,
                if (err)
                        return 1;
 
-               err = restore_fp_registers(userspace_pid[current_thread->cpu],
-                                          (unsigned long *) &fp);
+               err = restore_fp_registers(pid, (unsigned long *) &fp);
                if (err < 0) {
                        printk(KERN_ERR "copy_sc_from_user - "
                               "restore_fp_registers failed, errno = %d\n",
@@ -223,7 +222,7 @@ static int copy_sc_to_user(struct sigcontext __user *to,
 {
        struct sigcontext sc;
        struct faultinfo * fi = &current->thread.arch.faultinfo;
-       int err;
+       int err, pid;
 
        sc.gs = REGS_GS(regs->regs.gp);
        sc.fs = REGS_FS(regs->regs.gp);
@@ -249,11 +248,11 @@ static int copy_sc_to_user(struct sigcontext __user *to,
        to_fp = (to_fp ? to_fp : (struct _fpstate __user *) (to + 1));
        sc.fpstate = to_fp;
 
+       pid = userspace_pid[current_thread_info()->cpu];
        if (have_fpx_regs) {
                struct user_fxsr_struct fpx;
 
-               err = save_fpx_registers(userspace_pid[current_thread->cpu],
-                                        (unsigned long *) &fpx);
+               err = save_fpx_registers(pid, (unsigned long *) &fpx);
                if (err < 0){
                        printk(KERN_ERR "copy_sc_to_user - save_fpx_registers "
                               "failed, errno = %d\n", err);
@@ -276,8 +275,7 @@ static int copy_sc_to_user(struct sigcontext __user *to,
        else {
                struct user_i387_struct fp;
 
-               err = save_fp_registers(userspace_pid[current_thread->cpu],
-                                       (unsigned long *) &fp);
+               err = save_fp_registers(pid, (unsigned long *) &fp);
                if (copy_to_user(to_fp, &fp, sizeof(struct user_i387_struct)))
                        return 1;
        }
index e730772c401b53206810ceb387aa56b9f4f06cf9..7699e89f660fd42701736ce1bfe79e4d6b2d0ddc 100644 (file)
@@ -7,7 +7,7 @@
        .globl batch_syscall_stub
 batch_syscall_stub:
        /* load pointer to first operation */
-       mov     $(ASM_STUB_DATA+8), %esp
+       mov     $(STUB_DATA+8), %esp
 
 again:
        /* load length of additional data */
@@ -15,12 +15,12 @@ again:
 
        /* if(length == 0) : end of list */
        /* write possible 0 to header */
-       mov     %eax, ASM_STUB_DATA+4
+       mov     %eax, STUB_DATA+4
        cmpl    $0, %eax
        jz      done
 
        /* save current pointer */
-       mov     %esp, ASM_STUB_DATA+4
+       mov     %esp, STUB_DATA+4
 
        /* skip additional data */
        add     %eax, %esp
@@ -46,7 +46,7 @@ again:
 
 done:
        /* save return value */
-       mov     %eax, ASM_STUB_DATA
+       mov     %eax, STUB_DATA
 
        /* stop */
        int3
index b3999cb76bfd2eb004ba5f8be32fec82e38beeeb..28ccf737a79fa9c7364e89fb6c36d3d0608a2f62 100644 (file)
@@ -1,32 +1,17 @@
 /*
- * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
+ * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include <signal.h>
-#include <sys/select.h> /* The only way I can see to get sigset_t */
-#include <asm/unistd.h>
-#include "as-layout.h"
-#include "uml-config.h"
 #include "sysdep/stub.h"
 #include "sysdep/sigcontext.h"
-#include "sysdep/faultinfo.h"
 
 void __attribute__ ((__section__ (".__syscall_stub")))
 stub_segv_handler(int sig)
 {
        struct sigcontext *sc = (struct sigcontext *) (&sig + 1);
-       int pid;
 
        GET_FAULTINFO_FROM_SC(*((struct faultinfo *) STUB_DATA), sc);
 
-       pid = stub_syscall0(__NR_getpid);
-       stub_syscall2(__NR_kill, pid, SIGUSR1);
-
-       /* Load pointer to sigcontext into esp, since we need to leave
-        * the stack in its original form when we do the sigreturn here, by
-        * hand.
-        */
-       __asm__ __volatile__("mov %0,%%esp ; movl %1, %%eax ; "
-                            "int $0x80" : : "a" (sc), "g" (__NR_sigreturn));
+       trap_myself();
 }
index 12d4148dba39aa186aeddcff09be9a8c046a164e..00e5f5203eea337abd3a3e0ee115d6795ab0e4d3 100644 (file)
@@ -9,4 +9,9 @@
 
 #define old_mmap old_mmap_i386
 
+.section .rodata,"a"
+
 #include "../../x86/kernel/syscall_table_32.S"
+
+ENTRY(syscall_table_size)
+.long .-sys_call_table
index fcaff86b000c7397656320d67952821e44c73be2..c6c7131e563bcab77bf69cdfc1ef9160c8c6f9d4 100644 (file)
@@ -26,6 +26,11 @@ int do_set_thread_area(struct user_desc *info)
        cpu = get_cpu();
        ret = os_set_thread_area(info, userspace_pid[cpu]);
        put_cpu();
+
+       if (ret)
+               printk(KERN_ERR "PTRACE_SET_THREAD_AREA failed, err = %d, "
+                      "index = %d\n", ret, info->entry_number);
+
        return ret;
 }
 
@@ -37,6 +42,11 @@ int do_get_thread_area(struct user_desc *info)
        cpu = get_cpu();
        ret = os_get_thread_area(info, userspace_pid[cpu]);
        put_cpu();
+
+       if (ret)
+               printk(KERN_ERR "PTRACE_GET_THREAD_AREA failed, err = %d, "
+                      "index = %d\n", ret, info->entry_number);
+
        return ret;
 }
 
@@ -172,7 +182,7 @@ void clear_flushed_tls(struct task_struct *task)
  * SKAS patch.
  */
 
-int arch_switch_tls(struct task_struct *from, struct task_struct *to)
+int arch_switch_tls(struct task_struct *to)
 {
        if (!host_supports_tls)
                return 0;
@@ -225,7 +235,8 @@ out:
 }
 
 /* XXX: use do_get_thread_area to read the host value? I'm not at all sure! */
-static int get_tls_entry(struct task_struct* task, struct user_desc *info, int idx)
+static int get_tls_entry(struct task_struct *task, struct user_desc *info,
+                        int idx)
 {
        struct thread_struct *t = &task->thread;
 
@@ -263,7 +274,7 @@ clear:
        goto out;
 }
 
-asmlinkage int sys_set_thread_area(struct user_desc __user *user_desc)
+int sys_set_thread_area(struct user_desc __user *user_desc)
 {
        struct user_desc info;
        int idx, ret;
@@ -298,7 +309,7 @@ asmlinkage int sys_set_thread_area(struct user_desc __user *user_desc)
  * i386. However the only possible error are caused by bugs.
  */
 int ptrace_set_thread_area(struct task_struct *child, int idx,
-               struct user_desc __user *user_desc)
+                          struct user_desc __user *user_desc)
 {
        struct user_desc info;
 
@@ -311,7 +322,7 @@ int ptrace_set_thread_area(struct task_struct *child, int idx,
        return set_tls_entry(child, &info, idx, 0);
 }
 
-asmlinkage int sys_get_thread_area(struct user_desc __user *user_desc)
+int sys_get_thread_area(struct user_desc __user *user_desc)
 {
        struct user_desc info;
        int idx, ret;
@@ -355,10 +366,9 @@ out:
        return ret;
 }
 
-
 /*
- * XXX: This part is probably common to i386 and x86-64. Don't create a common
- * file for now, do that when implementing x86-64 support.
+ * This code is really i386-only, but it detects and logs x86_64 GDT indexes
+ * if a 32-bit UML is running on a 64-bit host.
  */
 static int __init __setup_host_supports_tls(void)
 {
@@ -367,13 +377,16 @@ static int __init __setup_host_supports_tls(void)
                printk(KERN_INFO "Host TLS support detected\n");
                printk(KERN_INFO "Detected host type: ");
                switch (host_gdt_entry_tls_min) {
-                       case GDT_ENTRY_TLS_MIN_I386:
-                               printk("i386\n");
-                               break;
-                       case GDT_ENTRY_TLS_MIN_X86_64:
-                               printk("x86_64\n");
-                               break;
+               case GDT_ENTRY_TLS_MIN_I386:
+                       printk(KERN_CONT "i386");
+                       break;
+               case GDT_ENTRY_TLS_MIN_X86_64:
+                       printk(KERN_CONT "x86_64");
+                       break;
                }
+               printk(KERN_CONT " (GDT indexes %d to %d)\n",
+                      host_gdt_entry_tls_min,
+                      host_gdt_entry_tls_min + GDT_ENTRY_TLS_ENTRIES);
        } else
                printk(KERN_ERR "  Host TLS support NOT detected! "
                                "TLS support inside UML will not work\n");
index a9814a7ae60efb1a6690a00b97f0ad01e7850697..08901526e893bda363b59246f8b22b3c3745b697 100644 (file)
@@ -6,7 +6,7 @@ OBJ = built-in.o
 OBJS = ptrace.o sigcontext.o semaphore.o checksum.o miscthings.o misc.o \
        ptrace_user.o sysrq.o
 
-EXTRA_AFLAGS := -DCONFIG_PPC32 -I. -I$(TOPDIR)/arch/ppc/kernel
+EXTRA_AFLAGS := -DCONFIG_PPC32 -I. -I$(srctree)/arch/ppc/kernel
 
 all: $(OBJ)
 
@@ -22,25 +22,25 @@ sigcontext.o: sigcontext.c
 
 semaphore.c:
        rm -f $@
-       ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+       ln -s $(srctree)/arch/ppc/kernel/$@ $@
 
 checksum.S:
        rm -f $@
-       ln -s $(TOPDIR)/arch/ppc/lib/$@ $@
+       ln -s $(srctree)/arch/ppc/lib/$@ $@
 
 mk_defs.c:
        rm -f $@
-       ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+       ln -s $(srctree)/arch/ppc/kernel/$@ $@
 
 ppc_defs.head:
        rm -f $@
-       ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+       ln -s $(srctree)/arch/ppc/kernel/$@ $@
 
 ppc_defs.h: mk_defs.c ppc_defs.head \
-               $(TOPDIR)/include/asm-ppc/mmu.h \
-               $(TOPDIR)/include/asm-ppc/processor.h \
-               $(TOPDIR)/include/asm-ppc/pgtable.h \
-               $(TOPDIR)/include/asm-ppc/ptrace.h
+               $(srctree)/include/asm-ppc/mmu.h \
+               $(srctree)/include/asm-ppc/processor.h \
+               $(srctree)/include/asm-ppc/pgtable.h \
+               $(srctree)/include/asm-ppc/ptrace.h
 #      $(CC) $(CFLAGS) -S mk_defs.c
        cp ppc_defs.head ppc_defs.h
 # for bk, this way we can write to the file even if it's not checked out
@@ -56,13 +56,13 @@ ppc_defs.h: mk_defs.c ppc_defs.head \
 
 checksum.o: checksum.S
        rm -f asm
-       ln -s $(TOPDIR)/include/asm-ppc asm
+       ln -s $(srctree)/include/asm-ppc asm
        $(CC) $(EXTRA_AFLAGS) $(KBUILD_AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o
        rm -f asm
 
 misc.o: misc.S ppc_defs.h
        rm -f asm
-       ln -s $(TOPDIR)/include/asm-ppc asm
+       ln -s $(srctree)/include/asm-ppc asm
        $(CC) $(EXTRA_AFLAGS) $(KBUILD_AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o
        rm -f asm
 
index a4360b5207db9e6c2e49676522c168942ff5b7f2..e8034e363d83f9be90460494af01787e73c13c77 100644 (file)
@@ -5,7 +5,8 @@
 
 #include <linux/uaccess.h>
 
-/* Mostly copied from i386/x86_86 - eliminated the eip < PAGE_OFFSET because
+/*
+ * Mostly copied from i386/x86_86 - eliminated the eip < PAGE_OFFSET because
  * that's not relevant in skas mode.
  */
 
index 506b6765bbcb917a5b77dcd5ab66e97c46da471f..44e02ba2a2656c54595d50ac315b7a64b5f24a7a 100644 (file)
@@ -6,15 +6,10 @@
 
 #include "sysdep/ptrace.h"
 
-void arch_init_thread(void)
-{
-}
-
 void arch_check_bugs(void)
 {
 }
 
-int arch_handle_signal(int sig, struct uml_pt_regs *regs)
+void arch_examine_signal(int sig, struct uml_pt_regs *regs)
 {
-       return 0;
 }
index b7631b0e9ddc212a12966652925646e996768188..f3458d7d1c5ac4a39d5d8aab4fe94c80bfa593e3 100644 (file)
@@ -5,13 +5,12 @@
  * Licensed under the GPL
  */
 
-#define __FRAME_OFFSETS
-#include <asm/ptrace.h>
+#include <linux/mm.h>
 #include <linux/sched.h>
 #include <linux/errno.h>
-#include <linux/mm.h>
+#define __FRAME_OFFSETS
+#include <asm/ptrace.h>
 #include <asm/uaccess.h>
-#include <asm/elf.h>
 
 /*
  * determines which flags the user has access to.
@@ -24,12 +23,14 @@ int putreg(struct task_struct *child, int regno, unsigned long value)
        unsigned long tmp;
 
 #ifdef TIF_IA32
-       /* Some code in the 64bit emulation may not be 64bit clean.
-          Don't take any chances. */
+       /*
+        * Some code in the 64bit emulation may not be 64bit clean.
+        * Don't take any chances.
+        */
        if (test_tsk_thread_flag(child, TIF_IA32))
                value &= 0xffffffff;
 #endif
-       switch (regno){
+       switch (regno) {
        case FS:
        case GS:
        case DS:
@@ -66,7 +67,7 @@ int poke_user(struct task_struct *child, long addr, long data)
        if (addr < MAX_REG_OFFSET)
                return putreg(child, addr, data);
        else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
-               (addr <= offsetof(struct user, u_debugreg[7]))){
+               (addr <= offsetof(struct user, u_debugreg[7]))) {
                addr -= offsetof(struct user, u_debugreg[0]);
                addr = addr >> 2;
                if ((addr == 4) || (addr == 5))
@@ -108,11 +109,10 @@ int peek_user(struct task_struct *child, long addr, long data)
                return -EIO;
 
        tmp = 0;  /* Default return condition */
-       if (addr < MAX_REG_OFFSET){
+       if (addr < MAX_REG_OFFSET)
                tmp = getreg(child, addr);
-       }
        else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
-               (addr <= offsetof(struct user, u_debugreg[7]))){
+               (addr <= offsetof(struct user, u_debugreg[7]))) {
                addr -= offsetof(struct user, u_debugreg[0]);
                addr = addr >> 2;
                tmp = child->thread.arch.debugregs[addr];
@@ -127,8 +127,9 @@ int is_syscall(unsigned long addr)
        int n;
 
        n = copy_from_user(&instr, (void __user *) addr, sizeof(instr));
-       if (n){
-               /* access_process_vm() grants access to vsyscall and stub,
+       if (n) {
+               /*
+                * access_process_vm() grants access to vsyscall and stub,
                 * while copy_from_user doesn't. Maybe access_process_vm is
                 * slow, but that doesn't matter, since it will be called only
                 * in case of singlestepping, if copy_from_user failed.
@@ -155,7 +156,7 @@ int get_fpregs(struct user_i387_struct __user *buf, struct task_struct *child)
                return err;
 
        n = copy_to_user(buf, fpregs, sizeof(fpregs));
-       if(n > 0)
+       if (n > 0)
                return -EFAULT;
 
        return n;
index b5f9c33e311e1b17bfdaf798365d299d0e9585a1..c57a496d3f5b13d668946067e62b7f0ae0a7663a 100644 (file)
@@ -4,55 +4,19 @@
  * Licensed under the GPL
  */
 
-#include <stddef.h>
 #include <errno.h>
 #include "ptrace_user.h"
-#include "user.h"
-#include "kern_constants.h"
 
 int ptrace_getregs(long pid, unsigned long *regs_out)
 {
-       if(ptrace(PTRACE_GETREGS, pid, 0, regs_out) < 0)
-               return(-errno);
-       return(0);
-}
-
-int ptrace_setregs(long pid, unsigned long *regs)
-{
-       if(ptrace(PTRACE_SETREGS, pid, 0, regs) < 0)
-               return(-errno);
+       if (ptrace(PTRACE_GETREGS, pid, 0, regs_out) < 0)
+               return -errno;
        return(0);
 }
 
-int ptrace_setfpregs(long pid, unsigned long *regs)
+int ptrace_setregs(long pid, unsigned long *regs_out)
 {
-       if (ptrace(PTRACE_SETFPREGS, pid, 0, regs) < 0)
+       if (ptrace(PTRACE_SETREGS, pid, 0, regs_out) < 0)
                return -errno;
-       return 0;
-}
-
-void ptrace_pokeuser(unsigned long addr, unsigned long data)
-{
-       panic("ptrace_pokeuser");
-}
-
-#define DS 184
-#define ES 192
-#define __USER_DS     0x2b
-
-void arch_enter_kernel(void *task, int pid)
-{
-}
-
-void arch_leave_kernel(void *task, int pid)
-{
-#ifdef UM_USER_CS
-        if(ptrace(PTRACE_POKEUSR, pid, CS, UM_USER_CS) < 0)
-                printk("POKEUSR CS failed");
-#endif
-
-        if(ptrace(PTRACE_POKEUSR, pid, DS, __USER_DS) < 0)
-                printk("POKEUSR DS failed");
-        if(ptrace(PTRACE_POKEUSR, pid, ES, __USER_DS) < 0)
-                printk("POKEUSR ES failed");
+       return(0);
 }
index 7457436b433a915c6b41d783417d2a0b40cbd171..1a899a7ed7a643261e8c6bc25d6bccbf201221a8 100644 (file)
@@ -81,7 +81,7 @@ static int copy_sc_from_user(struct pt_regs *regs,
        if (err)
                return 1;
 
-       err = restore_fp_registers(userspace_pid[current_thread->cpu],
+       err = restore_fp_registers(userspace_pid[current_thread_info()->cpu],
                                   (unsigned long *) &fp);
        if (err < 0) {
                printk(KERN_ERR "copy_sc_from_user - "
@@ -112,7 +112,7 @@ static int copy_sc_to_user(struct sigcontext __user *to,
        err |= PUTREG(regs, RSI, to, si);
        err |= PUTREG(regs, RBP, to, bp);
        /*
-        * Must use orignal RSP, which is passed in, rather than what's in
+        * Must use original RSP, which is passed in, rather than what's in
         * the pt_regs, because that's already been updated to point at the
         * signal frame.
         */
@@ -143,7 +143,7 @@ static int copy_sc_to_user(struct sigcontext __user *to,
        if (err)
                return 1;
 
-       err = save_fp_registers(userspace_pid[current_thread->cpu],
+       err = save_fp_registers(userspace_pid[current_thread_info()->cpu],
                                (unsigned long *) &fp);
        if (err < 0) {
                printk(KERN_ERR "copy_sc_from_user - restore_fp_registers "
index 4afe204a6af7acea809aa768facf1c6c11c3eb51..5687687631554dabc7e61719a4a900d8d5f691c1 100644 (file)
@@ -8,18 +8,18 @@ syscall_stub:
        /* We don't have 64-bit constants, so this constructs the address
         * we need.
         */
-       movq    $(ASM_STUB_DATA >> 32), %rbx
+       movq    $(STUB_DATA >> 32), %rbx
        salq    $32, %rbx
-       movq    $(ASM_STUB_DATA & 0xffffffff), %rcx
+       movq    $(STUB_DATA & 0xffffffff), %rcx
        or      %rcx, %rbx
        movq    %rax, (%rbx)
        int3
 
        .globl batch_syscall_stub
 batch_syscall_stub:
-       mov     $(ASM_STUB_DATA >> 32), %rbx
+       mov     $(STUB_DATA >> 32), %rbx
        sal     $32, %rbx
-       mov     $(ASM_STUB_DATA & 0xffffffff), %rax
+       mov     $(STUB_DATA & 0xffffffff), %rax
        or      %rax, %rbx
        /* load pointer to first operation */
        mov     %rbx, %rsp
index 3afb590f007212e2da4e90bad9c8447017b46dd4..ced051afc705c47ad29bcbacc78a0443a064267a 100644 (file)
@@ -1,51 +1,22 @@
 /*
- * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
+ * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include <stddef.h>
 #include <signal.h>
-#include <asm/unistd.h>
 #include "as-layout.h"
-#include "uml-config.h"
-#include "sysdep/sigcontext.h"
-#include "sysdep/faultinfo.h"
 #include "sysdep/stub.h"
-
-/* Copied from sys-x86_64/signal.c - Can't find an equivalent definition
- * in the libc headers anywhere.
- */
-struct rt_sigframe
-{
-       char *pretcode;
-       struct ucontext uc;
-       struct siginfo info;
-};
-
-/* Copied here from <linux/kernel.h> - we're userspace. */
-#define container_of(ptr, type, member) ({                   \
-       const typeof( ((type *)0)->member ) *__mptr = (ptr); \
-       (type *)( (char *)__mptr - offsetof(type,member) );})
+#include "sysdep/faultinfo.h"
+#include "sysdep/sigcontext.h"
 
 void __attribute__ ((__section__ (".__syscall_stub")))
 stub_segv_handler(int sig)
 {
        struct ucontext *uc;
-        int pid;
 
        __asm__ __volatile__("movq %%rdx, %0" : "=g" (uc) :);
        GET_FAULTINFO_FROM_SC(*((struct faultinfo *) STUB_DATA),
                              &uc->uc_mcontext);
-
-       pid = stub_syscall0(__NR_getpid);
-       stub_syscall2(__NR_kill, pid, SIGUSR1);
-
-       /* sys_sigreturn expects that the stack pointer will be 8 bytes into
-        * the signal frame.  So, we use the ucontext pointer, which we know
-        * already, to get the signal frame pointer, and add 8 to that.
-        */
-       __asm__ __volatile__("movq %0, %%rsp; movq %1, %%rax ; syscall": :
-                             "g" ((unsigned long)
-                                  container_of(uc, struct rt_sigframe, uc) + 8),
-                             "g" (__NR_rt_sigreturn));
+       trap_myself();
 }
+
index 71b2ae4ad5de17985ee73b97bc43088f67ef2167..c128eb89700804c62f275077147d8d879146ffa7 100644 (file)
@@ -1,5 +1,7 @@
-/* System call table for UML/x86-64, copied from arch/x86_64/kernel/syscall.c
- * with some changes for UML. */
+/*
+ * System call table for UML/x86-64, copied from arch/x86_64/kernel/syscall.c
+ * with some changes for UML.
+ */
 
 #include <linux/linkage.h>
 #include <linux/sys.h>
 
 #define __NO_STUBS
 
-/* Below you can see, in terms of #define's, the differences between the x86-64
- * and the UML syscall table. */
+/*
+ * Below you can see, in terms of #define's, the differences between the x86-64
+ * and the UML syscall table.
+ */
 
 /* Not going to be implemented by UML, since we have no hardware. */
 #define stub_iopl sys_ni_syscall
 #define sys_ioperm sys_ni_syscall
 
-/* The UML TLS problem. Note that x86_64 does not implement this, so the below
- * is needed only for the ia32 compatibility. */
-/*#define sys_set_thread_area sys_ni_syscall
-#define sys_get_thread_area sys_ni_syscall*/
+/*
+ * The UML TLS problem. Note that x86_64 does not implement this, so the below
+ * is needed only for the ia32 compatibility.
+ */
 
 /* On UML we call it this way ("old" means it's not mmap2) */
 #define sys_mmap old_mmap
-/* On x86-64 sys_uname is actually sys_newuname plus a compatibility trick.
- * See arch/x86_64/kernel/sys_x86_64.c */
+/*
+ * On x86-64 sys_uname is actually sys_newuname plus a compatibility trick.
+ * See arch/x86_64/kernel/sys_x86_64.c
+ */
 #define sys_uname sys_uname64
 
 #define stub_clone sys_clone
@@ -46,8 +52,19 @@ typedef void (*sys_call_ptr_t)(void);
 
 extern void sys_ni_syscall(void);
 
-sys_call_ptr_t sys_call_table[UM_NR_syscall_max+1] __cacheline_aligned = {
-       /* Smells like a like a compiler bug -- it doesn't work when the & below is removed. */
-       [0 ... UM_NR_syscall_max] = &sys_ni_syscall,
+/*
+ * We used to have a trick here which made sure that holes in the
+ * x86_64 table were filled in with sys_ni_syscall, but a comment in
+ * unistd_64.h says that holes aren't allowed, so the trick was
+ * removed.
+ * The trick looked like this
+ *     [0 ... UM_NR_syscall_max] = &sys_ni_syscall
+ * before including unistd_64.h - the later initializations overwrote
+ * the sys_ni_syscall filler.
+ */
+
+sys_call_ptr_t sys_call_table[] __cacheline_aligned = {
 #include <asm-x86/unistd_64.h>
 };
+
+int syscall_table_size = sizeof(sys_call_table);
index 86f6b18410ee9e470159c3b63ab8b0e814cff600..f1199fd34d383db5018f349ab811aaea5eb71197 100644 (file)
@@ -48,7 +48,9 @@ long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr)
        switch (code) {
        case ARCH_SET_FS:
        case ARCH_SET_GS:
-               restore_registers(pid, &current->thread.regs.regs);
+               ret = restore_registers(pid, &current->thread.regs.regs);
+               if (ret)
+                       return ret;
                break;
        case ARCH_GET_FS:
        case ARCH_GET_GS:
@@ -70,10 +72,10 @@ long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr)
        switch (code) {
        case ARCH_SET_FS:
                current->thread.arch.fs = (unsigned long) ptr;
-               save_registers(pid, &current->thread.regs.regs);
+               ret = save_registers(pid, &current->thread.regs.regs);
                break;
        case ARCH_SET_GS:
-               save_registers(pid, &current->thread.regs.regs);
+               ret = save_registers(pid, &current->thread.regs.regs);
                break;
        case ARCH_GET_FS:
                ret = put_user(tmp, addr);
@@ -105,7 +107,7 @@ long sys_clone(unsigned long clone_flags, unsigned long newsp,
        return ret;
 }
 
-void arch_switch_to(struct task_struct *from, struct task_struct *to)
+void arch_switch_to(struct task_struct *to)
 {
        if ((to->thread.arch.fs == 0) || (to->mm == NULL))
                return;
index 765444031819c55ce6c51f92f09e665c57448ccd..f4f82beb350889b3c69531797d8b9db11127eb6f 100644 (file)
@@ -4,32 +4,33 @@
  * Licensed under the GPL
  */
 
-#include "linux/kernel.h"
-#include "linux/utsname.h"
-#include "linux/module.h"
-#include "asm/current.h"
-#include "asm/ptrace.h"
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/utsname.h>
+#include <asm/current.h>
+#include <asm/ptrace.h>
 #include "sysrq.h"
 
-void __show_regs(struct pt_regs * regs)
+void __show_regs(struct pt_regs *regs)
 {
        printk("\n");
        print_modules();
-       printk("Pid: %d, comm: %.20s %s %s\n", task_pid_nr(current),
+       printk(KERN_INFO "Pid: %d, comm: %.20s %s %s\n", task_pid_nr(current),
                current->comm, print_tainted(), init_utsname()->release);
-       printk("RIP: %04lx:[<%016lx>] ", PT_REGS_CS(regs) & 0xffff,
+       printk(KERN_INFO "RIP: %04lx:[<%016lx>]\n", PT_REGS_CS(regs) & 0xffff,
               PT_REGS_RIP(regs));
-       printk("\nRSP: %016lx  EFLAGS: %08lx\n", PT_REGS_RSP(regs),
+       printk(KERN_INFO "RSP: %016lx  EFLAGS: %08lx\n", PT_REGS_RSP(regs),
               PT_REGS_EFLAGS(regs));
-       printk("RAX: %016lx RBX: %016lx RCX: %016lx\n",
+       printk(KERN_INFO "RAX: %016lx RBX: %016lx RCX: %016lx\n",
               PT_REGS_RAX(regs), PT_REGS_RBX(regs), PT_REGS_RCX(regs));
-       printk("RDX: %016lx RSI: %016lx RDI: %016lx\n",
+       printk(KERN_INFO "RDX: %016lx RSI: %016lx RDI: %016lx\n",
               PT_REGS_RDX(regs), PT_REGS_RSI(regs), PT_REGS_RDI(regs));
-       printk("RBP: %016lx R08: %016lx R09: %016lx\n",
+       printk(KERN_INFO "RBP: %016lx R08: %016lx R09: %016lx\n",
               PT_REGS_RBP(regs), PT_REGS_R8(regs), PT_REGS_R9(regs));
-       printk("R10: %016lx R11: %016lx R12: %016lx\n",
+       printk(KERN_INFO "R10: %016lx R11: %016lx R12: %016lx\n",
               PT_REGS_R10(regs), PT_REGS_R11(regs), PT_REGS_R12(regs));
-       printk("R13: %016lx R14: %016lx R15: %016lx\n",
+       printk(KERN_INFO "R13: %016lx R14: %016lx R15: %016lx\n",
               PT_REGS_R13(regs), PT_REGS_R14(regs), PT_REGS_R15(regs));
 }
 
index 8b8eff1bd9775de5c636b67f680ca4b49b95437e..3dead392a415d3abb5421582ac251298fcd99cf3 100644 (file)
@@ -1,7 +1,7 @@
 #include <linux/vmalloc.h>
 #include <linux/moduleloader.h>
 
-/*Copied from i386 arch/i386/kernel/module.c */
+/* Copied from i386 arch/i386/kernel/module.c */
 void *module_alloc(unsigned long size)
 {
        if (size == 0)
@@ -13,7 +13,9 @@ void *module_alloc(unsigned long size)
 void module_free(struct module *mod, void *module_region)
 {
        vfree(module_region);
-       /* FIXME: If module_region == mod->init_region, trim exception
-           table entries. */
+       /*
+        * FIXME: If module_region == mod->init_region, trim exception
+        * table entries.
+        */
 }
 
index b6a50b8b38de2c4edc2fdbc8b30012d772c3b672..ace479ab273ff329cc387ce536e8598f171054b4 100644 (file)
@@ -331,8 +331,6 @@ source "sound/Kconfig"
 
 source "drivers/usb/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/v850/Kconfig.debug"
 
 source "security/Kconfig"
index 93e66678e158b4a1e9cb302aa467316253b0b991..e6728bd61cc106fdd71f0ce7a4a025db020a1348 100644 (file)
@@ -18,6 +18,8 @@ config X86_64
 ### Arch settings
 config X86
        def_bool y
+       select HAVE_OPROFILE
+       select HAVE_KPROBES
 
 config GENERIC_LOCKBREAK
        def_bool n
@@ -106,12 +108,16 @@ config GENERIC_TIME_VSYSCALL
 config HAVE_SETUP_PER_CPU_AREA
        def_bool X86_64
 
-config ARCH_SUPPORTS_OPROFILE
-       bool
-       default y
-
 select HAVE_KVM
 
+config ARCH_HIBERNATION_POSSIBLE
+       def_bool y
+       depends on !SMP || !X86_VOYAGER
+
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+       depends on !X86_VOYAGER
+
 config ZONE_DMA32
        bool
        default X86_64
@@ -196,8 +202,7 @@ config SMP
          Y to "Enhanced Real Time Clock Support", below. The "Advanced Power
          Management" code will be disabled if you say Y here.
 
-         See also the <file:Documentation/smp.txt>,
-         <file:Documentation/i386/IO-APIC.txt>,
+         See also <file:Documentation/i386/IO-APIC.txt>,
          <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available at
          <http://www.tldp.org/docs.html#howto>.
 
@@ -301,6 +306,7 @@ config X86_RDC321X
        select M486
        select X86_REBOOTFIXUPS
        select GENERIC_GPIO
+       select LEDS_CLASS
        select LEDS_GPIO
        help
          This option is needed for RDC R-321x system-on-chip, also known
@@ -409,7 +415,7 @@ config HPET_TIMER
 
 config HPET_EMULATE_RTC
        def_bool y
-       depends on HPET_TIMER && (RTC=y || RTC=m)
+       depends on HPET_TIMER && (RTC=y || RTC=m || RTC_DRV_CMOS=m || RTC_DRV_CMOS=y)
 
 # Mark as embedded because too many people got it wrong.
 # The code disables itself when not needed.
@@ -459,6 +465,9 @@ config CALGARY_IOMMU_ENABLED_BY_DEFAULT
          Calgary anyway, pass 'iommu=calgary' on the kernel command line.
          If unsure, say Y.
 
+config IOMMU_HELPER
+       def_bool (CALGARY_IOMMU || GART_IOMMU)
+
 # need this always selected by IOMMU for the VIA workaround
 config SWIOTLB
        bool
@@ -1369,11 +1378,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't.
-
 choice
        prompt "PCI access mode"
        depends on X86_32 && PCI && !X86_VISWS
@@ -1594,8 +1598,6 @@ source "drivers/firmware/Kconfig"
 
 source "fs/Kconfig"
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/x86/Kconfig.debug"
 
 source "security/Kconfig"
index 2e1e3af28c3a2d5c455b048a330b720a74d1f8bf..fa555148823de98079ced8464fb31a28c25c4063 100644 (file)
@@ -220,9 +220,9 @@ config DEBUG_BOOT_PARAMS
          This option will cause struct boot_params to be exported via debugfs.
 
 config CPA_DEBUG
-       bool "CPA self test code"
+       bool "CPA self-test code"
        depends on DEBUG_KERNEL
        help
-         Do change_page_attr self tests at boot.
+         Do change_page_attr() self-tests every 30 seconds.
 
 endmenu
index 8978e98bed5b60dfa8fb34eca332c68d5f941fb0..364865b1b08de8b54625efbf3acb4bb9dbe8089d 100644 (file)
@@ -92,7 +92,6 @@ KBUILD_AFLAGS += $(cfi) $(cfi-sigframe)
 KBUILD_CFLAGS += $(cfi) $(cfi-sigframe)
 
 LDFLAGS := -m elf_$(UTS_MACHINE)
-OBJCOPYFLAGS := -O binary -R .note -R .comment -S
 
 # Speed up the build
 KBUILD_CFLAGS += -pipe
index 349b81a39c40b586275a5c8695f058ac80bc162f..f88458e83ef0dabc17229685c3b6089d24b5a660 100644 (file)
@@ -26,7 +26,7 @@ SVGA_MODE := -DSVGA_MODE=NORMAL_VGA
 #RAMDISK := -DRAMDISK=512
 
 targets                := vmlinux.bin setup.bin setup.elf zImage bzImage
-subdir-        := compressed
+subdir-                := compressed
 
 setup-y                += a20.o cmdline.o copy.o cpu.o cpucheck.o edd.o
 setup-y                += header.o main.o mca.o memory.o pm.o pmjump.o
@@ -43,9 +43,17 @@ setup-y              += video-vesa.o
 setup-y                += video-bios.o
 
 targets                += $(setup-y)
-hostprogs-y    := tools/build
+hostprogs-y    := mkcpustr tools/build
 
-HOSTCFLAGS_build.o := $(LINUXINCLUDE)
+HOST_EXTRACFLAGS += $(LINUXINCLUDE)
+
+$(obj)/cpu.o: $(obj)/cpustr.h
+
+quiet_cmd_cpustr = CPUSTR  $@
+      cmd_cpustr = $(obj)/mkcpustr > $@
+targets                += cpustr.h
+$(obj)/cpustr.h: $(obj)/mkcpustr FORCE
+       $(call if_changed,cpustr)
 
 # ---------------------------------------------------------------------------
 
@@ -80,6 +88,7 @@ $(obj)/zImage $(obj)/bzImage: $(obj)/setup.bin \
        $(call if_changed,image)
        @echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
 
+OBJCOPYFLAGS_vmlinux.bin := -O binary -R .note -R .comment -S
 $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
        $(call if_changed,objcopy)
 
@@ -90,7 +99,6 @@ $(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
        $(call if_changed,ld)
 
 OBJCOPYFLAGS_setup.bin := -O binary
-
 $(obj)/setup.bin: $(obj)/setup.elf FORCE
        $(call if_changed,objcopy)
 
@@ -98,7 +106,7 @@ $(obj)/compressed/vmlinux: FORCE
        $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@
 
 # Set this if you want to pass append arguments to the zdisk/fdimage/isoimage kernel
-FDARGS = 
+FDARGS =
 # Set this if you want an initrd included with the zdisk/fdimage/isoimage kernel
 FDINITRD =
 
index fe24ceabd9095b9d1c0c4c0aac50672e2cc38023..d2b9f3bb87c0575abc28020564b002f8c1965f25 100644 (file)
@@ -22,6 +22,7 @@ $(obj)/vmlinux: $(src)/vmlinux_$(BITS).lds $(obj)/head_$(BITS).o $(obj)/misc.o $
        $(call if_changed,ld)
        @:
 
+OBJCOPYFLAGS_vmlinux.bin := -O binary -R .note -R .comment -S
 $(obj)/vmlinux.bin: vmlinux FORCE
        $(call if_changed,objcopy)
 
index 1ccb38a7f0d2c72610c906bf89d5c142a97e9229..e8657b98c902a0773a1e9861fc4db6349f0bb909 100644 (file)
@@ -80,8 +80,8 @@ startup_32:
 
 #ifdef CONFIG_RELOCATABLE
        movl    %ebp, %ebx
-       addl    $(LARGE_PAGE_SIZE -1), %ebx
-       andl    $LARGE_PAGE_MASK, %ebx
+       addl    $(PMD_PAGE_SIZE -1), %ebx
+       andl    $PMD_PAGE_MASK, %ebx
 #else
        movl    $CONFIG_PHYSICAL_START, %ebx
 #endif
@@ -220,8 +220,8 @@ ENTRY(startup_64)
        /* Start with the delta to where the kernel will run at. */
 #ifdef CONFIG_RELOCATABLE
        leaq    startup_32(%rip) /* - $startup_32 */, %rbp
-       addq    $(LARGE_PAGE_SIZE - 1), %rbp
-       andq    $LARGE_PAGE_MASK, %rbp
+       addq    $(PMD_PAGE_SIZE - 1), %rbp
+       andq    $PMD_PAGE_MASK, %rbp
        movq    %rbp, %rbx
 #else
        movq    $CONFIG_PHYSICAL_START, %rbp
index 2a5c32da5852a307424a1b5105e60cff63e2d7ce..00e19edd852c60d8cc32a2b009a604938747dd77 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- linux-c -*- ------------------------------------------------------- *
  *
  *   Copyright (C) 1991, 1992 Linus Torvalds
- *   Copyright 2007 rPath, Inc. - All Rights Reserved
+ *   Copyright 2007-2008 rPath, Inc. - All Rights Reserved
  *
  *   This file is part of the Linux kernel, and is made available under
  *   the terms of the GNU General Public License version 2.
@@ -9,7 +9,7 @@
  * ----------------------------------------------------------------------- */
 
 /*
- * arch/i386/boot/cpu.c
+ * arch/x86/boot/cpu.c
  *
  * Check for obligatory CPU features and abort if the features are not
  * present.
@@ -19,6 +19,8 @@
 #include "bitops.h"
 #include <asm/cpufeature.h>
 
+#include "cpustr.h"
+
 static char *cpu_name(int level)
 {
        static char buf[6];
@@ -35,6 +37,7 @@ int validate_cpu(void)
 {
        u32 *err_flags;
        int cpu_level, req_level;
+       const unsigned char *msg_strs;
 
        check_cpu(&cpu_level, &req_level, &err_flags);
 
@@ -51,13 +54,26 @@ int validate_cpu(void)
                puts("This kernel requires the following features "
                     "not present on the CPU:\n");
 
+               msg_strs = (const unsigned char *)x86_cap_strs;
+
                for (i = 0; i < NCAPINTS; i++) {
                        u32 e = err_flags[i];
 
                        for (j = 0; j < 32; j++) {
-                               if (e & 1)
-                                       printf("%d:%d ", i, j);
-
+                               int n = (i << 5)+j;
+                               if (*msg_strs < n) {
+                                       /* Skip to the next string */
+                                       do {
+                                               msg_strs++;
+                                       } while (*msg_strs);
+                                       msg_strs++;
+                               }
+                               if (e & 1) {
+                                       if (*msg_strs == n && msg_strs[1])
+                                               printf("%s ", msg_strs+1);
+                                       else
+                                               printf("%d:%d ", i, j);
+                               }
                                e >>= 1;
                        }
                }
diff --git a/arch/x86/boot/mkcpustr.c b/arch/x86/boot/mkcpustr.c
new file mode 100644 (file)
index 0000000..bbe7695
--- /dev/null
@@ -0,0 +1,49 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2008 rPath, Inc. - All Rights Reserved
+ *
+ *   This file is part of the Linux kernel, and is made available under
+ *   the terms of the GNU General Public License version 2 or (at your
+ *   option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * This is a host program to preprocess the CPU strings into a
+ * compact format suitable for the setup code.
+ */
+
+#include <stdio.h>
+
+#include "../kernel/cpu/feature_names.c"
+
+#if NCAPFLAGS > 8
+# error "Need to adjust the boot code handling of CPUID strings"
+#endif
+
+int main(void)
+{
+       int i;
+       const char *str;
+
+       printf("static const char x86_cap_strs[] = \n");
+
+       for (i = 0; i < NCAPINTS*32; i++) {
+               str = x86_cap_flags[i];
+
+               if (i == NCAPINTS*32-1) {
+                       /* The last entry must be unconditional; this
+                          also consumes the compiler-added null character */
+                       if (!str)
+                               str = "";
+                       printf("\t\"\\x%02x\"\"%s\"\n", i, str);
+               } else if (str) {
+                       printf("#if REQUIRED_MASK%d & (1 << %d)\n"
+                              "\t\"\\x%02x\"\"%s\\0\"\n"
+                              "#endif\n",
+                              i >> 5, i & 31, i, str);
+               }
+       }
+       printf("\t;\n");
+       return 0;
+}
index 0db0a6291bbd06d059c654ce58f8e5d387d685c0..8022d3c695c0dcf0d4a609387d337bf8eeaac888 100644 (file)
@@ -722,7 +722,9 @@ ia32_sys_call_table:
        .quad sys_epoll_pwait
        .quad compat_sys_utimensat      /* 320 */
        .quad compat_sys_signalfd
-       .quad compat_sys_timerfd
+       .quad sys_timerfd_create
        .quad sys_eventfd
        .quad sys32_fallocate
+       .quad compat_sys_timerfd_settime        /* 325 */
+       .quad compat_sys_timerfd_gettime
 ia32_syscall_end:
index 6f813009d44b348de25cbb355a197f9c8f1241fe..21dc1a061bf1b13c653b6ba7c8f54e31941f80ff 100644 (file)
@@ -37,7 +37,8 @@ obj-$(CONFIG_X86_MSR)         += msr.o
 obj-$(CONFIG_X86_CPUID)                += cpuid.o
 obj-$(CONFIG_MICROCODE)                += microcode.o
 obj-$(CONFIG_PCI)              += early-quirks.o
-obj-$(CONFIG_APM)              += apm_32.o
+apm-y                          := apm_32.o
+obj-$(CONFIG_APM)              += apm.o
 obj-$(CONFIG_X86_SMP)          += smp_$(BITS).o smpboot_$(BITS).o tsc_sync.o
 obj-$(CONFIG_X86_32_SMP)       += smpcommon_32.o
 obj-$(CONFIG_X86_64_SMP)       += smp_64.o smpboot_64.o tsc_sync.o
@@ -74,7 +75,8 @@ ifdef CONFIG_INPUT_PCSPKR
 obj-y                          += pcspeaker.o
 endif
 
-obj-$(CONFIG_SCx200)           += scx200_32.o
+obj-$(CONFIG_SCx200)           += scx200.o
+scx200-y                       += scx200_32.o
 
 ###
 # 64 bit specific files
index cfdb2f3bd7636bff75d5ac2fd322800c5afa8639..a0c4d7c5dbd7bcf944fbc4e23ea74215c80c6d42 100644 (file)
@@ -3,6 +3,7 @@
 #
 
 obj-y                  := intel_cacheinfo.o addon_cpuid_features.o
+obj-y                  += feature_names.o
 
 obj-$(CONFIG_X86_32)   += common.o proc.o bugs.o
 obj-$(CONFIG_X86_32)   += amd.o
index b7b2142b58e7e8f81671afd4494751cb29b7b005..f86a3c4a2669909be340d195a6ee93201c53cdf9 100644 (file)
@@ -623,16 +623,6 @@ cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
  * They will insert themselves into the cpu_devs structure.
  * Then, when cpu_init() is called, we can just iterate over that array.
  */
-
-extern int intel_cpu_init(void);
-extern int cyrix_init_cpu(void);
-extern int nsc_init_cpu(void);
-extern int amd_init_cpu(void);
-extern int centaur_init_cpu(void);
-extern int transmeta_init_cpu(void);
-extern int nexgen_init_cpu(void);
-extern int umc_init_cpu(void);
-
 void __init early_cpu_init(void)
 {
        intel_cpu_init();
@@ -647,7 +637,7 @@ void __init early_cpu_init(void)
 }
 
 /* Make sure %fs is initialized properly in idle threads */
-struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
+struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
 {
        memset(regs, 0, sizeof(struct pt_regs));
        regs->fs = __KERNEL_PERCPU;
index ad6527a5beb12ba086ab643553722aa31fdbc08a..e0b38c33d84276c971110146960ecdcc1b11fdb3 100644 (file)
@@ -27,3 +27,12 @@ extern void display_cacheinfo(struct cpuinfo_x86 *c);
 extern void early_init_intel(struct cpuinfo_x86 *c);
 extern void early_init_amd(struct cpuinfo_x86 *c);
 
+/* Specific CPU type init functions */
+int intel_cpu_init(void);
+int amd_init_cpu(void);
+int cyrix_init_cpu(void);
+int nsc_init_cpu(void);
+int centaur_init_cpu(void);
+int transmeta_init_cpu(void);
+int nexgen_init_cpu(void);
+int umc_init_cpu(void);
index a0522735dd9d9298122b5069baabe2bc12c0cda4..5affe91ca1e5964ff9bd309c78c3619f04379c7b 100644 (file)
@@ -827,7 +827,6 @@ static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpuf
 
        for (i = 0; i < data->acpi_data.state_count; i++) {
                u32 index;
-               u32 hi = 0, lo = 0;
 
                index = data->acpi_data.states[i].control & HW_PSTATE_MASK;
                if (index > data->max_hw_pstate) {
index 404a6a2d4016c790c6457b966703f8ebdc669dc2..7139b02627034cb3f69482541b62b1102bbe6287 100644 (file)
@@ -83,8 +83,6 @@ static char cyrix_model_mult2[] __cpuinitdata = "12233445";
  * FIXME: our newer udelay uses the tsc. We don't need to frob with SLOP
  */
 
-extern void calibrate_delay(void) __init;
-
 static void __cpuinit check_cx686_slop(struct cpuinfo_x86 *c)
 {
        unsigned long flags;
diff --git a/arch/x86/kernel/cpu/feature_names.c b/arch/x86/kernel/cpu/feature_names.c
new file mode 100644 (file)
index 0000000..ee975ac
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Strings for the various x86 capability flags.
+ *
+ * This file must not contain any executable code.
+ */
+
+#include "asm/cpufeature.h"
+
+/*
+ * These flag bits must match the definitions in <asm/cpufeature.h>.
+ * NULL means this bit is undefined or reserved; either way it doesn't
+ * have meaning as far as Linux is concerned.  Note that it's important
+ * to realize there is a difference between this table and CPUID -- if
+ * applications want to get the raw CPUID data, they should access
+ * /dev/cpu/<cpu_nr>/cpuid instead.
+ */
+const char * const x86_cap_flags[NCAPINTS*32] = {
+       /* Intel-defined */
+       "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
+       "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
+       "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
+       "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", "pbe",
+
+       /* AMD-defined */
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, "mp", "nx", NULL, "mmxext", NULL,
+       NULL, "fxsr_opt", "pdpe1gb", "rdtscp", NULL, "lm",
+       "3dnowext", "3dnow",
+
+       /* Transmeta-defined */
+       "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+
+       /* Other (Linux-defined) */
+       "cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr",
+       NULL, NULL, NULL, NULL,
+       "constant_tsc", "up", NULL, "arch_perfmon",
+       "pebs", "bts", NULL, NULL,
+       "rep_good", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+
+       /* Intel-defined (#2) */
+       "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
+       "tm2", "ssse3", "cid", NULL, NULL, "cx16", "xtpr", NULL,
+       NULL, NULL, "dca", "sse4_1", "sse4_2", NULL, NULL, "popcnt",
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+
+       /* VIA/Cyrix/Centaur-defined */
+       NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
+       "ace2", "ace2_en", "phe", "phe_en", "pmm", "pmm_en", NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+
+       /* AMD-defined (#2) */
+       "lahf_lm", "cmp_legacy", "svm", "extapic",
+       "cr8_legacy", "abm", "sse4a", "misalignsse",
+       "3dnowprefetch", "osvw", "ibs", "sse5",
+       "skinit", "wdt", NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+
+       /* Auxiliary (Linux-defined) */
+       "ida", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+};
+
+const char *const x86_power_flags[32] = {
+       "ts",   /* temperature sensor */
+       "fid",  /* frequency id control */
+       "vid",  /* voltage id control */
+       "ttp",  /* thermal trip */
+       "tm",
+       "stc",
+       "100mhzsteps",
+       "hwpstate",
+       "",     /* tsc invariant mapped to constant_tsc */
+               /* nothing */
+};
index d1c372b018dbe299fde8ae3c5bcfc21961929e84..fae31ce747bdc042d0d94723a4e8da4fe5b61721 100644 (file)
@@ -13,6 +13,7 @@
 #include <asm/uaccess.h>
 #include <asm/ptrace.h>
 #include <asm/ds.h>
+#include <asm/bugs.h>
 
 #include "cpu.h"
 
index 8e139c70f888262a62535bc7c2007acd2ad5b7f6..ff14c320040ccf9ab496b4b170cd03f97626dc36 100644 (file)
@@ -7,8 +7,6 @@
 #include <asm/processor-flags.h>
 #include "mtrr.h"
 
-int arr3_protected;
-
 static void
 cyrix_get_arr(unsigned int reg, unsigned long *base,
              unsigned long *size, mtrr_type * type)
@@ -99,8 +97,6 @@ cyrix_get_free_region(unsigned long base, unsigned long size, int replace_reg)
        case 4:
                return replace_reg;
        case 3:
-               if (arr3_protected)
-                       break;
        case 2:
        case 1:
        case 0:
@@ -115,8 +111,6 @@ cyrix_get_free_region(unsigned long base, unsigned long size, int replace_reg)
        } else {
                for (i = 0; i < 7; i++) {
                        cyrix_get_arr(i, &lbase, &lsize, &ltype);
-                       if ((i == 3) && arr3_protected)
-                               continue;
                        if (lsize == 0)
                                return i;
                }
@@ -260,107 +254,6 @@ static void cyrix_set_all(void)
        post_set();
 }
 
-#if 0
-/*
- * On Cyrix 6x86(MX) and M II the ARR3 is special: it has connection
- * with the SMM (System Management Mode) mode. So we need the following:
- * Check whether SMI_LOCK (CCR3 bit 0) is set
- *   if it is set, write a warning message: ARR3 cannot be changed!
- *     (it cannot be changed until the next processor reset)
- *   if it is reset, then we can change it, set all the needed bits:
- *   - disable access to SMM memory through ARR3 range (CCR1 bit 7 reset)
- *   - disable access to SMM memory (CCR1 bit 2 reset)
- *   - disable SMM mode (CCR1 bit 1 reset)
- *   - disable write protection of ARR3 (CCR6 bit 1 reset)
- *   - (maybe) disable ARR3
- * Just to be sure, we enable ARR usage by the processor (CCR5 bit 5 set)
- */
-static void __init
-cyrix_arr_init(void)
-{
-       struct set_mtrr_context ctxt;
-       unsigned char ccr[7];
-       int ccrc[7] = { 0, 0, 0, 0, 0, 0, 0 };
-#ifdef CONFIG_SMP
-       int i;
-#endif
-
-       /* flush cache and enable MAPEN */
-       set_mtrr_prepare_save(&ctxt);
-       set_mtrr_cache_disable(&ctxt);
-
-       /* Save all CCRs locally */
-       ccr[0] = getCx86(CX86_CCR0);
-       ccr[1] = getCx86(CX86_CCR1);
-       ccr[2] = getCx86(CX86_CCR2);
-       ccr[3] = ctxt.ccr3;
-       ccr[4] = getCx86(CX86_CCR4);
-       ccr[5] = getCx86(CX86_CCR5);
-       ccr[6] = getCx86(CX86_CCR6);
-
-       if (ccr[3] & 1) {
-               ccrc[3] = 1;
-               arr3_protected = 1;
-       } else {
-               /* Disable SMM mode (bit 1), access to SMM memory (bit 2) and
-                * access to SMM memory through ARR3 (bit 7).
-                */
-               if (ccr[1] & 0x80) {
-                       ccr[1] &= 0x7f;
-                       ccrc[1] |= 0x80;
-               }
-               if (ccr[1] & 0x04) {
-                       ccr[1] &= 0xfb;
-                       ccrc[1] |= 0x04;
-               }
-               if (ccr[1] & 0x02) {
-                       ccr[1] &= 0xfd;
-                       ccrc[1] |= 0x02;
-               }
-               arr3_protected = 0;
-               if (ccr[6] & 0x02) {
-                       ccr[6] &= 0xfd;
-                       ccrc[6] = 1;    /* Disable write protection of ARR3 */
-                       setCx86(CX86_CCR6, ccr[6]);
-               }
-               /* Disable ARR3. This is safe now that we disabled SMM. */
-               /* cyrix_set_arr_up (3, 0, 0, 0, FALSE); */
-       }
-       /* If we changed CCR1 in memory, change it in the processor, too. */
-       if (ccrc[1])
-               setCx86(CX86_CCR1, ccr[1]);
-
-       /* Enable ARR usage by the processor */
-       if (!(ccr[5] & 0x20)) {
-               ccr[5] |= 0x20;
-               ccrc[5] = 1;
-               setCx86(CX86_CCR5, ccr[5]);
-       }
-#ifdef CONFIG_SMP
-       for (i = 0; i < 7; i++)
-               ccr_state[i] = ccr[i];
-       for (i = 0; i < 8; i++)
-               cyrix_get_arr(i,
-                             &arr_state[i].base, &arr_state[i].size,
-                             &arr_state[i].type);
-#endif
-
-       set_mtrr_done(&ctxt);   /* flush cache and disable MAPEN */
-
-       if (ccrc[5])
-               printk(KERN_INFO "mtrr: ARR usage was not enabled, enabled manually\n");
-       if (ccrc[3])
-               printk(KERN_INFO "mtrr: ARR3 cannot be changed\n");
-/*
-    if ( ccrc[1] & 0x80) printk ("mtrr: SMM memory access through ARR3 disabled\n");
-    if ( ccrc[1] & 0x04) printk ("mtrr: SMM memory access disabled\n");
-    if ( ccrc[1] & 0x02) printk ("mtrr: SMM mode disabled\n");
-*/
-       if (ccrc[6])
-               printk(KERN_INFO "mtrr: ARR3 was write protected, unprotected\n");
-}
-#endif
-
 static struct mtrr_ops cyrix_mtrr_ops = {
        .vendor            = X86_VENDOR_CYRIX,
 //     .init              = cyrix_arr_init,
index 715919582657564a32f2941947687d87c448f722..b6e136f23d3d3219094bc9fdadaeaba048f01b96 100644 (file)
@@ -59,12 +59,6 @@ struct mtrr_ops * mtrr_if = NULL;
 static void set_mtrr(unsigned int reg, unsigned long base,
                     unsigned long size, mtrr_type type);
 
-#ifndef CONFIG_X86_64
-extern int arr3_protected;
-#else
-#define arr3_protected 0
-#endif
-
 void set_mtrr_ops(struct mtrr_ops * ops)
 {
        if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
@@ -513,12 +507,6 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)
                printk(KERN_WARNING "mtrr: register: %d too big\n", reg);
                goto out;
        }
-       if (is_cpu(CYRIX) && !use_intel()) {
-               if ((reg == 3) && arr3_protected) {
-                       printk(KERN_WARNING "mtrr: ARR3 cannot be changed\n");
-                       goto out;
-               }
-       }
        mtrr_if->get(reg, &lbase, &lsize, &ltype);
        if (lsize < 1) {
                printk(KERN_WARNING "mtrr: MTRR %d not used\n", reg);
@@ -566,10 +554,6 @@ EXPORT_SYMBOL(mtrr_del);
  * These should be called implicitly, but we can't yet until all the initcall
  * stuff is done...
  */
-extern void amd_init_mtrr(void);
-extern void cyrix_init_mtrr(void);
-extern void centaur_init_mtrr(void);
-
 static void __init init_ifs(void)
 {
 #ifndef CONFIG_X86_64
@@ -675,7 +659,7 @@ static __init int amd_special_default_mtrr(void)
  */
 int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 {
-       unsigned long i, base, size, highest_addr = 0, def, dummy;
+       unsigned long i, base, size, highest_pfn = 0, def, dummy;
        mtrr_type type;
        u64 trim_start, trim_size;
 
@@ -698,28 +682,27 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
                mtrr_if->get(i, &base, &size, &type);
                if (type != MTRR_TYPE_WRBACK)
                        continue;
-               base <<= PAGE_SHIFT;
-               size <<= PAGE_SHIFT;
-               if (highest_addr < base + size)
-                       highest_addr = base + size;
+               if (highest_pfn < base + size)
+                       highest_pfn = base + size;
        }
 
        /* kvm/qemu doesn't have mtrr set right, don't trim them all */
-       if (!highest_addr) {
+       if (!highest_pfn) {
                printk(KERN_WARNING "WARNING: strange, CPU MTRRs all blank?\n");
                WARN_ON(1);
                return 0;
        }
 
-       if ((highest_addr >> PAGE_SHIFT) < end_pfn) {
+       if (highest_pfn < end_pfn) {
                printk(KERN_WARNING "WARNING: BIOS bug: CPU MTRRs don't cover"
-                       " all of memory, losing %LdMB of RAM.\n",
-                       (((u64)end_pfn << PAGE_SHIFT) - highest_addr) >> 20);
+                       " all of memory, losing %luMB of RAM.\n",
+                       (end_pfn - highest_pfn) >> (20 - PAGE_SHIFT));
 
                WARN_ON(1);
 
                printk(KERN_INFO "update e820 for mtrr\n");
-               trim_start = highest_addr;
+               trim_start = highest_pfn;
+               trim_start <<= PAGE_SHIFT;
                trim_size = end_pfn;
                trim_size <<= PAGE_SHIFT;
                trim_size -= trim_start;
index fb74a2c2081487bfd7207f6d4b620064cd67c4c8..2cc77eb6fea36967f7defdbae74359ebaac14ebb 100644 (file)
@@ -97,3 +97,7 @@ void mtrr_state_warn(void);
 const char *mtrr_attrib_to_str(int x);
 void mtrr_wrmsr(unsigned, unsigned, unsigned);
 
+/* CPU specific mtrr init functions */
+int amd_init_mtrr(void);
+int cyrix_init_mtrr(void);
+int centaur_init_mtrr(void);
index 028213260148d62b75f6d1804aa0977cfec6395f..af11d31dce0ae0df0b8a15772b2da15059a1871a 100644 (file)
  */
 static int show_cpuinfo(struct seq_file *m, void *v)
 {
-       /* 
-        * These flag bits must match the definitions in <asm/cpufeature.h>.
-        * NULL means this bit is undefined or reserved; either way it doesn't
-        * have meaning as far as Linux is concerned.  Note that it's important
-        * to realize there is a difference between this table and CPUID -- if
-        * applications want to get the raw CPUID data, they should access
-        * /dev/cpu/<cpu_nr>/cpuid instead.
-        */
-       static const char * const x86_cap_flags[] = {
-               /* Intel-defined */
-               "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
-               "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
-               "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
-               "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", "pbe",
-
-               /* AMD-defined */
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, "mp", "nx", NULL, "mmxext", NULL,
-               NULL, "fxsr_opt", "pdpe1gb", "rdtscp", NULL, "lm",
-               "3dnowext", "3dnow",
-
-               /* Transmeta-defined */
-               "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* Other (Linux-defined) */
-               "cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr",
-               NULL, NULL, NULL, NULL,
-               "constant_tsc", "up", NULL, "arch_perfmon",
-               "pebs", "bts", NULL, "sync_rdtsc",
-               "rep_good", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* Intel-defined (#2) */
-               "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
-               "tm2", "ssse3", "cid", NULL, NULL, "cx16", "xtpr", NULL,
-               NULL, NULL, "dca", "sse4_1", "sse4_2", NULL, NULL, "popcnt",
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* VIA/Cyrix/Centaur-defined */
-               NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
-               "ace2", "ace2_en", "phe", "phe_en", "pmm", "pmm_en", NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* AMD-defined (#2) */
-               "lahf_lm", "cmp_legacy", "svm", "extapic",
-               "cr8_legacy", "abm", "sse4a", "misalignsse",
-               "3dnowprefetch", "osvw", "ibs", "sse5",
-               "skinit", "wdt", NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* Auxiliary (Linux-defined) */
-               "ida", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-       };
-       static const char * const x86_power_flags[] = {
-               "ts",   /* temperature sensor */
-               "fid",  /* frequency id control */
-               "vid",  /* voltage id control */
-               "ttp",  /* thermal trip */
-               "tm",
-               "stc",
-               "100mhzsteps",
-               "hwpstate",
-               "",     /* constant_tsc - moved to flags */
-               /* nothing */
-       };
        struct cpuinfo_x86 *c = v;
        int i, n = 0;
        int fpu_exception;
index a63432d800f913960f055232d02aa668e892b83e..288e7a6598ac6450c1b13a88e51337ccc0c0b9d2 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
- *   
- *   Copyright 2000 H. Peter Anvin - All Rights Reserved
+ *
+ *   Copyright 2000-2008 H. Peter Anvin - All Rights Reserved
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
  * and then read in chunks of 16 bytes.  A larger size means multiple
  * reads of consecutive levels.
  *
+ * The lower 32 bits of the file position is used as the incoming %eax,
+ * and the upper 32 bits of the file position as the incoming %ecx,
+ * the latter intended for "counting" eax levels like eax=4.
+ *
  * This driver uses /dev/cpu/%d/cpuid where %d is the minor number, and on
  * an SMP box will direct the access to CPU %d.
  */
 
 static struct class *cpuid_class;
 
-struct cpuid_command {
-       u32 reg;
-       u32 *data;
+struct cpuid_regs {
+       u32 eax, ebx, ecx, edx;
 };
 
 static void cpuid_smp_cpuid(void *cmd_block)
 {
-       struct cpuid_command *cmd = cmd_block;
-
-       cpuid(cmd->reg, &cmd->data[0], &cmd->data[1], &cmd->data[2],
-                     &cmd->data[3]);
-}
-
-static inline void do_cpuid(int cpu, u32 reg, u32 * data)
-{
-       struct cpuid_command cmd;
-
-       cmd.reg = reg;
-       cmd.data = data;
+       struct cpuid_regs *cmd = (struct cpuid_regs *)cmd_block;
 
-       smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1, 1);
+       cpuid_count(cmd->eax, cmd->ecx,
+                   &cmd->eax, &cmd->ebx, &cmd->ecx, &cmd->edx);
 }
 
 static loff_t cpuid_seek(struct file *file, loff_t offset, int orig)
 {
        loff_t ret;
+       struct inode *inode = file->f_mapping->host;
 
-       lock_kernel();
-
+       mutex_lock(&inode->i_mutex);
        switch (orig) {
        case 0:
                file->f_pos = offset;
@@ -84,8 +77,7 @@ static loff_t cpuid_seek(struct file *file, loff_t offset, int orig)
        default:
                ret = -EINVAL;
        }
-
-       unlock_kernel();
+       mutex_unlock(&inode->i_mutex);
        return ret;
 }
 
@@ -93,19 +85,21 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
                          size_t count, loff_t * ppos)
 {
        char __user *tmp = buf;
-       u32 data[4];
-       u32 reg = *ppos;
+       struct cpuid_regs cmd;
        int cpu = iminor(file->f_path.dentry->d_inode);
+       u64 pos = *ppos;
 
        if (count % 16)
                return -EINVAL; /* Invalid chunk size */
 
        for (; count; count -= 16) {
-               do_cpuid(cpu, reg, data);
-               if (copy_to_user(tmp, &data, 16))
+               cmd.eax = pos;
+               cmd.ecx = pos >> 32;
+               smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1, 1);
+               if (copy_to_user(tmp, &cmd, 16))
                        return -EFAULT;
                tmp += 16;
-               *ppos = reg++;
+               *ppos = ++pos;
        }
 
        return tmp - buf;
@@ -193,7 +187,7 @@ static int __init cpuid_init(void)
        }
        for_each_online_cpu(i) {
                err = cpuid_device_create(i);
-               if (err != 0) 
+               if (err != 0)
                        goto out_class;
        }
        register_hotcpu_notifier(&cpuid_class_cpu_notifier);
@@ -208,7 +202,7 @@ out_class:
        }
        class_destroy(cpuid_class);
 out_chrdev:
-       unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");    
+       unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
 out:
        return err;
 }
index 1411324a625ca5ae0060d49afbdbc897b9e70c68..32dd62b36ff7e200807d1e8ea20651651bd41a9b 100644 (file)
@@ -379,11 +379,9 @@ void __init efi_init(void)
 #endif
 }
 
-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
 static void __init runtime_code_page_mkexec(void)
 {
        efi_memory_desc_t *md;
-       unsigned long end;
        void *p;
 
        if (!(__supported_pte_mask & _PAGE_NX))
@@ -392,18 +390,13 @@ static void __init runtime_code_page_mkexec(void)
        /* Make EFI runtime service code area executable */
        for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
                md = p;
-               end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
-               if (md->type == EFI_RUNTIME_SERVICES_CODE &&
-                   (end >> PAGE_SHIFT) <= max_pfn_mapped) {
-                       set_memory_x(md->virt_addr, md->num_pages);
-                       set_memory_uc(md->virt_addr, md->num_pages);
-               }
+
+               if (md->type != EFI_RUNTIME_SERVICES_CODE)
+                       continue;
+
+               set_memory_x(md->virt_addr, md->num_pages << EFI_PAGE_SHIFT);
        }
-       __flush_tlb_all();
 }
-#else
-static inline void __init runtime_code_page_mkexec(void) { }
-#endif
 
 /*
  * This function will switch the EFI runtime services to virtual mode.
@@ -417,30 +410,40 @@ void __init efi_enter_virtual_mode(void)
 {
        efi_memory_desc_t *md;
        efi_status_t status;
-       unsigned long end;
-       void *p;
+       unsigned long size;
+       u64 end, systab;
+       void *p, *va;
 
        efi.systab = NULL;
        for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
                md = p;
                if (!(md->attribute & EFI_MEMORY_RUNTIME))
                        continue;
-               end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
-               if ((md->attribute & EFI_MEMORY_WB) &&
-                   ((end >> PAGE_SHIFT) <= max_pfn_mapped))
-                       md->virt_addr = (unsigned long)__va(md->phys_addr);
+
+               size = md->num_pages << EFI_PAGE_SHIFT;
+               end = md->phys_addr + size;
+
+               if ((end >> PAGE_SHIFT) <= max_pfn_mapped)
+                       va = __va(md->phys_addr);
                else
-                       md->virt_addr = (unsigned long)
-                               efi_ioremap(md->phys_addr,
-                                           md->num_pages << EFI_PAGE_SHIFT);
-               if (!md->virt_addr)
+                       va = efi_ioremap(md->phys_addr, size);
+
+               if (md->attribute & EFI_MEMORY_WB)
+                       set_memory_uc(md->virt_addr, size);
+
+               md->virt_addr = (u64) (unsigned long) va;
+
+               if (!va) {
                        printk(KERN_ERR PFX "ioremap of 0x%llX failed!\n",
                               (unsigned long long)md->phys_addr);
-               if ((md->phys_addr <= (unsigned long)efi_phys.systab) &&
-                   ((unsigned long)efi_phys.systab < end))
-                       efi.systab = (efi_system_table_t *)(unsigned long)
-                               (md->virt_addr - md->phys_addr +
-                                (unsigned long)efi_phys.systab);
+                       continue;
+               }
+
+               systab = (u64) (unsigned long) efi_phys.systab;
+               if (md->phys_addr <= systab && systab < end) {
+                       systab += md->virt_addr - md->phys_addr;
+                       efi.systab = (efi_system_table_t *) (unsigned long) systab;
+               }
        }
 
        BUG_ON(!efi.systab);
index 674f2379480f99123aafef01ac0d4e34e5e330ee..09d5c23309342779ca955e641a408657a7395ec8 100644 (file)
@@ -54,10 +54,10 @@ static void __init early_mapping_set_exec(unsigned long start,
                else
                        set_pte(kpte, __pte((pte_val(*kpte) | _PAGE_NX) & \
                                            __supported_pte_mask));
-               if (level == 4)
-                       start = (start + PMD_SIZE) & PMD_MASK;
-               else
+               if (level == PG_LEVEL_4K)
                        start = (start + PAGE_SIZE) & PAGE_MASK;
+               else
+                       start = (start + PMD_SIZE) & PMD_MASK;
        }
 }
 
@@ -109,23 +109,23 @@ void __init efi_reserve_bootmem(void)
                                memmap.nr_map * memmap.desc_size);
 }
 
-void __iomem * __init efi_ioremap(unsigned long offset,
-                                 unsigned long size)
+void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size)
 {
        static unsigned pages_mapped;
-       unsigned long last_addr;
        unsigned i, pages;
 
-       last_addr = offset + size - 1;
-       offset &= PAGE_MASK;
-       pages = (PAGE_ALIGN(last_addr) - offset) >> PAGE_SHIFT;
+       /* phys_addr and size must be page aligned */
+       if ((phys_addr & ~PAGE_MASK) || (size & ~PAGE_MASK))
+               return NULL;
+
+       pages = size >> PAGE_SHIFT;
        if (pages_mapped + pages > MAX_EFI_IO_PAGES)
                return NULL;
 
        for (i = 0; i < pages; i++) {
                __set_fixmap(FIX_EFI_IO_MAP_FIRST_PAGE - pages_mapped,
-                            offset, PAGE_KERNEL_EXEC_NOCACHE);
-               offset += PAGE_SIZE;
+                            phys_addr, PAGE_KERNEL);
+               phys_addr += PAGE_SIZE;
                pages_mapped++;
        }
 
index bea8474744ffb633ad2d367bc478ec8cae3fb962..c7341e81941cc0e7d6863e317953316c2f045392 100644 (file)
@@ -582,7 +582,6 @@ retint_restore_args:        /* return to kernel space */
        TRACE_IRQS_IRETQ
 restore_args:
        RESTORE_ARGS 0,8,0                                              
-iret_label:    
 #ifdef CONFIG_PARAVIRT
        INTERRUPT_RETURN
 #endif
@@ -593,13 +592,22 @@ ENTRY(native_iret)
        .quad native_iret, bad_iret
        .previous
        .section .fixup,"ax"
-       /* force a signal here? this matches i386 behaviour */
-       /* running with kernel gs */
 bad_iret:
-       movq $11,%rdi   /* SIGSEGV */
-       TRACE_IRQS_ON
-       ENABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))
-       jmp do_exit
+       /*
+        * The iret traps when the %cs or %ss being restored is bogus.
+        * We've lost the original trap vector and error code.
+        * #GPF is the most likely one to get for an invalid selector.
+        * So pretend we completed the iret and took the #GPF in user mode.
+        *
+        * We are now running with the kernel GS after exception recovery.
+        * But error_entry expects us to have user GS to match the user %cs,
+        * so swap back.
+        */
+       pushq $0
+
+       SWAPGS
+       jmp general_protection
+
        .previous
 
        /* edi: workmask, edx: work */
@@ -911,7 +919,7 @@ error_kernelspace:
           iret run with kernel gs again, so don't set the user space flag.
           B stepping K8s sometimes report an truncated RIP for IRET 
           exceptions returning to compat mode. Check for these here too. */
-       leaq iret_label(%rip),%rbp
+       leaq native_iret(%rip),%rbp
        cmpq %rbp,RIP(%rsp) 
        je   error_swapgs
        movl %ebp,%ebp  /* zero extend */
index 1d5a7a361200b69e28e61294ce7e45b75e6ba659..09b38d539b09deb0874029b2e28fb7d5b7d2418f 100644 (file)
@@ -63,7 +63,7 @@ startup_64:
 
        /* Is the address not 2M aligned? */
        movq    %rbp, %rax
-       andl    $~LARGE_PAGE_MASK, %eax
+       andl    $~PMD_PAGE_MASK, %eax
        testl   %eax, %eax
        jnz     bad_address
 
@@ -88,7 +88,7 @@ startup_64:
 
        /* Add an Identity mapping if I am above 1G */
        leaq    _text(%rip), %rdi
-       andq    $LARGE_PAGE_MASK, %rdi
+       andq    $PMD_PAGE_MASK, %rdi
 
        movq    %rdi, %rax
        shrq    $PUD_SHIFT, %rax
@@ -250,18 +250,13 @@ ENTRY(secondary_startup_64)
        lretq
 
        /* SMP bootup changes these two */
-#ifndef CONFIG_HOTPLUG_CPU
-       .pushsection .init.data
-#endif
+       __CPUINITDATA
        .align  8
-       .globl  initial_code
-initial_code:
+       ENTRY(initial_code)
        .quad   x86_64_start_kernel
-#ifndef CONFIG_HOTPLUG_CPU
-       .popsection
-#endif
-       .globl init_rsp
-init_rsp:
+       __FINITDATA
+
+       ENTRY(init_rsp)
        .quad  init_thread_union+THREAD_SIZE-8
 
 bad_address:
index 8a7660c8394a5a2ae2362e6d3d4ec032d5def37e..0224c3637c73e68b4566124dd5d825034bc8c07a 100644 (file)
@@ -35,7 +35,8 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
        if (mincount <= pc->size)
                return 0;
        oldsize = pc->size;
-       mincount = (mincount + 511) & (~511);
+       mincount = (mincount + (PAGE_SIZE / LDT_ENTRY_SIZE - 1)) &
+                       (~(PAGE_SIZE / LDT_ENTRY_SIZE - 1));
        if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
                newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
        else
index bd82850e6519b8a51d2c2a68512a7b492d864229..af51ea8400b2de88509efab5ad3df145f2ccab08 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
- *   
- *   Copyright 2000 H. Peter Anvin - All Rights Reserved
+ *
+ *   Copyright 2000-2008 H. Peter Anvin - All Rights Reserved
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -45,9 +45,10 @@ static struct class *msr_class;
 
 static loff_t msr_seek(struct file *file, loff_t offset, int orig)
 {
-       loff_t ret = -EINVAL;
+       loff_t ret;
+       struct inode *inode = file->f_mapping->host;
 
-       lock_kernel();
+       mutex_lock(&inode->i_mutex);
        switch (orig) {
        case 0:
                file->f_pos = offset;
@@ -56,8 +57,11 @@ static loff_t msr_seek(struct file *file, loff_t offset, int orig)
        case 1:
                file->f_pos += offset;
                ret = file->f_pos;
+               break;
+       default:
+               ret = -EINVAL;
        }
-       unlock_kernel();
+       mutex_unlock(&inode->i_mutex);
        return ret;
 }
 
index 1fe7f043ebdee5d4d94c0b5e8bf0a54cdf87f2e8..1b5464c2434f2fbe115816a6603fc3434dd55b96 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/pci.h>
 #include <linux/delay.h>
 #include <linux/scatterlist.h>
+#include <linux/iommu-helper.h>
 #include <asm/gart.h>
 #include <asm/calgary.h>
 #include <asm/tce.h>
@@ -260,22 +261,28 @@ static void iommu_range_reserve(struct iommu_table *tbl,
        spin_unlock_irqrestore(&tbl->it_lock, flags);
 }
 
-static unsigned long iommu_range_alloc(struct iommu_table *tbl,
-       unsigned int npages)
+static unsigned long iommu_range_alloc(struct device *dev,
+                                      struct iommu_table *tbl,
+                                      unsigned int npages)
 {
        unsigned long flags;
        unsigned long offset;
+       unsigned long boundary_size;
+
+       boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
+                             PAGE_SIZE) >> PAGE_SHIFT;
 
        BUG_ON(npages == 0);
 
        spin_lock_irqsave(&tbl->it_lock, flags);
 
-       offset = find_next_zero_string(tbl->it_map, tbl->it_hint,
-                                      tbl->it_size, npages);
+       offset = iommu_area_alloc(tbl->it_map, tbl->it_size, tbl->it_hint,
+                                 npages, 0, boundary_size, 0);
        if (offset == ~0UL) {
                tbl->chip_ops->tce_cache_blast(tbl);
-               offset = find_next_zero_string(tbl->it_map, 0,
-                                              tbl->it_size, npages);
+
+               offset = iommu_area_alloc(tbl->it_map, tbl->it_size, 0,
+                                         npages, 0, boundary_size, 0);
                if (offset == ~0UL) {
                        printk(KERN_WARNING "Calgary: IOMMU full.\n");
                        spin_unlock_irqrestore(&tbl->it_lock, flags);
@@ -286,7 +293,6 @@ static unsigned long iommu_range_alloc(struct iommu_table *tbl,
                }
        }
 
-       set_bit_string(tbl->it_map, offset, npages);
        tbl->it_hint = offset + npages;
        BUG_ON(tbl->it_hint > tbl->it_size);
 
@@ -295,13 +301,13 @@ static unsigned long iommu_range_alloc(struct iommu_table *tbl,
        return offset;
 }
 
-static dma_addr_t iommu_alloc(struct iommu_table *tbl, void *vaddr,
-       unsigned int npages, int direction)
+static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
+                             void *vaddr, unsigned int npages, int direction)
 {
        unsigned long entry;
        dma_addr_t ret = bad_dma_address;
 
-       entry = iommu_range_alloc(tbl, npages);
+       entry = iommu_range_alloc(dev, tbl, npages);
 
        if (unlikely(entry == bad_dma_address))
                goto error;
@@ -354,7 +360,7 @@ static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
                               badbit, tbl, dma_addr, entry, npages);
        }
 
-       __clear_bit_string(tbl->it_map, entry, npages);
+       iommu_area_free(tbl->it_map, entry, npages);
 
        spin_unlock_irqrestore(&tbl->it_lock, flags);
 }
@@ -438,7 +444,7 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
                vaddr = (unsigned long) sg_virt(s);
                npages = num_dma_pages(vaddr, s->length);
 
-               entry = iommu_range_alloc(tbl, npages);
+               entry = iommu_range_alloc(dev, tbl, npages);
                if (entry == bad_dma_address) {
                        /* makes sure unmap knows to stop */
                        s->dma_length = 0;
@@ -476,7 +482,7 @@ static dma_addr_t calgary_map_single(struct device *dev, void *vaddr,
        npages = num_dma_pages(uaddr, size);
 
        if (translation_enabled(tbl))
-               dma_handle = iommu_alloc(tbl, vaddr, npages, direction);
+               dma_handle = iommu_alloc(dev, tbl, vaddr, npages, direction);
        else
                dma_handle = virt_to_bus(vaddr);
 
@@ -516,7 +522,7 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size,
 
        if (translation_enabled(tbl)) {
                /* set up tces to cover the allocated range */
-               mapping = iommu_alloc(tbl, ret, npages, DMA_BIDIRECTIONAL);
+               mapping = iommu_alloc(dev, tbl, ret, npages, DMA_BIDIRECTIONAL);
                if (mapping == bad_dma_address)
                        goto free;
 
index 4d5cc718198229eda0913fa5a19c6d417fa6589e..65f6acb025c8833dc8183991bb313e52e3cff9ec 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/bitops.h>
 #include <linux/kdebug.h>
 #include <linux/scatterlist.h>
+#include <linux/iommu-helper.h>
 #include <asm/atomic.h>
 #include <asm/io.h>
 #include <asm/mtrr.h>
@@ -82,17 +83,24 @@ AGPEXTERN __u32 *agp_gatt_table;
 static unsigned long next_bit;  /* protected by iommu_bitmap_lock */
 static int need_flush;         /* global flush state. set for each gart wrap */
 
-static unsigned long alloc_iommu(int size)
+static unsigned long alloc_iommu(struct device *dev, int size)
 {
        unsigned long offset, flags;
+       unsigned long boundary_size;
+       unsigned long base_index;
+
+       base_index = ALIGN(iommu_bus_base & dma_get_seg_boundary(dev),
+                          PAGE_SIZE) >> PAGE_SHIFT;
+       boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
+                             PAGE_SIZE) >> PAGE_SHIFT;
 
        spin_lock_irqsave(&iommu_bitmap_lock, flags);
-       offset = find_next_zero_string(iommu_gart_bitmap, next_bit,
-                                       iommu_pages, size);
+       offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, next_bit,
+                                 size, base_index, boundary_size, 0);
        if (offset == -1) {
                need_flush = 1;
-               offset = find_next_zero_string(iommu_gart_bitmap, 0,
-                                               iommu_pages, size);
+               offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, 0,
+                                         size, base_index, boundary_size, 0);
        }
        if (offset != -1) {
                set_bit_string(iommu_gart_bitmap, offset, size);
@@ -114,7 +122,7 @@ static void free_iommu(unsigned long offset, int size)
        unsigned long flags;
 
        spin_lock_irqsave(&iommu_bitmap_lock, flags);
-       __clear_bit_string(iommu_gart_bitmap, offset, size);
+       iommu_area_free(iommu_gart_bitmap, offset, size);
        spin_unlock_irqrestore(&iommu_bitmap_lock, flags);
 }
 
@@ -235,7 +243,7 @@ static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
                                size_t size, int dir)
 {
        unsigned long npages = to_pages(phys_mem, size);
-       unsigned long iommu_page = alloc_iommu(npages);
+       unsigned long iommu_page = alloc_iommu(dev, npages);
        int i;
 
        if (iommu_page == -1) {
@@ -355,10 +363,11 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg,
 }
 
 /* Map multiple scatterlist entries continuous into the first. */
-static int __dma_map_cont(struct scatterlist *start, int nelems,
-                         struct scatterlist *sout, unsigned long pages)
+static int __dma_map_cont(struct device *dev, struct scatterlist *start,
+                         int nelems, struct scatterlist *sout,
+                         unsigned long pages)
 {
-       unsigned long iommu_start = alloc_iommu(pages);
+       unsigned long iommu_start = alloc_iommu(dev, pages);
        unsigned long iommu_page = iommu_start;
        struct scatterlist *s;
        int i;
@@ -394,8 +403,8 @@ static int __dma_map_cont(struct scatterlist *start, int nelems,
 }
 
 static inline int
-dma_map_cont(struct scatterlist *start, int nelems, struct scatterlist *sout,
-            unsigned long pages, int need)
+dma_map_cont(struct device *dev, struct scatterlist *start, int nelems,
+            struct scatterlist *sout, unsigned long pages, int need)
 {
        if (!need) {
                BUG_ON(nelems != 1);
@@ -403,7 +412,7 @@ dma_map_cont(struct scatterlist *start, int nelems, struct scatterlist *sout,
                sout->dma_length = start->length;
                return 0;
        }
-       return __dma_map_cont(start, nelems, sout, pages);
+       return __dma_map_cont(dev, start, nelems, sout, pages);
 }
 
 /*
@@ -416,6 +425,8 @@ gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
        struct scatterlist *s, *ps, *start_sg, *sgmap;
        int need = 0, nextneed, i, out, start;
        unsigned long pages = 0;
+       unsigned int seg_size;
+       unsigned int max_seg_size;
 
        if (nents == 0)
                return 0;
@@ -426,6 +437,8 @@ gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
        out = 0;
        start = 0;
        start_sg = sgmap = sg;
+       seg_size = 0;
+       max_seg_size = dma_get_max_seg_size(dev);
        ps = NULL; /* shut up gcc */
        for_each_sg(sg, s, nents, i) {
                dma_addr_t addr = sg_phys(s);
@@ -443,11 +456,13 @@ gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
                         * offset.
                         */
                        if (!iommu_merge || !nextneed || !need || s->offset ||
+                           (s->length + seg_size > max_seg_size) ||
                            (ps->offset + ps->length) % PAGE_SIZE) {
-                               if (dma_map_cont(start_sg, i - start, sgmap,
-                                                 pages, need) < 0)
+                               if (dma_map_cont(dev, start_sg, i - start,
+                                                sgmap, pages, need) < 0)
                                        goto error;
                                out++;
+                               seg_size = 0;
                                sgmap = sg_next(sgmap);
                                pages = 0;
                                start = i;
@@ -455,11 +470,12 @@ gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
                        }
                }
 
+               seg_size += s->length;
                need = nextneed;
                pages += to_pages(s->offset, s->length);
                ps = s;
        }
-       if (dma_map_cont(start_sg, i - start, sgmap, pages, need) < 0)
+       if (dma_map_cont(dev, start_sg, i - start, sgmap, pages, need) < 0)
                goto error;
        out++;
        flush_gart();
@@ -501,7 +517,7 @@ static __init unsigned long check_iommu_size(unsigned long aper, u64 aper_size)
        }
 
        a = aper + iommu_size;
-       iommu_size -= round_up(a, LARGE_PAGE_SIZE) - a;
+       iommu_size -= round_up(a, PMD_PAGE_SIZE) - a;
 
        if (iommu_size < 64*1024*1024) {
                printk(KERN_WARNING
@@ -731,7 +747,8 @@ void __init gart_iommu_init(void)
         * the backing memory. The GART address is only used by PCI
         * devices.
         */
-       clear_kernel_mapping((unsigned long)__va(iommu_bus_base), iommu_size);
+       set_memory_np((unsigned long)__va(iommu_bus_base),
+                               iommu_size >> PAGE_SHIFT);
 
        /*
         * Try to workaround a bug (thanks to BenH)
index 968371ab223a250b59117d4fad4df43c247c104a..dabdbeff1f778685af46cb66b465ec0e36c71a02 100644 (file)
@@ -251,7 +251,7 @@ void cpu_idle_wait(void)
                 * because it has nothing to do.
                 * Give all the remaining CPUS a kick.
                 */
-               smp_call_function_mask(map, do_nothing, 0, 0);
+               smp_call_function_mask(map, do_nothing, NULL, 0);
        } while (!cpus_empty(map));
 
        set_cpus_allowed(current, tmp);
index 96286df1bb817fff6e314fead079d40c0cb29f6c..702c33efea84dfad40b15d62cd7775958d653979 100644 (file)
@@ -103,9 +103,26 @@ static int set_segment_reg(struct task_struct *task,
        if (invalid_selector(value))
                return -EIO;
 
-       if (offset != offsetof(struct user_regs_struct, gs))
+       /*
+        * For %cs and %ss we cannot permit a null selector.
+        * We can permit a bogus selector as long as it has USER_RPL.
+        * Null selectors are fine for other segment registers, but
+        * we will never get back to user mode with invalid %cs or %ss
+        * and will take the trap in iret instead.  Much code relies
+        * on user_mode() to distinguish a user trap frame (which can
+        * safely use invalid selectors) from a kernel trap frame.
+        */
+       switch (offset) {
+       case offsetof(struct user_regs_struct, cs):
+       case offsetof(struct user_regs_struct, ss):
+               if (unlikely(value == 0))
+                       return -EIO;
+
+       default:
                *pt_regs_access(task_pt_regs(task), offset) = value;
-       else {
+               break;
+
+       case offsetof(struct user_regs_struct, gs):
                task->thread.gs = value;
                if (task == current)
                        /*
@@ -227,12 +244,16 @@ static int set_segment_reg(struct task_struct *task,
                 * Can't actually change these in 64-bit mode.
                 */
        case offsetof(struct user_regs_struct,cs):
+               if (unlikely(value == 0))
+                       return -EIO;
 #ifdef CONFIG_IA32_EMULATION
                if (test_tsk_thread_flag(task, TIF_IA32))
                        task_pt_regs(task)->cs = value;
 #endif
                break;
        case offsetof(struct user_regs_struct,ss):
+               if (unlikely(value == 0))
+                       return -EIO;
 #ifdef CONFIG_IA32_EMULATION
                if (test_tsk_thread_flag(task, TIF_IA32))
                        task_pt_regs(task)->ss = value;
index 150ba29a0d331a486e2cea33c3ce3d4aec1464d7..6ba33ca8715abc3e925debf55797b0834aee1a38 100644 (file)
@@ -30,8 +30,8 @@ static void __devinit quirk_intel_irqbalance(struct pci_dev *dev)
        raw_pci_ops->read(0, 0, 0x40, 0x4c, 2, &word);
 
        if (!(word & (1 << 13))) {
-               printk(KERN_INFO "Intel E7520/7320/7525 detected. "
-                       "Disabling irq balancing and affinity\n");
+               dev_info(&dev->dev, "Intel E7520/7320/7525 detected; "
+                       "disabling irq balancing and affinity\n");
 #ifdef CONFIG_IRQBALANCE
                irqbalance_disable("");
 #endif
@@ -104,14 +104,16 @@ static void ich_force_enable_hpet(struct pci_dev *dev)
        pci_read_config_dword(dev, 0xF0, &rcba);
        rcba &= 0xFFFFC000;
        if (rcba == 0) {
-               printk(KERN_DEBUG "RCBA disabled. Cannot force enable HPET\n");
+               dev_printk(KERN_DEBUG, &dev->dev, "RCBA disabled; "
+                       "cannot force enable HPET\n");
                return;
        }
 
        /* use bits 31:14, 16 kB aligned */
        rcba_base = ioremap_nocache(rcba, 0x4000);
        if (rcba_base == NULL) {
-               printk(KERN_DEBUG "ioremap failed. Cannot force enable HPET\n");
+               dev_printk(KERN_DEBUG, &dev->dev, "ioremap failed; "
+                       "cannot force enable HPET\n");
                return;
        }
 
@@ -122,8 +124,8 @@ static void ich_force_enable_hpet(struct pci_dev *dev)
                /* HPET is enabled in HPTC. Just not reported by BIOS */
                val = val & 0x3;
                force_hpet_address = 0xFED00000 | (val << 12);
-               printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
-                              force_hpet_address);
+               dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
+                       "0x%lx\n", force_hpet_address);
                iounmap(rcba_base);
                return;
        }
@@ -142,11 +144,12 @@ static void ich_force_enable_hpet(struct pci_dev *dev)
        if (err) {
                force_hpet_address = 0;
                iounmap(rcba_base);
-               printk(KERN_DEBUG "Failed to force enable HPET\n");
+               dev_printk(KERN_DEBUG, &dev->dev,
+                       "Failed to force enable HPET\n");
        } else {
                force_hpet_resume_type = ICH_FORCE_HPET_RESUME;
-               printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
-                              force_hpet_address);
+               dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
+                       "0x%lx\n", force_hpet_address);
        }
 }
 
@@ -208,8 +211,8 @@ static void old_ich_force_enable_hpet(struct pci_dev *dev)
        if (val & 0x4) {
                val &= 0x3;
                force_hpet_address = 0xFED00000 | (val << 12);
-               printk(KERN_DEBUG "HPET at base address 0x%lx\n",
-                              force_hpet_address);
+               dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
+                       force_hpet_address);
                return;
        }
 
@@ -229,14 +232,14 @@ static void old_ich_force_enable_hpet(struct pci_dev *dev)
                /* HPET is enabled in HPTC. Just not reported by BIOS */
                val &= 0x3;
                force_hpet_address = 0xFED00000 | (val << 12);
-               printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
-                              force_hpet_address);
+               dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
+                       "0x%lx\n", force_hpet_address);
                cached_dev = dev;
                force_hpet_resume_type = OLD_ICH_FORCE_HPET_RESUME;
                return;
        }
 
-       printk(KERN_DEBUG "Failed to force enable HPET\n");
+       dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
 }
 
 /*
@@ -294,8 +297,8 @@ static void vt8237_force_enable_hpet(struct pci_dev *dev)
         */
        if (val & 0x80) {
                force_hpet_address = (val & ~0x3ff);
-               printk(KERN_DEBUG "HPET at base address 0x%lx\n",
-                              force_hpet_address);
+               dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
+                       force_hpet_address);
                return;
        }
 
@@ -309,14 +312,14 @@ static void vt8237_force_enable_hpet(struct pci_dev *dev)
        pci_read_config_dword(dev, 0x68, &val);
        if (val & 0x80) {
                force_hpet_address = (val & ~0x3ff);
-               printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
-                              force_hpet_address);
+               dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
+                       "0x%lx\n", force_hpet_address);
                cached_dev = dev;
                force_hpet_resume_type = VT8237_FORCE_HPET_RESUME;
                return;
        }
 
-       printk(KERN_DEBUG "Failed to force enable HPET\n");
+       dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
 }
 
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235,
@@ -344,7 +347,7 @@ static void nvidia_force_enable_hpet(struct pci_dev *dev)
        pci_read_config_dword(dev, 0x44, &val);
        force_hpet_address = val & 0xfffffffe;
        force_hpet_resume_type = NVIDIA_FORCE_HPET_RESUME;
-       printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
+       dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
                force_hpet_address);
        cached_dev = dev;
        return;
@@ -377,19 +380,19 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0367,
 void force_hpet_resume(void)
 {
        switch (force_hpet_resume_type) {
-           case ICH_FORCE_HPET_RESUME:
-               return ich_force_hpet_resume();
-
-           case OLD_ICH_FORCE_HPET_RESUME:
-               return old_ich_force_hpet_resume();
-
-           case VT8237_FORCE_HPET_RESUME:
-               return vt8237_force_hpet_resume();
-
-           case NVIDIA_FORCE_HPET_RESUME:
-               return nvidia_force_hpet_resume();
-
-           default:
+       case ICH_FORCE_HPET_RESUME:
+               ich_force_hpet_resume();
+               return;
+       case OLD_ICH_FORCE_HPET_RESUME:
+               old_ich_force_hpet_resume();
+               return;
+       case VT8237_FORCE_HPET_RESUME:
+               vt8237_force_hpet_resume();
+               return;
+       case NVIDIA_FORCE_HPET_RESUME:
+               nvidia_force_hpet_resume();
+               return;
+       default:
                break;
        }
 }
index 18df70c534b968a153d12ea5eff3ce339650e4a0..c8939dfddfba3c0f7bdd63e3d21d6d38e67712fc 100644 (file)
@@ -1068,82 +1068,6 @@ static int show_cpuinfo(struct seq_file *m, void *v)
        struct cpuinfo_x86 *c = v;
        int cpu = 0, i;
 
-       /*
-        * These flag bits must match the definitions in <asm/cpufeature.h>.
-        * NULL means this bit is undefined or reserved; either way it doesn't
-        * have meaning as far as Linux is concerned.  Note that it's important
-        * to realize there is a difference between this table and CPUID -- if
-        * applications want to get the raw CPUID data, they should access
-        * /dev/cpu/<cpu_nr>/cpuid instead.
-        */
-       static const char *const x86_cap_flags[] = {
-               /* Intel-defined */
-               "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
-               "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
-               "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
-               "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", "pbe",
-
-               /* AMD-defined */
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
-               NULL, "fxsr_opt", "pdpe1gb", "rdtscp", NULL, "lm",
-               "3dnowext", "3dnow",
-
-               /* Transmeta-defined */
-               "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* Other (Linux-defined) */
-               "cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr",
-               NULL, NULL, NULL, NULL,
-               "constant_tsc", "up", NULL, "arch_perfmon",
-               "pebs", "bts", NULL, "sync_rdtsc",
-               "rep_good", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* Intel-defined (#2) */
-               "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
-               "tm2", "ssse3", "cid", NULL, NULL, "cx16", "xtpr", NULL,
-               NULL, NULL, "dca", "sse4_1", "sse4_2", NULL, NULL, "popcnt",
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* VIA/Cyrix/Centaur-defined */
-               NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
-               "ace2", "ace2_en", "phe", "phe_en", "pmm", "pmm_en", NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* AMD-defined (#2) */
-               "lahf_lm", "cmp_legacy", "svm", "extapic",
-               "cr8_legacy", "abm", "sse4a", "misalignsse",
-               "3dnowprefetch", "osvw", "ibs", "sse5",
-               "skinit", "wdt", NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-
-               /* Auxiliary (Linux-defined) */
-               "ida", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-       };
-       static const char *const x86_power_flags[] = {
-               "ts",   /* temperature sensor */
-               "fid",  /* frequency id control */
-               "vid",  /* voltage id control */
-               "ttp",  /* thermal trip */
-               "tm",
-               "stc",
-               "100mhzsteps",
-               "hwpstate",
-               "",     /* tsc invariant mapped to constant_tsc */
-               /* nothing */
-       };
-
-
 #ifdef CONFIG_SMP
        cpu = c->cpu_index;
 #endif
index 5787a0c3e2960919f6dc82f0b034a5ba1d19735c..579b9b740c7c79326c079440cda33341b3ba6472 100644 (file)
@@ -202,8 +202,6 @@ valid_k7:
        ;
 }
 
-extern void calibrate_delay(void);
-
 static atomic_t init_deasserted;
 
 static void __cpuinit smp_callin(void)
index 09199511c25623057b8f3c60c96069c646ee27b8..7ac7130022f1a73926a392ee2a83d1c366d29164 100644 (file)
@@ -140,7 +140,12 @@ static void fix_processor_context(void)
        int cpu = smp_processor_id();
        struct tss_struct *t = &per_cpu(init_tss, cpu);
 
-       set_tss_desc(cpu,t);    /* This just modifies memory; should not be necessary. But... This is necessary, because 386 hardware has concept of busy TSS or some similar stupidity. */
+       /*
+        * This just modifies memory; should not be necessary. But... This
+        * is necessary, because 386 hardware has concept of busy TSS or some
+        * similar stupidity.
+        */
+       set_tss_desc(cpu, t);
 
        get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
 
@@ -160,7 +165,6 @@ static void fix_processor_context(void)
                 loaddebug(&current->thread, 6);
                 loaddebug(&current->thread, 7);
        }
-
 }
 
 #ifdef CONFIG_HIBERNATION
index 8344c70adf615264bc509a9d6e6f959a72b771d4..adff5562f5fd4bbc40965ba8eb5f33d433f9f776 100644 (file)
@@ -321,6 +321,8 @@ ENTRY(sys_call_table)
        .long sys_epoll_pwait
        .long sys_utimensat             /* 320 */
        .long sys_signalfd
-       .long sys_timerfd
+       .long sys_timerfd_create
        .long sys_eventfd
        .long sys_fallocate
+       .long sys_timerfd_settime       /* 325 */
+       .long sys_timerfd_gettime
index ae0ef2e304c72e60ff218fed26080f5645a7d029..10b8a6f69f84d51348827655903580cdfa6a5e93 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/sort.h>
 #include <asm/uaccess.h>
+#include <asm/asm.h>
 
 extern int rodata_test_data;
 
@@ -89,16 +90,7 @@ static noinline int test_address(void *address)
                "2:     mov %[zero], %[rslt]\n"
                "       ret\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 8\n"
-#ifdef CONFIG_X86_32
-               "       .long 0b\n"
-               "       .long 2b\n"
-#else
-               "       .quad 0b\n"
-               "       .quad 2b\n"
-#endif
-               ".previous\n"
+               _ASM_EXTABLE(0b,2b)
                : [rslt] "=r" (result)
                : [fake_code] "r" (address), [zero] "r" (0UL), "0" (result)
        );
@@ -147,7 +139,6 @@ static int test_NX(void)
         * Until then, don't run them to avoid too many people getting scared
         * by the error message
         */
-#if 0
 
 #ifdef CONFIG_DEBUG_RODATA
        /* Test 3: Check if the .rodata section is executable */
@@ -160,6 +151,7 @@ static int test_NX(void)
        }
 #endif
 
+#if 0
        /* Test 4: Check if the .data section of a module is executable */
        if (test_address(&test_data)) {
                printk(KERN_ERR "test_nx: .data section is executable\n");
index 9bcc1c6aca3d6b08ac916bd93e9482b128a1074b..64580679861e60371112b9d032d51f6d87c04a96 100644 (file)
  *     trampoline page to make our stack and everything else
  *     is a mystery.
  *
- *     In fact we don't actually need a stack so we don't
- *     set one up.
- *
- *     We jump into the boot/compressed/head.S code. So you'd
- *     better be running a compressed kernel image or you
- *     won't get very far.
+ *     We jump into arch/x86/kernel/head_32.S.
  *
  *     On entry to trampoline_data, the processor is in real mode
  *     with 16-bit addressing and 16-bit data.  CS has some value
index e30b67c6a9f5ddabb5893bef7dd62b07df0239a9..4aedd0bcee4cf58162a7c1296aee4b9bd9691687 100644 (file)
@@ -10,9 +10,6 @@
  *     trampoline page to make our stack and everything else
  *     is a mystery.
  *
- *     In fact we don't actually need a stack so we don't
- *     set one up.
- *
  *     On entry to trampoline_data, the processor is in real mode
  *     with 16-bit addressing and 16-bit data.  CS has some value
  *     and IP is zero.  Thus, data addresses need to be absolute
index 3cf72977d01292bbea4492568d85277a8ba6680f..b22c01e05a1841d4a3960a2e62a2881ee9c5babc 100644 (file)
@@ -1176,17 +1176,12 @@ void __init trap_init(void)
 #endif
        set_trap_gate(19,&simd_coprocessor_error);
 
+       /*
+        * Verify that the FXSAVE/FXRSTOR data will be 16-byte aligned.
+        * Generate a build-time error if the alignment is wrong.
+        */
+       BUILD_BUG_ON(offsetof(struct task_struct, thread.i387.fxsave) & 15);
        if (cpu_has_fxsr) {
-               /*
-                * Verify that the FXSAVE/FXRSTOR data will be 16-byte aligned.
-                * Generates a compile-time "error: zero width for bit-field" if
-                * the alignment is wrong.
-                */
-               struct fxsrAlignAssert {
-                       int _:!(offsetof(struct task_struct,
-                                       thread.i387.fxsave) & 15);
-               };
-
                printk(KERN_INFO "Enabling fast FPU save and restore... ");
                set_in_cr4(X86_CR4_OSFXSR);
                printk("done.\n");
index 4525bc2c2e19bd88fe00f1b399f2a05efa29454f..12affe1f9bce8d7da1a872880bf41e581e3281c7 100644 (file)
@@ -220,21 +220,21 @@ static void vmi_set_tr(void)
 static void vmi_write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
 {
        u32 *idt_entry = (u32 *)g;
-       vmi_ops.write_idt_entry(dt, entry, idt_entry[0], idt_entry[2]);
+       vmi_ops.write_idt_entry(dt, entry, idt_entry[0], idt_entry[1]);
 }
 
 static void vmi_write_gdt_entry(struct desc_struct *dt, int entry,
                                const void *desc, int type)
 {
        u32 *gdt_entry = (u32 *)desc;
-       vmi_ops.write_gdt_entry(dt, entry, gdt_entry[0], gdt_entry[2]);
+       vmi_ops.write_gdt_entry(dt, entry, gdt_entry[0], gdt_entry[1]);
 }
 
 static void vmi_write_ldt_entry(struct desc_struct *dt, int entry,
                                const void *desc)
 {
        u32 *ldt_entry = (u32 *)desc;
-       vmi_ops.write_idt_entry(dt, entry, ldt_entry[0], ldt_entry[2]);
+       vmi_ops.write_idt_entry(dt, entry, ldt_entry[0], ldt_entry[1]);
 }
 
 static void vmi_load_sp0(struct tss_struct *tss,
index c83e1c9b5129b3cc96ecfcb8992e378cd7d4119e..41962e793c0fe9f122d22517956535875ea1170f 100644 (file)
@@ -53,5 +53,6 @@ config KVM_AMD
 # OK, it's a little counter-intuitive to do this, but it puts it neatly under
 # the virtualization menu.
 source drivers/lguest/Kconfig
+source drivers/virtio/Kconfig
 
 endif # VIRTUALIZATION
index 8f94a0b89dffd51e5c5387be1b0bb6b1653762bc..cf530814868957a9de8058849538405ca493dcc5 100644 (file)
@@ -1739,7 +1739,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
        if (bytes == 8) {
                gpa_t gpa;
                struct page *page;
-               char *addr;
+               char *kaddr;
                u64 val;
 
                down_read(&current->mm->mmap_sem);
@@ -1754,9 +1754,9 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 
                val = *(u64 *)new;
                page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
-               addr = kmap_atomic(page, KM_USER0);
-               set_64bit((u64 *)(addr + offset_in_page(gpa)), val);
-               kunmap_atomic(addr, KM_USER0);
+               kaddr = kmap_atomic(page, KM_USER0);
+               set_64bit((u64 *)(kaddr + offset_in_page(gpa)), val);
+               kunmap_atomic(kaddr, KM_USER0);
                kvm_release_page_dirty(page);
        emul_write:
                up_read(&current->mm->mmap_sem);
index 4876182daf8a5d1af3bf11516fa6ab2ec0d15283..25df1c1989fe5e5574ba4e833978d99317b168c2 100644 (file)
@@ -21,7 +21,7 @@ else
 
         lib-y += csum-partial_64.o csum-copy_64.o csum-wrappers_64.o
         lib-y += thunk_64.o clear_page_64.o copy_page_64.o
-        lib-y += bitstr_64.o bitops_64.o
+        lib-y += bitops_64.o
         lib-y += memmove_64.o memset_64.o
         lib-y += copy_user_64.o rwlock_64.o copy_user_nocache_64.o
 endif
index afd0045595d470938ef69f6547db0f859b08fbf5..b65440459859e4843ee23a672c05519d2669876b 100644 (file)
@@ -2,7 +2,7 @@
 #include <linux/module.h>
 
 /**
- * find_next_bit - find the first set bit in a memory region
+ * find_next_bit - find the next set bit in a memory region
  * @addr: The address to base the search on
  * @offset: The bitnumber to start searching at
  * @size: The maximum size to search
index 95b6d9639fba60fa9c03c027199bd173f631102b..0e8f491e6ccc84b13ec7c0e82683002f829a862e 100644 (file)
@@ -58,7 +58,7 @@ long find_first_zero_bit(const unsigned long * addr, unsigned long size)
 }
 
 /**
- * find_next_zero_bit - find the first zero bit in a memory region
+ * find_next_zero_bit - find the next zero bit in a memory region
  * @addr: The address to base the search on
  * @offset: The bitnumber to start searching at
  * @size: The maximum size to search
diff --git a/arch/x86/lib/bitstr_64.c b/arch/x86/lib/bitstr_64.c
deleted file mode 100644 (file)
index 7445caf..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <linux/module.h>
-#include <linux/bitops.h>
-
-/* Find string of zero bits in a bitmap */ 
-unsigned long 
-find_next_zero_string(unsigned long *bitmap, long start, long nbits, int len)
-{ 
-       unsigned long n, end, i;        
-
- again:
-       n = find_next_zero_bit(bitmap, nbits, start);
-       if (n == -1) 
-               return -1;
-       
-       /* could test bitsliced, but it's hardly worth it */
-       end = n+len;
-       if (end > nbits)
-               return -1; 
-       for (i = n+1; i < end; i++) { 
-               if (test_bit(i, bitmap)) {  
-                       start = i+1; 
-                       goto again; 
-               } 
-       }
-       return n;
-}
-
-EXPORT_SYMBOL(find_next_zero_string);
index aad9d95469dc68dcb25b9fac93b743d44b7d9038..4535e6d147adb11ffb570a9adcb4e08c6d638130 100644 (file)
 
 #include <linux/module.h>
 #include <linux/sched.h>
+#include <linux/timex.h>
 #include <linux/preempt.h>
 #include <linux/delay.h>
+#include <linux/init.h>
 
 #include <asm/processor.h>
 #include <asm/delay.h>
@@ -63,7 +65,7 @@ void use_tsc_delay(void)
        delay_fn = delay_tsc;
 }
 
-int read_current_timer(unsigned long *timer_val)
+int __devinit read_current_timer(unsigned long *timer_val)
 {
        if (delay_fn == delay_tsc) {
                rdtscl(*timer_val);
index 45cdd3fbd91c514f38e2c2782f7dbc0dcecd8e90..bbc610518516b11c4bdbe1d10dacd29ce41130c6 100644 (file)
 
 #include <linux/module.h>
 #include <linux/sched.h>
+#include <linux/timex.h>
 #include <linux/preempt.h>
 #include <linux/delay.h>
+#include <linux/init.h>
 
 #include <asm/delay.h>
 #include <asm/msr.h>
@@ -20,7 +22,7 @@
 #include <asm/smp.h>
 #endif
 
-int read_current_timer(unsigned long *timer_value)
+int __devinit read_current_timer(unsigned long *timer_value)
 {
        rdtscll(*timer_value);
        return 0;
index 28084d2e8dd4d96f8371a629f206406b05031203..cc9b4a4450f3fe3fc344f34114fc3d9ec4cd4fe4 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/hardirq.h>
 #include <linux/module.h>
 
+#include <asm/asm.h>
 #include <asm/i387.h>
 
 
@@ -50,10 +51,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
                "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
                "   jmp 2b\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 4\n"
-               "       .long 1b, 3b\n"
-               ".previous"
+               _ASM_EXTABLE(1b,3b)
                : : "r" (from) );
                
        
@@ -81,10 +79,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
                "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
                "   jmp 2b\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 4\n"
-               "       .long 1b, 3b\n"
-               ".previous"
+               _ASM_EXTABLE(1b,3b)
                : : "r" (from), "r" (to) : "memory");
                from+=64;
                to+=64;
@@ -181,10 +176,7 @@ static void fast_copy_page(void *to, void *from)
                "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
                "   jmp 2b\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 4\n"
-               "       .long 1b, 3b\n"
-               ".previous"
+               _ASM_EXTABLE(1b,3b)
                : : "r" (from) );
 
        for(i=0; i<(4096-320)/64; i++)
@@ -211,10 +203,7 @@ static void fast_copy_page(void *to, void *from)
                "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
                "   jmp 2b\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 4\n"
-               "       .long 1b, 3b\n"
-               ".previous"
+               _ASM_EXTABLE(1b,3b)
                : : "r" (from), "r" (to) : "memory");
                from+=64;
                to+=64;
@@ -311,10 +300,7 @@ static void fast_copy_page(void *to, void *from)
                "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
                "   jmp 2b\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 4\n"
-               "       .long 1b, 3b\n"
-               ".previous"
+               _ASM_EXTABLE(1b,3b)
                : : "r" (from) );
 
        for(i=0; i<4096/64; i++)
@@ -341,10 +327,7 @@ static void fast_copy_page(void *to, void *from)
                "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
                "   jmp 2b\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 4\n"
-               "       .long 1b, 3b\n"
-               ".previous"
+               _ASM_EXTABLE(1b,3b)
                : : "r" (from), "r" (to) : "memory");
                from+=64;
                to+=64;
index 9c4ffd5bedb299ddaba538d460bd51cfb0bd8cc8..e849b9998b0e1577519a96f9f110893bfab804ca 100644 (file)
@@ -48,10 +48,7 @@ do {                                                                    \
                "3:     movl %5,%0\n"                                      \
                "       jmp 2b\n"                                          \
                ".previous\n"                                              \
-               ".section __ex_table,\"a\"\n"                              \
-               "       .align 4\n"                                        \
-               "       .long 0b,3b\n"                                     \
-               ".previous"                                                \
+               _ASM_EXTABLE(0b,3b)                                        \
                : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),      \
                  "=&D" (__d2)                                             \
                : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
@@ -132,11 +129,8 @@ do {                                                                       \
                "3:     lea 0(%2,%0,4),%0\n"                            \
                "       jmp 2b\n"                                       \
                ".previous\n"                                           \
-               ".section __ex_table,\"a\"\n"                           \
-               "       .align 4\n"                                     \
-               "       .long 0b,3b\n"                                  \
-               "       .long 1b,2b\n"                                  \
-               ".previous"                                             \
+               _ASM_EXTABLE(0b,3b)                                     \
+               _ASM_EXTABLE(1b,2b)                                     \
                : "=&c"(size), "=&D" (__d0)                             \
                : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0));     \
 } while (0)
index 893d43f838ccd0186a6ef6869594358de12fd303..0c89d1bb02871e0324b57418d5390535c1780c2b 100644 (file)
@@ -31,10 +31,7 @@ do {                                                                    \
                "3:     movq %5,%0\n"                                      \
                "       jmp 2b\n"                                          \
                ".previous\n"                                              \
-               ".section __ex_table,\"a\"\n"                              \
-               "       .align 8\n"                                        \
-               "       .quad 0b,3b\n"                                     \
-               ".previous"                                                \
+               _ASM_EXTABLE(0b,3b)                                        \
                : "=r"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),      \
                  "=&D" (__d2)                                             \
                : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
@@ -87,11 +84,8 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
                "3:     lea 0(%[size1],%[size8],8),%[size8]\n"
                "       jmp 2b\n"
                ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 8\n"
-               "       .quad 0b,3b\n"
-               "       .quad 1b,2b\n"
-               ".previous"
+               _ASM_EXTABLE(0b,3b)
+               _ASM_EXTABLE(1b,2b)
                : [size8] "=c"(size), [dst] "=&D" (__d0)
                : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
                  [zero] "r" (0UL), [eight] "r" (8UL));
index dffa786f61fe1b17c2a3a4b2e00f07d7e3a8bc2f..3cc8eb2f36a995ad57252be8310ece8fcd32327a 100644 (file)
@@ -444,8 +444,6 @@ static __u32 __init setup_trampoline(void)
 static void __init start_secondary(void *unused)
 {
        __u8 cpuid = hard_smp_processor_id();
-       /* external functions not defined in the headers */
-       extern void calibrate_delay(void);
 
        cpu_init();
 
index e4440d0abf817005e9fce4a2686ca452446e3fc0..621afb6343dc359d4205a56021658380b1dda427 100644 (file)
@@ -240,7 +240,8 @@ void dump_pagetable(unsigned long address)
        pud = pud_offset(pgd, address);
        if (bad_address(pud)) goto bad;
        printk("PUD %lx ", pud_val(*pud));
-       if (!pud_present(*pud)) goto ret;
+       if (!pud_present(*pud) || pud_large(*pud))
+               goto ret;
 
        pmd = pmd_offset(pud, address);
        if (bad_address(pmd)) goto bad;
@@ -427,6 +428,16 @@ static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs,
 }
 #endif
 
+static int spurious_fault_check(unsigned long error_code, pte_t *pte)
+{
+       if ((error_code & PF_WRITE) && !pte_write(*pte))
+               return 0;
+       if ((error_code & PF_INSTR) && !pte_exec(*pte))
+               return 0;
+
+       return 1;
+}
+
 /*
  * Handle a spurious fault caused by a stale TLB entry.  This allows
  * us to lazily refresh the TLB when increasing the permissions of a
@@ -456,20 +467,21 @@ static int spurious_fault(unsigned long address,
        if (!pud_present(*pud))
                return 0;
 
+       if (pud_large(*pud))
+               return spurious_fault_check(error_code, (pte_t *) pud);
+
        pmd = pmd_offset(pud, address);
        if (!pmd_present(*pmd))
                return 0;
 
+       if (pmd_large(*pmd))
+               return spurious_fault_check(error_code, (pte_t *) pmd);
+
        pte = pte_offset_kernel(pmd, address);
        if (!pte_present(*pte))
                return 0;
 
-       if ((error_code & PF_WRITE) && !pte_write(*pte))
-               return 0;
-       if ((error_code & PF_INSTR) && !pte_exec(*pte))
-               return 0;
-
-       return 1;
+       return spurious_fault_check(error_code, pte);
 }
 
 /*
@@ -508,6 +520,10 @@ static int vmalloc_fault(unsigned long address)
        pmd_t *pmd, *pmd_ref;
        pte_t *pte, *pte_ref;
 
+       /* Make sure we are in vmalloc area */
+       if (!(address >= VMALLOC_START && address < VMALLOC_END))
+               return -1;
+
        /* Copy kernel mappings over when needed. This can also
           happen within a race in page table update. In the later
           case just flush. */
@@ -603,6 +619,9 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
         */
 #ifdef CONFIG_X86_32
        if (unlikely(address >= TASK_SIZE)) {
+#else
+       if (unlikely(address >= TASK_SIZE64)) {
+#endif
                if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) &&
                    vmalloc_fault(address) >= 0)
                        return;
@@ -618,6 +637,8 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
                goto bad_area_nosemaphore;
        }
 
+
+#ifdef CONFIG_X86_32
        /* It's safe to allow irq's after cr2 has been saved and the vmalloc
           fault has been handled. */
        if (regs->flags & (X86_EFLAGS_IF|VM_MASK))
@@ -630,28 +651,6 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
        if (in_atomic() || !mm)
                goto bad_area_nosemaphore;
 #else /* CONFIG_X86_64 */
-       if (unlikely(address >= TASK_SIZE64)) {
-               /*
-                * Don't check for the module range here: its PML4
-                * is always initialized because it's shared with the main
-                * kernel text. Only vmalloc may need PML4 syncups.
-                */
-               if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) &&
-                     ((address >= VMALLOC_START && address < VMALLOC_END))) {
-                       if (vmalloc_fault(address) >= 0)
-                               return;
-               }
-
-               /* Can handle a stale RO->RW TLB */
-               if (spurious_fault(address, error_code))
-                       return;
-
-               /*
-                * Don't take the mm semaphore here. If we fixup a prefetch
-                * fault we could otherwise deadlock.
-                */
-               goto bad_area_nosemaphore;
-       }
        if (likely(regs->flags & X86_EFLAGS_IF))
                local_irq_enable();
 
@@ -959,11 +958,12 @@ void vmalloc_sync_all(void)
        for (address = start; address <= VMALLOC_END; address += PGDIR_SIZE) {
                if (!test_bit(pgd_index(address), insync)) {
                        const pgd_t *pgd_ref = pgd_offset_k(address);
+                       unsigned long flags;
                        struct page *page;
 
                        if (pgd_none(*pgd_ref))
                                continue;
-                       spin_lock(&pgd_lock);
+                       spin_lock_irqsave(&pgd_lock, flags);
                        list_for_each_entry(page, &pgd_list, lru) {
                                pgd_t *pgd;
                                pgd = (pgd_t *)page_address(page) + pgd_index(address);
@@ -972,7 +972,7 @@ void vmalloc_sync_all(void)
                                else
                                        BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
                        }
-                       spin_unlock(&pgd_lock);
+                       spin_unlock_irqrestore(&pgd_lock, flags);
                        set_bit(pgd_index(address), insync);
                }
                if (address == start)
index da524fb22422eafc8b4d6514609aec749ffc2dc0..d1bc04006d16e12fc706fe10b942e01cde3bb2d5 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/initrd.h>
 #include <linux/cpumask.h>
 
+#include <asm/asm.h>
 #include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -423,23 +424,23 @@ static void __init pagetable_init(void)
        paravirt_pagetable_setup_done(pgd_base);
 }
 
-#if defined(CONFIG_HIBERNATION) || defined(CONFIG_ACPI)
+#ifdef CONFIG_ACPI_SLEEP
 /*
- * Swap suspend & friends need this for resume because things like the intel-agp
+ * ACPI suspend needs this for resume, because things like the intel-agp
  * driver might have split up a kernel 4MB mapping.
  */
-char __nosavedata swsusp_pg_dir[PAGE_SIZE]
+char swsusp_pg_dir[PAGE_SIZE]
        __attribute__ ((aligned(PAGE_SIZE)));
 
 static inline void save_pg_dir(void)
 {
        memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
 }
-#else
+#else /* !CONFIG_ACPI_SLEEP */
 static inline void save_pg_dir(void)
 {
 }
-#endif
+#endif /* !CONFIG_ACPI_SLEEP */
 
 void zap_low_mappings(void)
 {
@@ -718,10 +719,7 @@ static noinline int do_test_wp_bit(void)
                "1:     movb %1, %0     \n"
                "       xorl %2, %2     \n"
                "2:                     \n"
-               ".section __ex_table, \"a\"\n"
-               "       .align 4        \n"
-               "       .long 1b, 2b    \n"
-               ".previous              \n"
+               _ASM_EXTABLE(1b,2b)
                :"=m" (*(char *)fix_to_virt(FIX_WP_TEST)),
                 "=q" (tmp_reg),
                 "=r" (flag)
index eabcaed76c28a15768b057119ebd8cecb8eb90d5..9b61c75a23556f76898ca2f8b1d26d71b206ca26 100644 (file)
@@ -273,7 +273,6 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)
        int i = pmd_index(address);
 
        for (; i < PTRS_PER_PMD; i++, address += PMD_SIZE) {
-               unsigned long entry;
                pmd_t *pmd = pmd_page + pmd_index(address);
 
                if (address >= end) {
@@ -287,9 +286,8 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)
                if (pmd_val(*pmd))
                        continue;
 
-               entry = __PAGE_KERNEL_LARGE|_PAGE_GLOBAL|address;
-               entry &= __supported_pte_mask;
-               set_pmd(pmd, __pmd(entry));
+               set_pte((pte_t *)pmd,
+                       pfn_pte(address >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
        }
 }
 
@@ -434,49 +432,6 @@ void __init paging_init(void)
 }
 #endif
 
-/*
- * Unmap a kernel mapping if it exists. This is useful to avoid
- * prefetches from the CPU leading to inconsistent cache lines.
- * address and size must be aligned to 2MB boundaries.
- * Does nothing when the mapping doesn't exist.
- */
-void __init clear_kernel_mapping(unsigned long address, unsigned long size)
-{
-       unsigned long end = address + size;
-
-       BUG_ON(address & ~LARGE_PAGE_MASK);
-       BUG_ON(size & ~LARGE_PAGE_MASK);
-
-       for (; address < end; address += LARGE_PAGE_SIZE) {
-               pgd_t *pgd = pgd_offset_k(address);
-               pud_t *pud;
-               pmd_t *pmd;
-
-               if (pgd_none(*pgd))
-                       continue;
-
-               pud = pud_offset(pgd, address);
-               if (pud_none(*pud))
-                       continue;
-
-               pmd = pmd_offset(pud, address);
-               if (!pmd || pmd_none(*pmd))
-                       continue;
-
-               if (!(pmd_val(*pmd) & _PAGE_PSE)) {
-                       /*
-                        * Could handle this, but it should not happen
-                        * currently:
-                        */
-                       printk(KERN_ERR "clear_kernel_mapping: "
-                               "mapping has been split. will leak memory\n");
-                       pmd_ERROR(*pmd);
-               }
-               set_pmd(pmd, __pmd(0));
-       }
-       __flush_tlb_all();
-}
-
 /*
  * Memory hotplug specific functions
  */
@@ -636,10 +591,17 @@ void mark_rodata_ro(void)
        if (end <= start)
                return;
 
-       set_memory_ro(start, (end - start) >> PAGE_SHIFT);
 
        printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
               (end - start) >> 10);
+       set_memory_ro(start, (end - start) >> PAGE_SHIFT);
+
+       /*
+        * The rodata section (but not the kernel text!) should also be
+        * not-executable.
+        */
+       start = ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
+       set_memory_nx(start, (end - start) >> PAGE_SHIFT);
 
        rodata_test();
 
index c004d94608fd4a21035684c12cf0b6af5d3d46ba..ee6648fe6b15de75a4e0fe53a90f6311fa8b917a 100644 (file)
@@ -70,25 +70,12 @@ int page_is_ram(unsigned long pagenr)
  * Fix up the linear direct mapping of the kernel to avoid cache attribute
  * conflicts.
  */
-static int ioremap_change_attr(unsigned long paddr, unsigned long size,
+static int ioremap_change_attr(unsigned long vaddr, unsigned long size,
                               enum ioremap_mode mode)
 {
-       unsigned long vaddr = (unsigned long)__va(paddr);
        unsigned long nrpages = size >> PAGE_SHIFT;
-       unsigned int level;
        int err;
 
-       /* No change for pages after the last mapping */
-       if ((paddr + size - 1) >= (max_pfn_mapped << PAGE_SHIFT))
-               return 0;
-
-       /*
-        * If there is no identity map for this address,
-        * change_page_attr_addr is unnecessary
-        */
-       if (!lookup_address(vaddr, &level))
-               return 0;
-
        switch (mode) {
        case IOR_MODE_UNCACHED:
        default:
@@ -114,9 +101,8 @@ static int ioremap_change_attr(unsigned long paddr, unsigned long size,
 static void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
                               enum ioremap_mode mode)
 {
-       void __iomem *addr;
+       unsigned long pfn, offset, last_addr, vaddr;
        struct vm_struct *area;
-       unsigned long offset, last_addr;
        pgprot_t prot;
 
        /* Don't allow wraparound or zero size */
@@ -133,9 +119,10 @@ static void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
        /*
         * Don't allow anybody to remap normal RAM that we're using..
         */
-       for (offset = phys_addr >> PAGE_SHIFT; offset < max_pfn_mapped &&
-            (offset << PAGE_SHIFT) < last_addr; offset++) {
-               if (page_is_ram(offset))
+       for (pfn = phys_addr >> PAGE_SHIFT; pfn < max_pfn_mapped &&
+            (pfn << PAGE_SHIFT) < last_addr; pfn++) {
+               if (page_is_ram(pfn) && pfn_valid(pfn) &&
+                   !PageReserved(pfn_to_page(pfn)))
                        return NULL;
        }
 
@@ -163,19 +150,18 @@ static void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
        if (!area)
                return NULL;
        area->phys_addr = phys_addr;
-       addr = (void __iomem *) area->addr;
-       if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
-                              phys_addr, prot)) {
-               remove_vm_area((void *)(PAGE_MASK & (unsigned long) addr));
+       vaddr = (unsigned long) area->addr;
+       if (ioremap_page_range(vaddr, vaddr + size, phys_addr, prot)) {
+               remove_vm_area((void *)(vaddr & PAGE_MASK));
                return NULL;
        }
 
-       if (ioremap_change_attr(phys_addr, size, mode) < 0) {
-               vunmap(addr);
+       if (ioremap_change_attr(vaddr, size, mode) < 0) {
+               vunmap(area->addr);
                return NULL;
        }
 
-       return (void __iomem *) (offset + (char __iomem *)addr);
+       return (void __iomem *) (vaddr + offset);
 }
 
 /**
@@ -254,9 +240,6 @@ void iounmap(volatile void __iomem *addr)
                return;
        }
 
-       /* Reset the direct mapping. Can block */
-       ioremap_change_attr(p->phys_addr, p->size, IOR_MODE_CACHED);
-
        /* Finally remove it */
        o = remove_vm_area((void *)addr);
        BUG_ON(p != o || o == NULL);
index a920d09b91948dcf8ea42b6c95f09fbbb07a2145..5a02bf4c91ec7eac8b9c25da1cf1f666bc2b961f 100644 (file)
@@ -202,6 +202,8 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
        if (node_data[nodeid] == NULL)
                return;
        nodedata_phys = __pa(node_data[nodeid]);
+       printk(KERN_INFO "  NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
+               nodedata_phys + pgdat_size - 1);
 
        memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
        NODE_DATA(nodeid)->bdata = &plat_node_bdata[nodeid];
@@ -225,12 +227,15 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
                return;
        }
        bootmap_start = __pa(bootmap);
-       Dprintk("bootmap start %lu pages %lu\n", bootmap_start, bootmap_pages);
 
        bootmap_size = init_bootmem_node(NODE_DATA(nodeid),
                                         bootmap_start >> PAGE_SHIFT,
                                         start_pfn, end_pfn);
 
+       printk(KERN_INFO "  bootmap [%016lx -  %016lx] pages %lx\n",
+                bootmap_start, bootmap_start + bootmap_size - 1,
+                bootmap_pages);
+
        free_bootmem_with_active_regions(nodeid, end);
 
        reserve_bootmem_node(NODE_DATA(nodeid), nodedata_phys, pgdat_size);
index 7573e786d2f202d98754f2a484220c75b1250c31..ed82016003540ec66ccd7b18157188f6a9d7a5cf 100644 (file)
@@ -5,6 +5,7 @@
  * and compares page tables forwards and afterwards.
  */
 #include <linux/bootmem.h>
+#include <linux/kthread.h>
 #include <linux/random.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <asm/pgtable.h>
 #include <asm/kdebug.h>
 
+/*
+ * Only print the results of the first pass:
+ */
+static __read_mostly int print = 1;
+
 enum {
-       NTEST                   = 4000,
+       NTEST                   = 400,
 #ifdef CONFIG_X86_64
        LPS                     = (1 << PMD_SHIFT),
 #elif defined(CONFIG_X86_PAE)
@@ -31,7 +37,7 @@ struct split_state {
        long min_exec, max_exec;
 };
 
-static __init int print_split(struct split_state *s)
+static int print_split(struct split_state *s)
 {
        long i, expected, missed = 0;
        int printed = 0;
@@ -82,10 +88,13 @@ static __init int print_split(struct split_state *s)
                                s->max_exec = addr;
                }
        }
-       printk(KERN_INFO
-               "CPA mapping 4k %lu large %lu gb %lu x %lu[%lx-%lx] miss %lu\n",
-               s->spg, s->lpg, s->gpg, s->exec,
-               s->min_exec != ~0UL ? s->min_exec : 0, s->max_exec, missed);
+       if (print) {
+               printk(KERN_INFO
+                       " 4k %lu large %lu gb %lu x %lu[%lx-%lx] miss %lu\n",
+                       s->spg, s->lpg, s->gpg, s->exec,
+                       s->min_exec != ~0UL ? s->min_exec : 0,
+                       s->max_exec, missed);
+       }
 
        expected = (s->gpg*GPS + s->lpg*LPS)/PAGE_SIZE + s->spg + missed;
        if (expected != i) {
@@ -96,11 +105,11 @@ static __init int print_split(struct split_state *s)
        return err;
 }
 
-static unsigned long __initdata addr[NTEST];
-static unsigned int __initdata len[NTEST];
+static unsigned long addr[NTEST];
+static unsigned int len[NTEST];
 
 /* Change the global bit on random pages in the direct mapping */
-static __init int exercise_pageattr(void)
+static int pageattr_test(void)
 {
        struct split_state sa, sb, sc;
        unsigned long *bm;
@@ -110,7 +119,8 @@ static __init int exercise_pageattr(void)
        int i, k;
        int err;
 
-       printk(KERN_INFO "CPA exercising pageattr\n");
+       if (print)
+               printk(KERN_INFO "CPA self-test:\n");
 
        bm = vmalloc((max_pfn_mapped + 7) / 8);
        if (!bm) {
@@ -137,7 +147,8 @@ static __init int exercise_pageattr(void)
 
                for (k = 0; k < len[i]; k++) {
                        pte = lookup_address(addr[i] + k*PAGE_SIZE, &level);
-                       if (!pte || pgprot_val(pte_pgprot(*pte)) == 0) {
+                       if (!pte || pgprot_val(pte_pgprot(*pte)) == 0 ||
+                           !(pte_val(*pte) & _PAGE_PRESENT)) {
                                addr[i] = 0;
                                break;
                        }
@@ -185,7 +196,6 @@ static __init int exercise_pageattr(void)
 
        failed += print_split(&sb);
 
-       printk(KERN_INFO "CPA reverting everything\n");
        for (i = 0; i < NTEST; i++) {
                if (!addr[i])
                        continue;
@@ -213,12 +223,40 @@ static __init int exercise_pageattr(void)
        failed += print_split(&sc);
 
        if (failed) {
-               printk(KERN_ERR "CPA selftests NOT PASSED. Please report.\n");
+               printk(KERN_ERR "NOT PASSED. Please report.\n");
                WARN_ON(1);
+               return -EINVAL;
        } else {
-               printk(KERN_INFO "CPA selftests PASSED\n");
+               if (print)
+                       printk(KERN_INFO "ok.\n");
        }
 
        return 0;
 }
-module_init(exercise_pageattr);
+
+static int do_pageattr_test(void *__unused)
+{
+       while (!kthread_should_stop()) {
+               schedule_timeout_interruptible(HZ*30);
+               if (pageattr_test() < 0)
+                       break;
+               if (print)
+                       print--;
+       }
+       return 0;
+}
+
+static int start_pageattr_test(void)
+{
+       struct task_struct *p;
+
+       p = kthread_create(do_pageattr_test, NULL, "pageattr-test");
+       if (!IS_ERR(p))
+               wake_up_process(p);
+       else
+               WARN_ON(1);
+
+       return 0;
+}
+
+module_init(start_pageattr_test);
index e297bd65e513308fd1c2a26ee59126c8c077e04b..8493c855582bf56a5a36d2e6e64266332c9d26c0 100644 (file)
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
 
+/*
+ * The current flushing context - we pass it instead of 5 arguments:
+ */
+struct cpa_data {
+       unsigned long   vaddr;
+       pgprot_t        mask_set;
+       pgprot_t        mask_clr;
+       int             numpages;
+       int             flushtlb;
+};
+
 static inline int
 within(unsigned long addr, unsigned long start, unsigned long end)
 {
@@ -52,21 +63,23 @@ void clflush_cache_range(void *vaddr, unsigned int size)
 
 static void __cpa_flush_all(void *arg)
 {
+       unsigned long cache = (unsigned long)arg;
+
        /*
         * Flush all to work around Errata in early athlons regarding
         * large page flushing.
         */
        __flush_tlb_all();
 
-       if (boot_cpu_data.x86_model >= 4)
+       if (cache && boot_cpu_data.x86_model >= 4)
                wbinvd();
 }
 
-static void cpa_flush_all(void)
+static void cpa_flush_all(unsigned long cache)
 {
        BUG_ON(irqs_disabled());
 
-       on_each_cpu(__cpa_flush_all, NULL, 1, 1);
+       on_each_cpu(__cpa_flush_all, (void *) cache, 1, 1);
 }
 
 static void __cpa_flush_range(void *arg)
@@ -79,7 +92,7 @@ static void __cpa_flush_range(void *arg)
        __flush_tlb_all();
 }
 
-static void cpa_flush_range(unsigned long start, int numpages)
+static void cpa_flush_range(unsigned long start, int numpages, int cache)
 {
        unsigned int i, level;
        unsigned long addr;
@@ -89,6 +102,9 @@ static void cpa_flush_range(unsigned long start, int numpages)
 
        on_each_cpu(__cpa_flush_range, NULL, 1, 1);
 
+       if (!cache)
+               return;
+
        /*
         * We only need to flush on one CPU,
         * clflush is a MESI-coherent instruction that
@@ -101,11 +117,27 @@ static void cpa_flush_range(unsigned long start, int numpages)
                /*
                 * Only flush present addresses:
                 */
-               if (pte && pte_present(*pte))
+               if (pte && (pte_val(*pte) & _PAGE_PRESENT))
                        clflush_cache_range((void *) addr, PAGE_SIZE);
        }
 }
 
+#define HIGH_MAP_START __START_KERNEL_map
+#define HIGH_MAP_END   (__START_KERNEL_map + KERNEL_TEXT_SIZE)
+
+
+/*
+ * Converts a virtual address to a X86-64 highmap address
+ */
+static unsigned long virt_to_highmap(void *address)
+{
+#ifdef CONFIG_X86_64
+       return __pa((unsigned long)address) + HIGH_MAP_START - phys_base;
+#else
+       return (unsigned long)address;
+#endif
+}
+
 /*
  * Certain areas of memory on x86 require very specific protection flags,
  * for example the BIOS area or kernel text. Callers don't always get this
@@ -129,19 +161,36 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address)
         */
        if (within(address, (unsigned long)_text, (unsigned long)_etext))
                pgprot_val(forbidden) |= _PAGE_NX;
+       /*
+        * Do the same for the x86-64 high kernel mapping
+        */
+       if (within(address, virt_to_highmap(_text), virt_to_highmap(_etext)))
+               pgprot_val(forbidden) |= _PAGE_NX;
 
-#ifdef CONFIG_DEBUG_RODATA
        /* The .rodata section needs to be read-only */
        if (within(address, (unsigned long)__start_rodata,
                                (unsigned long)__end_rodata))
                pgprot_val(forbidden) |= _PAGE_RW;
-#endif
+       /*
+        * Do the same for the x86-64 high kernel mapping
+        */
+       if (within(address, virt_to_highmap(__start_rodata),
+                               virt_to_highmap(__end_rodata)))
+               pgprot_val(forbidden) |= _PAGE_RW;
 
        prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
 
        return prot;
 }
 
+/*
+ * Lookup the page table entry for a virtual address. Return a pointer
+ * to the entry and the level of the mapping.
+ *
+ * Note: We return pud and pmd either when the entry is marked large
+ * or when the present bit is not set. Otherwise we would return a
+ * pointer to a nonexisting mapping.
+ */
 pte_t *lookup_address(unsigned long address, int *level)
 {
        pgd_t *pgd = pgd_offset_k(address);
@@ -152,21 +201,31 @@ pte_t *lookup_address(unsigned long address, int *level)
 
        if (pgd_none(*pgd))
                return NULL;
+
        pud = pud_offset(pgd, address);
        if (pud_none(*pud))
                return NULL;
+
+       *level = PG_LEVEL_1G;
+       if (pud_large(*pud) || !pud_present(*pud))
+               return (pte_t *)pud;
+
        pmd = pmd_offset(pud, address);
        if (pmd_none(*pmd))
                return NULL;
 
        *level = PG_LEVEL_2M;
-       if (pmd_large(*pmd))
+       if (pmd_large(*pmd) || !pmd_present(*pmd))
                return (pte_t *)pmd;
 
        *level = PG_LEVEL_4K;
+
        return pte_offset_kernel(pmd, address);
 }
 
+/*
+ * Set the new pmd in all the pgds we know about:
+ */
 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
 {
        /* change init_mm */
@@ -189,18 +248,103 @@ static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
 #endif
 }
 
+static int
+try_preserve_large_page(pte_t *kpte, unsigned long address,
+                       struct cpa_data *cpa)
+{
+       unsigned long nextpage_addr, numpages, pmask, psize, flags;
+       pte_t new_pte, old_pte, *tmp;
+       pgprot_t old_prot, new_prot;
+       int level, do_split = 1;
+
+       spin_lock_irqsave(&pgd_lock, flags);
+       /*
+        * Check for races, another CPU might have split this page
+        * up already:
+        */
+       tmp = lookup_address(address, &level);
+       if (tmp != kpte)
+               goto out_unlock;
+
+       switch (level) {
+       case PG_LEVEL_2M:
+               psize = PMD_PAGE_SIZE;
+               pmask = PMD_PAGE_MASK;
+               break;
+#ifdef CONFIG_X86_64
+       case PG_LEVEL_1G:
+               psize = PMD_PAGE_SIZE;
+               pmask = PMD_PAGE_MASK;
+               break;
+#endif
+       default:
+               do_split = -EINVAL;
+               goto out_unlock;
+       }
+
+       /*
+        * Calculate the number of pages, which fit into this large
+        * page starting at address:
+        */
+       nextpage_addr = (address + psize) & pmask;
+       numpages = (nextpage_addr - address) >> PAGE_SHIFT;
+       if (numpages < cpa->numpages)
+               cpa->numpages = numpages;
+
+       /*
+        * We are safe now. Check whether the new pgprot is the same:
+        */
+       old_pte = *kpte;
+       old_prot = new_prot = pte_pgprot(old_pte);
+
+       pgprot_val(new_prot) &= ~pgprot_val(cpa->mask_clr);
+       pgprot_val(new_prot) |= pgprot_val(cpa->mask_set);
+       new_prot = static_protections(new_prot, address);
+
+       /*
+        * If there are no changes, return. maxpages has been updated
+        * above:
+        */
+       if (pgprot_val(new_prot) == pgprot_val(old_prot)) {
+               do_split = 0;
+               goto out_unlock;
+       }
+
+       /*
+        * We need to change the attributes. Check, whether we can
+        * change the large page in one go. We request a split, when
+        * the address is not aligned and the number of pages is
+        * smaller than the number of pages in the large page. Note
+        * that we limited the number of possible pages already to
+        * the number of pages in the large page.
+        */
+       if (address == (nextpage_addr - psize) && cpa->numpages == numpages) {
+               /*
+                * The address is aligned and the number of pages
+                * covers the full page.
+                */
+               new_pte = pfn_pte(pte_pfn(old_pte), canon_pgprot(new_prot));
+               __set_pmd_pte(kpte, address, new_pte);
+               cpa->flushtlb = 1;
+               do_split = 0;
+       }
+
+out_unlock:
+       spin_unlock_irqrestore(&pgd_lock, flags);
+
+       return do_split;
+}
+
 static int split_large_page(pte_t *kpte, unsigned long address)
 {
-       pgprot_t ref_prot = pte_pgprot(pte_clrhuge(*kpte));
+       unsigned long flags, pfn, pfninc = 1;
        gfp_t gfp_flags = GFP_KERNEL;
-       unsigned long flags;
-       unsigned long addr;
+       unsigned int i, level;
        pte_t *pbase, *tmp;
+       pgprot_t ref_prot;
        struct page *base;
-       unsigned int i, level;
 
 #ifdef CONFIG_DEBUG_PAGEALLOC
-       gfp_flags = __GFP_HIGH | __GFP_NOFAIL | __GFP_NOWARN;
        gfp_flags = GFP_ATOMIC | __GFP_NOWARN;
 #endif
        base = alloc_pages(gfp_flags, 0);
@@ -213,30 +357,41 @@ static int split_large_page(pte_t *kpte, unsigned long address)
         * up for us already:
         */
        tmp = lookup_address(address, &level);
-       if (tmp != kpte) {
-               WARN_ON_ONCE(1);
+       if (tmp != kpte)
                goto out_unlock;
-       }
 
-       address = __pa(address);
-       addr = address & LARGE_PAGE_MASK;
        pbase = (pte_t *)page_address(base);
 #ifdef CONFIG_X86_32
        paravirt_alloc_pt(&init_mm, page_to_pfn(base));
 #endif
+       ref_prot = pte_pgprot(pte_clrhuge(*kpte));
 
-       pgprot_val(ref_prot) &= ~_PAGE_NX;
-       for (i = 0; i < PTRS_PER_PTE; i++, addr += PAGE_SIZE)
-               set_pte(&pbase[i], pfn_pte(addr >> PAGE_SHIFT, ref_prot));
+#ifdef CONFIG_X86_64
+       if (level == PG_LEVEL_1G) {
+               pfninc = PMD_PAGE_SIZE >> PAGE_SHIFT;
+               pgprot_val(ref_prot) |= _PAGE_PSE;
+       }
+#endif
+
+       /*
+        * Get the target pfn from the original entry:
+        */
+       pfn = pte_pfn(*kpte);
+       for (i = 0; i < PTRS_PER_PTE; i++, pfn += pfninc)
+               set_pte(&pbase[i], pfn_pte(pfn, ref_prot));
 
        /*
-        * Install the new, split up pagetable. Important detail here:
+        * Install the new, split up pagetable. Important details here:
         *
         * On Intel the NX bit of all levels must be cleared to make a
         * page executable. See section 4.13.2 of Intel 64 and IA-32
         * Architectures Software Developer's Manual).
+        *
+        * Mark the entry present. The current mapping might be
+        * set to not present, which we preserved above.
         */
        ref_prot = pte_pgprot(pte_mkexec(pte_clrhuge(*kpte)));
+       pgprot_val(ref_prot) |= _PAGE_PRESENT;
        __set_pmd_pte(kpte, address, mk_pte(base, ref_prot));
        base = NULL;
 
@@ -249,18 +404,12 @@ out_unlock:
        return 0;
 }
 
-static int
-__change_page_attr(unsigned long address, unsigned long pfn,
-                  pgprot_t mask_set, pgprot_t mask_clr)
+static int __change_page_attr(unsigned long address, struct cpa_data *cpa)
 {
+       int level, do_split, err;
        struct page *kpte_page;
-       int level, err = 0;
        pte_t *kpte;
 
-#ifdef CONFIG_X86_32
-       BUG_ON(pfn > max_low_pfn);
-#endif
-
 repeat:
        kpte = lookup_address(address, &level);
        if (!kpte)
@@ -271,23 +420,62 @@ repeat:
        BUG_ON(PageCompound(kpte_page));
 
        if (level == PG_LEVEL_4K) {
-               pgprot_t new_prot = pte_pgprot(*kpte);
                pte_t new_pte, old_pte = *kpte;
+               pgprot_t new_prot = pte_pgprot(old_pte);
+
+               if(!pte_val(old_pte)) {
+                       printk(KERN_WARNING "CPA: called for zero pte. "
+                              "vaddr = %lx cpa->vaddr = %lx\n", address,
+                               cpa->vaddr);
+                       WARN_ON(1);
+                       return -EINVAL;
+               }
 
-               pgprot_val(new_prot) &= ~pgprot_val(mask_clr);
-               pgprot_val(new_prot) |= pgprot_val(mask_set);
+               pgprot_val(new_prot) &= ~pgprot_val(cpa->mask_clr);
+               pgprot_val(new_prot) |= pgprot_val(cpa->mask_set);
 
                new_prot = static_protections(new_prot, address);
 
-               new_pte = pfn_pte(pfn, canon_pgprot(new_prot));
-               BUG_ON(pte_pfn(new_pte) != pte_pfn(old_pte));
+               /*
+                * We need to keep the pfn from the existing PTE,
+                * after all we're only going to change it's attributes
+                * not the memory it points to
+                */
+               new_pte = pfn_pte(pte_pfn(old_pte), canon_pgprot(new_prot));
 
-               set_pte_atomic(kpte, new_pte);
-       } else {
-               err = split_large_page(kpte, address);
-               if (!err)
-                       goto repeat;
+               /*
+                * Do we really change anything ?
+                */
+               if (pte_val(old_pte) != pte_val(new_pte)) {
+                       set_pte_atomic(kpte, new_pte);
+                       cpa->flushtlb = 1;
+               }
+               cpa->numpages = 1;
+               return 0;
        }
+
+       /*
+        * Check, whether we can keep the large page intact
+        * and just change the pte:
+        */
+       do_split = try_preserve_large_page(kpte, address, cpa);
+       /*
+        * When the range fits into the existing large page,
+        * return. cp->numpages and cpa->tlbflush have been updated in
+        * try_large_page:
+        */
+       if (do_split <= 0)
+               return do_split;
+
+       /*
+        * We have to split the large page:
+        */
+       err = split_large_page(kpte, address);
+       if (!err) {
+               cpa->flushtlb = 1;
+               goto repeat;
+       }
+
        return err;
 }
 
@@ -304,19 +492,14 @@ repeat:
  *
  * Modules and drivers should use the set_memory_* APIs instead.
  */
-
-#define HIGH_MAP_START __START_KERNEL_map
-#define HIGH_MAP_END   (__START_KERNEL_map + KERNEL_TEXT_SIZE)
-
-static int
-change_page_attr_addr(unsigned long address, pgprot_t mask_set,
-                     pgprot_t mask_clr)
+static int change_page_attr_addr(struct cpa_data *cpa)
 {
-       unsigned long phys_addr = __pa(address);
-       unsigned long pfn = phys_addr >> PAGE_SHIFT;
        int err;
+       unsigned long address = cpa->vaddr;
 
 #ifdef CONFIG_X86_64
+       unsigned long phys_addr = __pa(address);
+
        /*
         * If we are inside the high mapped kernel range, then we
         * fixup the low mapping first. __va() returns the virtual
@@ -326,7 +509,7 @@ change_page_attr_addr(unsigned long address, pgprot_t mask_set,
                address = (unsigned long) __va(phys_addr);
 #endif
 
-       err = __change_page_attr(address, pfn, mask_set, mask_clr);
+       err = __change_page_attr(address, cpa);
        if (err)
                return err;
 
@@ -339,42 +522,89 @@ change_page_attr_addr(unsigned long address, pgprot_t mask_set,
                /*
                 * Calc the high mapping address. See __phys_addr()
                 * for the non obvious details.
+                *
+                * Note that NX and other required permissions are
+                * checked in static_protections().
                 */
                address = phys_addr + HIGH_MAP_START - phys_base;
-               /* Make sure the kernel mappings stay executable */
-               pgprot_val(mask_clr) |= _PAGE_NX;
 
                /*
                 * Our high aliases are imprecise, because we check
                 * everything between 0 and KERNEL_TEXT_SIZE, so do
                 * not propagate lookup failures back to users:
                 */
-               __change_page_attr(address, pfn, mask_set, mask_clr);
+               __change_page_attr(address, cpa);
        }
 #endif
        return err;
 }
 
-static int __change_page_attr_set_clr(unsigned long addr, int numpages,
-                                     pgprot_t mask_set, pgprot_t mask_clr)
+static int __change_page_attr_set_clr(struct cpa_data *cpa)
 {
-       unsigned int i;
-       int ret;
+       int ret, numpages = cpa->numpages;
 
-       for (i = 0; i < numpages ; i++, addr += PAGE_SIZE) {
-               ret = change_page_attr_addr(addr, mask_set, mask_clr);
+       while (numpages) {
+               /*
+                * Store the remaining nr of pages for the large page
+                * preservation check.
+                */
+               cpa->numpages = numpages;
+               ret = change_page_attr_addr(cpa);
                if (ret)
                        return ret;
-       }
 
+               /*
+                * Adjust the number of pages with the result of the
+                * CPA operation. Either a large page has been
+                * preserved or a single page update happened.
+                */
+               BUG_ON(cpa->numpages > numpages);
+               numpages -= cpa->numpages;
+               cpa->vaddr += cpa->numpages * PAGE_SIZE;
+       }
        return 0;
 }
 
+static inline int cache_attr(pgprot_t attr)
+{
+       return pgprot_val(attr) &
+               (_PAGE_PAT | _PAGE_PAT_LARGE | _PAGE_PWT | _PAGE_PCD);
+}
+
 static int change_page_attr_set_clr(unsigned long addr, int numpages,
                                    pgprot_t mask_set, pgprot_t mask_clr)
 {
-       int ret = __change_page_attr_set_clr(addr, numpages, mask_set,
-                                            mask_clr);
+       struct cpa_data cpa;
+       int ret, cache;
+
+       /*
+        * Check, if we are requested to change a not supported
+        * feature:
+        */
+       mask_set = canon_pgprot(mask_set);
+       mask_clr = canon_pgprot(mask_clr);
+       if (!pgprot_val(mask_set) && !pgprot_val(mask_clr))
+               return 0;
+
+       cpa.vaddr = addr;
+       cpa.numpages = numpages;
+       cpa.mask_set = mask_set;
+       cpa.mask_clr = mask_clr;
+       cpa.flushtlb = 0;
+
+       ret = __change_page_attr_set_clr(&cpa);
+
+       /*
+        * Check whether we really changed something:
+        */
+       if (!cpa.flushtlb)
+               return ret;
+
+       /*
+        * No need to flush, when we did not set any of the caching
+        * attributes:
+        */
+       cache = cache_attr(mask_set);
 
        /*
         * On success we use clflush, when the CPU supports it to
@@ -383,9 +613,9 @@ static int change_page_attr_set_clr(unsigned long addr, int numpages,
         * wbindv):
         */
        if (!ret && cpu_has_clflush)
-               cpa_flush_range(addr, numpages);
+               cpa_flush_range(addr, numpages, cache);
        else
-               cpa_flush_all();
+               cpa_flush_all(cache);
 
        return ret;
 }
@@ -489,37 +719,26 @@ int set_pages_rw(struct page *page, int numpages)
        return set_memory_rw(addr, numpages);
 }
 
-
-#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_CPA_DEBUG)
-static inline int __change_page_attr_set(unsigned long addr, int numpages,
-                                        pgprot_t mask)
-{
-       return __change_page_attr_set_clr(addr, numpages, mask, __pgprot(0));
-}
-
-static inline int __change_page_attr_clear(unsigned long addr, int numpages,
-                                          pgprot_t mask)
-{
-       return __change_page_attr_set_clr(addr, numpages, __pgprot(0), mask);
-}
-#endif
-
 #ifdef CONFIG_DEBUG_PAGEALLOC
 
 static int __set_pages_p(struct page *page, int numpages)
 {
-       unsigned long addr = (unsigned long)page_address(page);
+       struct cpa_data cpa = { .vaddr = (unsigned long) page_address(page),
+                               .numpages = numpages,
+                               .mask_set = __pgprot(_PAGE_PRESENT | _PAGE_RW),
+                               .mask_clr = __pgprot(0)};
 
-       return __change_page_attr_set(addr, numpages,
-                                     __pgprot(_PAGE_PRESENT | _PAGE_RW));
+       return __change_page_attr_set_clr(&cpa);
 }
 
 static int __set_pages_np(struct page *page, int numpages)
 {
-       unsigned long addr = (unsigned long)page_address(page);
+       struct cpa_data cpa = { .vaddr = (unsigned long) page_address(page),
+                               .numpages = numpages,
+                               .mask_set = __pgprot(0),
+                               .mask_clr = __pgprot(_PAGE_PRESENT | _PAGE_RW)};
 
-       return __change_page_attr_clear(addr, numpages,
-                                       __pgprot(_PAGE_PRESENT));
+       return __change_page_attr_set_clr(&cpa);
 }
 
 void kernel_map_pages(struct page *page, int numpages, int enable)
index cb3aa470249b82fd457207455135addbde196733..6c1914622a88344456f571d2cbf06e58921f451b 100644 (file)
@@ -219,50 +219,39 @@ static inline void pgd_list_del(pgd_t *pgd)
        list_del(&page->lru);
 }
 
+#define UNSHARED_PTRS_PER_PGD                          \
+       (SHARED_KERNEL_PMD ? USER_PTRS_PER_PGD : PTRS_PER_PGD)
 
-
-#if (PTRS_PER_PMD == 1)
-/* Non-PAE pgd constructor */
-static void pgd_ctor(void *pgd)
+static void pgd_ctor(void *p)
 {
+       pgd_t *pgd = p;
        unsigned long flags;
 
-       /* !PAE, no pagetable sharing */
+       /* Clear usermode parts of PGD */
        memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
 
        spin_lock_irqsave(&pgd_lock, flags);
 
-       /* must happen under lock */
-       clone_pgd_range((pgd_t *)pgd + USER_PTRS_PER_PGD,
-                       swapper_pg_dir + USER_PTRS_PER_PGD,
-                       KERNEL_PGD_PTRS);
-       paravirt_alloc_pd_clone(__pa(pgd) >> PAGE_SHIFT,
-                               __pa(swapper_pg_dir) >> PAGE_SHIFT,
-                               USER_PTRS_PER_PGD,
-                               KERNEL_PGD_PTRS);
-       pgd_list_add(pgd);
-       spin_unlock_irqrestore(&pgd_lock, flags);
-}
-#else  /* PTRS_PER_PMD > 1 */
-/* PAE pgd constructor */
-static void pgd_ctor(void *pgd)
-{
-       /* PAE, kernel PMD may be shared */
-
-       if (SHARED_KERNEL_PMD) {
-               clone_pgd_range((pgd_t *)pgd + USER_PTRS_PER_PGD,
+       /* If the pgd points to a shared pagetable level (either the
+          ptes in non-PAE, or shared PMD in PAE), then just copy the
+          references from swapper_pg_dir. */
+       if (PAGETABLE_LEVELS == 2 ||
+           (PAGETABLE_LEVELS == 3 && SHARED_KERNEL_PMD)) {
+               clone_pgd_range(pgd + USER_PTRS_PER_PGD,
                                swapper_pg_dir + USER_PTRS_PER_PGD,
                                KERNEL_PGD_PTRS);
-       } else {
-               unsigned long flags;
+               paravirt_alloc_pd_clone(__pa(pgd) >> PAGE_SHIFT,
+                                       __pa(swapper_pg_dir) >> PAGE_SHIFT,
+                                       USER_PTRS_PER_PGD,
+                                       KERNEL_PGD_PTRS);
+       }
 
-               memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
-               spin_lock_irqsave(&pgd_lock, flags);
+       /* list required to sync kernel mapping updates */
+       if (!SHARED_KERNEL_PMD)
                pgd_list_add(pgd);
-               spin_unlock_irqrestore(&pgd_lock, flags);
-       }
+
+       spin_unlock_irqrestore(&pgd_lock, flags);
 }
-#endif /* PTRS_PER_PMD */
 
 static void pgd_dtor(void *pgd)
 {
@@ -276,9 +265,6 @@ static void pgd_dtor(void *pgd)
        spin_unlock_irqrestore(&pgd_lock, flags);
 }
 
-#define UNSHARED_PTRS_PER_PGD                          \
-       (SHARED_KERNEL_PMD ? USER_PTRS_PER_PGD : PTRS_PER_PGD)
-
 #ifdef CONFIG_X86_PAE
 /*
  * Mop up any pmd pages which may still be attached to the pgd.
@@ -286,7 +272,7 @@ static void pgd_dtor(void *pgd)
  * preallocate which never got a corresponding vma will need to be
  * freed manually.
  */
-static void pgd_mop_up_pmds(pgd_t *pgdp)
+static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
 {
        int i;
 
@@ -299,7 +285,7 @@ static void pgd_mop_up_pmds(pgd_t *pgdp)
                        pgdp[i] = native_make_pgd(0);
 
                        paravirt_release_pd(pgd_val(pgd) >> PAGE_SHIFT);
-                       pmd_free(pmd);
+                       pmd_free(mm, pmd);
                }
        }
 }
@@ -327,7 +313,7 @@ static int pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd)
                pmd_t *pmd = pmd_alloc_one(mm, addr);
 
                if (!pmd) {
-                       pgd_mop_up_pmds(pgd);
+                       pgd_mop_up_pmds(mm, pgd);
                        return 0;
                }
 
@@ -347,7 +333,7 @@ static int pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd)
        return 1;
 }
 
-static void pgd_mop_up_pmds(pgd_t *pgd)
+static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
 {
 }
 #endif /* CONFIG_X86_PAE */
@@ -366,9 +352,9 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
        return pgd;
 }
 
-void pgd_free(pgd_t *pgd)
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
-       pgd_mop_up_pmds(pgd);
+       pgd_mop_up_pmds(mm, pgd);
        quicklist_free(0, pgd_dtor, pgd);
 }
 
@@ -387,13 +373,6 @@ void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
 
 void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
 {
-       /* This is called just after the pmd has been detached from
-          the pgd, which requires a full tlb flush to be recognized
-          by the CPU.  Rather than incurring multiple tlb flushes
-          while the address space is being pulled down, make the tlb
-          gathering machinery do a full flush when we're done. */
-       tlb->fullmm = 1;
-
        paravirt_release_pd(__pa(pmd) >> PAGE_SHIFT);
        tlb_remove_page(tlb, virt_to_page(pmd));
 }
index cb63007e20b2af4142a6cf1703987a48ee86c944..74d30ff33c495319e6f45da8097f7fefc5f4f606 100644 (file)
@@ -17,7 +17,7 @@ static void __devinit pci_fixup_i450nx(struct pci_dev *d)
        int pxb, reg;
        u8 busno, suba, subb;
 
-       printk(KERN_WARNING "PCI: Searching for i450NX host bridges on %s\n", pci_name(d));
+       dev_warn(&d->dev, "Searching for i450NX host bridges\n");
        reg = 0xd0;
        for(pxb = 0; pxb < 2; pxb++) {
                pci_read_config_byte(d, reg++, &busno);
@@ -41,7 +41,7 @@ static void __devinit pci_fixup_i450gx(struct pci_dev *d)
         */
        u8 busno;
        pci_read_config_byte(d, 0x4a, &busno);
-       printk(KERN_INFO "PCI: i440KX/GX host bridge %s: secondary bus %02x\n", pci_name(d), busno);
+       dev_info(&d->dev, "i440KX/GX host bridge; secondary bus %02x\n", busno);
        pci_scan_bus_with_sysdata(busno);
        pcibios_last_bus = -1;
 }
@@ -55,7 +55,7 @@ static void __devinit  pci_fixup_umc_ide(struct pci_dev *d)
         */
        int i;
 
-       printk(KERN_WARNING "PCI: Fixing base address flags for device %s\n", pci_name(d));
+       dev_warn(&d->dev, "Fixing base address flags\n");
        for(i = 0; i < 4; i++)
                d->resource[i].flags |= PCI_BASE_ADDRESS_SPACE_IO;
 }
@@ -68,7 +68,7 @@ static void __devinit  pci_fixup_ncr53c810(struct pci_dev *d)
         * Fix class to be PCI_CLASS_STORAGE_SCSI
         */
        if (!d->class) {
-               printk(KERN_WARNING "PCI: fixing NCR 53C810 class code for %s\n", pci_name(d));
+               dev_warn(&d->dev, "Fixing NCR 53C810 class code\n");
                d->class = PCI_CLASS_STORAGE_SCSI << 8;
        }
 }
@@ -80,7 +80,7 @@ static void __devinit  pci_fixup_latency(struct pci_dev *d)
         *  SiS 5597 and 5598 chipsets require latency timer set to
         *  at most 32 to avoid lockups.
         */
-       DBG("PCI: Setting max latency to 32\n");
+       dev_dbg(&d->dev, "Setting max latency to 32\n");
        pcibios_max_latency = 32;
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, pci_fixup_latency);
@@ -138,7 +138,7 @@ static void pci_fixup_via_northbridge_bug(struct pci_dev *d)
 
        pci_read_config_byte(d, where, &v);
        if (v & ~mask) {
-               printk(KERN_WARNING "Disabling VIA memory write queue (PCI ID %04x, rev %02x): [%02x] %02x & %02x -> %02x\n", \
+               dev_warn(&d->dev, "Disabling VIA memory write queue (PCI ID %04x, rev %02x): [%02x] %02x & %02x -> %02x\n", \
                        d->device, d->revision, where, v, mask, v & mask);
                v &= mask;
                pci_write_config_byte(d, where, v);
@@ -200,7 +200,7 @@ static void pci_fixup_nforce2(struct pci_dev *dev)
         * Apply fixup if needed, but don't touch disconnect state
         */
        if ((val & 0x00FF0000) != 0x00010000) {
-               printk(KERN_WARNING "PCI: nForce2 C1 Halt Disconnect fixup\n");
+               dev_warn(&dev->dev, "nForce2 C1 Halt Disconnect fixup\n");
                pci_write_config_dword(dev, 0x6c, (val & 0xFF00FFFF) | 0x00010000);
        }
 }
@@ -348,7 +348,7 @@ static void __devinit pci_fixup_video(struct pci_dev *pdev)
        pci_read_config_word(pdev, PCI_COMMAND, &config);
        if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) {
                pdev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_SHADOW;
-               printk(KERN_DEBUG "Boot video device is %s\n", pci_name(pdev));
+               dev_printk(KERN_DEBUG, &pdev->dev, "Boot video device\n");
        }
 }
 DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_video);
@@ -388,11 +388,11 @@ static void __devinit pci_fixup_msi_k8t_onboard_sound(struct pci_dev *dev)
                /* verify the change for status output */
                pci_read_config_byte(dev, 0x50, &val);
                if (val & 0x40)
-                       printk(KERN_INFO "PCI: Detected MSI K8T Neo2-FIR, "
+                       dev_info(&dev->dev, "Detected MSI K8T Neo2-FIR; "
                                        "can't enable onboard soundcard!\n");
                else
-                       printk(KERN_INFO "PCI: Detected MSI K8T Neo2-FIR, "
-                                       "enabled onboard soundcard.\n");
+                       dev_info(&dev->dev, "Detected MSI K8T Neo2-FIR; "
+                                       "enabled onboard soundcard\n");
        }
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
index 42ba0e2da1a05235f4cade3b9c12315f4eca5134..103b9dff12136b7f87a3498dcf6149d23637175c 100644 (file)
@@ -72,7 +72,7 @@ pcibios_align_resource(void *data, struct resource *res,
                }
        }
 }
-
+EXPORT_SYMBOL(pcibios_align_resource);
 
 /*
  *  Handle resources of PCI devices.  If the world were perfect, we could
index f5f165f69e0c602b9a7619c5d4e316e5ff1839ca..55270c26237ce7ff1f95d65eb17d8c3b81e350d8 100644 (file)
@@ -5,36 +5,62 @@
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/nodemask.h>
+#include <mach_apic.h>
 #include "pci.h"
 
+#define XQUAD_PORTIO_BASE 0xfe400000
+#define XQUAD_PORTIO_QUAD 0x40000  /* 256k per quad. */
+
 #define BUS2QUAD(global) (mp_bus_id_to_node[global])
 #define BUS2LOCAL(global) (mp_bus_id_to_local[global])
 #define QUADLOCAL2BUS(quad,local) (quad_local_to_mp_bus_id[quad][local])
 
+extern void *xquad_portio;    /* Where the IO area was mapped */
+#define XQUAD_PORT_ADDR(port, quad) (xquad_portio + (XQUAD_PORTIO_QUAD*quad) + port)
+
 #define PCI_CONF1_MQ_ADDRESS(bus, devfn, reg) \
        (0x80000000 | (BUS2LOCAL(bus) << 16) | (devfn << 8) | (reg & ~3))
 
+static void write_cf8(unsigned bus, unsigned devfn, unsigned reg)
+{
+       unsigned val = PCI_CONF1_MQ_ADDRESS(bus, devfn, reg);
+       if (xquad_portio)
+               writel(val, XQUAD_PORT_ADDR(0xcf8, BUS2QUAD(bus)));
+       else
+               outl(val, 0xCF8);
+}
+
 static int pci_conf1_mq_read(unsigned int seg, unsigned int bus,
                             unsigned int devfn, int reg, int len, u32 *value)
 {
        unsigned long flags;
+       void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
 
        if (!value || (bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
                return -EINVAL;
 
        spin_lock_irqsave(&pci_config_lock, flags);
 
-       outl_quad(PCI_CONF1_MQ_ADDRESS(bus, devfn, reg), 0xCF8, BUS2QUAD(bus));
+       write_cf8(bus, devfn, reg);
 
        switch (len) {
        case 1:
-               *value = inb_quad(0xCFC + (reg & 3), BUS2QUAD(bus));
+               if (xquad_portio)
+                       *value = readb(adr + (reg & 3));
+               else
+                       *value = inb(0xCFC + (reg & 3));
                break;
        case 2:
-               *value = inw_quad(0xCFC + (reg & 2), BUS2QUAD(bus));
+               if (xquad_portio)
+                       *value = readw(adr + (reg & 2));
+               else
+                       *value = inw(0xCFC + (reg & 2));
                break;
        case 4:
-               *value = inl_quad(0xCFC, BUS2QUAD(bus));
+               if (xquad_portio)
+                       *value = readl(adr);
+               else
+                       *value = inl(0xCFC);
                break;
        }
 
@@ -47,23 +73,33 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
                              unsigned int devfn, int reg, int len, u32 value)
 {
        unsigned long flags;
+       void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
 
        if ((bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255)) 
                return -EINVAL;
 
        spin_lock_irqsave(&pci_config_lock, flags);
 
-       outl_quad(PCI_CONF1_MQ_ADDRESS(bus, devfn, reg), 0xCF8, BUS2QUAD(bus));
+       write_cf8(bus, devfn, reg);
 
        switch (len) {
        case 1:
-               outb_quad((u8)value, 0xCFC + (reg & 3), BUS2QUAD(bus));
+               if (xquad_portio)
+                       writeb(value, adr + (reg & 3));
+               else
+                       outb((u8)value, 0xCFC + (reg & 3));
                break;
        case 2:
-               outw_quad((u16)value, 0xCFC + (reg & 2), BUS2QUAD(bus));
+               if (xquad_portio)
+                       writew(value, adr + (reg & 2));
+               else
+                       outw((u16)value, 0xCFC + (reg & 2));
                break;
        case 4:
-               outl_quad((u32)value, 0xCFC, BUS2QUAD(bus));
+               if (xquad_portio)
+                       writel(value, adr + reg);
+               else
+                       outl((u32)value, 0xCFC);
                break;
        }
 
index d3cb3d6af4c8da3249b4e4cda5602724831dd549..5d5546ce88fe90b02ff376a633a4933b22639685 100644 (file)
@@ -174,11 +174,6 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
-         The PCI-HOWTO, available from
-         <http://www.linuxdoc.org/docs.html#howto>, contains valuable
-         information about which PCI hardware does work under Linux and which
-         doesn't
-
 source "drivers/pci/Kconfig"
 
 config HOTPLUG
@@ -251,8 +246,6 @@ config EMBEDDED_RAMDISK_IMAGE
          provide one yourself.
 endmenu
 
-source "kernel/Kconfig.instrumentation"
-
 source "arch/xtensa/Kconfig.debug"
 
 source "security/Kconfig"
index 60d29fe0b1bdfd7dac917d5b6ad9f3114acc08e3..8df1e842f6d401d060d077246d97d942c2033cad 100644 (file)
@@ -204,7 +204,7 @@ again:
 }
 
 #ifndef CONFIG_GENERIC_CALIBRATE_DELAY
-void __devinit calibrate_delay(void)
+void __cpuinit calibrate_delay(void)
 {
        loops_per_jiffy = CCOUNT_PER_JIFFY;
        printk("Calibrating delay loop (skipped)... "
index 047e533fcc5ba249977895ea1c3969f6a6b0be2e..0f6282207b3223baf9910332681fd5b3eb98295c 100644 (file)
@@ -35,7 +35,7 @@
  * @src: src page
  * @offset: offset in pages to start transaction
  * @len: length in bytes
- * @flags: ASYNC_TX_ASSUME_COHERENT, ASYNC_TX_ACK, ASYNC_TX_DEP_ACK,
+ * @flags: ASYNC_TX_ACK, ASYNC_TX_DEP_ACK,
  * @depend_tx: memcpy depends on the result of this transaction
  * @cb_fn: function to call when the memcpy completes
  * @cb_param: parameter to pass to the callback routine
@@ -46,33 +46,29 @@ async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
        struct dma_async_tx_descriptor *depend_tx,
        dma_async_tx_callback cb_fn, void *cb_param)
 {
-       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_MEMCPY);
+       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_MEMCPY,
+                                                     &dest, 1, &src, 1, len);
        struct dma_device *device = chan ? chan->device : NULL;
-       int int_en = cb_fn ? 1 : 0;
-       struct dma_async_tx_descriptor *tx = device ?
-               device->device_prep_dma_memcpy(chan, len,
-               int_en) : NULL;
+       struct dma_async_tx_descriptor *tx = NULL;
 
-       if (tx) { /* run the memcpy asynchronously */
-               dma_addr_t addr;
-               enum dma_data_direction dir;
+       if (device) {
+               dma_addr_t dma_dest, dma_src;
+               unsigned long dma_prep_flags = cb_fn ? DMA_PREP_INTERRUPT : 0;
 
-               pr_debug("%s: (async) len: %zu\n", __FUNCTION__, len);
-
-               dir = (flags & ASYNC_TX_ASSUME_COHERENT) ?
-                       DMA_NONE : DMA_FROM_DEVICE;
-
-               addr = dma_map_page(device->dev, dest, dest_offset, len, dir);
-               tx->tx_set_dest(addr, tx, 0);
+               dma_dest = dma_map_page(device->dev, dest, dest_offset, len,
+                                       DMA_FROM_DEVICE);
 
-               dir = (flags & ASYNC_TX_ASSUME_COHERENT) ?
-                       DMA_NONE : DMA_TO_DEVICE;
+               dma_src = dma_map_page(device->dev, src, src_offset, len,
+                                      DMA_TO_DEVICE);
 
-               addr = dma_map_page(device->dev, src, src_offset, len, dir);
-               tx->tx_set_src(addr, tx, 0);
+               tx = device->device_prep_dma_memcpy(chan, dma_dest, dma_src,
+                                                   len, dma_prep_flags);
+       }
 
+       if (tx) {
+               pr_debug("%s: (async) len: %zu\n", __FUNCTION__, len);
                async_tx_submit(chan, tx, flags, depend_tx, cb_fn, cb_param);
-       } else { /* run the memcpy synchronously */
+       } else {
                void *dest_buf, *src_buf;
                pr_debug("%s: (sync) len: %zu\n", __FUNCTION__, len);
 
index 66ef6351202ef9cf0f9ddb162524141b92e8b1cf..09c0e83664bc23f4465cad7b6c477ca76b1d46da 100644 (file)
@@ -35,7 +35,7 @@
  * @val: fill value
  * @offset: offset in pages to start transaction
  * @len: length in bytes
- * @flags: ASYNC_TX_ASSUME_COHERENT, ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
+ * @flags: ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
  * @depend_tx: memset depends on the result of this transaction
  * @cb_fn: function to call when the memcpy completes
  * @cb_param: parameter to pass to the callback routine
@@ -46,24 +46,24 @@ async_memset(struct page *dest, int val, unsigned int offset,
        struct dma_async_tx_descriptor *depend_tx,
        dma_async_tx_callback cb_fn, void *cb_param)
 {
-       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_MEMSET);
+       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_MEMSET,
+                                                     &dest, 1, NULL, 0, len);
        struct dma_device *device = chan ? chan->device : NULL;
-       int int_en = cb_fn ? 1 : 0;
-       struct dma_async_tx_descriptor *tx = device ?
-               device->device_prep_dma_memset(chan, val, len,
-                       int_en) : NULL;
+       struct dma_async_tx_descriptor *tx = NULL;
 
-       if (tx) { /* run the memset asynchronously */
-               dma_addr_t dma_addr;
-               enum dma_data_direction dir;
+       if (device) {
+               dma_addr_t dma_dest;
+               unsigned long dma_prep_flags = cb_fn ? DMA_PREP_INTERRUPT : 0;
 
-               pr_debug("%s: (async) len: %zu\n", __FUNCTION__, len);
-               dir = (flags & ASYNC_TX_ASSUME_COHERENT) ?
-                       DMA_NONE : DMA_FROM_DEVICE;
+               dma_dest = dma_map_page(device->dev, dest, offset, len,
+                                       DMA_FROM_DEVICE);
 
-               dma_addr = dma_map_page(device->dev, dest, offset, len, dir);
-               tx->tx_set_dest(dma_addr, tx, 0);
+               tx = device->device_prep_dma_memset(chan, dma_dest, val, len,
+                                                   dma_prep_flags);
+       }
 
+       if (tx) {
+               pr_debug("%s: (async) len: %zu\n", __FUNCTION__, len);
                async_tx_submit(chan, tx, flags, depend_tx, cb_fn, cb_param);
        } else { /* run the memset synchronously */
                void *dest_buf;
index bc18cbb8ea79562ce05401a5734d8310cf2ea938..562882189de589587c475b25770ff46b90eac6ac 100644 (file)
@@ -57,8 +57,7 @@ static struct chan_ref_percpu *channel_table[DMA_TX_TYPE_END];
  */
 static spinlock_t async_tx_lock;
 
-static struct list_head
-async_tx_master_list = LIST_HEAD_INIT(async_tx_master_list);
+static LIST_HEAD(async_tx_master_list);
 
 /* async_tx_issue_pending_all - start all transactions on all channels */
 void async_tx_issue_pending_all(void)
@@ -362,13 +361,13 @@ static void __exit async_tx_exit(void)
 }
 
 /**
- * async_tx_find_channel - find a channel to carry out the operation or let
+ * __async_tx_find_channel - find a channel to carry out the operation or let
  *     the transaction execute synchronously
  * @depend_tx: transaction dependency
  * @tx_type: transaction type
  */
 struct dma_chan *
-async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
+__async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
        enum dma_transaction_type tx_type)
 {
        /* see if we can keep the chain on one channel */
@@ -384,7 +383,7 @@ async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
        } else
                return NULL;
 }
-EXPORT_SYMBOL_GPL(async_tx_find_channel);
+EXPORT_SYMBOL_GPL(__async_tx_find_channel);
 #else
 static int __init async_tx_init(void)
 {
index 2575f674dcd5ee226cb2a29f946e27ab9b9b7c1a..2259a4ff15cb9ce7253f4cc5d4f6132586fe762d 100644 (file)
 #include <linux/raid/xor.h>
 #include <linux/async_tx.h>
 
-static void
-do_async_xor(struct dma_async_tx_descriptor *tx, struct dma_device *device,
+/* do_async_xor - dma map the pages and perform the xor with an engine.
+ *     This routine is marked __always_inline so it can be compiled away
+ *     when CONFIG_DMA_ENGINE=n
+ */
+static __always_inline struct dma_async_tx_descriptor *
+do_async_xor(struct dma_device *device,
        struct dma_chan *chan, struct page *dest, struct page **src_list,
        unsigned int offset, unsigned int src_cnt, size_t len,
        enum async_tx_flags flags, struct dma_async_tx_descriptor *depend_tx,
        dma_async_tx_callback cb_fn, void *cb_param)
 {
-       dma_addr_t dma_addr;
-       enum dma_data_direction dir;
+       dma_addr_t dma_dest;
+       dma_addr_t *dma_src = (dma_addr_t *) src_list;
+       struct dma_async_tx_descriptor *tx;
        int i;
+       unsigned long dma_prep_flags = cb_fn ? DMA_PREP_INTERRUPT : 0;
 
        pr_debug("%s: len: %zu\n", __FUNCTION__, len);
 
-       dir = (flags & ASYNC_TX_ASSUME_COHERENT) ?
-               DMA_NONE : DMA_FROM_DEVICE;
-
-       dma_addr = dma_map_page(device->dev, dest, offset, len, dir);
-       tx->tx_set_dest(dma_addr, tx, 0);
-
-       dir = (flags & ASYNC_TX_ASSUME_COHERENT) ?
-               DMA_NONE : DMA_TO_DEVICE;
+       dma_dest = dma_map_page(device->dev, dest, offset, len,
+                               DMA_FROM_DEVICE);
 
-       for (i = 0; i < src_cnt; i++) {
-               dma_addr = dma_map_page(device->dev, src_list[i],
-                       offset, len, dir);
-               tx->tx_set_src(dma_addr, tx, i);
+       for (i = 0; i < src_cnt; i++)
+               dma_src[i] = dma_map_page(device->dev, src_list[i], offset,
+                                         len, DMA_TO_DEVICE);
+
+       /* Since we have clobbered the src_list we are committed
+        * to doing this asynchronously.  Drivers force forward progress
+        * in case they can not provide a descriptor
+        */
+       tx = device->device_prep_dma_xor(chan, dma_dest, dma_src, src_cnt, len,
+                                        dma_prep_flags);
+       if (!tx) {
+               if (depend_tx)
+                       dma_wait_for_async_tx(depend_tx);
+
+               while (!tx)
+                       tx = device->device_prep_dma_xor(chan, dma_dest,
+                                                        dma_src, src_cnt, len,
+                                                        dma_prep_flags);
        }
 
        async_tx_submit(chan, tx, flags, depend_tx, cb_fn, cb_param);
+
+       return tx;
 }
 
 static void
@@ -102,7 +118,7 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
  * @src_cnt: number of source pages
  * @len: length in bytes
  * @flags: ASYNC_TX_XOR_ZERO_DST, ASYNC_TX_XOR_DROP_DEST,
- *     ASYNC_TX_ASSUME_COHERENT, ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
+ *     ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
  * @depend_tx: xor depends on the result of this transaction.
  * @cb_fn: function to call when the xor completes
  * @cb_param: parameter to pass to the callback routine
@@ -113,14 +129,16 @@ async_xor(struct page *dest, struct page **src_list, unsigned int offset,
        struct dma_async_tx_descriptor *depend_tx,
        dma_async_tx_callback cb_fn, void *cb_param)
 {
-       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_XOR);
+       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_XOR,
+                                                     &dest, 1, src_list,
+                                                     src_cnt, len);
        struct dma_device *device = chan ? chan->device : NULL;
        struct dma_async_tx_descriptor *tx = NULL;
        dma_async_tx_callback _cb_fn;
        void *_cb_param;
        unsigned long local_flags;
        int xor_src_cnt;
-       int i = 0, src_off = 0, int_en;
+       int i = 0, src_off = 0;
 
        BUG_ON(src_cnt <= 1);
 
@@ -140,20 +158,11 @@ async_xor(struct page *dest, struct page **src_list, unsigned int offset,
                                _cb_param = cb_param;
                        }
 
-                       int_en = _cb_fn ? 1 : 0;
-
-                       tx = device->device_prep_dma_xor(
-                               chan, xor_src_cnt, len, int_en);
-
-                       if (tx) {
-                               do_async_xor(tx, device, chan, dest,
-                               &src_list[src_off], offset, xor_src_cnt, len,
-                               local_flags, depend_tx, _cb_fn,
-                               _cb_param);
-                       } else /* fall through */
-                               goto xor_sync;
+                       tx = do_async_xor(device, chan, dest,
+                                         &src_list[src_off], offset,
+                                         xor_src_cnt, len, local_flags,
+                                         depend_tx, _cb_fn, _cb_param);
                } else { /* run the xor synchronously */
-xor_sync:
                        /* in the sync case the dest is an implied source
                         * (assumes the dest is at the src_off index)
                         */
@@ -242,7 +251,7 @@ static int page_is_zero(struct page *p, unsigned int offset, size_t len)
  * @src_cnt: number of source pages
  * @len: length in bytes
  * @result: 0 if sum == 0 else non-zero
- * @flags: ASYNC_TX_ASSUME_COHERENT, ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
+ * @flags: ASYNC_TX_ACK, ASYNC_TX_DEP_ACK
  * @depend_tx: xor depends on the result of this transaction.
  * @cb_fn: function to call when the xor completes
  * @cb_param: parameter to pass to the callback routine
@@ -254,29 +263,36 @@ async_xor_zero_sum(struct page *dest, struct page **src_list,
        struct dma_async_tx_descriptor *depend_tx,
        dma_async_tx_callback cb_fn, void *cb_param)
 {
-       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_ZERO_SUM);
+       struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_ZERO_SUM,
+                                                     &dest, 1, src_list,
+                                                     src_cnt, len);
        struct dma_device *device = chan ? chan->device : NULL;
-       int int_en = cb_fn ? 1 : 0;
-       struct dma_async_tx_descriptor *tx = device ?
-               device->device_prep_dma_zero_sum(chan, src_cnt, len, result,
-                       int_en) : NULL;
-       int i;
+       struct dma_async_tx_descriptor *tx = NULL;
 
        BUG_ON(src_cnt <= 1);
 
-       if (tx) {
-               dma_addr_t dma_addr;
-               enum dma_data_direction dir;
+       if (device) {
+               dma_addr_t *dma_src = (dma_addr_t *) src_list;
+               unsigned long dma_prep_flags = cb_fn ? DMA_PREP_INTERRUPT : 0;
+               int i;
 
                pr_debug("%s: (async) len: %zu\n", __FUNCTION__, len);
 
-               dir = (flags & ASYNC_TX_ASSUME_COHERENT) ?
-                       DMA_NONE : DMA_TO_DEVICE;
-
-               for (i = 0; i < src_cnt; i++) {
-                       dma_addr = dma_map_page(device->dev, src_list[i],
-                               offset, len, dir);
-                       tx->tx_set_src(dma_addr, tx, i);
+               for (i = 0; i < src_cnt; i++)
+                       dma_src[i] = dma_map_page(device->dev, src_list[i],
+                                                 offset, len, DMA_TO_DEVICE);
+
+               tx = device->device_prep_dma_zero_sum(chan, dma_src, src_cnt,
+                                                     len, result,
+                                                     dma_prep_flags);
+               if (!tx) {
+                       if (depend_tx)
+                               dma_wait_for_async_tx(depend_tx);
+
+                       while (!tx)
+                               tx = device->device_prep_dma_zero_sum(chan,
+                                       dma_src, src_cnt, len, result,
+                                       dma_prep_flags);
                }
 
                async_tx_submit(chan, tx, flags, depend_tx, cb_fn, cb_param);
@@ -311,6 +327,16 @@ EXPORT_SYMBOL_GPL(async_xor_zero_sum);
 
 static int __init async_xor_init(void)
 {
+       #ifdef CONFIG_DMA_ENGINE
+       /* To conserve stack space the input src_list (array of page pointers)
+        * is reused to hold the array of dma addresses passed to the driver.
+        * This conversion is only possible when dma_addr_t is less than the
+        * the size of a pointer.  HIGHMEM64G is known to violate this
+        * assumption.
+        */
+       BUILD_BUG_ON(sizeof(dma_addr_t) > sizeof(struct page *));
+       #endif
+
        return 0;
 }
 
index 08d4ae201597cde366f07efc2a4a8f4f8e08d83e..d74d9fbb9fd21177eca9f2096d8df82fc4f2b469 100644 (file)
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig"
 
 source "drivers/spi/Kconfig"
 
+source "drivers/gpio/Kconfig"
+
 source "drivers/w1/Kconfig"
 
 source "drivers/power/Kconfig"
@@ -91,6 +93,4 @@ source "drivers/dca/Kconfig"
 source "drivers/auxdisplay/Kconfig"
 
 source "drivers/uio/Kconfig"
-
-source "drivers/virtio/Kconfig"
 endmenu
index 0ee9a8a4095e6a5106789717dc57516a73d81fa8..f1c11db52a57e09b30b13380b1b000923dafcf3b 100644 (file)
@@ -5,6 +5,7 @@
 # Rewritten to use lists instead of if-statements.
 #
 
+obj-$(CONFIG_HAVE_GPIO_LIB)    += gpio/
 obj-$(CONFIG_PCI)              += pci/
 obj-$(CONFIG_PARISC)           += parisc/
 obj-$(CONFIG_RAPIDIO)          += rapidio/
index d915fec9bf63e8c1f085dff9ea18f36f1b7ce20d..d25ef961415cefdeebab67ac29f5a5f49d87ff18 100644 (file)
@@ -142,6 +142,7 @@ struct asus_hotk {
                xxN,            //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
                A4S,            //Z81sp
                //(Centrino)
+               F3Sa,
                END_MODEL
        } model;                //Models currently supported
        u16 event_count[128];   //count for each event TODO make this better
@@ -405,7 +406,20 @@ static struct model_data model_conf[END_MODEL] = {
                .brightness_get    = "GPLV",
                .mt_bt_switch      = "BLED",
                .mt_wled           = "WLED"
-       }
+       },
+
+       {
+               .name           = "F3Sa",
+               .mt_bt_switch   = "BLED",
+               .mt_wled        = "WLED",
+               .mt_mled        = "MLED",
+               .brightness_get = "GPLV",
+               .brightness_set = "SPLV",
+               .mt_lcd_switch  = "\\_SB.PCI0.SBRG.EC0._Q10",
+               .lcd_status     = "\\_SB.PCI0.SBRG.EC0.RPIN",
+               .display_get    = "\\ADVG",
+               .display_set    = "SDSP",
+       },
 
 };
 
@@ -710,15 +724,8 @@ static int get_lcd_state(void)
 {
        int lcd = 0;
 
-       if (hotk->model != L3H) {
-               /* We don't have to check anything if we are here */
-               if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
-                       printk(KERN_WARNING
-                              "Asus ACPI: Error reading LCD status\n");
-
-               if (hotk->model == L2D)
-                       lcd = ~lcd;
-       } else {                /* L3H and the like have to be handled differently */
+       if (hotk->model == L3H) {
+               /* L3H and the like have to be handled differently */
                acpi_status status = 0;
                struct acpi_object_list input;
                union acpi_object mt_params[2];
@@ -745,6 +752,32 @@ static int get_lcd_state(void)
                if (out_obj.type == ACPI_TYPE_INTEGER)
                        /* That's what the AML code does */
                        lcd = out_obj.integer.value >> 8;
+       } else if (hotk->model == F3Sa) {
+               unsigned long tmp;
+               union acpi_object param;
+               struct acpi_object_list input;
+               acpi_status status;
+
+               /* Read pin 11 */
+               param.type = ACPI_TYPE_INTEGER;
+               param.integer.value = 0x11;
+               input.count = 1;
+               input.pointer = &param;
+
+               status = acpi_evaluate_integer(NULL, hotk->methods->lcd_status,
+                                               &input, &tmp);
+               if (status != AE_OK)
+                       return -1;
+
+               lcd = tmp;
+       } else {
+               /* We don't have to check anything if we are here */
+               if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
+                       printk(KERN_WARNING
+                              "Asus ACPI: Error reading LCD status\n");
+
+               if (hotk->model == L2D)
+                       lcd = ~lcd;
        }
 
        return (lcd & 1);
@@ -1134,6 +1167,8 @@ static int asus_model_match(char *model)
                return W5A;
        else if (strncmp(model, "A4S", 3) == 0)
                return A4S;
+       else if (strncmp(model, "F3Sa", 4) == 0)
+               return F3Sa;
        else
                return END_MODEL;
 }
index c4a769d1ba8542bf0210f71eb6930641c9062a2f..f6215e8098086887f11b414e180923479949c467 100644 (file)
@@ -194,6 +194,9 @@ static int acpi_battery_get_property(struct power_supply *psy,
        case POWER_SUPPLY_PROP_MANUFACTURER:
                val->strval = battery->oem_info;
                break;
+       case POWER_SUPPLY_PROP_SERIAL_NUMBER:
+               val->strval = battery->serial_number;
+               break;
        default:
                return -EINVAL;
        }
@@ -212,6 +215,7 @@ static enum power_supply_property charge_battery_props[] = {
        POWER_SUPPLY_PROP_CHARGE_NOW,
        POWER_SUPPLY_PROP_MODEL_NAME,
        POWER_SUPPLY_PROP_MANUFACTURER,
+       POWER_SUPPLY_PROP_SERIAL_NUMBER,
 };
 
 static enum power_supply_property energy_battery_props[] = {
@@ -226,6 +230,7 @@ static enum power_supply_property energy_battery_props[] = {
        POWER_SUPPLY_PROP_ENERGY_NOW,
        POWER_SUPPLY_PROP_MODEL_NAME,
        POWER_SUPPLY_PROP_MANUFACTURER,
+       POWER_SUPPLY_PROP_SERIAL_NUMBER,
 };
 #endif
 
index 81b2484297037e4b4c4e86e9b82d431e50021f00..fd1c4ba63367469f9826460c6b545407491f9f86 100644 (file)
@@ -192,18 +192,13 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
        arg.type = ACPI_TYPE_INTEGER;
        arg.integer.value = sleep_state;
 
-       /* Run the _PTS and _GTS methods */
+       /* Run the _PTS method */
 
        status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL);
        if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
                return_ACPI_STATUS(status);
        }
 
-       status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL);
-       if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
-               return_ACPI_STATUS(status);
-       }
-
        /* Setup the argument to _SST */
 
        switch (sleep_state) {
@@ -234,10 +229,6 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
                                "While executing method _SST"));
        }
 
-       /* Disable/Clear all GPEs */
-
-       status = acpi_hw_disable_all_gpes();
-
        return_ACPI_STATUS(status);
 }
 
@@ -262,6 +253,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
        struct acpi_bit_register_info *sleep_type_reg_info;
        struct acpi_bit_register_info *sleep_enable_reg_info;
        u32 in_value;
+       struct acpi_object_list arg_list;
+       union acpi_object arg;
        acpi_status status;
 
        ACPI_FUNCTION_TRACE(acpi_enter_sleep_state);
@@ -307,6 +300,18 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
                return_ACPI_STATUS(status);
        }
 
+       /* Execute the _GTS method */
+
+       arg_list.count = 1;
+       arg_list.pointer = &arg;
+       arg.type = ACPI_TYPE_INTEGER;
+       arg.integer.value = sleep_state;
+
+       status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL);
+       if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+               return_ACPI_STATUS(status);
+       }
+
        /* Get current value of PM1A control */
 
        status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
@@ -473,17 +478,18 @@ ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_leave_sleep_state
+ * FUNCTION:    acpi_leave_sleep_state_prep
  *
- * PARAMETERS:  sleep_state         - Which sleep state we just exited
+ * PARAMETERS:  sleep_state         - Which sleep state we are exiting
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
- *              Called with interrupts ENABLED.
+ * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
+ *              sleep.
+ *              Called with interrupts DISABLED.
  *
  ******************************************************************************/
-acpi_status acpi_leave_sleep_state(u8 sleep_state)
+acpi_status acpi_leave_sleep_state_prep(u8 sleep_state)
 {
        struct acpi_object_list arg_list;
        union acpi_object arg;
@@ -493,7 +499,7 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
        u32 PM1Acontrol;
        u32 PM1Bcontrol;
 
-       ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
+       ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep);
 
        /*
         * Set SLP_TYPE and SLP_EN to state S0.
@@ -540,6 +546,41 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
                }
        }
 
+       /* Execute the _BFS method */
+
+       arg_list.count = 1;
+       arg_list.pointer = &arg;
+       arg.type = ACPI_TYPE_INTEGER;
+       arg.integer.value = sleep_state;
+
+       status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL);
+       if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+               ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS"));
+       }
+
+       return_ACPI_STATUS(status);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_leave_sleep_state
+ *
+ * PARAMETERS:  sleep_state         - Which sleep state we just exited
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
+ *              Called with interrupts ENABLED.
+ *
+ ******************************************************************************/
+acpi_status acpi_leave_sleep_state(u8 sleep_state)
+{
+       struct acpi_object_list arg_list;
+       union acpi_object arg;
+       acpi_status status;
+
+       ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
+
        /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
 
        acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
@@ -558,12 +599,6 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
                ACPI_EXCEPTION((AE_INFO, status, "During Method _SST"));
        }
 
-       arg.integer.value = sleep_state;
-       status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL);
-       if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
-               ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS"));
-       }
-
        /*
         * GPEs must be enabled before _WAK is called as GPEs
         * might get fired there
index eb1f82f79153c0d3c6f9136b8a88faf829c886d1..199ea21461534cf835cefdafd641b5194bc8a1d1 100644 (file)
@@ -38,7 +38,7 @@
 #include <linux/dmi.h>
 #include <linux/moduleparam.h>
 #include <linux/sched.h>       /* need_resched() */
-#include <linux/latency.h>
+#include <linux/pm_qos_params.h>
 #include <linux/clockchips.h>
 #include <linux/cpuidle.h>
 
@@ -648,7 +648,8 @@ static void acpi_processor_idle(void)
        if (cx->promotion.state &&
            ((cx->promotion.state - pr->power.states) <= max_cstate)) {
                if (sleep_ticks > cx->promotion.threshold.ticks &&
-                 cx->promotion.state->latency <= system_latency_constraint()) {
+                 cx->promotion.state->latency <=
+                               pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) {
                        cx->promotion.count++;
                        cx->demotion.count = 0;
                        if (cx->promotion.count >=
@@ -692,7 +693,8 @@ static void acpi_processor_idle(void)
         * or if the latency of the current state is unacceptable
         */
        if ((pr->power.state - pr->power.states) > max_cstate ||
-               pr->power.state->latency > system_latency_constraint()) {
+               pr->power.state->latency >
+                               pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) {
                if (cx->demotion.state)
                        next_state = cx->demotion.state;
        }
@@ -1200,7 +1202,7 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
                   "maximum allowed latency: %d usec\n",
                   pr->power.state ? pr->power.state - pr->power.states : 0,
                   max_cstate, (unsigned)pr->power.bm_activity,
-                  system_latency_constraint());
+                  pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
 
        seq_puts(seq, "states:\n");
 
@@ -1718,8 +1720,9 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
                               "ACPI: processor limited to max C-state %d\n",
                               max_cstate);
                first_run++;
-#if !defined (CONFIG_CPU_IDLE) && defined (CONFIG_SMP)
-               register_latency_notifier(&acpi_processor_latency_notifier);
+#if !defined(CONFIG_CPU_IDLE) && defined(CONFIG_SMP)
+               pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY,
+                               &acpi_processor_latency_notifier);
 #endif
        }
 
@@ -1806,7 +1809,8 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
                 */
                cpu_idle_wait();
 #ifdef CONFIG_SMP
-               unregister_latency_notifier(&acpi_processor_latency_notifier);
+               pm_qos_remove_notifier(PM_QOS_CPU_DMA_LATENCY,
+                               &acpi_processor_latency_notifier);
 #endif
        }
 #endif
index cbfe9ae7a9e55226d82c86e6e6947121ee6e7adc..d9d531cce27f26e401ff920b8325968b5fd4fb37 100644 (file)
@@ -830,7 +830,7 @@ static int acpi_bus_get_flags(struct acpi_device *device)
        if (ACPI_SUCCESS(status))
                device->flags.wake_capable = 1;
 
-       /* TBD: Peformance management */
+       /* TBD: Performance management */
 
        return 0;
 }
index 2c0b6630f8ba54603530fce4574f8697faaabe9e..7f97e32fc33f7d049c14e63b258da3c4b1e1d283 100644 (file)
@@ -26,9 +26,24 @@ u8 sleep_states[ACPI_S_STATE_COUNT];
 
 #ifdef CONFIG_PM_SLEEP
 static u32 acpi_target_sleep_state = ACPI_STATE_S0;
+static bool acpi_sleep_finish_wake_up;
+
+/*
+ * ACPI 2.0 and later want us to execute _PTS after suspending devices, so we
+ * allow the user to request that behavior by using the 'acpi_new_pts_ordering'
+ * kernel command line option that causes the following variable to be set.
+ */
+static bool new_pts_ordering;
+
+static int __init acpi_new_pts_ordering(char *str)
+{
+       new_pts_ordering = true;
+       return 1;
+}
+__setup("acpi_new_pts_ordering", acpi_new_pts_ordering);
 #endif
 
-int acpi_sleep_prepare(u32 acpi_state)
+static int acpi_sleep_prepare(u32 acpi_state)
 {
 #ifdef CONFIG_ACPI_SLEEP
        /* do we have a wakeup address for S2 and S3? */
@@ -44,6 +59,8 @@ int acpi_sleep_prepare(u32 acpi_state)
        ACPI_FLUSH_CPU_CACHE();
        acpi_enable_wakeup_device_prep(acpi_state);
 #endif
+       printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
+               acpi_state);
        acpi_enter_sleep_state_prep(acpi_state);
        return 0;
 }
@@ -63,17 +80,25 @@ static u32 acpi_suspend_states[] = {
 static int init_8259A_after_S1;
 
 /**
- *     acpi_pm_set_target - Set the target system sleep state to the state
+ *     acpi_pm_begin - Set the target system sleep state to the state
  *             associated with given @pm_state, if supported.
  */
 
-static int acpi_pm_set_target(suspend_state_t pm_state)
+static int acpi_pm_begin(suspend_state_t pm_state)
 {
        u32 acpi_state = acpi_suspend_states[pm_state];
        int error = 0;
 
        if (sleep_states[acpi_state]) {
                acpi_target_sleep_state = acpi_state;
+               if (new_pts_ordering)
+                       return 0;
+
+               error = acpi_sleep_prepare(acpi_state);
+               if (error)
+                       acpi_target_sleep_state = ACPI_STATE_S0;
+               else
+                       acpi_sleep_finish_wake_up = true;
        } else {
                printk(KERN_ERR "ACPI does not support this state: %d\n",
                        pm_state);
@@ -91,12 +116,17 @@ static int acpi_pm_set_target(suspend_state_t pm_state)
 
 static int acpi_pm_prepare(void)
 {
-       int error = acpi_sleep_prepare(acpi_target_sleep_state);
+       if (new_pts_ordering) {
+               int error = acpi_sleep_prepare(acpi_target_sleep_state);
 
-       if (error)
-               acpi_target_sleep_state = ACPI_STATE_S0;
+               if (error) {
+                       acpi_target_sleep_state = ACPI_STATE_S0;
+                       return error;
+               }
+               acpi_sleep_finish_wake_up = true;
+       }
 
-       return error;
+       return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT;
 }
 
 /**
@@ -120,10 +150,8 @@ static int acpi_pm_enter(suspend_state_t pm_state)
        if (acpi_state == ACPI_STATE_S3) {
                int error = acpi_save_state_mem();
 
-               if (error) {
-                       acpi_target_sleep_state = ACPI_STATE_S0;
+               if (error)
                        return error;
-               }
        }
 
        local_irq_save(flags);
@@ -139,6 +167,9 @@ static int acpi_pm_enter(suspend_state_t pm_state)
                break;
        }
 
+       /* Reprogram control registers and execute _BFS */
+       acpi_leave_sleep_state_prep(acpi_state);
+
        /* ACPI 3.0 specs (P62) says that it's the responsabilty
         * of the OSPM to clear the status bit [ implying that the
         * POWER_BUTTON event should not reach userspace ]
@@ -146,6 +177,13 @@ static int acpi_pm_enter(suspend_state_t pm_state)
        if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
                acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
 
+       /*
+        * Disable and clear GPE status before interrupt is enabled. Some GPEs
+        * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
+        * acpi_leave_sleep_state will reenable specific GPEs later
+        */
+       acpi_hw_disable_all_gpes();
+
        local_irq_restore(flags);
        printk(KERN_DEBUG "Back to C!\n");
 
@@ -157,7 +195,7 @@ static int acpi_pm_enter(suspend_state_t pm_state)
 }
 
 /**
- *     acpi_pm_finish - Finish up suspend sequence.
+ *     acpi_pm_finish - Instruct the platform to leave a sleep state.
  *
  *     This is called after we wake back up (or if entering the sleep state
  *     failed). 
@@ -174,6 +212,7 @@ static void acpi_pm_finish(void)
        acpi_set_firmware_waking_vector((acpi_physical_address) 0);
 
        acpi_target_sleep_state = ACPI_STATE_S0;
+       acpi_sleep_finish_wake_up = false;
 
 #ifdef CONFIG_X86
        if (init_8259A_after_S1) {
@@ -183,6 +222,20 @@ static void acpi_pm_finish(void)
 #endif
 }
 
+/**
+ *     acpi_pm_end - Finish up suspend sequence.
+ */
+
+static void acpi_pm_end(void)
+{
+       /*
+        * This is necessary in case acpi_pm_finish() is not called directly
+        * during a failing transition to a sleep state.
+        */
+       if (acpi_sleep_finish_wake_up)
+               acpi_pm_finish();
+}
+
 static int acpi_pm_state_valid(suspend_state_t pm_state)
 {
        u32 acpi_state;
@@ -201,10 +254,11 @@ static int acpi_pm_state_valid(suspend_state_t pm_state)
 
 static struct platform_suspend_ops acpi_pm_ops = {
        .valid = acpi_pm_state_valid,
-       .set_target = acpi_pm_set_target,
+       .begin = acpi_pm_begin,
        .prepare = acpi_pm_prepare,
        .enter = acpi_pm_enter,
        .finish = acpi_pm_finish,
+       .end = acpi_pm_end,
 };
 
 /*
@@ -229,15 +283,36 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
 #endif /* CONFIG_SUSPEND */
 
 #ifdef CONFIG_HIBERNATION
-static int acpi_hibernation_start(void)
+static int acpi_hibernation_begin(void)
 {
+       int error;
+
        acpi_target_sleep_state = ACPI_STATE_S4;
-       return 0;
+       if (new_pts_ordering)
+               return 0;
+
+       error = acpi_sleep_prepare(ACPI_STATE_S4);
+       if (error)
+               acpi_target_sleep_state = ACPI_STATE_S0;
+       else
+               acpi_sleep_finish_wake_up = true;
+
+       return error;
 }
 
 static int acpi_hibernation_prepare(void)
 {
-       return acpi_sleep_prepare(ACPI_STATE_S4);
+       if (new_pts_ordering) {
+               int error = acpi_sleep_prepare(ACPI_STATE_S4);
+
+               if (error) {
+                       acpi_target_sleep_state = ACPI_STATE_S0;
+                       return error;
+               }
+               acpi_sleep_finish_wake_up = true;
+       }
+
+       return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT;
 }
 
 static int acpi_hibernation_enter(void)
@@ -251,6 +326,8 @@ static int acpi_hibernation_enter(void)
        acpi_enable_wakeup_device(ACPI_STATE_S4);
        /* This shouldn't return.  If it returns, we have a problem */
        status = acpi_enter_sleep_state(ACPI_STATE_S4);
+       /* Reprogram control registers and execute _BFS */
+       acpi_leave_sleep_state_prep(ACPI_STATE_S4);
        local_irq_restore(flags);
 
        return ACPI_SUCCESS(status) ? 0 : -EFAULT;
@@ -263,15 +340,12 @@ static void acpi_hibernation_leave(void)
         * enable it here.
         */
        acpi_enable();
+       /* Reprogram control registers and execute _BFS */
+       acpi_leave_sleep_state_prep(ACPI_STATE_S4);
 }
 
 static void acpi_hibernation_finish(void)
 {
-       /*
-        * If ACPI is not enabled by the BIOS and the boot kernel, we need to
-        * enable it here.
-        */
-       acpi_enable();
        acpi_disable_wakeup_device(ACPI_STATE_S4);
        acpi_leave_sleep_state(ACPI_STATE_S4);
 
@@ -279,6 +353,17 @@ static void acpi_hibernation_finish(void)
        acpi_set_firmware_waking_vector((acpi_physical_address) 0);
 
        acpi_target_sleep_state = ACPI_STATE_S0;
+       acpi_sleep_finish_wake_up = false;
+}
+
+static void acpi_hibernation_end(void)
+{
+       /*
+        * This is necessary in case acpi_hibernation_finish() is not called
+        * directly during a failing transition to the sleep state.
+        */
+       if (acpi_sleep_finish_wake_up)
+               acpi_hibernation_finish();
 }
 
 static int acpi_hibernation_pre_restore(void)
@@ -296,7 +381,8 @@ static void acpi_hibernation_restore_cleanup(void)
 }
 
 static struct platform_hibernation_ops acpi_hibernation_ops = {
-       .start = acpi_hibernation_start,
+       .begin = acpi_hibernation_begin,
+       .end = acpi_hibernation_end,
        .pre_snapshot = acpi_hibernation_prepare,
        .finish = acpi_hibernation_finish,
        .prepare = acpi_hibernation_prepare,
@@ -386,11 +472,20 @@ int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p)
        if (acpi_target_sleep_state == ACPI_STATE_S0 ||
            (wake && adev->wakeup.state.enabled &&
             adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
+               acpi_status status;
+
                acpi_method[3] = 'W';
-               acpi_evaluate_integer(handle, acpi_method, NULL, &d_max);
-               /* Sanity check */
-               if (d_max < d_min)
+               status = acpi_evaluate_integer(handle, acpi_method, NULL,
+                                               &d_max);
+               if (ACPI_FAILURE(status)) {
+                       d_max = d_min;
+               } else if (d_max < d_min) {
+                       /* Warn the user of the broken DSDT */
+                       printk(KERN_WARNING "ACPI: Wrong value from %s\n",
+                               acpi_method);
+                       /* Sanitize it */
                        d_min = d_max;
+               }
        }
 
        if (d_min_p)
@@ -403,6 +498,7 @@ static void acpi_power_off_prepare(void)
 {
        /* Prepare to power off the system */
        acpi_sleep_prepare(ACPI_STATE_S5);
+       acpi_hw_disable_all_gpes();
 }
 
 static void acpi_power_off(void)
index a2ea125ae2d0e961c52aa909bdbb9083e2e5ea97..cfaf8f5b0a149b3b7bdcf056ebfcd2bfc7fb9870 100644 (file)
@@ -5,5 +5,3 @@ extern int acpi_suspend (u32 state);
 extern void acpi_enable_wakeup_device_prep(u8 sleep_state);
 extern void acpi_enable_wakeup_device(u8 sleep_state);
 extern void acpi_disable_wakeup_device(u8 sleep_state);
-
-extern int acpi_sleep_prepare(u32 acpi_state);
index cbbd3315a1e22bbc9eacc32942ccaded198c14a7..b630ee137ee197b4a2c8c9555ce1879886a26a3b 100644 (file)
@@ -1,6 +1,6 @@
 /*******************************************************************************
  *
- * Module Name: utresrc - Resource managment utilities
+ * Module Name: utresrc - Resource management utilities
  *
  ******************************************************************************/
 
index 27c8d56111c2959b8d7f6cb64b9dccd85cee8a39..29e71bddd6ffdd12420b4749eb88f79fb51ead26 100644 (file)
@@ -679,24 +679,20 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
 
        /* cross check port_map and cap.n_ports */
        if (port_map) {
-               u32 tmp_port_map = port_map;
-               int n_ports = ahci_nr_ports(cap);
+               int map_ports = 0;
 
-               for (i = 0; i < AHCI_MAX_PORTS && n_ports; i++) {
-                       if (tmp_port_map & (1 << i)) {
-                               n_ports--;
-                               tmp_port_map &= ~(1 << i);
-                       }
-               }
+               for (i = 0; i < AHCI_MAX_PORTS; i++)
+                       if (port_map & (1 << i))
+                               map_ports++;
 
-               /* If n_ports and port_map are inconsistent, whine and
-                * clear port_map and let it be generated from n_ports.
+               /* If PI has more ports than n_ports, whine, clear
+                * port_map and let it be generated from n_ports.
                 */
-               if (n_ports || tmp_port_map) {
+               if (map_ports > ahci_nr_ports(cap)) {
                        dev_printk(KERN_WARNING, &pdev->dev,
-                                  "nr_ports (%u) and implemented port map "
-                                  "(0x%x) don't match, using nr_ports\n",
-                                  ahci_nr_ports(cap), port_map);
+                                  "implemented port map (0x%x) contains more "
+                                  "ports than nr_ports (%u), using nr_ports\n",
+                                  port_map, ahci_nr_ports(cap));
                        port_map = 0;
                }
        }
@@ -2201,7 +2197,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        struct device *dev = &pdev->dev;
        struct ahci_host_priv *hpriv;
        struct ata_host *host;
-       int i, rc;
+       int n_ports, i, rc;
 
        VPRINTK("ENTER\n");
 
@@ -2255,7 +2251,14 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (hpriv->cap & HOST_CAP_PMP)
                pi.flags |= ATA_FLAG_PMP;
 
-       host = ata_host_alloc_pinfo(&pdev->dev, ppi, fls(hpriv->port_map));
+       /* CAP.NP sometimes indicate the index of the last enabled
+        * port, at other times, that of the last possible port, so
+        * determining the maximum port number requires looking at
+        * both CAP.NP and port_map.
+        */
+       n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
+
+       host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
        if (!host)
                return -ENOMEM;
        host->iomap = pcim_iomap_table(pdev);
index 47892e6f5ded72f310e0de62c0ec152ce6350f7e..9c2515f67de56c41237ceb20c221a5fa4e5db2a5 100644 (file)
@@ -837,7 +837,7 @@ static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev)
        if (is_slave) {
                /* clear TIME1|IE1|PPE1|DTE1 */
                master_data &= 0xff0f;
-               /* Enable SITRE (seperate slave timing register) */
+               /* Enable SITRE (separate slave timing register) */
                master_data |= 0x4000;
                /* enable PPE1, IE1 and TIME1 as needed */
                master_data |= (control << 4);
@@ -1603,7 +1603,8 @@ static void piix_iocfg_bit18_quirk(struct pci_dev *pdev)
  *     Zero on success, or -ERRNO value.
  */
 
-static int piix_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int __devinit piix_init_one(struct pci_dev *pdev,
+                                  const struct pci_device_id *ent)
 {
        static int printed_version;
        struct device *dev = &pdev->dev;
index bdbd55af70228ad38e646a4aa9e8bfcc1f0d0f37..3011919f3ec88f0860d39445d596d5f454f604d6 100644 (file)
@@ -3097,7 +3097,7 @@ static int ata_dev_set_mode(struct ata_device *dev)
 /**
  *     ata_do_set_mode - Program timings and issue SET FEATURES - XFER
  *     @link: link on which timings will be programmed
- *     @r_failed_dev: out paramter for failed device
+ *     @r_failed_dev: out parameter for failed device
  *
  *     Standard implementation of the function used to tune and set
  *     ATA device disk transfer mode (PIO3, UDMA6, etc.).  If
@@ -4154,8 +4154,6 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        /* NCQ is broken */
        { "Maxtor *",           "BANC*",        ATA_HORKAGE_NONCQ },
        { "Maxtor 7V300F0",     "VA111630",     ATA_HORKAGE_NONCQ },
-       { "HITACHI HDS7250SASUN500G*", NULL,    ATA_HORKAGE_NONCQ },
-       { "HITACHI HDS7225SBSUN250G*", NULL,    ATA_HORKAGE_NONCQ },
        { "ST380817AS",         "3.42",         ATA_HORKAGE_NONCQ },
        { "ST3160023AS",        "3.42",         ATA_HORKAGE_NONCQ },
 
index 67e574de31e855c5ae6b1a046d1bc3f5b5f29c1c..db057b183d601b95c9ff950bfaef5acba39de562 100644 (file)
@@ -324,7 +324,7 @@ static int __init pata_at32_probe(struct platform_device *pdev)
        if (irq < 0)
                return irq;
 
-       /* Setup struct containing private infomation */
+       /* Setup struct containing private information */
        info = kzalloc(sizeof(struct at32_ide_info), GFP_KERNEL);
        if (!info)
                return -ENOMEM;
index d4590f546c497c7aa2ae2a365bc1d2a0232b4bff..7ed279b0a12edb90af54c013261cfadf88a8d5c1 100644 (file)
@@ -229,7 +229,7 @@ static int __devinit cs5520_init_one(struct pci_dev *pdev, const struct pci_devi
                return -ENOMEM;
 
        /* Perform set up for DMA */
-       if (pci_enable_device_bars(pdev, 1<<2)) {
+       if (pci_enable_device_io(pdev)) {
                printk(KERN_ERR DRV_NAME ": unable to configure BAR2.\n");
                return -ENODEV;
        }
index 043dcd35106c0877aed1ce07e91a8f6a9d4b8892..dc33220fe5b20ca9588af25522d40288627bf2cf 100644 (file)
@@ -135,7 +135,7 @@ static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev)
                idetm_data &= 0xCC0F;
                idetm_data |= (control << 4);
 
-               /* Slave timing in seperate register */
+               /* Slave timing in separate register */
                pci_read_config_byte(dev, 0x44, &slave_data);
                slave_data &= 0x0F << shift;
                slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << shift;
index 1eda821e5e395b32dd78a86bc8c7ab2bd58fd537..e0c2cc29d0ca93d60b970441ef0d4d54599aced9 100644 (file)
@@ -128,7 +128,7 @@ static void it8213_set_piomode (struct ata_port *ap, struct ata_device *adev)
                idetm_data &= 0xCC0F;
                idetm_data |= (control << 4);
 
-               /* Slave timing in seperate register */
+               /* Slave timing in separate register */
                pci_read_config_byte(dev, 0x44, &slave_data);
                slave_data &= 0xF0;
                slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << 4;
index 938f48a807ebf5369d089b12300b3b7d1644a7ed..408da30594c442564f311deea0dcb62d7f14bc8b 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 
 static int __devinit pata_of_platform_probe(struct of_device *ofdev,
                                            const struct of_device_id *match)
index 224bb6c2030a3e33fd129f4bf92b59fa661517f3..aad7adc6ea564c9f50dbbcf443ce1396fdbf7593 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/ata.h>
 #include <linux/libata.h>
 #include <linux/platform_device.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 
 #define DRV_NAME "pata_platform"
 #define DRV_VERSION "1.2"
index 87546d9f1ca0839cf5067d94116af34ae297c7e7..dc7e91562e436fafadab3d2796e328ac4cf5b351 100644 (file)
@@ -345,7 +345,7 @@ static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
 
        if (adev->dma_mode < XFER_UDMA_0) {
                /* bits 3-0 hold recovery timing bits 8-10 active timing and
-                  the higer bits are dependant on the device */
+                  the higher bits are dependant on the device */
                timing &= ~0x870F;
                timing |= mwdma_bits[speed];
        } else {
@@ -385,7 +385,7 @@ static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
 
        if (adev->dma_mode < XFER_UDMA_0) {
                /* bits 3-0 hold recovery timing bits 8-10 active timing and
-                  the higer bits are dependant on the device, bit 15 udma */
+                  the higher bits are dependant on the device, bit 15 udma */
                timing &= ~0x870F;
                timing |= mwdma_bits[speed];
        } else {
index 922d7b2efba8cf50b6d2a1b8bb144630474623e1..efcb66b6cceff96755b886a7aade98c642530e59 100644 (file)
@@ -355,8 +355,8 @@ static unsigned int sata_fsl_fill_sg(struct ata_queued_cmd *qc, void *cmd_desc,
                        ata_port_printk(qc->ap, KERN_ERR,
                                        "s/g len unaligned : 0x%x\n", sg_len);
 
-               if ((num_prde == (SATA_FSL_MAX_PRD_DIRECT - 1)) &&
-                   (qc->n_iter + 1 != qc->n_elem)) {
+               if (num_prde == (SATA_FSL_MAX_PRD_DIRECT - 1) &&
+                   sg_next(sg) != NULL) {
                        VPRINTK("setting indirect prde\n");
                        prd_ptr_to_indirect_ext = prd;
                        prd->dba = cpu_to_le32(indirect_ext_segment_paddr);
index 96e614a1c1692c896c52d6a6fb71c13bb03470d9..59e65edc5820123169441619fbb515011e837410 100644 (file)
@@ -108,17 +108,6 @@ struct inic_port_priv {
        u8      cached_pirq_mask;
 };
 
-static int inic_slave_config(struct scsi_device *sdev)
-{
-       /* This controller is braindamaged.  dma_boundary is 0xffff
-        * like others but it will lock up the whole machine HARD if
-        * 65536 byte PRD entry is fed.  Reduce maximum segment size.
-        */
-       blk_queue_max_segment_size(sdev->request_queue, 65536 - 512);
-
-       return ata_scsi_slave_config(sdev);
-}
-
 static struct scsi_host_template inic_sht = {
        .module                 = THIS_MODULE,
        .name                   = DRV_NAME,
@@ -132,7 +121,7 @@ static struct scsi_host_template inic_sht = {
        .use_clustering         = ATA_SHT_USE_CLUSTERING,
        .proc_name              = DRV_NAME,
        .dma_boundary           = ATA_DMA_BOUNDARY,
-       .slave_configure        = inic_slave_config,
+       .slave_configure        = ata_scsi_slave_config,
        .slave_destroy          = ata_scsi_slave_destroy,
        .bios_param             = ata_std_bios_param,
 };
@@ -730,6 +719,18 @@ static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                return rc;
        }
 
+       /*
+        * This controller is braindamaged.  dma_boundary is 0xffff
+        * like others but it will lock up the whole machine HARD if
+        * 65536 byte PRD entry is fed. Reduce maximum segment size.
+        */
+       rc = pci_set_dma_max_seg_size(pdev, 65536 - 512);
+       if (rc) {
+               dev_printk(KERN_ERR, &pdev->dev,
+                          "failed to set the maximum segment size.\n");
+               return rc;
+       }
+
        rc = init_controller(iomap[MMIO_BAR], hpriv->cached_hctl);
        if (rc) {
                dev_printk(KERN_ERR, &pdev->dev,
index 3c1b5c9027db5a4446a041b3316440c77c1b1468..080b8362f8d63a033a66f7119c5be35f40d4f6de 100644 (file)
 #include <linux/blkdev.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
+#include <linux/dmapool.h>
 #include <linux/dma-mapping.h>
 #include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/ata_platform.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
@@ -179,6 +182,8 @@ enum {
 
        HC_MAIN_IRQ_CAUSE_OFS   = 0x1d60,
        HC_MAIN_IRQ_MASK_OFS    = 0x1d64,
+       HC_SOC_MAIN_IRQ_CAUSE_OFS = 0x20020,
+       HC_SOC_MAIN_IRQ_MASK_OFS = 0x20024,
        PORT0_ERR               = (1 << 0),     /* shift by port # */
        PORT0_DONE              = (1 << 1),     /* shift by port # */
        HC0_IRQ_PEND            = 0x1ff,        /* bits 0-8 = HC0's ports */
@@ -194,11 +199,13 @@ enum {
        TWSI_INT                = (1 << 24),
        HC_MAIN_RSVD            = (0x7f << 25), /* bits 31-25 */
        HC_MAIN_RSVD_5          = (0x1fff << 19), /* bits 31-19 */
+       HC_MAIN_RSVD_SOC        = (0x3fffffb << 6),     /* bits 31-9, 7-6 */
        HC_MAIN_MASKED_IRQS     = (TRAN_LO_DONE | TRAN_HI_DONE |
                                   PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
                                   HC_MAIN_RSVD),
        HC_MAIN_MASKED_IRQS_5   = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
                                   HC_MAIN_RSVD_5),
+       HC_MAIN_MASKED_IRQS_SOC = (PORTS_0_3_COAL_DONE | HC_MAIN_RSVD_SOC),
 
        /* SATAHC registers */
        HC_CFG_OFS              = 0,
@@ -368,6 +375,7 @@ enum chip_type {
        chip_608x,
        chip_6042,
        chip_7042,
+       chip_soc,
 };
 
 /* Command ReQuest Block: 32B */
@@ -424,6 +432,10 @@ struct mv_host_priv {
        u32                     hp_flags;
        struct mv_port_signal   signal[8];
        const struct mv_hw_ops  *ops;
+       int                     n_ports;
+       void __iomem            *base;
+       void __iomem            *main_cause_reg_addr;
+       void __iomem            *main_mask_reg_addr;
        u32                     irq_cause_ofs;
        u32                     irq_mask_ofs;
        u32                     unmask_all_irqs;
@@ -482,6 +494,15 @@ static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
 static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
                        unsigned int n_hc);
 static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
+static void mv_soc_enable_leds(struct mv_host_priv *hpriv,
+                                     void __iomem *mmio);
+static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx,
+                                     void __iomem *mmio);
+static int mv_soc_reset_hc(struct mv_host_priv *hpriv,
+                                 void __iomem *mmio, unsigned int n_hc);
+static void mv_soc_reset_flash(struct mv_host_priv *hpriv,
+                                     void __iomem *mmio);
+static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio);
 static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio);
 static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
                             unsigned int port_no);
@@ -661,6 +682,12 @@ static const struct ata_port_info mv_port_info[] = {
                .udma_mask      = ATA_UDMA6,
                .port_ops       = &mv_iie_ops,
        },
+       {  /* chip_soc */
+               .flags = MV_COMMON_FLAGS | MV_FLAG_SOC,
+               .pio_mask = 0x1f,      /* pio0-4 */
+               .udma_mask = ATA_UDMA6,
+               .port_ops = &mv_iie_ops,
+       },
 };
 
 static const struct pci_device_id mv_pci_tbl[] = {
@@ -711,6 +738,15 @@ static const struct mv_hw_ops mv6xxx_ops = {
        .reset_bus              = mv_reset_pci_bus,
 };
 
+static const struct mv_hw_ops mv_soc_ops = {
+       .phy_errata             = mv6_phy_errata,
+       .enable_leds            = mv_soc_enable_leds,
+       .read_preamp            = mv_soc_read_preamp,
+       .reset_hc               = mv_soc_reset_hc,
+       .reset_flash            = mv_soc_reset_flash,
+       .reset_bus              = mv_soc_reset_bus,
+};
+
 /*
  * Functions
  */
@@ -749,9 +785,15 @@ static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
                (mv_hardport_from_port(port) * MV_PORT_REG_SZ);
 }
 
+static inline void __iomem *mv_host_base(struct ata_host *host)
+{
+       struct mv_host_priv *hpriv = host->private_data;
+       return hpriv->base;
+}
+
 static inline void __iomem *mv_ap_base(struct ata_port *ap)
 {
-       return mv_port_base(ap->host->iomap[MV_PRIMARY_BAR], ap->port_no);
+       return mv_port_base(mv_host_base(ap->host), ap->port_no);
 }
 
 static inline int mv_get_hc_count(unsigned long port_flags)
@@ -1649,16 +1691,21 @@ static void mv_intr_edma(struct ata_port *ap)
  */
 static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
 {
-       void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
+       struct mv_host_priv *hpriv = host->private_data;
+       void __iomem *mmio = hpriv->base;
        void __iomem *hc_mmio = mv_hc_base(mmio, hc);
        u32 hc_irq_cause;
-       int port, port0;
+       int port, port0, last_port;
 
        if (hc == 0)
                port0 = 0;
        else
                port0 = MV_PORTS_PER_HC;
 
+       if (HAS_PCI(host))
+               last_port = port0 + MV_PORTS_PER_HC;
+       else
+               last_port = port0 + hpriv->n_ports;
        /* we'll need the HC success int register in most cases */
        hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
        if (!hc_irq_cause)
@@ -1669,7 +1716,7 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
        VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
                hc, relevant, hc_irq_cause);
 
-       for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
+       for (port = port0; port < port0 + last_port; port++) {
                struct ata_port *ap = host->ports[port];
                struct mv_port_priv *pp = ap->private_data;
                int have_err_bits, hard_port, shift;
@@ -1764,13 +1811,15 @@ static void mv_pci_error(struct ata_host *host, void __iomem *mmio)
 static irqreturn_t mv_interrupt(int irq, void *dev_instance)
 {
        struct ata_host *host = dev_instance;
+       struct mv_host_priv *hpriv = host->private_data;
        unsigned int hc, handled = 0, n_hcs;
-       void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
+       void __iomem *mmio = hpriv->base;
        u32 irq_stat, irq_mask;
 
        spin_lock(&host->lock);
-       irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
-       irq_mask = readl(mmio + HC_MAIN_IRQ_MASK_OFS);
+
+       irq_stat = readl(hpriv->main_cause_reg_addr);
+       irq_mask = readl(hpriv->main_mask_reg_addr);
 
        /* check the cases where we either have nothing pending or have read
         * a bogus register value which can indicate HW removal or PCI fault
@@ -1827,7 +1876,8 @@ static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
 
 static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
 {
-       void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
+       struct mv_host_priv *hpriv = ap->host->private_data;
+       void __iomem *mmio = hpriv->base;
        void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
        unsigned int ofs = mv5_scr_offset(sc_reg_in);
 
@@ -1840,7 +1890,8 @@ static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
 
 static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
 {
-       void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
+       struct mv_host_priv *hpriv = ap->host->private_data;
+       void __iomem *mmio = hpriv->base;
        void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
        unsigned int ofs = mv5_scr_offset(sc_reg_in);
 
@@ -2178,6 +2229,93 @@ static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
        writel(m2, port_mmio + PHY_MODE2);
 }
 
+/* TODO: use the generic LED interface to configure the SATA Presence */
+/* & Acitivy LEDs on the board */
+static void mv_soc_enable_leds(struct mv_host_priv *hpriv,
+                                     void __iomem *mmio)
+{
+       return;
+}
+
+static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx,
+                          void __iomem *mmio)
+{
+       void __iomem *port_mmio;
+       u32 tmp;
+
+       port_mmio = mv_port_base(mmio, idx);
+       tmp = readl(port_mmio + PHY_MODE2);
+
+       hpriv->signal[idx].amps = tmp & 0x700;  /* bits 10:8 */
+       hpriv->signal[idx].pre = tmp & 0xe0;    /* bits 7:5 */
+}
+
+#undef ZERO
+#define ZERO(reg) writel(0, port_mmio + (reg))
+static void mv_soc_reset_hc_port(struct mv_host_priv *hpriv,
+                                       void __iomem *mmio, unsigned int port)
+{
+       void __iomem *port_mmio = mv_port_base(mmio, port);
+
+       writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
+
+       mv_channel_reset(hpriv, mmio, port);
+
+       ZERO(0x028);            /* command */
+       writel(0x101f, port_mmio + EDMA_CFG_OFS);
+       ZERO(0x004);            /* timer */
+       ZERO(0x008);            /* irq err cause */
+       ZERO(0x00c);            /* irq err mask */
+       ZERO(0x010);            /* rq bah */
+       ZERO(0x014);            /* rq inp */
+       ZERO(0x018);            /* rq outp */
+       ZERO(0x01c);            /* respq bah */
+       ZERO(0x024);            /* respq outp */
+       ZERO(0x020);            /* respq inp */
+       ZERO(0x02c);            /* test control */
+       writel(0xbc, port_mmio + EDMA_IORDY_TMOUT);
+}
+
+#undef ZERO
+
+#define ZERO(reg) writel(0, hc_mmio + (reg))
+static void mv_soc_reset_one_hc(struct mv_host_priv *hpriv,
+                                      void __iomem *mmio)
+{
+       void __iomem *hc_mmio = mv_hc_base(mmio, 0);
+
+       ZERO(0x00c);
+       ZERO(0x010);
+       ZERO(0x014);
+
+}
+
+#undef ZERO
+
+static int mv_soc_reset_hc(struct mv_host_priv *hpriv,
+                                 void __iomem *mmio, unsigned int n_hc)
+{
+       unsigned int port;
+
+       for (port = 0; port < hpriv->n_ports; port++)
+               mv_soc_reset_hc_port(hpriv, mmio, port);
+
+       mv_soc_reset_one_hc(hpriv, mmio);
+
+       return 0;
+}
+
+static void mv_soc_reset_flash(struct mv_host_priv *hpriv,
+                                     void __iomem *mmio)
+{
+       return;
+}
+
+static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio)
+{
+       return;
+}
+
 static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
                             unsigned int port_no)
 {
@@ -2342,7 +2480,7 @@ static int mv_hardreset(struct ata_link *link, unsigned int *class,
 {
        struct ata_port *ap = link->ap;
        struct mv_host_priv *hpriv = ap->host->private_data;
-       void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
+       void __iomem *mmio = hpriv->base;
 
        mv_stop_dma(ap);
 
@@ -2383,7 +2521,7 @@ static void mv_error_handler(struct ata_port *ap)
 
 static void mv_eh_freeze(struct ata_port *ap)
 {
-       void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
+       struct mv_host_priv *hpriv = ap->host->private_data;
        unsigned int hc = (ap->port_no > 3) ? 1 : 0;
        u32 tmp, mask;
        unsigned int shift;
@@ -2397,13 +2535,14 @@ static void mv_eh_freeze(struct ata_port *ap)
        mask = 0x3 << shift;
 
        /* disable assertion of portN err, done events */
-       tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS);
-       writelfl(tmp & ~mask, mmio + HC_MAIN_IRQ_MASK_OFS);
+       tmp = readl(hpriv->main_mask_reg_addr);
+       writelfl(tmp & ~mask, hpriv->main_mask_reg_addr);
 }
 
 static void mv_eh_thaw(struct ata_port *ap)
 {
-       void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
+       struct mv_host_priv *hpriv = ap->host->private_data;
+       void __iomem *mmio = hpriv->base;
        unsigned int hc = (ap->port_no > 3) ? 1 : 0;
        void __iomem *hc_mmio = mv_hc_base(mmio, hc);
        void __iomem *port_mmio = mv_ap_base(ap);
@@ -2430,8 +2569,8 @@ static void mv_eh_thaw(struct ata_port *ap)
        writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
 
        /* enable assertion of portN err, done events */
-       tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS);
-       writelfl(tmp | mask, mmio + HC_MAIN_IRQ_MASK_OFS);
+       tmp = readl(hpriv->main_mask_reg_addr);
+       writelfl(tmp | mask, hpriv->main_mask_reg_addr);
 }
 
 /**
@@ -2598,9 +2737,13 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
                        break;
                }
                break;
+       case chip_soc:
+               hpriv->ops = &mv_soc_ops;
+               hp_flags |= MV_HP_ERRATA_60X1C0;
+               break;
 
        default:
-               dev_printk(KERN_ERR, &pdev->dev,
+               dev_printk(KERN_ERR, host->dev,
                           "BUG: invalid board index %u\n", board_idx);
                return 1;
        }
@@ -2633,15 +2776,25 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
 static int mv_init_host(struct ata_host *host, unsigned int board_idx)
 {
        int rc = 0, n_hc, port, hc;
-       void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
        struct mv_host_priv *hpriv = host->private_data;
-
-       /* global interrupt mask */
-       writel(0, mmio + HC_MAIN_IRQ_MASK_OFS);
+       void __iomem *mmio = hpriv->base;
 
        rc = mv_chip_id(host, board_idx);
        if (rc)
-               goto done;
+       goto done;
+
+       if (HAS_PCI(host)) {
+               hpriv->main_cause_reg_addr = hpriv->base +
+                 HC_MAIN_IRQ_CAUSE_OFS;
+               hpriv->main_mask_reg_addr = hpriv->base + HC_MAIN_IRQ_MASK_OFS;
+       } else {
+               hpriv->main_cause_reg_addr = hpriv->base +
+                 HC_SOC_MAIN_IRQ_CAUSE_OFS;
+               hpriv->main_mask_reg_addr = hpriv->base +
+                 HC_SOC_MAIN_IRQ_MASK_OFS;
+       }
+       /* global interrupt mask */
+       writel(0, hpriv->main_mask_reg_addr);
 
        n_hc = mv_get_hc_count(host->ports[0]->flags);
 
@@ -2672,13 +2825,15 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
        for (port = 0; port < host->n_ports; port++) {
                struct ata_port *ap = host->ports[port];
                void __iomem *port_mmio = mv_port_base(mmio, port);
-               unsigned int offset = port_mmio - mmio;
 
                mv_port_init(&ap->ioaddr, port_mmio);
 
 #ifdef CONFIG_PCI
-               ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio");
-               ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port");
+               if (HAS_PCI(host)) {
+                       unsigned int offset = port_mmio - mmio;
+                       ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio");
+                       ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port");
+               }
 #endif
        }
 
@@ -2694,35 +2849,141 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
                writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
        }
 
-       /* Clear any currently outstanding host interrupt conditions */
-       writelfl(0, mmio + hpriv->irq_cause_ofs);
+       if (HAS_PCI(host)) {
+               /* Clear any currently outstanding host interrupt conditions */
+               writelfl(0, mmio + hpriv->irq_cause_ofs);
 
-       /* and unmask interrupt generation for host regs */
-       writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs);
+               /* and unmask interrupt generation for host regs */
+               writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs);
+               if (IS_GEN_I(hpriv))
+                       writelfl(~HC_MAIN_MASKED_IRQS_5,
+                                hpriv->main_mask_reg_addr);
+               else
+                       writelfl(~HC_MAIN_MASKED_IRQS,
+                                hpriv->main_mask_reg_addr);
+
+               VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
+                       "PCI int cause/mask=0x%08x/0x%08x\n",
+                       readl(hpriv->main_cause_reg_addr),
+                       readl(hpriv->main_mask_reg_addr),
+                       readl(mmio + hpriv->irq_cause_ofs),
+                       readl(mmio + hpriv->irq_mask_ofs));
+       } else {
+               writelfl(~HC_MAIN_MASKED_IRQS_SOC,
+                        hpriv->main_mask_reg_addr);
+               VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x\n",
+                       readl(hpriv->main_cause_reg_addr),
+                       readl(hpriv->main_mask_reg_addr));
+       }
+done:
+       return rc;
+}
 
-       if (IS_GEN_I(hpriv))
-               writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS);
-       else
-               writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
+/**
+ *      mv_platform_probe - handle a positive probe of an soc Marvell
+ *      host
+ *      @pdev: platform device found
+ *
+ *      LOCKING:
+ *      Inherited from caller.
+ */
+static int mv_platform_probe(struct platform_device *pdev)
+{
+       static int printed_version;
+       const struct mv_sata_platform_data *mv_platform_data;
+       const struct ata_port_info *ppi[] =
+           { &mv_port_info[chip_soc], NULL };
+       struct ata_host *host;
+       struct mv_host_priv *hpriv;
+       struct resource *res;
+       int n_ports, rc;
 
-       VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
-               "PCI int cause/mask=0x%08x/0x%08x\n",
-               readl(mmio + HC_MAIN_IRQ_CAUSE_OFS),
-               readl(mmio + HC_MAIN_IRQ_MASK_OFS),
-               readl(mmio + hpriv->irq_cause_ofs),
-               readl(mmio + hpriv->irq_mask_ofs));
+       if (!printed_version++)
+               dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
 
-done:
-       return rc;
+       /*
+        * Simple resource validation ..
+        */
+       if (unlikely(pdev->num_resources != 2)) {
+               dev_err(&pdev->dev, "invalid number of resources\n");
+               return -EINVAL;
+       }
+
+       /*
+        * Get the register base first
+        */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL)
+               return -EINVAL;
+
+       /* allocate host */
+       mv_platform_data = pdev->dev.platform_data;
+       n_ports = mv_platform_data->n_ports;
+
+       host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
+       hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
+
+       if (!host || !hpriv)
+               return -ENOMEM;
+       host->private_data = hpriv;
+       hpriv->n_ports = n_ports;
+
+       host->iomap = NULL;
+       hpriv->base = ioremap(res->start, res->end - res->start + 1);
+       hpriv->base -= MV_SATAHC0_REG_BASE;
+
+       /* initialize adapter */
+       rc = mv_init_host(host, chip_soc);
+       if (rc)
+               return rc;
+
+       dev_printk(KERN_INFO, &pdev->dev,
+                  "slots %u ports %d\n", (unsigned)MV_MAX_Q_DEPTH,
+                  host->n_ports);
+
+       return ata_host_activate(host, platform_get_irq(pdev, 0), mv_interrupt,
+                                IRQF_SHARED, &mv6_sht);
+}
+
+/*
+ *
+ *      mv_platform_remove    -       unplug a platform interface
+ *      @pdev: platform device
+ *
+ *      A platform bus SATA device has been unplugged. Perform the needed
+ *      cleanup. Also called on module unload for any active devices.
+ */
+static int __devexit mv_platform_remove(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct ata_host *host = dev_get_drvdata(dev);
+       struct mv_host_priv *hpriv = host->private_data;
+       void __iomem *base = hpriv->base;
+
+       ata_host_detach(host);
+       iounmap(base);
+       return 0;
 }
 
+static struct platform_driver mv_platform_driver = {
+       .probe                  = mv_platform_probe,
+       .remove                 = __devexit_p(mv_platform_remove),
+       .driver                 = {
+                                  .name = DRV_NAME,
+                                  .owner = THIS_MODULE,
+                                 },
+};
+
+
 #ifdef CONFIG_PCI
-static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
+static int mv_pci_init_one(struct pci_dev *pdev,
+                          const struct pci_device_id *ent);
+
 
 static struct pci_driver mv_pci_driver = {
        .name                   = DRV_NAME,
        .id_table               = mv_pci_tbl,
-       .probe                  = mv_init_one,
+       .probe                  = mv_pci_init_one,
        .remove                 = ata_pci_remove_one,
 };
 
@@ -2828,14 +3089,15 @@ static int mv_create_dma_pools(struct mv_host_priv *hpriv, struct device *dev)
 }
 
 /**
- *      mv_init_one - handle a positive probe of a Marvell host
+ *      mv_pci_init_one - handle a positive probe of a PCI Marvell host
  *      @pdev: PCI device found
  *      @ent: PCI device ID entry for the matched host
  *
  *      LOCKING:
  *      Inherited from caller.
  */
-static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int mv_pci_init_one(struct pci_dev *pdev,
+                          const struct pci_device_id *ent)
 {
        static int printed_version;
        unsigned int board_idx = (unsigned int)ent->driver_data;
@@ -2855,6 +3117,7 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (!host || !hpriv)
                return -ENOMEM;
        host->private_data = hpriv;
+       hpriv->n_ports = n_ports;
 
        /* acquire resources */
        rc = pcim_enable_device(pdev);
@@ -2867,6 +3130,7 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (rc)
                return rc;
        host->iomap = pcim_iomap_table(pdev);
+       hpriv->base = host->iomap[MV_PRIMARY_BAR];
 
        rc = pci_go_64(pdev);
        if (rc)
@@ -2895,11 +3159,22 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 }
 #endif
 
+static int mv_platform_probe(struct platform_device *pdev);
+static int __devexit mv_platform_remove(struct platform_device *pdev);
+
 static int __init mv_init(void)
 {
        int rc = -ENODEV;
 #ifdef CONFIG_PCI
        rc = pci_register_driver(&mv_pci_driver);
+       if (rc < 0)
+               return rc;
+#endif
+       rc = platform_driver_register(&mv_platform_driver);
+
+#ifdef CONFIG_PCI
+       if (rc < 0)
+               pci_unregister_driver(&mv_pci_driver);
 #endif
        return rc;
 }
@@ -2909,6 +3184,7 @@ static void __exit mv_exit(void)
 #ifdef CONFIG_PCI
        pci_unregister_driver(&mv_pci_driver);
 #endif
+       platform_driver_unregister(&mv_platform_driver);
 }
 
 MODULE_AUTHOR("Brett Russ");
index bfe92a43cf895d4169619298d6f18a037b828a5c..ed5473bf7a0a2005ea5e156cc1eff7cc723ca54d 100644 (file)
@@ -247,6 +247,7 @@ struct nv_adma_port_priv {
        void __iomem            *ctl_block;
        void __iomem            *gen_block;
        void __iomem            *notifier_clear_block;
+       u64                     adma_dma_mask;
        u8                      flags;
        int                     last_issue_ncq;
 };
@@ -715,9 +716,10 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
 {
        struct ata_port *ap = ata_shost_to_port(sdev->host);
        struct nv_adma_port_priv *pp = ap->private_data;
+       struct nv_adma_port_priv *port0, *port1;
+       struct scsi_device *sdev0, *sdev1;
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
-       u64 bounce_limit;
-       unsigned long segment_boundary;
+       unsigned long segment_boundary, flags;
        unsigned short sg_tablesize;
        int rc;
        int adma_enable;
@@ -729,6 +731,8 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
                /* Not a proper libata device, ignore */
                return rc;
 
+       spin_lock_irqsave(ap->lock, flags);
+
        if (ap->link.device[sdev->id].class == ATA_DEV_ATAPI) {
                /*
                 * NVIDIA reports that ADMA mode does not support ATAPI commands.
@@ -737,7 +741,6 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
                 * Restrict DMA parameters as required by the legacy interface
                 * when an ATAPI device is connected.
                 */
-               bounce_limit = ATA_DMA_MASK;
                segment_boundary = ATA_DMA_BOUNDARY;
                /* Subtract 1 since an extra entry may be needed for padding, see
                   libata-scsi.c */
@@ -748,7 +751,6 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
                adma_enable = 0;
                nv_adma_register_mode(ap);
        } else {
-               bounce_limit = *ap->dev->dma_mask;
                segment_boundary = NV_ADMA_DMA_BOUNDARY;
                sg_tablesize = NV_ADMA_SGTBL_TOTAL_LEN;
                adma_enable = 1;
@@ -774,12 +776,49 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
        if (current_reg != new_reg)
                pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, new_reg);
 
-       blk_queue_bounce_limit(sdev->request_queue, bounce_limit);
+       port0 = ap->host->ports[0]->private_data;
+       port1 = ap->host->ports[1]->private_data;
+       sdev0 = ap->host->ports[0]->link.device[0].sdev;
+       sdev1 = ap->host->ports[1]->link.device[0].sdev;
+       if ((port0->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) ||
+           (port1->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)) {
+               /** We have to set the DMA mask to 32-bit if either port is in
+                   ATAPI mode, since they are on the same PCI device which is
+                   used for DMA mapping. If we set the mask we also need to set
+                   the bounce limit on both ports to ensure that the block
+                   layer doesn't feed addresses that cause DMA mapping to
+                   choke. If either SCSI device is not allocated yet, it's OK
+                   since that port will discover its correct setting when it
+                   does get allocated.
+                   Note: Setting 32-bit mask should not fail. */
+               if (sdev0)
+                       blk_queue_bounce_limit(sdev0->request_queue,
+                                              ATA_DMA_MASK);
+               if (sdev1)
+                       blk_queue_bounce_limit(sdev1->request_queue,
+                                              ATA_DMA_MASK);
+
+               pci_set_dma_mask(pdev, ATA_DMA_MASK);
+       } else {
+               /** This shouldn't fail as it was set to this value before */
+               pci_set_dma_mask(pdev, pp->adma_dma_mask);
+               if (sdev0)
+                       blk_queue_bounce_limit(sdev0->request_queue,
+                                              pp->adma_dma_mask);
+               if (sdev1)
+                       blk_queue_bounce_limit(sdev1->request_queue,
+                                              pp->adma_dma_mask);
+       }
+
        blk_queue_segment_boundary(sdev->request_queue, segment_boundary);
        blk_queue_max_hw_segments(sdev->request_queue, sg_tablesize);
        ata_port_printk(ap, KERN_INFO,
-               "bounce limit 0x%llX, segment boundary 0x%lX, hw segs %hu\n",
-               (unsigned long long)bounce_limit, segment_boundary, sg_tablesize);
+               "DMA mask 0x%llX, segment boundary 0x%lX, hw segs %hu\n",
+               (unsigned long long)*ap->host->dev->dma_mask,
+               segment_boundary, sg_tablesize);
+
+       spin_unlock_irqrestore(ap->lock, flags);
+
        return rc;
 }
 
@@ -1140,10 +1179,20 @@ static int nv_adma_port_start(struct ata_port *ap)
        void *mem;
        dma_addr_t mem_dma;
        void __iomem *mmio;
+       struct pci_dev *pdev = to_pci_dev(dev);
        u16 tmp;
 
        VPRINTK("ENTER\n");
 
+       /* Ensure DMA mask is set to 32-bit before allocating legacy PRD and
+          pad buffers */
+       rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+       if (rc)
+               return rc;
+       rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
+       if (rc)
+               return rc;
+
        rc = ata_port_start(ap);
        if (rc)
                return rc;
@@ -1159,6 +1208,15 @@ static int nv_adma_port_start(struct ata_port *ap)
        pp->notifier_clear_block = pp->gen_block +
               NV_ADMA_NOTIFIER_CLEAR + (4 * ap->port_no);
 
+       /* Now that the legacy PRD and padding buffer are allocated we can
+          safely raise the DMA mask to allocate the CPB/APRD table.
+          These are allowed to fail since we store the value that ends up
+          being used to set as the bounce limit in slave_config later if
+          needed. */
+       pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
+       pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
+       pp->adma_dma_mask = *dev->dma_mask;
+
        mem = dmam_alloc_coherent(dev, NV_ADMA_PORT_PRIV_DMA_SZ,
                                  &mem_dma, GFP_KERNEL);
        if (!mem)
@@ -2417,12 +2475,6 @@ static int nv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        hpriv->type = type;
        host->private_data = hpriv;
 
-       /* set 64bit dma masks, may fail */
-       if (type == ADMA) {
-               if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0)
-                       pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
-       }
-
        /* request and iomap NV_MMIO_BAR */
        rc = pcim_iomap_regions(pdev, 1 << NV_MMIO_BAR, DRV_NAME);
        if (rc)
index 3ef072ff319d28b8514e9ade2fde843d1a23ad2f..30caa033719039c73350fee395c30fd6f374bc24 100644 (file)
@@ -30,8 +30,6 @@
  *  Hardware documentation available under NDA.
  *
  *
- *  To-do list:
- *  - VT6421 PATA support
  *
  */
 
index 63e09c015ca02305e6bb475d3ba8ca78c5677e63..c66637392bbc71756731941a50253240d0da3b9a 100644 (file)
@@ -5,7 +5,7 @@ obj-y                   := core.o sys.o bus.o dd.o \
                           cpu.o firmware.o init.o map.o devres.o \
                           attribute_container.o transport_class.o
 obj-y                  += power/
-obj-$(CONFIG_HAS_DMA)  += dma-mapping.o dmapool.o
+obj-$(CONFIG_HAS_DMA)  += dma-mapping.o
 obj-$(CONFIG_ISA)      += isa.o
 obj-$(CONFIG_FW_LOADER)        += firmware_class.o
 obj-$(CONFIG_NUMA)     += node.o
index b1727876182cdff178550856fc0696a770db9bdc..9c0070b5bd3e75d828a44d405dca4695b70e6ef6 100644 (file)
@@ -423,10 +423,8 @@ struct kset *devices_kset;
 int device_create_file(struct device *dev, struct device_attribute *attr)
 {
        int error = 0;
-       if (get_device(dev)) {
+       if (dev)
                error = sysfs_create_file(&dev->kobj, &attr->attr);
-               put_device(dev);
-       }
        return error;
 }
 
@@ -437,10 +435,8 @@ int device_create_file(struct device *dev, struct device_attribute *attr)
  */
 void device_remove_file(struct device *dev, struct device_attribute *attr)
 {
-       if (get_device(dev)) {
+       if (dev)
                sysfs_remove_file(&dev->kobj, &attr->attr);
-               put_device(dev);
-       }
 }
 
 /**
@@ -1144,25 +1140,11 @@ error:
 }
 EXPORT_SYMBOL_GPL(device_create);
 
-/**
- * find_device - finds a device that was created with device_create()
- * @class: pointer to the struct class that this device was registered with
- * @devt: the dev_t of the device that was previously registered
- */
-static struct device *find_device(struct class *class, dev_t devt)
+static int __match_devt(struct device *dev, void *data)
 {
-       struct device *dev = NULL;
-       struct device *dev_tmp;
+       dev_t *devt = data;
 
-       down(&class->sem);
-       list_for_each_entry(dev_tmp, &class->devices, node) {
-               if (dev_tmp->devt == devt) {
-                       dev = dev_tmp;
-                       break;
-               }
-       }
-       up(&class->sem);
-       return dev;
+       return dev->devt == *devt;
 }
 
 /**
@@ -1177,9 +1159,11 @@ void device_destroy(struct class *class, dev_t devt)
 {
        struct device *dev;
 
-       dev = find_device(class, devt);
-       if (dev)
+       dev = class_find_device(class, &devt, __match_devt);
+       if (dev) {
+               put_device(dev);
                device_unregister(dev);
+       }
 }
 EXPORT_SYMBOL_GPL(device_destroy);
 
@@ -1203,9 +1187,11 @@ void destroy_suspended_device(struct class *class, dev_t devt)
 {
        struct device *dev;
 
-       dev = find_device(class, devt);
-       if (dev)
+       dev = class_find_device(class, &devt, __match_devt);
+       if (dev) {
                device_pm_schedule_removal(dev);
+               put_device(dev);
+       }
 }
 EXPORT_SYMBOL_GPL(destroy_suspended_device);
 #endif /* CONFIG_PM_SLEEP */
index c5885f5ce0ac9bc44b8bfdb37068360305133ed0..499b003f92782dfc8259791d6f13b4a377f24f5b 100644 (file)
@@ -110,7 +110,7 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
  *
  * Initialize and register the CPU device.
  */
-int __devinit register_cpu(struct cpu *cpu, int num)
+int __cpuinit register_cpu(struct cpu *cpu, int num)
 {
        int error;
        cpu->node_id = cpu_to_node(num);
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c
deleted file mode 100644 (file)
index b5034dc..0000000
+++ /dev/null
@@ -1,481 +0,0 @@
-
-#include <linux/device.h>
-#include <linux/mm.h>
-#include <asm/io.h>            /* Needed for i386 to build */
-#include <linux/dma-mapping.h>
-#include <linux/dmapool.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/poison.h>
-#include <linux/sched.h>
-
-/*
- * Pool allocator ... wraps the dma_alloc_coherent page allocator, so
- * small blocks are easily used by drivers for bus mastering controllers.
- * This should probably be sharing the guts of the slab allocator.
- */
-
-struct dma_pool {      /* the pool */
-       struct list_head        page_list;
-       spinlock_t              lock;
-       size_t                  blocks_per_page;
-       size_t                  size;
-       struct device           *dev;
-       size_t                  allocation;
-       char                    name [32];
-       wait_queue_head_t       waitq;
-       struct list_head        pools;
-};
-
-struct dma_page {      /* cacheable header for 'allocation' bytes */
-       struct list_head        page_list;
-       void                    *vaddr;
-       dma_addr_t              dma;
-       unsigned                in_use;
-       unsigned long           bitmap [0];
-};
-
-#define        POOL_TIMEOUT_JIFFIES    ((100 /* msec */ * HZ) / 1000)
-
-static DEFINE_MUTEX (pools_lock);
-
-static ssize_t
-show_pools (struct device *dev, struct device_attribute *attr, char *buf)
-{
-       unsigned temp;
-       unsigned size;
-       char *next;
-       struct dma_page *page;
-       struct dma_pool *pool;
-
-       next = buf;
-       size = PAGE_SIZE;
-
-       temp = scnprintf(next, size, "poolinfo - 0.1\n");
-       size -= temp;
-       next += temp;
-
-       mutex_lock(&pools_lock);
-       list_for_each_entry(pool, &dev->dma_pools, pools) {
-               unsigned pages = 0;
-               unsigned blocks = 0;
-
-               list_for_each_entry(page, &pool->page_list, page_list) {
-                       pages++;
-                       blocks += page->in_use;
-               }
-
-               /* per-pool info, no real statistics yet */
-               temp = scnprintf(next, size, "%-16s %4u %4Zu %4Zu %2u\n",
-                               pool->name,
-                               blocks, pages * pool->blocks_per_page,
-                               pool->size, pages);
-               size -= temp;
-               next += temp;
-       }
-       mutex_unlock(&pools_lock);
-
-       return PAGE_SIZE - size;
-}
-static DEVICE_ATTR (pools, S_IRUGO, show_pools, NULL);
-
-/**
- * dma_pool_create - Creates a pool of consistent memory blocks, for dma.
- * @name: name of pool, for diagnostics
- * @dev: device that will be doing the DMA
- * @size: size of the blocks in this pool.
- * @align: alignment requirement for blocks; must be a power of two
- * @allocation: returned blocks won't cross this boundary (or zero)
- * Context: !in_interrupt()
- *
- * Returns a dma allocation pool with the requested characteristics, or
- * null if one can't be created.  Given one of these pools, dma_pool_alloc()
- * may be used to allocate memory.  Such memory will all have "consistent"
- * DMA mappings, accessible by the device and its driver without using
- * cache flushing primitives.  The actual size of blocks allocated may be
- * larger than requested because of alignment.
- *
- * If allocation is nonzero, objects returned from dma_pool_alloc() won't
- * cross that size boundary.  This is useful for devices which have
- * addressing restrictions on individual DMA transfers, such as not crossing
- * boundaries of 4KBytes.
- */
-struct dma_pool *
-dma_pool_create (const char *name, struct device *dev,
-       size_t size, size_t align, size_t allocation)
-{
-       struct dma_pool         *retval;
-
-       if (align == 0)
-               align = 1;
-       if (size == 0)
-               return NULL;
-       else if (size < align)
-               size = align;
-       else if ((size % align) != 0) {
-               size += align + 1;
-               size &= ~(align - 1);
-       }
-
-       if (allocation == 0) {
-               if (PAGE_SIZE < size)
-                       allocation = size;
-               else
-                       allocation = PAGE_SIZE;
-               // FIXME: round up for less fragmentation
-       } else if (allocation < size)
-               return NULL;
-
-       if (!(retval = kmalloc_node (sizeof *retval, GFP_KERNEL, dev_to_node(dev))))
-               return retval;
-
-       strlcpy (retval->name, name, sizeof retval->name);
-
-       retval->dev = dev;
-
-       INIT_LIST_HEAD (&retval->page_list);
-       spin_lock_init (&retval->lock);
-       retval->size = size;
-       retval->allocation = allocation;
-       retval->blocks_per_page = allocation / size;
-       init_waitqueue_head (&retval->waitq);
-
-       if (dev) {
-               int ret;
-
-               mutex_lock(&pools_lock);
-               if (list_empty (&dev->dma_pools))
-                       ret = device_create_file (dev, &dev_attr_pools);
-               else
-                       ret = 0;
-               /* note:  not currently insisting "name" be unique */
-               if (!ret)
-                       list_add (&retval->pools, &dev->dma_pools);
-               else {
-                       kfree(retval);
-                       retval = NULL;
-               }
-               mutex_unlock(&pools_lock);
-       } else
-               INIT_LIST_HEAD (&retval->pools);
-
-       return retval;
-}
-
-
-static struct dma_page *
-pool_alloc_page (struct dma_pool *pool, gfp_t mem_flags)
-{
-       struct dma_page *page;
-       int             mapsize;
-
-       mapsize = pool->blocks_per_page;
-       mapsize = (mapsize + BITS_PER_LONG - 1) / BITS_PER_LONG;
-       mapsize *= sizeof (long);
-
-       page = kmalloc(mapsize + sizeof *page, mem_flags);
-       if (!page)
-               return NULL;
-       page->vaddr = dma_alloc_coherent (pool->dev,
-                                           pool->allocation,
-                                           &page->dma,
-                                           mem_flags);
-       if (page->vaddr) {
-               memset (page->bitmap, 0xff, mapsize);   // bit set == free
-#ifdef CONFIG_DEBUG_SLAB
-               memset (page->vaddr, POOL_POISON_FREED, pool->allocation);
-#endif
-               list_add (&page->page_list, &pool->page_list);
-               page->in_use = 0;
-       } else {
-               kfree (page);
-               page = NULL;
-       }
-       return page;
-}
-
-
-static inline int
-is_page_busy (int blocks, unsigned long *bitmap)
-{
-       while (blocks > 0) {
-               if (*bitmap++ != ~0UL)
-                       return 1;
-               blocks -= BITS_PER_LONG;
-       }
-       return 0;
-}
-
-static void
-pool_free_page (struct dma_pool *pool, struct dma_page *page)
-{
-       dma_addr_t      dma = page->dma;
-
-#ifdef CONFIG_DEBUG_SLAB
-       memset (page->vaddr, POOL_POISON_FREED, pool->allocation);
-#endif
-       dma_free_coherent (pool->dev, pool->allocation, page->vaddr, dma);
-       list_del (&page->page_list);
-       kfree (page);
-}
-
-
-/**
- * dma_pool_destroy - destroys a pool of dma memory blocks.
- * @pool: dma pool that will be destroyed
- * Context: !in_interrupt()
- *
- * Caller guarantees that no more memory from the pool is in use,
- * and that nothing will try to use the pool after this call.
- */
-void
-dma_pool_destroy (struct dma_pool *pool)
-{
-       mutex_lock(&pools_lock);
-       list_del (&pool->pools);
-       if (pool->dev && list_empty (&pool->dev->dma_pools))
-               device_remove_file (pool->dev, &dev_attr_pools);
-       mutex_unlock(&pools_lock);
-
-       while (!list_empty (&pool->page_list)) {
-               struct dma_page         *page;
-               page = list_entry (pool->page_list.next,
-                               struct dma_page, page_list);
-               if (is_page_busy (pool->blocks_per_page, page->bitmap)) {
-                       if (pool->dev)
-                               dev_err(pool->dev, "dma_pool_destroy %s, %p busy\n",
-                                       pool->name, page->vaddr);
-                       else
-                               printk (KERN_ERR "dma_pool_destroy %s, %p busy\n",
-                                       pool->name, page->vaddr);
-                       /* leak the still-in-use consistent memory */
-                       list_del (&page->page_list);
-                       kfree (page);
-               } else
-                       pool_free_page (pool, page);
-       }
-
-       kfree (pool);
-}
-
-
-/**
- * dma_pool_alloc - get a block of consistent memory
- * @pool: dma pool that will produce the block
- * @mem_flags: GFP_* bitmask
- * @handle: pointer to dma address of block
- *
- * This returns the kernel virtual address of a currently unused block,
- * and reports its dma address through the handle.
- * If such a memory block can't be allocated, null is returned.
- */
-void *
-dma_pool_alloc (struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle)
-{
-       unsigned long           flags;
-       struct dma_page         *page;
-       int                     map, block;
-       size_t                  offset;
-       void                    *retval;
-
-restart:
-       spin_lock_irqsave (&pool->lock, flags);
-       list_for_each_entry(page, &pool->page_list, page_list) {
-               int             i;
-               /* only cachable accesses here ... */
-               for (map = 0, i = 0;
-                               i < pool->blocks_per_page;
-                               i += BITS_PER_LONG, map++) {
-                       if (page->bitmap [map] == 0)
-                               continue;
-                       block = ffz (~ page->bitmap [map]);
-                       if ((i + block) < pool->blocks_per_page) {
-                               clear_bit (block, &page->bitmap [map]);
-                               offset = (BITS_PER_LONG * map) + block;
-                               offset *= pool->size;
-                               goto ready;
-                       }
-               }
-       }
-       if (!(page = pool_alloc_page (pool, GFP_ATOMIC))) {
-               if (mem_flags & __GFP_WAIT) {
-                       DECLARE_WAITQUEUE (wait, current);
-
-                       __set_current_state(TASK_INTERRUPTIBLE);
-                       add_wait_queue (&pool->waitq, &wait);
-                       spin_unlock_irqrestore (&pool->lock, flags);
-
-                       schedule_timeout (POOL_TIMEOUT_JIFFIES);
-
-                       remove_wait_queue (&pool->waitq, &wait);
-                       goto restart;
-               }
-               retval = NULL;
-               goto done;
-       }
-
-       clear_bit (0, &page->bitmap [0]);
-       offset = 0;
-ready:
-       page->in_use++;
-       retval = offset + page->vaddr;
-       *handle = offset + page->dma;
-#ifdef CONFIG_DEBUG_SLAB
-       memset (retval, POOL_POISON_ALLOCATED, pool->size);
-#endif
-done:
-       spin_unlock_irqrestore (&pool->lock, flags);
-       return retval;
-}
-
-
-static struct dma_page *
-pool_find_page (struct dma_pool *pool, dma_addr_t dma)
-{
-       unsigned long           flags;
-       struct dma_page         *page;
-
-       spin_lock_irqsave (&pool->lock, flags);
-       list_for_each_entry(page, &pool->page_list, page_list) {
-               if (dma < page->dma)
-                       continue;
-               if (dma < (page->dma + pool->allocation))
-                       goto done;
-       }
-       page = NULL;
-done:
-       spin_unlock_irqrestore (&pool->lock, flags);
-       return page;
-}
-
-
-/**
- * dma_pool_free - put block back into dma pool
- * @pool: the dma pool holding the block
- * @vaddr: virtual address of block
- * @dma: dma address of block
- *
- * Caller promises neither device nor driver will again touch this block
- * unless it is first re-allocated.
- */
-void
-dma_pool_free (struct dma_pool *pool, void *vaddr, dma_addr_t dma)
-{
-       struct dma_page         *page;
-       unsigned long           flags;
-       int                     map, block;
-
-       if ((page = pool_find_page(pool, dma)) == NULL) {
-               if (pool->dev)
-                       dev_err(pool->dev, "dma_pool_free %s, %p/%lx (bad dma)\n",
-                               pool->name, vaddr, (unsigned long) dma);
-               else
-                       printk (KERN_ERR "dma_pool_free %s, %p/%lx (bad dma)\n",
-                               pool->name, vaddr, (unsigned long) dma);
-               return;
-       }
-
-       block = dma - page->dma;
-       block /= pool->size;
-       map = block / BITS_PER_LONG;
-       block %= BITS_PER_LONG;
-
-#ifdef CONFIG_DEBUG_SLAB
-       if (((dma - page->dma) + (void *)page->vaddr) != vaddr) {
-               if (pool->dev)
-                       dev_err(pool->dev, "dma_pool_free %s, %p (bad vaddr)/%Lx\n",
-                               pool->name, vaddr, (unsigned long long) dma);
-               else
-                       printk (KERN_ERR "dma_pool_free %s, %p (bad vaddr)/%Lx\n",
-                               pool->name, vaddr, (unsigned long long) dma);
-               return;
-       }
-       if (page->bitmap [map] & (1UL << block)) {
-               if (pool->dev)
-                       dev_err(pool->dev, "dma_pool_free %s, dma %Lx already free\n",
-                               pool->name, (unsigned long long)dma);
-               else
-                       printk (KERN_ERR "dma_pool_free %s, dma %Lx already free\n",
-                               pool->name, (unsigned long long)dma);
-               return;
-       }
-       memset (vaddr, POOL_POISON_FREED, pool->size);
-#endif
-
-       spin_lock_irqsave (&pool->lock, flags);
-       page->in_use--;
-       set_bit (block, &page->bitmap [map]);
-       if (waitqueue_active (&pool->waitq))
-               wake_up (&pool->waitq);
-       /*
-        * Resist a temptation to do
-        *    if (!is_page_busy(bpp, page->bitmap)) pool_free_page(pool, page);
-        * Better have a few empty pages hang around.
-        */
-       spin_unlock_irqrestore (&pool->lock, flags);
-}
-
-/*
- * Managed DMA pool
- */
-static void dmam_pool_release(struct device *dev, void *res)
-{
-       struct dma_pool *pool = *(struct dma_pool **)res;
-
-       dma_pool_destroy(pool);
-}
-
-static int dmam_pool_match(struct device *dev, void *res, void *match_data)
-{
-       return *(struct dma_pool **)res == match_data;
-}
-
-/**
- * dmam_pool_create - Managed dma_pool_create()
- * @name: name of pool, for diagnostics
- * @dev: device that will be doing the DMA
- * @size: size of the blocks in this pool.
- * @align: alignment requirement for blocks; must be a power of two
- * @allocation: returned blocks won't cross this boundary (or zero)
- *
- * Managed dma_pool_create().  DMA pool created with this function is
- * automatically destroyed on driver detach.
- */
-struct dma_pool *dmam_pool_create(const char *name, struct device *dev,
-                                 size_t size, size_t align, size_t allocation)
-{
-       struct dma_pool **ptr, *pool;
-
-       ptr = devres_alloc(dmam_pool_release, sizeof(*ptr), GFP_KERNEL);
-       if (!ptr)
-               return NULL;
-
-       pool = *ptr = dma_pool_create(name, dev, size, align, allocation);
-       if (pool)
-               devres_add(dev, ptr);
-       else
-               devres_free(ptr);
-
-       return pool;
-}
-
-/**
- * dmam_pool_destroy - Managed dma_pool_destroy()
- * @pool: dma pool that will be destroyed
- *
- * Managed dma_pool_destroy().
- */
-void dmam_pool_destroy(struct dma_pool *pool)
-{
-       struct device *dev = pool->dev;
-
-       dma_pool_destroy(pool);
-       WARN_ON(devres_destroy(dev, dmam_pool_release, dmam_pool_match, pool));
-}
-
-EXPORT_SYMBOL (dma_pool_create);
-EXPORT_SYMBOL (dma_pool_destroy);
-EXPORT_SYMBOL (dma_pool_alloc);
-EXPORT_SYMBOL (dma_pool_free);
-EXPORT_SYMBOL (dmam_pool_create);
-EXPORT_SYMBOL (dmam_pool_destroy);
index a35f04121a00f938503f3b585c4e792e8a578d8f..ba75184c653c32794e3ac60283369a1bd39ea461 100644 (file)
@@ -97,10 +97,9 @@ int driver_create_file(struct device_driver *drv,
                       struct driver_attribute *attr)
 {
        int error;
-       if (get_driver(drv)) {
+       if (drv)
                error = sysfs_create_file(&drv->p->kobj, &attr->attr);
-               put_driver(drv);
-       } else
+       else
                error = -EINVAL;
        return error;
 }
@@ -114,10 +113,8 @@ EXPORT_SYMBOL_GPL(driver_create_file);
 void driver_remove_file(struct device_driver *drv,
                        struct driver_attribute *attr)
 {
-       if (get_driver(drv)) {
+       if (drv)
                sysfs_remove_file(&drv->p->kobj, &attr->attr);
-               put_driver(drv);
-       }
 }
 EXPORT_SYMBOL_GPL(driver_remove_file);
 
index de28dfd3b96c6ff4db97ed85320f017a8542e799..911208b892593965857211727a51b028cbd4b10f 100644 (file)
@@ -1,6 +1,6 @@
 obj-$(CONFIG_PM)       += sysfs.o
 obj-$(CONFIG_PM_SLEEP) += main.o
-obj-$(CONFIG_PM_TRACE) += trace.o
+obj-$(CONFIG_PM_TRACE_RTC)     += trace.o
 
 ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
 ccflags-$(CONFIG_PM_VERBOSE)   += -DDEBUG
index 200ed5fafd505ad0e18fff1131500e2a2fd4ba9c..bdc03f7e8424ceda39d454413a76d637a9215418 100644 (file)
@@ -129,6 +129,7 @@ void device_pm_schedule_removal(struct device *dev)
        list_move_tail(&dev->power.entry, &dpm_destroy);
        mutex_unlock(&dpm_list_mtx);
 }
+EXPORT_SYMBOL_GPL(device_pm_schedule_removal);
 
 /**
  *     pm_sleep_lock - mutual exclusion for registration and suspend
index 6f0dfca8ebdd2437da619ab7a0c89abd7a60dcca..e32d3bdb92c1dbf45d02c161130fcafbdd0044d9 100644 (file)
@@ -13,7 +13,6 @@ static inline struct device *to_device(struct list_head *entry)
 
 extern void device_pm_add(struct device *);
 extern void device_pm_remove(struct device *);
-extern void device_pm_schedule_removal(struct device *);
 extern int pm_sleep_lock(void);
 extern void pm_sleep_unlock(void);
 
index f2122855d4ec5d714ae0260708aa66562af17db1..64e5148d82bc8cce2018012f6bf5587570ba2267 100644 (file)
@@ -440,6 +440,7 @@ config VIRTIO_BLK
        tristate "Virtio block driver (EXPERIMENTAL)"
        depends on EXPERIMENTAL && VIRTIO
        ---help---
-         This is the virtual block driver for lguest.  Say Y or M.
+         This is the virtual block driver for virtio.  It can be used with
+          lguest or QEMU based VMMs (like KVM or Xen).  Say Y or M.
 
 endif # BLK_DEV
index 94268c75d04f867e920a39161ed5a4e0c2be21ad..424995073c6b23941fa123b50888b41fcab2148b 100644 (file)
@@ -90,7 +90,7 @@ static struct atari_disk_type {
        unsigned        blocks;         /* total number of blocks */
        unsigned        fdc_speed;      /* fdc_speed setting */
        unsigned        stretch;        /* track doubling ? */
-} disk_type[] = {
+} atari_disk_type[] = {
        { "d360",  9, 720, 0, 0},       /*  0: 360kB diskette */
        { "D360",  9, 720, 0, 1},       /*  1: 360kb in 720k or 1.2MB drive */
        { "D720",  9,1440, 0, 0},       /*  2: 720kb in 720k or 1.2MB drive */
@@ -658,7 +658,7 @@ static int do_format(int drive, int type, struct atari_format_descr *desc)
                        return -EINVAL;
                }
                type = minor2disktype[type].index;
-               UDT = &disk_type[type];
+               UDT = &atari_disk_type[type];
        }
 
        if (!UDT || desc->track >= UDT->blocks/UDT->spt/2 || desc->head >= 2) {
@@ -1064,7 +1064,7 @@ static void fd_rwsec_done1(int status)
               searched for a non-existent sector! */
            !(read_track && FDC_READ(FDCREG_SECTOR) > SUDT->spt)) {
                if (Probing) {
-                       if (SUDT > disk_type) {
+                       if (SUDT > atari_disk_type) {
                            if (SUDT[-1].blocks > ReqBlock) {
                                /* try another disk type */
                                SUDT--;
@@ -1082,7 +1082,7 @@ static void fd_rwsec_done1(int status)
                } else {        
 /* record not found, but not probing. Maybe stretch wrong ? Restart probing */
                        if (SUD.autoprobe) {
-                               SUDT = disk_type + StartDiskType[DriveType];
+                               SUDT = atari_disk_type + StartDiskType[DriveType];
                                set_capacity(unit[SelectedDrive].disk,
                                                        SUDT->blocks);
                                Probing = 1;
@@ -1421,7 +1421,7 @@ repeat:
        if (type == 0) {
                if (!UDT) {
                        Probing = 1;
-                       UDT = disk_type + StartDiskType[DriveType];
+                       UDT = atari_disk_type + StartDiskType[DriveType];
                        set_capacity(floppy->disk, UDT->blocks);
                        UD.autoprobe = 1;
                }
@@ -1439,7 +1439,7 @@ repeat:
                        goto repeat;
                }
                type = minor2disktype[type].index;
-               UDT = &disk_type[type];
+               UDT = &atari_disk_type[type];
                set_capacity(floppy->disk, UDT->blocks);
                UD.autoprobe = 0;
        }
@@ -1505,7 +1505,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
                        if (minor2disktype[type].drive_types > DriveType)
                                return -ENODEV;
                        type = minor2disktype[type].index;
-                       dtp = &disk_type[type];
+                       dtp = &atari_disk_type[type];
                        if (UD.flags & FTD_MSG)
                            printk (KERN_ERR "floppy%d: found dtp %p name %s!\n",
                                drive, dtp, dtp->name);
@@ -1576,7 +1576,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
                                continue;
                        }
                        setidx = minor2disktype[settype].index;
-                       dtp = &disk_type[setidx];
+                       dtp = &atari_disk_type[setidx];
 
                        /* found matching entry ?? */
                        if (   dtp->blocks  == setprm.size 
index 855ce8e5efbaf3aadca40a5f2405b026b751541f..9715be3f2487c161493f231ee2ef739806cdddc4 100644 (file)
@@ -2630,12 +2630,14 @@ static void do_cciss_request(struct request_queue *q)
                        c->Request.CDB[8] = creq->nr_sectors & 0xff;
                        c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
                } else {
+                       u32 upper32 = upper_32_bits(start_blk);
+
                        c->Request.CDBLen = 16;
                        c->Request.CDB[1]= 0;
-                       c->Request.CDB[2]= (start_blk >> 56) & 0xff;    //MSB
-                       c->Request.CDB[3]= (start_blk >> 48) & 0xff;
-                       c->Request.CDB[4]= (start_blk >> 40) & 0xff;
-                       c->Request.CDB[5]= (start_blk >> 32) & 0xff;
+                       c->Request.CDB[2]= (upper32 >> 24) & 0xff;      //MSB
+                       c->Request.CDB[3]= (upper32 >> 16) & 0xff;
+                       c->Request.CDB[4]= (upper32 >>  8) & 0xff;
+                       c->Request.CDB[5]= upper32 & 0xff;
                        c->Request.CDB[6]= (start_blk >> 24) & 0xff;
                        c->Request.CDB[7]= (start_blk >> 16) & 0xff;
                        c->Request.CDB[8]= (start_blk >>  8) & 0xff;
index 63ee6c076cb3ec61771c05b2743998a9a4da1b49..55178e9973a094fe08fd23bf040c237e58695a02 100644 (file)
@@ -1453,7 +1453,7 @@ static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
        rc = sendcmd(CCISS_RESET_MSG, ctlr, NULL, 0, 2, 0, 0, 
                (unsigned char *) &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 
                TYPE_MSG);
-       /* sendcmd turned off interrputs on the board, turn 'em back on. */
+       /* sendcmd turned off interrupts on the board, turn 'em back on. */
        (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
        if (rc == 0)
                return SUCCESS;
@@ -1483,7 +1483,7 @@ static int  cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
                0, 2, 0, 0, 
                (unsigned char *) &cmd_to_abort->Header.LUN.LunAddrBytes[0], 
                TYPE_MSG);
-       /* sendcmd turned off interrputs on the board, turn 'em back on. */
+       /* sendcmd turned off interrupts on the board, turn 'em back on. */
        (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
        if (rc == 0)
                return SUCCESS;
index b8af22e610dfe4f90ac1b637f0670ec5f9e6bfee..91ebb007416c185587b22ac08e46993f09fcb7dc 100644 (file)
@@ -973,6 +973,10 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
        lo->transfer = xfer->transfer;
        lo->ioctl = xfer->ioctl;
 
+       if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) !=
+            (info->lo_flags & LO_FLAGS_AUTOCLEAR))
+               lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
+
        lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
        lo->lo_init[0] = info->lo_init[0];
        lo->lo_init[1] = info->lo_init[1];
@@ -1331,6 +1335,10 @@ static int lo_release(struct inode *inode, struct file *file)
 
        mutex_lock(&lo->lo_ctl_mutex);
        --lo->lo_refcnt;
+
+       if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) && !lo->lo_refcnt)
+               loop_clr_fd(lo, inode->i_bdev);
+
        mutex_unlock(&lo->lo_ctl_mutex);
 
        return 0;
index 76096cad798f1c54708a498a90d5eb85eb105f83..8b9549ab4a4e6eafd21b2e38b835618448cf31d9 100644 (file)
@@ -660,7 +660,7 @@ static int pt_open(struct inode *inode, struct file *file)
        pt_identify(tape);
 
        err = -ENODEV;
-       if (!tape->flags & PT_MEDIA)
+       if (!(tape->flags & PT_MEDIA))
                goto out;
 
        err = -EROFS;
index e9de1712e5a0b1b98b8cc1ce95d59d8daf0b615e..674cd66dcabaae261ca0e97c5ab61a1f272b2db5 100644 (file)
@@ -2212,11 +2212,11 @@ static int pkt_media_speed(struct pktcdvd_device *pd, unsigned *speed)
                return ret;
        }
 
-       if (!buf[6] & 0x40) {
+       if (!(buf[6] & 0x40)) {
                printk(DRIVER_NAME": Disc type is not CD-RW\n");
                return 1;
        }
-       if (!buf[6] & 0x4) {
+       if (!(buf[6] & 0x4)) {
                printk(DRIVER_NAME": A1 values on media are not valid, maybe not CDRW?\n");
                return 1;
        }
index 82f4eecc8699d19e42e899b043e2c45842cdbcc1..06e23be70904423afc8e6646832eeda664aa5484 100644 (file)
@@ -56,6 +56,7 @@
 #include <linux/backing-dev.h>
 #include <linux/blkpg.h>
 #include <linux/writeback.h>
+#include <linux/log2.h>
 
 #include <asm/uaccess.h>
 
@@ -450,7 +451,7 @@ static int __init rd_init(void)
        err = -ENOMEM;
 
        if (rd_blocksize > PAGE_SIZE || rd_blocksize < 512 ||
-                       (rd_blocksize & (rd_blocksize-1))) {
+                       !is_power_of_2(rd_blocksize)) {
                printk("RAMDISK: wrong blocksize %d, reverting to defaults\n",
                       rd_blocksize);
                rd_blocksize = BLOCK_SIZE;
index c6179d6ac6e430764b5c22e67f2b4130191ef599..a70c1c29a7aa2c28e99c9fa352fa6f42b2048d17 100644 (file)
@@ -922,11 +922,6 @@ static int ub_scsi_cmd_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
        usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->send_bulk_pipe,
            bcb, US_BULK_CB_WRAP_LEN, ub_urb_complete, sc);
 
-       /* Fill what we shouldn't be filling, because usb-storage did so. */
-       sc->work_urb.actual_length = 0;
-       sc->work_urb.error_count = 0;
-       sc->work_urb.status = 0;
-
        if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
                /* XXX Clear stalls */
                ub_complete(&sc->work_done);
@@ -1313,9 +1308,6 @@ static void ub_data_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
        sc->last_pipe = pipe;
        usb_fill_bulk_urb(&sc->work_urb, sc->dev, pipe, sg_virt(sg),
            sg->length, ub_urb_complete, sc);
-       sc->work_urb.actual_length = 0;
-       sc->work_urb.error_count = 0;
-       sc->work_urb.status = 0;
 
        if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
                /* XXX Clear stalls */
@@ -1356,9 +1348,6 @@ static int __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
        sc->last_pipe = sc->recv_bulk_pipe;
        usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->recv_bulk_pipe,
            &sc->work_bcs, US_BULK_CS_WRAP_LEN, ub_urb_complete, sc);
-       sc->work_urb.actual_length = 0;
-       sc->work_urb.error_count = 0;
-       sc->work_urb.status = 0;
 
        if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
                /* XXX Clear stalls */
@@ -1473,9 +1462,6 @@ static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
 
        usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe,
            (unsigned char*) cr, NULL, 0, ub_urb_complete, sc);
-       sc->work_urb.actual_length = 0;
-       sc->work_urb.error_count = 0;
-       sc->work_urb.status = 0;
 
        if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
                ub_complete(&sc->work_done);
@@ -1953,9 +1939,6 @@ static int ub_sync_reset(struct ub_dev *sc)
 
        usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe,
            (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl);
-       sc->work_urb.actual_length = 0;
-       sc->work_urb.error_count = 0;
-       sc->work_urb.status = 0;
 
        if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) {
                printk(KERN_WARNING
@@ -2007,9 +1990,6 @@ static int ub_sync_getmaxlun(struct ub_dev *sc)
 
        usb_fill_control_urb(&sc->work_urb, sc->dev, sc->recv_ctrl_pipe,
            (unsigned char*) cr, p, 1, ub_probe_urb_complete, &compl);
-       sc->work_urb.actual_length = 0;
-       sc->work_urb.error_count = 0;
-       sc->work_urb.status = 0;
 
        if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0)
                goto err_submit;
@@ -2077,9 +2057,6 @@ static int ub_probe_clear_stall(struct ub_dev *sc, int stalled_pipe)
 
        usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe,
            (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl);
-       sc->work_urb.actual_length = 0;
-       sc->work_urb.error_count = 0;
-       sc->work_urb.status = 0;
 
        if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) {
                printk(KERN_WARNING
index 924ddd8bccd2b8fdd32e06a7db1c3e05918ebc12..3b1a68d6eddb3c0860794c778a643340b59ec920 100644 (file)
@@ -7,8 +7,10 @@
 #include <linux/scatterlist.h>
 
 #define VIRTIO_MAX_SG  (3+MAX_PHYS_SEGMENTS)
+#define PART_BITS 4
+
+static int major, index;
 
-static unsigned char virtblk_index = 'a';
 struct virtio_blk
 {
        spinlock_t lock;
@@ -36,7 +38,7 @@ struct virtblk_req
        struct virtio_blk_inhdr in_hdr;
 };
 
-static bool blk_done(struct virtqueue *vq)
+static void blk_done(struct virtqueue *vq)
 {
        struct virtio_blk *vblk = vq->vdev->priv;
        struct virtblk_req *vbr;
@@ -65,7 +67,6 @@ static bool blk_done(struct virtqueue *vq)
        /* In case queue is stopped waiting for more buffers. */
        blk_start_queue(vblk->disk->queue);
        spin_unlock_irqrestore(&vblk->lock, flags);
-       return true;
 }
 
 static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
@@ -153,20 +154,37 @@ static int virtblk_ioctl(struct inode *inode, struct file *filp,
                              (void __user *)data);
 }
 
+/* We provide getgeo only to please some old bootloader/partitioning tools */
+static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
+{
+       /* some standard values, similar to sd */
+       geo->heads = 1 << 6;
+       geo->sectors = 1 << 5;
+       geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+       return 0;
+}
+
 static struct block_device_operations virtblk_fops = {
-       .ioctl = virtblk_ioctl,
-       .owner = THIS_MODULE,
+       .ioctl  = virtblk_ioctl,
+       .owner  = THIS_MODULE,
+       .getgeo = virtblk_getgeo,
 };
 
+static int index_to_minor(int index)
+{
+       return index << PART_BITS;
+}
+
 static int virtblk_probe(struct virtio_device *vdev)
 {
        struct virtio_blk *vblk;
-       int err, major;
-       void *token;
-       unsigned int len;
+       int err;
        u64 cap;
        u32 v;
 
+       if (index_to_minor(index) >= 1 << MINORBITS)
+               return -ENOSPC;
+
        vdev->priv = vblk = kmalloc(sizeof(*vblk), GFP_KERNEL);
        if (!vblk) {
                err = -ENOMEM;
@@ -178,7 +196,7 @@ static int virtblk_probe(struct virtio_device *vdev)
        vblk->vdev = vdev;
 
        /* We expect one virtqueue, for output. */
-       vblk->vq = vdev->config->find_vq(vdev, blk_done);
+       vblk->vq = vdev->config->find_vq(vdev, 0, blk_done);
        if (IS_ERR(vblk->vq)) {
                err = PTR_ERR(vblk->vq);
                goto out_free_vblk;
@@ -190,17 +208,11 @@ static int virtblk_probe(struct virtio_device *vdev)
                goto out_free_vq;
        }
 
-       major = register_blkdev(0, "virtblk");
-       if (major < 0) {
-               err = major;
-               goto out_mempool;
-       }
-
        /* FIXME: How many partitions?  How long is a piece of string? */
-       vblk->disk = alloc_disk(1 << 4);
+       vblk->disk = alloc_disk(1 << PART_BITS);
        if (!vblk->disk) {
                err = -ENOMEM;
-               goto out_unregister_blkdev;
+               goto out_mempool;
        }
 
        vblk->disk->queue = blk_init_queue(do_virtblk_request, &vblk->lock);
@@ -209,22 +221,32 @@ static int virtblk_probe(struct virtio_device *vdev)
                goto out_put_disk;
        }
 
-       sprintf(vblk->disk->disk_name, "vd%c", virtblk_index++);
+       if (index < 26) {
+               sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26);
+       } else if (index < (26 + 1) * 26) {
+               sprintf(vblk->disk->disk_name, "vd%c%c",
+                       'a' + index / 26 - 1, 'a' + index % 26);
+       } else {
+               const unsigned int m1 = (index / 26 - 1) / 26 - 1;
+               const unsigned int m2 = (index / 26 - 1) % 26;
+               const unsigned int m3 =  index % 26;
+               sprintf(vblk->disk->disk_name, "vd%c%c%c",
+                       'a' + m1, 'a' + m2, 'a' + m3);
+       }
+
        vblk->disk->major = major;
-       vblk->disk->first_minor = 0;
+       vblk->disk->first_minor = index_to_minor(index);
        vblk->disk->private_data = vblk;
        vblk->disk->fops = &virtblk_fops;
+       index++;
 
        /* If barriers are supported, tell block layer that queue is ordered */
-       token = vdev->config->find(vdev, VIRTIO_CONFIG_BLK_F, &len);
-       if (virtio_use_bit(vdev, token, len, VIRTIO_BLK_F_BARRIER))
+       if (vdev->config->feature(vdev, VIRTIO_BLK_F_BARRIER))
                blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL);
 
-       err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_CAPACITY, &cap);
-       if (err) {
-               dev_err(&vdev->dev, "Bad/missing capacity in config\n");
-               goto out_cleanup_queue;
-       }
+       /* Host must always specify the capacity. */
+       __virtio_config_val(vdev, offsetof(struct virtio_blk_config, capacity),
+                           &cap);
 
        /* If capacity is too big, truncate with warning. */
        if ((sector_t)cap != cap) {
@@ -234,31 +256,25 @@ static int virtblk_probe(struct virtio_device *vdev)
        }
        set_capacity(vblk->disk, cap);
 
-       err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_SIZE_MAX, &v);
+       /* Host can optionally specify maximum segment size and number of
+        * segments. */
+       err = virtio_config_val(vdev, VIRTIO_BLK_F_SIZE_MAX,
+                               offsetof(struct virtio_blk_config, size_max),
+                               &v);
        if (!err)
                blk_queue_max_segment_size(vblk->disk->queue, v);
-       else if (err != -ENOENT) {
-               dev_err(&vdev->dev, "Bad SIZE_MAX in config\n");
-               goto out_cleanup_queue;
-       }
 
-       err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_SEG_MAX, &v);
+       err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX,
+                               offsetof(struct virtio_blk_config, seg_max),
+                               &v);
        if (!err)
                blk_queue_max_hw_segments(vblk->disk->queue, v);
-       else if (err != -ENOENT) {
-               dev_err(&vdev->dev, "Bad SEG_MAX in config\n");
-               goto out_cleanup_queue;
-       }
 
        add_disk(vblk->disk);
        return 0;
 
-out_cleanup_queue:
-       blk_cleanup_queue(vblk->disk->queue);
 out_put_disk:
        put_disk(vblk->disk);
-out_unregister_blkdev:
-       unregister_blkdev(major, "virtblk");
 out_mempool:
        mempool_destroy(vblk->pool);
 out_free_vq:
@@ -274,12 +290,16 @@ static void virtblk_remove(struct virtio_device *vdev)
        struct virtio_blk *vblk = vdev->priv;
        int major = vblk->disk->major;
 
+       /* Nothing should be pending. */
        BUG_ON(!list_empty(&vblk->reqs));
+
+       /* Stop all the virtqueues. */
+       vdev->config->reset(vdev);
+
        blk_cleanup_queue(vblk->disk->queue);
        put_disk(vblk->disk);
        unregister_blkdev(major, "virtblk");
        mempool_destroy(vblk->pool);
-       /* There should be nothing in the queue now, so no need to shutdown */
        vdev->config->del_vq(vblk->vq);
        kfree(vblk);
 }
@@ -299,11 +319,15 @@ static struct virtio_driver virtio_blk = {
 
 static int __init init(void)
 {
+       major = register_blkdev(0, "virtblk");
+       if (major < 0)
+               return major;
        return register_virtio_driver(&virtio_blk);
 }
 
 static void __exit fini(void)
 {
+       unregister_blkdev(major, "virtblk");
        unregister_virtio_driver(&virtio_blk);
 }
 module_init(init);
index 1375b5345a0a1466045204b80a2804672b6c4756..3b28658f5a1ff1b748bb450d3272388c71783fca 100644 (file)
@@ -423,6 +423,7 @@ static int bpa10x_send_frame(struct sk_buff *skb)
                break;
 
        default:
+               usb_free_urb(urb);
                return -EILSEQ;
        }
 
index a18f9b8c9e128c33e8c3942ce55d3b7197d22ecb..7703d6e06fd988926dd2e697e32c4a57eee37158 100644 (file)
@@ -704,7 +704,7 @@ static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *
 
 static int bt3c_config(struct pcmcia_device *link)
 {
-       static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+       static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
        bt3c_info_t *info = link->priv;
        tuple_t tuple;
        u_short buf[256];
index b786f618790210857f429bea9d21eb83266c1499..58630cc1eff2f1047ed0049edcbb9c4e578d511f 100644 (file)
@@ -162,10 +162,8 @@ static int btsdio_rx_packet(struct btsdio_data *data)
        bt_cb(skb)->pkt_type = hdr[3];
 
        err = hci_recv_frame(skb);
-       if (err < 0) {
-               kfree(skb);
+       if (err < 0)
                return err;
-       }
 
        sdio_writeb(data->func, 0x00, REG_PC_RRT, NULL);
 
index 08f48d577ababf1b38bb0cf4693a311922392a8e..68d1d258e6a4f5f4e8064a061d374ef1b632dca3 100644 (file)
@@ -383,7 +383,7 @@ static void btuart_change_speed(btuart_info_t *info, unsigned int speed)
        outb(lcr, iobase + UART_LCR);   /* Set 8N1  */
        outb(fcr, iobase + UART_FCR);   /* Enable FIFO's */
 
-       /* Turn on interrups */
+       /* Turn on interrupts */
        outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
 
        spin_unlock_irqrestore(&(info->lock), flags);
@@ -634,7 +634,7 @@ static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *
 
 static int btuart_config(struct pcmcia_device *link)
 {
-       static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+       static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
        btuart_info_t *info = link->priv;
        tuple_t tuple;
        u_short buf[256];
index 98a9cdeaffb67a8c9a435ec57ae78fa880200176..372c7ef633dab53471c5d3e0dda7ac4dc49fdeff 100644 (file)
@@ -111,6 +111,7 @@ static struct usb_device_id blacklist_ids[] = {
        { USB_DEVICE(0x0a5c, 0x2033), .driver_info = HCI_IGNORE },
 
        /* Broadcom BCM2035 */
+       { USB_DEVICE(0x0a5c, 0x2035), .driver_info = HCI_RESET | HCI_WRONG_SCO_MTU },
        { USB_DEVICE(0x0a5c, 0x200a), .driver_info = HCI_RESET | HCI_WRONG_SCO_MTU },
        { USB_DEVICE(0x0a5c, 0x2009), .driver_info = HCI_BCM92035 },
 
index 47e5b40510cb4655cb031ce7470a81c5b7ebf85e..db259e60289b51ca84b46f56f67a741b0c473c16 100644 (file)
@@ -1206,25 +1206,26 @@ int check_for_audio_disc(struct cdrom_device_info * cdi,
        return 0;
 }
 
-/* Admittedly, the logic below could be performed in a nicer way. */
 int cdrom_release(struct cdrom_device_info *cdi, struct file *fp)
 {
        struct cdrom_device_ops *cdo = cdi->ops;
        int opened_for_data;
 
-       cdinfo(CD_CLOSE, "entering cdrom_release\n"); 
+       cdinfo(CD_CLOSE, "entering cdrom_release\n");
 
        if (cdi->use_count > 0)
                cdi->use_count--;
-       if (cdi->use_count == 0)
+
+       if (cdi->use_count == 0) {
                cdinfo(CD_CLOSE, "Use count for \"/dev/%s\" now zero\n", cdi->name);
-       if (cdi->use_count == 0)
                cdrom_dvd_rw_close_write(cdi);
-       if (cdi->use_count == 0 &&
-           (cdo->capability & CDC_LOCK) && !keeplocked) {
-               cdinfo(CD_CLOSE, "Unlocking door!\n");
-               cdo->lock_door(cdi, 0);
+
+               if ((cdo->capability & CDC_LOCK) && !keeplocked) {
+                       cdinfo(CD_CLOSE, "Unlocking door!\n");
+                       cdo->lock_door(cdi, 0);
+               }
        }
+
        opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
                !(fp && fp->f_flags & O_NONBLOCK);
 
index 466629594776fc4af443dec3ca4dc0fa767d0c4e..85bf9b2aa74ad5e0e09d75a0da8b1080b126b62e 100644 (file)
@@ -276,7 +276,7 @@ config N_HDLC
 
 config RISCOM8
        tristate "SDL RISCom/8 card support"
-       depends on SERIAL_NONSTANDARD && BROKEN_ON_SMP
+       depends on SERIAL_NONSTANDARD
        help
          This is a driver for the SDL Communications RISCom/8 multiport card,
          which gives you many serial ports. You would need something like
@@ -765,7 +765,7 @@ config JS_RTC
 
 config SGI_DS1286
        tristate "SGI DS1286 RTC support"
-       depends on SGI_IP22
+       depends on SGI_HAS_DS1286
        help
          If you say Y here and create a character special file /dev/rtc with
          major number 10 and minor number 135 using mknod ("man mknod"), you
index b83824c41329f3d4f4459de76b981c67ec946ba5..c69f79598e47cb4c9e375bc648daaa0e28e26646 100644 (file)
@@ -117,7 +117,8 @@ struct agp_bridge_driver {
        void (*free_by_type)(struct agp_memory *);
        void *(*agp_alloc_page)(struct agp_bridge_data *);
        void (*agp_destroy_page)(void *, int flags);
-        int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
+       int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
+       void (*chipset_flush)(struct agp_bridge_data *);
 };
 
 struct agp_bridge_data {
@@ -235,6 +236,9 @@ struct agp_bridge_data {
 #define I965_PGETBL_SIZE_512KB (0 << 1)
 #define I965_PGETBL_SIZE_256KB (1 << 1)
 #define I965_PGETBL_SIZE_128KB (2 << 1)
+#define I965_PGETBL_SIZE_1MB   (3 << 1)
+#define I965_PGETBL_SIZE_2MB   (4 << 1)
+#define I965_PGETBL_SIZE_1_5MB (5 << 1)
 #define G33_PGETBL_SIZE_MASK    (3 << 8)
 #define G33_PGETBL_SIZE_1M      (1 << 8)
 #define G33_PGETBL_SIZE_2M      (2 << 8)
index aa8f3a39a7044d74fe1652d62ef077fc470b024b..e77c17838c8af6ac0bf0559a20e4055875f7d9a1 100644 (file)
 
 #include "agp.h"
 
-static struct page *alpha_core_agp_vm_nopage(struct vm_area_struct *vma,
-                                            unsigned long address,
-                                            int *type)
+static int alpha_core_agp_vm_fault(struct vm_area_struct *vma,
+                                       struct vm_fault *vmf)
 {
        alpha_agp_info *agp = agp_bridge->dev_private_data;
        dma_addr_t dma_addr;
        unsigned long pa;
        struct page *page;
 
-       dma_addr = address - vma->vm_start + agp->aperture.bus_base;
+       dma_addr = (unsigned long)vmf->virtual_address - vma->vm_start
+                                               + agp->aperture.bus_base;
        pa = agp->ops->translate(agp, dma_addr);
 
        if (pa == (unsigned long)-EINVAL)
-               return NULL;    /* no translation */
+               return VM_FAULT_SIGBUS; /* no translation */
 
        /*
         * Get the page, inc the use count, and return it
         */
        page = virt_to_page(__va(pa));
        get_page(page);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return page;
+       vmf->page = page;
+       return 0;
 }
 
 static struct aper_size_info_fixed alpha_core_agp_sizes[] =
@@ -42,7 +41,7 @@ static struct aper_size_info_fixed alpha_core_agp_sizes[] =
 };
 
 struct vm_operations_struct alpha_core_agp_vm_ops = {
-       .nopage = alpha_core_agp_vm_nopage,
+       .fault = alpha_core_agp_vm_fault,
 };
 
 
index 1405a42585e13eb29dcb9ae3bce3d99836b9d5fb..87be46406dafdc201e5da80cd5faabd7dd1060da 100644 (file)
@@ -436,10 +436,6 @@ static int __devinit agp_amdk7_probe(struct pci_dev *pdev,
                                return -ENODEV;
                        }
                        cap_ptr = pci_find_capability(gfxcard, PCI_CAP_ID_AGP);
-                       if (!cap_ptr) {
-                               pci_dev_put(gfxcard);
-                               continue;
-                       }
                }
 
                /* With so many variants of NVidia cards, it's simpler just
index 2720882e66fec157dd987f0c665ae732171aa8df..b1bdd015165c092a5f850f606b1d9a8ed948d409 100644 (file)
@@ -43,7 +43,7 @@
  * fix some real stupidity. It's only by chance we can bump
  * past 0.99 at all due to some boolean logic error. */
 #define AGPGART_VERSION_MAJOR 0
-#define AGPGART_VERSION_MINOR 102
+#define AGPGART_VERSION_MINOR 103
 static const struct agp_version agp_current_version =
 {
        .major = AGPGART_VERSION_MAJOR,
index ecd4248861b9dfda6475e29d0acfcc9c6c547f96..39275794fe63a433edd5760b740af63ee12bf062 100644 (file)
@@ -273,6 +273,10 @@ long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case AGPIOC_UNBIND32:
                ret_val = compat_agpioc_unbind_wrap(curr_priv, (void __user *) arg);
                break;
+
+       case AGPIOC_CHIPSET_FLUSH32:
+               ret_val = agpioc_chipset_flush_wrap(curr_priv);
+               break;
        }
 
 ioctl_out:
index 71939d637236c9e260e80a41ee74d1d8a69f8a05..0c9678ac03716809fa22ef01deaee895ffc40002 100644 (file)
@@ -39,6 +39,7 @@
 #define AGPIOC_DEALLOCATE32 _IOW (AGPIOC_BASE, 7, compat_int_t)
 #define AGPIOC_BIND32       _IOW (AGPIOC_BASE, 8, compat_uptr_t)
 #define AGPIOC_UNBIND32     _IOW (AGPIOC_BASE, 9, compat_uptr_t)
+#define AGPIOC_CHIPSET_FLUSH32 _IO (AGPIOC_BASE, 10)
 
 struct agp_info32 {
        struct agp_version version;     /* version of the driver        */
@@ -101,5 +102,6 @@ void agp_free_memory_wrap(struct agp_memory *memory);
 struct agp_memory *agp_allocate_memory_wrap(size_t pg_count, u32 type);
 struct agp_memory *agp_find_mem_by_key(int key);
 struct agp_client *agp_find_client_by_pid(pid_t id);
+int agpioc_chipset_flush_wrap(struct agp_file_private *priv);
 
 #endif /* _AGP_COMPAT_H */
index 7791e98de51c81a34ed3b4aed1b007cb4b728e46..55d7a82bd071a725a8813d888dabb77215de79be 100644 (file)
@@ -689,7 +689,7 @@ static int agp_open(struct inode *inode, struct file *file)
        set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags);
        priv->my_pid = current->pid;
 
-       if ((current->uid == 0) || (current->suid == 0)) {
+       if (capable(CAP_SYS_RAWIO)) {
                /* Root priv, can be controller */
                set_bit(AGP_FF_ALLOW_CONTROLLER, &priv->access_flags);
        }
@@ -960,6 +960,13 @@ static int agpioc_unbind_wrap(struct agp_file_private *priv, void __user *arg)
        return agp_unbind_memory(memory);
 }
 
+int agpioc_chipset_flush_wrap(struct agp_file_private *priv)
+{
+       DBG("");
+       agp_flush_chipset(agp_bridge);
+       return 0;
+}
+
 static int agp_ioctl(struct inode *inode, struct file *file,
                     unsigned int cmd, unsigned long arg)
 {
@@ -1033,6 +1040,10 @@ static int agp_ioctl(struct inode *inode, struct file *file,
        case AGPIOC_UNBIND:
                ret_val = agpioc_unbind_wrap(curr_priv, (void __user *) arg);
                break;
+              
+       case AGPIOC_CHIPSET_FLUSH:
+               ret_val = agpioc_chipset_flush_wrap(curr_priv);
+               break;
        }
 
 ioctl_out:
index 1a4674ce0c718f4c1c3a9bceb8342551fc5e73b8..7484bc759c4ccb8e2fb2fa407e68ae38e5936dae 100644 (file)
@@ -80,6 +80,13 @@ static int agp_get_key(void)
        return -1;
 }
 
+void agp_flush_chipset(struct agp_bridge_data *bridge)
+{
+       if (bridge->driver->chipset_flush)
+               bridge->driver->chipset_flush(bridge);
+}
+EXPORT_SYMBOL(agp_flush_chipset);
+
 /*
  * Use kmalloc if possible for the page list. Otherwise fall back to
  * vmalloc. This speeds things up and also saves memory for small AGP
index 189efb6ef970e81b07aa69e90847ddabd14b161e..eeea50a1d22ace69991af91a7bcee524a4319e3e 100644 (file)
@@ -14,8 +14,8 @@
 #define PCI_DEVICE_ID_INTEL_E7221_IG   0x258a
 #define PCI_DEVICE_ID_INTEL_82946GZ_HB      0x2970
 #define PCI_DEVICE_ID_INTEL_82946GZ_IG      0x2972
-#define PCI_DEVICE_ID_INTEL_82965G_1_HB     0x2980
-#define PCI_DEVICE_ID_INTEL_82965G_1_IG     0x2982
+#define PCI_DEVICE_ID_INTEL_82G35_HB     0x2980
+#define PCI_DEVICE_ID_INTEL_82G35_IG     0x2982
 #define PCI_DEVICE_ID_INTEL_82965Q_HB       0x2990
 #define PCI_DEVICE_ID_INTEL_82965Q_IG       0x2992
 #define PCI_DEVICE_ID_INTEL_82965G_HB       0x29A0
 #define PCI_DEVICE_ID_INTEL_Q35_IG          0x29B2
 #define PCI_DEVICE_ID_INTEL_Q33_HB          0x29D0
 #define PCI_DEVICE_ID_INTEL_Q33_IG          0x29D2
+#define PCI_DEVICE_ID_INTEL_IGD_HB          0x2A40
+#define PCI_DEVICE_ID_INTEL_IGD_IG          0x2A42
+
+/* cover 915 and 945 variants */
+#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB)
 
 #define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
-                 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_1_HB || \
-                 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
-                 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
-                 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
-                 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82G35_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB || \
+                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_HB)
 
 #define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
                agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
@@ -71,9 +82,11 @@ extern int agp_memory_reserved;
 #define I915_GMCH_GMS_STOLEN_64M       (0x7 << 4)
 #define G33_GMCH_GMS_STOLEN_128M       (0x8 << 4)
 #define G33_GMCH_GMS_STOLEN_256M       (0x9 << 4)
+#define I915_IFPADDR    0x60
 
 /* Intel 965G registers */
 #define I965_MSAC 0x62
+#define I965_IFPADDR    0x70
 
 /* Intel 7505 registers */
 #define INTEL_I7505_APSIZE     0x74
@@ -115,6 +128,13 @@ static struct _intel_private {
         * popup and for the GTT.
         */
        int gtt_entries;                        /* i830+ */
+       union {
+               void __iomem *i9xx_flush_page;
+               void *i8xx_flush_page;
+       };
+       struct page *i8xx_page;
+       struct resource ifp_resource;
+       int resource_valid;
 } intel_private;
 
 static int intel_i810_fetch_size(void)
@@ -204,7 +224,7 @@ static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
 /* Exists to support ARGB cursors */
 static void *i8xx_alloc_pages(void)
 {
-       struct page * page;
+       struct page *page;
 
        page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
        if (page == NULL)
@@ -433,7 +453,7 @@ static void intel_i830_init_gtt_entries(void)
        static const int ddt[4] = { 0, 16, 32, 64 };
        int size; /* reserved space (in kb) at the top of stolen memory */
 
-       pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
+       pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
 
        if (IS_I965) {
                u32 pgetbl_ctl;
@@ -453,6 +473,15 @@ static void intel_i830_init_gtt_entries(void)
                case I965_PGETBL_SIZE_512KB:
                        size = 512;
                        break;
+               case I965_PGETBL_SIZE_1MB:
+                       size = 1024;
+                       break;
+               case I965_PGETBL_SIZE_2MB:
+                       size = 2048;
+                       break;
+               case I965_PGETBL_SIZE_1_5MB:
+                       size = 1024 + 512;
+                       break;
                default:
                        printk(KERN_INFO PFX "Unknown page table size, "
                               "assuming 512KB\n");
@@ -523,26 +552,14 @@ static void intel_i830_init_gtt_entries(void)
                        break;
                case I915_GMCH_GMS_STOLEN_48M:
                        /* Check it's really I915G */
-                       if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB ||
-                           IS_I965 || IS_G33)
+                       if (IS_I915 || IS_I965 || IS_G33)
                                gtt_entries = MB(48) - KB(size);
                        else
                                gtt_entries = 0;
                        break;
                case I915_GMCH_GMS_STOLEN_64M:
                        /* Check it's really I915G */
-                       if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB ||
-                           agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB ||
-                           IS_I965 || IS_G33)
+                       if (IS_I915 || IS_I965 || IS_G33)
                                gtt_entries = MB(64) - KB(size);
                        else
                                gtt_entries = 0;
@@ -575,6 +592,45 @@ static void intel_i830_init_gtt_entries(void)
        intel_private.gtt_entries = gtt_entries;
 }
 
+static void intel_i830_fini_flush(void)
+{
+       kunmap(intel_private.i8xx_page);
+       intel_private.i8xx_flush_page = NULL;
+       unmap_page_from_agp(intel_private.i8xx_page);
+
+       __free_page(intel_private.i8xx_page);
+       intel_private.i8xx_page = NULL;
+}
+
+static void intel_i830_setup_flush(void)
+{
+       /* return if we've already set the flush mechanism up */
+       if (intel_private.i8xx_page)
+               return;
+
+       intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
+       if (!intel_private.i8xx_page)
+               return;
+
+       /* make page uncached */
+       map_page_into_agp(intel_private.i8xx_page);
+
+       intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
+       if (!intel_private.i8xx_flush_page)
+               intel_i830_fini_flush();
+}
+
+static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
+{
+       unsigned int *pg = intel_private.i8xx_flush_page;
+       int i;
+
+       for (i = 0; i < 256; i += 2)
+               *(pg + i) = i;
+
+       wmb();
+}
+
 /* The intel i830 automatically initializes the agp aperture during POST.
  * Use the memory already set aside for in the GTT.
  */
@@ -590,10 +646,10 @@ static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
        num_entries = size->num_entries;
        agp_bridge->gatt_table_real = NULL;
 
-       pci_read_config_dword(intel_private.pcidev,I810_MMADDR,&temp);
+       pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
        temp &= 0xfff80000;
 
-       intel_private.registers = ioremap(temp,128 * 4096);
+       intel_private.registers = ioremap(temp, 128 * 4096);
        if (!intel_private.registers)
                return -ENOMEM;
 
@@ -633,7 +689,7 @@ static int intel_i830_fetch_size(void)
                return values[0].size;
        }
 
-       pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
+       pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
 
        if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
                agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
@@ -657,12 +713,12 @@ static int intel_i830_configure(void)
 
        current_size = A_SIZE_FIX(agp_bridge->current_size);
 
-       pci_read_config_dword(intel_private.pcidev,I810_GMADDR,&temp);
+       pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
        agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
 
-       pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
+       pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
        gmch_ctrl |= I830_GMCH_ENABLED;
-       pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
+       pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
 
        writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
        readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
@@ -675,6 +731,8 @@ static int intel_i830_configure(void)
        }
 
        global_cache_flush();
+
+       intel_i830_setup_flush();
        return 0;
 }
 
@@ -683,9 +741,10 @@ static void intel_i830_cleanup(void)
        iounmap(intel_private.registers);
 }
 
-static int intel_i830_insert_entries(struct agp_memory *mem,off_t pg_start, int type)
+static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
+                                    int type)
 {
-       int i,j,num_entries;
+       int i, j, num_entries;
        void *temp;
        int ret = -EINVAL;
        int mask_type;
@@ -697,10 +756,10 @@ static int intel_i830_insert_entries(struct agp_memory *mem,off_t pg_start, int
        num_entries = A_SIZE_FIX(temp)->num_entries;
 
        if (pg_start < intel_private.gtt_entries) {
-               printk (KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
-                               pg_start,intel_private.gtt_entries);
+               printk(KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
+                               pg_start, intel_private.gtt_entries);
 
-               printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
+               printk(KERN_INFO PFX "Trying to insert into local/stolen memory\n");
                goto out_err;
        }
 
@@ -738,8 +797,8 @@ out_err:
        return ret;
 }
 
-static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
-                               int type)
+static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
+                                    int type)
 {
        int i;
 
@@ -747,7 +806,7 @@ static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
                return 0;
 
        if (pg_start < intel_private.gtt_entries) {
-               printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
+               printk(KERN_INFO PFX "Trying to disable local/stolen memory\n");
                return -EINVAL;
        }
 
@@ -760,7 +819,7 @@ static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
        return 0;
 }
 
-static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count,int type)
+static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count, int type)
 {
        if (type == AGP_PHYS_MEMORY)
                return alloc_agpphysmem_i8xx(pg_count, type);
@@ -768,6 +827,95 @@ static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count,int type)
        return NULL;
 }
 
+static int intel_alloc_chipset_flush_resource(void)
+{
+       int ret;
+       ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
+                                    PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
+                                    pcibios_align_resource, agp_bridge->dev);
+
+       return ret;
+}
+
+static void intel_i915_setup_chipset_flush(void)
+{
+       int ret;
+       u32 temp;
+
+       pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
+       if (!(temp & 0x1)) {
+               intel_alloc_chipset_flush_resource();
+               intel_private.resource_valid = 1;
+               pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
+       } else {
+               temp &= ~1;
+
+               intel_private.resource_valid = 1;
+               intel_private.ifp_resource.start = temp;
+               intel_private.ifp_resource.end = temp + PAGE_SIZE;
+               ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
+               /* some BIOSes reserve this area in a pnp some don't */
+               if (ret)
+                       intel_private.resource_valid = 0;
+       }
+}
+
+static void intel_i965_g33_setup_chipset_flush(void)
+{
+       u32 temp_hi, temp_lo;
+       int ret;
+
+       pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
+       pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
+
+       if (!(temp_lo & 0x1)) {
+
+               intel_alloc_chipset_flush_resource();
+
+               intel_private.resource_valid = 1;
+               pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
+                       upper_32_bits(intel_private.ifp_resource.start));
+               pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
+       } else {
+               u64 l64;
+
+               temp_lo &= ~0x1;
+               l64 = ((u64)temp_hi << 32) | temp_lo;
+
+               intel_private.resource_valid = 1;
+               intel_private.ifp_resource.start = l64;
+               intel_private.ifp_resource.end = l64 + PAGE_SIZE;
+               ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
+               /* some BIOSes reserve this area in a pnp some don't */
+               if (ret)
+                       intel_private.resource_valid = 0;
+       }
+}
+
+static void intel_i9xx_setup_flush(void)
+{
+       /* return if already configured */
+       if (intel_private.ifp_resource.start)
+               return;
+
+       /* setup a resource for this object */
+       intel_private.ifp_resource.name = "Intel Flush Page";
+       intel_private.ifp_resource.flags = IORESOURCE_MEM;
+
+       /* Setup chipset flush for 915 */
+       if (IS_I965 || IS_G33) {
+               intel_i965_g33_setup_chipset_flush();
+       } else {
+               intel_i915_setup_chipset_flush();
+       }
+
+       if (intel_private.ifp_resource.start) {
+               intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
+               if (!intel_private.i9xx_flush_page)
+                       printk(KERN_INFO "unable to ioremap flush  page - no chipset flushing");
+       }
+}
+
 static int intel_i915_configure(void)
 {
        struct aper_size_info_fixed *current_size;
@@ -781,9 +929,9 @@ static int intel_i915_configure(void)
 
        agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
 
-       pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
+       pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
        gmch_ctrl |= I830_GMCH_ENABLED;
-       pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
+       pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
 
        writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
        readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
@@ -796,19 +944,34 @@ static int intel_i915_configure(void)
        }
 
        global_cache_flush();
+
+       intel_i9xx_setup_flush();
+
        return 0;
 }
 
 static void intel_i915_cleanup(void)
 {
+       if (intel_private.i9xx_flush_page)
+               iounmap(intel_private.i9xx_flush_page);
+       if (intel_private.resource_valid)
+               release_resource(&intel_private.ifp_resource);
+       intel_private.ifp_resource.start = 0;
+       intel_private.resource_valid = 0;
        iounmap(intel_private.gtt);
        iounmap(intel_private.registers);
 }
 
-static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
-                               int type)
+static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
 {
-       int i,j,num_entries;
+       if (intel_private.i9xx_flush_page)
+               writel(1, intel_private.i9xx_flush_page);
+}
+
+static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
+                                    int type)
+{
+       int i, j, num_entries;
        void *temp;
        int ret = -EINVAL;
        int mask_type;
@@ -820,10 +983,10 @@ static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
        num_entries = A_SIZE_FIX(temp)->num_entries;
 
        if (pg_start < intel_private.gtt_entries) {
-               printk (KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
-                               pg_start,intel_private.gtt_entries);
+               printk(KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
+                               pg_start, intel_private.gtt_entries);
 
-               printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
+               printk(KERN_INFO PFX "Trying to insert into local/stolen memory\n");
                goto out_err;
        }
 
@@ -861,8 +1024,8 @@ static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
        return ret;
 }
 
-static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
-                               int type)
+static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
+                                    int type)
 {
        int i;
 
@@ -870,13 +1033,13 @@ static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
                return 0;
 
        if (pg_start < intel_private.gtt_entries) {
-               printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
+               printk(KERN_INFO PFX "Trying to disable local/stolen memory\n");
                return -EINVAL;
        }
 
-       for (i = pg_start; i < (mem->page_count + pg_start); i++) {
+       for (i = pg_start; i < (mem->page_count + pg_start); i++)
                writel(agp_bridge->scratch_page, intel_private.gtt+i);
-       }
+
        readl(intel_private.gtt+i-1);
 
        agp_bridge->driver->tlb_flush(mem);
@@ -923,7 +1086,7 @@ static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
        agp_bridge->gatt_table_real = NULL;
 
        pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
-       pci_read_config_dword(intel_private.pcidev, I915_PTEADDR,&temp2);
+       pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
 
        if (IS_G33)
            gtt_map_size = 1024 * 1024; /* 1M on G33 */
@@ -933,7 +1096,7 @@ static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
 
        temp &= 0xfff80000;
 
-       intel_private.registers = ioremap(temp,128 * 4096);
+       intel_private.registers = ioremap(temp, 128 * 4096);
        if (!intel_private.registers) {
                iounmap(intel_private.gtt);
                return -ENOMEM;
@@ -980,6 +1143,7 @@ static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
        struct aper_size_info_fixed *size;
        int num_entries;
        u32 temp;
+       int gtt_offset, gtt_size;
 
        size = agp_bridge->current_size;
        page_order = size->page_order;
@@ -989,13 +1153,18 @@ static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
        pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
 
        temp &= 0xfff00000;
-       intel_private.gtt = ioremap((temp + (512 * 1024)) , 512 * 1024);
 
-       if (!intel_private.gtt)
-               return -ENOMEM;
+       if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_HB)
+              gtt_offset = gtt_size = MB(2);
+       else
+              gtt_offset = gtt_size = KB(512);
+
+       intel_private.gtt = ioremap((temp + gtt_offset) , gtt_size);
 
+       if (!intel_private.gtt)
+              return -ENOMEM;
 
-       intel_private.registers = ioremap(temp,128 * 4096);
+       intel_private.registers = ioremap(temp, 128 * 4096);
        if (!intel_private.registers) {
                iounmap(intel_private.gtt);
                return -ENOMEM;
@@ -1154,7 +1323,7 @@ static int intel_815_configure(void)
        /* the Intel 815 chipset spec. says that bits 29-31 in the
        * ATTBASE register are reserved -> try not to write them */
        if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
-               printk (KERN_EMERG PFX "gatt bus addr too high");
+               printk(KERN_EMERG PFX "gatt bus addr too high");
                return -EINVAL;
        }
 
@@ -1296,6 +1465,8 @@ static int intel_845_configure(void)
        pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
        /* clear any possible error conditions */
        pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
+
+       intel_i830_setup_flush();
        return 0;
 }
 
@@ -1552,6 +1723,7 @@ static const struct agp_bridge_driver intel_830_driver = {
        .agp_alloc_page         = agp_generic_alloc_page,
        .agp_destroy_page       = agp_generic_destroy_page,
        .agp_type_to_mask_type  = intel_i830_type_to_mask_type,
+       .chipset_flush          = intel_i830_chipset_flush,
 };
 
 static const struct agp_bridge_driver intel_820_driver = {
@@ -1648,6 +1820,7 @@ static const struct agp_bridge_driver intel_845_driver = {
        .agp_alloc_page         = agp_generic_alloc_page,
        .agp_destroy_page       = agp_generic_destroy_page,
        .agp_type_to_mask_type  = agp_generic_type_to_mask_type,
+       .chipset_flush          = intel_i830_chipset_flush,
 };
 
 static const struct agp_bridge_driver intel_850_driver = {
@@ -1721,6 +1894,7 @@ static const struct agp_bridge_driver intel_915_driver = {
        .agp_alloc_page         = agp_generic_alloc_page,
        .agp_destroy_page       = agp_generic_destroy_page,
        .agp_type_to_mask_type  = intel_i830_type_to_mask_type,
+       .chipset_flush          = intel_i915_chipset_flush,
 };
 
 static const struct agp_bridge_driver intel_i965_driver = {
@@ -1746,6 +1920,7 @@ static const struct agp_bridge_driver intel_i965_driver = {
        .agp_alloc_page         = agp_generic_alloc_page,
        .agp_destroy_page       = agp_generic_destroy_page,
        .agp_type_to_mask_type  = intel_i830_type_to_mask_type,
+       .chipset_flush          = intel_i915_chipset_flush,
 };
 
 static const struct agp_bridge_driver intel_7505_driver = {
@@ -1795,6 +1970,7 @@ static const struct agp_bridge_driver intel_g33_driver = {
        .agp_alloc_page         = agp_generic_alloc_page,
        .agp_destroy_page       = agp_generic_destroy_page,
        .agp_type_to_mask_type  = intel_i830_type_to_mask_type,
+       .chipset_flush          = intel_i915_chipset_flush,
 };
 
 static int find_gmch(u16 device)
@@ -1804,7 +1980,7 @@ static int find_gmch(u16 device)
        gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
        if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
                gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
-                                device, gmch_device);
+                                            device, gmch_device);
        }
 
        if (!gmch_device)
@@ -1867,7 +2043,7 @@ static const struct intel_driver_description {
                NULL, &intel_915_driver },
        { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
                NULL, &intel_i965_driver },
-       { PCI_DEVICE_ID_INTEL_82965G_1_HB, PCI_DEVICE_ID_INTEL_82965G_1_IG, 0, "965G",
+       { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, 0, "G35",
                NULL, &intel_i965_driver },
        { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
                NULL, &intel_i965_driver },
@@ -1885,6 +2061,8 @@ static const struct intel_driver_description {
                NULL, &intel_g33_driver },
        { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
                NULL, &intel_g33_driver },
+       { PCI_DEVICE_ID_INTEL_IGD_HB, PCI_DEVICE_ID_INTEL_IGD_IG, 0,
+           "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
        { 0, 0, 0, NULL, NULL, NULL }
 };
 
@@ -1924,7 +2102,7 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
        if (intel_agp_chipsets[i].name == NULL) {
                if (cap_ptr)
                        printk(KERN_WARNING PFX "Unsupported Intel chipset"
-                               "(device id: %04x)\n", pdev->device);
+                              "(device id: %04x)\n", pdev->device);
                agp_put_bridge(bridge);
                return -ENODEV;
        }
@@ -1937,7 +2115,7 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
                                intel_agp_chipsets[i].gmch_chip_id);
                agp_put_bridge(bridge);
                return -ENODEV;
-        }
+       }
 
        bridge->dev = pdev;
        bridge->capndx = cap_ptr;
@@ -2067,7 +2245,7 @@ static struct pci_device_id agp_intel_pci_table[] = {
        ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
        ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
        ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
-       ID(PCI_DEVICE_ID_INTEL_82965G_1_HB),
+       ID(PCI_DEVICE_ID_INTEL_82G35_HB),
        ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
        ID(PCI_DEVICE_ID_INTEL_82965G_HB),
        ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
@@ -2075,6 +2253,7 @@ static struct pci_device_id agp_intel_pci_table[] = {
        ID(PCI_DEVICE_ID_INTEL_G33_HB),
        ID(PCI_DEVICE_ID_INTEL_Q35_HB),
        ID(PCI_DEVICE_ID_INTEL_Q33_HB),
+       ID(PCI_DEVICE_ID_INTEL_IGD_HB),
        { }
 };
 
index e8d50af58201825effe532d775362187a90b46fc..ef5e6b130c4845aa8b3ad68b36538b34d90e6311 100644 (file)
@@ -506,6 +506,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
        vma->vm_ops = &drm_vm_dma_ops;
 
        vma->vm_flags |= VM_RESERVED;   /* Don't swap */
+       vma->vm_flags |= VM_DONTEXPAND;
 
        vma->vm_file = filp;    /* Needed for drm_vm_open() */
        drm_vm_open_locked(vma);
@@ -655,6 +656,7 @@ static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma)
                return -EINVAL; /* This should never happen. */
        }
        vma->vm_flags |= VM_RESERVED;   /* Don't swap */
+       vma->vm_flags |= VM_DONTEXPAND;
 
        vma->vm_file = filp;    /* Needed for drm_vm_open() */
        drm_vm_open_locked(vma);
index 3ae57ecc7afd84b30b6557a4e01d0be30c45fc5c..fa194a46c1e4f3166ef0d2164e215b8221b9be07 100644 (file)
@@ -584,7 +584,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define R300_RE_FOG_START                     0x4298
 
 /* Not sure why there are duplicate of factor and constant values.
- * My best guess so far is that there are seperate zbiases for test and write.
+ * My best guess so far is that there are separate zbiases for test and write.
  * Ordering might be wrong.
  * Some of the tests indicate that fgl has a fallback implementation of zbias
  * via pixel shaders.
index 75d6b748c2c0dec1e2634082820681e5f5b3e288..7009dbddac436fc86fbd1fe20757382d6228541f 100644 (file)
@@ -400,7 +400,7 @@ static inline uint32_t *via_align_buffer(drm_via_private_t * dev_priv,
 }
 
 /*
- * This function is used internally by ring buffer mangement code.
+ * This function is used internally by ring buffer management code.
  *
  * Returns virtual pointer to ring buffer.
  */
index 004141d535a27852eda7d3a9ea287893ea3db2e7..49233f5898742040339b5a1d31c4ce7fd74d9960 100644 (file)
@@ -18,7 +18,7 @@
  *
  * NOTES:
  *     - Locking is required for safe execution of EFI calls with regards
- *       to interrrupts and SMP.
+ *       to interrupts and SMP.
  *
  * TODO (December 1999):
  *     - provide the API to set/get the WakeUp Alarm (different from the
index ffcecde9e2a5b317319e605480c5520264c77ee3..ffd747c5dff00dc7e69a1835d078003dd7ffc3d7 100644 (file)
@@ -1797,7 +1797,7 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
        res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
        /*
         * This gets a little confusing. The Digi cards have their own
-        * representation of c_cflags controling baud rate. For the most part
+        * representation of c_cflags controlling baud rate. For the most part
         * this is identical to the Linux implementation. However; Digi
         * supports one rate (76800) that Linux doesn't. This means that the
         * c_cflag entry that would normally mean 76800 for Digi actually means
@@ -2068,7 +2068,7 @@ static int info_ioctl(struct tty_struct *tty, struct file *file,
                {
                        /*
                         * This call is made by the apps to complete the
-                        * initilization of the board(s). This routine is
+                        * initialization of the board(s). This routine is
                         * responsible for setting the card to its initial
                         * state and setting the drivers control fields to the
                         * sutianle settings for the card in question.
index 0e8ceea5ea780a10c0e5f9bbb506da486cd658c6..712d9f271aa6b8ed7026bca1594cc3b38052287f 100644 (file)
@@ -26,7 +26,7 @@
  * The hangcheck-timer driver uses the TSC to catch delays that
  * jiffies does not notice.  A timer is set.  When the timer fires, it
  * checks whether it was delayed and if that delay exceeds a given
- * margin of error.  The hangcheck_tick module paramter takes the timer
+ * margin of error.  The hangcheck_tick module parameter takes the timer
  * duration in seconds.  The hangcheck_margin parameter defines the
  * margin of error, in seconds.  The defaults are 60 seconds for the
  * timer and 180 seconds for the margin of error.  IOW, a timer is set
index 480fae29c9b2a508305d67e870684136c8f7581e..44160d5ebca06dbcd7e300c9835cbeb1763c1a4c 100644 (file)
@@ -93,7 +93,7 @@ struct hvc_struct {
 };
 
 /* dynamic list of hvc_struct instances */
-static struct list_head hvc_structs = LIST_HEAD_INIT(hvc_structs);
+static LIST_HEAD(hvc_structs);
 
 /*
  * Protect the list of hvc_struct instances from inserts and removals during
index fd7559084b8204479c76dc0cbd72da06fe431126..786d518e947752a56079227111cb322a2de7700e 100644 (file)
@@ -306,7 +306,7 @@ struct hvcs_struct {
 /* Required to back map a kref to its containing object */
 #define from_kref(k) container_of(k, struct hvcs_struct, kref)
 
-static struct list_head hvcs_structs = LIST_HEAD_INIT(hvcs_structs);
+static LIST_HEAD(hvcs_structs);
 static DEFINE_SPINLOCK(hvcs_structs_lock);
 
 static void hvcs_unthrottle(struct tty_struct *tty);
@@ -838,7 +838,7 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
        if (!hvcsd)
                return -ENODEV;
 
-       /* By this time the vty-server won't be getting any more interrups */
+       /* By this time the vty-server won't be getting any more interrupts */
 
        spin_lock_irqsave(&hvcsd->lock, flags);
 
index 0118b9817a95efa7a414033d52418f2d6885f6f1..84cdf9025737722fe4341974cf3bce90d268bc3f 100644 (file)
@@ -234,11 +234,11 @@ static DEVICE_ATTR(rng_available, S_IRUGO,
                   NULL);
 
 
-static void unregister_miscdev(void)
+static void unregister_miscdev(bool suspended)
 {
        device_remove_file(rng_miscdev.this_device, &dev_attr_rng_available);
        device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current);
-       misc_deregister(&rng_miscdev);
+       __misc_deregister(&rng_miscdev, suspended);
 }
 
 static int register_miscdev(void)
@@ -313,7 +313,7 @@ out:
 }
 EXPORT_SYMBOL_GPL(hwrng_register);
 
-void hwrng_unregister(struct hwrng *rng)
+void __hwrng_unregister(struct hwrng *rng, bool suspended)
 {
        int err;
 
@@ -332,11 +332,11 @@ void hwrng_unregister(struct hwrng *rng)
                }
        }
        if (list_empty(&rng_list))
-               unregister_miscdev();
+               unregister_miscdev(suspended);
 
        mutex_unlock(&rng_mutex);
 }
-EXPORT_SYMBOL_GPL(hwrng_unregister);
+EXPORT_SYMBOL_GPL(__hwrng_unregister);
 
 
 MODULE_DESCRIPTION("H/W Random Number Generator (RNG) driver");
index 868e39fd42e49779e494d8c96d097c700ab2d0b2..f7feae4ebb5e9981e7f730f637a2b1e54f5cc767 100644 (file)
@@ -42,6 +42,8 @@ enum {
        VIA_STRFILT_ENABLE      = (1 << 14),
        VIA_RAWBITS_ENABLE      = (1 << 13),
        VIA_RNG_ENABLE          = (1 << 6),
+       VIA_NOISESRC1           = (1 << 8),
+       VIA_NOISESRC2           = (1 << 9),
        VIA_XSTORE_CNT_MASK     = 0x0F,
 
        VIA_RNG_CHUNK_8         = 0x00, /* 64 rand bits, 64 stored bits */
@@ -119,6 +121,7 @@ static int via_rng_data_read(struct hwrng *rng, u32 *data)
 
 static int via_rng_init(struct hwrng *rng)
 {
+       struct cpuinfo_x86 *c = &cpu_data(0);
        u32 lo, hi, old_lo;
 
        /* Control the RNG via MSR.  Tread lightly and pay very close
@@ -134,6 +137,17 @@ static int via_rng_init(struct hwrng *rng)
        lo &= ~VIA_XSTORE_CNT_MASK;
        lo &= ~(VIA_STRFILT_ENABLE | VIA_STRFILT_FAIL | VIA_RAWBITS_ENABLE);
        lo |= VIA_RNG_ENABLE;
+       lo |= VIA_NOISESRC1;
+
+       /* Enable secondary noise source on CPUs where it is present. */
+
+       /* Nehemiah stepping 8 and higher */
+       if ((c->x86_model == 9) && (c->x86_mask > 7))
+               lo |= VIA_NOISESRC2;
+
+       /* Esther */
+       if (c->x86_model >= 10)
+               lo |= VIA_NOISESRC2;
 
        if (lo != old_lo)
                wrmsr(MSR_VIA_RNG, lo, hi);
index 30e564516422edd31d42996d520c2fdb6bb7206b..179223a1741437ad6d8749b99909bdc1f5289588 100644 (file)
@@ -439,6 +439,13 @@ static struct dmi_system_id __initdata i8k_dmi_table[] = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
                },
        },
+       {       /* UK Inspiron 6400  */
+               .ident = "Dell Inspiron 3",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
+               },
+       },
        { }
 };
 
index e46120d05b689af32f855e68a1656fd1d9794fd0..d6567b32fb5c18c960651fb49fdfee5277225895 100644 (file)
@@ -661,7 +661,7 @@ i2QueueCommands(int type, i2ChanStrPtr pCh, int timeout, int nCommands,
                if (!in_interrupt()) {
                        schedule_timeout_interruptible(1);      // short nap
                } else {
-                       // we cannot sched/sleep in interrrupt silly
+                       // we cannot sched/sleep in interrupt silly
                        return 0;   
                }
                if (signal_pending(current)) {
index e04e66cf2c68c53c6bc829d2923fbc8c5910a909..0f49ccf02a7fea974440587b337e60f015740e6f 100644 (file)
@@ -1251,7 +1251,7 @@ ip2_poll(unsigned long arg)
 
        // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
        // It will NOT poll boards handled by hard interrupts.
-       // The issue of queued BH interrups is handled in ip2_interrupt().
+       // The issue of queued BH interrupts is handled in ip2_interrupt().
        ip2_polled_interrupt();
 
        PollTimer.expires = POLL_TIMEOUT;
index 932264a657d0da57a0567f428d88d07e01445b5a..86e6538a77b05835b352001d170dba5335be284b 100644 (file)
@@ -46,8 +46,8 @@
 #include <asm/sn/sn0/hub.h>
 #include <asm/sn/sn_private.h>
 
-static int rtc_ioctl(struct inode *inode, struct file *file,
-                    unsigned int cmd, unsigned long arg);
+static long rtc_ioctl(struct file *filp, unsigned int cmd,
+                       unsigned long arg);
 
 static int rtc_read_proc(char *page, char **start, off_t off,
                          int count, int *eof, void *data);
@@ -75,8 +75,7 @@ static unsigned long epoch = 1970;    /* year corresponding to 0x00   */
 static const unsigned char days_in_mo[] =
 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
-static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
-                    unsigned long arg)
+static long rtc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 
        struct rtc_time wtime;
@@ -197,7 +196,7 @@ static int rtc_release(struct inode *inode, struct file *file)
 
 static const struct file_operations rtc_fops = {
        .owner          = THIS_MODULE,
-       .ioctl          = rtc_ioctl,
+       .unlocked_ioctl = rtc_ioctl,
        .open           = rtc_open,
        .release        = rtc_release,
 };
index 5dc1265ce1d5b288c7049c9ecb305e72d223f618..32b2b22996dc34efc189ccc71b5cdc2b6b3b4ba2 100644 (file)
@@ -365,12 +365,12 @@ static struct device_driver ipmidriver = {
 };
 static DEFINE_MUTEX(ipmidriver_mutex);
 
-static struct list_head ipmi_interfaces = LIST_HEAD_INIT(ipmi_interfaces);
+static LIST_HEAD(ipmi_interfaces);
 static DEFINE_MUTEX(ipmi_interfaces_mutex);
 
 /* List of watchers that want to know when smi's are added and
    deleted. */
-static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers);
+static LIST_HEAD(smi_watchers);
 static DEFINE_MUTEX(smi_watchers_mutex);
 
 
@@ -441,7 +441,7 @@ struct watcher_entry {
 int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
 {
        ipmi_smi_t intf;
-       struct list_head to_deliver = LIST_HEAD_INIT(to_deliver);
+       LIST_HEAD(to_deliver);
        struct watcher_entry *e, *e2;
 
        mutex_lock(&smi_watchers_mutex);
index 81674d7c56c7e74c655e62bb86f2d20cc350aae3..60ac642752bea4441604515513efa160d6e8c73f 100644 (file)
@@ -312,7 +312,7 @@ static ssize_t lp_write(struct file * file, const char __user * buf,
        if (copy_size > LP_BUFFER_SIZE)
                copy_size = LP_BUFFER_SIZE;
 
-       if (down_interruptible (&lp_table[minor].port_mutex))
+       if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
                return -EINTR;
 
        if (copy_from_user (kbuf, buf, copy_size)) {
@@ -399,7 +399,7 @@ static ssize_t lp_write(struct file * file, const char __user * buf,
                lp_release_parport (&lp_table[minor]);
        }
 out_unlock:
-       up (&lp_table[minor].port_mutex);
+       mutex_unlock(&lp_table[minor].port_mutex);
 
        return retv;
 }
@@ -421,7 +421,7 @@ static ssize_t lp_read(struct file * file, char __user * buf,
        if (count > LP_BUFFER_SIZE)
                count = LP_BUFFER_SIZE;
 
-       if (down_interruptible (&lp_table[minor].port_mutex))
+       if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
                return -EINTR;
 
        lp_claim_parport_or_block (&lp_table[minor]);
@@ -479,7 +479,7 @@ static ssize_t lp_read(struct file * file, char __user * buf,
        if (retval > 0 && copy_to_user (buf, kbuf, retval))
                retval = -EFAULT;
 
-       up (&lp_table[minor].port_mutex);
+       mutex_unlock(&lp_table[minor].port_mutex);
 
        return retval;
 }
@@ -888,7 +888,7 @@ static int __init lp_init (void)
                lp_table[i].last_error = 0;
                init_waitqueue_head (&lp_table[i].waitq);
                init_waitqueue_head (&lp_table[i].dataq);
-               init_MUTEX (&lp_table[i].port_mutex);
+               mutex_init(&lp_table[i].port_mutex);
                lp_table[i].timeout = 10 * HZ;
        }
 
index 71c8cd7fa15f8d5c32574ce95016f980e6830c41..a39101feb2ed8f70ff57f5d74e1a05855bec959d 100644 (file)
@@ -232,8 +232,9 @@ int misc_register(struct miscdevice * misc)
 }
 
 /**
- *     misc_deregister - unregister a miscellaneous device
+ *     __misc_deregister - unregister a miscellaneous device
  *     @misc: device to unregister
+ *     @suspended: to be set if the function is used during suspend/resume
  *
  *     Unregister a miscellaneous device that was previously
  *     successfully registered with misc_register(). Success
@@ -241,7 +242,7 @@ int misc_register(struct miscdevice * misc)
  *     indicates an error.
  */
 
-int misc_deregister(struct miscdevice * misc)
+int __misc_deregister(struct miscdevice *misc, bool suspended)
 {
        int i = misc->minor;
 
@@ -250,7 +251,11 @@ int misc_deregister(struct miscdevice * misc)
 
        mutex_lock(&misc_mtx);
        list_del(&misc->list);
-       device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
+       if (suspended)
+               destroy_suspended_device(misc_class,
+                                       MKDEV(MISC_MAJOR, misc->minor));
+       else
+               device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
        if (i < DYNAMIC_MINORS && i>0) {
                misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
        }
@@ -259,7 +264,7 @@ int misc_deregister(struct miscdevice * misc)
 }
 
 EXPORT_SYMBOL(misc_register);
-EXPORT_SYMBOL(misc_deregister);
+EXPORT_SYMBOL(__misc_deregister);
 
 static int __init misc_init(void)
 {
index 82f2e27dca7d17ac42072adbd56cb52a175d551a..ff146c2b08fd65cb6e26498923d4df8b03ab95df 100644 (file)
@@ -283,7 +283,7 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma,
        vdata->refcnt = ATOMIC_INIT(1);
        vma->vm_private_data = vdata;
 
-       vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP);
+       vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP | VM_DONTEXPAND);
        if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED)
                vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
        vma->vm_ops = &mspec_vm_ops;
index fd0abef7ee0867dfb86ccc0958e0a1c64402e947..47420787a0174933c82777c3e14e689bb784ef0f 100644 (file)
@@ -37,7 +37,6 @@
 
 
 #include <linux/module.h>
-#include <linux/autoconf.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
index 081c84c7b5489ae9b3e80fb2730d8622dc552790..bf1bee4e1f5e6cea411dc276fb946ff231e70346 100644 (file)
@@ -20,7 +20,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/autoconf.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
index 596c7173997b577d1216d479604435053da4f92f..90c3969012a3ce5f5ddb941561a813c6a9a3349b 100644 (file)
@@ -695,17 +695,16 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
                return;
        }
        
-       if (tty->stopped && !tty->flow_stopped &&
-           I_IXON(tty) && I_IXANY(tty)) {
-               start_tty(tty);
-               return;
-       }
-       
        if (I_ISTRIP(tty))
                c &= 0x7f;
        if (I_IUCLC(tty) && L_IEXTEN(tty))
                c=tolower(c);
 
+       if (tty->stopped && !tty->flow_stopped && I_IXON(tty) &&
+           ((I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty)) ||
+            c == INTR_CHAR(tty) || c == QUIT_CHAR(tty)))
+               start_tty(tty);
+
        if (tty->closing) {
                if (I_IXON(tty)) {
                        if (c == START_CHAR(tty))
@@ -769,7 +768,21 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
                signal = SIGTSTP;
                if (c == SUSP_CHAR(tty)) {
 send_signal:
-                       isig(signal, tty, 0);
+                       /*
+                        * Echo character, and then send the signal.
+                        * Note that we do not use isig() here because we want
+                        * the order to be:
+                        * 1) flush, 2) echo, 3) signal
+                        */
+                       if (!L_NOFLSH(tty)) {
+                               n_tty_flush_buffer(tty);
+                               if (tty->driver->flush_buffer)
+                                       tty->driver->flush_buffer(tty);
+                       }
+                       if (L_ECHO(tty))
+                               echo_char(c, tty);
+                       if (tty->pgrp)
+                               kill_pgrp(tty->pgrp, signal, 1);
                        return;
                }
        }
index 6076e662886a43fc3b863ab3bd6022e0e8041f0e..dfaab2322de32c09a0adeab709cf5613ca9a0d5f 100644 (file)
@@ -2,7 +2,7 @@
  * nozomi.c  -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
  *
  * Written by: Ulf Jakobsson,
- *             Jan ï¿½erfeldt,
+ *             Jan Ã…kerfeldt,
  *             Stefan Thomasson,
  *
  * Maintained by: Paul Hardwick (p.hardwick@option.com)
  * --------------------------------------------------------------------------
  */
 
-/*
- * CHANGELOG
- * Version 2.1d
- * 11-November-2007 Jiri Slaby, Frank Seidel
- * - Big rework of multicard support by Jiri
- * - Major cleanups (semaphore to mutex, endianess, no major reservation)
- * - Optimizations
- *
- * Version 2.1c
- * 30-October-2007 Frank Seidel
- * - Completed multicard support
- * - Minor cleanups
- *
- * Version 2.1b
- * 07-August-2007 Frank Seidel
- * - Minor cleanups
- * - theoretical multicard support
- *
- * Version 2.1
- * 03-July-2006 Paul Hardwick
- *
- * - Stability Improvements. Incorporated spinlock wraps patch.
- * - Updated for newer 2.6.14+ kernels (tty_buffer_request_room)
- * - using __devexit macro for tty
- *
- *
- * Version 2.0
- * 08-feb-2006 15:34:10:Ulf
- *
- * -Fixed issue when not waking up line disipine layer, could probably result
- *  in better uplink performance for 2.4.
- *
- * -Fixed issue with big endian during initalization, now proper toggle flags
- *  are handled between preloader and maincode.
- *
- * -Fixed flow control issue.
- *
- * -Added support for setting DTR.
- *
- * -For 2.4 kernels, removing temporary buffer that's not needed.
- *
- * -Reading CTS only for modem port (only port that supports it).
- *
- * -Return 0 in write_room instead of netative value, it's not handled in
- *  upper layer.
- *
- * --------------------------------------------------------------------------
- * Version 1.0
- *
- * First version of driver, only tested with card of type F32_2.
- * Works fine with 2.4 and 2.6 kernels.
- * Driver also support big endian architecture.
- */
-
 /* Enable this to have a lot of debug printouts */
 #define DEBUG
 
@@ -143,8 +89,9 @@ do {                                                         \
 /* Do we need this settable at runtime? */
 static int debug = NOZOMI_DEBUG_LEVEL;
 
-#define D(lvl, args...)  do {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
-                               while (0)
+#define D(lvl, args...)  do \
+                       {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
+                       while (0)
 #define D_(lvl, args...) D(lvl, ##args)
 
 /* These printouts are always printed */
@@ -273,13 +220,13 @@ enum port_type {
 /* Big endian */
 
 struct toggles {
-       unsigned enabled:5;     /*
+       unsigned int enabled:5; /*
                                 * Toggle fields are valid if enabled is 0,
                                 * else A-channels must always be used.
                                 */
-       unsigned diag_dl:1;
-       unsigned mdm_dl:1;
-       unsigned mdm_ul:1;
+       unsigned int diag_dl:1;
+       unsigned int mdm_dl:1;
+       unsigned int mdm_ul:1;
 } __attribute__ ((packed));
 
 /* Configuration table to read at startup of card */
@@ -320,19 +267,19 @@ struct config_table {
 /* This stores all control downlink flags */
 struct ctrl_dl {
        u8 port;
-       unsigned reserved:4;
-       unsigned CTS:1;
-       unsigned RI:1;
-       unsigned DCD:1;
-       unsigned DSR:1;
+       unsigned int reserved:4;
+       unsigned int CTS:1;
+       unsigned int RI:1;
+       unsigned int DCD:1;
+       unsigned int DSR:1;
 } __attribute__ ((packed));
 
 /* This stores all control uplink flags */
 struct ctrl_ul {
        u8 port;
-       unsigned reserved:6;
-       unsigned RTS:1;
-       unsigned DTR:1;
+       unsigned int reserved:6;
+       unsigned int RTS:1;
+       unsigned int DTR:1;
 } __attribute__ ((packed));
 
 #else
@@ -340,10 +287,10 @@ struct ctrl_ul {
 
 /* This represents the toggle information */
 struct toggles {
-       unsigned mdm_ul:1;
-       unsigned mdm_dl:1;
-       unsigned diag_dl:1;
-       unsigned enabled:5;     /*
+       unsigned int mdm_ul:1;
+       unsigned int mdm_dl:1;
+       unsigned int diag_dl:1;
+       unsigned int enabled:5; /*
                                 * Toggle fields are valid if enabled is 0,
                                 * else A-channels must always be used.
                                 */
@@ -379,19 +326,19 @@ struct config_table {
 
 /* This stores all control downlink flags */
 struct ctrl_dl {
-       unsigned DSR:1;
-       unsigned DCD:1;
-       unsigned RI:1;
-       unsigned CTS:1;
-       unsigned reserverd:4;
+       unsigned int DSR:1;
+       unsigned int DCD:1;
+       unsigned int RI:1;
+       unsigned int CTS:1;
+       unsigned int reserverd:4;
        u8 port;
 } __attribute__ ((packed));
 
 /* This stores all control uplink flags */
 struct ctrl_ul {
-       unsigned DTR:1;
-       unsigned RTS:1;
-       unsigned reserved:6;
+       unsigned int DTR:1;
+       unsigned int RTS:1;
+       unsigned int reserved:6;
        u8 port;
 } __attribute__ ((packed));
 #endif
@@ -448,7 +395,7 @@ struct buffer {
 } __attribute__ ((packed));
 
 /*    Global variables */
-static struct pci_device_id nozomi_pci_tbl[] = {
+static const struct pci_device_id nozomi_pci_tbl[] __devinitconst = {
        {PCI_DEVICE(VENDOR1, DEVICE1)},
        {},
 };
@@ -524,12 +471,12 @@ out:
  * -Optimize
  * -Rewrite cleaner
  */
-static u32 write_mem32(void __iomem *mem_addr_start, u32 *buf,
+static u32 write_mem32(void __iomem *mem_addr_start, const u32 *buf,
                        u32 size_bytes)
 {
        u32 i = 0;
        u32 *ptr = (__force u32 *) mem_addr_start;
-       u16 *buf16;
+       const u16 *buf16;
 
        if (unlikely(!ptr || !buf))
                return 0;
@@ -537,7 +484,7 @@ static u32 write_mem32(void __iomem *mem_addr_start, u32 *buf,
        /* shortcut for extremely often used cases */
        switch (size_bytes) {
        case 2: /* 2 bytes */
-               buf16 = (u16 *) buf;
+               buf16 = (const u16 *)buf;
                writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
                return 2;
                break;
@@ -554,7 +501,7 @@ static u32 write_mem32(void __iomem *mem_addr_start, u32 *buf,
        while (i < size_bytes) {
                if (size_bytes - i == 2) {
                        /* 2 bytes */
-                       buf16 = (u16 *) buf;
+                       buf16 = (const u16 *)buf;
                        writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
                        i += 2;
                } else {
@@ -694,7 +641,7 @@ static void dump_table(const struct nozomi *dc)
           dc->config_table.ul_ctrl_len);
 }
 #else
-static __inline__ void dump_table(const struct nozomi *dc) { }
+static inline void dump_table(const struct nozomi *dc) { }
 #endif
 
 /*
@@ -776,8 +723,7 @@ static int nozomi_read_config_table(struct nozomi *dc)
 /* Enable uplink interrupts  */
 static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
 {
-       u16 mask[NOZOMI_MAX_PORTS] = \
-                       {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL};
+       static const u16 mask[] = {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL};
 
        if (port < NOZOMI_MAX_PORTS) {
                dc->last_ier |= mask[port];
@@ -790,8 +736,8 @@ static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
 /* Disable uplink interrupts  */
 static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
 {
-       u16 mask[NOZOMI_MAX_PORTS] = \
-                       {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL};
+       static const u16 mask[] =
+               {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL};
 
        if (port < NOZOMI_MAX_PORTS) {
                dc->last_ier &= mask[port];
@@ -804,8 +750,7 @@ static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
 /* Enable downlink interrupts */
 static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
 {
-       u16 mask[NOZOMI_MAX_PORTS] = \
-                       {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL};
+       static const u16 mask[] = {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL};
 
        if (port < NOZOMI_MAX_PORTS) {
                dc->last_ier |= mask[port];
@@ -818,8 +763,8 @@ static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
 /* Disable downlink interrupts */
 static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
 {
-       u16 mask[NOZOMI_MAX_PORTS] = \
-                       {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL};
+       static const u16 mask[] =
+               {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL};
 
        if (port < NOZOMI_MAX_PORTS) {
                dc->last_ier &= mask[port];
@@ -833,13 +778,13 @@ static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
  * Return 1 - send buffer to card and ack.
  * Return 0 - don't ack, don't send buffer to card.
  */
-static int send_data(enum port_type index, struct nozomi *dc)
+static int send_data(enum port_type index, const struct nozomi *dc)
 {
        u32 size = 0;
-       struct port *port = &dc->port[index];
-       u8 toggle = port->toggle_ul;
+       const struct port *port = &dc->port[index];
+       const u8 toggle = port->toggle_ul;
        void __iomem *addr = port->ul_addr[toggle];
-       u32 ul_size = port->ul_size[toggle];
+       const u32 ul_size = port->ul_size[toggle];
        struct tty_struct *tty = port->tty;
 
        /* Get data from tty and place in buf for now */
@@ -1102,7 +1047,7 @@ static int send_flow_control(struct nozomi *dc)
 }
 
 /*
- * Handle donlink data, ports that are handled are modem and diagnostics
+ * Handle downlink data, ports that are handled are modem and diagnostics
  * Return 1 - ok
  * Return 0 - toggle fields are out of sync
  */
@@ -1359,20 +1304,20 @@ static void nozomi_setup_private_data(struct nozomi *dc)
 static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
                          char *buf)
 {
-       struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
+       const struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
 
        return sprintf(buf, "%d\n", dc->card_type);
 }
-static DEVICE_ATTR(card_type, 0444, card_type_show, NULL);
+static DEVICE_ATTR(card_type, S_IRUGO, card_type_show, NULL);
 
 static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
                          char *buf)
 {
-       struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
+       const struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
 
        return sprintf(buf, "%u\n", dc->open_ttys);
 }
-static DEVICE_ATTR(open_ttys, 0444, open_ttys_show, NULL);
+static DEVICE_ATTR(open_ttys, S_IRUGO, open_ttys_show, NULL);
 
 static void make_sysfs_files(struct nozomi *dc)
 {
@@ -1735,7 +1680,7 @@ static int ntty_write_room(struct tty_struct *tty)
 {
        struct port *port = tty->driver_data;
        int room = 0;
-       struct nozomi *dc = get_dc_by_tty(tty);
+       const struct nozomi *dc = get_dc_by_tty(tty);
 
        if (!dc || !port)
                return 0;
@@ -1755,9 +1700,9 @@ exit:
 /* Gets io control parameters */
 static int ntty_tiocmget(struct tty_struct *tty, struct file *file)
 {
-       struct port *port = tty->driver_data;
-       struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
-       struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
+       const struct port *port = tty->driver_data;
+       const struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
+       const struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
 
        return  (ctrl_ul->RTS ? TIOCM_RTS : 0) |
                (ctrl_ul->DTR ? TIOCM_DTR : 0) |
@@ -1787,7 +1732,7 @@ static int ntty_tiocmset(struct tty_struct *tty, struct file *file,
 static int ntty_cflags_changed(struct port *port, unsigned long flags,
                struct async_icount *cprev)
 {
-       struct async_icount cnow = port->tty_icount;
+       const struct async_icount cnow = port->tty_icount;
        int ret;
 
        ret =   ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
@@ -1802,7 +1747,7 @@ static int ntty_cflags_changed(struct port *port, unsigned long flags,
 
 static int ntty_ioctl_tiocgicount(struct port *port, void __user *argp)
 {
-       struct async_icount cnow = port->tty_icount;
+       const struct async_icount cnow = port->tty_icount;
        struct serial_icounter_struct icount;
 
        icount.cts = cnow.cts;
@@ -1882,7 +1827,10 @@ static void ntty_throttle(struct tty_struct *tty)
 /* just to discard single character writes */
 static void ntty_put_char(struct tty_struct *tty, unsigned char c)
 {
-       /* FIXME !!! */
+       /*
+        * card does not react correct when we write single chars
+        * to the card, so we discard them
+        */
        DBG2("PUT CHAR Function: %c", c);
 }
 
@@ -1910,7 +1858,7 @@ exit_in_buffer:
        return rval;
 }
 
-static struct tty_operations tty_ops = {
+static const struct tty_operations tty_ops = {
        .ioctl = ntty_ioctl,
        .open = ntty_open,
        .close = ntty_close,
index 02518da6a386a934ef7c3af885c4630e3c46741f..454d7324ba40b19ef3ce1396b3f09dfb0aeaff9e 100644 (file)
@@ -308,7 +308,8 @@ static unsigned int calc_baudv(unsigned char fidi)
        return (wcrcf / wbrcf);
 }
 
-static unsigned short io_read_num_rec_bytes(ioaddr_t iobase, unsigned short *s)
+static unsigned short io_read_num_rec_bytes(unsigned int iobase,
+                                           unsigned short *s)
 {
        unsigned short tmp;
 
@@ -426,7 +427,7 @@ static struct card_fixup card_fixups[] = {
 static void set_cardparameter(struct cm4000_dev *dev)
 {
        int i;
-       ioaddr_t iobase = dev->p_dev->io.BasePort1;
+       unsigned int iobase = dev->p_dev->io.BasePort1;
        u_int8_t stopbits = 0x02; /* ISO default */
 
        DEBUGP(3, dev, "-> set_cardparameter\n");
@@ -459,7 +460,7 @@ static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
        unsigned short num_bytes_read;
        unsigned char pts_reply[4];
        ssize_t rc;
-       ioaddr_t iobase = dev->p_dev->io.BasePort1;
+       unsigned int iobase = dev->p_dev->io.BasePort1;
 
        rc = 0;
 
@@ -610,7 +611,7 @@ exit_setprotocol:
        return rc;
 }
 
-static int io_detect_cm4000(ioaddr_t iobase, struct cm4000_dev *dev)
+static int io_detect_cm4000(unsigned int iobase, struct cm4000_dev *dev)
 {
 
        /* note: statemachine is assumed to be reset */
@@ -671,7 +672,7 @@ static void terminate_monitor(struct cm4000_dev *dev)
 static void monitor_card(unsigned long p)
 {
        struct cm4000_dev *dev = (struct cm4000_dev *) p;
-       ioaddr_t iobase = dev->p_dev->io.BasePort1;
+       unsigned int iobase = dev->p_dev->io.BasePort1;
        unsigned short s;
        struct ptsreq ptsreq;
        int i, atrc;
@@ -933,7 +934,7 @@ static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
                        loff_t *ppos)
 {
        struct cm4000_dev *dev = filp->private_data;
-       ioaddr_t iobase = dev->p_dev->io.BasePort1;
+       unsigned int iobase = dev->p_dev->io.BasePort1;
        ssize_t rc;
        int i, j, k;
 
@@ -1054,7 +1055,7 @@ static ssize_t cmm_write(struct file *filp, const char __user *buf,
                         size_t count, loff_t *ppos)
 {
        struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data;
-       ioaddr_t iobase = dev->p_dev->io.BasePort1;
+       unsigned int iobase = dev->p_dev->io.BasePort1;
        unsigned short s;
        unsigned char tmp;
        unsigned char infolen;
@@ -1408,7 +1409,7 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                     unsigned long arg)
 {
        struct cm4000_dev *dev = filp->private_data;
-       ioaddr_t iobase = dev->p_dev->io.BasePort1;
+       unsigned int iobase = dev->p_dev->io.BasePort1;
        struct pcmcia_device *link;
        int size;
        int rc;
index 8caff0ca80ffad53eab22ef4db7bd014698cedca..279ff5005cec0890e18a6292788c11fcb9299057 100644 (file)
@@ -57,6 +57,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/ioctl.h>
+#include <linux/synclink.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
@@ -87,8 +88,6 @@
 
 #include <asm/uaccess.h>
 
-#include "linux/synclink.h"
-
 static MGSL_PARAMS default_params = {
        MGSL_MODE_HDLC,                 /* unsigned long mode */
        0,                              /* unsigned char loopback; */
index c511a831f0c053e60220d39c1f45b94ee3a93cb7..f43c89f7c449831b2441f5f8f55441f2253a65ce 100644 (file)
@@ -1039,6 +1039,7 @@ write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
                p += bytes;
 
                add_entropy_words(r, buf, (bytes + 3) / 4);
+               cond_resched();
        }
 
        return 0;
index 102ece4c4e0e8050efe26b36745db83e45069e4b..d130b87d8ed793186e63e13dbb7fc139378076b7 100644 (file)
@@ -47,6 +47,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/tty_flip.h>
+#include <linux/spinlock.h>
 
 #include <asm/uaccess.h>
 
@@ -81,6 +82,8 @@
 
 static struct tty_driver *riscom_driver;
 
+static DEFINE_SPINLOCK(riscom_lock);
+
 static struct riscom_board rc_board[RC_NBOARD] =  {
        {
                .base   = RC_IOBASE1,
@@ -217,13 +220,14 @@ static void __init rc_init_CD180(struct riscom_board const * bp)
 {
        unsigned long flags;
        
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        rc_out(bp, RC_CTOUT, 0);                   /* Clear timeout             */
        rc_wait_CCR(bp);                           /* Wait for CCR ready        */
        rc_out(bp, CD180_CCR, CCR_HARDRESET);      /* Reset CD180 chip          */
-       sti();
+       spin_unlock_irqrestore(&riscom_lock, flags);
        msleep(50);                                /* Delay 0.05 sec            */
-       cli();
+       spin_lock_irqsave(&riscom_lock, flags);
        rc_out(bp, CD180_GIVR, RC_ID);             /* Set ID for this chip      */
        rc_out(bp, CD180_GICR, 0);                 /* Clear all bits            */
        rc_out(bp, CD180_PILR1, RC_ACK_MINT);      /* Prio for modem intr       */
@@ -234,7 +238,7 @@ static void __init rc_init_CD180(struct riscom_board const * bp)
        rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
        rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
        
-       restore_flags(flags);
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 /* Main probing routine, also sets irq. */
@@ -812,9 +816,9 @@ static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
                }
                port->xmit_buf = (unsigned char *) tmp;
        }
-               
-       save_flags(flags); cli();
-               
+
+       spin_lock_irqsave(&riscom_lock, flags);
+
        if (port->tty) 
                clear_bit(TTY_IO_ERROR, &port->tty->flags);
                
@@ -825,7 +829,7 @@ static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
        rc_change_speed(bp, port);
        port->flags |= ASYNC_INITIALIZED;
                
-       restore_flags(flags);
+       spin_unlock_irqrestore(&riscom_lock, flags);
        return 0;
 }
 
@@ -901,6 +905,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
        int    retval;
        int    do_clocal = 0;
        int    CD;
+       unsigned long flags;
 
        /*
         * If the device is in the middle of being closed, then block
@@ -936,19 +941,26 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
         */
        retval = 0;
        add_wait_queue(&port->open_wait, &wait);
-       cli();
+
+       spin_lock_irqsave(&riscom_lock, flags);
+
        if (!tty_hung_up_p(filp))
                port->count--;
-       sti();
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
+
        port->blocked_open++;
        while (1) {
-               cli();
+               spin_lock_irqsave(&riscom_lock, flags);
+
                rc_out(bp, CD180_CAR, port_No(port));
                CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
                rc_out(bp, CD180_MSVR, MSVR_RTS);
                bp->DTR &= ~(1u << port_No(port));
                rc_out(bp, RC_DTR, bp->DTR);
-               sti();
+
+               spin_unlock_irqrestore(&riscom_lock, flags);
+
                set_current_state(TASK_INTERRUPTIBLE);
                if (tty_hung_up_p(filp) ||
                    !(port->flags & ASYNC_INITIALIZED)) {
@@ -1020,8 +1032,9 @@ static void rc_close(struct tty_struct * tty, struct file * filp)
        
        if (!port || rc_paranoia_check(port, tty->name, "close"))
                return;
-       
-       save_flags(flags); cli();
+
+       spin_lock_irqsave(&riscom_lock, flags);
+
        if (tty_hung_up_p(filp))
                goto out;
        
@@ -1088,7 +1101,9 @@ static void rc_close(struct tty_struct * tty, struct file * filp)
        }
        port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
        wake_up_interruptible(&port->close_wait);
-out:   restore_flags(flags);
+
+out:
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 static int rc_write(struct tty_struct * tty, 
@@ -1107,34 +1122,33 @@ static int rc_write(struct tty_struct * tty,
        if (!tty || !port->xmit_buf)
                return 0;
 
-       save_flags(flags);
        while (1) {
-               cli();          
+               spin_lock_irqsave(&riscom_lock, flags);
+
                c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
                                          SERIAL_XMIT_SIZE - port->xmit_head));
-               if (c <= 0) {
-                       restore_flags(flags);
-                       break;
-               }
+               if (c <= 0)
+                       break;  /* lock continues to be held */
 
                memcpy(port->xmit_buf + port->xmit_head, buf, c);
                port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
                port->xmit_cnt += c;
-               restore_flags(flags);
+
+               spin_unlock_irqrestore(&riscom_lock, flags);
 
                buf += c;
                count -= c;
                total += c;
        }
 
-       cli();
        if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
            !(port->IER & IER_TXRDY)) {
                port->IER |= IER_TXRDY;
                rc_out(bp, CD180_CAR, port_No(port));
                rc_out(bp, CD180_IER, port->IER);
        }
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 
        return total;
 }
@@ -1150,7 +1164,7 @@ static void rc_put_char(struct tty_struct * tty, unsigned char ch)
        if (!tty || !port->xmit_buf)
                return;
 
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
        
        if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
                goto out;
@@ -1158,7 +1172,9 @@ static void rc_put_char(struct tty_struct * tty, unsigned char ch)
        port->xmit_buf[port->xmit_head++] = ch;
        port->xmit_head &= SERIAL_XMIT_SIZE - 1;
        port->xmit_cnt++;
-out:   restore_flags(flags);
+
+out:
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 static void rc_flush_chars(struct tty_struct * tty)
@@ -1173,11 +1189,13 @@ static void rc_flush_chars(struct tty_struct * tty)
            !port->xmit_buf)
                return;
 
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        port->IER |= IER_TXRDY;
        rc_out(port_Board(port), CD180_CAR, port_No(port));
        rc_out(port_Board(port), CD180_IER, port->IER);
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 static int rc_write_room(struct tty_struct * tty)
@@ -1212,9 +1230,11 @@ static void rc_flush_buffer(struct tty_struct *tty)
        if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
                return;
 
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
        
        tty_wakeup(tty);
 }
@@ -1231,11 +1251,15 @@ static int rc_tiocmget(struct tty_struct *tty, struct file *file)
                return -ENODEV;
 
        bp = port_Board(port);
-       save_flags(flags); cli();
+
+       spin_lock_irqsave(&riscom_lock, flags);
+
        rc_out(bp, CD180_CAR, port_No(port));
        status = rc_in(bp, CD180_MSVR);
        result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
+
        result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
                | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
                | ((status & MSVR_CD)  ? TIOCM_CAR : 0)
@@ -1256,7 +1280,8 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
 
        bp = port_Board(port);
 
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        if (set & TIOCM_RTS)
                port->MSVR |= MSVR_RTS;
        if (set & TIOCM_DTR)
@@ -1270,7 +1295,9 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
        rc_out(bp, CD180_CAR, port_No(port));
        rc_out(bp, CD180_MSVR, port->MSVR);
        rc_out(bp, RC_DTR, bp->DTR);
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
+
        return 0;
 }
 
@@ -1279,7 +1306,8 @@ static inline void rc_send_break(struct riscom_port * port, unsigned long length
        struct riscom_board *bp = port_Board(port);
        unsigned long flags;
        
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        port->break_length = RISCOM_TPS / HZ * length;
        port->COR2 |= COR2_ETC;
        port->IER  |= IER_TXRDY;
@@ -1289,7 +1317,8 @@ static inline void rc_send_break(struct riscom_port * port, unsigned long length
        rc_wait_CCR(bp);
        rc_out(bp, CD180_CCR, CCR_CORCHG2);
        rc_wait_CCR(bp);
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 static inline int rc_set_serial_info(struct riscom_port * port,
@@ -1298,7 +1327,6 @@ static inline int rc_set_serial_info(struct riscom_port * port,
        struct serial_struct tmp;
        struct riscom_board *bp = port_Board(port);
        int change_speed;
-       unsigned long flags;
        
        if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
                return -EFAULT;
@@ -1332,9 +1360,11 @@ static inline int rc_set_serial_info(struct riscom_port * port,
                port->closing_wait = tmp.closing_wait;
        }
        if (change_speed)  {
-               save_flags(flags); cli();
+               unsigned long flags;
+
+               spin_lock_irqsave(&riscom_lock, flags);
                rc_change_speed(bp, port);
-               restore_flags(flags);
+               spin_unlock_irqrestore(&riscom_lock, flags);
        }
        return 0;
 }
@@ -1414,17 +1444,19 @@ static void rc_throttle(struct tty_struct * tty)
                return;
        
        bp = port_Board(port);
-       
-       save_flags(flags); cli();
+
+       spin_lock_irqsave(&riscom_lock, flags);
+
        port->MSVR &= ~MSVR_RTS;
        rc_out(bp, CD180_CAR, port_No(port));
-       if (I_IXOFF(tty))  {
+       if (I_IXOFF(tty)) {
                rc_wait_CCR(bp);
                rc_out(bp, CD180_CCR, CCR_SSCH2);
                rc_wait_CCR(bp);
        }
        rc_out(bp, CD180_MSVR, port->MSVR);
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 static void rc_unthrottle(struct tty_struct * tty)
@@ -1438,7 +1470,8 @@ static void rc_unthrottle(struct tty_struct * tty)
        
        bp = port_Board(port);
        
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        port->MSVR |= MSVR_RTS;
        rc_out(bp, CD180_CAR, port_No(port));
        if (I_IXOFF(tty))  {
@@ -1447,7 +1480,8 @@ static void rc_unthrottle(struct tty_struct * tty)
                rc_wait_CCR(bp);
        }
        rc_out(bp, CD180_MSVR, port->MSVR);
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 static void rc_stop(struct tty_struct * tty)
@@ -1461,11 +1495,13 @@ static void rc_stop(struct tty_struct * tty)
        
        bp = port_Board(port);
        
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        port->IER &= ~IER_TXRDY;
        rc_out(bp, CD180_CAR, port_No(port));
        rc_out(bp, CD180_IER, port->IER);
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 static void rc_start(struct tty_struct * tty)
@@ -1479,13 +1515,15 @@ static void rc_start(struct tty_struct * tty)
        
        bp = port_Board(port);
        
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY))  {
                port->IER |= IER_TXRDY;
                rc_out(bp, CD180_CAR, port_No(port));
                rc_out(bp, CD180_IER, port->IER);
        }
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 /*
@@ -1537,9 +1575,9 @@ static void rc_set_termios(struct tty_struct * tty, struct ktermios * old_termio
            tty->termios->c_iflag == old_termios->c_iflag)
                return;
 
-       save_flags(flags); cli();
+       spin_lock_irqsave(&riscom_lock, flags);
        rc_change_speed(port_Board(port), port);
-       restore_flags(flags);
+       spin_unlock_irqrestore(&riscom_lock, flags);
 
        if ((old_termios->c_cflag & CRTSCTS) &&
            !(tty->termios->c_cflag & CRTSCTS)) {
@@ -1627,11 +1665,12 @@ static void rc_release_drivers(void)
 {
        unsigned long flags;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&riscom_lock, flags);
+
        tty_unregister_driver(riscom_driver);
        put_tty_driver(riscom_driver);
-       restore_flags(flags);
+
+       spin_unlock_irqrestore(&riscom_lock, flags);
 }
 
 #ifndef MODULE
index 3c869145bfdcb1169ab41c4a49633051212ab964..4ba3aec9e1cd0dc50444c05857467ade96a0fc4e 100644 (file)
@@ -653,7 +653,7 @@ static void a2232_init_portstructs(void)
                port->gs.closing_wait = 30 * HZ;
                port->gs.rd = &a2232_real_driver;
 #ifdef NEW_WRITE_LOCKING
-               init_MUTEX(&(port->gs.port_write_mutex));
+               mutex_init(&(port->gs.port_write_mutex));
 #endif
                init_waitqueue_head(&port->gs.open_wait);
                init_waitqueue_head(&port->gs.close_wait);
index 905d1f51a7bfd7db75f90b9de128f13fd5142ac8..ddc74d1f4f1beb3922c39fa4809a428529a74615 100644 (file)
@@ -85,6 +85,7 @@
 #include <linux/vmalloc.h>
 #include <linux/init.h>
 #include <linux/ioctl.h>
+#include <linux/synclink.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
 
 #include <asm/uaccess.h>
 
-#include "linux/synclink.h"
-
 #define RCLRVALUE 0xffff
 
 static MGSL_PARAMS default_params = {
@@ -1544,7 +1543,7 @@ static void mgsl_isr_receive_data( struct mgsl_struct *info )
 
 /* mgsl_isr_misc()
  * 
- *     Service a miscellaneos interrupt source.
+ *     Service a miscellaneous interrupt source.
  *     
  * Arguments:          info            pointer to device extension (instance data)
  * Return Value:       None
index 64e835f62438d3bb6b629224355403c14681927a..1f954acf2bac49125be4b18f0167eb437ec0cbe0 100644 (file)
@@ -73,6 +73,7 @@
 #include <linux/bitops.h>
 #include <linux/workqueue.h>
 #include <linux/hdlc.h>
+#include <linux/synclink.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
@@ -81,8 +82,6 @@
 #include <asm/types.h>
 #include <asm/uaccess.h>
 
-#include "linux/synclink.h"
-
 #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE))
 #define SYNCLINK_GENERIC_HDLC 1
 #else
@@ -2040,37 +2039,41 @@ static void bh_transmit(struct slgt_info *info)
                tty_wakeup(tty);
 }
 
-static void dsr_change(struct slgt_info *info)
+static void dsr_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT3) {
+               info->signals |= SerialSignal_DSR;
+               info->input_signal_events.dsr_up++;
+       } else {
+               info->signals &= ~SerialSignal_DSR;
+               info->input_signal_events.dsr_down++;
+       }
        DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_DSR);
                return;
        }
        info->icount.dsr++;
-       if (info->signals & SerialSignal_DSR)
-               info->input_signal_events.dsr_up++;
-       else
-               info->input_signal_events.dsr_down++;
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
        info->pending_bh |= BH_STATUS;
 }
 
-static void cts_change(struct slgt_info *info)
+static void cts_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT2) {
+               info->signals |= SerialSignal_CTS;
+               info->input_signal_events.cts_up++;
+       } else {
+               info->signals &= ~SerialSignal_CTS;
+               info->input_signal_events.cts_down++;
+       }
        DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_CTS);
                return;
        }
        info->icount.cts++;
-       if (info->signals & SerialSignal_CTS)
-               info->input_signal_events.cts_up++;
-       else
-               info->input_signal_events.cts_down++;
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
        info->pending_bh |= BH_STATUS;
@@ -2091,20 +2094,21 @@ static void cts_change(struct slgt_info *info)
        }
 }
 
-static void dcd_change(struct slgt_info *info)
+static void dcd_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT1) {
+               info->signals |= SerialSignal_DCD;
+               info->input_signal_events.dcd_up++;
+       } else {
+               info->signals &= ~SerialSignal_DCD;
+               info->input_signal_events.dcd_down++;
+       }
        DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_DCD);
                return;
        }
        info->icount.dcd++;
-       if (info->signals & SerialSignal_DCD) {
-               info->input_signal_events.dcd_up++;
-       } else {
-               info->input_signal_events.dcd_down++;
-       }
 #if SYNCLINK_GENERIC_HDLC
        if (info->netcount) {
                if (info->signals & SerialSignal_DCD)
@@ -2127,20 +2131,21 @@ static void dcd_change(struct slgt_info *info)
        }
 }
 
-static void ri_change(struct slgt_info *info)
+static void ri_change(struct slgt_info *info, unsigned short status)
 {
-       get_signals(info);
+       if (status & BIT0) {
+               info->signals |= SerialSignal_RI;
+               info->input_signal_events.ri_up++;
+       } else {
+               info->signals &= ~SerialSignal_RI;
+               info->input_signal_events.ri_down++;
+       }
        DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals));
        if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
                slgt_irq_off(info, IRQ_RI);
                return;
        }
-       info->icount.dcd++;
-       if (info->signals & SerialSignal_RI) {
-               info->input_signal_events.ri_up++;
-       } else {
-               info->input_signal_events.ri_down++;
-       }
+       info->icount.rng++;
        wake_up_interruptible(&info->status_event_wait_q);
        wake_up_interruptible(&info->event_wait_q);
        info->pending_bh |= BH_STATUS;
@@ -2191,13 +2196,13 @@ static void isr_serial(struct slgt_info *info)
        }
 
        if (status & IRQ_DSR)
-               dsr_change(info);
+               dsr_change(info, status);
        if (status & IRQ_CTS)
-               cts_change(info);
+               cts_change(info, status);
        if (status & IRQ_DCD)
-               dcd_change(info);
+               dcd_change(info, status);
        if (status & IRQ_RI)
-               ri_change(info);
+               ri_change(info, status);
 }
 
 static void isr_rdma(struct slgt_info *info)
index c63013b2fc366487a781b925e7738175e7ccee7a..f3e7807f78d98781d903ea8075a970e18c881033 100644 (file)
@@ -66,6 +66,7 @@
 #include <linux/termios.h>
 #include <linux/workqueue.h>
 #include <linux/hdlc.h>
+#include <linux/synclink.h>
 
 #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINKMP_MODULE))
 #define SYNCLINK_GENERIC_HDLC 1
@@ -80,8 +81,6 @@
 
 #include <asm/uaccess.h>
 
-#include "linux/synclink.h"
-
 static MGSL_PARAMS default_params = {
        MGSL_MODE_HDLC,                 /* unsigned long mode */
        0,                              /* unsigned char loopback; */
index 5422f999636fffff6e499a9b7242d52f9e733fa9..ce5ebe3b168ffe0cb59f83484370a2bf6d957602 100644 (file)
@@ -505,7 +505,7 @@ static int __init toshiba_init(void)
        if (tosh_probe())
                return -ENODEV;
 
-       printk(KERN_INFO "Toshiba System Managment Mode driver v" TOSH_VERSION "\n");
+       printk(KERN_INFO "Toshiba System Management Mode driver v" TOSH_VERSION "\n");
 
        /* set the port to use for Fn status if not specified as a parameter */
        if (tosh_fn==0x00)
index c88424a0c89b60d28d3805895e6ee973710b7d8c..a5d8bcb40000df912d43cb9ad4a8cc9c7453642c 100644 (file)
@@ -1031,18 +1031,13 @@ void tpm_remove_hardware(struct device *dev)
 
        spin_unlock(&driver_lock);
 
-       dev_set_drvdata(dev, NULL);
        misc_deregister(&chip->vendor.miscdev);
-       kfree(chip->vendor.miscdev.name);
 
        sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
        tpm_bios_log_teardown(chip->bios_dir);
 
-       clear_bit(chip->dev_num, dev_mask);
-
-       kfree(chip);
-
-       put_device(dev);
+       /* write it this way to be explicit (chip->dev == dev) */
+       put_device(chip->dev);
 }
 EXPORT_SYMBOL_GPL(tpm_remove_hardware);
 
@@ -1082,6 +1077,26 @@ int tpm_pm_resume(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
 
+/*
+ * Once all references to platform device are down to 0,
+ * release all allocated structures.
+ * In case vendor provided release function,
+ * call it too.
+ */
+static void tpm_dev_release(struct device *dev)
+{
+       struct tpm_chip *chip = dev_get_drvdata(dev);
+
+       if (chip->vendor.release)
+               chip->vendor.release(dev);
+
+       chip->release(dev);
+
+       clear_bit(chip->dev_num, dev_mask);
+       kfree(chip->vendor.miscdev.name);
+       kfree(chip);
+}
+
 /*
  * Called from tpm_<specific>.c probe function only for devices 
  * the driver has determined it should claim.  Prior to calling
@@ -1136,23 +1151,21 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
 
        chip->vendor.miscdev.parent = dev;
        chip->dev = get_device(dev);
+       chip->release = dev->release;
+       dev->release = tpm_dev_release;
+       dev_set_drvdata(dev, chip);
 
        if (misc_register(&chip->vendor.miscdev)) {
                dev_err(chip->dev,
                        "unable to misc_register %s, minor %d\n",
                        chip->vendor.miscdev.name,
                        chip->vendor.miscdev.minor);
-               put_device(dev);
-               clear_bit(chip->dev_num, dev_mask);
-               kfree(chip);
-               kfree(devname);
+               put_device(chip->dev);
                return NULL;
        }
 
        spin_lock(&driver_lock);
 
-       dev_set_drvdata(dev, chip);
-
        list_add(&chip->list, &tpm_chip_list);
 
        spin_unlock(&driver_lock);
@@ -1160,10 +1173,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
        if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) {
                list_del(&chip->list);
                misc_deregister(&chip->vendor.miscdev);
-               put_device(dev);
-               clear_bit(chip->dev_num, dev_mask);
-               kfree(chip);
-               kfree(devname);
+               put_device(chip->dev);
                return NULL;
        }
 
index d15ccddc92ebc6080762cb3c22d019d7f16c923a..e885148b4cfbd0b177f77b87e6e629511db16983 100644 (file)
@@ -74,6 +74,7 @@ struct tpm_vendor_specific {
        int (*send) (struct tpm_chip *, u8 *, size_t);
        void (*cancel) (struct tpm_chip *);
        u8 (*status) (struct tpm_chip *);
+       void (*release) (struct device *);
        struct miscdevice miscdev;
        struct attribute_group *attr_group;
        struct list_head list;
@@ -106,6 +107,7 @@ struct tpm_chip {
        struct dentry **bios_dir;
 
        struct list_head list;
+       void (*release) (struct device *);
 };
 
 #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
index 967002a5a1e56dae86010e8af334a2b814fe9a4c..726ee8a0277fe6fbefebd58e93c28da5713d9f9a 100644 (file)
@@ -611,7 +611,7 @@ static __devexit void tpm_inf_pnp_remove(struct pnp_dev *dev)
        }
 }
 
-static struct pnp_driver tpm_inf_pnp = {
+static struct pnp_driver tpm_inf_pnp_driver = {
        .name = "tpm_inf_pnp",
        .driver = {
                .owner = THIS_MODULE,
@@ -625,12 +625,12 @@ static struct pnp_driver tpm_inf_pnp = {
 
 static int __init init_inf(void)
 {
-       return pnp_register_driver(&tpm_inf_pnp);
+       return pnp_register_driver(&tpm_inf_pnp_driver);
 }
 
 static void __exit cleanup_inf(void)
 {
-       pnp_unregister_driver(&tpm_inf_pnp);
+       pnp_unregister_driver(&tpm_inf_pnp_driver);
 }
 
 module_init(init_inf);
index f36fecd3fd264a67cf7d66b2fd8e74369a38f406..79c86c47947f4da921051be399b028f176f18ad9 100644 (file)
@@ -138,7 +138,7 @@ EXPORT_SYMBOL(tty_mutex);
 extern struct tty_driver *ptm_driver;  /* Unix98 pty masters; for /dev/ptmx */
 extern int pty_limit;          /* Config limit on Unix98 ptys */
 static DEFINE_IDR(allocated_ptys);
-static DECLARE_MUTEX(allocated_ptys_lock);
+static DEFINE_MUTEX(allocated_ptys_lock);
 static int ptmx_open(struct inode *, struct file *);
 #endif
 
@@ -2571,9 +2571,9 @@ static void release_dev(struct file * filp)
 #ifdef CONFIG_UNIX98_PTYS
        /* Make this pty number available for reallocation */
        if (devpts) {
-               down(&allocated_ptys_lock);
+               mutex_lock(&allocated_ptys_lock);
                idr_remove(&allocated_ptys, idx);
-               up(&allocated_ptys_lock);
+               mutex_unlock(&allocated_ptys_lock);
        }
 #endif
 
@@ -2737,24 +2737,24 @@ static int ptmx_open(struct inode * inode, struct file * filp)
        nonseekable_open(inode, filp);
 
        /* find a device that is not in use. */
-       down(&allocated_ptys_lock);
+       mutex_lock(&allocated_ptys_lock);
        if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) {
-               up(&allocated_ptys_lock);
+               mutex_unlock(&allocated_ptys_lock);
                return -ENOMEM;
        }
        idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
        if (idr_ret < 0) {
-               up(&allocated_ptys_lock);
+               mutex_unlock(&allocated_ptys_lock);
                if (idr_ret == -EAGAIN)
                        return -ENOMEM;
                return -EIO;
        }
        if (index >= pty_limit) {
                idr_remove(&allocated_ptys, index);
-               up(&allocated_ptys_lock);
+               mutex_unlock(&allocated_ptys_lock);
                return -EIO;
        }
-       up(&allocated_ptys_lock);
+       mutex_unlock(&allocated_ptys_lock);
 
        mutex_lock(&tty_mutex);
        retval = init_dev(ptm_driver, index, &tty);
@@ -2781,9 +2781,9 @@ out1:
        release_dev(filp);
        return retval;
 out:
-       down(&allocated_ptys_lock);
+       mutex_lock(&allocated_ptys_lock);
        idr_remove(&allocated_ptys, index);
-       up(&allocated_ptys_lock);
+       mutex_unlock(&allocated_ptys_lock);
        return retval;
 }
 #endif
@@ -3721,7 +3721,6 @@ static void initialize_tty_struct(struct tty_struct *tty)
        tty->buf.head = tty->buf.tail = NULL;
        tty_buffer_init(tty);
        INIT_DELAYED_WORK(&tty->buf.work, flush_to_ldisc);
-       init_MUTEX(&tty->buf.pty_sem);
        mutex_init(&tty->termios_mutex);
        init_waitqueue_head(&tty->write_wait);
        init_waitqueue_head(&tty->read_wait);
@@ -4048,10 +4047,6 @@ void __init console_init(void)
        }
 }
 
-#ifdef CONFIG_VT
-extern int vty_init(void);
-#endif
-
 static int __init tty_class_init(void)
 {
        tty_class = class_create(THIS_MODULE, "tty");
index e34da5c971966fc87d68b40588ea4f22e3f94189..dc17fe3a88bc48f2813ad5c3e5dd27efd00ff7d3 100644 (file)
@@ -158,13 +158,13 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
        /* Find the input queue. */
        /* FIXME: This is why we want to wean off hvc: we do nothing
         * when input comes in. */
-       in_vq = vdev->config->find_vq(vdev, NULL);
+       in_vq = vdev->config->find_vq(vdev, 0, NULL);
        if (IS_ERR(in_vq)) {
                err = PTR_ERR(in_vq);
                goto free;
        }
 
-       out_vq = vdev->config->find_vq(vdev, NULL);
+       out_vq = vdev->config->find_vq(vdev, 1, NULL);
        if (IS_ERR(out_vq)) {
                err = PTR_ERR(out_vq);
                goto free_in_vq;
index 7a5badfb7d846e00d85dbbd2c082461264b7a660..367be917506117b08d2407b7f74beb55432701d4 100644 (file)
@@ -2400,13 +2400,15 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
 {
        struct vc_data *vc = vc_cons[fg_console].d;
        unsigned char c;
-       static unsigned long printing;
+       static DEFINE_SPINLOCK(printing_lock);
        const ushort *start;
        ushort cnt = 0;
        ushort myx;
 
        /* console busy or not yet initialized */
-       if (!printable || test_and_set_bit(0, &printing))
+       if (!printable)
+               return;
+       if (!spin_trylock(&printing_lock))
                return;
 
        if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1))
@@ -2481,7 +2483,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
        notify_update(vc);
 
 quit:
-       clear_bit(0, &printing);
+       spin_unlock(&printing_lock);
 }
 
 static struct tty_driver *vt_console_device(struct console *c, int *index)
index d2fabe7863a96345e096f5a644c111436a492819..2a98d99cbd46075707c15572dff6ace4e6c602c3 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/mutex.h>
 #include <linux/sched.h>
 #include <linux/notifier.h>
-#include <linux/latency.h>
+#include <linux/pm_qos_params.h>
 #include <linux/cpu.h>
 #include <linux/cpuidle.h>
 
@@ -265,7 +265,10 @@ static struct notifier_block cpuidle_latency_notifier = {
        .notifier_call = cpuidle_latency_notify,
 };
 
-#define latency_notifier_init(x) do { register_latency_notifier(x); } while (0)
+static inline void latency_notifier_init(struct notifier_block *n)
+{
+       pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY, n);
+}
 
 #else /* CONFIG_SMP */
 
index eb666ecae7c913a769529a9b0debef857947103d..ba7b9a6b17a13678896bd1390b1d4823504b641a 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <linux/kernel.h>
 #include <linux/cpuidle.h>
-#include <linux/latency.h>
+#include <linux/pm_qos_params.h>
 #include <linux/moduleparam.h>
 #include <linux/jiffies.h>
 
@@ -81,7 +81,8 @@ static int ladder_select_state(struct cpuidle_device *dev)
        /* consider promotion */
        if (last_idx < dev->state_count - 1 &&
            last_residency > last_state->threshold.promotion_time &&
-           dev->states[last_idx + 1].exit_latency <= system_latency_constraint()) {
+           dev->states[last_idx + 1].exit_latency <=
+                       pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) {
                last_state->stats.promotion_count++;
                last_state->stats.demotion_count = 0;
                if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) {
index 299d45c3bdd28c6f6111dde39080c76c51dfb172..78d77c5dc35c3ec00b261fa39a7e3aa89271a957 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <linux/kernel.h>
 #include <linux/cpuidle.h>
-#include <linux/latency.h>
+#include <linux/pm_qos_params.h>
 #include <linux/time.h>
 #include <linux/ktime.h>
 #include <linux/hrtimer.h>
@@ -48,7 +48,7 @@ static int menu_select(struct cpuidle_device *dev)
                        break;
                if (s->target_residency > data->predicted_us)
                        break;
-               if (s->exit_latency > system_latency_constraint())
+               if (s->exit_latency > pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY))
                        break;
        }
 
index e4c48e329367d93617635e65a671ffb2816a47f7..8cd8507b1a8ae4e76662101b4a55c513ec91e14e 100644 (file)
 #include <linux/dio.h>
 
 
-       /**
-        *  dio_match_device - Tell if a DIO device structure has a matching
-        *                     DIO device id structure
-        *  @ids: array of DIO device id structures to search in
-        *  @dev: the DIO device structure to match against
-        *
-        *  Used by a driver to check whether a DIO device present in the
-        *  system is in its list of supported devices. Returns the matching
-        *  dio_device_id structure or %NULL if there is no match.
-        */
+/**
+ *  dio_match_device - Tell if a DIO device structure has a matching DIO device id structure
+ *  @ids: array of DIO device id structures to search in
+ *  @d: the DIO device structure to match against
+ *
+ *  Used by a driver to check whether a DIO device present in the
+ *  system is in its list of supported devices. Returns the matching
+ *  dio_device_id structure or %NULL if there is no match.
+ */
 
 const struct dio_device_id *
 dio_match_device(const struct dio_device_id *ids,
@@ -66,13 +65,13 @@ static int dio_device_probe(struct device *dev)
 }
 
 
-       /**
       *  dio_register_driver - register a new DIO driver
       *  @drv: the driver structure to register
       *
       *  Adds the driver structure to the list of registered drivers
       *  Returns zero or a negative error value.
       */
+/**
+ *  dio_register_driver - register a new DIO driver
+ *  @drv: the driver structure to register
+ *
+ *  Adds the driver structure to the list of registered drivers
+ *  Returns zero or a negative error value.
+ */
 
 int dio_register_driver(struct dio_driver *drv)
 {
@@ -85,15 +84,15 @@ int dio_register_driver(struct dio_driver *drv)
 }
 
 
-       /**
       *  dio_unregister_driver - unregister a DIO driver
       *  @drv: the driver structure to unregister
       *
       *  Deletes the driver structure from the list of registered DIO drivers,
       *  gives it a chance to clean up by calling its remove() function for
       *  each device it was responsible for, and marks those devices as
       *  driverless.
       */
+/**
+ *  dio_unregister_driver - unregister a DIO driver
+ *  @drv: the driver structure to unregister
+ *
+ *  Deletes the driver structure from the list of registered DIO drivers,
+ *  gives it a chance to clean up by calling its remove() function for
+ *  each device it was responsible for, and marks those devices as
+ *  driverless.
+ */
 
 void dio_unregister_driver(struct dio_driver *drv)
 {
@@ -101,16 +100,15 @@ void dio_unregister_driver(struct dio_driver *drv)
 }
 
 
-       /**
-        *  dio_bus_match - Tell if a DIO device structure has a matching DIO
-        *                  device id structure
-        *  @ids: array of DIO device id structures to search in
-        *  @dev: the DIO device structure to match against
-        *
-        *  Used by a driver to check whether a DIO device present in the
-        *  system is in its list of supported devices. Returns the matching
-        *  dio_device_id structure or %NULL if there is no match.
-        */
+/**
+ *  dio_bus_match - Tell if a DIO device structure has a matching DIO device id structure
+ *  @dev: the DIO device structure to match against
+ *  @drv: the &device_driver that points to the array of DIO device id structures to search
+ *
+ *  Used by a driver to check whether a DIO device present in the
+ *  system is in its list of supported devices. Returns the matching
+ *  dio_device_id structure or %NULL if there is no match.
+ */
 
 static int dio_bus_match(struct device *dev, struct device_driver *drv)
 {
index 17502d6efae788c2bb614f3833a550de9059a59c..07f274f853d95f5dc0cf8b671e989fca3a65742f 100644 (file)
@@ -88,8 +88,6 @@ static struct dioname names[] =
 #undef DIONAME
 #undef DIOFBNAME
 
-#define NUMNAMES (sizeof(names) / sizeof(struct dioname))
-
 static const char *unknowndioname 
         = "unknown DIO board -- please email <linux-m68k@lists.linux-m68k.org>!";
 
@@ -97,7 +95,7 @@ static const char *dio_getname(int id)
 {
         /* return pointer to a constant string describing the board with given ID */
        unsigned int i;
-        for (i = 0; i < NUMNAMES; i++)
+       for (i = 0; i < ARRAY_SIZE(names); i++)
                 if (names[i].id == id) 
                         return names[i].name;
 
index c46b7c219ee92987b59386adbaa791b167aa28df..a703deffb7954cd3a1fd4831adaa48403b1b06ba 100644 (file)
@@ -5,6 +5,7 @@
 menuconfig DMADEVICES
        bool "DMA Engine support"
        depends on (PCI && X86) || ARCH_IOP32X || ARCH_IOP33X || ARCH_IOP13XX
+       depends on !HIGHMEM64G
        help
          DMA engines can do asynchronous data transfers without
          involving the host CPU.  Currently, this framework can be
index bcf52df303390dbf775ea91cd9ab9e714f3f8178..29965231b9127e6e9e658997f26b72ffb69c4d3c 100644 (file)
@@ -473,20 +473,22 @@ dma_async_memcpy_buf_to_buf(struct dma_chan *chan, void *dest,
 {
        struct dma_device *dev = chan->device;
        struct dma_async_tx_descriptor *tx;
-       dma_addr_t addr;
+       dma_addr_t dma_dest, dma_src;
        dma_cookie_t cookie;
        int cpu;
 
-       tx = dev->device_prep_dma_memcpy(chan, len, 0);
-       if (!tx)
+       dma_src = dma_map_single(dev->dev, src, len, DMA_TO_DEVICE);
+       dma_dest = dma_map_single(dev->dev, dest, len, DMA_FROM_DEVICE);
+       tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, 0);
+
+       if (!tx) {
+               dma_unmap_single(dev->dev, dma_src, len, DMA_TO_DEVICE);
+               dma_unmap_single(dev->dev, dma_dest, len, DMA_FROM_DEVICE);
                return -ENOMEM;
+       }
 
        tx->ack = 1;
        tx->callback = NULL;
-       addr = dma_map_single(dev->dev, src, len, DMA_TO_DEVICE);
-       tx->tx_set_src(addr, tx, 0);
-       addr = dma_map_single(dev->dev, dest, len, DMA_FROM_DEVICE);
-       tx->tx_set_dest(addr, tx, 0);
        cookie = tx->tx_submit(tx);
 
        cpu = get_cpu();
@@ -517,20 +519,22 @@ dma_async_memcpy_buf_to_pg(struct dma_chan *chan, struct page *page,
 {
        struct dma_device *dev = chan->device;
        struct dma_async_tx_descriptor *tx;
-       dma_addr_t addr;
+       dma_addr_t dma_dest, dma_src;
        dma_cookie_t cookie;
        int cpu;
 
-       tx = dev->device_prep_dma_memcpy(chan, len, 0);
-       if (!tx)
+       dma_src = dma_map_single(dev->dev, kdata, len, DMA_TO_DEVICE);
+       dma_dest = dma_map_page(dev->dev, page, offset, len, DMA_FROM_DEVICE);
+       tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, 0);
+
+       if (!tx) {
+               dma_unmap_single(dev->dev, dma_src, len, DMA_TO_DEVICE);
+               dma_unmap_page(dev->dev, dma_dest, len, DMA_FROM_DEVICE);
                return -ENOMEM;
+       }
 
        tx->ack = 1;
        tx->callback = NULL;
-       addr = dma_map_single(dev->dev, kdata, len, DMA_TO_DEVICE);
-       tx->tx_set_src(addr, tx, 0);
-       addr = dma_map_page(dev->dev, page, offset, len, DMA_FROM_DEVICE);
-       tx->tx_set_dest(addr, tx, 0);
        cookie = tx->tx_submit(tx);
 
        cpu = get_cpu();
@@ -563,20 +567,23 @@ dma_async_memcpy_pg_to_pg(struct dma_chan *chan, struct page *dest_pg,
 {
        struct dma_device *dev = chan->device;
        struct dma_async_tx_descriptor *tx;
-       dma_addr_t addr;
+       dma_addr_t dma_dest, dma_src;
        dma_cookie_t cookie;
        int cpu;
 
-       tx = dev->device_prep_dma_memcpy(chan, len, 0);
-       if (!tx)
+       dma_src = dma_map_page(dev->dev, src_pg, src_off, len, DMA_TO_DEVICE);
+       dma_dest = dma_map_page(dev->dev, dest_pg, dest_off, len,
+                               DMA_FROM_DEVICE);
+       tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, 0);
+
+       if (!tx) {
+               dma_unmap_page(dev->dev, dma_src, len, DMA_TO_DEVICE);
+               dma_unmap_page(dev->dev, dma_dest, len, DMA_FROM_DEVICE);
                return -ENOMEM;
+       }
 
        tx->ack = 1;
        tx->callback = NULL;
-       addr = dma_map_page(dev->dev, src_pg, src_off, len, DMA_TO_DEVICE);
-       tx->tx_set_src(addr, tx, 0);
-       addr = dma_map_page(dev->dev, dest_pg, dest_off, len, DMA_FROM_DEVICE);
-       tx->tx_set_dest(addr, tx, 0);
        cookie = tx->tx_submit(tx);
 
        cpu = get_cpu();
index 45e7b4666c7b3c5197eeaa0c256dcf76860a2161..dff38accc5c1df47193a73b4fb81e467012d80b6 100644 (file)
@@ -159,20 +159,6 @@ static int ioat_dma_enumerate_channels(struct ioatdma_device *device)
        return device->common.chancnt;
 }
 
-static void ioat_set_src(dma_addr_t addr,
-                        struct dma_async_tx_descriptor *tx,
-                        int index)
-{
-       tx_to_ioat_desc(tx)->src = addr;
-}
-
-static void ioat_set_dest(dma_addr_t addr,
-                         struct dma_async_tx_descriptor *tx,
-                         int index)
-{
-       tx_to_ioat_desc(tx)->dst = addr;
-}
-
 /**
  * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended
  *                                 descriptors to hw
@@ -415,8 +401,6 @@ static struct ioat_desc_sw *ioat_dma_alloc_descriptor(
 
        memset(desc, 0, sizeof(*desc));
        dma_async_tx_descriptor_init(&desc_sw->async_tx, &ioat_chan->common);
-       desc_sw->async_tx.tx_set_src = ioat_set_src;
-       desc_sw->async_tx.tx_set_dest = ioat_set_dest;
        switch (ioat_chan->device->version) {
        case IOAT_VER_1_2:
                desc_sw->async_tx.tx_submit = ioat1_tx_submit;
@@ -714,8 +698,10 @@ static struct ioat_desc_sw *ioat_dma_get_next_descriptor(
 
 static struct dma_async_tx_descriptor *ioat1_dma_prep_memcpy(
                                                struct dma_chan *chan,
+                                               dma_addr_t dma_dest,
+                                               dma_addr_t dma_src,
                                                size_t len,
-                                               int int_en)
+                                               unsigned long flags)
 {
        struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
        struct ioat_desc_sw *new;
@@ -726,6 +712,8 @@ static struct dma_async_tx_descriptor *ioat1_dma_prep_memcpy(
 
        if (new) {
                new->len = len;
+               new->dst = dma_dest;
+               new->src = dma_src;
                return &new->async_tx;
        } else
                return NULL;
@@ -733,8 +721,10 @@ static struct dma_async_tx_descriptor *ioat1_dma_prep_memcpy(
 
 static struct dma_async_tx_descriptor *ioat2_dma_prep_memcpy(
                                                struct dma_chan *chan,
+                                               dma_addr_t dma_dest,
+                                               dma_addr_t dma_src,
                                                size_t len,
-                                               int int_en)
+                                               unsigned long flags)
 {
        struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
        struct ioat_desc_sw *new;
@@ -749,6 +739,8 @@ static struct dma_async_tx_descriptor *ioat2_dma_prep_memcpy(
 
        if (new) {
                new->len = len;
+               new->dst = dma_dest;
+               new->src = dma_src;
                return &new->async_tx;
        } else
                return NULL;
@@ -1045,7 +1037,7 @@ static int ioat_dma_self_test(struct ioatdma_device *device)
        u8 *dest;
        struct dma_chan *dma_chan;
        struct dma_async_tx_descriptor *tx;
-       dma_addr_t addr;
+       dma_addr_t dma_dest, dma_src;
        dma_cookie_t cookie;
        int err = 0;
 
@@ -1073,7 +1065,12 @@ static int ioat_dma_self_test(struct ioatdma_device *device)
                goto out;
        }
 
-       tx = device->common.device_prep_dma_memcpy(dma_chan, IOAT_TEST_SIZE, 0);
+       dma_src = dma_map_single(dma_chan->device->dev, src, IOAT_TEST_SIZE,
+                                DMA_TO_DEVICE);
+       dma_dest = dma_map_single(dma_chan->device->dev, dest, IOAT_TEST_SIZE,
+                                 DMA_FROM_DEVICE);
+       tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
+                                                  IOAT_TEST_SIZE, 0);
        if (!tx) {
                dev_err(&device->pdev->dev,
                        "Self-test prep failed, disabling\n");
@@ -1082,12 +1079,6 @@ static int ioat_dma_self_test(struct ioatdma_device *device)
        }
 
        async_tx_ack(tx);
-       addr = dma_map_single(dma_chan->device->dev, src, IOAT_TEST_SIZE,
-                             DMA_TO_DEVICE);
-       tx->tx_set_src(addr, tx, 0);
-       addr = dma_map_single(dma_chan->device->dev, dest, IOAT_TEST_SIZE,
-                             DMA_FROM_DEVICE);
-       tx->tx_set_dest(addr, tx, 0);
        tx->callback = ioat_dma_test_callback;
        tx->callback_param = (void *)0x8086;
        cookie = tx->tx_submit(tx);
index e5c62b75f36f1adefe418e28d6089fc83dc4f6f9..3986d54492bde18d2b0d45d2e64a449dac5af227 100644 (file)
@@ -284,7 +284,7 @@ iop_adma_alloc_slots(struct iop_adma_chan *iop_chan, int num_slots,
                        int slots_per_op)
 {
        struct iop_adma_desc_slot *iter, *_iter, *alloc_start = NULL;
-       struct list_head chain = LIST_HEAD_INIT(chain);
+       LIST_HEAD(chain);
        int slots_found, retry = 0;
 
        /* start search from the last allocated descrtiptor
@@ -443,17 +443,6 @@ iop_adma_tx_submit(struct dma_async_tx_descriptor *tx)
        return cookie;
 }
 
-static void
-iop_adma_set_dest(dma_addr_t addr, struct dma_async_tx_descriptor *tx,
-       int index)
-{
-       struct iop_adma_desc_slot *sw_desc = tx_to_iop_adma_slot(tx);
-       struct iop_adma_chan *iop_chan = to_iop_adma_chan(tx->chan);
-
-       /* to do: support transfers lengths > IOP_ADMA_MAX_BYTE_COUNT */
-       iop_desc_set_dest_addr(sw_desc->group_head, iop_chan, addr);
-}
-
 static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan);
 static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan);
 
@@ -486,7 +475,6 @@ static int iop_adma_alloc_chan_resources(struct dma_chan *chan)
 
                dma_async_tx_descriptor_init(&slot->async_tx, chan);
                slot->async_tx.tx_submit = iop_adma_tx_submit;
-               slot->async_tx.tx_set_dest = iop_adma_set_dest;
                INIT_LIST_HEAD(&slot->chain_node);
                INIT_LIST_HEAD(&slot->slot_node);
                INIT_LIST_HEAD(&slot->async_tx.tx_list);
@@ -547,18 +535,9 @@ iop_adma_prep_dma_interrupt(struct dma_chan *chan)
        return sw_desc ? &sw_desc->async_tx : NULL;
 }
 
-static void
-iop_adma_memcpy_set_src(dma_addr_t addr, struct dma_async_tx_descriptor *tx,
-       int index)
-{
-       struct iop_adma_desc_slot *sw_desc = tx_to_iop_adma_slot(tx);
-       struct iop_adma_desc_slot *grp_start = sw_desc->group_head;
-
-       iop_desc_set_memcpy_src_addr(grp_start, addr);
-}
-
 static struct dma_async_tx_descriptor *
-iop_adma_prep_dma_memcpy(struct dma_chan *chan, size_t len, int int_en)
+iop_adma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dma_dest,
+                        dma_addr_t dma_src, size_t len, unsigned long flags)
 {
        struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
        struct iop_adma_desc_slot *sw_desc, *grp_start;
@@ -576,11 +555,12 @@ iop_adma_prep_dma_memcpy(struct dma_chan *chan, size_t len, int int_en)
        sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
        if (sw_desc) {
                grp_start = sw_desc->group_head;
-               iop_desc_init_memcpy(grp_start, int_en);
+               iop_desc_init_memcpy(grp_start, flags);
                iop_desc_set_byte_count(grp_start, iop_chan, len);
+               iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
+               iop_desc_set_memcpy_src_addr(grp_start, dma_src);
                sw_desc->unmap_src_cnt = 1;
                sw_desc->unmap_len = len;
-               sw_desc->async_tx.tx_set_src = iop_adma_memcpy_set_src;
        }
        spin_unlock_bh(&iop_chan->lock);
 
@@ -588,8 +568,8 @@ iop_adma_prep_dma_memcpy(struct dma_chan *chan, size_t len, int int_en)
 }
 
 static struct dma_async_tx_descriptor *
-iop_adma_prep_dma_memset(struct dma_chan *chan, int value, size_t len,
-       int int_en)
+iop_adma_prep_dma_memset(struct dma_chan *chan, dma_addr_t dma_dest,
+                        int value, size_t len, unsigned long flags)
 {
        struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
        struct iop_adma_desc_slot *sw_desc, *grp_start;
@@ -607,9 +587,10 @@ iop_adma_prep_dma_memset(struct dma_chan *chan, int value, size_t len,
        sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
        if (sw_desc) {
                grp_start = sw_desc->group_head;
-               iop_desc_init_memset(grp_start, int_en);
+               iop_desc_init_memset(grp_start, flags);
                iop_desc_set_byte_count(grp_start, iop_chan, len);
                iop_desc_set_block_fill_val(grp_start, value);
+               iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
                sw_desc->unmap_src_cnt = 1;
                sw_desc->unmap_len = len;
        }
@@ -618,19 +599,10 @@ iop_adma_prep_dma_memset(struct dma_chan *chan, int value, size_t len,
        return sw_desc ? &sw_desc->async_tx : NULL;
 }
 
-static void
-iop_adma_xor_set_src(dma_addr_t addr, struct dma_async_tx_descriptor *tx,
-       int index)
-{
-       struct iop_adma_desc_slot *sw_desc = tx_to_iop_adma_slot(tx);
-       struct iop_adma_desc_slot *grp_start = sw_desc->group_head;
-
-       iop_desc_set_xor_src_addr(grp_start, index, addr);
-}
-
 static struct dma_async_tx_descriptor *
-iop_adma_prep_dma_xor(struct dma_chan *chan, unsigned int src_cnt, size_t len,
-       int int_en)
+iop_adma_prep_dma_xor(struct dma_chan *chan, dma_addr_t dma_dest,
+                     dma_addr_t *dma_src, unsigned int src_cnt, size_t len,
+                     unsigned long flags)
 {
        struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
        struct iop_adma_desc_slot *sw_desc, *grp_start;
@@ -641,39 +613,32 @@ iop_adma_prep_dma_xor(struct dma_chan *chan, unsigned int src_cnt, size_t len,
        BUG_ON(unlikely(len > IOP_ADMA_XOR_MAX_BYTE_COUNT));
 
        dev_dbg(iop_chan->device->common.dev,
-               "%s src_cnt: %d len: %u int_en: %d\n",
-               __FUNCTION__, src_cnt, len, int_en);
+               "%s src_cnt: %d len: %u flags: %lx\n",
+               __FUNCTION__, src_cnt, len, flags);
 
        spin_lock_bh(&iop_chan->lock);
        slot_cnt = iop_chan_xor_slot_count(len, src_cnt, &slots_per_op);
        sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
        if (sw_desc) {
                grp_start = sw_desc->group_head;
-               iop_desc_init_xor(grp_start, src_cnt, int_en);
+               iop_desc_init_xor(grp_start, src_cnt, flags);
                iop_desc_set_byte_count(grp_start, iop_chan, len);
+               iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
                sw_desc->unmap_src_cnt = src_cnt;
                sw_desc->unmap_len = len;
-               sw_desc->async_tx.tx_set_src = iop_adma_xor_set_src;
+               while (src_cnt--)
+                       iop_desc_set_xor_src_addr(grp_start, src_cnt,
+                                                 dma_src[src_cnt]);
        }
        spin_unlock_bh(&iop_chan->lock);
 
        return sw_desc ? &sw_desc->async_tx : NULL;
 }
 
-static void
-iop_adma_xor_zero_sum_set_src(dma_addr_t addr,
-                               struct dma_async_tx_descriptor *tx,
-                               int index)
-{
-       struct iop_adma_desc_slot *sw_desc = tx_to_iop_adma_slot(tx);
-       struct iop_adma_desc_slot *grp_start = sw_desc->group_head;
-
-       iop_desc_set_zero_sum_src_addr(grp_start, index, addr);
-}
-
 static struct dma_async_tx_descriptor *
-iop_adma_prep_dma_zero_sum(struct dma_chan *chan, unsigned int src_cnt,
-       size_t len, u32 *result, int int_en)
+iop_adma_prep_dma_zero_sum(struct dma_chan *chan, dma_addr_t *dma_src,
+                          unsigned int src_cnt, size_t len, u32 *result,
+                          unsigned long flags)
 {
        struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
        struct iop_adma_desc_slot *sw_desc, *grp_start;
@@ -690,14 +655,16 @@ iop_adma_prep_dma_zero_sum(struct dma_chan *chan, unsigned int src_cnt,
        sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
        if (sw_desc) {
                grp_start = sw_desc->group_head;
-               iop_desc_init_zero_sum(grp_start, src_cnt, int_en);
+               iop_desc_init_zero_sum(grp_start, src_cnt, flags);
                iop_desc_set_zero_sum_byte_count(grp_start, len);
                grp_start->xor_check_result = result;
                pr_debug("\t%s: grp_start->xor_check_result: %p\n",
                        __FUNCTION__, grp_start->xor_check_result);
                sw_desc->unmap_src_cnt = src_cnt;
                sw_desc->unmap_len = len;
-               sw_desc->async_tx.tx_set_src = iop_adma_xor_zero_sum_set_src;
+               while (src_cnt--)
+                       iop_desc_set_zero_sum_src_addr(grp_start, src_cnt,
+                                                      dma_src[src_cnt]);
        }
        spin_unlock_bh(&iop_chan->lock);
 
@@ -882,13 +849,12 @@ static int __devinit iop_adma_memcpy_self_test(struct iop_adma_device *device)
                goto out;
        }
 
-       tx = iop_adma_prep_dma_memcpy(dma_chan, IOP_ADMA_TEST_SIZE, 1);
        dest_dma = dma_map_single(dma_chan->device->dev, dest,
                                IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE);
-       iop_adma_set_dest(dest_dma, tx, 0);
        src_dma = dma_map_single(dma_chan->device->dev, src,
                                IOP_ADMA_TEST_SIZE, DMA_TO_DEVICE);
-       iop_adma_memcpy_set_src(src_dma, tx, 0);
+       tx = iop_adma_prep_dma_memcpy(dma_chan, dest_dma, src_dma,
+                                     IOP_ADMA_TEST_SIZE, 1);
 
        cookie = iop_adma_tx_submit(tx);
        iop_adma_issue_pending(dma_chan);
@@ -929,6 +895,7 @@ iop_adma_xor_zero_sum_self_test(struct iop_adma_device *device)
        struct page *dest;
        struct page *xor_srcs[IOP_ADMA_NUM_SRC_TEST];
        struct page *zero_sum_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
+       dma_addr_t dma_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
        dma_addr_t dma_addr, dest_dma;
        struct dma_async_tx_descriptor *tx;
        struct dma_chan *dma_chan;
@@ -981,17 +948,13 @@ iop_adma_xor_zero_sum_self_test(struct iop_adma_device *device)
        }
 
        /* test xor */
-       tx = iop_adma_prep_dma_xor(dma_chan, IOP_ADMA_NUM_SRC_TEST,
-                               PAGE_SIZE, 1);
        dest_dma = dma_map_page(dma_chan->device->dev, dest, 0,
                                PAGE_SIZE, DMA_FROM_DEVICE);
-       iop_adma_set_dest(dest_dma, tx, 0);
-
-       for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) {
-               dma_addr = dma_map_page(dma_chan->device->dev, xor_srcs[i], 0,
-                       PAGE_SIZE, DMA_TO_DEVICE);
-               iop_adma_xor_set_src(dma_addr, tx, i);
-       }
+       for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
+               dma_srcs[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i],
+                                          0, PAGE_SIZE, DMA_TO_DEVICE);
+       tx = iop_adma_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
+                                  IOP_ADMA_NUM_SRC_TEST, PAGE_SIZE, 1);
 
        cookie = iop_adma_tx_submit(tx);
        iop_adma_issue_pending(dma_chan);
@@ -1032,13 +995,13 @@ iop_adma_xor_zero_sum_self_test(struct iop_adma_device *device)
 
        zero_sum_result = 1;
 
-       tx = iop_adma_prep_dma_zero_sum(dma_chan, IOP_ADMA_NUM_SRC_TEST + 1,
-               PAGE_SIZE, &zero_sum_result, 1);
-       for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++) {
-               dma_addr = dma_map_page(dma_chan->device->dev, zero_sum_srcs[i],
-                       0, PAGE_SIZE, DMA_TO_DEVICE);
-               iop_adma_xor_zero_sum_set_src(dma_addr, tx, i);
-       }
+       for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
+               dma_srcs[i] = dma_map_page(dma_chan->device->dev,
+                                          zero_sum_srcs[i], 0, PAGE_SIZE,
+                                          DMA_TO_DEVICE);
+       tx = iop_adma_prep_dma_zero_sum(dma_chan, dma_srcs,
+                                       IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
+                                       &zero_sum_result, 1);
 
        cookie = iop_adma_tx_submit(tx);
        iop_adma_issue_pending(dma_chan);
@@ -1060,10 +1023,9 @@ iop_adma_xor_zero_sum_self_test(struct iop_adma_device *device)
        }
 
        /* test memset */
-       tx = iop_adma_prep_dma_memset(dma_chan, 0, PAGE_SIZE, 1);
        dma_addr = dma_map_page(dma_chan->device->dev, dest, 0,
                        PAGE_SIZE, DMA_FROM_DEVICE);
-       iop_adma_set_dest(dma_addr, tx, 0);
+       tx = iop_adma_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE, 1);
 
        cookie = iop_adma_tx_submit(tx);
        iop_adma_issue_pending(dma_chan);
@@ -1089,13 +1051,13 @@ iop_adma_xor_zero_sum_self_test(struct iop_adma_device *device)
 
        /* test for non-zero parity sum */
        zero_sum_result = 0;
-       tx = iop_adma_prep_dma_zero_sum(dma_chan, IOP_ADMA_NUM_SRC_TEST + 1,
-               PAGE_SIZE, &zero_sum_result, 1);
-       for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++) {
-               dma_addr = dma_map_page(dma_chan->device->dev, zero_sum_srcs[i],
-                       0, PAGE_SIZE, DMA_TO_DEVICE);
-               iop_adma_xor_zero_sum_set_src(dma_addr, tx, i);
-       }
+       for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
+               dma_srcs[i] = dma_map_page(dma_chan->device->dev,
+                                          zero_sum_srcs[i], 0, PAGE_SIZE,
+                                          DMA_TO_DEVICE);
+       tx = iop_adma_prep_dma_zero_sum(dma_chan, dma_srcs,
+                                       IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
+                                       &zero_sum_result, 1);
 
        cookie = iop_adma_tx_submit(tx);
        iop_adma_issue_pending(dma_chan);
index 5dee9f50414bee396fde63895efa6ddcf7f0841c..e0b47b74ec4581aa60dda973c612bddc6c5738ca 100644 (file)
@@ -73,7 +73,7 @@ EXPORT_SYMBOL_GPL(edac_pci_alloc_ctl_info);
  *
  *     Last action on the pci control structure.
  *
- *     call the remove sysfs informaton, which will unregister
+ *     call the remove sysfs information, which will unregister
  *     this control struct's kobj. When that kobj's ref count
  *     goes to zero, its release function will be call and then
  *     kfree() the memory.
index a1f24c42d5ff45176984727961c245df1d0908fc..5a852017c17a70dc87d1bd16c7e83587b8b7a1c7 100644 (file)
@@ -351,7 +351,7 @@ struct i5000_pvt {
        u16 b1_ambpresent0;     /* Branch 1, Channel 8 */
        u16 b1_ambpresent1;     /* Branch 1, Channel 1 */
 
-       /* DIMM infomation matrix, allocating architecture maximums */
+       /* DIMM information matrix, allocating architecture maximums */
        struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
 
        /* Actual values for this controller */
index 18cdcb3ae1ca3d11131b0cf9498086a25066ec14..1636806ec55e8432af872e6327ef02b297db795c 100644 (file)
@@ -658,4 +658,5 @@ MODULE_DESCRIPTION(DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")");
 MODULE_VERSION(DRIVER_VERSION);
 MODULE_AUTHOR("Dell Inc.");
 MODULE_LICENSE("GPL");
-
+/* Any System or BIOS claiming to be by Dell */
+MODULE_ALIAS("dmi:*:[bs]vnD[Ee][Ll][Ll]*:*");
index 313c99cbdc62363632217d3061b7709b972b2127..e880d6c8d8965d88e9fcc9674006cf6b4206a215 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/init.h>
 #include <linux/dmi.h>
 #include <linux/device.h>
-#include <linux/autoconf.h>
 
 struct dmi_device_attribute{
        struct device_attribute dev_attr;
index d168223db1594b7d351956f14903448548c08e1e..744011989044e029ca95cd00b9e3eb9ffed7cfb8 100644 (file)
@@ -11,7 +11,7 @@
  *
  * This code takes information provided by BIOS EDD calls
  * fn41 - Check Extensions Present and
- * fn48 - Get Device Parametes with EDD extensions
+ * fn48 - Get Device Parameters with EDD extensions
  * made in setup.S, copied to safe structures in setup.c,
  * and presents it in sysfs.
  *
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
new file mode 100644 (file)
index 0000000..bbd2834
--- /dev/null
@@ -0,0 +1,73 @@
+#
+# GPIO infrastructure and expanders
+#
+
+config HAVE_GPIO_LIB
+       bool
+       help
+         Platforms select gpiolib if they use this infrastructure
+         for all their GPIOs, usually starting with ones integrated
+         into SOC processors.
+
+menu "GPIO Support"
+       depends on HAVE_GPIO_LIB
+
+config DEBUG_GPIO
+       bool "Debug GPIO calls"
+       depends on DEBUG_KERNEL
+       help
+         Say Y here to add some extra checks and diagnostics to GPIO calls.
+         The checks help ensure that GPIOs have been properly initialized
+         before they are used and that sleeping calls aren not made from
+         nonsleeping contexts.  They can make bitbanged serial protocols
+         slower.  The diagnostics help catch the type of setup errors
+         that are most common when setting up new platforms or boards.
+
+# put expanders in the right section, in alphabetical order
+
+comment "I2C GPIO expanders:"
+
+config GPIO_PCA953X
+       tristate "PCA953x I/O ports"
+       depends on I2C
+       help
+         Say yes here to support the PCA9534 (8-bit), PCA9535 (16-bit),
+         PCA9536 (4-bit), PCA9537 (4-bit), PCA9538 (8-bit), and PCA9539
+         (16-bit) I/O ports. These parts are made by NXP and TI.
+
+         This driver can also be built as a module.  If so, the module
+         will be called pca953x.
+
+config GPIO_PCF857X
+       tristate "PCF857x, PCA857x, and PCA967x I2C GPIO expanders"
+       depends on I2C
+       help
+         Say yes here to provide access to most "quasi-bidirectional" I2C
+         GPIO expanders used for additional digital outputs or inputs.
+         Most of these parts are from NXP, though TI is a second source for
+         some of them.  Compatible models include:
+
+         8 bits:   pcf8574, pcf8574a, pca8574, pca8574a,
+                   pca9670, pca9672, pca9674, pca9674a
+
+         16 bits:  pcf8575, pcf8575c, pca8575,
+                   pca9671, pca9673, pca9675
+
+         Your board setup code will need to declare the expanders in
+         use, and assign numbers to the GPIOs they expose.  Those GPIOs
+         can then be used from drivers and other kernel code, just like
+         other GPIOs, but only accessible from task contexts.
+
+         This driver provides an in-kernel interface to those GPIOs using
+         platform-neutral GPIO calls.
+
+comment "SPI GPIO expanders:"
+
+config GPIO_MCP23S08
+       tristate "Microchip MCP23S08 I/O expander"
+       depends on SPI_MASTER
+       help
+         SPI driver for Microchip MCP23S08 I/O expander.  This provides
+         a GPIO interface supporting inputs and outputs.
+
+endmenu
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
new file mode 100644 (file)
index 0000000..fdde992
--- /dev/null
@@ -0,0 +1,9 @@
+# gpio support: dedicated expander chips, etc
+
+ccflags-$(CONFIG_DEBUG_GPIO)   += -DDEBUG
+
+obj-$(CONFIG_HAVE_GPIO_LIB)    += gpiolib.o
+
+obj-$(CONFIG_GPIO_MCP23S08)    += mcp23s08.o
+obj-$(CONFIG_GPIO_PCA953X)     += pca953x.o
+obj-$(CONFIG_GPIO_PCF857X)     += pcf857x.o
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
new file mode 100644 (file)
index 0000000..d8db2f8
--- /dev/null
@@ -0,0 +1,567 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/irq.h>
+#include <linux/spinlock.h>
+
+#include <asm/gpio.h>
+
+
+/* Optional implementation infrastructure for GPIO interfaces.
+ *
+ * Platforms may want to use this if they tend to use very many GPIOs
+ * that aren't part of a System-On-Chip core; or across I2C/SPI/etc.
+ *
+ * When kernel footprint or instruction count is an issue, simpler
+ * implementations may be preferred.  The GPIO programming interface
+ * allows for inlining speed-critical get/set operations for common
+ * cases, so that access to SOC-integrated GPIOs can sometimes cost
+ * only an instruction or two per bit.
+ */
+
+
+/* When debugging, extend minimal trust to callers and platform code.
+ * Also emit diagnostic messages that may help initial bringup, when
+ * board setup or driver bugs are most common.
+ *
+ * Otherwise, minimize overhead in what may be bitbanging codepaths.
+ */
+#ifdef DEBUG
+#define        extra_checks    1
+#else
+#define        extra_checks    0
+#endif
+
+/* gpio_lock prevents conflicts during gpio_desc[] table updates.
+ * While any GPIO is requested, its gpio_chip is not removable;
+ * each GPIO's "requested" flag serves as a lock and refcount.
+ */
+static DEFINE_SPINLOCK(gpio_lock);
+
+struct gpio_desc {
+       struct gpio_chip        *chip;
+       unsigned long           flags;
+/* flag symbols are bit numbers */
+#define FLAG_REQUESTED 0
+#define FLAG_IS_OUT    1
+
+#ifdef CONFIG_DEBUG_FS
+       const char              *label;
+#endif
+};
+static struct gpio_desc gpio_desc[ARCH_NR_GPIOS];
+
+static inline void desc_set_label(struct gpio_desc *d, const char *label)
+{
+#ifdef CONFIG_DEBUG_FS
+       d->label = label;
+#endif
+}
+
+/* Warn when drivers omit gpio_request() calls -- legal but ill-advised
+ * when setting direction, and otherwise illegal.  Until board setup code
+ * and drivers use explicit requests everywhere (which won't happen when
+ * those calls have no teeth) we can't avoid autorequesting.  This nag
+ * message should motivate switching to explicit requests...
+ */
+static void gpio_ensure_requested(struct gpio_desc *desc)
+{
+       if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
+               pr_warning("GPIO-%d autorequested\n", (int)(desc - gpio_desc));
+               desc_set_label(desc, "[auto]");
+       }
+}
+
+/* caller holds gpio_lock *OR* gpio is marked as requested */
+static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
+{
+       return gpio_desc[gpio].chip;
+}
+
+/**
+ * gpiochip_add() - register a gpio_chip
+ * @chip: the chip to register, with chip->base initialized
+ * Context: potentially before irqs or kmalloc will work
+ *
+ * Returns a negative errno if the chip can't be registered, such as
+ * because the chip->base is invalid or already associated with a
+ * different chip.  Otherwise it returns zero as a success code.
+ */
+int gpiochip_add(struct gpio_chip *chip)
+{
+       unsigned long   flags;
+       int             status = 0;
+       unsigned        id;
+
+       /* NOTE chip->base negative is reserved to mean a request for
+        * dynamic allocation.  We don't currently support that.
+        */
+
+       if (chip->base < 0 || (chip->base  + chip->ngpio) >= ARCH_NR_GPIOS) {
+               status = -EINVAL;
+               goto fail;
+       }
+
+       spin_lock_irqsave(&gpio_lock, flags);
+
+       /* these GPIO numbers must not be managed by another gpio_chip */
+       for (id = chip->base; id < chip->base + chip->ngpio; id++) {
+               if (gpio_desc[id].chip != NULL) {
+                       status = -EBUSY;
+                       break;
+               }
+       }
+       if (status == 0) {
+               for (id = chip->base; id < chip->base + chip->ngpio; id++) {
+                       gpio_desc[id].chip = chip;
+                       gpio_desc[id].flags = 0;
+               }
+       }
+
+       spin_unlock_irqrestore(&gpio_lock, flags);
+fail:
+       /* failures here can mean systems won't boot... */
+       if (status)
+               pr_err("gpiochip_add: gpios %d..%d (%s) not registered\n",
+                       chip->base, chip->base + chip->ngpio,
+                       chip->label ? : "generic");
+       return status;
+}
+EXPORT_SYMBOL_GPL(gpiochip_add);
+
+/**
+ * gpiochip_remove() - unregister a gpio_chip
+ * @chip: the chip to unregister
+ *
+ * A gpio_chip with any GPIOs still requested may not be removed.
+ */
+int gpiochip_remove(struct gpio_chip *chip)
+{
+       unsigned long   flags;
+       int             status = 0;
+       unsigned        id;
+
+       spin_lock_irqsave(&gpio_lock, flags);
+
+       for (id = chip->base; id < chip->base + chip->ngpio; id++) {
+               if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) {
+                       status = -EBUSY;
+                       break;
+               }
+       }
+       if (status == 0) {
+               for (id = chip->base; id < chip->base + chip->ngpio; id++)
+                       gpio_desc[id].chip = NULL;
+       }
+
+       spin_unlock_irqrestore(&gpio_lock, flags);
+       return status;
+}
+EXPORT_SYMBOL_GPL(gpiochip_remove);
+
+
+/* These "optional" allocation calls help prevent drivers from stomping
+ * on each other, and help provide better diagnostics in debugfs.
+ * They're called even less than the "set direction" calls.
+ */
+int gpio_request(unsigned gpio, const char *label)
+{
+       struct gpio_desc        *desc;
+       int                     status = -EINVAL;
+       unsigned long           flags;
+
+       spin_lock_irqsave(&gpio_lock, flags);
+
+       if (gpio >= ARCH_NR_GPIOS)
+               goto done;
+       desc = &gpio_desc[gpio];
+       if (desc->chip == NULL)
+               goto done;
+
+       /* NOTE:  gpio_request() can be called in early boot,
+        * before IRQs are enabled.
+        */
+
+       if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
+               desc_set_label(desc, label ? : "?");
+               status = 0;
+       } else
+               status = -EBUSY;
+
+done:
+       if (status)
+               pr_debug("gpio_request: gpio-%d (%s) status %d\n",
+                       gpio, label ? : "?", status);
+       spin_unlock_irqrestore(&gpio_lock, flags);
+       return status;
+}
+EXPORT_SYMBOL_GPL(gpio_request);
+
+void gpio_free(unsigned gpio)
+{
+       unsigned long           flags;
+       struct gpio_desc        *desc;
+
+       if (gpio >= ARCH_NR_GPIOS) {
+               WARN_ON(extra_checks);
+               return;
+       }
+
+       spin_lock_irqsave(&gpio_lock, flags);
+
+       desc = &gpio_desc[gpio];
+       if (desc->chip && test_and_clear_bit(FLAG_REQUESTED, &desc->flags))
+               desc_set_label(desc, NULL);
+       else
+               WARN_ON(extra_checks);
+
+       spin_unlock_irqrestore(&gpio_lock, flags);
+}
+EXPORT_SYMBOL_GPL(gpio_free);
+
+
+/**
+ * gpiochip_is_requested - return string iff signal was requested
+ * @chip: controller managing the signal
+ * @offset: of signal within controller's 0..(ngpio - 1) range
+ *
+ * Returns NULL if the GPIO is not currently requested, else a string.
+ * If debugfs support is enabled, the string returned is the label passed
+ * to gpio_request(); otherwise it is a meaningless constant.
+ *
+ * This function is for use by GPIO controller drivers.  The label can
+ * help with diagnostics, and knowing that the signal is used as a GPIO
+ * can help avoid accidentally multiplexing it to another controller.
+ */
+const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset)
+{
+       unsigned gpio = chip->base + offset;
+
+       if (gpio >= ARCH_NR_GPIOS || gpio_desc[gpio].chip != chip)
+               return NULL;
+       if (test_bit(FLAG_REQUESTED, &gpio_desc[gpio].flags) == 0)
+               return NULL;
+#ifdef CONFIG_DEBUG_FS
+       return gpio_desc[gpio].label;
+#else
+       return "?";
+#endif
+}
+EXPORT_SYMBOL_GPL(gpiochip_is_requested);
+
+
+/* Drivers MUST set GPIO direction before making get/set calls.  In
+ * some cases this is done in early boot, before IRQs are enabled.
+ *
+ * As a rule these aren't called more than once (except for drivers
+ * using the open-drain emulation idiom) so these are natural places
+ * to accumulate extra debugging checks.  Note that we can't (yet)
+ * rely on gpio_request() having been called beforehand.
+ */
+
+int gpio_direction_input(unsigned gpio)
+{
+       unsigned long           flags;
+       struct gpio_chip        *chip;
+       struct gpio_desc        *desc = &gpio_desc[gpio];
+       int                     status = -EINVAL;
+
+       spin_lock_irqsave(&gpio_lock, flags);
+
+       if (gpio >= ARCH_NR_GPIOS)
+               goto fail;
+       chip = desc->chip;
+       if (!chip || !chip->get || !chip->direction_input)
+               goto fail;
+       gpio -= chip->base;
+       if (gpio >= chip->ngpio)
+               goto fail;
+       gpio_ensure_requested(desc);
+
+       /* now we know the gpio is valid and chip won't vanish */
+
+       spin_unlock_irqrestore(&gpio_lock, flags);
+
+       might_sleep_if(extra_checks && chip->can_sleep);
+
+       status = chip->direction_input(chip, gpio);
+       if (status == 0)
+               clear_bit(FLAG_IS_OUT, &desc->flags);
+       return status;
+fail:
+       spin_unlock_irqrestore(&gpio_lock, flags);
+       if (status)
+               pr_debug("%s: gpio-%d status %d\n",
+                       __FUNCTION__, gpio, status);
+       return status;
+}
+EXPORT_SYMBOL_GPL(gpio_direction_input);
+
+int gpio_direction_output(unsigned gpio, int value)
+{
+       unsigned long           flags;
+       struct gpio_chip        *chip;
+       struct gpio_desc        *desc = &gpio_desc[gpio];
+       int                     status = -EINVAL;
+
+       spin_lock_irqsave(&gpio_lock, flags);
+
+       if (gpio >= ARCH_NR_GPIOS)
+               goto fail;
+       chip = desc->chip;
+       if (!chip || !chip->set || !chip->direction_output)
+               goto fail;
+       gpio -= chip->base;
+       if (gpio >= chip->ngpio)
+               goto fail;
+       gpio_ensure_requested(desc);
+
+       /* now we know the gpio is valid and chip won't vanish */
+
+       spin_unlock_irqrestore(&gpio_lock, flags);
+
+       might_sleep_if(extra_checks && chip->can_sleep);
+
+       status = chip->direction_output(chip, gpio, value);
+       if (status == 0)
+               set_bit(FLAG_IS_OUT, &desc->flags);
+       return status;
+fail:
+       spin_unlock_irqrestore(&gpio_lock, flags);
+       if (status)
+               pr_debug("%s: gpio-%d status %d\n",
+                       __FUNCTION__, gpio, status);
+       return status;
+}
+EXPORT_SYMBOL_GPL(gpio_direction_output);
+
+
+/* I/O calls are only valid after configuration completed; the relevant
+ * "is this a valid GPIO" error checks should already have been done.
+ *
+ * "Get" operations are often inlinable as reading a pin value register,
+ * and masking the relevant bit in that register.
+ *
+ * When "set" operations are inlinable, they involve writing that mask to
+ * one register to set a low value, or a different register to set it high.
+ * Otherwise locking is needed, so there may be little value to inlining.
+ *
+ *------------------------------------------------------------------------
+ *
+ * IMPORTANT!!!  The hot paths -- get/set value -- assume that callers
+ * have requested the GPIO.  That can include implicit requesting by
+ * a direction setting call.  Marking a gpio as requested locks its chip
+ * in memory, guaranteeing that these table lookups need no more locking
+ * and that gpiochip_remove() will fail.
+ *
+ * REVISIT when debugging, consider adding some instrumentation to ensure
+ * that the GPIO was actually requested.
+ */
+
+/**
+ * __gpio_get_value() - return a gpio's value
+ * @gpio: gpio whose value will be returned
+ * Context: any
+ *
+ * This is used directly or indirectly to implement gpio_get_value().
+ * It returns the zero or nonzero value provided by the associated
+ * gpio_chip.get() method; or zero if no such method is provided.
+ */
+int __gpio_get_value(unsigned gpio)
+{
+       struct gpio_chip        *chip;
+
+       chip = gpio_to_chip(gpio);
+       WARN_ON(extra_checks && chip->can_sleep);
+       return chip->get ? chip->get(chip, gpio - chip->base) : 0;
+}
+EXPORT_SYMBOL_GPL(__gpio_get_value);
+
+/**
+ * __gpio_set_value() - assign a gpio's value
+ * @gpio: gpio whose value will be assigned
+ * @value: value to assign
+ * Context: any
+ *
+ * This is used directly or indirectly to implement gpio_set_value().
+ * It invokes the associated gpio_chip.set() method.
+ */
+void __gpio_set_value(unsigned gpio, int value)
+{
+       struct gpio_chip        *chip;
+
+       chip = gpio_to_chip(gpio);
+       WARN_ON(extra_checks && chip->can_sleep);
+       chip->set(chip, gpio - chip->base, value);
+}
+EXPORT_SYMBOL_GPL(__gpio_set_value);
+
+/**
+ * __gpio_cansleep() - report whether gpio value access will sleep
+ * @gpio: gpio in question
+ * Context: any
+ *
+ * This is used directly or indirectly to implement gpio_cansleep().  It
+ * returns nonzero if access reading or writing the GPIO value can sleep.
+ */
+int __gpio_cansleep(unsigned gpio)
+{
+       struct gpio_chip        *chip;
+
+       /* only call this on GPIOs that are valid! */
+       chip = gpio_to_chip(gpio);
+
+       return chip->can_sleep;
+}
+EXPORT_SYMBOL_GPL(__gpio_cansleep);
+
+
+
+/* There's no value in making it easy to inline GPIO calls that may sleep.
+ * Common examples include ones connected to I2C or SPI chips.
+ */
+
+int gpio_get_value_cansleep(unsigned gpio)
+{
+       struct gpio_chip        *chip;
+
+       might_sleep_if(extra_checks);
+       chip = gpio_to_chip(gpio);
+       return chip->get(chip, gpio - chip->base);
+}
+EXPORT_SYMBOL_GPL(gpio_get_value_cansleep);
+
+void gpio_set_value_cansleep(unsigned gpio, int value)
+{
+       struct gpio_chip        *chip;
+
+       might_sleep_if(extra_checks);
+       chip = gpio_to_chip(gpio);
+       chip->set(chip, gpio - chip->base, value);
+}
+EXPORT_SYMBOL_GPL(gpio_set_value_cansleep);
+
+
+#ifdef CONFIG_DEBUG_FS
+
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+
+
+static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
+{
+       unsigned                i;
+       unsigned                gpio = chip->base;
+       struct gpio_desc        *gdesc = &gpio_desc[gpio];
+       int                     is_out;
+
+       for (i = 0; i < chip->ngpio; i++, gpio++, gdesc++) {
+               if (!test_bit(FLAG_REQUESTED, &gdesc->flags))
+                       continue;
+
+               is_out = test_bit(FLAG_IS_OUT, &gdesc->flags);
+               seq_printf(s, " gpio-%-3d (%-12s) %s %s",
+                       gpio, gdesc->label,
+                       is_out ? "out" : "in ",
+                       chip->get
+                               ? (chip->get(chip, i) ? "hi" : "lo")
+                               : "?  ");
+
+               if (!is_out) {
+                       int             irq = gpio_to_irq(gpio);
+                       struct irq_desc *desc = irq_desc + irq;
+
+                       /* This races with request_irq(), set_irq_type(),
+                        * and set_irq_wake() ... but those are "rare".
+                        *
+                        * More significantly, trigger type flags aren't
+                        * currently maintained by genirq.
+                        */
+                       if (irq >= 0 && desc->action) {
+                               char *trigger;
+
+                               switch (desc->status & IRQ_TYPE_SENSE_MASK) {
+                               case IRQ_TYPE_NONE:
+                                       trigger = "(default)";
+                                       break;
+                               case IRQ_TYPE_EDGE_FALLING:
+                                       trigger = "edge-falling";
+                                       break;
+                               case IRQ_TYPE_EDGE_RISING:
+                                       trigger = "edge-rising";
+                                       break;
+                               case IRQ_TYPE_EDGE_BOTH:
+                                       trigger = "edge-both";
+                                       break;
+                               case IRQ_TYPE_LEVEL_HIGH:
+                                       trigger = "level-high";
+                                       break;
+                               case IRQ_TYPE_LEVEL_LOW:
+                                       trigger = "level-low";
+                                       break;
+                               default:
+                                       trigger = "?trigger?";
+                                       break;
+                               }
+
+                               seq_printf(s, " irq-%d %s%s",
+                                       irq, trigger,
+                                       (desc->status & IRQ_WAKEUP)
+                                               ? " wakeup" : "");
+                       }
+               }
+
+               seq_printf(s, "\n");
+       }
+}
+
+static int gpiolib_show(struct seq_file *s, void *unused)
+{
+       struct gpio_chip        *chip = NULL;
+       unsigned                gpio;
+       int                     started = 0;
+
+       /* REVISIT this isn't locked against gpio_chip removal ... */
+
+       for (gpio = 0; gpio < ARCH_NR_GPIOS; gpio++) {
+               if (chip == gpio_desc[gpio].chip)
+                       continue;
+               chip = gpio_desc[gpio].chip;
+               if (!chip)
+                       continue;
+
+               seq_printf(s, "%sGPIOs %d-%d, %s%s:\n",
+                               started ? "\n" : "",
+                               chip->base, chip->base + chip->ngpio - 1,
+                               chip->label ? : "generic",
+                               chip->can_sleep ? ", can sleep" : "");
+               started = 1;
+               if (chip->dbg_show)
+                       chip->dbg_show(s, chip);
+               else
+                       gpiolib_dbg_show(s, chip);
+       }
+       return 0;
+}
+
+static int gpiolib_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, gpiolib_show, NULL);
+}
+
+static struct file_operations gpiolib_operations = {
+       .open           = gpiolib_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int __init gpiolib_debugfs_init(void)
+{
+       /* /sys/kernel/debug/gpio */
+       (void) debugfs_create_file("gpio", S_IFREG | S_IRUGO,
+                               NULL, NULL, &gpiolib_operations);
+       return 0;
+}
+subsys_initcall(gpiolib_debugfs_init);
+
+#endif /* DEBUG_FS */
diff --git a/drivers/gpio/mcp23s08.c b/drivers/gpio/mcp23s08.c
new file mode 100644 (file)
index 0000000..bb60e8c
--- /dev/null
@@ -0,0 +1,357 @@
+/*
+ * mcp23s08.c - SPI gpio expander driver
+ */
+
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/workqueue.h>
+#include <linux/mutex.h>
+
+#include <linux/spi/spi.h>
+#include <linux/spi/mcp23s08.h>
+
+#include <asm/gpio.h>
+
+
+/* Registers are all 8 bits wide.
+ *
+ * The mcp23s17 has twice as many bits, and can be configured to work
+ * with either 16 bit registers or with two adjacent 8 bit banks.
+ *
+ * Also, there are I2C versions of both chips.
+ */
+#define MCP_IODIR      0x00            /* init/reset:  all ones */
+#define MCP_IPOL       0x01
+#define MCP_GPINTEN    0x02
+#define MCP_DEFVAL     0x03
+#define MCP_INTCON     0x04
+#define MCP_IOCON      0x05
+#      define IOCON_SEQOP      (1 << 5)
+#      define IOCON_HAEN       (1 << 3)
+#      define IOCON_ODR        (1 << 2)
+#      define IOCON_INTPOL     (1 << 1)
+#define MCP_GPPU       0x06
+#define MCP_INTF       0x07
+#define MCP_INTCAP     0x08
+#define MCP_GPIO       0x09
+#define MCP_OLAT       0x0a
+
+struct mcp23s08 {
+       struct spi_device       *spi;
+       u8                      addr;
+
+       /* lock protects the cached values */
+       struct mutex            lock;
+       u8                      cache[11];
+
+       struct gpio_chip        chip;
+
+       struct work_struct      work;
+};
+
+static int mcp23s08_read(struct mcp23s08 *mcp, unsigned reg)
+{
+       u8      tx[2], rx[1];
+       int     status;
+
+       tx[0] = mcp->addr | 0x01;
+       tx[1] = reg;
+       status = spi_write_then_read(mcp->spi, tx, sizeof tx, rx, sizeof rx);
+       return (status < 0) ? status : rx[0];
+}
+
+static int mcp23s08_write(struct mcp23s08 *mcp, unsigned reg, u8 val)
+{
+       u8      tx[3];
+
+       tx[0] = mcp->addr;
+       tx[1] = reg;
+       tx[2] = val;
+       return spi_write_then_read(mcp->spi, tx, sizeof tx, NULL, 0);
+}
+
+static int
+mcp23s08_read_regs(struct mcp23s08 *mcp, unsigned reg, u8 *vals, unsigned n)
+{
+       u8      tx[2];
+
+       if ((n + reg) > sizeof mcp->cache)
+               return -EINVAL;
+       tx[0] = mcp->addr | 0x01;
+       tx[1] = reg;
+       return spi_write_then_read(mcp->spi, tx, sizeof tx, vals, n);
+}
+
+/*----------------------------------------------------------------------*/
+
+static int mcp23s08_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+       struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip);
+       int status;
+
+       mutex_lock(&mcp->lock);
+       mcp->cache[MCP_IODIR] |= (1 << offset);
+       status = mcp23s08_write(mcp, MCP_IODIR, mcp->cache[MCP_IODIR]);
+       mutex_unlock(&mcp->lock);
+       return status;
+}
+
+static int mcp23s08_get(struct gpio_chip *chip, unsigned offset)
+{
+       struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip);
+       int status;
+
+       mutex_lock(&mcp->lock);
+
+       /* REVISIT reading this clears any IRQ ... */
+       status = mcp23s08_read(mcp, MCP_GPIO);
+       if (status < 0)
+               status = 0;
+       else {
+               mcp->cache[MCP_GPIO] = status;
+               status = !!(status & (1 << offset));
+       }
+       mutex_unlock(&mcp->lock);
+       return status;
+}
+
+static int __mcp23s08_set(struct mcp23s08 *mcp, unsigned mask, int value)
+{
+       u8 olat = mcp->cache[MCP_OLAT];
+
+       if (value)
+               olat |= mask;
+       else
+               olat &= ~mask;
+       mcp->cache[MCP_OLAT] = olat;
+       return mcp23s08_write(mcp, MCP_OLAT, olat);
+}
+
+static void mcp23s08_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+       struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip);
+       u8 mask = 1 << offset;
+
+       mutex_lock(&mcp->lock);
+       __mcp23s08_set(mcp, mask, value);
+       mutex_unlock(&mcp->lock);
+}
+
+static int
+mcp23s08_direction_output(struct gpio_chip *chip, unsigned offset, int value)
+{
+       struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip);
+       u8 mask = 1 << offset;
+       int status;
+
+       mutex_lock(&mcp->lock);
+       status = __mcp23s08_set(mcp, mask, value);
+       if (status == 0) {
+               mcp->cache[MCP_IODIR] &= ~mask;
+               status = mcp23s08_write(mcp, MCP_IODIR, mcp->cache[MCP_IODIR]);
+       }
+       mutex_unlock(&mcp->lock);
+       return status;
+}
+
+/*----------------------------------------------------------------------*/
+
+#ifdef CONFIG_DEBUG_FS
+
+#include <linux/seq_file.h>
+
+/*
+ * This shows more info than the generic gpio dump code:
+ * pullups, deglitching, open drain drive.
+ */
+static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip)
+{
+       struct mcp23s08 *mcp;
+       char            bank;
+       unsigned        t;
+       unsigned        mask;
+
+       mcp = container_of(chip, struct mcp23s08, chip);
+
+       /* NOTE: we only handle one bank for now ... */
+       bank = '0' + ((mcp->addr >> 1) & 0x3);
+
+       mutex_lock(&mcp->lock);
+       t = mcp23s08_read_regs(mcp, 0, mcp->cache, sizeof mcp->cache);
+       if (t < 0) {
+               seq_printf(s, " I/O ERROR %d\n", t);
+               goto done;
+       }
+
+       for (t = 0, mask = 1; t < 8; t++, mask <<= 1) {
+               const char      *label;
+
+               label = gpiochip_is_requested(chip, t);
+               if (!label)
+                       continue;
+
+               seq_printf(s, " gpio-%-3d P%c.%d (%-12s) %s %s %s",
+                       chip->base + t, bank, t, label,
+                       (mcp->cache[MCP_IODIR] & mask) ? "in " : "out",
+                       (mcp->cache[MCP_GPIO] & mask) ? "hi" : "lo",
+                       (mcp->cache[MCP_GPPU] & mask) ? "  " : "up");
+               /* NOTE:  ignoring the irq-related registers */
+               seq_printf(s, "\n");
+       }
+done:
+       mutex_unlock(&mcp->lock);
+}
+
+#else
+#define mcp23s08_dbg_show      NULL
+#endif
+
+/*----------------------------------------------------------------------*/
+
+static int mcp23s08_probe(struct spi_device *spi)
+{
+       struct mcp23s08                 *mcp;
+       struct mcp23s08_platform_data   *pdata;
+       int                             status;
+       int                             do_update = 0;
+
+       pdata = spi->dev.platform_data;
+       if (!pdata || pdata->slave > 3 || !pdata->base)
+               return -ENODEV;
+
+       mcp = kzalloc(sizeof *mcp, GFP_KERNEL);
+       if (!mcp)
+               return -ENOMEM;
+
+       mutex_init(&mcp->lock);
+
+       mcp->spi = spi;
+       mcp->addr = 0x40 | (pdata->slave << 1);
+
+       mcp->chip.label = "mcp23s08",
+
+       mcp->chip.direction_input = mcp23s08_direction_input;
+       mcp->chip.get = mcp23s08_get;
+       mcp->chip.direction_output = mcp23s08_direction_output;
+       mcp->chip.set = mcp23s08_set;
+       mcp->chip.dbg_show = mcp23s08_dbg_show;
+
+       mcp->chip.base = pdata->base;
+       mcp->chip.ngpio = 8;
+       mcp->chip.can_sleep = 1;
+
+       spi_set_drvdata(spi, mcp);
+
+       /* verify MCP_IOCON.SEQOP = 0, so sequential reads work */
+       status = mcp23s08_read(mcp, MCP_IOCON);
+       if (status < 0)
+               goto fail;
+       if (status & IOCON_SEQOP) {
+               status &= ~IOCON_SEQOP;
+               status = mcp23s08_write(mcp, MCP_IOCON, (u8) status);
+               if (status < 0)
+                       goto fail;
+       }
+
+       /* configure ~100K pullups */
+       status = mcp23s08_write(mcp, MCP_GPPU, pdata->pullups);
+       if (status < 0)
+               goto fail;
+
+       status = mcp23s08_read_regs(mcp, 0, mcp->cache, sizeof mcp->cache);
+       if (status < 0)
+               goto fail;
+
+       /* disable inverter on input */
+       if (mcp->cache[MCP_IPOL] != 0) {
+               mcp->cache[MCP_IPOL] = 0;
+               do_update = 1;
+       }
+
+       /* disable irqs */
+       if (mcp->cache[MCP_GPINTEN] != 0) {
+               mcp->cache[MCP_GPINTEN] = 0;
+               do_update = 1;
+       }
+
+       if (do_update) {
+               u8 tx[4];
+
+               tx[0] = mcp->addr;
+               tx[1] = MCP_IPOL;
+               memcpy(&tx[2], &mcp->cache[MCP_IPOL], sizeof(tx) - 2);
+               status = spi_write_then_read(mcp->spi, tx, sizeof tx, NULL, 0);
+
+               /* FIXME check status... */
+       }
+
+       status = gpiochip_add(&mcp->chip);
+
+       /* NOTE:  these chips have a relatively sane IRQ framework, with
+        * per-signal masking and level/edge triggering.  It's not yet
+        * handled here...
+        */
+
+       if (pdata->setup) {
+               status = pdata->setup(spi, mcp->chip.base,
+                               mcp->chip.ngpio, pdata->context);
+               if (status < 0)
+                       dev_dbg(&spi->dev, "setup --> %d\n", status);
+       }
+
+       return 0;
+
+fail:
+       kfree(mcp);
+       return status;
+}
+
+static int mcp23s08_remove(struct spi_device *spi)
+{
+       struct mcp23s08                 *mcp = spi_get_drvdata(spi);
+       struct mcp23s08_platform_data   *pdata = spi->dev.platform_data;
+       int                             status = 0;
+
+       if (pdata->teardown) {
+               status = pdata->teardown(spi,
+                               mcp->chip.base, mcp->chip.ngpio,
+                               pdata->context);
+               if (status < 0) {
+                       dev_err(&spi->dev, "%s --> %d\n", "teardown", status);
+                       return status;
+               }
+       }
+
+       status = gpiochip_remove(&mcp->chip);
+       if (status == 0)
+               kfree(mcp);
+       else
+               dev_err(&spi->dev, "%s --> %d\n", "remove", status);
+       return status;
+}
+
+static struct spi_driver mcp23s08_driver = {
+       .probe          = mcp23s08_probe,
+       .remove         = mcp23s08_remove,
+       .driver = {
+               .name   = "mcp23s08",
+               .owner  = THIS_MODULE,
+       },
+};
+
+/*----------------------------------------------------------------------*/
+
+static int __init mcp23s08_init(void)
+{
+       return spi_register_driver(&mcp23s08_driver);
+}
+module_init(mcp23s08_init);
+
+static void __exit mcp23s08_exit(void)
+{
+       spi_unregister_driver(&mcp23s08_driver);
+}
+module_exit(mcp23s08_exit);
+
+MODULE_LICENSE("GPL");
+
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
new file mode 100644 (file)
index 0000000..92583cd
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ *  pca953x.c - 4/8/16 bit I/O ports
+ *
+ *  Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
+ *  Copyright (C) 2007 Marvell International Ltd.
+ *
+ *  Derived from drivers/i2c/chips/pca9539.c
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/i2c/pca953x.h>
+
+#include <asm/gpio.h>
+
+#define PCA953X_INPUT          0
+#define PCA953X_OUTPUT         1
+#define PCA953X_INVERT         2
+#define PCA953X_DIRECTION      3
+
+/* This is temporary - in 2.6.26 i2c_driver_data should replace it. */
+struct pca953x_desc {
+       char            name[I2C_NAME_SIZE];
+       unsigned long   driver_data;
+};
+
+static const struct pca953x_desc pca953x_descs[] = {
+       { "pca9534", 8, },
+       { "pca9535", 16, },
+       { "pca9536", 4, },
+       { "pca9537", 4, },
+       { "pca9538", 8, },
+       { "pca9539", 16, },
+       /* REVISIT several pca955x parts should work here too */
+};
+
+struct pca953x_chip {
+       unsigned gpio_start;
+       uint16_t reg_output;
+       uint16_t reg_direction;
+
+       struct i2c_client *client;
+       struct gpio_chip gpio_chip;
+};
+
+/* NOTE:  we can't currently rely on fault codes to come from SMBus
+ * calls, so we map all errors to EIO here and return zero otherwise.
+ */
+static int pca953x_write_reg(struct pca953x_chip *chip, int reg, uint16_t val)
+{
+       int ret;
+
+       if (chip->gpio_chip.ngpio <= 8)
+               ret = i2c_smbus_write_byte_data(chip->client, reg, val);
+       else
+               ret = i2c_smbus_write_word_data(chip->client, reg << 1, val);
+
+       if (ret < 0) {
+               dev_err(&chip->client->dev, "failed writing register\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+static int pca953x_read_reg(struct pca953x_chip *chip, int reg, uint16_t *val)
+{
+       int ret;
+
+       if (chip->gpio_chip.ngpio <= 8)
+               ret = i2c_smbus_read_byte_data(chip->client, reg);
+       else
+               ret = i2c_smbus_read_word_data(chip->client, reg << 1);
+
+       if (ret < 0) {
+               dev_err(&chip->client->dev, "failed reading register\n");
+               return -EIO;
+       }
+
+       *val = (uint16_t)ret;
+       return 0;
+}
+
+static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
+{
+       struct pca953x_chip *chip;
+       uint16_t reg_val;
+       int ret;
+
+       chip = container_of(gc, struct pca953x_chip, gpio_chip);
+
+       reg_val = chip->reg_direction | (1u << off);
+       ret = pca953x_write_reg(chip, PCA953X_DIRECTION, reg_val);
+       if (ret)
+               return ret;
+
+       chip->reg_direction = reg_val;
+       return 0;
+}
+
+static int pca953x_gpio_direction_output(struct gpio_chip *gc,
+               unsigned off, int val)
+{
+       struct pca953x_chip *chip;
+       uint16_t reg_val;
+       int ret;
+
+       chip = container_of(gc, struct pca953x_chip, gpio_chip);
+
+       /* set output level */
+       if (val)
+               reg_val = chip->reg_output | (1u << off);
+       else
+               reg_val = chip->reg_output & ~(1u << off);
+
+       ret = pca953x_write_reg(chip, PCA953X_OUTPUT, reg_val);
+       if (ret)
+               return ret;
+
+       chip->reg_output = reg_val;
+
+       /* then direction */
+       reg_val = chip->reg_direction & ~(1u << off);
+       ret = pca953x_write_reg(chip, PCA953X_DIRECTION, reg_val);
+       if (ret)
+               return ret;
+
+       chip->reg_direction = reg_val;
+       return 0;
+}
+
+static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off)
+{
+       struct pca953x_chip *chip;
+       uint16_t reg_val;
+       int ret;
+
+       chip = container_of(gc, struct pca953x_chip, gpio_chip);
+
+       ret = pca953x_read_reg(chip, PCA953X_INPUT, &reg_val);
+       if (ret < 0) {
+               /* NOTE:  diagnostic already emitted; that's all we should
+                * do unless gpio_*_value_cansleep() calls become different
+                * from their nonsleeping siblings (and report faults).
+                */
+               return 0;
+       }
+
+       return (reg_val & (1u << off)) ? 1 : 0;
+}
+
+static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
+{
+       struct pca953x_chip *chip;
+       uint16_t reg_val;
+       int ret;
+
+       chip = container_of(gc, struct pca953x_chip, gpio_chip);
+
+       if (val)
+               reg_val = chip->reg_output | (1u << off);
+       else
+               reg_val = chip->reg_output & ~(1u << off);
+
+       ret = pca953x_write_reg(chip, PCA953X_OUTPUT, reg_val);
+       if (ret)
+               return;
+
+       chip->reg_output = reg_val;
+}
+
+static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
+{
+       struct gpio_chip *gc;
+
+       gc = &chip->gpio_chip;
+
+       gc->direction_input  = pca953x_gpio_direction_input;
+       gc->direction_output = pca953x_gpio_direction_output;
+       gc->get = pca953x_gpio_get_value;
+       gc->set = pca953x_gpio_set_value;
+
+       gc->base = chip->gpio_start;
+       gc->ngpio = gpios;
+       gc->label = chip->client->name;
+}
+
+static int __devinit pca953x_probe(struct i2c_client *client)
+{
+       struct pca953x_platform_data *pdata;
+       struct pca953x_chip *chip;
+       int ret, i;
+       const struct pca953x_desc *id = NULL;
+
+       pdata = client->dev.platform_data;
+       if (pdata == NULL)
+               return -ENODEV;
+
+       /* this loop vanishes when we get i2c_device_id */
+       for (i = 0; i < ARRAY_SIZE(pca953x_descs); i++)
+               if (!strcmp(pca953x_descs[i].name, client->name)) {
+                       id = pca953x_descs + i;
+                       break;
+               }
+       if (!id)
+               return -ENODEV;
+
+       chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
+       if (chip == NULL)
+               return -ENOMEM;
+
+       chip->client = client;
+
+       chip->gpio_start = pdata->gpio_base;
+
+       /* initialize cached registers from their original values.
+        * we can't share this chip with another i2c master.
+        */
+       pca953x_setup_gpio(chip, id->driver_data);
+
+       ret = pca953x_read_reg(chip, PCA953X_OUTPUT, &chip->reg_output);
+       if (ret)
+               goto out_failed;
+
+       ret = pca953x_read_reg(chip, PCA953X_DIRECTION, &chip->reg_direction);
+       if (ret)
+               goto out_failed;
+
+       /* set platform specific polarity inversion */
+       ret = pca953x_write_reg(chip, PCA953X_INVERT, pdata->invert);
+       if (ret)
+               goto out_failed;
+
+
+       ret = gpiochip_add(&chip->gpio_chip);
+       if (ret)
+               goto out_failed;
+
+       if (pdata->setup) {
+               ret = pdata->setup(client, chip->gpio_chip.base,
+                               chip->gpio_chip.ngpio, pdata->context);
+               if (ret < 0)
+                       dev_warn(&client->dev, "setup failed, %d\n", ret);
+       }
+
+       i2c_set_clientdata(client, chip);
+       return 0;
+
+out_failed:
+       kfree(chip);
+       return ret;
+}
+
+static int pca953x_remove(struct i2c_client *client)
+{
+       struct pca953x_platform_data *pdata = client->dev.platform_data;
+       struct pca953x_chip *chip = i2c_get_clientdata(client);
+       int ret = 0;
+
+       if (pdata->teardown) {
+               ret = pdata->teardown(client, chip->gpio_chip.base,
+                               chip->gpio_chip.ngpio, pdata->context);
+               if (ret < 0) {
+                       dev_err(&client->dev, "%s failed, %d\n",
+                                       "teardown", ret);
+                       return ret;
+               }
+       }
+
+       ret = gpiochip_remove(&chip->gpio_chip);
+       if (ret) {
+               dev_err(&client->dev, "%s failed, %d\n",
+                               "gpiochip_remove()", ret);
+               return ret;
+       }
+
+       kfree(chip);
+       return 0;
+}
+
+static struct i2c_driver pca953x_driver = {
+       .driver = {
+               .name   = "pca953x",
+       },
+       .probe          = pca953x_probe,
+       .remove         = pca953x_remove,
+};
+
+static int __init pca953x_init(void)
+{
+       return i2c_add_driver(&pca953x_driver);
+}
+module_init(pca953x_init);
+
+static void __exit pca953x_exit(void)
+{
+       i2c_del_driver(&pca953x_driver);
+}
+module_exit(pca953x_exit);
+
+MODULE_AUTHOR("eric miao <eric.miao@marvell.com>");
+MODULE_DESCRIPTION("GPIO expander driver for PCA953x");
+MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
new file mode 100644 (file)
index 0000000..c6b3b53
--- /dev/null
@@ -0,0 +1,330 @@
+/*
+ * pcf857x - driver for pcf857x, pca857x, and pca967x I2C GPIO expanders
+ *
+ * Copyright (C) 2007 David Brownell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/i2c/pcf857x.h>
+
+#include <asm/gpio.h>
+
+
+/*
+ * The pcf857x, pca857x, and pca967x chips only expose one read and one
+ * write register.  Writing a "one" bit (to match the reset state) lets
+ * that pin be used as an input; it's not an open-drain model, but acts
+ * a bit like one.  This is described as "quasi-bidirectional"; read the
+ * chip documentation for details.
+ *
+ * Many other I2C GPIO expander chips (like the pca953x models) have
+ * more complex register models and more conventional circuitry using
+ * push/pull drivers.  They often use the same 0x20..0x27 addresses as
+ * pcf857x parts, making the "legacy" I2C driver model problematic.
+ */
+struct pcf857x {
+       struct gpio_chip        chip;
+       struct i2c_client       *client;
+       unsigned                out;            /* software latch */
+};
+
+/*-------------------------------------------------------------------------*/
+
+/* Talk to 8-bit I/O expander */
+
+static int pcf857x_input8(struct gpio_chip *chip, unsigned offset)
+{
+       struct pcf857x  *gpio = container_of(chip, struct pcf857x, chip);
+
+       gpio->out |= (1 << offset);
+       return i2c_smbus_write_byte(gpio->client, gpio->out);
+}
+
+static int pcf857x_get8(struct gpio_chip *chip, unsigned offset)
+{
+       struct pcf857x  *gpio = container_of(chip, struct pcf857x, chip);
+       s32             value;
+
+       value = i2c_smbus_read_byte(gpio->client);
+       return (value < 0) ? 0 : (value & (1 << offset));
+}
+
+static int pcf857x_output8(struct gpio_chip *chip, unsigned offset, int value)
+{
+       struct pcf857x  *gpio = container_of(chip, struct pcf857x, chip);
+       unsigned        bit = 1 << offset;
+
+       if (value)
+               gpio->out |= bit;
+       else
+               gpio->out &= ~bit;
+       return i2c_smbus_write_byte(gpio->client, gpio->out);
+}
+
+static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value)
+{
+       pcf857x_output8(chip, offset, value);
+}
+
+/*-------------------------------------------------------------------------*/
+
+/* Talk to 16-bit I/O expander */
+
+static int i2c_write_le16(struct i2c_client *client, u16 word)
+{
+       u8 buf[2] = { word & 0xff, word >> 8, };
+       int status;
+
+       status = i2c_master_send(client, buf, 2);
+       return (status < 0) ? status : 0;
+}
+
+static int i2c_read_le16(struct i2c_client *client)
+{
+       u8 buf[2];
+       int status;
+
+       status = i2c_master_recv(client, buf, 2);
+       if (status < 0)
+               return status;
+       return (buf[1] << 8) | buf[0];
+}
+
+static int pcf857x_input16(struct gpio_chip *chip, unsigned offset)
+{
+       struct pcf857x  *gpio = container_of(chip, struct pcf857x, chip);
+
+       gpio->out |= (1 << offset);
+       return i2c_write_le16(gpio->client, gpio->out);
+}
+
+static int pcf857x_get16(struct gpio_chip *chip, unsigned offset)
+{
+       struct pcf857x  *gpio = container_of(chip, struct pcf857x, chip);
+       int             value;
+
+       value = i2c_read_le16(gpio->client);
+       return (value < 0) ? 0 : (value & (1 << offset));
+}
+
+static int pcf857x_output16(struct gpio_chip *chip, unsigned offset, int value)
+{
+       struct pcf857x  *gpio = container_of(chip, struct pcf857x, chip);
+       unsigned        bit = 1 << offset;
+
+       if (value)
+               gpio->out |= bit;
+       else
+               gpio->out &= ~bit;
+       return i2c_write_le16(gpio->client, gpio->out);
+}
+
+static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value)
+{
+       pcf857x_output16(chip, offset, value);
+}
+
+/*-------------------------------------------------------------------------*/
+
+static int pcf857x_probe(struct i2c_client *client)
+{
+       struct pcf857x_platform_data    *pdata;
+       struct pcf857x                  *gpio;
+       int                             status;
+
+       pdata = client->dev.platform_data;
+       if (!pdata)
+               return -ENODEV;
+
+       /* Allocate, initialize, and register this gpio_chip. */
+       gpio = kzalloc(sizeof *gpio, GFP_KERNEL);
+       if (!gpio)
+               return -ENOMEM;
+
+       gpio->chip.base = pdata->gpio_base;
+       gpio->chip.can_sleep = 1;
+
+       /* NOTE:  the OnSemi jlc1562b is also largely compatible with
+        * these parts, notably for output.  It has a low-resolution
+        * DAC instead of pin change IRQs; and its inputs can be the
+        * result of comparators.
+        */
+
+       /* 8574 addresses are 0x20..0x27; 8574a uses 0x38..0x3f;
+        * 9670, 9672, 9764, and 9764a use quite a variety.
+        *
+        * NOTE: we don't distinguish here between *4 and *4a parts.
+        */
+       if (strcmp(client->name, "pcf8574") == 0
+                       || strcmp(client->name, "pca8574") == 0
+                       || strcmp(client->name, "pca9670") == 0
+                       || strcmp(client->name, "pca9672") == 0
+                       || strcmp(client->name, "pca9674") == 0
+                       ) {
+               gpio->chip.ngpio = 8;
+               gpio->chip.direction_input = pcf857x_input8;
+               gpio->chip.get = pcf857x_get8;
+               gpio->chip.direction_output = pcf857x_output8;
+               gpio->chip.set = pcf857x_set8;
+
+               if (!i2c_check_functionality(client->adapter,
+                               I2C_FUNC_SMBUS_BYTE))
+                       status = -EIO;
+
+               /* fail if there's no chip present */
+               else
+                       status = i2c_smbus_read_byte(client);
+
+       /* '75/'75c addresses are 0x20..0x27, just like the '74;
+        * the '75c doesn't have a current source pulling high.
+        * 9671, 9673, and 9765 use quite a variety of addresses.
+        *
+        * NOTE: we don't distinguish here between '75 and '75c parts.
+        */
+       } else if (strcmp(client->name, "pcf8575") == 0
+                       || strcmp(client->name, "pca8575") == 0
+                       || strcmp(client->name, "pca9671") == 0
+                       || strcmp(client->name, "pca9673") == 0
+                       || strcmp(client->name, "pca9675") == 0
+                       ) {
+               gpio->chip.ngpio = 16;
+               gpio->chip.direction_input = pcf857x_input16;
+               gpio->chip.get = pcf857x_get16;
+               gpio->chip.direction_output = pcf857x_output16;
+               gpio->chip.set = pcf857x_set16;
+
+               if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+                       status = -EIO;
+
+               /* fail if there's no chip present */
+               else
+                       status = i2c_read_le16(client);
+
+       } else
+               status = -ENODEV;
+
+       if (status < 0)
+               goto fail;
+
+       gpio->chip.label = client->name;
+
+       gpio->client = client;
+       i2c_set_clientdata(client, gpio);
+
+       /* NOTE:  these chips have strange "quasi-bidirectional" I/O pins.
+        * We can't actually know whether a pin is configured (a) as output
+        * and driving the signal low, or (b) as input and reporting a low
+        * value ... without knowing the last value written since the chip
+        * came out of reset (if any).  We can't read the latched output.
+        *
+        * In short, the only reliable solution for setting up pin direction
+        * is to do it explicitly.  The setup() method can do that, but it
+        * may cause transient glitching since it can't know the last value
+        * written (some pins may need to be driven low).
+        *
+        * Using pdata->n_latch avoids that trouble.  When left initialized
+        * to zero, our software copy of the "latch" then matches the chip's
+        * all-ones reset state.  Otherwise it flags pins to be driven low.
+        */
+       gpio->out = ~pdata->n_latch;
+
+       status = gpiochip_add(&gpio->chip);
+       if (status < 0)
+               goto fail;
+
+       /* NOTE: these chips can issue "some pin-changed" IRQs, which we
+        * don't yet even try to use.  Among other issues, the relevant
+        * genirq state isn't available to modular drivers; and most irq
+        * methods can't be called from sleeping contexts.
+        */
+
+       dev_info(&client->dev, "gpios %d..%d on a %s%s\n",
+                       gpio->chip.base,
+                       gpio->chip.base + gpio->chip.ngpio - 1,
+                       client->name,
+                       client->irq ? " (irq ignored)" : "");
+
+       /* Let platform code set up the GPIOs and their users.
+        * Now is the first time anyone could use them.
+        */
+       if (pdata->setup) {
+               status = pdata->setup(client,
+                               gpio->chip.base, gpio->chip.ngpio,
+                               pdata->context);
+               if (status < 0)
+                       dev_warn(&client->dev, "setup --> %d\n", status);
+       }
+
+       return 0;
+
+fail:
+       dev_dbg(&client->dev, "probe error %d for '%s'\n",
+                       status, client->name);
+       kfree(gpio);
+       return status;
+}
+
+static int pcf857x_remove(struct i2c_client *client)
+{
+       struct pcf857x_platform_data    *pdata = client->dev.platform_data;
+       struct pcf857x                  *gpio = i2c_get_clientdata(client);
+       int                             status = 0;
+
+       if (pdata->teardown) {
+               status = pdata->teardown(client,
+                               gpio->chip.base, gpio->chip.ngpio,
+                               pdata->context);
+               if (status < 0) {
+                       dev_err(&client->dev, "%s --> %d\n",
+                                       "teardown", status);
+                       return status;
+               }
+       }
+
+       status = gpiochip_remove(&gpio->chip);
+       if (status == 0)
+               kfree(gpio);
+       else
+               dev_err(&client->dev, "%s --> %d\n", "remove", status);
+       return status;
+}
+
+static struct i2c_driver pcf857x_driver = {
+       .driver = {
+               .name   = "pcf857x",
+               .owner  = THIS_MODULE,
+       },
+       .probe  = pcf857x_probe,
+       .remove = pcf857x_remove,
+};
+
+static int __init pcf857x_init(void)
+{
+       return i2c_add_driver(&pcf857x_driver);
+}
+module_init(pcf857x_init);
+
+static void __exit pcf857x_exit(void)
+{
+       i2c_del_driver(&pcf857x_driver);
+}
+module_exit(pcf857x_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Brownell");
index e6c4a2b762ec955497864f860815fb027d9aa275..f5e7a70da831b1c54b51e081bdf0c1a0bc6ef1f8 100644 (file)
@@ -492,7 +492,7 @@ static __init int scx200_create_pci(const char *text, struct pci_dev *pdev,
        iface->pdev = pdev;
        iface->bar = bar;
 
-       rc = pci_enable_device_bars(iface->pdev, 1 << iface->bar);
+       rc = pci_enable_device_io(iface->pdev);
        if (rc)
                goto errout_free;
 
index bd7082c2443dbd5336553ccbb18bca9c62ec7fea..b21593f93586adc191cf43178c06d1166bf0ed6b 100644 (file)
@@ -54,8 +54,8 @@ config PCF8575
          hardware.  If unsure, say N.
 
 config SENSORS_PCA9539
-       tristate "Philips PCA9539 16-bit I/O port"
-       depends on EXPERIMENTAL
+       tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)"
+       depends on EXPERIMENTAL && GPIO_PCA9539 = "n"
        help
          If you say yes here you get support for the Philips PCA9539
          16-bit I/O port.
@@ -63,6 +63,9 @@ config SENSORS_PCA9539
          This driver can also be built as a module.  If so, the module
          will be called pca9539.
 
+         This driver is deprecated and will be dropped soon. Use
+         drivers/gpio/pca9539.c instead.
+
 config SENSORS_PCF8591
        tristate "Philips PCF8591"
        depends on EXPERIMENTAL
index e42a465f57177029dcdd594fc8e3147da49054fe..ab8fb257528ed51cb4e9bac0abb0710ce7543fbb 100644 (file)
@@ -216,8 +216,7 @@ config BLK_DEV_IDECD_VERBOSE_ERRORS
          memory, though.
 
 config BLK_DEV_IDETAPE
-       tristate "Include IDE/ATAPI TAPE support (EXPERIMENTAL)"
-       depends on EXPERIMENTAL
+       tristate "Include IDE/ATAPI TAPE support"
        help
          If you have an IDE tape drive using the ATAPI protocol, say Y.
          ATAPI is a newer protocol used by IDE tape and CD-ROM drives,
@@ -1010,6 +1009,15 @@ config BLK_DEV_Q40IDE
          normally be on; disable it only if you are running a custom hard
          drive subsystem through an expansion card.
 
+config BLK_DEV_PALMCHIP_BK3710
+       tristate "Palmchip bk3710 IDE controller support"
+       depends on ARCH_DAVINCI
+       select BLK_DEV_IDEDMA_PCI
+       help
+         Say Y here if you want to support the onchip IDE controller on the
+         TI DaVinci SoC
+
+
 config BLK_DEV_MPC8xx_IDE
        tristate "MPC8xx IDE support"
        depends on 8xx && (LWMON || IVMS8 || IVML24 || TQM8xxL) && IDE=y && BLK_DEV_IDE=y && !PPC_MERGE
index 5f63ad216862e50fd1d583384cc61a83d2dd182f..936e7b0237f5499fe0305845679c12a96d025d16 100644 (file)
@@ -2,6 +2,7 @@
 obj-$(CONFIG_BLK_DEV_IDE_ICSIDE)       += icside.o
 obj-$(CONFIG_BLK_DEV_IDE_RAPIDE)       += rapide.o
 obj-$(CONFIG_BLK_DEV_IDE_BAST)         += bast-ide.o
+obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710)  += palm_bk3710.o
 
 ifeq ($(CONFIG_IDE_ARM), m)
        obj-m += ide_arm.o
index 037300fa284c6ba741ddcf53f68ab2c037154129..0e7574c0ee60bcbfa48c75ef8f3843b71c44bac5 100644 (file)
@@ -28,8 +28,10 @@ static int __init
 bastide_register(unsigned int base, unsigned int aux, int irq,
                 ide_hwif_t **hwif)
 {
+       ide_hwif_t *hwif;
        hw_regs_t hw;
        int i;
+       u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
 
        memset(&hw, 0, sizeof(hw));
 
@@ -44,8 +46,24 @@ bastide_register(unsigned int base, unsigned int aux, int irq,
        hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20);
        hw.irq = irq;
 
-       ide_register_hw(&hw, NULL, hwif);
+       hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]);
+       if (hwif == NULL)
+               goto out;
 
+       i = hwif->index;
+
+       if (hwif->present)
+               ide_unregister(i, 0, 0);
+       else if (!hwif->hold)
+               ide_init_port_data(hwif, i);
+
+       ide_init_port_hw(hwif, &hw);
+       hwif->quirkproc = NULL;
+
+       idx[0] = i;
+
+       ide_device_add(idx, NULL);
+out:
        return 0;
 }
 
index 8d2cc47a362e1cf1f9d21186a6c0116eda2f2ce5..e816b0ffcfe647a1899161225708014271316517 100644 (file)
@@ -365,7 +365,7 @@ static void icside_dma_timeout(ide_drive_t *drive)
        if (icside_dma_test_irq(drive))
                return;
 
-       ide_dump_status(drive, "DMA timeout", HWIF(drive)->INB(IDE_STATUS_REG));
+       ide_dump_status(drive, "DMA timeout", ide_read_status(drive));
 
        icside_dma_end(drive);
 }
@@ -377,9 +377,6 @@ static void icside_dma_lost_irq(ide_drive_t *drive)
 
 static void icside_dma_init(ide_hwif_t *hwif)
 {
-       hwif->mwdma_mask        = 7; /* MW0..2 */
-       hwif->swdma_mask        = 7; /* SW0..2 */
-
        hwif->dmatable_cpu      = NULL;
        hwif->dmatable_dma      = 0;
        hwif->set_dma_mode      = icside_set_dma_mode;
@@ -459,11 +456,19 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
 
        idx[0] = hwif->index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, NULL);
 
        return 0;
 }
 
+static const struct ide_port_info icside_v6_port_info __initdata = {
+       .host_flags             = IDE_HFLAG_SERIALIZE |
+                                 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
+                                 IDE_HFLAG_NO_AUTOTUNE,
+       .mwdma_mask             = ATA_MWDMA2,
+       .swdma_mask             = ATA_SWDMA2,
+};
+
 static int __init
 icside_register_v6(struct icside_state *state, struct expansion_card *ec)
 {
@@ -472,6 +477,7 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
        unsigned int sel = 0;
        int ret;
        u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
+       struct ide_port_info d = icside_v6_port_info;
 
        ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
        if (!ioc_base) {
@@ -521,30 +527,25 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
        state->hwif[1]    = mate;
 
        hwif->maskproc    = icside_maskproc;
-       hwif->channel     = 0;
        hwif->hwif_data   = state;
-       hwif->mate        = mate;
-       hwif->serialized  = 1;
        hwif->config_data = (unsigned long)ioc_base;
        hwif->select_data = sel;
 
        mate->maskproc    = icside_maskproc;
-       mate->channel     = 1;
        mate->hwif_data   = state;
-       mate->mate        = hwif;
-       mate->serialized  = 1;
        mate->config_data = (unsigned long)ioc_base;
        mate->select_data = sel | 1;
 
        if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) {
                icside_dma_init(hwif);
                icside_dma_init(mate);
-       }
+       } else
+               d.mwdma_mask = d.swdma_mask = 0;
 
        idx[0] = hwif->index;
        idx[1] = mate->index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, &d);
 
        return 0;
 
index 60f2497542c05048d9a3f9b5e1a780d8717426f3..43a70e91363e0b2eed2cdde591a4ffb345c388f3 100644 (file)
@@ -39,7 +39,7 @@ static int __init ide_arm_init(void)
                ide_init_port_hw(hwif, &hw);
                idx[0] = hwif->index;
 
-               ide_device_add(idx);
+               ide_device_add(idx, NULL);
        }
 
        return 0;
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c
new file mode 100644 (file)
index 0000000..c306997
--- /dev/null
@@ -0,0 +1,395 @@
+/*
+ * Palmchip bk3710 IDE controller
+ *
+ * Copyright (C) 2006 Texas Instruments.
+ * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
+ *
+ * ----------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * ----------------------------------------------------------------------------
+ *
+ */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/ioport.h>
+#include <linux/hdreg.h>
+#include <linux/ide.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+
+/* Offset of the primary interface registers */
+#define IDE_PALM_ATA_PRI_REG_OFFSET 0x1F0
+
+/* Primary Control Offset */
+#define IDE_PALM_ATA_PRI_CTL_OFFSET 0x3F6
+
+/*
+ * PalmChip 3710 IDE Controller UDMA timing structure Definition
+ */
+struct palm_bk3710_udmatiming {
+       unsigned int rptime;    /* Ready to pause time  */
+       unsigned int cycletime; /* Cycle Time           */
+};
+
+#define BK3710_BMICP           0x00
+#define BK3710_BMISP           0x02
+#define BK3710_BMIDTP          0x04
+#define BK3710_BMICS           0x08
+#define BK3710_BMISS           0x0A
+#define BK3710_BMIDTS          0x0C
+#define BK3710_IDETIMP         0x40
+#define BK3710_IDETIMS         0x42
+#define BK3710_SIDETIM         0x44
+#define BK3710_SLEWCTL         0x45
+#define BK3710_IDESTATUS       0x47
+#define BK3710_UDMACTL         0x48
+#define BK3710_UDMATIM         0x4A
+#define BK3710_MISCCTL         0x50
+#define BK3710_REGSTB          0x54
+#define BK3710_REGRCVR         0x58
+#define BK3710_DATSTB          0x5C
+#define BK3710_DATRCVR         0x60
+#define BK3710_DMASTB          0x64
+#define BK3710_DMARCVR         0x68
+#define BK3710_UDMASTB         0x6C
+#define BK3710_UDMATRP         0x70
+#define BK3710_UDMAENV         0x74
+#define BK3710_IORDYTMP                0x78
+#define BK3710_IORDYTMS                0x7C
+
+#include "../ide-timing.h"
+
+static long ide_palm_clk;
+
+static const struct palm_bk3710_udmatiming palm_bk3710_udmatimings[6] = {
+       {160, 240},             /* UDMA Mode 0 */
+       {125, 160},             /* UDMA Mode 1 */
+       {100, 120},             /* UDMA Mode 2 */
+       {100, 90},              /* UDMA Mode 3 */
+       {85,  60},              /* UDMA Mode 4 */
+};
+
+static struct clk *ideclkp;
+
+static void palm_bk3710_setudmamode(void __iomem *base, unsigned int dev,
+                                   unsigned int mode)
+{
+       u8 tenv, trp, t0;
+       u32 val32;
+       u16 val16;
+
+       /* DMA Data Setup */
+       t0 = (palm_bk3710_udmatimings[mode].cycletime + ide_palm_clk - 1)
+                       / ide_palm_clk - 1;
+       tenv = (20 + ide_palm_clk - 1) / ide_palm_clk - 1;
+       trp = (palm_bk3710_udmatimings[mode].rptime + ide_palm_clk - 1)
+                       / ide_palm_clk - 1;
+
+       /* udmatim Register */
+       val16 = readw(base + BK3710_UDMATIM) & (dev ? 0xFF0F : 0xFFF0);
+       val16 |= (mode << (dev ? 4 : 0));
+       writew(val16, base + BK3710_UDMATIM);
+
+       /* udmastb Ultra DMA Access Strobe Width */
+       val32 = readl(base + BK3710_UDMASTB) & (0xFF << (dev ? 0 : 8));
+       val32 |= (t0 << (dev ? 8 : 0));
+       writel(val32, base + BK3710_UDMASTB);
+
+       /* udmatrp Ultra DMA Ready to Pause Time */
+       val32 = readl(base + BK3710_UDMATRP) & (0xFF << (dev ? 0 : 8));
+       val32 |= (trp << (dev ? 8 : 0));
+       writel(val32, base + BK3710_UDMATRP);
+
+       /* udmaenv Ultra DMA envelop Time */
+       val32 = readl(base + BK3710_UDMAENV) & (0xFF << (dev ? 0 : 8));
+       val32 |= (tenv << (dev ? 8 : 0));
+       writel(val32, base + BK3710_UDMAENV);
+
+       /* Enable UDMA for Device */
+       val16 = readw(base + BK3710_UDMACTL) | (1 << dev);
+       writew(val16, base + BK3710_UDMACTL);
+}
+
+static void palm_bk3710_setdmamode(void __iomem *base, unsigned int dev,
+                                  unsigned short min_cycle,
+                                  unsigned int mode)
+{
+       u8 td, tkw, t0;
+       u32 val32;
+       u16 val16;
+       struct ide_timing *t;
+       int cycletime;
+
+       t = ide_timing_find_mode(mode);
+       cycletime = max_t(int, t->cycle, min_cycle);
+
+       /* DMA Data Setup */
+       t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk;
+       td = (t->active + ide_palm_clk - 1) / ide_palm_clk;
+       tkw = t0 - td - 1;
+       td -= 1;
+
+       val32 = readl(base + BK3710_DMASTB) & (0xFF << (dev ? 0 : 8));
+       val32 |= (td << (dev ? 8 : 0));
+       writel(val32, base + BK3710_DMASTB);
+
+       val32 = readl(base + BK3710_DMARCVR) & (0xFF << (dev ? 0 : 8));
+       val32 |= (tkw << (dev ? 8 : 0));
+       writel(val32, base + BK3710_DMARCVR);
+
+       /* Disable UDMA for Device */
+       val16 = readw(base + BK3710_UDMACTL) & ~(1 << dev);
+       writew(val16, base + BK3710_UDMACTL);
+}
+
+static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
+                                  unsigned int dev, unsigned int cycletime,
+                                  unsigned int mode)
+{
+       u8 t2, t2i, t0;
+       u32 val32;
+       struct ide_timing *t;
+
+       /* PIO Data Setup */
+       t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk;
+       t2 = (ide_timing_find_mode(XFER_PIO_0 + mode)->active +
+             ide_palm_clk - 1) / ide_palm_clk;
+
+       t2i = t0 - t2 - 1;
+       t2 -= 1;
+
+       val32 = readl(base + BK3710_DATSTB) & (0xFF << (dev ? 0 : 8));
+       val32 |= (t2 << (dev ? 8 : 0));
+       writel(val32, base + BK3710_DATSTB);
+
+       val32 = readl(base + BK3710_DATRCVR) & (0xFF << (dev ? 0 : 8));
+       val32 |= (t2i << (dev ? 8 : 0));
+       writel(val32, base + BK3710_DATRCVR);
+
+       if (mate && mate->present) {
+               u8 mode2 = ide_get_best_pio_mode(mate, 255, 4);
+
+               if (mode2 < mode)
+                       mode = mode2;
+       }
+
+       /* TASKFILE Setup */
+       t = ide_timing_find_mode(XFER_PIO_0 + mode);
+       t0 = (t->cyc8b + ide_palm_clk - 1) / ide_palm_clk;
+       t2 = (t->act8b + ide_palm_clk - 1) / ide_palm_clk;
+
+       t2i = t0 - t2 - 1;
+       t2 -= 1;
+
+       val32 = readl(base + BK3710_REGSTB) & (0xFF << (dev ? 0 : 8));
+       val32 |= (t2 << (dev ? 8 : 0));
+       writel(val32, base + BK3710_REGSTB);
+
+       val32 = readl(base + BK3710_REGRCVR) & (0xFF << (dev ? 0 : 8));
+       val32 |= (t2i << (dev ? 8 : 0));
+       writel(val32, base + BK3710_REGRCVR);
+}
+
+static void palm_bk3710_set_dma_mode(ide_drive_t *drive, u8 xferspeed)
+{
+       int is_slave = drive->dn & 1;
+       void __iomem *base = (void *)drive->hwif->dma_base;
+
+       if (xferspeed >= XFER_UDMA_0) {
+               palm_bk3710_setudmamode(base, is_slave,
+                                       xferspeed - XFER_UDMA_0);
+       } else {
+               palm_bk3710_setdmamode(base, is_slave, drive->id->eide_dma_min,
+                                      xferspeed);
+       }
+}
+
+static void palm_bk3710_set_pio_mode(ide_drive_t *drive, u8 pio)
+{
+       unsigned int cycle_time;
+       int is_slave = drive->dn & 1;
+       ide_drive_t *mate;
+       void __iomem *base = (void *)drive->hwif->dma_base;
+
+       /*
+        * Obtain the drive PIO data for tuning the Palm Chip registers
+        */
+       cycle_time = ide_pio_cycle_time(drive, pio);
+       mate = ide_get_paired_drive(drive);
+       palm_bk3710_setpiomode(base, mate, is_slave, cycle_time, pio);
+}
+
+static void __devinit palm_bk3710_chipinit(void __iomem *base)
+{
+       /*
+        * enable the reset_en of ATA controller so that when ata signals
+        * are brought out, by writing into device config. at that
+        * time por_n signal should not be 'Z' and have a stable value.
+        */
+       writel(0x0300, base + BK3710_MISCCTL);
+
+       /* wait for some time and deassert the reset of ATA Device. */
+       mdelay(100);
+
+       /* Deassert the Reset */
+       writel(0x0200, base + BK3710_MISCCTL);
+
+       /*
+        * Program the IDETIMP Register Value based on the following assumptions
+        *
+        * (ATA_IDETIMP_IDEEN           , ENABLE ) |
+        * (ATA_IDETIMP_SLVTIMEN        , DISABLE) |
+        * (ATA_IDETIMP_RDYSMPL         , 70NS)    |
+        * (ATA_IDETIMP_RDYRCVRY        , 50NS)    |
+        * (ATA_IDETIMP_DMAFTIM1        , PIOCOMP) |
+        * (ATA_IDETIMP_PREPOST1        , DISABLE) |
+        * (ATA_IDETIMP_RDYSEN1         , DISABLE) |
+        * (ATA_IDETIMP_PIOFTIM1        , DISABLE) |
+        * (ATA_IDETIMP_DMAFTIM0        , PIOCOMP) |
+        * (ATA_IDETIMP_PREPOST0        , DISABLE) |
+        * (ATA_IDETIMP_RDYSEN0         , DISABLE) |
+        * (ATA_IDETIMP_PIOFTIM0        , DISABLE)
+        */
+       writew(0xB388, base + BK3710_IDETIMP);
+
+       /*
+        * Configure  SIDETIM  Register
+        * (ATA_SIDETIM_RDYSMPS1        ,120NS ) |
+        * (ATA_SIDETIM_RDYRCYS1        ,120NS )
+        */
+       writeb(0, base + BK3710_SIDETIM);
+
+       /*
+        * UDMACTL Ultra-ATA DMA Control
+        * (ATA_UDMACTL_UDMAP1  , 0 ) |
+        * (ATA_UDMACTL_UDMAP0  , 0 )
+        *
+        */
+       writew(0, base + BK3710_UDMACTL);
+
+       /*
+        * MISCCTL Miscellaneous Conrol Register
+        * (ATA_MISCCTL_RSTMODEP        , 1) |
+        * (ATA_MISCCTL_RESETP          , 0) |
+        * (ATA_MISCCTL_TIMORIDE        , 1)
+        */
+       writel(0x201, base + BK3710_MISCCTL);
+
+       /*
+        * IORDYTMP IORDY Timer for Primary Register
+        * (ATA_IORDYTMP_IORDYTMP     , 0xffff  )
+        */
+       writel(0xFFFF, base + BK3710_IORDYTMP);
+
+       /*
+        * Configure BMISP Register
+        * (ATA_BMISP_DMAEN1    , DISABLE )     |
+        * (ATA_BMISP_DMAEN0    , DISABLE )     |
+        * (ATA_BMISP_IORDYINT  , CLEAR)        |
+        * (ATA_BMISP_INTRSTAT  , CLEAR)        |
+        * (ATA_BMISP_DMAERROR  , CLEAR)
+        */
+       writew(0, base + BK3710_BMISP);
+
+       palm_bk3710_setpiomode(base, NULL, 0, 600, 0);
+       palm_bk3710_setpiomode(base, NULL, 1, 600, 0);
+}
+static int __devinit palm_bk3710_probe(struct platform_device *pdev)
+{
+       hw_regs_t ide_ctlr_info;
+       int index = 0;
+       int pribase;
+       struct clk *clkp;
+       struct resource *mem, *irq;
+       ide_hwif_t *hwif;
+       void __iomem *base;
+
+       clkp = clk_get(NULL, "IDECLK");
+       if (IS_ERR(clkp))
+               return -ENODEV;
+
+       ideclkp = clkp;
+       clk_enable(ideclkp);
+       ide_palm_clk = clk_get_rate(ideclkp)/100000;
+       ide_palm_clk = (10000/ide_palm_clk) + 1;
+       /* Register the IDE interface with Linux ATA Interface */
+       memset(&ide_ctlr_info, 0, sizeof(ide_ctlr_info));
+
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (mem == NULL) {
+               printk(KERN_ERR "failed to get memory region resource\n");
+               return -ENODEV;
+       }
+       irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+       if (irq == NULL) {
+               printk(KERN_ERR "failed to get IRQ resource\n");
+               return -ENODEV;
+       }
+
+       base = (void *)mem->start;
+
+       /* Configure the Palm Chip controller */
+       palm_bk3710_chipinit(base);
+
+       pribase = mem->start + IDE_PALM_ATA_PRI_REG_OFFSET;
+       for (index = 0; index < IDE_NR_PORTS - 2; index++)
+               ide_ctlr_info.io_ports[index] = pribase + index;
+       ide_ctlr_info.io_ports[IDE_CONTROL_OFFSET] = mem->start +
+                       IDE_PALM_ATA_PRI_CTL_OFFSET;
+       ide_ctlr_info.irq = irq->start;
+       ide_ctlr_info.chipset = ide_palm3710;
+
+       if (ide_register_hw(&ide_ctlr_info, NULL, &hwif) < 0) {
+               printk(KERN_WARNING "Palm Chip BK3710 IDE Register Fail\n");
+               return -ENODEV;
+       }
+
+       hwif->set_pio_mode = &palm_bk3710_set_pio_mode;
+       hwif->set_dma_mode = &palm_bk3710_set_dma_mode;
+       hwif->mmio = 1;
+       default_hwif_mmiops(hwif);
+       hwif->cbl = ATA_CBL_PATA80;
+       hwif->ultra_mask = 0x1f;        /* Ultra DMA Mode 4 Max
+                                               (input clk 99MHz) */
+       hwif->mwdma_mask = 0x7;
+       hwif->drives[0].autotune = 1;
+       hwif->drives[1].autotune = 1;
+
+       ide_setup_dma(hwif, mem->start);
+
+       return 0;
+}
+
+static struct platform_driver platform_bk_driver = {
+       .driver = {
+               .name = "palm_bk3710",
+       },
+       .probe = palm_bk3710_probe,
+       .remove = NULL,
+};
+
+static int __init palm_bk3710_init(void)
+{
+       return platform_driver_register(&platform_bk_driver);
+}
+
+module_init(palm_bk3710_init);
+MODULE_LICENSE("GPL");
+
index c8b6581e624eb6b2c6d9da598691a6419bc67e2a..efba00d2fc37bf4de6c20b35a46b5ee02b7c4663 100644 (file)
@@ -58,7 +58,7 @@ rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
 
                idx[0] = hwif->index;
 
-               ide_device_add(idx);
+               ide_device_add(idx, NULL);
 
                ecard_set_drvdata(ec, hwif);
                goto out;
@@ -76,7 +76,7 @@ static void __devexit rapide_remove(struct expansion_card *ec)
 
        ecard_set_drvdata(ec, NULL);
 
-       ide_unregister(hwif->index);
+       ide_unregister(hwif->index, 0, 0);
 
        ecard_release_resources(ec);
 }
index 0640a38ff127bfadca177859c059203c3c68f45f..e79bf8f9b7dbc29ca3c66f2f338a013ef12062fb 100644 (file)
@@ -753,34 +753,53 @@ static void cris_set_dma_mode(ide_drive_t *drive, const u8 speed)
                cris_ide_set_speed(TYPE_DMA, 0, strobe, hold);
 }
 
+static void __init cris_setup_ports(hw_regs_t *hw, unsigned long base)
+{
+       int i;
+
+       memset(hw, 0, sizeof(*hw));
+
+       for (i = 0; i <= 7; i++)
+               hw->io_ports[i] = base + cris_ide_reg_addr(i, 0, 1);
+
+       /*
+        * the IDE control register is at ATA address 6,
+        * with CS1 active instead of CS0
+        */
+       hw->io_ports[IDE_CONTROL_OFFSET] = base + cris_ide_reg_addr(6, 1, 0);
+
+       hw->irq = ide_default_irq(0);
+       hw->ack_intr = cris_ide_ack_intr;
+}
+
+static const struct ide_port_info cris_port_info __initdata = {
+       .chipset                = ide_etrax100,
+       .host_flags             = IDE_HFLAG_NO_ATAPI_DMA |
+                                 IDE_HFLAG_NO_DMA, /* no SFF-style DMA */
+       .pio_mask               = ATA_PIO4,
+       .udma_mask              = cris_ultra_mask,
+       .mwdma_mask             = ATA_MWDMA2,
+};
+
 static int __init init_e100_ide(void)
 {
        hw_regs_t hw;
-       int ide_offsets[IDE_NR_PORTS], h, i;
+       int h;
        u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
 
        printk("ide: ETRAX FS built-in ATA DMA controller\n");
 
-       for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
-               ide_offsets[i] = cris_ide_reg_addr(i, 0, 1);
-
-       /* the IDE control register is at ATA address 6, with CS1 active instead of CS0 */
-       ide_offsets[IDE_CONTROL_OFFSET] = cris_ide_reg_addr(6, 1, 0);
-
        for (h = 0; h < 4; h++) {
                ide_hwif_t *hwif = NULL;
 
-               ide_setup_ports(&hw, cris_ide_base_address(h),
-                               ide_offsets,
-                               0, 0, cris_ide_ack_intr,
-                               ide_default_irq(0));
+               cris_setup_ports(&hw, cris_ide_base_address(h));
+
                hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
                if (hwif == NULL)
                        continue;
                ide_init_port_data(hwif, hwif->index);
                ide_init_port_hw(hwif, &hw);
                hwif->mmio = 1;
-               hwif->chipset = ide_etrax100;
                hwif->set_pio_mode = &cris_set_pio_mode;
                hwif->set_dma_mode = &cris_set_dma_mode;
                hwif->ata_input_data = &cris_ide_input_data;
@@ -799,12 +818,6 @@ static int __init init_e100_ide(void)
                hwif->INB = &cris_ide_inb;
                hwif->INW = &cris_ide_inw;
                hwif->cbl = ATA_CBL_PATA40;
-               hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
-               hwif->pio_mask = ATA_PIO4,
-               hwif->drives[0].autotune = 1;
-               hwif->drives[1].autotune = 1;
-               hwif->ultra_mask = cris_ultra_mask;
-               hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */
 
                idx[h] = hwif->index;
        }
@@ -820,7 +833,7 @@ static int __init init_e100_ide(void)
        cris_ide_set_speed(TYPE_DMA, 0, ATA_DMA2_STROBE, ATA_DMA2_HOLD);
        cris_ide_set_speed(TYPE_UDMA, ATA_UDMA2_CYC, ATA_UDMA2_DVS, 0);
 
-       ide_device_add(idx);
+       ide_device_add(idx, &cris_port_info);
 
        return 0;
 }
@@ -1032,11 +1045,7 @@ static int cris_dma_setup(ide_drive_t *drive)
 
 static void cris_dma_exec_cmd(ide_drive_t *drive, u8 command)
 {
-       /* set the irq handler which will finish the request when DMA is done */
-       ide_set_handler(drive, &cris_dma_intr, WAIT_CMD, NULL);
-
-       /* issue cmd to drive */
-       cris_ide_outb(command, IDE_COMMAND_REG);
+       ide_execute_command(drive, command, &cris_dma_intr, WAIT_CMD, NULL);
 }
 
 static void cris_dma_start(ide_drive_t *drive)
index 02432958dfe1a6df7d7b57f757a94cef8885c194..520aec075700d691a75b3ac03e66ea315e4bc1fd 100644 (file)
@@ -114,7 +114,7 @@ static int __init h8300_ide_init(void)
 
        idx[0] = index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, NULL);
 
        return 0;
 
index 68bc618447801305741977fe257b70dbdd3ff301..e07b189f3ec8504d7f2b19628253855f884ba2c6 100644 (file)
@@ -39,7 +39,6 @@ struct GTM_buffer {
 };
 
 struct ide_acpi_drive_link {
-       ide_drive_t     *drive;
        acpi_handle      obj_handle;
        u8               idbuff[512];
 };
@@ -172,7 +171,7 @@ err:
 static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
 {
        struct device           *dev = hwif->gendev.parent;
-       acpi_handle             dev_handle;
+       acpi_handle             uninitialized_var(dev_handle);
        acpi_integer            pcidevfn;
        acpi_handle             chan_handle;
        int                     err;
@@ -280,16 +279,6 @@ static int do_drive_get_GTF(ide_drive_t *drive,
 
        port = hwif->channel ? drive->dn - 2: drive->dn;
 
-       if (!drive->acpidata) {
-               if (port == 0) {
-                       drive->acpidata = &hwif->acpidata->master;
-                       hwif->acpidata->master.drive = drive;
-               } else {
-                       drive->acpidata = &hwif->acpidata->slave;
-                       hwif->acpidata->slave.drive = drive;
-               }
-       }
-
        DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
                 hwif->name, dev->bus_id, port, hwif->channel);
 
@@ -494,7 +483,6 @@ int ide_acpi_exec_tfs(ide_drive_t *drive)
 
        return ret;
 }
-EXPORT_SYMBOL_GPL(ide_acpi_exec_tfs);
 
 /**
  * ide_acpi_get_timing - get the channel (controller) timings
@@ -580,7 +568,6 @@ void ide_acpi_get_timing(ide_hwif_t *hwif)
 
        kfree(output.pointer);
 }
-EXPORT_SYMBOL_GPL(ide_acpi_get_timing);
 
 /**
  * ide_acpi_push_timing - set the channel (controller) timings
@@ -634,7 +621,6 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
        }
        DEBPRINT("_STM status: %d\n", status);
 }
-EXPORT_SYMBOL_GPL(ide_acpi_push_timing);
 
 /**
  * ide_acpi_set_state - set the channel power state
@@ -688,11 +674,6 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
  */
 void ide_acpi_init(ide_hwif_t *hwif)
 {
-       int unit;
-       int                     err;
-       struct ide_acpi_drive_link      *master;
-       struct ide_acpi_drive_link      *slave;
-
        ide_acpi_blacklist();
 
        hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
@@ -704,40 +685,38 @@ void ide_acpi_init(ide_hwif_t *hwif)
                DEBPRINT("no ACPI object for %s found\n", hwif->name);
                kfree(hwif->acpidata);
                hwif->acpidata = NULL;
-               return;
        }
+}
+
+void ide_acpi_port_init_devices(ide_hwif_t *hwif)
+{
+       ide_drive_t *drive;
+       int i, err;
+
+       if (hwif->acpidata == NULL)
+               return;
 
        /*
         * The ACPI spec mandates that we send information
         * for both drives, regardless whether they are connected
         * or not.
         */
-       hwif->acpidata->master.drive = &hwif->drives[0];
        hwif->drives[0].acpidata = &hwif->acpidata->master;
-       master = &hwif->acpidata->master;
-
-       hwif->acpidata->slave.drive = &hwif->drives[1];
        hwif->drives[1].acpidata = &hwif->acpidata->slave;
-       slave = &hwif->acpidata->slave;
-
 
        /*
         * Send IDENTIFY for each drive
         */
-       if (master->drive->present) {
-               err = taskfile_lib_get_identify(master->drive, master->idbuff);
-               if (err) {
-                       DEBPRINT("identify device %s failed (%d)\n",
-                                master->drive->name, err);
-               }
-       }
+       for (i = 0; i < MAX_DRIVES; i++) {
+               drive = &hwif->drives[i];
+
+               if (!drive->present)
+                       continue;
 
-       if (slave->drive->present) {
-               err = taskfile_lib_get_identify(slave->drive, slave->idbuff);
-               if (err) {
+               err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
+               if (err)
                        DEBPRINT("identify device %s failed (%d)\n",
-                                slave->drive->name, err);
-               }
+                                drive->name, err);
        }
 
        if (ide_noacpionboot) {
@@ -753,13 +732,11 @@ void ide_acpi_init(ide_hwif_t *hwif)
        ide_acpi_get_timing(hwif);
        ide_acpi_push_timing(hwif);
 
-       for (unit = 0; unit < MAX_DRIVES; ++unit) {
-               ide_drive_t *drive = &hwif->drives[unit];
+       for (i = 0; i < MAX_DRIVES; i++) {
+               drive = &hwif->drives[i];
 
-               if (drive->present) {
+               if (drive->present)
                        /* Execute ACPI startup code */
                        ide_acpi_exec_tfs(drive);
-               }
        }
 }
-EXPORT_SYMBOL_GPL(ide_acpi_init);
index 23074e84472eb167434fbfc5bb728d17af0ab746..5e42c19a03e3b7f9e2eec932a929660cb513730d 100644 (file)
@@ -295,7 +295,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
        int stat, err, sense_key;
        
        /* Check for errors. */
-       stat = HWIF(drive)->INB(IDE_STATUS_REG);
+       stat = ide_read_status(drive);
+
        if (stat_ret)
                *stat_ret = stat;
 
@@ -303,7 +304,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
                return 0;
 
        /* Get the IDE error register. */
-       err = HWIF(drive)->INB(IDE_ERROR_REG);
+       err = ide_read_error(drive);
        sense_key = err >> 4;
 
        if (rq == NULL) {
@@ -604,8 +605,6 @@ static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive,
  * Block read functions.
  */
 
-typedef void (xfer_func_t)(ide_drive_t *, void *, u32);
-
 static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len)
 {
        while (len > 0) {
@@ -694,7 +693,7 @@ int ide_cd_check_ireason(ide_drive_t *drive, int len, int ireason, int rw)
                /* Some drives (ASUS) seem to tell us that status
                 * info is available. just get it and ignore.
                 */
-               (void) HWIF(drive)->INB(IDE_STATUS_REG);
+               (void)ide_read_status(drive);
                return 0;
        } else {
                /* Drive wants a command packet, or invalid ireason... */
@@ -1328,7 +1327,7 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
        if (blk_fs_request(rq)) {
                if (info->cd_flags & IDE_CD_FLAG_SEEKING) {
                        unsigned long elapsed = jiffies - info->start_seek;
-                       int stat = HWIF(drive)->INB(IDE_STATUS_REG);
+                       int stat = ide_read_status(drive);
 
                        if ((stat & SEEK_STAT) != SEEK_STAT) {
                                if (elapsed < IDECD_SEEK_TIMEOUT) {
index 7beaf1e9be1264432f597f4376320e588cb0edc0..a4bb32883c6bfb23d04c19f60e2b714da9a92744 100644 (file)
@@ -147,7 +147,8 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
        u8 stat = 0, dma_stat = 0;
 
        dma_stat = HWIF(drive)->ide_dma_end(drive);
-       stat = HWIF(drive)->INB(IDE_STATUS_REG);        /* get drive status */
+       stat = ide_read_status(drive);
+
        if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) {
                if (!dma_stat) {
                        struct request *rq = HWGROUP(drive)->rq;
@@ -819,6 +820,26 @@ int ide_set_dma(ide_drive_t *drive)
        return 0;
 }
 
+void ide_check_dma_crc(ide_drive_t *drive)
+{
+       u8 mode;
+
+       ide_dma_off_quietly(drive);
+       drive->crc_count = 0;
+       mode = drive->current_speed;
+       /*
+        * Don't try non Ultra-DMA modes without iCRC's.  Force the
+        * device to PIO and make the user enable SWDMA/MWDMA modes.
+        */
+       if (mode > XFER_UDMA_0 && mode <= XFER_UDMA_7)
+               mode--;
+       else
+               mode = XFER_PIO_4;
+       ide_set_xfer_rate(drive, mode);
+       if (drive->current_speed >= XFER_SW_DMA_0)
+               ide_dma_on(drive);
+}
+
 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
 void ide_dma_lost_irq (ide_drive_t *drive)
 {
index 3512637ae8d482154615b14164685b0841fe16e3..faf22d716f805995e6e59351c77e740b514f4fce 100644 (file)
@@ -4,11 +4,6 @@
  * Copyright (C) 1996-1999  Gadi Oxman <gadio@netvision.net.il>
  * Copyright (C) 2000-2002  Paul Bristow <paul@paulbristow.net>
  * Copyright (C) 2005       Bartlomiej Zolnierkiewicz
- */
-
-/*
- * The driver currently doesn't have any fancy features, just the bare
- * minimum read/write support.
  *
  * This driver supports the following IDE floppy drives:
  *
@@ -20,7 +15,7 @@
  * Documentation/ide/ChangeLog.ide-floppy.1996-2002
  */
 
-#define IDEFLOPPY_VERSION "0.99.newide"
+#define IDEFLOPPY_VERSION "1.00"
 
 #include <linux/module.h>
 #include <linux/types.h>
 #include <scsi/scsi_ioctl.h>
 
 #include <asm/byteorder.h>
-#include <asm/irq.h>
-#include <asm/uaccess.h>
-#include <asm/io.h>
+#include <linux/irq.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
 #include <asm/unaligned.h>
 
-/*
- *     The following are used to debug the driver.
- */
+/* define to see debug info */
 #define IDEFLOPPY_DEBUG_LOG            0
-#define IDEFLOPPY_DEBUG_INFO           0
-#define IDEFLOPPY_DEBUG_BUGS           1
 
 /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
-#define IDEFLOPPY_DEBUG( fmt, args... )
+#define IDEFLOPPY_DEBUG(fmt, args...)
 
 #if IDEFLOPPY_DEBUG_LOG
-#define debug_log printk
+#define debug_log(fmt, args...) \
+       printk(KERN_INFO "ide-floppy: " fmt, ## args)
 #else
-#define debug_log(fmt, args... ) do {} while(0)
+#define debug_log(fmt, args...) do {} while (0)
 #endif
 
 
-/*
- *     Some drives require a longer irq timeout.
- */
+/* Some drives require a longer irq timeout. */
 #define IDEFLOPPY_WAIT_CMD             (5 * WAIT_CMD)
 
 /*
- *     After each failed packet command we issue a request sense command
- *     and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times.
+ * After each failed packet command we issue a request sense command and retry
+ * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
  */
 #define IDEFLOPPY_MAX_PC_RETRIES       3
 
 /*
- *     With each packet command, we allocate a buffer of
- *     IDEFLOPPY_PC_BUFFER_SIZE bytes.
+ * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
+ * bytes.
  */
 #define IDEFLOPPY_PC_BUFFER_SIZE       256
 
 /*
- *     In various places in the driver, we need to allocate storage
- *     for packet commands and requests, which will remain valid while
- *     we leave the driver to wait for an interrupt or a timeout event.
+ * In various places in the driver, we need to allocate storage for packet
+ * commands and requests, which will remain valid while        we leave the driver to
+ * wait for an interrupt or a timeout event.
  */
 #define IDEFLOPPY_PC_STACK             (10 + IDEFLOPPY_MAX_PC_RETRIES)
 
-/*
- *     Our view of a packet command.
- */
 typedef struct idefloppy_packet_command_s {
        u8 c[12];                               /* Actual packet bytes */
-       int retries;                            /* On each retry, we increment retries */
+       int retries;                            /* On each retry, we increment
+                                                  retries */
        int error;                              /* Error code */
        int request_transfer;                   /* Bytes to transfer */
        int actually_transferred;               /* Bytes actually transferred */
        int buffer_size;                        /* Size of our data buffer */
-       int b_count;                            /* Missing/Available data on the current buffer */
+       int b_count;                            /* Missing/Available data on
+                                                  the current buffer */
        struct request *rq;                     /* The corresponding request */
        u8 *buffer;                             /* Data buffer */
-       u8 *current_position;                   /* Pointer into the above buffer */
-       void (*callback) (ide_drive_t *);       /* Called when this packet command is completed */
+       u8 *current_position;                   /* Pointer into above buffer */
+       void (*callback) (ide_drive_t *);       /* Called when this packet
+                                                  command is completed */
        u8 pc_buffer[IDEFLOPPY_PC_BUFFER_SIZE]; /* Temporary buffer */
-       unsigned long flags;                    /* Status/Action bit flags: long for set_bit */
+       unsigned long flags;                    /* Status/Action bit flags: long
+                                                  for set_bit */
 } idefloppy_pc_t;
 
-/*
- *     Packet command flag bits.
- */
-#define        PC_ABORT                        0       /* Set when an error is considered normal - We won't retry */
-#define PC_DMA_RECOMMENDED             2       /* 1 when we prefer to use DMA if possible */
-#define        PC_DMA_IN_PROGRESS              3       /* 1 while DMA in progress */
-#define        PC_DMA_ERROR                    4       /* 1 when encountered problem during DMA */
-#define        PC_WRITING                      5       /* Data direction */
-
-#define        PC_SUPPRESS_ERROR               6       /* Suppress error reporting */
-
-/*
- *     Removable Block Access Capabilities Page
- */
-typedef struct {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       unsigned        page_code       :6;     /* Page code - Should be 0x1b */
-       unsigned        reserved1_6     :1;     /* Reserved */
-       unsigned        ps              :1;     /* Should be 0 */
-#elif defined(__BIG_ENDIAN_BITFIELD)
-       unsigned        ps              :1;     /* Should be 0 */
-       unsigned        reserved1_6     :1;     /* Reserved */
-       unsigned        page_code       :6;     /* Page code - Should be 0x1b */
-#else
-#error "Bitfield endianness not defined! Check your byteorder.h"
-#endif
-       u8              page_length;            /* Page Length - Should be 0xa */
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       unsigned        reserved2       :6;
-       unsigned        srfp            :1;     /* Supports reporting progress of format */
-       unsigned        sflp            :1;     /* System floppy type device */
-       unsigned        tlun            :3;     /* Total logical units supported by the device */
-       unsigned        reserved3       :3;
-       unsigned        sml             :1;     /* Single / Multiple lun supported */
-       unsigned        ncd             :1;     /* Non cd optical device */
-#elif defined(__BIG_ENDIAN_BITFIELD)
-       unsigned        sflp            :1;     /* System floppy type device */
-       unsigned        srfp            :1;     /* Supports reporting progress of format */
-       unsigned        reserved2       :6;
-       unsigned        ncd             :1;     /* Non cd optical device */
-       unsigned        sml             :1;     /* Single / Multiple lun supported */
-       unsigned        reserved3       :3;
-       unsigned        tlun            :3;     /* Total logical units supported by the device */
-#else
-#error "Bitfield endianness not defined! Check your byteorder.h"
-#endif
-       u8              reserved[8];
-} idefloppy_capabilities_page_t;
-
-/*
- *     Flexible disk page.
- */
-typedef struct {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       unsigned        page_code       :6;     /* Page code - Should be 0x5 */
-       unsigned        reserved1_6     :1;     /* Reserved */
-       unsigned        ps              :1;     /* The device is capable of saving the page */
-#elif defined(__BIG_ENDIAN_BITFIELD)
-       unsigned        ps              :1;     /* The device is capable of saving the page */
-       unsigned        reserved1_6     :1;     /* Reserved */
-       unsigned        page_code       :6;     /* Page code - Should be 0x5 */
-#else
-#error "Bitfield endianness not defined! Check your byteorder.h"
-#endif
-       u8              page_length;            /* Page Length - Should be 0x1e */
-       u16             transfer_rate;          /* In kilobits per second */
-       u8              heads, sectors;         /* Number of heads, Number of sectors per track */
-       u16             sector_size;            /* Byes per sector */
-       u16             cyls;                   /* Number of cylinders */
-       u8              reserved10[10];
-       u8              motor_delay;            /* Motor off delay */
-       u8              reserved21[7];
-       u16             rpm;                    /* Rotations per minute */
-       u8              reserved30[2];
-} idefloppy_flexible_disk_page_t;
-/*
- *     Format capacity
- */
-typedef struct {
-       u8              reserved[3];
-       u8              length;                 /* Length of the following descriptors in bytes */
-} idefloppy_capacity_header_t;
-
-typedef struct {
-       u32             blocks;                 /* Number of blocks */
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       unsigned        dc              :2;     /* Descriptor Code */
-       unsigned        reserved        :6;
-#elif defined(__BIG_ENDIAN_BITFIELD)
-       unsigned        reserved        :6;
-       unsigned        dc              :2;     /* Descriptor Code */
-#else
-#error "Bitfield endianness not defined! Check your byteorder.h"
-#endif
-       u8              length_msb;             /* Block Length (MSB)*/
-       u16             length;                 /* Block Length */
-} idefloppy_capacity_descriptor_t;
+/* Packet command flag bits. */
+enum {
+       /* 1 when we prefer to use DMA if possible */
+       PC_FLAG_DMA_RECOMMENDED = (1 << 0),
+       /* 1 while DMA in progress */
+       PC_FLAG_DMA_IN_PROGRESS = (1 << 1),
+       /* 1 when encountered problem during DMA */
+       PC_FLAG_DMA_ERROR       = (1 << 2),
+       /* Data direction */
+       PC_FLAG_WRITING         = (1 << 3),
+       /* Suppress error reporting */
+       PC_FLAG_SUPPRESS_ERROR  = (1 << 4),
+};
 
+/* format capacities descriptor codes */
 #define CAPACITY_INVALID       0x00
 #define CAPACITY_UNFORMATTED   0x01
 #define CAPACITY_CURRENT       0x02
 #define CAPACITY_NO_CARTRIDGE  0x03
 
 /*
- *     Most of our global data which we need to save even as we leave the
- *     driver due to an interrupt or a timer event is stored in a variable
- *     of type idefloppy_floppy_t, defined below.
+ * Most of our global data which we need to save even as we leave the driver
+ * due to an interrupt or a timer event is stored in a variable of type
+ * idefloppy_floppy_t, defined below.
  */
 typedef struct ide_floppy_obj {
        ide_drive_t     *drive;
@@ -235,23 +142,19 @@ typedef struct ide_floppy_obj {
        /* We implement a circular array */
        int rq_stack_index;
 
-       /*
-        *      Last error information
-        */
+       /* Last error information */
        u8 sense_key, asc, ascq;
        /* delay this long before sending packet command */
        u8 ticks;
        int progress_indication;
 
-       /*
-        *      Device information
-        */
+       /* Device information */
        /* Current format */
        int blocks, block_size, bs_factor;
-       /* Last format capacity */
-       idefloppy_capacity_descriptor_t capacity;
+       /* Last format capacity descriptor */
+       u8 cap_desc[8];
        /* Copy of the flexible disk page */
-       idefloppy_flexible_disk_page_t flexible_disk_page;
+       u8 flexible_disk_page[32];
        /* Write protect */
        int wp;
        /* Supports format progress report */
@@ -262,64 +165,40 @@ typedef struct ide_floppy_obj {
 
 #define IDEFLOPPY_TICKS_DELAY  HZ/20   /* default delay for ZIP 100 (50ms) */
 
-/*
- *     Floppy flag bits values.
- */
-#define IDEFLOPPY_DRQ_INTERRUPT                0       /* DRQ interrupt device */
-#define IDEFLOPPY_MEDIA_CHANGED                1       /* Media may have changed */
-#define IDEFLOPPY_USE_READ12           2       /* Use READ12/WRITE12 or READ10/WRITE10 */
-#define        IDEFLOPPY_FORMAT_IN_PROGRESS    3       /* Format in progress */
-#define IDEFLOPPY_CLIK_DRIVE           4       /* Avoid commands not supported in Clik drive */
-#define IDEFLOPPY_ZIP_DRIVE            5       /* Requires BH algorithm for packets */
-
-/*
- *     ATAPI floppy drive packet commands
- */
-#define IDEFLOPPY_FORMAT_UNIT_CMD      0x04
-#define IDEFLOPPY_INQUIRY_CMD          0x12
-#define IDEFLOPPY_MODE_SELECT_CMD      0x55
-#define IDEFLOPPY_MODE_SENSE_CMD       0x5a
-#define IDEFLOPPY_READ10_CMD           0x28
-#define IDEFLOPPY_READ12_CMD           0xa8
-#define IDEFLOPPY_READ_CAPACITY_CMD    0x23
-#define IDEFLOPPY_REQUEST_SENSE_CMD    0x03
-#define IDEFLOPPY_PREVENT_REMOVAL_CMD  0x1e
-#define IDEFLOPPY_SEEK_CMD             0x2b
-#define IDEFLOPPY_START_STOP_CMD       0x1b
-#define IDEFLOPPY_TEST_UNIT_READY_CMD  0x00
-#define IDEFLOPPY_VERIFY_CMD           0x2f
-#define IDEFLOPPY_WRITE10_CMD          0x2a
-#define IDEFLOPPY_WRITE12_CMD          0xaa
-#define IDEFLOPPY_WRITE_VERIFY_CMD     0x2e
+/* Floppy flag bits values. */
+enum {
+       /* DRQ interrupt device */
+       IDEFLOPPY_FLAG_DRQ_INTERRUPT            = (1 << 0),
+       /* Media may have changed */
+       IDEFLOPPY_FLAG_MEDIA_CHANGED            = (1 << 1),
+       /* Format in progress */
+       IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS       = (1 << 2),
+       /* Avoid commands not supported in Clik drive */
+       IDEFLOPPY_FLAG_CLIK_DRIVE               = (1 << 3),
+       /* Requires BH algorithm for packets */
+       IDEFLOPPY_FLAG_ZIP_DRIVE                = (1 << 4),
+};
 
-/*
- *     Defines for the mode sense command
- */
+/* Defines for the MODE SENSE command */
 #define MODE_SENSE_CURRENT             0x00
 #define MODE_SENSE_CHANGEABLE          0x01
-#define MODE_SENSE_DEFAULT             0x02 
+#define MODE_SENSE_DEFAULT             0x02
 #define MODE_SENSE_SAVED               0x03
 
-/*
- *     IOCTLs used in low-level formatting.
- */
-
+/* IOCTLs used in low-level formatting. */
 #define        IDEFLOPPY_IOCTL_FORMAT_SUPPORTED        0x4600
 #define        IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY     0x4601
 #define        IDEFLOPPY_IOCTL_FORMAT_START            0x4602
 #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS    0x4603
 
-/*
- *     Error codes which are returned in rq->errors to the higher part
- *     of the driver.
- */
+/* Error code returned in rq->errors to the higher part of the driver. */
 #define        IDEFLOPPY_ERROR_GENERAL         101
 
 /*
- *     The following is used to format the general configuration word of
- *     the ATAPI IDENTIFY DEVICE command.
+ * The following is used to format the general configuration word of the
+ * ATAPI IDENTIFY DEVICE command.
  */
-struct idefloppy_id_gcw {      
+struct idefloppy_id_gcw {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
        unsigned packet_size            :2;     /* Packet Size */
        unsigned reserved234            :3;     /* Reserved */
@@ -342,103 +221,12 @@ struct idefloppy_id_gcw {
 };
 
 /*
- *     INQUIRY packet command - Data Format
- */
-typedef struct {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       unsigned        device_type     :5;     /* Peripheral Device Type */
-       unsigned        reserved0_765   :3;     /* Peripheral Qualifier - Reserved */
-       unsigned        reserved1_6t0   :7;     /* Reserved */
-       unsigned        rmb             :1;     /* Removable Medium Bit */
-       unsigned        ansi_version    :3;     /* ANSI Version */
-       unsigned        ecma_version    :3;     /* ECMA Version */
-       unsigned        iso_version     :2;     /* ISO Version */
-       unsigned        response_format :4;     /* Response Data Format */
-       unsigned        reserved3_45    :2;     /* Reserved */
-       unsigned        reserved3_6     :1;     /* TrmIOP - Reserved */
-       unsigned        reserved3_7     :1;     /* AENC - Reserved */
-#elif defined(__BIG_ENDIAN_BITFIELD)
-       unsigned        reserved0_765   :3;     /* Peripheral Qualifier - Reserved */
-       unsigned        device_type     :5;     /* Peripheral Device Type */
-       unsigned        rmb             :1;     /* Removable Medium Bit */
-       unsigned        reserved1_6t0   :7;     /* Reserved */
-       unsigned        iso_version     :2;     /* ISO Version */
-       unsigned        ecma_version    :3;     /* ECMA Version */
-       unsigned        ansi_version    :3;     /* ANSI Version */
-       unsigned        reserved3_7     :1;     /* AENC - Reserved */
-       unsigned        reserved3_6     :1;     /* TrmIOP - Reserved */
-       unsigned        reserved3_45    :2;     /* Reserved */
-       unsigned        response_format :4;     /* Response Data Format */
-#else
-#error "Bitfield endianness not defined! Check your byteorder.h"
-#endif
-       u8              additional_length;      /* Additional Length (total_length-4) */
-       u8              rsv5, rsv6, rsv7;       /* Reserved */
-       u8              vendor_id[8];           /* Vendor Identification */
-       u8              product_id[16];         /* Product Identification */
-       u8              revision_level[4];      /* Revision Level */
-       u8              vendor_specific[20];    /* Vendor Specific - Optional */
-       u8              reserved56t95[40];      /* Reserved - Optional */
-                                               /* Additional information may be returned */
-} idefloppy_inquiry_result_t;
-
-/*
- *     REQUEST SENSE packet command result - Data Format.
- */
-typedef struct {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       unsigned        error_code      :7;     /* Current error (0x70) */
-       unsigned        valid           :1;     /* The information field conforms to SFF-8070i */
-       u8              reserved1       :8;     /* Reserved */
-       unsigned        sense_key       :4;     /* Sense Key */
-       unsigned        reserved2_4     :1;     /* Reserved */
-       unsigned        ili             :1;     /* Incorrect Length Indicator */
-       unsigned        reserved2_67    :2;
-#elif defined(__BIG_ENDIAN_BITFIELD)
-       unsigned        valid           :1;     /* The information field conforms to SFF-8070i */
-       unsigned        error_code      :7;     /* Current error (0x70) */
-       u8              reserved1       :8;     /* Reserved */
-       unsigned        reserved2_67    :2;
-       unsigned        ili             :1;     /* Incorrect Length Indicator */
-       unsigned        reserved2_4     :1;     /* Reserved */
-       unsigned        sense_key       :4;     /* Sense Key */
-#else
-#error "Bitfield endianness not defined! Check your byteorder.h"
-#endif
-       u32             information __attribute__ ((packed));
-       u8              asl;                    /* Additional sense length (n-7) */
-       u32             command_specific;       /* Additional command specific information */
-       u8              asc;                    /* Additional Sense Code */
-       u8              ascq;                   /* Additional Sense Code Qualifier */
-       u8              replaceable_unit_code;  /* Field Replaceable Unit Code */
-       u8              sksv[3];
-       u8              pad[2];                 /* Padding to 20 bytes */
-} idefloppy_request_sense_result_t;
-
-/*
- *     Pages of the SELECT SENSE / MODE SENSE packet commands.
+ * Pages of the SELECT SENSE / MODE SENSE packet commands.
+ * See SFF-8070i spec.
  */
 #define        IDEFLOPPY_CAPABILITIES_PAGE     0x1b
 #define IDEFLOPPY_FLEXIBLE_DISK_PAGE   0x05
 
-/*
- *     Mode Parameter Header for the MODE SENSE packet command
- */
-typedef struct {
-       u16             mode_data_length;       /* Length of the following data transfer */
-       u8              medium_type;            /* Medium Type */
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       unsigned        reserved3       :7;
-       unsigned        wp              :1;     /* Write protect */
-#elif defined(__BIG_ENDIAN_BITFIELD)
-       unsigned        wp              :1;     /* Write protect */
-       unsigned        reserved3       :7;
-#else
-#error "Bitfield endianness not defined! Check your byteorder.h"
-#endif
-       u8              reserved[4];
-} idefloppy_mode_parameter_header_t;
-
 static DEFINE_MUTEX(idefloppy_ref_mutex);
 
 #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
@@ -458,39 +246,35 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
        return floppy;
 }
 
-static void ide_floppy_release(struct kref *);
+static void idefloppy_cleanup_obj(struct kref *);
 
 static void ide_floppy_put(struct ide_floppy_obj *floppy)
 {
        mutex_lock(&idefloppy_ref_mutex);
-       kref_put(&floppy->kref, ide_floppy_release);
+       kref_put(&floppy->kref, idefloppy_cleanup_obj);
        mutex_unlock(&idefloppy_ref_mutex);
 }
 
 /*
- *     Too bad. The drive wants to send us data which we are not ready to accept.
- *     Just throw it away.
+ * Too bad. The drive wants to send us data which we are not ready to accept.
+ * Just throw it away.
  */
-static void idefloppy_discard_data (ide_drive_t *drive, unsigned int bcount)
+static void idefloppy_discard_data(ide_drive_t *drive, unsigned int bcount)
 {
        while (bcount--)
                (void) HWIF(drive)->INB(IDE_DATA_REG);
 }
 
-#if IDEFLOPPY_DEBUG_BUGS
-static void idefloppy_write_zeros (ide_drive_t *drive, unsigned int bcount)
+static void idefloppy_write_zeros(ide_drive_t *drive, unsigned int bcount)
 {
        while (bcount--)
                HWIF(drive)->OUTB(0, IDE_DATA_REG);
 }
-#endif /* IDEFLOPPY_DEBUG_BUGS */
 
 
 /*
- *     idefloppy_do_end_request is used to finish servicing a request.
- *
- *     For read/write requests, we will call ide_end_request to pass to the
- *     next buffer.
+ * Used to finish servicing a request. For read/write requests, we will call
+ * ide_end_request to pass to the next buffer.
  */
 static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
 {
@@ -498,12 +282,12 @@ static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
        struct request *rq = HWGROUP(drive)->rq;
        int error;
 
-       debug_log(KERN_INFO "Reached idefloppy_end_request\n");
+       debug_log("Reached %s\n", __func__);
 
        switch (uptodate) {
-               case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
-               case 1: error = 0; break;
-               default: error = uptodate;
+       case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
+       case 1: error = 0; break;
+       default: error = uptodate;
        }
        if (error)
                floppy->failed_pc = NULL;
@@ -521,39 +305,8 @@ static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
        return 0;
 }
 
-static void idefloppy_input_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount)
-{
-       struct request *rq = pc->rq;
-       struct bio_vec *bvec;
-       struct req_iterator iter;
-       unsigned long flags;
-       char *data;
-       int count, done = 0;
-
-       rq_for_each_segment(bvec, rq, iter) {
-               if (!bcount)
-                       break;
-
-               count = min(bvec->bv_len, bcount);
-
-               data = bvec_kmap_irq(bvec, &flags);
-               drive->hwif->atapi_input_bytes(drive, data, count);
-               bvec_kunmap_irq(data, &flags);
-
-               bcount -= count;
-               pc->b_count += count;
-               done += count;
-       }
-
-       idefloppy_do_end_request(drive, 1, done >> 9);
-
-       if (bcount) {
-               printk(KERN_ERR "%s: leftover data in idefloppy_input_buffers, bcount == %d\n", drive->name, bcount);
-               idefloppy_discard_data(drive, bcount);
-       }
-}
-
-static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount)
+static void ide_floppy_io_buffers(ide_drive_t *drive, idefloppy_pc_t *pc,
+                                 unsigned int bcount, int direction)
 {
        struct request *rq = pc->rq;
        struct req_iterator iter;
@@ -569,7 +322,10 @@ static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, un
                count = min(bvec->bv_len, bcount);
 
                data = bvec_kmap_irq(bvec, &flags);
-               drive->hwif->atapi_output_bytes(drive, data, count);
+               if (direction)
+                       drive->hwif->atapi_output_bytes(drive, data, count);
+               else
+                       drive->hwif->atapi_input_bytes(drive, data, count);
                bvec_kunmap_irq(data, &flags);
 
                bcount -= count;
@@ -579,15 +335,18 @@ static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, un
 
        idefloppy_do_end_request(drive, 1, done >> 9);
 
-#if IDEFLOPPY_DEBUG_BUGS
        if (bcount) {
-               printk(KERN_ERR "%s: leftover data in idefloppy_output_buffers, bcount == %d\n", drive->name, bcount);
-               idefloppy_write_zeros(drive, bcount);
+               printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
+                               drive->name, __func__, bcount);
+               if (direction)
+                       idefloppy_write_zeros(drive, bcount);
+               else
+                       idefloppy_discard_data(drive, bcount);
+
        }
-#endif
 }
 
-static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc)
+static void idefloppy_update_buffers(ide_drive_t *drive, idefloppy_pc_t *pc)
 {
        struct request *rq = pc->rq;
        struct bio *bio = rq->bio;
@@ -597,11 +356,12 @@ static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc)
 }
 
 /*
- *     idefloppy_queue_pc_head generates a new packet command request in front
- *     of the request queue, before the current request, so that it will be
- *     processed immediately, on the next pass through the driver.
+ * Generate a new packet command request in front of the request queue, before
+ * the current request so that it will be processed immediately, on the next
+ * pass through the driver.
  */
-static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struct request *rq)
+static void idefloppy_queue_pc_head(ide_drive_t *drive, idefloppy_pc_t *pc,
+               struct request *rq)
 {
        struct ide_floppy_obj *floppy = drive->driver_data;
 
@@ -612,16 +372,16 @@ static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struc
        (void) ide_do_drive_cmd(drive, rq, ide_preempt);
 }
 
-static idefloppy_pc_t *idefloppy_next_pc_storage (ide_drive_t *drive)
+static idefloppy_pc_t *idefloppy_next_pc_storage(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
 
        if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
-               floppy->pc_stack_index=0;
+               floppy->pc_stack_index = 0;
        return (&floppy->pc_stack[floppy->pc_stack_index++]);
 }
 
-static struct request *idefloppy_next_rq_storage (ide_drive_t *drive)
+static struct request *idefloppy_next_rq_storage(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
 
@@ -630,60 +390,53 @@ static struct request *idefloppy_next_rq_storage (ide_drive_t *drive)
        return (&floppy->rq_stack[floppy->rq_stack_index++]);
 }
 
-/*
- *     idefloppy_analyze_error is called on each failed packet command retry
- *     to analyze the request sense.
- */
-static void idefloppy_analyze_error (ide_drive_t *drive,idefloppy_request_sense_result_t *result)
+static void idefloppy_request_sense_callback(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
+       u8 *buf = floppy->pc->buffer;
 
-       floppy->sense_key = result->sense_key;
-       floppy->asc = result->asc;
-       floppy->ascq = result->ascq;
-       floppy->progress_indication = result->sksv[0] & 0x80 ?
-               (u16)get_unaligned((u16 *)(result->sksv+1)):0x10000;
-       if (floppy->failed_pc)
-               debug_log(KERN_INFO "ide-floppy: pc = %x, sense key = %x, "
-                       "asc = %x, ascq = %x\n", floppy->failed_pc->c[0],
-                       result->sense_key, result->asc, result->ascq);
-       else
-               debug_log(KERN_INFO "ide-floppy: sense key = %x, asc = %x, "
-                       "ascq = %x\n", result->sense_key,
-                       result->asc, result->ascq);
-}
-
-static void idefloppy_request_sense_callback (ide_drive_t *drive)
-{
-       idefloppy_floppy_t *floppy = drive->driver_data;
+       debug_log("Reached %s\n", __func__);
 
-       debug_log(KERN_INFO "ide-floppy: Reached %s\n", __FUNCTION__);
-       
        if (!floppy->pc->error) {
-               idefloppy_analyze_error(drive,(idefloppy_request_sense_result_t *) floppy->pc->buffer);
+               floppy->sense_key = buf[2] & 0x0F;
+               floppy->asc = buf[12];
+               floppy->ascq = buf[13];
+               floppy->progress_indication = buf[15] & 0x80 ?
+                       (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
+
+               if (floppy->failed_pc)
+                       debug_log("pc = %x, sense key = %x, asc = %x,"
+                                       " ascq = %x\n",
+                                       floppy->failed_pc->c[0],
+                                       floppy->sense_key,
+                                       floppy->asc,
+                                       floppy->ascq);
+               else
+                       debug_log("sense key = %x, asc = %x, ascq = %x\n",
+                                       floppy->sense_key,
+                                       floppy->asc,
+                                       floppy->ascq);
+
+
                idefloppy_do_end_request(drive, 1, 0);
        } else {
-               printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting request!\n");
+               printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting"
+                               " request!\n");
                idefloppy_do_end_request(drive, 0, 0);
        }
 }
 
-/*
- *     General packet command callback function.
- */
-static void idefloppy_pc_callback (ide_drive_t *drive)
+/* General packet command callback function. */
+static void idefloppy_pc_callback(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
-       
-       debug_log(KERN_INFO "ide-floppy: Reached %s\n", __FUNCTION__);
+
+       debug_log("Reached %s\n", __func__);
 
        idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0);
 }
 
-/*
- *     idefloppy_init_pc initializes a packet command.
- */
-static void idefloppy_init_pc (idefloppy_pc_t *pc)
+static void idefloppy_init_pc(idefloppy_pc_t *pc)
 {
        memset(pc->c, 0, 12);
        pc->retries = 0;
@@ -694,75 +447,75 @@ static void idefloppy_init_pc (idefloppy_pc_t *pc)
        pc->callback = &idefloppy_pc_callback;
 }
 
-static void idefloppy_create_request_sense_cmd (idefloppy_pc_t *pc)
+static void idefloppy_create_request_sense_cmd(idefloppy_pc_t *pc)
 {
-       idefloppy_init_pc(pc);  
-       pc->c[0] = IDEFLOPPY_REQUEST_SENSE_CMD;
+       idefloppy_init_pc(pc);
+       pc->c[0] = GPCMD_REQUEST_SENSE;
        pc->c[4] = 255;
        pc->request_transfer = 18;
        pc->callback = &idefloppy_request_sense_callback;
 }
 
 /*
- *     idefloppy_retry_pc is called when an error was detected during the
- *     last packet command. We queue a request sense packet command in
- *     the head of the request list.
+ * Called when an error was detected during the last packet command. We queue a
+ * request sense packet command in the head of the request list.
  */
-static void idefloppy_retry_pc (ide_drive_t *drive)
+static void idefloppy_retry_pc(ide_drive_t *drive)
 {
        idefloppy_pc_t *pc;
        struct request *rq;
 
-       (void)drive->hwif->INB(IDE_ERROR_REG);
+       (void)ide_read_error(drive);
        pc = idefloppy_next_pc_storage(drive);
        rq = idefloppy_next_rq_storage(drive);
        idefloppy_create_request_sense_cmd(pc);
        idefloppy_queue_pc_head(drive, pc, rq);
 }
 
-/*
- *     idefloppy_pc_intr is the usual interrupt handler which will be called
- *     during a packet command.
- */
+/* The usual interrupt handler called during a packet command. */
 static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        ide_hwif_t *hwif = drive->hwif;
        idefloppy_pc_t *pc = floppy->pc;
        struct request *rq = pc->rq;
+       xfer_func_t *xferfunc;
        unsigned int temp;
+       int dma_error = 0;
        u16 bcount;
        u8 stat, ireason;
 
-       debug_log(KERN_INFO "ide-floppy: Reached %s interrupt handler\n",
-               __FUNCTION__);
+       debug_log("Reached %s interrupt handler\n", __func__);
 
-       if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
-               if (HWIF(drive)->ide_dma_end(drive)) {
-                       set_bit(PC_DMA_ERROR, &pc->flags);
+       if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
+               dma_error = hwif->ide_dma_end(drive);
+               if (dma_error) {
+                       printk(KERN_ERR "%s: DMA %s error\n", drive->name,
+                                       rq_data_dir(rq) ? "write" : "read");
+                       pc->flags |= PC_FLAG_DMA_ERROR;
                } else {
                        pc->actually_transferred = pc->request_transfer;
                        idefloppy_update_buffers(drive, pc);
                }
-               debug_log(KERN_INFO "ide-floppy: DMA finished\n");
+               debug_log("DMA finished\n");
        }
 
        /* Clear the interrupt */
-       stat = drive->hwif->INB(IDE_STATUS_REG);
+       stat = ide_read_status(drive);
 
-       if ((stat & DRQ_STAT) == 0) {           /* No more interrupts */
-               debug_log(KERN_INFO "Packet command completed, %d bytes "
-                       "transferred\n", pc->actually_transferred);
-               clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
+       /* No more interrupts */
+       if ((stat & DRQ_STAT) == 0) {
+               debug_log("Packet command completed, %d bytes transferred\n",
+                               pc->actually_transferred);
+               pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
 
                local_irq_enable_in_hardirq();
 
-               if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) {
+               if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) {
                        /* Error detected */
-                       debug_log(KERN_INFO "ide-floppy: %s: I/O error\n",
-                               drive->name);
+                       debug_log("%s: I/O error\n", drive->name);
                        rq->errors++;
-                       if (pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD) {
+                       if (pc->c[0] == GPCMD_REQUEST_SENSE) {
                                printk(KERN_ERR "ide-floppy: I/O error in "
                                        "request sense command\n");
                                return ide_do_reset(drive);
@@ -780,7 +533,8 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
                return ide_stopped;
        }
 
-       if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
+       if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
+               pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
                printk(KERN_ERR "ide-floppy: The floppy wants to issue "
                        "more interrupts in DMA mode\n");
                ide_dma_off(drive);
@@ -794,10 +548,10 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
        ireason = hwif->INB(IDE_IREASON_REG);
 
        if (ireason & CD) {
-               printk(KERN_ERR "ide-floppy: CoD != 0 in idefloppy_pc_intr\n");
+               printk(KERN_ERR "ide-floppy: CoD != 0 in %s\n", __func__);
                return ide_do_reset(drive);
        }
-       if (((ireason & IO) == IO) == test_bit(PC_WRITING, &pc->flags)) {
+       if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) {
                /* Hopefully, we will never get here */
                printk(KERN_ERR "ide-floppy: We wanted to %s, ",
                                (ireason & IO) ? "Write" : "Read");
@@ -805,7 +559,7 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
                                (ireason & IO) ? "Read" : "Write");
                return ide_do_reset(drive);
        }
-       if (!test_bit(PC_WRITING, &pc->flags)) {
+       if (!(pc->flags & PC_FLAG_WRITING)) {
                /* Reading - Check that we have enough space */
                temp = pc->actually_transferred + bcount;
                if (temp > pc->request_transfer) {
@@ -814,39 +568,34 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
                                        "to send us more data than expected "
                                        "- discarding data\n");
                                idefloppy_discard_data(drive, bcount);
-                               BUG_ON(HWGROUP(drive)->handler != NULL);
+
                                ide_set_handler(drive,
                                                &idefloppy_pc_intr,
                                                IDEFLOPPY_WAIT_CMD,
                                                NULL);
                                return ide_started;
                        }
-                       debug_log(KERN_NOTICE "ide-floppy: The floppy wants to "
-                               "send us more data than expected - "
-                               "allowing transfer\n");
+                       debug_log("The floppy wants to send us more data than"
+                                       " expected - allowing transfer\n");
                }
        }
-       if (test_bit(PC_WRITING, &pc->flags)) {
-               if (pc->buffer != NULL)
-                       /* Write the current buffer */
-                       hwif->atapi_output_bytes(drive, pc->current_position,
-                                                bcount);
-               else
-                       idefloppy_output_buffers(drive, pc, bcount);
-       } else {
-               if (pc->buffer != NULL)
-                       /* Read the current buffer */
-                       hwif->atapi_input_bytes(drive, pc->current_position,
-                                               bcount);
-               else
-                       idefloppy_input_buffers(drive, pc, bcount);
-       }
+       if (pc->flags & PC_FLAG_WRITING)
+               xferfunc = hwif->atapi_output_bytes;
+       else
+               xferfunc = hwif->atapi_input_bytes;
+
+       if (pc->buffer)
+               xferfunc(drive, pc->current_position, bcount);
+       else
+               ide_floppy_io_buffers(drive, pc, bcount,
+                                     !!(pc->flags & PC_FLAG_WRITING));
+
        /* Update the current position */
        pc->actually_transferred += bcount;
        pc->current_position += bcount;
 
-       BUG_ON(HWGROUP(drive)->handler != NULL);
-       ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);           /* And set the interrupt handler again */
+       /* And set the interrupt handler again */
+       ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
        return ide_started;
 }
 
@@ -855,7 +604,7 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
  * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
  * for that drive below. The algorithm is chosen based on drive type
  */
-static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive)
+static ide_startstop_t idefloppy_transfer_pc(ide_drive_t *drive)
 {
        ide_startstop_t startstop;
        idefloppy_floppy_t *floppy = drive->driver_data;
@@ -872,7 +621,7 @@ static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive)
                                "issuing a packet command\n");
                return ide_do_reset(drive);
        }
-       BUG_ON(HWGROUP(drive)->handler != NULL);
+
        /* Set the interrupt routine */
        ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
        /* Send the actual packet */
@@ -882,18 +631,16 @@ static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive)
 
 
 /*
- * What we have here is a classic case of a top half / bottom half
- * interrupt service routine. In interrupt mode, the device sends
- * an interrupt to signal it's ready to receive a packet. However,
- * we need to delay about 2-3 ticks before issuing the packet or we
- * gets in trouble.
+ * What we have here is a classic case of a top half / bottom half interrupt
+ * service routine. In interrupt mode, the device sends an interrupt to signal
+ * that it is ready to receive a packet. However, we need to delay about 2-3
+ * ticks before issuing the packet or we gets in trouble.
  *
- * So, follow carefully. transfer_pc1 is called as an interrupt (or
- * directly). In either case, when the device says it's ready for a 
- * packet, we schedule the packet transfer to occur about 2-3 ticks
- * later in transfer_pc2.
+ * So, follow carefully. transfer_pc1 is called as an interrupt (or directly).
+ * In either case, when the device says it's ready for a packet, we schedule
+ * the packet transfer to occur about 2-3 ticks later in transfer_pc2.
  */
-static int idefloppy_transfer_pc2 (ide_drive_t *drive)
+static int idefloppy_transfer_pc2(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
 
@@ -903,7 +650,7 @@ static int idefloppy_transfer_pc2 (ide_drive_t *drive)
        return IDEFLOPPY_WAIT_CMD;
 }
 
-static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive)
+static ide_startstop_t idefloppy_transfer_pc1(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        ide_startstop_t startstop;
@@ -920,7 +667,7 @@ static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive)
                                "while issuing a packet command\n");
                return ide_do_reset(drive);
        }
-       /* 
+       /*
         * The following delay solves a problem with ATAPI Zip 100 drives
         * where the Busy flag was apparently being deasserted before the
         * unit was ready to receive data. This was happening on a
@@ -928,32 +675,30 @@ static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive)
         * 40 and 50msec work well. idefloppy_pc_intr will not be actually
         * used until after the packet is moved in about 50 msec.
         */
-       BUG_ON(HWGROUP(drive)->handler != NULL);
-       ide_set_handler(drive, 
-         &idefloppy_pc_intr,           /* service routine for packet command */
-         floppy->ticks,                /* wait this long before "failing" */
-         &idefloppy_transfer_pc2);     /* fail == transfer_pc2 */
+
+       ide_set_handler(drive, &idefloppy_pc_intr, floppy->ticks,
+                       &idefloppy_transfer_pc2);
        return ide_started;
 }
 
-/**
- * idefloppy_should_report_error()
- *
- * Supresses error messages resulting from Medium not present
- */
-static inline int idefloppy_should_report_error(idefloppy_floppy_t *floppy)
+static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
+                                   idefloppy_pc_t *pc)
 {
+       /* supress error messages resulting from Medium not present */
        if (floppy->sense_key == 0x02 &&
            floppy->asc       == 0x3a &&
            floppy->ascq      == 0x00)
-               return 0;
-       return 1;
+               return;
+
+       printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
+                       "asc = %2x, ascq = %2x\n",
+                       floppy->drive->name, pc->c[0], floppy->sense_key,
+                       floppy->asc, floppy->ascq);
+
 }
 
-/*
- *     Issue a packet command
- */
-static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *pc)
+static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
+               idefloppy_pc_t *pc)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        ide_hwif_t *hwif = drive->hwif;
@@ -962,36 +707,23 @@ static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *p
        u8 dma;
 
        if (floppy->failed_pc == NULL &&
-           pc->c[0] != IDEFLOPPY_REQUEST_SENSE_CMD)
+           pc->c[0] != GPCMD_REQUEST_SENSE)
                floppy->failed_pc = pc;
        /* Set the current packet command */
        floppy->pc = pc;
 
-       if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES ||
-           test_bit(PC_ABORT, &pc->flags)) {
-               /*
-                *      We will "abort" retrying a packet command in case
-                *      a legitimate error code was received.
-                */
-               if (!test_bit(PC_ABORT, &pc->flags)) {
-                       if (!test_bit(PC_SUPPRESS_ERROR, &pc->flags)) {
-                               if (idefloppy_should_report_error(floppy))
-                                       printk(KERN_ERR "ide-floppy: %s: I/O error, "
-                                              "pc = %2x, key = %2x, "
-                                              "asc = %2x, ascq = %2x\n",
-                                              drive->name, pc->c[0],
-                                              floppy->sense_key,
-                                              floppy->asc, floppy->ascq);
-                       }
-                       /* Giving up */
-                       pc->error = IDEFLOPPY_ERROR_GENERAL;
-               }
+       if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
+               if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
+                       ide_floppy_report_error(floppy, pc);
+               /* Giving up */
+               pc->error = IDEFLOPPY_ERROR_GENERAL;
+
                floppy->failed_pc = NULL;
                pc->callback(drive);
                return ide_stopped;
        }
 
-       debug_log(KERN_INFO "Retry number - %d\n",pc->retries);
+       debug_log("Retry number - %d\n", pc->retries);
 
        pc->retries++;
        /* We haven't transferred any data yet */
@@ -999,24 +731,26 @@ static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *p
        pc->current_position = pc->buffer;
        bcount = min(pc->request_transfer, 63 * 1024);
 
-       if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags))
+       if (pc->flags & PC_FLAG_DMA_ERROR) {
+               pc->flags &= ~PC_FLAG_DMA_ERROR;
                ide_dma_off(drive);
-
+       }
        dma = 0;
 
-       if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
+       if ((pc->flags & PC_FLAG_DMA_RECOMMENDED) && drive->using_dma)
                dma = !hwif->dma_setup(drive);
 
        ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK |
                           IDE_TFLAG_OUT_DEVICE, bcount, dma);
 
-       if (dma) {      /* Begin DMA, if necessary */
-               set_bit(PC_DMA_IN_PROGRESS, &pc->flags);
+       if (dma) {
+               /* Begin DMA, if necessary */
+               pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
                hwif->dma_start(drive);
        }
 
        /* Can we transfer the packet when we get the interrupt or wait? */
-       if (test_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags)) {
+       if (floppy->flags & IDEFLOPPY_FLAG_ZIP_DRIVE) {
                /* wait */
                pkt_xfer_routine = &idefloppy_transfer_pc1;
        } else {
@@ -1024,7 +758,7 @@ static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *p
                pkt_xfer_routine = &idefloppy_transfer_pc;
        }
        
-       if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) {
+       if (floppy->flags & IDEFLOPPY_FLAG_DRQ_INTERRUPT) {
                /* Issue the packet command */
                ide_execute_command(drive, WIN_PACKETCMD,
                                pkt_xfer_routine,
@@ -1038,38 +772,37 @@ static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *p
        }
 }
 
-static void idefloppy_rw_callback (ide_drive_t *drive)
+static void idefloppy_rw_callback(ide_drive_t *drive)
 {
-       debug_log(KERN_INFO "ide-floppy: Reached idefloppy_rw_callback\n");
+       debug_log("Reached %s\n", __func__);
 
        idefloppy_do_end_request(drive, 1, 0);
        return;
 }
 
-static void idefloppy_create_prevent_cmd (idefloppy_pc_t *pc, int prevent)
+static void idefloppy_create_prevent_cmd(idefloppy_pc_t *pc, int prevent)
 {
-       debug_log(KERN_INFO "ide-floppy: creating prevent removal command, "
-               "prevent = %d\n", prevent);
+       debug_log("creating prevent removal command, prevent = %d\n", prevent);
 
        idefloppy_init_pc(pc);
-       pc->c[0] = IDEFLOPPY_PREVENT_REMOVAL_CMD;
+       pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
        pc->c[4] = prevent;
 }
 
-static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t *pc)
+static void idefloppy_create_read_capacity_cmd(idefloppy_pc_t *pc)
 {
        idefloppy_init_pc(pc);
-       pc->c[0] = IDEFLOPPY_READ_CAPACITY_CMD;
+       pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
        pc->c[7] = 255;
        pc->c[8] = 255;
        pc->request_transfer = 255;
 }
 
-static void idefloppy_create_format_unit_cmd (idefloppy_pc_t *pc, int b, int l,
+static void idefloppy_create_format_unit_cmd(idefloppy_pc_t *pc, int b, int l,
                                              int flags)
 {
        idefloppy_init_pc(pc);
-       pc->c[0] = IDEFLOPPY_FORMAT_UNIT_CMD;
+       pc->c[0] = GPCMD_FORMAT_UNIT;
        pc->c[1] = 0x17;
 
        memset(pc->buffer, 0, 12);
@@ -1080,83 +813,79 @@ static void idefloppy_create_format_unit_cmd (idefloppy_pc_t *pc, int b, int l,
                pc->buffer[1] ^= 0x20;          /* ... turn off DCRT bit */
        pc->buffer[3] = 8;
 
-       put_unaligned(htonl(b), (unsigned int *)(&pc->buffer[4]));
-       put_unaligned(htonl(l), (unsigned int *)(&pc->buffer[8]));
-       pc->buffer_size=12;
-       set_bit(PC_WRITING, &pc->flags);
+       put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buffer[4]));
+       put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buffer[8]));
+       pc->buffer_size = 12;
+       pc->flags |= PC_FLAG_WRITING;
 }
 
-/*
- *     A mode sense command is used to "sense" floppy parameters.
- */
-static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t *pc, u8 page_code, u8 type)
+/* A mode sense command is used to "sense" floppy parameters. */
+static void idefloppy_create_mode_sense_cmd(idefloppy_pc_t *pc, u8 page_code,
+               u8 type)
 {
-       u16 length = sizeof(idefloppy_mode_parameter_header_t);
-       
+       u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
+
        idefloppy_init_pc(pc);
-       pc->c[0] = IDEFLOPPY_MODE_SENSE_CMD;
+       pc->c[0] = GPCMD_MODE_SENSE_10;
        pc->c[1] = 0;
        pc->c[2] = page_code + (type << 6);
 
        switch (page_code) {
-               case IDEFLOPPY_CAPABILITIES_PAGE:
-                       length += 12;
-                       break;
-               case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
-                       length += 32;
-                       break;
-               default:
-                       printk(KERN_ERR "ide-floppy: unsupported page code "
+       case IDEFLOPPY_CAPABILITIES_PAGE:
+               length += 12;
+               break;
+       case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
+               length += 32;
+               break;
+       default:
+               printk(KERN_ERR "ide-floppy: unsupported page code "
                                "in create_mode_sense_cmd\n");
        }
-       put_unaligned(htons(length), (u16 *) &pc->c[7]);
+       put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
        pc->request_transfer = length;
 }
 
-static void idefloppy_create_start_stop_cmd (idefloppy_pc_t *pc, int start)
+static void idefloppy_create_start_stop_cmd(idefloppy_pc_t *pc, int start)
 {
        idefloppy_init_pc(pc);
-       pc->c[0] = IDEFLOPPY_START_STOP_CMD;
+       pc->c[0] = GPCMD_START_STOP_UNIT;
        pc->c[4] = start;
 }
 
 static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc)
 {
        idefloppy_init_pc(pc);
-       pc->c[0] = IDEFLOPPY_TEST_UNIT_READY_CMD;
+       pc->c[0] = GPCMD_TEST_UNIT_READY;
 }
 
-static void idefloppy_create_rw_cmd (idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq, unsigned long sector)
+static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
+                                   idefloppy_pc_t *pc, struct request *rq,
+                                   unsigned long sector)
 {
        int block = sector / floppy->bs_factor;
        int blocks = rq->nr_sectors / floppy->bs_factor;
        int cmd = rq_data_dir(rq);
 
-       debug_log("create_rw1%d_cmd: block == %d, blocks == %d\n",
-               2 * test_bit (IDEFLOPPY_USE_READ12, &floppy->flags),
+       debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
                block, blocks);
 
        idefloppy_init_pc(pc);
-       if (test_bit(IDEFLOPPY_USE_READ12, &floppy->flags)) {
-               pc->c[0] = cmd == READ ? IDEFLOPPY_READ12_CMD : IDEFLOPPY_WRITE12_CMD;
-               put_unaligned(htonl(blocks), (unsigned int *) &pc->c[6]);
-       } else {
-               pc->c[0] = cmd == READ ? IDEFLOPPY_READ10_CMD : IDEFLOPPY_WRITE10_CMD;
-               put_unaligned(htons(blocks), (unsigned short *) &pc->c[7]);
-       }
-       put_unaligned(htonl(block), (unsigned int *) &pc->c[2]);
+       pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
+       put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
+       put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
+
        pc->callback = &idefloppy_rw_callback;
        pc->rq = rq;
        pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
        if (rq->cmd_flags & REQ_RW)
-               set_bit(PC_WRITING, &pc->flags);
+               pc->flags |= PC_FLAG_WRITING;
        pc->buffer = NULL;
        pc->request_transfer = pc->buffer_size = blocks * floppy->block_size;
-       set_bit(PC_DMA_RECOMMENDED, &pc->flags);
+       pc->flags |= PC_FLAG_DMA_RECOMMENDED;
 }
 
-static void
-idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq)
+static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
+               idefloppy_pc_t *pc, struct request *rq)
 {
        idefloppy_init_pc(pc);
        pc->callback = &idefloppy_rw_callback;
@@ -1164,11 +893,10 @@ idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct req
        pc->rq = rq;
        pc->b_count = rq->data_len;
        if (rq->data_len && rq_data_dir(rq) == WRITE)
-               set_bit(PC_WRITING, &pc->flags);
+               pc->flags |= PC_FLAG_WRITING;
        pc->buffer = rq->data;
        if (rq->bio)
-               set_bit(PC_DMA_RECOMMENDED, &pc->flags);
-               
+               pc->flags |= PC_FLAG_DMA_RECOMMENDED;
        /*
         * possibly problematic, doesn't look like ide-floppy correctly
         * handled scattered requests if dma fails...
@@ -1176,30 +904,23 @@ idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct req
        pc->request_transfer = pc->buffer_size = rq->data_len;
 }
 
-/*
- *     idefloppy_do_request is our request handling function.  
- */
-static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request *rq, sector_t block_s)
+static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
+               struct request *rq, sector_t block_s)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        idefloppy_pc_t *pc;
        unsigned long block = (unsigned long)block_s;
 
-       debug_log(KERN_INFO "dev: %s, flags: %lx, errors: %d\n",
+       debug_log("dev: %s, cmd_type: %x, errors: %d\n",
                        rq->rq_disk ? rq->rq_disk->disk_name : "?",
-                       rq->flags, rq->errors);
-       debug_log(KERN_INFO "sector: %ld, nr_sectors: %ld, "
+                       rq->cmd_type, rq->errors);
+       debug_log("sector: %ld, nr_sectors: %ld, "
                        "current_nr_sectors: %d\n", (long)rq->sector,
                        rq->nr_sectors, rq->current_nr_sectors);
 
        if (rq->errors >= ERROR_MAX) {
-               if (floppy->failed_pc != NULL) {
-                       if (idefloppy_should_report_error(floppy))
-                               printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x,"
-                                      " key = %2x, asc = %2x, ascq = %2x\n",
-                                      drive->name, floppy->failed_pc->c[0],
-                                      floppy->sense_key, floppy->asc, floppy->ascq);
-               }
+               if (floppy->failed_pc)
+                       ide_floppy_report_error(floppy, floppy->failed_pc);
                else
                        printk(KERN_ERR "ide-floppy: %s: I/O error\n",
                                drive->name);
@@ -1209,8 +930,8 @@ static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request
        if (blk_fs_request(rq)) {
                if (((long)rq->sector % floppy->bs_factor) ||
                    (rq->nr_sectors % floppy->bs_factor)) {
-                       printk("%s: unsupported r/w request size\n",
-                               drive->name);
+                       printk(KERN_ERR "%s: unsupported r/w request size\n",
+                                       drive->name);
                        idefloppy_do_end_request(drive, 0, 0);
                        return ide_stopped;
                }
@@ -1233,15 +954,15 @@ static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request
 }
 
 /*
- *     idefloppy_queue_pc_tail adds a special packet command request to the
- *     tail of the request queue, and waits for it to be serviced.
+ * Add a special packet command request to the tail of the request queue,
+ * and wait for it to be serviced.
  */
-static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc)
+static int idefloppy_queue_pc_tail(ide_drive_t *drive, idefloppy_pc_t *pc)
 {
        struct ide_floppy_obj *floppy = drive->driver_data;
        struct request rq;
 
-       ide_init_drive_cmd (&rq);
+       ide_init_drive_cmd(&rq);
        rq.buffer = (char *) pc;
        rq.cmd_type = REQ_TYPE_SPECIAL;
        rq.rq_disk = floppy->disk;
@@ -1250,88 +971,90 @@ static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc)
 }
 
 /*
- *     Look at the flexible disk page parameters. We will ignore the CHS
- *     capacity parameters and use the LBA parameters instead.
+ * Look at the flexible disk page parameters. We ignore the CHS capacity
+ * parameters and use the LBA parameters instead.
  */
-static int idefloppy_get_flexible_disk_page (ide_drive_t *drive)
+static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        idefloppy_pc_t pc;
-       idefloppy_mode_parameter_header_t *header;
-       idefloppy_flexible_disk_page_t *page;
+       u8 *page;
        int capacity, lba_capacity;
+       u16 transfer_rate, sector_size, cyls, rpm;
+       u8 heads, sectors;
+
+       idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE,
+                                       MODE_SENSE_CURRENT);
 
-       idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, MODE_SENSE_CURRENT);
-       if (idefloppy_queue_pc_tail(drive,&pc)) {
-               printk(KERN_ERR "ide-floppy: Can't get flexible disk "
-                       "page parameters\n");
+       if (idefloppy_queue_pc_tail(drive, &pc)) {
+               printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
+                               " parameters\n");
                return 1;
        }
-       header = (idefloppy_mode_parameter_header_t *) pc.buffer;
-       floppy->wp = header->wp;
+       floppy->wp = !!(pc.buffer[3] & 0x80);
        set_disk_ro(floppy->disk, floppy->wp);
-       page = (idefloppy_flexible_disk_page_t *) (header + 1);
-
-       page->transfer_rate = ntohs(page->transfer_rate);
-       page->sector_size = ntohs(page->sector_size);
-       page->cyls = ntohs(page->cyls);
-       page->rpm = ntohs(page->rpm);
-       capacity = page->cyls * page->heads * page->sectors * page->sector_size;
-       if (memcmp (page, &floppy->flexible_disk_page, sizeof (idefloppy_flexible_disk_page_t)))
+       page = &pc.buffer[8];
+
+       transfer_rate = be16_to_cpu(*(u16 *)&pc.buffer[8 + 2]);
+       sector_size   = be16_to_cpu(*(u16 *)&pc.buffer[8 + 6]);
+       cyls          = be16_to_cpu(*(u16 *)&pc.buffer[8 + 8]);
+       rpm           = be16_to_cpu(*(u16 *)&pc.buffer[8 + 28]);
+       heads         = pc.buffer[8 + 4];
+       sectors       = pc.buffer[8 + 5];
+
+       capacity = cyls * heads * sectors * sector_size;
+
+       if (memcmp(page, &floppy->flexible_disk_page, 32))
                printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
                                "%d sector size, %d rpm\n",
-                       drive->name, capacity / 1024, page->cyls,
-                       page->heads, page->sectors,
-                       page->transfer_rate / 8, page->sector_size, page->rpm);
-
-       floppy->flexible_disk_page = *page;
-       drive->bios_cyl = page->cyls;
-       drive->bios_head = page->heads;
-       drive->bios_sect = page->sectors;
+                               drive->name, capacity / 1024, cyls, heads,
+                               sectors, transfer_rate / 8, sector_size, rpm);
+
+       memcpy(&floppy->flexible_disk_page, page, 32);
+       drive->bios_cyl = cyls;
+       drive->bios_head = heads;
+       drive->bios_sect = sectors;
        lba_capacity = floppy->blocks * floppy->block_size;
+
        if (capacity < lba_capacity) {
                printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
                        "bytes, but the drive only handles %d\n",
                        drive->name, lba_capacity, capacity);
-               floppy->blocks = floppy->block_size ? capacity / floppy->block_size : 0;
+               floppy->blocks = floppy->block_size ?
+                       capacity / floppy->block_size : 0;
        }
        return 0;
 }
 
-static int idefloppy_get_capability_page(ide_drive_t *drive)
+static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        idefloppy_pc_t pc;
-       idefloppy_mode_parameter_header_t *header;
-       idefloppy_capabilities_page_t *page;
 
        floppy->srfp = 0;
        idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
                                                 MODE_SENSE_CURRENT);
 
-       set_bit(PC_SUPPRESS_ERROR, &pc.flags);
-       if (idefloppy_queue_pc_tail(drive,&pc)) {
+       pc.flags |= PC_FLAG_SUPPRESS_ERROR;
+       if (idefloppy_queue_pc_tail(drive, &pc))
                return 1;
-       }
 
-       header = (idefloppy_mode_parameter_header_t *) pc.buffer;
-       page= (idefloppy_capabilities_page_t *)(header+1);
-       floppy->srfp = page->srfp;
+       floppy->srfp = pc.buffer[8 + 2] & 0x40;
        return (0);
 }
 
 /*
- *     Determine if a media is present in the floppy drive, and if so,
- *     its LBA capacity.
+ * Determine if a media is present in the floppy drive, and if so, its LBA
+ * capacity.
  */
-static int idefloppy_get_capacity (ide_drive_t *drive)
+static int ide_floppy_get_capacity(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        idefloppy_pc_t pc;
-       idefloppy_capacity_header_t *header;
-       idefloppy_capacity_descriptor_t *descriptor;
-       int i, descriptors, rc = 1, blocks, length;
-       
+       u8 *cap_desc;
+       u8 header_len, desc_cnt;
+       int i, rc = 1, blocks, length;
+
        drive->bios_cyl = 0;
        drive->bios_head = drive->bios_sect = 0;
        floppy->blocks = 0;
@@ -1343,44 +1066,55 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
                printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
                return 1;
        }
-       header = (idefloppy_capacity_header_t *) pc.buffer;
-       descriptors = header->length / sizeof(idefloppy_capacity_descriptor_t);
-       descriptor = (idefloppy_capacity_descriptor_t *) (header + 1);
+       header_len = pc.buffer[3];
+       cap_desc = &pc.buffer[4];
+       desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
+
+       for (i = 0; i < desc_cnt; i++) {
+               unsigned int desc_start = 4 + i*8;
+
+               blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
+               length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
 
-       for (i = 0; i < descriptors; i++, descriptor++) {
-               blocks = descriptor->blocks = ntohl(descriptor->blocks);
-               length = descriptor->length = ntohs(descriptor->length);
+               debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
+                               i, blocks * length / 1024, blocks, length);
 
-               if (!i) 
-               {
-               switch (descriptor->dc) {
+               if (i)
+                       continue;
+               /*
+                * the code below is valid only for the 1st descriptor, ie i=0
+                */
+
+               switch (pc.buffer[desc_start + 4] & 0x03) {
                /* Clik! drive returns this instead of CAPACITY_CURRENT */
                case CAPACITY_UNFORMATTED:
-                       if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
-                                /*
+                       if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE))
+                               /*
                                 * If it is not a clik drive, break out
                                 * (maintains previous driver behaviour)
                                 */
                                break;
                case CAPACITY_CURRENT:
                        /* Normal Zip/LS-120 disks */
-                       if (memcmp(descriptor, &floppy->capacity, sizeof (idefloppy_capacity_descriptor_t)))
+                       if (memcmp(cap_desc, &floppy->cap_desc, 8))
                                printk(KERN_INFO "%s: %dkB, %d blocks, %d "
                                        "sector size\n", drive->name,
                                        blocks * length / 1024, blocks, length);
-                       floppy->capacity = *descriptor;
+                       memcpy(&floppy->cap_desc, cap_desc, 8);
+
                        if (!length || length % 512) {
                                printk(KERN_NOTICE "%s: %d bytes block size "
                                        "not supported\n", drive->name, length);
                        } else {
-                                floppy->blocks = blocks;
-                                floppy->block_size = length;
-                                if ((floppy->bs_factor = length / 512) != 1)
-                                        printk(KERN_NOTICE "%s: warning: non "
+                               floppy->blocks = blocks;
+                               floppy->block_size = length;
+                               floppy->bs_factor = length / 512;
+                               if (floppy->bs_factor != 1)
+                                       printk(KERN_NOTICE "%s: warning: non "
                                                "512 bytes block size not "
                                                "fully supported\n",
                                                drive->name);
-                                rc = 0;
+                               rc = 0;
                        }
                        break;
                case CAPACITY_NO_CARTRIDGE:
@@ -1395,54 +1129,42 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
                                "in drive\n", drive->name);
                        break;
                }
-               }
-               if (!i) {
-                       debug_log( "Descriptor 0 Code: %d\n",
-                               descriptor->dc);
-               }
-               debug_log( "Descriptor %d: %dkB, %d blocks, %d "
-                       "sector size\n", i, blocks * length / 1024, blocks,
-                       length);
+               debug_log("Descriptor 0 Code: %d\n",
+                         pc.buffer[desc_start + 4] & 0x03);
        }
 
        /* Clik! disk does not support get_flexible_disk_page */
-        if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
-               (void) idefloppy_get_flexible_disk_page(drive);
-       }
+       if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE))
+               (void) ide_floppy_get_flexible_disk_page(drive);
 
        set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
        return rc;
 }
 
 /*
-** Obtain the list of formattable capacities.
-** Very similar to idefloppy_get_capacity, except that we push the capacity
-** descriptors to userland, instead of our own structures.
-**
-** Userland gives us the following structure:
-**
-** struct idefloppy_format_capacities {
-**        int nformats;
-**        struct {
-**                int nblocks;
-**                int blocksize;
-**                } formats[];
-**        } ;
-**
-** userland initializes nformats to the number of allocated formats[]
-** records.  On exit we set nformats to the number of records we've
-** actually initialized.
-**
-*/
-
-static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
+ * Obtain the list of formattable capacities.
+ * Very similar to ide_floppy_get_capacity, except that we push the capacity
+ * descriptors to userland, instead of our own structures.
+ *
+ * Userland gives us the following structure:
+ *
+ * struct idefloppy_format_capacities {
+ *     int nformats;
+ *     struct {
+ *             int nblocks;
+ *             int blocksize;
+ *     } formats[];
+ * };
+ *
+ * userland initializes nformats to the number of allocated formats[] records.
+ * On exit we set nformats to the number of records we've actually initialized.
+ */
+
+static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
 {
-        idefloppy_pc_t pc;
-       idefloppy_capacity_header_t *header;
-        idefloppy_capacity_descriptor_t *descriptor;
-       int i, descriptors, blocks, length;
-       int u_array_size;
-       int u_index;
+       idefloppy_pc_t pc;
+       u8 header_len, desc_cnt;
+       int i, blocks, length, u_array_size, u_index;
        int __user *argp;
 
        if (get_user(u_array_size, arg))
@@ -1454,30 +1176,27 @@ static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
        idefloppy_create_read_capacity_cmd(&pc);
        if (idefloppy_queue_pc_tail(drive, &pc)) {
                printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
-                return (-EIO);
-        }
-        header = (idefloppy_capacity_header_t *) pc.buffer;
-        descriptors = header->length /
-               sizeof(idefloppy_capacity_descriptor_t);
-       descriptor = (idefloppy_capacity_descriptor_t *) (header + 1);
+               return (-EIO);
+       }
+       header_len = pc.buffer[3];
+       desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
 
        u_index = 0;
        argp = arg + 1;
 
        /*
-       ** We always skip the first capacity descriptor.  That's the
-       ** current capacity.  We are interested in the remaining descriptors,
-       ** the formattable capacities.
-       */
+        * We always skip the first capacity descriptor.  That's the current
+        * capacity.  We are interested in the remaining descriptors, the
+        * formattable capacities.
+        */
+       for (i = 1; i < desc_cnt; i++) {
+               unsigned int desc_start = 4 + i*8;
 
-       for (i=0; i<descriptors; i++, descriptor++) {
                if (u_index >= u_array_size)
                        break;  /* User-supplied buffer too small */
-               if (i == 0)
-                       continue;       /* Skip the first descriptor */
 
-               blocks = ntohl(descriptor->blocks);
-               length = ntohs(descriptor->length);
+               blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
+               length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
 
                if (put_user(blocks, argp))
                        return(-EFAULT);
@@ -1496,53 +1215,14 @@ static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
 }
 
 /*
-** Send ATAPI_FORMAT_UNIT to the drive.
-**
-** Userland gives us the following structure:
-**
-** struct idefloppy_format_command {
-**        int nblocks;
-**        int blocksize;
-**        int flags;
-**        } ;
-**
-** flags is a bitmask, currently, the only defined flag is:
-**
-**        0x01 - verify media after format.
-*/
-
-static int idefloppy_begin_format(ide_drive_t *drive, int __user *arg)
-{
-       int blocks;
-       int length;
-       int flags;
-       idefloppy_pc_t pc;
-
-       if (get_user(blocks, arg) ||
-           get_user(length, arg+1) ||
-           get_user(flags, arg+2)) {
-               return (-EFAULT);
-       }
-
-       /* Get the SFRP bit */
-       (void) idefloppy_get_capability_page(drive);
-       idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
-       if (idefloppy_queue_pc_tail(drive, &pc)) {
-                return (-EIO);
-       }
-
-       return (0);
-}
-
-/*
-** Get ATAPI_FORMAT_UNIT progress indication.
-**
-** Userland gives a pointer to an int.  The int is set to a progress
-** indicator 0-65536, with 65536=100%.
-**
-** If the drive does not support format progress indication, we just check
-** the dsc bit, and return either 0 or 65536.
-*/
+ * Get ATAPI_FORMAT_UNIT progress indication.
+ *
+ * Userland gives a pointer to an int.  The int is set to a progress
+ * indicator 0-65536, with 65536=100%.
+ *
+ * If the drive does not support format progress indication, we just check
+ * the dsc bit, and return either 0 or 65536.
+ */
 
 static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
 {
@@ -1552,23 +1232,21 @@ static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
 
        if (floppy->srfp) {
                idefloppy_create_request_sense_cmd(&pc);
-               if (idefloppy_queue_pc_tail(drive, &pc)) {
+               if (idefloppy_queue_pc_tail(drive, &pc))
                        return (-EIO);
-               }
 
                if (floppy->sense_key == 2 &&
                    floppy->asc == 4 &&
-                   floppy->ascq == 4) {
+                   floppy->ascq == 4)
                        progress_indication = floppy->progress_indication;
-               }
-               /* Else assume format_unit has finished, and we're
-               ** at 0x10000 */
+
+               /* Else assume format_unit has finished, and we're at 0x10000 */
        } else {
                unsigned long flags;
                u8 stat;
 
                local_irq_save(flags);
-               stat = drive->hwif->INB(IDE_STATUS_REG);
+               stat = ide_read_status(drive);
                local_irq_restore(flags);
 
                progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
@@ -1579,10 +1257,7 @@ static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
        return (0);
 }
 
-/*
- *     Return the current floppy capacity.
- */
-static sector_t idefloppy_capacity (ide_drive_t *drive)
+static sector_t idefloppy_capacity(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        unsigned long capacity = floppy->blocks * floppy->bs_factor;
@@ -1591,15 +1266,12 @@ static sector_t idefloppy_capacity (ide_drive_t *drive)
 }
 
 /*
- *     idefloppy_identify_device checks if we can support a drive,
- *     based on the ATAPI IDENTIFY command results.
+ * Check whether we can support a drive, based on the ATAPI IDENTIFY command
+ * results.
  */
-static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id)
+static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
 {
        struct idefloppy_id_gcw gcw;
-#if IDEFLOPPY_DEBUG_INFO
-       char buffer[80];
-#endif /* IDEFLOPPY_DEBUG_INFO */
 
        *((u16 *) &gcw) = id->config;
 
@@ -1608,54 +1280,23 @@ static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id)
        if ((gcw.device_type == 5) &&
            !strstr(id->model, "CD-ROM") &&
            strstr(id->model, "ZIP"))
-               gcw.device_type = 0;                    
+               gcw.device_type = 0;
 #endif
 
-#if IDEFLOPPY_DEBUG_INFO
-       printk(KERN_INFO "Dumping ATAPI Identify Device floppy parameters\n");
-       switch (gcw.protocol) {
-               case 0: case 1: sprintf(buffer, "ATA");break;
-               case 2: sprintf(buffer, "ATAPI");break;
-               case 3: sprintf(buffer, "Reserved (Unknown to ide-floppy)");break;
-       }
-       printk(KERN_INFO "Protocol Type: %s\n", buffer);
-       switch (gcw.device_type) {
-               case 0: sprintf(buffer, "Direct-access Device");break;
-               case 1: sprintf(buffer, "Streaming Tape Device");break;
-               case 2: case 3: case 4: sprintf (buffer, "Reserved");break;
-               case 5: sprintf(buffer, "CD-ROM Device");break;
-               case 6: sprintf(buffer, "Reserved");
-               case 7: sprintf(buffer, "Optical memory Device");break;
-               case 0x1f: sprintf(buffer, "Unknown or no Device type");break;
-               default: sprintf(buffer, "Reserved");
-       }
-       printk(KERN_INFO "Device Type: %x - %s\n", gcw.device_type, buffer);
-       printk(KERN_INFO "Removable: %s\n",gcw.removable ? "Yes":"No"); 
-       switch (gcw.drq_type) {
-               case 0: sprintf(buffer, "Microprocessor DRQ");break;
-               case 1: sprintf(buffer, "Interrupt DRQ");break;
-               case 2: sprintf(buffer, "Accelerated DRQ");break;
-               case 3: sprintf(buffer, "Reserved");break;
-       }
-       printk(KERN_INFO "Command Packet DRQ Type: %s\n", buffer);
-       switch (gcw.packet_size) {
-               case 0: sprintf(buffer, "12 bytes");break;
-               case 1: sprintf(buffer, "16 bytes");break;
-               default: sprintf(buffer, "Reserved");break;
-       }
-       printk(KERN_INFO "Command Packet Size: %s\n", buffer);
-#endif /* IDEFLOPPY_DEBUG_INFO */
-
        if (gcw.protocol != 2)
-               printk(KERN_ERR "ide-floppy: Protocol is not ATAPI\n");
+               printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
+                               gcw.protocol);
        else if (gcw.device_type != 0)
-               printk(KERN_ERR "ide-floppy: Device type is not set to floppy\n");
+               printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
+                               "to floppy\n", gcw.device_type);
        else if (!gcw.removable)
                printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
        else if (gcw.drq_type == 3) {
-               printk(KERN_ERR "ide-floppy: Sorry, DRQ type %d not supported\n", gcw.drq_type);
+               printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
+                               "supported\n", gcw.drq_type);
        } else if (gcw.packet_size != 0) {
-               printk(KERN_ERR "ide-floppy: Packet size is not 12 bytes long\n");
+               printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
+                               "bytes long\n", gcw.packet_size);
        } else
                return 1;
        return 0;
@@ -1666,59 +1307,53 @@ static void idefloppy_add_settings(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
 
-/*
- *                     drive   setting name    read/write      data type       min     max     mul_factor      div_factor      data pointer            set function
- */
-       ide_add_setting(drive,  "bios_cyl",     SETTING_RW,     TYPE_INT,       0,      1023,           1,              1,      &drive->bios_cyl,       NULL);
-       ide_add_setting(drive,  "bios_head",    SETTING_RW,     TYPE_BYTE,      0,      255,            1,              1,      &drive->bios_head,      NULL);
-       ide_add_setting(drive,  "bios_sect",    SETTING_RW,     TYPE_BYTE,      0,      63,             1,              1,      &drive->bios_sect,      NULL);
-       ide_add_setting(drive,  "ticks",        SETTING_RW,     TYPE_BYTE,      0,      255,            1,              1,      &floppy->ticks,         NULL);
+       ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1,
+                       &drive->bios_cyl, NULL);
+       ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
+                       &drive->bios_head, NULL);
+       ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0,  63, 1, 1,
+                       &drive->bios_sect, NULL);
+       ide_add_setting(drive, "ticks",    SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
+                       &floppy->ticks,  NULL);
 }
 #else
 static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
 #endif
 
-/*
- *     Driver initialization.
- */
-static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy)
+static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
 {
        struct idefloppy_id_gcw gcw;
 
        *((u16 *) &gcw) = drive->id->config;
        floppy->pc = floppy->pc_stack;
        if (gcw.drq_type == 1)
-               set_bit(IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags);
+               floppy->flags |= IDEFLOPPY_FLAG_DRQ_INTERRUPT;
        /*
-        *      We used to check revisions here. At this point however
-        *      I'm giving up. Just assume they are all broken, its easier.
+        * We used to check revisions here. At this point however I'm giving up.
+        * Just assume they are all broken, its easier.
         *
-        *      The actual reason for the workarounds was likely
-        *      a driver bug after all rather than a firmware bug,
-        *      and the workaround below used to hide it. It should
-        *      be fixed as of version 1.9, but to be on the safe side
-        *      we'll leave the limitation below for the 2.2.x tree.
+        * The actual reason for the workarounds was likely a driver bug after
+        * all rather than a firmware bug, and the workaround below used to hide
+        * it. It should be fixed as of version 1.9, but to be on the safe side
+        * we'll leave the limitation below for the 2.2.x tree.
         */
-
        if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) {
-               set_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags);
+               floppy->flags |= IDEFLOPPY_FLAG_ZIP_DRIVE;
                /* This value will be visible in the /proc/ide/hdx/settings */
                floppy->ticks = IDEFLOPPY_TICKS_DELAY;
                blk_queue_max_sectors(drive->queue, 64);
        }
 
        /*
-       *      Guess what?  The IOMEGA Clik! drive also needs the
-       *      above fix.  It makes nasty clicking noises without
-       *      it, so please don't remove this.
-       */
+        * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
+        * nasty clicking noises without it, so please don't remove this.
+        */
        if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) {
                blk_queue_max_sectors(drive->queue, 64);
-               set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags);
+               floppy->flags |= IDEFLOPPY_FLAG_CLIK_DRIVE;
        }
 
-
-       (void) idefloppy_get_capacity(drive);
+       (void) ide_floppy_get_capacity(drive);
        idefloppy_add_settings(drive);
 }
 
@@ -1734,7 +1369,7 @@ static void ide_floppy_remove(ide_drive_t *drive)
        ide_floppy_put(floppy);
 }
 
-static void ide_floppy_release(struct kref *kref)
+static void idefloppy_cleanup_obj(struct kref *kref)
 {
        struct ide_floppy_obj *floppy = to_ide_floppy(kref);
        ide_drive_t *drive = floppy->drive;
@@ -1747,19 +1382,19 @@ static void ide_floppy_release(struct kref *kref)
 }
 
 #ifdef CONFIG_IDE_PROC_FS
-static int proc_idefloppy_read_capacity
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
+               int count, int *eof, void *data)
 {
        ide_drive_t*drive = (ide_drive_t *)data;
        int len;
 
-       len = sprintf(page,"%llu\n", (long long)idefloppy_capacity(drive));
-       PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
+       len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
+       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
 }
 
 static ide_proc_entry_t idefloppy_proc[] = {
-       { "capacity",   S_IFREG|S_IRUGO,        proc_idefloppy_read_capacity, NULL },
-       { "geometry",   S_IFREG|S_IRUGO,        proc_ide_read_geometry, NULL },
+       { "capacity",   S_IFREG|S_IRUGO, proc_idefloppy_read_capacity,  NULL },
+       { "geometry",   S_IFREG|S_IRUGO, proc_ide_read_geometry,        NULL },
        { NULL, 0, NULL, NULL }
 };
 #endif /* CONFIG_IDE_PROC_FS */
@@ -1794,9 +1429,10 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
        idefloppy_pc_t pc;
        int ret = 0;
 
-       debug_log(KERN_INFO "Reached idefloppy_open\n");
+       debug_log("Reached %s\n", __func__);
 
-       if (!(floppy = ide_floppy_get(disk)))
+       floppy = ide_floppy_get(disk);
+       if (!floppy)
                return -ENXIO;
 
        drive = floppy->drive;
@@ -1804,7 +1440,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
        floppy->openers++;
 
        if (floppy->openers == 1) {
-               clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
+               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
                /* Just in case */
 
                idefloppy_create_test_unit_ready_cmd(&pc);
@@ -1813,13 +1449,13 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
                        (void) idefloppy_queue_pc_tail(drive, &pc);
                }
 
-               if (idefloppy_get_capacity (drive)
+               if (ide_floppy_get_capacity(drive)
                   && (filp->f_flags & O_NDELAY) == 0
                    /*
-                   ** Allow O_NDELAY to open a drive without a disk, or with
-                   ** an unreadable disk, so that we can get the format
-                   ** capacity of the drive or begin the format - Sam
-                   */
+                    * Allow O_NDELAY to open a drive without a disk, or with an
+                    * unreadable disk, so that we can get the format capacity
+                    * of the drive or begin the format - Sam
+                    */
                    ) {
                        ret = -EIO;
                        goto out_put_floppy;
@@ -1829,14 +1465,14 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
                        ret = -EROFS;
                        goto out_put_floppy;
                }
-               set_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
+               floppy->flags |= IDEFLOPPY_FLAG_MEDIA_CHANGED;
                /* IOMEGA Clik! drives do not support lock/unlock commands */
-                if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
+               if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
                        idefloppy_create_prevent_cmd(&pc, 1);
                        (void) idefloppy_queue_pc_tail(drive, &pc);
                }
                check_disk_change(inode->i_bdev);
-       } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) {
+       } else if (floppy->flags & IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS) {
                ret = -EBUSY;
                goto out_put_floppy;
        }
@@ -1854,17 +1490,17 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
        struct ide_floppy_obj *floppy = ide_floppy_g(disk);
        ide_drive_t *drive = floppy->drive;
        idefloppy_pc_t pc;
-       
-       debug_log(KERN_INFO "Reached idefloppy_release\n");
+
+       debug_log("Reached %s\n", __func__);
 
        if (floppy->openers == 1) {
                /* IOMEGA Clik! drives do not support lock/unlock commands */
-                if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
+               if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
                        idefloppy_create_prevent_cmd(&pc, 0);
                        (void) idefloppy_queue_pc_tail(drive, &pc);
                }
 
-               clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
+               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
        }
 
        floppy->openers--;
@@ -1885,64 +1521,105 @@ static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        return 0;
 }
 
+static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc,
+                              unsigned long arg, unsigned int cmd)
+{
+       if (floppy->openers > 1)
+               return -EBUSY;
+
+       /* The IOMEGA Clik! Drive doesn't support this command -
+        * no room for an eject mechanism */
+       if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
+               int prevent = arg ? 1 : 0;
+
+               if (cmd == CDROMEJECT)
+                       prevent = 0;
+
+               idefloppy_create_prevent_cmd(pc, prevent);
+               (void) idefloppy_queue_pc_tail(floppy->drive, pc);
+       }
+
+       if (cmd == CDROMEJECT) {
+               idefloppy_create_start_stop_cmd(pc, 2);
+               (void) idefloppy_queue_pc_tail(floppy->drive, pc);
+       }
+
+       return 0;
+}
+
+static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
+                                 int __user *arg)
+{
+       int blocks, length, flags, err = 0;
+       idefloppy_pc_t pc;
+
+       if (floppy->openers > 1) {
+               /* Don't format if someone is using the disk */
+               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+               return -EBUSY;
+       }
+
+       floppy->flags |= IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+
+       /*
+        * Send ATAPI_FORMAT_UNIT to the drive.
+        *
+        * Userland gives us the following structure:
+        *
+        * struct idefloppy_format_command {
+        *        int nblocks;
+        *        int blocksize;
+        *        int flags;
+        *        } ;
+        *
+        * flags is a bitmask, currently, the only defined flag is:
+        *
+        *        0x01 - verify media after format.
+        */
+       if (get_user(blocks, arg) ||
+                       get_user(length, arg+1) ||
+                       get_user(flags, arg+2)) {
+               err = -EFAULT;
+               goto out;
+       }
+
+       (void) idefloppy_get_sfrp_bit(floppy->drive);
+       idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
+
+       if (idefloppy_queue_pc_tail(floppy->drive, &pc))
+               err = -EIO;
+
+out:
+       if (err)
+               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+       return err;
+}
+
+
 static int idefloppy_ioctl(struct inode *inode, struct file *file,
                        unsigned int cmd, unsigned long arg)
 {
        struct block_device *bdev = inode->i_bdev;
        struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
        ide_drive_t *drive = floppy->drive;
+       idefloppy_pc_t pc;
        void __user *argp = (void __user *)arg;
        int err;
-       int prevent = (arg) ? 1 : 0;
-       idefloppy_pc_t pc;
 
        switch (cmd) {
        case CDROMEJECT:
-               prevent = 0;
                /* fall through */
        case CDROM_LOCKDOOR:
-               if (floppy->openers > 1)
-                       return -EBUSY;
-
-               /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
-                if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
-                       idefloppy_create_prevent_cmd(&pc, prevent);
-                       (void) idefloppy_queue_pc_tail(drive, &pc);
-               }
-               if (cmd == CDROMEJECT) {
-                       idefloppy_create_start_stop_cmd(&pc, 2);
-                       (void) idefloppy_queue_pc_tail(drive, &pc);
-               }
-               return 0;
+               return ide_floppy_lockdoor(floppy, &pc, arg, cmd);
        case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
                return 0;
        case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
-               return idefloppy_get_format_capacities(drive, argp);
+               return ide_floppy_get_format_capacities(drive, argp);
        case IDEFLOPPY_IOCTL_FORMAT_START:
-
                if (!(file->f_mode & 2))
                        return -EPERM;
 
-               if (floppy->openers > 1) {
-                       /* Don't format if someone is using the disk */
-
-                       clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS,
-                                 &floppy->flags);
-                       return -EBUSY;
-               }
-
-               set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
-
-               err = idefloppy_begin_format(drive, argp);
-               if (err)
-                       clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
-               return err;
-               /*
-               ** Note, the bit will be cleared when the device is
-               ** closed.  This is the cleanest way to handle the
-               ** situation where the drive does not support
-               ** format progress reporting.
-               */
+               return ide_floppy_format_unit(floppy, (int __user *)arg);
        case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
                return idefloppy_get_format_progress(drive, argp);
        }
@@ -1967,13 +1644,16 @@ static int idefloppy_media_changed(struct gendisk *disk)
 {
        struct ide_floppy_obj *floppy = ide_floppy_g(disk);
        ide_drive_t *drive = floppy->drive;
+       int ret;
 
        /* do not scan partitions twice if this is a removable device */
        if (drive->attach) {
                drive->attach = 0;
                return 0;
        }
-       return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
+       ret = !!(floppy->flags & IDEFLOPPY_FLAG_MEDIA_CHANGED);
+       floppy->flags &= ~IDEFLOPPY_FLAG_MEDIA_CHANGED;
+       return ret;
 }
 
 static int idefloppy_revalidate_disk(struct gendisk *disk)
@@ -2004,16 +1684,20 @@ static int ide_floppy_probe(ide_drive_t *drive)
                goto failed;
        if (drive->media != ide_floppy)
                goto failed;
-       if (!idefloppy_identify_device (drive, drive->id)) {
-               printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
+       if (!idefloppy_identify_device(drive, drive->id)) {
+               printk(KERN_ERR "ide-floppy: %s: not supported by this version"
+                               " of ide-floppy\n", drive->name);
                goto failed;
        }
        if (drive->scsi) {
-               printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
+               printk(KERN_INFO "ide-floppy: passing drive %s to ide-scsi"
+                               " emulation.\n", drive->name);
                goto failed;
        }
-       if ((floppy = kzalloc(sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
-               printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
+       floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
+       if (!floppy) {
+               printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"
+                               " structure\n", drive->name);
                goto failed;
        }
 
@@ -2035,7 +1719,7 @@ static int ide_floppy_probe(ide_drive_t *drive)
 
        drive->driver_data = floppy;
 
-       idefloppy_setup (drive, floppy);
+       idefloppy_setup(drive, floppy);
 
        g->minors = 1 << PARTN_BITS;
        g->driverfs_dev = &drive->gendev;
@@ -2051,9 +1735,7 @@ failed:
        return -ENODEV;
 }
 
-MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
-
-static void __exit idefloppy_exit (void)
+static void __exit idefloppy_exit(void)
 {
        driver_unregister(&idefloppy_driver.gen_driver);
 }
@@ -2068,3 +1750,5 @@ MODULE_ALIAS("ide:*m-floppy*");
 module_init(idefloppy_init);
 module_exit(idefloppy_exit);
 MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
+
index bb30c29f6ec04599d7d55d86ffc5cdc351c3b9c4..709b9e4d2871239f75c8f6b8f59834f8375f003f 100644 (file)
@@ -20,10 +20,16 @@ static int __init ide_generic_init(void)
        if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
                ide_get_lock(NULL, NULL); /* for atari only */
 
-       for (i = 0; i < MAX_HWIFS; i++)
-               idx[i] = ide_hwifs[i].present ? 0xff : i;
+       for (i = 0; i < MAX_HWIFS; i++) {
+               ide_hwif_t *hwif = &ide_hwifs[i];
 
-       ide_device_add_all(idx);
+               if (hwif->io_ports[IDE_DATA_OFFSET] && !hwif->present)
+                       idx[i] = i;
+               else
+                       idx[i] = 0xff;
+       }
+
+       ide_device_add_all(idx, NULL);
 
        if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
                ide_release_lock();     /* for atari only */
index 4bddef0c0b965b341c5c96a16bc9d5d036ce9efc..3addbe478d26743701ba669c4ae6acf5b2050725 100644 (file)
@@ -466,7 +466,7 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
                return ide_stopped;
        }
 
-       if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
+       if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
                rq->errors |= ERROR_RESET;
 
        if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
@@ -493,7 +493,7 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
                /* add decoding error stuff */
        }
 
-       if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
+       if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
                /* force an abort */
                hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
 
@@ -821,9 +821,8 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
 #ifdef DEBUG
        printk("%s: DRIVE_CMD (null)\n", drive->name);
 #endif
-       ide_end_drive_cmd(drive,
-                       hwif->INB(IDE_STATUS_REG),
-                       hwif->INB(IDE_ERROR_REG));
+       ide_end_drive_cmd(drive, ide_read_status(drive), ide_read_error(drive));
+
        return ide_stopped;
 }
 
@@ -1231,7 +1230,7 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
                printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
                (void)HWIF(drive)->ide_dma_end(drive);
                ret = ide_error(drive, "dma timeout error",
-                                               hwif->INB(IDE_STATUS_REG));
+                               ide_read_status(drive));
        } else {
                printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
                hwif->dma_timeout(drive);
@@ -1355,7 +1354,8 @@ void ide_timer_expiry (unsigned long data)
                                        startstop = ide_dma_timeout_retry(drive, wait);
                                } else
                                        startstop =
-                                       ide_error(drive, "irq timeout", hwif->INB(IDE_STATUS_REG));
+                                       ide_error(drive, "irq timeout",
+                                                 ide_read_status(drive));
                        }
                        drive->service_time = jiffies - drive->service_start;
                        spin_lock_irq(&ide_lock);
index 16b1f6e12781a7c53a1e5ea1cb3b8bc786b971df..c32e759df2089a5229f211154f0642da5e6e3fed 100644 (file)
@@ -163,8 +163,6 @@ void SELECT_DRIVE (ide_drive_t *drive)
        HWIF(drive)->OUTB(drive->select.all, IDE_SELECT_REG);
 }
 
-EXPORT_SYMBOL(SELECT_DRIVE);
-
 void SELECT_MASK (ide_drive_t *drive, int mask)
 {
        if (HWIF(drive)->maskproc)
@@ -432,10 +430,10 @@ int drive_is_ready (ide_drive_t *drive)
         * about possible isa-pnp and pci-pnp issues yet.
         */
        if (IDE_CONTROL_REG)
-               stat = hwif->INB(IDE_ALTSTATUS_REG);
+               stat = ide_read_altstatus(drive);
        else
                /* Note: this may clear a pending IRQ!! */
-               stat = hwif->INB(IDE_STATUS_REG);
+               stat = ide_read_status(drive);
 
        if (stat & BUSY_STAT)
                /* drive busy:  definitely not interrupting */
@@ -460,23 +458,24 @@ EXPORT_SYMBOL(drive_is_ready);
  */
 static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout, u8 *rstat)
 {
-       ide_hwif_t *hwif = drive->hwif;
        unsigned long flags;
        int i;
        u8 stat;
 
        udelay(1);      /* spec allows drive 400ns to assert "BUSY" */
-       if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) {
+       stat = ide_read_status(drive);
+
+       if (stat & BUSY_STAT) {
                local_irq_set(flags);
                timeout += jiffies;
-               while ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) {
+               while ((stat = ide_read_status(drive)) & BUSY_STAT) {
                        if (time_after(jiffies, timeout)) {
                                /*
                                 * One last read after the timeout in case
                                 * heavy interrupt load made us not make any
                                 * progress during the timeout..
                                 */
-                               stat = hwif->INB(IDE_STATUS_REG);
+                               stat = ide_read_status(drive);
                                if (!(stat & BUSY_STAT))
                                        break;
 
@@ -496,7 +495,9 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti
         */
        for (i = 0; i < 10; i++) {
                udelay(1);
-               if (OK_STAT((stat = hwif->INB(IDE_STATUS_REG)), good, bad)) {
+               stat = ide_read_status(drive);
+
+               if (OK_STAT(stat, good, bad)) {
                        *rstat = stat;
                        return 0;
                }
@@ -614,71 +615,12 @@ no_80w:
        return 0;
 }
 
-int ide_ata66_check (ide_drive_t *drive, ide_task_t *args)
-{
-       if (args->tf.command == WIN_SETFEATURES &&
-           args->tf.nsect > XFER_UDMA_2 &&
-           args->tf.feature == SETFEATURES_XFER) {
-               if (eighty_ninty_three(drive) == 0) {
-                       printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
-                                           "be set\n", drive->name);
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-
-/*
- * Backside of HDIO_DRIVE_CMD call of SETFEATURES_XFER.
- * 1 : Safe to update drive->id DMA registers.
- * 0 : OOPs not allowed.
- */
-int set_transfer (ide_drive_t *drive, ide_task_t *args)
-{
-       if (args->tf.command == WIN_SETFEATURES &&
-           args->tf.nsect >= XFER_SW_DMA_0 &&
-           args->tf.feature == SETFEATURES_XFER &&
-           (drive->id->dma_ultra ||
-            drive->id->dma_mword ||
-            drive->id->dma_1word))
-               return 1;
-
-       return 0;
-}
-
-#ifdef CONFIG_BLK_DEV_IDEDMA
-static u8 ide_auto_reduce_xfer (ide_drive_t *drive)
-{
-       if (!drive->crc_count)
-               return drive->current_speed;
-       drive->crc_count = 0;
-
-       switch(drive->current_speed) {
-               case XFER_UDMA_7:       return XFER_UDMA_6;
-               case XFER_UDMA_6:       return XFER_UDMA_5;
-               case XFER_UDMA_5:       return XFER_UDMA_4;
-               case XFER_UDMA_4:       return XFER_UDMA_3;
-               case XFER_UDMA_3:       return XFER_UDMA_2;
-               case XFER_UDMA_2:       return XFER_UDMA_1;
-               case XFER_UDMA_1:       return XFER_UDMA_0;
-                       /*
-                        * OOPS we do not goto non Ultra DMA modes
-                        * without iCRC's available we force
-                        * the system to PIO and make the user
-                        * invoke the ATA-1 ATA-2 DMA modes.
-                        */
-               case XFER_UDMA_0:
-               default:                return XFER_PIO_4;
-       }
-}
-#endif /* CONFIG_BLK_DEV_IDEDMA */
-
 int ide_driveid_update(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct hd_driveid *id;
        unsigned long timeout, flags;
+       u8 stat;
 
        /*
         * Re-read drive->id for possible DMA mode
@@ -695,10 +637,15 @@ int ide_driveid_update(ide_drive_t *drive)
                        SELECT_MASK(drive, 0);
                        return 0;       /* drive timed-out */
                }
+
                msleep(50);     /* give drive a breather */
-       } while (hwif->INB(IDE_ALTSTATUS_REG) & BUSY_STAT);
+               stat = ide_read_altstatus(drive);
+       } while (stat & BUSY_STAT);
+
        msleep(50);     /* wait for IRQ and DRQ_STAT */
-       if (!OK_STAT(hwif->INB(IDE_STATUS_REG),DRQ_STAT,BAD_R_STAT)) {
+       stat = ide_read_status(drive);
+
+       if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) {
                SELECT_MASK(drive, 0);
                printk("%s: CHECK for good STATUS\n", drive->name);
                return 0;
@@ -711,7 +658,7 @@ int ide_driveid_update(ide_drive_t *drive)
                return 0;
        }
        ata_input_data(drive, id, SECTOR_WORDS);
-       (void) hwif->INB(IDE_STATUS_REG);       /* clear drive IRQ */
+       (void)ide_read_status(drive);   /* clear drive IRQ */
        local_irq_enable();
        local_irq_restore(flags);
        ide_fix_driveid(id);
@@ -882,22 +829,17 @@ void ide_execute_command(ide_drive_t *drive, u8 cmd, ide_handler_t *handler,
        unsigned long flags;
        ide_hwgroup_t *hwgroup = HWGROUP(drive);
        ide_hwif_t *hwif = HWIF(drive);
-       
+
        spin_lock_irqsave(&ide_lock, flags);
-       
        BUG_ON(hwgroup->handler);
-       hwgroup->handler        = handler;
-       hwgroup->expiry         = expiry;
-       hwgroup->timer.expires  = jiffies + timeout;
-       hwgroup->req_gen_timer = hwgroup->req_gen;
-       add_timer(&hwgroup->timer);
+       __ide_set_handler(drive, handler, timeout, expiry);
        hwif->OUTBSYNC(drive, cmd, IDE_COMMAND_REG);
-       /* Drive takes 400nS to respond, we must avoid the IRQ being
-          serviced before that. 
-          
-          FIXME: we could skip this delay with care on non shared
-          devices 
-       */
+       /*
+        * Drive takes 400nS to respond, we must avoid the IRQ being
+        * serviced before that.
+        *
+        * FIXME: we could skip this delay with care on non shared devices
+        */
        ndelay(400);
        spin_unlock_irqrestore(&ide_lock, flags);
 }
@@ -917,17 +859,16 @@ static ide_startstop_t do_reset1 (ide_drive_t *, int);
 static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
 {
        ide_hwgroup_t *hwgroup  = HWGROUP(drive);
-       ide_hwif_t *hwif        = HWIF(drive);
        u8 stat;
 
        SELECT_DRIVE(drive);
        udelay (10);
+       stat = ide_read_status(drive);
 
-       if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG), 0, BUSY_STAT)) {
+       if (OK_STAT(stat, 0, BUSY_STAT))
                printk("%s: ATAPI reset complete\n", drive->name);
-       else {
+       else {
                if (time_before(jiffies, hwgroup->poll_timeout)) {
-                       BUG_ON(HWGROUP(drive)->handler != NULL);
                        ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
                        /* continue polling */
                        return ide_started;
@@ -965,9 +906,10 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
                }
        }
 
-       if (!OK_STAT(tmp = hwif->INB(IDE_STATUS_REG), 0, BUSY_STAT)) {
+       tmp = ide_read_status(drive);
+
+       if (!OK_STAT(tmp, 0, BUSY_STAT)) {
                if (time_before(jiffies, hwgroup->poll_timeout)) {
-                       BUG_ON(HWGROUP(drive)->handler != NULL);
                        ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
                        /* continue polling */
                        return ide_started;
@@ -976,7 +918,9 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
                drive->failures++;
        } else  {
                printk("%s: reset: ", hwif->name);
-               if ((tmp = hwif->INB(IDE_ERROR_REG)) == 1) {
+               tmp = ide_read_error(drive);
+
+               if (tmp == 1) {
                        printk("success\n");
                        drive->failures = 0;
                } else {
@@ -1005,19 +949,6 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
        return ide_stopped;
 }
 
-static void check_dma_crc(ide_drive_t *drive)
-{
-#ifdef CONFIG_BLK_DEV_IDEDMA
-       if (drive->crc_count) {
-               ide_dma_off_quietly(drive);
-               ide_set_xfer_rate(drive, ide_auto_reduce_xfer(drive));
-               if (drive->current_speed >= XFER_SW_DMA_0)
-                       ide_dma_on(drive);
-       } else
-               ide_dma_off(drive);
-#endif
-}
-
 static void ide_disk_pre_reset(ide_drive_t *drive)
 {
        int legacy = (drive->id->cfs_enable_2 & 0x0400) ? 0 : 1;
@@ -1039,17 +970,20 @@ static void pre_reset(ide_drive_t *drive)
        else
                drive->post_reset = 1;
 
+       if (drive->using_dma) {
+               if (drive->crc_count)
+                       ide_check_dma_crc(drive);
+               else
+                       ide_dma_off(drive);
+       }
+
        if (!drive->keep_settings) {
-               if (drive->using_dma) {
-                       check_dma_crc(drive);
-               } else {
+               if (!drive->using_dma) {
                        drive->unmask = 0;
                        drive->io_32bit = 0;
                }
                return;
        }
-       if (drive->using_dma)
-               check_dma_crc(drive);
 
        if (HWIF(drive)->pre_reset != NULL)
                HWIF(drive)->pre_reset(drive);
index b42940d8bf70e68661412ba554967f9b8f160737..1ff676cc6473f56dd9a5cc00b7f31d57c4899e4d 100644 (file)
@@ -578,7 +578,7 @@ u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
        }
        printk("}\n");
        if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
-               err = drive->hwif->INB(IDE_ERROR_REG);
+               err = ide_read_error(drive);
                printk("%s: %s: error=0x%02x ", drive->name, msg, err);
                if (drive->media == ide_disk)
                        ide_dump_ata_error(drive, err);
index 4bda5cf2be3742a294c57d00197c4ed16abc3819..b163b2e522128d16bd513b1eac2346042878a377 100644 (file)
@@ -49,7 +49,7 @@ static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id
                printk(KERN_INFO "ide%d: generic PnP IDE interface\n", index);
                pnp_set_drvdata(dev,hwif);
 
-               ide_device_add(idx);
+               ide_device_add(idx, NULL);
 
                return 0;
        }
@@ -60,9 +60,10 @@ static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id
 static void idepnp_remove(struct pnp_dev * dev)
 {
        ide_hwif_t *hwif = pnp_get_drvdata(dev);
-       if (hwif) {
-               ide_unregister(hwif->index);
-       } else
+
+       if (hwif)
+               ide_unregister(hwif->index, 0, 0);
+       else
                printk(KERN_ERR "idepnp: Unable to remove device, please report.\n");
 }
 
index 98a8af44bf644bea97343a4ee3071df19ddc9d57..6daea896c5dbe34ca18095e12f8f708e73a4c7b0 100644 (file)
@@ -264,8 +264,7 @@ err_misc:
 static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
 {
        ide_hwif_t *hwif = HWIF(drive);
-       int rc;
-       unsigned long hd_status;
+       int use_altstatus = 0, rc;
        unsigned long timeout;
        u8 s = 0, a = 0;
 
@@ -273,19 +272,17 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
        msleep(50);
 
        if (IDE_CONTROL_REG) {
-               a = hwif->INB(IDE_ALTSTATUS_REG);
-               s = hwif->INB(IDE_STATUS_REG);
-               if ((a ^ s) & ~INDEX_STAT) {
-                       printk(KERN_INFO "%s: probing with STATUS(0x%02x) instead of "
-                               "ALTSTATUS(0x%02x)\n", drive->name, s, a);
+               a = ide_read_altstatus(drive);
+               s = ide_read_status(drive);
+               if ((a ^ s) & ~INDEX_STAT)
                        /* ancient Seagate drives, broken interfaces */
-                       hd_status = IDE_STATUS_REG;
-               } else {
+                       printk(KERN_INFO "%s: probing with STATUS(0x%02x) "
+                                        "instead of ALTSTATUS(0x%02x)\n",
+                                        drive->name, s, a);
+               else
                        /* use non-intrusive polling */
-                       hd_status = IDE_ALTSTATUS_REG;
-               }
-       } else
-               hd_status = IDE_STATUS_REG;
+                       use_altstatus = 1;
+       }
 
        /* set features register for atapi
         * identify command to be sure of reply
@@ -306,11 +303,15 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
                }
                /* give drive a breather */
                msleep(50);
-       } while ((hwif->INB(hd_status)) & BUSY_STAT);
+               s = use_altstatus ? ide_read_altstatus(drive)
+                                 : ide_read_status(drive);
+       } while (s & BUSY_STAT);
 
        /* wait for IRQ and DRQ_STAT */
        msleep(50);
-       if (OK_STAT((hwif->INB(IDE_STATUS_REG)), DRQ_STAT, BAD_R_STAT)) {
+       s = ide_read_status(drive);
+
+       if (OK_STAT(s, DRQ_STAT, BAD_R_STAT)) {
                unsigned long flags;
 
                /* local CPU only; some systems need this */
@@ -320,7 +321,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
                /* drive responded with ID */
                rc = 0;
                /* clear drive IRQ */
-               (void) hwif->INB(IDE_STATUS_REG);
+               (void)ide_read_status(drive);
                local_irq_restore(flags);
        } else {
                /* drive refused ID */
@@ -367,7 +368,7 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd)
 
                ide_set_irq(drive, 0);
                /* clear drive IRQ */
-               (void) hwif->INB(IDE_STATUS_REG);
+               (void)ide_read_status(drive);
                udelay(5);
                irq = probe_irq_off(cookie);
                if (!hwif->irq) {
@@ -423,8 +424,9 @@ static int ide_busy_sleep(ide_hwif_t *hwif)
 
 static int do_probe (ide_drive_t *drive, u8 cmd)
 {
-       int rc;
        ide_hwif_t *hwif = HWIF(drive);
+       int rc;
+       u8 stat;
 
        if (drive->present) {
                /* avoid waiting for inappropriate probes */
@@ -454,22 +456,26 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
                return 3;
        }
 
-       if (OK_STAT((hwif->INB(IDE_STATUS_REG)), READY_STAT, BUSY_STAT) ||
+       stat = ide_read_status(drive);
+
+       if (OK_STAT(stat, READY_STAT, BUSY_STAT) ||
            drive->present || cmd == WIN_PIDENTIFY) {
                /* send cmd and wait */
                if ((rc = try_to_identify(drive, cmd))) {
                        /* failed: try again */
                        rc = try_to_identify(drive,cmd);
                }
-               if (hwif->INB(IDE_STATUS_REG) == (BUSY_STAT|READY_STAT))
+
+               stat = ide_read_status(drive);
+
+               if (stat == (BUSY_STAT | READY_STAT))
                        return 4;
 
                if ((rc == 1 && cmd == WIN_PIDENTIFY) &&
                        ((drive->autotune == IDE_TUNE_DEFAULT) ||
                        (drive->autotune == IDE_TUNE_AUTO))) {
-                       printk("%s: no response (status = 0x%02x), "
-                               "resetting drive\n", drive->name,
-                               hwif->INB(IDE_STATUS_REG));
+                       printk(KERN_ERR "%s: no response (status = 0x%02x), "
+                                       "resetting drive\n", drive->name, stat);
                        msleep(50);
                        hwif->OUTB(drive->select.all, IDE_SELECT_REG);
                        msleep(50);
@@ -477,11 +483,13 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
                        (void)ide_busy_sleep(hwif);
                        rc = try_to_identify(drive, cmd);
                }
+
+               /* ensure drive IRQ is clear */
+               stat = ide_read_status(drive);
+
                if (rc == 1)
-                       printk("%s: no response (status = 0x%02x)\n",
-                               drive->name, hwif->INB(IDE_STATUS_REG));
-               /* ensure drive irq is clear */
-               (void) hwif->INB(IDE_STATUS_REG);
+                       printk(KERN_ERR "%s: no response (status = 0x%02x)\n",
+                                       drive->name, stat);
        } else {
                /* not present or maybe ATAPI */
                rc = 3;
@@ -491,7 +499,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
                SELECT_DRIVE(&hwif->drives[0]);
                msleep(50);
                /* ensure drive irq is clear */
-               (void) hwif->INB(IDE_STATUS_REG);
+               (void)ide_read_status(drive);
        }
        return rc;
 }
@@ -502,6 +510,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
 static void enable_nest (ide_drive_t *drive)
 {
        ide_hwif_t *hwif = HWIF(drive);
+       u8 stat;
 
        printk("%s: enabling %s -- ", hwif->name, drive->id->model);
        SELECT_DRIVE(drive);
@@ -515,11 +524,12 @@ static void enable_nest (ide_drive_t *drive)
 
        msleep(50);
 
-       if (!OK_STAT((hwif->INB(IDE_STATUS_REG)), 0, BAD_STAT)) {
-               printk("failed (status = 0x%02x)\n", hwif->INB(IDE_STATUS_REG));
-       } else {
-               printk("success\n");
-       }
+       stat = ide_read_status(drive);
+
+       if (!OK_STAT(stat, 0, BAD_STAT))
+               printk(KERN_CONT "failed (status = 0x%02x)\n", stat);
+       else
+               printk(KERN_CONT "success\n");
 
        /* if !(success||timed-out) */
        if (do_probe(drive, WIN_IDENTIFY) >= 2) {
@@ -822,7 +832,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
        for (unit = 0; unit < MAX_DRIVES; ++unit) {
                ide_drive_t *drive = &hwif->drives[unit];
 
-               if (hwif->no_io_32bit)
+               if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
                        drive->no_io_32bit = 1;
                else
                        drive->no_io_32bit = drive->id->dword_io ? 1 : 0;
@@ -881,13 +891,6 @@ static int ide_init_queue(ide_drive_t *drive)
        q->queuedata = drive;
        blk_queue_segment_boundary(q, 0xffff);
 
-       if (!hwif->rqsize) {
-               if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
-                   (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
-                       hwif->rqsize = 256;
-               else
-                       hwif->rqsize = 65536;
-       }
        if (hwif->rqsize < max_sectors)
                max_sectors = hwif->rqsize;
        blk_queue_max_sectors(q, max_sectors);
@@ -918,6 +921,48 @@ static int ide_init_queue(ide_drive_t *drive)
        return 0;
 }
 
+static void ide_add_drive_to_hwgroup(ide_drive_t *drive)
+{
+       ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
+
+       spin_lock_irq(&ide_lock);
+       if (!hwgroup->drive) {
+               /* first drive for hwgroup. */
+               drive->next = drive;
+               hwgroup->drive = drive;
+               hwgroup->hwif = HWIF(hwgroup->drive);
+       } else {
+               drive->next = hwgroup->drive->next;
+               hwgroup->drive->next = drive;
+       }
+       spin_unlock_irq(&ide_lock);
+}
+
+/*
+ * For any present drive:
+ * - allocate the block device queue
+ * - link drive into the hwgroup
+ */
+static void ide_port_setup_devices(ide_hwif_t *hwif)
+{
+       int i;
+
+       for (i = 0; i < MAX_DRIVES; i++) {
+               ide_drive_t *drive = &hwif->drives[i];
+
+               if (!drive->present)
+                       continue;
+
+               if (ide_init_queue(drive)) {
+                       printk(KERN_ERR "ide: failed to init %s\n",
+                                       drive->name);
+                       continue;
+               }
+
+               ide_add_drive_to_hwgroup(drive);
+       }
+}
+
 /*
  * This routine sets up the irq for an ide interface, and creates a new
  * hwgroup for the irq/hwif if none was previously assigned.
@@ -1004,7 +1049,7 @@ static int init_irq (ide_hwif_t *hwif)
         */
        if (!match || match->irq != hwif->irq) {
                int sa = 0;
-#if defined(__mc68000__) || defined(CONFIG_APUS)
+#if defined(__mc68000__)
                sa = IRQF_SHARED;
 #endif /* __mc68000__ || CONFIG_APUS */
 
@@ -1019,33 +1064,15 @@ static int init_irq (ide_hwif_t *hwif)
                        goto out_unlink;
        }
 
-       /*
-        * For any present drive:
-        * - allocate the block device queue
-        * - link drive into the hwgroup
-        */
-       for (index = 0; index < MAX_DRIVES; ++index) {
-               ide_drive_t *drive = &hwif->drives[index];
-               if (!drive->present)
-                       continue;
-               if (ide_init_queue(drive)) {
-                       printk(KERN_ERR "ide: failed to init %s\n",drive->name);
-                       continue;
-               }
-               spin_lock_irq(&ide_lock);
-               if (!hwgroup->drive) {
-                       /* first drive for hwgroup. */
-                       drive->next = drive;
-                       hwgroup->drive = drive;
-                       hwgroup->hwif = HWIF(hwgroup->drive);
-               } else {
-                       drive->next = hwgroup->drive->next;
-                       hwgroup->drive->next = drive;
-               }
-               spin_unlock_irq(&ide_lock);
+       if (!hwif->rqsize) {
+               if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
+                   (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
+                       hwif->rqsize = 256;
+               else
+                       hwif->rqsize = 65536;
        }
 
-#if !defined(__mc68000__) && !defined(CONFIG_APUS)
+#if !defined(__mc68000__)
        printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name,
                hwif->io_ports[IDE_DATA_OFFSET],
                hwif->io_ports[IDE_DATA_OFFSET]+7,
@@ -1053,11 +1080,14 @@ static int init_irq (ide_hwif_t *hwif)
 #else
        printk("%s at 0x%08lx on irq %d", hwif->name,
                hwif->io_ports[IDE_DATA_OFFSET], hwif->irq);
-#endif /* __mc68000__ && CONFIG_APUS */
+#endif /* __mc68000__ */
        if (match)
                printk(" (%sed with %s)",
                        hwif->sharing_irq ? "shar" : "serializ", match->name);
        printk("\n");
+
+       ide_port_setup_devices(hwif);
+
        mutex_unlock(&ide_cfg_mtx);
        return 0;
 out_unlink:
@@ -1182,30 +1212,6 @@ static void drive_release_dev (struct device *dev)
        complete(&drive->gendev_rel_comp);
 }
 
-/*
- * init_gendisk() (as opposed to ide_geninit) is called for each major device,
- * after probing for drives, to allocate partition tables and other data
- * structures needed for the routines in genhd.c.  ide_geninit() gets called
- * somewhat later, during the partition check.
- */
-static void init_gendisk (ide_hwif_t *hwif)
-{
-       unsigned int unit;
-
-       for (unit = 0; unit < MAX_DRIVES; ++unit) {
-               ide_drive_t * drive = &hwif->drives[unit];
-               ide_add_generic_settings(drive);
-               snprintf(drive->gendev.bus_id,BUS_ID_SIZE,"%u.%u",
-                        hwif->index,unit);
-               drive->gendev.parent = &hwif->gendev;
-               drive->gendev.bus = &ide_bus_type;
-               drive->gendev.driver_data = drive;
-               drive->gendev.release = drive_release_dev;
-       }
-       blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
-                       THIS_MODULE, ata_probe, ata_lock, hwif);
-}
-
 static int hwif_init(ide_hwif_t *hwif)
 {
        int old_irq;
@@ -1262,8 +1268,8 @@ static int hwif_init(ide_hwif_t *hwif)
                hwif->name, hwif->irq);
 
 done:
-       init_gendisk(hwif);
-       ide_acpi_init(hwif);
+       blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
+                           THIS_MODULE, ata_probe, ata_lock, hwif);
        return 1;
 
 out:
@@ -1277,23 +1283,118 @@ static void hwif_register_devices(ide_hwif_t *hwif)
 
        for (i = 0; i < MAX_DRIVES; i++) {
                ide_drive_t *drive = &hwif->drives[i];
+               struct device *dev = &drive->gendev;
+               int ret;
 
-               if (drive->present) {
-                       int ret = device_register(&drive->gendev);
+               if (!drive->present)
+                       continue;
 
-                       if (ret < 0)
-                               printk(KERN_WARNING "IDE: %s: "
-                                       "device_register error: %d\n",
-                                       __FUNCTION__, ret);
-               }
+               ide_add_generic_settings(drive);
+
+               snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
+               dev->parent = &hwif->gendev;
+               dev->bus = &ide_bus_type;
+               dev->driver_data = drive;
+               dev->release = drive_release_dev;
+
+               ret = device_register(dev);
+               if (ret < 0)
+                       printk(KERN_WARNING "IDE: %s: device_register error: "
+                                           "%d\n", __func__, ret);
+       }
+}
+
+static void ide_port_init_devices(ide_hwif_t *hwif)
+{
+       int i;
+
+       for (i = 0; i < MAX_DRIVES; i++) {
+               ide_drive_t *drive = &hwif->drives[i];
+
+               if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
+                       drive->io_32bit = 1;
+               if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
+                       drive->unmask = 1;
+               if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
+                       drive->no_unmask = 1;
+               if ((hwif->host_flags & IDE_HFLAG_NO_AUTOTUNE) == 0)
+                       drive->autotune = 1;
+       }
+
+       if (hwif->port_init_devs)
+               hwif->port_init_devs(hwif);
+}
+
+static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
+                         const struct ide_port_info *d)
+{
+       if (d->chipset != ide_etrax100)
+               hwif->channel = port;
+
+       if (d->chipset)
+               hwif->chipset = d->chipset;
+
+       if (d->init_iops)
+               d->init_iops(hwif);
+
+       if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0)
+               ide_hwif_setup_dma(hwif, d);
+
+       if ((!hwif->irq && (d->host_flags & IDE_HFLAG_LEGACY_IRQS)) ||
+           (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS))
+               hwif->irq = port ? 15 : 14;
+
+       hwif->host_flags = d->host_flags;
+       hwif->pio_mask = d->pio_mask;
+
+       if ((d->host_flags & IDE_HFLAG_SERIALIZE) && hwif->mate)
+               hwif->mate->serialized = hwif->serialized = 1;
+
+       hwif->swdma_mask = d->swdma_mask;
+       hwif->mwdma_mask = d->mwdma_mask;
+       hwif->ultra_mask = d->udma_mask;
+
+       /* reset DMA masks only for SFF-style DMA controllers */
+       if ((d->host_flags && IDE_HFLAG_NO_DMA) == 0 && hwif->dma_base == 0)
+               hwif->swdma_mask = hwif->mwdma_mask = hwif->ultra_mask = 0;
+
+       if (d->host_flags & IDE_HFLAG_RQSIZE_256)
+               hwif->rqsize = 256;
+
+       /* call chipset specific routine for each enabled port */
+       if (d->init_hwif)
+               d->init_hwif(hwif);
+
+       if (hwif->cable_detect && (hwif->ultra_mask & 0x78)) {
+               if (hwif->cbl != ATA_CBL_PATA40_SHORT)
+                       hwif->cbl = hwif->cable_detect(hwif);
        }
 }
 
-int ide_device_add_all(u8 *idx)
+int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
 {
-       ide_hwif_t *hwif;
+       ide_hwif_t *hwif, *mate = NULL;
        int i, rc = 0;
 
+       for (i = 0; i < MAX_HWIFS; i++) {
+               if (d == NULL || idx[i] == 0xff) {
+                       mate = NULL;
+                       continue;
+               }
+
+               hwif = &ide_hwifs[idx[i]];
+
+               if (d->chipset != ide_etrax100 && (i & 1) && mate) {
+                       hwif->mate = mate;
+                       mate->mate = hwif;
+               }
+
+               mate = (i & 1) ? NULL : hwif;
+
+               ide_init_port(hwif, i & 1, d);
+               ide_port_init_devices(hwif);
+       }
+
        for (i = 0; i < MAX_HWIFS; i++) {
                if (idx[i] == 0xff)
                        continue;
@@ -1337,6 +1438,9 @@ int ide_device_add_all(u8 *idx)
                        rc = -1;
                        continue;
                }
+
+               ide_acpi_init(hwif);
+               ide_acpi_port_init_devices(hwif);
        }
 
        for (i = 0; i < MAX_HWIFS; i++) {
@@ -1354,15 +1458,22 @@ int ide_device_add_all(u8 *idx)
        }
 
        for (i = 0; i < MAX_HWIFS; i++) {
-               if (idx[i] != 0xff)
-                       ide_proc_register_port(&ide_hwifs[idx[i]]);
+               if (idx[i] == 0xff)
+                       continue;
+
+               hwif = &ide_hwifs[idx[i]];
+
+               if (hwif->present) {
+                       ide_proc_register_port(hwif);
+                       ide_proc_port_register_devices(hwif);
+               }
        }
 
        return rc;
 }
 EXPORT_SYMBOL_GPL(ide_device_add_all);
 
-int ide_device_add(u8 idx[4])
+int ide_device_add(u8 idx[4], const struct ide_port_info *d)
 {
        u8 idx_all[MAX_HWIFS];
        int i;
@@ -1370,6 +1481,6 @@ int ide_device_add(u8 idx[4])
        for (i = 0; i < MAX_HWIFS; i++)
                idx_all[i] = (i < 4) ? idx[i] : 0xff;
 
-       return ide_device_add_all(idx_all);
+       return ide_device_add_all(idx_all, d);
 }
 EXPORT_SYMBOL_GPL(ide_device_add);
index 00c249cba236c88e90d75411e64ce5841f1f2f6e..bab88ca7f7ecb953495cd09c17d979a395ae5fd9 100644 (file)
@@ -65,6 +65,7 @@ static int proc_ide_read_imodel
                case ide_4drives:       name = "4drives";       break;
                case ide_pmac:          name = "mac-io";        break;
                case ide_au1xxx:        name = "au1xxx";        break;
+               case ide_palm3710:      name = "palm3710";      break;
                case ide_etrax100:      name = "etrax100";      break;
                case ide_acorn:         name = "acorn";         break;
                default:                name = "(unknown)";     break;
@@ -739,7 +740,7 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
 
 EXPORT_SYMBOL(ide_proc_unregister_driver);
 
-static void create_proc_ide_drives(ide_hwif_t *hwif)
+void ide_proc_port_register_devices(ide_hwif_t *hwif)
 {
        int     d;
        struct proc_dir_entry *ent;
@@ -793,9 +794,6 @@ static ide_proc_entry_t hwif_entries[] = {
 
 void ide_proc_register_port(ide_hwif_t *hwif)
 {
-       if (!hwif->present)
-               return;
-
        if (!hwif->proc) {
                hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
 
@@ -804,8 +802,6 @@ void ide_proc_register_port(ide_hwif_t *hwif)
 
                ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
        }
-
-       create_proc_ide_drives(hwif);
 }
 
 #ifdef CONFIG_BLK_DEV_IDEPCI
index 5aef63acf1e8d7af13b566200da3e8845cb207cf..49dd2e7bae7a788f95f8157089f9d20c8d7e695b 100644 (file)
 /*
+ * IDE ATAPI streaming tape driver.
+ *
  * Copyright (C) 1995-1999  Gadi Oxman <gadio@netvision.net.il>
  * Copyright (C) 2003-2005  Bartlomiej Zolnierkiewicz
  *
- * $Header$
- *
  * This driver was constructed as a student project in the software laboratory
  * of the faculty of electrical engineering in the Technion - Israel's
  * Institute Of Technology, with the guide of Avner Lottem and Dr. Ilana David.
  *
  * It is hereby placed under the terms of the GNU general public license.
  * (See linux/COPYING).
- */
-/*
- * IDE ATAPI streaming tape driver.
- *
- * This driver is a part of the Linux ide driver and works in co-operation
- * with linux/drivers/block/ide.c.
- *
- * The driver, in co-operation with ide.c, basically traverses the 
- * request-list for the block device interface. The character device
- * interface, on the other hand, creates new requests, adds them
- * to the request-list of the block device, and waits for their completion.
- *
- * Pipelined operation mode is now supported on both reads and writes.
- *
- * The block device major and minor numbers are determined from the
- * tape's relative position in the ide interfaces, as explained in ide.c.
- *
- * The character device interface consists of the following devices:
- *
- * ht0         major 37, minor 0       first  IDE tape, rewind on close.
- * ht1         major 37, minor 1       second IDE tape, rewind on close.
- * ...
- * nht0                major 37, minor 128     first  IDE tape, no rewind on close.
- * nht1                major 37, minor 129     second IDE tape, no rewind on close.
- * ...
- *
- * Run linux/scripts/MAKEDEV.ide to create the above entries.
- *
- * The general magnetic tape commands compatible interface, as defined by
- * include/linux/mtio.h, is accessible through the character device.
- *
- * General ide driver configuration options, such as the interrupt-unmask
- * flag, can be configured by issuing an ioctl to the block device interface,
- * as any other ide device.
- *
- * Our own ide-tape ioctl's can be issued to either the block device or
- * the character device interface.
- *
- * Maximal throughput with minimal bus load will usually be achieved in the
- * following scenario:
- *
- *     1.      ide-tape is operating in the pipelined operation mode.
- *     2.      No buffering is performed by the user backup program.
- *
- * Testing was done with a 2 GB CONNER CTMA 4000 IDE ATAPI Streaming Tape Drive.
- * 
- * Ver 0.1   Nov  1 95   Pre-working code :-)
- * Ver 0.2   Nov 23 95   A short backup (few megabytes) and restore procedure
- *                        was successful ! (Using tar cvf ... on the block
- *                        device interface).
- *                       A longer backup resulted in major swapping, bad
- *                        overall Linux performance and eventually failed as
- *                        we received non serial read-ahead requests from the
- *                        buffer cache.
- * Ver 0.3   Nov 28 95   Long backups are now possible, thanks to the
- *                        character device interface. Linux's responsiveness
- *                        and performance doesn't seem to be much affected
- *                        from the background backup procedure.
- *                       Some general mtio.h magnetic tape operations are
- *                        now supported by our character device. As a result,
- *                        popular tape utilities are starting to work with
- *                        ide tapes :-)
- *                       The following configurations were tested:
- *                             1. An IDE ATAPI TAPE shares the same interface
- *                                and irq with an IDE ATAPI CDROM.
- *                             2. An IDE ATAPI TAPE shares the same interface
- *                                and irq with a normal IDE disk.
- *                        Both configurations seemed to work just fine !
- *                        However, to be on the safe side, it is meanwhile
- *                        recommended to give the IDE TAPE its own interface
- *                        and irq.
- *                       The one thing which needs to be done here is to
- *                        add a "request postpone" feature to ide.c,
- *                        so that we won't have to wait for the tape to finish
- *                        performing a long media access (DSC) request (such
- *                        as a rewind) before we can access the other device
- *                        on the same interface. This effect doesn't disturb
- *                        normal operation most of the time because read/write
- *                        requests are relatively fast, and once we are
- *                        performing one tape r/w request, a lot of requests
- *                        from the other device can be queued and ide.c will
- *                       service all of them after this single tape request.
- * Ver 1.0   Dec 11 95   Integrated into Linux 1.3.46 development tree.
- *                       On each read / write request, we now ask the drive
- *                        if we can transfer a constant number of bytes
- *                        (a parameter of the drive) only to its buffers,
- *                        without causing actual media access. If we can't,
- *                        we just wait until we can by polling the DSC bit.
- *                        This ensures that while we are not transferring
- *                        more bytes than the constant referred to above, the
- *                        interrupt latency will not become too high and
- *                        we won't cause an interrupt timeout, as happened
- *                        occasionally in the previous version.
- *                       While polling for DSC, the current request is
- *                        postponed and ide.c is free to handle requests from
- *                        the other device. This is handled transparently to
- *                        ide.c. The hwgroup locking method which was used
- *                        in the previous version was removed.
- *                       Use of new general features which are provided by
- *                        ide.c for use with atapi devices.
- *                        (Programming done by Mark Lord)
- *                       Few potential bug fixes (Again, suggested by Mark)
- *                       Single character device data transfers are now
- *                        not limited in size, as they were before.
- *                       We are asking the tape about its recommended
- *                        transfer unit and send a larger data transfer
- *                        as several transfers of the above size.
- *                        For best results, use an integral number of this
- *                        basic unit (which is shown during driver
- *                        initialization). I will soon add an ioctl to get
- *                        this important parameter.
- *                       Our data transfer buffer is allocated on startup,
- *                        rather than before each data transfer. This should
- *                        ensure that we will indeed have a data buffer.
- * Ver 1.1   Dec 14 95   Fixed random problems which occurred when the tape
- *                        shared an interface with another device.
- *                        (poll_for_dsc was a complete mess).
- *                       Removed some old (non-active) code which had
- *                        to do with supporting buffer cache originated
- *                        requests.
- *                       The block device interface can now be opened, so
- *                        that general ide driver features like the unmask
- *                        interrupts flag can be selected with an ioctl.
- *                        This is the only use of the block device interface.
- *                       New fast pipelined operation mode (currently only on
- *                        writes). When using the pipelined mode, the
- *                        throughput can potentially reach the maximum
- *                        tape supported throughput, regardless of the
- *                        user backup program. On my tape drive, it sometimes
- *                        boosted performance by a factor of 2. Pipelined
- *                        mode is enabled by default, but since it has a few
- *                        downfalls as well, you may want to disable it.
- *                        A short explanation of the pipelined operation mode
- *                        is available below.
- * Ver 1.2   Jan  1 96   Eliminated pipelined mode race condition.
- *                       Added pipeline read mode. As a result, restores
- *                        are now as fast as backups.
- *                       Optimized shared interface behavior. The new behavior
- *                        typically results in better IDE bus efficiency and
- *                        higher tape throughput.
- *                       Pre-calculation of the expected read/write request
- *                        service time, based on the tape's parameters. In
- *                        the pipelined operation mode, this allows us to
- *                        adjust our polling frequency to a much lower value,
- *                        and thus to dramatically reduce our load on Linux,
- *                        without any decrease in performance.
- *                       Implemented additional mtio.h operations.
- *                       The recommended user block size is returned by
- *                        the MTIOCGET ioctl.
- *                       Additional minor changes.
- * Ver 1.3   Feb  9 96   Fixed pipelined read mode bug which prevented the
- *                        use of some block sizes during a restore procedure.
- *                       The character device interface will now present a
- *                        continuous view of the media - any mix of block sizes
- *                        during a backup/restore procedure is supported. The
- *                        driver will buffer the requests internally and
- *                        convert them to the tape's recommended transfer
- *                        unit, making performance almost independent of the
- *                        chosen user block size.
- *                       Some improvements in error recovery.
- *                       By cooperating with ide-dma.c, bus mastering DMA can
- *                        now sometimes be used with IDE tape drives as well.
- *                        Bus mastering DMA has the potential to dramatically
- *                        reduce the CPU's overhead when accessing the device,
- *                        and can be enabled by using hdparm -d1 on the tape's
- *                        block device interface. For more info, read the
- *                        comments in ide-dma.c.
- * Ver 1.4   Mar 13 96   Fixed serialize support.
- * Ver 1.5   Apr 12 96   Fixed shared interface operation, broken in 1.3.85.
- *                       Fixed pipelined read mode inefficiency.
- *                       Fixed nasty null dereferencing bug.
- * Ver 1.6   Aug 16 96   Fixed FPU usage in the driver.
- *                       Fixed end of media bug.
- * Ver 1.7   Sep 10 96   Minor changes for the CONNER CTT8000-A model.
- * Ver 1.8   Sep 26 96   Attempt to find a better balance between good
- *                        interactive response and high system throughput.
- * Ver 1.9   Nov  5 96   Automatically cross encountered filemarks rather
- *                        than requiring an explicit FSF command.
- *                       Abort pending requests at end of media.
- *                       MTTELL was sometimes returning incorrect results.
- *                       Return the real block size in the MTIOCGET ioctl.
- *                       Some error recovery bug fixes.
- * Ver 1.10  Nov  5 96   Major reorganization.
- *                       Reduced CPU overhead a bit by eliminating internal
- *                        bounce buffers.
- *                       Added module support.
- *                       Added multiple tape drives support.
- *                       Added partition support.
- *                       Rewrote DSC handling.
- *                       Some portability fixes.
- *                       Removed ide-tape.h.
- *                       Additional minor changes.
- * Ver 1.11  Dec  2 96   Bug fix in previous DSC timeout handling.
- *                       Use ide_stall_queue() for DSC overlap.
- *                       Use the maximum speed rather than the current speed
- *                        to compute the request service time.
- * Ver 1.12  Dec  7 97   Fix random memory overwriting and/or last block data
- *                        corruption, which could occur if the total number
- *                        of bytes written to the tape was not an integral
- *                        number of tape blocks.
- *                       Add support for INTERRUPT DRQ devices.
- * Ver 1.13  Jan  2 98   Add "speed == 0" work-around for HP COLORADO 5GB
- * Ver 1.14  Dec 30 98   Partial fixes for the Sony/AIWA tape drives.
- *                       Replace cli()/sti() with hwgroup spinlocks.
- * Ver 1.15  Mar 25 99   Fix SMP race condition by replacing hwgroup
- *                        spinlock with private per-tape spinlock.
- * Ver 1.16  Sep  1 99   Add OnStream tape support.
- *                       Abort read pipeline on EOD.
- *                       Wait for the tape to become ready in case it returns
- *                        "in the process of becoming ready" on open().
- *                       Fix zero padding of the last written block in
- *                        case the tape block size is larger than PAGE_SIZE.
- *                       Decrease the default disconnection time to tn.
- * Ver 1.16e Oct  3 99   Minor fixes.
- * Ver 1.16e1 Oct 13 99  Patches by Arnold Niessen,
- *                          niessen@iae.nl / arnold.niessen@philips.com
- *                   GO-1)  Undefined code in idetape_read_position
- *                             according to Gadi's email
- *                   AJN-1) Minor fix asc == 11 should be asc == 0x11
- *                               in idetape_issue_packet_command (did effect
- *                               debugging output only)
- *                   AJN-2) Added more debugging output, and
- *                              added ide-tape: where missing. I would also
- *                             like to add tape->name where possible
- *                   AJN-3) Added different debug_level's 
- *                              via /proc/ide/hdc/settings
- *                             "debug_level" determines amount of debugging output;
- *                             can be changed using /proc/ide/hdx/settings
- *                             0 : almost no debugging output
- *                             1 : 0+output errors only
- *                             2 : 1+output all sensekey/asc
- *                             3 : 2+follow all chrdev related procedures
- *                             4 : 3+follow all procedures
- *                             5 : 4+include pc_stack rq_stack info
- *                             6 : 5+USE_COUNT updates
- *                   AJN-4) Fixed timeout for retension in idetape_queue_pc_tail
- *                             from 5 to 10 minutes
- *                   AJN-5) Changed maximum number of blocks to skip when
- *                              reading tapes with multiple consecutive write
- *                              errors from 100 to 1000 in idetape_get_logical_blk
- *                   Proposed changes to code:
- *                   1) output "logical_blk_num" via /proc
- *                   2) output "current_operation" via /proc
- *                   3) Either solve or document the fact that `mt rewind' is
- *                      required after reading from /dev/nhtx to be
- *                     able to rmmod the idetape module;
- *                     Also, sometimes an application finishes but the
- *                     device remains `busy' for some time. Same cause ?
- *                   Proposed changes to release-notes:
- *                  4) write a simple `quickstart' section in the
- *                      release notes; I volunteer if you don't want to
- *                  5) include a pointer to video4linux in the doc
- *                      to stimulate video applications
- *                   6) release notes lines 331 and 362: explain what happens
- *                     if the application data rate is higher than 1100 KB/s; 
- *                     similar approach to lower-than-500 kB/s ?
- *                  7) 6.6 Comparison; wouldn't it be better to allow different 
- *                     strategies for read and write ?
- *                     Wouldn't it be better to control the tape buffer
- *                     contents instead of the bandwidth ?
- *                  8) line 536: replace will by would (if I understand
- *                     this section correctly, a hypothetical and unwanted situation
- *                      is being described)
- * Ver 1.16f Dec 15 99   Change place of the secondary OnStream header frames.
- * Ver 1.17  Nov 2000 / Jan 2001  Marcel Mol, marcel@mesa.nl
- *                     - Add idetape_onstream_mode_sense_tape_parameter_page
- *                       function to get tape capacity in frames: tape->capacity.
- *                     - Add support for DI-50 drives( or any DI- drive).
- *                     - 'workaround' for read error/blank block around block 3000.
- *                     - Implement Early warning for end of media for Onstream.
- *                     - Cosmetic code changes for readability.
- *                     - Idetape_position_tape should not use SKIP bit during
- *                       Onstream read recovery.
- *                     - Add capacity, logical_blk_num and first/last_frame_position
- *                       to /proc/ide/hd?/settings.
- *                     - Module use count was gone in the Linux 2.4 driver.
- * Ver 1.17a Apr 2001 Willem Riede osst@riede.org
- *                     - Get drive's actual block size from mode sense block descriptor
- *                     - Limit size of pipeline
- * Ver 1.17b Oct 2002   Alan Stern <stern@rowland.harvard.edu>
- *                     Changed IDETAPE_MIN_PIPELINE_STAGES to 1 and actually used
- *                      it in the code!
- *                     Actually removed aborted stages in idetape_abort_pipeline
- *                      instead of just changing the command code.
- *                     Made the transfer byte count for Request Sense equal to the
- *                      actual length of the data transfer.
- *                     Changed handling of partial data transfers: they do not
- *                      cause DMA errors.
- *                     Moved initiation of DMA transfers to the correct place.
- *                     Removed reference to unallocated memory.
- *                     Made __idetape_discard_read_pipeline return the number of
- *                      sectors skipped, not the number of stages.
- *                     Replaced errant kfree() calls with __idetape_kfree_stage().
- *                     Fixed off-by-one error in testing the pipeline length.
- *                     Fixed handling of filemarks in the read pipeline.
- *                     Small code optimization for MTBSF and MTBSFM ioctls.
- *                     Don't try to unlock the door during device close if is
- *                      already unlocked!
- *                     Cosmetic fixes to miscellaneous debugging output messages.
- *                     Set the minimum /proc/ide/hd?/settings values for "pipeline",
- *                      "pipeline_min", and "pipeline_max" to 1.
- *
- * Here are some words from the first releases of hd.c, which are quoted
- * in ide.c and apply here as well:
- *
- * | Special care is recommended.  Have Fun!
- *
- */
-
-/*
- * An overview of the pipelined operation mode.
- *
- * In the pipelined write mode, we will usually just add requests to our
- * pipeline and return immediately, before we even start to service them. The
- * user program will then have enough time to prepare the next request while
- * we are still busy servicing previous requests. In the pipelined read mode,
- * the situation is similar - we add read-ahead requests into the pipeline,
- * before the user even requested them.
- *
- * The pipeline can be viewed as a "safety net" which will be activated when
- * the system load is high and prevents the user backup program from keeping up
- * with the current tape speed. At this point, the pipeline will get
- * shorter and shorter but the tape will still be streaming at the same speed.
- * Assuming we have enough pipeline stages, the system load will hopefully
- * decrease before the pipeline is completely empty, and the backup program
- * will be able to "catch up" and refill the pipeline again.
- * 
- * When using the pipelined mode, it would be best to disable any type of
- * buffering done by the user program, as ide-tape already provides all the
- * benefits in the kernel, where it can be done in a more efficient way.
- * As we will usually not block the user program on a request, the most
- * efficient user code will then be a simple read-write-read-... cycle.
- * Any additional logic will usually just slow down the backup process.
- *
- * Using the pipelined mode, I get a constant over 400 KBps throughput,
- * which seems to be the maximum throughput supported by my tape.
- *
- * However, there are some downfalls:
- *
- *     1.      We use memory (for data buffers) in proportional to the number
- *             of pipeline stages (each stage is about 26 KB with my tape).
- *     2.      In the pipelined write mode, we cheat and postpone error codes
- *             to the user task. In read mode, the actual tape position
- *             will be a bit further than the last requested block.
- *
- * Concerning (1):
  *
- *     1.      We allocate stages dynamically only when we need them. When
- *             we don't need them, we don't consume additional memory. In
- *             case we can't allocate stages, we just manage without them
- *             (at the expense of decreased throughput) so when Linux is
- *             tight in memory, we will not pose additional difficulties.
- *
- *     2.      The maximum number of stages (which is, in fact, the maximum
- *             amount of memory) which we allocate is limited by the compile
- *             time parameter IDETAPE_MAX_PIPELINE_STAGES.
- *
- *     3.      The maximum number of stages is a controlled parameter - We
- *             don't start from the user defined maximum number of stages
- *             but from the lower IDETAPE_MIN_PIPELINE_STAGES (again, we
- *             will not even allocate this amount of stages if the user
- *             program can't handle the speed). We then implement a feedback
- *             loop which checks if the pipeline is empty, and if it is, we
- *             increase the maximum number of stages as necessary until we
- *             reach the optimum value which just manages to keep the tape
- *             busy with minimum allocated memory or until we reach
- *             IDETAPE_MAX_PIPELINE_STAGES.
- *
- * Concerning (2):
- *
- *     In pipelined write mode, ide-tape can not return accurate error codes
- *     to the user program since we usually just add the request to the
- *      pipeline without waiting for it to be serviced. In case an error
- *      occurs, I will report it on the next user request.
- *
- *     In the pipelined read mode, subsequent read requests or forward
- *     filemark spacing will perform correctly, as we preserve all blocks
- *     and filemarks which we encountered during our excess read-ahead.
- * 
- *     For accurate tape positioning and error reporting, disabling
- *     pipelined mode might be the best option.
- *
- * You can enable/disable/tune the pipelined operation mode by adjusting
- * the compile time parameters below.
- */
-
-/*
- *     Possible improvements.
- *
- *     1.      Support for the ATAPI overlap protocol.
- *
- *             In order to maximize bus throughput, we currently use the DSC
- *             overlap method which enables ide.c to service requests from the
- *             other device while the tape is busy executing a command. The
- *             DSC overlap method involves polling the tape's status register
- *             for the DSC bit, and servicing the other device while the tape
- *             isn't ready.
- *
- *             In the current QIC development standard (December 1995),
- *             it is recommended that new tape drives will *in addition* 
- *             implement the ATAPI overlap protocol, which is used for the
- *             same purpose - efficient use of the IDE bus, but is interrupt
- *             driven and thus has much less CPU overhead.
- *
- *             ATAPI overlap is likely to be supported in most new ATAPI
- *             devices, including new ATAPI cdroms, and thus provides us
- *             a method by which we can achieve higher throughput when
- *             sharing a (fast) ATA-2 disk with any (slow) new ATAPI device.
+ * For a historical changelog see
+ * Documentation/ide/ChangeLog.ide-tape.1995-2002
  */
 
-#define IDETAPE_VERSION "1.19"
+#define IDETAPE_VERSION "1.20"
 
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/completion.h>
 #include <linux/bitops.h>
 #include <linux/mutex.h>
+#include <scsi/scsi.h>
 
 #include <asm/byteorder.h>
-#include <asm/irq.h>
-#include <asm/uaccess.h>
-#include <asm/io.h>
+#include <linux/irq.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
 #include <asm/unaligned.h>
+#include <linux/mtio.h>
 
-/*
- * partition
- */
-typedef struct os_partition_s {
-       __u8    partition_num;
-       __u8    par_desc_ver;
-       __u16   wrt_pass_cntr;
-       __u32   first_frame_addr;
-       __u32   last_frame_addr;
-       __u32   eod_frame_addr;
-} os_partition_t;
-
-/*
- * DAT entry
- */
-typedef struct os_dat_entry_s {
-       __u32   blk_sz;
-       __u16   blk_cnt;
-       __u8    flags;
-       __u8    reserved;
-} os_dat_entry_t;
-
-/*
- * DAT
- */
-#define OS_DAT_FLAGS_DATA      (0xc)
-#define OS_DAT_FLAGS_MARK      (0x1)
+enum {
+       /* output errors only */
+       DBG_ERR =               (1 << 0),
+       /* output all sense key/asc */
+       DBG_SENSE =             (1 << 1),
+       /* info regarding all chrdev-related procedures */
+       DBG_CHRDEV =            (1 << 2),
+       /* all remaining procedures */
+       DBG_PROCS =             (1 << 3),
+       /* buffer alloc info (pc_stack & rq_stack) */
+       DBG_PCRQ_STACK =        (1 << 4),
+};
 
-typedef struct os_dat_s {
-       __u8            dat_sz;
-       __u8            reserved1;
-       __u8            entry_cnt;
-       __u8            reserved3;
-       os_dat_entry_t  dat_list[16];
-} os_dat_t;
+/* define to see debug info */
+#define IDETAPE_DEBUG_LOG              0
 
-#include <linux/mtio.h>
+#if IDETAPE_DEBUG_LOG
+#define debug_log(lvl, fmt, args...)                   \
+{                                                      \
+       if (tape->debug_mask & lvl)                     \
+       printk(KERN_INFO "ide-tape: " fmt, ## args);    \
+}
+#else
+#define debug_log(lvl, fmt, args...) do {} while (0)
+#endif
 
 /**************************** Tunable parameters *****************************/
 
 
 /*
- *     Pipelined mode parameters.
+ * Pipelined mode parameters.
  *
- *     We try to use the minimum number of stages which is enough to
- *     keep the tape constantly streaming. To accomplish that, we implement
- *     a feedback loop around the maximum number of stages:
+ * We try to use the minimum number of stages which is enough to keep the tape
+ * constantly streaming. To accomplish that, we implement a feedback loop around
+ * the maximum number of stages:
  *
- *     We start from MIN maximum stages (we will not even use MIN stages
- *      if we don't need them), increment it by RATE*(MAX-MIN)
- *     whenever we sense that the pipeline is empty, until we reach
- *     the optimum value or until we reach MAX.
+ * We start from MIN maximum stages (we will not even use MIN stages if we don't
+ * need them), increment it by RATE*(MAX-MIN) whenever we sense that the
+ * pipeline is empty, until we reach the optimum value or until we reach MAX.
  *
- *     Setting the following parameter to 0 is illegal: the pipelined mode
- *     cannot be disabled (calculate_speeds() divides by tape->max_stages.)
+ * Setting the following parameter to 0 is illegal: the pipelined mode cannot be
+ * disabled (idetape_calculate_speeds() divides by tape->max_stages.)
  */
 #define IDETAPE_MIN_PIPELINE_STAGES      1
 #define IDETAPE_MAX_PIPELINE_STAGES    400
 #define IDETAPE_INCREASE_STAGES_RATE    20
 
 /*
- *     The following are used to debug the driver:
- *
- *     Setting IDETAPE_DEBUG_INFO to 1 will report device capabilities.
- *     Setting IDETAPE_DEBUG_LOG to 1 will log driver flow control.
- *     Setting IDETAPE_DEBUG_BUGS to 1 will enable self-sanity checks in
- *     some places.
+ * After each failed packet command we issue a request sense command and retry
+ * the packet command IDETAPE_MAX_PC_RETRIES times.
  *
- *     Setting them to 0 will restore normal operation mode:
- *
- *             1.      Disable logging normal successful operations.
- *             2.      Disable self-sanity checks.
- *             3.      Errors will still be logged, of course.
- *
- *     All the #if DEBUG code will be removed some day, when the driver
- *     is verified to be stable enough. This will make it much more
- *     esthetic.
- */
-#define IDETAPE_DEBUG_INFO             0
-#define IDETAPE_DEBUG_LOG              0
-#define IDETAPE_DEBUG_BUGS             1
-
-/*
- *     After each failed packet command we issue a request sense command
- *     and retry the packet command IDETAPE_MAX_PC_RETRIES times.
- *
- *     Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
+ * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
  */
 #define IDETAPE_MAX_PC_RETRIES         3
 
 /*
- *     With each packet command, we allocate a buffer of
- *     IDETAPE_PC_BUFFER_SIZE bytes. This is used for several packet
- *     commands (Not for READ/WRITE commands).
+ * With each packet command, we allocate a buffer of IDETAPE_PC_BUFFER_SIZE
+ * bytes. This is used for several packet commands (Not for READ/WRITE commands)
  */
 #define IDETAPE_PC_BUFFER_SIZE         256
 
@@ -561,48 +121,39 @@ typedef struct os_dat_s {
 #define IDETAPE_WAIT_CMD               (900*HZ)
 
 /*
- *     The following parameter is used to select the point in the internal
- *     tape fifo in which we will start to refill the buffer. Decreasing
- *     the following parameter will improve the system's latency and
- *     interactive response, while using a high value might improve system
- *     throughput.
+ * The following parameter is used to select the point in the internal tape fifo
+ * in which we will start to refill the buffer. Decreasing the following
+ * parameter will improve the system's latency and interactive response, while
+ * using a high value might improve system throughput.
  */
-#define IDETAPE_FIFO_THRESHOLD                 2
+#define IDETAPE_FIFO_THRESHOLD         2
 
 /*
- *     DSC polling parameters.
- *
- *     Polling for DSC (a single bit in the status register) is a very
- *     important function in ide-tape. There are two cases in which we
- *     poll for DSC:
+ * DSC polling parameters.
  *
- *     1.      Before a read/write packet command, to ensure that we
- *             can transfer data from/to the tape's data buffers, without
- *             causing an actual media access. In case the tape is not
- *             ready yet, we take out our request from the device
- *             request queue, so that ide.c will service requests from
- *             the other device on the same interface meanwhile.
+ * Polling for DSC (a single bit in the status register) is a very important
+ * function in ide-tape. There are two cases in which we poll for DSC:
  *
- *     2.      After the successful initialization of a "media access
- *             packet command", which is a command which can take a long
- *             time to complete (it can be several seconds or even an hour).
+ * 1. Before a read/write packet command, to ensure that we can transfer data
+ * from/to the tape's data buffers, without causing an actual media access.
+ * In case the tape is not ready yet, we take out our request from the device
+ * request queue, so that ide.c could service requests from the other device
+ * on the same interface in the meantime.
  *
- *             Again, we postpone our request in the middle to free the bus
- *             for the other device. The polling frequency here should be
- *             lower than the read/write frequency since those media access
- *             commands are slow. We start from a "fast" frequency -
- *             IDETAPE_DSC_MA_FAST (one second), and if we don't receive DSC
- *             after IDETAPE_DSC_MA_THRESHOLD (5 minutes), we switch it to a
- *             lower frequency - IDETAPE_DSC_MA_SLOW (1 minute).
+ * 2. After the successful initialization of a "media access packet command",
+ * which is a command that can take a long time to complete (the interval can
+ * range from several seconds to even an hour). Again, we postpone our request
+ * in the middle to free the bus for the other device. The polling frequency
+ * here should be lower than the read/write frequency since those media access
+ * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST
+ * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD
+ * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min).
  *
- *     We also set a timeout for the timer, in case something goes wrong.
- *     The timeout should be longer then the maximum execution time of a
- *     tape operation.
- */
-/*
- *     DSC timings.
+ * We also set a timeout for the timer, in case something goes wrong. The
+ * timeout should be longer then the maximum execution time of a tape operation.
  */
+
+/* DSC timings. */
 #define IDETAPE_DSC_RW_MIN             5*HZ/100        /* 50 msec */
 #define IDETAPE_DSC_RW_MAX             40*HZ/100       /* 400 msec */
 #define IDETAPE_DSC_RW_TIMEOUT         2*60*HZ         /* 2 minutes */
@@ -613,19 +164,15 @@ typedef struct os_dat_s {
 
 /*************************** End of tunable parameters ***********************/
 
-/*
- *     Read/Write error simulation
- */
+/* Read/Write error simulation */
 #define SIMULATE_ERRORS                        0
 
-/*
- *     For general magnetic tape device compatibility.
- */
-typedef enum {
-       idetape_direction_none,
-       idetape_direction_read,
-       idetape_direction_write
-} idetape_chrdev_direction_t;
+/* tape directions */
+enum {
+       IDETAPE_DIR_NONE  = (1 << 0),
+       IDETAPE_DIR_READ  = (1 << 1),
+       IDETAPE_DIR_WRITE = (1 << 2),
+};
 
 struct idetape_bh {
        u32 b_size;
@@ -634,24 +181,32 @@ struct idetape_bh {
        char *b_data;
 };
 
-/*
- *     Our view of a packet command.
- */
 typedef struct idetape_packet_command_s {
-       u8 c[12];                               /* Actual packet bytes */
-       int retries;                            /* On each retry, we increment retries */
-       int error;                              /* Error code */
-       int request_transfer;                   /* Bytes to transfer */
-       int actually_transferred;               /* Bytes actually transferred */
-       int buffer_size;                        /* Size of our data buffer */
+       /* Actual packet bytes */
+       u8 c[12];
+       /* On each retry, we increment retries */
+       int retries;
+       /* Error code */
+       int error;
+       /* Bytes to transfer */
+       int request_transfer;
+       /* Bytes actually transferred */
+       int actually_transferred;
+       /* Size of our data buffer */
+       int buffer_size;
        struct idetape_bh *bh;
        char *b_data;
        int b_count;
-       u8 *buffer;                             /* Data buffer */
-       u8 *current_position;                   /* Pointer into the above buffer */
-       ide_startstop_t (*callback) (ide_drive_t *);    /* Called when this packet command is completed */
-       u8 pc_buffer[IDETAPE_PC_BUFFER_SIZE];   /* Temporary buffer */
-       unsigned long flags;                    /* Status/Action bit flags: long for set_bit */
+       /* Data buffer */
+       u8 *buffer;
+       /* Pointer into the above buffer */
+       u8 *current_position;
+       /* Called when this packet command is completed */
+       ide_startstop_t (*callback) (ide_drive_t *);
+       /* Temporary buffer */
+       u8 pc_buffer[IDETAPE_PC_BUFFER_SIZE];
+       /* Status/Action bit flags: long for set_bit */
+       unsigned long flags;
 } idetape_pc_t;
 
 /*
@@ -670,68 +225,7 @@ typedef struct idetape_packet_command_s {
 /* Data direction */
 #define        PC_WRITING                      5
 
-/*
- *     Capabilities and Mechanical Status Page
- */
-typedef struct {
-       unsigned        page_code       :6;     /* Page code - Should be 0x2a */
-       __u8            reserved0_6     :1;
-       __u8            ps              :1;     /* parameters saveable */
-       __u8            page_length;            /* Page Length - Should be 0x12 */
-       __u8            reserved2, reserved3;
-       unsigned        ro              :1;     /* Read Only Mode */
-       unsigned        reserved4_1234  :4;
-       unsigned        sprev           :1;     /* Supports SPACE in the reverse direction */
-       unsigned        reserved4_67    :2;
-       unsigned        reserved5_012   :3;
-       unsigned        efmt            :1;     /* Supports ERASE command initiated formatting */
-       unsigned        reserved5_4     :1;
-       unsigned        qfa             :1;     /* Supports the QFA two partition formats */
-       unsigned        reserved5_67    :2;
-       unsigned        lock            :1;     /* Supports locking the volume */
-       unsigned        locked          :1;     /* The volume is locked */
-       unsigned        prevent         :1;     /* The device defaults in the prevent state after power up */   
-       unsigned        eject           :1;     /* The device can eject the volume */
-       __u8            disconnect      :1;     /* The device can break request > ctl */        
-       __u8            reserved6_5     :1;
-       unsigned        ecc             :1;     /* Supports error correction */
-       unsigned        cmprs           :1;     /* Supports data compression */
-       unsigned        reserved7_0     :1;
-       unsigned        blk512          :1;     /* Supports 512 bytes block size */
-       unsigned        blk1024         :1;     /* Supports 1024 bytes block size */
-       unsigned        reserved7_3_6   :4;
-       unsigned        blk32768        :1;     /* slowb - the device restricts the byte count for PIO */
-                                               /* transfers for slow buffer memory ??? */
-                                               /* Also 32768 block size in some cases */
-       __u16           max_speed;              /* Maximum speed supported in KBps */
-       __u8            reserved10, reserved11;
-       __u16           ctl;                    /* Continuous Transfer Limit in blocks */
-       __u16           speed;                  /* Current Speed, in KBps */
-       __u16           buffer_size;            /* Buffer Size, in 512 bytes */
-       __u8            reserved18, reserved19;
-} idetape_capabilities_page_t;
-
-/*
- *     Block Size Page
- */
-typedef struct {
-       unsigned        page_code       :6;     /* Page code - Should be 0x30 */
-       unsigned        reserved1_6     :1;
-       unsigned        ps              :1;
-       __u8            page_length;            /* Page Length - Should be 2 */
-       __u8            reserved2;
-       unsigned        play32          :1;
-       unsigned        play32_5        :1;
-       unsigned        reserved2_23    :2;
-       unsigned        record32        :1;
-       unsigned        record32_5      :1;
-       unsigned        reserved2_6     :1;
-       unsigned        one             :1;
-} idetape_block_size_page_t;
-
-/*
- *     A pipeline stage.
- */
+/* A pipeline stage. */
 typedef struct idetape_stage_s {
        struct request rq;                      /* The corresponding request */
        struct idetape_bh *bh;                  /* The data buffers */
@@ -739,35 +233,8 @@ typedef struct idetape_stage_s {
 } idetape_stage_t;
 
 /*
- *     REQUEST SENSE packet command result - Data Format.
- */
-typedef struct {
-       unsigned        error_code      :7;     /* Current of deferred errors */
-       unsigned        valid           :1;     /* The information field conforms to QIC-157C */
-       __u8            reserved1       :8;     /* Segment Number - Reserved */
-       unsigned        sense_key       :4;     /* Sense Key */
-       unsigned        reserved2_4     :1;     /* Reserved */
-       unsigned        ili             :1;     /* Incorrect Length Indicator */
-       unsigned        eom             :1;     /* End Of Medium */
-       unsigned        filemark        :1;     /* Filemark */
-       __u32           information __attribute__ ((packed));
-       __u8            asl;                    /* Additional sense length (n-7) */
-       __u32           command_specific;       /* Additional command specific information */
-       __u8            asc;                    /* Additional Sense Code */
-       __u8            ascq;                   /* Additional Sense Code Qualifier */
-       __u8            replaceable_unit_code;  /* Field Replaceable Unit Code */
-       unsigned        sk_specific1    :7;     /* Sense Key Specific */
-       unsigned        sksv            :1;     /* Sense Key Specific information is valid */
-       __u8            sk_specific2;           /* Sense Key Specific */
-       __u8            sk_specific3;           /* Sense Key Specific */
-       __u8            pad[2];                 /* Padding to 20 bytes */
-} idetape_request_sense_result_t;
-
-
-/*
- *     Most of our global data which we need to save even as we leave the
- *     driver due to an interrupt or a timer event is stored in a variable
- *     of type idetape_tape_t, defined below.
+ * Most of our global data which we need to save even as we leave the driver due
+ * to an interrupt or a timer event is stored in the struct defined below.
  */
 typedef struct ide_tape_obj {
        ide_drive_t     *drive;
@@ -803,15 +270,14 @@ typedef struct ide_tape_obj {
        int rq_stack_index;
 
        /*
-        *      DSC polling variables.
+        * DSC polling variables.
         *
-        *      While polling for DSC we use postponed_rq to postpone the
-        *      current request so that ide.c will be able to service
-        *      pending requests on the other device. Note that at most
-        *      we will have only one DSC (usually data transfer) request
-        *      in the device request queue. Additional requests can be
-        *      queued in our internal pipeline, but they will be visible
-        *      to ide.c only one at a time.
+        * While polling for DSC we use postponed_rq to postpone the current
+        * request so that ide.c will be able to service pending requests on the
+        * other device. Note that at most we will have only one DSC (usually
+        * data transfer) request in the device request queue. Additional
+        * requests can be queued in our internal pipeline, but they will be
+        * visible to ide.c only one at a time.
         */
        struct request *postponed_rq;
        /* The time in which we started polling for DSC */
@@ -819,72 +285,57 @@ typedef struct ide_tape_obj {
        /* Timer used to poll for dsc */
        struct timer_list dsc_timer;
        /* Read/Write dsc polling frequency */
-       unsigned long best_dsc_rw_frequency;
-       /* The current polling frequency */
-       unsigned long dsc_polling_frequency;
-       /* Maximum waiting time */
+       unsigned long best_dsc_rw_freq;
+       unsigned long dsc_poll_freq;
        unsigned long dsc_timeout;
 
-       /*
-        *      Read position information
-        */
+       /* Read position information */
        u8 partition;
        /* Current block */
-       unsigned int first_frame_position;
-       unsigned int last_frame_position;
-       unsigned int blocks_in_buffer;
+       unsigned int first_frame;
 
-       /*
-        *      Last error information
-        */
+       /* Last error information */
        u8 sense_key, asc, ascq;
 
-       /*
-        *      Character device operation
-        */
+       /* Character device operation */
        unsigned int minor;
        /* device name */
        char name[4];
        /* Current character device data transfer direction */
-       idetape_chrdev_direction_t chrdev_direction;
+       u8 chrdev_dir;
 
-       /*
-        *      Device information
-        */
-       /* Usually 512 or 1024 bytes */
-       unsigned short tape_block_size;
+       /* tape block size, usually 512 or 1024 bytes */
+       unsigned short blk_size;
        int user_bs_factor;
+
        /* Copy of the tape's Capabilities and Mechanical Page */
-       idetape_capabilities_page_t capabilities;
+       u8 caps[20];
 
        /*
-        *      Active data transfer request parameters.
-        *
-        *      At most, there is only one ide-tape originated data transfer
-        *      request in the device request queue. This allows ide.c to
-        *      easily service requests from the other device when we
-        *      postpone our active request. In the pipelined operation
-        *      mode, we use our internal pipeline structure to hold
-        *      more data requests.
+        * Active data transfer request parameters.
         *
-        *      The data buffer size is chosen based on the tape's
-        *      recommendation.
+        * At most, there is only one ide-tape originated data transfer request
+        * in the device request queue. This allows ide.c to easily service
+        * requests from the other device when we postpone our active request.
+        * In the pipelined operation mode, we use our internal pipeline
+        * structure to hold more data requests. The data buffer size is chosen
+        * based on the tape's recommendation.
         */
-       /* Pointer to the request which is waiting in the device request queue */
-       struct request *active_data_request;
-       /* Data buffer size (chosen based on the tape's recommendation */
+       /* ptr to the request which is waiting in the device request queue */
+       struct request *active_data_rq;
+       /* Data buffer size chosen based on the tape's recommendation */
        int stage_size;
        idetape_stage_t *merge_stage;
        int merge_stage_size;
        struct idetape_bh *bh;
        char *b_data;
        int b_count;
-       
+
        /*
-        *      Pipeline parameters.
+        * Pipeline parameters.
         *
-        *      To accomplish non-pipelined mode, we simply set the following
-        *      variables to zero (or NULL, where appropriate).
+        * To accomplish non-pipelined mode, we simply set the following
+        * variables to zero (or NULL, where appropriate).
         */
        /* Number of currently used stages */
        int nr_stages;
@@ -909,23 +360,13 @@ typedef struct ide_tape_obj {
        /* Status/Action flags: long for set_bit */
        unsigned long flags;
        /* protects the ide-tape queue */
-       spinlock_t spinlock;
+       spinlock_t lock;
 
-       /*
-        * Measures average tape speed
-        */
+       /* Measures average tape speed */
        unsigned long avg_time;
        int avg_size;
        int avg_speed;
 
-       /* last sense information */
-       idetape_request_sense_result_t sense;
-
-       char vendor_id[10];
-       char product_id[18];
-       char firmware_revision[6];
-       int firmware_revision_num;
-
        /* the door is currently locked */
        int door_locked;
        /* the tape hardware is write protected */
@@ -934,11 +375,9 @@ typedef struct ide_tape_obj {
        char write_prot;
 
        /*
-        * Limit the number of times a request can
-        * be postponed, to avoid an infinite postpone
-        * deadlock.
+        * Limit the number of times a request can be postponed, to avoid an
+        * infinite postpone deadlock.
         */
-       /* request postpone count limit */
        int postpone_cnt;
 
        /*
@@ -953,30 +392,19 @@ typedef struct ide_tape_obj {
        int tape_head;
        int last_tape_head;
 
-       /*
-        * Speed control at the tape buffers input/output
-        */
+       /* Speed control at the tape buffers input/output */
        unsigned long insert_time;
        int insert_size;
        int insert_speed;
        int max_insert_speed;
        int measure_insert_time;
 
-       /*
-        * Measure tape still time, in milliseconds
-        */
-       unsigned long tape_still_time_begin;
-       int tape_still_time;
-
-       /*
-        * Speed regulation negative feedback loop
-        */
+       /* Speed regulation negative feedback loop */
        int speed_control;
        int pipeline_head_speed;
        int controlled_pipeline_head_speed;
        int uncontrolled_pipeline_head_speed;
        int controlled_last_pipeline_head;
-       int uncontrolled_last_pipeline_head;
        unsigned long uncontrolled_pipeline_head_time;
        unsigned long controlled_pipeline_head_time;
        int controlled_previous_pipeline_head;
@@ -985,18 +413,7 @@ typedef struct ide_tape_obj {
        unsigned long uncontrolled_previous_head_time;
        int restart_speed_control_req;
 
-        /*
-         * Debug_level determines amount of debugging output;
-         * can be changed using /proc/ide/hdx/settings
-         * 0 : almost no debugging output
-         * 1 : 0+output errors only
-         * 2 : 1+output all sensekey/asc
-         * 3 : 2+follow all chrdev related procedures
-         * 4 : 3+follow all procedures
-         * 5 : 4+include pc_stack rq_stack info
-         * 6 : 5+USE_COUNT updates
-         */
-         int debug_level; 
+       u32 debug_mask;
 } idetape_tape_t;
 
 static DEFINE_MUTEX(idetape_ref_mutex);
@@ -1029,9 +446,7 @@ static void ide_tape_put(struct ide_tape_obj *tape)
        mutex_unlock(&idetape_ref_mutex);
 }
 
-/*
- *     Tape door status
- */
+/* Tape door status */
 #define DOOR_UNLOCKED                  0
 #define DOOR_LOCKED                    1
 #define DOOR_EXPLICITLY_LOCKED         2
@@ -1051,51 +466,23 @@ static void ide_tape_put(struct ide_tape_obj *tape)
 /* 0 = no tape is loaded, so we don't rewind after ejecting */
 #define IDETAPE_MEDIUM_PRESENT         9
 
-/*
- *     Supported ATAPI tape drives packet commands
- */
-#define IDETAPE_TEST_UNIT_READY_CMD    0x00
-#define IDETAPE_REWIND_CMD             0x01
-#define IDETAPE_REQUEST_SENSE_CMD      0x03
-#define IDETAPE_READ_CMD               0x08
-#define IDETAPE_WRITE_CMD              0x0a
-#define IDETAPE_WRITE_FILEMARK_CMD     0x10
-#define IDETAPE_SPACE_CMD              0x11
-#define IDETAPE_INQUIRY_CMD            0x12
-#define IDETAPE_ERASE_CMD              0x19
-#define IDETAPE_MODE_SENSE_CMD         0x1a
-#define IDETAPE_MODE_SELECT_CMD                0x15
-#define IDETAPE_LOAD_UNLOAD_CMD                0x1b
-#define IDETAPE_PREVENT_CMD            0x1e
-#define IDETAPE_LOCATE_CMD             0x2b
-#define IDETAPE_READ_POSITION_CMD      0x34
-#define IDETAPE_READ_BUFFER_CMD                0x3c
-#define IDETAPE_SET_SPEED_CMD          0xbb
-
-/*
- *     Some defines for the READ BUFFER command
- */
+/* A define for the READ BUFFER command */
 #define IDETAPE_RETRIEVE_FAULTY_BLOCK  6
 
-/*
- *     Some defines for the SPACE command
- */
+/* Some defines for the SPACE command */
 #define IDETAPE_SPACE_OVER_FILEMARK    1
 #define IDETAPE_SPACE_TO_EOD           3
 
-/*
- *     Some defines for the LOAD UNLOAD command
- */
+/* Some defines for the LOAD UNLOAD command */
 #define IDETAPE_LU_LOAD_MASK           1
 #define IDETAPE_LU_RETENSION_MASK      2
 #define IDETAPE_LU_EOT_MASK            4
 
 /*
- *     Special requests for our block device strategy routine.
+ * Special requests for our block device strategy routine.
  *
- *     In order to service a character device command, we add special
- *     requests to the tail of our block device request queue and wait
- *     for their completion.
+ * In order to service a character device command, we add special requests to
+ * the tail of our block device request queue and wait for their completion.
  */
 
 enum {
@@ -1106,171 +493,20 @@ enum {
        REQ_IDETAPE_READ_BUFFER = (1 << 4),
 };
 
-/*
- *     Error codes which are returned in rq->errors to the higher part
- *     of the driver.
- */
+/* Error codes returned in rq->errors to the higher part of the driver. */
 #define        IDETAPE_ERROR_GENERAL           101
 #define        IDETAPE_ERROR_FILEMARK          102
 #define        IDETAPE_ERROR_EOD               103
 
-/*
- *     The following is used to format the general configuration word of
- *     the ATAPI IDENTIFY DEVICE command.
- */
-struct idetape_id_gcw {        
-       unsigned packet_size            :2;     /* Packet Size */
-       unsigned reserved234            :3;     /* Reserved */
-       unsigned drq_type               :2;     /* Command packet DRQ type */
-       unsigned removable              :1;     /* Removable media */
-       unsigned device_type            :5;     /* Device type */
-       unsigned reserved13             :1;     /* Reserved */
-       unsigned protocol               :2;     /* Protocol type */
-};
-
-/*
- *     INQUIRY packet command - Data Format (From Table 6-8 of QIC-157C)
- */
-typedef struct {
-       unsigned        device_type     :5;     /* Peripheral Device Type */
-       unsigned        reserved0_765   :3;     /* Peripheral Qualifier - Reserved */
-       unsigned        reserved1_6t0   :7;     /* Reserved */
-       unsigned        rmb             :1;     /* Removable Medium Bit */
-       unsigned        ansi_version    :3;     /* ANSI Version */
-       unsigned        ecma_version    :3;     /* ECMA Version */
-       unsigned        iso_version     :2;     /* ISO Version */
-       unsigned        response_format :4;     /* Response Data Format */
-       unsigned        reserved3_45    :2;     /* Reserved */
-       unsigned        reserved3_6     :1;     /* TrmIOP - Reserved */
-       unsigned        reserved3_7     :1;     /* AENC - Reserved */
-       __u8            additional_length;      /* Additional Length (total_length-4) */
-       __u8            rsv5, rsv6, rsv7;       /* Reserved */
-       __u8            vendor_id[8];           /* Vendor Identification */
-       __u8            product_id[16];         /* Product Identification */
-       __u8            revision_level[4];      /* Revision Level */
-       __u8            vendor_specific[20];    /* Vendor Specific - Optional */
-       __u8            reserved56t95[40];      /* Reserved - Optional */
-                                               /* Additional information may be returned */
-} idetape_inquiry_result_t;
-
-/*
- *     READ POSITION packet command - Data Format (From Table 6-57)
- */
-typedef struct {
-       unsigned        reserved0_10    :2;     /* Reserved */
-       unsigned        bpu             :1;     /* Block Position Unknown */    
-       unsigned        reserved0_543   :3;     /* Reserved */
-       unsigned        eop             :1;     /* End Of Partition */
-       unsigned        bop             :1;     /* Beginning Of Partition */
-       u8              partition;              /* Partition Number */
-       u8              reserved2, reserved3;   /* Reserved */
-       u32             first_block;            /* First Block Location */
-       u32             last_block;             /* Last Block Location (Optional) */
-       u8              reserved12;             /* Reserved */
-       u8              blocks_in_buffer[3];    /* Blocks In Buffer - (Optional) */
-       u32             bytes_in_buffer;        /* Bytes In Buffer (Optional) */
-} idetape_read_position_result_t;
-
-/*
- *     Follows structures which are related to the SELECT SENSE / MODE SENSE
- *     packet commands. Those packet commands are still not supported
- *     by ide-tape.
- */
+/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
 #define IDETAPE_BLOCK_DESCRIPTOR       0
 #define        IDETAPE_CAPABILITIES_PAGE       0x2a
-#define IDETAPE_PARAMTR_PAGE           0x2b   /* Onstream DI-x0 only */
-#define IDETAPE_BLOCK_SIZE_PAGE                0x30
-#define IDETAPE_BUFFER_FILLING_PAGE    0x33
-
-/*
- *     Mode Parameter Header for the MODE SENSE packet command
- */
-typedef struct {
-       __u8    mode_data_length;       /* Length of the following data transfer */
-       __u8    medium_type;            /* Medium Type */
-       __u8    dsp;                    /* Device Specific Parameter */
-       __u8    bdl;                    /* Block Descriptor Length */
-#if 0
-       /* data transfer page */
-       __u8    page_code       :6;
-       __u8    reserved0_6     :1;
-       __u8    ps              :1;     /* parameters saveable */
-       __u8    page_length;            /* page Length == 0x02 */
-       __u8    reserved2;
-       __u8    read32k         :1;     /* 32k blk size (data only) */
-       __u8    read32k5        :1;     /* 32.5k blk size (data&AUX) */
-       __u8    reserved3_23    :2;
-       __u8    write32k        :1;     /* 32k blk size (data only) */
-       __u8    write32k5       :1;     /* 32.5k blk size (data&AUX) */
-       __u8    reserved3_6     :1;
-       __u8    streaming       :1;     /* streaming mode enable */
-#endif
-} idetape_mode_parameter_header_t;
-
-/*
- *     Mode Parameter Block Descriptor the MODE SENSE packet command
- *
- *     Support for block descriptors is optional.
- */
-typedef struct {
-       __u8            density_code;           /* Medium density code */
-       __u8            blocks[3];              /* Number of blocks */
-       __u8            reserved4;              /* Reserved */
-       __u8            length[3];              /* Block Length */
-} idetape_parameter_block_descriptor_t;
-
-/*
- *     The Data Compression Page, as returned by the MODE SENSE packet command.
- */
-typedef struct {
-       unsigned        page_code       :6;     /* Page Code - Should be 0xf */
-       unsigned        reserved0       :1;     /* Reserved */
-       unsigned        ps              :1;
-       __u8            page_length;            /* Page Length - Should be 14 */
-       unsigned        reserved2       :6;     /* Reserved */
-       unsigned        dcc             :1;     /* Data Compression Capable */
-       unsigned        dce             :1;     /* Data Compression Enable */
-       unsigned        reserved3       :5;     /* Reserved */
-       unsigned        red             :2;     /* Report Exception on Decompression */
-       unsigned        dde             :1;     /* Data Decompression Enable */
-       __u32           ca;                     /* Compression Algorithm */
-       __u32           da;                     /* Decompression Algorithm */
-       __u8            reserved[4];            /* Reserved */
-} idetape_data_compression_page_t;
-
-/*
- *     The Medium Partition Page, as returned by the MODE SENSE packet command.
- */
-typedef struct {
-       unsigned        page_code       :6;     /* Page Code - Should be 0x11 */
-       unsigned        reserved1_6     :1;     /* Reserved */
-       unsigned        ps              :1;
-       __u8            page_length;            /* Page Length - Should be 6 */
-       __u8            map;                    /* Maximum Additional Partitions - Should be 0 */
-       __u8            apd;                    /* Additional Partitions Defined - Should be 0 */
-       unsigned        reserved4_012   :3;     /* Reserved */
-       unsigned        psum            :2;     /* Should be 0 */
-       unsigned        idp             :1;     /* Should be 0 */
-       unsigned        sdp             :1;     /* Should be 0 */
-       unsigned        fdp             :1;     /* Fixed Data Partitions */
-       __u8            mfr;                    /* Medium Format Recognition */
-       __u8            reserved[2];            /* Reserved */
-} idetape_medium_partition_page_t;
-
-/*
- *     Run time configurable parameters.
- */
-typedef struct {
-       int     dsc_rw_frequency;
-       int     dsc_media_access_frequency;
-       int     nr_stages;
-} idetape_config_t;
 
 /*
- *     The variables below are used for the character device interface.
- *     Additional state variables are defined in our ide_drive_t structure.
+ * The variables below are used for the character device interface. Additional
+ * state variables are defined in our ide_drive_t structure.
  */
-static struct ide_tape_obj * idetape_devs[MAX_HWIFS * MAX_DRIVES];
+static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
 
 #define ide_tape_f(file) ((file)->private_data)
 
@@ -1286,39 +522,34 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
        return tape;
 }
 
-/*
- *      Function declarations
- *
- */
-static int idetape_chrdev_release (struct inode *inode, struct file *filp);
-static void idetape_write_release (ide_drive_t *drive, unsigned int minor);
-
 /*
  * Too bad. The drive wants to send us data which we are not ready to accept.
  * Just throw it away.
  */
-static void idetape_discard_data (ide_drive_t *drive, unsigned int bcount)
+static void idetape_discard_data(ide_drive_t *drive, unsigned int bcount)
 {
        while (bcount--)
                (void) HWIF(drive)->INB(IDE_DATA_REG);
 }
 
-static void idetape_input_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigned int bcount)
+static void idetape_input_buffers(ide_drive_t *drive, idetape_pc_t *pc,
+                                 unsigned int bcount)
 {
        struct idetape_bh *bh = pc->bh;
        int count;
 
        while (bcount) {
-#if IDETAPE_DEBUG_BUGS
                if (bh == NULL) {
                        printk(KERN_ERR "ide-tape: bh == NULL in "
                                "idetape_input_buffers\n");
                        idetape_discard_data(drive, bcount);
                        return;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
-               count = min((unsigned int)(bh->b_size - atomic_read(&bh->b_count)), bcount);
-               HWIF(drive)->atapi_input_bytes(drive, bh->b_data + atomic_read(&bh->b_count), count);
+               count = min(
+                       (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
+                       bcount);
+               HWIF(drive)->atapi_input_bytes(drive, bh->b_data +
+                                       atomic_read(&bh->b_count), count);
                bcount -= count;
                atomic_add(count, &bh->b_count);
                if (atomic_read(&bh->b_count) == bh->b_size) {
@@ -1330,26 +561,26 @@ static void idetape_input_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigne
        pc->bh = bh;
 }
 
-static void idetape_output_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigned int bcount)
+static void idetape_output_buffers(ide_drive_t *drive, idetape_pc_t *pc,
+                                  unsigned int bcount)
 {
        struct idetape_bh *bh = pc->bh;
        int count;
 
        while (bcount) {
-#if IDETAPE_DEBUG_BUGS
                if (bh == NULL) {
-                       printk(KERN_ERR "ide-tape: bh == NULL in "
-                               "idetape_output_buffers\n");
+                       printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
+                                       __func__);
                        return;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
                count = min((unsigned int)pc->b_count, (unsigned int)bcount);
                HWIF(drive)->atapi_output_bytes(drive, pc->b_data, count);
                bcount -= count;
                pc->b_data += count;
                pc->b_count -= count;
                if (!pc->b_count) {
-                       pc->bh = bh = bh->b_reqnext;
+                       bh = bh->b_reqnext;
+                       pc->bh = bh;
                        if (bh) {
                                pc->b_data = bh->b_data;
                                pc->b_count = atomic_read(&bh->b_count);
@@ -1358,7 +589,7 @@ static void idetape_output_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsign
        }
 }
 
-static void idetape_update_buffers (idetape_pc_t *pc)
+static void idetape_update_buffers(idetape_pc_t *pc)
 {
        struct idetape_bh *bh = pc->bh;
        int count;
@@ -1367,13 +598,11 @@ static void idetape_update_buffers (idetape_pc_t *pc)
        if (test_bit(PC_WRITING, &pc->flags))
                return;
        while (bcount) {
-#if IDETAPE_DEBUG_BUGS
                if (bh == NULL) {
-                       printk(KERN_ERR "ide-tape: bh == NULL in "
-                               "idetape_update_buffers\n");
+                       printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
+                                       __func__);
                        return;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
                count = min((unsigned int)bh->b_size, (unsigned int)bcount);
                atomic_set(&bh->b_count, count);
                if (atomic_read(&bh->b_count) == bh->b_size)
@@ -1389,17 +618,14 @@ static void idetape_update_buffers (idetape_pc_t *pc)
  *     driver. A storage space for a maximum of IDETAPE_PC_STACK packet
  *     commands is allocated at initialization time.
  */
-static idetape_pc_t *idetape_next_pc_storage (ide_drive_t *drive)
+static idetape_pc_t *idetape_next_pc_storage(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 5)
-               printk(KERN_INFO "ide-tape: pc_stack_index=%d\n",
-                       tape->pc_stack_index);
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_PCRQ_STACK, "pc_stack_index=%d\n", tape->pc_stack_index);
+
        if (tape->pc_stack_index == IDETAPE_PC_STACK)
-               tape->pc_stack_index=0;
+               tape->pc_stack_index = 0;
        return (&tape->pc_stack[tape->pc_stack_index++]);
 }
 
@@ -1408,32 +634,26 @@ static idetape_pc_t *idetape_next_pc_storage (ide_drive_t *drive)
  *     Since we queue packet commands in the request queue, we need to
  *     allocate a request, along with the allocation of a packet command.
  */
+
 /**************************************************************
  *                                                            *
  *  This should get fixed to use kmalloc(.., GFP_ATOMIC)      *
  *  followed later on by kfree().   -ml                       *
  *                                                            *
  **************************************************************/
-static struct request *idetape_next_rq_storage (ide_drive_t *drive)
+
+static struct request *idetape_next_rq_storage(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 5)
-               printk(KERN_INFO "ide-tape: rq_stack_index=%d\n",
-                       tape->rq_stack_index);
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_PCRQ_STACK, "rq_stack_index=%d\n", tape->rq_stack_index);
+
        if (tape->rq_stack_index == IDETAPE_PC_STACK)
-               tape->rq_stack_index=0;
+               tape->rq_stack_index = 0;
        return (&tape->rq_stack[tape->rq_stack_index++]);
 }
 
-/*
- *     idetape_init_pc initializes a packet command.
- */
-static void idetape_init_pc (idetape_pc_t *pc)
+static void idetape_init_pc(idetape_pc_t *pc)
 {
        memset(pc->c, 0, 12);
        pc->retries = 0;
@@ -1446,36 +666,26 @@ static void idetape_init_pc (idetape_pc_t *pc)
 }
 
 /*
- *     idetape_analyze_error is called on each failed packet command retry
- *     to analyze the request sense. We currently do not utilize this
- *     information.
+ * called on each failed packet command retry to analyze the request sense. We
+ * currently do not utilize this information.
  */
-static void idetape_analyze_error (ide_drive_t *drive, idetape_request_sense_result_t *result)
+static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t *pc = tape->failed_pc;
 
-       tape->sense     = *result;
-       tape->sense_key = result->sense_key;
-       tape->asc       = result->asc;
-       tape->ascq      = result->ascq;
-#if IDETAPE_DEBUG_LOG
-       /*
-        *      Without debugging, we only log an error if we decided to
-        *      give up retrying.
-        */
-       if (tape->debug_level >= 1)
-               printk(KERN_INFO "ide-tape: pc = %x, sense key = %x, "
-                       "asc = %x, ascq = %x\n",
-                       pc->c[0], result->sense_key,
-                       result->asc, result->ascq);
-#endif /* IDETAPE_DEBUG_LOG */
+       tape->sense_key = sense[2] & 0xF;
+       tape->asc       = sense[12];
+       tape->ascq      = sense[13];
 
-       /*
-        *      Correct pc->actually_transferred by asking the tape.
-        */
+       debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n",
+                pc->c[0], tape->sense_key, tape->asc, tape->ascq);
+
+       /* Correct pc->actually_transferred by asking the tape.  */
        if (test_bit(PC_DMA_ERROR, &pc->flags)) {
-               pc->actually_transferred = pc->request_transfer - tape->tape_block_size * ntohl(get_unaligned(&result->information));
+               pc->actually_transferred = pc->request_transfer -
+                       tape->blk_size *
+                       be32_to_cpu(get_unaligned((u32 *)&sense[3]));
                idetape_update_buffers(pc);
        }
 
@@ -1484,29 +694,29 @@ static void idetape_analyze_error (ide_drive_t *drive, idetape_request_sense_res
         * with sense key=5, asc=0x22, ascq=0, let it slide.  Some drives
         * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes.
         */
-       if ((pc->c[0] == IDETAPE_READ_CMD || pc->c[0] == IDETAPE_WRITE_CMD)
-           && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) { /* length==0 */
-               if (result->sense_key == 5) {
+       if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6)
+           /* length == 0 */
+           && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) {
+               if (tape->sense_key == 5) {
                        /* don't report an error, everything's ok */
                        pc->error = 0;
                        /* don't retry read/write */
                        set_bit(PC_ABORT, &pc->flags);
                }
        }
-       if (pc->c[0] == IDETAPE_READ_CMD && result->filemark) {
+       if (pc->c[0] == READ_6 && (sense[2] & 0x80)) {
                pc->error = IDETAPE_ERROR_FILEMARK;
                set_bit(PC_ABORT, &pc->flags);
        }
-       if (pc->c[0] == IDETAPE_WRITE_CMD) {
-               if (result->eom ||
-                   (result->sense_key == 0xd && result->asc == 0x0 &&
-                    result->ascq == 0x2)) {
+       if (pc->c[0] == WRITE_6) {
+               if ((sense[2] & 0x40) || (tape->sense_key == 0xd
+                    && tape->asc == 0x0 && tape->ascq == 0x2)) {
                        pc->error = IDETAPE_ERROR_EOD;
                        set_bit(PC_ABORT, &pc->flags);
                }
        }
-       if (pc->c[0] == IDETAPE_READ_CMD || pc->c[0] == IDETAPE_WRITE_CMD) {
-               if (result->sense_key == 8) {
+       if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
+               if (tape->sense_key == 8) {
                        pc->error = IDETAPE_ERROR_EOD;
                        set_bit(PC_ABORT, &pc->flags);
                }
@@ -1516,61 +726,30 @@ static void idetape_analyze_error (ide_drive_t *drive, idetape_request_sense_res
        }
 }
 
-/*
- * idetape_active_next_stage will declare the next stage as "active".
- */
-static void idetape_active_next_stage (ide_drive_t *drive)
+static void idetape_activate_next_stage(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_stage_t *stage = tape->next_stage;
        struct request *rq = &stage->rq;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_active_next_stage\n");
-#endif /* IDETAPE_DEBUG_LOG */
-#if IDETAPE_DEBUG_BUGS
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+
        if (stage == NULL) {
-               printk(KERN_ERR "ide-tape: bug: Trying to activate a non existing stage\n");
+               printk(KERN_ERR "ide-tape: bug: Trying to activate a non"
+                               " existing stage\n");
                return;
        }
-#endif /* IDETAPE_DEBUG_BUGS */        
 
        rq->rq_disk = tape->disk;
        rq->buffer = NULL;
        rq->special = (void *)stage->bh;
-       tape->active_data_request = rq;
+       tape->active_data_rq = rq;
        tape->active_stage = stage;
        tape->next_stage = stage->next;
 }
 
-/*
- *     idetape_increase_max_pipeline_stages is a part of the feedback
- *     loop which tries to find the optimum number of stages. In the
- *     feedback loop, we are starting from a minimum maximum number of
- *     stages, and if we sense that the pipeline is empty, we try to
- *     increase it, until we reach the user compile time memory limit.
- */
-static void idetape_increase_max_pipeline_stages (ide_drive_t *drive)
-{
-       idetape_tape_t *tape = drive->driver_data;
-       int increase = (tape->max_pipeline - tape->min_pipeline) / 10;
-       
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk (KERN_INFO "ide-tape: Reached idetape_increase_max_pipeline_stages\n");
-#endif /* IDETAPE_DEBUG_LOG */
-
-       tape->max_stages += max(increase, 1);
-       tape->max_stages = max(tape->max_stages, tape->min_pipeline);
-       tape->max_stages = min(tape->max_stages, tape->max_pipeline);
-}
-
-/*
- *     idetape_kfree_stage calls kfree to completely free a stage, along with
- *     its related buffers.
- */
-static void __idetape_kfree_stage (idetape_stage_t *stage)
+/* Free a stage along with its related buffers completely. */
+static void __idetape_kfree_stage(idetape_stage_t *stage)
 {
        struct idetape_bh *prev_bh, *bh = stage->bh;
        int size;
@@ -1591,46 +770,43 @@ static void __idetape_kfree_stage (idetape_stage_t *stage)
        kfree(stage);
 }
 
-static void idetape_kfree_stage (idetape_tape_t *tape, idetape_stage_t *stage)
+static void idetape_kfree_stage(idetape_tape_t *tape, idetape_stage_t *stage)
 {
        __idetape_kfree_stage(stage);
 }
 
 /*
- *     idetape_remove_stage_head removes tape->first_stage from the pipeline.
- *     The caller should avoid race conditions.
+ * Remove tape->first_stage from the pipeline. The caller should avoid race
+ * conditions.
  */
-static void idetape_remove_stage_head (ide_drive_t *drive)
+static void idetape_remove_stage_head(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_stage_t *stage;
-       
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_remove_stage_head\n");
-#endif /* IDETAPE_DEBUG_LOG */
-#if IDETAPE_DEBUG_BUGS
+
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+
        if (tape->first_stage == NULL) {
                printk(KERN_ERR "ide-tape: bug: tape->first_stage is NULL\n");
-               return;         
+               return;
        }
        if (tape->active_stage == tape->first_stage) {
-               printk(KERN_ERR "ide-tape: bug: Trying to free our active pipeline stage\n");
+               printk(KERN_ERR "ide-tape: bug: Trying to free our active "
+                               "pipeline stage\n");
                return;
        }
-#endif /* IDETAPE_DEBUG_BUGS */
        stage = tape->first_stage;
        tape->first_stage = stage->next;
        idetape_kfree_stage(tape, stage);
        tape->nr_stages--;
        if (tape->first_stage == NULL) {
                tape->last_stage = NULL;
-#if IDETAPE_DEBUG_BUGS
                if (tape->next_stage != NULL)
-                       printk(KERN_ERR "ide-tape: bug: tape->next_stage != NULL\n");
+                       printk(KERN_ERR "ide-tape: bug: tape->next_stage !="
+                                       " NULL\n");
                if (tape->nr_stages)
-                       printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 now\n");
-#endif /* IDETAPE_DEBUG_BUGS */
+                       printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 "
+                                       "now\n");
        }
 }
 
@@ -1645,10 +821,8 @@ static void idetape_abort_pipeline(ide_drive_t *drive,
        idetape_stage_t *stage = new_last_stage->next;
        idetape_stage_t *nstage;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: %s: idetape_abort_pipeline called\n", tape->name);
-#endif
+       debug_log(DBG_PROCS, "%s: Enter %s\n", tape->name, __func__);
+
        while (stage) {
                nstage = stage->next;
                idetape_kfree_stage(tape, stage);
@@ -1663,8 +837,8 @@ static void idetape_abort_pipeline(ide_drive_t *drive,
 }
 
 /*
- *     idetape_end_request is used to finish servicing a request, and to
- *     insert a pending pipeline request into the main device queue.
+ * Finish servicing a request and insert a pending pipeline request into the
+ * main device queue.
  */
 static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
 {
@@ -1675,15 +849,12 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
        int remove_stage = 0;
        idetape_stage_t *active_stage;
 
-#if IDETAPE_DEBUG_LOG
-        if (tape->debug_level >= 4)
-       printk(KERN_INFO "ide-tape: Reached idetape_end_request\n");
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
        switch (uptodate) {
-               case 0: error = IDETAPE_ERROR_GENERAL; break;
-               case 1: error = 0; break;
-               default: error = uptodate;
+       case 0: error = IDETAPE_ERROR_GENERAL; break;
+       case 1: error = 0; break;
+       default: error = uptodate;
        }
        rq->errors = error;
        if (error)
@@ -1694,20 +865,21 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
                return 0;
        }
 
-       spin_lock_irqsave(&tape->spinlock, flags);
+       spin_lock_irqsave(&tape->lock, flags);
 
        /* The request was a pipelined data transfer request */
-       if (tape->active_data_request == rq) {
+       if (tape->active_data_rq == rq) {
                active_stage = tape->active_stage;
                tape->active_stage = NULL;
-               tape->active_data_request = NULL;
+               tape->active_data_rq = NULL;
                tape->nr_pending_stages--;
                if (rq->cmd[0] & REQ_IDETAPE_WRITE) {
                        remove_stage = 1;
                        if (error) {
                                set_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
                                if (error == IDETAPE_ERROR_EOD)
-                                       idetape_abort_pipeline(drive, active_stage);
+                                       idetape_abort_pipeline(drive,
+                                                               active_stage);
                        }
                } else if (rq->cmd[0] & REQ_IDETAPE_READ) {
                        if (error == IDETAPE_ERROR_EOD) {
@@ -1716,51 +888,60 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
                        }
                }
                if (tape->next_stage != NULL) {
-                       idetape_active_next_stage(drive);
+                       idetape_activate_next_stage(drive);
 
+                       /* Insert the next request into the request queue. */
+                       (void)ide_do_drive_cmd(drive, tape->active_data_rq,
+                                               ide_end);
+               } else if (!error) {
                        /*
-                        * Insert the next request into the request queue.
+                        * This is a part of the feedback loop which tries to
+                        * find the optimum number of stages. We are starting
+                        * from a minimum maximum number of stages, and if we
+                        * sense that the pipeline is empty, we try to increase
+                        * it, until we reach the user compile time memory
+                        * limit.
                         */
-                       (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end);
-               } else if (!error) {
-                               idetape_increase_max_pipeline_stages(drive);
+                       int i = (tape->max_pipeline - tape->min_pipeline) / 10;
+
+                       tape->max_stages += max(i, 1);
+                       tape->max_stages = max(tape->max_stages,
+                                               tape->min_pipeline);
+                       tape->max_stages = min(tape->max_stages,
+                                               tape->max_pipeline);
                }
        }
        ide_end_drive_cmd(drive, 0, 0);
-//     blkdev_dequeue_request(rq);
-//     drive->rq = NULL;
-//     end_that_request_last(rq);
 
        if (remove_stage)
                idetape_remove_stage_head(drive);
-       if (tape->active_data_request == NULL)
+       if (tape->active_data_rq == NULL)
                clear_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
-       spin_unlock_irqrestore(&tape->spinlock, flags);
+       spin_unlock_irqrestore(&tape->lock, flags);
        return 0;
 }
 
-static ide_startstop_t idetape_request_sense_callback (ide_drive_t *drive)
+static ide_startstop_t idetape_request_sense_callback(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_request_sense_callback\n");
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+
        if (!tape->pc->error) {
-               idetape_analyze_error(drive, (idetape_request_sense_result_t *) tape->pc->buffer);
+               idetape_analyze_error(drive, tape->pc->buffer);
                idetape_end_request(drive, 1, 0);
        } else {
-               printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - Aborting request!\n");
+               printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - "
+                               "Aborting request!\n");
                idetape_end_request(drive, 0, 0);
        }
        return ide_stopped;
 }
 
-static void idetape_create_request_sense_cmd (idetape_pc_t *pc)
+static void idetape_create_request_sense_cmd(idetape_pc_t *pc)
 {
-       idetape_init_pc(pc);    
-       pc->c[0] = IDETAPE_REQUEST_SENSE_CMD;
+       idetape_init_pc(pc);
+       pc->c[0] = REQUEST_SENSE;
        pc->c[4] = 20;
        pc->request_transfer = 20;
        pc->callback = &idetape_request_sense_callback;
@@ -1774,25 +955,22 @@ static void idetape_init_rq(struct request *rq, u8 cmd)
 }
 
 /*
- *     idetape_queue_pc_head generates a new packet command request in front
- *     of the request queue, before the current request, so that it will be
- *     processed immediately, on the next pass through the driver.
- *
- *     idetape_queue_pc_head is called from the request handling part of
- *     the driver (the "bottom" part). Safe storage for the request should
- *     be allocated with idetape_next_pc_storage and idetape_next_rq_storage
- *     before calling idetape_queue_pc_head.
+ * Generate a new packet command request in front of the request queue, before
+ * the current request, so that it will be processed immediately, on the next
+ * pass through the driver. The function below is called from the request
+ * handling part of the driver (the "bottom" part). Safe storage for the request
+ * should be allocated with ide_tape_next_{pc,rq}_storage() prior to that.
  *
- *     Memory for those requests is pre-allocated at initialization time, and
- *     is limited to IDETAPE_PC_STACK requests. We assume that we have enough
- *     space for the maximum possible number of inter-dependent packet commands.
+ * Memory for those requests is pre-allocated at initialization time, and is
+ * limited to IDETAPE_PC_STACK requests. We assume that we have enough space for
+ * the maximum possible number of inter-dependent packet commands.
  *
- *     The higher level of the driver - The ioctl handler and the character
- *     device handling functions should queue request to the lower level part
- *     and wait for their completion using idetape_queue_pc_tail or
- *     idetape_queue_rw_tail.
+ * The higher level of the driver - The ioctl handler and the character device
+ * handling functions should queue request to the lower level part and wait for
+ * their completion using idetape_queue_pc_tail or idetape_queue_rw_tail.
  */
-static void idetape_queue_pc_head (ide_drive_t *drive, idetape_pc_t *pc,struct request *rq)
+static void idetape_queue_pc_head(ide_drive_t *drive, idetape_pc_t *pc,
+                                 struct request *rq)
 {
        struct ide_tape_obj *tape = drive->driver_data;
 
@@ -1813,7 +991,7 @@ static ide_startstop_t idetape_retry_pc (ide_drive_t *drive)
        idetape_pc_t *pc;
        struct request *rq;
 
-       (void)drive->hwif->INB(IDE_ERROR_REG);
+       (void)ide_read_error(drive);
        pc = idetape_next_pc_storage(drive);
        rq = idetape_next_rq_storage(drive);
        idetape_create_request_sense_cmd(pc);
@@ -1823,50 +1001,46 @@ static ide_startstop_t idetape_retry_pc (ide_drive_t *drive)
 }
 
 /*
- *     idetape_postpone_request postpones the current request so that
- *     ide.c will be able to service requests from another device on
- *     the same hwgroup while we are polling for DSC.
+ * Postpone the current request so that ide.c will be able to service requests
+ * from another device on the same hwgroup while we are polling for DSC.
  */
-static void idetape_postpone_request (ide_drive_t *drive)
+static void idetape_postpone_request(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: idetape_postpone_request\n");
-#endif
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+
        tape->postponed_rq = HWGROUP(drive)->rq;
-       ide_stall_queue(drive, tape->dsc_polling_frequency);
+       ide_stall_queue(drive, tape->dsc_poll_freq);
 }
 
+typedef void idetape_io_buf(ide_drive_t *, idetape_pc_t *, unsigned int);
+
 /*
- *     idetape_pc_intr is the usual interrupt handler which will be called
- *     during a packet command. We will transfer some of the data (as
- *     requested by the drive) and will re-point interrupt handler to us.
- *     When data transfer is finished, we will act according to the
- *     algorithm described before idetape_issue_packet_command.
- *
+ * This is the usual interrupt handler which will be called during a packet
+ * command. We will transfer some of the data (as requested by the drive) and
+ * will re-point interrupt handler to us. When data transfer is finished, we
+ * will act according to the algorithm described before
+ * idetape_issue_pc.
  */
-static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
+static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t *pc = tape->pc;
+       xfer_func_t *xferfunc;
+       idetape_io_buf *iobuf;
        unsigned int temp;
 #if SIMULATE_ERRORS
-       static int error_sim_count = 0;
+       static int error_sim_count;
 #endif
        u16 bcount;
        u8 stat, ireason;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_pc_intr "
-                               "interrupt handler\n");
-#endif /* IDETAPE_DEBUG_LOG */ 
+       debug_log(DBG_PROCS, "Enter %s - interrupt handler\n", __func__);
 
        /* Clear the interrupt */
-       stat = hwif->INB(IDE_STATUS_REG);
+       stat = ide_read_status(drive);
 
        if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
                if (hwif->ide_dma_end(drive) || (stat & ERR_STAT)) {
@@ -1896,48 +1070,40 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
                        pc->actually_transferred = pc->request_transfer;
                        idetape_update_buffers(pc);
                }
-#if IDETAPE_DEBUG_LOG
-               if (tape->debug_level >= 4)
-                       printk(KERN_INFO "ide-tape: DMA finished\n");
-#endif /* IDETAPE_DEBUG_LOG */
+               debug_log(DBG_PROCS, "DMA finished\n");
+
        }
 
        /* No more interrupts */
        if ((stat & DRQ_STAT) == 0) {
-#if IDETAPE_DEBUG_LOG
-               if (tape->debug_level >= 2)
-                       printk(KERN_INFO "ide-tape: Packet command completed, %d bytes transferred\n", pc->actually_transferred);
-#endif /* IDETAPE_DEBUG_LOG */
-               clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
+               debug_log(DBG_SENSE, "Packet command completed, %d bytes"
+                               " transferred\n", pc->actually_transferred);
 
+               clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
                local_irq_enable();
 
 #if SIMULATE_ERRORS
-               if ((pc->c[0] == IDETAPE_WRITE_CMD ||
-                    pc->c[0] == IDETAPE_READ_CMD) &&
+               if ((pc->c[0] == WRITE_6 || pc->c[0] == READ_6) &&
                    (++error_sim_count % 100) == 0) {
                        printk(KERN_INFO "ide-tape: %s: simulating error\n",
                                tape->name);
                        stat |= ERR_STAT;
                }
 #endif
-               if ((stat & ERR_STAT) && pc->c[0] == IDETAPE_REQUEST_SENSE_CMD)
+               if ((stat & ERR_STAT) && pc->c[0] == REQUEST_SENSE)
                        stat &= ~ERR_STAT;
                if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) {
                        /* Error detected */
-#if IDETAPE_DEBUG_LOG
-                       if (tape->debug_level >= 1)
-                               printk(KERN_INFO "ide-tape: %s: I/O error\n",
-                                       tape->name);
-#endif /* IDETAPE_DEBUG_LOG */
-                       if (pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
-                               printk(KERN_ERR "ide-tape: I/O error in request sense command\n");
+                       debug_log(DBG_ERR, "%s: I/O error\n", tape->name);
+
+                       if (pc->c[0] == REQUEST_SENSE) {
+                               printk(KERN_ERR "ide-tape: I/O error in request"
+                                               " sense command\n");
                                return ide_do_reset(drive);
                        }
-#if IDETAPE_DEBUG_LOG
-                       if (tape->debug_level >= 1)
-                               printk(KERN_INFO "ide-tape: [cmd %x]: check condition\n", pc->c[0]);
-#endif
+                       debug_log(DBG_ERR, "[cmd %x]: check condition\n",
+                                       pc->c[0]);
+
                        /* Retry operation */
                        return idetape_retry_pc(drive);
                }
@@ -1946,7 +1112,7 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
                    (stat & SEEK_STAT) == 0) {
                        /* Media access command */
                        tape->dsc_polling_start = jiffies;
-                       tape->dsc_polling_frequency = IDETAPE_DSC_MA_FAST;
+                       tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
                        tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
                        /* Allow ide.c to handle other requests */
                        idetape_postpone_request(drive);
@@ -1971,7 +1137,7 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
        ireason = hwif->INB(IDE_IREASON_REG);
 
        if (ireason & CD) {
-               printk(KERN_ERR "ide-tape: CoD != 0 in idetape_pc_intr\n");
+               printk(KERN_ERR "ide-tape: CoD != 0 in %s\n", __func__);
                return ide_do_reset(drive);
        }
        if (((ireason & IO) == IO) == test_bit(PC_WRITING, &pc->flags)) {
@@ -1987,86 +1153,76 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
                temp = pc->actually_transferred + bcount;
                if (temp > pc->request_transfer) {
                        if (temp > pc->buffer_size) {
-                               printk(KERN_ERR "ide-tape: The tape wants to send us more data than expected - discarding data\n");
+                               printk(KERN_ERR "ide-tape: The tape wants to "
+                                       "send us more data than expected "
+                                       "- discarding data\n");
                                idetape_discard_data(drive, bcount);
-                               ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL);
+                               ide_set_handler(drive, &idetape_pc_intr,
+                                               IDETAPE_WAIT_CMD, NULL);
                                return ide_started;
                        }
-#if IDETAPE_DEBUG_LOG
-                       if (tape->debug_level >= 2)
-                               printk(KERN_NOTICE "ide-tape: The tape wants to send us more data than expected - allowing transfer\n");
-#endif /* IDETAPE_DEBUG_LOG */
+                       debug_log(DBG_SENSE, "The tape wants to send us more "
+                               "data than expected - allowing transfer\n");
                }
-       }
-       if (test_bit(PC_WRITING, &pc->flags)) {
-               if (pc->bh != NULL)
-                       idetape_output_buffers(drive, pc, bcount);
-               else
-                       /* Write the current buffer */
-                       hwif->atapi_output_bytes(drive, pc->current_position,
-                                                bcount);
+               iobuf = &idetape_input_buffers;
+               xferfunc = hwif->atapi_input_bytes;
        } else {
-               if (pc->bh != NULL)
-                       idetape_input_buffers(drive, pc, bcount);
-               else
-                       /* Read the current buffer */
-                       hwif->atapi_input_bytes(drive, pc->current_position,
-                                               bcount);
+               iobuf = &idetape_output_buffers;
+               xferfunc = hwif->atapi_output_bytes;
        }
+
+       if (pc->bh)
+               iobuf(drive, pc, bcount);
+       else
+               xferfunc(drive, pc->current_position, bcount);
+
        /* Update the current position */
        pc->actually_transferred += bcount;
        pc->current_position += bcount;
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 2)
-               printk(KERN_INFO "ide-tape: [cmd %x] transferred %d bytes "
-                                "on that interrupt\n", pc->c[0], bcount);
-#endif
+
+       debug_log(DBG_SENSE, "[cmd %x] transferred %d bytes on that intr.\n",
+                       pc->c[0], bcount);
+
        /* And set the interrupt handler again */
        ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL);
        return ide_started;
 }
 
 /*
- *     Packet Command Interface
- *
- *     The current Packet Command is available in tape->pc, and will not
- *     change until we finish handling it. Each packet command is associated
- *     with a callback function that will be called when the command is
- *     finished.
+ * Packet Command Interface
  *
- *     The handling will be done in three stages:
+ * The current Packet Command is available in tape->pc, and will not change
+ * until we finish handling it. Each packet command is associated with a
+ * callback function that will be called when the command is finished.
  *
- *     1.      idetape_issue_packet_command will send the packet command to the
- *             drive, and will set the interrupt handler to idetape_pc_intr.
+ * The handling will be done in three stages:
  *
- *     2.      On each interrupt, idetape_pc_intr will be called. This step
- *             will be repeated until the device signals us that no more
- *             interrupts will be issued.
+ * 1. idetape_issue_pc will send the packet command to the drive, and will set
+ * the interrupt handler to idetape_pc_intr.
  *
- *     3.      ATAPI Tape media access commands have immediate status with a
- *             delayed process. In case of a successful initiation of a
- *             media access packet command, the DSC bit will be set when the
- *             actual execution of the command is finished. 
- *             Since the tape drive will not issue an interrupt, we have to
- *             poll for this event. In this case, we define the request as
- *             "low priority request" by setting rq_status to
- *             IDETAPE_RQ_POSTPONED,   set a timer to poll for DSC and exit
- *             the driver.
+ * 2. On each interrupt, idetape_pc_intr will be called. This step will be
+ * repeated until the device signals us that no more interrupts will be issued.
  *
- *             ide.c will then give higher priority to requests which
- *             originate from the other device, until will change rq_status
- *             to RQ_ACTIVE.
+ * 3. ATAPI Tape media access commands have immediate status with a delayed
+ * process. In case of a successful initiation of a media access packet command,
+ * the DSC bit will be set when the actual execution of the command is finished.
+ * Since the tape drive will not issue an interrupt, we have to poll for this
+ * event. In this case, we define the request as "low priority request" by
+ * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and
+ * exit the driver.
  *
- *     4.      When the packet command is finished, it will be checked for errors.
+ * ide.c will then give higher priority to requests which originate from the
+ * other device, until will change rq_status to RQ_ACTIVE.
  *
- *     5.      In case an error was found, we queue a request sense packet
- *             command in front of the request queue and retry the operation
- *             up to IDETAPE_MAX_PC_RETRIES times.
+ * 4. When the packet command is finished, it will be checked for errors.
  *
- *     6.      In case no error was found, or we decided to give up and not
- *             to retry again, the callback function will be called and then
- *             we will handle the next request.
+ * 5. In case an error was found, we queue a request sense packet command in
+ * front of the request queue and retry the operation up to
+ * IDETAPE_MAX_PC_RETRIES times.
  *
+ * 6. In case no error was found, or we decided to give up and not to retry
+ * again, the callback function will be called and then we will handle the next
+ * request.
  */
 static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
 {
@@ -2077,8 +1233,9 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
        ide_startstop_t startstop;
        u8 ireason;
 
-       if (ide_wait_stat(&startstop,drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) {
-               printk(KERN_ERR "ide-tape: Strange, packet command initiated yet DRQ isn't asserted\n");
+       if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
+               printk(KERN_ERR "ide-tape: Strange, packet command initiated "
+                               "yet DRQ isn't asserted\n");
                return startstop;
        }
        ireason = hwif->INB(IDE_IREASON_REG);
@@ -2111,22 +1268,20 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
        return ide_started;
 }
 
-static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape_pc_t *pc)
+static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, idetape_pc_t *pc)
 {
        ide_hwif_t *hwif = drive->hwif;
        idetape_tape_t *tape = drive->driver_data;
        int dma_ok = 0;
        u16 bcount;
 
-#if IDETAPE_DEBUG_BUGS
-       if (tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD &&
-           pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
+       if (tape->pc->c[0] == REQUEST_SENSE &&
+           pc->c[0] == REQUEST_SENSE) {
                printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
                        "Two request sense in serial were issued\n");
        }
-#endif /* IDETAPE_DEBUG_BUGS */
 
-       if (tape->failed_pc == NULL && pc->c[0] != IDETAPE_REQUEST_SENSE_CMD)
+       if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
                tape->failed_pc = pc;
        /* Set the current packet command */
        tape->pc = pc;
@@ -2134,12 +1289,12 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
        if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
            test_bit(PC_ABORT, &pc->flags)) {
                /*
-                *      We will "abort" retrying a packet command in case
-                *      a legitimate error code was received (crossing a
-                *      filemark, or end of the media, for example).
+                * We will "abort" retrying a packet command in case legitimate
+                * error code was received (crossing a filemark, or end of the
+                * media, for example).
                 */
                if (!test_bit(PC_ABORT, &pc->flags)) {
-                       if (!(pc->c[0] == IDETAPE_TEST_UNIT_READY_CMD &&
+                       if (!(pc->c[0] == TEST_UNIT_READY &&
                              tape->sense_key == 2 && tape->asc == 4 &&
                             (tape->ascq == 1 || tape->ascq == 8))) {
                                printk(KERN_ERR "ide-tape: %s: I/O error, "
@@ -2155,10 +1310,7 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
                tape->failed_pc = NULL;
                return pc->callback(drive);
        }
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 2)
-               printk(KERN_INFO "ide-tape: Retry number - %d, cmd = %02X\n", pc->retries, pc->c[0]);
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
 
        pc->retries++;
        /* We haven't transferred any data yet */
@@ -2181,8 +1333,8 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
        if (dma_ok)                     /* Will begin DMA later */
                set_bit(PC_DMA_IN_PROGRESS, &pc->flags);
        if (test_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags)) {
-               ide_set_handler(drive, &idetape_transfer_pc, IDETAPE_WAIT_CMD, NULL);
-               hwif->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
+               ide_execute_command(drive, WIN_PACKETCMD, &idetape_transfer_pc,
+                                   IDETAPE_WAIT_CMD, NULL);
                return ide_started;
        } else {
                hwif->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
@@ -2190,31 +1342,24 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
        }
 }
 
-/*
- *     General packet command callback function.
- */
-static ide_startstop_t idetape_pc_callback (ide_drive_t *drive)
+static ide_startstop_t idetape_pc_callback(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
-       
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_pc_callback\n");
-#endif /* IDETAPE_DEBUG_LOG */
+
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
        idetape_end_request(drive, tape->pc->error ? 0 : 1, 0);
        return ide_stopped;
 }
 
-/*
- *     A mode sense command is used to "sense" tape parameters.
- */
-static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code)
+/* A mode sense command is used to "sense" tape parameters. */
+static void idetape_create_mode_sense_cmd(idetape_pc_t *pc, u8 page_code)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_MODE_SENSE_CMD;
+       pc->c[0] = MODE_SENSE;
        if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
-               pc->c[1] = 8;   /* DBD = 1 - Don't return block descriptors */
+               /* DBD = 1 - Don't return block descriptors */
+               pc->c[1] = 8;
        pc->c[2] = page_code;
        /*
         * Changed pc->c[3] to 0 (255 will at best return unused info).
@@ -2224,7 +1369,8 @@ static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code)
         * and return an error when 255 is used.
         */
        pc->c[3] = 0;
-       pc->c[4] = 255;         /* (We will just discard data in that case) */
+       /* We will just discard data in that case */
+       pc->c[4] = 255;
        if (page_code == IDETAPE_BLOCK_DESCRIPTOR)
                pc->request_transfer = 12;
        else if (page_code == IDETAPE_CAPABILITIES_PAGE)
@@ -2234,66 +1380,81 @@ static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code)
        pc->callback = &idetape_pc_callback;
 }
 
-static void calculate_speeds(ide_drive_t *drive)
+static void idetape_calculate_speeds(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
-       int full = 125, empty = 75;
 
-       if (time_after(jiffies, tape->controlled_pipeline_head_time + 120 * HZ)) {
-               tape->controlled_previous_pipeline_head = tape->controlled_last_pipeline_head;
-               tape->controlled_previous_head_time = tape->controlled_pipeline_head_time;
+       if (time_after(jiffies,
+                       tape->controlled_pipeline_head_time + 120 * HZ)) {
+               tape->controlled_previous_pipeline_head =
+                       tape->controlled_last_pipeline_head;
+               tape->controlled_previous_head_time =
+                       tape->controlled_pipeline_head_time;
                tape->controlled_last_pipeline_head = tape->pipeline_head;
                tape->controlled_pipeline_head_time = jiffies;
        }
        if (time_after(jiffies, tape->controlled_pipeline_head_time + 60 * HZ))
-               tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_last_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_pipeline_head_time);
+               tape->controlled_pipeline_head_speed = (tape->pipeline_head -
+                               tape->controlled_last_pipeline_head) * 32 * HZ /
+                               (jiffies - tape->controlled_pipeline_head_time);
        else if (time_after(jiffies, tape->controlled_previous_head_time))
-               tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_previous_head_time);
+               tape->controlled_pipeline_head_speed = (tape->pipeline_head -
+                               tape->controlled_previous_pipeline_head) * 32 *
+                       HZ / (jiffies - tape->controlled_previous_head_time);
 
-       if (tape->nr_pending_stages < tape->max_stages /*- 1 */) {
+       if (tape->nr_pending_stages < tape->max_stages/*- 1 */) {
                /* -1 for read mode error recovery */
-               if (time_after(jiffies, tape->uncontrolled_previous_head_time + 10 * HZ)) {
+               if (time_after(jiffies, tape->uncontrolled_previous_head_time +
+                                       10 * HZ)) {
                        tape->uncontrolled_pipeline_head_time = jiffies;
-                       tape->uncontrolled_pipeline_head_speed = (tape->pipeline_head - tape->uncontrolled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->uncontrolled_previous_head_time);
+                       tape->uncontrolled_pipeline_head_speed =
+                               (tape->pipeline_head -
+                                tape->uncontrolled_previous_pipeline_head) *
+                               32 * HZ / (jiffies -
+                                       tape->uncontrolled_previous_head_time);
                }
        } else {
                tape->uncontrolled_previous_head_time = jiffies;
                tape->uncontrolled_previous_pipeline_head = tape->pipeline_head;
-               if (time_after(jiffies, tape->uncontrolled_pipeline_head_time + 30 * HZ)) {
+               if (time_after(jiffies, tape->uncontrolled_pipeline_head_time +
+                                       30 * HZ))
                        tape->uncontrolled_pipeline_head_time = jiffies;
-               }
+
        }
-       tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed, tape->controlled_pipeline_head_speed);
-       if (tape->speed_control == 0) {
-               tape->max_insert_speed = 5000;
-       } else if (tape->speed_control == 1) {
+       tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed,
+                                       tape->controlled_pipeline_head_speed);
+
+       if (tape->speed_control == 1) {
                if (tape->nr_pending_stages >= tape->max_stages / 2)
                        tape->max_insert_speed = tape->pipeline_head_speed +
-                               (1100 - tape->pipeline_head_speed) * 2 * (tape->nr_pending_stages - tape->max_stages / 2) / tape->max_stages;
+                               (1100 - tape->pipeline_head_speed) * 2 *
+                               (tape->nr_pending_stages - tape->max_stages / 2)
+                               / tape->max_stages;
                else
                        tape->max_insert_speed = 500 +
-                               (tape->pipeline_head_speed - 500) * 2 * tape->nr_pending_stages / tape->max_stages;
+                               (tape->pipeline_head_speed - 500) * 2 *
+                               tape->nr_pending_stages / tape->max_stages;
+
                if (tape->nr_pending_stages >= tape->max_stages * 99 / 100)
                        tape->max_insert_speed = 5000;
-       } else if (tape->speed_control == 2) {
-               tape->max_insert_speed = tape->pipeline_head_speed * empty / 100 +
-                       (tape->pipeline_head_speed * full / 100 - tape->pipeline_head_speed * empty / 100) * tape->nr_pending_stages / tape->max_stages;
        } else
                tape->max_insert_speed = tape->speed_control;
+
        tape->max_insert_speed = max(tape->max_insert_speed, 500);
 }
 
-static ide_startstop_t idetape_media_access_finished (ide_drive_t *drive)
+static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t *pc = tape->pc;
        u8 stat;
 
-       stat = drive->hwif->INB(IDE_STATUS_REG);
+       stat = ide_read_status(drive);
+
        if (stat & SEEK_STAT) {
                if (stat & ERR_STAT) {
                        /* Error detected */
-                       if (pc->c[0] != IDETAPE_TEST_UNIT_READY_CMD)
+                       if (pc->c[0] != TEST_UNIT_READY)
                                printk(KERN_ERR "ide-tape: %s: I/O error, ",
                                                tape->name);
                        /* Retry operation */
@@ -2309,14 +1470,14 @@ static ide_startstop_t idetape_media_access_finished (ide_drive_t *drive)
        return pc->callback(drive);
 }
 
-static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
+static ide_startstop_t idetape_rw_callback(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct request *rq = HWGROUP(drive)->rq;
-       int blocks = tape->pc->actually_transferred / tape->tape_block_size;
+       int blocks = tape->pc->actually_transferred / tape->blk_size;
 
-       tape->avg_size += blocks * tape->tape_block_size;
-       tape->insert_size += blocks * tape->tape_block_size;
+       tape->avg_size += blocks * tape->blk_size;
+       tape->insert_size += blocks * tape->blk_size;
        if (tape->insert_size > 1024 * 1024)
                tape->measure_insert_time = 1;
        if (tape->measure_insert_time) {
@@ -2325,19 +1486,17 @@ static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
                tape->insert_size = 0;
        }
        if (time_after(jiffies, tape->insert_time))
-               tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time);
+               tape->insert_speed = tape->insert_size / 1024 * HZ /
+                                       (jiffies - tape->insert_time);
        if (time_after_eq(jiffies, tape->avg_time + HZ)) {
-               tape->avg_speed = tape->avg_size * HZ / (jiffies - tape->avg_time) / 1024;
+               tape->avg_speed = tape->avg_size * HZ /
+                               (jiffies - tape->avg_time) / 1024;
                tape->avg_size = 0;
                tape->avg_time = jiffies;
        }
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
-#if IDETAPE_DEBUG_LOG  
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_rw_callback\n");
-#endif /* IDETAPE_DEBUG_LOG */
-
-       tape->first_frame_position += blocks;
+       tape->first_frame += blocks;
        rq->current_nr_sectors -= blocks;
 
        if (!tape->pc->error)
@@ -2347,28 +1506,31 @@ static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
        return ide_stopped;
 }
 
-static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
+static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc,
+               unsigned int length, struct idetape_bh *bh)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_READ_CMD;
-       put_unaligned(htonl(length), (unsigned int *) &pc->c[1]);
+       pc->c[0] = READ_6;
+       put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
        pc->c[1] = 1;
        pc->callback = &idetape_rw_callback;
        pc->bh = bh;
        atomic_set(&bh->b_count, 0);
        pc->buffer = NULL;
-       pc->request_transfer = pc->buffer_size = length * tape->tape_block_size;
+       pc->buffer_size = length * tape->blk_size;
+       pc->request_transfer = pc->buffer_size;
        if (pc->request_transfer == tape->stage_size)
                set_bit(PC_DMA_RECOMMENDED, &pc->flags);
 }
 
-static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
+static void idetape_create_read_buffer_cmd(idetape_tape_t *tape,
+               idetape_pc_t *pc, struct idetape_bh *bh)
 {
        int size = 32768;
        struct idetape_bh *p = bh;
 
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_READ_BUFFER_CMD;
+       pc->c[0] = READ_BUFFER;
        pc->c[1] = IDETAPE_RETRIEVE_FAULTY_BLOCK;
        pc->c[7] = size >> 8;
        pc->c[8] = size & 0xff;
@@ -2380,14 +1542,16 @@ static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *p
                atomic_set(&p->b_count, 0);
                p = p->b_reqnext;
        }
-       pc->request_transfer = pc->buffer_size = size;
+       pc->request_transfer = size;
+       pc->buffer_size = size;
 }
 
-static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
+static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc,
+               unsigned int length, struct idetape_bh *bh)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_WRITE_CMD;
-       put_unaligned(htonl(length), (unsigned int *) &pc->c[1]);
+       pc->c[0] = WRITE_6;
+       put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
        pc->c[1] = 1;
        pc->callback = &idetape_rw_callback;
        set_bit(PC_WRITING, &pc->flags);
@@ -2395,14 +1559,12 @@ static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, uns
        pc->b_data = bh->b_data;
        pc->b_count = atomic_read(&bh->b_count);
        pc->buffer = NULL;
-       pc->request_transfer = pc->buffer_size = length * tape->tape_block_size;
+       pc->buffer_size = length * tape->blk_size;
+       pc->request_transfer = pc->buffer_size;
        if (pc->request_transfer == tape->stage_size)
                set_bit(PC_DMA_RECOMMENDED, &pc->flags);
 }
 
-/*
- * idetape_do_request is our request handling function.        
- */
 static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                                          struct request *rq, sector_t block)
 {
@@ -2411,37 +1573,22 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
        struct request *postponed_rq = tape->postponed_rq;
        u8 stat;
 
-#if IDETAPE_DEBUG_LOG
-#if 0
-       if (tape->debug_level >= 5)
-               printk(KERN_INFO "ide-tape:  %d, "
-                       "dev: %s, cmd: %ld, errors: %d\n",
-                        rq->rq_disk->disk_name, rq->cmd[0], rq->errors);
-#endif
-       if (tape->debug_level >= 2)
-               printk(KERN_INFO "ide-tape: sector: %ld, "
-                       "nr_sectors: %ld, current_nr_sectors: %d\n",
+       debug_log(DBG_SENSE, "sector: %ld, nr_sectors: %ld,"
+                       " current_nr_sectors: %d\n",
                        rq->sector, rq->nr_sectors, rq->current_nr_sectors);
-#endif /* IDETAPE_DEBUG_LOG */
 
        if (!blk_special_request(rq)) {
-               /*
-                * We do not support buffer cache originated requests.
-                */
+               /* We do not support buffer cache originated requests. */
                printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
                        "request queue (%d)\n", drive->name, rq->cmd_type);
                ide_end_request(drive, 0, 0);
                return ide_stopped;
        }
 
-       /*
-        *      Retry a failed packet command
-        */
-       if (tape->failed_pc != NULL &&
-           tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
-               return idetape_issue_packet_command(drive, tape->failed_pc);
-       }
-#if IDETAPE_DEBUG_BUGS
+       /* Retry a failed packet command */
+       if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE)
+               return idetape_issue_pc(drive, tape->failed_pc);
+
        if (postponed_rq != NULL)
                if (rq != postponed_rq) {
                        printk(KERN_ERR "ide-tape: ide-tape.c bug - "
@@ -2449,7 +1596,6 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                        idetape_end_request(drive, 0, 0);
                        return ide_stopped;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
 
        tape->postponed_rq = NULL;
 
@@ -2457,7 +1603,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
         * If the tape is still busy, postpone our request and service
         * the other device meanwhile.
         */
-       stat = drive->hwif->INB(IDE_STATUS_REG);
+       stat = ide_read_status(drive);
 
        if (!drive->dsc_overlap && !(rq->cmd[0] & REQ_IDETAPE_PC2))
                set_bit(IDETAPE_IGNORE_DSC, &tape->flags);
@@ -2467,16 +1613,15 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                drive->post_reset = 0;
        }
 
-       if (tape->tape_still_time > 100 && tape->tape_still_time < 200)
-               tape->measure_insert_time = 1;
        if (time_after(jiffies, tape->insert_time))
-               tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time);
-       calculate_speeds(drive);
+               tape->insert_speed = tape->insert_size / 1024 * HZ /
+                                       (jiffies - tape->insert_time);
+       idetape_calculate_speeds(drive);
        if (!test_and_clear_bit(IDETAPE_IGNORE_DSC, &tape->flags) &&
            (stat & SEEK_STAT) == 0) {
                if (postponed_rq == NULL) {
                        tape->dsc_polling_start = jiffies;
-                       tape->dsc_polling_frequency = tape->best_dsc_rw_frequency;
+                       tape->dsc_poll_freq = tape->best_dsc_rw_freq;
                        tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
                } else if (time_after(jiffies, tape->dsc_timeout)) {
                        printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
@@ -2487,8 +1632,10 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                        } else {
                                return ide_do_reset(drive);
                        }
-               } else if (time_after(jiffies, tape->dsc_polling_start + IDETAPE_DSC_MA_THRESHOLD))
-                       tape->dsc_polling_frequency = IDETAPE_DSC_MA_SLOW;
+               } else if (time_after(jiffies,
+                                       tape->dsc_polling_start +
+                                       IDETAPE_DSC_MA_THRESHOLD))
+                       tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
                idetape_postpone_request(drive);
                return ide_stopped;
        }
@@ -2496,20 +1643,23 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                tape->buffer_head++;
                tape->postpone_cnt = 0;
                pc = idetape_next_pc_storage(drive);
-               idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special);
+               idetape_create_read_cmd(tape, pc, rq->current_nr_sectors,
+                                       (struct idetape_bh *)rq->special);
                goto out;
        }
        if (rq->cmd[0] & REQ_IDETAPE_WRITE) {
                tape->buffer_head++;
                tape->postpone_cnt = 0;
                pc = idetape_next_pc_storage(drive);
-               idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special);
+               idetape_create_write_cmd(tape, pc, rq->current_nr_sectors,
+                                        (struct idetape_bh *)rq->special);
                goto out;
        }
        if (rq->cmd[0] & REQ_IDETAPE_READ_BUFFER) {
                tape->postpone_cnt = 0;
                pc = idetape_next_pc_storage(drive);
-               idetape_create_read_buffer_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special);
+               idetape_create_read_buffer_cmd(tape, pc,
+                               (struct idetape_bh *)rq->special);
                goto out;
        }
        if (rq->cmd[0] & REQ_IDETAPE_PC1) {
@@ -2524,49 +1674,51 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
        }
        BUG();
 out:
-       return idetape_issue_packet_command(drive, pc);
+       return idetape_issue_pc(drive, pc);
 }
 
-/*
- *     Pipeline related functions
- */
-static inline int idetape_pipeline_active (idetape_tape_t *tape)
+/* Pipeline related functions */
+static inline int idetape_pipeline_active(idetape_tape_t *tape)
 {
        int rc1, rc2;
 
        rc1 = test_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
-       rc2 = (tape->active_data_request != NULL);
+       rc2 = (tape->active_data_rq != NULL);
        return rc1;
 }
 
 /*
- *     idetape_kmalloc_stage uses __get_free_page to allocate a pipeline
- *     stage, along with all the necessary small buffers which together make
- *     a buffer of size tape->stage_size (or a bit more). We attempt to
- *     combine sequential pages as much as possible.
+ * The function below uses __get_free_page to allocate a pipeline stage, along
+ * with all the necessary small buffers which together make a buffer of size
+ * tape->stage_size (or a bit more). We attempt to combine sequential pages as
+ * much as possible.
  *
- *     Returns a pointer to the new allocated stage, or NULL if we
- *     can't (or don't want to) allocate a stage.
+ * It returns a pointer to the new allocated stage, or NULL if we can't (or
+ * don't want to) allocate a stage.
  *
- *     Pipeline stages are optional and are used to increase performance.
- *     If we can't allocate them, we'll manage without them.
+ * Pipeline stages are optional and are used to increase performance. If we
+ * can't allocate them, we'll manage without them.
  */
-static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, int clear)
+static idetape_stage_t *__idetape_kmalloc_stage(idetape_tape_t *tape, int full,
+                                               int clear)
 {
        idetape_stage_t *stage;
        struct idetape_bh *prev_bh, *bh;
        int pages = tape->pages_per_stage;
        char *b_data = NULL;
 
-       if ((stage = kmalloc(sizeof (idetape_stage_t),GFP_KERNEL)) == NULL)
+       stage = kmalloc(sizeof(idetape_stage_t), GFP_KERNEL);
+       if (!stage)
                return NULL;
        stage->next = NULL;
 
-       bh = stage->bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
+       stage->bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
+       bh = stage->bh;
        if (bh == NULL)
                goto abort;
        bh->b_reqnext = NULL;
-       if ((bh->b_data = (char *) __get_free_page (GFP_KERNEL)) == NULL)
+       bh->b_data = (char *) __get_free_page(GFP_KERNEL);
+       if (!bh->b_data)
                goto abort;
        if (clear)
                memset(bh->b_data, 0, PAGE_SIZE);
@@ -2574,7 +1726,8 @@ static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full,
        atomic_set(&bh->b_count, full ? bh->b_size : 0);
 
        while (--pages) {
-               if ((b_data = (char *) __get_free_page (GFP_KERNEL)) == NULL)
+               b_data = (char *) __get_free_page(GFP_KERNEL);
+               if (!b_data)
                        goto abort;
                if (clear)
                        memset(b_data, 0, PAGE_SIZE);
@@ -2592,7 +1745,8 @@ static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full,
                        continue;
                }
                prev_bh = bh;
-               if ((bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL)) == NULL) {
+               bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
+               if (!bh) {
                        free_page((unsigned long) b_data);
                        goto abort;
                }
@@ -2611,14 +1765,11 @@ abort:
        return NULL;
 }
 
-static idetape_stage_t *idetape_kmalloc_stage (idetape_tape_t *tape)
+static idetape_stage_t *idetape_kmalloc_stage(idetape_tape_t *tape)
 {
        idetape_stage_t *cache_stage = tape->cache_stage;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_kmalloc_stage\n");
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
        if (tape->nr_stages >= tape->max_stages)
                return NULL;
@@ -2629,22 +1780,24 @@ static idetape_stage_t *idetape_kmalloc_stage (idetape_tape_t *tape)
        return __idetape_kmalloc_stage(tape, 0, 0);
 }
 
-static int idetape_copy_stage_from_user (idetape_tape_t *tape, idetape_stage_t *stage, const char __user *buf, int n)
+static int idetape_copy_stage_from_user(idetape_tape_t *tape,
+               idetape_stage_t *stage, const char __user *buf, int n)
 {
        struct idetape_bh *bh = tape->bh;
        int count;
        int ret = 0;
 
        while (n) {
-#if IDETAPE_DEBUG_BUGS
                if (bh == NULL) {
-                       printk(KERN_ERR "ide-tape: bh == NULL in "
-                               "idetape_copy_stage_from_user\n");
+                       printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
+                                       __func__);
                        return 1;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
-               count = min((unsigned int)(bh->b_size - atomic_read(&bh->b_count)), (unsigned int)n);
-               if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf, count))
+               count = min((unsigned int)
+                               (bh->b_size - atomic_read(&bh->b_count)),
+                               (unsigned int)n);
+               if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf,
+                               count))
                        ret = 1;
                n -= count;
                atomic_add(count, &bh->b_count);
@@ -2659,20 +1812,19 @@ static int idetape_copy_stage_from_user (idetape_tape_t *tape, idetape_stage_t *
        return ret;
 }
 
-static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, idetape_stage_t *stage, int n)
+static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf,
+               idetape_stage_t *stage, int n)
 {
        struct idetape_bh *bh = tape->bh;
        int count;
        int ret = 0;
 
        while (n) {
-#if IDETAPE_DEBUG_BUGS
                if (bh == NULL) {
-                       printk(KERN_ERR "ide-tape: bh == NULL in "
-                               "idetape_copy_stage_to_user\n");
+                       printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
+                                       __func__);
                        return 1;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
                count = min(tape->b_count, n);
                if  (copy_to_user(buf, tape->b_data, count))
                        ret = 1;
@@ -2681,7 +1833,8 @@ static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, i
                tape->b_count -= count;
                buf += count;
                if (!tape->b_count) {
-                       tape->bh = bh = bh->b_reqnext;
+                       bh = bh->b_reqnext;
+                       tape->bh = bh;
                        if (bh) {
                                tape->b_data = bh->b_data;
                                tape->b_count = atomic_read(&bh->b_count);
@@ -2691,12 +1844,12 @@ static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, i
        return ret;
 }
 
-static void idetape_init_merge_stage (idetape_tape_t *tape)
+static void idetape_init_merge_stage(idetape_tape_t *tape)
 {
        struct idetape_bh *bh = tape->merge_stage->bh;
-       
+
        tape->bh = bh;
-       if (tape->chrdev_direction == idetape_direction_write)
+       if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
                atomic_set(&bh->b_count, 0);
        else {
                tape->b_data = bh->b_data;
@@ -2704,7 +1857,7 @@ static void idetape_init_merge_stage (idetape_tape_t *tape)
        }
 }
 
-static void idetape_switch_buffers (idetape_tape_t *tape, idetape_stage_t *stage)
+static void idetape_switch_buffers(idetape_tape_t *tape, idetape_stage_t *stage)
 {
        struct idetape_bh *tmp;
 
@@ -2714,89 +1867,76 @@ static void idetape_switch_buffers (idetape_tape_t *tape, idetape_stage_t *stage
        idetape_init_merge_stage(tape);
 }
 
-/*
- *     idetape_add_stage_tail adds a new stage at the end of the pipeline.
- */
-static void idetape_add_stage_tail (ide_drive_t *drive,idetape_stage_t *stage)
+/* Add a new stage at the end of the pipeline. */
+static void idetape_add_stage_tail(ide_drive_t *drive, idetape_stage_t *stage)
 {
        idetape_tape_t *tape = drive->driver_data;
        unsigned long flags;
-       
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk (KERN_INFO "ide-tape: Reached idetape_add_stage_tail\n");
-#endif /* IDETAPE_DEBUG_LOG */
-       spin_lock_irqsave(&tape->spinlock, flags);
+
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+
+       spin_lock_irqsave(&tape->lock, flags);
        stage->next = NULL;
        if (tape->last_stage != NULL)
-               tape->last_stage->next=stage;
+               tape->last_stage->next = stage;
        else
-               tape->first_stage = tape->next_stage=stage;
+               tape->first_stage = stage;
+               tape->next_stage  = stage;
        tape->last_stage = stage;
        if (tape->next_stage == NULL)
                tape->next_stage = tape->last_stage;
        tape->nr_stages++;
        tape->nr_pending_stages++;
-       spin_unlock_irqrestore(&tape->spinlock, flags);
+       spin_unlock_irqrestore(&tape->lock, flags);
 }
 
-/*
- *     idetape_wait_for_request installs a completion in a pending request
- *     and sleeps until it is serviced.
- *
- *     The caller should ensure that the request will not be serviced
- *     before we install the completion (usually by disabling interrupts).
+/* Install a completion in a pending request and sleep until it is serviced. The
+ * caller should ensure that the request will not be serviced before we install
+ * the completion (usually by disabling interrupts).
  */
-static void idetape_wait_for_request (ide_drive_t *drive, struct request *rq)
+static void idetape_wait_for_request(ide_drive_t *drive, struct request *rq)
 {
        DECLARE_COMPLETION_ONSTACK(wait);
        idetape_tape_t *tape = drive->driver_data;
 
-#if IDETAPE_DEBUG_BUGS
        if (rq == NULL || !blk_special_request(rq)) {
-               printk (KERN_ERR "ide-tape: bug: Trying to sleep on non-valid request\n");
+               printk(KERN_ERR "ide-tape: bug: Trying to sleep on non-valid"
+                                " request\n");
                return;
        }
-#endif /* IDETAPE_DEBUG_BUGS */
        rq->end_io_data = &wait;
        rq->end_io = blk_end_sync_rq;
-       spin_unlock_irq(&tape->spinlock);
+       spin_unlock_irq(&tape->lock);
        wait_for_completion(&wait);
        /* The stage and its struct request have been deallocated */
-       spin_lock_irq(&tape->spinlock);
+       spin_lock_irq(&tape->lock);
 }
 
-static ide_startstop_t idetape_read_position_callback (ide_drive_t *drive)
+static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
-       idetape_read_position_result_t *result;
-       
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_read_position_callback\n");
-#endif /* IDETAPE_DEBUG_LOG */
+       u8 *readpos = tape->pc->buffer;
+
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
        if (!tape->pc->error) {
-               result = (idetape_read_position_result_t *) tape->pc->buffer;
-#if IDETAPE_DEBUG_LOG
-               if (tape->debug_level >= 2)
-                       printk(KERN_INFO "ide-tape: BOP - %s\n",result->bop ? "Yes":"No");
-               if (tape->debug_level >= 2)
-                       printk(KERN_INFO "ide-tape: EOP - %s\n",result->eop ? "Yes":"No");
-#endif /* IDETAPE_DEBUG_LOG */
-               if (result->bpu) {
-                       printk(KERN_INFO "ide-tape: Block location is unknown to the tape\n");
+               debug_log(DBG_SENSE, "BOP - %s\n",
+                               (readpos[0] & 0x80) ? "Yes" : "No");
+               debug_log(DBG_SENSE, "EOP - %s\n",
+                               (readpos[0] & 0x40) ? "Yes" : "No");
+
+               if (readpos[0] & 0x4) {
+                       printk(KERN_INFO "ide-tape: Block location is unknown"
+                                        "to the tape\n");
                        clear_bit(IDETAPE_ADDRESS_VALID, &tape->flags);
                        idetape_end_request(drive, 0, 0);
                } else {
-#if IDETAPE_DEBUG_LOG
-                       if (tape->debug_level >= 2)
-                               printk(KERN_INFO "ide-tape: Block Location - %u\n", ntohl(result->first_block));
-#endif /* IDETAPE_DEBUG_LOG */
-                       tape->partition = result->partition;
-                       tape->first_frame_position = ntohl(result->first_block);
-                       tape->last_frame_position = ntohl(result->last_block);
-                       tape->blocks_in_buffer = result->blocks_in_buffer[2];
+                       debug_log(DBG_SENSE, "Block Location - %u\n",
+                                       be32_to_cpu(*(u32 *)&readpos[4]));
+
+                       tape->partition = readpos[1];
+                       tape->first_frame =
+                               be32_to_cpu(*(u32 *)&readpos[4]);
                        set_bit(IDETAPE_ADDRESS_VALID, &tape->flags);
                        idetape_end_request(drive, 1, 0);
                }
@@ -2807,17 +1947,14 @@ static ide_startstop_t idetape_read_position_callback (ide_drive_t *drive)
 }
 
 /*
- *     idetape_create_write_filemark_cmd will:
- *
- *             1.      Write a filemark if write_filemark=1.
- *             2.      Flush the device buffers without writing a filemark
- *                     if write_filemark=0.
- *
+ * Write a filemark if write_filemark=1. Flush the device buffers without
+ * writing a filemark otherwise.
  */
-static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t *pc,int write_filemark)
+static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
+               idetape_pc_t *pc, int write_filemark)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_WRITE_FILEMARK_CMD;
+       pc->c[0] = WRITE_FILEMARKS;
        pc->c[4] = write_filemark;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
@@ -2826,31 +1963,24 @@ static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t
 static void idetape_create_test_unit_ready_cmd(idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_TEST_UNIT_READY_CMD;
+       pc->c[0] = TEST_UNIT_READY;
        pc->callback = &idetape_pc_callback;
 }
 
 /*
- *     idetape_queue_pc_tail is based on the following functions:
- *
- *     ide_do_drive_cmd from ide.c
- *     cdrom_queue_request and cdrom_queue_packet_command from ide-cd.c
+ * We add a special packet command request to the tail of the request queue, and
+ * wait for it to be serviced. This is not to be called from within the request
+ * handling part of the driver! We allocate here data on the stack and it is
+ * valid until the request is finished. This is not the case for the bottom part
+ * of the driver, where we are always leaving the functions to wait for an
+ * interrupt or a timer event.
  *
- *     We add a special packet command request to the tail of the request
- *     queue, and wait for it to be serviced.
- *
- *     This is not to be called from within the request handling part
- *     of the driver ! We allocate here data in the stack, and it is valid
- *     until the request is finished. This is not the case for the bottom
- *     part of the driver, where we are always leaving the functions to wait
- *     for an interrupt or a timer event.
- *
- *     From the bottom part of the driver, we should allocate safe memory
- *     using idetape_next_pc_storage and idetape_next_rq_storage, and add
- *     the request to the request list without waiting for it to be serviced !
- *     In that case, we usually use idetape_queue_pc_head.
+ * From the bottom part of the driver, we should allocate safe memory using
+ * idetape_next_pc_storage() and ide_tape_next_rq_storage(), and add the request
+ * to the request list without waiting for it to be serviced! In that case, we
+ * usually use idetape_queue_pc_head().
  */
-static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc)
+static int __idetape_queue_pc_tail(ide_drive_t *drive, idetape_pc_t *pc)
 {
        struct ide_tape_obj *tape = drive->driver_data;
        struct request rq;
@@ -2861,10 +1991,11 @@ static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc)
        return ide_do_drive_cmd(drive, &rq, ide_wait);
 }
 
-static void idetape_create_load_unload_cmd (ide_drive_t *drive, idetape_pc_t *pc,int cmd)
+static void idetape_create_load_unload_cmd(ide_drive_t *drive, idetape_pc_t *pc,
+               int cmd)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_LOAD_UNLOAD_CMD;
+       pc->c[0] = START_STOP;
        pc->c[4] = cmd;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
@@ -2876,9 +2007,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
        idetape_pc_t pc;
        int load_attempted = 0;
 
-       /*
-        * Wait for the tape to become ready
-        */
+       /* Wait for the tape to become ready */
        set_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
        timeout += jiffies;
        while (time_before(jiffies, timeout)) {
@@ -2886,10 +2015,12 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
                if (!__idetape_queue_pc_tail(drive, &pc))
                        return 0;
                if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
-                   || (tape->asc == 0x3A)) {   /* no media */
+                   || (tape->asc == 0x3A)) {
+                       /* no media */
                        if (load_attempted)
                                return -ENOMEDIUM;
-                       idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK);
+                       idetape_create_load_unload_cmd(drive, &pc,
+                                                       IDETAPE_LU_LOAD_MASK);
                        __idetape_queue_pc_tail(drive, &pc);
                        load_attempted = 1;
                /* not about to be ready */
@@ -2901,85 +2032,86 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
        return -EIO;
 }
 
-static int idetape_queue_pc_tail (ide_drive_t *drive,idetape_pc_t *pc)
+static int idetape_queue_pc_tail(ide_drive_t *drive, idetape_pc_t *pc)
 {
        return __idetape_queue_pc_tail(drive, pc);
 }
 
-static int idetape_flush_tape_buffers (ide_drive_t *drive)
+static int idetape_flush_tape_buffers(ide_drive_t *drive)
 {
        idetape_pc_t pc;
        int rc;
 
        idetape_create_write_filemark_cmd(drive, &pc, 0);
-       if ((rc = idetape_queue_pc_tail(drive, &pc)))
+       rc = idetape_queue_pc_tail(drive, &pc);
+       if (rc)
                return rc;
        idetape_wait_ready(drive, 60 * 5 * HZ);
        return 0;
 }
 
-static void idetape_create_read_position_cmd (idetape_pc_t *pc)
+static void idetape_create_read_position_cmd(idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_READ_POSITION_CMD;
+       pc->c[0] = READ_POSITION;
        pc->request_transfer = 20;
        pc->callback = &idetape_read_position_callback;
 }
 
-static int idetape_read_position (ide_drive_t *drive)
+static int idetape_read_position(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t pc;
        int position;
 
-#if IDETAPE_DEBUG_LOG
-        if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_read_position\n");
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
        idetape_create_read_position_cmd(&pc);
        if (idetape_queue_pc_tail(drive, &pc))
                return -1;
-       position = tape->first_frame_position;
+       position = tape->first_frame;
        return position;
 }
 
-static void idetape_create_locate_cmd (ide_drive_t *drive, idetape_pc_t *pc, unsigned int block, u8 partition, int skip)
+static void idetape_create_locate_cmd(ide_drive_t *drive, idetape_pc_t *pc,
+               unsigned int block, u8 partition, int skip)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_LOCATE_CMD;
+       pc->c[0] = POSITION_TO_ELEMENT;
        pc->c[1] = 2;
-       put_unaligned(htonl(block), (unsigned int *) &pc->c[3]);
+       put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
        pc->c[8] = partition;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
 }
 
-static int idetape_create_prevent_cmd (ide_drive_t *drive, idetape_pc_t *pc, int prevent)
+static int idetape_create_prevent_cmd(ide_drive_t *drive, idetape_pc_t *pc,
+                                     int prevent)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-       if (!tape->capabilities.lock)
+       /* device supports locking according to capabilities page */
+       if (!(tape->caps[6] & 0x01))
                return 0;
 
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_PREVENT_CMD;
+       pc->c[0] = ALLOW_MEDIUM_REMOVAL;
        pc->c[4] = prevent;
        pc->callback = &idetape_pc_callback;
        return 1;
 }
 
-static int __idetape_discard_read_pipeline (ide_drive_t *drive)
+static int __idetape_discard_read_pipeline(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        unsigned long flags;
        int cnt;
 
-       if (tape->chrdev_direction != idetape_direction_read)
+       if (tape->chrdev_dir != IDETAPE_DIR_READ)
                return 0;
 
        /* Remove merge stage. */
-       cnt = tape->merge_stage_size / tape->tape_block_size;
+       cnt = tape->merge_stage_size / tape->blk_size;
        if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags))
                ++cnt;          /* Filemarks count as 1 sector */
        tape->merge_stage_size = 0;
@@ -2990,22 +2122,22 @@ static int __idetape_discard_read_pipeline (ide_drive_t *drive)
 
        /* Clear pipeline flags. */
        clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
-       tape->chrdev_direction = idetape_direction_none;
+       tape->chrdev_dir = IDETAPE_DIR_NONE;
 
        /* Remove pipeline stages. */
        if (tape->first_stage == NULL)
                return 0;
 
-       spin_lock_irqsave(&tape->spinlock, flags);
+       spin_lock_irqsave(&tape->lock, flags);
        tape->next_stage = NULL;
        if (idetape_pipeline_active(tape))
-               idetape_wait_for_request(drive, tape->active_data_request);
-       spin_unlock_irqrestore(&tape->spinlock, flags);
+               idetape_wait_for_request(drive, tape->active_data_rq);
+       spin_unlock_irqrestore(&tape->lock, flags);
 
        while (tape->first_stage != NULL) {
                struct request *rq_ptr = &tape->first_stage->rq;
 
-               cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors; 
+               cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors;
                if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK)
                        ++cnt;
                idetape_remove_stage_head(drive);
@@ -3016,21 +2148,19 @@ static int __idetape_discard_read_pipeline (ide_drive_t *drive)
 }
 
 /*
- *     idetape_position_tape positions the tape to the requested block
- *     using the LOCATE packet command. A READ POSITION command is then
- *     issued to check where we are positioned.
- *
- *     Like all higher level operations, we queue the commands at the tail
- *     of the request queue and wait for their completion.
- *     
+ * Position the tape to the requested block using the LOCATE packet command.
+ * A READ POSITION command is then issued to check where we are positioned. Like
+ * all higher level operations, we queue the commands at the tail of the request
+ * queue and wait for their completion.
  */
-static int idetape_position_tape (ide_drive_t *drive, unsigned int block, u8 partition, int skip)
+static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
+               u8 partition, int skip)
 {
        idetape_tape_t *tape = drive->driver_data;
        int retval;
        idetape_pc_t pc;
 
-       if (tape->chrdev_direction == idetape_direction_read)
+       if (tape->chrdev_dir == IDETAPE_DIR_READ)
                __idetape_discard_read_pipeline(drive);
        idetape_wait_ready(drive, 60 * 5 * HZ);
        idetape_create_locate_cmd(drive, &pc, block, partition, skip);
@@ -3042,7 +2172,8 @@ static int idetape_position_tape (ide_drive_t *drive, unsigned int block, u8 par
        return (idetape_queue_pc_tail(drive, &pc));
 }
 
-static void idetape_discard_read_pipeline (ide_drive_t *drive, int restore_position)
+static void idetape_discard_read_pipeline(ide_drive_t *drive,
+                                         int restore_position)
 {
        idetape_tape_t *tape = drive->driver_data;
        int cnt;
@@ -3053,37 +2184,37 @@ static void idetape_discard_read_pipeline (ide_drive_t *drive, int restore_posit
                position = idetape_read_position(drive);
                seek = position > cnt ? position - cnt : 0;
                if (idetape_position_tape(drive, seek, 0, 0)) {
-                       printk(KERN_INFO "ide-tape: %s: position_tape failed in discard_pipeline()\n", tape->name);
+                       printk(KERN_INFO "ide-tape: %s: position_tape failed in"
+                                        " discard_pipeline()\n", tape->name);
                        return;
                }
        }
 }
 
 /*
- * idetape_queue_rw_tail generates a read/write request for the block
- * device interface and wait for it to be serviced.
+ * Generate a read/write request for the block device interface and wait for it
+ * to be serviced.
  */
-static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, struct idetape_bh *bh)
+static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
+                                struct idetape_bh *bh)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct request rq;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 2)
-               printk(KERN_INFO "ide-tape: idetape_queue_rw_tail: cmd=%d\n",cmd);
-#endif /* IDETAPE_DEBUG_LOG */
-#if IDETAPE_DEBUG_BUGS
+       debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
+
        if (idetape_pipeline_active(tape)) {
-               printk(KERN_ERR "ide-tape: bug: the pipeline is active in idetape_queue_rw_tail\n");
+               printk(KERN_ERR "ide-tape: bug: the pipeline is active in %s\n",
+                               __func__);
                return (0);
        }
-#endif /* IDETAPE_DEBUG_BUGS */        
 
        idetape_init_rq(&rq, cmd);
        rq.rq_disk = tape->disk;
        rq.special = (void *)bh;
-       rq.sector = tape->first_frame_position;
-       rq.nr_sectors = rq.current_nr_sectors = blocks;
+       rq.sector = tape->first_frame;
+       rq.nr_sectors           = blocks;
+       rq.current_nr_sectors   = blocks;
        (void) ide_do_drive_cmd(drive, &rq, ide_wait);
 
        if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0)
@@ -3093,14 +2224,11 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, struct
                idetape_init_merge_stage(tape);
        if (rq.errors == IDETAPE_ERROR_GENERAL)
                return -EIO;
-       return (tape->tape_block_size * (blocks-rq.current_nr_sectors));
+       return (tape->blk_size * (blocks-rq.current_nr_sectors));
 }
 
-/*
- *     idetape_insert_pipeline_into_queue is used to start servicing the
- *     pipeline stages, starting from tape->next_stage.
- */
-static void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
+/* start servicing the pipeline stages, starting from tape->next_stage. */
+static void idetape_plug_pipeline(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
@@ -3108,142 +2236,128 @@ static void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
                return;
        if (!idetape_pipeline_active(tape)) {
                set_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
-               idetape_active_next_stage(drive);
-               (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end);
+               idetape_activate_next_stage(drive);
+               (void) ide_do_drive_cmd(drive, tape->active_data_rq, ide_end);
        }
 }
 
-static void idetape_create_inquiry_cmd (idetape_pc_t *pc)
+static void idetape_create_inquiry_cmd(idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_INQUIRY_CMD;
-       pc->c[4] = pc->request_transfer = 254;
+       pc->c[0] = INQUIRY;
+       pc->c[4] = 254;
+       pc->request_transfer = 254;
        pc->callback = &idetape_pc_callback;
 }
 
-static void idetape_create_rewind_cmd (ide_drive_t *drive, idetape_pc_t *pc)
+static void idetape_create_rewind_cmd(ide_drive_t *drive, idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_REWIND_CMD;
+       pc->c[0] = REZERO_UNIT;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
 }
 
-#if 0
-static void idetape_create_mode_select_cmd (idetape_pc_t *pc, int length)
+static void idetape_create_erase_cmd(idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       set_bit(PC_WRITING, &pc->flags);
-       pc->c[0] = IDETAPE_MODE_SELECT_CMD;
-       pc->c[1] = 0x10;
-       put_unaligned(htons(length), (unsigned short *) &pc->c[3]);
-       pc->request_transfer = 255;
-       pc->callback = &idetape_pc_callback;
-}
-#endif
-
-static void idetape_create_erase_cmd (idetape_pc_t *pc)
-{
-       idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_ERASE_CMD;
+       pc->c[0] = ERASE;
        pc->c[1] = 1;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
 }
 
-static void idetape_create_space_cmd (idetape_pc_t *pc,int count, u8 cmd)
+static void idetape_create_space_cmd(idetape_pc_t *pc, int count, u8 cmd)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_SPACE_CMD;
-       put_unaligned(htonl(count), (unsigned int *) &pc->c[1]);
+       pc->c[0] = SPACE;
+       put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
        pc->c[1] = cmd;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
 }
 
-static void idetape_wait_first_stage (ide_drive_t *drive)
+static void idetape_wait_first_stage(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        unsigned long flags;
 
        if (tape->first_stage == NULL)
                return;
-       spin_lock_irqsave(&tape->spinlock, flags);
+       spin_lock_irqsave(&tape->lock, flags);
        if (tape->active_stage == tape->first_stage)
-               idetape_wait_for_request(drive, tape->active_data_request);
-       spin_unlock_irqrestore(&tape->spinlock, flags);
+               idetape_wait_for_request(drive, tape->active_data_rq);
+       spin_unlock_irqrestore(&tape->lock, flags);
 }
 
 /*
- *     idetape_add_chrdev_write_request tries to add a character device
- *     originated write request to our pipeline. In case we don't succeed,
- *     we revert to non-pipelined operation mode for this request.
+ * Try to add a character device originated write request to our pipeline. In
+ * case we don't succeed, we revert to non-pipelined operation mode for this
+ * request. In order to accomplish that, we
  *
- *     1.      Try to allocate a new pipeline stage.
- *     2.      If we can't, wait for more and more requests to be serviced
- *             and try again each time.
- *     3.      If we still can't allocate a stage, fallback to
- *             non-pipelined operation mode for this request.
+ * 1. Try to allocate a new pipeline stage.
+ * 2. If we can't, wait for more and more requests to be serviced and try again
+ * each time.
+ * 3. If we still can't allocate a stage, fallback to non-pipelined operation
+ * mode for this request.
  */
-static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks)
+static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_stage_t *new_stage;
        unsigned long flags;
        struct request *rq;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 3)
-               printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_write_request\n");
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
 
-       /*
-        *      Attempt to allocate a new stage.
-        *      Pay special attention to possible race conditions.
-        */
+       /* Attempt to allocate a new stage. Beware possible race conditions. */
        while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) {
-               spin_lock_irqsave(&tape->spinlock, flags);
+               spin_lock_irqsave(&tape->lock, flags);
                if (idetape_pipeline_active(tape)) {
-                       idetape_wait_for_request(drive, tape->active_data_request);
-                       spin_unlock_irqrestore(&tape->spinlock, flags);
+                       idetape_wait_for_request(drive, tape->active_data_rq);
+                       spin_unlock_irqrestore(&tape->lock, flags);
                } else {
-                       spin_unlock_irqrestore(&tape->spinlock, flags);
-                       idetape_insert_pipeline_into_queue(drive);
+                       spin_unlock_irqrestore(&tape->lock, flags);
+                       idetape_plug_pipeline(drive);
                        if (idetape_pipeline_active(tape))
                                continue;
                        /*
-                        *      Linux is short on memory. Fallback to
-                        *      non-pipelined operation mode for this request.
+                        * The machine is short on memory. Fallback to non-
+                        * pipelined operation mode for this request.
                         */
-                       return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh);
+                       return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
+                                               blocks, tape->merge_stage->bh);
                }
        }
        rq = &new_stage->rq;
        idetape_init_rq(rq, REQ_IDETAPE_WRITE);
        /* Doesn't actually matter - We always assume sequential access */
-       rq->sector = tape->first_frame_position;
-       rq->nr_sectors = rq->current_nr_sectors = blocks;
+       rq->sector = tape->first_frame;
+       rq->current_nr_sectors = blocks;
+       rq->nr_sectors = blocks;
 
        idetape_switch_buffers(tape, new_stage);
        idetape_add_stage_tail(drive, new_stage);
        tape->pipeline_head++;
-       calculate_speeds(drive);
+       idetape_calculate_speeds(drive);
 
        /*
-        *      Estimate whether the tape has stopped writing by checking
-        *      if our write pipeline is currently empty. If we are not
-        *      writing anymore, wait for the pipeline to be full enough
-        *      (90%) before starting to service requests, so that we will
-        *      be able to keep up with the higher speeds of the tape.
+        * Estimate whether the tape has stopped writing by checking if our
+        * write pipeline is currently empty. If we are not writing anymore,
+        * wait for the pipeline to be almost completely full (90%) before
+        * starting to service requests, so that we will be able to keep up with
+        * the higher speeds of the tape.
         */
        if (!idetape_pipeline_active(tape)) {
                if (tape->nr_stages >= tape->max_stages * 9 / 10 ||
-                   tape->nr_stages >= tape->max_stages - tape->uncontrolled_pipeline_head_speed * 3 * 1024 / tape->tape_block_size) {
+                       tape->nr_stages >= tape->max_stages -
+                       tape->uncontrolled_pipeline_head_speed * 3 * 1024 /
+                       tape->blk_size) {
                        tape->measure_insert_time = 1;
                        tape->insert_time = jiffies;
                        tape->insert_size = 0;
                        tape->insert_speed = 0;
-                       idetape_insert_pipeline_into_queue(drive);
+                       idetape_plug_pipeline(drive);
                }
        }
        if (test_and_clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags))
@@ -3253,46 +2367,46 @@ static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks)
 }
 
 /*
- *     idetape_wait_for_pipeline will wait until all pending pipeline
- *     requests are serviced. Typically called on device close.
+ * Wait until all pending pipeline requests are serviced. Typically called on
+ * device close.
  */
-static void idetape_wait_for_pipeline (ide_drive_t *drive)
+static void idetape_wait_for_pipeline(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        unsigned long flags;
 
        while (tape->next_stage || idetape_pipeline_active(tape)) {
-               idetape_insert_pipeline_into_queue(drive);
-               spin_lock_irqsave(&tape->spinlock, flags);
+               idetape_plug_pipeline(drive);
+               spin_lock_irqsave(&tape->lock, flags);
                if (idetape_pipeline_active(tape))
-                       idetape_wait_for_request(drive, tape->active_data_request);
-               spin_unlock_irqrestore(&tape->spinlock, flags);
+                       idetape_wait_for_request(drive, tape->active_data_rq);
+               spin_unlock_irqrestore(&tape->lock, flags);
        }
 }
 
-static void idetape_empty_write_pipeline (ide_drive_t *drive)
+static void idetape_empty_write_pipeline(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        int blocks, min;
        struct idetape_bh *bh;
-       
-#if IDETAPE_DEBUG_BUGS
-       if (tape->chrdev_direction != idetape_direction_write) {
-               printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline, but we are not writing.\n");
+
+       if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
+               printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline,"
+                               " but we are not writing.\n");
                return;
        }
        if (tape->merge_stage_size > tape->stage_size) {
                printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n");
                tape->merge_stage_size = tape->stage_size;
        }
-#endif /* IDETAPE_DEBUG_BUGS */
        if (tape->merge_stage_size) {
-               blocks = tape->merge_stage_size / tape->tape_block_size;
-               if (tape->merge_stage_size % tape->tape_block_size) {
+               blocks = tape->merge_stage_size / tape->blk_size;
+               if (tape->merge_stage_size % tape->blk_size) {
                        unsigned int i;
 
                        blocks++;
-                       i = tape->tape_block_size - tape->merge_stage_size % tape->tape_block_size;
+                       i = tape->blk_size - tape->merge_stage_size %
+                               tape->blk_size;
                        bh = tape->bh->b_reqnext;
                        while (bh) {
                                atomic_set(&bh->b_count, 0);
@@ -3301,12 +2415,14 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive)
                        bh = tape->bh;
                        while (i) {
                                if (bh == NULL) {
-
-                                       printk(KERN_INFO "ide-tape: bug, bh NULL\n");
+                                       printk(KERN_INFO "ide-tape: bug,"
+                                                        " bh NULL\n");
                                        break;
                                }
-                               min = min(i, (unsigned int)(bh->b_size - atomic_read(&bh->b_count)));
-                               memset(bh->b_data + atomic_read(&bh->b_count), 0, min);
+                               min = min(i, (unsigned int)(bh->b_size -
+                                               atomic_read(&bh->b_count)));
+                               memset(bh->b_data + atomic_read(&bh->b_count),
+                                               0, min);
                                atomic_add(min, &bh->b_count);
                                i -= min;
                                bh = bh->b_reqnext;
@@ -3321,16 +2437,15 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive)
                tape->merge_stage = NULL;
        }
        clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
-       tape->chrdev_direction = idetape_direction_none;
+       tape->chrdev_dir = IDETAPE_DIR_NONE;
 
        /*
-        *      On the next backup, perform the feedback loop again.
-        *      (I don't want to keep sense information between backups,
-        *       as some systems are constantly on, and the system load
-        *       can be totally different on the next backup).
+        * On the next backup, perform the feedback loop again. (I don't want to
+        * keep sense information between backups, as some systems are
+        * constantly on, and the system load can be totally different on the
+        * next backup).
         */
        tape->max_stages = tape->min_pipeline;
-#if IDETAPE_DEBUG_BUGS
        if (tape->first_stage != NULL ||
            tape->next_stage != NULL ||
            tape->last_stage != NULL ||
@@ -3341,60 +2456,64 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive)
                        tape->first_stage, tape->next_stage,
                        tape->last_stage, tape->nr_stages);
        }
-#endif /* IDETAPE_DEBUG_BUGS */
 }
 
-static void idetape_restart_speed_control (ide_drive_t *drive)
+static void idetape_restart_speed_control(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
        tape->restart_speed_control_req = 0;
        tape->pipeline_head = 0;
-       tape->controlled_last_pipeline_head = tape->uncontrolled_last_pipeline_head = 0;
-       tape->controlled_previous_pipeline_head = tape->uncontrolled_previous_pipeline_head = 0;
-       tape->pipeline_head_speed = tape->controlled_pipeline_head_speed = 5000;
+       tape->controlled_last_pipeline_head = 0;
+       tape->controlled_previous_pipeline_head = 0;
+       tape->uncontrolled_previous_pipeline_head = 0;
+       tape->controlled_pipeline_head_speed = 5000;
+       tape->pipeline_head_speed = 5000;
        tape->uncontrolled_pipeline_head_speed = 0;
-       tape->controlled_pipeline_head_time = tape->uncontrolled_pipeline_head_time = jiffies;
-       tape->controlled_previous_head_time = tape->uncontrolled_previous_head_time = jiffies;
+       tape->controlled_pipeline_head_time =
+               tape->uncontrolled_pipeline_head_time = jiffies;
+       tape->controlled_previous_head_time =
+               tape->uncontrolled_previous_head_time = jiffies;
 }
 
-static int idetape_initiate_read (ide_drive_t *drive, int max_stages)
+static int idetape_init_read(ide_drive_t *drive, int max_stages)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_stage_t *new_stage;
        struct request rq;
        int bytes_read;
-       int blocks = tape->capabilities.ctl;
+       u16 blocks = *(u16 *)&tape->caps[12];
 
        /* Initialize read operation */
-       if (tape->chrdev_direction != idetape_direction_read) {
-               if (tape->chrdev_direction == idetape_direction_write) {
+       if (tape->chrdev_dir != IDETAPE_DIR_READ) {
+               if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
                        idetape_empty_write_pipeline(drive);
                        idetape_flush_tape_buffers(drive);
                }
-#if IDETAPE_DEBUG_BUGS
                if (tape->merge_stage || tape->merge_stage_size) {
-                       printk (KERN_ERR "ide-tape: merge_stage_size should be 0 now\n");
+                       printk(KERN_ERR "ide-tape: merge_stage_size should be"
+                                        " 0 now\n");
                        tape->merge_stage_size = 0;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
-               if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL)
+               tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0);
+               if (!tape->merge_stage)
                        return -ENOMEM;
-               tape->chrdev_direction = idetape_direction_read;
+               tape->chrdev_dir = IDETAPE_DIR_READ;
 
                /*
-                *      Issue a read 0 command to ensure that DSC handshake
-                *      is switched from completion mode to buffer available
-                *      mode.
-                *      No point in issuing this if DSC overlap isn't supported,
-                *      some drives (Seagate STT3401A) will return an error.
+                * Issue a read 0 command to ensure that DSC handshake is
+                * switched from completion mode to buffer available mode.
+                * No point in issuing this if DSC overlap isn't supported, some
+                * drives (Seagate STT3401A) will return an error.
                 */
                if (drive->dsc_overlap) {
-                       bytes_read = idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, 0, tape->merge_stage->bh);
+                       bytes_read = idetape_queue_rw_tail(drive,
+                                                       REQ_IDETAPE_READ, 0,
+                                                       tape->merge_stage->bh);
                        if (bytes_read < 0) {
                                __idetape_kfree_stage(tape->merge_stage);
                                tape->merge_stage = NULL;
-                               tape->chrdev_direction = idetape_direction_none;
+                               tape->chrdev_dir = IDETAPE_DIR_NONE;
                                return bytes_read;
                        }
                }
@@ -3402,8 +2521,9 @@ static int idetape_initiate_read (ide_drive_t *drive, int max_stages)
        if (tape->restart_speed_control_req)
                idetape_restart_speed_control(drive);
        idetape_init_rq(&rq, REQ_IDETAPE_READ);
-       rq.sector = tape->first_frame_position;
-       rq.nr_sectors = rq.current_nr_sectors = blocks;
+       rq.sector = tape->first_frame;
+       rq.nr_sectors = blocks;
+       rq.current_nr_sectors = blocks;
        if (!test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags) &&
            tape->nr_stages < max_stages) {
                new_stage = idetape_kmalloc_stage(tape);
@@ -3421,50 +2541,43 @@ static int idetape_initiate_read (ide_drive_t *drive, int max_stages)
                        tape->insert_time = jiffies;
                        tape->insert_size = 0;
                        tape->insert_speed = 0;
-                       idetape_insert_pipeline_into_queue(drive);
+                       idetape_plug_pipeline(drive);
                }
        }
        return 0;
 }
 
 /*
- *     idetape_add_chrdev_read_request is called from idetape_chrdev_read
- *     to service a character device read request and add read-ahead
- *     requests to our pipeline.
+ * Called from idetape_chrdev_read() to service a character device read request
+ * and add read-ahead requests to our pipeline.
  */
-static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks)
+static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks)
 {
        idetape_tape_t *tape = drive->driver_data;
        unsigned long flags;
        struct request *rq_ptr;
        int bytes_read;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_read_request, %d blocks\n", blocks);
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks);
 
-       /*
-        * If we are at a filemark, return a read length of 0
-        */
+       /* If we are at a filemark, return a read length of 0 */
        if (test_bit(IDETAPE_FILEMARK, &tape->flags))
                return 0;
 
-       /*
-        * Wait for the next block to be available at the head
-        * of the pipeline
-        */
-       idetape_initiate_read(drive, tape->max_stages);
+       /* Wait for the next block to reach the head of the pipeline. */
+       idetape_init_read(drive, tape->max_stages);
        if (tape->first_stage == NULL) {
                if (test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags))
                        return 0;
-               return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, tape->merge_stage->bh);
+               return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks,
+                                       tape->merge_stage->bh);
        }
        idetape_wait_first_stage(drive);
        rq_ptr = &tape->first_stage->rq;
-       bytes_read = tape->tape_block_size * (rq_ptr->nr_sectors - rq_ptr->current_nr_sectors);
-       rq_ptr->nr_sectors = rq_ptr->current_nr_sectors = 0;
-
+       bytes_read = tape->blk_size * (rq_ptr->nr_sectors -
+                                       rq_ptr->current_nr_sectors);
+       rq_ptr->nr_sectors = 0;
+       rq_ptr->current_nr_sectors = 0;
 
        if (rq_ptr->errors == IDETAPE_ERROR_EOD)
                return 0;
@@ -3472,45 +2585,46 @@ static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks)
                idetape_switch_buffers(tape, tape->first_stage);
                if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK)
                        set_bit(IDETAPE_FILEMARK, &tape->flags);
-               spin_lock_irqsave(&tape->spinlock, flags);
+               spin_lock_irqsave(&tape->lock, flags);
                idetape_remove_stage_head(drive);
-               spin_unlock_irqrestore(&tape->spinlock, flags);
+               spin_unlock_irqrestore(&tape->lock, flags);
                tape->pipeline_head++;
-               calculate_speeds(drive);
+               idetape_calculate_speeds(drive);
        }
-#if IDETAPE_DEBUG_BUGS
-       if (bytes_read > blocks * tape->tape_block_size) {
-               printk(KERN_ERR "ide-tape: bug: trying to return more bytes than requested\n");
-               bytes_read = blocks * tape->tape_block_size;
+       if (bytes_read > blocks * tape->blk_size) {
+               printk(KERN_ERR "ide-tape: bug: trying to return more bytes"
+                               " than requested\n");
+               bytes_read = blocks * tape->blk_size;
        }
-#endif /* IDETAPE_DEBUG_BUGS */
        return (bytes_read);
 }
 
-static void idetape_pad_zeros (ide_drive_t *drive, int bcount)
+static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct idetape_bh *bh;
        int blocks;
-       
+
        while (bcount) {
                unsigned int count;
 
                bh = tape->merge_stage->bh;
                count = min(tape->stage_size, bcount);
                bcount -= count;
-               blocks = count / tape->tape_block_size;
+               blocks = count / tape->blk_size;
                while (count) {
-                       atomic_set(&bh->b_count, min(count, (unsigned int)bh->b_size));
+                       atomic_set(&bh->b_count,
+                                  min(count, (unsigned int)bh->b_size));
                        memset(bh->b_data, 0, atomic_read(&bh->b_count));
                        count -= atomic_read(&bh->b_count);
                        bh = bh->b_reqnext;
                }
-               idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh);
+               idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks,
+                                     tape->merge_stage->bh);
        }
 }
 
-static int idetape_pipeline_size (ide_drive_t *drive)
+static int idetape_pipeline_size(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_stage_t *stage;
@@ -3521,9 +2635,10 @@ static int idetape_pipeline_size (ide_drive_t *drive)
        stage = tape->first_stage;
        while (stage != NULL) {
                rq = &stage->rq;
-               size += tape->tape_block_size * (rq->nr_sectors-rq->current_nr_sectors);
+               size += tape->blk_size * (rq->nr_sectors -
+                               rq->current_nr_sectors);
                if (rq->errors == IDETAPE_ERROR_FILEMARK)
-                       size += tape->tape_block_size;
+                       size += tape->blk_size;
                stage = stage->next;
        }
        size += tape->merge_stage_size;
@@ -3531,20 +2646,18 @@ static int idetape_pipeline_size (ide_drive_t *drive)
 }
 
 /*
- *     Rewinds the tape to the Beginning Of the current Partition (BOP).
- *
- *     We currently support only one partition.
- */ 
-static int idetape_rewind_tape (ide_drive_t *drive)
+ * Rewinds the tape to the Beginning Of the current Partition (BOP). We
+ * currently support only one partition.
+ */
+static int idetape_rewind_tape(ide_drive_t *drive)
 {
        int retval;
        idetape_pc_t pc;
-#if IDETAPE_DEBUG_LOG
-       idetape_tape_t *tape = drive->driver_data;
-       if (tape->debug_level >= 2)
-               printk(KERN_INFO "ide-tape: Reached idetape_rewind_tape\n");
-#endif /* IDETAPE_DEBUG_LOG */ 
-       
+       idetape_tape_t *tape;
+       tape = drive->driver_data;
+
+       debug_log(DBG_SENSE, "Enter %s\n", __func__);
+
        idetape_create_rewind_cmd(drive, &pc);
        retval = idetape_queue_pc_tail(drive, &pc);
        if (retval)
@@ -3557,71 +2670,66 @@ static int idetape_rewind_tape (ide_drive_t *drive)
        return 0;
 }
 
-/*
- *     Our special ide-tape ioctl's.
- *
- *     Currently there aren't any ioctl's.
- *     mtio.h compatible commands should be issued to the character device
- *     interface.
- */
-static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned long arg)
+/* mtio.h compatible commands should be issued to the chrdev interface. */
+static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
+                               unsigned long arg)
 {
        idetape_tape_t *tape = drive->driver_data;
-       idetape_config_t config;
        void __user *argp = (void __user *)arg;
 
-#if IDETAPE_DEBUG_LOG  
-       if (tape->debug_level >= 4)
-               printk(KERN_INFO "ide-tape: Reached idetape_blkdev_ioctl\n");
-#endif /* IDETAPE_DEBUG_LOG */
+       struct idetape_config {
+               int dsc_rw_frequency;
+               int dsc_media_access_frequency;
+               int nr_stages;
+       } config;
+
+       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+
        switch (cmd) {
-               case 0x0340:
-                       if (copy_from_user(&config, argp, sizeof (idetape_config_t)))
-                               return -EFAULT;
-                       tape->best_dsc_rw_frequency = config.dsc_rw_frequency;
-                       tape->max_stages = config.nr_stages;
-                       break;
-               case 0x0350:
-                       config.dsc_rw_frequency = (int) tape->best_dsc_rw_frequency;
-                       config.nr_stages = tape->max_stages; 
-                       if (copy_to_user(argp, &config, sizeof (idetape_config_t)))
-                               return -EFAULT;
-                       break;
-               default:
-                       return -EIO;
+       case 0x0340:
+               if (copy_from_user(&config, argp, sizeof(config)))
+                       return -EFAULT;
+               tape->best_dsc_rw_freq = config.dsc_rw_frequency;
+               tape->max_stages = config.nr_stages;
+               break;
+       case 0x0350:
+               config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
+               config.nr_stages = tape->max_stages;
+               if (copy_to_user(argp, &config, sizeof(config)))
+                       return -EFAULT;
+               break;
+       default:
+               return -EIO;
        }
        return 0;
 }
 
 /*
- *     idetape_space_over_filemarks is now a bit more complicated than just
- *     passing the command to the tape since we may have crossed some
- *     filemarks during our pipelined read-ahead mode.
- *
- *     As a minor side effect, the pipeline enables us to support MTFSFM when
- *     the filemark is in our internal pipeline even if the tape doesn't
- *     support spacing over filemarks in the reverse direction.
+ * The function below is now a bit more complicated than just passing the
+ * command to the tape since we may have crossed some filemarks during our
+ * pipelined read-ahead mode. As a minor side effect, the pipeline enables us to
+ * support MTFSFM when the filemark is in our internal pipeline even if the tape
+ * doesn't support spacing over filemarks in the reverse direction.
  */
-static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_count)
+static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
+                                       int mt_count)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t pc;
        unsigned long flags;
-       int retval,count=0;
+       int retval, count = 0;
+       int sprev = !!(tape->caps[4] & 0x20);
 
        if (mt_count == 0)
                return 0;
        if (MTBSF == mt_op || MTBSFM == mt_op) {
-               if (!tape->capabilities.sprev)
+               if (!sprev)
                        return -EIO;
-               mt_count = - mt_count;
+               mt_count = -mt_count;
        }
 
-       if (tape->chrdev_direction == idetape_direction_read) {
-               /*
-                *      We have a read-ahead buffer. Scan it for crossed
-                *      filemarks.
-                */
+       if (tape->chrdev_dir == IDETAPE_DIR_READ) {
+               /* its a read-ahead buffer, scan it for crossed filemarks. */
                tape->merge_stage_size = 0;
                if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags))
                        ++count;
@@ -3631,24 +2739,27 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c
                                        set_bit(IDETAPE_FILEMARK, &tape->flags);
                                return 0;
                        }
-                       spin_lock_irqsave(&tape->spinlock, flags);
+                       spin_lock_irqsave(&tape->lock, flags);
                        if (tape->first_stage == tape->active_stage) {
                                /*
-                                *      We have reached the active stage in the read pipeline.
-                                *      There is no point in allowing the drive to continue
-                                *      reading any farther, so we stop the pipeline.
+                                * We have reached the active stage in the read
+                                * pipeline. There is no point in allowing the
+                                * drive to continue reading any farther, so we
+                                * stop the pipeline.
                                 *
-                                *      This section should be moved to a separate subroutine,
-                                *      because a similar function is performed in
-                                *      __idetape_discard_read_pipeline(), for example.
+                                * This section should be moved to a separate
+                                * subroutine because similar operations are
+                                * done in __idetape_discard_read_pipeline(),
+                                * for example.
                                 */
                                tape->next_stage = NULL;
-                               spin_unlock_irqrestore(&tape->spinlock, flags);
+                               spin_unlock_irqrestore(&tape->lock, flags);
                                idetape_wait_first_stage(drive);
                                tape->next_stage = tape->first_stage->next;
                        } else
-                               spin_unlock_irqrestore(&tape->spinlock, flags);
-                       if (tape->first_stage->rq.errors == IDETAPE_ERROR_FILEMARK)
+                               spin_unlock_irqrestore(&tape->lock, flags);
+                       if (tape->first_stage->rq.errors ==
+                                       IDETAPE_ERROR_FILEMARK)
                                ++count;
                        idetape_remove_stage_head(drive);
                }
@@ -3656,157 +2767,156 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c
        }
 
        /*
-        *      The filemark was not found in our internal pipeline.
-        *      Now we can issue the space command.
+        * The filemark was not found in our internal pipeline; now we can issue
+        * the space command.
         */
        switch (mt_op) {
-               case MTFSF:
-               case MTBSF:
-                       idetape_create_space_cmd(&pc,mt_count-count,IDETAPE_SPACE_OVER_FILEMARK);
-                       return (idetape_queue_pc_tail(drive, &pc));
-               case MTFSFM:
-               case MTBSFM:
-                       if (!tape->capabilities.sprev)
-                               return (-EIO);
-                       retval = idetape_space_over_filemarks(drive, MTFSF, mt_count-count);
-                       if (retval) return (retval);
-                       count = (MTBSFM == mt_op ? 1 : -1);
-                       return (idetape_space_over_filemarks(drive, MTFSF, count));
-               default:
-                       printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",mt_op);
-                       return (-EIO);
+       case MTFSF:
+       case MTBSF:
+               idetape_create_space_cmd(&pc, mt_count - count,
+                                        IDETAPE_SPACE_OVER_FILEMARK);
+               return idetape_queue_pc_tail(drive, &pc);
+       case MTFSFM:
+       case MTBSFM:
+               if (!sprev)
+                       return -EIO;
+               retval = idetape_space_over_filemarks(drive, MTFSF,
+                                                     mt_count - count);
+               if (retval)
+                       return retval;
+               count = (MTBSFM == mt_op ? 1 : -1);
+               return idetape_space_over_filemarks(drive, MTFSF, count);
+       default:
+               printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
+                               mt_op);
+               return -EIO;
        }
 }
 
-
 /*
- *     Our character device read / write functions.
+ * Our character device read / write functions.
  *
- *     The tape is optimized to maximize throughput when it is transferring
- *     an integral number of the "continuous transfer limit", which is
- *     a parameter of the specific tape (26 KB on my particular tape).
- *      (32 kB for Onstream)
+ * The tape is optimized to maximize throughput when it is transferring an
+ * integral number of the "continuous transfer limit", which is a parameter of
+ * the specific tape (26kB on my particular tape, 32kB for Onstream).
  *
- *     As of version 1.3 of the driver, the character device provides an
- *     abstract continuous view of the media - any mix of block sizes (even 1
- *     byte) on the same backup/restore procedure is supported. The driver
- *     will internally convert the requests to the recommended transfer unit,
- *     so that an unmatch between the user's block size to the recommended
- *     size will only result in a (slightly) increased driver overhead, but
- *     will no longer hit performance.
- *      This is not applicable to Onstream.
+ * As of version 1.3 of the driver, the character device provides an abstract
+ * continuous view of the media - any mix of block sizes (even 1 byte) on the
+ * same backup/restore procedure is supported. The driver will internally
+ * convert the requests to the recommended transfer unit, so that an unmatch
+ * between the user's block size to the recommended size will only result in a
+ * (slightly) increased driver overhead, but will no longer hit performance.
+ * This is not applicable to Onstream.
  */
-static ssize_t idetape_chrdev_read (struct file *file, char __user *buf,
-                                   size_t count, loff_t *ppos)
+static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
+                                  size_t count, loff_t *ppos)
 {
        struct ide_tape_obj *tape = ide_tape_f(file);
        ide_drive_t *drive = tape->drive;
-       ssize_t bytes_read,temp, actually_read = 0, rc;
+       ssize_t bytes_read, temp, actually_read = 0, rc;
        ssize_t ret = 0;
+       u16 ctl = *(u16 *)&tape->caps[12];
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 3)
-               printk(KERN_INFO "ide-tape: Reached idetape_chrdev_read, count %Zd\n", count);
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
 
-       if (tape->chrdev_direction != idetape_direction_read) {
+       if (tape->chrdev_dir != IDETAPE_DIR_READ) {
                if (test_bit(IDETAPE_DETECT_BS, &tape->flags))
-                       if (count > tape->tape_block_size &&
-                           (count % tape->tape_block_size) == 0)
-                               tape->user_bs_factor = count / tape->tape_block_size;
+                       if (count > tape->blk_size &&
+                           (count % tape->blk_size) == 0)
+                               tape->user_bs_factor = count / tape->blk_size;
        }
-       if ((rc = idetape_initiate_read(drive, tape->max_stages)) < 0)
+       rc = idetape_init_read(drive, tape->max_stages);
+       if (rc < 0)
                return rc;
        if (count == 0)
                return (0);
        if (tape->merge_stage_size) {
-               actually_read = min((unsigned int)(tape->merge_stage_size), (unsigned int)count);
-               if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, actually_read))
+               actually_read = min((unsigned int)(tape->merge_stage_size),
+                                   (unsigned int)count);
+               if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage,
+                                              actually_read))
                        ret = -EFAULT;
                buf += actually_read;
                tape->merge_stage_size -= actually_read;
                count -= actually_read;
        }
        while (count >= tape->stage_size) {
-               bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl);
+               bytes_read = idetape_add_chrdev_read_request(drive, ctl);
                if (bytes_read <= 0)
                        goto finish;
-               if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, bytes_read))
+               if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage,
+                                              bytes_read))
                        ret = -EFAULT;
                buf += bytes_read;
                count -= bytes_read;
                actually_read += bytes_read;
        }
        if (count) {
-               bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl);
+               bytes_read = idetape_add_chrdev_read_request(drive, ctl);
                if (bytes_read <= 0)
                        goto finish;
                temp = min((unsigned long)count, (unsigned long)bytes_read);
-               if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, temp))
+               if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage,
+                                              temp))
                        ret = -EFAULT;
                actually_read += temp;
                tape->merge_stage_size = bytes_read-temp;
        }
 finish:
        if (!actually_read && test_bit(IDETAPE_FILEMARK, &tape->flags)) {
-#if IDETAPE_DEBUG_LOG
-               if (tape->debug_level >= 2)
-                       printk(KERN_INFO "ide-tape: %s: spacing over filemark\n", tape->name);
-#endif
+               debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
+
                idetape_space_over_filemarks(drive, MTFSF, 1);
                return 0;
        }
 
-       return (ret) ? ret : actually_read;
+       return ret ? ret : actually_read;
 }
 
-static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
+static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
                                     size_t count, loff_t *ppos)
 {
        struct ide_tape_obj *tape = ide_tape_f(file);
        ide_drive_t *drive = tape->drive;
        ssize_t actually_written = 0;
        ssize_t ret = 0;
+       u16 ctl = *(u16 *)&tape->caps[12];
 
        /* The drive is write protected. */
        if (tape->write_prot)
                return -EACCES;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 3)
-               printk(KERN_INFO "ide-tape: Reached idetape_chrdev_write, "
-                       "count %Zd\n", count);
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
 
        /* Initialize write operation */
-       if (tape->chrdev_direction != idetape_direction_write) {
-               if (tape->chrdev_direction == idetape_direction_read)
+       if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
+               if (tape->chrdev_dir == IDETAPE_DIR_READ)
                        idetape_discard_read_pipeline(drive, 1);
-#if IDETAPE_DEBUG_BUGS
                if (tape->merge_stage || tape->merge_stage_size) {
                        printk(KERN_ERR "ide-tape: merge_stage_size "
                                "should be 0 now\n");
                        tape->merge_stage_size = 0;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
-               if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL)
+               tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0);
+               if (!tape->merge_stage)
                        return -ENOMEM;
-               tape->chrdev_direction = idetape_direction_write;
+               tape->chrdev_dir = IDETAPE_DIR_WRITE;
                idetape_init_merge_stage(tape);
 
                /*
-                *      Issue a write 0 command to ensure that DSC handshake
-                *      is switched from completion mode to buffer available
-                *      mode.
-                *      No point in issuing this if DSC overlap isn't supported,
-                *      some drives (Seagate STT3401A) will return an error.
+                * Issue a write 0 command to ensure that DSC handshake is
+                * switched from completion mode to buffer available mode. No
+                * point in issuing this if DSC overlap isn't supported, some
+                * drives (Seagate STT3401A) will return an error.
                 */
                if (drive->dsc_overlap) {
-                       ssize_t retval = idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, 0, tape->merge_stage->bh);
+                       ssize_t retval = idetape_queue_rw_tail(drive,
+                                                       REQ_IDETAPE_WRITE, 0,
+                                                       tape->merge_stage->bh);
                        if (retval < 0) {
                                __idetape_kfree_stage(tape->merge_stage);
                                tape->merge_stage = NULL;
-                               tape->chrdev_direction = idetape_direction_none;
+                               tape->chrdev_dir = IDETAPE_DIR_NONE;
                                return retval;
                        }
                }
@@ -3816,14 +2926,15 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
        if (tape->restart_speed_control_req)
                idetape_restart_speed_control(drive);
        if (tape->merge_stage_size) {
-#if IDETAPE_DEBUG_BUGS
                if (tape->merge_stage_size >= tape->stage_size) {
-                       printk(KERN_ERR "ide-tape: bug: merge buffer too big\n");
+                       printk(KERN_ERR "ide-tape: bug: merge buf too big\n");
                        tape->merge_stage_size = 0;
                }
-#endif /* IDETAPE_DEBUG_BUGS */
-               actually_written = min((unsigned int)(tape->stage_size - tape->merge_stage_size), (unsigned int)count);
-               if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, actually_written))
+               actually_written = min((unsigned int)
+                               (tape->stage_size - tape->merge_stage_size),
+                               (unsigned int)count);
+               if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf,
+                                                actually_written))
                                ret = -EFAULT;
                buf += actually_written;
                tape->merge_stage_size += actually_written;
@@ -3832,32 +2943,34 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
                if (tape->merge_stage_size == tape->stage_size) {
                        ssize_t retval;
                        tape->merge_stage_size = 0;
-                       retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl);
+                       retval = idetape_add_chrdev_write_request(drive, ctl);
                        if (retval <= 0)
                                return (retval);
                }
        }
        while (count >= tape->stage_size) {
                ssize_t retval;
-               if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, tape->stage_size))
+               if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf,
+                                                tape->stage_size))
                        ret = -EFAULT;
                buf += tape->stage_size;
                count -= tape->stage_size;
-               retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl);
+               retval = idetape_add_chrdev_write_request(drive, ctl);
                actually_written += tape->stage_size;
                if (retval <= 0)
                        return (retval);
        }
        if (count) {
                actually_written += count;
-               if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, count))
+               if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf,
+                                                count))
                        ret = -EFAULT;
                tape->merge_stage_size += count;
        }
-       return (ret) ? ret : actually_written;
+       return ret ? ret : actually_written;
 }
 
-static int idetape_write_filemark (ide_drive_t *drive)
+static int idetape_write_filemark(ide_drive_t *drive)
 {
        idetape_pc_t pc;
 
@@ -3871,265 +2984,224 @@ static int idetape_write_filemark (ide_drive_t *drive)
 }
 
 /*
- *     idetape_mtioctop is called from idetape_chrdev_ioctl when
- *     the general mtio MTIOCTOP ioctl is requested.
- *
- *     We currently support the following mtio.h operations:
- *
- *     MTFSF   -       Space over mt_count filemarks in the positive direction.
- *                     The tape is positioned after the last spaced filemark.
- *
- *     MTFSFM  -       Same as MTFSF, but the tape is positioned before the
- *                     last filemark.
- *
- *     MTBSF   -       Steps background over mt_count filemarks, tape is
- *                     positioned before the last filemark.
- *
- *     MTBSFM  -       Like MTBSF, only tape is positioned after the last filemark.
- *
- *     Note:
- *
- *             MTBSF and MTBSFM are not supported when the tape doesn't
- *             support spacing over filemarks in the reverse direction.
- *             In this case, MTFSFM is also usually not supported (it is
- *             supported in the rare case in which we crossed the filemark
- *             during our read-ahead pipelined operation mode).
- *             
- *     MTWEOF  -       Writes mt_count filemarks. Tape is positioned after
- *                     the last written filemark.
- *
- *     MTREW   -       Rewinds tape.
- *
- *     MTLOAD  -       Loads the tape.
- *
- *     MTOFFL  -       Puts the tape drive "Offline": Rewinds the tape and
- *     MTUNLOAD        prevents further access until the media is replaced.
- *
- *     MTNOP   -       Flushes tape buffers.
- *
- *     MTRETEN -       Retension media. This typically consists of one end
- *                     to end pass on the media.
- *
- *     MTEOM   -       Moves to the end of recorded data.
+ * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is
+ * requested.
  *
- *     MTERASE -       Erases tape.
+ * Note: MTBSF and MTBSFM are not supported when the tape doesn't support
+ * spacing over filemarks in the reverse direction. In this case, MTFSFM is also
+ * usually not supported (it is supported in the rare case in which we crossed
+ * the filemark during our read-ahead pipelined operation mode).
  *
- *     MTSETBLK -      Sets the user block size to mt_count bytes. If
- *                     mt_count is 0, we will attempt to autodetect
- *                     the block size.
+ * The following commands are currently not supported:
  *
- *     MTSEEK  -       Positions the tape in a specific block number, where
- *                     each block is assumed to contain which user_block_size
- *                     bytes.
- *
- *     MTSETPART -     Switches to another tape partition.
- *
- *     MTLOCK -        Locks the tape door.
- *
- *     MTUNLOCK -      Unlocks the tape door.
- *
- *     The following commands are currently not supported:
- *
- *     MTFSS, MTBSS, MTWSM, MTSETDENSITY,
- *     MTSETDRVBUFFER, MT_ST_BOOLEANS, MT_ST_WRITE_THRESHOLD.
+ * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS,
+ * MT_ST_WRITE_THRESHOLD.
  */
-static int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count)
+static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t pc;
-       int i,retval;
+       int i, retval;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 1)
-               printk(KERN_INFO "ide-tape: Handling MTIOCTOP ioctl: "
-                       "mt_op=%d, mt_count=%d\n", mt_op, mt_count);
-#endif /* IDETAPE_DEBUG_LOG */
-       /*
-        *      Commands which need our pipelined read-ahead stages.
-        */
+       debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",
+                       mt_op, mt_count);
+
+       /* Commands which need our pipelined read-ahead stages. */
        switch (mt_op) {
-               case MTFSF:
-               case MTFSFM:
-               case MTBSF:
-               case MTBSFM:
-                       if (!mt_count)
-                               return (0);
-                       return (idetape_space_over_filemarks(drive,mt_op,mt_count));
-               default:
-                       break;
+       case MTFSF:
+       case MTFSFM:
+       case MTBSF:
+       case MTBSFM:
+               if (!mt_count)
+                       return 0;
+               return idetape_space_over_filemarks(drive, mt_op, mt_count);
+       default:
+               break;
        }
+
        switch (mt_op) {
-               case MTWEOF:
-                       if (tape->write_prot)
-                               return -EACCES;
-                       idetape_discard_read_pipeline(drive, 1);
-                       for (i = 0; i < mt_count; i++) {
-                               retval = idetape_write_filemark(drive);
-                               if (retval)
-                                       return retval;
-                       }
-                       return (0);
-               case MTREW:
-                       idetape_discard_read_pipeline(drive, 0);
-                       if (idetape_rewind_tape(drive))
+       case MTWEOF:
+               if (tape->write_prot)
+                       return -EACCES;
+               idetape_discard_read_pipeline(drive, 1);
+               for (i = 0; i < mt_count; i++) {
+                       retval = idetape_write_filemark(drive);
+                       if (retval)
+                               return retval;
+               }
+               return 0;
+       case MTREW:
+               idetape_discard_read_pipeline(drive, 0);
+               if (idetape_rewind_tape(drive))
+                       return -EIO;
+               return 0;
+       case MTLOAD:
+               idetape_discard_read_pipeline(drive, 0);
+               idetape_create_load_unload_cmd(drive, &pc,
+                                              IDETAPE_LU_LOAD_MASK);
+               return idetape_queue_pc_tail(drive, &pc);
+       case MTUNLOAD:
+       case MTOFFL:
+               /*
+                * If door is locked, attempt to unlock before
+                * attempting to eject.
+                */
+               if (tape->door_locked) {
+                       if (idetape_create_prevent_cmd(drive, &pc, 0))
+                               if (!idetape_queue_pc_tail(drive, &pc))
+                                       tape->door_locked = DOOR_UNLOCKED;
+               }
+               idetape_discard_read_pipeline(drive, 0);
+               idetape_create_load_unload_cmd(drive, &pc,
+                                             !IDETAPE_LU_LOAD_MASK);
+               retval = idetape_queue_pc_tail(drive, &pc);
+               if (!retval)
+                       clear_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
+               return retval;
+       case MTNOP:
+               idetape_discard_read_pipeline(drive, 0);
+               return idetape_flush_tape_buffers(drive);
+       case MTRETEN:
+               idetape_discard_read_pipeline(drive, 0);
+               idetape_create_load_unload_cmd(drive, &pc,
+                       IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
+               return idetape_queue_pc_tail(drive, &pc);
+       case MTEOM:
+               idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
+               return idetape_queue_pc_tail(drive, &pc);
+       case MTERASE:
+               (void)idetape_rewind_tape(drive);
+               idetape_create_erase_cmd(&pc);
+               return idetape_queue_pc_tail(drive, &pc);
+       case MTSETBLK:
+               if (mt_count) {
+                       if (mt_count < tape->blk_size ||
+                           mt_count % tape->blk_size)
                                return -EIO;
+                       tape->user_bs_factor = mt_count / tape->blk_size;
+                       clear_bit(IDETAPE_DETECT_BS, &tape->flags);
+               } else
+                       set_bit(IDETAPE_DETECT_BS, &tape->flags);
+               return 0;
+       case MTSEEK:
+               idetape_discard_read_pipeline(drive, 0);
+               return idetape_position_tape(drive,
+                       mt_count * tape->user_bs_factor, tape->partition, 0);
+       case MTSETPART:
+               idetape_discard_read_pipeline(drive, 0);
+               return idetape_position_tape(drive, 0, mt_count, 0);
+       case MTFSR:
+       case MTBSR:
+       case MTLOCK:
+               if (!idetape_create_prevent_cmd(drive, &pc, 1))
                        return 0;
-               case MTLOAD:
-                       idetape_discard_read_pipeline(drive, 0);
-                       idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK);
-                       return (idetape_queue_pc_tail(drive, &pc));
-               case MTUNLOAD:
-               case MTOFFL:
-                       /*
-                        * If door is locked, attempt to unlock before
-                        * attempting to eject.
-                        */
-                       if (tape->door_locked) {
-                               if (idetape_create_prevent_cmd(drive, &pc, 0))
-                                       if (!idetape_queue_pc_tail(drive, &pc))
-                                               tape->door_locked = DOOR_UNLOCKED;
-                       }
-                       idetape_discard_read_pipeline(drive, 0);
-                       idetape_create_load_unload_cmd(drive, &pc,!IDETAPE_LU_LOAD_MASK);
-                       retval = idetape_queue_pc_tail(drive, &pc);
-                       if (!retval)
-                               clear_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
+               retval = idetape_queue_pc_tail(drive, &pc);
+               if (retval)
                        return retval;
-               case MTNOP:
-                       idetape_discard_read_pipeline(drive, 0);
-                       return (idetape_flush_tape_buffers(drive));
-               case MTRETEN:
-                       idetape_discard_read_pipeline(drive, 0);
-                       idetape_create_load_unload_cmd(drive, &pc,IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
-                       return (idetape_queue_pc_tail(drive, &pc));
-               case MTEOM:
-                       idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
-                       return (idetape_queue_pc_tail(drive, &pc));
-               case MTERASE:
-                       (void) idetape_rewind_tape(drive);
-                       idetape_create_erase_cmd(&pc);
-                       return (idetape_queue_pc_tail(drive, &pc));
-               case MTSETBLK:
-                       if (mt_count) {
-                               if (mt_count < tape->tape_block_size || mt_count % tape->tape_block_size)
-                                       return -EIO;
-                               tape->user_bs_factor = mt_count / tape->tape_block_size;
-                               clear_bit(IDETAPE_DETECT_BS, &tape->flags);
-                       } else
-                               set_bit(IDETAPE_DETECT_BS, &tape->flags);
-                       return 0;
-               case MTSEEK:
-                       idetape_discard_read_pipeline(drive, 0);
-                       return idetape_position_tape(drive, mt_count * tape->user_bs_factor, tape->partition, 0);
-               case MTSETPART:
-                       idetape_discard_read_pipeline(drive, 0);
-                       return (idetape_position_tape(drive, 0, mt_count, 0));
-               case MTFSR:
-               case MTBSR:
-               case MTLOCK:
-                       if (!idetape_create_prevent_cmd(drive, &pc, 1))
-                               return 0;
-                       retval = idetape_queue_pc_tail(drive, &pc);
-                       if (retval) return retval;
-                       tape->door_locked = DOOR_EXPLICITLY_LOCKED;
-                       return 0;
-               case MTUNLOCK:
-                       if (!idetape_create_prevent_cmd(drive, &pc, 0))
-                               return 0;
-                       retval = idetape_queue_pc_tail(drive, &pc);
-                       if (retval) return retval;
-                       tape->door_locked = DOOR_UNLOCKED;
+               tape->door_locked = DOOR_EXPLICITLY_LOCKED;
+               return 0;
+       case MTUNLOCK:
+               if (!idetape_create_prevent_cmd(drive, &pc, 0))
                        return 0;
-               default:
-                       printk(KERN_ERR "ide-tape: MTIO operation %d not "
-                               "supported\n", mt_op);
-                       return (-EIO);
+               retval = idetape_queue_pc_tail(drive, &pc);
+               if (retval)
+                       return retval;
+               tape->door_locked = DOOR_UNLOCKED;
+               return 0;
+       default:
+               printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
+                               mt_op);
+               return -EIO;
        }
 }
 
 /*
- *     Our character device ioctls.
- *
- *     General mtio.h magnetic io commands are supported here, and not in
- *     the corresponding block interface.
- *
- *     The following ioctls are supported:
- *
- *     MTIOCTOP -      Refer to idetape_mtioctop for detailed description.
- *
- *     MTIOCGET -      The mt_dsreg field in the returned mtget structure
- *                     will be set to (user block size in bytes <<
- *                     MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK.
- *
- *                     The mt_blkno is set to the current user block number.
- *                     The other mtget fields are not supported.
- *
- *     MTIOCPOS -      The current tape "block position" is returned. We
- *                     assume that each block contains user_block_size
- *                     bytes.
- *
- *     Our own ide-tape ioctls are supported on both interfaces.
+ * Our character device ioctls. General mtio.h magnetic io commands are
+ * supported here, and not in the corresponding block interface. Our own
+ * ide-tape ioctls are supported on both interfaces.
  */
-static int idetape_chrdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
+                               unsigned int cmd, unsigned long arg)
 {
        struct ide_tape_obj *tape = ide_tape_f(file);
        ide_drive_t *drive = tape->drive;
        struct mtop mtop;
        struct mtget mtget;
        struct mtpos mtpos;
-       int block_offset = 0, position = tape->first_frame_position;
+       int block_offset = 0, position = tape->first_frame;
        void __user *argp = (void __user *)arg;
 
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 3)
-               printk(KERN_INFO "ide-tape: Reached idetape_chrdev_ioctl, "
-                       "cmd=%u\n", cmd);
-#endif /* IDETAPE_DEBUG_LOG */
+       debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd);
 
        tape->restart_speed_control_req = 1;
-       if (tape->chrdev_direction == idetape_direction_write) {
+       if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
                idetape_empty_write_pipeline(drive);
                idetape_flush_tape_buffers(drive);
        }
        if (cmd == MTIOCGET || cmd == MTIOCPOS) {
-               block_offset = idetape_pipeline_size(drive) / (tape->tape_block_size * tape->user_bs_factor);
-               if ((position = idetape_read_position(drive)) < 0)
+               block_offset = idetape_pipeline_size(drive) /
+                       (tape->blk_size * tape->user_bs_factor);
+               position = idetape_read_position(drive);
+               if (position < 0)
                        return -EIO;
        }
        switch (cmd) {
-               case MTIOCTOP:
-                       if (copy_from_user(&mtop, argp, sizeof (struct mtop)))
-                               return -EFAULT;
-                       return (idetape_mtioctop(drive,mtop.mt_op,mtop.mt_count));
-               case MTIOCGET:
-                       memset(&mtget, 0, sizeof (struct mtget));
-                       mtget.mt_type = MT_ISSCSI2;
-                       mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
-                       mtget.mt_dsreg = ((tape->tape_block_size * tape->user_bs_factor) << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
-                       if (tape->drv_write_prot) {
-                               mtget.mt_gstat |= GMT_WR_PROT(0xffffffff);
-                       }
-                       if (copy_to_user(argp, &mtget, sizeof(struct mtget)))
-                               return -EFAULT;
-                       return 0;
-               case MTIOCPOS:
-                       mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
-                       if (copy_to_user(argp, &mtpos, sizeof(struct mtpos)))
-                               return -EFAULT;
-                       return 0;
-               default:
-                       if (tape->chrdev_direction == idetape_direction_read)
-                               idetape_discard_read_pipeline(drive, 1);
-                       return idetape_blkdev_ioctl(drive, cmd, arg);
+       case MTIOCTOP:
+               if (copy_from_user(&mtop, argp, sizeof(struct mtop)))
+                       return -EFAULT;
+               return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count);
+       case MTIOCGET:
+               memset(&mtget, 0, sizeof(struct mtget));
+               mtget.mt_type = MT_ISSCSI2;
+               mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
+               mtget.mt_dsreg =
+                       ((tape->blk_size * tape->user_bs_factor)
+                        << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
+
+               if (tape->drv_write_prot)
+                       mtget.mt_gstat |= GMT_WR_PROT(0xffffffff);
+
+               if (copy_to_user(argp, &mtget, sizeof(struct mtget)))
+                       return -EFAULT;
+               return 0;
+       case MTIOCPOS:
+               mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
+               if (copy_to_user(argp, &mtpos, sizeof(struct mtpos)))
+                       return -EFAULT;
+               return 0;
+       default:
+               if (tape->chrdev_dir == IDETAPE_DIR_READ)
+                       idetape_discard_read_pipeline(drive, 1);
+               return idetape_blkdev_ioctl(drive, cmd, arg);
        }
 }
 
-static void idetape_get_blocksize_from_block_descriptor(ide_drive_t *drive);
-
 /*
- *     Our character device open function.
+ * Do a mode sense page 0 with block descriptor and if it succeeds set the tape
+ * block size with the reported value.
  */
-static int idetape_chrdev_open (struct inode *inode, struct file *filp)
+static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
+{
+       idetape_tape_t *tape = drive->driver_data;
+       idetape_pc_t pc;
+
+       idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
+       if (idetape_queue_pc_tail(drive, &pc)) {
+               printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
+               if (tape->blk_size == 0) {
+                       printk(KERN_WARNING "ide-tape: Cannot deal with zero "
+                                           "block size, assuming 32k\n");
+                       tape->blk_size = 32768;
+               }
+               return;
+       }
+       tape->blk_size = (pc.buffer[4 + 5] << 16) +
+                               (pc.buffer[4 + 6] << 8)  +
+                                pc.buffer[4 + 7];
+       tape->drv_write_prot = (pc.buffer[2] & 0x80) >> 7;
+}
+
+static int idetape_chrdev_open(struct inode *inode, struct file *filp)
 {
        unsigned int minor = iminor(inode), i = minor & ~0xc0;
        ide_drive_t *drive;
@@ -4137,6 +3209,15 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
        idetape_pc_t pc;
        int retval;
 
+       if (i >= MAX_HWIFS * MAX_DRIVES)
+               return -ENXIO;
+
+       tape = ide_tape_chrdev_get(i);
+       if (!tape)
+               return -ENXIO;
+
+       debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
+
        /*
         * We really want to do nonseekable_open(inode, filp); here, but some
         * versions of tar incorrectly call lseek on tapes and bail out if that
@@ -4144,16 +3225,6 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
         */
        filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
 
-#if IDETAPE_DEBUG_LOG
-       printk(KERN_INFO "ide-tape: Reached idetape_chrdev_open\n");
-#endif /* IDETAPE_DEBUG_LOG */
-       
-       if (i >= MAX_HWIFS * MAX_DRIVES)
-               return -ENXIO;
-
-       if (!(tape = ide_tape_chrdev_get(i)))
-               return -ENXIO;
-
        drive = tape->drive;
 
        filp->private_data = tape;
@@ -4174,11 +3245,11 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
        if (!test_bit(IDETAPE_ADDRESS_VALID, &tape->flags))
                (void)idetape_rewind_tape(drive);
 
-       if (tape->chrdev_direction != idetape_direction_read)
+       if (tape->chrdev_dir != IDETAPE_DIR_READ)
                clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
 
        /* Read block size and write protect status from drive. */
-       idetape_get_blocksize_from_block_descriptor(drive);
+       ide_tape_get_bsize_from_bdesc(drive);
 
        /* Set write protect flag if device is opened as read-only. */
        if ((filp->f_flags & O_ACCMODE) == O_RDONLY)
@@ -4196,10 +3267,8 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
                }
        }
 
-       /*
-        * Lock the tape drive door so user can't eject.
-        */
-       if (tape->chrdev_direction == idetape_direction_none) {
+       /* Lock the tape drive door so user can't eject. */
+       if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
                if (idetape_create_prevent_cmd(drive, &pc, 1)) {
                        if (!idetape_queue_pc_tail(drive, &pc)) {
                                if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
@@ -4216,14 +3285,15 @@ out_put_tape:
        return retval;
 }
 
-static void idetape_write_release (ide_drive_t *drive, unsigned int minor)
+static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
 {
        idetape_tape_t *tape = drive->driver_data;
 
        idetape_empty_write_pipeline(drive);
        tape->merge_stage = __idetape_kmalloc_stage(tape, 1, 0);
        if (tape->merge_stage != NULL) {
-               idetape_pad_zeros(drive, tape->tape_block_size * (tape->user_bs_factor - 1));
+               idetape_pad_zeros(drive, tape->blk_size *
+                               (tape->user_bs_factor - 1));
                __idetape_kfree_stage(tape->merge_stage);
                tape->merge_stage = NULL;
        }
@@ -4232,10 +3302,7 @@ static void idetape_write_release (ide_drive_t *drive, unsigned int minor)
        idetape_flush_tape_buffers(drive);
 }
 
-/*
- *     Our character device release function.
- */
-static int idetape_chrdev_release (struct inode *inode, struct file *filp)
+static int idetape_chrdev_release(struct inode *inode, struct file *filp)
 {
        struct ide_tape_obj *tape = ide_tape_f(filp);
        ide_drive_t *drive = tape->drive;
@@ -4244,14 +3311,12 @@ static int idetape_chrdev_release (struct inode *inode, struct file *filp)
 
        lock_kernel();
        tape = drive->driver_data;
-#if IDETAPE_DEBUG_LOG
-       if (tape->debug_level >= 3)
-               printk(KERN_INFO "ide-tape: Reached idetape_chrdev_release\n");
-#endif /* IDETAPE_DEBUG_LOG */
 
-       if (tape->chrdev_direction == idetape_direction_write)
+       debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
+
+       if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
                idetape_write_release(drive, minor);
-       if (tape->chrdev_direction == idetape_direction_read) {
+       if (tape->chrdev_dir == IDETAPE_DIR_READ) {
                if (minor < 128)
                        idetape_discard_read_pipeline(drive, 1);
                else
@@ -4263,7 +3328,7 @@ static int idetape_chrdev_release (struct inode *inode, struct file *filp)
        }
        if (minor < 128 && test_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags))
                (void) idetape_rewind_tape(drive);
-       if (tape->chrdev_direction == idetape_direction_none) {
+       if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
                if (tape->door_locked == DOOR_LOCKED) {
                        if (idetape_create_prevent_cmd(drive, &pc, 0)) {
                                if (!idetape_queue_pc_tail(drive, &pc))
@@ -4278,258 +3343,182 @@ static int idetape_chrdev_release (struct inode *inode, struct file *filp)
 }
 
 /*
- *     idetape_identify_device is called to check the contents of the
- *     ATAPI IDENTIFY command results. We return:
+ * check the contents of the ATAPI IDENTIFY command results. We return:
  *
- *     1       If the tape can be supported by us, based on the information
- *             we have so far.
+ * 1 - If the tape can be supported by us, based on the information we have so
+ * far.
  *
- *     0       If this tape driver is not currently supported by us.
+ * 0 - If this tape driver is not currently supported by us.
  */
-static int idetape_identify_device (ide_drive_t *drive)
+static int idetape_identify_device(ide_drive_t *drive)
 {
-       struct idetape_id_gcw gcw;
-       struct hd_driveid *id = drive->id;
+       u8 gcw[2], protocol, device_type, removable, packet_size;
 
        if (drive->id_read == 0)
                return 1;
 
-       *((unsigned short *) &gcw) = id->config;
+       *((unsigned short *) &gcw) = drive->id->config;
 
-#if IDETAPE_DEBUG_INFO
-       printk(KERN_INFO "ide-tape: Dumping ATAPI Identify Device tape parameters\n");
-       printk(KERN_INFO "ide-tape: Protocol Type: ");
-       switch (gcw.protocol) {
-               case 0: case 1: printk("ATA\n");break;
-               case 2: printk("ATAPI\n");break;
-               case 3: printk("Reserved (Unknown to ide-tape)\n");break;
-       }
-       printk(KERN_INFO "ide-tape: Device Type: %x - ",gcw.device_type);       
-       switch (gcw.device_type) {
-               case 0: printk("Direct-access Device\n");break;
-               case 1: printk("Streaming Tape Device\n");break;
-               case 2: case 3: case 4: printk("Reserved\n");break;
-               case 5: printk("CD-ROM Device\n");break;
-               case 6: printk("Reserved\n");
-               case 7: printk("Optical memory Device\n");break;
-               case 0x1f: printk("Unknown or no Device type\n");break;
-               default: printk("Reserved\n");
-       }
-       printk(KERN_INFO "ide-tape: Removable: %s",gcw.removable ? "Yes\n":"No\n");     
-       printk(KERN_INFO "ide-tape: Command Packet DRQ Type: ");
-       switch (gcw.drq_type) {
-               case 0: printk("Microprocessor DRQ\n");break;
-               case 1: printk("Interrupt DRQ\n");break;
-               case 2: printk("Accelerated DRQ\n");break;
-               case 3: printk("Reserved\n");break;
-       }
-       printk(KERN_INFO "ide-tape: Command Packet Size: ");
-       switch (gcw.packet_size) {
-               case 0: printk("12 bytes\n");break;
-               case 1: printk("16 bytes\n");break;
-               default: printk("Reserved\n");break;
-       }
-#endif /* IDETAPE_DEBUG_INFO */
+       protocol        =   (gcw[1] & 0xC0) >> 6;
+       device_type     =    gcw[1] & 0x1F;
+       removable       = !!(gcw[0] & 0x80);
+       packet_size     =    gcw[0] & 0x3;
 
        /* Check that we can support this device */
-
-       if (gcw.protocol !=2 )
-               printk(KERN_ERR "ide-tape: Protocol is not ATAPI\n");
-       else if (gcw.device_type != 1)
-               printk(KERN_ERR "ide-tape: Device type is not set to tape\n");
-       else if (!gcw.removable)
+       if (protocol != 2)
+               printk(KERN_ERR "ide-tape: Protocol (0x%02x) is not ATAPI\n",
+                               protocol);
+       else if (device_type != 1)
+               printk(KERN_ERR "ide-tape: Device type (0x%02x) is not set "
+                               "to tape\n", device_type);
+       else if (!removable)
                printk(KERN_ERR "ide-tape: The removable flag is not set\n");
-       else if (gcw.packet_size != 0) {
-               printk(KERN_ERR "ide-tape: Packet size is not 12 bytes long\n");
-               if (gcw.packet_size == 1)
-                       printk(KERN_ERR "ide-tape: Sorry, padding to 16 bytes is still not supported\n");
+       else if (packet_size != 0) {
+               printk(KERN_ERR "ide-tape: Packet size (0x%02x) is not 12"
+                               " bytes\n", packet_size);
        } else
                return 1;
        return 0;
 }
 
-/*
- * Use INQUIRY to get the firmware revision
- */
-static void idetape_get_inquiry_results (ide_drive_t *drive)
+static void idetape_get_inquiry_results(ide_drive_t *drive)
 {
-       char *r;
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t pc;
-       idetape_inquiry_result_t *inquiry;
-       
+       char fw_rev[6], vendor_id[10], product_id[18];
+
        idetape_create_inquiry_cmd(&pc);
        if (idetape_queue_pc_tail(drive, &pc)) {
-               printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", tape->name);
+               printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
+                               tape->name);
                return;
        }
-       inquiry = (idetape_inquiry_result_t *) pc.buffer;
-       memcpy(tape->vendor_id, inquiry->vendor_id, 8);
-       memcpy(tape->product_id, inquiry->product_id, 16);
-       memcpy(tape->firmware_revision, inquiry->revision_level, 4);
-       ide_fixstring(tape->vendor_id, 10, 0);
-       ide_fixstring(tape->product_id, 18, 0);
-       ide_fixstring(tape->firmware_revision, 6, 0);
-       r = tape->firmware_revision;
-       if (*(r + 1) == '.')
-               tape->firmware_revision_num = (*r - '0') * 100 + (*(r + 2) - '0') * 10 + *(r + 3) - '0';
-       printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n", drive->name, tape->name, tape->vendor_id, tape->product_id, tape->firmware_revision);
+       memcpy(vendor_id, &pc.buffer[8], 8);
+       memcpy(product_id, &pc.buffer[16], 16);
+       memcpy(fw_rev, &pc.buffer[32], 4);
+
+       ide_fixstring(vendor_id, 10, 0);
+       ide_fixstring(product_id, 18, 0);
+       ide_fixstring(fw_rev, 6, 0);
+
+       printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n",
+                       drive->name, tape->name, vendor_id, product_id, fw_rev);
 }
 
 /*
- *     idetape_get_mode_sense_results asks the tape about its various
- *     parameters. In particular, we will adjust our data transfer buffer
- *     size to the recommended value as returned by the tape.
+ * Ask the tape about its various parameters. In particular, we will adjust our
+ * data transfer buffer        size to the recommended value as returned by the tape.
  */
-static void idetape_get_mode_sense_results (ide_drive_t *drive)
+static void idetape_get_mode_sense_results(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t pc;
-       idetape_mode_parameter_header_t *header;
-       idetape_capabilities_page_t *capabilities;
-       
+       u8 *caps;
+       u8 speed, max_speed;
+
        idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
        if (idetape_queue_pc_tail(drive, &pc)) {
-               printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming some default values\n");
-               tape->tape_block_size = 512;
-               tape->capabilities.ctl = 52;
-               tape->capabilities.speed = 450;
-               tape->capabilities.buffer_size = 6 * 52;
+               printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
+                               " some default values\n");
+               tape->blk_size = 512;
+               put_unaligned(52,   (u16 *)&tape->caps[12]);
+               put_unaligned(540,  (u16 *)&tape->caps[14]);
+               put_unaligned(6*52, (u16 *)&tape->caps[16]);
                return;
        }
-       header = (idetape_mode_parameter_header_t *) pc.buffer;
-       capabilities = (idetape_capabilities_page_t *) (pc.buffer + sizeof(idetape_mode_parameter_header_t) + header->bdl);
+       caps = pc.buffer + 4 + pc.buffer[3];
 
-       capabilities->max_speed = ntohs(capabilities->max_speed);
-       capabilities->ctl = ntohs(capabilities->ctl);
-       capabilities->speed = ntohs(capabilities->speed);
-       capabilities->buffer_size = ntohs(capabilities->buffer_size);
+       /* convert to host order and save for later use */
+       speed = be16_to_cpu(*(u16 *)&caps[14]);
+       max_speed = be16_to_cpu(*(u16 *)&caps[8]);
 
-       if (!capabilities->speed) {
-               printk(KERN_INFO "ide-tape: %s: overriding capabilities->speed (assuming 650KB/sec)\n", drive->name);
-               capabilities->speed = 650;
+       put_unaligned(max_speed, (u16 *)&caps[8]);
+       put_unaligned(be16_to_cpu(*(u16 *)&caps[12]), (u16 *)&caps[12]);
+       put_unaligned(speed, (u16 *)&caps[14]);
+       put_unaligned(be16_to_cpu(*(u16 *)&caps[16]), (u16 *)&caps[16]);
+
+       if (!speed) {
+               printk(KERN_INFO "ide-tape: %s: invalid tape speed "
+                               "(assuming 650KB/sec)\n", drive->name);
+               put_unaligned(650, (u16 *)&caps[14]);
        }
-       if (!capabilities->max_speed) {
-               printk(KERN_INFO "ide-tape: %s: overriding capabilities->max_speed (assuming 650KB/sec)\n", drive->name);
-               capabilities->max_speed = 650;
+       if (!max_speed) {
+               printk(KERN_INFO "ide-tape: %s: invalid max_speed "
+                               "(assuming 650KB/sec)\n", drive->name);
+               put_unaligned(650, (u16 *)&caps[8]);
        }
 
-       tape->capabilities = *capabilities;             /* Save us a copy */
-       if (capabilities->blk512)
-               tape->tape_block_size = 512;
-       else if (capabilities->blk1024)
-               tape->tape_block_size = 1024;
-
-#if IDETAPE_DEBUG_INFO
-       printk(KERN_INFO "ide-tape: Dumping the results of the MODE SENSE packet command\n");
-       printk(KERN_INFO "ide-tape: Mode Parameter Header:\n");
-       printk(KERN_INFO "ide-tape: Mode Data Length - %d\n",header->mode_data_length);
-       printk(KERN_INFO "ide-tape: Medium Type - %d\n",header->medium_type);
-       printk(KERN_INFO "ide-tape: Device Specific Parameter - %d\n",header->dsp);
-       printk(KERN_INFO "ide-tape: Block Descriptor Length - %d\n",header->bdl);
-       
-       printk(KERN_INFO "ide-tape: Capabilities and Mechanical Status Page:\n");
-       printk(KERN_INFO "ide-tape: Page code - %d\n",capabilities->page_code);
-       printk(KERN_INFO "ide-tape: Page length - %d\n",capabilities->page_length);
-       printk(KERN_INFO "ide-tape: Read only - %s\n",capabilities->ro ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports reverse space - %s\n",capabilities->sprev ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports erase initiated formatting - %s\n",capabilities->efmt ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports QFA two Partition format - %s\n",capabilities->qfa ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports locking the medium - %s\n",capabilities->lock ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: The volume is currently locked - %s\n",capabilities->locked ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: The device defaults in the prevent state - %s\n",capabilities->prevent ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports ejecting the medium - %s\n",capabilities->eject ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports error correction - %s\n",capabilities->ecc ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports data compression - %s\n",capabilities->cmprs ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports 512 bytes block size - %s\n",capabilities->blk512 ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports 1024 bytes block size - %s\n",capabilities->blk1024 ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Supports 32768 bytes block size / Restricted byte count for PIO transfers - %s\n",capabilities->blk32768 ? "Yes":"No");
-       printk(KERN_INFO "ide-tape: Maximum supported speed in KBps - %d\n",capabilities->max_speed);
-       printk(KERN_INFO "ide-tape: Continuous transfer limits in blocks - %d\n",capabilities->ctl);
-       printk(KERN_INFO "ide-tape: Current speed in KBps - %d\n",capabilities->speed); 
-       printk(KERN_INFO "ide-tape: Buffer size - %d\n",capabilities->buffer_size*512);
-#endif /* IDETAPE_DEBUG_INFO */
-}
-
-/*
- *     ide_get_blocksize_from_block_descriptor does a mode sense page 0 with block descriptor
- *     and if it succeeds sets the tape block size with the reported value
- */
-static void idetape_get_blocksize_from_block_descriptor(ide_drive_t *drive)
-{
-
-       idetape_tape_t *tape = drive->driver_data;
-       idetape_pc_t pc;
-       idetape_mode_parameter_header_t *header;
-       idetape_parameter_block_descriptor_t *block_descrp;
-       
-       idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
-       if (idetape_queue_pc_tail(drive, &pc)) {
-               printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
-               if (tape->tape_block_size == 0) {
-                       printk(KERN_WARNING "ide-tape: Cannot deal with zero block size, assume 32k\n");
-                       tape->tape_block_size =  32768;
-               }
-               return;
-       }
-       header = (idetape_mode_parameter_header_t *) pc.buffer;
-       block_descrp = (idetape_parameter_block_descriptor_t *) (pc.buffer + sizeof(idetape_mode_parameter_header_t));
-       tape->tape_block_size =( block_descrp->length[0]<<16) + (block_descrp->length[1]<<8) + block_descrp->length[2];
-       tape->drv_write_prot = (header->dsp & 0x80) >> 7;
-
-#if IDETAPE_DEBUG_INFO
-       printk(KERN_INFO "ide-tape: Adjusted block size - %d\n", tape->tape_block_size);
-#endif /* IDETAPE_DEBUG_INFO */
+       memcpy(&tape->caps, caps, 20);
+       if (caps[7] & 0x02)
+               tape->blk_size = 512;
+       else if (caps[7] & 0x04)
+               tape->blk_size = 1024;
 }
 
 #ifdef CONFIG_IDE_PROC_FS
-static void idetape_add_settings (ide_drive_t *drive)
+static void idetape_add_settings(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-/*
- *                     drive   setting name            read/write      data type       min                     max                     mul_factor                      div_factor      data pointer                            set function
- */
-       ide_add_setting(drive,  "buffer",               SETTING_READ,   TYPE_SHORT,     0,                      0xffff,                 1,                              2,              &tape->capabilities.buffer_size,        NULL);
-       ide_add_setting(drive,  "pipeline_min",         SETTING_RW,     TYPE_INT,       1,                      0xffff,                 tape->stage_size / 1024,        1,              &tape->min_pipeline,                    NULL);
-       ide_add_setting(drive,  "pipeline",             SETTING_RW,     TYPE_INT,       1,                      0xffff,                 tape->stage_size / 1024,        1,              &tape->max_stages,                      NULL);
-       ide_add_setting(drive,  "pipeline_max",         SETTING_RW,     TYPE_INT,       1,                      0xffff,                 tape->stage_size / 1024,        1,              &tape->max_pipeline,                    NULL);
-       ide_add_setting(drive,  "pipeline_used",        SETTING_READ,   TYPE_INT,       0,                      0xffff,                 tape->stage_size / 1024,        1,              &tape->nr_stages,                       NULL);
-       ide_add_setting(drive,  "pipeline_pending",     SETTING_READ,   TYPE_INT,       0,                      0xffff,                 tape->stage_size / 1024,        1,              &tape->nr_pending_stages,               NULL);
-       ide_add_setting(drive,  "speed",                SETTING_READ,   TYPE_SHORT,     0,                      0xffff,                 1,                              1,              &tape->capabilities.speed,              NULL);
-       ide_add_setting(drive,  "stage",                SETTING_READ,   TYPE_INT,       0,                      0xffff,                 1,                              1024,           &tape->stage_size,                      NULL);
-       ide_add_setting(drive,  "tdsc",                 SETTING_RW,     TYPE_INT,       IDETAPE_DSC_RW_MIN,     IDETAPE_DSC_RW_MAX,     1000,                           HZ,             &tape->best_dsc_rw_frequency,           NULL);
-       ide_add_setting(drive,  "dsc_overlap",          SETTING_RW,     TYPE_BYTE,      0,                      1,                      1,                              1,              &drive->dsc_overlap,                    NULL);
-       ide_add_setting(drive,  "pipeline_head_speed_c",SETTING_READ,   TYPE_INT,       0,                      0xffff,                 1,                              1,              &tape->controlled_pipeline_head_speed,  NULL);
-       ide_add_setting(drive,  "pipeline_head_speed_u",SETTING_READ,   TYPE_INT,       0,                      0xffff,                 1,                              1,              &tape->uncontrolled_pipeline_head_speed,NULL);
-       ide_add_setting(drive,  "avg_speed",            SETTING_READ,   TYPE_INT,       0,                      0xffff,                 1,                              1,              &tape->avg_speed,                       NULL);
-       ide_add_setting(drive,  "debug_level",          SETTING_RW,     TYPE_INT,       0,                      0xffff,                 1,                              1,              &tape->debug_level,                     NULL);
+       ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff,
+                       1, 2, (u16 *)&tape->caps[16], NULL);
+       ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff,
+                       tape->stage_size / 1024, 1, &tape->min_pipeline, NULL);
+       ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff,
+                       tape->stage_size / 1024, 1, &tape->max_stages, NULL);
+       ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff,
+                       tape->stage_size / 1024, 1, &tape->max_pipeline, NULL);
+       ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0,
+                       0xffff, tape->stage_size / 1024, 1, &tape->nr_stages,
+                       NULL);
+       ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0,
+                       0xffff, tape->stage_size / 1024, 1,
+                       &tape->nr_pending_stages, NULL);
+       ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff,
+                       1, 1, (u16 *)&tape->caps[14], NULL);
+       ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1,
+                       1024, &tape->stage_size, NULL);
+       ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN,
+                       IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_freq,
+                       NULL);
+       ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1,
+                       1, &drive->dsc_overlap, NULL);
+       ide_add_setting(drive, "pipeline_head_speed_c", SETTING_READ, TYPE_INT,
+                       0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed,
+                       NULL);
+       ide_add_setting(drive, "pipeline_head_speed_u", SETTING_READ, TYPE_INT,
+                       0, 0xffff, 1, 1,
+                       &tape->uncontrolled_pipeline_head_speed, NULL);
+       ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff,
+                       1, 1, &tape->avg_speed, NULL);
+       ide_add_setting(drive, "debug_mask", SETTING_RW, TYPE_INT, 0, 0xffff, 1,
+                       1, &tape->debug_mask, NULL);
 }
 #else
 static inline void idetape_add_settings(ide_drive_t *drive) { ; }
 #endif
 
 /*
- *     ide_setup is called to:
+ * The function below is called to:
  *
- *             1.      Initialize our various state variables.
- *             2.      Ask the tape for its capabilities.
- *             3.      Allocate a buffer which will be used for data
- *                     transfer. The buffer size is chosen based on
- *                     the recommendation which we received in step (2).
+ * 1. Initialize our various state variables.
+ * 2. Ask the tape for its capabilities.
+ * 3. Allocate a buffer which will be used for data transfer. The buffer size
+ * is chosen based on the recommendation which we received in step 2.
  *
- *     Note that at this point ide.c already assigned us an irq, so that
- *     we can queue requests here and wait for their completion.
+ * Note that at this point ide.c already assigned us an irq, so that we can
+ * queue requests here and wait for their completion.
  */
-static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
+static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
 {
        unsigned long t1, tmid, tn, t;
        int speed;
-       struct idetape_id_gcw gcw;
        int stage_size;
+       u8 gcw[2];
        struct sysinfo si;
+       u16 *ctl = (u16 *)&tape->caps[12];
 
-       spin_lock_init(&tape->spinlock);
+       spin_lock_init(&tape->lock);
        drive->dsc_overlap = 1;
        if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
                printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
@@ -4543,25 +3532,29 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
        tape->name[0] = 'h';
        tape->name[1] = 't';
        tape->name[2] = '0' + minor;
-       tape->chrdev_direction = idetape_direction_none;
+       tape->chrdev_dir = IDETAPE_DIR_NONE;
        tape->pc = tape->pc_stack;
        tape->max_insert_speed = 10000;
        tape->speed_control = 1;
        *((unsigned short *) &gcw) = drive->id->config;
-       if (gcw.drq_type == 1)
+
+       /* Command packet DRQ type */
+       if (((gcw[0] & 0x60) >> 5) == 1)
                set_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags);
 
-       tape->min_pipeline = tape->max_pipeline = tape->max_stages = 10;
-       
+       tape->min_pipeline = 10;
+       tape->max_pipeline = 10;
+       tape->max_stages   = 10;
+
        idetape_get_inquiry_results(drive);
        idetape_get_mode_sense_results(drive);
-       idetape_get_blocksize_from_block_descriptor(drive);
+       ide_tape_get_bsize_from_bdesc(drive);
        tape->user_bs_factor = 1;
-       tape->stage_size = tape->capabilities.ctl * tape->tape_block_size;
+       tape->stage_size = *ctl * tape->blk_size;
        while (tape->stage_size > 0xffff) {
                printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
-               tape->capabilities.ctl /= 2;
-               tape->stage_size = tape->capabilities.ctl * tape->tape_block_size;
+               *ctl /= 2;
+               tape->stage_size = *ctl * tape->blk_size;
        }
        stage_size = tape->stage_size;
        tape->pages_per_stage = stage_size / PAGE_SIZE;
@@ -4570,28 +3563,30 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
                tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE;
        }
 
-       /*
-        *      Select the "best" DSC read/write polling frequency
-        *      and pipeline size.
-        */
-       speed = max(tape->capabilities.speed, tape->capabilities.max_speed);
+       /* Select the "best" DSC read/write polling freq and pipeline size. */
+       speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
 
        tape->max_stages = speed * 1000 * 10 / tape->stage_size;
 
-       /*
-        *      Limit memory use for pipeline to 10% of physical memory
-        */
+       /* Limit memory use for pipeline to 10% of physical memory */
        si_meminfo(&si);
-       if (tape->max_stages * tape->stage_size > si.totalram * si.mem_unit / 10)
-               tape->max_stages = si.totalram * si.mem_unit / (10 * tape->stage_size);
+       if (tape->max_stages * tape->stage_size >
+                       si.totalram * si.mem_unit / 10)
+               tape->max_stages =
+                       si.totalram * si.mem_unit / (10 * tape->stage_size);
+
        tape->max_stages   = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES);
        tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES);
-       tape->max_pipeline = min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES);
-       if (tape->max_stages == 0)
-               tape->max_stages = tape->min_pipeline = tape->max_pipeline = 1;
+       tape->max_pipeline =
+               min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES);
+       if (tape->max_stages == 0) {
+               tape->max_stages   = 1;
+               tape->min_pipeline = 1;
+               tape->max_pipeline = 1;
+       }
 
        t1 = (tape->stage_size * HZ) / (speed * 1000);
-       tmid = (tape->capabilities.buffer_size * 32 * HZ) / (speed * 125);
+       tmid = (*(u16 *)&tape->caps[16] * 32 * HZ) / (speed * 125);
        tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000);
 
        if (tape->max_stages)
@@ -4600,17 +3595,19 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
                t = t1;
 
        /*
-        *      Ensure that the number we got makes sense; limit
-        *      it within IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
+        * Ensure that the number we got makes sense; limit it within
+        * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
         */
-       tape->best_dsc_rw_frequency = max_t(unsigned long, min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), IDETAPE_DSC_RW_MIN);
+       tape->best_dsc_rw_freq = max_t(unsigned long,
+                               min_t(unsigned long, t, IDETAPE_DSC_RW_MAX),
+                               IDETAPE_DSC_RW_MIN);
        printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
                "%dkB pipeline, %lums tDSC%s\n",
-               drive->name, tape->name, tape->capabilities.speed,
-               (tape->capabilities.buffer_size * 512) / tape->stage_size,
+               drive->name, tape->name, *(u16 *)&tape->caps[14],
+               (*(u16 *)&tape->caps[16] * 512) / tape->stage_size,
                tape->stage_size / 1024,
                tape->max_stages * tape->stage_size / 1024,
-               tape->best_dsc_rw_frequency * 1000 / HZ,
+               tape->best_dsc_rw_freq * 1000 / HZ,
                drive->using_dma ? ", DMA":"");
 
        idetape_add_settings(drive);
@@ -4638,7 +3635,8 @@ static void ide_tape_release(struct kref *kref)
        drive->dsc_overlap = 0;
        drive->driver_data = NULL;
        device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
-       device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor + 128));
+       device_destroy(idetape_sysfs_class,
+                       MKDEV(IDETAPE_MAJOR, tape->minor + 128));
        idetape_devs[tape->minor] = NULL;
        g->private_data = NULL;
        put_disk(g);
@@ -4687,9 +3685,7 @@ static ide_driver_t idetape_driver = {
 #endif
 };
 
-/*
- *     Our character device supporting functions, passed to register_chrdev.
- */
+/* Our character device supporting functions, passed to register_chrdev. */
 static const struct file_operations idetape_fops = {
        .owner          = THIS_MODULE,
        .read           = idetape_chrdev_read,
@@ -4704,7 +3700,8 @@ static int idetape_open(struct inode *inode, struct file *filp)
        struct gendisk *disk = inode->i_bdev->bd_disk;
        struct ide_tape_obj *tape;
 
-       if (!(tape = ide_tape_get(disk)))
+       tape = ide_tape_get(disk);
+       if (!tape)
                return -ENXIO;
 
        return 0;
@@ -4751,21 +3748,20 @@ static int ide_tape_probe(ide_drive_t *drive)
                goto failed;
        if (drive->media != ide_tape)
                goto failed;
-       if (!idetape_identify_device (drive)) {
-               printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name);
+       if (!idetape_identify_device(drive)) {
+               printk(KERN_ERR "ide-tape: %s: not supported by this version of"
+                               " the driver\n", drive->name);
                goto failed;
        }
        if (drive->scsi) {
-               printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive->name);
+               printk(KERN_INFO "ide-tape: passing drive %s to ide-scsi"
+                                " emulation.\n", drive->name);
                goto failed;
        }
-       if (strstr(drive->id->model, "OnStream DI-")) {
-               printk(KERN_WARNING "ide-tape: Use drive %s with ide-scsi emulation and osst.\n", drive->name);
-               printk(KERN_WARNING "ide-tape: OnStream support will be removed soon from ide-tape!\n");
-       }
-       tape = kzalloc(sizeof (idetape_tape_t), GFP_KERNEL);
+       tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL);
        if (tape == NULL) {
-               printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name);
+               printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n",
+                               drive->name);
                goto failed;
        }
 
@@ -4811,10 +3807,7 @@ failed:
        return -ENODEV;
 }
 
-MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
-MODULE_LICENSE("GPL");
-
-static void __exit idetape_exit (void)
+static void __exit idetape_exit(void)
 {
        driver_unregister(&idetape_driver.gen_driver);
        class_destroy(idetape_sysfs_class);
@@ -4833,7 +3826,8 @@ static int __init idetape_init(void)
        }
 
        if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
-               printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
+               printk(KERN_ERR "ide-tape: Failed to register chrdev"
+                               " interface\n");
                error = -EBUSY;
                goto out_free_class;
        }
@@ -4856,3 +3850,5 @@ MODULE_ALIAS("ide:*m-tape*");
 module_init(idetape_init);
 module_exit(idetape_exit);
 MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR);
+MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
+MODULE_LICENSE("GPL");
index 16a9a581d089501053a6a6efd822c0b98d485da9..0518a2e948cf46f9317f8ef27e4a4121c6df08ae 100644 (file)
@@ -189,12 +189,11 @@ EXPORT_SYMBOL_GPL(do_rw_taskfile);
  */
 static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
-       u8 stat;
+       u8 stat = ide_read_status(drive);
 
-       if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
+       if (OK_STAT(stat, READY_STAT, BAD_STAT))
                drive->mult_count = drive->mult_req;
-       else {
+       else {
                drive->mult_req = drive->mult_count = 0;
                drive->special.b.recalibrate = 1;
                (void) ide_dump_status(drive, "set_multmode", stat);
@@ -207,11 +206,10 @@ static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
  */
 static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
        int retries = 5;
        u8 stat;
 
-       while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
+       while (((stat = ide_read_status(drive)) & BUSY_STAT) && retries--)
                udelay(10);
 
        if (OK_STAT(stat, READY_STAT, BAD_STAT))
@@ -230,10 +228,9 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
  */
 static ide_startstop_t recal_intr(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
-       u8 stat;
+       u8 stat = ide_read_status(drive);
 
-       if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
+       if (!OK_STAT(stat, READY_STAT, BAD_STAT))
                return ide_error(drive, "recal_intr", stat);
        return ide_stopped;
 }
@@ -244,23 +241,23 @@ static ide_startstop_t recal_intr(ide_drive_t *drive)
 static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
 {
        ide_task_t *args        = HWGROUP(drive)->rq->special;
-       ide_hwif_t *hwif        = HWIF(drive);
        u8 stat;
 
        local_irq_enable_in_hardirq();
-       if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
+       stat = ide_read_status(drive);
+
+       if (!OK_STAT(stat, READY_STAT, BAD_STAT))
                return ide_error(drive, "task_no_data_intr", stat);
                /* calls ide_end_drive_cmd */
-       }
+
        if (args)
-               ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
+               ide_end_drive_cmd(drive, stat, ide_read_error(drive));
 
        return ide_stopped;
 }
 
 static u8 wait_drive_not_busy(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
        int retries;
        u8 stat;
 
@@ -269,7 +266,9 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
         * This can take up to 10 usec, but we will wait max 1 ms.
         */
        for (retries = 0; retries < 100; retries++) {
-               if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT)
+               stat = ide_read_status(drive);
+
+               if (stat & BUSY_STAT)
                        udelay(10);
                else
                        break;
@@ -408,7 +407,7 @@ static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
 void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
 {
        if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
-               u8 err = drive->hwif->INB(IDE_ERROR_REG);
+               u8 err = ide_read_error(drive);
 
                ide_end_drive_cmd(drive, stat, err);
                return;
@@ -430,7 +429,7 @@ static ide_startstop_t task_in_intr(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = HWGROUP(drive)->rq;
-       u8 stat = hwif->INB(IDE_STATUS_REG);
+       u8 stat = ide_read_status(drive);
 
        /* new way for dealing with premature shared PCI interrupts */
        if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) {
@@ -465,7 +464,7 @@ static ide_startstop_t task_out_intr (ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = HWGROUP(drive)->rq;
-       u8 stat = hwif->INB(IDE_STATUS_REG);
+       u8 stat = ide_read_status(drive);
 
        if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
                return task_error(drive, rq, __FUNCTION__, stat);
@@ -755,6 +754,7 @@ int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
        u8 args[4], xfer_rate = 0;
        ide_task_t tfargs;
        struct ide_taskfile *tf = &tfargs.tf;
+       struct hd_driveid *id = drive->id;
 
        if (NULL == (void *) arg) {
                struct request rq;
@@ -792,10 +792,16 @@ int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
                        return -ENOMEM;
        }
 
-       if (set_transfer(drive, &tfargs)) {
+       if (tf->command == WIN_SETFEATURES &&
+           tf->feature == SETFEATURES_XFER &&
+           tf->nsect >= XFER_SW_DMA_0 &&
+           (id->dma_ultra || id->dma_mword || id->dma_1word)) {
                xfer_rate = args[1];
-               if (ide_ata66_check(drive, &tfargs))
+               if (tf->nsect > XFER_UDMA_2 && !eighty_ninty_three(drive)) {
+                       printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
+                                           "be set\n", drive->name);
                        goto abort;
+               }
        }
 
        err = ide_raw_taskfile(drive, &tfargs, buf, args[3]);
index adeda7626529eaa15ca17baa51d83f43a4cd8e3a..3b12ffe770712dd1f1a708c7852ff5745a9b6e2a 100644 (file)
@@ -199,7 +199,7 @@ static int ide_timing_compute(ide_drive_t *drive, short speed, struct ide_timing
        }
 
 /*
- * Lenghten active & recovery time so that cycle time is correct.
+ * Lengthen active & recovery time so that cycle time is correct.
  */
 
        if (t->act8b + t->rec8b < t->cyc8b) {
index ab9ca2b5b66cdd25d6e6d60a6559f8823cee47b1..ad0e9955f73c9ce38de7485b487bb778b9542e87 100644 (file)
@@ -499,6 +499,8 @@ void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
 /**
  *     ide_unregister          -       free an IDE interface
  *     @index: index of interface (will change soon to a pointer)
+ *     @init_default: init default hwif flag
+ *     @restore: restore hwif flag
  *
  *     Perform the final unregister of an IDE interface. At the moment
  *     we don't refcount interfaces so this will also get split up.
@@ -518,7 +520,7 @@ void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
  *     This is raving bonkers.
  */
 
-void ide_unregister(unsigned int index)
+void ide_unregister(unsigned int index, int init_default, int restore)
 {
        ide_drive_t *drive;
        ide_hwif_t *hwif, *g;
@@ -602,9 +604,12 @@ void ide_unregister(unsigned int index)
 
        /* restore hwif data to pristine status */
        ide_init_port_data(hwif, index);
-       init_hwif_default(hwif, index);
 
-       ide_hwif_restore(hwif, &tmp_hwif);
+       if (init_default)
+               init_hwif_default(hwif, index);
+
+       if (restore)
+               ide_hwif_restore(hwif, &tmp_hwif);
 
 abort:
        spin_unlock_irq(&ide_lock);
@@ -613,60 +618,6 @@ abort:
 
 EXPORT_SYMBOL(ide_unregister);
 
-
-/**
- *     ide_setup_ports         -       set up IDE interface ports
- *     @hw: register descriptions
- *     @base: base register
- *     @offsets: table of register offsets
- *     @ctrl: control register
- *     @ack_irq: IRQ ack
- *     @irq: interrupt lie
- *
- *     Setup hw_regs_t structure described by parameters.  You
- *     may set up the hw structure yourself OR use this routine to
- *     do it for you. This is basically a helper
- *
- */
-void ide_setup_ports ( hw_regs_t *hw,
-                       unsigned long base, int *offsets,
-                       unsigned long ctrl, unsigned long intr,
-                       ide_ack_intr_t *ack_intr,
-/*
- *                     ide_io_ops_t *iops,
- */
-                       int irq)
-{
-       int i;
-
-       memset(hw, 0, sizeof(hw_regs_t));
-       for (i = 0; i < IDE_NR_PORTS; i++) {
-               if (offsets[i] == -1) {
-                       switch(i) {
-                               case IDE_CONTROL_OFFSET:
-                                       hw->io_ports[i] = ctrl;
-                                       break;
-#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
-                               case IDE_IRQ_OFFSET:
-                                       hw->io_ports[i] = intr;
-                                       break;
-#endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
-                               default:
-                                       hw->io_ports[i] = 0;
-                                       break;
-                       }
-               } else {
-                       hw->io_ports[i] = base + offsets[i];
-               }
-       }
-       hw->irq = irq;
-       hw->ack_intr = ack_intr;
-/*
- *     hw->iops = iops;
- */
-}
-
 void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
 {
        memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
@@ -678,6 +629,31 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
 }
 EXPORT_SYMBOL_GPL(ide_init_port_hw);
 
+ide_hwif_t *ide_deprecated_find_port(unsigned long base)
+{
+       ide_hwif_t *hwif;
+       int i;
+
+       for (i = 0; i < MAX_HWIFS; i++) {
+               hwif = &ide_hwifs[i];
+               if (hwif->io_ports[IDE_DATA_OFFSET] == base)
+                       goto found;
+       }
+
+       for (i = 0; i < MAX_HWIFS; i++) {
+               hwif = &ide_hwifs[i];
+               if (hwif->hold)
+                       continue;
+               if (!hwif->present && hwif->mate == NULL)
+                       goto found;
+       }
+
+       hwif = NULL;
+found:
+       return hwif;
+}
+EXPORT_SYMBOL_GPL(ide_deprecated_find_port);
+
 /**
  *     ide_register_hw         -       register IDE interface
  *     @hw: hardware registers
@@ -697,38 +673,26 @@ int ide_register_hw(hw_regs_t *hw, void (*quirkproc)(ide_drive_t *),
        u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
 
        do {
-               for (index = 0; index < MAX_HWIFS; ++index) {
-                       hwif = &ide_hwifs[index];
-                       if (hwif->io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
-                               goto found;
-               }
-               for (index = 0; index < MAX_HWIFS; ++index) {
-                       hwif = &ide_hwifs[index];
-                       if (hwif->hold)
-                               continue;
-                       if (!hwif->present && hwif->mate == NULL)
-                               goto found;
-               }
+               hwif = ide_deprecated_find_port(hw->io_ports[IDE_DATA_OFFSET]);
+               index = hwif->index;
+               if (hwif)
+                       goto found;
                for (index = 0; index < MAX_HWIFS; index++)
-                       ide_unregister(index);
+                       ide_unregister(index, 1, 1);
        } while (retry--);
        return -1;
 found:
        if (hwif->present)
-               ide_unregister(index);
-       else if (!hwif->hold) {
+               ide_unregister(index, 0, 1);
+       else if (!hwif->hold)
                ide_init_port_data(hwif, index);
-               init_hwif_default(hwif, index);
-       }
-       if (hwif->present)
-               return -1;
 
        ide_init_port_hw(hwif, hw);
        hwif->quirkproc = quirkproc;
 
        idx[0] = index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, NULL);
 
        if (hwifp)
                *hwifp = hwif;
@@ -791,10 +755,6 @@ int set_io_32bit(ide_drive_t *drive, int arg)
                return -EBUSY;
 
        drive->io_32bit = arg;
-#ifdef CONFIG_BLK_DEV_DTC2278
-       if (HWIF(drive)->chipset == ide_dtc2278)
-               HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
-#endif /* CONFIG_BLK_DEV_DTC2278 */
 
        spin_unlock_irq(&ide_lock);
 
@@ -1021,11 +981,8 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
                case HDIO_GET_NICE:
                        return put_user(drive->dsc_overlap      <<      IDE_NICE_DSC_OVERLAP    |
                                        drive->atapi_overlap    <<      IDE_NICE_ATAPI_OVERLAP  |
-                                       drive->nice0            <<      IDE_NICE_0              |
-                                       drive->nice1            <<      IDE_NICE_1              |
-                                       drive->nice2            <<      IDE_NICE_2,
+                                       drive->nice1 << IDE_NICE_1,
                                        (long __user *) arg);
-
 #ifdef CONFIG_IDE_TASK_IOCTL
                case HDIO_DRIVE_TASKFILE:
                        if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
@@ -1066,7 +1023,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
                case HDIO_UNREGISTER_HWIF:
                        if (!capable(CAP_SYS_RAWIO)) return -EACCES;
                        /* (arg > MAX_HWIFS) checked in function */
-                       ide_unregister(arg);
+                       ide_unregister(arg, 1, 1);
                        return 0;
                case HDIO_SET_NICE:
                        if (!capable(CAP_SYS_ADMIN)) return -EACCES;
@@ -1711,7 +1668,7 @@ void __exit cleanup_module (void)
        int index;
 
        for (index = 0; index < MAX_HWIFS; ++index)
-               ide_unregister(index);
+               ide_unregister(index, 0, 0);
 
        proc_ide_destroy();
 
index e3ea2096804ad752517862a89a0af1ecd5f19d39..d4d1a6bea599e3bf93dbae01d4e05dc5ffd2d9f7 100644 (file)
@@ -191,9 +191,14 @@ static int __init initRegisters (void) {
        return t;
 }
 
+static const struct ide_port_info ali14xx_port_info = {
+       .chipset                = ide_ali14xx,
+       .host_flags             = IDE_HFLAG_NO_DMA | IDE_HFLAG_NO_AUTOTUNE,
+       .pio_mask               = ATA_PIO4,
+};
+
 static int __init ali14xx_probe(void)
 {
-       ide_hwif_t *hwif, *mate;
        static u8 idx[4] = { 0, 1, 0xff, 0xff };
 
        printk(KERN_DEBUG "ali14xx: base=0x%03x, regOn=0x%02x.\n",
@@ -205,21 +210,10 @@ static int __init ali14xx_probe(void)
                return 1;
        }
 
-       hwif = &ide_hwifs[0];
-       mate = &ide_hwifs[1];
-
-       hwif->chipset = ide_ali14xx;
-       hwif->pio_mask = ATA_PIO4;
-       hwif->set_pio_mode = &ali14xx_set_pio_mode;
-       hwif->mate = mate;
-
-       mate->chipset = ide_ali14xx;
-       mate->pio_mask = ATA_PIO4;
-       mate->set_pio_mode = &ali14xx_set_pio_mode;
-       mate->mate = hwif;
-       mate->channel = 1;
+       ide_hwifs[0].set_pio_mode = &ali14xx_set_pio_mode;
+       ide_hwifs[1].set_pio_mode = &ali14xx_set_pio_mode;
 
-       ide_device_add(idx);
+       ide_device_add(idx, &ali14xx_port_info);
 
        return 0;
 }
index dd3d198ade47ba3c61d3dc45c2cf8afccbed28b0..50ffa871d5e937b190490f4be21f68f98f6667b5 100644 (file)
@@ -56,31 +56,11 @@ static u_int xsurf_bases[XSURF_NUM_HWIFS] __initdata = {
      XSURF_BASE1, XSURF_BASE2
 };
 
-
     /*
      *  Offsets from one of the above bases
      */
 
-#define BUDDHA_DATA    0x00
-#define BUDDHA_ERROR   0x06            /* see err-bits */
-#define BUDDHA_NSECTOR 0x0a            /* nr of sectors to read/write */
-#define BUDDHA_SECTOR  0x0e            /* starting sector */
-#define BUDDHA_LCYL    0x12            /* starting cylinder */
-#define BUDDHA_HCYL    0x16            /* high byte of starting cyl */
-#define BUDDHA_SELECT  0x1a            /* 101dhhhh , d=drive, hhhh=head */
-#define BUDDHA_STATUS  0x1e            /* see status-bits */
 #define BUDDHA_CONTROL 0x11a
-#define XSURF_CONTROL   -1              /* X-Surf has no CS1* (Control/AltStat) */
-
-static int buddha_offsets[IDE_NR_PORTS] __initdata = {
-    BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL,
-    BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, BUDDHA_CONTROL, -1
-};
-
-static int xsurf_offsets[IDE_NR_PORTS] __initdata = {
-    BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL,
-    BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, XSURF_CONTROL, -1
-};
 
     /*
      *  Other registers
@@ -140,6 +120,26 @@ static int xsurf_ack_intr(ide_hwif_t *hwif)
     return 1;
 }
 
+static void __init buddha_setup_ports(hw_regs_t *hw, unsigned long base,
+                                     unsigned long ctl, unsigned long irq_port,
+                                     ide_ack_intr_t *ack_intr)
+{
+       int i;
+
+       memset(hw, 0, sizeof(*hw));
+
+       hw->io_ports[IDE_DATA_OFFSET] = base;
+
+       for (i = 1; i < 8; i++)
+               hw->io_ports[i] = base + 2 + i * 4;
+
+       hw->io_ports[IDE_CONTROL_OFFSET] = ctl;
+       hw->io_ports[IDE_IRQ_OFFSET] = irq_port;
+
+       hw->irq = IRQ_AMIGA_PORTS;
+       hw->ack_intr = ack_intr;
+}
+
     /*
      *  Probe for a Buddha or Catweasel IDE interface
      */
@@ -202,22 +202,24 @@ fail_base2:
                printk(KERN_INFO "ide: %s IDE controller\n",
                                 buddha_board_name[type]);
 
-               for(i=0;i<buddha_num_hwifs;i++) {
-                       if(type != BOARD_XSURF) {
-                               ide_setup_ports(&hw, (buddha_board+buddha_bases[i]),
-                                               buddha_offsets, 0,
-                                               (buddha_board+buddha_irqports[i]),
-                                               buddha_ack_intr,
-//                                             budda_iops,
-                                               IRQ_AMIGA_PORTS);
+               for (i = 0; i < buddha_num_hwifs; i++) {
+                       unsigned long base, ctl, irq_port;
+                       ide_ack_intr_t *ack_intr;
+
+                       if (type != BOARD_XSURF) {
+                               base = buddha_board + buddha_bases[i];
+                               ctl = base + BUDDHA_CONTROL;
+                               irq_port = buddha_board + buddha_irqports[i];
+                               ack_intr = buddha_ack_intr;
                        } else {
-                               ide_setup_ports(&hw, (buddha_board+xsurf_bases[i]),
-                                               xsurf_offsets, 0,
-                                               (buddha_board+xsurf_irqports[i]),
-                                               xsurf_ack_intr,
-//                                             xsurf_iops,
-                                               IRQ_AMIGA_PORTS);
-                       }       
+                               base = buddha_board + xsurf_bases[i];
+                               /* X-Surf has no CS1* (Control/AltStat) */
+                               ctl = 0;
+                               irq_port = buddha_board + xsurf_irqports[i];
+                               ack_intr = xsurf_ack_intr;
+                       }
+
+                       buddha_setup_ports(&hw, base, ctl, irq_port, ack_intr);
 
                        hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
                        if (hwif) {
@@ -232,7 +234,7 @@ fail_base2:
                        }
                }
 
-               ide_device_add(idx);
+               ide_device_add(idx, NULL);
        }
 
        return 0;
index 611c9705a3aec88946b8b82c547a9eea9b23bf51..73396f70f2b74c6aed1b5a7c41da3dde495d4fe2 100644 (file)
@@ -84,14 +84,20 @@ static void dtc2278_set_pio_mode(ide_drive_t *drive, const u8 pio)
                /* Actually we do - there is a data sheet available for the
                   Winbond but does anyone actually care */
        }
-
-       /*
-        * 32bit I/O has to be enabled for *both* drives at the same time.
-        */
-       drive->io_32bit = 1;
-       HWIF(drive)->drives[!drive->select.b.unit].io_32bit = 1;
 }
 
+static const struct ide_port_info dtc2278_port_info __initdata = {
+       .chipset                = ide_dtc2278,
+       .host_flags             = IDE_HFLAG_SERIALIZE |
+                                 IDE_HFLAG_NO_UNMASK_IRQS |
+                                 IDE_HFLAG_IO_32BIT |
+                                 /* disallow ->io_32bit changes */
+                                 IDE_HFLAG_NO_IO_32BIT |
+                                 IDE_HFLAG_NO_DMA |
+                                 IDE_HFLAG_NO_AUTOTUNE,
+       .pio_mask               = ATA_PIO4,
+};
+
 static int __init dtc2278_probe(void)
 {
        unsigned long flags;
@@ -122,23 +128,9 @@ static int __init dtc2278_probe(void)
 #endif
        local_irq_restore(flags);
 
-       hwif->serialized = 1;
-       hwif->chipset = ide_dtc2278;
-       hwif->pio_mask = ATA_PIO4;
        hwif->set_pio_mode = &dtc2278_set_pio_mode;
-       hwif->drives[0].no_unmask = 1;
-       hwif->drives[1].no_unmask = 1;
-       hwif->mate = mate;
-
-       mate->serialized = 1;
-       mate->chipset = ide_dtc2278;
-       mate->pio_mask = ATA_PIO4;
-       mate->drives[0].no_unmask = 1;
-       mate->drives[1].no_unmask = 1;
-       mate->mate = hwif;
-       mate->channel = 1;
-
-       ide_device_add(idx);
+
+       ide_device_add(idx, &dtc2278_port_info);
 
        return 0;
 }
index c9bd6bfb1f3b788a3eee877bfae5b1affcf7a763..f044048903b3ebc8af7b3f67aa4cb8a073c89bc7 100644 (file)
      *  Offsets from the above base
      */
 
-#define ATA_HD_DATA    0x00
-#define ATA_HD_ERROR   0x05            /* see err-bits */
-#define ATA_HD_NSECTOR 0x09            /* nr of sectors to read/write */
-#define ATA_HD_SECTOR  0x0d            /* starting sector */
-#define ATA_HD_LCYL    0x11            /* starting cylinder */
-#define ATA_HD_HCYL    0x15            /* high byte of starting cyl */
-#define ATA_HD_SELECT  0x19            /* 101dhhhh , d=drive, hhhh=head */
-#define ATA_HD_STATUS  0x1d            /* see status-bits */
 #define ATA_HD_CONTROL 0x39
 
-static int falconide_offsets[IDE_NR_PORTS] __initdata = {
-    ATA_HD_DATA, ATA_HD_ERROR, ATA_HD_NSECTOR, ATA_HD_SECTOR, ATA_HD_LCYL,
-    ATA_HD_HCYL, ATA_HD_SELECT, ATA_HD_STATUS, ATA_HD_CONTROL, -1
-};
-
-
     /*
      *  falconide_intr_lock is used to obtain access to the IDE interrupt,
      *  which is shared between several drivers.
@@ -57,6 +43,22 @@ static int falconide_offsets[IDE_NR_PORTS] __initdata = {
 int falconide_intr_lock;
 EXPORT_SYMBOL(falconide_intr_lock);
 
+static void __init falconide_setup_ports(hw_regs_t *hw)
+{
+       int i;
+
+       memset(hw, 0, sizeof(*hw));
+
+       hw->io_ports[IDE_DATA_OFFSET] = ATA_HD_BASE;
+
+       for (i = 1; i < 8; i++)
+               hw->io_ports[i] = ATA_HD_BASE + 1 + i * 4;
+
+       hw->io_ports[IDE_CONTROL_OFFSET] = ATA_HD_CONTROL;
+
+       hw->irq = IRQ_MFP_IDE;
+       hw->ack_intr = NULL;
+}
 
     /*
      *  Probe for a Falcon IDE interface
@@ -64,16 +66,15 @@ EXPORT_SYMBOL(falconide_intr_lock);
 
 static int __init falconide_init(void)
 {
-    if (MACH_IS_ATARI && ATARIHW_PRESENT(IDE)) {
        hw_regs_t hw;
        ide_hwif_t *hwif;
 
+       if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
+               return 0;
+
        printk(KERN_INFO "ide: Falcon IDE controller\n");
 
-       ide_setup_ports(&hw, ATA_HD_BASE, falconide_offsets,
-                       0, 0, NULL,
-//                     falconide_iops,
-                       IRQ_MFP_IDE);
+       falconide_setup_ports(&hw);
 
        hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
        if (hwif) {
@@ -83,11 +84,10 @@ static int __init falconide_init(void)
                ide_init_port_data(hwif, index);
                ide_init_port_hw(hwif, &hw);
 
-               ide_device_add(idx);
+               ide_device_add(idx, NULL);
        }
-    }
 
-    return 0;
+       return 0;
 }
 
 module_init(falconide_init);
index f67c51a2c84add49d81e10d35cb11b1acec2a391..9d3851d27677785ff331fc8908cd93e9e5da81ed 100644 (file)
      *  Offsets from one of the above bases
      */
 
-#define GAYLE_DATA     0x00
-#define GAYLE_ERROR    0x06            /* see err-bits */
-#define GAYLE_NSECTOR  0x0a            /* nr of sectors to read/write */
-#define GAYLE_SECTOR   0x0e            /* starting sector */
-#define GAYLE_LCYL     0x12            /* starting cylinder */
-#define GAYLE_HCYL     0x16            /* high byte of starting cyl */
-#define GAYLE_SELECT   0x1a            /* 101dhhhh , d=drive, hhhh=head */
-#define GAYLE_STATUS   0x1e            /* see status-bits */
 #define GAYLE_CONTROL  0x101a
 
-static int gayle_offsets[IDE_NR_PORTS] __initdata = {
-    GAYLE_DATA, GAYLE_ERROR, GAYLE_NSECTOR, GAYLE_SECTOR, GAYLE_LCYL,
-    GAYLE_HCYL, GAYLE_SELECT, GAYLE_STATUS, -1, -1
-};
-
-
     /*
      *  These are at different offsets from the base
      */
@@ -106,6 +92,26 @@ static int gayle_ack_intr_a1200(ide_hwif_t *hwif)
     return 1;
 }
 
+static void __init gayle_setup_ports(hw_regs_t *hw, unsigned long base,
+                                    unsigned long ctl, unsigned long irq_port,
+                                    ide_ack_intr_t *ack_intr);
+{
+       int i;
+
+       memset(hw, 0, sizeof(*hw));
+
+       hw->io_ports[IDE_DATA_OFFSET] = base;
+
+       for (i = 1; i < 8; i++)
+               hw->io_ports[i] = base + 2 + i * 4;
+
+       hw->io_ports[IDE_CONTROL_OFFSET] = ctl;
+       hw->io_ports[IDE_IRQ_OFFSET] = irq_port;
+
+       hw->irq = IRQ_AMIGA_PORTS;
+       hw->ack_intr = ack_intr;
+}
+
     /*
      *  Probe for a Gayle IDE interface (and optionally for an IDE doubler)
      */
@@ -167,10 +173,7 @@ found:
        base = (unsigned long)ZTWO_VADDR(phys_base);
        ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
 
-       ide_setup_ports(&hw, base, gayle_offsets,
-                       ctrlport, irqport, ack_intr,
-//                     &gayle_iops,
-                       IRQ_AMIGA_PORTS);
+       gayle_setup_ports(&hw, base, ctrlport, irqport, ack_intr);
 
        hwif = ide_find_port(base);
        if (hwif) {
@@ -186,7 +189,7 @@ found:
            release_mem_region(res_start, res_n);
     }
 
-    ide_device_add(idx);
+    ide_device_add(idx, NULL);
 
     return 0;
 }
index 8e05d88e81babd0e74560821e80065dfa18e79d7..0b0d867319278af5e652d1310f887f0dafc915fa 100644 (file)
@@ -421,11 +421,14 @@ static void bad_rw_intr(void)
 
 static inline int wait_DRQ(void)
 {
-       int retries = 100000, stat;
+       int retries;
+       int stat;
 
-       while (--retries > 0)
-               if ((stat = inb_p(HD_STATUS)) & DRQ_STAT)
+       for (retries = 0; retries < 100000; retries++) {
+               stat = inb_p(HD_STATUS);
+               if (stat & DRQ_STAT)
                        return 0;
+       }
        dump_status("wait_DRQ", stat);
        return -1;
 }
index 57bc15cddca0d6d12edc8559e2fb5e6d367a6fd0..02d12c74764a6a6fcd38935f8cbba4286398b4f7 100644 (file)
@@ -300,16 +300,36 @@ static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio)
 #endif
 }
 
+static void __init ht6560b_port_init_devs(ide_hwif_t *hwif)
+{
+       /* Setting default configurations for drives. */
+       int t = (HT_CONFIG_DEFAULT << 8) | HT_TIMING_DEFAULT;
+
+       if (hwif->channel)
+               t |= (HT_SECONDARY_IF << 8);
+
+       hwif->drives[0].drive_data = t;
+       hwif->drives[1].drive_data = t;
+}
+
 int probe_ht6560b = 0;
 
 module_param_named(probe, probe_ht6560b, bool, 0);
 MODULE_PARM_DESC(probe, "probe for HT6560B chipset");
 
+static const struct ide_port_info ht6560b_port_info __initdata = {
+       .chipset                = ide_ht6560b,
+       .host_flags             = IDE_HFLAG_SERIALIZE | /* is this needed? */
+                                 IDE_HFLAG_NO_DMA |
+                                 IDE_HFLAG_NO_AUTOTUNE |
+                                 IDE_HFLAG_ABUSE_PREFETCH,
+       .pio_mask               = ATA_PIO5,
+};
+
 static int __init ht6560b_init(void)
 {
        ide_hwif_t *hwif, *mate;
        static u8 idx[4] = { 0, 1, 0xff, 0xff };
-       int t;
 
        if (probe_ht6560b == 0)
                return -ENODEV;
@@ -328,36 +348,16 @@ static int __init ht6560b_init(void)
                goto release_region;
        }
 
-       hwif->chipset = ide_ht6560b;
        hwif->selectproc = &ht6560b_selectproc;
-       hwif->host_flags = IDE_HFLAG_ABUSE_PREFETCH;
-       hwif->pio_mask = ATA_PIO5;
        hwif->set_pio_mode = &ht6560b_set_pio_mode;
-       hwif->serialized = 1;   /* is this needed? */
-       hwif->mate = mate;
 
-       mate->chipset = ide_ht6560b;
        mate->selectproc = &ht6560b_selectproc;
-       mate->host_flags = IDE_HFLAG_ABUSE_PREFETCH;
-       mate->pio_mask = ATA_PIO5;
        mate->set_pio_mode = &ht6560b_set_pio_mode;
-       mate->serialized = 1;   /* is this needed? */
-       mate->mate = hwif;
-       mate->channel = 1;
-
-       /*
-        * Setting default configurations for drives
-        */
-       t = (HT_CONFIG_DEFAULT << 8);
-       t |= HT_TIMING_DEFAULT;
-       hwif->drives[0].drive_data = t;
-       hwif->drives[1].drive_data = t;
 
-       t |= (HT_SECONDARY_IF << 8);
-       mate->drives[0].drive_data = t;
-       mate->drives[1].drive_data = t;
+       hwif->port_init_devs = ht6560b_port_init_devs;
+       mate->port_init_devs = ht6560b_port_init_devs;
 
-       ide_device_add(idx);
+       ide_device_add(idx, &ht6560b_port_info);
 
        return 0;
 
index 3bd29676ef6ad14358bdbe9d18e2c468883bf8c8..15ccf6944ae21565a3829e2ecdfcaea3d7c6080e 100644 (file)
@@ -145,13 +145,36 @@ static void ide_detach(struct pcmcia_device *link)
 
 static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle)
 {
+    ide_hwif_t *hwif;
     hw_regs_t hw;
+    int i;
+    u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
+
     memset(&hw, 0, sizeof(hw));
-    ide_init_hwif_ports(&hw, io, ctl, NULL);
+    ide_std_init_ports(&hw, io, ctl);
     hw.irq = irq;
     hw.chipset = ide_pci;
     hw.dev = &handle->dev;
-    return ide_register_hw(&hw, &ide_undecoded_slave, NULL);
+
+    hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]);
+    if (hwif == NULL)
+       return -1;
+
+    i = hwif->index;
+
+    if (hwif->present)
+       ide_unregister(i, 0, 0);
+    else if (!hwif->hold)
+       ide_init_port_data(hwif, i);
+
+    ide_init_port_hw(hwif, &hw);
+    hwif->quirkproc = &ide_undecoded_slave;
+
+    idx[0] = i;
+
+    ide_device_add(idx, NULL);
+
+    return hwif->present ? i : -1;
 }
 
 /*======================================================================
@@ -337,7 +360,7 @@ void ide_release(struct pcmcia_device *link)
     if (info->ndev) {
        /* FIXME: if this fails we need to queue the cleanup somehow
           -- need to investigate the required PCMCIA magic */
-       ide_unregister(info->hd);
+       ide_unregister(info->hd, 0, 0);
     }
     info->ndev = 0;
 
index 7c3231a21d176067c781665471c7e66d4381c5c6..688fcae17488d85505d6a44cd6a2c36fa87e0c9a 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/ide.h>
 #include <linux/ioport.h>
 #include <linux/module.h>
-#include <linux/pata_platform.h>
+#include <linux/ata_platform.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
 
@@ -108,7 +108,7 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
 
        idx[0] = hwif->index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, NULL);
 
        platform_set_drvdata(pdev, hwif);
 
@@ -122,7 +122,7 @@ static int __devexit plat_ide_remove(struct platform_device *pdev)
 {
        ide_hwif_t *hwif = pdev->dev.driver_data;
 
-       ide_unregister(hwif->index);
+       ide_unregister(hwif->index, 0, 0);
 
        return 0;
 }
index c54d07ff64fe62910ca9f1f8445fda3483b7fb51..a61e60737dc70d658c74eb060a6cc678a9a41a8f 100644 (file)
  * These match MkLinux so they should be correct.
  */
 
-#define IDE_DATA       0x00
-#define IDE_ERROR      0x04    /* see err-bits */
-#define IDE_NSECTOR    0x08    /* nr of sectors to read/write */
-#define IDE_SECTOR     0x0c    /* starting sector */
-#define IDE_LCYL       0x10    /* starting cylinder */
-#define IDE_HCYL       0x14    /* high byte of starting cyl */
-#define IDE_SELECT     0x18    /* 101dhhhh , d=drive, hhhh=head */
-#define IDE_STATUS     0x1c    /* see status-bits */
 #define IDE_CONTROL    0x38    /* control/altstatus */
 
 /*
 
 volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR);
 
-static int macide_offsets[IDE_NR_PORTS] = {
-    IDE_DATA, IDE_ERROR,  IDE_NSECTOR, IDE_SECTOR, IDE_LCYL,
-    IDE_HCYL, IDE_SELECT, IDE_STATUS,  IDE_CONTROL
-};
-
 int macide_ack_intr(ide_hwif_t* hwif)
 {
        if (*ide_ifr & 0x20) {
@@ -77,6 +64,22 @@ int macide_ack_intr(ide_hwif_t* hwif)
        return 0;
 }
 
+static void __init macide_setup_ports(hw_regs_t *hw, unsigned long base,
+                                     int irq, ide_ack_intr_t *ack_intr)
+{
+       int i;
+
+       memset(hw, 0, sizeof(*hw));
+
+       for (i = 0; i < 8; i++)
+               hw->io_ports[i] = base + i * 4;
+
+       hw->io_ports[IDE_CONTROL_OFFSET] = IDE_CONTROL;
+
+       hw->irq = irq;
+       hw->ack_intr = ack_intr;
+}
+
 static const char *mac_ide_name[] =
        { "Quadra", "Powerbook", "Powerbook Baboon" };
 
@@ -86,27 +89,27 @@ static const char *mac_ide_name[] =
 
 static int __init macide_init(void)
 {
-       hw_regs_t hw;
        ide_hwif_t *hwif;
+       ide_ack_intr_t *ack_intr;
+       unsigned long base;
+       int irq;
+       hw_regs_t hw;
 
        switch (macintosh_config->ide_type) {
        case MAC_IDE_QUADRA:
-               ide_setup_ports(&hw, IDE_BASE, macide_offsets,
-                               0, 0, macide_ack_intr,
-//                             quadra_ide_iops,
-                               IRQ_NUBUS_F);
+               base = IDE_BASE;
+               ack_intr = macide_ack_intr;
+               irq = IRQ_NUBUS_F;
                break;
        case MAC_IDE_PB:
-               ide_setup_ports(&hw, IDE_BASE, macide_offsets,
-                               0, 0, macide_ack_intr,
-//                             macide_pb_iops,
-                               IRQ_NUBUS_C);
+               base = IDE_BASE;
+               ack_intr = macide_ack_intr;
+               irq = IRQ_NUBUS_C;
                break;
        case MAC_IDE_BABOON:
-               ide_setup_ports(&hw, BABOON_BASE, macide_offsets,
-                               0, 0, NULL,
-//                             macide_baboon_iops,
-                               IRQ_BABOON_1);
+               base = BABOON_BASE;
+               ack_intr = NULL;
+               irq = IRQ_BABOON_1;
                break;
        default:
                return -ENODEV;
@@ -115,6 +118,8 @@ static int __init macide_init(void)
        printk(KERN_INFO "ide: Macintosh %s IDE controller\n",
                         mac_ide_name[macintosh_config->ide_type - 1]);
 
+       macide_setup_ports(&hw, base, irq, ack_intr);
+
        hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
        if (hwif) {
                u8 index = hwif->index;
@@ -123,19 +128,9 @@ static int __init macide_init(void)
                ide_init_port_data(hwif, index);
                ide_init_port_hw(hwif, &hw);
 
-               if (macintosh_config->ide_type == MAC_IDE_BABOON &&
-                   macintosh_config->ident == MAC_MODEL_PB190) {
-                       /* Fix breakage in ide-disk.c: drive capacity   */
-                       /* is not initialized for drives without a      */
-                       /* hardware ID, and we can't get that without   */
-                       /* probing the drive which freezes a 190.       */
-                       ide_drive_t *drive = &hwif->drives[0];
-                       drive->capacity64 = drive->cyl*drive->head*drive->sect;
-               }
-
                hwif->mmio = 1;
 
-               ide_device_add(idx);
+               ide_device_add(idx, NULL);
        }
 
        return 0;
index a9c6b0609c54c30c7500c6960e33e927ccfcc409..1381b91bc316e3982671bf281b2455ac7ff8c02b 100644 (file)
@@ -66,16 +66,12 @@ static int q40ide_default_irq(unsigned long base)
 
 
 /*
- * This is very similar to ide_setup_ports except that addresses
- * are pretranslated for q40 ISA access
+ * Addresses are pretranslated for Q40 ISA access.
  */
 void q40_ide_setup_ports ( hw_regs_t *hw,
                        unsigned long base, int *offsets,
                        unsigned long ctrl, unsigned long intr,
                        ide_ack_intr_t *ack_intr,
-/*
- *                     ide_io_ops_t *iops,
- */
                        int irq)
 {
        int i;
@@ -92,9 +88,6 @@ void q40_ide_setup_ports ( hw_regs_t *hw,
 
        hw->irq = irq;
        hw->ack_intr = ack_intr;
-/*
- *     hw->iops = iops;
- */
 }
 
 
@@ -154,7 +147,7 @@ static int __init q40ide_init(void)
        }
     }
 
-    ide_device_add(idx);
+    ide_device_add(idx, NULL);
 
     return 0;
 }
index 37534bb483a70c68be224655629ac45c4067c1d0..bba29df5f21d6094660c777724c38ef9d2de454b 100644 (file)
@@ -305,18 +305,33 @@ static int __init qd_testreg(int port)
  * called to setup an ata channel : adjusts attributes & links for tuning
  */
 
-static void __init qd_setup(ide_hwif_t *hwif, int base, int config,
-                           unsigned int data0, unsigned int data1)
+static void __init qd_setup(ide_hwif_t *hwif, int base, int config)
 {
-       hwif->chipset = ide_qd65xx;
-       hwif->channel = hwif->index;
        hwif->select_data = base;
        hwif->config_data = config;
-       hwif->drives[0].drive_data = data0;
-       hwif->drives[1].drive_data = data1;
-       hwif->drives[0].io_32bit =
-       hwif->drives[1].io_32bit = 1;
-       hwif->pio_mask = ATA_PIO4;
+}
+
+static void __init qd6500_port_init_devs(ide_hwif_t *hwif)
+{
+       u8 base = hwif->select_data, config = QD_CONFIG(hwif);
+
+       hwif->drives[0].drive_data = QD6500_DEF_DATA;
+       hwif->drives[1].drive_data = QD6500_DEF_DATA;
+}
+
+static void __init qd6580_port_init_devs(ide_hwif_t *hwif)
+{
+       u16 t1, t2;
+       u8 base = hwif->select_data, config = QD_CONFIG(hwif);
+
+       if (QD_CONTROL(hwif) & QD_CONTR_SEC_DISABLED) {
+               t1 = QD6580_DEF_DATA;
+               t2 = QD6580_DEF_DATA2;
+       } else
+               t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA;
+
+       hwif->drives[0].drive_data = t1;
+       hwif->drives[1].drive_data = t2;
 }
 
 /*
@@ -356,6 +371,14 @@ static void __exit qd_unsetup(ide_hwif_t *hwif)
 }
 */
 
+static const struct ide_port_info qd65xx_port_info __initdata = {
+       .chipset                = ide_qd65xx,
+       .host_flags             = IDE_HFLAG_IO_32BIT |
+                                 IDE_HFLAG_NO_DMA |
+                                 IDE_HFLAG_NO_AUTOTUNE,
+       .pio_mask               = ATA_PIO4,
+};
+
 /*
  * qd_probe:
  *
@@ -393,13 +416,14 @@ static int __init qd_probe(int base)
                        return 1;
                }
 
-               qd_setup(hwif, base, config, QD6500_DEF_DATA, QD6500_DEF_DATA);
+               qd_setup(hwif, base, config);
 
+               hwif->port_init_devs = qd6500_port_init_devs;
                hwif->set_pio_mode = &qd6500_set_pio_mode;
 
-               idx[0] = unit;
+               idx[unit] = unit;
 
-               ide_device_add(idx);
+               ide_device_add(idx, &qd65xx_port_info);
 
                return 1;
        }
@@ -426,14 +450,15 @@ static int __init qd_probe(int base)
                        hwif = &ide_hwifs[unit];
                        printk(KERN_INFO "%s: qd6580: single IDE board\n",
                                         hwif->name);
-                       qd_setup(hwif, base, config | (control << 8),
-                                QD6580_DEF_DATA, QD6580_DEF_DATA2);
 
+                       qd_setup(hwif, base, config | (control << 8));
+
+                       hwif->port_init_devs = qd6580_port_init_devs;
                        hwif->set_pio_mode = &qd6580_set_pio_mode;
 
-                       idx[0] = unit;
+                       idx[unit] = unit;
 
-                       ide_device_add(idx);
+                       ide_device_add(idx, &qd65xx_port_info);
 
                        outb(QD_DEF_CONTR, QD_CONTROL_PORT);
 
@@ -447,20 +472,20 @@ static int __init qd_probe(int base)
                        printk(KERN_INFO "%s&%s: qd6580: dual IDE board\n",
                                        hwif->name, mate->name);
 
-                       qd_setup(hwif, base, config | (control << 8),
-                                QD6580_DEF_DATA, QD6580_DEF_DATA);
+                       qd_setup(hwif, base, config | (control << 8));
 
+                       hwif->port_init_devs = qd6580_port_init_devs;
                        hwif->set_pio_mode = &qd6580_set_pio_mode;
 
-                       qd_setup(mate, base, config | (control << 8),
-                                QD6580_DEF_DATA2, QD6580_DEF_DATA2);
+                       qd_setup(mate, base, config | (control << 8));
 
+                       mate->port_init_devs = qd6580_port_init_devs;
                        mate->set_pio_mode = &qd6580_set_pio_mode;
 
                        idx[0] = 0;
                        idx[1] = 1;
 
-                       ide_device_add(idx);
+                       ide_device_add(idx, &qd65xx_port_info);
 
                        outb(QD_DEF_CONTR, QD_CONTROL_PORT);
 
index 26f38ce58776d02acc4e8bc1e3796e2a13471ef0..5696ba026005359b0126acab59b48f27725f3ab9 100644 (file)
@@ -120,9 +120,14 @@ static void umc_set_pio_mode(ide_drive_t *drive, const u8 pio)
        spin_unlock_irqrestore(&ide_lock, flags);
 }
 
+static const struct ide_port_info umc8672_port_info __initdata = {
+       .chipset                = ide_umc8672,
+       .host_flags             = IDE_HFLAG_NO_DMA | IDE_HFLAG_NO_AUTOTUNE,
+       .pio_mask               = ATA_PIO4,
+};
+
 static int __init umc8672_probe(void)
 {
-       ide_hwif_t *hwif, *mate;
        unsigned long flags;
        static u8 idx[4] = { 0, 1, 0xff, 0xff };
 
@@ -143,21 +148,10 @@ static int __init umc8672_probe(void)
        umc_set_speeds (current_speeds);
        local_irq_restore(flags);
 
-       hwif = &ide_hwifs[0];
-       mate = &ide_hwifs[1];
-
-       hwif->chipset = ide_umc8672;
-       hwif->pio_mask = ATA_PIO4;
-       hwif->set_pio_mode = &umc_set_pio_mode;
-       hwif->mate = mate;
-
-       mate->chipset = ide_umc8672;
-       mate->pio_mask = ATA_PIO4;
-       mate->set_pio_mode = &umc_set_pio_mode;
-       mate->mate = hwif;
-       mate->channel = 1;
+       ide_hwifs[0].set_pio_mode = &umc_set_pio_mode;
+       ide_hwifs[1].set_pio_mode = &umc_set_pio_mode;
 
-       ide_device_add(idx);
+       ide_device_add(idx, &umc8672_port_info);
 
        return 0;
 }
index cd42b30a7a3b69f86c3f5d8c442bd0b643c0ec47..0f4bf5d7283598b20b7df331fc62a20085a1c03f 100644 (file)
@@ -548,6 +548,17 @@ static void auide_setup_ports(hw_regs_t *hw, _auide_hwif *ahwif)
        *ata_regs = ahwif->regbase + (14 << AU1XXX_ATA_REG_OFFSET);
 }
 
+static const struct ide_port_info au1xxx_port_info = {
+       .host_flags             = IDE_HFLAG_POST_SET_MODE |
+                                 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
+                                 IDE_HFLAG_NO_IO_32BIT |
+                                 IDE_HFLAG_UNMASK_IRQS,
+       .pio_mask               = ATA_PIO4,
+#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
+       .mwdma_mask             = ATA_MWDMA2,
+#endif
+};
+
 static int au_ide_probe(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
@@ -606,21 +617,6 @@ static int au_ide_probe(struct device *dev)
 
        hwif->dev = dev;
 
-       hwif->ultra_mask                = 0x0;  /* Disable Ultra DMA */
-#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
-       hwif->mwdma_mask                = 0x07; /* Multimode-2 DMA  */
-       hwif->swdma_mask                = 0x00;
-#else
-       hwif->mwdma_mask                = 0x0;
-       hwif->swdma_mask                = 0x0;
-#endif
-
-       hwif->pio_mask = ATA_PIO4;
-       hwif->host_flags = IDE_HFLAG_POST_SET_MODE;
-
-       hwif->drives[0].unmask          = 1;
-       hwif->drives[1].unmask          = 1;
-
        /* hold should be on in all cases */
        hwif->hold                      = 1;
 
@@ -651,16 +647,9 @@ static int au_ide_probe(struct device *dev)
        hwif->ide_dma_test_irq          = &auide_dma_test_irq;
        hwif->dma_lost_irq              = &auide_dma_lost_irq;
 #endif
-       hwif->channel                   = 0;
        hwif->select_data               = 0;    /* no chipset-specific code */
        hwif->config_data               = 0;    /* no chipset-specific code */
 
-       hwif->drives[0].autotune        = 1;    /* 1=autotune, 2=noautotune, 0=default */
-       hwif->drives[1].autotune        = 1;
-
-       hwif->drives[0].no_io_32bit     = 1;
-       hwif->drives[1].no_io_32bit     = 1;
-
        auide_hwif.hwif                 = hwif;
        hwif->hwif_data                 = &auide_hwif;
 
@@ -671,7 +660,7 @@ static int au_ide_probe(struct device *dev)
 
        idx[0] = hwif->index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, &au1xxx_port_info);
 
        dev_set_drvdata(dev, hwif);
 
@@ -688,7 +677,7 @@ static int au_ide_remove(struct device *dev)
        ide_hwif_t *hwif = dev_get_drvdata(dev);
        _auide_hwif *ahwif = &auide_hwif;
 
-       ide_unregister(hwif->index);
+       ide_unregister(hwif->index, 0, 0);
 
        iounmap((void *)ahwif->regbase);
 
index 8b3959dfa2b7b692c806fd979890900065dbd20a..956259fc09ba079ced2db086cdf6fbf6a63fcab5 100644 (file)
@@ -129,7 +129,7 @@ static int __devinit swarm_ide_probe(struct device *dev)
 
        idx[0] = hwif->index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, NULL);
 
        dev_set_drvdata(dev, hwif);
 
index 94803253e8af0268d1878833e7600d37035ace3a..02e6ee7d751defaad1fe96d081a881495ecceca5 100644 (file)
@@ -34,7 +34,8 @@ obj-$(CONFIG_BLK_DEV_TRM290)          += trm290.o
 obj-$(CONFIG_BLK_DEV_VIA82CXXX)                += via82cxxx.o
 
 # Must appear at the end of the block
-obj-$(CONFIG_BLK_DEV_GENERIC)          += generic.o
+obj-$(CONFIG_BLK_DEV_GENERIC)          += ide-pci-generic.o
+ide-pci-generic-y                      += generic.o
 
 ifeq ($(CONFIG_BLK_DEV_CMD640), m)
        obj-m += cmd640.o
index 824df78c70125966631c65dc450efb3dd67ee947..cfb3265bc1a8764befa33b60ca8b5ed23057260b 100644 (file)
@@ -7,7 +7,6 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
@@ -166,6 +165,16 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const ch
        return dev->irq;
 }
 
+static u8 __devinit atp86x_cable_detect(ide_hwif_t *hwif)
+{
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+       u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01;
+
+       pci_read_config_byte(dev, 0x49, &ata66);
+
+       return (ata66 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+}
+
 static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
 {
        struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -174,21 +183,10 @@ static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
 
        if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
                hwif->set_dma_mode = &aec6210_set_mode;
-       else
+       else {
                hwif->set_dma_mode = &aec6260_set_mode;
 
-       if (hwif->dma_base == 0)
-               return;
-
-       if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
-               return;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
-               u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01;
-
-               pci_read_config_byte(dev, 0x49, &ata66);
-
-               hwif->cbl = (ata66 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+               hwif->cable_detect = atp86x_cable_detect;
        }
 }
 
index 130cc6e784e552e7db3f842095e2ca9b8d83a6bd..b3b6f514ce2d8ac4d5775ebddb353f4907ca4460 100644 (file)
@@ -31,7 +31,6 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
@@ -666,13 +665,12 @@ static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
        hwif->set_dma_mode = &ali_set_dma_mode;
        hwif->udma_filter = &ali_udma_filter;
 
+       hwif->cable_detect = ata66_ali15x3;
+
        if (hwif->dma_base == 0)
                return;
 
        hwif->dma_setup = &ali15x3_dma_setup;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = ata66_ali15x3(hwif);
 }
 
 /**
index 8c52bc9eaa5910575d70c123e86ffd3edd1ecc55..2ef890ce80976fa83e6667f80ade5689df0899dc 100644 (file)
 
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
-#include <asm/io.h>
 
 #include "ide-timing.h"
 
@@ -199,6 +196,14 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev,
        return dev->irq;
 }
 
+static u8 __devinit amd_cable_detect(ide_hwif_t *hwif)
+{
+       if ((amd_80w >> hwif->channel) & 1)
+               return ATA_CBL_PATA80;
+       else
+               return ATA_CBL_PATA40;
+}
+
 static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
 {
        struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -209,15 +214,7 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
        hwif->set_pio_mode = &amd_set_pio_mode;
        hwif->set_dma_mode = &amd_set_drive;
 
-       if (!hwif->dma_base)
-               return;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
-               if ((amd_80w >> hwif->channel) & 1)
-                       hwif->cbl = ATA_CBL_PATA80;
-               else
-                       hwif->cbl = ATA_CBL_PATA40;
-       }
+       hwif->cable_detect = amd_cable_detect;
 }
 
 #define IDE_HFLAGS_AMD \
index b56274af17825735c1e8d1c0712e45cd28c18b4b..7e037c880cb0a62279f22dfc4654ef05ab446982 100644 (file)
@@ -6,15 +6,11 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/ioport.h>
 #include <linux/pci.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
-#include <linux/delay.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 #define ATIIXP_IDE_PIO_TIMING          0x40
 #define ATIIXP_IDE_MDMA_TIMING         0x44
 #define ATIIXP_IDE_PIO_CONTROL         0x48
@@ -121,6 +117,19 @@ static void atiixp_set_dma_mode(ide_drive_t *drive, const u8 speed)
        spin_unlock_irqrestore(&atiixp_lock, flags);
 }
 
+static u8 __devinit atiixp_cable_detect(ide_hwif_t *hwif)
+{
+       struct pci_dev *pdev = to_pci_dev(hwif->dev);
+       u8 udma_mode = 0, ch = hwif->channel;
+
+       pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
+
+       if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
+               return ATA_CBL_PATA80;
+       else
+               return ATA_CBL_PATA40;
+}
+
 /**
  *     init_hwif_atiixp                -       fill in the hwif for the ATIIXP
  *     @hwif: IDE interface
@@ -131,21 +140,10 @@ static void atiixp_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
 static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
 {
-       struct pci_dev *pdev = to_pci_dev(hwif->dev);
-       u8 udma_mode = 0, ch = hwif->channel;
-
        hwif->set_pio_mode = &atiixp_set_pio_mode;
        hwif->set_dma_mode = &atiixp_set_dma_mode;
 
-       if (!hwif->dma_base)
-               return;
-
-       pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
-
-       if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
-               hwif->cbl = ATA_CBL_PATA80;
-       else
-               hwif->cbl = ATA_CBL_PATA40;
+       hwif->cable_detect = atiixp_cable_detect;
 }
 
 static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
index 7240c20b9593f80b1d9e8154035729976db107b2..bd24dad3cfc6b2a82c990120ff7e10ac567599ab 100644 (file)
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
@@ -703,6 +699,18 @@ static int pci_conf2(void)
        return 0;
 }
 
+static const struct ide_port_info cmd640_port_info __initdata = {
+       .chipset                = ide_cmd640,
+       .host_flags             = IDE_HFLAG_SERIALIZE |
+                                 IDE_HFLAG_NO_DMA |
+                                 IDE_HFLAG_NO_AUTOTUNE |
+                                 IDE_HFLAG_ABUSE_PREFETCH |
+                                 IDE_HFLAG_ABUSE_FAST_DEVSEL,
+#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
+       .pio_mask               = ATA_PIO5,
+#endif
+};
+
 /*
  * Probe for a cmd640 chipset, and initialize it if found.
  */
@@ -760,11 +768,7 @@ static int __init cmd640x_init(void)
        setup_device_ptrs ();
        printk("%s: buggy cmd640%c interface on %s, config=0x%02x\n",
               cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr);
-       cmd_hwif0->chipset = ide_cmd640;
 #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
-       cmd_hwif0->host_flags = IDE_HFLAG_ABUSE_PREFETCH |
-                               IDE_HFLAG_ABUSE_FAST_DEVSEL;
-       cmd_hwif0->pio_mask = ATA_PIO5;
        cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode;
 #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
 
@@ -815,23 +819,14 @@ static int __init cmd640x_init(void)
         * Initialize data for secondary cmd640 port, if enabled
         */
        if (second_port_cmd640) {
-               cmd_hwif0->serialized = 1;
-               cmd_hwif1->serialized = 1;
-               cmd_hwif1->chipset = ide_cmd640;
-               cmd_hwif0->mate = cmd_hwif1;
-               cmd_hwif1->mate = cmd_hwif0;
-               cmd_hwif1->channel = 1;
 #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
-               cmd_hwif1->host_flags = IDE_HFLAG_ABUSE_PREFETCH |
-                                       IDE_HFLAG_ABUSE_FAST_DEVSEL;
-               cmd_hwif1->pio_mask = ATA_PIO5;
                cmd_hwif1->set_pio_mode = &cmd640_set_pio_mode;
 #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
 
                idx[1] = cmd_hwif1->index;
        }
        printk(KERN_INFO "%s: %sserialized, secondary interface %s\n", cmd_hwif1->name,
-               cmd_hwif0->serialized ? "" : "not ", port2);
+                        second_port_cmd640 ? "" : "not ", port2);
 
        /*
         * Establish initial timings/prefetch for all drives.
@@ -876,7 +871,7 @@ static int __init cmd640x_init(void)
        cmd640_dump_regs();
 #endif
 
-       ide_device_add(idx);
+       ide_device_add(idx, &cmd640_port_info);
 
        return 1;
 }
index 04aa9e59670ea5413f184637bdcd490cad9527b2..edabe6299efdf58ca2b6806600c7191b45fed0fa 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
@@ -393,6 +392,8 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
        hwif->set_pio_mode = &cmd64x_set_pio_mode;
        hwif->set_dma_mode = &cmd64x_set_dma_mode;
 
+       hwif->cable_detect = ata66_cmd64x;
+
        if (!hwif->dma_base)
                return;
 
@@ -411,9 +412,6 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
        if (dev->device == PCI_DEVICE_ID_CMD_646 && dev->revision < 5)
                hwif->ultra_mask = 0x00;
 
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = ata66_cmd64x(hwif);
-
        switch (dev->device) {
        case PCI_DEVICE_ID_CMD_648:
        case PCI_DEVICE_ID_CMD_649:
index 9e01c6dc758eb6c0d898e22a523283d3392f6a8d..0be1a824102b90494f33410e3a199e8f5a432187 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
-
-#include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/ide.h>
 #include <linux/dma-mapping.h>
 
-#include <asm/io.h>
-#include <asm/irq.h>
-
 struct pio_clocks
 {
        int address;
@@ -156,8 +146,14 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
        ide_setup_pci_noise(dev, d);
 
        /* We must not grab the entire device, it has 'ISA' space in its
-          BARS too and we will freak out other bits of the kernel */
-       if (pci_enable_device_bars(dev, 1<<2)) {
+        * BARS too and we will freak out other bits of the kernel
+        *
+        * pci_enable_device_bars() is going away. I replaced it with
+        * IO only enable for now but I'll need confirmation this is
+        * allright for that device. If not, it will need some kind of
+        * quirk. --BenH.
+        */
+       if (pci_enable_device_io(dev)) {
                printk(KERN_WARNING "%s: Unable to enable 55x0.\n", d->name);
                return -ENODEV;
        }
@@ -174,7 +170,7 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
 
        ide_pci_setup_ports(dev, d, 14, &idx[0]);
 
-       ide_device_add(idx);
+       ide_device_add(idx, d);
 
        return 0;
 }
index 765aac397ced847f05a7a69b5ccf918e99d864a4..941a1344820b95ae8d2f238714124f9d3e4c6470 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
-#include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
+
 #include <asm/io.h>
-#include <asm/irq.h>
 
 /*
  * Here are the standard PIO mode 0-4 timings for each "format".
index 66433aa53f594fc58ca256eedb7d67622e282228..d7b5ea992e94a25ee10b46eac7bb4237a9848764 100644 (file)
@@ -155,8 +155,9 @@ static void cs5535_set_pio_mode(ide_drive_t *drive, const u8 pio)
        cs5535_set_speed(drive, XFER_PIO_0 + pio);
 }
 
-static u8 __devinit cs5535_cable_detect(struct pci_dev *dev)
+static u8 __devinit cs5535_cable_detect(ide_hwif_t *hwif)
 {
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
        u8 bit;
 
        /* if a 80 wire cable was detected */
@@ -175,15 +176,10 @@ static u8 __devinit cs5535_cable_detect(struct pci_dev *dev)
  */
 static void __devinit init_hwif_cs5535(ide_hwif_t *hwif)
 {
-       struct pci_dev *dev = to_pci_dev(hwif->dev);
-
        hwif->set_pio_mode = &cs5535_set_pio_mode;
        hwif->set_dma_mode = &cs5535_set_dma_mode;
 
-       if (hwif->dma_base == 0)
-               return;
-
-       hwif->cbl = cs5535_cable_detect(dev);
+       hwif->cable_detect = cs5535_cable_detect;
 }
 
 static const struct ide_port_info cs5535_chipset __devinitdata = {
index 50100ac8770ff6814e8edfb4f973b3043d1450a4..724cbacf4e5b04d9a82e19e5ea05a0d6e0cf5292 100644 (file)
@@ -45,7 +45,6 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 
index 27e47fc97100248a05c6232f84eb7b717fee253d..3f9cd64c26a6aa0f2214918c485fcce7c9b6d120 100644 (file)
  *  License.  See the file COPYING in the main directory of this archive for
  *  more details.
  */
-#include <linux/autoconf.h>
+
 #include <linux/types.h>
 #include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 #include <linux/pci.h>
+
 #include <asm/io.h>
 
 /*
@@ -52,6 +51,7 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
        ide_hwif_t *hwif = NULL;
        ide_drive_t *drive;
        int i, rc;
+       u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
 
        rc = pci_enable_device(dev);
        if (rc) {
@@ -78,12 +78,27 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
        hw.irq = dev->irq;
        hw.chipset = ide_pci;           /* this enables IRQ sharing */
 
-       rc = ide_register_hw(&hw, &ide_undecoded_slave, &hwif);
-       if (rc < 0) {
-               printk(KERN_ERR "delkin_cb: ide_register_hw failed (%d)\n", rc);
-               pci_disable_device(dev);
-               return -ENODEV;
-       }
+       hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]);
+       if (hwif == NULL)
+               goto out_disable;
+
+       i = hwif->index;
+
+       if (hwif->present)
+               ide_unregister(i, 0, 0);
+       else if (!hwif->hold)
+               ide_init_port_data(hwif, i);
+
+       ide_init_port_hw(hwif, &hw);
+       hwif->quirkproc = &ide_undecoded_slave;
+
+       idx[0] = i;
+
+       ide_device_add(idx, NULL);
+
+       if (!hwif->present)
+               goto out_disable;
+
        pci_set_drvdata(dev, hwif);
        hwif->dev = &dev->dev;
        drive = &hwif->drives[0];
@@ -92,6 +107,11 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
                drive->unmask   = 1;
        }
        return 0;
+
+out_disable:
+       printk(KERN_ERR "delkin_cb: no IDE devices found\n");
+       pci_disable_device(dev);
+       return -ENODEV;
 }
 
 static void
@@ -100,7 +120,8 @@ delkin_cb_remove (struct pci_dev *dev)
        ide_hwif_t *hwif = pci_get_drvdata(dev);
 
        if (hwif)
-               ide_unregister(hwif->index);
+               ide_unregister(hwif->index, 0, 0);
+
        pci_disable_device(dev);
 }
 
index 59ebe84f1053b36d0bc922595d38ff2dee7cc893..7fd83a9d4dee16fb8612850bce50732e0e60930a 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/pci.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 static int ide_generic_all;            /* Set to claim all devices */
 
-/*
- * the module_param_named() was added for the modular case
- * the __setup() is left as compatibility for existing setups
- */
-#ifndef MODULE
-static int __init ide_generic_all_on(char *unused)
-{
-       ide_generic_all = 1;
-       printk(KERN_INFO "IDE generic will claim all unknown PCI IDE storage controllers.\n");
-       return 1;
-}
-const __setup("all-generic-ide", ide_generic_all_on);
-#endif
 module_param_named(all_generic_ide, ide_generic_all, bool, 0444);
 MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers.");
 
index 25dbb814822d6410e92ec4e8852bf53c79a325ee..9f01da46b01648d6ead8c8b516fbe7a7a9d4cc1e 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
 #include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
 
-#include <asm/io.h>
-#include <asm/irq.h>
-
 #define HPT343_DEBUG_DRIVE_INFO                0
 
 static void hpt34x_set_mode(ide_drive_t *drive, const u8 speed)
index 5623cad569da3f3b6e0c813e41f3b666d84a1b94..d0f7bb8b8adf1d881fe4d2f7c5f86106dc4b63d1 100644 (file)
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
 #include <linux/blkdev.h>
 #include <linux/hdreg.h>
-
 #include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
-#include <asm/irq.h>
 
 /* various tuning parameters */
 #define HPT_RESET_STATE_ENGINE
@@ -1279,12 +1274,55 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
        return dev->irq;
 }
 
+static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
+{
+       struct pci_dev  *dev    = to_pci_dev(hwif->dev);
+       struct hpt_info *info   = pci_get_drvdata(dev);
+       u8 chip_type            = info->chip_type;
+       u8 scr1 = 0, ata66      = hwif->channel ? 0x01 : 0x02;
+
+       /*
+        * The HPT37x uses the CBLID pins as outputs for MA15/MA16
+        * address lines to access an external EEPROM.  To read valid
+        * cable detect state the pins must be enabled as inputs.
+        */
+       if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
+               /*
+                * HPT374 PCI function 1
+                * - set bit 15 of reg 0x52 to enable TCBLID as input
+                * - set bit 15 of reg 0x56 to enable FCBLID as input
+                */
+               u8  mcr_addr = hwif->select_data + 2;
+               u16 mcr;
+
+               pci_read_config_word(dev, mcr_addr, &mcr);
+               pci_write_config_word(dev, mcr_addr, (mcr | 0x8000));
+               /* now read cable id register */
+               pci_read_config_byte(dev, 0x5a, &scr1);
+               pci_write_config_word(dev, mcr_addr, mcr);
+       } else if (chip_type >= HPT370) {
+               /*
+                * HPT370/372 and 374 pcifn 0
+                * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs
+                */
+               u8 scr2 = 0;
+
+               pci_read_config_byte(dev, 0x5b, &scr2);
+               pci_write_config_byte(dev, 0x5b, (scr2 & ~1));
+               /* now read cable id register */
+               pci_read_config_byte(dev, 0x5a, &scr1);
+               pci_write_config_byte(dev, 0x5b,  scr2);
+       } else
+               pci_read_config_byte(dev, 0x5a, &scr1);
+
+       return (scr1 & ata66) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+}
+
 static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
 {
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
        struct hpt_info *info   = pci_get_drvdata(dev);
        int serialize           = HPT_SERIALIZE_IO;
-       u8  scr1 = 0, ata66     = hwif->channel ? 0x01 : 0x02;
        u8  chip_type           = info->chip_type;
        u8  new_mcr, old_mcr    = 0;
 
@@ -1301,6 +1339,8 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
        hwif->udma_filter       = &hpt3xx_udma_filter;
        hwif->mdma_filter       = &hpt3xx_mdma_filter;
 
+       hwif->cable_detect      = hpt3xx_cable_detect;
+
        /*
         * HPT3xxN chips have some complications:
         *
@@ -1346,43 +1386,6 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
        if (hwif->dma_base == 0)
                return;
 
-       /*
-        * The HPT37x uses the CBLID pins as outputs for MA15/MA16
-        * address lines to access an external EEPROM.  To read valid
-        * cable detect state the pins must be enabled as inputs.
-        */
-       if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
-               /*
-                * HPT374 PCI function 1
-                * - set bit 15 of reg 0x52 to enable TCBLID as input
-                * - set bit 15 of reg 0x56 to enable FCBLID as input
-                */
-               u8  mcr_addr = hwif->select_data + 2;
-               u16 mcr;
-
-               pci_read_config_word (dev, mcr_addr, &mcr);
-               pci_write_config_word(dev, mcr_addr, (mcr | 0x8000));
-               /* now read cable id register */
-               pci_read_config_byte (dev, 0x5a, &scr1);
-               pci_write_config_word(dev, mcr_addr, mcr);
-       } else if (chip_type >= HPT370) {
-               /*
-                * HPT370/372 and 374 pcifn 0
-                * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs
-                */
-               u8 scr2 = 0;
-
-               pci_read_config_byte (dev, 0x5b, &scr2);
-               pci_write_config_byte(dev, 0x5b, (scr2 & ~1));
-               /* now read cable id register */
-               pci_read_config_byte (dev, 0x5a, &scr1);
-               pci_write_config_byte(dev, 0x5b,  scr2);
-       } else
-               pci_read_config_byte (dev, 0x5a, &scr1);
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = (scr1 & ata66) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
-
        if (chip_type >= HPT374) {
                hwif->ide_dma_test_irq  = &hpt374_ide_dma_test_irq;
                hwif->ide_dma_end       = &hpt374_ide_dma_end;
index df74e588a530daea46e44b1a5fa30ea621fe88a3..e3427eaab430b9de5ef463c4e8c558e6bace1fec 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 /**
  *     it8213_set_pio_mode     -       set host controller for PIO mode
  *     @drive: drive
@@ -143,6 +140,16 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
        }
 }
 
+static u8 __devinit it8213_cable_detect(ide_hwif_t *hwif)
+{
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+       u8 reg42h = 0;
+
+       pci_read_config_byte(dev, 0x42, &reg42h);
+
+       return (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+}
+
 /**
  *     init_hwif_it8213        -       set up hwif structs
  *     @hwif: interface to set up
@@ -152,19 +159,10 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
 static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
 {
-       struct pci_dev *dev = to_pci_dev(hwif->dev);
-       u8 reg42h = 0;
-
        hwif->set_dma_mode = &it8213_set_dma_mode;
        hwif->set_pio_mode = &it8213_set_pio_mode;
 
-       if (!hwif->dma_base)
-               return;
-
-       pci_read_config_byte(dev, 0x42, &reg42h);
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+       hwif->cable_detect = it8213_cable_detect;
 }
 
 
index 938d35f35c81a97ed2db333b0faa5d54a8763928..1597f0cc1bf1ced36b76caa3b7e264f563f5a3f0 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 struct it821x_dev
 {
        unsigned int smart:1,           /* Are we in smart raid mode */
@@ -579,14 +576,13 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
        } else
                hwif->host_flags |= IDE_HFLAG_NO_SET_MODE;
 
+       hwif->cable_detect = ata66_it821x;
+
        if (hwif->dma_base == 0)
                return;
 
        hwif->ultra_mask = ATA_UDMA6;
        hwif->mwdma_mask = ATA_MWDMA2;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = ata66_it821x(hwif);
 }
 
 static void __devinit it8212_disable_raid(struct pci_dev *dev)
index 8b40f6479c55c9a694a6066766f8a0ab1c9d299f..a56bcb4f22f4f9d402616d5314c50a4ed8794ec5 100644 (file)
@@ -8,13 +8,10 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 typedef enum {
        PORT_PATA0 = 0,
        PORT_PATA1 = 1,
@@ -111,11 +108,7 @@ static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
        hwif->set_pio_mode = &jmicron_set_pio_mode;
        hwif->set_dma_mode = &jmicron_set_dma_mode;
 
-       if (hwif->dma_base == 0)
-               return;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = ata66_jmicron(hwif);
+       hwif->cable_detect = ata66_jmicron;
 }
 
 static const struct ide_port_info jmicron_chipset __devinitdata = {
index fc9eee9ccac30d3ef5f7540d7ec23b4d7a24157f..bf0d3b2931f1c3202259fa40c444642cb93f07c6 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
 #include <linux/interrupt.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/pci.h>
 #include <linux/delay.h>
index 0ce92d323036c5061a2e31f8db02e362ca7547ef..46e8748f507e57cdb985007b32f18e80619f93a6 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/pci.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
@@ -320,14 +315,18 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
        spin_unlock_irqrestore(&opti621_lock, flags);
 }
 
+static void __devinit opti621_port_init_devs(ide_hwif_t *hwif)
+{
+       hwif->drives[0].drive_data = PIO_DONT_KNOW;
+       hwif->drives[1].drive_data = PIO_DONT_KNOW;
+}
+
 /*
  * init_hwif_opti621() is called once for each hwif found at boot.
  */
 static void __devinit init_hwif_opti621 (ide_hwif_t *hwif)
 {
-       hwif->drives[0].drive_data = PIO_DONT_KNOW;
-       hwif->drives[1].drive_data = PIO_DONT_KNOW;
-
+       hwif->port_init_devs = opti621_port_init_devs;
        hwif->set_pio_mode = &opti621_set_pio_mode;
 }
 
index bb29db03540edbec0dedb62333f6f06dabee947d..1c8cb7797a4aea2a6800c22da7ab251fe9cb8163 100644 (file)
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
-#include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
 
 #include <asm/io.h>
-#include <asm/irq.h>
 
 #ifdef CONFIG_PPC_PMAC
 #include <asm/prom.h>
@@ -197,7 +191,7 @@ static void pdcnew_set_pio_mode(ide_drive_t *drive, const u8 pio)
        }
 }
 
-static u8 pdcnew_cable_detect(ide_hwif_t *hwif)
+static u8 __devinit pdcnew_cable_detect(ide_hwif_t *hwif)
 {
        if (get_indexed_reg(hwif, 0x0b) & 0x04)
                return ATA_CBL_PATA40;
@@ -456,11 +450,7 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
        hwif->quirkproc = &pdcnew_quirkproc;
        hwif->resetproc = &pdcnew_reset;
 
-       if (hwif->dma_base == 0)
-               return;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = pdcnew_cable_detect(hwif);
+       hwif->cable_detect = pdcnew_cable_detect;
 }
 
 static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev)
index 31a1308414a0f87a57a004831ca1e4fc8ac160ae..da4329790387c6019ceaf7b24d7394840b25fb1d 100644 (file)
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
 #include <linux/blkdev.h>
 #include <linux/hdreg.h>
-#include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
 
 #include <asm/io.h>
-#include <asm/irq.h>
 
 #define PDC202XX_DEBUG_DRIVE_INFO      0
 
@@ -140,10 +135,10 @@ static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
        pdc202xx_set_mode(drive, XFER_PIO_0 + pio);
 }
 
-static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
+static u8 __devinit pdc2026x_old_cable_detect(ide_hwif_t *hwif)
 {
        struct pci_dev *dev = to_pci_dev(hwif->dev);
-       u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10);
+       u16 CIS, mask = hwif->channel ? (1 << 11) : (1 << 10);
 
        pci_read_config_word(dev, 0x50, &CIS);
 
@@ -311,9 +306,12 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
 
        hwif->quirkproc = &pdc202xx_quirkproc;
 
-       if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
+       if (dev->device != PCI_DEVICE_ID_PROMISE_20246) {
                hwif->resetproc = &pdc202xx_reset;
 
+               hwif->cable_detect = pdc2026x_old_cable_detect;
+       }
+
        if (hwif->dma_base == 0)
                return;
 
@@ -321,9 +319,6 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
        hwif->dma_timeout = &pdc202xx_dma_timeout;
 
        if (dev->device != PCI_DEVICE_ID_PROMISE_20246) {
-               if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-                       hwif->cbl = pdc202xx_old_cable_detect(hwif);
-
                hwif->dma_start = &pdc202xx_old_ide_dma_start;
                hwif->ide_dma_end = &pdc202xx_old_ide_dma_end;
        } 
index c1a6b68337d52816bb3f22f13aebb3025a549d48..decef0f476748ab0858360f3bc9fbfa647f96f06 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/ioport.h>
 #include <linux/pci.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
-#include <linux/delay.h>
 #include <linux/init.h>
 
 #include <asm/io.h>
@@ -290,14 +288,11 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
        hwif->set_pio_mode = &piix_set_pio_mode;
        hwif->set_dma_mode = &piix_set_dma_mode;
 
+       hwif->cable_detect = piix_cable_detect;
+
        if (!hwif->dma_base)
                return;
 
-       if (hwif->ultra_mask & 0x78) {
-               if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-                       hwif->cbl = piix_cable_detect(hwif);
-       }
-
        if (no_piix_dma)
                hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
 }
index 7ed6625819d4c79df46eb8457688238ec7ef22ba..51676612f78f0d603e49e8456a8012ca54f58f06 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/pci.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif)
 {
        struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -40,8 +33,7 @@ static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif)
        } else {
                if (hwif->mate)
                        hwif->mate->serialized = hwif->serialized = 1;
-               hwif->drives[0].no_unmask = 1;
-               hwif->drives[1].no_unmask = 1;
+               hwif->host_flags |= IDE_HFLAG_NO_UNMASK_IRQS;
                printk(KERN_INFO "%s: serialized, disabled unmasking "
                        "(buggy RZ1000/RZ1001)\n", hwif->name);
        }
index af499a60eb312afdd6d92326fa98915f5566f0d6..561aa47c7720fafa38c615a4fa36d0dd62dba76d 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
-#include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
 #include <linux/pm.h>
+
 #include <asm/io.h>
-#include <asm/irq.h>
 
 #define SC1200_REV_A   0x00
 #define SC1200_REV_B1  0x01
index 7694969b02ce1097ce730e74833a84cce06a537f..238e3e181e873f0f98566e72f50e67e6771d54c1 100644 (file)
@@ -644,6 +644,11 @@ static void __devinit init_iops_scc(ide_hwif_t *hwif)
        init_mmio_iops_scc(hwif);
 }
 
+static u8 __devinit scc_cable_detect(ide_hwif_t *hwif)
+{
+       return ATA_CBL_PATA80;
+}
+
 /**
  *     init_hwif_scc   -       set up hwif
  *     @hwif: interface to set up
@@ -678,8 +683,7 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
        else
                hwif->ultra_mask = ATA_UDMA5; /* 100MHz */
 
-       /* we support 80c cable only. */
-       hwif->cbl = ATA_CBL_PATA80;
+       hwif->cable_detect = scc_cable_detect;
 }
 
 #define DECLARE_SCC_DEV(name_str)                      \
@@ -732,7 +736,7 @@ static void __devexit scc_remove(struct pci_dev *dev)
                hwif->dmatable_cpu = NULL;
        }
 
-       ide_unregister(hwif->index);
+       ide_unregister(hwif->index, 0, 0);
 
        hwif->chipset = ide_unknown;
        iounmap((void*)ports->dma);
index f495253b7d417d0666fa77a3330407436306ad2d..c11880b0709f711c4ee49ef2edc376f8e57e1df6 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/ioport.h>
 #include <linux/pci.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
-#include <linux/delay.h>
 
 #include <asm/io.h>
 
@@ -346,13 +344,8 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
        hwif->set_dma_mode = &svwks_set_dma_mode;
        hwif->udma_filter = &svwks_udma_filter;
 
-       if (!hwif->dma_base)
-               return;
-
-       if (dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
-               if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-                       hwif->cbl = ata66_svwks(hwif);
-       }
+       if (dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
+               hwif->cable_detect = ata66_svwks;
 }
 
 #define IDE_HFLAGS_SVWKS \
index 85902074b1fc03e7751d9d66ee409603de618f2e..054626497be49405cd5e9ae95952196040564689 100644 (file)
@@ -25,8 +25,6 @@
 #include <linux/hdreg.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
 #include <linux/ioport.h>
 #include <linux/blkdev.h>
 #include <linux/scatterlist.h>
@@ -555,7 +553,6 @@ static void __devinit
 ide_init_sgiioc4(ide_hwif_t * hwif)
 {
        hwif->mmio = 1;
-       hwif->pio_mask = 0x00;
        hwif->set_pio_mode = NULL; /* Sets timing for PIO mode */
        hwif->set_dma_mode = &sgiioc4_set_dma_mode;
        hwif->selectproc = NULL;/* Use the default routine to select drive */
@@ -572,8 +569,6 @@ ide_init_sgiioc4(ide_hwif_t * hwif)
        if (hwif->dma_base == 0)
                return;
 
-       hwif->mwdma_mask = ATA_MWDMA2_ONLY;
-
        hwif->dma_host_set = &sgiioc4_dma_host_set;
        hwif->dma_setup = &sgiioc4_ide_dma_setup;
        hwif->dma_start = &sgiioc4_ide_dma_start;
@@ -583,6 +578,13 @@ ide_init_sgiioc4(ide_hwif_t * hwif)
        hwif->dma_timeout = &ide_dma_timeout;
 }
 
+static const struct ide_port_info sgiioc4_port_info __devinitdata = {
+       .chipset                = ide_pci,
+       .host_flags             = IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
+                                 IDE_HFLAG_NO_AUTOTUNE,
+       .mwdma_mask             = ATA_MWDMA2_ONLY,
+};
+
 static int __devinit
 sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
 {
@@ -593,6 +595,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
        int h;
        u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
        hw_regs_t hw;
+       struct ide_port_info d = sgiioc4_port_info;
 
        /*
         * Find an empty HWIF; if none available, return -ENOMEM.
@@ -641,7 +644,6 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
        ide_init_port_hw(hwif, &hw);
 
        hwif->dev = &dev->dev;
-       hwif->channel = 0;      /* Single Channel chip */
 
        /* The IOC4 uses MMIO rather than Port IO. */
        default_hwif_mmiops(hwif);
@@ -649,15 +651,17 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
        /* Initializing chipset IRQ Registers */
        writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
 
-       if (dma_base == 0 || ide_dma_sgiioc4(hwif, dma_base))
+       if (dma_base == 0 || ide_dma_sgiioc4(hwif, dma_base)) {
                printk(KERN_INFO "%s: %s Bus-Master DMA disabled\n",
                                 hwif->name, DRV_NAME);
+               d.mwdma_mask = 0;
+       }
 
        ide_init_sgiioc4(hwif);
 
        idx[0] = hwif->index;
 
-       if (ide_device_add(idx))
+       if (ide_device_add(idx, &d))
                return -EIO;
 
        return 0;
index 4877bc8cd599cd27feea2c0108fe5f781e99d685..cc4be9621bc0ec04048f9811183283ece1d55e10 100644 (file)
@@ -39,7 +39,6 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
@@ -332,15 +331,18 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        unsigned long addr      = siimage_selreg(hwif, 0x1);
+       void __iomem *sata_error_addr
+               = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET];
 
-       if (SATA_ERROR_REG) {
+       if (sata_error_addr) {
                unsigned long base = (unsigned long)hwif->hwif_data;
-
                u32 ext_stat = readl((void __iomem *)(base + 0x10));
                u8 watchdog = 0;
+
                if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) {
-                       u32 sata_error = readl((void __iomem *)SATA_ERROR_REG);
-                       writel(sata_error, (void __iomem *)SATA_ERROR_REG);
+                       u32 sata_error = readl(sata_error_addr);
+
+                       writel(sata_error, sata_error_addr);
                        watchdog = (sata_error & 0x00680000) ? 1 : 0;
                        printk(KERN_WARNING "%s: sata_error = 0x%08x, "
                                "watchdog = %d, %s\n",
@@ -419,13 +421,17 @@ static int sil_sata_busproc(ide_drive_t * drive, int state)
 
 static int sil_sata_reset_poll(ide_drive_t *drive)
 {
-       if (SATA_STATUS_REG) {
-               ide_hwif_t *hwif        = HWIF(drive);
+       ide_hwif_t *hwif = drive->hwif;
+       void __iomem *sata_status_addr
+               = (void __iomem *)hwif->sata_scr[SATA_STATUS_OFFSET];
 
-               /* SATA_STATUS_REG is valid only when in MMIO mode */
-               if ((readl((void __iomem *)SATA_STATUS_REG) & 0x03) != 0x03) {
+       if (sata_status_addr) {
+               /* SATA Status is available only when in MMIO mode */
+               u32 sata_stat = readl(sata_status_addr);
+
+               if ((sata_stat & 0x03) != 0x03) {
                        printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n",
-                               hwif->name, readl((void __iomem *)SATA_STATUS_REG));
+                                           hwif->name, sata_stat);
                        HWGROUP(drive)->polling = 0;
                        return ide_started;
                }
@@ -698,9 +704,6 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
                hwif->sata_scr[SATA_STATUS_OFFSET]      = base + 0x104;
                hwif->sata_scr[SATA_ERROR_OFFSET]       = base + 0x108;
                hwif->sata_scr[SATA_CONTROL_OFFSET]     = base + 0x100;
-               hwif->sata_misc[SATA_MISC_OFFSET]       = base + 0x140;
-               hwif->sata_misc[SATA_PHY_OFFSET]        = base + 0x144;
-               hwif->sata_misc[SATA_IEN_OFFSET]        = base + 0x148;
        }
 
        memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports));
@@ -827,15 +830,14 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
        } else
                hwif->udma_filter = &sil_pata_udma_filter;
 
+       hwif->cable_detect = ata66_siimage;
+
        if (hwif->dma_base == 0)
                return;
 
        if (sata)
                hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
 
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = ata66_siimage(hwif);
-
        if (hwif->mmio) {
                hwif->ide_dma_test_irq = &siimage_mmio_ide_dma_test_irq;
        } else {
index 2a461de22aa005099fa7e27bb53e5de3afebeb0b..512bb4c1fd5cdab9a2005fff535ea0838d3d2a90 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
-
-#include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
 
-#include <asm/irq.h>
-
 #include "ide-timing.h"
 
 /* registers layout and init values are chipset family dependant */
@@ -565,13 +556,12 @@ static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
        if (chipset_family >= ATA_133)
                hwif->udma_filter = sis5513_ata133_udma_filter;
 
+       hwif->cable_detect = ata66_sis5513;
+
        if (hwif->dma_base == 0)
                return;
 
        hwif->ultra_mask = udma_rates[chipset_family];
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = ata66_sis5513(hwif);
 }
 
 static const struct ide_port_info sis5513_chipset __devinitdata = {
index da13a1298adab430727ffe17bb409184ee771e65..ee261ae15b6f01afecea50e926a968bbec553249 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/interrupt.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/pci.h>
 #include <linux/ide.h>
 
 #include <asm/io.h>
-#include <asm/dma.h>
 
 #undef DEBUG
 
index a6cf810c469984bf906d5bd7101c8b01b6ddbb28..65f4c2ffaa5964604c713a1ca78719ee6112ae48 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/ioport.h>
 #include <linux/pci.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
-#include <linux/delay.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 static DEFINE_SPINLOCK(slc90e66_lock);
 
 static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
@@ -118,23 +114,23 @@ static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
        }
 }
 
-static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif)
+static u8 __devinit slc90e66_cable_detect(ide_hwif_t *hwif)
 {
        struct pci_dev *dev = to_pci_dev(hwif->dev);
-       u8 reg47 = 0;
-       u8 mask = hwif->channel ? 0x01 : 0x02;  /* bit0:Primary */
-
-       hwif->set_pio_mode = &slc90e66_set_pio_mode;
-       hwif->set_dma_mode = &slc90e66_set_dma_mode;
+       u8 reg47 = 0, mask = hwif->channel ? 0x01 : 0x02;
 
        pci_read_config_byte(dev, 0x47, &reg47);
 
-       if (hwif->dma_base == 0)
-               return;
+       /* bit[0(1)]: 0:80, 1:40 */
+       return (reg47 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+}
+
+static void __devinit init_hwif_slc90e66(ide_hwif_t *hwif)
+{
+       hwif->set_pio_mode = &slc90e66_set_pio_mode;
+       hwif->set_dma_mode = &slc90e66_set_dma_mode;
 
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               /* bit[0(1)]: 0:80, 1:40 */
-               hwif->cbl = (reg47 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+       hwif->cable_detect = slc90e66_cable_detect;
 }
 
 static const struct ide_port_info slc90e66_chipset __devinitdata = {
index 9fbbb4f2dd5475561c41405a8b869064babe13a7..2ef2ed2f2b32a9e0ba45d263963edf97efeccda5 100644 (file)
@@ -160,6 +160,19 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
        return 0;
 }
 
+static u8 __devinit tc86c001_cable_detect(ide_hwif_t *hwif)
+{
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+       unsigned long sc_base = pci_resource_start(dev, 5);
+       u16 scr1 = inw(sc_base + 0x00);
+
+       /*
+        * System Control  1 Register bit 13 (PDIAGN):
+        * 0=80-pin cable, 1=40-pin cable
+        */
+       return (scr1 & 0x2000) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+}
+
 static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
 {
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
@@ -183,6 +196,8 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
 
        hwif->busproc   = &tc86c001_busproc;
 
+       hwif->cable_detect = tc86c001_cable_detect;
+
        if (!hwif->dma_base)
                return;
 
@@ -196,15 +211,6 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
        hwif->rqsize     = 0xffff;
 
        hwif->dma_start         = &tc86c001_dma_start;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
-               /*
-                * System Control  1 Register bit 13 (PDIAGN):
-                * 0=80-pin cable, 1=40-pin cable
-                */
-               scr1 = inw(sc_base + 0x00);
-               hwif->cbl = (scr1 & 0x2000) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
-       }
 }
 
 static unsigned int __devinit init_chipset_tc86c001(struct pci_dev *dev,
index 852b72693736a3b1b56a458e91eeab5301d87664..a67d02a3f96e108484f42b71cbbbeec9dc97a6aa 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/pci.h>
 #include <linux/ide.h>
index d9ebb698953a5753c2ddb24638c835cadbb5e9bb..de750f7a43e97f12725a7673c3557b6ab1ed38b8 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/mm.h>
 #include <linux/ioport.h>
 #include <linux/interrupt.h>
 #include <linux/blkdev.h>
 #include <linux/init.h>
 #include <linux/hdreg.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/ide.h>
 
 #include <asm/io.h>
@@ -179,10 +177,7 @@ static void trm290_selectproc (ide_drive_t *drive)
 
 static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command)
 {
-       BUG_ON(HWGROUP(drive)->handler != NULL);        /* paranoia check */
-       ide_set_handler(drive, &ide_dma_intr, WAIT_CMD, NULL);
-       /* issue cmd to drive */
-       outb(command, IDE_COMMAND_REG);
+       ide_execute_command(drive, command, &ide_dma_intr, WAIT_CMD, NULL);
 }
 
 static int trm290_dma_setup(ide_drive_t *drive)
index 24cb9047fb419a8ad3e6c6bcc1ea903b79b64245..f3f79f8058131836164dea76d90f777949c7d82d 100644 (file)
 
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
 #include <linux/dmi.h>
 
-#include <asm/io.h>
-
 #ifdef CONFIG_PPC_CHRP
 #include <asm/processor.h>
 #endif
@@ -424,11 +420,7 @@ static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
        hwif->set_pio_mode = &via_set_pio_mode;
        hwif->set_dma_mode = &via_set_drive;
 
-       if (!hwif->dma_base)
-               return;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = via82cxxx_cable_detect(hwif);
+       hwif->cable_detect = via82cxxx_cable_detect;
 }
 
 static const struct ide_port_info via82cxxx_chipset __devinitdata = {
index 45c1d55e60dfd62186a2d5c32caf163702a8e197..06190b1c4ec5ef5e310223c2dbbee6414a5726b7 100644 (file)
@@ -848,7 +848,7 @@ static int __init mpc8xx_ide_probe(void)
 #endif
 #endif
 
-       ide_device_add(idx);
+       ide_device_add(idx, NULL);
 
        return 0;
 }
index 23112ef68f675d43565bc04688e0127eadb18db1..12ac3bfb4f9ac1d098cae0738521b44442e992b3 100644 (file)
@@ -412,7 +412,7 @@ kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
  */
 #define IDE_WAKEUP_DELAY       (1*HZ)
 
-static void pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
+static int pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
 static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq);
 static void pmac_ide_selectproc(ide_drive_t *drive);
 static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
@@ -1003,6 +1003,17 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
        return 0;
 }
 
+static const struct ide_port_info pmac_port_info = {
+       .chipset                = ide_pmac,
+       .host_flags             = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
+                                 IDE_HFLAG_PIO_NO_DOWNGRADE |
+                                 IDE_HFLAG_POST_SET_MODE |
+                                 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
+                                 IDE_HFLAG_UNMASK_IRQS,
+       .pio_mask               = ATA_PIO4,
+       .mwdma_mask             = ATA_MWDMA2,
+};
+
 /*
  * Setup, register & probe an IDE channel driven by this driver, this is
  * called by one of the 2 probe functions (macio or PCI). Note that a channel
@@ -1016,23 +1027,28 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
        struct device_node *np = pmif->node;
        const int *bidp;
        u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
+       struct ide_port_info d = pmac_port_info;
 
        pmif->cable_80 = 0;
        pmif->broken_dma = pmif->broken_dma_warn = 0;
-       if (of_device_is_compatible(np, "shasta-ata"))
+       if (of_device_is_compatible(np, "shasta-ata")) {
                pmif->kind = controller_sh_ata6;
-       else if (of_device_is_compatible(np, "kauai-ata"))
+               d.udma_mask = ATA_UDMA6;
+       } else if (of_device_is_compatible(np, "kauai-ata")) {
                pmif->kind = controller_un_ata6;
-       else if (of_device_is_compatible(np, "K2-UATA"))
+               d.udma_mask = ATA_UDMA5;
+       } else if (of_device_is_compatible(np, "K2-UATA")) {
                pmif->kind = controller_k2_ata6;
-       else if (of_device_is_compatible(np, "keylargo-ata")) {
-               if (strcmp(np->name, "ata-4") == 0)
+               d.udma_mask = ATA_UDMA5;
+       } else if (of_device_is_compatible(np, "keylargo-ata")) {
+               if (strcmp(np->name, "ata-4") == 0) {
                        pmif->kind = controller_kl_ata4;
-               else
+                       d.udma_mask = ATA_UDMA4;
+               } else
                        pmif->kind = controller_kl_ata3;
-       } else if (of_device_is_compatible(np, "heathrow-ata"))
+       } else if (of_device_is_compatible(np, "heathrow-ata")) {
                pmif->kind = controller_heathrow;
-       else {
+       else {
                pmif->kind = controller_ohare;
                pmif->broken_dma = 1;
        }
@@ -1101,19 +1117,10 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
        /* Tell common code _not_ to mess with resources */
        hwif->mmio = 1;
        hwif->hwif_data = pmif;
-       hw->chipset = ide_pmac;
        ide_init_port_hw(hwif, hw);
        hwif->noprobe = pmif->mediabay;
        hwif->hold = pmif->mediabay;
        hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
-       hwif->drives[0].unmask = 1;
-       hwif->drives[1].unmask = 1;
-       hwif->drives[0].autotune = IDE_TUNE_AUTO;
-       hwif->drives[1].autotune = IDE_TUNE_AUTO;
-       hwif->host_flags = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
-                          IDE_HFLAG_PIO_NO_DOWNGRADE |
-                          IDE_HFLAG_POST_SET_MODE;
-       hwif->pio_mask = ATA_PIO4;
        hwif->set_pio_mode = pmac_ide_set_pio_mode;
        if (pmif->kind == controller_un_ata6
            || pmif->kind == controller_k2_ata6
@@ -1133,14 +1140,16 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
 #endif /* CONFIG_PMAC_MEDIABAY */
 
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
+       if (pmif->cable_80 == 0)
+               d.udma_mask &= ATA_UDMA2;
        /* has a DBDMA controller channel */
-       if (pmif->dma_regs)
-               pmac_ide_setup_dma(pmif, hwif);
-#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
+       if (pmif->dma_regs == 0 || pmac_ide_setup_dma(pmif, hwif) < 0)
+#endif
+               d.udma_mask = d.mwdma_mask = 0;
 
        idx[0] = hwif->index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, &d);
 
        return 0;
 }
@@ -1721,8 +1730,7 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
  * Allocate the data structures needed for using DMA with an interface
  * and fill the proper list of functions pointers
  */
-static void __devinit
-pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
+static int __devinit pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
 {
        struct pci_dev *dev = to_pci_dev(hwif->dev);
 
@@ -1730,7 +1738,7 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
         * DMA routines ...
         */
        if (dev == NULL)
-               return;
+               return -ENODEV;
        /*
         * Allocate space for the DBDMA commands.
         * The +2 is +1 for the stop command and +1 to allow for
@@ -1743,7 +1751,7 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        if (pmif->dma_table_cpu == NULL) {
                printk(KERN_ERR "%s: unable to allocate DMA command list\n",
                       hwif->name);
-               return;
+               return -ENOMEM;
        }
 
        hwif->sg_max_nents = MAX_DCMDS;
@@ -1757,29 +1765,7 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        hwif->dma_timeout = &ide_dma_timeout;
        hwif->dma_lost_irq = &pmac_ide_dma_lost_irq;
 
-       switch(pmif->kind) {
-               case controller_sh_ata6:
-                       hwif->ultra_mask = pmif->cable_80 ? 0x7f : 0x07;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-               case controller_un_ata6:
-               case controller_k2_ata6:
-                       hwif->ultra_mask = pmif->cable_80 ? 0x3f : 0x07;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-               case controller_kl_ata4:
-                       hwif->ultra_mask = pmif->cable_80 ? 0x1f : 0x07;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-               default:
-                       hwif->ultra_mask = 0x00;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-       }
+       return 0;
 }
 
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
index 8ff5a0ef10adc35bc4e50c7dc4892b03fcf91617..634e3f6a96087907b8053fc8bcdb29d3b20281d0 100644 (file)
@@ -228,7 +228,9 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
  *     @d: IDE port info
  *
  *     Enable the IDE PCI device. We attempt to enable the device in full
- *     but if that fails then we only need BAR4 so we will enable that.
+ *     but if that fails then we only need IO space. The PCI code should
+ *     have setup the proper resources for us already for controllers in
+ *     legacy mode.
  *     
  *     Returns zero on success or an error code
  */
@@ -238,7 +240,7 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
        int ret;
 
        if (pci_enable_device(dev)) {
-               ret = pci_enable_device_bars(dev, 1 << 4);
+               ret = pci_enable_device_io(dev);
                if (ret < 0) {
                        printk(KERN_WARNING "%s: (ide_setup_pci_device:) "
                                "Could not enable device.\n", d->name);
@@ -337,7 +339,8 @@ static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *
  *     ide_hwif_configure      -       configure an IDE interface
  *     @dev: PCI device holding interface
  *     @d: IDE port info
- *     @mate: Paired interface if any
+ *     @port: port number
+ *     @irq: PCI IRQ
  *
  *     Perform the initial set up for the hardware interface structure. This
  *     is done per interface port rather than per PCI device. There may be
@@ -346,7 +349,9 @@ static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *
  *     Returns the new hardware interface structure, or NULL on a failure
  */
 
-static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, const struct ide_port_info *d, ide_hwif_t *mate, int port, int irq)
+static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
+                                     const struct ide_port_info *d,
+                                     unsigned int port, int irq)
 {
        unsigned long ctl = 0, base = 0;
        ide_hwif_t *hwif;
@@ -392,29 +397,24 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, const struct ide_port
 
        hwif->dev = &dev->dev;
        hwif->cds = d;
-       hwif->channel = port;
 
-       if (mate) {
-               hwif->mate = mate;
-               mate->mate = hwif;
-       }
        return hwif;
 }
 
+#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
 /**
  *     ide_hwif_setup_dma      -       configure DMA interface
- *     @dev: PCI device
- *     @d: IDE port info
  *     @hwif: IDE interface
+ *     @d: IDE port info
  *
  *     Set up the DMA base for the interface. Enable the master bits as
  *     necessary and attempt to bring the device DMA into a ready to use
  *     state
  */
 
-static void ide_hwif_setup_dma(struct pci_dev *dev, const struct ide_port_info *d, ide_hwif_t *hwif)
+void ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
 {
-#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
        u16 pcicmd;
 
        pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
@@ -446,8 +446,8 @@ static void ide_hwif_setup_dma(struct pci_dev *dev, const struct ide_port_info *
                                "(BIOS)\n", hwif->name, d->name);
                }
        }
-#endif /* CONFIG_BLK_DEV_IDEDMA_PCI*/
 }
+#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
 
 /**
  *     ide_setup_pci_controller        -       set up IDE PCI
@@ -509,7 +509,7 @@ out:
 void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, int pciirq, u8 *idx)
 {
        int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port;
-       ide_hwif_t *hwif, *mate = NULL;
+       ide_hwif_t *hwif;
        u8 tmp;
 
        /*
@@ -525,56 +525,11 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, int
                        continue;       /* port not enabled */
                }
 
-               if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL)
+               hwif = ide_hwif_configure(dev, d, port, pciirq);
+               if (hwif == NULL)
                        continue;
 
                *(idx + port) = hwif->index;
-
-               if (d->init_iops)
-                       d->init_iops(hwif);
-
-               if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0)
-                       ide_hwif_setup_dma(dev, d, hwif);
-
-               if ((!hwif->irq && (d->host_flags & IDE_HFLAG_LEGACY_IRQS)) ||
-                   (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS))
-                       hwif->irq = port ? 15 : 14;
-
-               hwif->host_flags = d->host_flags;
-               hwif->pio_mask = d->pio_mask;
-
-               if ((d->host_flags & IDE_HFLAG_SERIALIZE) && hwif->mate)
-                       hwif->mate->serialized = hwif->serialized = 1;
-
-               if (d->host_flags & IDE_HFLAG_IO_32BIT) {
-                       hwif->drives[0].io_32bit = 1;
-                       hwif->drives[1].io_32bit = 1;
-               }
-
-               if (d->host_flags & IDE_HFLAG_UNMASK_IRQS) {
-                       hwif->drives[0].unmask = 1;
-                       hwif->drives[1].unmask = 1;
-               }
-
-               if (hwif->dma_base) {
-                       hwif->swdma_mask = d->swdma_mask;
-                       hwif->mwdma_mask = d->mwdma_mask;
-                       hwif->ultra_mask = d->udma_mask;
-               }
-
-               hwif->drives[0].autotune = 1;
-               hwif->drives[1].autotune = 1;
-
-               if (d->host_flags & IDE_HFLAG_RQSIZE_256)
-                       hwif->rqsize = 256;
-
-               if (d->init_hwif)
-                       /* Call chipset-specific routine
-                        * for each enabled hwif
-                        */
-                       d->init_hwif(hwif);
-
-               mate = hwif;
        }
 }
 
@@ -656,7 +611,7 @@ int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d)
        ret = do_ide_setup_pci_device(dev, d, &idx[0], 1);
 
        if (ret >= 0)
-               ide_device_add(idx);
+               ide_device_add(idx, d);
 
        return ret;
 }
@@ -680,7 +635,7 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
                        goto out;
        }
 
-       ide_device_add(idx);
+       ide_device_add(idx, d);
 out:
        return ret;
 }
index 2b889d91e673d3fa7d073f40763ef3de7faad629..28e155a9e2a5a6bc8e424e2e1dc235f94fac2c26 100644 (file)
@@ -1465,10 +1465,9 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
        orb->misc |= ORB_SET_DIRECTION(orb_direction);
 
        /* special case if only one element (and less than 64KB in size) */
-       if ((scsi_use_sg == 1) &&
-           (sg_dma_len(sg) <= SBP2_MAX_SG_ELEMENT_LENGTH)) {
+       if (scsi_use_sg == 1 && sg->length <= SBP2_MAX_SG_ELEMENT_LENGTH) {
 
-               cmd->dma_size = sg_dma_len(sg);
+               cmd->dma_size = sg->length;
                cmd->dma_type = CMD_DMA_PAGE;
                cmd->cmd_dma = dma_map_page(hi->host->device.parent,
                                            sg_page(sg), sg->offset,
index a193dfbf99d2f38dd6c9066efb63daeaa14d3b1b..a5dc78ae62d43c5cef9722250f2a7e4db58cddcc 100644 (file)
@@ -44,8 +44,8 @@ source "drivers/infiniband/hw/ipath/Kconfig"
 source "drivers/infiniband/hw/ehca/Kconfig"
 source "drivers/infiniband/hw/amso1100/Kconfig"
 source "drivers/infiniband/hw/cxgb3/Kconfig"
-
 source "drivers/infiniband/hw/mlx4/Kconfig"
+source "drivers/infiniband/hw/nes/Kconfig"
 
 source "drivers/infiniband/ulp/ipoib/Kconfig"
 
index 75f325e40b54516e44e65934885053fae2782993..ed35e44962410ffaa7a715d30f2eba75bc3c6598 100644 (file)
@@ -5,6 +5,7 @@ obj-$(CONFIG_INFINIBAND_EHCA)           += hw/ehca/
 obj-$(CONFIG_INFINIBAND_AMSO1100)      += hw/amso1100/
 obj-$(CONFIG_INFINIBAND_CXGB3)         += hw/cxgb3/
 obj-$(CONFIG_MLX4_INFINIBAND)          += hw/mlx4/
+obj-$(CONFIG_INFINIBAND_NES)           += hw/nes/
 obj-$(CONFIG_INFINIBAND_IPOIB)         += ulp/ipoib/
 obj-$(CONFIG_INFINIBAND_SRP)           += ulp/srp/
 obj-$(CONFIG_INFINIBAND_ISER)          += ulp/iser/
index c0150147d3478d5c539d2e3e320e1722c4b408ba..638b727d42e0796ff57de4de2fd3b4881c1839c4 100644 (file)
@@ -974,6 +974,9 @@ static void cm_format_req(struct cm_req_msg *req_msg,
                          struct cm_id_private *cm_id_priv,
                          struct ib_cm_req_param *param)
 {
+       struct ib_sa_path_rec *pri_path = param->primary_path;
+       struct ib_sa_path_rec *alt_path = param->alternate_path;
+
        cm_format_mad_hdr(&req_msg->hdr, CM_REQ_ATTR_ID,
                          cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_REQ));
 
@@ -997,35 +1000,46 @@ static void cm_format_req(struct cm_req_msg *req_msg,
        cm_req_set_max_cm_retries(req_msg, param->max_cm_retries);
        cm_req_set_srq(req_msg, param->srq);
 
-       req_msg->primary_local_lid = param->primary_path->slid;
-       req_msg->primary_remote_lid = param->primary_path->dlid;
-       req_msg->primary_local_gid = param->primary_path->sgid;
-       req_msg->primary_remote_gid = param->primary_path->dgid;
-       cm_req_set_primary_flow_label(req_msg, param->primary_path->flow_label);
-       cm_req_set_primary_packet_rate(req_msg, param->primary_path->rate);
-       req_msg->primary_traffic_class = param->primary_path->traffic_class;
-       req_msg->primary_hop_limit = param->primary_path->hop_limit;
-       cm_req_set_primary_sl(req_msg, param->primary_path->sl);
-       cm_req_set_primary_subnet_local(req_msg, 1); /* local only... */
+       if (pri_path->hop_limit <= 1) {
+               req_msg->primary_local_lid = pri_path->slid;
+               req_msg->primary_remote_lid = pri_path->dlid;
+       } else {
+               /* Work-around until there's a way to obtain remote LID info */
+               req_msg->primary_local_lid = IB_LID_PERMISSIVE;
+               req_msg->primary_remote_lid = IB_LID_PERMISSIVE;
+       }
+       req_msg->primary_local_gid = pri_path->sgid;
+       req_msg->primary_remote_gid = pri_path->dgid;
+       cm_req_set_primary_flow_label(req_msg, pri_path->flow_label);
+       cm_req_set_primary_packet_rate(req_msg, pri_path->rate);
+       req_msg->primary_traffic_class = pri_path->traffic_class;
+       req_msg->primary_hop_limit = pri_path->hop_limit;
+       cm_req_set_primary_sl(req_msg, pri_path->sl);
+       cm_req_set_primary_subnet_local(req_msg, (pri_path->hop_limit <= 1));
        cm_req_set_primary_local_ack_timeout(req_msg,
                cm_ack_timeout(cm_id_priv->av.port->cm_dev->ack_delay,
-                              param->primary_path->packet_life_time));
+                              pri_path->packet_life_time));
 
-       if (param->alternate_path) {
-               req_msg->alt_local_lid = param->alternate_path->slid;
-               req_msg->alt_remote_lid = param->alternate_path->dlid;
-               req_msg->alt_local_gid = param->alternate_path->sgid;
-               req_msg->alt_remote_gid = param->alternate_path->dgid;
+       if (alt_path) {
+               if (alt_path->hop_limit <= 1) {
+                       req_msg->alt_local_lid = alt_path->slid;
+                       req_msg->alt_remote_lid = alt_path->dlid;
+               } else {
+                       req_msg->alt_local_lid = IB_LID_PERMISSIVE;
+                       req_msg->alt_remote_lid = IB_LID_PERMISSIVE;
+               }
+               req_msg->alt_local_gid = alt_path->sgid;
+               req_msg->alt_remote_gid = alt_path->dgid;
                cm_req_set_alt_flow_label(req_msg,
-                                         param->alternate_path->flow_label);
-               cm_req_set_alt_packet_rate(req_msg, param->alternate_path->rate);
-               req_msg->alt_traffic_class = param->alternate_path->traffic_class;
-               req_msg->alt_hop_limit = param->alternate_path->hop_limit;
-               cm_req_set_alt_sl(req_msg, param->alternate_path->sl);
-               cm_req_set_alt_subnet_local(req_msg, 1); /* local only... */
+                                         alt_path->flow_label);
+               cm_req_set_alt_packet_rate(req_msg, alt_path->rate);
+               req_msg->alt_traffic_class = alt_path->traffic_class;
+               req_msg->alt_hop_limit = alt_path->hop_limit;
+               cm_req_set_alt_sl(req_msg, alt_path->sl);
+               cm_req_set_alt_subnet_local(req_msg, (alt_path->hop_limit <= 1));
                cm_req_set_alt_local_ack_timeout(req_msg,
                        cm_ack_timeout(cm_id_priv->av.port->cm_dev->ack_delay,
-                                      param->alternate_path->packet_life_time));
+                                      alt_path->packet_life_time));
        }
 
        if (param->private_data && param->private_data_len)
@@ -1441,6 +1455,34 @@ out:
        return listen_cm_id_priv;
 }
 
+/*
+ * Work-around for inter-subnet connections.  If the LIDs are permissive,
+ * we need to override the LID/SL data in the REQ with the LID information
+ * in the work completion.
+ */
+static void cm_process_routed_req(struct cm_req_msg *req_msg, struct ib_wc *wc)
+{
+       if (!cm_req_get_primary_subnet_local(req_msg)) {
+               if (req_msg->primary_local_lid == IB_LID_PERMISSIVE) {
+                       req_msg->primary_local_lid = cpu_to_be16(wc->slid);
+                       cm_req_set_primary_sl(req_msg, wc->sl);
+               }
+
+               if (req_msg->primary_remote_lid == IB_LID_PERMISSIVE)
+                       req_msg->primary_remote_lid = cpu_to_be16(wc->dlid_path_bits);
+       }
+
+       if (!cm_req_get_alt_subnet_local(req_msg)) {
+               if (req_msg->alt_local_lid == IB_LID_PERMISSIVE) {
+                       req_msg->alt_local_lid = cpu_to_be16(wc->slid);
+                       cm_req_set_alt_sl(req_msg, wc->sl);
+               }
+
+               if (req_msg->alt_remote_lid == IB_LID_PERMISSIVE)
+                       req_msg->alt_remote_lid = cpu_to_be16(wc->dlid_path_bits);
+       }
+}
+
 static int cm_req_handler(struct cm_work *work)
 {
        struct ib_cm_id *cm_id;
@@ -1481,6 +1523,7 @@ static int cm_req_handler(struct cm_work *work)
        cm_id_priv->id.service_id = req_msg->service_id;
        cm_id_priv->id.service_mask = __constant_cpu_to_be64(~0ULL);
 
+       cm_process_routed_req(req_msg, work->mad_recv_wc->wc);
        cm_format_paths_from_req(req_msg, &work->path[0], &work->path[1]);
        ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av);
        if (ret) {
index 6c7aa59794d4ebb248f8e16fe789e7bdace6f81d..7f00347364f7a4b07f4b0237cb77ab45983c2732 100644 (file)
@@ -320,10 +320,13 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd             *pd,
                        .max_maps   = pool->max_remaps,
                        .page_shift = params->page_shift
                };
+               int bytes_per_fmr = sizeof *fmr;
+
+               if (pool->cache_bucket)
+                       bytes_per_fmr += params->max_pages_per_fmr * sizeof (u64);
 
                for (i = 0; i < params->pool_size; ++i) {
-                       fmr = kmalloc(sizeof *fmr + params->max_pages_per_fmr * sizeof (u64),
-                                     GFP_KERNEL);
+                       fmr = kmalloc(bytes_per_fmr, GFP_KERNEL);
                        if (!fmr) {
                                printk(KERN_WARNING PFX "failed to allocate fmr "
                                       "struct for FMR %d\n", i);
index f281d16040f5ac794e14e28820b37e537a7db51f..92cce8aacbb7279d3f45af63ac8e812001111ef6 100644 (file)
@@ -101,6 +101,7 @@ struct ehca_sport {
        spinlock_t mod_sqp_lock;
        enum ib_port_state port_state;
        struct ehca_sma_attr saved_attr;
+       u32 pma_qp_nr;
 };
 
 #define HCA_CAP_MR_PGSIZE_4K  0x80000000
index 863b34fa9ff9391c85fa1411d13ee4ce759436db..b5ca94c6b8d91a603aebff7f907c42f3234bb31e 100644 (file)
@@ -403,6 +403,8 @@ static void parse_ec(struct ehca_shca *shca, u64 eqe)
                        sport->port_state = IB_PORT_ACTIVE;
                        dispatch_port_event(shca, port, IB_EVENT_PORT_ACTIVE,
                                            "is active");
+                       ehca_query_sma_attr(shca, port,
+                                           &sport->saved_attr);
                } else
                        notify_port_conf_change(shca, port);
                break;
index c469bfde270875521f91411df5ea51b4f4bed13e..a8a2ea585d2f93c038300652e4a329f55ede6f27 100644 (file)
@@ -187,6 +187,11 @@ int ehca_dealloc_ucontext(struct ib_ucontext *context);
 
 int ehca_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
 
+int ehca_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
+                    struct ib_wc *in_wc, struct ib_grh *in_grh,
+                    struct ib_mad *in_mad,
+                    struct ib_mad *out_mad);
+
 void ehca_poll_eqs(unsigned long data);
 
 int ehca_calc_ipd(struct ehca_shca *shca, int port,
index 84c9b7b8669b0edc1833ff3c18c388d6feeb5999..a86ebcc79a95a7db5343cdcd4f37fb6a9a1e8d07 100644 (file)
@@ -472,7 +472,7 @@ int ehca_init_device(struct ehca_shca *shca)
        shca->ib_device.dealloc_fmr         = ehca_dealloc_fmr;
        shca->ib_device.attach_mcast        = ehca_attach_mcast;
        shca->ib_device.detach_mcast        = ehca_detach_mcast;
-       /* shca->ib_device.process_mad      = ehca_process_mad;     */
+       shca->ib_device.process_mad         = ehca_process_mad;
        shca->ib_device.mmap                = ehca_mmap;
 
        if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) {
index 3aacc8cf1e448391feb37accef997118c5ca6f08..2ce8cffb8664537035586cf30a5004adcdb83a25 100644 (file)
@@ -209,6 +209,10 @@ static inline int ehca_write_swqe(struct ehca_qp *qp,
                        ehca_gen_err("wr.ud.ah is NULL. qp=%p", qp);
                        return -EINVAL;
                }
+               if (unlikely(send_wr->wr.ud.remote_qpn == 0)) {
+                       ehca_gen_err("dest QP# is 0. qp=%x", qp->real_qp_num);
+                       return -EINVAL;
+               }
                my_av = container_of(send_wr->wr.ud.ah, struct ehca_av, ib_ah);
                wqe_p->u.ud_av.ud_av = my_av->av;
 
index 79e72b25b252f33fd6d1d6d5c1ac18b1e12969bd..706d97ad5555cd5243cf8a2081d46c5f743b5b03 100644 (file)
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <rdma/ib_mad.h>
 
 #include "ehca_classes.h"
 #include "ehca_tools.h"
 #include "ehca_iverbs.h"
 #include "hcp_if.h"
 
+#define IB_MAD_STATUS_REDIRECT         __constant_htons(0x0002)
+#define IB_MAD_STATUS_UNSUP_VERSION    __constant_htons(0x0004)
+#define IB_MAD_STATUS_UNSUP_METHOD     __constant_htons(0x0008)
+
+#define IB_PMA_CLASS_PORT_INFO         __constant_htons(0x0001)
 
 /**
  * ehca_define_sqp - Defines special queue pair 1 (GSI QP). When special queue
@@ -83,6 +89,9 @@ u64 ehca_define_sqp(struct ehca_shca *shca,
                                 port, ret);
                        return ret;
                }
+               shca->sport[port - 1].pma_qp_nr = pma_qp_nr;
+               ehca_dbg(&shca->ib_device, "port=%x pma_qp_nr=%x",
+                        port, pma_qp_nr);
                break;
        default:
                ehca_err(&shca->ib_device, "invalid qp_type=%x",
@@ -109,3 +118,85 @@ u64 ehca_define_sqp(struct ehca_shca *shca,
 
        return H_SUCCESS;
 }
+
+struct ib_perf {
+       struct ib_mad_hdr mad_hdr;
+       u8 reserved[40];
+       u8 data[192];
+} __attribute__ ((packed));
+
+
+static int ehca_process_perf(struct ib_device *ibdev, u8 port_num,
+                            struct ib_mad *in_mad, struct ib_mad *out_mad)
+{
+       struct ib_perf *in_perf = (struct ib_perf *)in_mad;
+       struct ib_perf *out_perf = (struct ib_perf *)out_mad;
+       struct ib_class_port_info *poi =
+               (struct ib_class_port_info *)out_perf->data;
+       struct ehca_shca *shca =
+               container_of(ibdev, struct ehca_shca, ib_device);
+       struct ehca_sport *sport = &shca->sport[port_num - 1];
+
+       ehca_dbg(ibdev, "method=%x", in_perf->mad_hdr.method);
+
+       *out_mad = *in_mad;
+
+       if (in_perf->mad_hdr.class_version != 1) {
+               ehca_warn(ibdev, "Unsupported class_version=%x",
+                         in_perf->mad_hdr.class_version);
+               out_perf->mad_hdr.status = IB_MAD_STATUS_UNSUP_VERSION;
+               goto perf_reply;
+       }
+
+       switch (in_perf->mad_hdr.method) {
+       case IB_MGMT_METHOD_GET:
+       case IB_MGMT_METHOD_SET:
+               /* set class port info for redirection */
+               out_perf->mad_hdr.attr_id = IB_PMA_CLASS_PORT_INFO;
+               out_perf->mad_hdr.status = IB_MAD_STATUS_REDIRECT;
+               memset(poi, 0, sizeof(*poi));
+               poi->base_version = 1;
+               poi->class_version = 1;
+               poi->resp_time_value = 18;
+               poi->redirect_lid = sport->saved_attr.lid;
+               poi->redirect_qp = sport->pma_qp_nr;
+               poi->redirect_qkey = IB_QP1_QKEY;
+               poi->redirect_pkey = IB_DEFAULT_PKEY_FULL;
+
+               ehca_dbg(ibdev, "ehca_pma_lid=%x ehca_pma_qp=%x",
+                        sport->saved_attr.lid, sport->pma_qp_nr);
+               break;
+
+       case IB_MGMT_METHOD_GET_RESP:
+               return IB_MAD_RESULT_FAILURE;
+
+       default:
+               out_perf->mad_hdr.status = IB_MAD_STATUS_UNSUP_METHOD;
+               break;
+       }
+
+perf_reply:
+       out_perf->mad_hdr.method = IB_MGMT_METHOD_GET_RESP;
+
+       return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
+}
+
+int ehca_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
+                    struct ib_wc *in_wc, struct ib_grh *in_grh,
+                    struct ib_mad *in_mad,
+                    struct ib_mad *out_mad)
+{
+       int ret;
+
+       if (!port_num || port_num > ibdev->phys_port_cnt)
+               return IB_MAD_RESULT_FAILURE;
+
+       /* accept only pma request */
+       if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_PERF_MGMT)
+               return IB_MAD_RESULT_SUCCESS;
+
+       ehca_dbg(ibdev, "port_num=%x src_qp=%x", port_num, in_wc->src_qp);
+       ret = ehca_process_perf(ibdev, port_num, in_mad, out_mad);
+
+       return ret;
+}
index d8287d9db41e5a8eb0bb3167db75635c266b4960..96a39b5c9254491a6e0b0aae227f7fb327ad0df9 100644 (file)
@@ -52,7 +52,7 @@ MODULE_DESCRIPTION("Mellanox ConnectX HCA InfiniBand driver");
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_VERSION(DRV_VERSION);
 
-static const char mlx4_ib_version[] __devinitdata =
+static const char mlx4_ib_version[] =
        DRV_NAME ": Mellanox ConnectX InfiniBand driver v"
        DRV_VERSION " (" DRV_RELDATE ")\n";
 
@@ -468,6 +468,7 @@ static int init_node_data(struct mlx4_ib_dev *dev)
        if (err)
                goto out;
 
+       dev->dev->rev_id = be32_to_cpup((__be32 *) (out_mad->data + 32));
        memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
 
 out:
@@ -516,9 +517,16 @@ static struct class_device_attribute *mlx4_class_attributes[] = {
 
 static void *mlx4_ib_add(struct mlx4_dev *dev)
 {
+       static int mlx4_ib_version_printed;
        struct mlx4_ib_dev *ibdev;
        int i;
 
+
+       if (!mlx4_ib_version_printed) {
+               printk(KERN_INFO "%s", mlx4_ib_version);
+               ++mlx4_ib_version_printed;
+       }
+
        ibdev = (struct mlx4_ib_dev *) ib_alloc_device(sizeof *ibdev);
        if (!ibdev) {
                dev_err(&dev->pdev->dev, "Device struct alloc failed\n");
index 6966f943f44036b2fee4c07ccb4f0eda25a0956f..09a30dd12b147433020a796ef94b21cd33725bf3 100644 (file)
@@ -1255,9 +1255,14 @@ int mthca_QUERY_ADAPTER(struct mthca_dev *dev,
        if (err)
                goto out;
 
-       MTHCA_GET(adapter->vendor_id, outbox,   QUERY_ADAPTER_VENDOR_ID_OFFSET);
-       MTHCA_GET(adapter->device_id, outbox,   QUERY_ADAPTER_DEVICE_ID_OFFSET);
-       MTHCA_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET);
+       if (!mthca_is_memfree(dev)) {
+               MTHCA_GET(adapter->vendor_id, outbox,
+                         QUERY_ADAPTER_VENDOR_ID_OFFSET);
+               MTHCA_GET(adapter->device_id, outbox,
+                         QUERY_ADAPTER_DEVICE_ID_OFFSET);
+               MTHCA_GET(adapter->revision_id, outbox,
+                         QUERY_ADAPTER_REVISION_ID_OFFSET);
+       }
        MTHCA_GET(adapter->inta_pin, outbox,    QUERY_ADAPTER_INTA_PIN_OFFSET);
 
        get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4,
index 5cf8250d4e164003312fed79579b578267c94eed..cd3d8adbef9ffe6a5f6d8d152ad9b5b8aa20c155 100644 (file)
@@ -126,7 +126,7 @@ module_param_named(fmr_reserved_mtts, hca_profile.fmr_reserved_mtts, int, 0444);
 MODULE_PARM_DESC(fmr_reserved_mtts,
                 "number of memory translation table segments reserved for FMR");
 
-static const char mthca_version[] __devinitdata =
+static char mthca_version[] __devinitdata =
        DRV_NAME ": Mellanox InfiniBand HCA driver v"
        DRV_VERSION " (" DRV_RELDATE ")\n";
 
@@ -735,7 +735,8 @@ static int mthca_init_hca(struct mthca_dev *mdev)
        }
 
        mdev->eq_table.inta_pin = adapter.inta_pin;
-       mdev->rev_id            = adapter.revision_id;
+       if (!mthca_is_memfree(mdev))
+               mdev->rev_id = adapter.revision_id;
        memcpy(mdev->board_id, adapter.board_id, sizeof mdev->board_id);
 
        return 0;
index aa6c70a6a36f24c35fbfc3d7bff3b741a18f6cae..3b6985557cb21cb77cc05df345a9dfb8dd573d3d 100644 (file)
@@ -613,8 +613,10 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
                        sizeof *(mr->mem.tavor.mpt) * idx;
 
        mr->mtt = __mthca_alloc_mtt(dev, list_len, dev->mr_table.fmr_mtt_buddy);
-       if (IS_ERR(mr->mtt))
+       if (IS_ERR(mr->mtt)) {
+               err = PTR_ERR(mr->mtt);
                goto err_out_table;
+       }
 
        mtt_seg = mr->mtt->first_seg * MTHCA_MTT_SEG_SIZE;
 
@@ -627,8 +629,10 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
                mr->mem.tavor.mtts = dev->mr_table.tavor_fmr.mtt_base + mtt_seg;
 
        mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
-       if (IS_ERR(mailbox))
+       if (IS_ERR(mailbox)) {
+               err = PTR_ERR(mailbox);
                goto err_out_free_mtt;
+       }
 
        mpt_entry = mailbox->buf;
 
index 6bcde1cb9688f9860b8116fb22526553a23d5746..9e491df6419cd12b2266fb2846f381479d6e07b4 100644 (file)
@@ -923,17 +923,13 @@ static struct ib_mr *mthca_reg_phys_mr(struct ib_pd       *pd,
        struct mthca_mr *mr;
        u64 *page_list;
        u64 total_size;
-       u64 mask;
+       unsigned long mask;
        int shift;
        int npages;
        int err;
        int i, j, n;
 
-       /* First check that we have enough alignment */
-       if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK))
-               return ERR_PTR(-EINVAL);
-
-       mask = 0;
+       mask = buffer_list[0].addr ^ *iova_start;
        total_size = 0;
        for (i = 0; i < num_phys_buf; ++i) {
                if (i != 0)
@@ -947,17 +943,7 @@ static struct ib_mr *mthca_reg_phys_mr(struct ib_pd       *pd,
        if (mask & ~PAGE_MASK)
                return ERR_PTR(-EINVAL);
 
-       /* Find largest page shift we can use to cover buffers */
-       for (shift = PAGE_SHIFT; shift < 31; ++shift)
-               if (num_phys_buf > 1) {
-                       if ((1ULL << shift) & mask)
-                               break;
-               } else {
-                       if (1ULL << shift >=
-                           buffer_list[0].size +
-                           (buffer_list[0].addr & ((1ULL << shift) - 1)))
-                               break;
-               }
+       shift = __ffs(mask | 1 << 31);
 
        buffer_list[0].size += buffer_list[0].addr & ((1ULL << shift) - 1);
        buffer_list[0].addr &= ~0ull << shift;
@@ -1270,6 +1256,8 @@ static int mthca_init_node_data(struct mthca_dev *dev)
                goto out;
        }
 
+       if (mthca_is_memfree(dev))
+               dev->rev_id = be32_to_cpup((__be32 *) (out_mad->data + 32));
        memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
 
 out:
index 0e5461c65731db15ec38a16bc670ca331f69b4b7..db5595bbf7f08fb30e5993a301e063b2df21ee05 100644 (file)
@@ -1175,6 +1175,7 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
 {
        int ret;
        int i;
+       struct mthca_next_seg *next;
 
        qp->refcount = 1;
        init_waitqueue_head(&qp->wait);
@@ -1217,7 +1218,6 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
        }
 
        if (mthca_is_memfree(dev)) {
-               struct mthca_next_seg *next;
                struct mthca_data_seg *scatter;
                int size = (sizeof (struct mthca_next_seg) +
                            qp->rq.max_gs * sizeof (struct mthca_data_seg)) / 16;
@@ -1240,6 +1240,13 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
                                                    qp->sq.wqe_shift) +
                                                   qp->send_wqe_offset);
                }
+       } else {
+               for (i = 0; i < qp->rq.max; ++i) {
+                       next = get_recv_wqe(qp, i);
+                       next->nda_op = htonl((((i + 1) % qp->rq.max) <<
+                                             qp->rq.wqe_shift) | 1);
+               }
+
        }
 
        qp->sq.last = get_send_wqe(qp, qp->sq.max - 1);
@@ -1863,7 +1870,6 @@ int mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
                prev_wqe = qp->rq.last;
                qp->rq.last = wqe;
 
-               ((struct mthca_next_seg *) wqe)->nda_op = 0;
                ((struct mthca_next_seg *) wqe)->ee_nds =
                        cpu_to_be32(MTHCA_NEXT_DBD);
                ((struct mthca_next_seg *) wqe)->flags = 0;
@@ -1885,9 +1891,6 @@ int mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
 
                qp->wrid[ind] = wr->wr_id;
 
-               ((struct mthca_next_seg *) prev_wqe)->nda_op =
-                       cpu_to_be32((ind << qp->rq.wqe_shift) | 1);
-               wmb();
                ((struct mthca_next_seg *) prev_wqe)->ee_nds =
                        cpu_to_be32(MTHCA_NEXT_DBD | size);
 
index 553d681f6813a709a2d8e2a5601c8e1dc98bc902..a5ffff6e10263c06c296c0c6d7c0dd3f35b8bd2f 100644 (file)
@@ -175,9 +175,17 @@ static int mthca_alloc_srq_buf(struct mthca_dev *dev, struct mthca_pd *pd,
         * scatter list L_Keys to the sentry value of 0x100.
         */
        for (i = 0; i < srq->max; ++i) {
-               wqe = get_wqe(srq, i);
+               struct mthca_next_seg *next;
 
-               *wqe_to_link(wqe) = i < srq->max - 1 ? i + 1 : -1;
+               next = wqe = get_wqe(srq, i);
+
+               if (i < srq->max - 1) {
+                       *wqe_to_link(wqe) = i + 1;
+                       next->nda_op = htonl(((i + 1) << srq->wqe_shift) | 1);
+               } else {
+                       *wqe_to_link(wqe) = -1;
+                       next->nda_op = 0;
+               }
 
                for (scatter = wqe + sizeof (struct mthca_next_seg);
                     (void *) scatter < wqe + (1 << srq->wqe_shift);
@@ -470,16 +478,15 @@ out:
 void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr)
 {
        int ind;
+       struct mthca_next_seg *last_free;
 
        ind = wqe_addr >> srq->wqe_shift;
 
        spin_lock(&srq->lock);
 
-       if (likely(srq->first_free >= 0))
-               *wqe_to_link(get_wqe(srq, srq->last_free)) = ind;
-       else
-               srq->first_free = ind;
-
+       last_free = get_wqe(srq, srq->last_free);
+       *wqe_to_link(last_free) = ind;
+       last_free->nda_op = htonl((ind << srq->wqe_shift) | 1);
        *wqe_to_link(get_wqe(srq, ind)) = -1;
        srq->last_free = ind;
 
@@ -506,15 +513,7 @@ int mthca_tavor_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
        first_ind = srq->first_free;
 
        for (nreq = 0; wr; wr = wr->next) {
-               ind = srq->first_free;
-
-               if (unlikely(ind < 0)) {
-                       mthca_err(dev, "SRQ %06x full\n", srq->srqn);
-                       err = -ENOMEM;
-                       *bad_wr = wr;
-                       break;
-               }
-
+               ind       = srq->first_free;
                wqe       = get_wqe(srq, ind);
                next_ind  = *wqe_to_link(wqe);
 
@@ -528,7 +527,6 @@ int mthca_tavor_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
                prev_wqe  = srq->last;
                srq->last = wqe;
 
-               ((struct mthca_next_seg *) wqe)->nda_op = 0;
                ((struct mthca_next_seg *) wqe)->ee_nds = 0;
                /* flags field will always remain 0 */
 
@@ -549,9 +547,6 @@ int mthca_tavor_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
                if (i < srq->max_gs)
                        mthca_set_data_seg_inval(wqe);
 
-               ((struct mthca_next_seg *) prev_wqe)->nda_op =
-                       cpu_to_be32((ind << srq->wqe_shift) | 1);
-               wmb();
                ((struct mthca_next_seg *) prev_wqe)->ee_nds =
                        cpu_to_be32(MTHCA_NEXT_DBD);
 
@@ -614,15 +609,7 @@ int mthca_arbel_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
        spin_lock_irqsave(&srq->lock, flags);
 
        for (nreq = 0; wr; ++nreq, wr = wr->next) {
-               ind = srq->first_free;
-
-               if (unlikely(ind < 0)) {
-                       mthca_err(dev, "SRQ %06x full\n", srq->srqn);
-                       err = -ENOMEM;
-                       *bad_wr = wr;
-                       break;
-               }
-
+               ind       = srq->first_free;
                wqe       = get_wqe(srq, ind);
                next_ind  = *wqe_to_link(wqe);
 
@@ -633,8 +620,6 @@ int mthca_arbel_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
                        break;
                }
 
-               ((struct mthca_next_seg *) wqe)->nda_op =
-                       cpu_to_be32((next_ind << srq->wqe_shift) | 1);
                ((struct mthca_next_seg *) wqe)->ee_nds = 0;
                /* flags field will always remain 0 */
 
diff --git a/drivers/infiniband/hw/nes/Kconfig b/drivers/infiniband/hw/nes/Kconfig
new file mode 100644 (file)
index 0000000..2aeb7ac
--- /dev/null
@@ -0,0 +1,16 @@
+config INFINIBAND_NES
+       tristate "NetEffect RNIC Driver"
+       depends on PCI && INET && INFINIBAND
+       select LIBCRC32C
+       ---help---
+         This is a low-level driver for NetEffect RDMA enabled
+         Network Interface Cards (RNIC).
+
+config INFINIBAND_NES_DEBUG
+       bool "Verbose debugging output"
+       depends on INFINIBAND_NES
+       default n
+       ---help---
+         This option causes the NetEffect RNIC driver to produce debug
+         messages.  Select this if you are developing the driver
+         or trying to diagnose a problem.
diff --git a/drivers/infiniband/hw/nes/Makefile b/drivers/infiniband/hw/nes/Makefile
new file mode 100644 (file)
index 0000000..3514851
--- /dev/null
@@ -0,0 +1,3 @@
+obj-$(CONFIG_INFINIBAND_NES) += iw_nes.o
+
+iw_nes-objs := nes.o nes_hw.o nes_nic.o nes_utils.o nes_verbs.o nes_cm.o
diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
new file mode 100644 (file)
index 0000000..7f8853b
--- /dev/null
@@ -0,0 +1,1152 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/if_vlan.h>
+#include <linux/crc32.h>
+#include <linux/in.h>
+#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/if_arp.h>
+#include <linux/highmem.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/byteorder.h>
+#include <rdma/ib_smi.h>
+#include <rdma/ib_verbs.h>
+#include <rdma/ib_pack.h>
+#include <rdma/iw_cm.h>
+
+#include "nes.h"
+
+#include <net/netevent.h>
+#include <net/neighbour.h>
+#include <linux/route.h>
+#include <net/ip_fib.h>
+
+MODULE_AUTHOR("NetEffect");
+MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_VERSION(DRV_VERSION);
+
+int max_mtu = 9000;
+int nics_per_function = 1;
+int interrupt_mod_interval = 0;
+
+
+/* Interoperability */
+int mpa_version = 1;
+module_param(mpa_version, int, 0);
+MODULE_PARM_DESC(mpa_version, "MPA version to be used int MPA Req/Resp (0 or 1)");
+
+/* Interoperability */
+int disable_mpa_crc = 0;
+module_param(disable_mpa_crc, int, 0);
+MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
+
+unsigned int send_first = 0;
+module_param(send_first, int, 0);
+MODULE_PARM_DESC(send_first, "Send RDMA Message First on Active Connection");
+
+
+unsigned int nes_drv_opt = 0;
+module_param(nes_drv_opt, int, 0);
+MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
+
+unsigned int nes_debug_level = 0;
+module_param_named(debug_level, nes_debug_level, uint, 0644);
+MODULE_PARM_DESC(debug_level, "Enable debug output level");
+
+LIST_HEAD(nes_adapter_list);
+LIST_HEAD(nes_dev_list);
+
+atomic_t qps_destroyed;
+atomic_t cqp_reqs_allocated;
+atomic_t cqp_reqs_freed;
+atomic_t cqp_reqs_dynallocated;
+atomic_t cqp_reqs_dynfreed;
+atomic_t cqp_reqs_queued;
+atomic_t cqp_reqs_redriven;
+
+static void nes_print_macaddr(struct net_device *netdev);
+static irqreturn_t nes_interrupt(int, void *);
+static int __devinit nes_probe(struct pci_dev *, const struct pci_device_id *);
+static void __devexit nes_remove(struct pci_dev *);
+static int __init nes_init_module(void);
+static void __exit nes_exit_module(void);
+static unsigned int ee_flsh_adapter;
+static unsigned int sysfs_nonidx_addr;
+static unsigned int sysfs_idx_addr;
+
+static struct pci_device_id nes_pci_table[] = {
+       {PCI_VENDOR_ID_NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020, PCI_ANY_ID, PCI_ANY_ID},
+       {0}
+};
+
+MODULE_DEVICE_TABLE(pci, nes_pci_table);
+
+static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
+static int nes_net_event(struct notifier_block *, unsigned long, void *);
+static int nes_notifiers_registered;
+
+
+static struct notifier_block nes_inetaddr_notifier = {
+       .notifier_call = nes_inetaddr_event
+};
+
+static struct notifier_block nes_net_notifier = {
+       .notifier_call = nes_net_event
+};
+
+
+
+
+/**
+ * nes_inetaddr_event
+ */
+static int nes_inetaddr_event(struct notifier_block *notifier,
+               unsigned long event, void *ptr)
+{
+       struct in_ifaddr *ifa = ptr;
+       struct net_device *event_netdev = ifa->ifa_dev->dev;
+       struct nes_device *nesdev;
+       struct net_device *netdev;
+       struct nes_vnic *nesvnic;
+       unsigned int addr;
+       unsigned int mask;
+
+       addr = ntohl(ifa->ifa_address);
+       mask = ntohl(ifa->ifa_mask);
+       nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %08X, netmask %08X.\n",
+                       addr, mask);
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
+                               nesdev, nesdev->netdev[0]->name);
+               netdev = nesdev->netdev[0];
+               nesvnic = netdev_priv(netdev);
+               if (netdev == event_netdev) {
+                       if (nesvnic->rdma_enabled == 0) {
+                               nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
+                                               " RDMA is not enabled.\n",
+                                               netdev->name);
+                               return NOTIFY_OK;
+                       }
+                       /* we have ifa->ifa_address/mask here if we need it */
+                       switch (event) {
+                               case NETDEV_DOWN:
+                                       nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
+                                       nes_write_indexed(nesdev,
+                                                       NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
+
+                                       nes_manage_arp_cache(netdev, netdev->dev_addr,
+                                                       ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
+                                       nesvnic->local_ipaddr = 0;
+                                       return NOTIFY_OK;
+                                       break;
+                               case NETDEV_UP:
+                                       nes_debug(NES_DBG_NETDEV, "event:UP\n");
+
+                                       if (nesvnic->local_ipaddr != 0) {
+                                               nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
+                                               return NOTIFY_OK;
+                                       }
+                                       /* Add the address to the IP table */
+                                       nesvnic->local_ipaddr = ifa->ifa_address;
+
+                                       nes_write_indexed(nesdev,
+                                                       NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
+                                                       ntohl(ifa->ifa_address));
+                                       nes_manage_arp_cache(netdev, netdev->dev_addr,
+                                                       ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
+                                       return NOTIFY_OK;
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+       }
+
+       return NOTIFY_DONE;
+}
+
+
+/**
+ * nes_net_event
+ */
+static int nes_net_event(struct notifier_block *notifier,
+               unsigned long event, void *ptr)
+{
+       struct neighbour *neigh = ptr;
+       struct nes_device *nesdev;
+       struct net_device *netdev;
+       struct nes_vnic *nesvnic;
+
+       switch (event) {
+               case NETEVENT_NEIGH_UPDATE:
+                       list_for_each_entry(nesdev, &nes_dev_list, list) {
+                               /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
+                               netdev = nesdev->netdev[0];
+                               nesvnic = netdev_priv(netdev);
+                               if (netdev == neigh->dev) {
+                                       if (nesvnic->rdma_enabled == 0) {
+                                               nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
+                                                               netdev->name);
+                                       } else {
+                                               if (neigh->nud_state & NUD_VALID) {
+                                                       nes_manage_arp_cache(neigh->dev, neigh->ha,
+                                                                       ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
+                                               } else {
+                                                       nes_manage_arp_cache(neigh->dev, neigh->ha,
+                                                                       ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
+                                               }
+                                       }
+                                       return NOTIFY_OK;
+                               }
+                       }
+                       break;
+               default:
+                       nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
+                       break;
+       }
+
+       return NOTIFY_DONE;
+}
+
+
+/**
+ * nes_add_ref
+ */
+void nes_add_ref(struct ib_qp *ibqp)
+{
+       struct nes_qp *nesqp;
+
+       nesqp = to_nesqp(ibqp);
+       nes_debug(NES_DBG_QP, "Bumping refcount for QP%u.  Pre-inc value = %u\n",
+                       ibqp->qp_num, atomic_read(&nesqp->refcount));
+       atomic_inc(&nesqp->refcount);
+}
+
+static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
+{
+       unsigned long flags;
+       struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 qp_id;
+
+       atomic_inc(&qps_destroyed);
+
+       /* Free the control structures */
+
+       qp_id = nesqp->hwqp.qp_id;
+       if (nesqp->pbl_vbase) {
+               pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
+                               nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
+               spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+               nesadapter->free_256pbl++;
+               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+               pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
+               nesqp->pbl_vbase = NULL;
+
+       } else {
+               pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
+                               nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
+       }
+       nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
+
+       kfree(nesqp->allocated_buffer);
+
+}
+
+/**
+ * nes_rem_ref
+ */
+void nes_rem_ref(struct ib_qp *ibqp)
+{
+       u64 u64temp;
+       struct nes_qp *nesqp;
+       struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_cqp_request *cqp_request;
+       u32 opcode;
+
+       nesqp = to_nesqp(ibqp);
+
+       if (atomic_read(&nesqp->refcount) == 0) {
+               printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
+                               __FUNCTION__, ibqp->qp_num, nesqp->last_aeq);
+               BUG();
+       }
+
+       if (atomic_dec_and_test(&nesqp->refcount)) {
+               nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
+
+               /* Destroy the QP */
+               cqp_request = nes_get_cqp_request(nesdev);
+               if (cqp_request == NULL) {
+                       nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
+                       return;
+               }
+               cqp_request->waiting = 0;
+               cqp_request->callback = 1;
+               cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
+               cqp_request->cqp_callback_pointer = nesqp;
+               cqp_wqe = &cqp_request->cqp_wqe;
+
+               nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+               opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
+
+               if (nesqp->hte_added) {
+                       opcode  |= NES_CQP_QP_DEL_HTE;
+                       nesqp->hte_added = 0;
+               }
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
+               u64temp = (u64)nesqp->nesqp_context_pbase;
+               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
+               nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+       }
+}
+
+
+/**
+ * nes_get_qp
+ */
+struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
+{
+       struct nes_vnic *nesvnic = to_nesvnic(device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+
+       if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
+               return NULL;
+
+       return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
+}
+
+
+/**
+ * nes_print_macaddr
+ */
+static void nes_print_macaddr(struct net_device *netdev)
+{
+       nes_debug(NES_DBG_INIT, "%s: MAC %02X:%02X:%02X:%02X:%02X:%02X, IRQ %u\n",
+                       netdev->name,
+                       netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
+                       netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5],
+                       netdev->irq);
+}
+
+
+/**
+ * nes_interrupt - handle interrupts
+ */
+static irqreturn_t nes_interrupt(int irq, void *dev_id)
+{
+       struct nes_device *nesdev = (struct nes_device *)dev_id;
+       int handled = 0;
+       u32 int_mask;
+       u32 int_req;
+       u32 int_stat;
+       u32 intf_int_stat;
+       u32 timer_stat;
+
+       if (nesdev->msi_enabled) {
+               /* No need to read the interrupt pending register if msi is enabled */
+               handled = 1;
+       } else {
+               if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
+                       /* Master interrupt enable provides synchronization for kicking off bottom half
+                         when interrupt sharing is going on */
+                       int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
+                       if (int_mask & 0x80000000) {
+                               /* Check interrupt status to see if this might be ours */
+                               int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
+                               int_req = nesdev->int_req;
+                               if (int_stat&int_req) {
+                                       /* if interesting CEQ or AEQ is pending, claim the interrupt */
+                                       if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
+                                               handled = 1;
+                                       } else {
+                                               if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
+                                                       /* Timer might be running but might be for another function */
+                                                       timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
+                                                       if ((timer_stat & nesdev->timer_int_req) != 0) {
+                                                               handled = 1;
+                                                       }
+                                               }
+                                               if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
+                                                               (handled == 0)) {
+                                                       intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
+                                                       if ((intf_int_stat & nesdev->intf_int_req) != 0) {
+                                                               handled = 1;
+                                                       }
+                                               }
+                                       }
+                                       if (handled) {
+                                               nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
+                                               int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
+                                               /* Save off the status to save an additional read */
+                                               nesdev->int_stat = int_stat;
+                                               nesdev->napi_isr_ran = 1;
+                                       }
+                               }
+                       }
+               } else {
+                       handled = nes_read32(nesdev->regs+NES_INT_PENDING);
+               }
+       }
+
+       if (handled) {
+
+               if (nes_napi_isr(nesdev) == 0) {
+                       tasklet_schedule(&nesdev->dpc_tasklet);
+
+               }
+               return IRQ_HANDLED;
+       } else {
+               return IRQ_NONE;
+       }
+}
+
+
+/**
+ * nes_probe - Device initialization
+ */
+static int __devinit nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
+{
+       struct net_device *netdev = NULL;
+       struct nes_device *nesdev = NULL;
+       int ret = 0;
+       struct nes_vnic *nesvnic = NULL;
+       void __iomem *mmio_regs = NULL;
+       u8 hw_rev;
+
+       assert(pcidev != NULL);
+       assert(ent != NULL);
+
+       printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
+                       DRV_VERSION, pci_name(pcidev));
+
+       ret = pci_enable_device(pcidev);
+       if (ret) {
+               printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
+               goto bail0;
+       }
+
+       nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
+                       (long unsigned int)pci_resource_start(pcidev, BAR_0),
+                       (long unsigned int)pci_resource_len(pcidev, BAR_0));
+       nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
+                       (long unsigned int)pci_resource_start(pcidev, BAR_1),
+                       (long unsigned int)pci_resource_len(pcidev, BAR_1));
+
+       /* Make sure PCI base addr are MMIO */
+       if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
+                       !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
+               printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
+               ret = -ENODEV;
+               goto bail1;
+       }
+
+       /* Reserve PCI I/O and memory resources */
+       ret = pci_request_regions(pcidev, DRV_NAME);
+       if (ret) {
+               printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
+               goto bail1;
+       }
+
+       if ((sizeof(dma_addr_t) > 4)) {
+               ret = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
+               if (ret < 0) {
+                       printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
+                       goto bail2;
+               }
+               ret = pci_set_consistent_dma_mask(pcidev, DMA_64BIT_MASK);
+               if (ret) {
+                       printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
+                       goto bail2;
+               }
+       } else {
+               ret = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
+               if (ret < 0) {
+                       printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
+                       goto bail2;
+               }
+               ret = pci_set_consistent_dma_mask(pcidev, DMA_32BIT_MASK);
+               if (ret) {
+                       printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
+                       goto bail2;
+               }
+       }
+
+       pci_set_master(pcidev);
+
+       /* Allocate hardware structure */
+       nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
+       if (!nesdev) {
+               printk(KERN_ERR PFX "%s: Unable to alloc hardware struct\n", pci_name(pcidev));
+               ret = -ENOMEM;
+               goto bail2;
+       }
+
+       nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
+       nesdev->pcidev = pcidev;
+       pci_set_drvdata(pcidev, nesdev);
+
+       pci_read_config_byte(pcidev, 0x0008, &hw_rev);
+       nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
+
+       spin_lock_init(&nesdev->indexed_regs_lock);
+
+       /* Remap the PCI registers in adapter BAR0 to kernel VA space */
+       mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0), sizeof(mmio_regs));
+       if (mmio_regs == NULL) {
+               printk(KERN_ERR PFX "Unable to remap BAR0\n");
+               ret = -EIO;
+               goto bail3;
+       }
+       nesdev->regs = mmio_regs;
+       nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
+
+       /* Ensure interrupts are disabled */
+       nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
+
+       if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
+               if (!pci_enable_msi(nesdev->pcidev)) {
+                       nesdev->msi_enabled = 1;
+                       nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
+                                       pci_name(pcidev));
+               } else {
+                       nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
+                                       pci_name(pcidev));
+               }
+       } else {
+               nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
+                               pci_name(pcidev));
+       }
+
+       nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
+       nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
+
+       /* Init the adapter */
+       nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
+       nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
+       if (!nesdev->nesadapter) {
+               printk(KERN_ERR PFX "Unable to initialize adapter.\n");
+               ret = -ENOMEM;
+               goto bail5;
+       }
+
+       /* nesdev->base_doorbell_index =
+                       nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
+       nesdev->base_doorbell_index = 1;
+       nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
+       nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) % nesdev->nesadapter->port_count;
+
+       tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
+
+       /* bring up the Control QP */
+       if (nes_init_cqp(nesdev)) {
+               ret = -ENODEV;
+               goto bail6;
+       }
+
+       /* Arm the CCQ */
+       nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
+                       PCI_FUNC(nesdev->pcidev->devfn));
+       nes_read32(nesdev->regs+NES_CQE_ALLOC);
+
+       /* Enable the interrupts */
+       nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
+                       (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
+       if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
+               nesdev->int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+24));
+       }
+
+       /* TODO: This really should be the first driver to load, not function 0 */
+       if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
+               /* pick up PCI and critical errors if the first driver to load */
+               nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
+               nesdev->int_req |= NES_INT_INTF;
+       } else {
+               nesdev->intf_int_req = 0;
+       }
+       nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
+       nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
+       nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
+       nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
+       nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
+
+       nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
+
+       /* deal with both periodic and one_shot */
+       nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
+       nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
+       nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
+                       PCI_FUNC(nesdev->pcidev->devfn),
+                       nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
+
+       nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
+
+       list_add_tail(&nesdev->list, &nes_dev_list);
+
+       /* Request an interrupt line for the driver */
+       ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
+       if (ret) {
+               printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
+                               pci_name(pcidev), pcidev->irq);
+               goto bail65;
+       }
+
+       nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
+
+       if (nes_notifiers_registered == 0) {
+               register_inetaddr_notifier(&nes_inetaddr_notifier);
+               register_netevent_notifier(&nes_net_notifier);
+       }
+       nes_notifiers_registered++;
+
+       /* Initialize network devices */
+               if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL) {
+                       goto bail7;
+               }
+
+               /* Register network device */
+               ret = register_netdev(netdev);
+               if (ret) {
+                       printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
+                       nes_netdev_destroy(netdev);
+                       goto bail7;
+               }
+
+               nes_print_macaddr(netdev);
+               /* create a CM core for this netdev */
+               nesvnic = netdev_priv(netdev);
+
+               nesdev->netdev_count++;
+               nesdev->nesadapter->netdev_count++;
+
+
+       printk(KERN_ERR PFX "%s: NetEffect RNIC driver successfully loaded.\n",
+                       pci_name(pcidev));
+       return 0;
+
+       bail7:
+       printk(KERN_ERR PFX "bail7\n");
+       while (nesdev->netdev_count > 0) {
+               nesdev->netdev_count--;
+               nesdev->nesadapter->netdev_count--;
+
+               unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
+               nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
+       }
+
+       nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
+                       nesdev->netdev_count, nesdev->nesadapter->netdev_count);
+
+       nes_notifiers_registered--;
+       if (nes_notifiers_registered == 0) {
+               unregister_netevent_notifier(&nes_net_notifier);
+               unregister_inetaddr_notifier(&nes_inetaddr_notifier);
+       }
+
+       list_del(&nesdev->list);
+       nes_destroy_cqp(nesdev);
+
+       bail65:
+       printk(KERN_ERR PFX "bail65\n");
+       free_irq(pcidev->irq, nesdev);
+       if (nesdev->msi_enabled) {
+               pci_disable_msi(pcidev);
+       }
+       bail6:
+       printk(KERN_ERR PFX "bail6\n");
+       tasklet_kill(&nesdev->dpc_tasklet);
+       /* Deallocate the Adapter Structure */
+       nes_destroy_adapter(nesdev->nesadapter);
+
+       bail5:
+       printk(KERN_ERR PFX "bail5\n");
+       iounmap(nesdev->regs);
+
+       bail3:
+       printk(KERN_ERR PFX "bail3\n");
+       kfree(nesdev);
+
+       bail2:
+       pci_release_regions(pcidev);
+
+       bail1:
+       pci_disable_device(pcidev);
+
+       bail0:
+       return ret;
+}
+
+
+/**
+ * nes_remove - unload from kernel
+ */
+static void __devexit nes_remove(struct pci_dev *pcidev)
+{
+       struct nes_device *nesdev = pci_get_drvdata(pcidev);
+       struct net_device *netdev;
+       int netdev_index = 0;
+
+               if (nesdev->netdev_count) {
+                       netdev = nesdev->netdev[netdev_index];
+                       if (netdev) {
+                               netif_stop_queue(netdev);
+                               unregister_netdev(netdev);
+                               nes_netdev_destroy(netdev);
+
+                               nesdev->netdev[netdev_index] = NULL;
+                               nesdev->netdev_count--;
+                               nesdev->nesadapter->netdev_count--;
+                       }
+               }
+
+       nes_notifiers_registered--;
+       if (nes_notifiers_registered == 0) {
+               unregister_netevent_notifier(&nes_net_notifier);
+               unregister_inetaddr_notifier(&nes_inetaddr_notifier);
+       }
+
+       list_del(&nesdev->list);
+       nes_destroy_cqp(nesdev);
+       tasklet_kill(&nesdev->dpc_tasklet);
+
+       /* Deallocate the Adapter Structure */
+       nes_destroy_adapter(nesdev->nesadapter);
+
+       free_irq(pcidev->irq, nesdev);
+
+       if (nesdev->msi_enabled) {
+               pci_disable_msi(pcidev);
+       }
+
+       iounmap(nesdev->regs);
+       kfree(nesdev);
+
+       /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
+       pci_release_regions(pcidev);
+       pci_disable_device(pcidev);
+       pci_set_drvdata(pcidev, NULL);
+}
+
+
+static struct pci_driver nes_pci_driver = {
+       .name = DRV_NAME,
+       .id_table = nes_pci_table,
+       .probe = nes_probe,
+       .remove = __devexit_p(nes_remove),
+};
+
+static ssize_t nes_show_adapter(struct device_driver *ddp, char *buf)
+{
+       unsigned int  devfn = 0xffffffff;
+       unsigned char bus_number = 0xff;
+       unsigned int  i = 0;
+       struct nes_device *nesdev;
+
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               if (i == ee_flsh_adapter) {
+                       devfn      = nesdev->nesadapter->devfn;
+                       bus_number = nesdev->nesadapter->bus_number;
+                       break;
+               }
+               i++;
+       }
+
+       return snprintf(buf, PAGE_SIZE, "%x:%x", bus_number, devfn);
+}
+
+static ssize_t nes_store_adapter(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+
+       ee_flsh_adapter = simple_strtoul(p, &p, 10);
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_ee_cmd(struct device_driver *ddp, char *buf)
+{
+       u32 eeprom_cmd = 0xdead;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               if (i == ee_flsh_adapter) {
+                       eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
+                       break;
+               }
+               i++;
+       }
+       return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
+}
+
+static ssize_t nes_store_ee_cmd(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+       u32 val;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
+               val = simple_strtoul(p, &p, 16);
+               list_for_each_entry(nesdev, &nes_dev_list, list) {
+                       if (i == ee_flsh_adapter) {
+                               nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
+                               break;
+                       }
+                       i++;
+               }
+       }
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_ee_data(struct device_driver *ddp, char *buf)
+{
+       u32 eeprom_data = 0xdead;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               if (i == ee_flsh_adapter) {
+                       eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
+                       break;
+               }
+               i++;
+       }
+
+       return  snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
+}
+
+static ssize_t nes_store_ee_data(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+       u32 val;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
+               val = simple_strtoul(p, &p, 16);
+               list_for_each_entry(nesdev, &nes_dev_list, list) {
+                       if (i == ee_flsh_adapter) {
+                               nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
+                               break;
+                       }
+                       i++;
+               }
+       }
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_flash_cmd(struct device_driver *ddp, char *buf)
+{
+       u32 flash_cmd = 0xdead;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               if (i == ee_flsh_adapter) {
+                       flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
+                       break;
+               }
+               i++;
+       }
+
+       return  snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
+}
+
+static ssize_t nes_store_flash_cmd(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+       u32 val;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
+               val = simple_strtoul(p, &p, 16);
+               list_for_each_entry(nesdev, &nes_dev_list, list) {
+                       if (i == ee_flsh_adapter) {
+                               nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
+                               break;
+                       }
+                       i++;
+               }
+       }
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_flash_data(struct device_driver *ddp, char *buf)
+{
+       u32 flash_data = 0xdead;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               if (i == ee_flsh_adapter) {
+                       flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
+                       break;
+               }
+               i++;
+       }
+
+       return  snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
+}
+
+static ssize_t nes_store_flash_data(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+       u32 val;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
+               val = simple_strtoul(p, &p, 16);
+               list_for_each_entry(nesdev, &nes_dev_list, list) {
+                       if (i == ee_flsh_adapter) {
+                               nes_write32(nesdev->regs + NES_FLASH_DATA, val);
+                               break;
+                       }
+                       i++;
+               }
+       }
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_nonidx_addr(struct device_driver *ddp, char *buf)
+{
+       return  snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
+}
+
+static ssize_t nes_store_nonidx_addr(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
+               sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
+
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_nonidx_data(struct device_driver *ddp, char *buf)
+{
+       u32 nonidx_data = 0xdead;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               if (i == ee_flsh_adapter) {
+                       nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
+                       break;
+               }
+               i++;
+       }
+
+       return  snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
+}
+
+static ssize_t nes_store_nonidx_data(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+       u32 val;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
+               val = simple_strtoul(p, &p, 16);
+               list_for_each_entry(nesdev, &nes_dev_list, list) {
+                       if (i == ee_flsh_adapter) {
+                               nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
+                               break;
+                       }
+                       i++;
+               }
+       }
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_idx_addr(struct device_driver *ddp, char *buf)
+{
+       return  snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
+}
+
+static ssize_t nes_store_idx_addr(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
+               sysfs_idx_addr = simple_strtoul(p, &p, 16);
+
+       return strnlen(buf, count);
+}
+
+static ssize_t nes_show_idx_data(struct device_driver *ddp, char *buf)
+{
+       u32 idx_data = 0xdead;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       list_for_each_entry(nesdev, &nes_dev_list, list) {
+               if (i == ee_flsh_adapter) {
+                       idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
+                       break;
+               }
+               i++;
+       }
+
+       return  snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
+}
+
+static ssize_t nes_store_idx_data(struct device_driver *ddp,
+       const char *buf, size_t count)
+{
+       char *p = (char *)buf;
+       u32 val;
+       u32 i = 0;
+       struct nes_device *nesdev;
+
+       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
+               val = simple_strtoul(p, &p, 16);
+               list_for_each_entry(nesdev, &nes_dev_list, list) {
+                       if (i == ee_flsh_adapter) {
+                               nes_write_indexed(nesdev, sysfs_idx_addr, val);
+                               break;
+                       }
+                       i++;
+               }
+       }
+       return strnlen(buf, count);
+}
+
+static DRIVER_ATTR(adapter, S_IRUSR | S_IWUSR,
+                  nes_show_adapter, nes_store_adapter);
+static DRIVER_ATTR(eeprom_cmd, S_IRUSR | S_IWUSR,
+                  nes_show_ee_cmd, nes_store_ee_cmd);
+static DRIVER_ATTR(eeprom_data, S_IRUSR | S_IWUSR,
+                  nes_show_ee_data, nes_store_ee_data);
+static DRIVER_ATTR(flash_cmd, S_IRUSR | S_IWUSR,
+                  nes_show_flash_cmd, nes_store_flash_cmd);
+static DRIVER_ATTR(flash_data, S_IRUSR | S_IWUSR,
+                  nes_show_flash_data, nes_store_flash_data);
+static DRIVER_ATTR(nonidx_addr, S_IRUSR | S_IWUSR,
+                  nes_show_nonidx_addr, nes_store_nonidx_addr);
+static DRIVER_ATTR(nonidx_data, S_IRUSR | S_IWUSR,
+                  nes_show_nonidx_data, nes_store_nonidx_data);
+static DRIVER_ATTR(idx_addr, S_IRUSR | S_IWUSR,
+                  nes_show_idx_addr, nes_store_idx_addr);
+static DRIVER_ATTR(idx_data, S_IRUSR | S_IWUSR,
+                  nes_show_idx_data, nes_store_idx_data);
+
+static int nes_create_driver_sysfs(struct pci_driver *drv)
+{
+       int error;
+       error  = driver_create_file(&drv->driver, &driver_attr_adapter);
+       error |= driver_create_file(&drv->driver, &driver_attr_eeprom_cmd);
+       error |= driver_create_file(&drv->driver, &driver_attr_eeprom_data);
+       error |= driver_create_file(&drv->driver, &driver_attr_flash_cmd);
+       error |= driver_create_file(&drv->driver, &driver_attr_flash_data);
+       error |= driver_create_file(&drv->driver, &driver_attr_nonidx_addr);
+       error |= driver_create_file(&drv->driver, &driver_attr_nonidx_data);
+       error |= driver_create_file(&drv->driver, &driver_attr_idx_addr);
+       error |= driver_create_file(&drv->driver, &driver_attr_idx_data);
+       return error;
+}
+
+static void nes_remove_driver_sysfs(struct pci_driver *drv)
+{
+       driver_remove_file(&drv->driver, &driver_attr_adapter);
+       driver_remove_file(&drv->driver, &driver_attr_eeprom_cmd);
+       driver_remove_file(&drv->driver, &driver_attr_eeprom_data);
+       driver_remove_file(&drv->driver, &driver_attr_flash_cmd);
+       driver_remove_file(&drv->driver, &driver_attr_flash_data);
+       driver_remove_file(&drv->driver, &driver_attr_nonidx_addr);
+       driver_remove_file(&drv->driver, &driver_attr_nonidx_data);
+       driver_remove_file(&drv->driver, &driver_attr_idx_addr);
+       driver_remove_file(&drv->driver, &driver_attr_idx_data);
+}
+
+/**
+ * nes_init_module - module initialization entry point
+ */
+static int __init nes_init_module(void)
+{
+       int retval;
+       int retval1;
+
+       retval = nes_cm_start();
+       if (retval) {
+               printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
+               return retval;
+       }
+       retval = pci_register_driver(&nes_pci_driver);
+       if (retval >= 0) {
+               retval1 = nes_create_driver_sysfs(&nes_pci_driver);
+               if (retval1 < 0)
+                       printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n");
+       }
+       return retval;
+}
+
+
+/**
+ * nes_exit_module - module unload entry point
+ */
+static void __exit nes_exit_module(void)
+{
+       nes_cm_stop();
+       nes_remove_driver_sysfs(&nes_pci_driver);
+
+       pci_unregister_driver(&nes_pci_driver);
+}
+
+
+module_init(nes_init_module);
+module_exit(nes_exit_module);
diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
new file mode 100644 (file)
index 0000000..fd57e8a
--- /dev/null
@@ -0,0 +1,560 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __NES_H
+#define __NES_H
+
+#include <linux/netdevice.h>
+#include <linux/inetdevice.h>
+#include <linux/spinlock.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include <linux/workqueue.h>
+#include <linux/slab.h>
+#include <asm/semaphore.h>
+#include <linux/version.h>
+#include <asm/io.h>
+#include <linux/crc32c.h>
+
+#include <rdma/ib_smi.h>
+#include <rdma/ib_verbs.h>
+#include <rdma/ib_pack.h>
+#include <rdma/rdma_cm.h>
+#include <rdma/iw_cm.h>
+
+#define NES_SEND_FIRST_WRITE
+
+#define QUEUE_DISCONNECTS
+
+#define DRV_BUILD   "1"
+
+#define DRV_NAME    "iw_nes"
+#define DRV_VERSION "1.0 KO Build " DRV_BUILD
+#define PFX         DRV_NAME ": "
+
+/*
+ * NetEffect PCI vendor id and NE010 PCI device id.
+ */
+#ifndef PCI_VENDOR_ID_NETEFFECT        /* not in pci.ids yet */
+#define PCI_VENDOR_ID_NETEFFECT       0x1678
+#define PCI_DEVICE_ID_NETEFFECT_NE020 0x0100
+#endif
+
+#define NE020_REV   4
+#define NE020_REV1  5
+
+#define BAR_0       0
+#define BAR_1       2
+
+#define RX_BUF_SIZE             (1536 + 8)
+#define NES_REG0_SIZE           (4 * 1024)
+#define NES_TX_TIMEOUT          (6*HZ)
+#define NES_FIRST_QPN           64
+#define NES_SW_CONTEXT_ALIGN    1024
+
+#define NES_NIC_MAX_NICS        16
+#define NES_MAX_ARP_TABLE_SIZE  4096
+
+#define NES_NIC_CEQ_SIZE        8
+/* NICs will be on a separate CQ */
+#define NES_CCEQ_SIZE ((nesadapter->max_cq / nesadapter->port_count) - 32)
+
+#define NES_MAX_PORT_COUNT 4
+
+#define MAX_DPC_ITERATIONS               128
+
+#define NES_CQP_REQUEST_NO_DOORBELL_RING 0
+#define NES_CQP_REQUEST_RING_DOORBELL    1
+
+#define NES_DRV_OPT_ENABLE_MPA_VER_0     0x00000001
+#define NES_DRV_OPT_DISABLE_MPA_CRC      0x00000002
+#define NES_DRV_OPT_DISABLE_FIRST_WRITE  0x00000004
+#define NES_DRV_OPT_DISABLE_INTF         0x00000008
+#define NES_DRV_OPT_ENABLE_MSI           0x00000010
+#define NES_DRV_OPT_DUAL_LOGICAL_PORT    0x00000020
+#define NES_DRV_OPT_SUPRESS_OPTION_BC    0x00000040
+#define NES_DRV_OPT_NO_INLINE_DATA       0x00000080
+#define NES_DRV_OPT_DISABLE_INT_MOD      0x00000100
+#define NES_DRV_OPT_DISABLE_VIRT_WQ      0x00000200
+
+#define NES_AEQ_EVENT_TIMEOUT         2500
+#define NES_DISCONNECT_EVENT_TIMEOUT  2000
+
+/* debug levels */
+/* must match userspace */
+#define NES_DBG_HW          0x00000001
+#define NES_DBG_INIT        0x00000002
+#define NES_DBG_ISR         0x00000004
+#define NES_DBG_PHY         0x00000008
+#define NES_DBG_NETDEV      0x00000010
+#define NES_DBG_CM          0x00000020
+#define NES_DBG_CM1         0x00000040
+#define NES_DBG_NIC_RX      0x00000080
+#define NES_DBG_NIC_TX      0x00000100
+#define NES_DBG_CQP         0x00000200
+#define NES_DBG_MMAP        0x00000400
+#define NES_DBG_MR          0x00000800
+#define NES_DBG_PD          0x00001000
+#define NES_DBG_CQ          0x00002000
+#define NES_DBG_QP          0x00004000
+#define NES_DBG_MOD_QP      0x00008000
+#define NES_DBG_AEQ         0x00010000
+#define NES_DBG_IW_RX       0x00020000
+#define NES_DBG_IW_TX       0x00040000
+#define NES_DBG_SHUTDOWN    0x00080000
+#define NES_DBG_RSVD1       0x10000000
+#define NES_DBG_RSVD2       0x20000000
+#define NES_DBG_RSVD3       0x40000000
+#define NES_DBG_RSVD4       0x80000000
+#define NES_DBG_ALL         0xffffffff
+
+#ifdef CONFIG_INFINIBAND_NES_DEBUG
+#define nes_debug(level, fmt, args...) \
+       if (level & nes_debug_level) \
+               printk(KERN_ERR PFX "%s[%u]: " fmt, __FUNCTION__, __LINE__, ##args)
+
+#define assert(expr)                                                \
+if (!(expr)) {                                                       \
+       printk(KERN_ERR PFX "Assertion failed! %s, %s, %s, line %d\n",  \
+                  #expr, __FILE__, __FUNCTION__, __LINE__);                \
+}
+
+#define NES_EVENT_TIMEOUT   1200000
+#else
+#define nes_debug(level, fmt, args...)
+#define assert(expr)          do {} while (0)
+
+#define NES_EVENT_TIMEOUT   100000
+#endif
+
+#include "nes_hw.h"
+#include "nes_verbs.h"
+#include "nes_context.h"
+#include "nes_user.h"
+#include "nes_cm.h"
+
+extern int max_mtu;
+extern int nics_per_function;
+#define max_frame_len (max_mtu+ETH_HLEN)
+extern int interrupt_mod_interval;
+extern int nes_if_count;
+extern int mpa_version;
+extern int disable_mpa_crc;
+extern unsigned int send_first;
+extern unsigned int nes_drv_opt;
+extern unsigned int nes_debug_level;
+
+extern struct list_head nes_adapter_list;
+extern struct list_head nes_dev_list;
+
+extern struct nes_cm_core *g_cm_core;
+
+extern atomic_t cm_connects;
+extern atomic_t cm_accepts;
+extern atomic_t cm_disconnects;
+extern atomic_t cm_closes;
+extern atomic_t cm_connecteds;
+extern atomic_t cm_connect_reqs;
+extern atomic_t cm_rejects;
+extern atomic_t mod_qp_timouts;
+extern atomic_t qps_created;
+extern atomic_t qps_destroyed;
+extern atomic_t sw_qps_destroyed;
+extern u32 mh_detected;
+extern u32 mh_pauses_sent;
+extern u32 cm_packets_sent;
+extern u32 cm_packets_bounced;
+extern u32 cm_packets_created;
+extern u32 cm_packets_received;
+extern u32 cm_packets_dropped;
+extern u32 cm_packets_retrans;
+extern u32 cm_listens_created;
+extern u32 cm_listens_destroyed;
+extern u32 cm_backlog_drops;
+extern atomic_t cm_loopbacks;
+extern atomic_t cm_nodes_created;
+extern atomic_t cm_nodes_destroyed;
+extern atomic_t cm_accel_dropped_pkts;
+extern atomic_t cm_resets_recvd;
+
+extern u32 crit_err_count;
+extern u32 int_mod_timer_init;
+extern u32 int_mod_cq_depth_256;
+extern u32 int_mod_cq_depth_128;
+extern u32 int_mod_cq_depth_32;
+extern u32 int_mod_cq_depth_24;
+extern u32 int_mod_cq_depth_16;
+extern u32 int_mod_cq_depth_4;
+extern u32 int_mod_cq_depth_1;
+
+extern atomic_t cqp_reqs_allocated;
+extern atomic_t cqp_reqs_freed;
+extern atomic_t cqp_reqs_dynallocated;
+extern atomic_t cqp_reqs_dynfreed;
+extern atomic_t cqp_reqs_queued;
+extern atomic_t cqp_reqs_redriven;
+
+
+struct nes_device {
+       struct nes_adapter         *nesadapter;
+       void __iomem           *regs;
+       void __iomem           *index_reg;
+       struct pci_dev         *pcidev;
+       struct net_device      *netdev[NES_NIC_MAX_NICS];
+       u64                    link_status_interrupts;
+       struct tasklet_struct  dpc_tasklet;
+       spinlock_t             indexed_regs_lock;
+       unsigned long          csr_start;
+       unsigned long          doorbell_region;
+       unsigned long          doorbell_start;
+       unsigned long          mac_tx_errors;
+       unsigned long          mac_pause_frames_sent;
+       unsigned long          mac_pause_frames_received;
+       unsigned long          mac_rx_errors;
+       unsigned long          mac_rx_crc_errors;
+       unsigned long          mac_rx_symbol_err_frames;
+       unsigned long          mac_rx_jabber_frames;
+       unsigned long          mac_rx_oversized_frames;
+       unsigned long          mac_rx_short_frames;
+       unsigned long          port_rx_discards;
+       unsigned long          port_tx_discards;
+       unsigned int           mac_index;
+       unsigned int           nes_stack_start;
+
+       /* Control Structures */
+       void                   *cqp_vbase;
+       dma_addr_t             cqp_pbase;
+       u32                    cqp_mem_size;
+       u8                     ceq_index;
+       u8                     nic_ceq_index;
+       struct nes_hw_cqp      cqp;
+       struct nes_hw_cq       ccq;
+       struct list_head       cqp_avail_reqs;
+       struct list_head       cqp_pending_reqs;
+       struct nes_cqp_request *nes_cqp_requests;
+
+       u32                    int_req;
+       u32                    int_stat;
+       u32                    timer_int_req;
+       u32                    timer_only_int_count;
+       u32                    intf_int_req;
+       u32                    last_mac_tx_pauses;
+       u32                    last_used_chunks_tx;
+       struct list_head       list;
+
+       u16                    base_doorbell_index;
+       u16                    currcq_count;
+       u16                    deepcq_count;
+       u8                     msi_enabled;
+       u8                     netdev_count;
+       u8                     napi_isr_ran;
+       u8                     disable_rx_flow_control;
+       u8                     disable_tx_flow_control;
+};
+
+
+static inline void
+set_wqe_64bit_value(__le32 *wqe_words, u32 index, u64 value)
+{
+       wqe_words[index]     = cpu_to_le32((u32) ((unsigned long)value));
+       wqe_words[index + 1] = cpu_to_le32((u32)(upper_32_bits((unsigned long)value)));
+}
+
+static inline void
+set_wqe_32bit_value(__le32 *wqe_words, u32 index, u32 value)
+{
+       wqe_words[index] = cpu_to_le32(value);
+}
+
+static inline void
+nes_fill_init_cqp_wqe(struct nes_hw_cqp_wqe *cqp_wqe, struct nes_device *nesdev)
+{
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_COMP_CTX_LOW_IDX,
+                       (u64)((unsigned long) &nesdev->cqp));
+       cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX]   = 0;
+       cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX]  = 0;
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_PBL_BLK_COUNT_IDX] = 0;
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_PBL_LEN_IDX]       = 0;
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_LEN_LOW_IDX]       = 0;
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_PA_LOW_IDX]        = 0;
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_PA_HIGH_IDX]       = 0;
+}
+
+static inline void
+nes_fill_init_qp_wqe(struct nes_hw_qp_wqe *wqe, struct nes_qp *nesqp, u32 head)
+{
+       u32 value;
+       value = ((u32)((unsigned long) nesqp)) | head;
+       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_CTX_HIGH_IDX,
+                       (u32)(upper_32_bits((unsigned long)(nesqp))));
+       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX, value);
+}
+
+/* Read from memory-mapped device */
+static inline u32 nes_read_indexed(struct nes_device *nesdev, u32 reg_index)
+{
+       unsigned long flags;
+       void __iomem *addr = nesdev->index_reg;
+       u32 value;
+
+       spin_lock_irqsave(&nesdev->indexed_regs_lock, flags);
+
+       writel(reg_index, addr);
+       value = readl((void __iomem *)addr + 4);
+
+       spin_unlock_irqrestore(&nesdev->indexed_regs_lock, flags);
+       return value;
+}
+
+static inline u32 nes_read32(const void __iomem *addr)
+{
+       return readl(addr);
+}
+
+static inline u16 nes_read16(const void __iomem *addr)
+{
+       return readw(addr);
+}
+
+static inline u8 nes_read8(const void __iomem *addr)
+{
+       return readb(addr);
+}
+
+/* Write to memory-mapped device */
+static inline void nes_write_indexed(struct nes_device *nesdev, u32 reg_index, u32 val)
+{
+       unsigned long flags;
+       void __iomem *addr = nesdev->index_reg;
+
+       spin_lock_irqsave(&nesdev->indexed_regs_lock, flags);
+
+       writel(reg_index, addr);
+       writel(val, (void __iomem *)addr + 4);
+
+       spin_unlock_irqrestore(&nesdev->indexed_regs_lock, flags);
+}
+
+static inline void nes_write32(void __iomem *addr, u32 val)
+{
+       writel(val, addr);
+}
+
+static inline void nes_write16(void __iomem *addr, u16 val)
+{
+       writew(val, addr);
+}
+
+static inline void nes_write8(void __iomem *addr, u8 val)
+{
+       writeb(val, addr);
+}
+
+
+
+static inline int nes_alloc_resource(struct nes_adapter *nesadapter,
+               unsigned long *resource_array, u32 max_resources,
+               u32 *req_resource_num, u32 *next)
+{
+       unsigned long flags;
+       u32 resource_num;
+
+       spin_lock_irqsave(&nesadapter->resource_lock, flags);
+
+       resource_num = find_next_zero_bit(resource_array, max_resources, *next);
+       if (resource_num >= max_resources) {
+               resource_num = find_first_zero_bit(resource_array, max_resources);
+               if (resource_num >= max_resources) {
+                       printk(KERN_ERR PFX "%s: No available resourcess.\n", __FUNCTION__);
+                       spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
+                       return -EMFILE;
+               }
+       }
+       set_bit(resource_num, resource_array);
+       *next = resource_num+1;
+       if (*next == max_resources) {
+               *next = 0;
+       }
+       spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
+       *req_resource_num = resource_num;
+
+       return 0;
+}
+
+static inline int nes_is_resource_allocated(struct nes_adapter *nesadapter,
+               unsigned long *resource_array, u32 resource_num)
+{
+       unsigned long flags;
+       int bit_is_set;
+
+       spin_lock_irqsave(&nesadapter->resource_lock, flags);
+
+       bit_is_set = test_bit(resource_num, resource_array);
+       nes_debug(NES_DBG_HW, "resource_num %u is%s allocated.\n",
+                       resource_num, (bit_is_set ? "": " not"));
+       spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
+
+       return bit_is_set;
+}
+
+static inline void nes_free_resource(struct nes_adapter *nesadapter,
+               unsigned long *resource_array, u32 resource_num)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&nesadapter->resource_lock, flags);
+       clear_bit(resource_num, resource_array);
+       spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
+}
+
+static inline struct nes_vnic *to_nesvnic(struct ib_device *ibdev)
+{
+       return container_of(ibdev, struct nes_ib_device, ibdev)->nesvnic;
+}
+
+static inline struct nes_pd *to_nespd(struct ib_pd *ibpd)
+{
+       return container_of(ibpd, struct nes_pd, ibpd);
+}
+
+static inline struct nes_ucontext *to_nesucontext(struct ib_ucontext *ibucontext)
+{
+       return container_of(ibucontext, struct nes_ucontext, ibucontext);
+}
+
+static inline struct nes_mr *to_nesmr(struct ib_mr *ibmr)
+{
+       return container_of(ibmr, struct nes_mr, ibmr);
+}
+
+static inline struct nes_mr *to_nesmr_from_ibfmr(struct ib_fmr *ibfmr)
+{
+       return container_of(ibfmr, struct nes_mr, ibfmr);
+}
+
+static inline struct nes_mr *to_nesmw(struct ib_mw *ibmw)
+{
+       return container_of(ibmw, struct nes_mr, ibmw);
+}
+
+static inline struct nes_fmr *to_nesfmr(struct nes_mr *nesmr)
+{
+       return container_of(nesmr, struct nes_fmr, nesmr);
+}
+
+static inline struct nes_cq *to_nescq(struct ib_cq *ibcq)
+{
+       return container_of(ibcq, struct nes_cq, ibcq);
+}
+
+static inline struct nes_qp *to_nesqp(struct ib_qp *ibqp)
+{
+       return container_of(ibqp, struct nes_qp, ibqp);
+}
+
+
+
+/* nes.c */
+void nes_add_ref(struct ib_qp *);
+void nes_rem_ref(struct ib_qp *);
+struct ib_qp *nes_get_qp(struct ib_device *, int);
+
+
+/* nes_hw.c */
+struct nes_adapter *nes_init_adapter(struct nes_device *, u8);
+void  nes_nic_init_timer_defaults(struct nes_device *, u8);
+unsigned int nes_reset_adapter_ne020(struct nes_device *, u8 *);
+int nes_init_serdes(struct nes_device *, u8, u8, u8);
+void nes_init_csr_ne020(struct nes_device *, u8, u8);
+void nes_destroy_adapter(struct nes_adapter *);
+int nes_init_cqp(struct nes_device *);
+int nes_init_phy(struct nes_device *);
+int nes_init_nic_qp(struct nes_device *, struct net_device *);
+void nes_destroy_nic_qp(struct nes_vnic *);
+int nes_napi_isr(struct nes_device *);
+void nes_dpc(unsigned long);
+void nes_process_ceq(struct nes_device *, struct nes_hw_ceq *);
+void nes_process_aeq(struct nes_device *, struct nes_hw_aeq *);
+void nes_process_mac_intr(struct nes_device *, u32);
+void nes_nic_napi_ce_handler(struct nes_device *, struct nes_hw_nic_cq *);
+void nes_nic_ce_handler(struct nes_device *, struct nes_hw_nic_cq *);
+void nes_cqp_ce_handler(struct nes_device *, struct nes_hw_cq *);
+void nes_process_iwarp_aeqe(struct nes_device *, struct nes_hw_aeqe *);
+void nes_iwarp_ce_handler(struct nes_device *, struct nes_hw_cq *);
+int nes_destroy_cqp(struct nes_device *);
+int nes_nic_cm_xmit(struct sk_buff *, struct net_device *);
+
+/* nes_nic.c */
+void nes_netdev_set_multicast_list(struct net_device *);
+void nes_netdev_exit(struct nes_vnic *);
+struct net_device *nes_netdev_init(struct nes_device *, void __iomem *);
+void nes_netdev_destroy(struct net_device *);
+int nes_nic_cm_xmit(struct sk_buff *, struct net_device *);
+
+/* nes_cm.c */
+void *nes_cm_create(struct net_device *);
+int nes_cm_recv(struct sk_buff *, struct net_device *);
+void nes_update_arp(unsigned char *, u32, u32, u16, u16);
+void nes_manage_arp_cache(struct net_device *, unsigned char *, u32, u32);
+void nes_sock_release(struct nes_qp *, unsigned long *);
+struct nes_cm_core *nes_cm_alloc_core(void);
+void flush_wqes(struct nes_device *nesdev, struct nes_qp *, u32, u32);
+int nes_manage_apbvt(struct nes_vnic *, u32, u32, u32);
+int nes_cm_disconn(struct nes_qp *);
+void nes_cm_disconn_worker(void *);
+
+/* nes_verbs.c */
+int nes_hw_modify_qp(struct nes_device *, struct nes_qp *, u32, u32);
+int nes_modify_qp(struct ib_qp *, struct ib_qp_attr *, int, struct ib_udata *);
+struct nes_ib_device *nes_init_ofa_device(struct net_device *);
+void nes_destroy_ofa_device(struct nes_ib_device *);
+int nes_register_ofa_device(struct nes_ib_device *);
+void nes_unregister_ofa_device(struct nes_ib_device *);
+
+/* nes_util.c */
+int nes_read_eeprom_values(struct nes_device *, struct nes_adapter *);
+void nes_write_1G_phy_reg(struct nes_device *, u8, u8, u16);
+void nes_read_1G_phy_reg(struct nes_device *, u8, u8, u16 *);
+void nes_write_10G_phy_reg(struct nes_device *, u16, u8, u16);
+void nes_read_10G_phy_reg(struct nes_device *, u16, u8);
+struct nes_cqp_request *nes_get_cqp_request(struct nes_device *);
+void nes_post_cqp_request(struct nes_device *, struct nes_cqp_request *, int);
+int nes_arp_table(struct nes_device *, u32, u8 *, u32);
+void nes_mh_fix(unsigned long);
+void nes_clc(unsigned long);
+void nes_dump_mem(unsigned int, void *, int);
+u32 nes_crc32(u32, u32, u32, u32, u8 *, u32, u32, u32);
+
+#endif /* __NES_H */
diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
new file mode 100644 (file)
index 0000000..bd5cfea
--- /dev/null
@@ -0,0 +1,3088 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+
+#define TCPOPT_TIMESTAMP 8
+
+#include <asm/atomic.h>
+#include <linux/skbuff.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/init.h>
+#include <linux/if_arp.h>
+#include <linux/notifier.h>
+#include <linux/net.h>
+#include <linux/types.h>
+#include <linux/timer.h>
+#include <linux/time.h>
+#include <linux/delay.h>
+#include <linux/etherdevice.h>
+#include <linux/netdevice.h>
+#include <linux/random.h>
+#include <linux/list.h>
+#include <linux/threads.h>
+
+#include <net/neighbour.h>
+#include <net/route.h>
+#include <net/ip_fib.h>
+
+#include "nes.h"
+
+u32 cm_packets_sent;
+u32 cm_packets_bounced;
+u32 cm_packets_dropped;
+u32 cm_packets_retrans;
+u32 cm_packets_created;
+u32 cm_packets_received;
+u32 cm_listens_created;
+u32 cm_listens_destroyed;
+u32 cm_backlog_drops;
+atomic_t cm_loopbacks;
+atomic_t cm_nodes_created;
+atomic_t cm_nodes_destroyed;
+atomic_t cm_accel_dropped_pkts;
+atomic_t cm_resets_recvd;
+
+static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
+static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *,
+               struct nes_vnic *, struct nes_cm_info *);
+static int add_ref_cm_node(struct nes_cm_node *);
+static int rem_ref_cm_node(struct nes_cm_core *, struct nes_cm_node *);
+static int mini_cm_del_listen(struct nes_cm_core *, struct nes_cm_listener *);
+
+
+/* External CM API Interface */
+/* instance of function pointers for client API */
+/* set address of this instance to cm_core->cm_ops at cm_core alloc */
+static struct nes_cm_ops nes_cm_api = {
+       mini_cm_accelerated,
+       mini_cm_listen,
+       mini_cm_del_listen,
+       mini_cm_connect,
+       mini_cm_close,
+       mini_cm_accept,
+       mini_cm_reject,
+       mini_cm_recv_pkt,
+       mini_cm_dealloc_core,
+       mini_cm_get,
+       mini_cm_set
+};
+
+struct nes_cm_core *g_cm_core;
+
+atomic_t cm_connects;
+atomic_t cm_accepts;
+atomic_t cm_disconnects;
+atomic_t cm_closes;
+atomic_t cm_connecteds;
+atomic_t cm_connect_reqs;
+atomic_t cm_rejects;
+
+
+/**
+ * create_event
+ */
+static struct nes_cm_event *create_event(struct nes_cm_node *cm_node,
+               enum nes_cm_event_type type)
+{
+       struct nes_cm_event *event;
+
+       if (!cm_node->cm_id)
+               return NULL;
+
+       /* allocate an empty event */
+       event = kzalloc(sizeof(*event), GFP_ATOMIC);
+
+       if (!event)
+               return NULL;
+
+       event->type = type;
+       event->cm_node = cm_node;
+       event->cm_info.rem_addr = cm_node->rem_addr;
+       event->cm_info.loc_addr = cm_node->loc_addr;
+       event->cm_info.rem_port = cm_node->rem_port;
+       event->cm_info.loc_port = cm_node->loc_port;
+       event->cm_info.cm_id = cm_node->cm_id;
+
+       nes_debug(NES_DBG_CM, "Created event=%p, type=%u, dst_addr=%08x[%x],"
+                       " src_addr=%08x[%x]\n",
+                       event, type,
+                       event->cm_info.loc_addr, event->cm_info.loc_port,
+                       event->cm_info.rem_addr, event->cm_info.rem_port);
+
+       nes_cm_post_event(event);
+       return event;
+}
+
+
+/**
+ * send_mpa_request
+ */
+int send_mpa_request(struct nes_cm_node *cm_node)
+{
+       struct sk_buff *skb;
+       int ret;
+
+       skb = get_free_pkt(cm_node);
+       if (!skb) {
+               nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
+               return -1;
+       }
+
+       /* send an MPA Request frame */
+       form_cm_frame(skb, cm_node, NULL, 0, &cm_node->mpa_frame,
+                       cm_node->mpa_frame_size, SET_ACK);
+
+       ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
+       if (ret < 0) {
+               return ret;
+       }
+
+       return 0;
+}
+
+
+/**
+ * recv_mpa - process a received TCP pkt, we are expecting an
+ * IETF MPA frame
+ */
+static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 len)
+{
+       struct ietf_mpa_frame *mpa_frame;
+
+       /* assume req frame is in tcp data payload */
+       if (len < sizeof(struct ietf_mpa_frame)) {
+               nes_debug(NES_DBG_CM, "The received ietf buffer was too small (%x)\n", len);
+               return -1;
+       }
+
+       mpa_frame = (struct ietf_mpa_frame *)buffer;
+       cm_node->mpa_frame_size = ntohs(mpa_frame->priv_data_len);
+
+       if (cm_node->mpa_frame_size + sizeof(struct ietf_mpa_frame) != len) {
+               nes_debug(NES_DBG_CM, "The received ietf buffer was not right"
+                               " complete (%x + %x != %x)\n",
+                               cm_node->mpa_frame_size, (u32)sizeof(struct ietf_mpa_frame), len);
+               return -1;
+       }
+
+       /* copy entire MPA frame to our cm_node's frame */
+       memcpy(cm_node->mpa_frame_buf, buffer + sizeof(struct ietf_mpa_frame),
+                       cm_node->mpa_frame_size);
+
+       return 0;
+}
+
+
+/**
+ * handle_exception_pkt - process an exception packet.
+ * We have been in a TSA state, and we have now received SW
+ * TCP/IP traffic should be a FIN request or IP pkt with options
+ */
+static int handle_exception_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb)
+{
+       int ret = 0;
+       struct tcphdr *tcph = tcp_hdr(skb);
+
+       /* first check to see if this a FIN pkt */
+       if (tcph->fin) {
+               /* we need to ACK the FIN request */
+               send_ack(cm_node);
+
+               /* check which side we are (client/server) and set next state accordingly */
+               if (cm_node->tcp_cntxt.client)
+                       cm_node->state = NES_CM_STATE_CLOSING;
+               else {
+                       /* we are the server side */
+                       cm_node->state = NES_CM_STATE_CLOSE_WAIT;
+                       /* since this is a self contained CM we don't wait for */
+                       /* an APP to close us, just send final FIN immediately */
+                       ret = send_fin(cm_node, NULL);
+                       cm_node->state = NES_CM_STATE_LAST_ACK;
+               }
+       } else {
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+
+/**
+ * form_cm_frame - get a free packet and build empty frame Use
+ * node info to build.
+ */
+struct sk_buff *form_cm_frame(struct sk_buff *skb, struct nes_cm_node *cm_node,
+               void *options, u32 optionsize, void *data, u32 datasize, u8 flags)
+{
+       struct tcphdr *tcph;
+       struct iphdr *iph;
+       struct ethhdr *ethh;
+       u8 *buf;
+       u16 packetsize = sizeof(*iph);
+
+       packetsize += sizeof(*tcph);
+       packetsize +=  optionsize + datasize;
+
+       memset(skb->data, 0x00, ETH_HLEN + sizeof(*iph) + sizeof(*tcph));
+
+       skb->len = 0;
+       buf = skb_put(skb, packetsize + ETH_HLEN);
+
+       ethh = (struct ethhdr *) buf;
+       buf += ETH_HLEN;
+
+       iph = (struct iphdr *)buf;
+       buf += sizeof(*iph);
+       tcph = (struct tcphdr *)buf;
+       skb_reset_mac_header(skb);
+       skb_set_network_header(skb, ETH_HLEN);
+       skb_set_transport_header(skb, ETH_HLEN+sizeof(*iph));
+       buf += sizeof(*tcph);
+
+       skb->ip_summed = CHECKSUM_PARTIAL;
+       skb->protocol = htons(0x800);
+       skb->data_len = 0;
+       skb->mac_len = ETH_HLEN;
+
+       memcpy(ethh->h_dest, cm_node->rem_mac, ETH_ALEN);
+       memcpy(ethh->h_source, cm_node->loc_mac, ETH_ALEN);
+       ethh->h_proto = htons(0x0800);
+
+       iph->version = IPVERSION;
+       iph->ihl = 5;           /* 5 * 4Byte words, IP headr len */
+       iph->tos = 0;
+       iph->tot_len = htons(packetsize);
+       iph->id = htons(++cm_node->tcp_cntxt.loc_id);
+
+       iph->frag_off = htons(0x4000);
+       iph->ttl = 0x40;
+       iph->protocol = 0x06;   /* IPPROTO_TCP */
+
+       iph->saddr = htonl(cm_node->loc_addr);
+       iph->daddr = htonl(cm_node->rem_addr);
+
+       tcph->source = htons(cm_node->loc_port);
+       tcph->dest = htons(cm_node->rem_port);
+       tcph->seq = htonl(cm_node->tcp_cntxt.loc_seq_num);
+
+       if (flags & SET_ACK) {
+               cm_node->tcp_cntxt.loc_ack_num = cm_node->tcp_cntxt.rcv_nxt;
+               tcph->ack_seq = htonl(cm_node->tcp_cntxt.loc_ack_num);
+               tcph->ack = 1;
+       } else
+               tcph->ack_seq = 0;
+
+       if (flags & SET_SYN) {
+               cm_node->tcp_cntxt.loc_seq_num++;
+               tcph->syn = 1;
+       } else
+               cm_node->tcp_cntxt.loc_seq_num += datasize;     /* data (no headers) */
+
+       if (flags & SET_FIN)
+               tcph->fin = 1;
+
+       if (flags & SET_RST)
+               tcph->rst = 1;
+
+       tcph->doff = (u16)((sizeof(*tcph) + optionsize + 3) >> 2);
+       tcph->window = htons(cm_node->tcp_cntxt.rcv_wnd);
+       tcph->urg_ptr = 0;
+       if (optionsize)
+               memcpy(buf, options, optionsize);
+       buf += optionsize;
+       if (datasize)
+               memcpy(buf, data, datasize);
+
+       skb_shinfo(skb)->nr_frags = 0;
+       cm_packets_created++;
+
+       return skb;
+}
+
+
+/**
+ * print_core - dump a cm core
+ */
+static void print_core(struct nes_cm_core *core)
+{
+       nes_debug(NES_DBG_CM, "---------------------------------------------\n");
+       nes_debug(NES_DBG_CM, "CM Core  -- (core = %p )\n", core);
+       if (!core)
+               return;
+       nes_debug(NES_DBG_CM, "---------------------------------------------\n");
+       nes_debug(NES_DBG_CM, "Session ID    : %u \n", atomic_read(&core->session_id));
+
+       nes_debug(NES_DBG_CM, "State         : %u \n",  core->state);
+
+       nes_debug(NES_DBG_CM, "Tx Free cnt   : %u \n", skb_queue_len(&core->tx_free_list));
+       nes_debug(NES_DBG_CM, "Listen Nodes  : %u \n", atomic_read(&core->listen_node_cnt));
+       nes_debug(NES_DBG_CM, "Active Nodes  : %u \n", atomic_read(&core->node_cnt));
+
+       nes_debug(NES_DBG_CM, "core          : %p \n", core);
+
+       nes_debug(NES_DBG_CM, "-------------- end core ---------------\n");
+}
+
+
+/**
+ * schedule_nes_timer
+ * note - cm_node needs to be protected before calling this. Encase in:
+ *                     rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
+ */
+int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
+               enum nes_timer_type type, int send_retrans,
+               int close_when_complete)
+{
+       unsigned long  flags;
+       struct nes_cm_core *cm_core;
+       struct nes_timer_entry *new_send;
+       int ret = 0;
+       u32 was_timer_set;
+
+       new_send = kzalloc(sizeof(*new_send), GFP_ATOMIC);
+       if (!new_send)
+               return -1;
+       if (!cm_node)
+               return -EINVAL;
+
+       /* new_send->timetosend = currenttime */
+       new_send->retrycount = NES_DEFAULT_RETRYS;
+       new_send->retranscount = NES_DEFAULT_RETRANS;
+       new_send->skb = skb;
+       new_send->timetosend = jiffies;
+       new_send->type = type;
+       new_send->netdev = cm_node->netdev;
+       new_send->send_retrans = send_retrans;
+       new_send->close_when_complete = close_when_complete;
+
+       if (type == NES_TIMER_TYPE_CLOSE) {
+               new_send->timetosend += (HZ/2); /* TODO: decide on the correct value here */
+               spin_lock_irqsave(&cm_node->recv_list_lock, flags);
+               list_add_tail(&new_send->list, &cm_node->recv_list);
+               spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
+       }
+
+       if (type == NES_TIMER_TYPE_SEND) {
+               new_send->seq_num = htonl(tcp_hdr(skb)->seq);
+               atomic_inc(&new_send->skb->users);
+
+               ret = nes_nic_cm_xmit(new_send->skb, cm_node->netdev);
+               if (ret != NETDEV_TX_OK) {
+                       nes_debug(NES_DBG_CM, "Error sending packet %p (jiffies = %lu)\n",
+                                       new_send, jiffies);
+                       atomic_dec(&new_send->skb->users);
+                       new_send->timetosend = jiffies;
+               } else {
+                       cm_packets_sent++;
+                       if (!send_retrans) {
+                               if (close_when_complete)
+                                       rem_ref_cm_node(cm_node->cm_core, cm_node);
+                               dev_kfree_skb_any(new_send->skb);
+                               kfree(new_send);
+                               return ret;
+                       }
+                       new_send->timetosend = jiffies + NES_RETRY_TIMEOUT;
+               }
+               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+               list_add_tail(&new_send->list, &cm_node->retrans_list);
+               spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+       }
+       if (type == NES_TIMER_TYPE_RECV) {
+               new_send->seq_num = htonl(tcp_hdr(skb)->seq);
+               new_send->timetosend = jiffies;
+               spin_lock_irqsave(&cm_node->recv_list_lock, flags);
+               list_add_tail(&new_send->list, &cm_node->recv_list);
+               spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
+       }
+       cm_core = cm_node->cm_core;
+
+       was_timer_set = timer_pending(&cm_core->tcp_timer);
+
+       if (!was_timer_set) {
+               cm_core->tcp_timer.expires = new_send->timetosend;
+               add_timer(&cm_core->tcp_timer);
+       }
+
+       return ret;
+}
+
+
+/**
+ * nes_cm_timer_tick
+ */
+void nes_cm_timer_tick(unsigned long pass)
+{
+       unsigned long flags, qplockflags;
+       unsigned long nexttimeout = jiffies + NES_LONG_TIME;
+       struct iw_cm_id *cm_id;
+       struct nes_cm_node *cm_node;
+       struct nes_timer_entry *send_entry, *recv_entry;
+       struct list_head *list_core, *list_core_temp;
+       struct list_head *list_node, *list_node_temp;
+       struct nes_cm_core *cm_core = g_cm_core;
+       struct nes_qp *nesqp;
+       struct sk_buff *skb;
+       u32 settimer = 0;
+       int ret = NETDEV_TX_OK;
+       int    node_done;
+
+       spin_lock_irqsave(&cm_core->ht_lock, flags);
+
+       list_for_each_safe(list_node, list_core_temp, &cm_core->connected_nodes) {
+               cm_node = container_of(list_node, struct nes_cm_node, list);
+               add_ref_cm_node(cm_node);
+               spin_unlock_irqrestore(&cm_core->ht_lock, flags);
+               spin_lock_irqsave(&cm_node->recv_list_lock, flags);
+               list_for_each_safe(list_core, list_node_temp, &cm_node->recv_list) {
+                       recv_entry = container_of(list_core, struct nes_timer_entry, list);
+                       if ((time_after(recv_entry->timetosend, jiffies)) &&
+                                       (recv_entry->type == NES_TIMER_TYPE_CLOSE)) {
+                               if (nexttimeout > recv_entry->timetosend || !settimer) {
+                                       nexttimeout = recv_entry->timetosend;
+                                       settimer = 1;
+                               }
+                               continue;
+                       }
+                       list_del(&recv_entry->list);
+                       cm_id = cm_node->cm_id;
+                       spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
+                       if (recv_entry->type == NES_TIMER_TYPE_CLOSE) {
+                               nesqp = (struct nes_qp *)recv_entry->skb;
+                               spin_lock_irqsave(&nesqp->lock, qplockflags);
+                               if (nesqp->cm_id) {
+                                       nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, refcount = %d: "
+                                                       "****** HIT A NES_TIMER_TYPE_CLOSE"
+                                                       " with something to do!!! ******\n",
+                                                       nesqp->hwqp.qp_id, cm_id,
+                                                       atomic_read(&nesqp->refcount));
+                                       nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
+                                       nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
+                                       nesqp->ibqp_state = IB_QPS_ERR;
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_cm_disconn(nesqp);
+                               } else {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, refcount = %d:"
+                                                       " ****** HIT A NES_TIMER_TYPE_CLOSE"
+                                                       " with nothing to do!!! ******\n",
+                                                       nesqp->hwqp.qp_id, cm_id,
+                                                       atomic_read(&nesqp->refcount));
+                                       nes_rem_ref(&nesqp->ibqp);
+                               }
+                               if (cm_id)
+                                       cm_id->rem_ref(cm_id);
+                       }
+                       kfree(recv_entry);
+                       spin_lock_irqsave(&cm_node->recv_list_lock, flags);
+               }
+               spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
+
+               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+               node_done = 0;
+               list_for_each_safe(list_core, list_node_temp, &cm_node->retrans_list) {
+                       if (node_done) {
+                               break;
+                       }
+                       send_entry = container_of(list_core, struct nes_timer_entry, list);
+                       if (time_after(send_entry->timetosend, jiffies)) {
+                               if (cm_node->state != NES_CM_STATE_TSA) {
+                                       if ((nexttimeout > send_entry->timetosend) || !settimer) {
+                                               nexttimeout = send_entry->timetosend;
+                                               settimer = 1;
+                                       }
+                                       node_done = 1;
+                                       continue;
+                               } else {
+                                       list_del(&send_entry->list);
+                                       skb = send_entry->skb;
+                                       spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+                                       dev_kfree_skb_any(skb);
+                                       kfree(send_entry);
+                                       spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+                                       continue;
+                               }
+                       }
+                       if (send_entry->type == NES_TIMER_NODE_CLEANUP) {
+                               list_del(&send_entry->list);
+                               spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+                               kfree(send_entry);
+                               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+                               continue;
+                       }
+                       if ((send_entry->seq_num < cm_node->tcp_cntxt.rem_ack_num) ||
+                                       (cm_node->state == NES_CM_STATE_TSA) ||
+                                       (cm_node->state == NES_CM_STATE_CLOSED)) {
+                               skb = send_entry->skb;
+                               list_del(&send_entry->list);
+                               spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+                               kfree(send_entry);
+                               dev_kfree_skb_any(skb);
+                               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+                               continue;
+                       }
+
+                       if (!send_entry->retranscount || !send_entry->retrycount) {
+                               cm_packets_dropped++;
+                               skb = send_entry->skb;
+                               list_del(&send_entry->list);
+                               spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+                               dev_kfree_skb_any(skb);
+                               kfree(send_entry);
+                               if (cm_node->state == NES_CM_STATE_SYN_RCVD) {
+                                       /* this node never even generated an indication up to the cm */
+                                       rem_ref_cm_node(cm_core, cm_node);
+                               } else {
+                                       cm_node->state = NES_CM_STATE_CLOSED;
+                                       create_event(cm_node, NES_CM_EVENT_ABORTED);
+                               }
+                               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+                               continue;
+                       }
+                       /* this seems like the correct place, but leave send entry unprotected */
+                       // spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+                       atomic_inc(&send_entry->skb->users);
+                       cm_packets_retrans++;
+                       nes_debug(NES_DBG_CM, "Retransmitting send_entry %p for node %p,"
+                                       " jiffies = %lu, time to send =  %lu, retranscount = %u, "
+                                       "send_entry->seq_num = 0x%08X, cm_node->tcp_cntxt.rem_ack_num = 0x%08X\n",
+                                       send_entry, cm_node, jiffies, send_entry->timetosend, send_entry->retranscount,
+                                       send_entry->seq_num, cm_node->tcp_cntxt.rem_ack_num);
+
+                       spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+                       ret = nes_nic_cm_xmit(send_entry->skb, cm_node->netdev);
+                       if (ret != NETDEV_TX_OK) {
+                               cm_packets_bounced++;
+                               atomic_dec(&send_entry->skb->users);
+                               send_entry->retrycount--;
+                               nexttimeout = jiffies + NES_SHORT_TIME;
+                               settimer = 1;
+                               node_done = 1;
+                               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+                               continue;
+                       } else {
+                               cm_packets_sent++;
+                       }
+                       spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+                       list_del(&send_entry->list);
+                       nes_debug(NES_DBG_CM, "Packet Sent: retrans count = %u, retry count = %u.\n",
+                                       send_entry->retranscount, send_entry->retrycount);
+                       if (send_entry->send_retrans) {
+                               send_entry->retranscount--;
+                               send_entry->timetosend = jiffies + NES_RETRY_TIMEOUT;
+                               if (nexttimeout > send_entry->timetosend || !settimer) {
+                                       nexttimeout = send_entry->timetosend;
+                                       settimer = 1;
+                               }
+                               list_add(&send_entry->list, &cm_node->retrans_list);
+                               continue;
+                       } else {
+                               int close_when_complete;
+                               skb = send_entry->skb;
+                               close_when_complete = send_entry->close_when_complete;
+                               spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+                               if (close_when_complete) {
+                                       BUG_ON(atomic_read(&cm_node->ref_count) == 1);
+                                       rem_ref_cm_node(cm_core, cm_node);
+                               }
+                               dev_kfree_skb_any(skb);
+                               kfree(send_entry);
+                               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+                               continue;
+                       }
+               }
+               spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+
+               rem_ref_cm_node(cm_core, cm_node);
+
+               spin_lock_irqsave(&cm_core->ht_lock, flags);
+               if (ret != NETDEV_TX_OK)
+                       break;
+       }
+       spin_unlock_irqrestore(&cm_core->ht_lock, flags);
+
+       if (settimer) {
+               if (!timer_pending(&cm_core->tcp_timer)) {
+                       cm_core->tcp_timer.expires  = nexttimeout;
+                       add_timer(&cm_core->tcp_timer);
+               }
+       }
+}
+
+
+/**
+ * send_syn
+ */
+int send_syn(struct nes_cm_node *cm_node, u32 sendack)
+{
+       int ret;
+       int flags = SET_SYN;
+       struct sk_buff *skb;
+       char optionsbuffer[sizeof(struct option_mss) +
+                       sizeof(struct option_windowscale) +
+                       sizeof(struct option_base) + 1];
+
+       int optionssize = 0;
+       /* Sending MSS option */
+       union all_known_options *options;
+
+       if (!cm_node)
+               return -EINVAL;
+
+       options = (union all_known_options *)&optionsbuffer[optionssize];
+       options->as_mss.optionnum = OPTION_NUMBER_MSS;
+       options->as_mss.length = sizeof(struct option_mss);
+       options->as_mss.mss = htons(cm_node->tcp_cntxt.mss);
+       optionssize += sizeof(struct option_mss);
+
+       options = (union all_known_options *)&optionsbuffer[optionssize];
+       options->as_windowscale.optionnum = OPTION_NUMBER_WINDOW_SCALE;
+       options->as_windowscale.length = sizeof(struct option_windowscale);
+       options->as_windowscale.shiftcount = cm_node->tcp_cntxt.rcv_wscale;
+       optionssize += sizeof(struct option_windowscale);
+
+       if (sendack && !(NES_DRV_OPT_SUPRESS_OPTION_BC & nes_drv_opt)
+                       ) {
+               options = (union all_known_options *)&optionsbuffer[optionssize];
+               options->as_base.optionnum = OPTION_NUMBER_WRITE0;
+               options->as_base.length = sizeof(struct option_base);
+               optionssize += sizeof(struct option_base);
+               /* we need the size to be a multiple of 4 */
+               options = (union all_known_options *)&optionsbuffer[optionssize];
+               options->as_end = 1;
+               optionssize += 1;
+               options = (union all_known_options *)&optionsbuffer[optionssize];
+               options->as_end = 1;
+               optionssize += 1;
+       }
+
+       options = (union all_known_options *)&optionsbuffer[optionssize];
+       options->as_end = OPTION_NUMBER_END;
+       optionssize += 1;
+
+       skb = get_free_pkt(cm_node);
+       if (!skb) {
+               nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
+               return -1;
+       }
+
+       if (sendack)
+               flags |= SET_ACK;
+
+       form_cm_frame(skb, cm_node, optionsbuffer, optionssize, NULL, 0, flags);
+       ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
+
+       return ret;
+}
+
+
+/**
+ * send_reset
+ */
+int send_reset(struct nes_cm_node *cm_node)
+{
+       int ret;
+       struct sk_buff *skb = get_free_pkt(cm_node);
+       int flags = SET_RST | SET_ACK;
+
+       if (!skb) {
+               nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
+               return -1;
+       }
+
+       add_ref_cm_node(cm_node);
+       form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, flags);
+       ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 1);
+
+       return ret;
+}
+
+
+/**
+ * send_ack
+ */
+int send_ack(struct nes_cm_node *cm_node)
+{
+       int ret;
+       struct sk_buff *skb = get_free_pkt(cm_node);
+
+       if (!skb) {
+               nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
+               return -1;
+       }
+
+       form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK);
+       ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 0);
+
+       return ret;
+}
+
+
+/**
+ * send_fin
+ */
+int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb)
+{
+       int ret;
+
+       /* if we didn't get a frame get one */
+       if (!skb)
+               skb = get_free_pkt(cm_node);
+
+       if (!skb) {
+               nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
+               return -1;
+       }
+
+       form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK | SET_FIN);
+       ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
+
+       return ret;
+}
+
+
+/**
+ * get_free_pkt
+ */
+struct sk_buff *get_free_pkt(struct nes_cm_node *cm_node)
+{
+       struct sk_buff *skb, *new_skb;
+
+       /* check to see if we need to repopulate the free tx pkt queue */
+       if (skb_queue_len(&cm_node->cm_core->tx_free_list) < NES_CM_FREE_PKT_LO_WATERMARK) {
+               while (skb_queue_len(&cm_node->cm_core->tx_free_list) <
+                               cm_node->cm_core->free_tx_pkt_max) {
+                       /* replace the frame we took, we won't get it back */
+                       new_skb = dev_alloc_skb(cm_node->cm_core->mtu);
+                       BUG_ON(!new_skb);
+                       /* add a replacement frame to the free tx list head */
+                       skb_queue_head(&cm_node->cm_core->tx_free_list, new_skb);
+               }
+       }
+
+       skb = skb_dequeue(&cm_node->cm_core->tx_free_list);
+
+       return skb;
+}
+
+
+/**
+ * make_hashkey - generate hash key from node tuple
+ */
+static inline int make_hashkey(u16 loc_port, nes_addr_t loc_addr, u16 rem_port,
+               nes_addr_t rem_addr)
+{
+       u32 hashkey = 0;
+
+       hashkey = loc_addr + rem_addr + loc_port + rem_port;
+       hashkey = (hashkey % NES_CM_HASHTABLE_SIZE);
+
+       return hashkey;
+}
+
+
+/**
+ * find_node - find a cm node that matches the reference cm node
+ */
+static struct nes_cm_node *find_node(struct nes_cm_core *cm_core,
+               u16 rem_port, nes_addr_t rem_addr, u16 loc_port, nes_addr_t loc_addr)
+{
+       unsigned long flags;
+       u32 hashkey;
+       struct list_head *list_pos;
+       struct list_head *hte;
+       struct nes_cm_node *cm_node;
+
+       /* make a hash index key for this packet */
+       hashkey = make_hashkey(loc_port, loc_addr, rem_port, rem_addr);
+
+       /* get a handle on the hte */
+       hte = &cm_core->connected_nodes;
+
+       nes_debug(NES_DBG_CM, "Searching for an owner node:%x:%x from core %p->%p\n",
+                       loc_addr, loc_port, cm_core, hte);
+
+       /* walk list and find cm_node associated with this session ID */
+       spin_lock_irqsave(&cm_core->ht_lock, flags);
+       list_for_each(list_pos, hte) {
+               cm_node = container_of(list_pos, struct nes_cm_node, list);
+               /* compare quad, return node handle if a match */
+               nes_debug(NES_DBG_CM, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
+                               cm_node->loc_addr, cm_node->loc_port,
+                               loc_addr, loc_port,
+                               cm_node->rem_addr, cm_node->rem_port,
+                               rem_addr, rem_port);
+               if ((cm_node->loc_addr == loc_addr) && (cm_node->loc_port == loc_port) &&
+                               (cm_node->rem_addr == rem_addr) && (cm_node->rem_port == rem_port)) {
+                       add_ref_cm_node(cm_node);
+                       spin_unlock_irqrestore(&cm_core->ht_lock, flags);
+                       return cm_node;
+               }
+       }
+       spin_unlock_irqrestore(&cm_core->ht_lock, flags);
+
+       /* no owner node */
+       return NULL;
+}
+
+
+/**
+ * find_listener - find a cm node listening on this addr-port pair
+ */
+static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
+               nes_addr_t dst_addr, u16 dst_port, enum nes_cm_listener_state listener_state)
+{
+       unsigned long flags;
+       struct list_head *listen_list;
+       struct nes_cm_listener *listen_node;
+
+       /* walk list and find cm_node associated with this session ID */
+       spin_lock_irqsave(&cm_core->listen_list_lock, flags);
+       list_for_each(listen_list, &cm_core->listen_list.list) {
+               listen_node = container_of(listen_list, struct nes_cm_listener, list);
+               /* compare node pair, return node handle if a match */
+               if (((listen_node->loc_addr == dst_addr) ||
+                               listen_node->loc_addr == 0x00000000) &&
+                               (listen_node->loc_port == dst_port) &&
+                               (listener_state & listen_node->listener_state)) {
+                       atomic_inc(&listen_node->ref_count);
+                       spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
+                       return listen_node;
+               }
+       }
+       spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
+
+       nes_debug(NES_DBG_CM, "Unable to find listener- %x:%x\n",
+                       dst_addr, dst_port);
+
+       /* no listener */
+       return NULL;
+}
+
+
+/**
+ * add_hte_node - add a cm node to the hash table
+ */
+static int add_hte_node(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
+{
+       unsigned long flags;
+       u32 hashkey;
+       struct list_head *hte;
+
+       if (!cm_node || !cm_core)
+               return -EINVAL;
+
+       nes_debug(NES_DBG_CM, "Adding Node to Active Connection HT\n");
+
+       /* first, make an index into our hash table */
+       hashkey = make_hashkey(cm_node->loc_port, cm_node->loc_addr,
+                       cm_node->rem_port, cm_node->rem_addr);
+       cm_node->hashkey = hashkey;
+
+       spin_lock_irqsave(&cm_core->ht_lock, flags);
+
+       /* get a handle on the hash table element (list head for this slot) */
+       hte = &cm_core->connected_nodes;
+       list_add_tail(&cm_node->list, hte);
+       atomic_inc(&cm_core->ht_node_cnt);
+
+       spin_unlock_irqrestore(&cm_core->ht_lock, flags);
+
+       return 0;
+}
+
+
+/**
+ * mini_cm_dec_refcnt_listen
+ */
+static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
+               struct nes_cm_listener *listener, int free_hanging_nodes)
+{
+       int ret = 1;
+       unsigned long flags;
+       spin_lock_irqsave(&cm_core->listen_list_lock, flags);
+       if (!atomic_dec_return(&listener->ref_count)) {
+               list_del(&listener->list);
+
+               /* decrement our listen node count */
+               atomic_dec(&cm_core->listen_node_cnt);
+
+               spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
+
+               if (listener->nesvnic) {
+                       nes_manage_apbvt(listener->nesvnic, listener->loc_port,
+                                       PCI_FUNC(listener->nesvnic->nesdev->pcidev->devfn), NES_MANAGE_APBVT_DEL);
+               }
+
+               nes_debug(NES_DBG_CM, "destroying listener (%p)\n", listener);
+
+               kfree(listener);
+               ret = 0;
+               cm_listens_destroyed++;
+       } else {
+               spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
+       }
+       if (listener) {
+               if (atomic_read(&listener->pend_accepts_cnt) > 0)
+                       nes_debug(NES_DBG_CM, "destroying listener (%p)"
+                                       " with non-zero pending accepts=%u\n",
+                                       listener, atomic_read(&listener->pend_accepts_cnt));
+       }
+
+       return ret;
+}
+
+
+/**
+ * mini_cm_del_listen
+ */
+static int mini_cm_del_listen(struct nes_cm_core *cm_core,
+               struct nes_cm_listener *listener)
+{
+       listener->listener_state = NES_CM_LISTENER_PASSIVE_STATE;
+       listener->cm_id = NULL; /* going to be destroyed pretty soon */
+       return mini_cm_dec_refcnt_listen(cm_core, listener, 1);
+}
+
+
+/**
+ * mini_cm_accelerated
+ */
+static inline int mini_cm_accelerated(struct nes_cm_core *cm_core,
+               struct nes_cm_node *cm_node)
+{
+       u32 was_timer_set;
+       cm_node->accelerated = 1;
+
+       if (cm_node->accept_pend) {
+               BUG_ON(!cm_node->listener);
+               atomic_dec(&cm_node->listener->pend_accepts_cnt);
+               BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
+       }
+
+       was_timer_set = timer_pending(&cm_core->tcp_timer);
+       if (!was_timer_set) {
+               cm_core->tcp_timer.expires = jiffies + NES_SHORT_TIME;
+               add_timer(&cm_core->tcp_timer);
+       }
+
+       return 0;
+}
+
+
+/**
+ * nes_addr_send_arp
+ */
+static void nes_addr_send_arp(u32 dst_ip)
+{
+       struct rtable *rt;
+       struct flowi fl;
+
+       memset(&fl, 0, sizeof fl);
+       fl.nl_u.ip4_u.daddr = htonl(dst_ip);
+       if (ip_route_output_key(&init_net, &rt, &fl)) {
+               printk("%s: ip_route_output_key failed for 0x%08X\n",
+                               __FUNCTION__, dst_ip);
+               return;
+       }
+
+       neigh_event_send(rt->u.dst.neighbour, NULL);
+       ip_rt_put(rt);
+}
+
+
+/**
+ * make_cm_node - create a new instance of a cm node
+ */
+static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
+               struct nes_vnic *nesvnic, struct nes_cm_info *cm_info,
+               struct nes_cm_listener *listener)
+{
+       struct nes_cm_node *cm_node;
+       struct timespec ts;
+       int arpindex = 0;
+       struct nes_device *nesdev;
+       struct nes_adapter *nesadapter;
+
+       /* create an hte and cm_node for this instance */
+       cm_node = kzalloc(sizeof(*cm_node), GFP_ATOMIC);
+       if (!cm_node)
+               return NULL;
+
+       /* set our node specific transport info */
+       cm_node->loc_addr = cm_info->loc_addr;
+       cm_node->rem_addr = cm_info->rem_addr;
+       cm_node->loc_port = cm_info->loc_port;
+       cm_node->rem_port = cm_info->rem_port;
+       cm_node->send_write0 = send_first;
+       nes_debug(NES_DBG_CM, "Make node addresses : loc = %x:%x, rem = %x:%x\n",
+                       cm_node->loc_addr, cm_node->loc_port, cm_node->rem_addr, cm_node->rem_port);
+       cm_node->listener = listener;
+       cm_node->netdev = nesvnic->netdev;
+       cm_node->cm_id = cm_info->cm_id;
+       memcpy(cm_node->loc_mac, nesvnic->netdev->dev_addr, ETH_ALEN);
+
+       nes_debug(NES_DBG_CM, "listener=%p, cm_id=%p\n",
+                       cm_node->listener, cm_node->cm_id);
+
+       INIT_LIST_HEAD(&cm_node->retrans_list);
+       spin_lock_init(&cm_node->retrans_list_lock);
+       INIT_LIST_HEAD(&cm_node->recv_list);
+       spin_lock_init(&cm_node->recv_list_lock);
+
+       cm_node->loopbackpartner = NULL;
+       atomic_set(&cm_node->ref_count, 1);
+       /* associate our parent CM core */
+       cm_node->cm_core = cm_core;
+       cm_node->tcp_cntxt.loc_id = NES_CM_DEF_LOCAL_ID;
+       cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
+       cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >>
+                       NES_CM_DEFAULT_RCV_WND_SCALE;
+       ts = current_kernel_time();
+       cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec);
+       cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) -
+                       sizeof(struct tcphdr) - ETH_HLEN;
+       cm_node->tcp_cntxt.rcv_nxt = 0;
+       /* get a unique session ID , add thread_id to an upcounter to handle race */
+       atomic_inc(&cm_core->node_cnt);
+       atomic_inc(&cm_core->session_id);
+       cm_node->session_id = (u32)(atomic_read(&cm_core->session_id) + current->tgid);
+       cm_node->conn_type = cm_info->conn_type;
+       cm_node->apbvt_set = 0;
+       cm_node->accept_pend = 0;
+
+       cm_node->nesvnic = nesvnic;
+       /* get some device handles, for arp lookup */
+       nesdev = nesvnic->nesdev;
+       nesadapter = nesdev->nesadapter;
+
+       cm_node->loopbackpartner = NULL;
+       /* get the mac addr for the remote node */
+       arpindex = nes_arp_table(nesdev, cm_node->rem_addr, NULL, NES_ARP_RESOLVE);
+       if (arpindex < 0) {
+               kfree(cm_node);
+               nes_addr_send_arp(cm_info->rem_addr);
+               return NULL;
+       }
+
+       /* copy the mac addr to node context */
+       memcpy(cm_node->rem_mac, nesadapter->arp_table[arpindex].mac_addr, ETH_ALEN);
+       nes_debug(NES_DBG_CM, "Remote mac addr from arp table:%02x,"
+                       " %02x, %02x, %02x, %02x, %02x\n",
+                       cm_node->rem_mac[0], cm_node->rem_mac[1],
+                       cm_node->rem_mac[2], cm_node->rem_mac[3],
+                       cm_node->rem_mac[4], cm_node->rem_mac[5]);
+
+       add_hte_node(cm_core, cm_node);
+       atomic_inc(&cm_nodes_created);
+
+       return cm_node;
+}
+
+
+/**
+ * add_ref_cm_node - destroy an instance of a cm node
+ */
+static int add_ref_cm_node(struct nes_cm_node *cm_node)
+{
+       atomic_inc(&cm_node->ref_count);
+       return 0;
+}
+
+
+/**
+ * rem_ref_cm_node - destroy an instance of a cm node
+ */
+static int rem_ref_cm_node(struct nes_cm_core *cm_core,
+               struct nes_cm_node *cm_node)
+{
+       unsigned long flags, qplockflags;
+       struct nes_timer_entry *send_entry;
+       struct nes_timer_entry *recv_entry;
+       struct iw_cm_id *cm_id;
+       struct list_head *list_core, *list_node_temp;
+       struct nes_qp *nesqp;
+
+       if (!cm_node)
+               return -EINVAL;
+
+       spin_lock_irqsave(&cm_node->cm_core->ht_lock, flags);
+       if (atomic_dec_return(&cm_node->ref_count)) {
+               spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
+               return 0;
+       }
+       list_del(&cm_node->list);
+       atomic_dec(&cm_core->ht_node_cnt);
+       spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
+
+       /* if the node is destroyed before connection was accelerated */
+       if (!cm_node->accelerated && cm_node->accept_pend) {
+               BUG_ON(!cm_node->listener);
+               atomic_dec(&cm_node->listener->pend_accepts_cnt);
+               BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
+       }
+
+       spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+       list_for_each_safe(list_core, list_node_temp, &cm_node->retrans_list) {
+               send_entry = container_of(list_core, struct nes_timer_entry, list);
+               list_del(&send_entry->list);
+               spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+               dev_kfree_skb_any(send_entry->skb);
+               kfree(send_entry);
+               spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
+               continue;
+       }
+       spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
+
+       spin_lock_irqsave(&cm_node->recv_list_lock, flags);
+       list_for_each_safe(list_core, list_node_temp, &cm_node->recv_list) {
+               recv_entry = container_of(list_core, struct nes_timer_entry, list);
+               list_del(&recv_entry->list);
+               cm_id = cm_node->cm_id;
+               spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
+               if (recv_entry->type == NES_TIMER_TYPE_CLOSE) {
+                       nesqp = (struct nes_qp *)recv_entry->skb;
+                       spin_lock_irqsave(&nesqp->lock, qplockflags);
+                       if (nesqp->cm_id) {
+                               nes_debug(NES_DBG_CM, "QP%u: cm_id = %p: ****** HIT A NES_TIMER_TYPE_CLOSE"
+                                               " with something to do!!! ******\n",
+                                               nesqp->hwqp.qp_id, cm_id);
+                               nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
+                               nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
+                               nesqp->ibqp_state = IB_QPS_ERR;
+                               spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                               nes_cm_disconn(nesqp);
+                       } else {
+                               spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                               nes_debug(NES_DBG_CM, "QP%u: cm_id = %p: ****** HIT A NES_TIMER_TYPE_CLOSE"
+                                               " with nothing to do!!! ******\n",
+                                               nesqp->hwqp.qp_id, cm_id);
+                               nes_rem_ref(&nesqp->ibqp);
+                       }
+                       cm_id->rem_ref(cm_id);
+               } else if (recv_entry->type == NES_TIMER_TYPE_RECV) {
+                       dev_kfree_skb_any(recv_entry->skb);
+               }
+               kfree(recv_entry);
+               spin_lock_irqsave(&cm_node->recv_list_lock, flags);
+       }
+       spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
+
+       if (cm_node->listener) {
+               mini_cm_dec_refcnt_listen(cm_core, cm_node->listener, 0);
+       } else {
+               if (cm_node->apbvt_set && cm_node->nesvnic) {
+                       nes_manage_apbvt(cm_node->nesvnic, cm_node->loc_port,
+                                       PCI_FUNC(cm_node->nesvnic->nesdev->pcidev->devfn),
+                                       NES_MANAGE_APBVT_DEL);
+               }
+       }
+
+       kfree(cm_node);
+       atomic_dec(&cm_core->node_cnt);
+       atomic_inc(&cm_nodes_destroyed);
+
+       return 0;
+}
+
+
+/**
+ * process_options
+ */
+static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc, u32 optionsize, u32 syn_packet)
+{
+       u32 tmp;
+       u32 offset = 0;
+       union all_known_options *all_options;
+       char got_mss_option = 0;
+
+       while (offset < optionsize) {
+               all_options = (union all_known_options *)(optionsloc + offset);
+               switch (all_options->as_base.optionnum) {
+                       case OPTION_NUMBER_END:
+                               offset = optionsize;
+                               break;
+                       case OPTION_NUMBER_NONE:
+                               offset += 1;
+                               continue;
+                       case OPTION_NUMBER_MSS:
+                               nes_debug(NES_DBG_CM, "%s: MSS Length: %d Offset: %d Size: %d\n",
+                                               __FUNCTION__,
+                                               all_options->as_mss.length, offset, optionsize);
+                               got_mss_option = 1;
+                               if (all_options->as_mss.length != 4) {
+                                       return 1;
+                               } else {
+                                       tmp = ntohs(all_options->as_mss.mss);
+                                       if (tmp > 0 && tmp < cm_node->tcp_cntxt.mss)
+                                               cm_node->tcp_cntxt.mss = tmp;
+                               }
+                               break;
+                       case OPTION_NUMBER_WINDOW_SCALE:
+                               cm_node->tcp_cntxt.snd_wscale = all_options->as_windowscale.shiftcount;
+                               break;
+                       case OPTION_NUMBER_WRITE0:
+                               cm_node->send_write0 = 1;
+                               break;
+                       default:
+                               nes_debug(NES_DBG_CM, "TCP Option not understood: %x\n",
+                                               all_options->as_base.optionnum);
+                               break;
+               }
+               offset += all_options->as_base.length;
+       }
+       if ((!got_mss_option) && (syn_packet))
+               cm_node->tcp_cntxt.mss = NES_CM_DEFAULT_MSS;
+       return 0;
+}
+
+
+/**
+ * process_packet
+ */
+int process_packet(struct nes_cm_node *cm_node, struct sk_buff *skb,
+               struct nes_cm_core *cm_core)
+{
+       int optionsize;
+       int datasize;
+       int ret = 0;
+       struct tcphdr *tcph = tcp_hdr(skb);
+       u32 inc_sequence;
+       if (cm_node->state == NES_CM_STATE_SYN_SENT && tcph->syn) {
+               inc_sequence = ntohl(tcph->seq);
+               cm_node->tcp_cntxt.rcv_nxt = inc_sequence;
+       }
+
+       if ((!tcph) || (cm_node->state == NES_CM_STATE_TSA)) {
+               BUG_ON(!tcph);
+               atomic_inc(&cm_accel_dropped_pkts);
+               return -1;
+       }
+
+       if (tcph->rst) {
+               atomic_inc(&cm_resets_recvd);
+               nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u. refcnt=%d\n",
+                               cm_node, cm_node->state, atomic_read(&cm_node->ref_count));
+               switch (cm_node->state) {
+                       case NES_CM_STATE_LISTENING:
+                               rem_ref_cm_node(cm_core, cm_node);
+                               break;
+                       case NES_CM_STATE_TSA:
+                       case NES_CM_STATE_CLOSED:
+                               break;
+                       case NES_CM_STATE_SYN_RCVD:
+                                       nes_debug(NES_DBG_CM, "Received a reset for local 0x%08X:%04X,"
+                                                       " remote 0x%08X:%04X, node state = %u\n",
+                                                       cm_node->loc_addr, cm_node->loc_port,
+                                                       cm_node->rem_addr, cm_node->rem_port,
+                                                       cm_node->state);
+                               rem_ref_cm_node(cm_core, cm_node);
+                               break;
+                       case NES_CM_STATE_ONE_SIDE_ESTABLISHED:
+                       case NES_CM_STATE_ESTABLISHED:
+                       case NES_CM_STATE_MPAREQ_SENT:
+                       default:
+                                       nes_debug(NES_DBG_CM, "Received a reset for local 0x%08X:%04X,"
+                                                       " remote 0x%08X:%04X, node state = %u refcnt=%d\n",
+                                                       cm_node->loc_addr, cm_node->loc_port,
+                                                       cm_node->rem_addr, cm_node->rem_port,
+                                                       cm_node->state, atomic_read(&cm_node->ref_count));
+                               // create event
+                               cm_node->state = NES_CM_STATE_CLOSED;
+
+                               create_event(cm_node, NES_CM_EVENT_ABORTED);
+                               break;
+
+               }
+               return -1;
+       }
+
+       optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
+
+       skb_pull(skb, ip_hdr(skb)->ihl << 2);
+       skb_pull(skb, tcph->doff << 2);
+
+       datasize = skb->len;
+       inc_sequence = ntohl(tcph->seq);
+       nes_debug(NES_DBG_CM, "datasize = %u, sequence = 0x%08X, ack_seq = 0x%08X,"
+                       " rcv_nxt = 0x%08X Flags: %s %s.\n",
+                       datasize, inc_sequence, ntohl(tcph->ack_seq),
+                       cm_node->tcp_cntxt.rcv_nxt, (tcph->syn ? "SYN":""),
+                       (tcph->ack ? "ACK":""));
+
+       if (!tcph->syn && (inc_sequence != cm_node->tcp_cntxt.rcv_nxt)
+               ) {
+               nes_debug(NES_DBG_CM, "dropping packet, datasize = %u, sequence = 0x%08X,"
+                               " ack_seq = 0x%08X, rcv_nxt = 0x%08X Flags: %s.\n",
+                               datasize, inc_sequence, ntohl(tcph->ack_seq),
+                               cm_node->tcp_cntxt.rcv_nxt, (tcph->ack ? "ACK":""));
+               if (cm_node->state == NES_CM_STATE_LISTENING) {
+                       rem_ref_cm_node(cm_core, cm_node);
+               }
+               return -1;
+       }
+
+               cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
+
+
+       if (optionsize) {
+               u8 *optionsloc = (u8 *)&tcph[1];
+               if (process_options(cm_node, optionsloc, optionsize, (u32)tcph->syn)) {
+                       nes_debug(NES_DBG_CM, "%s: Node %p, Sending RESET\n", __FUNCTION__, cm_node);
+                       send_reset(cm_node);
+                       if (cm_node->state != NES_CM_STATE_SYN_SENT)
+                       rem_ref_cm_node(cm_core, cm_node);
+                       return 0;
+               }
+       } else if (tcph->syn)
+               cm_node->tcp_cntxt.mss = NES_CM_DEFAULT_MSS;
+
+       cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window) <<
+                       cm_node->tcp_cntxt.snd_wscale;
+
+       if (cm_node->tcp_cntxt.snd_wnd > cm_node->tcp_cntxt.max_snd_wnd) {
+               cm_node->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.snd_wnd;
+       }
+
+       if (tcph->ack) {
+               cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
+               switch (cm_node->state) {
+                       case NES_CM_STATE_SYN_RCVD:
+                       case NES_CM_STATE_SYN_SENT:
+                               /* read and stash current sequence number */
+                               if (cm_node->tcp_cntxt.rem_ack_num != cm_node->tcp_cntxt.loc_seq_num) {
+                                       nes_debug(NES_DBG_CM, "ERROR - cm_node->tcp_cntxt.rem_ack_num !="
+                                                       " cm_node->tcp_cntxt.loc_seq_num\n");
+                                       send_reset(cm_node);
+                                       return 0;
+                               }
+                               if (cm_node->state == NES_CM_STATE_SYN_SENT)
+                                       cm_node->state = NES_CM_STATE_ONE_SIDE_ESTABLISHED;
+                               else {
+                                               cm_node->state = NES_CM_STATE_ESTABLISHED;
+                               }
+                               break;
+                       case NES_CM_STATE_LAST_ACK:
+                               cm_node->state = NES_CM_STATE_CLOSED;
+                               break;
+                       case NES_CM_STATE_FIN_WAIT1:
+                               cm_node->state = NES_CM_STATE_FIN_WAIT2;
+                               break;
+                       case NES_CM_STATE_CLOSING:
+                               cm_node->state = NES_CM_STATE_TIME_WAIT;
+                               /* need to schedule this to happen in 2MSL timeouts */
+                               cm_node->state = NES_CM_STATE_CLOSED;
+                               break;
+                       case NES_CM_STATE_ONE_SIDE_ESTABLISHED:
+                       case NES_CM_STATE_ESTABLISHED:
+                       case NES_CM_STATE_MPAREQ_SENT:
+                       case NES_CM_STATE_CLOSE_WAIT:
+                       case NES_CM_STATE_TIME_WAIT:
+                       case NES_CM_STATE_CLOSED:
+                               break;
+                       case NES_CM_STATE_LISTENING:
+                               nes_debug(NES_DBG_CM, "Received an ACK on a listening port (SYN %d)\n", tcph->syn);
+                               cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
+                               send_reset(cm_node);
+                               /* send_reset bumps refcount, this should have been a new node */
+                               rem_ref_cm_node(cm_core, cm_node);
+                               return -1;
+                               break;
+                       case NES_CM_STATE_TSA:
+                               nes_debug(NES_DBG_CM, "Received a packet with the ack bit set while in TSA state\n");
+                               break;
+                       case NES_CM_STATE_UNKNOWN:
+                       case NES_CM_STATE_INITED:
+                       case NES_CM_STATE_ACCEPTING:
+                       case NES_CM_STATE_FIN_WAIT2:
+                       default:
+                               nes_debug(NES_DBG_CM, "Received ack from unknown state: %x\n",
+                                               cm_node->state);
+                               send_reset(cm_node);
+                               break;
+               }
+       }
+
+       if (tcph->syn) {
+               if (cm_node->state == NES_CM_STATE_LISTENING) {
+                       /* do not exceed backlog */
+                       atomic_inc(&cm_node->listener->pend_accepts_cnt);
+                       if (atomic_read(&cm_node->listener->pend_accepts_cnt) >
+                                       cm_node->listener->backlog) {
+                               nes_debug(NES_DBG_CM, "drop syn due to backlog pressure \n");
+                               cm_backlog_drops++;
+                               atomic_dec(&cm_node->listener->pend_accepts_cnt);
+                               rem_ref_cm_node(cm_core, cm_node);
+                               return 0;
+                       }
+                       cm_node->accept_pend = 1;
+
+               }
+               if (datasize == 0)
+                       cm_node->tcp_cntxt.rcv_nxt ++;
+
+               if (cm_node->state == NES_CM_STATE_LISTENING) {
+                       cm_node->state = NES_CM_STATE_SYN_RCVD;
+                       send_syn(cm_node, 1);
+               }
+               if (cm_node->state == NES_CM_STATE_ONE_SIDE_ESTABLISHED) {
+                       cm_node->state = NES_CM_STATE_ESTABLISHED;
+                       /* send final handshake ACK */
+                       ret = send_ack(cm_node);
+                       if (ret < 0)
+                               return ret;
+
+                               cm_node->state = NES_CM_STATE_MPAREQ_SENT;
+                               ret = send_mpa_request(cm_node);
+                               if (ret < 0)
+                                       return ret;
+               }
+       }
+
+       if (tcph->fin) {
+               cm_node->tcp_cntxt.rcv_nxt++;
+               switch (cm_node->state) {
+                       case NES_CM_STATE_SYN_RCVD:
+                       case NES_CM_STATE_SYN_SENT:
+                       case NES_CM_STATE_ONE_SIDE_ESTABLISHED:
+                       case NES_CM_STATE_ESTABLISHED:
+                       case NES_CM_STATE_ACCEPTING:
+                       case NES_CM_STATE_MPAREQ_SENT:
+                               cm_node->state = NES_CM_STATE_CLOSE_WAIT;
+                               cm_node->state = NES_CM_STATE_LAST_ACK;
+                               ret = send_fin(cm_node, NULL);
+                               break;
+                       case NES_CM_STATE_FIN_WAIT1:
+                               cm_node->state = NES_CM_STATE_CLOSING;
+                               ret = send_ack(cm_node);
+                               break;
+                       case NES_CM_STATE_FIN_WAIT2:
+                               cm_node->state = NES_CM_STATE_TIME_WAIT;
+                               cm_node->tcp_cntxt.loc_seq_num ++;
+                               ret = send_ack(cm_node);
+                               /* need to schedule this to happen in 2MSL timeouts */
+                               cm_node->state = NES_CM_STATE_CLOSED;
+                               break;
+                       case NES_CM_STATE_CLOSE_WAIT:
+                       case NES_CM_STATE_LAST_ACK:
+                       case NES_CM_STATE_CLOSING:
+                       case NES_CM_STATE_TSA:
+                       default:
+                               nes_debug(NES_DBG_CM, "Received a fin while in %x state\n",
+                                               cm_node->state);
+                               ret = -EINVAL;
+                               break;
+               }
+       }
+
+       if (datasize) {
+               u8 *dataloc = skb->data;
+               /* figure out what state we are in and handle transition to next state */
+               switch (cm_node->state) {
+                       case NES_CM_STATE_LISTENING:
+                       case NES_CM_STATE_SYN_RCVD:
+                       case NES_CM_STATE_SYN_SENT:
+                       case NES_CM_STATE_FIN_WAIT1:
+                       case NES_CM_STATE_FIN_WAIT2:
+                       case NES_CM_STATE_CLOSE_WAIT:
+                       case NES_CM_STATE_LAST_ACK:
+                       case NES_CM_STATE_CLOSING:
+                               break;
+                       case  NES_CM_STATE_MPAREQ_SENT:
+                               /* recv the mpa res frame, ret=frame len (incl priv data) */
+                               ret = parse_mpa(cm_node, dataloc, datasize);
+                               if (ret < 0)
+                                       break;
+                               /* set the req frame payload len in skb */
+                               /* we are done handling this state, set node to a TSA state */
+                               cm_node->state = NES_CM_STATE_TSA;
+                               send_ack(cm_node);
+                               create_event(cm_node, NES_CM_EVENT_CONNECTED);
+                               break;
+
+                       case  NES_CM_STATE_ESTABLISHED:
+                               /* we are expecting an MPA req frame */
+                               ret = parse_mpa(cm_node, dataloc, datasize);
+                               if (ret < 0) {
+                                       break;
+                               }
+                               cm_node->state = NES_CM_STATE_TSA;
+                               send_ack(cm_node);
+                               /* we got a valid MPA request, create an event */
+                               create_event(cm_node, NES_CM_EVENT_MPA_REQ);
+                               break;
+                       case  NES_CM_STATE_TSA:
+                               handle_exception_pkt(cm_node, skb);
+                               break;
+                       case NES_CM_STATE_UNKNOWN:
+                       case NES_CM_STATE_INITED:
+                       default:
+                               ret = -1;
+               }
+       }
+
+       return ret;
+}
+
+
+/**
+ * mini_cm_listen - create a listen node with params
+ */
+static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *cm_core,
+               struct nes_vnic *nesvnic, struct nes_cm_info *cm_info)
+{
+       struct nes_cm_listener *listener;
+       unsigned long flags;
+
+       nes_debug(NES_DBG_CM, "Search for 0x%08x : 0x%04x\n",
+               cm_info->loc_addr, cm_info->loc_port);
+
+       /* cannot have multiple matching listeners */
+       listener = find_listener(cm_core, htonl(cm_info->loc_addr),
+                       htons(cm_info->loc_port), NES_CM_LISTENER_EITHER_STATE);
+       if (listener && listener->listener_state == NES_CM_LISTENER_ACTIVE_STATE) {
+               /* find automatically incs ref count ??? */
+               atomic_dec(&listener->ref_count);
+               nes_debug(NES_DBG_CM, "Not creating listener since it already exists\n");
+               return NULL;
+       }
+
+       if (!listener) {
+               /* create a CM listen node (1/2 node to compare incoming traffic to) */
+               listener = kzalloc(sizeof(*listener), GFP_ATOMIC);
+               if (!listener) {
+                       nes_debug(NES_DBG_CM, "Not creating listener memory allocation failed\n");
+                       return NULL;
+               }
+
+               memset(listener, 0, sizeof(struct nes_cm_listener));
+               listener->loc_addr = htonl(cm_info->loc_addr);
+               listener->loc_port = htons(cm_info->loc_port);
+               listener->reused_node = 0;
+
+               atomic_set(&listener->ref_count, 1);
+       }
+       /* pasive case */
+       /* find already inc'ed the ref count */
+       else {
+               listener->reused_node = 1;
+       }
+
+       listener->cm_id = cm_info->cm_id;
+       atomic_set(&listener->pend_accepts_cnt, 0);
+       listener->cm_core = cm_core;
+       listener->nesvnic = nesvnic;
+       atomic_inc(&cm_core->node_cnt);
+       atomic_inc(&cm_core->session_id);
+
+       listener->session_id = (u32)(atomic_read(&cm_core->session_id) + current->tgid);
+       listener->conn_type = cm_info->conn_type;
+       listener->backlog = cm_info->backlog;
+       listener->listener_state = NES_CM_LISTENER_ACTIVE_STATE;
+
+       if (!listener->reused_node) {
+               spin_lock_irqsave(&cm_core->listen_list_lock, flags);
+               list_add(&listener->list, &cm_core->listen_list.list);
+               spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
+               atomic_inc(&cm_core->listen_node_cnt);
+       }
+
+       nes_debug(NES_DBG_CM, "Api - listen(): addr=0x%08X, port=0x%04x,"
+                       " listener = %p, backlog = %d, cm_id = %p.\n",
+                       cm_info->loc_addr, cm_info->loc_port,
+                       listener, listener->backlog, listener->cm_id);
+
+       return listener;
+}
+
+
+/**
+ * mini_cm_connect - make a connection node with params
+ */
+struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
+               struct nes_vnic *nesvnic, struct ietf_mpa_frame *mpa_frame,
+               struct nes_cm_info *cm_info)
+{
+       int ret = 0;
+       struct nes_cm_node *cm_node;
+       struct nes_cm_listener *loopbackremotelistener;
+       struct nes_cm_node *loopbackremotenode;
+       struct nes_cm_info loopback_cm_info;
+
+       u16 mpa_frame_size = sizeof(struct ietf_mpa_frame) +
+                       ntohs(mpa_frame->priv_data_len);
+
+       cm_info->loc_addr = htonl(cm_info->loc_addr);
+       cm_info->rem_addr = htonl(cm_info->rem_addr);
+       cm_info->loc_port = htons(cm_info->loc_port);
+       cm_info->rem_port = htons(cm_info->rem_port);
+
+       /* create a CM connection node */
+       cm_node = make_cm_node(cm_core, nesvnic, cm_info, NULL);
+       if (!cm_node)
+               return NULL;
+
+       // set our node side to client (active) side
+       cm_node->tcp_cntxt.client = 1;
+       cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
+
+       if (cm_info->loc_addr == cm_info->rem_addr) {
+               loopbackremotelistener = find_listener(cm_core, cm_node->rem_addr,
+                               cm_node->rem_port, NES_CM_LISTENER_ACTIVE_STATE);
+               if (loopbackremotelistener == NULL) {
+                       create_event(cm_node, NES_CM_EVENT_ABORTED);
+               } else {
+                       atomic_inc(&cm_loopbacks);
+                       loopback_cm_info = *cm_info;
+                       loopback_cm_info.loc_port = cm_info->rem_port;
+                       loopback_cm_info.rem_port = cm_info->loc_port;
+                       loopback_cm_info.cm_id = loopbackremotelistener->cm_id;
+                       loopbackremotenode = make_cm_node(cm_core, nesvnic, &loopback_cm_info,
+                                       loopbackremotelistener);
+                       loopbackremotenode->loopbackpartner = cm_node;
+                       loopbackremotenode->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
+                       cm_node->loopbackpartner = loopbackremotenode;
+                       memcpy(loopbackremotenode->mpa_frame_buf, &mpa_frame->priv_data,
+                                       mpa_frame_size);
+                       loopbackremotenode->mpa_frame_size = mpa_frame_size -
+                                       sizeof(struct ietf_mpa_frame);
+
+                       // we are done handling this state, set node to a TSA state
+                       cm_node->state = NES_CM_STATE_TSA;
+                       cm_node->tcp_cntxt.rcv_nxt = loopbackremotenode->tcp_cntxt.loc_seq_num;
+                       loopbackremotenode->tcp_cntxt.rcv_nxt = cm_node->tcp_cntxt.loc_seq_num;
+                       cm_node->tcp_cntxt.max_snd_wnd = loopbackremotenode->tcp_cntxt.rcv_wnd;
+                       loopbackremotenode->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.rcv_wnd;
+                       cm_node->tcp_cntxt.snd_wnd = loopbackremotenode->tcp_cntxt.rcv_wnd;
+                       loopbackremotenode->tcp_cntxt.snd_wnd = cm_node->tcp_cntxt.rcv_wnd;
+                       cm_node->tcp_cntxt.snd_wscale = loopbackremotenode->tcp_cntxt.rcv_wscale;
+                       loopbackremotenode->tcp_cntxt.snd_wscale = cm_node->tcp_cntxt.rcv_wscale;
+
+                       create_event(loopbackremotenode, NES_CM_EVENT_MPA_REQ);
+               }
+               return cm_node;
+       }
+
+       /* set our node side to client (active) side */
+       cm_node->tcp_cntxt.client = 1;
+       /* init our MPA frame ptr */
+       memcpy(&cm_node->mpa_frame, mpa_frame, mpa_frame_size);
+       cm_node->mpa_frame_size = mpa_frame_size;
+
+       /* send a syn and goto syn sent state */
+       cm_node->state = NES_CM_STATE_SYN_SENT;
+       ret = send_syn(cm_node, 0);
+
+       nes_debug(NES_DBG_CM, "Api - connect(): dest addr=0x%08X, port=0x%04x,"
+                       " cm_node=%p, cm_id = %p.\n",
+                       cm_node->rem_addr, cm_node->rem_port, cm_node, cm_node->cm_id);
+
+       return cm_node;
+}
+
+
+/**
+ * mini_cm_accept - accept a connection
+ * This function is never called
+ */
+int mini_cm_accept(struct nes_cm_core *cm_core, struct ietf_mpa_frame *mpa_frame,
+               struct nes_cm_node *cm_node)
+{
+       return 0;
+}
+
+
+/**
+ * mini_cm_reject - reject and teardown a connection
+ */
+int mini_cm_reject(struct nes_cm_core *cm_core,
+               struct ietf_mpa_frame *mpa_frame,
+               struct nes_cm_node *cm_node)
+{
+       int ret = 0;
+       struct sk_buff *skb;
+       u16 mpa_frame_size = sizeof(struct ietf_mpa_frame) +
+                       ntohs(mpa_frame->priv_data_len);
+
+       skb = get_free_pkt(cm_node);
+       if (!skb) {
+               nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
+               return -1;
+       }
+
+       /* send an MPA Request frame */
+       form_cm_frame(skb, cm_node, NULL, 0, mpa_frame, mpa_frame_size, SET_ACK | SET_FIN);
+       ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
+
+       cm_node->state = NES_CM_STATE_CLOSED;
+       ret = send_fin(cm_node, NULL);
+
+       if (ret < 0) {
+               printk(KERN_INFO PFX "failed to send MPA Reply (reject)\n");
+               return ret;
+       }
+
+       return ret;
+}
+
+
+/**
+ * mini_cm_close
+ */
+int mini_cm_close(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
+{
+       int ret = 0;
+
+       if (!cm_core || !cm_node)
+               return -EINVAL;
+
+       switch (cm_node->state) {
+               /* if passed in node is null, create a reference key node for node search */
+               /* check if we found an owner node for this pkt */
+               case NES_CM_STATE_SYN_RCVD:
+               case NES_CM_STATE_SYN_SENT:
+               case NES_CM_STATE_ONE_SIDE_ESTABLISHED:
+               case NES_CM_STATE_ESTABLISHED:
+               case NES_CM_STATE_ACCEPTING:
+               case NES_CM_STATE_MPAREQ_SENT:
+                       cm_node->state = NES_CM_STATE_FIN_WAIT1;
+                       send_fin(cm_node, NULL);
+                       break;
+               case NES_CM_STATE_CLOSE_WAIT:
+                       cm_node->state = NES_CM_STATE_LAST_ACK;
+                       send_fin(cm_node, NULL);
+                       break;
+               case NES_CM_STATE_FIN_WAIT1:
+               case NES_CM_STATE_FIN_WAIT2:
+               case NES_CM_STATE_LAST_ACK:
+               case NES_CM_STATE_TIME_WAIT:
+               case NES_CM_STATE_CLOSING:
+                       ret = -1;
+                       break;
+               case NES_CM_STATE_LISTENING:
+               case NES_CM_STATE_UNKNOWN:
+               case NES_CM_STATE_INITED:
+               case NES_CM_STATE_CLOSED:
+               case NES_CM_STATE_TSA:
+                       ret = rem_ref_cm_node(cm_core, cm_node);
+                       break;
+       }
+       cm_node->cm_id = NULL;
+       return ret;
+}
+
+
+/**
+ * recv_pkt - recv an ETHERNET packet, and process it through CM
+ * node state machine
+ */
+int mini_cm_recv_pkt(struct nes_cm_core *cm_core, struct nes_vnic *nesvnic,
+               struct sk_buff *skb)
+{
+       struct nes_cm_node *cm_node = NULL;
+       struct nes_cm_listener *listener = NULL;
+       struct iphdr *iph;
+       struct tcphdr *tcph;
+       struct nes_cm_info nfo;
+       int ret = 0;
+
+       if (!skb || skb->len < sizeof(struct iphdr) + sizeof(struct tcphdr)) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       iph = (struct iphdr *)skb->data;
+       tcph = (struct tcphdr *)(skb->data + sizeof(struct iphdr));
+       skb_reset_network_header(skb);
+       skb_set_transport_header(skb, sizeof(*tcph));
+       skb->len = ntohs(iph->tot_len);
+
+       nfo.loc_addr = ntohl(iph->daddr);
+       nfo.loc_port = ntohs(tcph->dest);
+       nfo.rem_addr = ntohl(iph->saddr);
+       nfo.rem_port = ntohs(tcph->source);
+
+       nes_debug(NES_DBG_CM, "Received packet: dest=0x%08X:0x%04X src=0x%08X:0x%04X\n",
+                       iph->daddr, tcph->dest, iph->saddr, tcph->source);
+
+       /* note: this call is going to increment cm_node ref count */
+       cm_node = find_node(cm_core,
+                       nfo.rem_port, nfo.rem_addr,
+                       nfo.loc_port, nfo.loc_addr);
+
+       if (!cm_node) {
+               listener = find_listener(cm_core, nfo.loc_addr, nfo.loc_port,
+                               NES_CM_LISTENER_ACTIVE_STATE);
+               if (listener) {
+                       nfo.cm_id = listener->cm_id;
+                       nfo.conn_type = listener->conn_type;
+               } else {
+                       nfo.cm_id = NULL;
+                       nfo.conn_type = 0;
+               }
+
+               cm_node = make_cm_node(cm_core, nesvnic, &nfo, listener);
+               if (!cm_node) {
+                       nes_debug(NES_DBG_CM, "Unable to allocate node\n");
+                       if (listener) {
+                               nes_debug(NES_DBG_CM, "unable to allocate node and decrementing listener refcount\n");
+                               atomic_dec(&listener->ref_count);
+                       }
+                       ret = -1;
+                       goto out;
+               }
+               if (!listener) {
+                       nes_debug(NES_DBG_CM, "Packet found for unknown port %x refcnt=%d\n",
+                                       nfo.loc_port, atomic_read(&cm_node->ref_count));
+                       if (!tcph->rst) {
+                               nes_debug(NES_DBG_CM, "Packet found for unknown port=%d"
+                                               " rem_port=%d refcnt=%d\n",
+                                               nfo.loc_port, nfo.rem_port, atomic_read(&cm_node->ref_count));
+
+                               cm_node->tcp_cntxt.rcv_nxt = ntohl(tcph->seq);
+                               cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
+                               send_reset(cm_node);
+                       }
+                       rem_ref_cm_node(cm_core, cm_node);
+                       ret = -1;
+                       goto out;
+               }
+               add_ref_cm_node(cm_node);
+               cm_node->state = NES_CM_STATE_LISTENING;
+       }
+
+       nes_debug(NES_DBG_CM, "Processing Packet for node %p, data = (%p):\n",
+                       cm_node, skb->data);
+       process_packet(cm_node, skb, cm_core);
+
+       rem_ref_cm_node(cm_core, cm_node);
+       out:
+       if (skb)
+               dev_kfree_skb_any(skb);
+       return ret;
+}
+
+
+/**
+ * nes_cm_alloc_core - allocate a top level instance of a cm core
+ */
+struct nes_cm_core *nes_cm_alloc_core(void)
+{
+       int i;
+
+       struct nes_cm_core *cm_core;
+       struct sk_buff *skb = NULL;
+
+       /* setup the CM core */
+       /* alloc top level core control structure */
+       cm_core = kzalloc(sizeof(*cm_core), GFP_KERNEL);
+       if (!cm_core)
+               return NULL;
+
+       INIT_LIST_HEAD(&cm_core->connected_nodes);
+       init_timer(&cm_core->tcp_timer);
+       cm_core->tcp_timer.function = nes_cm_timer_tick;
+
+       cm_core->mtu   = NES_CM_DEFAULT_MTU;
+       cm_core->state = NES_CM_STATE_INITED;
+       cm_core->free_tx_pkt_max = NES_CM_DEFAULT_FREE_PKTS;
+
+       atomic_set(&cm_core->session_id, 0);
+       atomic_set(&cm_core->events_posted, 0);
+
+       /* init the packet lists */
+       skb_queue_head_init(&cm_core->tx_free_list);
+
+       for (i = 0; i < NES_CM_DEFAULT_FRAME_CNT; i++) {
+               skb = dev_alloc_skb(cm_core->mtu);
+               if (!skb) {
+                       kfree(cm_core);
+                       return NULL;
+               }
+               /* add 'raw' skb to free frame list */
+               skb_queue_head(&cm_core->tx_free_list, skb);
+       }
+
+       cm_core->api = &nes_cm_api;
+
+       spin_lock_init(&cm_core->ht_lock);
+       spin_lock_init(&cm_core->listen_list_lock);
+
+       INIT_LIST_HEAD(&cm_core->listen_list.list);
+
+       nes_debug(NES_DBG_CM, "Init CM Core completed -- cm_core=%p\n", cm_core);
+
+       nes_debug(NES_DBG_CM, "Enable QUEUE EVENTS\n");
+       cm_core->event_wq = create_singlethread_workqueue("nesewq");
+       cm_core->post_event = nes_cm_post_event;
+       nes_debug(NES_DBG_CM, "Enable QUEUE DISCONNECTS\n");
+       cm_core->disconn_wq = create_singlethread_workqueue("nesdwq");
+
+       print_core(cm_core);
+       return cm_core;
+}
+
+
+/**
+ * mini_cm_dealloc_core - deallocate a top level instance of a cm core
+ */
+int mini_cm_dealloc_core(struct nes_cm_core *cm_core)
+{
+       nes_debug(NES_DBG_CM, "De-Alloc CM Core (%p)\n", cm_core);
+
+       if (!cm_core)
+               return -EINVAL;
+
+       barrier();
+
+       if (timer_pending(&cm_core->tcp_timer)) {
+               del_timer(&cm_core->tcp_timer);
+       }
+
+       destroy_workqueue(cm_core->event_wq);
+       destroy_workqueue(cm_core->disconn_wq);
+       nes_debug(NES_DBG_CM, "\n");
+       kfree(cm_core);
+
+       return 0;
+}
+
+
+/**
+ * mini_cm_get
+ */
+int mini_cm_get(struct nes_cm_core *cm_core)
+{
+       return cm_core->state;
+}
+
+
+/**
+ * mini_cm_set
+ */
+int mini_cm_set(struct nes_cm_core *cm_core, u32 type, u32 value)
+{
+       int ret = 0;
+
+       switch (type) {
+               case NES_CM_SET_PKT_SIZE:
+                       cm_core->mtu = value;
+                       break;
+               case NES_CM_SET_FREE_PKT_Q_SIZE:
+                       cm_core->free_tx_pkt_max = value;
+                       break;
+               default:
+                       /* unknown set option */
+                       ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+
+/**
+ * nes_cm_init_tsa_conn setup HW; MPA frames must be
+ * successfully exchanged when this is called
+ */
+static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_node)
+{
+       int ret = 0;
+
+       if (!nesqp)
+               return -EINVAL;
+
+       nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4 |
+                       NES_QPCONTEXT_MISC_NO_NAGLE | NES_QPCONTEXT_MISC_DO_NOT_FRAG |
+                       NES_QPCONTEXT_MISC_DROS);
+
+       if (cm_node->tcp_cntxt.snd_wscale || cm_node->tcp_cntxt.rcv_wscale)
+               nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE);
+
+       nesqp->nesqp_context->misc2 |= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT);
+
+       nesqp->nesqp_context->mss |= cpu_to_le32(((u32)cm_node->tcp_cntxt.mss) << 16);
+
+       nesqp->nesqp_context->tcp_state_flow_label |= cpu_to_le32(
+                       (u32)NES_QPCONTEXT_TCPSTATE_EST << NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT);
+
+       nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
+                       (cm_node->tcp_cntxt.snd_wscale << NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT) &
+                       NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK);
+
+       nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
+                       (cm_node->tcp_cntxt.rcv_wscale << NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT) &
+                       NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK);
+
+       nesqp->nesqp_context->keepalive = cpu_to_le32(0x80);
+       nesqp->nesqp_context->ts_recent = 0;
+       nesqp->nesqp_context->ts_age = 0;
+       nesqp->nesqp_context->snd_nxt = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
+       nesqp->nesqp_context->snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.snd_wnd);
+       nesqp->nesqp_context->rcv_nxt = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
+       nesqp->nesqp_context->rcv_wnd = cpu_to_le32(cm_node->tcp_cntxt.rcv_wnd <<
+                       cm_node->tcp_cntxt.rcv_wscale);
+       nesqp->nesqp_context->snd_max = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
+       nesqp->nesqp_context->snd_una = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
+       nesqp->nesqp_context->srtt = 0;
+       nesqp->nesqp_context->rttvar = cpu_to_le32(0x6);
+       nesqp->nesqp_context->ssthresh = cpu_to_le32(0x3FFFC000);
+       nesqp->nesqp_context->cwnd = cpu_to_le32(2*cm_node->tcp_cntxt.mss);
+       nesqp->nesqp_context->snd_wl1 = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
+       nesqp->nesqp_context->snd_wl2 = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
+       nesqp->nesqp_context->max_snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.max_snd_wnd);
+
+       nes_debug(NES_DBG_CM, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
+                       " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
+                       nesqp->hwqp.qp_id, le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
+                       le32_to_cpu(nesqp->nesqp_context->snd_nxt),
+                       cm_node->tcp_cntxt.mss, le32_to_cpu(nesqp->nesqp_context->pd_index_wscale),
+                       le32_to_cpu(nesqp->nesqp_context->rcv_wnd),
+                       le32_to_cpu(nesqp->nesqp_context->misc));
+       nes_debug(NES_DBG_CM, "  snd_wnd  = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->snd_wnd));
+       nes_debug(NES_DBG_CM, "  snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->cwnd));
+       nes_debug(NES_DBG_CM, "  max_swnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->max_snd_wnd));
+
+       nes_debug(NES_DBG_CM, "Change cm_node state to TSA\n");
+       cm_node->state = NES_CM_STATE_TSA;
+
+       return ret;
+}
+
+
+/**
+ * nes_cm_disconn
+ */
+int nes_cm_disconn(struct nes_qp *nesqp)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&nesqp->lock, flags);
+       if (nesqp->disconn_pending == 0) {
+               nesqp->disconn_pending++;
+               spin_unlock_irqrestore(&nesqp->lock, flags);
+               /* nes_add_ref(&nesqp->ibqp); */
+               /* init our disconnect work element, to */
+               INIT_WORK(&nesqp->disconn_work, nes_disconnect_worker);
+
+               queue_work(g_cm_core->disconn_wq, &nesqp->disconn_work);
+       } else {
+               spin_unlock_irqrestore(&nesqp->lock, flags);
+               nes_rem_ref(&nesqp->ibqp);
+       }
+
+       return 0;
+}
+
+
+/**
+ * nes_disconnect_worker
+ */
+void nes_disconnect_worker(struct work_struct *work)
+{
+       struct nes_qp *nesqp = container_of(work, struct nes_qp, disconn_work);
+
+       nes_debug(NES_DBG_CM, "processing AEQE id 0x%04X for QP%u.\n",
+                       nesqp->last_aeq, nesqp->hwqp.qp_id);
+       nes_cm_disconn_true(nesqp);
+}
+
+
+/**
+ * nes_cm_disconn_true
+ */
+int nes_cm_disconn_true(struct nes_qp *nesqp)
+{
+       unsigned long flags;
+       int ret = 0;
+       struct iw_cm_id *cm_id;
+       struct iw_cm_event cm_event;
+       struct nes_vnic *nesvnic;
+       u16 last_ae;
+       u8 original_hw_tcp_state;
+       u8 original_ibqp_state;
+       u8 issued_disconnect_reset = 0;
+
+       if (!nesqp) {
+               nes_debug(NES_DBG_CM, "disconnect_worker nesqp is NULL\n");
+               return -1;
+       }
+
+       spin_lock_irqsave(&nesqp->lock, flags);
+       cm_id = nesqp->cm_id;
+       /* make sure we havent already closed this connection */
+       if (!cm_id) {
+               nes_debug(NES_DBG_CM, "QP%u disconnect_worker cmid is NULL\n",
+                               nesqp->hwqp.qp_id);
+               spin_unlock_irqrestore(&nesqp->lock, flags);
+               nes_rem_ref(&nesqp->ibqp);
+               return -1;
+       }
+
+       nesvnic = to_nesvnic(nesqp->ibqp.device);
+       nes_debug(NES_DBG_CM, "Disconnecting QP%u\n", nesqp->hwqp.qp_id);
+
+       original_hw_tcp_state = nesqp->hw_tcp_state;
+       original_ibqp_state   = nesqp->ibqp_state;
+       last_ae = nesqp->last_aeq;
+
+
+       nes_debug(NES_DBG_CM, "set ibqp_state=%u\n", nesqp->ibqp_state);
+
+       if ((nesqp->cm_id) && (cm_id->event_handler)) {
+               if ((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
+                               ((original_ibqp_state == IB_QPS_RTS) &&
+                               (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
+                       atomic_inc(&cm_disconnects);
+                       cm_event.event = IW_CM_EVENT_DISCONNECT;
+                       if (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET) {
+                               issued_disconnect_reset = 1;
+                               cm_event.status = IW_CM_EVENT_STATUS_RESET;
+                               nes_debug(NES_DBG_CM, "Generating a CM Disconnect Event (status reset) for "
+                                               " QP%u, cm_id = %p. \n",
+                                               nesqp->hwqp.qp_id, cm_id);
+                       } else {
+                               cm_event.status = IW_CM_EVENT_STATUS_OK;
+                       }
+
+                       cm_event.local_addr = cm_id->local_addr;
+                       cm_event.remote_addr = cm_id->remote_addr;
+                       cm_event.private_data = NULL;
+                       cm_event.private_data_len = 0;
+
+                       nes_debug(NES_DBG_CM, "Generating a CM Disconnect Event for "
+                                       " QP%u, SQ Head = %u, SQ Tail = %u. cm_id = %p, refcount = %u.\n",
+                                       nesqp->hwqp.qp_id,
+                                       nesqp->hwqp.sq_head, nesqp->hwqp.sq_tail, cm_id,
+                                       atomic_read(&nesqp->refcount));
+
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       ret = cm_id->event_handler(cm_id, &cm_event);
+                       if (ret)
+                               nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
+                       spin_lock_irqsave(&nesqp->lock, flags);
+               }
+
+               nesqp->disconn_pending = 0;
+               /* There might have been another AE while the lock was released */
+               original_hw_tcp_state = nesqp->hw_tcp_state;
+               original_ibqp_state   = nesqp->ibqp_state;
+               last_ae = nesqp->last_aeq;
+
+               if ((issued_disconnect_reset == 0) && (nesqp->cm_id) &&
+                               ((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
+                                (original_hw_tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT) ||
+                                (last_ae == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) ||
+                                (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
+                       atomic_inc(&cm_closes);
+                       nesqp->cm_id = NULL;
+                       nesqp->in_disconnect = 0;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_disconnect(nesqp, 1);
+
+                       cm_id->provider_data = nesqp;
+                       /* Send up the close complete event */
+                       cm_event.event = IW_CM_EVENT_CLOSE;
+                       cm_event.status = IW_CM_EVENT_STATUS_OK;
+                       cm_event.provider_data = cm_id->provider_data;
+                       cm_event.local_addr = cm_id->local_addr;
+                       cm_event.remote_addr = cm_id->remote_addr;
+                       cm_event.private_data = NULL;
+                       cm_event.private_data_len = 0;
+
+                       ret = cm_id->event_handler(cm_id, &cm_event);
+                       if (ret) {
+                               nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
+                       }
+
+                       cm_id->rem_ref(cm_id);
+
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       if (nesqp->flush_issued == 0) {
+                               nesqp->flush_issued = 1;
+                               spin_unlock_irqrestore(&nesqp->lock, flags);
+                               flush_wqes(nesvnic->nesdev, nesqp, NES_CQP_FLUSH_RQ, 1);
+                       } else {
+                               spin_unlock_irqrestore(&nesqp->lock, flags);
+                       }
+
+                       /* This reference is from either ModifyQP or the AE processing,
+                                       there is still a race here with modifyqp */
+                       nes_rem_ref(&nesqp->ibqp);
+
+               } else {
+                       cm_id = nesqp->cm_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       /* check to see if the inbound reset beat the outbound reset */
+                       if ((!cm_id) && (last_ae==NES_AEQE_AEID_RESET_SENT)) {
+                               nes_debug(NES_DBG_CM, "QP%u: Decing refcount due to inbound reset"
+                                               " beating the outbound reset.\n",
+                                               nesqp->hwqp.qp_id);
+                               nes_rem_ref(&nesqp->ibqp);
+                       }
+               }
+       } else {
+               nesqp->disconn_pending = 0;
+               spin_unlock_irqrestore(&nesqp->lock, flags);
+       }
+       nes_rem_ref(&nesqp->ibqp);
+
+       return 0;
+}
+
+
+/**
+ * nes_disconnect
+ */
+int nes_disconnect(struct nes_qp *nesqp, int abrupt)
+{
+       int ret = 0;
+       struct nes_vnic *nesvnic;
+       struct nes_device *nesdev;
+
+       nesvnic = to_nesvnic(nesqp->ibqp.device);
+       if (!nesvnic)
+               return -EINVAL;
+
+       nesdev = nesvnic->nesdev;
+
+       nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
+                       atomic_read(&nesvnic->netdev->refcnt));
+
+       if (nesqp->active_conn) {
+
+               /* indicate this connection is NOT active */
+               nesqp->active_conn = 0;
+       } else {
+               /* Need to free the Last Streaming Mode Message */
+               if (nesqp->ietf_frame) {
+                       pci_free_consistent(nesdev->pcidev,
+                                       nesqp->private_data_len+sizeof(struct ietf_mpa_frame),
+                                       nesqp->ietf_frame, nesqp->ietf_frame_pbase);
+               }
+       }
+
+       /* close the CM node down if it is still active */
+       if (nesqp->cm_node) {
+               nes_debug(NES_DBG_CM, "Call close API\n");
+
+               g_cm_core->api->close(g_cm_core, nesqp->cm_node);
+               nesqp->cm_node = NULL;
+       }
+
+       return ret;
+}
+
+
+/**
+ * nes_accept
+ */
+int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
+{
+       u64 u64temp;
+       struct ib_qp *ibqp;
+       struct nes_qp *nesqp;
+       struct nes_vnic *nesvnic;
+       struct nes_device *nesdev;
+       struct nes_cm_node *cm_node;
+       struct nes_adapter *adapter;
+       struct ib_qp_attr attr;
+       struct iw_cm_event cm_event;
+       struct nes_hw_qp_wqe *wqe;
+       struct nes_v4_quad nes_quad;
+       int ret;
+
+       ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
+       if (!ibqp)
+               return -EINVAL;
+
+       /* get all our handles */
+       nesqp = to_nesqp(ibqp);
+       nesvnic = to_nesvnic(nesqp->ibqp.device);
+       nesdev = nesvnic->nesdev;
+       adapter = nesdev->nesadapter;
+
+       nes_debug(NES_DBG_CM, "nesvnic=%p, netdev=%p, %s\n",
+                       nesvnic, nesvnic->netdev, nesvnic->netdev->name);
+
+       /* since this is from a listen, we were able to put node handle into cm_id */
+       cm_node = (struct nes_cm_node *)cm_id->provider_data;
+
+       /* associate the node with the QP */
+       nesqp->cm_node = (void *)cm_node;
+
+       nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu\n",
+                       nesqp->hwqp.qp_id, cm_node, jiffies);
+       atomic_inc(&cm_accepts);
+
+       nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
+                       atomic_read(&nesvnic->netdev->refcnt));
+
+               /* allocate the ietf frame and space for private data */
+               nesqp->ietf_frame = pci_alloc_consistent(nesdev->pcidev,
+                               sizeof(struct ietf_mpa_frame) + conn_param->private_data_len,
+                               &nesqp->ietf_frame_pbase);
+
+               if (!nesqp->ietf_frame) {
+                       nes_debug(NES_DBG_CM, "Unable to allocate memory for private data\n");
+                       return -ENOMEM;
+               }
+
+
+               /* setup the MPA frame */
+               nesqp->private_data_len = conn_param->private_data_len;
+               memcpy(nesqp->ietf_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
+
+               memcpy(nesqp->ietf_frame->priv_data, conn_param->private_data,
+                               conn_param->private_data_len);
+
+               nesqp->ietf_frame->priv_data_len = cpu_to_be16(conn_param->private_data_len);
+               nesqp->ietf_frame->rev = mpa_version;
+               nesqp->ietf_frame->flags = IETF_MPA_FLAGS_CRC;
+
+               /* setup our first outgoing iWarp send WQE (the IETF frame response) */
+               wqe = &nesqp->hwqp.sq_vbase[0];
+
+               if (cm_id->remote_addr.sin_addr.s_addr != cm_id->local_addr.sin_addr.s_addr) {
+                       u64temp = (unsigned long)nesqp;
+                       u64temp |= NES_SW_CONTEXT_ALIGN>>1;
+                       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX,
+                                           u64temp);
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
+                                       cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING | NES_IWARP_SQ_WQE_WRPDU);
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] =
+                                       cpu_to_le32(conn_param->private_data_len + sizeof(struct ietf_mpa_frame));
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] =
+                                       cpu_to_le32((u32)nesqp->ietf_frame_pbase);
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] =
+                                       cpu_to_le32((u32)((u64)nesqp->ietf_frame_pbase >> 32));
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] =
+                                       cpu_to_le32(conn_param->private_data_len + sizeof(struct ietf_mpa_frame));
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
+
+                       nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32(
+                                       NES_QPCONTEXT_ORDIRD_LSMM_PRESENT | NES_QPCONTEXT_ORDIRD_WRPDU);
+               } else {
+                       nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32((NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
+                                       NES_QPCONTEXT_ORDIRD_WRPDU | NES_QPCONTEXT_ORDIRD_ALSMM));
+               }
+               nesqp->skip_lsmm = 1;
+
+
+       /* Cache the cm_id in the qp */
+       nesqp->cm_id = cm_id;
+       cm_node->cm_id = cm_id;
+
+       /*  nesqp->cm_node = (void *)cm_id->provider_data; */
+       cm_id->provider_data = nesqp;
+       nesqp->active_conn   = 0;
+
+       nes_cm_init_tsa_conn(nesqp, cm_node);
+
+       nesqp->nesqp_context->tcpPorts[0] = cpu_to_le16(ntohs(cm_id->local_addr.sin_port));
+       nesqp->nesqp_context->tcpPorts[1] = cpu_to_le16(ntohs(cm_id->remote_addr.sin_port));
+       nesqp->nesqp_context->ip0 = cpu_to_le32(ntohl(cm_id->remote_addr.sin_addr.s_addr));
+
+       nesqp->nesqp_context->misc2 |= cpu_to_le32(
+                       (u32)PCI_FUNC(nesdev->pcidev->devfn) << NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
+
+       nesqp->nesqp_context->arp_index_vlan |= cpu_to_le32(
+                       nes_arp_table(nesdev, le32_to_cpu(nesqp->nesqp_context->ip0), NULL,
+                       NES_ARP_RESOLVE) << 16);
+
+       nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
+                       jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
+
+       nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
+
+       nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32(
+                       ((u32)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT));
+       nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32((u32)conn_param->ord);
+
+       memset(&nes_quad, 0, sizeof(nes_quad));
+       nes_quad.DstIpAdrIndex = cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
+       nes_quad.SrcIpadr      = cm_id->remote_addr.sin_addr.s_addr;
+       nes_quad.TcpPorts[0]   = cm_id->remote_addr.sin_port;
+       nes_quad.TcpPorts[1]   = cm_id->local_addr.sin_port;
+
+       /* Produce hash key */
+       nesqp->hte_index = cpu_to_be32(
+                       crc32c(~0, (void *)&nes_quad, sizeof(nes_quad)) ^ 0xffffffff);
+       nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, CRC = 0x%08X\n",
+                       nesqp->hte_index, nesqp->hte_index & adapter->hte_index_mask);
+
+       nesqp->hte_index &= adapter->hte_index_mask;
+       nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
+
+       cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
+
+       nes_debug(NES_DBG_CM, "QP%u, Destination IP = 0x%08X:0x%04X, local = 0x%08X:0x%04X,"
+                       " rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + private data length=%zu.\n",
+                       nesqp->hwqp.qp_id,
+                       ntohl(cm_id->remote_addr.sin_addr.s_addr),
+                       ntohs(cm_id->remote_addr.sin_port),
+                       ntohl(cm_id->local_addr.sin_addr.s_addr),
+                       ntohs(cm_id->local_addr.sin_port),
+                       le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
+                       le32_to_cpu(nesqp->nesqp_context->snd_nxt),
+                       conn_param->private_data_len+sizeof(struct ietf_mpa_frame));
+
+       attr.qp_state = IB_QPS_RTS;
+       nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
+
+       /* notify OF layer that accept event was successfull */
+       cm_id->add_ref(cm_id);
+
+       cm_event.event = IW_CM_EVENT_ESTABLISHED;
+       cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED;
+       cm_event.provider_data = (void *)nesqp;
+       cm_event.local_addr = cm_id->local_addr;
+       cm_event.remote_addr = cm_id->remote_addr;
+       cm_event.private_data = NULL;
+       cm_event.private_data_len = 0;
+       ret = cm_id->event_handler(cm_id, &cm_event);
+       if (cm_node->loopbackpartner) {
+               cm_node->loopbackpartner->mpa_frame_size = nesqp->private_data_len;
+               /* copy entire MPA frame to our cm_node's frame */
+               memcpy(cm_node->loopbackpartner->mpa_frame_buf, nesqp->ietf_frame->priv_data,
+                          nesqp->private_data_len);
+               create_event(cm_node->loopbackpartner, NES_CM_EVENT_CONNECTED);
+       }
+       if (ret)
+               printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
+                               __FUNCTION__, __LINE__, ret);
+
+       return 0;
+}
+
+
+/**
+ * nes_reject
+ */
+int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
+{
+       struct nes_cm_node *cm_node;
+       struct nes_cm_core *cm_core;
+
+       atomic_inc(&cm_rejects);
+       cm_node = (struct nes_cm_node *) cm_id->provider_data;
+       cm_core = cm_node->cm_core;
+       cm_node->mpa_frame_size = sizeof(struct ietf_mpa_frame) + pdata_len;
+
+       strcpy(&cm_node->mpa_frame.key[0], IEFT_MPA_KEY_REP);
+       memcpy(&cm_node->mpa_frame.priv_data, pdata, pdata_len);
+
+       cm_node->mpa_frame.priv_data_len = cpu_to_be16(pdata_len);
+       cm_node->mpa_frame.rev = mpa_version;
+       cm_node->mpa_frame.flags = IETF_MPA_FLAGS_CRC | IETF_MPA_FLAGS_REJECT;
+
+       cm_core->api->reject(cm_core, &cm_node->mpa_frame, cm_node);
+
+       return 0;
+}
+
+
+/**
+ * nes_connect
+ * setup and launch cm connect node
+ */
+int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
+{
+       struct ib_qp *ibqp;
+       struct nes_qp *nesqp;
+       struct nes_vnic *nesvnic;
+       struct nes_device *nesdev;
+       struct nes_cm_node *cm_node;
+       struct nes_cm_info cm_info;
+
+       ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
+       if (!ibqp)
+               return -EINVAL;
+       nesqp = to_nesqp(ibqp);
+       if (!nesqp)
+               return -EINVAL;
+       nesvnic = to_nesvnic(nesqp->ibqp.device);
+       if (!nesvnic)
+               return -EINVAL;
+       nesdev  = nesvnic->nesdev;
+       if (!nesdev)
+               return -EINVAL;
+
+       atomic_inc(&cm_connects);
+
+       nesqp->ietf_frame = kzalloc(sizeof(struct ietf_mpa_frame) +
+                       conn_param->private_data_len, GFP_KERNEL);
+       if (!nesqp->ietf_frame)
+               return -ENOMEM;
+
+       /* set qp as having an active connection */
+       nesqp->active_conn = 1;
+
+       nes_debug(NES_DBG_CM, "QP%u, Destination IP = 0x%08X:0x%04X, local = 0x%08X:0x%04X.\n",
+                       nesqp->hwqp.qp_id,
+                       ntohl(cm_id->remote_addr.sin_addr.s_addr),
+                       ntohs(cm_id->remote_addr.sin_port),
+                       ntohl(cm_id->local_addr.sin_addr.s_addr),
+                       ntohs(cm_id->local_addr.sin_port));
+
+       /* cache the cm_id in the qp */
+       nesqp->cm_id = cm_id;
+
+       cm_id->provider_data = nesqp;
+
+       /* copy the private data */
+       if (conn_param->private_data_len) {
+               memcpy(nesqp->ietf_frame->priv_data, conn_param->private_data,
+                               conn_param->private_data_len);
+       }
+
+       nesqp->private_data_len = conn_param->private_data_len;
+       nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32((u32)conn_param->ord);
+       nes_debug(NES_DBG_CM, "requested ord = 0x%08X.\n", (u32)conn_param->ord);
+       nes_debug(NES_DBG_CM, "mpa private data len =%u\n", conn_param->private_data_len);
+
+       strcpy(&nesqp->ietf_frame->key[0], IEFT_MPA_KEY_REQ);
+       nesqp->ietf_frame->flags = IETF_MPA_FLAGS_CRC;
+       nesqp->ietf_frame->rev = IETF_MPA_VERSION;
+       nesqp->ietf_frame->priv_data_len = htons(conn_param->private_data_len);
+
+       if (cm_id->local_addr.sin_addr.s_addr != cm_id->remote_addr.sin_addr.s_addr)
+               nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
+                               PCI_FUNC(nesdev->pcidev->devfn), NES_MANAGE_APBVT_ADD);
+
+       /* set up the connection params for the node */
+       cm_info.loc_addr = (cm_id->local_addr.sin_addr.s_addr);
+       cm_info.loc_port = (cm_id->local_addr.sin_port);
+       cm_info.rem_addr = (cm_id->remote_addr.sin_addr.s_addr);
+       cm_info.rem_port = (cm_id->remote_addr.sin_port);
+       cm_info.cm_id = cm_id;
+       cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
+
+       cm_id->add_ref(cm_id);
+       nes_add_ref(&nesqp->ibqp);
+
+       /* create a connect CM node connection */
+       cm_node = g_cm_core->api->connect(g_cm_core, nesvnic, nesqp->ietf_frame, &cm_info);
+       if (!cm_node) {
+               if (cm_id->local_addr.sin_addr.s_addr != cm_id->remote_addr.sin_addr.s_addr)
+                       nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
+                                       PCI_FUNC(nesdev->pcidev->devfn), NES_MANAGE_APBVT_DEL);
+               nes_rem_ref(&nesqp->ibqp);
+               kfree(nesqp->ietf_frame);
+               nesqp->ietf_frame = NULL;
+               cm_id->rem_ref(cm_id);
+               return -ENOMEM;
+       }
+
+       cm_node->apbvt_set = 1;
+       nesqp->cm_node = cm_node;
+
+       return 0;
+}
+
+
+/**
+ * nes_create_listen
+ */
+int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
+{
+       struct nes_vnic *nesvnic;
+       struct nes_cm_listener *cm_node;
+       struct nes_cm_info cm_info;
+       struct nes_adapter *adapter;
+       int err;
+
+
+       nes_debug(NES_DBG_CM, "cm_id = %p, local port = 0x%04X.\n",
+                       cm_id, ntohs(cm_id->local_addr.sin_port));
+
+       nesvnic = to_nesvnic(cm_id->device);
+       if (!nesvnic)
+               return -EINVAL;
+       adapter = nesvnic->nesdev->nesadapter;
+       nes_debug(NES_DBG_CM, "nesvnic=%p, netdev=%p, %s\n",
+                       nesvnic, nesvnic->netdev, nesvnic->netdev->name);
+
+       nes_debug(NES_DBG_CM, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
+                       nesvnic->local_ipaddr, cm_id->local_addr.sin_addr.s_addr);
+
+       /* setup listen params in our api call struct */
+       cm_info.loc_addr = nesvnic->local_ipaddr;
+       cm_info.loc_port = cm_id->local_addr.sin_port;
+       cm_info.backlog = backlog;
+       cm_info.cm_id = cm_id;
+
+       cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
+
+
+       cm_node = g_cm_core->api->listen(g_cm_core, nesvnic, &cm_info);
+       if (!cm_node) {
+               printk("%s[%u] Error returned from listen API call\n",
+                               __FUNCTION__, __LINE__);
+               return -ENOMEM;
+       }
+
+       cm_id->provider_data = cm_node;
+
+       if (!cm_node->reused_node) {
+               err = nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
+                               PCI_FUNC(nesvnic->nesdev->pcidev->devfn), NES_MANAGE_APBVT_ADD);
+               if (err) {
+                       printk("nes_manage_apbvt call returned %d.\n", err);
+                       g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
+                       return err;
+               }
+               cm_listens_created++;
+       }
+
+       cm_id->add_ref(cm_id);
+       cm_id->provider_data = (void *)cm_node;
+
+
+       return 0;
+}
+
+
+/**
+ * nes_destroy_listen
+ */
+int nes_destroy_listen(struct iw_cm_id *cm_id)
+{
+       if (cm_id->provider_data)
+               g_cm_core->api->stop_listener(g_cm_core, cm_id->provider_data);
+       else
+               nes_debug(NES_DBG_CM, "cm_id->provider_data was NULL\n");
+
+       cm_id->rem_ref(cm_id);
+
+       return 0;
+}
+
+
+/**
+ * nes_cm_recv
+ */
+int nes_cm_recv(struct sk_buff *skb, struct net_device *netdevice)
+{
+       cm_packets_received++;
+       if ((g_cm_core) && (g_cm_core->api)) {
+               g_cm_core->api->recv_pkt(g_cm_core, netdev_priv(netdevice), skb);
+       } else {
+               nes_debug(NES_DBG_CM, "Unable to process packet for CM,"
+                               " cm is not setup properly.\n");
+       }
+
+       return 0;
+}
+
+
+/**
+ * nes_cm_start
+ * Start and init a cm core module
+ */
+int nes_cm_start(void)
+{
+       nes_debug(NES_DBG_CM, "\n");
+       /* create the primary CM core, pass this handle to subsequent core inits */
+       g_cm_core = nes_cm_alloc_core();
+       if (g_cm_core) {
+               return 0;
+       } else {
+               return -ENOMEM;
+       }
+}
+
+
+/**
+ * nes_cm_stop
+ * stop and dealloc all cm core instances
+ */
+int nes_cm_stop(void)
+{
+       g_cm_core->api->destroy_cm_core(g_cm_core);
+       return 0;
+}
+
+
+/**
+ * cm_event_connected
+ * handle a connected event, setup QPs and HW
+ */
+void cm_event_connected(struct nes_cm_event *event)
+{
+       u64 u64temp;
+       struct nes_qp *nesqp;
+       struct nes_vnic *nesvnic;
+       struct nes_device *nesdev;
+       struct nes_cm_node *cm_node;
+       struct nes_adapter *nesadapter;
+       struct ib_qp_attr attr;
+       struct iw_cm_id *cm_id;
+       struct iw_cm_event cm_event;
+       struct nes_hw_qp_wqe *wqe;
+       struct nes_v4_quad nes_quad;
+       int ret;
+
+       /* get all our handles */
+       cm_node = event->cm_node;
+       cm_id = cm_node->cm_id;
+       nes_debug(NES_DBG_CM, "cm_event_connected - %p - cm_id = %p\n", cm_node, cm_id);
+       nesqp = (struct nes_qp *)cm_id->provider_data;
+       nesvnic = to_nesvnic(nesqp->ibqp.device);
+       nesdev = nesvnic->nesdev;
+       nesadapter = nesdev->nesadapter;
+
+       if (nesqp->destroyed) {
+               return;
+       }
+       atomic_inc(&cm_connecteds);
+       nes_debug(NES_DBG_CM, "QP%u attempting to connect to  0x%08X:0x%04X on"
+                       " local port 0x%04X. jiffies = %lu.\n",
+                       nesqp->hwqp.qp_id,
+                       ntohl(cm_id->remote_addr.sin_addr.s_addr),
+                       ntohs(cm_id->remote_addr.sin_port),
+                       ntohs(cm_id->local_addr.sin_port),
+                       jiffies);
+
+       nes_cm_init_tsa_conn(nesqp, cm_node);
+
+       /* set the QP tsa context */
+       nesqp->nesqp_context->tcpPorts[0] = cpu_to_le16(ntohs(cm_id->local_addr.sin_port));
+       nesqp->nesqp_context->tcpPorts[1] = cpu_to_le16(ntohs(cm_id->remote_addr.sin_port));
+       nesqp->nesqp_context->ip0 = cpu_to_le32(ntohl(cm_id->remote_addr.sin_addr.s_addr));
+
+       nesqp->nesqp_context->misc2 |= cpu_to_le32(
+                       (u32)PCI_FUNC(nesdev->pcidev->devfn) << NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
+       nesqp->nesqp_context->arp_index_vlan |= cpu_to_le32(
+                       nes_arp_table(nesdev, le32_to_cpu(nesqp->nesqp_context->ip0),
+                       NULL, NES_ARP_RESOLVE) << 16);
+       nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
+                       jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
+       nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
+       nesqp->nesqp_context->ird_ord_sizes |=
+                       cpu_to_le32((u32)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT);
+
+       /* Adjust tail for not having a LSMM */
+       nesqp->hwqp.sq_tail = 1;
+
+#if defined(NES_SEND_FIRST_WRITE)
+               if (cm_node->send_write0) {
+                       nes_debug(NES_DBG_CM, "Sending first write.\n");
+                       wqe = &nesqp->hwqp.sq_vbase[0];
+                       u64temp = (unsigned long)nesqp;
+                       u64temp |= NES_SW_CONTEXT_ALIGN>>1;
+                       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX,
+                                           u64temp);
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] = cpu_to_le32(NES_IWARP_SQ_OP_RDMAW);
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] = 0;
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] = 0;
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] = 0;
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] = 0;
+                       wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
+
+                       /* use the reserved spot on the WQ for the extra first WQE */
+                       nesqp->nesqp_context->ird_ord_sizes &= cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
+                                       NES_QPCONTEXT_ORDIRD_WRPDU | NES_QPCONTEXT_ORDIRD_ALSMM));
+                       nesqp->skip_lsmm = 1;
+                       nesqp->hwqp.sq_tail = 0;
+                       nes_write32(nesdev->regs + NES_WQE_ALLOC,
+                                       (1 << 24) | 0x00800000 | nesqp->hwqp.qp_id);
+               }
+#endif
+
+       memset(&nes_quad, 0, sizeof(nes_quad));
+
+       nes_quad.DstIpAdrIndex = cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
+       nes_quad.SrcIpadr = cm_id->remote_addr.sin_addr.s_addr;
+       nes_quad.TcpPorts[0] = cm_id->remote_addr.sin_port;
+       nes_quad.TcpPorts[1] = cm_id->local_addr.sin_port;
+
+       /* Produce hash key */
+       nesqp->hte_index = cpu_to_be32(
+                       crc32c(~0, (void *)&nes_quad, sizeof(nes_quad)) ^ 0xffffffff);
+       nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
+                       nesqp->hte_index, nesqp->hte_index & nesadapter->hte_index_mask);
+
+       nesqp->hte_index &= nesadapter->hte_index_mask;
+       nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
+
+       nesqp->ietf_frame = &cm_node->mpa_frame;
+       nesqp->private_data_len = (u8) cm_node->mpa_frame_size;
+       cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
+
+       /* modify QP state to rts */
+       attr.qp_state = IB_QPS_RTS;
+       nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
+
+       /* notify OF layer we successfully created the requested connection */
+       cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
+       cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED;
+       cm_event.provider_data = cm_id->provider_data;
+       cm_event.local_addr.sin_family = AF_INET;
+       cm_event.local_addr.sin_port = cm_id->local_addr.sin_port;
+       cm_event.remote_addr = cm_id->remote_addr;
+
+               cm_event.private_data = (void *)event->cm_node->mpa_frame_buf;
+               cm_event.private_data_len = (u8) event->cm_node->mpa_frame_size;
+
+       cm_event.local_addr.sin_addr.s_addr = event->cm_info.rem_addr;
+       ret = cm_id->event_handler(cm_id, &cm_event);
+       nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
+
+       if (ret)
+               printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
+                               __FUNCTION__, __LINE__, ret);
+       nes_debug(NES_DBG_CM, "Exiting connect thread for QP%u. jiffies = %lu\n",
+                       nesqp->hwqp.qp_id, jiffies );
+
+       nes_rem_ref(&nesqp->ibqp);
+
+       return;
+}
+
+
+/**
+ * cm_event_connect_error
+ */
+void cm_event_connect_error(struct nes_cm_event *event)
+{
+       struct nes_qp *nesqp;
+       struct iw_cm_id *cm_id;
+       struct iw_cm_event cm_event;
+       /* struct nes_cm_info cm_info; */
+       int ret;
+
+       if (!event->cm_node)
+               return;
+
+       cm_id = event->cm_node->cm_id;
+       if (!cm_id) {
+               return;
+       }
+
+       nes_debug(NES_DBG_CM, "cm_node=%p, cm_id=%p\n", event->cm_node, cm_id);
+       nesqp = cm_id->provider_data;
+
+       if (!nesqp) {
+               return;
+       }
+
+       /* notify OF layer about this connection error event */
+       /* cm_id->rem_ref(cm_id); */
+       nesqp->cm_id = NULL;
+       cm_id->provider_data = NULL;
+       cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
+       cm_event.status = IW_CM_EVENT_STATUS_REJECTED;
+       cm_event.provider_data = cm_id->provider_data;
+       cm_event.local_addr = cm_id->local_addr;
+       cm_event.remote_addr = cm_id->remote_addr;
+       cm_event.private_data = NULL;
+       cm_event.private_data_len = 0;
+
+       nes_debug(NES_DBG_CM, "call CM_EVENT REJECTED, local_addr=%08x, remove_addr=%08x\n",
+                       cm_event.local_addr.sin_addr.s_addr, cm_event.remote_addr.sin_addr.s_addr);
+
+       ret = cm_id->event_handler(cm_id, &cm_event);
+       nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
+       if (ret)
+               printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
+                               __FUNCTION__, __LINE__, ret);
+       nes_rem_ref(&nesqp->ibqp);
+               cm_id->rem_ref(cm_id);
+
+       return;
+}
+
+
+/**
+ * cm_event_reset
+ */
+void cm_event_reset(struct nes_cm_event *event)
+{
+       struct nes_qp *nesqp;
+       struct iw_cm_id *cm_id;
+       struct iw_cm_event cm_event;
+       /* struct nes_cm_info cm_info; */
+       int ret;
+
+       if (!event->cm_node)
+               return;
+
+       if (!event->cm_node->cm_id)
+               return;
+
+       cm_id = event->cm_node->cm_id;
+
+       nes_debug(NES_DBG_CM, "%p - cm_id = %p\n", event->cm_node, cm_id);
+       nesqp = cm_id->provider_data;
+
+       nesqp->cm_id = NULL;
+       /* cm_id->provider_data = NULL; */
+       cm_event.event = IW_CM_EVENT_DISCONNECT;
+       cm_event.status = IW_CM_EVENT_STATUS_RESET;
+       cm_event.provider_data = cm_id->provider_data;
+       cm_event.local_addr = cm_id->local_addr;
+       cm_event.remote_addr = cm_id->remote_addr;
+       cm_event.private_data = NULL;
+       cm_event.private_data_len = 0;
+
+       ret = cm_id->event_handler(cm_id, &cm_event);
+       nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
+
+
+       /* notify OF layer about this connection error event */
+       cm_id->rem_ref(cm_id);
+
+       return;
+}
+
+
+/**
+ * cm_event_mpa_req
+ */
+void cm_event_mpa_req(struct nes_cm_event *event)
+{
+       struct iw_cm_id   *cm_id;
+       struct iw_cm_event cm_event;
+       int ret;
+       struct nes_cm_node *cm_node;
+
+       cm_node = event->cm_node;
+       if (!cm_node)
+               return;
+       cm_id = cm_node->cm_id;
+
+       atomic_inc(&cm_connect_reqs);
+       nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
+                       cm_node, cm_id, jiffies);
+
+       cm_event.event = IW_CM_EVENT_CONNECT_REQUEST;
+       cm_event.status = IW_CM_EVENT_STATUS_OK;
+       cm_event.provider_data = (void *)cm_node;
+
+       cm_event.local_addr.sin_family = AF_INET;
+       cm_event.local_addr.sin_port = htons(event->cm_info.loc_port);
+       cm_event.local_addr.sin_addr.s_addr = htonl(event->cm_info.loc_addr);
+
+       cm_event.remote_addr.sin_family = AF_INET;
+       cm_event.remote_addr.sin_port = htons(event->cm_info.rem_port);
+       cm_event.remote_addr.sin_addr.s_addr = htonl(event->cm_info.rem_addr);
+
+               cm_event.private_data                = cm_node->mpa_frame_buf;
+               cm_event.private_data_len            = (u8) cm_node->mpa_frame_size;
+
+       ret = cm_id->event_handler(cm_id, &cm_event);
+       if (ret)
+               printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
+                               __FUNCTION__, __LINE__, ret);
+
+       return;
+}
+
+
+static void nes_cm_event_handler(struct work_struct *);
+
+/**
+ * nes_cm_post_event
+ * post an event to the cm event handler
+ */
+int nes_cm_post_event(struct nes_cm_event *event)
+{
+       atomic_inc(&event->cm_node->cm_core->events_posted);
+       add_ref_cm_node(event->cm_node);
+       event->cm_info.cm_id->add_ref(event->cm_info.cm_id);
+       INIT_WORK(&event->event_work, nes_cm_event_handler);
+       nes_debug(NES_DBG_CM, "queue_work, event=%p\n", event);
+
+       queue_work(event->cm_node->cm_core->event_wq, &event->event_work);
+
+       nes_debug(NES_DBG_CM, "Exit\n");
+       return 0;
+}
+
+
+/**
+ * nes_cm_event_handler
+ * worker function to handle cm events
+ * will free instance of nes_cm_event
+ */
+static void nes_cm_event_handler(struct work_struct *work)
+{
+       struct nes_cm_event *event = container_of(work, struct nes_cm_event, event_work);
+       struct nes_cm_core *cm_core;
+
+       if ((!event) || (!event->cm_node) || (!event->cm_node->cm_core)) {
+               return;
+       }
+       cm_core = event->cm_node->cm_core;
+       nes_debug(NES_DBG_CM, "event=%p, event->type=%u, events posted=%u\n",
+                       event, event->type, atomic_read(&cm_core->events_posted));
+
+       switch (event->type) {
+               case NES_CM_EVENT_MPA_REQ:
+                       cm_event_mpa_req(event);
+                       nes_debug(NES_DBG_CM, "CM Event: MPA REQUEST\n");
+                       break;
+               case NES_CM_EVENT_RESET:
+                       nes_debug(NES_DBG_CM, "CM Event: RESET\n");
+                       cm_event_reset(event);
+                       break;
+               case NES_CM_EVENT_CONNECTED:
+                       if ((!event->cm_node->cm_id) ||
+                               (event->cm_node->state != NES_CM_STATE_TSA)) {
+                               break;
+                       }
+                       cm_event_connected(event);
+                       nes_debug(NES_DBG_CM, "CM Event: CONNECTED\n");
+                       break;
+               case NES_CM_EVENT_ABORTED:
+                       if ((!event->cm_node->cm_id) || (event->cm_node->state == NES_CM_STATE_TSA)) {
+                               break;
+                       }
+                       cm_event_connect_error(event);
+                       nes_debug(NES_DBG_CM, "CM Event: ABORTED\n");
+                       break;
+               case NES_CM_EVENT_DROPPED_PKT:
+                       nes_debug(NES_DBG_CM, "CM Event: DROPPED PKT\n");
+                       break;
+               default:
+                       nes_debug(NES_DBG_CM, "CM Event: UNKNOWN EVENT TYPE\n");
+                       break;
+       }
+
+       atomic_dec(&cm_core->events_posted);
+       event->cm_info.cm_id->rem_ref(event->cm_info.cm_id);
+       rem_ref_cm_node(cm_core, event->cm_node);
+       kfree(event);
+
+       return;
+}
diff --git a/drivers/infiniband/hw/nes/nes_cm.h b/drivers/infiniband/hw/nes/nes_cm.h
new file mode 100644 (file)
index 0000000..a59f0a7
--- /dev/null
@@ -0,0 +1,433 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef NES_CM_H
+#define NES_CM_H
+
+#define QUEUE_EVENTS
+
+#define NES_MANAGE_APBVT_DEL 0
+#define NES_MANAGE_APBVT_ADD 1
+
+/* IETF MPA -- defines, enums, structs */
+#define IEFT_MPA_KEY_REQ  "MPA ID Req Frame"
+#define IEFT_MPA_KEY_REP  "MPA ID Rep Frame"
+#define IETF_MPA_KEY_SIZE 16
+#define IETF_MPA_VERSION  1
+
+enum ietf_mpa_flags {
+       IETF_MPA_FLAGS_MARKERS = 0x80,  /* receive Markers */
+       IETF_MPA_FLAGS_CRC     = 0x40,  /* receive Markers */
+       IETF_MPA_FLAGS_REJECT  = 0x20,  /* Reject */
+};
+
+struct ietf_mpa_frame {
+       u8 key[IETF_MPA_KEY_SIZE];
+       u8 flags;
+       u8 rev;
+       __be16 priv_data_len;
+       u8 priv_data[0];
+};
+
+#define ietf_mpa_req_resp_frame ietf_mpa_frame
+
+struct nes_v4_quad {
+       u32 rsvd0;
+       __le32 DstIpAdrIndex;   /* Only most significant 5 bits are valid */
+       __be32 SrcIpadr;
+       __be16 TcpPorts[2];             /* src is low, dest is high */
+};
+
+struct nes_cm_node;
+enum nes_timer_type {
+       NES_TIMER_TYPE_SEND,
+       NES_TIMER_TYPE_RECV,
+       NES_TIMER_NODE_CLEANUP,
+       NES_TIMER_TYPE_CLOSE,
+};
+
+#define MAX_NES_IFS 4
+
+#define SET_ACK 1
+#define SET_SYN 2
+#define SET_FIN 4
+#define SET_RST 8
+
+struct option_base {
+       u8 optionnum;
+       u8 length;
+};
+
+enum option_numbers {
+       OPTION_NUMBER_END,
+       OPTION_NUMBER_NONE,
+       OPTION_NUMBER_MSS,
+       OPTION_NUMBER_WINDOW_SCALE,
+       OPTION_NUMBER_SACK_PERM,
+       OPTION_NUMBER_SACK,
+       OPTION_NUMBER_WRITE0 = 0xbc
+};
+
+struct option_mss {
+       u8 optionnum;
+       u8 length;
+       __be16 mss;
+};
+
+struct option_windowscale {
+       u8 optionnum;
+       u8 length;
+       u8 shiftcount;
+};
+
+union all_known_options {
+       char as_end;
+       struct option_base as_base;
+       struct option_mss as_mss;
+       struct option_windowscale as_windowscale;
+};
+
+struct nes_timer_entry {
+       struct list_head list;
+       unsigned long timetosend;       /* jiffies */
+       struct sk_buff *skb;
+       u32 type;
+       u32 retrycount;
+       u32 retranscount;
+       u32 context;
+       u32 seq_num;
+       u32 send_retrans;
+       int close_when_complete;
+       struct net_device *netdev;
+};
+
+#define NES_DEFAULT_RETRYS  64
+#define NES_DEFAULT_RETRANS 8
+#ifdef CONFIG_INFINIBAND_NES_DEBUG
+#define NES_RETRY_TIMEOUT   (1000*HZ/1000)
+#else
+#define NES_RETRY_TIMEOUT   (3000*HZ/1000)
+#endif
+#define NES_SHORT_TIME      (10)
+#define NES_LONG_TIME       (2000*HZ/1000)
+
+#define NES_CM_HASHTABLE_SIZE         1024
+#define NES_CM_TCP_TIMER_INTERVAL     3000
+#define NES_CM_DEFAULT_MTU            1540
+#define NES_CM_DEFAULT_FRAME_CNT      10
+#define NES_CM_THREAD_STACK_SIZE      256
+#define NES_CM_DEFAULT_RCV_WND        64240    // before we know that window scaling is allowed
+#define NES_CM_DEFAULT_RCV_WND_SCALED 256960  // after we know that window scaling is allowed
+#define NES_CM_DEFAULT_RCV_WND_SCALE  2
+#define NES_CM_DEFAULT_FREE_PKTS      0x000A
+#define NES_CM_FREE_PKT_LO_WATERMARK  2
+
+#define NES_CM_DEFAULT_MSS   536
+
+#define NES_CM_DEF_SEQ       0x159bf75f
+#define NES_CM_DEF_LOCAL_ID  0x3b47
+
+#define NES_CM_DEF_SEQ2      0x18ed5740
+#define NES_CM_DEF_LOCAL_ID2 0xb807
+
+typedef u32 nes_addr_t;
+
+#define nes_cm_tsa_context nes_qp_context
+
+struct nes_qp;
+
+/* cm node transition states */
+enum nes_cm_node_state {
+       NES_CM_STATE_UNKNOWN,
+       NES_CM_STATE_INITED,
+       NES_CM_STATE_LISTENING,
+       NES_CM_STATE_SYN_RCVD,
+       NES_CM_STATE_SYN_SENT,
+       NES_CM_STATE_ONE_SIDE_ESTABLISHED,
+       NES_CM_STATE_ESTABLISHED,
+       NES_CM_STATE_ACCEPTING,
+       NES_CM_STATE_MPAREQ_SENT,
+       NES_CM_STATE_TSA,
+       NES_CM_STATE_FIN_WAIT1,
+       NES_CM_STATE_FIN_WAIT2,
+       NES_CM_STATE_CLOSE_WAIT,
+       NES_CM_STATE_TIME_WAIT,
+       NES_CM_STATE_LAST_ACK,
+       NES_CM_STATE_CLOSING,
+       NES_CM_STATE_CLOSED
+};
+
+/* type of nes connection */
+enum nes_cm_conn_type {
+       NES_CM_IWARP_CONN_TYPE,
+};
+
+/* CM context params */
+struct nes_cm_tcp_context {
+       u8  client;
+
+       u32 loc_seq_num;
+       u32 loc_ack_num;
+       u32 rem_ack_num;
+       u32 rcv_nxt;
+
+       u32 loc_id;
+       u32 rem_id;
+
+       u32 snd_wnd;
+       u32 max_snd_wnd;
+
+       u32 rcv_wnd;
+       u32 mss;
+       u8  snd_wscale;
+       u8  rcv_wscale;
+
+       struct nes_cm_tsa_context tsa_cntxt;
+       struct timeval            sent_ts;
+};
+
+
+enum nes_cm_listener_state {
+       NES_CM_LISTENER_PASSIVE_STATE=1,
+       NES_CM_LISTENER_ACTIVE_STATE=2,
+       NES_CM_LISTENER_EITHER_STATE=3
+};
+
+struct nes_cm_listener {
+       struct list_head           list;
+       u64                        session_id;
+       struct nes_cm_core         *cm_core;
+       u8                         loc_mac[ETH_ALEN];
+       nes_addr_t                 loc_addr;
+       u16                        loc_port;
+       struct iw_cm_id            *cm_id;
+       enum nes_cm_conn_type      conn_type;
+       atomic_t                   ref_count;
+       struct nes_vnic            *nesvnic;
+       atomic_t                   pend_accepts_cnt;
+       int                        backlog;
+       enum nes_cm_listener_state listener_state;
+       u32                        reused_node;
+};
+
+/* per connection node and node state information */
+struct nes_cm_node {
+       u64                       session_id;
+       u32                       hashkey;
+
+       nes_addr_t                loc_addr, rem_addr;
+       u16                       loc_port, rem_port;
+
+       u8                        loc_mac[ETH_ALEN];
+       u8                        rem_mac[ETH_ALEN];
+
+       enum nes_cm_node_state    state;
+       struct nes_cm_tcp_context tcp_cntxt;
+       struct nes_cm_core        *cm_core;
+       struct sk_buff_head       resend_list;
+       atomic_t                  ref_count;
+       struct net_device         *netdev;
+
+       struct nes_cm_node        *loopbackpartner;
+       struct list_head          retrans_list;
+       spinlock_t                retrans_list_lock;
+       struct list_head          recv_list;
+       spinlock_t                recv_list_lock;
+
+       int                       send_write0;
+       union {
+               struct ietf_mpa_frame mpa_frame;
+               u8                    mpa_frame_buf[NES_CM_DEFAULT_MTU];
+       };
+       u16                       mpa_frame_size;
+       struct iw_cm_id           *cm_id;
+       struct list_head          list;
+       int                       accelerated;
+       struct nes_cm_listener    *listener;
+       enum nes_cm_conn_type     conn_type;
+       struct nes_vnic           *nesvnic;
+       int                       apbvt_set;
+       int                       accept_pend;
+};
+
+/* structure for client or CM to fill when making CM api calls. */
+/*     - only need to set relevant data, based on op. */
+struct nes_cm_info {
+       union {
+               struct iw_cm_id   *cm_id;
+               struct net_device *netdev;
+       };
+
+       u16 loc_port;
+       u16 rem_port;
+       nes_addr_t loc_addr;
+       nes_addr_t rem_addr;
+
+       enum nes_cm_conn_type  conn_type;
+       int backlog;
+};
+
+/* CM event codes */
+enum  nes_cm_event_type {
+       NES_CM_EVENT_UNKNOWN,
+       NES_CM_EVENT_ESTABLISHED,
+       NES_CM_EVENT_MPA_REQ,
+       NES_CM_EVENT_MPA_CONNECT,
+       NES_CM_EVENT_MPA_ACCEPT,
+       NES_CM_EVENT_MPA_ESTABLISHED,
+       NES_CM_EVENT_CONNECTED,
+       NES_CM_EVENT_CLOSED,
+       NES_CM_EVENT_RESET,
+       NES_CM_EVENT_DROPPED_PKT,
+       NES_CM_EVENT_CLOSE_IMMED,
+       NES_CM_EVENT_CLOSE_HARD,
+       NES_CM_EVENT_CLOSE_CLEAN,
+       NES_CM_EVENT_ABORTED,
+       NES_CM_EVENT_SEND_FIRST
+};
+
+/* event to post to CM event handler */
+struct nes_cm_event {
+       enum nes_cm_event_type type;
+
+       struct nes_cm_info cm_info;
+       struct work_struct event_work;
+       struct nes_cm_node *cm_node;
+};
+
+struct nes_cm_core {
+       enum nes_cm_node_state  state;
+       atomic_t                session_id;
+
+       atomic_t                listen_node_cnt;
+       struct nes_cm_node      listen_list;
+       spinlock_t              listen_list_lock;
+
+       u32                     mtu;
+       u32                     free_tx_pkt_max;
+       u32                     rx_pkt_posted;
+       struct sk_buff_head     tx_free_list;
+       atomic_t                ht_node_cnt;
+       struct list_head        connected_nodes;
+       /* struct list_head hashtable[NES_CM_HASHTABLE_SIZE]; */
+       spinlock_t              ht_lock;
+
+       struct timer_list       tcp_timer;
+
+       struct nes_cm_ops       *api;
+
+       int (*post_event)(struct nes_cm_event *event);
+       atomic_t                events_posted;
+       struct workqueue_struct *event_wq;
+       struct workqueue_struct *disconn_wq;
+
+       atomic_t                node_cnt;
+       u64                     aborted_connects;
+       u32                     options;
+
+       struct nes_cm_node      *current_listen_node;
+};
+
+
+#define NES_CM_SET_PKT_SIZE        (1 << 1)
+#define NES_CM_SET_FREE_PKT_Q_SIZE (1 << 2)
+
+/* CM ops/API for client interface */
+struct nes_cm_ops {
+       int (*accelerated)(struct nes_cm_core *, struct nes_cm_node *);
+       struct nes_cm_listener * (*listen)(struct nes_cm_core *, struct nes_vnic *,
+                       struct nes_cm_info *);
+       int (*stop_listener)(struct nes_cm_core *, struct nes_cm_listener *);
+       struct nes_cm_node * (*connect)(struct nes_cm_core *,
+                       struct nes_vnic *, struct ietf_mpa_frame *,
+                       struct nes_cm_info *);
+       int (*close)(struct nes_cm_core *, struct nes_cm_node *);
+       int (*accept)(struct nes_cm_core *, struct ietf_mpa_frame *,
+                       struct nes_cm_node *);
+       int (*reject)(struct nes_cm_core *, struct ietf_mpa_frame *,
+                       struct nes_cm_node *);
+       int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,
+                       struct sk_buff *);
+       int (*destroy_cm_core)(struct nes_cm_core *);
+       int (*get)(struct nes_cm_core *);
+       int (*set)(struct nes_cm_core *, u32, u32);
+};
+
+
+int send_mpa_request(struct nes_cm_node *);
+struct sk_buff *form_cm_frame(struct sk_buff *, struct nes_cm_node *,
+               void *, u32, void *, u32, u8);
+int schedule_nes_timer(struct nes_cm_node *, struct sk_buff *,
+               enum nes_timer_type, int, int);
+void nes_cm_timer_tick(unsigned long);
+int send_syn(struct nes_cm_node *, u32);
+int send_reset(struct nes_cm_node *);
+int send_ack(struct nes_cm_node *);
+int send_fin(struct nes_cm_node *, struct sk_buff *);
+struct sk_buff *get_free_pkt(struct nes_cm_node *);
+int process_packet(struct nes_cm_node *, struct sk_buff *, struct nes_cm_core *);
+
+struct nes_cm_node * mini_cm_connect(struct nes_cm_core *,
+               struct nes_vnic *, struct ietf_mpa_frame *, struct nes_cm_info *);
+int mini_cm_accept(struct nes_cm_core *, struct ietf_mpa_frame *, struct nes_cm_node *);
+int mini_cm_reject(struct nes_cm_core *, struct ietf_mpa_frame *, struct nes_cm_node *);
+int mini_cm_close(struct nes_cm_core *, struct nes_cm_node *);
+int mini_cm_recv_pkt(struct nes_cm_core *, struct nes_vnic *, struct sk_buff *);
+struct nes_cm_core *mini_cm_alloc_core(struct nes_cm_info *);
+int mini_cm_dealloc_core(struct nes_cm_core *);
+int mini_cm_get(struct nes_cm_core *);
+int mini_cm_set(struct nes_cm_core *, u32, u32);
+
+int nes_cm_disconn(struct nes_qp *);
+void nes_disconnect_worker(struct work_struct *);
+int nes_cm_disconn_true(struct nes_qp *);
+int nes_disconnect(struct nes_qp *, int);
+
+int nes_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
+int nes_reject(struct iw_cm_id *, const void *, u8);
+int nes_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
+int nes_create_listen(struct iw_cm_id *, int);
+int nes_destroy_listen(struct iw_cm_id *);
+
+int nes_cm_recv(struct sk_buff *, struct net_device *);
+int nes_cm_start(void);
+int nes_cm_stop(void);
+
+/* CM event handler functions */
+void cm_event_connected(struct nes_cm_event *);
+void cm_event_connect_error(struct nes_cm_event *);
+void cm_event_reset(struct nes_cm_event *);
+void cm_event_mpa_req(struct nes_cm_event *);
+int nes_cm_post_event(struct nes_cm_event *);
+
+#endif                 /* NES_CM_H */
diff --git a/drivers/infiniband/hw/nes/nes_context.h b/drivers/infiniband/hw/nes/nes_context.h
new file mode 100644 (file)
index 0000000..da9daba
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef NES_CONTEXT_H
+#define NES_CONTEXT_H
+
+struct nes_qp_context {
+       __le32   misc;
+       __le32   cqs;
+       __le32   sq_addr_low;
+       __le32   sq_addr_high;
+       __le32   rq_addr_low;
+       __le32   rq_addr_high;
+       __le32   misc2;
+       __le16   tcpPorts[2];
+       __le32   ip0;
+       __le32   ip1;
+       __le32   ip2;
+       __le32   ip3;
+       __le32   mss;
+       __le32   arp_index_vlan;
+       __le32   tcp_state_flow_label;
+       __le32   pd_index_wscale;
+       __le32   keepalive;
+       u32   ts_recent;
+       u32   ts_age;
+       __le32   snd_nxt;
+       __le32   snd_wnd;
+       __le32   rcv_nxt;
+       __le32   rcv_wnd;
+       __le32   snd_max;
+       __le32   snd_una;
+       u32   srtt;
+       __le32   rttvar;
+       __le32   ssthresh;
+       __le32   cwnd;
+       __le32   snd_wl1;
+       __le32   snd_wl2;
+       __le32   max_snd_wnd;
+       __le32   ts_val_delta;
+       u32   retransmit;
+       u32   probe_cnt;
+       u32   hte_index;
+       __le32   q2_addr_low;
+       __le32   q2_addr_high;
+       __le32   ird_index;
+       u32   Rsvd3;
+       __le32   ird_ord_sizes;
+       u32   mrkr_offset;
+       __le32   aeq_token_low;
+       __le32   aeq_token_high;
+};
+
+/* QP Context Misc Field */
+
+#define NES_QPCONTEXT_MISC_IWARP_VER_MASK    0x00000003
+#define NES_QPCONTEXT_MISC_IWARP_VER_SHIFT   0
+#define NES_QPCONTEXT_MISC_EFB_SIZE_MASK     0x000000C0
+#define NES_QPCONTEXT_MISC_EFB_SIZE_SHIFT    6
+#define NES_QPCONTEXT_MISC_RQ_SIZE_MASK      0x00000300
+#define NES_QPCONTEXT_MISC_RQ_SIZE_SHIFT     8
+#define NES_QPCONTEXT_MISC_SQ_SIZE_MASK      0x00000c00
+#define NES_QPCONTEXT_MISC_SQ_SIZE_SHIFT     10
+#define NES_QPCONTEXT_MISC_PCI_FCN_MASK      0x00007000
+#define NES_QPCONTEXT_MISC_PCI_FCN_SHIFT     12
+#define NES_QPCONTEXT_MISC_DUP_ACKS_MASK     0x00070000
+#define NES_QPCONTEXT_MISC_DUP_ACKS_SHIFT    16
+
+enum nes_qp_context_misc_bits {
+       NES_QPCONTEXT_MISC_RX_WQE_SIZE         = 0x00000004,
+       NES_QPCONTEXT_MISC_IPV4                = 0x00000008,
+       NES_QPCONTEXT_MISC_DO_NOT_FRAG         = 0x00000010,
+       NES_QPCONTEXT_MISC_INSERT_VLAN         = 0x00000020,
+       NES_QPCONTEXT_MISC_DROS                = 0x00008000,
+       NES_QPCONTEXT_MISC_WSCALE              = 0x00080000,
+       NES_QPCONTEXT_MISC_KEEPALIVE           = 0x00100000,
+       NES_QPCONTEXT_MISC_TIMESTAMP           = 0x00200000,
+       NES_QPCONTEXT_MISC_SACK                = 0x00400000,
+       NES_QPCONTEXT_MISC_RDMA_WRITE_EN       = 0x00800000,
+       NES_QPCONTEXT_MISC_RDMA_READ_EN        = 0x01000000,
+       NES_QPCONTEXT_MISC_WBIND_EN            = 0x10000000,
+       NES_QPCONTEXT_MISC_FAST_REGISTER_EN    = 0x20000000,
+       NES_QPCONTEXT_MISC_PRIV_EN             = 0x40000000,
+       NES_QPCONTEXT_MISC_NO_NAGLE            = 0x80000000
+};
+
+enum nes_qp_acc_wq_sizes {
+       HCONTEXT_TSA_WQ_SIZE_4 = 0,
+       HCONTEXT_TSA_WQ_SIZE_32 = 1,
+       HCONTEXT_TSA_WQ_SIZE_128 = 2,
+       HCONTEXT_TSA_WQ_SIZE_512 = 3
+};
+
+/* QP Context Misc2 Fields */
+#define NES_QPCONTEXT_MISC2_TTL_MASK            0x000000ff
+#define NES_QPCONTEXT_MISC2_TTL_SHIFT           0
+#define NES_QPCONTEXT_MISC2_HOP_LIMIT_MASK      0x000000ff
+#define NES_QPCONTEXT_MISC2_HOP_LIMIT_SHIFT     0
+#define NES_QPCONTEXT_MISC2_LIMIT_MASK          0x00000300
+#define NES_QPCONTEXT_MISC2_LIMIT_SHIFT         8
+#define NES_QPCONTEXT_MISC2_NIC_INDEX_MASK      0x0000fc00
+#define NES_QPCONTEXT_MISC2_NIC_INDEX_SHIFT     10
+#define NES_QPCONTEXT_MISC2_SRC_IP_MASK         0x001f0000
+#define NES_QPCONTEXT_MISC2_SRC_IP_SHIFT        16
+#define NES_QPCONTEXT_MISC2_TOS_MASK            0xff000000
+#define NES_QPCONTEXT_MISC2_TOS_SHIFT           24
+#define NES_QPCONTEXT_MISC2_TRAFFIC_CLASS_MASK  0xff000000
+#define NES_QPCONTEXT_MISC2_TRAFFIC_CLASS_SHIFT 24
+
+/* QP Context Tcp State/Flow Label Fields */
+#define NES_QPCONTEXT_TCPFLOW_FLOW_LABEL_MASK   0x000fffff
+#define NES_QPCONTEXT_TCPFLOW_FLOW_LABEL_SHIFT  0
+#define NES_QPCONTEXT_TCPFLOW_TCP_STATE_MASK    0xf0000000
+#define NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT   28
+
+enum nes_qp_tcp_state {
+       NES_QPCONTEXT_TCPSTATE_CLOSED = 1,
+       NES_QPCONTEXT_TCPSTATE_EST = 5,
+       NES_QPCONTEXT_TCPSTATE_TIME_WAIT = 11,
+};
+
+/* QP Context PD Index/wscale Fields */
+#define NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK  0x0000000f
+#define NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT 0
+#define NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK  0x00000f00
+#define NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT 8
+#define NES_QPCONTEXT_PDWSCALE_PDINDEX_MASK     0xffff0000
+#define NES_QPCONTEXT_PDWSCALE_PDINDEX_SHIFT    16
+
+/* QP Context Keepalive Fields */
+#define NES_QPCONTEXT_KEEPALIVE_DELTA_MASK      0x0000ffff
+#define NES_QPCONTEXT_KEEPALIVE_DELTA_SHIFT     0
+#define NES_QPCONTEXT_KEEPALIVE_PROBE_CNT_MASK  0x00ff0000
+#define NES_QPCONTEXT_KEEPALIVE_PROBE_CNT_SHIFT 16
+#define NES_QPCONTEXT_KEEPALIVE_INTV_MASK       0xff000000
+#define NES_QPCONTEXT_KEEPALIVE_INTV_SHIFT      24
+
+/* QP Context ORD/IRD Fields */
+#define NES_QPCONTEXT_ORDIRD_ORDSIZE_MASK       0x0000007f
+#define NES_QPCONTEXT_ORDIRD_ORDSIZE_SHIFT      0
+#define NES_QPCONTEXT_ORDIRD_IRDSIZE_MASK       0x00030000
+#define NES_QPCONTEXT_ORDIRD_IRDSIZE_SHIFT      16
+#define NES_QPCONTEXT_ORDIRD_IWARP_MODE_MASK    0x30000000
+#define NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT   28
+
+enum nes_ord_ird_bits {
+       NES_QPCONTEXT_ORDIRD_WRPDU                   = 0x02000000,
+       NES_QPCONTEXT_ORDIRD_LSMM_PRESENT            = 0x04000000,
+       NES_QPCONTEXT_ORDIRD_ALSMM                   = 0x08000000,
+       NES_QPCONTEXT_ORDIRD_AAH                     = 0x40000000,
+       NES_QPCONTEXT_ORDIRD_RNMC                    = 0x80000000
+};
+
+enum nes_iwarp_qp_state {
+       NES_QPCONTEXT_IWARP_STATE_NONEXIST  = 0,
+       NES_QPCONTEXT_IWARP_STATE_IDLE      = 1,
+       NES_QPCONTEXT_IWARP_STATE_RTS       = 2,
+       NES_QPCONTEXT_IWARP_STATE_CLOSING   = 3,
+       NES_QPCONTEXT_IWARP_STATE_TERMINATE = 5,
+       NES_QPCONTEXT_IWARP_STATE_ERROR     = 6
+};
+
+
+#endif         /* NES_CONTEXT_H */
diff --git a/drivers/infiniband/hw/nes/nes_hw.c b/drivers/infiniband/hw/nes/nes_hw.c
new file mode 100644 (file)
index 0000000..7c4c0fb
--- /dev/null
@@ -0,0 +1,3080 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/if_vlan.h>
+
+#include "nes.h"
+
+u32 crit_err_count = 0;
+u32 int_mod_timer_init;
+u32 int_mod_cq_depth_256;
+u32 int_mod_cq_depth_128;
+u32 int_mod_cq_depth_32;
+u32 int_mod_cq_depth_24;
+u32 int_mod_cq_depth_16;
+u32 int_mod_cq_depth_4;
+u32 int_mod_cq_depth_1;
+
+#include "nes_cm.h"
+
+
+#ifdef CONFIG_INFINIBAND_NES_DEBUG
+static unsigned char *nes_iwarp_state_str[] = {
+       "Non-Existant",
+       "Idle",
+       "RTS",
+       "Closing",
+       "RSVD1",
+       "Terminate",
+       "Error",
+       "RSVD2",
+};
+
+static unsigned char *nes_tcp_state_str[] = {
+       "Non-Existant",
+       "Closed",
+       "Listen",
+       "SYN Sent",
+       "SYN Rcvd",
+       "Established",
+       "Close Wait",
+       "FIN Wait 1",
+       "Closing",
+       "Last Ack",
+       "FIN Wait 2",
+       "Time Wait",
+       "RSVD1",
+       "RSVD2",
+       "RSVD3",
+       "RSVD4",
+};
+#endif
+
+
+/**
+ * nes_nic_init_timer_defaults
+ */
+void  nes_nic_init_timer_defaults(struct nes_device *nesdev, u8 jumbomode)
+{
+       unsigned long flags;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
+
+       spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
+
+       shared_timer->timer_in_use_min = NES_NIC_FAST_TIMER_LOW;
+       shared_timer->timer_in_use_max = NES_NIC_FAST_TIMER_HIGH;
+       if (jumbomode) {
+               shared_timer->threshold_low    = DEFAULT_JUMBO_NES_QL_LOW;
+               shared_timer->threshold_target = DEFAULT_JUMBO_NES_QL_TARGET;
+               shared_timer->threshold_high   = DEFAULT_JUMBO_NES_QL_HIGH;
+       } else {
+               shared_timer->threshold_low    = DEFAULT_NES_QL_LOW;
+               shared_timer->threshold_target = DEFAULT_NES_QL_TARGET;
+               shared_timer->threshold_high   = DEFAULT_NES_QL_HIGH;
+       }
+
+       /* todo use netdev->mtu to set thresholds */
+       spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
+}
+
+
+/**
+ * nes_nic_init_timer
+ */
+static void  nes_nic_init_timer(struct nes_device *nesdev)
+{
+       unsigned long flags;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
+
+       spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
+
+       if (shared_timer->timer_in_use_old == 0) {
+               nesdev->deepcq_count = 0;
+               shared_timer->timer_direction_upward = 0;
+               shared_timer->timer_direction_downward = 0;
+               shared_timer->timer_in_use = NES_NIC_FAST_TIMER;
+               shared_timer->timer_in_use_old = 0;
+
+       }
+       if (shared_timer->timer_in_use != shared_timer->timer_in_use_old) {
+               shared_timer->timer_in_use_old = shared_timer->timer_in_use;
+               nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
+                       0x80000000 | ((u32)(shared_timer->timer_in_use*8)));
+       }
+       /* todo use netdev->mtu to set thresholds */
+       spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
+}
+
+
+/**
+ * nes_nic_tune_timer
+ */
+static void nes_nic_tune_timer(struct nes_device *nesdev)
+{
+       unsigned long flags;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
+       u16 cq_count = nesdev->currcq_count;
+
+       spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
+
+       if (shared_timer->cq_count_old < cq_count) {
+               if (cq_count > shared_timer->threshold_low)
+                       shared_timer->cq_direction_downward=0;
+       }
+       if (shared_timer->cq_count_old >= cq_count)
+               shared_timer->cq_direction_downward++;
+       shared_timer->cq_count_old = cq_count;
+       if (shared_timer->cq_direction_downward > NES_NIC_CQ_DOWNWARD_TREND) {
+               if (cq_count <= shared_timer->threshold_low) {
+                       shared_timer->threshold_low = shared_timer->threshold_low/2;
+                       shared_timer->cq_direction_downward=0;
+                       nesdev->currcq_count = 0;
+                       spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
+                       return;
+               }
+       }
+
+       if (cq_count > 1) {
+               nesdev->deepcq_count += cq_count;
+               if (cq_count <= shared_timer->threshold_low) {       /* increase timer gently */
+                       shared_timer->timer_direction_upward++;
+                       shared_timer->timer_direction_downward = 0;
+               } else if (cq_count <= shared_timer->threshold_target) { /* balanced */
+                       shared_timer->timer_direction_upward = 0;
+                       shared_timer->timer_direction_downward = 0;
+               } else if (cq_count <= shared_timer->threshold_high) {  /* decrease timer gently */
+                       shared_timer->timer_direction_downward++;
+                       shared_timer->timer_direction_upward = 0;
+               } else if (cq_count <= (shared_timer->threshold_high) * 2) {
+                       shared_timer->timer_in_use -= 2;
+                       shared_timer->timer_direction_upward = 0;
+                       shared_timer->timer_direction_downward++;
+               } else {
+                       shared_timer->timer_in_use -= 4;
+                       shared_timer->timer_direction_upward = 0;
+                       shared_timer->timer_direction_downward++;
+               }
+
+               if (shared_timer->timer_direction_upward > 3 ) {  /* using history */
+                       shared_timer->timer_in_use += 3;
+                       shared_timer->timer_direction_upward = 0;
+                       shared_timer->timer_direction_downward = 0;
+               }
+               if (shared_timer->timer_direction_downward > 5) { /* using history */
+                       shared_timer->timer_in_use -= 4 ;
+                       shared_timer->timer_direction_downward = 0;
+                       shared_timer->timer_direction_upward = 0;
+               }
+       }
+
+       /* boundary checking */
+       if (shared_timer->timer_in_use > NES_NIC_FAST_TIMER_HIGH)
+               shared_timer->timer_in_use = NES_NIC_FAST_TIMER_HIGH;
+       else if (shared_timer->timer_in_use < NES_NIC_FAST_TIMER_LOW) {
+               shared_timer->timer_in_use = NES_NIC_FAST_TIMER_LOW;
+       }
+
+       nesdev->currcq_count = 0;
+
+       spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
+}
+
+
+/**
+ * nes_init_adapter - initialize adapter
+ */
+struct nes_adapter *nes_init_adapter(struct nes_device *nesdev, u8 hw_rev) {
+       struct nes_adapter *nesadapter = NULL;
+       unsigned long num_pds;
+       u32 u32temp;
+       u32 port_count;
+       u16 max_rq_wrs;
+       u16 max_sq_wrs;
+       u32 max_mr;
+       u32 max_256pbl;
+       u32 max_4kpbl;
+       u32 max_qp;
+       u32 max_irrq;
+       u32 max_cq;
+       u32 hte_index_mask;
+       u32 adapter_size;
+       u32 arp_table_size;
+       u16 vendor_id;
+       u8  OneG_Mode;
+       u8  func_index;
+
+       /* search the list of existing adapters */
+       list_for_each_entry(nesadapter, &nes_adapter_list, list) {
+               nes_debug(NES_DBG_INIT, "Searching Adapter list for PCI devfn = 0x%X,"
+                               " adapter PCI slot/bus = %u/%u, pci devices PCI slot/bus = %u/%u, .\n",
+                               nesdev->pcidev->devfn,
+                               PCI_SLOT(nesadapter->devfn),
+                               nesadapter->bus_number,
+                               PCI_SLOT(nesdev->pcidev->devfn),
+                               nesdev->pcidev->bus->number );
+               if ((PCI_SLOT(nesadapter->devfn) == PCI_SLOT(nesdev->pcidev->devfn)) &&
+                               (nesadapter->bus_number == nesdev->pcidev->bus->number)) {
+                       nesadapter->ref_count++;
+                       return nesadapter;
+               }
+       }
+
+       /* no adapter found */
+       num_pds = pci_resource_len(nesdev->pcidev, BAR_1) >> PAGE_SHIFT;
+       if ((hw_rev != NE020_REV) && (hw_rev != NE020_REV1)) {
+               nes_debug(NES_DBG_INIT, "NE020 driver detected unknown hardware revision 0x%x\n",
+                               hw_rev);
+               return NULL;
+       }
+
+       nes_debug(NES_DBG_INIT, "Determine Soft Reset, QP_control=0x%x, CPU0=0x%x, CPU1=0x%x, CPU2=0x%x\n",
+                       nes_read_indexed(nesdev, NES_IDX_QP_CONTROL + PCI_FUNC(nesdev->pcidev->devfn) * 8),
+                       nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS),
+                       nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 4),
+                       nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 8));
+
+       nes_debug(NES_DBG_INIT, "Reset and init NE020\n");
+
+
+       if ((port_count = nes_reset_adapter_ne020(nesdev, &OneG_Mode)) == 0)
+               return NULL;
+       if (nes_init_serdes(nesdev, hw_rev, port_count, OneG_Mode))
+               return NULL;
+       nes_init_csr_ne020(nesdev, hw_rev, port_count);
+
+       max_qp = nes_read_indexed(nesdev, NES_IDX_QP_CTX_SIZE);
+       nes_debug(NES_DBG_INIT, "QP_CTX_SIZE=%u\n", max_qp);
+
+       u32temp = nes_read_indexed(nesdev, NES_IDX_QUAD_HASH_TABLE_SIZE);
+       if (max_qp > ((u32)1 << (u32temp & 0x001f))) {
+               nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to hash table size = 0x%08X\n",
+                               max_qp, u32temp);
+               max_qp = (u32)1 << (u32temp & 0x001f);
+       }
+
+       hte_index_mask = ((u32)1 << ((u32temp & 0x001f)+1))-1;
+       nes_debug(NES_DBG_INIT, "Max QP = %u, hte_index_mask = 0x%08X.\n",
+                       max_qp, hte_index_mask);
+
+       u32temp = nes_read_indexed(nesdev, NES_IDX_IRRQ_COUNT);
+
+       max_irrq = 1 << (u32temp & 0x001f);
+
+       if (max_qp > max_irrq) {
+               max_qp = max_irrq;
+               nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to Available Q1s.\n",
+                               max_qp);
+       }
+
+       /* there should be no reason to allocate more pds than qps */
+       if (num_pds > max_qp)
+               num_pds = max_qp;
+
+       u32temp = nes_read_indexed(nesdev, NES_IDX_MRT_SIZE);
+       max_mr = (u32)8192 << (u32temp & 0x7);
+
+       u32temp = nes_read_indexed(nesdev, NES_IDX_PBL_REGION_SIZE);
+       max_256pbl = (u32)1 << (u32temp & 0x0000001f);
+       max_4kpbl = (u32)1 << ((u32temp >> 16) & 0x0000001f);
+       max_cq = nes_read_indexed(nesdev, NES_IDX_CQ_CTX_SIZE);
+
+       u32temp = nes_read_indexed(nesdev, NES_IDX_ARP_CACHE_SIZE);
+       arp_table_size = 1 << u32temp;
+
+       adapter_size = (sizeof(struct nes_adapter) +
+                       (sizeof(unsigned long)-1)) & (~(sizeof(unsigned long)-1));
+       adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_qp);
+       adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_mr);
+       adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_cq);
+       adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(num_pds);
+       adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size);
+       adapter_size += sizeof(struct nes_qp **) * max_qp;
+
+       /* allocate a new adapter struct */
+       nesadapter = kzalloc(adapter_size, GFP_KERNEL);
+       if (nesadapter == NULL) {
+               return NULL;
+       }
+
+       nes_debug(NES_DBG_INIT, "Allocating new nesadapter @ %p, size = %u (actual size = %u).\n",
+                       nesadapter, (u32)sizeof(struct nes_adapter), adapter_size);
+
+       /* populate the new nesadapter */
+       nesadapter->devfn = nesdev->pcidev->devfn;
+       nesadapter->bus_number = nesdev->pcidev->bus->number;
+       nesadapter->ref_count = 1;
+       nesadapter->timer_int_req = 0xffff0000;
+       nesadapter->OneG_Mode = OneG_Mode;
+       nesadapter->doorbell_start = nesdev->doorbell_region;
+
+       /* nesadapter->tick_delta = clk_divisor; */
+       nesadapter->hw_rev = hw_rev;
+       nesadapter->port_count = port_count;
+
+       nesadapter->max_qp = max_qp;
+       nesadapter->hte_index_mask = hte_index_mask;
+       nesadapter->max_irrq = max_irrq;
+       nesadapter->max_mr = max_mr;
+       nesadapter->max_256pbl = max_256pbl - 1;
+       nesadapter->max_4kpbl = max_4kpbl - 1;
+       nesadapter->max_cq = max_cq;
+       nesadapter->free_256pbl = max_256pbl - 1;
+       nesadapter->free_4kpbl = max_4kpbl - 1;
+       nesadapter->max_pd = num_pds;
+       nesadapter->arp_table_size = arp_table_size;
+
+       nesadapter->et_pkt_rate_low = NES_TIMER_ENABLE_LIMIT;
+       if (nes_drv_opt & NES_DRV_OPT_DISABLE_INT_MOD) {
+               nesadapter->et_use_adaptive_rx_coalesce = 0;
+               nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
+               nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
+       } else {
+               nesadapter->et_use_adaptive_rx_coalesce = 1;
+               nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
+               nesadapter->et_rx_coalesce_usecs_irq = 0;
+               printk(PFX "%s: Using Adaptive Interrupt Moderation\n", __FUNCTION__);
+       }
+       /* Setup and enable the periodic timer */
+       if (nesadapter->et_rx_coalesce_usecs_irq)
+               nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x80000000 |
+                               ((u32)(nesadapter->et_rx_coalesce_usecs_irq * 8)));
+       else
+               nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x00000000);
+
+       nesadapter->base_pd = 1;
+
+       nesadapter->device_cap_flags =
+                       IB_DEVICE_ZERO_STAG | IB_DEVICE_SEND_W_INV | IB_DEVICE_MEM_WINDOW;
+
+       nesadapter->allocated_qps = (unsigned long *)&(((unsigned char *)nesadapter)
+                       [(sizeof(struct nes_adapter)+(sizeof(unsigned long)-1))&(~(sizeof(unsigned long)-1))]);
+       nesadapter->allocated_cqs = &nesadapter->allocated_qps[BITS_TO_LONGS(max_qp)];
+       nesadapter->allocated_mrs = &nesadapter->allocated_cqs[BITS_TO_LONGS(max_cq)];
+       nesadapter->allocated_pds = &nesadapter->allocated_mrs[BITS_TO_LONGS(max_mr)];
+       nesadapter->allocated_arps = &nesadapter->allocated_pds[BITS_TO_LONGS(num_pds)];
+       nesadapter->qp_table = (struct nes_qp **)(&nesadapter->allocated_arps[BITS_TO_LONGS(arp_table_size)]);
+
+
+       /* mark the usual suspect QPs and CQs as in use */
+       for (u32temp = 0; u32temp < NES_FIRST_QPN; u32temp++) {
+               set_bit(u32temp, nesadapter->allocated_qps);
+               set_bit(u32temp, nesadapter->allocated_cqs);
+       }
+
+       for (u32temp = 0; u32temp < 20; u32temp++)
+               set_bit(u32temp, nesadapter->allocated_pds);
+       u32temp = nes_read_indexed(nesdev, NES_IDX_QP_MAX_CFG_SIZES);
+
+       max_rq_wrs = ((u32temp >> 8) & 3);
+       switch (max_rq_wrs) {
+               case 0:
+                       max_rq_wrs = 4;
+                       break;
+               case 1:
+                       max_rq_wrs = 16;
+                       break;
+               case 2:
+                       max_rq_wrs = 32;
+                       break;
+               case 3:
+                       max_rq_wrs = 512;
+                       break;
+       }
+
+       max_sq_wrs = (u32temp & 3);
+       switch (max_sq_wrs) {
+               case 0:
+                       max_sq_wrs = 4;
+                       break;
+               case 1:
+                       max_sq_wrs = 16;
+                       break;
+               case 2:
+                       max_sq_wrs = 32;
+                       break;
+               case 3:
+                       max_sq_wrs = 512;
+                       break;
+       }
+       nesadapter->max_qp_wr = min(max_rq_wrs, max_sq_wrs);
+       nesadapter->max_irrq_wr = (u32temp >> 16) & 3;
+
+       nesadapter->max_sge = 4;
+       nesadapter->max_cqe = 32767;
+
+       if (nes_read_eeprom_values(nesdev, nesadapter)) {
+               printk(KERN_ERR PFX "Unable to read EEPROM data.\n");
+               kfree(nesadapter);
+               return NULL;
+       }
+
+       u32temp = nes_read_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG);
+       nes_write_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG,
+                       (u32temp & 0xff000000) | (nesadapter->tcp_timer_core_clk_divisor & 0x00ffffff));
+
+       /* setup port configuration */
+       if (nesadapter->port_count == 1) {
+               u32temp = 0x00000000;
+               if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT)
+                       nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000002);
+               else
+                       nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
+       } else {
+               if (nesadapter->port_count == 2)
+                       u32temp = 0x00000044;
+               else
+                       u32temp = 0x000000e4;
+               nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
+       }
+
+       nes_write_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT, u32temp);
+       nes_debug(NES_DBG_INIT, "Probe time, LOG2PHY=%u\n",
+                       nes_read_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT));
+
+       spin_lock_init(&nesadapter->resource_lock);
+       spin_lock_init(&nesadapter->phy_lock);
+       spin_lock_init(&nesadapter->pbl_lock);
+       spin_lock_init(&nesadapter->periodic_timer_lock);
+
+       INIT_LIST_HEAD(&nesadapter->nesvnic_list[0]);
+       INIT_LIST_HEAD(&nesadapter->nesvnic_list[1]);
+       INIT_LIST_HEAD(&nesadapter->nesvnic_list[2]);
+       INIT_LIST_HEAD(&nesadapter->nesvnic_list[3]);
+
+       if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
+               u32 pcs_control_status0, pcs_control_status1;
+               u32 reset_value;
+               u32 i = 0;
+               u32 int_cnt = 0;
+               u32 ext_cnt = 0;
+               unsigned long flags;
+               u32 j = 0;
+
+               pcs_control_status0 = nes_read_indexed(nesdev,
+                       NES_IDX_PHY_PCS_CONTROL_STATUS0);
+               pcs_control_status1 = nes_read_indexed(nesdev,
+                       NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
+
+               for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
+                       pcs_control_status0 = nes_read_indexed(nesdev,
+                                       NES_IDX_PHY_PCS_CONTROL_STATUS0);
+                       pcs_control_status1 = nes_read_indexed(nesdev,
+                                       NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
+                       if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
+                           || (0x0F000100 == (pcs_control_status1 & 0x0F000100)))
+                               int_cnt++;
+                       msleep(1);
+               }
+               if (int_cnt > 1) {
+                       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
+                       mh_detected++;
+                       reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
+                       reset_value |= 0x0000003d;
+                       nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
+
+                       while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
+                               & 0x00000040) != 0x00000040) && (j++ < 5000));
+                       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+
+                       pcs_control_status0 = nes_read_indexed(nesdev,
+                                       NES_IDX_PHY_PCS_CONTROL_STATUS0);
+                       pcs_control_status1 = nes_read_indexed(nesdev,
+                                       NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
+
+                       for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
+                               pcs_control_status0 = nes_read_indexed(nesdev,
+                                       NES_IDX_PHY_PCS_CONTROL_STATUS0);
+                               pcs_control_status1 = nes_read_indexed(nesdev,
+                                       NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
+                               if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
+                                       || (0x0F000100 == (pcs_control_status1 & 0x0F000100))) {
+                                       if (++ext_cnt > int_cnt) {
+                                               spin_lock_irqsave(&nesadapter->phy_lock, flags);
+                                               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1,
+                                                               0x0000F0C8);
+                                               mh_detected++;
+                                               reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
+                                               reset_value |= 0x0000003d;
+                                               nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
+
+                                               while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
+                                                       & 0x00000040) != 0x00000040) && (j++ < 5000));
+                                               spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+                                               break;
+                                       }
+                               }
+                               msleep(1);
+                       }
+               }
+       }
+
+       if (nesadapter->hw_rev == NE020_REV) {
+               init_timer(&nesadapter->mh_timer);
+               nesadapter->mh_timer.function = nes_mh_fix;
+               nesadapter->mh_timer.expires = jiffies + (HZ/5);  /* 1 second */
+               nesadapter->mh_timer.data = (unsigned long)nesdev;
+               add_timer(&nesadapter->mh_timer);
+       } else {
+               nes_write32(nesdev->regs+NES_INTF_INT_STAT, 0x0f000000);
+       }
+
+       init_timer(&nesadapter->lc_timer);
+       nesadapter->lc_timer.function = nes_clc;
+       nesadapter->lc_timer.expires = jiffies + 3600 * HZ;  /* 1 hour */
+       nesadapter->lc_timer.data = (unsigned long)nesdev;
+       add_timer(&nesadapter->lc_timer);
+
+       list_add_tail(&nesadapter->list, &nes_adapter_list);
+
+       for (func_index = 0; func_index < 8; func_index++) {
+               pci_bus_read_config_word(nesdev->pcidev->bus,
+                                       PCI_DEVFN(PCI_SLOT(nesdev->pcidev->devfn),
+                                       func_index), 0, &vendor_id);
+               if (vendor_id == 0xffff)
+                       break;
+       }
+       nes_debug(NES_DBG_INIT, "%s %d functions found for %s.\n", __FUNCTION__,
+               func_index, pci_name(nesdev->pcidev));
+       nesadapter->adapter_fcn_count = func_index;
+
+       return nesadapter;
+}
+
+
+/**
+ * nes_reset_adapter_ne020
+ */
+unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode)
+{
+       u32 port_count;
+       u32 u32temp;
+       u32 i;
+
+       u32temp = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
+       port_count = ((u32temp & 0x00000300) >> 8) + 1;
+       /* TODO: assuming that both SERDES are set the same for now */
+       *OneG_Mode = (u32temp & 0x00003c00) ? 0 : 1;
+       nes_debug(NES_DBG_INIT, "Initial Software Reset = 0x%08X, port_count=%u\n",
+                       u32temp, port_count);
+       if (*OneG_Mode)
+               nes_debug(NES_DBG_INIT, "Running in 1G mode.\n");
+       u32temp &= 0xff00ffc0;
+       switch (port_count) {
+               case 1:
+                       u32temp |= 0x00ee0000;
+                       break;
+               case 2:
+                       u32temp |= 0x00cc0000;
+                       break;
+               case 4:
+                       u32temp |= 0x00000000;
+                       break;
+               default:
+                       return 0;
+                       break;
+       }
+
+       /* check and do full reset if needed */
+       if (nes_read_indexed(nesdev, NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8))) {
+               nes_debug(NES_DBG_INIT, "Issuing Full Soft reset = 0x%08X\n", u32temp | 0xd);
+               nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
+
+               i = 0;
+               while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
+                       mdelay(1);
+               if (i >= 10000) {
+                       nes_debug(NES_DBG_INIT, "Did not see full soft reset done.\n");
+                       return 0;
+               }
+       }
+
+       /* port reset */
+       switch (port_count) {
+               case 1:
+                       u32temp |= 0x00ee0010;
+                       break;
+               case 2:
+                       u32temp |= 0x00cc0030;
+                       break;
+               case 4:
+                       u32temp |= 0x00000030;
+                       break;
+       }
+
+       nes_debug(NES_DBG_INIT, "Issuing Port Soft reset = 0x%08X\n", u32temp | 0xd);
+       nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
+
+       i = 0;
+       while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
+               mdelay(1);
+       if (i >= 10000) {
+               nes_debug(NES_DBG_INIT, "Did not see port soft reset done.\n");
+               return 0;
+       }
+
+       /* serdes 0 */
+       i = 0;
+       while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
+                       & 0x0000000f)) != 0x0000000f) && i++ < 5000)
+               mdelay(1);
+       if (i >= 5000) {
+               nes_debug(NES_DBG_INIT, "Serdes 0 not ready, status=%x\n", u32temp);
+               return 0;
+       }
+
+       /* serdes 1 */
+       if (port_count > 1) {
+               i = 0;
+               while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
+                               & 0x0000000f)) != 0x0000000f) && i++ < 5000)
+                       mdelay(1);
+               if (i >= 5000) {
+                       nes_debug(NES_DBG_INIT, "Serdes 1 not ready, status=%x\n", u32temp);
+                       return 0;
+               }
+       }
+
+
+
+       i = 0;
+       while ((nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS) != 0x80) && i++ < 10000)
+               mdelay(1);
+       if (i >= 10000) {
+               printk(KERN_ERR PFX "Internal CPU not ready, status = %02X\n",
+                               nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS));
+               return 0;
+       }
+
+       return port_count;
+}
+
+
+/**
+ * nes_init_serdes
+ */
+int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count, u8  OneG_Mode)
+{
+       int i;
+       u32 u32temp;
+
+       if (hw_rev != NE020_REV) {
+               /* init serdes 0 */
+
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000FF);
+               if (!OneG_Mode)
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE0, 0x11110000);
+               if (port_count > 1) {
+                       /* init serdes 1 */
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000FF);
+                       if (!OneG_Mode)
+                               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE1, 0x11110000);
+                       }
+       } else {
+               /* init serdes 0 */
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, 0x00000008);
+               i = 0;
+               while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
+                               & 0x0000000f)) != 0x0000000f) && i++ < 5000)
+                       mdelay(1);
+               if (i >= 5000) {
+                       nes_debug(NES_DBG_PHY, "Init: serdes 0 not ready, status=%x\n", u32temp);
+                       return 1;
+               }
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP0, 0x000bdef7);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE0, 0x9ce73000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE0, 0x0ff00000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET0, 0x00000000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS0, 0x00000000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0, 0x00000000);
+               if (OneG_Mode)
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0182222);
+               else
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0042222);
+
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000ff);
+               if (port_count > 1) {
+                       /* init serdes 1 */
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x00000048);
+                       i = 0;
+                       while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
+                               & 0x0000000f)) != 0x0000000f) && (i++ < 5000))
+                               mdelay(1);
+                       if (i >= 5000) {
+                               printk("%s: Init: serdes 1 not ready, status=%x\n", __FUNCTION__, u32temp);
+                               /* return 1; */
+                       }
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP1, 0x000bdef7);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE1, 0x9ce73000);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE1, 0x0ff00000);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET1, 0x00000000);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS1, 0x00000000);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL1, 0x00000000);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL1, 0xf0002222);
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000ff);
+               }
+       }
+       return 0;
+}
+
+
+/**
+ * nes_init_csr_ne020
+ * Initialize registers for ne020 hardware
+ */
+void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count)
+{
+       u32 u32temp;
+
+       nes_debug(NES_DBG_INIT, "port_count=%d\n", port_count);
+
+       nes_write_indexed(nesdev, 0x000001E4, 0x00000007);
+       /* nes_write_indexed(nesdev, 0x000001E8, 0x000208C4); */
+       nes_write_indexed(nesdev, 0x000001E8, 0x00020874);
+       nes_write_indexed(nesdev, 0x000001D8, 0x00048002);
+       /* nes_write_indexed(nesdev, 0x000001D8, 0x0004B002); */
+       nes_write_indexed(nesdev, 0x000001FC, 0x00050005);
+       nes_write_indexed(nesdev, 0x00000600, 0x55555555);
+       nes_write_indexed(nesdev, 0x00000604, 0x55555555);
+
+       /* TODO: move these MAC register settings to NIC bringup */
+       nes_write_indexed(nesdev, 0x00002000, 0x00000001);
+       nes_write_indexed(nesdev, 0x00002004, 0x00000001);
+       nes_write_indexed(nesdev, 0x00002008, 0x0000FFFF);
+       nes_write_indexed(nesdev, 0x0000200C, 0x00000001);
+       nes_write_indexed(nesdev, 0x00002010, 0x000003c1);
+       nes_write_indexed(nesdev, 0x0000201C, 0x75345678);
+       if (port_count > 1) {
+               nes_write_indexed(nesdev, 0x00002200, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002204, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002208, 0x0000FFFF);
+               nes_write_indexed(nesdev, 0x0000220C, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002210, 0x000003c1);
+               nes_write_indexed(nesdev, 0x0000221C, 0x75345678);
+               nes_write_indexed(nesdev, 0x00000908, 0x20000001);
+       }
+       if (port_count > 2) {
+               nes_write_indexed(nesdev, 0x00002400, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002404, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002408, 0x0000FFFF);
+               nes_write_indexed(nesdev, 0x0000240C, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002410, 0x000003c1);
+               nes_write_indexed(nesdev, 0x0000241C, 0x75345678);
+               nes_write_indexed(nesdev, 0x00000910, 0x20000001);
+
+               nes_write_indexed(nesdev, 0x00002600, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002604, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002608, 0x0000FFFF);
+               nes_write_indexed(nesdev, 0x0000260C, 0x00000001);
+               nes_write_indexed(nesdev, 0x00002610, 0x000003c1);
+               nes_write_indexed(nesdev, 0x0000261C, 0x75345678);
+               nes_write_indexed(nesdev, 0x00000918, 0x20000001);
+       }
+
+       nes_write_indexed(nesdev, 0x00005000, 0x00018000);
+       /* nes_write_indexed(nesdev, 0x00005000, 0x00010000); */
+       nes_write_indexed(nesdev, 0x00005004, 0x00020001);
+       nes_write_indexed(nesdev, 0x00005008, 0x1F1F1F1F);
+       nes_write_indexed(nesdev, 0x00005010, 0x1F1F1F1F);
+       nes_write_indexed(nesdev, 0x00005018, 0x1F1F1F1F);
+       nes_write_indexed(nesdev, 0x00005020, 0x1F1F1F1F);
+       nes_write_indexed(nesdev, 0x00006090, 0xFFFFFFFF);
+
+       /* TODO: move this to code, get from EEPROM */
+       nes_write_indexed(nesdev, 0x00000900, 0x20000001);
+       nes_write_indexed(nesdev, 0x000060C0, 0x0000028e);
+       nes_write_indexed(nesdev, 0x000060C8, 0x00000020);
+                                                                                                               //
+       nes_write_indexed(nesdev, 0x000001EC, 0x7b2625a0);
+       /* nes_write_indexed(nesdev, 0x000001EC, 0x5f2625a0); */
+
+       if (hw_rev != NE020_REV) {
+               u32temp = nes_read_indexed(nesdev, 0x000008e8);
+               u32temp |= 0x80000000;
+               nes_write_indexed(nesdev, 0x000008e8, u32temp);
+               u32temp = nes_read_indexed(nesdev, 0x000021f8);
+               u32temp &= 0x7fffffff;
+               u32temp |= 0x7fff0010;
+               nes_write_indexed(nesdev, 0x000021f8, u32temp);
+       }
+}
+
+
+/**
+ * nes_destroy_adapter - destroy the adapter structure
+ */
+void nes_destroy_adapter(struct nes_adapter *nesadapter)
+{
+       struct nes_adapter *tmp_adapter;
+
+       list_for_each_entry(tmp_adapter, &nes_adapter_list, list) {
+               nes_debug(NES_DBG_SHUTDOWN, "Nes Adapter list entry = 0x%p.\n",
+                               tmp_adapter);
+       }
+
+       nesadapter->ref_count--;
+       if (!nesadapter->ref_count) {
+               if (nesadapter->hw_rev == NE020_REV) {
+                       del_timer(&nesadapter->mh_timer);
+               }
+               del_timer(&nesadapter->lc_timer);
+
+               list_del(&nesadapter->list);
+               kfree(nesadapter);
+       }
+}
+
+
+/**
+ * nes_init_cqp
+ */
+int nes_init_cqp(struct nes_device *nesdev)
+{
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_cqp_qp_context *cqp_qp_context;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_hw_ceq *ceq;
+       struct nes_hw_ceq *nic_ceq;
+       struct nes_hw_aeq *aeq;
+       void *vmem;
+       dma_addr_t pmem;
+       u32 count=0;
+       u32 cqp_head;
+       u64 u64temp;
+       u32 u32temp;
+
+       /* allocate CQP memory */
+       /* Need to add max_cq to the aeq size once cq overflow checking is added back */
+       /* SQ is 512 byte aligned, others are 256 byte aligned */
+       nesdev->cqp_mem_size = 512 +
+                       (sizeof(struct nes_hw_cqp_wqe) * NES_CQP_SQ_SIZE) +
+                       (sizeof(struct nes_hw_cqe) * NES_CCQ_SIZE) +
+                       max(((u32)sizeof(struct nes_hw_ceqe) * NES_CCEQ_SIZE), (u32)256) +
+                       max(((u32)sizeof(struct nes_hw_ceqe) * NES_NIC_CEQ_SIZE), (u32)256) +
+                       (sizeof(struct nes_hw_aeqe) * nesadapter->max_qp) +
+                       sizeof(struct nes_hw_cqp_qp_context);
+
+       nesdev->cqp_vbase = pci_alloc_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
+                       &nesdev->cqp_pbase);
+       if (!nesdev->cqp_vbase) {
+               nes_debug(NES_DBG_INIT, "Unable to allocate memory for host descriptor rings\n");
+               return -ENOMEM;
+       }
+       memset(nesdev->cqp_vbase, 0, nesdev->cqp_mem_size);
+
+       /* Allocate a twice the number of CQP requests as the SQ size */
+       nesdev->nes_cqp_requests = kzalloc(sizeof(struct nes_cqp_request) *
+                       2 * NES_CQP_SQ_SIZE, GFP_KERNEL);
+       if (nesdev->nes_cqp_requests == NULL) {
+               nes_debug(NES_DBG_INIT, "Unable to allocate memory CQP request entries.\n");
+               pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
+                               nesdev->cqp.sq_pbase);
+               return -ENOMEM;
+       }
+
+       nes_debug(NES_DBG_INIT, "Allocated CQP structures at %p (phys = %016lX), size = %u.\n",
+                       nesdev->cqp_vbase, (unsigned long)nesdev->cqp_pbase, nesdev->cqp_mem_size);
+
+       spin_lock_init(&nesdev->cqp.lock);
+       init_waitqueue_head(&nesdev->cqp.waitq);
+
+       /* Setup Various Structures */
+       vmem = (void *)(((unsigned long)nesdev->cqp_vbase + (512 - 1)) &
+                       ~(unsigned long)(512 - 1));
+       pmem = (dma_addr_t)(((unsigned long long)nesdev->cqp_pbase + (512 - 1)) &
+                       ~(unsigned long long)(512 - 1));
+
+       nesdev->cqp.sq_vbase = vmem;
+       nesdev->cqp.sq_pbase = pmem;
+       nesdev->cqp.sq_size = NES_CQP_SQ_SIZE;
+       nesdev->cqp.sq_head = 0;
+       nesdev->cqp.sq_tail = 0;
+       nesdev->cqp.qp_id = PCI_FUNC(nesdev->pcidev->devfn);
+
+       vmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
+       pmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
+
+       nesdev->ccq.cq_vbase = vmem;
+       nesdev->ccq.cq_pbase = pmem;
+       nesdev->ccq.cq_size = NES_CCQ_SIZE;
+       nesdev->ccq.cq_head = 0;
+       nesdev->ccq.ce_handler = nes_cqp_ce_handler;
+       nesdev->ccq.cq_number = PCI_FUNC(nesdev->pcidev->devfn);
+
+       vmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
+       pmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
+
+       nesdev->ceq_index = PCI_FUNC(nesdev->pcidev->devfn);
+       ceq = &nesadapter->ceq[nesdev->ceq_index];
+       ceq->ceq_vbase = vmem;
+       ceq->ceq_pbase = pmem;
+       ceq->ceq_size = NES_CCEQ_SIZE;
+       ceq->ceq_head = 0;
+
+       vmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
+       pmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
+
+       nesdev->nic_ceq_index = PCI_FUNC(nesdev->pcidev->devfn) + 8;
+       nic_ceq = &nesadapter->ceq[nesdev->nic_ceq_index];
+       nic_ceq->ceq_vbase = vmem;
+       nic_ceq->ceq_pbase = pmem;
+       nic_ceq->ceq_size = NES_NIC_CEQ_SIZE;
+       nic_ceq->ceq_head = 0;
+
+       vmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
+       pmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
+
+       aeq = &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)];
+       aeq->aeq_vbase = vmem;
+       aeq->aeq_pbase = pmem;
+       aeq->aeq_size = nesadapter->max_qp;
+       aeq->aeq_head = 0;
+
+       /* Setup QP Context */
+       vmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
+       pmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
+
+       cqp_qp_context = vmem;
+       cqp_qp_context->context_words[0] =
+                       cpu_to_le32((PCI_FUNC(nesdev->pcidev->devfn) << 12) + (2 << 10));
+       cqp_qp_context->context_words[1] = 0;
+       cqp_qp_context->context_words[2] = cpu_to_le32((u32)nesdev->cqp.sq_pbase);
+       cqp_qp_context->context_words[3] = cpu_to_le32(((u64)nesdev->cqp.sq_pbase) >> 32);
+
+
+       /* Write the address to Create CQP */
+       if ((sizeof(dma_addr_t) > 4)) {
+               nes_write_indexed(nesdev,
+                               NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
+                               ((u64)pmem) >> 32);
+       } else {
+               nes_write_indexed(nesdev,
+                               NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8), 0);
+       }
+       nes_write_indexed(nesdev,
+                       NES_IDX_CREATE_CQP_LOW + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
+                       (u32)pmem);
+
+       INIT_LIST_HEAD(&nesdev->cqp_avail_reqs);
+       INIT_LIST_HEAD(&nesdev->cqp_pending_reqs);
+
+       for (count = 0; count < 2*NES_CQP_SQ_SIZE; count++) {
+               init_waitqueue_head(&nesdev->nes_cqp_requests[count].waitq);
+               list_add_tail(&nesdev->nes_cqp_requests[count].list, &nesdev->cqp_avail_reqs);
+       }
+
+       /* Write Create CCQ WQE */
+       cqp_head = nesdev->cqp.sq_head++;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                       (NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
+                       NES_CQP_CQ_CHK_OVERFLOW | ((u32)nesdev->ccq.cq_size << 16)));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+                           (nesdev->ccq.cq_number |
+                            ((u32)nesdev->ceq_index << 16)));
+       u64temp = (u64)nesdev->ccq.cq_pbase;
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
+       u64temp = (unsigned long)&nesdev->ccq;
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] =
+                       cpu_to_le32((u32)(u64temp >> 1));
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
+                       cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
+
+       /* Write Create CEQ WQE */
+       cqp_head = nesdev->cqp.sq_head++;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                           (NES_CQP_CREATE_CEQ + ((u32)nesdev->ceq_index << 8)));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, ceq->ceq_size);
+       u64temp = (u64)ceq->ceq_pbase;
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
+
+       /* Write Create AEQ WQE */
+       cqp_head = nesdev->cqp.sq_head++;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                       (NES_CQP_CREATE_AEQ + ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8)));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_AEQ_WQE_ELEMENT_COUNT_IDX, aeq->aeq_size);
+       u64temp = (u64)aeq->aeq_pbase;
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
+
+       /* Write Create NIC CEQ WQE */
+       cqp_head = nesdev->cqp.sq_head++;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                       (NES_CQP_CREATE_CEQ + ((u32)nesdev->nic_ceq_index << 8)));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, nic_ceq->ceq_size);
+       u64temp = (u64)nic_ceq->ceq_pbase;
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
+
+       /* Poll until CCQP done */
+       count = 0;
+       do {
+               if (count++ > 1000) {
+                       printk(KERN_ERR PFX "Error creating CQP\n");
+                       pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
+                                       nesdev->cqp_vbase, nesdev->cqp_pbase);
+                       return -1;
+               }
+               udelay(10);
+       } while (!(nes_read_indexed(nesdev,
+                       NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn) * 8)) & (1 << 8)));
+
+       nes_debug(NES_DBG_INIT, "CQP Status = 0x%08X\n", nes_read_indexed(nesdev,
+                       NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
+
+       u32temp = 0x04800000;
+       nes_write32(nesdev->regs+NES_WQE_ALLOC, u32temp | nesdev->cqp.qp_id);
+
+       /* wait for the CCQ, CEQ, and AEQ to get created */
+       count = 0;
+       do {
+               if (count++ > 1000) {
+                       printk(KERN_ERR PFX "Error creating CCQ, CEQ, and AEQ\n");
+                       pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
+                                       nesdev->cqp_vbase, nesdev->cqp_pbase);
+                       return -1;
+               }
+               udelay(10);
+       } while (((nes_read_indexed(nesdev,
+                       NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15<<8)) != (15<<8)));
+
+       /* dump the QP status value */
+       nes_debug(NES_DBG_INIT, "QP Status = 0x%08X\n", nes_read_indexed(nesdev,
+                       NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
+
+       nesdev->cqp.sq_tail++;
+
+       return 0;
+}
+
+
+/**
+ * nes_destroy_cqp
+ */
+int nes_destroy_cqp(struct nes_device *nesdev)
+{
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       u32 count = 0;
+       u32 cqp_head;
+       unsigned long flags;
+
+       do {
+               if (count++ > 1000)
+                       break;
+               udelay(10);
+       } while (!(nesdev->cqp.sq_head == nesdev->cqp.sq_tail));
+
+       /* Reset CCQ */
+       nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_RESET |
+                       nesdev->ccq.cq_number);
+
+       /* Disable device interrupts */
+       nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
+
+       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+
+       /* Destroy the AEQ */
+       cqp_head = nesdev->cqp.sq_head++;
+       nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_AEQ |
+                       ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8));
+       cqp_wqe->wqe_words[NES_CQP_WQE_COMP_CTX_HIGH_IDX] = 0;
+
+       /* Destroy the NIC CEQ */
+       cqp_head = nesdev->cqp.sq_head++;
+       nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
+                       ((u32)nesdev->nic_ceq_index << 8));
+
+       /* Destroy the CEQ */
+       cqp_head = nesdev->cqp.sq_head++;
+       nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
+                       (nesdev->ceq_index << 8));
+
+       /* Destroy the CCQ */
+       cqp_head = nesdev->cqp.sq_head++;
+       nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CQ);
+       cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->ccq.cq_number |
+                       ((u32)nesdev->ceq_index << 16));
+
+       /* Destroy CQP */
+       cqp_head = nesdev->cqp.sq_head++;
+       nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_QP |
+                       NES_CQP_QP_TYPE_CQP);
+       cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->cqp.qp_id);
+
+       barrier();
+       /* Ring doorbell (5 WQEs) */
+       nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x05800000 | nesdev->cqp.qp_id);
+
+       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+
+       /* wait for the CCQ, CEQ, and AEQ to get destroyed */
+       count = 0;
+       do {
+               if (count++ > 1000) {
+                       printk(KERN_ERR PFX "Function%d: Error destroying CCQ, CEQ, and AEQ\n",
+                                       PCI_FUNC(nesdev->pcidev->devfn));
+                       break;
+               }
+               udelay(10);
+       } while (((nes_read_indexed(nesdev,
+                       NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15 << 8)) != 0));
+
+       /* dump the QP status value */
+       nes_debug(NES_DBG_SHUTDOWN, "Function%d: QP Status = 0x%08X\n",
+                       PCI_FUNC(nesdev->pcidev->devfn),
+                       nes_read_indexed(nesdev,
+                       NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
+
+       kfree(nesdev->nes_cqp_requests);
+
+       /* Free the control structures */
+       pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
+                       nesdev->cqp.sq_pbase);
+
+       return 0;
+}
+
+
+/**
+ * nes_init_phy
+ */
+int nes_init_phy(struct nes_device *nesdev)
+{
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 counter = 0;
+       u32 mac_index = nesdev->mac_index;
+       u32 tx_config;
+       u16 phy_data;
+
+       if (nesadapter->OneG_Mode) {
+               nes_debug(NES_DBG_PHY, "1G PHY, mac_index = %d.\n", mac_index);
+               if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_1G) {
+                       printk(PFX "%s: Programming mdc config for 1G\n", __FUNCTION__);
+                       tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
+                       tx_config |= 0x04;
+                       nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
+               }
+
+               nes_read_1G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 1 phy address %u = 0x%X.\n",
+                               nesadapter->phy_index[mac_index], phy_data);
+               nes_write_1G_phy_reg(nesdev, 23, nesadapter->phy_index[mac_index],  0xb000);
+
+               /* Reset the PHY */
+               nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], 0x8000);
+               udelay(100);
+               counter = 0;
+               do {
+                       nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
+                       nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
+                       if (counter++ > 100) break;
+               } while (phy_data & 0x8000);
+
+               /* Setting no phy loopback */
+               phy_data &= 0xbfff;
+               phy_data |= 0x1140;
+               nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index],  phy_data);
+               nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
+
+               nes_read_1G_phy_reg(nesdev, 0x17, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x17 = 0x%X.\n", phy_data);
+
+               nes_read_1G_phy_reg(nesdev, 0x1e, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x1e = 0x%X.\n", phy_data);
+
+               /* Setting the interrupt mask */
+               nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
+               nes_write_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], 0xffee);
+
+               nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
+
+               /* turning on flow control */
+               nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
+               nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
+                               (phy_data & ~(0x03E0)) | 0xc00);
+               /* nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
+                               phy_data | 0xc00); */
+               nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
+
+               nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
+               /* Clear Half duplex */
+               nes_write_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index],
+                               phy_data & ~(0x0100));
+               nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
+               nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
+
+               nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
+               nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data | 0x0300);
+       } else {
+               if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) {
+                       /* setup 10G MDIO operation */
+                       tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
+                       tx_config |= 0x14;
+                       nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
+               }
+       }
+       return 0;
+}
+
+
+/**
+ * nes_replenish_nic_rq
+ */
+static void nes_replenish_nic_rq(struct nes_vnic *nesvnic)
+{
+       unsigned long flags;
+       dma_addr_t bus_address;
+       struct sk_buff *skb;
+       struct nes_hw_nic_rq_wqe *nic_rqe;
+       struct nes_hw_nic *nesnic;
+       struct nes_device *nesdev;
+       u32 rx_wqes_posted = 0;
+
+       nesnic = &nesvnic->nic;
+       nesdev = nesvnic->nesdev;
+       spin_lock_irqsave(&nesnic->rq_lock, flags);
+       if (nesnic->replenishing_rq !=0) {
+               if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
+                               (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
+                       atomic_set(&nesvnic->rx_skb_timer_running, 1);
+                       spin_unlock_irqrestore(&nesnic->rq_lock, flags);
+                       nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2);      /* 1/2 second */
+                       add_timer(&nesvnic->rq_wqes_timer);
+               } else
+               spin_unlock_irqrestore(&nesnic->rq_lock, flags);
+               return;
+       }
+       nesnic->replenishing_rq = 1;
+       spin_unlock_irqrestore(&nesnic->rq_lock, flags);
+       do {
+               skb = dev_alloc_skb(nesvnic->max_frame_size);
+               if (skb) {
+                       skb->dev = nesvnic->netdev;
+
+                       bus_address = pci_map_single(nesdev->pcidev,
+                                       skb->data, nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+
+                       nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_head];
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] =
+                                       cpu_to_le32(nesvnic->max_frame_size);
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] =
+                                       cpu_to_le32((u32)bus_address);
+                       nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] =
+                                       cpu_to_le32((u32)((u64)bus_address >> 32));
+                       nesnic->rx_skb[nesnic->rq_head] = skb;
+                       nesnic->rq_head++;
+                       nesnic->rq_head &= nesnic->rq_size - 1;
+                       atomic_dec(&nesvnic->rx_skbs_needed);
+                       barrier();
+                       if (++rx_wqes_posted == 255) {
+                               nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
+                               rx_wqes_posted = 0;
+                       }
+               } else {
+                       spin_lock_irqsave(&nesnic->rq_lock, flags);
+                       if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
+                                       (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
+                               atomic_set(&nesvnic->rx_skb_timer_running, 1);
+                               spin_unlock_irqrestore(&nesnic->rq_lock, flags);
+                               nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2);      /* 1/2 second */
+                               add_timer(&nesvnic->rq_wqes_timer);
+                       } else
+                               spin_unlock_irqrestore(&nesnic->rq_lock, flags);
+                       break;
+               }
+       } while (atomic_read(&nesvnic->rx_skbs_needed));
+       barrier();
+       if (rx_wqes_posted)
+               nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
+       nesnic->replenishing_rq = 0;
+}
+
+
+/**
+ * nes_rq_wqes_timeout
+ */
+static void nes_rq_wqes_timeout(unsigned long parm)
+{
+       struct nes_vnic *nesvnic = (struct nes_vnic *)parm;
+       printk("%s: Timer fired.\n", __FUNCTION__);
+       atomic_set(&nesvnic->rx_skb_timer_running, 0);
+       if (atomic_read(&nesvnic->rx_skbs_needed))
+               nes_replenish_nic_rq(nesvnic);
+}
+
+
+/**
+ * nes_init_nic_qp
+ */
+int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
+{
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_hw_nic_sq_wqe *nic_sqe;
+       struct nes_hw_nic_qp_context *nic_context;
+       struct sk_buff *skb;
+       struct nes_hw_nic_rq_wqe *nic_rqe;
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       unsigned long flags;
+       void *vmem;
+       dma_addr_t pmem;
+       u64 u64temp;
+       int ret;
+       u32 cqp_head;
+       u32 counter;
+       u32 wqe_count;
+       u8 jumbomode=0;
+
+       /* Allocate fragment, SQ, RQ, and CQ; Reuse CEQ based on the PCI function */
+       nesvnic->nic_mem_size = 256 +
+                       (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag)) +
+                       (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe)) +
+                       (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe)) +
+                       (NES_NIC_WQ_SIZE * 2 * sizeof(struct nes_hw_nic_cqe)) +
+                       sizeof(struct nes_hw_nic_qp_context);
+
+       nesvnic->nic_vbase = pci_alloc_consistent(nesdev->pcidev, nesvnic->nic_mem_size,
+                       &nesvnic->nic_pbase);
+       if (!nesvnic->nic_vbase) {
+               nes_debug(NES_DBG_INIT, "Unable to allocate memory for NIC host descriptor rings\n");
+               return -ENOMEM;
+       }
+       memset(nesvnic->nic_vbase, 0, nesvnic->nic_mem_size);
+       nes_debug(NES_DBG_INIT, "Allocated NIC QP structures at %p (phys = %016lX), size = %u.\n",
+                       nesvnic->nic_vbase, (unsigned long)nesvnic->nic_pbase, nesvnic->nic_mem_size);
+
+       vmem = (void *)(((unsigned long)nesvnic->nic_vbase + (256 - 1)) &
+                       ~(unsigned long)(256 - 1));
+       pmem = (dma_addr_t)(((unsigned long long)nesvnic->nic_pbase + (256 - 1)) &
+                       ~(unsigned long long)(256 - 1));
+
+       /* Setup the first Fragment buffers */
+       nesvnic->nic.first_frag_vbase = vmem;
+
+       for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
+               nesvnic->nic.frag_paddr[counter] = pmem;
+               pmem += sizeof(struct nes_first_frag);
+       }
+
+       /* setup the SQ */
+       vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag));
+
+       nesvnic->nic.sq_vbase = (void *)vmem;
+       nesvnic->nic.sq_pbase = pmem;
+       nesvnic->nic.sq_head = 0;
+       nesvnic->nic.sq_tail = 0;
+       nesvnic->nic.sq_size = NES_NIC_WQ_SIZE;
+       for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
+               nic_sqe = &nesvnic->nic.sq_vbase[counter];
+               nic_sqe->wqe_words[NES_NIC_SQ_WQE_MISC_IDX] =
+                               cpu_to_le32(NES_NIC_SQ_WQE_DISABLE_CHKSUM |
+                               NES_NIC_SQ_WQE_COMPLETION);
+               nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX] =
+                               cpu_to_le32((u32)NES_FIRST_FRAG_SIZE << 16);
+               nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX] =
+                               cpu_to_le32((u32)nesvnic->nic.frag_paddr[counter]);
+               nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX] =
+                               cpu_to_le32((u32)((u64)nesvnic->nic.frag_paddr[counter] >> 32));
+       }
+
+       nesvnic->get_cqp_request = nes_get_cqp_request;
+       nesvnic->post_cqp_request = nes_post_cqp_request;
+       nesvnic->mcrq_mcast_filter = NULL;
+
+       spin_lock_init(&nesvnic->nic.sq_lock);
+       spin_lock_init(&nesvnic->nic.rq_lock);
+
+       /* setup the RQ */
+       vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
+       pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
+
+
+       nesvnic->nic.rq_vbase = vmem;
+       nesvnic->nic.rq_pbase = pmem;
+       nesvnic->nic.rq_head = 0;
+       nesvnic->nic.rq_tail = 0;
+       nesvnic->nic.rq_size = NES_NIC_WQ_SIZE;
+
+       /* setup the CQ */
+       vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
+       pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
+
+       if (nesdev->nesadapter->netdev_count > 2)
+               nesvnic->mcrq_qp_id = nesvnic->nic_index + 32;
+       else
+               nesvnic->mcrq_qp_id = nesvnic->nic.qp_id + 4;
+
+       nesvnic->nic_cq.cq_vbase = vmem;
+       nesvnic->nic_cq.cq_pbase = pmem;
+       nesvnic->nic_cq.cq_head = 0;
+       nesvnic->nic_cq.cq_size = NES_NIC_WQ_SIZE * 2;
+
+       nesvnic->nic_cq.ce_handler = nes_nic_napi_ce_handler;
+
+       /* Send CreateCQ request to CQP */
+       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+       cqp_head = nesdev->cqp.sq_head;
+
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
+                       NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
+                       ((u32)nesvnic->nic_cq.cq_size << 16));
+       cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(
+                       nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16));
+       u64temp = (u64)nesvnic->nic_cq.cq_pbase;
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =  0;
+       u64temp = (unsigned long)&nesvnic->nic_cq;
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] =  cpu_to_le32((u32)(u64temp >> 1));
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
+                       cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
+       if (++cqp_head >= nesdev->cqp.sq_size)
+               cqp_head = 0;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+       /* Send CreateQP request to CQP */
+       nic_context = (void *)(&nesvnic->nic_cq.cq_vbase[nesvnic->nic_cq.cq_size]);
+       nic_context->context_words[NES_NIC_CTX_MISC_IDX] =
+                       cpu_to_le32((u32)NES_NIC_CTX_SIZE |
+                       ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 12));
+       nes_debug(NES_DBG_INIT, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
+                       nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE),
+                       nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE));
+       if (nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE) != 0) {
+               nic_context->context_words[NES_NIC_CTX_MISC_IDX] |= cpu_to_le32(NES_NIC_BACK_STORE);
+       }
+
+       u64temp = (u64)nesvnic->nic.sq_pbase;
+       nic_context->context_words[NES_NIC_CTX_SQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
+       nic_context->context_words[NES_NIC_CTX_SQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
+       u64temp = (u64)nesvnic->nic.rq_pbase;
+       nic_context->context_words[NES_NIC_CTX_RQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
+       nic_context->context_words[NES_NIC_CTX_RQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
+
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_CREATE_QP |
+                       NES_CQP_QP_TYPE_NIC);
+       cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesvnic->nic.qp_id);
+       u64temp = (u64)nesvnic->nic_cq.cq_pbase +
+                       (nesvnic->nic_cq.cq_size * sizeof(struct nes_hw_nic_cqe));
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
+
+       if (++cqp_head >= nesdev->cqp.sq_size)
+               cqp_head = 0;
+       nesdev->cqp.sq_head = cqp_head;
+
+       barrier();
+
+       /* Ring doorbell (2 WQEs) */
+       nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
+
+       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+       nes_debug(NES_DBG_INIT, "Waiting for create NIC QP%u to complete.\n",
+                       nesvnic->nic.qp_id);
+
+       ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
+                       NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_INIT, "Create NIC QP%u completed, wait_event_timeout ret = %u.\n",
+                       nesvnic->nic.qp_id, ret);
+       if (!ret) {
+               nes_debug(NES_DBG_INIT, "NIC QP%u create timeout expired\n", nesvnic->nic.qp_id);
+               pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
+                               nesvnic->nic_pbase);
+               return -EIO;
+       }
+
+       /* Populate the RQ */
+       for (counter = 0; counter < (NES_NIC_WQ_SIZE - 1); counter++) {
+               skb = dev_alloc_skb(nesvnic->max_frame_size);
+               if (!skb) {
+                       nes_debug(NES_DBG_INIT, "%s: out of memory for receive skb\n", netdev->name);
+
+                       nes_destroy_nic_qp(nesvnic);
+                       return -ENOMEM;
+               }
+
+               skb->dev = netdev;
+
+               pmem = pci_map_single(nesdev->pcidev, skb->data,
+                               nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+
+               nic_rqe = &nesvnic->nic.rq_vbase[counter];
+               nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] = cpu_to_le32(nesvnic->max_frame_size);
+               nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
+               nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] = cpu_to_le32((u32)pmem);
+               nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] = cpu_to_le32((u32)((u64)pmem >> 32));
+               nesvnic->nic.rx_skb[counter] = skb;
+       }
+
+       wqe_count = NES_NIC_WQ_SIZE - 1;
+       nesvnic->nic.rq_head = wqe_count;
+       barrier();
+       do {
+               counter = min(wqe_count, ((u32)255));
+               wqe_count -= counter;
+               nes_write32(nesdev->regs+NES_WQE_ALLOC, (counter << 24) | nesvnic->nic.qp_id);
+       } while (wqe_count);
+       init_timer(&nesvnic->rq_wqes_timer);
+       nesvnic->rq_wqes_timer.function = nes_rq_wqes_timeout;
+       nesvnic->rq_wqes_timer.data = (unsigned long)nesvnic;
+       nes_debug(NES_DBG_INIT, "NAPI support Enabled\n");
+
+       if (nesdev->nesadapter->et_use_adaptive_rx_coalesce)
+       {
+               nes_nic_init_timer(nesdev);
+               if (netdev->mtu > 1500)
+                       jumbomode = 1;
+                nes_nic_init_timer_defaults(nesdev, jumbomode);
+       }
+
+       return 0;
+}
+
+
+/**
+ * nes_destroy_nic_qp
+ */
+void nes_destroy_nic_qp(struct nes_vnic *nesvnic)
+{
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_hw_nic_rq_wqe *nic_rqe;
+       u64 wqe_frag;
+       u32 cqp_head;
+       unsigned long flags;
+       int ret;
+
+       /* Free remaining NIC receive buffers */
+       while (nesvnic->nic.rq_head != nesvnic->nic.rq_tail) {
+               nic_rqe = &nesvnic->nic.rq_vbase[nesvnic->nic.rq_tail];
+               wqe_frag = (u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
+               wqe_frag |= ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
+               pci_unmap_single(nesdev->pcidev, (dma_addr_t)wqe_frag,
+                               nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+               dev_kfree_skb(nesvnic->nic.rx_skb[nesvnic->nic.rq_tail++]);
+               nesvnic->nic.rq_tail &= (nesvnic->nic.rq_size - 1);
+       }
+
+       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+
+       /* Destroy NIC QP */
+       cqp_head = nesdev->cqp.sq_head;
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+               (NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_NIC));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+               nesvnic->nic.qp_id);
+
+       if (++cqp_head >= nesdev->cqp.sq_size)
+               cqp_head = 0;
+
+       cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+
+       /* Destroy NIC CQ */
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+               (NES_CQP_DESTROY_CQ | ((u32)nesvnic->nic_cq.cq_size << 16)));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+               (nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16)));
+
+       if (++cqp_head >= nesdev->cqp.sq_size)
+               cqp_head = 0;
+
+       nesdev->cqp.sq_head = cqp_head;
+       barrier();
+
+       /* Ring doorbell (2 WQEs) */
+       nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
+
+       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+       nes_debug(NES_DBG_SHUTDOWN, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
+                       " cqp.sq_tail=%u, cqp.sq_size=%u\n",
+                       cqp_head, nesdev->cqp.sq_head,
+                       nesdev->cqp.sq_tail, nesdev->cqp.sq_size);
+
+       ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
+                       NES_EVENT_TIMEOUT);
+
+       nes_debug(NES_DBG_SHUTDOWN, "Destroy NIC QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
+                       " cqp.sq_head=%u, cqp.sq_tail=%u\n",
+                       ret, cqp_head, nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
+       if (!ret) {
+               nes_debug(NES_DBG_SHUTDOWN, "NIC QP%u destroy timeout expired\n",
+                               nesvnic->nic.qp_id);
+       }
+
+       pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
+                       nesvnic->nic_pbase);
+}
+
+/**
+ * nes_napi_isr
+ */
+int nes_napi_isr(struct nes_device *nesdev)
+{
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 int_stat;
+
+       if (nesdev->napi_isr_ran) {
+               /* interrupt status has already been read in ISR */
+               int_stat = nesdev->int_stat;
+       } else {
+               int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
+               nesdev->int_stat = int_stat;
+               nesdev->napi_isr_ran = 1;
+       }
+
+       int_stat &= nesdev->int_req;
+       /* iff NIC, process here, else wait for DPC */
+       if ((int_stat) && ((int_stat & 0x0000ff00) == int_stat)) {
+               nesdev->napi_isr_ran = 0;
+               nes_write32(nesdev->regs+NES_INT_STAT,
+                               (int_stat &
+                               ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)));
+
+               /* Process the CEQs */
+               nes_process_ceq(nesdev, &nesdev->nesadapter->ceq[nesdev->nic_ceq_index]);
+
+               if (unlikely((((nesadapter->et_rx_coalesce_usecs_irq) &&
+                                          (!nesadapter->et_use_adaptive_rx_coalesce)) ||
+                                         ((nesadapter->et_use_adaptive_rx_coalesce) &&
+                                          (nesdev->deepcq_count > nesadapter->et_pkt_rate_low)))) ) {
+                       if ((nesdev->int_req & NES_INT_TIMER) == 0) {
+                               /* Enable Periodic timer interrupts */
+                               nesdev->int_req |= NES_INT_TIMER;
+                               /* ack any pending periodic timer interrupts so we don't get an immediate interrupt */
+                               /* TODO: need to also ack other unused periodic timer values, get from nesadapter */
+                               nes_write32(nesdev->regs+NES_TIMER_STAT,
+                                               nesdev->timer_int_req  | ~(nesdev->nesadapter->timer_int_req));
+                               nes_write32(nesdev->regs+NES_INTF_INT_MASK,
+                                               ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
+                       }
+
+                       if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
+                       {
+                               nes_nic_init_timer(nesdev);
+                       }
+                       /* Enable interrupts, except CEQs */
+                       nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
+               } else {
+                       /* Enable interrupts, make sure timer is off */
+                       nesdev->int_req &= ~NES_INT_TIMER;
+                       nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
+                       nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
+                       nesadapter->tune_timer.timer_in_use_old = 0;
+               }
+               nesdev->deepcq_count = 0;
+               return 1;
+       } else {
+               return 0;
+       }
+}
+
+
+/**
+ * nes_dpc
+ */
+void nes_dpc(unsigned long param)
+{
+       struct nes_device *nesdev = (struct nes_device *)param;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 counter;
+       u32 loop_counter = 0;
+       u32 int_status_bit;
+       u32 int_stat;
+       u32 timer_stat;
+       u32 temp_int_stat;
+       u32 intf_int_stat;
+       u32 debug_error;
+       u32 processed_intf_int = 0;
+       u16 processed_timer_int = 0;
+       u16 completion_ints = 0;
+       u16 timer_ints = 0;
+
+       /* nes_debug(NES_DBG_ISR, "\n"); */
+
+       do {
+               timer_stat = 0;
+               if (nesdev->napi_isr_ran) {
+                       nesdev->napi_isr_ran = 0;
+                       int_stat = nesdev->int_stat;
+               } else
+                       int_stat = nes_read32(nesdev->regs+NES_INT_STAT);
+               if (processed_intf_int != 0)
+                       int_stat &= nesdev->int_req & ~NES_INT_INTF;
+               else
+                       int_stat &= nesdev->int_req;
+               if (processed_timer_int == 0) {
+                       processed_timer_int = 1;
+                       if (int_stat & NES_INT_TIMER) {
+                               timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
+                               if ((timer_stat & nesdev->timer_int_req) == 0) {
+                                       int_stat &= ~NES_INT_TIMER;
+                               }
+                       }
+               } else {
+                       int_stat &= ~NES_INT_TIMER;
+               }
+
+               if (int_stat) {
+                       if (int_stat & ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
+                                       NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)) {
+                               /* Ack the interrupts */
+                               nes_write32(nesdev->regs+NES_INT_STAT,
+                                               (int_stat & ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
+                                               NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)));
+                       }
+
+                       temp_int_stat = int_stat;
+                       for (counter = 0, int_status_bit = 1; counter < 16; counter++) {
+                               if (int_stat & int_status_bit) {
+                                       nes_process_ceq(nesdev, &nesadapter->ceq[counter]);
+                                       temp_int_stat &= ~int_status_bit;
+                                       completion_ints = 1;
+                               }
+                               if (!(temp_int_stat & 0x0000ffff))
+                                       break;
+                               int_status_bit <<= 1;
+                       }
+
+                       /* Process the AEQ for this pci function */
+                       int_status_bit = 1 << (16 + PCI_FUNC(nesdev->pcidev->devfn));
+                       if (int_stat & int_status_bit) {
+                               nes_process_aeq(nesdev, &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)]);
+                       }
+
+                       /* Process the MAC interrupt for this pci function */
+                       int_status_bit = 1 << (24 + nesdev->mac_index);
+                       if (int_stat & int_status_bit) {
+                               nes_process_mac_intr(nesdev, nesdev->mac_index);
+                       }
+
+                       if (int_stat & NES_INT_TIMER) {
+                               if (timer_stat & nesdev->timer_int_req) {
+                                       nes_write32(nesdev->regs + NES_TIMER_STAT,
+                                                       (timer_stat & nesdev->timer_int_req) |
+                                                       ~(nesdev->nesadapter->timer_int_req));
+                                       timer_ints = 1;
+                               }
+                       }
+
+                       if (int_stat & NES_INT_INTF) {
+                               processed_intf_int = 1;
+                               intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
+                               intf_int_stat &= nesdev->intf_int_req;
+                               if (NES_INTF_INT_CRITERR & intf_int_stat) {
+                                       debug_error = nes_read_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS);
+                                       printk(KERN_ERR PFX "Critical Error reported by device!!! 0x%02X\n",
+                                                       (u16)debug_error);
+                                       nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS,
+                                                       0x01010000 | (debug_error & 0x0000ffff));
+                                       /* BUG(); */
+                                       if (crit_err_count++ > 10)
+                                               nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 1 << 0x17);
+                               }
+                               if (NES_INTF_INT_PCIERR & intf_int_stat) {
+                                       printk(KERN_ERR PFX "PCI Error reported by device!!!\n");
+                                       BUG();
+                               }
+                               if (NES_INTF_INT_AEQ_OFLOW & intf_int_stat) {
+                                       printk(KERN_ERR PFX "AEQ Overflow reported by device!!!\n");
+                                       BUG();
+                               }
+                               nes_write32(nesdev->regs+NES_INTF_INT_STAT, intf_int_stat);
+                       }
+
+                       if (int_stat & NES_INT_TSW) {
+                       }
+               }
+               /* Don't use the interface interrupt bit stay in loop */
+               int_stat &= ~NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
+                               NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3;
+       } while ((int_stat != 0) && (loop_counter++ < MAX_DPC_ITERATIONS));
+
+       if (timer_ints == 1) {
+               if ((nesadapter->et_rx_coalesce_usecs_irq) || (nesadapter->et_use_adaptive_rx_coalesce)) {
+                       if (completion_ints == 0) {
+                               nesdev->timer_only_int_count++;
+                               if (nesdev->timer_only_int_count>=nesadapter->timer_int_limit) {
+                                       nesdev->timer_only_int_count = 0;
+                                       nesdev->int_req &= ~NES_INT_TIMER;
+                                       nes_write32(nesdev->regs + NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
+                                       nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
+                                       nesdev->nesadapter->tune_timer.timer_in_use_old = 0;
+                               } else {
+                                       nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff|(~nesdev->int_req));
+                               }
+                       } else {
+                               if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
+                               {
+                                       nes_nic_init_timer(nesdev);
+                               }
+                               nesdev->timer_only_int_count = 0;
+                               nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff|(~nesdev->int_req));
+                       }
+               } else {
+                       nesdev->timer_only_int_count = 0;
+                       nesdev->int_req &= ~NES_INT_TIMER;
+                       nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
+                       nes_write32(nesdev->regs+NES_TIMER_STAT,
+                                       nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
+                       nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
+               }
+       } else {
+               if ( (completion_ints == 1) &&
+                        (((nesadapter->et_rx_coalesce_usecs_irq) &&
+                          (!nesadapter->et_use_adaptive_rx_coalesce)) ||
+                         ((nesdev->deepcq_count > nesadapter->et_pkt_rate_low) &&
+                          (nesadapter->et_use_adaptive_rx_coalesce) )) ) {
+                       /* nes_debug(NES_DBG_ISR, "Enabling periodic timer interrupt.\n" ); */
+                       nesdev->timer_only_int_count = 0;
+                       nesdev->int_req |= NES_INT_TIMER;
+                       nes_write32(nesdev->regs+NES_TIMER_STAT,
+                                       nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
+                       nes_write32(nesdev->regs+NES_INTF_INT_MASK,
+                                       ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
+                       nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
+               } else {
+                       nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
+               }
+       }
+       nesdev->deepcq_count = 0;
+}
+
+
+/**
+ * nes_process_ceq
+ */
+void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq)
+{
+       u64 u64temp;
+       struct nes_hw_cq *cq;
+       u32 head;
+       u32 ceq_size;
+
+       /* nes_debug(NES_DBG_CQ, "\n"); */
+       head = ceq->ceq_head;
+       ceq_size = ceq->ceq_size;
+
+       do {
+               if (le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX]) &
+                               NES_CEQE_VALID) {
+                       u64temp = (((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX])))<<32) |
+                                               ((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_LOW_IDX])));
+                       u64temp <<= 1;
+                       cq = *((struct nes_hw_cq **)&u64temp);
+                       /* nes_debug(NES_DBG_CQ, "pCQ = %p\n", cq); */
+                       barrier();
+                       ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX] = 0;
+
+                       /* call the event handler */
+                       cq->ce_handler(nesdev, cq);
+
+                       if (++head >= ceq_size)
+                               head = 0;
+               } else {
+                       break;
+               }
+
+       } while (1);
+
+       ceq->ceq_head = head;
+}
+
+
+/**
+ * nes_process_aeq
+ */
+void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq)
+{
+//     u64 u64temp;
+       u32 head;
+       u32 aeq_size;
+       u32 aeqe_misc;
+       u32 aeqe_cq_id;
+       struct nes_hw_aeqe volatile *aeqe;
+
+       head = aeq->aeq_head;
+       aeq_size = aeq->aeq_size;
+
+       do {
+               aeqe = &aeq->aeq_vbase[head];
+               if ((le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]) & NES_AEQE_VALID) == 0)
+                       break;
+               aeqe_misc  = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
+               aeqe_cq_id = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]);
+               if (aeqe_misc & (NES_AEQE_QP|NES_AEQE_CQ)) {
+                       if (aeqe_cq_id >= NES_FIRST_QPN) {
+                               /* dealing with an accelerated QP related AE */
+//                             u64temp = (((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])))<<32) |
+//                                     ((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX])));
+                               nes_process_iwarp_aeqe(nesdev, (struct nes_hw_aeqe *)aeqe);
+                       } else {
+                               /* TODO: dealing with a CQP related AE */
+                               nes_debug(NES_DBG_AEQ, "Processing CQP related AE, misc = 0x%04X\n",
+                                               (u16)(aeqe_misc >> 16));
+                       }
+               }
+
+               aeqe->aeqe_words[NES_AEQE_MISC_IDX] = 0;
+
+               if (++head >= aeq_size)
+                       head = 0;
+       }
+       while (1);
+       aeq->aeq_head = head;
+}
+
+static void nes_reset_link(struct nes_device *nesdev, u32 mac_index)
+{
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 reset_value;
+       u32 i=0;
+       u32 u32temp;
+
+       if (nesadapter->hw_rev == NE020_REV) {
+               return;
+       }
+       mh_detected++;
+
+       reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
+
+       if ((mac_index == 0) || ((mac_index == 1) && (nesadapter->OneG_Mode)))
+               reset_value |= 0x0000001d;
+       else
+               reset_value |= 0x0000002d;
+
+       if (4 <= (nesadapter->link_interrupt_count[mac_index] / ((u16)NES_MAX_LINK_INTERRUPTS))) {
+               if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
+                       nesadapter->link_interrupt_count[0] = 0;
+                       nesadapter->link_interrupt_count[1] = 0;
+                       u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
+                       if (0x00000040 & u32temp)
+                               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
+                       else
+                               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
+
+                       reset_value |= 0x0000003d;
+               }
+               nesadapter->link_interrupt_count[mac_index] = 0;
+       }
+
+       nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
+
+       while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
+                       & 0x00000040) != 0x00000040) && (i++ < 5000));
+
+       if (0x0000003d == (reset_value & 0x0000003d)) {
+               u32 pcs_control_status0, pcs_control_status1;
+
+               for (i = 0; i < 10; i++) {
+                       pcs_control_status0 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0);
+                       pcs_control_status1 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
+                       if (((0x0F000000 == (pcs_control_status0 & 0x0F000000))
+                            && (pcs_control_status0 & 0x00100000))
+                           || ((0x0F000000 == (pcs_control_status1 & 0x0F000000))
+                               && (pcs_control_status1 & 0x00100000)))
+                               continue;
+                       else
+                               break;
+               }
+               if (10 == i) {
+                       u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
+                       if (0x00000040 & u32temp)
+                               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
+                       else
+                               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
+
+                       nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
+
+                       while (((nes_read32(nesdev->regs + NES_SOFTWARE_RESET)
+                                & 0x00000040) != 0x00000040) && (i++ < 5000));
+               }
+       }
+}
+
+/**
+ * nes_process_mac_intr
+ */
+void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
+{
+       unsigned long flags;
+       u32 pcs_control_status;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_vnic *nesvnic;
+       u32 mac_status;
+       u32 mac_index = nesdev->mac_index;
+       u32 u32temp;
+       u16 phy_data;
+       u16 temp_phy_data;
+
+       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+       if (nesadapter->mac_sw_state[mac_number] != NES_MAC_SW_IDLE) {
+               spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+               return;
+       }
+       nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_INTERRUPT;
+       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+
+       /* ack the MAC interrupt */
+       mac_status = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200));
+       /* Clear the interrupt */
+       nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200), mac_status);
+
+       nes_debug(NES_DBG_PHY, "MAC%u interrupt status = 0x%X.\n", mac_number, mac_status);
+
+       if (mac_status & (NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT)) {
+               nesdev->link_status_interrupts++;
+               if (0 == (++nesadapter->link_interrupt_count[mac_index] % ((u16)NES_MAX_LINK_INTERRUPTS))) {
+                       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+                       nes_reset_link(nesdev, mac_index);
+                       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+               }
+               /* read the PHY interrupt status register */
+               if (nesadapter->OneG_Mode) {
+                       do {
+                               nes_read_1G_phy_reg(nesdev, 0x1a,
+                                               nesadapter->phy_index[mac_index], &phy_data);
+                               nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1a = 0x%X.\n",
+                                               nesadapter->phy_index[mac_index], phy_data);
+                       } while (phy_data&0x8000);
+
+                       temp_phy_data = 0;
+                       do {
+                               nes_read_1G_phy_reg(nesdev, 0x11,
+                                               nesadapter->phy_index[mac_index], &phy_data);
+                               nes_debug(NES_DBG_PHY, "Phy%d data from register 0x11 = 0x%X.\n",
+                                               nesadapter->phy_index[mac_index], phy_data);
+                               if (temp_phy_data == phy_data)
+                                       break;
+                               temp_phy_data = phy_data;
+                       } while (1);
+
+                       nes_read_1G_phy_reg(nesdev, 0x1e,
+                                       nesadapter->phy_index[mac_index], &phy_data);
+                       nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1e = 0x%X.\n",
+                                       nesadapter->phy_index[mac_index], phy_data);
+
+                       nes_read_1G_phy_reg(nesdev, 1,
+                                       nesadapter->phy_index[mac_index], &phy_data);
+                       nes_debug(NES_DBG_PHY, "1G phy%u data from register 1 = 0x%X\n",
+                                       nesadapter->phy_index[mac_index], phy_data);
+
+                       if (temp_phy_data & 0x1000) {
+                               nes_debug(NES_DBG_PHY, "The Link is up according to the PHY\n");
+                               phy_data = 4;
+                       } else {
+                               nes_debug(NES_DBG_PHY, "The Link is down according to the PHY\n");
+                       }
+               }
+               nes_debug(NES_DBG_PHY, "Eth SERDES Common Status: 0=0x%08X, 1=0x%08X\n",
+                               nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0),
+                               nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0+0x200));
+               pcs_control_status = nes_read_indexed(nesdev,
+                               NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index&1)*0x200));
+               pcs_control_status = nes_read_indexed(nesdev,
+                               NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index&1)*0x200));
+               nes_debug(NES_DBG_PHY, "PCS PHY Control/Status%u: 0x%08X\n",
+                               mac_index, pcs_control_status);
+               if (nesadapter->OneG_Mode) {
+                       u32temp = 0x01010000;
+                       if (nesadapter->port_count > 2) {
+                               u32temp |= 0x02020000;
+                       }
+                       if ((pcs_control_status & u32temp)!= u32temp) {
+                               phy_data = 0;
+                               nes_debug(NES_DBG_PHY, "PCS says the link is down\n");
+                       }
+               } else if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) {
+                       nes_read_10G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index]);
+                       temp_phy_data = (u16)nes_read_indexed(nesdev,
+                                                               NES_IDX_MAC_MDIO_CONTROL);
+                       u32temp = 20;
+                       do {
+                               nes_read_10G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index]);
+                               phy_data = (u16)nes_read_indexed(nesdev,
+                                                               NES_IDX_MAC_MDIO_CONTROL);
+                               if ((phy_data == temp_phy_data) || (!(--u32temp)))
+                                       break;
+                               temp_phy_data = phy_data;
+                       } while (1);
+                       nes_debug(NES_DBG_PHY, "%s: Phy data = 0x%04X, link was %s.\n",
+                               __FUNCTION__, phy_data, nesadapter->mac_link_down ? "DOWN" : "UP");
+
+               } else {
+                       phy_data = (0x0f0f0000 == (pcs_control_status & 0x0f1f0000)) ? 4 : 0;
+               }
+
+               if (phy_data & 0x0004) {
+                       nesadapter->mac_link_down[mac_index] = 0;
+                       list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
+                               nes_debug(NES_DBG_PHY, "The Link is UP!!.  linkup was %d\n",
+                                               nesvnic->linkup);
+                               if (nesvnic->linkup == 0) {
+                                       printk(PFX "The Link is now up for port %u, netdev %p.\n",
+                                                       mac_index, nesvnic->netdev);
+                                       if (netif_queue_stopped(nesvnic->netdev))
+                                               netif_start_queue(nesvnic->netdev);
+                                       nesvnic->linkup = 1;
+                                       netif_carrier_on(nesvnic->netdev);
+                               }
+                       }
+               } else {
+                       nesadapter->mac_link_down[mac_index] = 1;
+                       list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
+                               nes_debug(NES_DBG_PHY, "The Link is Down!!. linkup was %d\n",
+                                               nesvnic->linkup);
+                               if (nesvnic->linkup == 1) {
+                                       printk(PFX "The Link is now down for port %u, netdev %p.\n",
+                                                       mac_index, nesvnic->netdev);
+                                       if (!(netif_queue_stopped(nesvnic->netdev)))
+                                               netif_stop_queue(nesvnic->netdev);
+                                       nesvnic->linkup = 0;
+                                       netif_carrier_off(nesvnic->netdev);
+                               }
+                       }
+               }
+       }
+
+       nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_IDLE;
+}
+
+
+
+void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
+{
+       struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
+
+       netif_rx_schedule(nesdev->netdev[nesvnic->netdev_index], &nesvnic->napi);
+}
+
+
+/* The MAX_RQES_TO_PROCESS defines how many max read requests to complete before
+* getting out of nic_ce_handler
+*/
+#define        MAX_RQES_TO_PROCESS     384
+
+/**
+ * nes_nic_ce_handler
+ */
+void nes_nic_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
+{
+       u64 u64temp;
+       dma_addr_t bus_address;
+       struct nes_hw_nic *nesnic;
+       struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_nic_rq_wqe *nic_rqe;
+       struct nes_hw_nic_sq_wqe *nic_sqe;
+       struct sk_buff *skb;
+       struct sk_buff *rx_skb;
+       __le16 *wqe_fragment_length;
+       u32 head;
+       u32 cq_size;
+       u32 rx_pkt_size;
+       u32 cqe_count=0;
+       u32 cqe_errv;
+       u32 cqe_misc;
+       u16 wqe_fragment_index = 1;     /* first fragment (0) is used by copy buffer */
+       u16 vlan_tag;
+       u16 pkt_type;
+       u16 rqes_processed = 0;
+       u8 sq_cqes = 0;
+
+       head = cq->cq_head;
+       cq_size = cq->cq_size;
+       cq->cqes_pending = 1;
+       do {
+               if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]) &
+                               NES_NIC_CQE_VALID) {
+                       nesnic = &nesvnic->nic;
+                       cqe_misc = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]);
+                       if (cqe_misc & NES_NIC_CQE_SQ) {
+                               sq_cqes++;
+                               wqe_fragment_index = 1;
+                               nic_sqe = &nesnic->sq_vbase[nesnic->sq_tail];
+                               skb = nesnic->tx_skb[nesnic->sq_tail];
+                               wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
+                               /* bump past the vlan tag */
+                               wqe_fragment_length++;
+                               if (le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
+                                       u64temp = (u64) le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX+wqe_fragment_index*2]);
+                                       u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX+wqe_fragment_index*2]))<<32;
+                                       bus_address = (dma_addr_t)u64temp;
+                                       if (test_and_clear_bit(nesnic->sq_tail, nesnic->first_frag_overflow)) {
+                                               pci_unmap_single(nesdev->pcidev,
+                                                               bus_address,
+                                                               le16_to_cpu(wqe_fragment_length[wqe_fragment_index++]),
+                                                               PCI_DMA_TODEVICE);
+                                       }
+                                       for (; wqe_fragment_index < 5; wqe_fragment_index++) {
+                                               if (wqe_fragment_length[wqe_fragment_index]) {
+                                                       u64temp = le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX+wqe_fragment_index*2]);
+                                                       u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX+wqe_fragment_index*2]))<<32;
+                                                       bus_address = (dma_addr_t)u64temp;
+                                                       pci_unmap_page(nesdev->pcidev,
+                                                                       bus_address,
+                                                                       le16_to_cpu(wqe_fragment_length[wqe_fragment_index]),
+                                                                       PCI_DMA_TODEVICE);
+                                               } else
+                                                       break;
+                                       }
+                                       if (skb)
+                                               dev_kfree_skb_any(skb);
+                               }
+                               nesnic->sq_tail++;
+                               nesnic->sq_tail &= nesnic->sq_size-1;
+                               if (sq_cqes > 128) {
+                                       barrier();
+                               /* restart the queue if it had been stopped */
+                               if (netif_queue_stopped(nesvnic->netdev))
+                                       netif_wake_queue(nesvnic->netdev);
+                                       sq_cqes = 0;
+                               }
+                       } else {
+                               rqes_processed ++;
+
+                               cq->rx_cqes_completed++;
+                               cq->rx_pkts_indicated++;
+                               rx_pkt_size = cqe_misc & 0x0000ffff;
+                               nic_rqe = &nesnic->rq_vbase[nesnic->rq_tail];
+                               /* Get the skb */
+                               rx_skb = nesnic->rx_skb[nesnic->rq_tail];
+                               nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_tail];
+                               bus_address = (dma_addr_t)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
+                               bus_address += ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
+                               pci_unmap_single(nesdev->pcidev, bus_address,
+                                               nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
+                               /* rx_skb->tail = rx_skb->data + rx_pkt_size; */
+                               /* rx_skb->len = rx_pkt_size; */
+                               rx_skb->len = 0;  /* TODO: see if this is necessary */
+                               skb_put(rx_skb, rx_pkt_size);
+                               rx_skb->protocol = eth_type_trans(rx_skb, nesvnic->netdev);
+                               nesnic->rq_tail++;
+                               nesnic->rq_tail &= nesnic->rq_size - 1;
+
+                               atomic_inc(&nesvnic->rx_skbs_needed);
+                               if (atomic_read(&nesvnic->rx_skbs_needed) > (nesvnic->nic.rq_size>>1)) {
+                                       nes_write32(nesdev->regs+NES_CQE_ALLOC,
+                                                       cq->cq_number | (cqe_count << 16));
+//                                     nesadapter->tune_timer.cq_count += cqe_count;
+                                       nesdev->currcq_count += cqe_count;
+                                       cqe_count = 0;
+                                       nes_replenish_nic_rq(nesvnic);
+                               }
+                               pkt_type = (u16)(le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX]));
+                               cqe_errv = (cqe_misc & NES_NIC_CQE_ERRV_MASK) >> NES_NIC_CQE_ERRV_SHIFT;
+                               rx_skb->ip_summed = CHECKSUM_NONE;
+
+                               if ((NES_PKT_TYPE_TCPV4_BITS == (pkt_type & NES_PKT_TYPE_TCPV4_MASK)) ||
+                                               (NES_PKT_TYPE_UDPV4_BITS == (pkt_type & NES_PKT_TYPE_UDPV4_MASK))) {
+                                       if ((cqe_errv &
+                                                       (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_TCPUDP_CSUM_ERR |
+                                                       NES_NIC_ERRV_BITS_IPH_ERR | NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
+                                               if (nesvnic->rx_checksum_disabled == 0) {
+                                                       rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
+                                               }
+                                       } else
+                                               nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
+                                                               " errv = 0x%X, pkt_type = 0x%X.\n",
+                                                               nesvnic->netdev->name, cqe_errv, pkt_type);
+
+                               } else if ((pkt_type & NES_PKT_TYPE_IPV4_MASK) == NES_PKT_TYPE_IPV4_BITS) {
+                                       if ((cqe_errv &
+                                                       (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_IPH_ERR |
+                                                       NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
+                                               if (nesvnic->rx_checksum_disabled == 0) {
+                                                       rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
+                                                       /* nes_debug(NES_DBG_CQ, "%s: Reporting successfully checksummed IPv4 packet.\n",
+                                                                 nesvnic->netdev->name); */
+                                               }
+                                       } else
+                                               nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
+                                                               " errv = 0x%X, pkt_type = 0x%X.\n",
+                                                               nesvnic->netdev->name, cqe_errv, pkt_type);
+                                       }
+                               /* nes_debug(NES_DBG_CQ, "pkt_type=%x, APBVT_MASK=%x\n",
+                                                       pkt_type, (pkt_type & NES_PKT_TYPE_APBVT_MASK)); */
+
+                               if ((pkt_type & NES_PKT_TYPE_APBVT_MASK) == NES_PKT_TYPE_APBVT_BITS) {
+                                       nes_cm_recv(rx_skb, nesvnic->netdev);
+                               } else {
+                                       if ((cqe_misc & NES_NIC_CQE_TAG_VALID) && (nesvnic->vlan_grp != NULL)) {
+                                               vlan_tag = (u16)(le32_to_cpu(
+                                                               cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX])
+                                                               >> 16);
+                                               nes_debug(NES_DBG_CQ, "%s: Reporting stripped VLAN packet. Tag = 0x%04X\n",
+                                                               nesvnic->netdev->name, vlan_tag);
+                                               nes_vlan_rx(rx_skb, nesvnic->vlan_grp, vlan_tag);
+                                       } else {
+                                               nes_netif_rx(rx_skb);
+                                       }
+                               }
+
+                               nesvnic->netdev->last_rx = jiffies;
+                               /* nesvnic->netstats.rx_packets++; */
+                               /* nesvnic->netstats.rx_bytes += rx_pkt_size; */
+                       }
+
+                       cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX] = 0;
+                       /* Accounting... */
+                       cqe_count++;
+                       if (++head >= cq_size)
+                               head = 0;
+                       if (cqe_count == 255) {
+                               /* Replenish Nic CQ */
+                               nes_write32(nesdev->regs+NES_CQE_ALLOC,
+                                               cq->cq_number | (cqe_count << 16));
+//                             nesdev->nesadapter->tune_timer.cq_count += cqe_count;
+                               nesdev->currcq_count += cqe_count;
+                               cqe_count = 0;
+                       }
+
+                       if (cq->rx_cqes_completed >= nesvnic->budget)
+                               break;
+               } else {
+                       cq->cqes_pending = 0;
+                       break;
+               }
+
+       } while (1);
+
+       if (sq_cqes) {
+               barrier();
+               /* restart the queue if it had been stopped */
+               if (netif_queue_stopped(nesvnic->netdev))
+                       netif_wake_queue(nesvnic->netdev);
+       }
+
+       cq->cq_head = head;
+       /* nes_debug(NES_DBG_CQ, "CQ%u Processed = %u cqes, new head = %u.\n",
+                       cq->cq_number, cqe_count, cq->cq_head); */
+       cq->cqe_allocs_pending = cqe_count;
+       if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
+       {
+//             nesdev->nesadapter->tune_timer.cq_count += cqe_count;
+               nesdev->currcq_count += cqe_count;
+               nes_nic_tune_timer(nesdev);
+       }
+       if (atomic_read(&nesvnic->rx_skbs_needed))
+               nes_replenish_nic_rq(nesvnic);
+       }
+
+
+/**
+ * nes_cqp_ce_handler
+ */
+void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
+{
+       u64 u64temp;
+       unsigned long flags;
+       struct nes_hw_cqp *cqp = NULL;
+       struct nes_cqp_request *cqp_request;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       u32 head;
+       u32 cq_size;
+       u32 cqe_count=0;
+       u32 error_code;
+       /* u32 counter; */
+
+       head = cq->cq_head;
+       cq_size = cq->cq_size;
+
+       do {
+               /* process the CQE */
+               /* nes_debug(NES_DBG_CQP, "head=%u cqe_words=%08X\n", head,
+                         le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])); */
+
+               if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]) & NES_CQE_VALID) {
+                       u64temp = (((u64)(le32_to_cpu(cq->cq_vbase[head].
+                                       cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX])))<<32) |
+                                       ((u64)(le32_to_cpu(cq->cq_vbase[head].
+                                       cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX])));
+                       cqp = *((struct nes_hw_cqp **)&u64temp);
+
+                       error_code = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_ERROR_CODE_IDX]);
+                       if (error_code) {
+                               nes_debug(NES_DBG_CQP, "Bad Completion code for opcode 0x%02X from CQP,"
+                                               " Major/Minor codes = 0x%04X:%04X.\n",
+                                               le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])&0x3f,
+                                               (u16)(error_code >> 16),
+                                               (u16)error_code);
+                               nes_debug(NES_DBG_CQP, "cqp: qp_id=%u, sq_head=%u, sq_tail=%u\n",
+                                               cqp->qp_id, cqp->sq_head, cqp->sq_tail);
+                       }
+
+                       u64temp = (((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
+                                       wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX])))<<32) |
+                                       ((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
+                                       wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX])));
+                       cqp_request = *((struct nes_cqp_request **)&u64temp);
+                       if (cqp_request) {
+                               if (cqp_request->waiting) {
+                                       /* nes_debug(NES_DBG_CQP, "%s: Waking up requestor\n"); */
+                                       cqp_request->major_code = (u16)(error_code >> 16);
+                                       cqp_request->minor_code = (u16)error_code;
+                                       barrier();
+                                       cqp_request->request_done = 1;
+                                       wake_up(&cqp_request->waitq);
+                                       if (atomic_dec_and_test(&cqp_request->refcount)) {
+                                               nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
+                                                               cqp_request,
+                                                               le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
+                                               if (cqp_request->dynamic) {
+                                                       kfree(cqp_request);
+                                               } else {
+                                                       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                                                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                                       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                                               }
+                                       }
+                               } else if (cqp_request->callback) {
+                                       /* Envoke the callback routine */
+                                       cqp_request->cqp_callback(nesdev, cqp_request);
+                                       if (cqp_request->dynamic) {
+                                               kfree(cqp_request);
+                                       } else {
+                                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                                       }
+                               } else {
+                                       nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
+                                                       cqp_request,
+                                                       le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
+                                       if (cqp_request->dynamic) {
+                                               kfree(cqp_request);
+                                       } else {
+                                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                                       }
+                               }
+                       } else {
+                               wake_up(&nesdev->cqp.waitq);
+                       }
+
+                       cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX] = 0;
+                       nes_write32(nesdev->regs+NES_CQE_ALLOC, cq->cq_number | (1 << 16));
+                       if (++cqp->sq_tail >= cqp->sq_size)
+                               cqp->sq_tail = 0;
+
+                       /* Accounting... */
+                       cqe_count++;
+                       if (++head >= cq_size)
+                               head = 0;
+               } else {
+                       break;
+               }
+       } while (1);
+       cq->cq_head = head;
+
+       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+       while ((!list_empty(&nesdev->cqp_pending_reqs)) &&
+                       ((((nesdev->cqp.sq_tail+nesdev->cqp.sq_size)-nesdev->cqp.sq_head) &
+                       (nesdev->cqp.sq_size - 1)) != 1)) {
+               cqp_request = list_entry(nesdev->cqp_pending_reqs.next,
+                               struct nes_cqp_request, list);
+               list_del_init(&cqp_request->list);
+               head = nesdev->cqp.sq_head++;
+               nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
+               cqp_wqe = &nesdev->cqp.sq_vbase[head];
+               memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
+               barrier();
+               cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX] =
+                       cpu_to_le32((u32)((unsigned long)cqp_request));
+               cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX] =
+                       cpu_to_le32((u32)(upper_32_bits((unsigned long)cqp_request)));
+               nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) put on CQPs SQ wqe%u.\n",
+                               cqp_request, le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f, head);
+               /* Ring doorbell (1 WQEs) */
+               barrier();
+               nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x01800000 | nesdev->cqp.qp_id);
+       }
+       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+
+       /* Arm the CCQ */
+       nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
+                       cq->cq_number);
+       nes_read32(nesdev->regs+NES_CQE_ALLOC);
+}
+
+
+/**
+ * nes_process_iwarp_aeqe
+ */
+void nes_process_iwarp_aeqe(struct nes_device *nesdev, struct nes_hw_aeqe *aeqe)
+{
+       u64 context;
+       u64 aeqe_context = 0;
+       unsigned long flags;
+       struct nes_qp *nesqp;
+       int resource_allocated;
+       /* struct iw_cm_id *cm_id; */
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct ib_event ibevent;
+       /* struct iw_cm_event cm_event; */
+       u32 aeq_info;
+       u32 next_iwarp_state = 0;
+       u16 async_event_id;
+       u8 tcp_state;
+       u8 iwarp_state;
+
+       nes_debug(NES_DBG_AEQ, "\n");
+       aeq_info = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
+       if ((NES_AEQE_INBOUND_RDMA&aeq_info) || (!(NES_AEQE_QP&aeq_info))) {
+               context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
+               context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
+       } else {
+               aeqe_context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
+               aeqe_context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
+               context = (unsigned long)nesadapter->qp_table[le32_to_cpu(
+                                               aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
+               BUG_ON(!context);
+       }
+
+       async_event_id = (u16)aeq_info;
+       tcp_state = (aeq_info & NES_AEQE_TCP_STATE_MASK) >> NES_AEQE_TCP_STATE_SHIFT;
+       iwarp_state = (aeq_info & NES_AEQE_IWARP_STATE_MASK) >> NES_AEQE_IWARP_STATE_SHIFT;
+       nes_debug(NES_DBG_AEQ, "aeid = 0x%04X, qp-cq id = %d, aeqe = %p,"
+                       " Tcp state = %s, iWARP state = %s\n",
+                       async_event_id,
+                       le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), aeqe,
+                       nes_tcp_state_str[tcp_state], nes_iwarp_state_str[iwarp_state]);
+
+
+       switch (async_event_id) {
+               case NES_AEQE_AEID_LLP_FIN_RECEIVED:
+                       nesqp = *((struct nes_qp **)&context);
+                       if (atomic_inc_return(&nesqp->close_timer_started) == 1) {
+                               nesqp->cm_id->add_ref(nesqp->cm_id);
+                               nes_add_ref(&nesqp->ibqp);
+                               schedule_nes_timer(nesqp->cm_node, (struct sk_buff *)nesqp,
+                                               NES_TIMER_TYPE_CLOSE, 1, 0);
+                               nes_debug(NES_DBG_AEQ, "QP%u Not decrementing QP refcount (%d),"
+                                               " need ae to finish up, original_last_aeq = 0x%04X."
+                                               " last_aeq = 0x%04X, scheduling timer. TCP state = %d\n",
+                                               nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
+                                               async_event_id, nesqp->last_aeq, tcp_state);
+                       }
+                       if ((tcp_state != NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
+                                       (nesqp->ibqp_state != IB_QPS_RTS)) {
+                               /* FIN Received but tcp state or IB state moved on,
+                                               should expect a close complete */
+                               return;
+                       }
+               case NES_AEQE_AEID_LLP_CLOSE_COMPLETE:
+               case NES_AEQE_AEID_LLP_CONNECTION_RESET:
+               case NES_AEQE_AEID_TERMINATE_SENT:
+               case NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE:
+               case NES_AEQE_AEID_RESET_SENT:
+                       nesqp = *((struct nes_qp **)&context);
+                       if (async_event_id == NES_AEQE_AEID_RESET_SENT) {
+                               tcp_state = NES_AEQE_TCP_STATE_CLOSED;
+                       }
+                       nes_add_ref(&nesqp->ibqp);
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+
+                       if ((tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
+                                       (tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT)) {
+                               nesqp->hte_added = 0;
+                               spin_unlock_irqrestore(&nesqp->lock, flags);
+                               nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u to remove hte\n",
+                                               nesqp->hwqp.qp_id);
+                               nes_hw_modify_qp(nesdev, nesqp,
+                                               NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_DEL_HTE, 0);
+                               spin_lock_irqsave(&nesqp->lock, flags);
+                       }
+
+                       if ((nesqp->ibqp_state == IB_QPS_RTS) &&
+                                       ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
+                                       (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
+                               switch (nesqp->hw_iwarp_state) {
+                                       case NES_AEQE_IWARP_STATE_RTS:
+                                               next_iwarp_state = NES_CQP_QP_IWARP_STATE_CLOSING;
+                                               nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_CLOSING;
+                                               break;
+                                       case NES_AEQE_IWARP_STATE_TERMINATE:
+                                               next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE;
+                                               nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_TERMINATE;
+                                               if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
+                                                       next_iwarp_state |= 0x02000000;
+                                                       nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
+                                               }
+                                               break;
+                                       default:
+                                               next_iwarp_state = 0;
+                               }
+                               spin_unlock_irqrestore(&nesqp->lock, flags);
+                               if (next_iwarp_state) {
+                                       nes_add_ref(&nesqp->ibqp);
+                                       nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
+                                                       " also added another reference\n",
+                                                       nesqp->hwqp.qp_id, next_iwarp_state);
+                                       nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
+                               }
+                               nes_cm_disconn(nesqp);
+                       } else {
+                               if (async_event_id ==  NES_AEQE_AEID_LLP_FIN_RECEIVED) {
+                                       /* FIN Received but ib state not RTS,
+                                                       close complete will be on its way */
+                                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return;
+                               }
+                               spin_unlock_irqrestore(&nesqp->lock, flags);
+                               if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
+                                       next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000;
+                                       nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
+                                       nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
+                                                       " also added another reference\n",
+                                                       nesqp->hwqp.qp_id, next_iwarp_state);
+                                       nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
+                               }
+                               nes_cm_disconn(nesqp);
+                       }
+                       break;
+               case NES_AEQE_AEID_LLP_TERMINATE_RECEIVED:
+                       nesqp = *((struct nes_qp **)&context);
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TERMINATE_RECEIVED"
+                                       " event on QP%u \n  Q2 Data:\n",
+                                       nesqp->hwqp.qp_id);
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_FATAL;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       if ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
+                                       ((nesqp->ibqp_state == IB_QPS_RTS)&&
+                                       (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
+                               nes_add_ref(&nesqp->ibqp);
+                               nes_cm_disconn(nesqp);
+                       } else {
+                               nesqp->in_disconnect = 0;
+                               wake_up(&nesqp->kick_waitq);
+                       }
+                       break;
+               case NES_AEQE_AEID_LLP_TOO_MANY_RETRIES:
+                       nesqp = *((struct nes_qp **)&context);
+                       nes_add_ref(&nesqp->ibqp);
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_ERROR;
+                       nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
+                       nesqp->last_aeq = async_event_id;
+                       if (nesqp->cm_id) {
+                               nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
+                                               " event on QP%u, remote IP = 0x%08X \n",
+                                               nesqp->hwqp.qp_id,
+                                               ntohl(nesqp->cm_id->remote_addr.sin_addr.s_addr));
+                       } else {
+                               nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
+                                               " event on QP%u \n",
+                                               nesqp->hwqp.qp_id);
+                       }
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       next_iwarp_state = NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_RESET;
+                       nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_FATAL;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       break;
+               case NES_AEQE_AEID_AMP_BAD_STAG_INDEX:
+                       if (NES_AEQE_INBOUND_RDMA&aeq_info) {
+                               nesqp = nesadapter->qp_table[le32_to_cpu(
+                                               aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
+                       } else {
+                               /* TODO: get the actual WQE and mask off wqe index */
+                               context &= ~((u64)511);
+                               nesqp = *((struct nes_qp **)&context);
+                       }
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_BAD_STAG_INDEX event on QP%u\n",
+                                       nesqp->hwqp.qp_id);
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_ACCESS_ERR;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       break;
+               case NES_AEQE_AEID_AMP_UNALLOCATED_STAG:
+                       nesqp = *((struct nes_qp **)&context);
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_UNALLOCATED_STAG event on QP%u\n",
+                                       nesqp->hwqp.qp_id);
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_ACCESS_ERR;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       break;
+               case NES_AEQE_AEID_PRIV_OPERATION_DENIED:
+                       nesqp = nesadapter->qp_table[le32_to_cpu(aeqe->aeqe_words
+                                       [NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_PRIV_OPERATION_DENIED event on QP%u,"
+                                       " nesqp = %p, AE reported %p\n",
+                                       nesqp->hwqp.qp_id, nesqp, *((struct nes_qp **)&context));
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_ACCESS_ERR;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       break;
+               case NES_AEQE_AEID_CQ_OPERATION_ERROR:
+                       context <<= 1;
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u, %p\n",
+                                       le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), (void *)(unsigned long)context);
+                       resource_allocated = nes_is_resource_allocated(nesadapter, nesadapter->allocated_cqs,
+                                       le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
+                       if (resource_allocated) {
+                               printk(KERN_ERR PFX "%s: Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u\n",
+                                               __FUNCTION__, le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
+                       }
+                       break;
+               case NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
+                       nesqp = nesadapter->qp_table[le32_to_cpu(
+                                       aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG"
+                                       "_FOR_AVAILABLE_BUFFER event on QP%u\n",
+                                       nesqp->hwqp.qp_id);
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_ACCESS_ERR;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       /* tell cm to disconnect, cm will queue work to thread */
+                       nes_add_ref(&nesqp->ibqp);
+                       nes_cm_disconn(nesqp);
+                       break;
+               case NES_AEQE_AEID_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
+                       nesqp = *((struct nes_qp **)&context);
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_INVALID_MSN"
+                                       "_NO_BUFFER_AVAILABLE event on QP%u\n",
+                                       nesqp->hwqp.qp_id);
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_FATAL;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       /* tell cm to disconnect, cm will queue work to thread */
+                       nes_add_ref(&nesqp->ibqp);
+                       nes_cm_disconn(nesqp);
+                       break;
+               case NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR:
+                       nesqp = *((struct nes_qp **)&context);
+                       spin_lock_irqsave(&nesqp->lock, flags);
+                       nesqp->hw_iwarp_state = iwarp_state;
+                       nesqp->hw_tcp_state = tcp_state;
+                       nesqp->last_aeq = async_event_id;
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+                       nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR"
+                                       " event on QP%u \n  Q2 Data:\n",
+                                       nesqp->hwqp.qp_id);
+                       if (nesqp->ibqp.event_handler) {
+                               ibevent.device = nesqp->ibqp.device;
+                               ibevent.element.qp = &nesqp->ibqp;
+                               ibevent.event = IB_EVENT_QP_FATAL;
+                               nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
+                       }
+                       /* tell cm to disconnect, cm will queue work to thread */
+                       nes_add_ref(&nesqp->ibqp);
+                       nes_cm_disconn(nesqp);
+                       break;
+                       /* TODO: additional AEs need to be here */
+               default:
+                       nes_debug(NES_DBG_AEQ, "Processing an iWARP related AE for QP, misc = 0x%04X\n",
+                                       async_event_id);
+                       break;
+       }
+
+}
+
+
+/**
+ * nes_iwarp_ce_handler
+ */
+void nes_iwarp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *hw_cq)
+{
+       struct nes_cq *nescq = container_of(hw_cq, struct nes_cq, hw_cq);
+
+       /* nes_debug(NES_DBG_CQ, "Processing completion event for iWARP CQ%u.\n",
+                       nescq->hw_cq.cq_number); */
+       nes_write32(nesdev->regs+NES_CQ_ACK, nescq->hw_cq.cq_number);
+
+       if (nescq->ibcq.comp_handler)
+               nescq->ibcq.comp_handler(&nescq->ibcq, nescq->ibcq.cq_context);
+
+       return;
+}
+
+
+/**
+ * nes_manage_apbvt()
+ */
+int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
+               u32 nic_index, u32 add_port)
+{
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       unsigned long flags;
+       struct nes_cqp_request *cqp_request;
+       int ret = 0;
+       u16 major_code;
+
+       /* Send manage APBVT request to CQP */
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
+               return -ENOMEM;
+       }
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+
+       nes_debug(NES_DBG_QP, "%s APBV for local port=%u(0x%04x), nic_index=%u\n",
+                       (add_port == NES_MANAGE_APBVT_ADD) ? "ADD" : "DEL",
+                       accel_local_port, accel_local_port, nic_index);
+
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, (NES_CQP_MANAGE_APBVT |
+                       ((add_port == NES_MANAGE_APBVT_ADD) ? NES_CQP_APBVT_ADD : 0)));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+                       ((nic_index << NES_CQP_APBVT_NIC_SHIFT) | accel_local_port));
+
+       nes_debug(NES_DBG_QP, "Waiting for CQP completion for APBVT.\n");
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       if (add_port == NES_MANAGE_APBVT_ADD)
+               ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
+                               NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_QP, "Completed, ret=%u,  CQP Major:Minor codes = 0x%04X:0x%04X\n",
+                       ret, cqp_request->major_code, cqp_request->minor_code);
+       major_code = cqp_request->major_code;
+       if (atomic_dec_and_test(&cqp_request->refcount)) {
+               if (cqp_request->dynamic) {
+                       kfree(cqp_request);
+               } else {
+                       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+               }
+       }
+       if (!ret)
+               return -ETIME;
+       else if (major_code)
+               return -EIO;
+       else
+               return 0;
+}
+
+
+/**
+ * nes_manage_arp_cache
+ */
+void nes_manage_arp_cache(struct net_device *netdev, unsigned char *mac_addr,
+               u32 ip_addr, u32 action)
+{
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev;
+       struct nes_cqp_request *cqp_request;
+       int arp_index;
+
+       nesdev = nesvnic->nesdev;
+       arp_index = nes_arp_table(nesdev, ip_addr, mac_addr, action);
+       if (arp_index == -1) {
+               return;
+       }
+
+       /* update the ARP entry */
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_NETDEV, "Failed to get a cqp_request.\n");
+               return;
+       }
+       cqp_request->waiting = 0;
+       cqp_wqe = &cqp_request->cqp_wqe;
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
+                       NES_CQP_MANAGE_ARP_CACHE | NES_CQP_ARP_PERM);
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(
+                       (u32)PCI_FUNC(nesdev->pcidev->devfn) << NES_CQP_ARP_AEQ_INDEX_SHIFT);
+       cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(arp_index);
+
+       if (action == NES_ARP_ADD) {
+               cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(NES_CQP_ARP_VALID);
+               cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = cpu_to_le32(
+                               (((u32)mac_addr[2]) << 24) | (((u32)mac_addr[3]) << 16) |
+                               (((u32)mac_addr[4]) << 8) | (u32)mac_addr[5]);
+               cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = cpu_to_le32(
+                               (((u32)mac_addr[0]) << 16) | (u32)mac_addr[1]);
+       } else {
+               cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = 0;
+               cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = 0;
+       }
+
+       nes_debug(NES_DBG_NETDEV, "Not waiting for CQP, cqp.sq_head=%u, cqp.sq_tail=%u\n",
+                       nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
+
+       atomic_set(&cqp_request->refcount, 1);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+}
+
+
+/**
+ * flush_wqes
+ */
+void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
+               u32 which_wq, u32 wait_completion)
+{
+       unsigned long flags;
+       struct nes_cqp_request *cqp_request;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       int ret;
+
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
+               return;
+       }
+       if (wait_completion) {
+               cqp_request->waiting = 1;
+               atomic_set(&cqp_request->refcount, 2);
+       } else {
+               cqp_request->waiting = 0;
+       }
+       cqp_wqe = &cqp_request->cqp_wqe;
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] =
+                       cpu_to_le32(NES_CQP_FLUSH_WQES | which_wq);
+       cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesqp->hwqp.qp_id);
+
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       if (wait_completion) {
+               /* Wait for CQP */
+               ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
+                               NES_EVENT_TIMEOUT);
+               nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u,"
+                               " CQP Major:Minor codes = 0x%04X:0x%04X\n",
+                               ret, cqp_request->major_code, cqp_request->minor_code);
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+       }
+}
diff --git a/drivers/infiniband/hw/nes/nes_hw.h b/drivers/infiniband/hw/nes/nes_hw.h
new file mode 100644 (file)
index 0000000..1e10df5
--- /dev/null
@@ -0,0 +1,1206 @@
+/*
+* Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+*
+* This software is available to you under a choice of one of two
+* licenses.  You may choose to be licensed under the terms of the GNU
+* General Public License (GPL) Version 2, available from the file
+* COPYING in the main directory of this source tree, or the
+* OpenIB.org BSD license below:
+*
+*     Redistribution and use in source and binary forms, with or
+*     without modification, are permitted provided that the following
+*     conditions are met:
+*
+*      - Redistributions of source code must retain the above
+*        copyright notice, this list of conditions and the following
+*        disclaimer.
+*
+*      - Redistributions in binary form must reproduce the above
+*        copyright notice, this list of conditions and the following
+*        disclaimer in the documentation and/or other materials
+*        provided with the distribution.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+* SOFTWARE.
+*/
+
+#ifndef __NES_HW_H
+#define __NES_HW_H
+
+#define NES_PHY_TYPE_1G   2
+#define NES_PHY_TYPE_IRIS 3
+#define NES_PHY_TYPE_PUMA_10G  6
+
+#define NES_MULTICAST_PF_MAX 8
+
+enum pci_regs {
+       NES_INT_STAT = 0x0000,
+       NES_INT_MASK = 0x0004,
+       NES_INT_PENDING = 0x0008,
+       NES_INTF_INT_STAT = 0x000C,
+       NES_INTF_INT_MASK = 0x0010,
+       NES_TIMER_STAT = 0x0014,
+       NES_PERIODIC_CONTROL = 0x0018,
+       NES_ONE_SHOT_CONTROL = 0x001C,
+       NES_EEPROM_COMMAND = 0x0020,
+       NES_EEPROM_DATA = 0x0024,
+       NES_FLASH_COMMAND = 0x0028,
+       NES_FLASH_DATA  = 0x002C,
+       NES_SOFTWARE_RESET = 0x0030,
+       NES_CQ_ACK = 0x0034,
+       NES_WQE_ALLOC = 0x0040,
+       NES_CQE_ALLOC = 0x0044,
+};
+
+enum indexed_regs {
+       NES_IDX_CREATE_CQP_LOW = 0x0000,
+       NES_IDX_CREATE_CQP_HIGH = 0x0004,
+       NES_IDX_QP_CONTROL = 0x0040,
+       NES_IDX_FLM_CONTROL = 0x0080,
+       NES_IDX_INT_CPU_STATUS = 0x00a0,
+       NES_IDX_GPIO_CONTROL = 0x00f0,
+       NES_IDX_GPIO_DATA = 0x00f4,
+       NES_IDX_TCP_CONFIG0 = 0x01e4,
+       NES_IDX_TCP_TIMER_CONFIG = 0x01ec,
+       NES_IDX_TCP_NOW = 0x01f0,
+       NES_IDX_QP_MAX_CFG_SIZES = 0x0200,
+       NES_IDX_QP_CTX_SIZE = 0x0218,
+       NES_IDX_TCP_TIMER_SIZE0 = 0x0238,
+       NES_IDX_TCP_TIMER_SIZE1 = 0x0240,
+       NES_IDX_ARP_CACHE_SIZE = 0x0258,
+       NES_IDX_CQ_CTX_SIZE = 0x0260,
+       NES_IDX_MRT_SIZE = 0x0278,
+       NES_IDX_PBL_REGION_SIZE = 0x0280,
+       NES_IDX_IRRQ_COUNT = 0x02b0,
+       NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x02f0,
+       NES_IDX_RX_WINDOW_BUFFER_SIZE = 0x0300,
+       NES_IDX_DST_IP_ADDR = 0x0400,
+       NES_IDX_PCIX_DIAG = 0x08e8,
+       NES_IDX_MPP_DEBUG = 0x0a00,
+       NES_IDX_PORT_RX_DISCARDS = 0x0a30,
+       NES_IDX_PORT_TX_DISCARDS = 0x0a34,
+       NES_IDX_MPP_LB_DEBUG = 0x0b00,
+       NES_IDX_DENALI_CTL_22 = 0x1058,
+       NES_IDX_MAC_TX_CONTROL = 0x2000,
+       NES_IDX_MAC_TX_CONFIG = 0x2004,
+       NES_IDX_MAC_TX_PAUSE_QUANTA = 0x2008,
+       NES_IDX_MAC_RX_CONTROL = 0x200c,
+       NES_IDX_MAC_RX_CONFIG = 0x2010,
+       NES_IDX_MAC_EXACT_MATCH_BOTTOM = 0x201c,
+       NES_IDX_MAC_MDIO_CONTROL = 0x2084,
+       NES_IDX_MAC_TX_OCTETS_LOW = 0x2100,
+       NES_IDX_MAC_TX_OCTETS_HIGH = 0x2104,
+       NES_IDX_MAC_TX_FRAMES_LOW = 0x2108,
+       NES_IDX_MAC_TX_FRAMES_HIGH = 0x210c,
+       NES_IDX_MAC_TX_PAUSE_FRAMES = 0x2118,
+       NES_IDX_MAC_TX_ERRORS = 0x2138,
+       NES_IDX_MAC_RX_OCTETS_LOW = 0x213c,
+       NES_IDX_MAC_RX_OCTETS_HIGH = 0x2140,
+       NES_IDX_MAC_RX_FRAMES_LOW = 0x2144,
+       NES_IDX_MAC_RX_FRAMES_HIGH = 0x2148,
+       NES_IDX_MAC_RX_BC_FRAMES_LOW = 0x214c,
+       NES_IDX_MAC_RX_MC_FRAMES_HIGH = 0x2150,
+       NES_IDX_MAC_RX_PAUSE_FRAMES = 0x2154,
+       NES_IDX_MAC_RX_SHORT_FRAMES = 0x2174,
+       NES_IDX_MAC_RX_OVERSIZED_FRAMES = 0x2178,
+       NES_IDX_MAC_RX_JABBER_FRAMES = 0x217c,
+       NES_IDX_MAC_RX_CRC_ERR_FRAMES = 0x2180,
+       NES_IDX_MAC_RX_LENGTH_ERR_FRAMES = 0x2184,
+       NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES = 0x2188,
+       NES_IDX_MAC_INT_STATUS = 0x21f0,
+       NES_IDX_MAC_INT_MASK = 0x21f4,
+       NES_IDX_PHY_PCS_CONTROL_STATUS0 = 0x2800,
+       NES_IDX_PHY_PCS_CONTROL_STATUS1 = 0x2a00,
+       NES_IDX_ETH_SERDES_COMMON_CONTROL0 = 0x2808,
+       NES_IDX_ETH_SERDES_COMMON_CONTROL1 = 0x2a08,
+       NES_IDX_ETH_SERDES_COMMON_STATUS0 = 0x280c,
+       NES_IDX_ETH_SERDES_COMMON_STATUS1 = 0x2a0c,
+       NES_IDX_ETH_SERDES_TX_EMP0 = 0x2810,
+       NES_IDX_ETH_SERDES_TX_EMP1 = 0x2a10,
+       NES_IDX_ETH_SERDES_TX_DRIVE0 = 0x2814,
+       NES_IDX_ETH_SERDES_TX_DRIVE1 = 0x2a14,
+       NES_IDX_ETH_SERDES_RX_MODE0 = 0x2818,
+       NES_IDX_ETH_SERDES_RX_MODE1 = 0x2a18,
+       NES_IDX_ETH_SERDES_RX_SIGDET0 = 0x281c,
+       NES_IDX_ETH_SERDES_RX_SIGDET1 = 0x2a1c,
+       NES_IDX_ETH_SERDES_BYPASS0 = 0x2820,
+       NES_IDX_ETH_SERDES_BYPASS1 = 0x2a20,
+       NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0 = 0x2824,
+       NES_IDX_ETH_SERDES_LOOPBACK_CONTROL1 = 0x2a24,
+       NES_IDX_ETH_SERDES_RX_EQ_CONTROL0 = 0x2828,
+       NES_IDX_ETH_SERDES_RX_EQ_CONTROL1 = 0x2a28,
+       NES_IDX_ETH_SERDES_RX_EQ_STATUS0 = 0x282c,
+       NES_IDX_ETH_SERDES_RX_EQ_STATUS1 = 0x2a2c,
+       NES_IDX_ETH_SERDES_CDR_RESET0 = 0x2830,
+       NES_IDX_ETH_SERDES_CDR_RESET1 = 0x2a30,
+       NES_IDX_ETH_SERDES_CDR_CONTROL0 = 0x2834,
+       NES_IDX_ETH_SERDES_CDR_CONTROL1 = 0x2a34,
+       NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE0 = 0x2838,
+       NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE1 = 0x2a38,
+       NES_IDX_ENDNODE0_NSTAT_RX_DISCARD = 0x3080,
+       NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO = 0x3000,
+       NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI = 0x3004,
+       NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO = 0x3008,
+       NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI = 0x300c,
+       NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO = 0x7000,
+       NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI = 0x7004,
+       NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO = 0x7008,
+       NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI = 0x700c,
+       NES_IDX_CM_CONFIG = 0x5100,
+       NES_IDX_NIC_LOGPORT_TO_PHYPORT = 0x6000,
+       NES_IDX_NIC_PHYPORT_TO_USW = 0x6008,
+       NES_IDX_NIC_ACTIVE = 0x6010,
+       NES_IDX_NIC_UNICAST_ALL = 0x6018,
+       NES_IDX_NIC_MULTICAST_ALL = 0x6020,
+       NES_IDX_NIC_MULTICAST_ENABLE = 0x6028,
+       NES_IDX_NIC_BROADCAST_ON = 0x6030,
+       NES_IDX_USED_CHUNKS_TX = 0x60b0,
+       NES_IDX_TX_POOL_SIZE = 0x60b8,
+       NES_IDX_QUAD_HASH_TABLE_SIZE = 0x6148,
+       NES_IDX_PERFECT_FILTER_LOW = 0x6200,
+       NES_IDX_PERFECT_FILTER_HIGH = 0x6204,
+       NES_IDX_IPV4_TCP_REXMITS = 0x7080,
+       NES_IDX_DEBUG_ERROR_CONTROL_STATUS = 0x913c,
+       NES_IDX_DEBUG_ERROR_MASKS0 = 0x9140,
+       NES_IDX_DEBUG_ERROR_MASKS1 = 0x9144,
+       NES_IDX_DEBUG_ERROR_MASKS2 = 0x9148,
+       NES_IDX_DEBUG_ERROR_MASKS3 = 0x914c,
+       NES_IDX_DEBUG_ERROR_MASKS4 = 0x9150,
+       NES_IDX_DEBUG_ERROR_MASKS5 = 0x9154,
+};
+
+#define NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE   1
+#define NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE (1 << 17)
+
+enum nes_cqp_opcodes {
+       NES_CQP_CREATE_QP = 0x00,
+       NES_CQP_MODIFY_QP = 0x01,
+       NES_CQP_DESTROY_QP = 0x02,
+       NES_CQP_CREATE_CQ = 0x03,
+       NES_CQP_MODIFY_CQ = 0x04,
+       NES_CQP_DESTROY_CQ = 0x05,
+       NES_CQP_ALLOCATE_STAG = 0x09,
+       NES_CQP_REGISTER_STAG = 0x0a,
+       NES_CQP_QUERY_STAG = 0x0b,
+       NES_CQP_REGISTER_SHARED_STAG = 0x0c,
+       NES_CQP_DEALLOCATE_STAG = 0x0d,
+       NES_CQP_MANAGE_ARP_CACHE = 0x0f,
+       NES_CQP_SUSPEND_QPS = 0x11,
+       NES_CQP_UPLOAD_CONTEXT = 0x13,
+       NES_CQP_CREATE_CEQ = 0x16,
+       NES_CQP_DESTROY_CEQ = 0x18,
+       NES_CQP_CREATE_AEQ = 0x19,
+       NES_CQP_DESTROY_AEQ = 0x1b,
+       NES_CQP_LMI_ACCESS = 0x20,
+       NES_CQP_FLUSH_WQES = 0x22,
+       NES_CQP_MANAGE_APBVT = 0x23
+};
+
+enum nes_cqp_wqe_word_idx {
+       NES_CQP_WQE_OPCODE_IDX = 0,
+       NES_CQP_WQE_ID_IDX = 1,
+       NES_CQP_WQE_COMP_CTX_LOW_IDX = 2,
+       NES_CQP_WQE_COMP_CTX_HIGH_IDX = 3,
+       NES_CQP_WQE_COMP_SCRATCH_LOW_IDX = 4,
+       NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX = 5,
+};
+
+enum nes_cqp_cq_wqeword_idx {
+       NES_CQP_CQ_WQE_PBL_LOW_IDX = 6,
+       NES_CQP_CQ_WQE_PBL_HIGH_IDX = 7,
+       NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX = 8,
+       NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX = 9,
+       NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX = 10,
+};
+
+enum nes_cqp_stag_wqeword_idx {
+       NES_CQP_STAG_WQE_PBL_BLK_COUNT_IDX = 1,
+       NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX = 6,
+       NES_CQP_STAG_WQE_LEN_LOW_IDX = 7,
+       NES_CQP_STAG_WQE_STAG_IDX = 8,
+       NES_CQP_STAG_WQE_VA_LOW_IDX = 10,
+       NES_CQP_STAG_WQE_VA_HIGH_IDX = 11,
+       NES_CQP_STAG_WQE_PA_LOW_IDX = 12,
+       NES_CQP_STAG_WQE_PA_HIGH_IDX = 13,
+       NES_CQP_STAG_WQE_PBL_LEN_IDX = 14
+};
+
+#define NES_CQP_OP_IWARP_STATE_SHIFT 28
+
+enum nes_cqp_qp_bits {
+       NES_CQP_QP_ARP_VALID = (1<<8),
+       NES_CQP_QP_WINBUF_VALID = (1<<9),
+       NES_CQP_QP_CONTEXT_VALID = (1<<10),
+       NES_CQP_QP_ORD_VALID = (1<<11),
+       NES_CQP_QP_WINBUF_DATAIND_EN = (1<<12),
+       NES_CQP_QP_VIRT_WQS = (1<<13),
+       NES_CQP_QP_DEL_HTE = (1<<14),
+       NES_CQP_QP_CQS_VALID = (1<<15),
+       NES_CQP_QP_TYPE_TSA = 0,
+       NES_CQP_QP_TYPE_IWARP = (1<<16),
+       NES_CQP_QP_TYPE_CQP = (4<<16),
+       NES_CQP_QP_TYPE_NIC = (5<<16),
+       NES_CQP_QP_MSS_CHG = (1<<20),
+       NES_CQP_QP_STATIC_RESOURCES = (1<<21),
+       NES_CQP_QP_IGNORE_MW_BOUND = (1<<22),
+       NES_CQP_QP_VWQ_USE_LMI = (1<<23),
+       NES_CQP_QP_IWARP_STATE_IDLE = (1<<NES_CQP_OP_IWARP_STATE_SHIFT),
+       NES_CQP_QP_IWARP_STATE_RTS = (2<<NES_CQP_OP_IWARP_STATE_SHIFT),
+       NES_CQP_QP_IWARP_STATE_CLOSING = (3<<NES_CQP_OP_IWARP_STATE_SHIFT),
+       NES_CQP_QP_IWARP_STATE_TERMINATE = (5<<NES_CQP_OP_IWARP_STATE_SHIFT),
+       NES_CQP_QP_IWARP_STATE_ERROR = (6<<NES_CQP_OP_IWARP_STATE_SHIFT),
+       NES_CQP_QP_IWARP_STATE_MASK = (7<<NES_CQP_OP_IWARP_STATE_SHIFT),
+       NES_CQP_QP_RESET = (1<<31),
+};
+
+enum nes_cqp_qp_wqe_word_idx {
+       NES_CQP_QP_WQE_CONTEXT_LOW_IDX = 6,
+       NES_CQP_QP_WQE_CONTEXT_HIGH_IDX = 7,
+       NES_CQP_QP_WQE_NEW_MSS_IDX = 15,
+};
+
+enum nes_nic_ctx_bits {
+       NES_NIC_CTX_RQ_SIZE_32 = (3<<8),
+       NES_NIC_CTX_RQ_SIZE_512 = (3<<8),
+       NES_NIC_CTX_SQ_SIZE_32 = (1<<10),
+       NES_NIC_CTX_SQ_SIZE_512 = (3<<10),
+};
+
+enum nes_nic_qp_ctx_word_idx {
+       NES_NIC_CTX_MISC_IDX = 0,
+       NES_NIC_CTX_SQ_LOW_IDX = 2,
+       NES_NIC_CTX_SQ_HIGH_IDX = 3,
+       NES_NIC_CTX_RQ_LOW_IDX = 4,
+       NES_NIC_CTX_RQ_HIGH_IDX = 5,
+};
+
+enum nes_cqp_cq_bits {
+       NES_CQP_CQ_CEQE_MASK = (1<<9),
+       NES_CQP_CQ_CEQ_VALID = (1<<10),
+       NES_CQP_CQ_RESIZE = (1<<11),
+       NES_CQP_CQ_CHK_OVERFLOW = (1<<12),
+       NES_CQP_CQ_4KB_CHUNK = (1<<14),
+       NES_CQP_CQ_VIRT = (1<<15),
+};
+
+enum nes_cqp_stag_bits {
+       NES_CQP_STAG_VA_TO = (1<<9),
+       NES_CQP_STAG_DEALLOC_PBLS = (1<<10),
+       NES_CQP_STAG_PBL_BLK_SIZE = (1<<11),
+       NES_CQP_STAG_MR = (1<<13),
+       NES_CQP_STAG_RIGHTS_LOCAL_READ = (1<<16),
+       NES_CQP_STAG_RIGHTS_LOCAL_WRITE = (1<<17),
+       NES_CQP_STAG_RIGHTS_REMOTE_READ = (1<<18),
+       NES_CQP_STAG_RIGHTS_REMOTE_WRITE = (1<<19),
+       NES_CQP_STAG_RIGHTS_WINDOW_BIND = (1<<20),
+       NES_CQP_STAG_REM_ACC_EN = (1<<21),
+       NES_CQP_STAG_LEAVE_PENDING = (1<<31),
+};
+
+enum nes_cqp_ceq_wqeword_idx {
+       NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX = 1,
+       NES_CQP_CEQ_WQE_PBL_LOW_IDX = 6,
+       NES_CQP_CEQ_WQE_PBL_HIGH_IDX = 7,
+};
+
+enum nes_cqp_ceq_bits {
+       NES_CQP_CEQ_4KB_CHUNK = (1<<14),
+       NES_CQP_CEQ_VIRT = (1<<15),
+};
+
+enum nes_cqp_aeq_wqeword_idx {
+       NES_CQP_AEQ_WQE_ELEMENT_COUNT_IDX = 1,
+       NES_CQP_AEQ_WQE_PBL_LOW_IDX = 6,
+       NES_CQP_AEQ_WQE_PBL_HIGH_IDX = 7,
+};
+
+enum nes_cqp_aeq_bits {
+       NES_CQP_AEQ_4KB_CHUNK = (1<<14),
+       NES_CQP_AEQ_VIRT = (1<<15),
+};
+
+enum nes_cqp_lmi_wqeword_idx {
+       NES_CQP_LMI_WQE_LMI_OFFSET_IDX = 1,
+       NES_CQP_LMI_WQE_FRAG_LOW_IDX = 8,
+       NES_CQP_LMI_WQE_FRAG_HIGH_IDX = 9,
+       NES_CQP_LMI_WQE_FRAG_LEN_IDX = 10,
+};
+
+enum nes_cqp_arp_wqeword_idx {
+       NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX = 6,
+       NES_CQP_ARP_WQE_MAC_HIGH_IDX = 7,
+       NES_CQP_ARP_WQE_REACHABILITY_MAX_IDX = 1,
+};
+
+enum nes_cqp_upload_wqeword_idx {
+       NES_CQP_UPLOAD_WQE_CTXT_LOW_IDX = 6,
+       NES_CQP_UPLOAD_WQE_CTXT_HIGH_IDX = 7,
+       NES_CQP_UPLOAD_WQE_HTE_IDX = 8,
+};
+
+enum nes_cqp_arp_bits {
+       NES_CQP_ARP_VALID = (1<<8),
+       NES_CQP_ARP_PERM = (1<<9),
+};
+
+enum nes_cqp_flush_bits {
+       NES_CQP_FLUSH_SQ = (1<<30),
+       NES_CQP_FLUSH_RQ = (1<<31),
+};
+
+enum nes_cqe_opcode_bits {
+       NES_CQE_STAG_VALID = (1<<6),
+       NES_CQE_ERROR = (1<<7),
+       NES_CQE_SQ = (1<<8),
+       NES_CQE_SE = (1<<9),
+       NES_CQE_PSH = (1<<29),
+       NES_CQE_FIN = (1<<30),
+       NES_CQE_VALID = (1<<31),
+};
+
+
+enum nes_cqe_word_idx {
+       NES_CQE_PAYLOAD_LENGTH_IDX = 0,
+       NES_CQE_COMP_COMP_CTX_LOW_IDX = 2,
+       NES_CQE_COMP_COMP_CTX_HIGH_IDX = 3,
+       NES_CQE_INV_STAG_IDX = 4,
+       NES_CQE_QP_ID_IDX = 5,
+       NES_CQE_ERROR_CODE_IDX = 6,
+       NES_CQE_OPCODE_IDX = 7,
+};
+
+enum nes_ceqe_word_idx {
+       NES_CEQE_CQ_CTX_LOW_IDX = 0,
+       NES_CEQE_CQ_CTX_HIGH_IDX = 1,
+};
+
+enum nes_ceqe_status_bit {
+       NES_CEQE_VALID = (1<<31),
+};
+
+enum nes_int_bits {
+       NES_INT_CEQ0 = (1<<0),
+       NES_INT_CEQ1 = (1<<1),
+       NES_INT_CEQ2 = (1<<2),
+       NES_INT_CEQ3 = (1<<3),
+       NES_INT_CEQ4 = (1<<4),
+       NES_INT_CEQ5 = (1<<5),
+       NES_INT_CEQ6 = (1<<6),
+       NES_INT_CEQ7 = (1<<7),
+       NES_INT_CEQ8 = (1<<8),
+       NES_INT_CEQ9 = (1<<9),
+       NES_INT_CEQ10 = (1<<10),
+       NES_INT_CEQ11 = (1<<11),
+       NES_INT_CEQ12 = (1<<12),
+       NES_INT_CEQ13 = (1<<13),
+       NES_INT_CEQ14 = (1<<14),
+       NES_INT_CEQ15 = (1<<15),
+       NES_INT_AEQ0 = (1<<16),
+       NES_INT_AEQ1 = (1<<17),
+       NES_INT_AEQ2 = (1<<18),
+       NES_INT_AEQ3 = (1<<19),
+       NES_INT_AEQ4 = (1<<20),
+       NES_INT_AEQ5 = (1<<21),
+       NES_INT_AEQ6 = (1<<22),
+       NES_INT_AEQ7 = (1<<23),
+       NES_INT_MAC0 = (1<<24),
+       NES_INT_MAC1 = (1<<25),
+       NES_INT_MAC2 = (1<<26),
+       NES_INT_MAC3 = (1<<27),
+       NES_INT_TSW = (1<<28),
+       NES_INT_TIMER = (1<<29),
+       NES_INT_INTF = (1<<30),
+};
+
+enum nes_intf_int_bits {
+       NES_INTF_INT_PCIERR = (1<<0),
+       NES_INTF_PERIODIC_TIMER = (1<<2),
+       NES_INTF_ONE_SHOT_TIMER = (1<<3),
+       NES_INTF_INT_CRITERR = (1<<14),
+       NES_INTF_INT_AEQ0_OFLOW = (1<<16),
+       NES_INTF_INT_AEQ1_OFLOW = (1<<17),
+       NES_INTF_INT_AEQ2_OFLOW = (1<<18),
+       NES_INTF_INT_AEQ3_OFLOW = (1<<19),
+       NES_INTF_INT_AEQ4_OFLOW = (1<<20),
+       NES_INTF_INT_AEQ5_OFLOW = (1<<21),
+       NES_INTF_INT_AEQ6_OFLOW = (1<<22),
+       NES_INTF_INT_AEQ7_OFLOW = (1<<23),
+       NES_INTF_INT_AEQ_OFLOW = (0xff<<16),
+};
+
+enum nes_mac_int_bits {
+       NES_MAC_INT_LINK_STAT_CHG = (1<<1),
+       NES_MAC_INT_XGMII_EXT = (1<<2),
+       NES_MAC_INT_TX_UNDERFLOW = (1<<6),
+       NES_MAC_INT_TX_ERROR = (1<<7),
+};
+
+enum nes_cqe_allocate_bits {
+       NES_CQE_ALLOC_INC_SELECT = (1<<28),
+       NES_CQE_ALLOC_NOTIFY_NEXT = (1<<29),
+       NES_CQE_ALLOC_NOTIFY_SE = (1<<30),
+       NES_CQE_ALLOC_RESET = (1<<31),
+};
+
+enum nes_nic_rq_wqe_word_idx {
+       NES_NIC_RQ_WQE_LENGTH_1_0_IDX = 0,
+       NES_NIC_RQ_WQE_LENGTH_3_2_IDX = 1,
+       NES_NIC_RQ_WQE_FRAG0_LOW_IDX = 2,
+       NES_NIC_RQ_WQE_FRAG0_HIGH_IDX = 3,
+       NES_NIC_RQ_WQE_FRAG1_LOW_IDX = 4,
+       NES_NIC_RQ_WQE_FRAG1_HIGH_IDX = 5,
+       NES_NIC_RQ_WQE_FRAG2_LOW_IDX = 6,
+       NES_NIC_RQ_WQE_FRAG2_HIGH_IDX = 7,
+       NES_NIC_RQ_WQE_FRAG3_LOW_IDX = 8,
+       NES_NIC_RQ_WQE_FRAG3_HIGH_IDX = 9,
+};
+
+enum nes_nic_sq_wqe_word_idx {
+       NES_NIC_SQ_WQE_MISC_IDX = 0,
+       NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX = 1,
+       NES_NIC_SQ_WQE_LSO_INFO_IDX = 2,
+       NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX = 3,
+       NES_NIC_SQ_WQE_LENGTH_2_1_IDX = 4,
+       NES_NIC_SQ_WQE_LENGTH_4_3_IDX = 5,
+       NES_NIC_SQ_WQE_FRAG0_LOW_IDX = 6,
+       NES_NIC_SQ_WQE_FRAG0_HIGH_IDX = 7,
+       NES_NIC_SQ_WQE_FRAG1_LOW_IDX = 8,
+       NES_NIC_SQ_WQE_FRAG1_HIGH_IDX = 9,
+       NES_NIC_SQ_WQE_FRAG2_LOW_IDX = 10,
+       NES_NIC_SQ_WQE_FRAG2_HIGH_IDX = 11,
+       NES_NIC_SQ_WQE_FRAG3_LOW_IDX = 12,
+       NES_NIC_SQ_WQE_FRAG3_HIGH_IDX = 13,
+       NES_NIC_SQ_WQE_FRAG4_LOW_IDX = 14,
+       NES_NIC_SQ_WQE_FRAG4_HIGH_IDX = 15,
+};
+
+enum nes_iwarp_sq_wqe_word_idx {
+       NES_IWARP_SQ_WQE_MISC_IDX = 0,
+       NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX = 1,
+       NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX = 2,
+       NES_IWARP_SQ_WQE_COMP_CTX_HIGH_IDX = 3,
+       NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX = 4,
+       NES_IWARP_SQ_WQE_COMP_SCRATCH_HIGH_IDX = 5,
+       NES_IWARP_SQ_WQE_INV_STAG_LOW_IDX = 7,
+       NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX = 8,
+       NES_IWARP_SQ_WQE_RDMA_TO_HIGH_IDX = 9,
+       NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX = 10,
+       NES_IWARP_SQ_WQE_RDMA_STAG_IDX = 11,
+       NES_IWARP_SQ_WQE_IMM_DATA_START_IDX = 12,
+       NES_IWARP_SQ_WQE_FRAG0_LOW_IDX = 16,
+       NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX = 17,
+       NES_IWARP_SQ_WQE_LENGTH0_IDX = 18,
+       NES_IWARP_SQ_WQE_STAG0_IDX = 19,
+       NES_IWARP_SQ_WQE_FRAG1_LOW_IDX = 20,
+       NES_IWARP_SQ_WQE_FRAG1_HIGH_IDX = 21,
+       NES_IWARP_SQ_WQE_LENGTH1_IDX = 22,
+       NES_IWARP_SQ_WQE_STAG1_IDX = 23,
+       NES_IWARP_SQ_WQE_FRAG2_LOW_IDX = 24,
+       NES_IWARP_SQ_WQE_FRAG2_HIGH_IDX = 25,
+       NES_IWARP_SQ_WQE_LENGTH2_IDX = 26,
+       NES_IWARP_SQ_WQE_STAG2_IDX = 27,
+       NES_IWARP_SQ_WQE_FRAG3_LOW_IDX = 28,
+       NES_IWARP_SQ_WQE_FRAG3_HIGH_IDX = 29,
+       NES_IWARP_SQ_WQE_LENGTH3_IDX = 30,
+       NES_IWARP_SQ_WQE_STAG3_IDX = 31,
+};
+
+enum nes_iwarp_sq_bind_wqe_word_idx {
+       NES_IWARP_SQ_BIND_WQE_MR_IDX = 6,
+       NES_IWARP_SQ_BIND_WQE_MW_IDX = 7,
+       NES_IWARP_SQ_BIND_WQE_LENGTH_LOW_IDX = 8,
+       NES_IWARP_SQ_BIND_WQE_LENGTH_HIGH_IDX = 9,
+       NES_IWARP_SQ_BIND_WQE_VA_FBO_LOW_IDX = 10,
+       NES_IWARP_SQ_BIND_WQE_VA_FBO_HIGH_IDX = 11,
+};
+
+enum nes_iwarp_sq_fmr_wqe_word_idx {
+       NES_IWARP_SQ_FMR_WQE_MR_STAG_IDX = 7,
+       NES_IWARP_SQ_FMR_WQE_LENGTH_LOW_IDX = 8,
+       NES_IWARP_SQ_FMR_WQE_LENGTH_HIGH_IDX = 9,
+       NES_IWARP_SQ_FMR_WQE_VA_FBO_LOW_IDX = 10,
+       NES_IWARP_SQ_FMR_WQE_VA_FBO_HIGH_IDX = 11,
+       NES_IWARP_SQ_FMR_WQE_PBL_ADDR_LOW_IDX = 12,
+       NES_IWARP_SQ_FMR_WQE_PBL_ADDR_HIGH_IDX = 13,
+       NES_IWARP_SQ_FMR_WQE_PBL_LENGTH_IDX = 14,
+};
+
+enum nes_iwarp_sq_locinv_wqe_word_idx {
+       NES_IWARP_SQ_LOCINV_WQE_INV_STAG_IDX = 6,
+};
+
+
+enum nes_iwarp_rq_wqe_word_idx {
+       NES_IWARP_RQ_WQE_TOTAL_PAYLOAD_IDX = 1,
+       NES_IWARP_RQ_WQE_COMP_CTX_LOW_IDX = 2,
+       NES_IWARP_RQ_WQE_COMP_CTX_HIGH_IDX = 3,
+       NES_IWARP_RQ_WQE_COMP_SCRATCH_LOW_IDX = 4,
+       NES_IWARP_RQ_WQE_COMP_SCRATCH_HIGH_IDX = 5,
+       NES_IWARP_RQ_WQE_FRAG0_LOW_IDX = 8,
+       NES_IWARP_RQ_WQE_FRAG0_HIGH_IDX = 9,
+       NES_IWARP_RQ_WQE_LENGTH0_IDX = 10,
+       NES_IWARP_RQ_WQE_STAG0_IDX = 11,
+       NES_IWARP_RQ_WQE_FRAG1_LOW_IDX = 12,
+       NES_IWARP_RQ_WQE_FRAG1_HIGH_IDX = 13,
+       NES_IWARP_RQ_WQE_LENGTH1_IDX = 14,
+       NES_IWARP_RQ_WQE_STAG1_IDX = 15,
+       NES_IWARP_RQ_WQE_FRAG2_LOW_IDX = 16,
+       NES_IWARP_RQ_WQE_FRAG2_HIGH_IDX = 17,
+       NES_IWARP_RQ_WQE_LENGTH2_IDX = 18,
+       NES_IWARP_RQ_WQE_STAG2_IDX = 19,
+       NES_IWARP_RQ_WQE_FRAG3_LOW_IDX = 20,
+       NES_IWARP_RQ_WQE_FRAG3_HIGH_IDX = 21,
+       NES_IWARP_RQ_WQE_LENGTH3_IDX = 22,
+       NES_IWARP_RQ_WQE_STAG3_IDX = 23,
+};
+
+enum nes_nic_sq_wqe_bits {
+       NES_NIC_SQ_WQE_PHDR_CS_READY =  (1<<21),
+       NES_NIC_SQ_WQE_LSO_ENABLE = (1<<22),
+       NES_NIC_SQ_WQE_TAGVALUE_ENABLE = (1<<23),
+       NES_NIC_SQ_WQE_DISABLE_CHKSUM = (1<<30),
+       NES_NIC_SQ_WQE_COMPLETION = (1<<31),
+};
+
+enum nes_nic_cqe_word_idx {
+       NES_NIC_CQE_ACCQP_ID_IDX = 0,
+       NES_NIC_CQE_TAG_PKT_TYPE_IDX = 2,
+       NES_NIC_CQE_MISC_IDX = 3,
+};
+
+#define NES_PKT_TYPE_APBVT_BITS 0xC112
+#define NES_PKT_TYPE_APBVT_MASK 0xff3e
+
+#define NES_PKT_TYPE_PVALID_BITS 0x10000000
+#define NES_PKT_TYPE_PVALID_MASK 0x30000000
+
+#define NES_PKT_TYPE_TCPV4_BITS 0x0110
+#define NES_PKT_TYPE_TCPV4_MASK 0x3f30
+
+#define NES_PKT_TYPE_UDPV4_BITS 0x0210
+#define NES_PKT_TYPE_UDPV4_MASK 0x3f30
+
+#define NES_PKT_TYPE_IPV4_BITS  0x0010
+#define NES_PKT_TYPE_IPV4_MASK  0x3f30
+
+#define NES_PKT_TYPE_OTHER_BITS 0x0000
+#define NES_PKT_TYPE_OTHER_MASK 0x0030
+
+#define NES_NIC_CQE_ERRV_SHIFT 16
+enum nes_nic_ev_bits {
+       NES_NIC_ERRV_BITS_MODE = (1<<0),
+       NES_NIC_ERRV_BITS_IPV4_CSUM_ERR = (1<<1),
+       NES_NIC_ERRV_BITS_TCPUDP_CSUM_ERR = (1<<2),
+       NES_NIC_ERRV_BITS_WQE_OVERRUN = (1<<3),
+       NES_NIC_ERRV_BITS_IPH_ERR = (1<<4),
+};
+
+enum nes_nic_cqe_bits {
+       NES_NIC_CQE_ERRV_MASK = (0xff<<NES_NIC_CQE_ERRV_SHIFT),
+       NES_NIC_CQE_SQ = (1<<24),
+       NES_NIC_CQE_ACCQP_PORT = (1<<28),
+       NES_NIC_CQE_ACCQP_VALID = (1<<29),
+       NES_NIC_CQE_TAG_VALID = (1<<30),
+       NES_NIC_CQE_VALID = (1<<31),
+};
+
+enum nes_aeqe_word_idx {
+       NES_AEQE_COMP_CTXT_LOW_IDX = 0,
+       NES_AEQE_COMP_CTXT_HIGH_IDX = 1,
+       NES_AEQE_COMP_QP_CQ_ID_IDX = 2,
+       NES_AEQE_MISC_IDX = 3,
+};
+
+enum nes_aeqe_bits {
+       NES_AEQE_QP = (1<<16),
+       NES_AEQE_CQ = (1<<17),
+       NES_AEQE_SQ = (1<<18),
+       NES_AEQE_INBOUND_RDMA = (1<<19),
+       NES_AEQE_IWARP_STATE_MASK = (7<<20),
+       NES_AEQE_TCP_STATE_MASK = (0xf<<24),
+       NES_AEQE_VALID = (1<<31),
+};
+
+#define NES_AEQE_IWARP_STATE_SHIFT     20
+#define NES_AEQE_TCP_STATE_SHIFT       24
+
+enum nes_aeqe_iwarp_state {
+       NES_AEQE_IWARP_STATE_NON_EXISTANT = 0,
+       NES_AEQE_IWARP_STATE_IDLE = 1,
+       NES_AEQE_IWARP_STATE_RTS = 2,
+       NES_AEQE_IWARP_STATE_CLOSING = 3,
+       NES_AEQE_IWARP_STATE_TERMINATE = 5,
+       NES_AEQE_IWARP_STATE_ERROR = 6
+};
+
+enum nes_aeqe_tcp_state {
+       NES_AEQE_TCP_STATE_NON_EXISTANT = 0,
+       NES_AEQE_TCP_STATE_CLOSED = 1,
+       NES_AEQE_TCP_STATE_LISTEN = 2,
+       NES_AEQE_TCP_STATE_SYN_SENT = 3,
+       NES_AEQE_TCP_STATE_SYN_RCVD = 4,
+       NES_AEQE_TCP_STATE_ESTABLISHED = 5,
+       NES_AEQE_TCP_STATE_CLOSE_WAIT = 6,
+       NES_AEQE_TCP_STATE_FIN_WAIT_1 = 7,
+       NES_AEQE_TCP_STATE_CLOSING = 8,
+       NES_AEQE_TCP_STATE_LAST_ACK = 9,
+       NES_AEQE_TCP_STATE_FIN_WAIT_2 = 10,
+       NES_AEQE_TCP_STATE_TIME_WAIT = 11
+};
+
+enum nes_aeqe_aeid {
+       NES_AEQE_AEID_AMP_UNALLOCATED_STAG                            = 0x0102,
+       NES_AEQE_AEID_AMP_INVALID_STAG                                = 0x0103,
+       NES_AEQE_AEID_AMP_BAD_QP                                      = 0x0104,
+       NES_AEQE_AEID_AMP_BAD_PD                                      = 0x0105,
+       NES_AEQE_AEID_AMP_BAD_STAG_KEY                                = 0x0106,
+       NES_AEQE_AEID_AMP_BAD_STAG_INDEX                              = 0x0107,
+       NES_AEQE_AEID_AMP_BOUNDS_VIOLATION                            = 0x0108,
+       NES_AEQE_AEID_AMP_RIGHTS_VIOLATION                            = 0x0109,
+       NES_AEQE_AEID_AMP_TO_WRAP                                     = 0x010a,
+       NES_AEQE_AEID_AMP_FASTREG_SHARED                              = 0x010b,
+       NES_AEQE_AEID_AMP_FASTREG_VALID_STAG                          = 0x010c,
+       NES_AEQE_AEID_AMP_FASTREG_MW_STAG                             = 0x010d,
+       NES_AEQE_AEID_AMP_FASTREG_INVALID_RIGHTS                      = 0x010e,
+       NES_AEQE_AEID_AMP_FASTREG_PBL_TABLE_OVERFLOW                  = 0x010f,
+       NES_AEQE_AEID_AMP_FASTREG_INVALID_LENGTH                      = 0x0110,
+       NES_AEQE_AEID_AMP_INVALIDATE_SHARED                           = 0x0111,
+       NES_AEQE_AEID_AMP_INVALIDATE_NO_REMOTE_ACCESS_RIGHTS          = 0x0112,
+       NES_AEQE_AEID_AMP_INVALIDATE_MR_WITH_BOUND_WINDOWS            = 0x0113,
+       NES_AEQE_AEID_AMP_MWBIND_VALID_STAG                           = 0x0114,
+       NES_AEQE_AEID_AMP_MWBIND_OF_MR_STAG                           = 0x0115,
+       NES_AEQE_AEID_AMP_MWBIND_TO_ZERO_BASED_STAG                   = 0x0116,
+       NES_AEQE_AEID_AMP_MWBIND_TO_MW_STAG                           = 0x0117,
+       NES_AEQE_AEID_AMP_MWBIND_INVALID_RIGHTS                       = 0x0118,
+       NES_AEQE_AEID_AMP_MWBIND_INVALID_BOUNDS                       = 0x0119,
+       NES_AEQE_AEID_AMP_MWBIND_TO_INVALID_PARENT                    = 0x011a,
+       NES_AEQE_AEID_AMP_MWBIND_BIND_DISABLED                        = 0x011b,
+       NES_AEQE_AEID_BAD_CLOSE                                       = 0x0201,
+       NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE                         = 0x0202,
+       NES_AEQE_AEID_CQ_OPERATION_ERROR                              = 0x0203,
+       NES_AEQE_AEID_PRIV_OPERATION_DENIED                           = 0x0204,
+       NES_AEQE_AEID_RDMA_READ_WHILE_ORD_ZERO                        = 0x0205,
+       NES_AEQE_AEID_STAG_ZERO_INVALID                               = 0x0206,
+       NES_AEQE_AEID_DDP_INVALID_MSN_GAP_IN_MSN                      = 0x0301,
+       NES_AEQE_AEID_DDP_INVALID_MSN_RANGE_IS_NOT_VALID              = 0x0302,
+       NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER = 0x0303,
+       NES_AEQE_AEID_DDP_UBE_INVALID_DDP_VERSION                     = 0x0304,
+       NES_AEQE_AEID_DDP_UBE_INVALID_MO                              = 0x0305,
+       NES_AEQE_AEID_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE         = 0x0306,
+       NES_AEQE_AEID_DDP_UBE_INVALID_QN                              = 0x0307,
+       NES_AEQE_AEID_DDP_NO_L_BIT                                    = 0x0308,
+       NES_AEQE_AEID_RDMAP_ROE_INVALID_RDMAP_VERSION                 = 0x0311,
+       NES_AEQE_AEID_RDMAP_ROE_UNEXPECTED_OPCODE                     = 0x0312,
+       NES_AEQE_AEID_ROE_INVALID_RDMA_READ_REQUEST                   = 0x0313,
+       NES_AEQE_AEID_ROE_INVALID_RDMA_WRITE_OR_READ_RESP             = 0x0314,
+       NES_AEQE_AEID_INVALID_ARP_ENTRY                               = 0x0401,
+       NES_AEQE_AEID_INVALID_TCP_OPTION_RCVD                         = 0x0402,
+       NES_AEQE_AEID_STALE_ARP_ENTRY                                 = 0x0403,
+       NES_AEQE_AEID_LLP_CLOSE_COMPLETE                              = 0x0501,
+       NES_AEQE_AEID_LLP_CONNECTION_RESET                            = 0x0502,
+       NES_AEQE_AEID_LLP_FIN_RECEIVED                                = 0x0503,
+       NES_AEQE_AEID_LLP_RECEIVED_MARKER_AND_LENGTH_FIELDS_DONT_MATCH =  0x0504,
+       NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR                      = 0x0505,
+       NES_AEQE_AEID_LLP_SEGMENT_TOO_LARGE                           = 0x0506,
+       NES_AEQE_AEID_LLP_SEGMENT_TOO_SMALL                           = 0x0507,
+       NES_AEQE_AEID_LLP_SYN_RECEIVED                                = 0x0508,
+       NES_AEQE_AEID_LLP_TERMINATE_RECEIVED                          = 0x0509,
+       NES_AEQE_AEID_LLP_TOO_MANY_RETRIES                            = 0x050a,
+       NES_AEQE_AEID_LLP_TOO_MANY_KEEPALIVE_RETRIES                  = 0x050b,
+       NES_AEQE_AEID_RESET_SENT                                      = 0x0601,
+       NES_AEQE_AEID_TERMINATE_SENT                                  = 0x0602,
+       NES_AEQE_AEID_DDP_LCE_LOCAL_CATASTROPHIC                      = 0x0700
+};
+
+enum nes_iwarp_sq_opcodes {
+       NES_IWARP_SQ_WQE_WRPDU = (1<<15),
+       NES_IWARP_SQ_WQE_PSH = (1<<21),
+       NES_IWARP_SQ_WQE_STREAMING = (1<<23),
+       NES_IWARP_SQ_WQE_IMM_DATA = (1<<28),
+       NES_IWARP_SQ_WQE_READ_FENCE = (1<<29),
+       NES_IWARP_SQ_WQE_LOCAL_FENCE = (1<<30),
+       NES_IWARP_SQ_WQE_SIGNALED_COMPL = (1<<31),
+};
+
+enum nes_iwarp_sq_wqe_bits {
+       NES_IWARP_SQ_OP_RDMAW = 0,
+       NES_IWARP_SQ_OP_RDMAR = 1,
+       NES_IWARP_SQ_OP_SEND = 3,
+       NES_IWARP_SQ_OP_SENDINV = 4,
+       NES_IWARP_SQ_OP_SENDSE = 5,
+       NES_IWARP_SQ_OP_SENDSEINV = 6,
+       NES_IWARP_SQ_OP_BIND = 8,
+       NES_IWARP_SQ_OP_FAST_REG = 9,
+       NES_IWARP_SQ_OP_LOCINV = 10,
+       NES_IWARP_SQ_OP_RDMAR_LOCINV = 11,
+       NES_IWARP_SQ_OP_NOP = 12,
+};
+
+#define NES_EEPROM_READ_REQUEST (1<<16)
+#define NES_MAC_ADDR_VALID      (1<<20)
+
+/*
+ * NES index registers init values.
+ */
+struct nes_init_values {
+       u32 index;
+       u32 data;
+       u8  wrt;
+};
+
+/*
+ * NES registers in BAR0.
+ */
+struct nes_pci_regs {
+       u32 int_status;
+       u32 int_mask;
+       u32 int_pending;
+       u32 intf_int_status;
+       u32 intf_int_mask;
+       u32 other_regs[59];      /* pad out to 256 bytes for now */
+};
+
+#define NES_CQP_SQ_SIZE    128
+#define NES_CCQ_SIZE       128
+#define NES_NIC_WQ_SIZE    512
+#define NES_NIC_CTX_SIZE   ((NES_NIC_CTX_RQ_SIZE_512) | (NES_NIC_CTX_SQ_SIZE_512))
+#define NES_NIC_BACK_STORE 0x00038000
+
+struct nes_device;
+
+struct nes_hw_nic_qp_context {
+       __le32 context_words[6];
+};
+
+struct nes_hw_nic_sq_wqe {
+       __le32 wqe_words[16];
+};
+
+struct nes_hw_nic_rq_wqe {
+       __le32 wqe_words[16];
+};
+
+struct nes_hw_nic_cqe {
+       __le32 cqe_words[4];
+};
+
+struct nes_hw_cqp_qp_context {
+       __le32 context_words[4];
+};
+
+struct nes_hw_cqp_wqe {
+       __le32 wqe_words[16];
+};
+
+struct nes_hw_qp_wqe {
+       __le32 wqe_words[32];
+};
+
+struct nes_hw_cqe {
+       __le32 cqe_words[8];
+};
+
+struct nes_hw_ceqe {
+       __le32 ceqe_words[2];
+};
+
+struct nes_hw_aeqe {
+       __le32 aeqe_words[4];
+};
+
+struct nes_cqp_request {
+       union {
+               u64 cqp_callback_context;
+               void *cqp_callback_pointer;
+       };
+       wait_queue_head_t     waitq;
+       struct nes_hw_cqp_wqe cqp_wqe;
+       struct list_head      list;
+       atomic_t              refcount;
+       void (*cqp_callback)(struct nes_device *nesdev, struct nes_cqp_request *cqp_request);
+       u16                   major_code;
+       u16                   minor_code;
+       u8                    waiting;
+       u8                    request_done;
+       u8                    dynamic;
+       u8                    callback;
+};
+
+struct nes_hw_cqp {
+       struct nes_hw_cqp_wqe *sq_vbase;
+       dma_addr_t            sq_pbase;
+       spinlock_t            lock;
+       wait_queue_head_t     waitq;
+       u16                   qp_id;
+       u16                   sq_head;
+       u16                   sq_tail;
+       u16                   sq_size;
+};
+
+#define NES_FIRST_FRAG_SIZE 128
+struct nes_first_frag {
+       u8 buffer[NES_FIRST_FRAG_SIZE];
+};
+
+struct nes_hw_nic {
+       struct nes_first_frag    *first_frag_vbase;     /* virtual address of first frags */
+       struct nes_hw_nic_sq_wqe *sq_vbase;                     /* virtual address of sq */
+       struct nes_hw_nic_rq_wqe *rq_vbase;                     /* virtual address of rq */
+       struct sk_buff           *tx_skb[NES_NIC_WQ_SIZE];
+       struct sk_buff           *rx_skb[NES_NIC_WQ_SIZE];
+       dma_addr_t frag_paddr[NES_NIC_WQ_SIZE];
+       unsigned long first_frag_overflow[BITS_TO_LONGS(NES_NIC_WQ_SIZE)];
+       dma_addr_t sq_pbase;                    /* PCI memory for host rings */
+       dma_addr_t rq_pbase;                    /* PCI memory for host rings */
+
+       u16 qp_id;
+       u16 sq_head;
+       u16 sq_tail;
+       u16 sq_size;
+       u16 rq_head;
+       u16 rq_tail;
+       u16 rq_size;
+       u8 replenishing_rq;
+       u8 reserved;
+
+       spinlock_t sq_lock;
+       spinlock_t rq_lock;
+};
+
+struct nes_hw_nic_cq {
+       struct nes_hw_nic_cqe volatile *cq_vbase;       /* PCI memory for host rings */
+       void (*ce_handler)(struct nes_device *nesdev, struct nes_hw_nic_cq *cq);
+       dma_addr_t cq_pbase;    /* PCI memory for host rings */
+       int rx_cqes_completed;
+       int cqe_allocs_pending;
+       int rx_pkts_indicated;
+       u16 cq_head;
+       u16 cq_size;
+       u16 cq_number;
+       u8  cqes_pending;
+};
+
+struct nes_hw_qp {
+       struct nes_hw_qp_wqe *sq_vbase;         /* PCI memory for host rings */
+       struct nes_hw_qp_wqe *rq_vbase;         /* PCI memory for host rings */
+       void                 *q2_vbase;                 /* PCI memory for host rings */
+       dma_addr_t sq_pbase;    /* PCI memory for host rings */
+       dma_addr_t rq_pbase;    /* PCI memory for host rings */
+       dma_addr_t q2_pbase;    /* PCI memory for host rings */
+       u32 qp_id;
+       u16 sq_head;
+       u16 sq_tail;
+       u16 sq_size;
+       u16 rq_head;
+       u16 rq_tail;
+       u16 rq_size;
+       u8  rq_encoded_size;
+       u8  sq_encoded_size;
+};
+
+struct nes_hw_cq {
+       struct nes_hw_cqe volatile *cq_vbase;   /* PCI memory for host rings */
+       void (*ce_handler)(struct nes_device *nesdev, struct nes_hw_cq *cq);
+       dma_addr_t cq_pbase;    /* PCI memory for host rings */
+       u16 cq_head;
+       u16 cq_size;
+       u16 cq_number;
+};
+
+struct nes_hw_ceq {
+       struct nes_hw_ceqe volatile *ceq_vbase; /* PCI memory for host rings */
+       dma_addr_t ceq_pbase;   /* PCI memory for host rings */
+       u16 ceq_head;
+       u16 ceq_size;
+};
+
+struct nes_hw_aeq {
+       struct nes_hw_aeqe volatile *aeq_vbase; /* PCI memory for host rings */
+       dma_addr_t aeq_pbase;   /* PCI memory for host rings */
+       u16 aeq_head;
+       u16 aeq_size;
+};
+
+struct nic_qp_map {
+       u8 qpid;
+       u8 nic_index;
+       u8 logical_port;
+       u8 is_hnic;
+};
+
+#define        NES_CQP_ARP_AEQ_INDEX_MASK  0x000f0000
+#define        NES_CQP_ARP_AEQ_INDEX_SHIFT 16
+
+#define NES_CQP_APBVT_ADD                      0x00008000
+#define NES_CQP_APBVT_NIC_SHIFT                16
+
+#define NES_ARP_ADD     1
+#define NES_ARP_DELETE  2
+#define NES_ARP_RESOLVE 3
+
+#define NES_MAC_SW_IDLE      0
+#define NES_MAC_SW_INTERRUPT 1
+#define NES_MAC_SW_MH        2
+
+struct nes_arp_entry {
+       u32 ip_addr;
+       u8  mac_addr[ETH_ALEN];
+};
+
+#define NES_NIC_FAST_TIMER          96
+#define NES_NIC_FAST_TIMER_LOW      40
+#define NES_NIC_FAST_TIMER_HIGH     1000
+#define DEFAULT_NES_QL_HIGH         256
+#define DEFAULT_NES_QL_LOW          16
+#define DEFAULT_NES_QL_TARGET       64
+#define DEFAULT_JUMBO_NES_QL_LOW    12
+#define DEFAULT_JUMBO_NES_QL_TARGET 40
+#define DEFAULT_JUMBO_NES_QL_HIGH   128
+#define NES_NIC_CQ_DOWNWARD_TREND   8
+
+struct nes_hw_tune_timer {
+    //u16 cq_count;
+    u16 threshold_low;
+    u16 threshold_target;
+    u16 threshold_high;
+    u16 timer_in_use;
+    u16 timer_in_use_old;
+    u16 timer_in_use_min;
+    u16 timer_in_use_max;
+    u8  timer_direction_upward;
+    u8  timer_direction_downward;
+    u16 cq_count_old;
+    u8  cq_direction_downward;
+};
+
+#define NES_TIMER_INT_LIMIT         2
+#define NES_TIMER_INT_LIMIT_DYNAMIC 10
+#define NES_TIMER_ENABLE_LIMIT      4
+#define NES_MAX_LINK_INTERRUPTS                128
+#define NES_MAX_LINK_CHECK             200
+
+struct nes_adapter {
+       u64              fw_ver;
+       unsigned long    *allocated_qps;
+       unsigned long    *allocated_cqs;
+       unsigned long    *allocated_mrs;
+       unsigned long    *allocated_pds;
+       unsigned long    *allocated_arps;
+       struct nes_qp    **qp_table;
+       struct workqueue_struct *work_q;
+
+       struct list_head list;
+       struct list_head active_listeners;
+       /* list of the netdev's associated with each logical port */
+       struct list_head nesvnic_list[4];
+
+       struct timer_list  mh_timer;
+       struct timer_list  lc_timer;
+       struct work_struct work;
+       spinlock_t         resource_lock;
+       spinlock_t         phy_lock;
+       spinlock_t         pbl_lock;
+       spinlock_t         periodic_timer_lock;
+
+       struct nes_arp_entry arp_table[NES_MAX_ARP_TABLE_SIZE];
+
+       /* Adapter CEQ and AEQs */
+       struct nes_hw_ceq ceq[16];
+       struct nes_hw_aeq aeq[8];
+
+       struct nes_hw_tune_timer tune_timer;
+
+       unsigned long doorbell_start;
+
+       u32 hw_rev;
+       u32 vendor_id;
+       u32 vendor_part_id;
+       u32 device_cap_flags;
+       u32 tick_delta;
+       u32 timer_int_req;
+       u32 arp_table_size;
+       u32 next_arp_index;
+
+       u32 max_mr;
+       u32 max_256pbl;
+       u32 max_4kpbl;
+       u32 free_256pbl;
+       u32 free_4kpbl;
+       u32 max_mr_size;
+       u32 max_qp;
+       u32 next_qp;
+       u32 max_irrq;
+       u32 max_qp_wr;
+       u32 max_sge;
+       u32 max_cq;
+       u32 next_cq;
+       u32 max_cqe;
+       u32 max_pd;
+       u32 base_pd;
+       u32 next_pd;
+       u32 hte_index_mask;
+
+       /* EEPROM information */
+       u32 rx_pool_size;
+       u32 tx_pool_size;
+       u32 rx_threshold;
+       u32 tcp_timer_core_clk_divisor;
+       u32 iwarp_config;
+       u32 cm_config;
+       u32 sws_timer_config;
+       u32 tcp_config1;
+       u32 wqm_wat;
+       u32 core_clock;
+       u32 firmware_version;
+
+       u32 nic_rx_eth_route_err;
+
+       u32 et_rx_coalesce_usecs;
+       u32     et_rx_max_coalesced_frames;
+       u32 et_rx_coalesce_usecs_irq;
+       u32 et_rx_max_coalesced_frames_irq;
+       u32 et_pkt_rate_low;
+       u32 et_rx_coalesce_usecs_low;
+       u32 et_rx_max_coalesced_frames_low;
+       u32 et_pkt_rate_high;
+       u32 et_rx_coalesce_usecs_high;
+       u32 et_rx_max_coalesced_frames_high;
+       u32 et_rate_sample_interval;
+       u32 timer_int_limit;
+
+       /* Adapter base MAC address */
+       u32 mac_addr_low;
+       u16 mac_addr_high;
+
+       u16 firmware_eeprom_offset;
+       u16 software_eeprom_offset;
+
+       u16 max_irrq_wr;
+
+       /* pd config for each port */
+       u16 pd_config_size[4];
+       u16 pd_config_base[4];
+
+       u16 link_interrupt_count[4];
+
+       /* the phy index for each port */
+       u8  phy_index[4];
+       u8  mac_sw_state[4];
+       u8  mac_link_down[4];
+       u8  phy_type[4];
+
+       /* PCI information */
+       unsigned int  devfn;
+       unsigned char bus_number;
+       unsigned char OneG_Mode;
+
+       unsigned char ref_count;
+       u8            netdev_count;
+       u8            netdev_max;       /* from host nic address count in EEPROM */
+       u8            port_count;
+       u8            virtwq;
+       u8            et_use_adaptive_rx_coalesce;
+       u8            adapter_fcn_count;
+};
+
+struct nes_pbl {
+       u64              *pbl_vbase;
+       dma_addr_t       pbl_pbase;
+       struct page      *page;
+       unsigned long    user_base;
+       u32              pbl_size;
+       struct list_head list;
+       /* TODO: need to add list for two level tables */
+};
+
+struct nes_listener {
+       struct work_struct      work;
+       struct workqueue_struct *wq;
+       struct nes_vnic         *nesvnic;
+       struct iw_cm_id         *cm_id;
+       struct list_head        list;
+       unsigned long           socket;
+       u8                      accept_failed;
+};
+
+struct nes_ib_device;
+
+struct nes_vnic {
+       struct nes_ib_device *nesibdev;
+       u64 sq_full;
+       u64 sq_locked;
+       u64 tso_requests;
+       u64 segmented_tso_requests;
+       u64 linearized_skbs;
+       u64 tx_sw_dropped;
+       u64 endnode_nstat_rx_discard;
+       u64 endnode_nstat_rx_octets;
+       u64 endnode_nstat_rx_frames;
+       u64 endnode_nstat_tx_octets;
+       u64 endnode_nstat_tx_frames;
+       u64 endnode_ipv4_tcp_retransmits;
+       /* void *mem; */
+       struct nes_device *nesdev;
+       struct net_device *netdev;
+       struct vlan_group *vlan_grp;
+       atomic_t          rx_skbs_needed;
+       atomic_t          rx_skb_timer_running;
+       int               budget;
+       u32               msg_enable;
+       /* u32 tx_avail; */
+       __be32            local_ipaddr;
+       struct napi_struct   napi;
+       spinlock_t           tx_lock;   /* could use netdev tx lock? */
+       struct timer_list    rq_wqes_timer;
+       u32                  nic_mem_size;
+       void                 *nic_vbase;
+       dma_addr_t           nic_pbase;
+       struct nes_hw_nic    nic;
+       struct nes_hw_nic_cq nic_cq;
+       u32    mcrq_qp_id;
+       struct nes_ucontext *mcrq_ucontext;
+       struct nes_cqp_request* (*get_cqp_request)(struct nes_device *nesdev);
+       void (*post_cqp_request)(struct nes_device*, struct nes_cqp_request *, int);
+       int (*mcrq_mcast_filter)( struct nes_vnic* nesvnic, __u8* dmi_addr );
+       struct net_device_stats netstats;
+       /* used to put the netdev on the adapters logical port list */
+       struct list_head list;
+       u16 max_frame_size;
+       u8  netdev_open;
+       u8  linkup;
+       u8  logical_port;
+       u8  netdev_index;  /* might not be needed, indexes nesdev->netdev */
+       u8  perfect_filter_index;
+       u8  nic_index;
+       u8  qp_nic_index[4];
+       u8  next_qp_nic_index;
+       u8  of_device_registered;
+       u8  rdma_enabled;
+       u8  rx_checksum_disabled;
+};
+
+struct nes_ib_device {
+       struct ib_device ibdev;
+       struct nes_vnic *nesvnic;
+
+       /* Virtual RNIC Limits */
+       u32 max_mr;
+       u32 max_qp;
+       u32 max_cq;
+       u32 max_pd;
+       u32 num_mr;
+       u32 num_qp;
+       u32 num_cq;
+       u32 num_pd;
+};
+
+#define nes_vlan_rx vlan_hwaccel_receive_skb
+#define nes_netif_rx netif_receive_skb
+
+#endif         /* __NES_HW_H */
diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
new file mode 100644 (file)
index 0000000..b6cc265
--- /dev/null
@@ -0,0 +1,1703 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/if_arp.h>
+#include <linux/if_vlan.h>
+#include <linux/ethtool.h>
+#include <net/tcp.h>
+
+#include <net/inet_common.h>
+#include <linux/inet.h>
+
+#include "nes.h"
+
+static struct nic_qp_map nic_qp_mapping_0[] = {
+       {16,0,0,1},{24,4,0,0},{28,8,0,0},{32,12,0,0},
+       {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0},
+       {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
+       {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
+};
+
+static struct nic_qp_map nic_qp_mapping_1[] = {
+       {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
+       {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
+};
+
+static struct nic_qp_map nic_qp_mapping_2[] = {
+       {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0}
+};
+
+static struct nic_qp_map nic_qp_mapping_3[] = {
+       {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
+};
+
+static struct nic_qp_map nic_qp_mapping_4[] = {
+       {28,8,0,0},{32,12,0,0}
+};
+
+static struct nic_qp_map nic_qp_mapping_5[] = {
+       {29,9,1,0},{33,13,1,0}
+};
+
+static struct nic_qp_map nic_qp_mapping_6[] = {
+       {30,10,2,0},{34,14,2,0}
+};
+
+static struct nic_qp_map nic_qp_mapping_7[] = {
+       {31,11,3,0},{35,15,3,0}
+};
+
+static struct nic_qp_map *nic_qp_mapping_per_function[] = {
+       nic_qp_mapping_0, nic_qp_mapping_1, nic_qp_mapping_2, nic_qp_mapping_3,
+       nic_qp_mapping_4, nic_qp_mapping_5, nic_qp_mapping_6, nic_qp_mapping_7
+};
+
+static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
+               | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
+static int debug = -1;
+
+
+static int nes_netdev_open(struct net_device *);
+static int nes_netdev_stop(struct net_device *);
+static int nes_netdev_start_xmit(struct sk_buff *, struct net_device *);
+static struct net_device_stats *nes_netdev_get_stats(struct net_device *);
+static void nes_netdev_tx_timeout(struct net_device *);
+static int nes_netdev_set_mac_address(struct net_device *, void *);
+static int nes_netdev_change_mtu(struct net_device *, int);
+
+/**
+ * nes_netdev_poll
+ */
+static int nes_netdev_poll(struct napi_struct *napi, int budget)
+{
+       struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi);
+       struct net_device *netdev = nesvnic->netdev;
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_hw_nic_cq *nescq = &nesvnic->nic_cq;
+
+       nesvnic->budget = budget;
+       nescq->cqes_pending = 0;
+       nescq->rx_cqes_completed = 0;
+       nescq->cqe_allocs_pending = 0;
+       nescq->rx_pkts_indicated = 0;
+
+       nes_nic_ce_handler(nesdev, nescq);
+
+       if (nescq->cqes_pending == 0) {
+               netif_rx_complete(netdev, napi);
+               /* clear out completed cqes and arm */
+               nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
+                               nescq->cq_number | (nescq->cqe_allocs_pending << 16));
+               nes_read32(nesdev->regs+NES_CQE_ALLOC);
+       } else {
+               /* clear out completed cqes but don't arm */
+               nes_write32(nesdev->regs+NES_CQE_ALLOC,
+                               nescq->cq_number | (nescq->cqe_allocs_pending << 16));
+               nes_debug(NES_DBG_NETDEV, "%s: exiting with work pending\n",
+                               nesvnic->netdev->name);
+       }
+       return nescq->rx_pkts_indicated;
+}
+
+
+/**
+ * nes_netdev_open - Activate the network interface; ifconfig
+ * ethx up.
+ */
+static int nes_netdev_open(struct net_device *netdev)
+{
+       u32 macaddr_low;
+       u16 macaddr_high;
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       int ret;
+       int i;
+       struct nes_vnic *first_nesvnic;
+       u32 nic_active_bit;
+       u32 nic_active;
+
+       assert(nesdev != NULL);
+
+       first_nesvnic = list_entry(nesdev->nesadapter->nesvnic_list[nesdev->mac_index].next,
+                       struct nes_vnic, list);
+
+       if (netif_msg_ifup(nesvnic))
+               printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name);
+
+       ret = nes_init_nic_qp(nesdev, netdev);
+       if (ret) {
+               return ret;
+       }
+
+       netif_carrier_off(netdev);
+       netif_stop_queue(netdev);
+
+       if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) {
+               nesvnic->nesibdev = nes_init_ofa_device(netdev);
+               if (nesvnic->nesibdev == NULL) {
+                       printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name);
+               } else {
+                       nesvnic->nesibdev->nesvnic = nesvnic;
+                       ret = nes_register_ofa_device(nesvnic->nesibdev);
+                       if (ret) {
+                               printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n",
+                                               netdev->name, ret);
+                       }
+               }
+       }
+       /* Set packet filters */
+       nic_active_bit = 1 << nesvnic->nic_index;
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
+       nic_active |= nic_active_bit;
+       nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
+       nic_active |= nic_active_bit;
+       nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
+       nic_active |= nic_active_bit;
+       nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
+
+       macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
+       macaddr_high += (u16)netdev->dev_addr[1];
+       macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
+       macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
+       macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
+       macaddr_low += (u32)netdev->dev_addr[5];
+
+       /* Program the various MAC regs */
+       for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
+               if (nesvnic->qp_nic_index[i] == 0xf) {
+                       break;
+               }
+               nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW"
+                               " (Addr:%08X) = %08X, HIGH = %08X.\n",
+                               i, nesvnic->qp_nic_index[i],
+                               NES_IDX_PERFECT_FILTER_LOW+((nesvnic->perfect_filter_index + i) * 8),
+                               macaddr_low,
+                               (u32)macaddr_high | NES_MAC_ADDR_VALID |
+                               ((((u32)nesvnic->nic_index) << 16)));
+               nes_write_indexed(nesdev,
+                               NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
+                               macaddr_low);
+               nes_write_indexed(nesdev,
+                               NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
+                               (u32)macaddr_high | NES_MAC_ADDR_VALID |
+                               ((((u32)nesvnic->nic_index) << 16)));
+       }
+
+
+       nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
+                       nesvnic->nic_cq.cq_number);
+       nes_read32(nesdev->regs+NES_CQE_ALLOC);
+
+       if (first_nesvnic->linkup) {
+               /* Enable network packets */
+               nesvnic->linkup = 1;
+               netif_start_queue(netdev);
+               netif_carrier_on(netdev);
+       }
+       napi_enable(&nesvnic->napi);
+       nesvnic->netdev_open = 1;
+
+       return 0;
+}
+
+
+/**
+ * nes_netdev_stop
+ */
+static int nes_netdev_stop(struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       u32 nic_active_mask;
+       u32 nic_active;
+
+       nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n",
+                       nesvnic, nesdev, netdev, netdev->name);
+       if (nesvnic->netdev_open == 0)
+               return 0;
+
+       if (netif_msg_ifdown(nesvnic))
+               printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);
+
+       /* Disable network packets */
+       napi_disable(&nesvnic->napi);
+       netif_stop_queue(netdev);
+       if ((nesdev->netdev[0] == netdev) & (nesvnic->logical_port == nesdev->mac_index)) {
+               nes_write_indexed(nesdev,
+                               NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
+       }
+
+       nic_active_mask = ~((u32)(1 << nesvnic->nic_index));
+       nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+
+                       (nesvnic->perfect_filter_index*8), 0);
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
+       nic_active &= nic_active_mask;
+       nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
+       nic_active &= nic_active_mask;
+       nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
+       nic_active &= nic_active_mask;
+       nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
+       nic_active &= nic_active_mask;
+       nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
+       nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
+       nic_active &= nic_active_mask;
+       nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
+
+
+       if (nesvnic->of_device_registered) {
+               nes_destroy_ofa_device(nesvnic->nesibdev);
+               nesvnic->nesibdev = NULL;
+               nesvnic->of_device_registered = 0;
+       }
+       nes_destroy_nic_qp(nesvnic);
+
+       nesvnic->netdev_open = 0;
+
+       return 0;
+}
+
+
+/**
+ * nes_nic_send
+ */
+static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_hw_nic *nesnic = &nesvnic->nic;
+       struct nes_hw_nic_sq_wqe *nic_sqe;
+       struct tcphdr *tcph;
+       __le16 *wqe_fragment_length;
+       u32 wqe_misc;
+       u16 wqe_fragment_index = 1;     /* first fragment (0) is used by copy buffer */
+       u16 skb_fragment_index;
+       dma_addr_t bus_address;
+
+       nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
+       wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
+
+       /* setup the VLAN tag if present */
+       if (vlan_tx_tag_present(skb)) {
+               nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
+                               netdev->name, vlan_tx_tag_get(skb));
+               wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
+               wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
+       } else
+               wqe_misc = 0;
+
+       /* bump past the vlan tag */
+       wqe_fragment_length++;
+       /*      wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */
+
+       if (skb->ip_summed == CHECKSUM_PARTIAL) {
+               tcph = tcp_hdr(skb);
+               if (1) {
+                       if (skb_is_gso(skb)) {
+                               /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... seg size = %u\n",
+                                               netdev->name, skb_is_gso(skb)); */
+                               wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE |
+                                               NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
+                               set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
+                                               ((u32)tcph->doff) |
+                                               (((u32)(((unsigned char *)tcph) - skb->data)) << 4));
+                       } else {
+                               wqe_misc |= NES_NIC_SQ_WQE_COMPLETION;
+                       }
+               }
+       } else {        /* CHECKSUM_HW */
+               wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM | NES_NIC_SQ_WQE_COMPLETION;
+       }
+
+       set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
+                               skb->len);
+       memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
+                       skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb)));
+       wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
+                       skb_headlen(skb)));
+       wqe_fragment_length[1] = 0;
+       if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
+               if ((skb_shinfo(skb)->nr_frags + 1) > 4) {
+                       nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n",
+                                       netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb));
+                       kfree_skb(skb);
+                       nesvnic->tx_sw_dropped++;
+                       return NETDEV_TX_LOCKED;
+               }
+               set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
+               bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE,
+                               skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE);
+               wqe_fragment_length[wqe_fragment_index++] =
+                               cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE);
+               wqe_fragment_length[wqe_fragment_index] = 0;
+               set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
+                               ((u64)(bus_address)));
+               nesnic->tx_skb[nesnic->sq_head] = skb;
+       }
+
+       if (skb_headlen(skb) == skb->len) {
+               if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) {
+                       nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0;
+                       nesnic->tx_skb[nesnic->sq_head] = NULL;
+                       dev_kfree_skb(skb);
+               }
+       } else {
+               /* Deal with Fragments */
+               nesnic->tx_skb[nesnic->sq_head] = skb;
+               for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags;
+                               skb_fragment_index++) {
+                       bus_address = pci_map_page( nesdev->pcidev,
+                                       skb_shinfo(skb)->frags[skb_fragment_index].page,
+                                       skb_shinfo(skb)->frags[skb_fragment_index].page_offset,
+                                       skb_shinfo(skb)->frags[skb_fragment_index].size,
+                                       PCI_DMA_TODEVICE);
+                       wqe_fragment_length[wqe_fragment_index] =
+                                       cpu_to_le16(skb_shinfo(skb)->frags[skb_fragment_index].size);
+                       set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
+                               bus_address);
+                       wqe_fragment_index++;
+                       if (wqe_fragment_index < 5)
+                               wqe_fragment_length[wqe_fragment_index] = 0;
+               }
+       }
+
+       set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc);
+       nesnic->sq_head++;
+       nesnic->sq_head &= nesnic->sq_size - 1;
+
+       return NETDEV_TX_OK;
+}
+
+
+/**
+ * nes_netdev_start_xmit
+ */
+static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_hw_nic *nesnic = &nesvnic->nic;
+       struct nes_hw_nic_sq_wqe *nic_sqe;
+       struct tcphdr *tcph;
+       /* struct udphdr *udph; */
+#define NES_MAX_TSO_FRAGS 18
+       /* 64K segment plus overflow on each side */
+       dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS];
+       dma_addr_t bus_address;
+       u32 tso_frag_index;
+       u32 tso_frag_count;
+       u32 tso_wqe_length;
+       u32 curr_tcp_seq;
+       u32 wqe_count=1;
+       u32 send_rc;
+       struct iphdr *iph;
+       unsigned long flags;
+       __le16 *wqe_fragment_length;
+       u32 nr_frags;
+       u32 original_first_length;
+//     u64 *wqe_fragment_address;
+       /* first fragment (0) is used by copy buffer */
+       u16 wqe_fragment_index=1;
+       u16 hoffset;
+       u16 nhoffset;
+       u16 wqes_needed;
+       u16 wqes_available;
+       u32 old_head;
+       u32 wqe_misc;
+
+       /* nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
+                       " (%u frags), tso_size=%u\n",
+                       netdev->name, skb->len, skb_headlen(skb),
+                       skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
+       */
+
+       if (!netif_carrier_ok(netdev))
+               return NETDEV_TX_OK;
+
+       if (netif_queue_stopped(netdev))
+               return NETDEV_TX_BUSY;
+
+       local_irq_save(flags);
+       if (!spin_trylock(&nesnic->sq_lock)) {
+               local_irq_restore(flags);
+               nesvnic->sq_locked++;
+               return NETDEV_TX_LOCKED;
+       }
+
+       /* Check if SQ is full */
+       if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) {
+               if (!netif_queue_stopped(netdev)) {
+                       netif_stop_queue(netdev);
+                       barrier();
+                       if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) {
+                               netif_start_queue(netdev);
+                               goto sq_no_longer_full;
+                       }
+               }
+               nesvnic->sq_full++;
+               spin_unlock_irqrestore(&nesnic->sq_lock, flags);
+               return NETDEV_TX_BUSY;
+       }
+
+sq_no_longer_full:
+       nr_frags = skb_shinfo(skb)->nr_frags;
+       if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
+               nr_frags++;
+       }
+       /* Check if too many fragments */
+       if (unlikely((nr_frags > 4))) {
+               if (skb_is_gso(skb)) {
+                       nesvnic->segmented_tso_requests++;
+                       nesvnic->tso_requests++;
+                       old_head = nesnic->sq_head;
+                       /* Basically 4 fragments available per WQE with extended fragments */
+                       wqes_needed = nr_frags >> 2;
+                       wqes_needed += (nr_frags&3)?1:0;
+                       wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) &
+                                       (nesnic->sq_size - 1);
+
+                       if (unlikely(wqes_needed > wqes_available)) {
+                               if (!netif_queue_stopped(netdev)) {
+                                       netif_stop_queue(netdev);
+                                       barrier();
+                                       wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) &
+                                               (nesnic->sq_size - 1);
+                                       if (wqes_needed <= wqes_available) {
+                                               netif_start_queue(netdev);
+                                               goto tso_sq_no_longer_full;
+                                       }
+                               }
+                               nesvnic->sq_full++;
+                               spin_unlock_irqrestore(&nesnic->sq_lock, flags);
+                               nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n",
+                                               netdev->name);
+                               return NETDEV_TX_BUSY;
+                       }
+tso_sq_no_longer_full:
+                       /* Map all the buffers */
+                       for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags;
+                                       tso_frag_count++) {
+                               tso_bus_address[tso_frag_count] = pci_map_page( nesdev->pcidev,
+                                               skb_shinfo(skb)->frags[tso_frag_count].page,
+                                               skb_shinfo(skb)->frags[tso_frag_count].page_offset,
+                                               skb_shinfo(skb)->frags[tso_frag_count].size,
+                                               PCI_DMA_TODEVICE);
+                       }
+
+                       tso_frag_index = 0;
+                       curr_tcp_seq = ntohl(tcp_hdr(skb)->seq);
+                       hoffset = skb_transport_header(skb) - skb->data;
+                       nhoffset = skb_network_header(skb) - skb->data;
+                       original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2);
+
+                       for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) {
+                               tso_wqe_length = 0;
+                               nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
+                               wqe_fragment_length =
+                                               (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
+                               /* setup the VLAN tag if present */
+                               if (vlan_tx_tag_present(skb)) {
+                                       nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
+                                                       netdev->name, vlan_tx_tag_get(skb) );
+                                       wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
+                                       wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
+                               } else
+                                       wqe_misc = 0;
+
+                               /* bump past the vlan tag */
+                               wqe_fragment_length++;
+
+                               /* Assumes header totally fits in allocated buffer and is in first fragment */
+                               if (original_first_length > NES_FIRST_FRAG_SIZE) {
+                                       nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
+                                                       original_first_length, NES_FIRST_FRAG_SIZE);
+                                       nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
+                                                       " (%u frags), tso_size=%u\n",
+                                                       netdev->name,
+                                                       skb->len, skb_headlen(skb),
+                                                       skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
+                               }
+                               memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
+                                               skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE),
+                                               original_first_length));
+                               iph = (struct iphdr *)
+                               (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]);
+                               tcph = (struct tcphdr *)
+                               (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]);
+                               if ((wqe_count+1)!=(u32)wqes_needed) {
+                                       tcph->fin = 0;
+                                       tcph->psh = 0;
+                                       tcph->rst = 0;
+                                       tcph->urg = 0;
+                               }
+                               if (wqe_count) {
+                                       tcph->syn = 0;
+                               }
+                               tcph->seq = htonl(curr_tcp_seq);
+                               wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
+                                               original_first_length));
+
+                               wqe_fragment_index = 1;
+                               if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) {
+                                       set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
+                                       bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length,
+                                                       skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE);
+                                       wqe_fragment_length[wqe_fragment_index++] =
+                                               cpu_to_le16(skb_headlen(skb) - original_first_length);
+                                       wqe_fragment_length[wqe_fragment_index] = 0;
+                                       set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
+                                                                       bus_address);
+                               }
+                               while (wqe_fragment_index < 5) {
+                                       wqe_fragment_length[wqe_fragment_index] =
+                                                       cpu_to_le16(skb_shinfo(skb)->frags[tso_frag_index].size);
+                                       set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
+                                               (u64)tso_bus_address[tso_frag_index]);
+                                       wqe_fragment_index++;
+                                       tso_wqe_length += skb_shinfo(skb)->frags[tso_frag_index++].size;
+                                       if (wqe_fragment_index < 5)
+                                               wqe_fragment_length[wqe_fragment_index] = 0;
+                                       if (tso_frag_index == tso_frag_count)
+                                               break;
+                               }
+                               if ((wqe_count+1) == (u32)wqes_needed) {
+                                       nesnic->tx_skb[nesnic->sq_head] = skb;
+                               } else {
+                                       nesnic->tx_skb[nesnic->sq_head] = NULL;
+                               }
+                               wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
+                               if ((tso_wqe_length + original_first_length) > skb_is_gso(skb)) {
+                                       wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE;
+                               } else {
+                                       iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset);
+                               }
+
+                               set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX,
+                                                wqe_misc);
+                               set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
+                                               ((u32)tcph->doff) | (((u32)hoffset) << 4));
+
+                               set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
+                                               tso_wqe_length + original_first_length);
+                               curr_tcp_seq += tso_wqe_length;
+                               nesnic->sq_head++;
+                               nesnic->sq_head &= nesnic->sq_size-1;
+                       }
+               } else {
+                       nesvnic->linearized_skbs++;
+                       hoffset = skb_transport_header(skb) - skb->data;
+                       nhoffset = skb_network_header(skb) - skb->data;
+                       skb_linearize(skb);
+                       skb_set_transport_header(skb, hoffset);
+                       skb_set_network_header(skb, nhoffset);
+                       send_rc = nes_nic_send(skb, netdev);
+                       if (send_rc != NETDEV_TX_OK) {
+                               spin_unlock_irqrestore(&nesnic->sq_lock, flags);
+                               return NETDEV_TX_OK;
+                       }
+               }
+       } else {
+               send_rc = nes_nic_send(skb, netdev);
+               if (send_rc != NETDEV_TX_OK) {
+                       spin_unlock_irqrestore(&nesnic->sq_lock, flags);
+                       return NETDEV_TX_OK;
+               }
+       }
+
+       barrier();
+
+       if (wqe_count)
+               nes_write32(nesdev->regs+NES_WQE_ALLOC,
+                               (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id);
+
+       netdev->trans_start = jiffies;
+       spin_unlock_irqrestore(&nesnic->sq_lock, flags);
+
+       return NETDEV_TX_OK;
+}
+
+
+/**
+ * nes_netdev_get_stats
+ */
+static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       u64 u64temp;
+       u32 u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200));
+       nesvnic->netstats.rx_dropped += u32temp;
+       nesvnic->endnode_nstat_rx_discard += u32temp;
+
+       u64temp = (u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + (nesvnic->nic_index*0x200));
+       u64temp += ((u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
+
+       nesvnic->endnode_nstat_rx_octets += u64temp;
+       nesvnic->netstats.rx_bytes += u64temp;
+
+       u64temp = (u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + (nesvnic->nic_index*0x200));
+       u64temp += ((u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
+
+       nesvnic->endnode_nstat_rx_frames += u64temp;
+       nesvnic->netstats.rx_packets += u64temp;
+
+       u64temp = (u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + (nesvnic->nic_index*0x200));
+       u64temp += ((u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
+
+       nesvnic->endnode_nstat_tx_octets += u64temp;
+       nesvnic->netstats.tx_bytes += u64temp;
+
+       u64temp = (u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + (nesvnic->nic_index*0x200));
+       u64temp += ((u64)nes_read_indexed(nesdev,
+                       NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
+
+       nesvnic->endnode_nstat_tx_frames += u64temp;
+       nesvnic->netstats.tx_packets += u64temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->netstats.rx_dropped += u32temp;
+       nesvnic->nesdev->mac_rx_errors += u32temp;
+       nesvnic->nesdev->mac_rx_short_frames += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->netstats.rx_dropped += u32temp;
+       nesvnic->nesdev->mac_rx_errors += u32temp;
+       nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->netstats.rx_dropped += u32temp;
+       nesvnic->nesdev->mac_rx_errors += u32temp;
+       nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->netstats.rx_dropped += u32temp;
+       nesvnic->nesdev->mac_rx_errors += u32temp;
+       nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->netstats.rx_length_errors += u32temp;
+       nesvnic->nesdev->mac_rx_errors += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->nesdev->mac_rx_errors += u32temp;
+       nesvnic->nesdev->mac_rx_crc_errors += u32temp;
+       nesvnic->netstats.rx_crc_errors += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->nesdev->mac_tx_errors += u32temp;
+       nesvnic->netstats.tx_errors += u32temp;
+
+       return &nesvnic->netstats;
+}
+
+
+/**
+ * nes_netdev_tx_timeout
+ */
+static void nes_netdev_tx_timeout(struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+
+       if (netif_msg_timer(nesvnic))
+               nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name);
+}
+
+
+/**
+ * nes_netdev_set_mac_address
+ */
+static int nes_netdev_set_mac_address(struct net_device *netdev, void *p)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct sockaddr *mac_addr = p;
+       int i;
+       u32 macaddr_low;
+       u16 macaddr_high;
+
+       if (!is_valid_ether_addr(mac_addr->sa_data))
+               return -EADDRNOTAVAIL;
+
+       memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
+       printk(PFX "%s: Address length = %d, Address = %02X%02X%02X%02X%02X%02X..\n",
+                  __FUNCTION__, netdev->addr_len,
+                  mac_addr->sa_data[0], mac_addr->sa_data[1],
+                  mac_addr->sa_data[2], mac_addr->sa_data[3],
+                  mac_addr->sa_data[4], mac_addr->sa_data[5]);
+       macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
+       macaddr_high += (u16)netdev->dev_addr[1];
+       macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
+       macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
+       macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
+       macaddr_low += (u32)netdev->dev_addr[5];
+
+       for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
+               if (nesvnic->qp_nic_index[i] == 0xf) {
+                       break;
+               }
+               nes_write_indexed(nesdev,
+                               NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
+                               macaddr_low);
+               nes_write_indexed(nesdev,
+                               NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
+                               (u32)macaddr_high | NES_MAC_ADDR_VALID |
+                               ((((u32)nesvnic->nic_index) << 16)));
+       }
+       return 0;
+}
+
+
+/**
+ * nes_netdev_set_multicast_list
+ */
+void nes_netdev_set_multicast_list(struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct dev_mc_list *multicast_addr;
+       u32 nic_active_bit;
+       u32 nic_active;
+       u32 perfect_filter_register_address;
+       u32 macaddr_low;
+       u16 macaddr_high;
+       u8 mc_all_on = 0;
+       u8 mc_index;
+       int mc_nic_index = -1;
+
+       nic_active_bit = 1 << nesvnic->nic_index;
+
+       if (netdev->flags & IFF_PROMISC) {
+               nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
+               nic_active |= nic_active_bit;
+               nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
+               nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
+               nic_active |= nic_active_bit;
+               nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
+               mc_all_on = 1;
+       } else if ((netdev->flags & IFF_ALLMULTI) || (netdev->mc_count > NES_MULTICAST_PF_MAX) ||
+                          (nesvnic->nic_index > 3)) {
+               nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
+               nic_active |= nic_active_bit;
+               nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
+               nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
+               nic_active &= ~nic_active_bit;
+               nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
+               mc_all_on = 1;
+       } else {
+               nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
+               nic_active &= ~nic_active_bit;
+               nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
+               nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
+               nic_active &= ~nic_active_bit;
+               nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
+       }
+
+       nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscous = %d, All Multicast = %d.\n",
+                         netdev->mc_count, (netdev->flags & IFF_PROMISC)?1:0,
+                         (netdev->flags & IFF_ALLMULTI)?1:0);
+       if (!mc_all_on) {
+               multicast_addr = netdev->mc_list;
+               perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW + 0x80;
+               perfect_filter_register_address += nesvnic->nic_index*0x40;
+               for (mc_index=0; mc_index < NES_MULTICAST_PF_MAX; mc_index++) {
+                       while (multicast_addr && nesvnic->mcrq_mcast_filter && ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic, multicast_addr->dmi_addr)) == 0))
+                               multicast_addr = multicast_addr->next;
+
+                       if (mc_nic_index < 0)
+                               mc_nic_index = nesvnic->nic_index;
+                       if (multicast_addr) {
+                               nes_debug(NES_DBG_NIC_RX, "Assigning MC Address = %02X%02X%02X%02X%02X%02X to register 0x%04X nic_idx=%d\n",
+                                                 multicast_addr->dmi_addr[0], multicast_addr->dmi_addr[1],
+                                                 multicast_addr->dmi_addr[2], multicast_addr->dmi_addr[3],
+                                                 multicast_addr->dmi_addr[4], multicast_addr->dmi_addr[5],
+                                                 perfect_filter_register_address+(mc_index * 8), mc_nic_index);
+                               macaddr_high = ((u16)multicast_addr->dmi_addr[0]) << 8;
+                               macaddr_high += (u16)multicast_addr->dmi_addr[1];
+                               macaddr_low = ((u32)multicast_addr->dmi_addr[2]) << 24;
+                               macaddr_low += ((u32)multicast_addr->dmi_addr[3]) << 16;
+                               macaddr_low += ((u32)multicast_addr->dmi_addr[4]) << 8;
+                               macaddr_low += (u32)multicast_addr->dmi_addr[5];
+                               nes_write_indexed(nesdev,
+                                               perfect_filter_register_address+(mc_index * 8),
+                                               macaddr_low);
+                               nes_write_indexed(nesdev,
+                                               perfect_filter_register_address+4+(mc_index * 8),
+                                               (u32)macaddr_high | NES_MAC_ADDR_VALID |
+                                               ((((u32)(1<<mc_nic_index)) << 16)));
+                               multicast_addr = multicast_addr->next;
+                       } else {
+                               nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n",
+                                                 perfect_filter_register_address+(mc_index * 8));
+                               nes_write_indexed(nesdev,
+                                               perfect_filter_register_address+4+(mc_index * 8),
+                                               0);
+                       }
+               }
+       }
+}
+
+
+/**
+ * nes_netdev_change_mtu
+ */
+static int nes_netdev_change_mtu(struct        net_device *netdev,     int     new_mtu)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev =     nesvnic->nesdev;
+       int     ret     = 0;
+       u8 jumbomode=0;
+
+       if ((new_mtu < ETH_ZLEN) ||     (new_mtu > max_mtu))
+               return -EINVAL;
+
+       netdev->mtu     = new_mtu;
+       nesvnic->max_frame_size = new_mtu+ETH_HLEN;
+
+       if (netdev->mtu > 1500) {
+               jumbomode=1;
+       }
+       nes_nic_init_timer_defaults(nesdev,     jumbomode);
+
+       if (netif_running(netdev)) {
+               nes_netdev_stop(netdev);
+               nes_netdev_open(netdev);
+       }
+
+       return ret;
+}
+
+
+/**
+ * nes_netdev_exit - destroy network device
+ */
+void nes_netdev_exit(struct nes_vnic *nesvnic)
+{
+       struct net_device *netdev = nesvnic->netdev;
+       struct nes_ib_device *nesibdev = nesvnic->nesibdev;
+
+       nes_debug(NES_DBG_SHUTDOWN, "\n");
+
+       // destroy the ibdevice if RDMA enabled
+       if ((nesvnic->rdma_enabled)&&(nesvnic->of_device_registered)) {
+               nes_destroy_ofa_device( nesibdev );
+               nesvnic->of_device_registered = 0;
+               nesvnic->nesibdev = NULL;
+       }
+       unregister_netdev(netdev);
+       nes_debug(NES_DBG_SHUTDOWN, "\n");
+}
+
+
+#define NES_ETHTOOL_STAT_COUNT 55
+static const char nes_ethtool_stringset[NES_ETHTOOL_STAT_COUNT][ETH_GSTRING_LEN] = {
+       "Link Change Interrupts",
+       "Linearized SKBs",
+       "T/GSO Requests",
+       "Pause Frames Sent",
+       "Pause Frames Received",
+       "Internal Routing Errors",
+       "SQ SW Dropped SKBs",
+       "SQ Locked",
+       "SQ Full",
+       "Segmented TSO Requests",
+       "Rx Symbol Errors",
+       "Rx Jabber Errors",
+       "Rx Oversized Frames",
+       "Rx Short Frames",
+       "Endnode Rx Discards",
+       "Endnode Rx Octets",
+       "Endnode Rx Frames",
+       "Endnode Tx Octets",
+       "Endnode Tx Frames",
+       "mh detected",
+       "mh pauses",
+       "Retransmission Count",
+       "CM Connects",
+       "CM Accepts",
+       "Disconnects",
+       "Connected Events",
+       "Connect Requests",
+       "CM Rejects",
+       "ModifyQP Timeouts",
+       "CreateQPs",
+       "SW DestroyQPs",
+       "DestroyQPs",
+       "CM Closes",
+       "CM Packets Sent",
+       "CM Packets Bounced",
+       "CM Packets Created",
+       "CM Packets Rcvd",
+       "CM Packets Dropped",
+       "CM Packets Retrans",
+       "CM Listens Created",
+       "CM Listens Destroyed",
+       "CM Backlog Drops",
+       "CM Loopbacks",
+       "CM Nodes Created",
+       "CM Nodes Destroyed",
+       "CM Accel Drops",
+       "CM Resets Received",
+       "Timer Inits",
+       "CQ Depth 1",
+       "CQ Depth 4",
+       "CQ Depth 16",
+       "CQ Depth 24",
+       "CQ Depth 32",
+       "CQ Depth 128",
+       "CQ Depth 256",
+};
+
+
+/**
+ * nes_netdev_get_rx_csum
+ */
+static u32 nes_netdev_get_rx_csum (struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+
+       if (nesvnic->rx_checksum_disabled)
+               return 0;
+       else
+               return 1;
+}
+
+
+/**
+ * nes_netdev_set_rc_csum
+ */
+static int nes_netdev_set_rx_csum(struct net_device *netdev, u32 enable)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+
+       if (enable)
+               nesvnic->rx_checksum_disabled = 0;
+       else
+               nesvnic->rx_checksum_disabled = 1;
+       return 0;
+}
+
+
+/**
+ * nes_netdev_get_stats_count
+ */
+static int nes_netdev_get_stats_count(struct net_device *netdev)
+{
+       return NES_ETHTOOL_STAT_COUNT;
+}
+
+
+/**
+ * nes_netdev_get_strings
+ */
+static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset,
+               u8 *ethtool_strings)
+{
+       if (stringset == ETH_SS_STATS)
+               memcpy(ethtool_strings,
+                               &nes_ethtool_stringset,
+                               sizeof(nes_ethtool_stringset));
+}
+
+
+/**
+ * nes_netdev_get_ethtool_stats
+ */
+static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
+               struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values)
+{
+       u64 u64temp;
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       u32 nic_count;
+       u32 u32temp;
+
+       target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
+       target_stat_values[0] = nesvnic->nesdev->link_status_interrupts;
+       target_stat_values[1] = nesvnic->linearized_skbs;
+       target_stat_values[2] = nesvnic->tso_requests;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->nesdev->mac_pause_frames_sent += u32temp;
+       target_stat_values[3] = nesvnic->nesdev->mac_pause_frames_sent;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
+       nesvnic->nesdev->mac_pause_frames_received += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
+       nesvnic->nesdev->port_rx_discards += u32temp;
+       nesvnic->netstats.rx_dropped += u32temp;
+
+       u32temp = nes_read_indexed(nesdev,
+                       NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
+       nesvnic->nesdev->port_tx_discards += u32temp;
+       nesvnic->netstats.tx_dropped += u32temp;
+
+       for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) {
+               if (nesvnic->qp_nic_index[nic_count] == 0xf)
+                       break;
+
+               u32temp = nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_RX_DISCARD +
+                               (nesvnic->qp_nic_index[nic_count]*0x200));
+               nesvnic->netstats.rx_dropped += u32temp;
+               nesvnic->endnode_nstat_rx_discard += u32temp;
+
+               u64temp = (u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO +
+                               (nesvnic->qp_nic_index[nic_count]*0x200));
+               u64temp += ((u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI +
+                               (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
+
+               nesvnic->endnode_nstat_rx_octets += u64temp;
+               nesvnic->netstats.rx_bytes += u64temp;
+
+               u64temp = (u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO +
+                               (nesvnic->qp_nic_index[nic_count]*0x200));
+               u64temp += ((u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI +
+                               (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
+
+               nesvnic->endnode_nstat_rx_frames += u64temp;
+               nesvnic->netstats.rx_packets += u64temp;
+
+               u64temp = (u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO +
+                               (nesvnic->qp_nic_index[nic_count]*0x200));
+               u64temp += ((u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI +
+                               (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
+
+               nesvnic->endnode_nstat_tx_octets += u64temp;
+               nesvnic->netstats.tx_bytes += u64temp;
+
+               u64temp = (u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO +
+                               (nesvnic->qp_nic_index[nic_count]*0x200));
+               u64temp += ((u64)nes_read_indexed(nesdev,
+                               NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI +
+                               (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
+
+               nesvnic->endnode_nstat_tx_frames += u64temp;
+               nesvnic->netstats.tx_packets += u64temp;
+
+               u32temp = nes_read_indexed(nesdev,
+                               NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200));
+               nesvnic->endnode_ipv4_tcp_retransmits += u32temp;
+       }
+
+       target_stat_values[4] = nesvnic->nesdev->mac_pause_frames_received;
+       target_stat_values[5] = nesdev->nesadapter->nic_rx_eth_route_err;
+       target_stat_values[6] = nesvnic->tx_sw_dropped;
+       target_stat_values[7] = nesvnic->sq_locked;
+       target_stat_values[8] = nesvnic->sq_full;
+       target_stat_values[9] = nesvnic->segmented_tso_requests;
+       target_stat_values[10] = nesvnic->nesdev->mac_rx_symbol_err_frames;
+       target_stat_values[11] = nesvnic->nesdev->mac_rx_jabber_frames;
+       target_stat_values[12] = nesvnic->nesdev->mac_rx_oversized_frames;
+       target_stat_values[13] = nesvnic->nesdev->mac_rx_short_frames;
+       target_stat_values[14] = nesvnic->endnode_nstat_rx_discard;
+       target_stat_values[15] = nesvnic->endnode_nstat_rx_octets;
+       target_stat_values[16] = nesvnic->endnode_nstat_rx_frames;
+       target_stat_values[17] = nesvnic->endnode_nstat_tx_octets;
+       target_stat_values[18] = nesvnic->endnode_nstat_tx_frames;
+       target_stat_values[19] = mh_detected;
+       target_stat_values[20] = mh_pauses_sent;
+       target_stat_values[21] = nesvnic->endnode_ipv4_tcp_retransmits;
+       target_stat_values[22] = atomic_read(&cm_connects);
+       target_stat_values[23] = atomic_read(&cm_accepts);
+       target_stat_values[24] = atomic_read(&cm_disconnects);
+       target_stat_values[25] = atomic_read(&cm_connecteds);
+       target_stat_values[26] = atomic_read(&cm_connect_reqs);
+       target_stat_values[27] = atomic_read(&cm_rejects);
+       target_stat_values[28] = atomic_read(&mod_qp_timouts);
+       target_stat_values[29] = atomic_read(&qps_created);
+       target_stat_values[30] = atomic_read(&sw_qps_destroyed);
+       target_stat_values[31] = atomic_read(&qps_destroyed);
+       target_stat_values[32] = atomic_read(&cm_closes);
+       target_stat_values[33] = cm_packets_sent;
+       target_stat_values[34] = cm_packets_bounced;
+       target_stat_values[35] = cm_packets_created;
+       target_stat_values[36] = cm_packets_received;
+       target_stat_values[37] = cm_packets_dropped;
+       target_stat_values[38] = cm_packets_retrans;
+       target_stat_values[39] = cm_listens_created;
+       target_stat_values[40] = cm_listens_destroyed;
+       target_stat_values[41] = cm_backlog_drops;
+       target_stat_values[42] = atomic_read(&cm_loopbacks);
+       target_stat_values[43] = atomic_read(&cm_nodes_created);
+       target_stat_values[44] = atomic_read(&cm_nodes_destroyed);
+       target_stat_values[45] = atomic_read(&cm_accel_dropped_pkts);
+       target_stat_values[46] = atomic_read(&cm_resets_recvd);
+       target_stat_values[47] = int_mod_timer_init;
+       target_stat_values[48] = int_mod_cq_depth_1;
+       target_stat_values[49] = int_mod_cq_depth_4;
+       target_stat_values[50] = int_mod_cq_depth_16;
+       target_stat_values[51] = int_mod_cq_depth_24;
+       target_stat_values[52] = int_mod_cq_depth_32;
+       target_stat_values[53] = int_mod_cq_depth_128;
+       target_stat_values[54] = int_mod_cq_depth_256;
+
+}
+
+
+/**
+ * nes_netdev_get_drvinfo
+ */
+static void nes_netdev_get_drvinfo(struct net_device *netdev,
+               struct ethtool_drvinfo *drvinfo)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+
+       strcpy(drvinfo->driver, DRV_NAME);
+       strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
+       strcpy(drvinfo->fw_version, "TBD");
+       strcpy(drvinfo->version, DRV_VERSION);
+       drvinfo->n_stats = nes_netdev_get_stats_count(netdev);
+       drvinfo->testinfo_len = 0;
+       drvinfo->eedump_len = 0;
+       drvinfo->regdump_len = 0;
+}
+
+
+/**
+ * nes_netdev_set_coalesce
+ */
+static int nes_netdev_set_coalesce(struct net_device *netdev,
+               struct ethtool_coalesce *et_coalesce)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev =     nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
+       unsigned long flags;
+
+       spin_lock_irqsave(&nesadapter->periodic_timer_lock,     flags);
+       if (et_coalesce->rx_max_coalesced_frames_low) {
+               shared_timer->threshold_low      = et_coalesce->rx_max_coalesced_frames_low;
+       }
+       if (et_coalesce->rx_max_coalesced_frames_irq) {
+               shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq;
+       }
+       if (et_coalesce->rx_max_coalesced_frames_high) {
+               shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high;
+       }
+       if (et_coalesce->rx_coalesce_usecs_low) {
+               shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low;
+       }
+       if (et_coalesce->rx_coalesce_usecs_high) {
+               shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high;
+       }
+       spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
+
+       /* using this to drive total interrupt moderation */
+       nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq;
+       if (et_coalesce->use_adaptive_rx_coalesce) {
+               nesadapter->et_use_adaptive_rx_coalesce = 1;
+               nesadapter->timer_int_limit     = NES_TIMER_INT_LIMIT_DYNAMIC;
+               nesadapter->et_rx_coalesce_usecs_irq = 0;
+               if (et_coalesce->pkt_rate_low) {
+                       nesadapter->et_pkt_rate_low     = et_coalesce->pkt_rate_low;
+               }
+       } else {
+               nesadapter->et_use_adaptive_rx_coalesce = 0;
+               nesadapter->timer_int_limit     = NES_TIMER_INT_LIMIT;
+               if (nesadapter->et_rx_coalesce_usecs_irq) {
+                       nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
+                                       0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8)));
+               }
+       }
+       return 0;
+}
+
+
+/**
+ * nes_netdev_get_coalesce
+ */
+static int nes_netdev_get_coalesce(struct net_device *netdev,
+               struct ethtool_coalesce *et_coalesce)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev =     nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct ethtool_coalesce temp_et_coalesce;
+       struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
+       unsigned long flags;
+
+       memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce));
+       temp_et_coalesce.rx_coalesce_usecs_irq = nesadapter->et_rx_coalesce_usecs_irq;
+       temp_et_coalesce.use_adaptive_rx_coalesce =     nesadapter->et_use_adaptive_rx_coalesce;
+       temp_et_coalesce.rate_sample_interval = nesadapter->et_rate_sample_interval;
+       temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low;
+       spin_lock_irqsave(&nesadapter->periodic_timer_lock,     flags);
+       temp_et_coalesce.rx_max_coalesced_frames_low =  shared_timer->threshold_low;
+       temp_et_coalesce.rx_max_coalesced_frames_irq =  shared_timer->threshold_target;
+       temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
+       temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min;
+       temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max;
+       if (nesadapter->et_use_adaptive_rx_coalesce) {
+               temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use;
+       }
+       spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
+       memcpy(et_coalesce,     &temp_et_coalesce, sizeof(*et_coalesce));
+       return 0;
+}
+
+
+/**
+ * nes_netdev_get_pauseparam
+ */
+static void nes_netdev_get_pauseparam(struct net_device *netdev,
+               struct ethtool_pauseparam *et_pauseparam)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+
+       et_pauseparam->autoneg = 0;
+       et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0;
+       et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0;
+}
+
+
+/**
+ * nes_netdev_set_pauseparam
+ */
+static int nes_netdev_set_pauseparam(struct net_device *netdev,
+               struct ethtool_pauseparam *et_pauseparam)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       u32 u32temp;
+
+       if (et_pauseparam->autoneg) {
+               /* TODO: should return unsupported */
+               return 0;
+       }
+       if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) {
+               u32temp = nes_read_indexed(nesdev,
+                               NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
+               u32temp |= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
+               nes_write_indexed(nesdev,
+                               NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp);
+               nesdev->disable_tx_flow_control = 0;
+       } else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) {
+               u32temp = nes_read_indexed(nesdev,
+                               NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
+               u32temp &= ~NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
+               nes_write_indexed(nesdev,
+                               NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp);
+               nesdev->disable_tx_flow_control = 1;
+       }
+       if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) {
+               u32temp = nes_read_indexed(nesdev,
+                               NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
+               u32temp &= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
+               nes_write_indexed(nesdev,
+                               NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
+               nesdev->disable_rx_flow_control = 0;
+       } else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) {
+               u32temp = nes_read_indexed(nesdev,
+                               NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
+               u32temp |= NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
+               nes_write_indexed(nesdev,
+                               NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
+               nesdev->disable_rx_flow_control = 1;
+       }
+
+       return 0;
+}
+
+
+/**
+ * nes_netdev_get_settings
+ */
+static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u16 phy_data;
+
+       et_cmd->duplex = DUPLEX_FULL;
+       et_cmd->port = PORT_MII;
+       if (nesadapter->OneG_Mode) {
+               et_cmd->supported = SUPPORTED_1000baseT_Full|SUPPORTED_Autoneg;
+               et_cmd->advertising = ADVERTISED_1000baseT_Full|ADVERTISED_Autoneg;
+               et_cmd->speed = SPEED_1000;
+               nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
+                               &phy_data);
+               if (phy_data&0x1000) {
+                       et_cmd->autoneg = AUTONEG_ENABLE;
+               } else {
+                       et_cmd->autoneg = AUTONEG_DISABLE;
+               }
+               et_cmd->transceiver = XCVR_EXTERNAL;
+               et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
+       } else {
+               if (nesadapter->phy_type[nesvnic->logical_port] == NES_PHY_TYPE_IRIS) {
+                       et_cmd->transceiver = XCVR_EXTERNAL;
+                       et_cmd->port = PORT_FIBRE;
+                       et_cmd->supported = SUPPORTED_FIBRE;
+                       et_cmd->advertising = ADVERTISED_FIBRE;
+                       et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
+               } else {
+                       et_cmd->transceiver = XCVR_INTERNAL;
+                       et_cmd->supported = SUPPORTED_10000baseT_Full;
+                       et_cmd->advertising = ADVERTISED_10000baseT_Full;
+                       et_cmd->phy_address = nesdev->mac_index;
+               }
+               et_cmd->speed = SPEED_10000;
+               et_cmd->autoneg = AUTONEG_DISABLE;
+       }
+       et_cmd->maxtxpkt = 511;
+       et_cmd->maxrxpkt = 511;
+       return 0;
+}
+
+
+/**
+ * nes_netdev_set_settings
+ */
+static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u16 phy_data;
+
+       if (nesadapter->OneG_Mode) {
+               nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
+                               &phy_data);
+               if (et_cmd->autoneg) {
+                       /* Turn on Full duplex, Autoneg, and restart autonegotiation */
+                       phy_data |= 0x1300;
+               } else {
+                       // Turn off autoneg
+                       phy_data &= ~0x1000;
+               }
+               nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
+                               phy_data);
+       }
+
+       return 0;
+}
+
+
+static struct ethtool_ops nes_ethtool_ops = {
+       .get_link = ethtool_op_get_link,
+       .get_settings = nes_netdev_get_settings,
+       .set_settings = nes_netdev_set_settings,
+       .get_tx_csum = ethtool_op_get_tx_csum,
+       .get_rx_csum = nes_netdev_get_rx_csum,
+       .get_sg = ethtool_op_get_sg,
+       .get_strings = nes_netdev_get_strings,
+       .get_stats_count = nes_netdev_get_stats_count,
+       .get_ethtool_stats = nes_netdev_get_ethtool_stats,
+       .get_drvinfo = nes_netdev_get_drvinfo,
+       .get_coalesce = nes_netdev_get_coalesce,
+       .set_coalesce = nes_netdev_set_coalesce,
+       .get_pauseparam = nes_netdev_get_pauseparam,
+       .set_pauseparam = nes_netdev_set_pauseparam,
+       .set_tx_csum = ethtool_op_set_tx_csum,
+       .set_rx_csum = nes_netdev_set_rx_csum,
+       .set_sg = ethtool_op_set_sg,
+       .get_tso = ethtool_op_get_tso,
+       .set_tso = ethtool_op_set_tso,
+};
+
+
+static void nes_netdev_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       u32 u32temp;
+
+       nesvnic->vlan_grp = grp;
+
+       /* Enable/Disable VLAN Stripping */
+       u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
+       if (grp)
+               u32temp &= 0xfdffffff;
+       else
+               u32temp |= 0x02000000;
+
+       nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
+}
+
+
+/**
+ * nes_netdev_init - initialize network device
+ */
+struct net_device *nes_netdev_init(struct nes_device *nesdev,
+               void __iomem *mmio_addr)
+{
+       u64 u64temp;
+       struct nes_vnic *nesvnic = NULL;
+       struct net_device *netdev;
+       struct nic_qp_map *curr_qp_map;
+       u32 u32temp;
+       u16 phy_data;
+       u16 temp_phy_data;
+
+       netdev = alloc_etherdev(sizeof(struct nes_vnic));
+       if (!netdev) {
+               printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
+               return NULL;
+       }
+
+       nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name);
+
+       SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev);
+
+       nesvnic = netdev_priv(netdev);
+       memset(nesvnic, 0, sizeof(*nesvnic));
+
+       netdev->open = nes_netdev_open;
+       netdev->stop = nes_netdev_stop;
+       netdev->hard_start_xmit = nes_netdev_start_xmit;
+       netdev->get_stats = nes_netdev_get_stats;
+       netdev->tx_timeout = nes_netdev_tx_timeout;
+       netdev->set_mac_address = nes_netdev_set_mac_address;
+       netdev->set_multicast_list = nes_netdev_set_multicast_list;
+       netdev->change_mtu = nes_netdev_change_mtu;
+       netdev->watchdog_timeo = NES_TX_TIMEOUT;
+       netdev->irq = nesdev->pcidev->irq;
+       netdev->mtu = ETH_DATA_LEN;
+       netdev->hard_header_len = ETH_HLEN;
+       netdev->addr_len = ETH_ALEN;
+       netdev->type = ARPHRD_ETHER;
+       netdev->features = NETIF_F_HIGHDMA;
+       netdev->ethtool_ops = &nes_ethtool_ops;
+       netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128);
+       nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n");
+       netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
+       netdev->vlan_rx_register = nes_netdev_vlan_rx_register;
+       netdev->features |= NETIF_F_LLTX;
+
+       /* Fill in the port structure */
+       nesvnic->netdev = netdev;
+       nesvnic->nesdev = nesdev;
+       nesvnic->msg_enable = netif_msg_init(debug, default_msg);
+       nesvnic->netdev_index = nesdev->netdev_count;
+       nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count;
+       nesvnic->max_frame_size = netdev->mtu+netdev->hard_header_len;
+
+       curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)];
+       nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid;
+       nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index;
+       nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port;
+
+       /* Setup the burned in MAC address */
+       u64temp = (u64)nesdev->nesadapter->mac_addr_low;
+       u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32;
+       u64temp += nesvnic->nic_index;
+       netdev->dev_addr[0] = (u8)(u64temp>>40);
+       netdev->dev_addr[1] = (u8)(u64temp>>32);
+       netdev->dev_addr[2] = (u8)(u64temp>>24);
+       netdev->dev_addr[3] = (u8)(u64temp>>16);
+       netdev->dev_addr[4] = (u8)(u64temp>>8);
+       netdev->dev_addr[5] = (u8)u64temp;
+       memcpy(netdev->perm_addr, netdev->dev_addr, 6);
+
+       if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV)) {
+               netdev->features |= NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
+               netdev->features |= NETIF_F_GSO | NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
+       } else {
+               netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
+       }
+
+       nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
+                       " nic_index = %d, logical_port = %d, mac_index = %d.\n",
+                       nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id,
+                       nesvnic->nic_index, nesvnic->logical_port,  nesdev->mac_index);
+
+       if (nesvnic->nesdev->nesadapter->port_count == 1) {
+               nesvnic->qp_nic_index[0] = nesvnic->nic_index;
+               nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1;
+               if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) {
+                       nesvnic->qp_nic_index[2] = 0xf;
+                       nesvnic->qp_nic_index[3] = 0xf;
+               } else {
+                       nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2;
+                       nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3;
+               }
+       } else {
+               if (nesvnic->nesdev->nesadapter->port_count == 2) {
+                       nesvnic->qp_nic_index[0] = nesvnic->nic_index;
+                       nesvnic->qp_nic_index[1] = nesvnic->nic_index + 2;
+                       nesvnic->qp_nic_index[2] = 0xf;
+                       nesvnic->qp_nic_index[3] = 0xf;
+               } else {
+                       nesvnic->qp_nic_index[0] = nesvnic->nic_index;
+                       nesvnic->qp_nic_index[1] = 0xf;
+                       nesvnic->qp_nic_index[2] = 0xf;
+                       nesvnic->qp_nic_index[3] = 0xf;
+               }
+       }
+       nesvnic->next_qp_nic_index = 0;
+
+       if (nesdev->netdev_count == 0) {
+               nesvnic->rdma_enabled = 1;
+       } else {
+               nesvnic->rdma_enabled = 0;
+       }
+       nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id;
+       spin_lock_init(&nesvnic->tx_lock);
+       nesdev->netdev[nesdev->netdev_count] = netdev;
+
+       nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
+                       nesvnic, nesdev->mac_index);
+       list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]);
+
+       if ((nesdev->netdev_count == 0) &&
+                       (PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index)) {
+               nes_debug(NES_DBG_INIT, "Setting up PHY interrupt mask. Using register index 0x%04X\n",
+                               NES_IDX_PHY_PCS_CONTROL_STATUS0+(0x200*(nesvnic->logical_port&1)));
+               u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
+                               (0x200*(nesvnic->logical_port&1)));
+               u32temp |= 0x00200000;
+               nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
+                               (0x200*(nesvnic->logical_port&1)), u32temp);
+               u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
+                               (0x200*(nesvnic->logical_port&1)) );
+               if ((u32temp&0x0f1f0000) == 0x0f0f0000) {
+                       if (nesdev->nesadapter->phy_type[nesvnic->logical_port] == NES_PHY_TYPE_IRIS) {
+                               nes_init_phy(nesdev);
+                               nes_read_10G_phy_reg(nesdev, 1,
+                                               nesdev->nesadapter->phy_index[nesvnic->logical_port]);
+                               temp_phy_data = (u16)nes_read_indexed(nesdev,
+                                                                       NES_IDX_MAC_MDIO_CONTROL);
+                               u32temp = 20;
+                               do {
+                                       nes_read_10G_phy_reg(nesdev, 1,
+                                                       nesdev->nesadapter->phy_index[nesvnic->logical_port]);
+                                       phy_data = (u16)nes_read_indexed(nesdev,
+                                                                       NES_IDX_MAC_MDIO_CONTROL);
+                                       if ((phy_data == temp_phy_data) || (!(--u32temp)))
+                                               break;
+                                       temp_phy_data = phy_data;
+                               } while (1);
+                               if (phy_data & 4) {
+                                       nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
+                                       nesvnic->linkup = 1;
+                               } else {
+                                       nes_debug(NES_DBG_INIT, "The Link is DOWN!!.\n");
+                               }
+                       } else {
+                               nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
+                               nesvnic->linkup = 1;
+                       }
+               }
+               nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n");
+               /* clear the MAC interrupt status, assumes direct logical to physical mapping */
+               u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS+(0x200*nesvnic->logical_port));
+               nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
+               nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS+(0x200*nesvnic->logical_port), u32temp);
+
+               if (nesdev->nesadapter->phy_type[nesvnic->logical_port] != NES_PHY_TYPE_IRIS)
+                       nes_init_phy(nesdev);
+
+               nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesvnic->logical_port),
+                               ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
+                               NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
+       }
+
+       return netdev;
+}
+
+
+/**
+ * nes_netdev_destroy - destroy network device structure
+ */
+void nes_netdev_destroy(struct net_device *netdev)
+{
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+
+       /* make sure 'stop' method is called by Linux stack */
+       /* nes_netdev_stop(netdev); */
+
+       list_del(&nesvnic->list);
+
+       if (nesvnic->of_device_registered) {
+               nes_destroy_ofa_device(nesvnic->nesibdev);
+       }
+
+       free_netdev(netdev);
+}
+
+
+/**
+ * nes_nic_cm_xmit -- CM calls this to send out pkts
+ */
+int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev)
+{
+       int ret;
+
+       skb->dev = netdev;
+       ret = dev_queue_xmit(skb);
+       if (ret) {
+               nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret);
+       }
+
+       return ret;
+}
diff --git a/drivers/infiniband/hw/nes/nes_user.h b/drivers/infiniband/hw/nes/nes_user.h
new file mode 100644 (file)
index 0000000..e64306b
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect.  All rights reserved.
+ * Copyright (c) 2005 Topspin Communications.  All rights reserved.
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
+ * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef NES_USER_H
+#define NES_USER_H
+
+#include <linux/types.h>
+
+#define NES_ABI_USERSPACE_VER 1
+#define NES_ABI_KERNEL_VER    1
+
+/*
+ * Make sure that all structs defined in this file remain laid out so
+ * that they pack the same way on 32-bit and 64-bit architectures (to
+ * avoid incompatibility between 32-bit userspace and 64-bit kernels).
+ * In particular do not use pointer types -- pass pointers in __u64
+ * instead.
+ */
+
+struct nes_alloc_ucontext_req {
+       __u32 reserved32;
+       __u8  userspace_ver;
+       __u8  reserved8[3];
+};
+
+struct nes_alloc_ucontext_resp {
+       __u32 max_pds; /* maximum pds allowed for this user process */
+       __u32 max_qps; /* maximum qps allowed for this user process */
+       __u32 wq_size; /* size of the WQs (sq+rq) allocated to the mmaped area */
+       __u8  virtwq;  /* flag to indicate if virtual WQ are to be used or not */
+       __u8  kernel_ver;
+       __u8  reserved[2];
+};
+
+struct nes_alloc_pd_resp {
+       __u32 pd_id;
+       __u32 mmap_db_index;
+};
+
+struct nes_create_cq_req {
+       __u64 user_cq_buffer;
+       __u32 mcrqf;
+       __u8 reserved[4];
+};
+
+struct nes_create_qp_req {
+       __u64 user_wqe_buffers;
+};
+
+enum iwnes_memreg_type {
+       IWNES_MEMREG_TYPE_MEM = 0x0000,
+       IWNES_MEMREG_TYPE_QP = 0x0001,
+       IWNES_MEMREG_TYPE_CQ = 0x0002,
+       IWNES_MEMREG_TYPE_MW = 0x0003,
+       IWNES_MEMREG_TYPE_FMR = 0x0004,
+};
+
+struct nes_mem_reg_req {
+       __u32 reg_type; /* indicates if id is memory, QP or CQ */
+       __u32 reserved;
+};
+
+struct nes_create_cq_resp {
+       __u32 cq_id;
+       __u32 cq_size;
+       __u32 mmap_db_index;
+       __u32 reserved;
+};
+
+struct nes_create_qp_resp {
+       __u32 qp_id;
+       __u32 actual_sq_size;
+       __u32 actual_rq_size;
+       __u32 mmap_sq_db_index;
+       __u32 mmap_rq_db_index;
+       __u32 nes_drv_opt;
+};
+
+#endif                         /* NES_USER_H */
diff --git a/drivers/infiniband/hw/nes/nes_utils.c b/drivers/infiniband/hw/nes/nes_utils.c
new file mode 100644 (file)
index 0000000..c4ec6ac
--- /dev/null
@@ -0,0 +1,917 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/if_vlan.h>
+#include <linux/crc32.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/init.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/byteorder.h>
+
+#include "nes.h"
+
+
+
+static u16 nes_read16_eeprom(void __iomem *addr, u16 offset);
+
+u32 mh_detected;
+u32 mh_pauses_sent;
+
+/**
+ * nes_read_eeprom_values -
+ */
+int nes_read_eeprom_values(struct nes_device *nesdev, struct nes_adapter *nesadapter)
+{
+       u32 mac_addr_low;
+       u16 mac_addr_high;
+       u16 eeprom_data;
+       u16 eeprom_offset;
+       u16 next_section_address;
+       u16 sw_section_ver;
+       u8  major_ver = 0;
+       u8  minor_ver = 0;
+
+       /* TODO: deal with EEPROM endian issues */
+       if (nesadapter->firmware_eeprom_offset == 0) {
+               /* Read the EEPROM Parameters */
+               eeprom_data = nes_read16_eeprom(nesdev->regs, 0);
+               nes_debug(NES_DBG_HW, "EEPROM Offset 0  = 0x%04X\n", eeprom_data);
+               eeprom_offset = 2 + (((eeprom_data & 0x007f) << 3) <<
+                               ((eeprom_data & 0x0080) >> 7));
+               nes_debug(NES_DBG_HW, "Firmware Offset = 0x%04X\n", eeprom_offset);
+               nesadapter->firmware_eeprom_offset = eeprom_offset;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 4);
+               if (eeprom_data != 0x5746) {
+                       nes_debug(NES_DBG_HW, "Not a valid Firmware Image = 0x%04X\n", eeprom_data);
+                       return -1;
+               }
+
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 2);
+               nes_debug(NES_DBG_HW, "EEPROM Offset %u  = 0x%04X\n",
+                               eeprom_offset + 2, eeprom_data);
+               eeprom_offset += ((eeprom_data & 0x00ff) << 3) << ((eeprom_data & 0x0100) >> 8);
+               nes_debug(NES_DBG_HW, "Software Offset = 0x%04X\n", eeprom_offset);
+               nesadapter->software_eeprom_offset = eeprom_offset;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 4);
+               if (eeprom_data != 0x5753) {
+                       printk("Not a valid Software Image = 0x%04X\n", eeprom_data);
+                       return -1;
+               }
+               sw_section_ver = nes_read16_eeprom(nesdev->regs, nesadapter->software_eeprom_offset  + 6);
+               nes_debug(NES_DBG_HW, "Software section version number = 0x%04X\n",
+                               sw_section_ver);
+
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 2);
+               nes_debug(NES_DBG_HW, "EEPROM Offset %u (next section)  = 0x%04X\n",
+                               eeprom_offset + 2, eeprom_data);
+               next_section_address = eeprom_offset + (((eeprom_data & 0x00ff) << 3) <<
+                               ((eeprom_data & 0x0100) >> 8));
+               eeprom_data = nes_read16_eeprom(nesdev->regs, next_section_address + 4);
+               if (eeprom_data != 0x414d) {
+                       nes_debug(NES_DBG_HW, "EEPROM Changed offset should be 0x414d but was 0x%04X\n",
+                                       eeprom_data);
+                       goto no_fw_rev;
+               }
+               eeprom_offset = next_section_address;
+
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 2);
+               nes_debug(NES_DBG_HW, "EEPROM Offset %u (next section)  = 0x%04X\n",
+                               eeprom_offset + 2, eeprom_data);
+               next_section_address = eeprom_offset + (((eeprom_data & 0x00ff) << 3) <<
+                               ((eeprom_data & 0x0100) >> 8));
+               eeprom_data = nes_read16_eeprom(nesdev->regs, next_section_address + 4);
+               if (eeprom_data != 0x4f52) {
+                       nes_debug(NES_DBG_HW, "EEPROM Changed offset should be 0x4f52 but was 0x%04X\n",
+                                       eeprom_data);
+                       goto no_fw_rev;
+               }
+               eeprom_offset = next_section_address;
+
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 2);
+               nes_debug(NES_DBG_HW, "EEPROM Offset %u (next section)  = 0x%04X\n",
+                               eeprom_offset + 2, eeprom_data);
+               next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
+               eeprom_data = nes_read16_eeprom(nesdev->regs, next_section_address + 4);
+               if (eeprom_data != 0x5746) {
+                       nes_debug(NES_DBG_HW, "EEPROM Changed offset should be 0x5746 but was 0x%04X\n",
+                                       eeprom_data);
+                       goto no_fw_rev;
+               }
+               eeprom_offset = next_section_address;
+
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 2);
+               nes_debug(NES_DBG_HW, "EEPROM Offset %u (next section)  = 0x%04X\n",
+                               eeprom_offset + 2, eeprom_data);
+               next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
+               eeprom_data = nes_read16_eeprom(nesdev->regs, next_section_address + 4);
+               if (eeprom_data != 0x5753) {
+                       nes_debug(NES_DBG_HW, "EEPROM Changed offset should be 0x5753 but was 0x%04X\n",
+                                       eeprom_data);
+                       goto no_fw_rev;
+               }
+               eeprom_offset = next_section_address;
+
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 2);
+               nes_debug(NES_DBG_HW, "EEPROM Offset %u (next section)  = 0x%04X\n",
+                               eeprom_offset + 2, eeprom_data);
+               next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
+               eeprom_data = nes_read16_eeprom(nesdev->regs, next_section_address + 4);
+               if (eeprom_data != 0x414d) {
+                       nes_debug(NES_DBG_HW, "EEPROM Changed offset should be 0x414d but was 0x%04X\n",
+                                       eeprom_data);
+                       goto no_fw_rev;
+               }
+               eeprom_offset = next_section_address;
+
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset + 2);
+               nes_debug(NES_DBG_HW, "EEPROM Offset %u (next section)  = 0x%04X\n",
+                               eeprom_offset + 2, eeprom_data);
+               next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
+               eeprom_data = nes_read16_eeprom(nesdev->regs, next_section_address + 4);
+               if (eeprom_data != 0x464e) {
+                       nes_debug(NES_DBG_HW, "EEPROM Changed offset should be 0x464e but was 0x%04X\n",
+                                       eeprom_data);
+                       goto no_fw_rev;
+               }
+               eeprom_data = nes_read16_eeprom(nesdev->regs, next_section_address + 8);
+               printk(PFX "Firmware version %u.%u\n", (u8)(eeprom_data>>8), (u8)eeprom_data);
+               major_ver = (u8)(eeprom_data >> 8);
+               minor_ver = (u8)(eeprom_data);
+
+               if (nes_drv_opt & NES_DRV_OPT_DISABLE_VIRT_WQ) {
+                       nes_debug(NES_DBG_HW, "Virtual WQs have been disabled\n");
+               } else if (((major_ver == 2) && (minor_ver > 21)) || ((major_ver > 2) && (major_ver != 255))) {
+                       nesadapter->virtwq = 1;
+               }
+               nesadapter->firmware_version = (((u32)(u8)(eeprom_data>>8))  <<  16) +
+                               (u32)((u8)eeprom_data);
+
+no_fw_rev:
+               /* eeprom is valid */
+               eeprom_offset = nesadapter->software_eeprom_offset;
+               eeprom_offset += 8;
+               nesadapter->netdev_max = (u8)nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               mac_addr_high = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               mac_addr_low = (u32)nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               mac_addr_low <<= 16;
+               mac_addr_low += (u32)nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "Base MAC Address = 0x%04X%08X\n",
+                               mac_addr_high, mac_addr_low);
+               nes_debug(NES_DBG_HW, "MAC Address count = %u\n", nesadapter->netdev_max);
+
+               nesadapter->mac_addr_low = mac_addr_low;
+               nesadapter->mac_addr_high = mac_addr_high;
+
+               /* Read the Phy Type array */
+               eeprom_offset += 10;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->phy_type[0] = (u8)(eeprom_data >> 8);
+               nesadapter->phy_type[1] = (u8)eeprom_data;
+
+               /* Read the port array */
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->phy_type[2] = (u8)(eeprom_data >> 8);
+               nesadapter->phy_type[3] = (u8)eeprom_data;
+               /* port_count is set by soft reset reg */
+               nes_debug(NES_DBG_HW, "port_count = %u, port 0 -> %u, port 1 -> %u,"
+                               " port 2 -> %u, port 3 -> %u\n",
+                               nesadapter->port_count,
+                               nesadapter->phy_type[0], nesadapter->phy_type[1],
+                               nesadapter->phy_type[2], nesadapter->phy_type[3]);
+
+               /* Read PD config array */
+               eeprom_offset += 10;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_size[0] = eeprom_data;
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_base[0] = eeprom_data;
+               nes_debug(NES_DBG_HW, "PD0 config, size=0x%04x, base=0x%04x\n",
+                               nesadapter->pd_config_size[0], nesadapter->pd_config_base[0]);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_size[1] = eeprom_data;
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_base[1] = eeprom_data;
+               nes_debug(NES_DBG_HW, "PD1 config, size=0x%04x, base=0x%04x\n",
+                               nesadapter->pd_config_size[1], nesadapter->pd_config_base[1]);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_size[2] = eeprom_data;
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_base[2] = eeprom_data;
+               nes_debug(NES_DBG_HW, "PD2 config, size=0x%04x, base=0x%04x\n",
+                               nesadapter->pd_config_size[2], nesadapter->pd_config_base[2]);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_size[3] = eeprom_data;
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nesadapter->pd_config_base[3] = eeprom_data;
+               nes_debug(NES_DBG_HW, "PD3 config, size=0x%04x, base=0x%04x\n",
+                               nesadapter->pd_config_size[3], nesadapter->pd_config_base[3]);
+
+               /* Read Rx Pool Size */
+               eeprom_offset += 22;   /* 46 */
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->rx_pool_size = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "rx_pool_size = 0x%08X\n", nesadapter->rx_pool_size);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->tx_pool_size = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "tx_pool_size = 0x%08X\n", nesadapter->tx_pool_size);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->rx_threshold = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "rx_threshold = 0x%08X\n", nesadapter->rx_threshold);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->tcp_timer_core_clk_divisor = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "tcp_timer_core_clk_divisor = 0x%08X\n",
+                               nesadapter->tcp_timer_core_clk_divisor);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->iwarp_config = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "iwarp_config = 0x%08X\n", nesadapter->iwarp_config);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->cm_config = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "cm_config = 0x%08X\n", nesadapter->cm_config);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->sws_timer_config = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "sws_timer_config = 0x%08X\n", nesadapter->sws_timer_config);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->tcp_config1 = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "tcp_config1 = 0x%08X\n", nesadapter->tcp_config1);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->wqm_wat = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "wqm_wat = 0x%08X\n", nesadapter->wqm_wat);
+
+               eeprom_offset += 2;
+               eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               eeprom_offset += 2;
+               nesadapter->core_clock = (((u32)eeprom_data) << 16) +
+                               nes_read16_eeprom(nesdev->regs, eeprom_offset);
+               nes_debug(NES_DBG_HW, "core_clock = 0x%08X\n", nesadapter->core_clock);
+
+               if ((sw_section_ver) && (nesadapter->hw_rev != NE020_REV)) {
+                       eeprom_offset += 2;
+                       eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+                       nesadapter->phy_index[0] = (eeprom_data & 0xff00)>>8;
+                       nesadapter->phy_index[1] = eeprom_data & 0x00ff;
+                       eeprom_offset += 2;
+                       eeprom_data = nes_read16_eeprom(nesdev->regs, eeprom_offset);
+                       nesadapter->phy_index[2] = (eeprom_data & 0xff00)>>8;
+                       nesadapter->phy_index[3] = eeprom_data & 0x00ff;
+               } else {
+                       nesadapter->phy_index[0] = 4;
+                       nesadapter->phy_index[1] = 5;
+                       nesadapter->phy_index[2] = 6;
+                       nesadapter->phy_index[3] = 7;
+               }
+               nes_debug(NES_DBG_HW, "Phy address map = 0 > %u,  1 > %u, 2 > %u, 3 > %u\n",
+                          nesadapter->phy_index[0],nesadapter->phy_index[1],
+                          nesadapter->phy_index[2],nesadapter->phy_index[3]);
+       }
+
+       return 0;
+}
+
+
+/**
+ * nes_read16_eeprom
+ */
+static u16 nes_read16_eeprom(void __iomem *addr, u16 offset)
+{
+       writel(NES_EEPROM_READ_REQUEST + (offset >> 1),
+                       (void __iomem *)addr + NES_EEPROM_COMMAND);
+
+       do {
+       } while (readl((void __iomem *)addr + NES_EEPROM_COMMAND) &
+                       NES_EEPROM_READ_REQUEST);
+
+       return readw((void __iomem *)addr + NES_EEPROM_DATA);
+}
+
+
+/**
+ * nes_write_1G_phy_reg
+ */
+void nes_write_1G_phy_reg(struct nes_device *nesdev, u8 phy_reg, u8 phy_addr, u16 data)
+{
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 u32temp;
+       u32 counter;
+       unsigned long flags;
+
+       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+
+       nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
+                       0x50020000 | data | ((u32)phy_reg << 18) | ((u32)phy_addr << 23));
+       for (counter = 0; counter < 100 ; counter++) {
+               udelay(30);
+               u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS);
+               if (u32temp & 1) {
+                       /* nes_debug(NES_DBG_PHY, "Phy interrupt status = 0x%X.\n", u32temp); */
+                       nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS, 1);
+                       break;
+               }
+       }
+       if (!(u32temp & 1))
+               nes_debug(NES_DBG_PHY, "Phy is not responding. interrupt status = 0x%X.\n",
+                               u32temp);
+
+       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+}
+
+
+/**
+ * nes_read_1G_phy_reg
+ * This routine only issues the read, the data must be read
+ * separately.
+ */
+void nes_read_1G_phy_reg(struct nes_device *nesdev, u8 phy_reg, u8 phy_addr, u16 *data)
+{
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 u32temp;
+       u32 counter;
+       unsigned long flags;
+
+       /* nes_debug(NES_DBG_PHY, "phy addr = %d, mac_index = %d\n",
+                       phy_addr, nesdev->mac_index); */
+       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+
+       nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
+                       0x60020000 | ((u32)phy_reg << 18) | ((u32)phy_addr << 23));
+       for (counter = 0; counter < 100 ; counter++) {
+               udelay(30);
+               u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS);
+               if (u32temp & 1) {
+                       /* nes_debug(NES_DBG_PHY, "Phy interrupt status = 0x%X.\n", u32temp); */
+                       nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS, 1);
+                       break;
+               }
+       }
+       if (!(u32temp & 1)) {
+               nes_debug(NES_DBG_PHY, "Phy is not responding. interrupt status = 0x%X.\n",
+                               u32temp);
+               *data = 0xffff;
+       } else {
+               *data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
+       }
+       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+}
+
+
+/**
+ * nes_write_10G_phy_reg
+ */
+void nes_write_10G_phy_reg(struct nes_device *nesdev, u16 phy_reg,
+               u8 phy_addr, u16 data)
+{
+       u32 dev_addr;
+       u32 port_addr;
+       u32 u32temp;
+       u32 counter;
+
+       dev_addr = 1;
+       port_addr = phy_addr;
+
+       /* set address */
+       nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
+                       0x00020000 | (u32)phy_reg | (((u32)dev_addr) << 18) | (((u32)port_addr) << 23));
+       for (counter = 0; counter < 100 ; counter++) {
+               udelay(30);
+               u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS);
+               if (u32temp & 1) {
+                       nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS, 1);
+                       break;
+               }
+       }
+       if (!(u32temp & 1))
+               nes_debug(NES_DBG_PHY, "Phy is not responding. interrupt status = 0x%X.\n",
+                               u32temp);
+
+       /* set data */
+       nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
+                       0x10020000 | (u32)data | (((u32)dev_addr) << 18) | (((u32)port_addr) << 23));
+       for (counter = 0; counter < 100 ; counter++) {
+               udelay(30);
+               u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS);
+               if (u32temp & 1) {
+                       nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS, 1);
+                       break;
+               }
+       }
+       if (!(u32temp & 1))
+               nes_debug(NES_DBG_PHY, "Phy is not responding. interrupt status = 0x%X.\n",
+                               u32temp);
+}
+
+
+/**
+ * nes_read_10G_phy_reg
+ * This routine only issues the read, the data must be read
+ * separately.
+ */
+void nes_read_10G_phy_reg(struct nes_device *nesdev, u16 phy_reg, u8 phy_addr)
+{
+       u32 dev_addr;
+       u32 port_addr;
+       u32 u32temp;
+       u32 counter;
+
+       dev_addr = 1;
+       port_addr = phy_addr;
+
+       /* set address */
+       nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
+                       0x00020000 | (u32)phy_reg | (((u32)dev_addr) << 18) | (((u32)port_addr) << 23));
+       for (counter = 0; counter < 100 ; counter++) {
+               udelay(30);
+               u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS);
+               if (u32temp & 1) {
+                       nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS, 1);
+                       break;
+               }
+       }
+       if (!(u32temp & 1))
+               nes_debug(NES_DBG_PHY, "Phy is not responding. interrupt status = 0x%X.\n",
+                               u32temp);
+
+       /* issue read */
+       nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
+                       0x30020000 | (((u32)dev_addr) << 18) | (((u32)port_addr) << 23));
+       for (counter = 0; counter < 100 ; counter++) {
+               udelay(30);
+               u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS);
+               if (u32temp & 1) {
+                       nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS, 1);
+                       break;
+               }
+       }
+       if (!(u32temp & 1))
+               nes_debug(NES_DBG_PHY, "Phy is not responding. interrupt status = 0x%X.\n",
+                               u32temp);
+}
+
+
+/**
+ * nes_get_cqp_request
+ */
+struct nes_cqp_request *nes_get_cqp_request(struct nes_device *nesdev)
+{
+       unsigned long flags;
+       struct nes_cqp_request *cqp_request = NULL;
+
+       if (!list_empty(&nesdev->cqp_avail_reqs)) {
+               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+               cqp_request = list_entry(nesdev->cqp_avail_reqs.next,
+                               struct nes_cqp_request, list);
+               list_del_init(&cqp_request->list);
+               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+       } else {
+               cqp_request = kzalloc(sizeof(struct nes_cqp_request), GFP_KERNEL);
+               if (cqp_request) {
+                       cqp_request->dynamic = 1;
+                       INIT_LIST_HEAD(&cqp_request->list);
+               }
+       }
+
+       if (cqp_request) {
+               init_waitqueue_head(&cqp_request->waitq);
+               cqp_request->waiting = 0;
+               cqp_request->request_done = 0;
+               cqp_request->callback = 0;
+               init_waitqueue_head(&cqp_request->waitq);
+               nes_debug(NES_DBG_CQP, "Got cqp request %p from the available list \n",
+                               cqp_request);
+       } else
+               printk(KERN_ERR PFX "%s: Could not allocated a CQP request.\n",
+                          __FUNCTION__);
+
+       return cqp_request;
+}
+
+
+/**
+ * nes_post_cqp_request
+ */
+void nes_post_cqp_request(struct nes_device *nesdev,
+               struct nes_cqp_request *cqp_request, int ring_doorbell)
+{
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       unsigned long flags;
+       u32 cqp_head;
+       u64 u64temp;
+
+       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+
+       if (((((nesdev->cqp.sq_tail+(nesdev->cqp.sq_size*2))-nesdev->cqp.sq_head) &
+                       (nesdev->cqp.sq_size - 1)) != 1)
+                       && (list_empty(&nesdev->cqp_pending_reqs))) {
+               cqp_head = nesdev->cqp.sq_head++;
+               nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
+               cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
+               memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
+               barrier();
+               u64temp = (unsigned long)cqp_request;
+               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_COMP_SCRATCH_LOW_IDX,
+                                   u64temp);
+               nes_debug(NES_DBG_CQP, "CQP request (opcode 0x%02X), line 1 = 0x%08X put on CQPs SQ,"
+                               " request = %p, cqp_head = %u, cqp_tail = %u, cqp_size = %u,"
+                               " waiting = %d, refcount = %d.\n",
+                               le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f,
+                               le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX]), cqp_request,
+                               nesdev->cqp.sq_head, nesdev->cqp.sq_tail, nesdev->cqp.sq_size,
+                               cqp_request->waiting, atomic_read(&cqp_request->refcount));
+               barrier();
+               if (ring_doorbell) {
+                       /* Ring doorbell (1 WQEs) */
+                       nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x01800000 | nesdev->cqp.qp_id);
+               }
+
+               barrier();
+       } else {
+               nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X), line 1 = 0x%08X"
+                               " put on the pending queue.\n",
+                               cqp_request,
+                               le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f,
+                               le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_ID_IDX]));
+               list_add_tail(&cqp_request->list, &nesdev->cqp_pending_reqs);
+       }
+
+       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+
+       return;
+}
+
+
+/**
+ * nes_arp_table
+ */
+int nes_arp_table(struct nes_device *nesdev, u32 ip_addr, u8 *mac_addr, u32 action)
+{
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       int arp_index;
+       int err = 0;
+
+       for (arp_index = 0; (u32) arp_index < nesadapter->arp_table_size; arp_index++) {
+               if (nesadapter->arp_table[arp_index].ip_addr == ip_addr)
+                       break;
+       }
+
+       if (action == NES_ARP_ADD) {
+               if (arp_index != nesadapter->arp_table_size) {
+                       return -1;
+               }
+
+               arp_index = 0;
+               err = nes_alloc_resource(nesadapter, nesadapter->allocated_arps,
+                               nesadapter->arp_table_size, (u32 *)&arp_index, &nesadapter->next_arp_index);
+               if (err) {
+                       nes_debug(NES_DBG_NETDEV, "nes_alloc_resource returned error = %u\n", err);
+                       return err;
+               }
+               nes_debug(NES_DBG_NETDEV, "ADD, arp_index=%d\n", arp_index);
+
+               nesadapter->arp_table[arp_index].ip_addr = ip_addr;
+               memcpy(nesadapter->arp_table[arp_index].mac_addr, mac_addr, ETH_ALEN);
+               return arp_index;
+       }
+
+       /* DELETE or RESOLVE */
+       if (arp_index == nesadapter->arp_table_size) {
+               nes_debug(NES_DBG_NETDEV, "mac address not in ARP table - cannot delete or resolve\n");
+               return -1;
+       }
+
+       if (action == NES_ARP_RESOLVE) {
+               nes_debug(NES_DBG_NETDEV, "RESOLVE, arp_index=%d\n", arp_index);
+               return arp_index;
+       }
+
+       if (action == NES_ARP_DELETE) {
+               nes_debug(NES_DBG_NETDEV, "DELETE, arp_index=%d\n", arp_index);
+               nesadapter->arp_table[arp_index].ip_addr = 0;
+               memset(nesadapter->arp_table[arp_index].mac_addr, 0x00, ETH_ALEN);
+               nes_free_resource(nesadapter, nesadapter->allocated_arps, arp_index);
+               return arp_index;
+       }
+
+       return -1;
+}
+
+
+/**
+ * nes_mh_fix
+ */
+void nes_mh_fix(unsigned long parm)
+{
+       unsigned long flags;
+       struct nes_device *nesdev = (struct nes_device *)parm;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_vnic *nesvnic;
+       u32 used_chunks_tx;
+       u32 temp_used_chunks_tx;
+       u32 temp_last_used_chunks_tx;
+       u32 used_chunks_mask;
+       u32 mac_tx_frames_low;
+       u32 mac_tx_frames_high;
+       u32 mac_tx_pauses;
+       u32 serdes_status;
+       u32 reset_value;
+       u32 tx_control;
+       u32 tx_config;
+       u32 tx_pause_quanta;
+       u32 rx_control;
+       u32 rx_config;
+       u32 mac_exact_match;
+       u32 mpp_debug;
+       u32 i=0;
+       u32 chunks_tx_progress = 0;
+
+       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+       if ((nesadapter->mac_sw_state[0] != NES_MAC_SW_IDLE) || (nesadapter->mac_link_down[0])) {
+               spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+               goto no_mh_work;
+       }
+       nesadapter->mac_sw_state[0] = NES_MAC_SW_MH;
+       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+       do {
+               mac_tx_frames_low = nes_read_indexed(nesdev, NES_IDX_MAC_TX_FRAMES_LOW);
+               mac_tx_frames_high = nes_read_indexed(nesdev, NES_IDX_MAC_TX_FRAMES_HIGH);
+               mac_tx_pauses = nes_read_indexed(nesdev, NES_IDX_MAC_TX_PAUSE_FRAMES);
+               used_chunks_tx = nes_read_indexed(nesdev, NES_IDX_USED_CHUNKS_TX);
+               nesdev->mac_pause_frames_sent += mac_tx_pauses;
+               used_chunks_mask = 0;
+               temp_used_chunks_tx = used_chunks_tx;
+               temp_last_used_chunks_tx = nesdev->last_used_chunks_tx;
+
+               if (nesdev->netdev[0]) {
+                       nesvnic = netdev_priv(nesdev->netdev[0]);
+               } else {
+                       break;
+               }
+
+               for (i=0; i<4; i++) {
+                       used_chunks_mask <<= 8;
+                       if (nesvnic->qp_nic_index[i] != 0xff) {
+                               used_chunks_mask |= 0xff;
+                               if ((temp_used_chunks_tx&0xff)<(temp_last_used_chunks_tx&0xff)) {
+                                       chunks_tx_progress = 1;
+                               }
+                       }
+                       temp_used_chunks_tx >>= 8;
+                       temp_last_used_chunks_tx >>= 8;
+               }
+               if ((mac_tx_frames_low) || (mac_tx_frames_high) ||
+                       (!(used_chunks_tx&used_chunks_mask)) ||
+                       (!(nesdev->last_used_chunks_tx&used_chunks_mask)) ||
+                       (chunks_tx_progress) ) {
+                       nesdev->last_used_chunks_tx = used_chunks_tx;
+                       break;
+               }
+               nesdev->last_used_chunks_tx = used_chunks_tx;
+               barrier();
+
+               nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONTROL, 0x00000005);
+               mh_pauses_sent++;
+               mac_tx_pauses = nes_read_indexed(nesdev, NES_IDX_MAC_TX_PAUSE_FRAMES);
+               if (mac_tx_pauses) {
+                       nesdev->mac_pause_frames_sent += mac_tx_pauses;
+                       break;
+               }
+
+               tx_control = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONTROL);
+               tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
+               tx_pause_quanta = nes_read_indexed(nesdev, NES_IDX_MAC_TX_PAUSE_QUANTA);
+               rx_control = nes_read_indexed(nesdev, NES_IDX_MAC_RX_CONTROL);
+               rx_config = nes_read_indexed(nesdev, NES_IDX_MAC_RX_CONFIG);
+               mac_exact_match = nes_read_indexed(nesdev, NES_IDX_MAC_EXACT_MATCH_BOTTOM);
+               mpp_debug = nes_read_indexed(nesdev, NES_IDX_MPP_DEBUG);
+
+               /* one last ditch effort to avoid a false positive */
+               mac_tx_pauses = nes_read_indexed(nesdev, NES_IDX_MAC_TX_PAUSE_FRAMES);
+               if (mac_tx_pauses) {
+                       nesdev->last_mac_tx_pauses = nesdev->mac_pause_frames_sent;
+                       nes_debug(NES_DBG_HW, "failsafe caught slow outbound pause\n");
+                       break;
+               }
+               mh_detected++;
+
+               nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONTROL, 0x00000000);
+               nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, 0x00000000);
+               reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
+
+               nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value | 0x0000001d);
+
+               while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
+                               & 0x00000040) != 0x00000040) && (i++ < 5000)) {
+                       /* mdelay(1); */
+               }
+
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, 0x00000008);
+               serdes_status = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0);
+
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP0, 0x000bdef7);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE0, 0x9ce73000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE0, 0x0ff00000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET0, 0x00000000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS0, 0x00000000);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0, 0x00000000);
+               if (nesadapter->OneG_Mode) {
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0182222);
+               } else {
+                       nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0042222);
+               }
+               serdes_status = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_STATUS0);
+               nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000ff);
+
+               nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONTROL, tx_control);
+               nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
+               nes_write_indexed(nesdev, NES_IDX_MAC_TX_PAUSE_QUANTA, tx_pause_quanta);
+               nes_write_indexed(nesdev, NES_IDX_MAC_RX_CONTROL, rx_control);
+               nes_write_indexed(nesdev, NES_IDX_MAC_RX_CONFIG, rx_config);
+               nes_write_indexed(nesdev, NES_IDX_MAC_EXACT_MATCH_BOTTOM, mac_exact_match);
+               nes_write_indexed(nesdev, NES_IDX_MPP_DEBUG, mpp_debug);
+
+       } while (0);
+
+       nesadapter->mac_sw_state[0] = NES_MAC_SW_IDLE;
+no_mh_work:
+       nesdev->nesadapter->mh_timer.expires = jiffies + (HZ/5);
+       add_timer(&nesdev->nesadapter->mh_timer);
+}
+
+/**
+ * nes_clc
+ */
+void nes_clc(unsigned long parm)
+{
+       unsigned long flags;
+       struct nes_device *nesdev = (struct nes_device *)parm;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+
+       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+    nesadapter->link_interrupt_count[0] = 0;
+    nesadapter->link_interrupt_count[1] = 0;
+    nesadapter->link_interrupt_count[2] = 0;
+    nesadapter->link_interrupt_count[3] = 0;
+       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
+
+       nesadapter->lc_timer.expires = jiffies + 3600 * HZ;  /* 1 hour */
+       add_timer(&nesadapter->lc_timer);
+}
+
+
+/**
+ * nes_dump_mem
+ */
+void nes_dump_mem(unsigned int dump_debug_level, void *addr, int length)
+{
+       char  xlate[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+               'a', 'b', 'c', 'd', 'e', 'f'};
+       char  *ptr;
+       char  hex_buf[80];
+       char  ascii_buf[20];
+       int   num_char;
+       int   num_ascii;
+       int   num_hex;
+
+       if (!(nes_debug_level & dump_debug_level)) {
+               return;
+       }
+
+       ptr = addr;
+       if (length > 0x100) {
+               nes_debug(dump_debug_level, "Length truncated from %x to %x\n", length, 0x100);
+               length = 0x100;
+       }
+       nes_debug(dump_debug_level, "Address=0x%p, length=0x%x (%d)\n", ptr, length, length);
+
+       memset(ascii_buf, 0, 20);
+       memset(hex_buf, 0, 80);
+
+       num_ascii = 0;
+       num_hex = 0;
+       for (num_char = 0; num_char < length; num_char++) {
+               if (num_ascii == 8) {
+                       ascii_buf[num_ascii++] = ' ';
+                       hex_buf[num_hex++] = '-';
+                       hex_buf[num_hex++] = ' ';
+               }
+
+               if (*ptr < 0x20 || *ptr > 0x7e)
+                       ascii_buf[num_ascii++] = '.';
+               else
+                       ascii_buf[num_ascii++] = *ptr;
+               hex_buf[num_hex++] = xlate[((*ptr & 0xf0) >> 4)];
+               hex_buf[num_hex++] = xlate[*ptr & 0x0f];
+               hex_buf[num_hex++] = ' ';
+               ptr++;
+
+               if (num_ascii >= 17) {
+                       /* output line and reset */
+                       nes_debug(dump_debug_level, "   %s |  %s\n", hex_buf, ascii_buf);
+                       memset(ascii_buf, 0, 20);
+                       memset(hex_buf, 0, 80);
+                       num_ascii = 0;
+                       num_hex = 0;
+               }
+       }
+
+       /* output the rest */
+       if (num_ascii) {
+               while (num_ascii < 17) {
+                       if (num_ascii == 8) {
+                               hex_buf[num_hex++] = ' ';
+                               hex_buf[num_hex++] = ' ';
+                       }
+                       hex_buf[num_hex++] = ' ';
+                       hex_buf[num_hex++] = ' ';
+                       hex_buf[num_hex++] = ' ';
+                       num_ascii++;
+               }
+
+               nes_debug(dump_debug_level, "   %s |  %s\n", hex_buf, ascii_buf);
+       }
+}
diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
new file mode 100644 (file)
index 0000000..ffd4b42
--- /dev/null
@@ -0,0 +1,3917 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/random.h>
+#include <linux/highmem.h>
+#include <asm/byteorder.h>
+
+#include <rdma/ib_verbs.h>
+#include <rdma/iw_cm.h>
+#include <rdma/ib_user_verbs.h>
+
+#include "nes.h"
+
+#include <rdma/ib_umem.h>
+
+atomic_t mod_qp_timouts;
+atomic_t qps_created;
+atomic_t sw_qps_destroyed;
+
+
+/**
+ * nes_alloc_mw
+ */
+static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd) {
+       unsigned long flags;
+       struct nes_pd *nespd = to_nespd(ibpd);
+       struct nes_vnic *nesvnic = to_nesvnic(ibpd->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_cqp_request *cqp_request;
+       struct nes_mr *nesmr;
+       struct ib_mw *ibmw;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       int ret;
+       u32 stag;
+       u32 stag_index = 0;
+       u32 next_stag_index = 0;
+       u32 driver_key = 0;
+       u8 stag_key = 0;
+
+       get_random_bytes(&next_stag_index, sizeof(next_stag_index));
+       stag_key = (u8)next_stag_index;
+
+       driver_key = 0;
+
+       next_stag_index >>= 8;
+       next_stag_index %= nesadapter->max_mr;
+
+       ret = nes_alloc_resource(nesadapter, nesadapter->allocated_mrs,
+                       nesadapter->max_mr, &stag_index, &next_stag_index);
+       if (ret) {
+               return ERR_PTR(ret);
+       }
+
+       nesmr = kzalloc(sizeof(*nesmr), GFP_KERNEL);
+       if (!nesmr) {
+               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       stag = stag_index << 8;
+       stag |= driver_key;
+       stag += (u32)stag_key;
+
+       nes_debug(NES_DBG_MR, "Registering STag 0x%08X, index = 0x%08X\n",
+                       stag, stag_index);
+
+       /* Register the region with the adapter */
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               kfree(nesmr);
+               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+
+       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] =
+                       cpu_to_le32( NES_CQP_ALLOCATE_STAG | NES_CQP_STAG_RIGHTS_REMOTE_READ |
+                       NES_CQP_STAG_RIGHTS_REMOTE_WRITE | NES_CQP_STAG_VA_TO |
+                       NES_CQP_STAG_REM_ACC_EN);
+
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX, (nespd->pd_id & 0x00007fff));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_STAG_IDX, stag);
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
+                       NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_MR, "Register STag 0x%08X completed, wait_event_timeout ret = %u,"
+                       " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
+                       stag, ret, cqp_request->major_code, cqp_request->minor_code);
+       if ((!ret) || (cqp_request->major_code)) {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+               kfree(nesmr);
+               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+               if (!ret) {
+                       return ERR_PTR(-ETIME);
+               } else {
+                       return ERR_PTR(-ENOMEM);
+               }
+       } else {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+       }
+
+       nesmr->ibmw.rkey = stag;
+       nesmr->mode = IWNES_MEMREG_TYPE_MW;
+       ibmw = &nesmr->ibmw;
+       nesmr->pbl_4k = 0;
+       nesmr->pbls_used = 0;
+
+       return ibmw;
+}
+
+
+/**
+ * nes_dealloc_mw
+ */
+static int nes_dealloc_mw(struct ib_mw *ibmw)
+{
+       struct nes_mr *nesmr = to_nesmw(ibmw);
+       struct nes_vnic *nesvnic = to_nesvnic(ibmw->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_cqp_request *cqp_request;
+       int err = 0;
+       unsigned long flags;
+       int ret;
+
+       /* Deallocate the window with the adapter */
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_MR, "Failed to get a cqp_request.\n");
+               return -ENOMEM;
+       }
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, NES_CQP_DEALLOCATE_STAG);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_STAG_IDX, ibmw->rkey);
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       nes_debug(NES_DBG_MR, "Waiting for deallocate STag 0x%08X to complete.\n",
+                       ibmw->rkey);
+       ret = wait_event_timeout(cqp_request->waitq, (0 != cqp_request->request_done),
+                       NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_MR, "Deallocate STag completed, wait_event_timeout ret = %u,"
+                       " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
+                       ret, cqp_request->major_code, cqp_request->minor_code);
+       if ((!ret) || (cqp_request->major_code)) {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+               if (!ret) {
+                       err = -ETIME;
+               } else {
+                       err = -EIO;
+               }
+       } else {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+       }
+
+       nes_free_resource(nesadapter, nesadapter->allocated_mrs,
+                       (ibmw->rkey & 0x0fffff00) >> 8);
+       kfree(nesmr);
+
+       return err;
+}
+
+
+/**
+ * nes_bind_mw
+ */
+static int nes_bind_mw(struct ib_qp *ibqp, struct ib_mw *ibmw,
+               struct ib_mw_bind *ibmw_bind)
+{
+       u64 u64temp;
+       struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       /* struct nes_mr *nesmr = to_nesmw(ibmw); */
+       struct nes_qp *nesqp = to_nesqp(ibqp);
+       struct nes_hw_qp_wqe *wqe;
+       unsigned long flags = 0;
+       u32 head;
+       u32 wqe_misc = 0;
+       u32 qsize;
+
+       if (nesqp->ibqp_state > IB_QPS_RTS)
+               return -EINVAL;
+
+               spin_lock_irqsave(&nesqp->lock, flags);
+
+       head = nesqp->hwqp.sq_head;
+       qsize = nesqp->hwqp.sq_tail;
+
+       /* Check for SQ overflow */
+       if (((head + (2 * qsize) - nesqp->hwqp.sq_tail) % qsize) == (qsize - 1)) {
+                       spin_unlock_irqrestore(&nesqp->lock, flags);
+               return -EINVAL;
+       }
+
+       wqe = &nesqp->hwqp.sq_vbase[head];
+       /* nes_debug(NES_DBG_MR, "processing sq wqe at %p, head = %u.\n", wqe, head); */
+       nes_fill_init_qp_wqe(wqe, nesqp, head);
+       u64temp = ibmw_bind->wr_id;
+       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX, u64temp);
+       wqe_misc = NES_IWARP_SQ_OP_BIND;
+
+       wqe_misc |= NES_IWARP_SQ_WQE_LOCAL_FENCE;
+
+       if (ibmw_bind->send_flags & IB_SEND_SIGNALED)
+               wqe_misc |= NES_IWARP_SQ_WQE_SIGNALED_COMPL;
+
+       if (ibmw_bind->mw_access_flags & IB_ACCESS_REMOTE_WRITE) {
+               wqe_misc |= NES_CQP_STAG_RIGHTS_REMOTE_WRITE;
+       }
+       if (ibmw_bind->mw_access_flags & IB_ACCESS_REMOTE_READ) {
+               wqe_misc |= NES_CQP_STAG_RIGHTS_REMOTE_READ;
+       }
+
+       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_MISC_IDX, wqe_misc);
+       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_BIND_WQE_MR_IDX, ibmw_bind->mr->lkey);
+       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_BIND_WQE_MW_IDX, ibmw->rkey);
+       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_BIND_WQE_LENGTH_LOW_IDX,
+                       ibmw_bind->length);
+       wqe->wqe_words[NES_IWARP_SQ_BIND_WQE_LENGTH_HIGH_IDX] = 0;
+       u64temp = (u64)ibmw_bind->addr;
+       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_BIND_WQE_VA_FBO_LOW_IDX, u64temp);
+
+       head++;
+       if (head >= qsize)
+               head = 0;
+
+       nesqp->hwqp.sq_head = head;
+       barrier();
+
+       nes_write32(nesdev->regs+NES_WQE_ALLOC,
+                       (1 << 24) | 0x00800000 | nesqp->hwqp.qp_id);
+
+               spin_unlock_irqrestore(&nesqp->lock, flags);
+
+       return 0;
+}
+
+
+/**
+ * nes_alloc_fmr
+ */
+static struct ib_fmr *nes_alloc_fmr(struct ib_pd *ibpd,
+               int ibmr_access_flags,
+               struct ib_fmr_attr *ibfmr_attr)
+{
+       unsigned long flags;
+       struct nes_pd *nespd = to_nespd(ibpd);
+       struct nes_vnic *nesvnic = to_nesvnic(ibpd->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_fmr *nesfmr;
+       struct nes_cqp_request *cqp_request;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       int ret;
+       u32 stag;
+       u32 stag_index = 0;
+       u32 next_stag_index = 0;
+       u32 driver_key = 0;
+       u32 opcode = 0;
+       u8 stag_key = 0;
+       int i=0;
+       struct nes_vpbl vpbl;
+
+       get_random_bytes(&next_stag_index, sizeof(next_stag_index));
+       stag_key = (u8)next_stag_index;
+
+       driver_key = 0;
+
+       next_stag_index >>= 8;
+       next_stag_index %= nesadapter->max_mr;
+
+       ret = nes_alloc_resource(nesadapter, nesadapter->allocated_mrs,
+                       nesadapter->max_mr, &stag_index, &next_stag_index);
+       if (ret) {
+               goto failed_resource_alloc;
+       }
+
+       nesfmr = kzalloc(sizeof(*nesfmr), GFP_KERNEL);
+       if (!nesfmr) {
+               ret = -ENOMEM;
+               goto failed_fmr_alloc;
+       }
+
+       nesfmr->nesmr.mode = IWNES_MEMREG_TYPE_FMR;
+       if (ibfmr_attr->max_pages == 1) {
+               /* use zero length PBL */
+               nesfmr->nesmr.pbl_4k = 0;
+               nesfmr->nesmr.pbls_used = 0;
+       } else if (ibfmr_attr->max_pages <= 32) {
+               /* use PBL 256 */
+               nesfmr->nesmr.pbl_4k = 0;
+               nesfmr->nesmr.pbls_used = 1;
+       } else if (ibfmr_attr->max_pages <= 512) {
+               /* use 4K PBLs */
+               nesfmr->nesmr.pbl_4k = 1;
+               nesfmr->nesmr.pbls_used = 1;
+       } else {
+               /* use two level 4K PBLs */
+               /* add support for two level 256B PBLs */
+               nesfmr->nesmr.pbl_4k = 1;
+               nesfmr->nesmr.pbls_used = 1 + (ibfmr_attr->max_pages >> 9) +
+                               ((ibfmr_attr->max_pages & 511) ? 1 : 0);
+       }
+       /* Register the region with the adapter */
+       spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+
+       /* track PBL resources */
+       if (nesfmr->nesmr.pbls_used != 0) {
+               if (nesfmr->nesmr.pbl_4k) {
+                       if (nesfmr->nesmr.pbls_used > nesadapter->free_4kpbl) {
+                               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               ret = -ENOMEM;
+                               goto failed_vpbl_alloc;
+                       } else {
+                               nesadapter->free_4kpbl -= nesfmr->nesmr.pbls_used;
+                       }
+               } else {
+                       if (nesfmr->nesmr.pbls_used > nesadapter->free_256pbl) {
+                               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               ret = -ENOMEM;
+                               goto failed_vpbl_alloc;
+                       } else {
+                               nesadapter->free_256pbl -= nesfmr->nesmr.pbls_used;
+                       }
+               }
+       }
+
+       /* one level pbl */
+       if (nesfmr->nesmr.pbls_used == 0) {
+               nesfmr->root_vpbl.pbl_vbase = NULL;
+               nes_debug(NES_DBG_MR,  "zero level pbl \n");
+       } else if (nesfmr->nesmr.pbls_used == 1) {
+               /* can change it to kmalloc & dma_map_single */
+               nesfmr->root_vpbl.pbl_vbase = pci_alloc_consistent(nesdev->pcidev, 4096,
+                               &nesfmr->root_vpbl.pbl_pbase);
+               if (!nesfmr->root_vpbl.pbl_vbase) {
+                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                       ret = -ENOMEM;
+                       goto failed_vpbl_alloc;
+               }
+               nesfmr->leaf_pbl_cnt = 0;
+               nes_debug(NES_DBG_MR, "one level pbl, root_vpbl.pbl_vbase=%p \n",
+                               nesfmr->root_vpbl.pbl_vbase);
+       }
+       /* two level pbl */
+       else {
+               nesfmr->root_vpbl.pbl_vbase = pci_alloc_consistent(nesdev->pcidev, 8192,
+                               &nesfmr->root_vpbl.pbl_pbase);
+               if (!nesfmr->root_vpbl.pbl_vbase) {
+                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                       ret = -ENOMEM;
+                       goto failed_vpbl_alloc;
+               }
+
+               nesfmr->root_vpbl.leaf_vpbl = kzalloc(sizeof(*nesfmr->root_vpbl.leaf_vpbl)*1024, GFP_KERNEL);
+               if (!nesfmr->root_vpbl.leaf_vpbl) {
+                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                       ret = -ENOMEM;
+                       goto failed_leaf_vpbl_alloc;
+               }
+
+               nesfmr->leaf_pbl_cnt = nesfmr->nesmr.pbls_used-1;
+               nes_debug(NES_DBG_MR, "two level pbl, root_vpbl.pbl_vbase=%p"
+                               " leaf_pbl_cnt=%d root_vpbl.leaf_vpbl=%p\n",
+                               nesfmr->root_vpbl.pbl_vbase, nesfmr->leaf_pbl_cnt, nesfmr->root_vpbl.leaf_vpbl);
+
+               for (i=0; i<nesfmr->leaf_pbl_cnt; i++)
+                       nesfmr->root_vpbl.leaf_vpbl[i].pbl_vbase = NULL;
+
+               for (i=0; i<nesfmr->leaf_pbl_cnt; i++) {
+                       vpbl.pbl_vbase = pci_alloc_consistent(nesdev->pcidev, 4096,
+                                       &vpbl.pbl_pbase);
+
+                       if (!vpbl.pbl_vbase) {
+                               ret = -ENOMEM;
+                               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               goto failed_leaf_vpbl_pages_alloc;
+                       }
+
+                       nesfmr->root_vpbl.pbl_vbase[i].pa_low = cpu_to_le32((u32)vpbl.pbl_pbase);
+                       nesfmr->root_vpbl.pbl_vbase[i].pa_high = cpu_to_le32((u32)((((u64)vpbl.pbl_pbase)>>32)));
+                       nesfmr->root_vpbl.leaf_vpbl[i] = vpbl;
+
+                       nes_debug(NES_DBG_MR, "pbase_low=0x%x, pbase_high=0x%x, vpbl=%p\n",
+                                       nesfmr->root_vpbl.pbl_vbase[i].pa_low,
+                                       nesfmr->root_vpbl.pbl_vbase[i].pa_high,
+                                       &nesfmr->root_vpbl.leaf_vpbl[i]);
+               }
+       }
+       nesfmr->ib_qp = NULL;
+       nesfmr->access_rights =0;
+
+       stag = stag_index << 8;
+       stag |= driver_key;
+       stag += (u32)stag_key;
+
+       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_MR, "Failed to get a cqp_request.\n");
+               ret = -ENOMEM;
+               goto failed_leaf_vpbl_pages_alloc;
+       }
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+
+       nes_debug(NES_DBG_MR, "Registering STag 0x%08X, index = 0x%08X\n",
+                       stag, stag_index);
+
+       opcode = NES_CQP_ALLOCATE_STAG | NES_CQP_STAG_VA_TO | NES_CQP_STAG_MR;
+
+       if (nesfmr->nesmr.pbl_4k == 1)
+               opcode |= NES_CQP_STAG_PBL_BLK_SIZE;
+
+       if (ibmr_access_flags & IB_ACCESS_REMOTE_WRITE) {
+               opcode |= NES_CQP_STAG_RIGHTS_REMOTE_WRITE |
+                               NES_CQP_STAG_RIGHTS_LOCAL_WRITE | NES_CQP_STAG_REM_ACC_EN;
+               nesfmr->access_rights |=
+                               NES_CQP_STAG_RIGHTS_REMOTE_WRITE | NES_CQP_STAG_RIGHTS_LOCAL_WRITE |
+                               NES_CQP_STAG_REM_ACC_EN;
+       }
+
+       if (ibmr_access_flags & IB_ACCESS_REMOTE_READ) {
+               opcode |= NES_CQP_STAG_RIGHTS_REMOTE_READ |
+                               NES_CQP_STAG_RIGHTS_LOCAL_READ | NES_CQP_STAG_REM_ACC_EN;
+               nesfmr->access_rights |=
+                               NES_CQP_STAG_RIGHTS_REMOTE_READ | NES_CQP_STAG_RIGHTS_LOCAL_READ |
+                               NES_CQP_STAG_REM_ACC_EN;
+       }
+
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX, (nespd->pd_id & 0x00007fff));
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_STAG_IDX, stag);
+
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_PBL_BLK_COUNT_IDX] =
+                       cpu_to_le32((nesfmr->nesmr.pbls_used>1) ?
+                       (nesfmr->nesmr.pbls_used-1) : nesfmr->nesmr.pbls_used);
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
+                       NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_MR, "Register STag 0x%08X completed, wait_event_timeout ret = %u,"
+                       " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
+                       stag, ret, cqp_request->major_code, cqp_request->minor_code);
+
+       if ((!ret) || (cqp_request->major_code)) {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+               ret = (!ret) ? -ETIME : -EIO;
+               goto failed_leaf_vpbl_pages_alloc;
+       } else {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+       }
+
+       nesfmr->nesmr.ibfmr.lkey = stag;
+       nesfmr->nesmr.ibfmr.rkey = stag;
+       nesfmr->attr = *ibfmr_attr;
+
+       return &nesfmr->nesmr.ibfmr;
+
+       failed_leaf_vpbl_pages_alloc:
+       /* unroll all allocated pages */
+       for (i=0; i<nesfmr->leaf_pbl_cnt; i++) {
+               if (nesfmr->root_vpbl.leaf_vpbl[i].pbl_vbase) {
+                       pci_free_consistent(nesdev->pcidev, 4096, nesfmr->root_vpbl.leaf_vpbl[i].pbl_vbase,
+                                       nesfmr->root_vpbl.leaf_vpbl[i].pbl_pbase);
+               }
+       }
+       if (nesfmr->root_vpbl.leaf_vpbl)
+               kfree(nesfmr->root_vpbl.leaf_vpbl);
+
+       failed_leaf_vpbl_alloc:
+       if (nesfmr->leaf_pbl_cnt == 0) {
+               if (nesfmr->root_vpbl.pbl_vbase)
+                       pci_free_consistent(nesdev->pcidev, 4096, nesfmr->root_vpbl.pbl_vbase,
+                                       nesfmr->root_vpbl.pbl_pbase);
+       } else
+               pci_free_consistent(nesdev->pcidev, 8192, nesfmr->root_vpbl.pbl_vbase,
+                               nesfmr->root_vpbl.pbl_pbase);
+
+       failed_vpbl_alloc:
+       kfree(nesfmr);
+
+       failed_fmr_alloc:
+       nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+
+       failed_resource_alloc:
+       return ERR_PTR(ret);
+}
+
+
+/**
+ * nes_dealloc_fmr
+ */
+static int nes_dealloc_fmr(struct ib_fmr *ibfmr)
+{
+       struct nes_mr *nesmr = to_nesmr_from_ibfmr(ibfmr);
+       struct nes_fmr *nesfmr = to_nesfmr(nesmr);
+       struct nes_vnic *nesvnic = to_nesvnic(ibfmr->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_mr temp_nesmr = *nesmr;
+       int i = 0;
+
+       temp_nesmr.ibmw.device = ibfmr->device;
+       temp_nesmr.ibmw.pd = ibfmr->pd;
+       temp_nesmr.ibmw.rkey = ibfmr->rkey;
+       temp_nesmr.ibmw.uobject = NULL;
+
+       /* free the resources */
+       if (nesfmr->leaf_pbl_cnt == 0) {
+               /* single PBL case */
+               if (nesfmr->root_vpbl.pbl_vbase)
+                       pci_free_consistent(nesdev->pcidev, 4096, nesfmr->root_vpbl.pbl_vbase,
+                                       nesfmr->root_vpbl.pbl_pbase);
+       } else {
+               for (i = 0; i < nesfmr->leaf_pbl_cnt; i++) {
+                       pci_free_consistent(nesdev->pcidev, 4096, nesfmr->root_vpbl.leaf_vpbl[i].pbl_vbase,
+                                       nesfmr->root_vpbl.leaf_vpbl[i].pbl_pbase);
+               }
+               kfree(nesfmr->root_vpbl.leaf_vpbl);
+               pci_free_consistent(nesdev->pcidev, 8192, nesfmr->root_vpbl.pbl_vbase,
+                               nesfmr->root_vpbl.pbl_pbase);
+       }
+
+       return nes_dealloc_mw(&temp_nesmr.ibmw);
+}
+
+
+/**
+ * nes_map_phys_fmr
+ */
+static int nes_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
+               int list_len, u64 iova)
+{
+       return 0;
+}
+
+
+/**
+ * nes_unmap_frm
+ */
+static int nes_unmap_fmr(struct list_head *ibfmr_list)
+{
+       return 0;
+}
+
+
+
+/**
+ * nes_query_device
+ */
+static int nes_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
+{
+       struct nes_vnic *nesvnic = to_nesvnic(ibdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_ib_device *nesibdev = nesvnic->nesibdev;
+
+       memset(props, 0, sizeof(*props));
+       memcpy(&props->sys_image_guid, nesvnic->netdev->dev_addr, 6);
+
+       props->fw_ver = nesdev->nesadapter->fw_ver;
+       props->device_cap_flags = nesdev->nesadapter->device_cap_flags;
+       props->vendor_id = nesdev->nesadapter->vendor_id;
+       props->vendor_part_id = nesdev->nesadapter->vendor_part_id;
+       props->hw_ver = nesdev->nesadapter->hw_rev;
+       props->max_mr_size = 0x80000000;
+       props->max_qp = nesibdev->max_qp;
+       props->max_qp_wr = nesdev->nesadapter->max_qp_wr - 2;
+       props->max_sge = nesdev->nesadapter->max_sge;
+       props->max_cq = nesibdev->max_cq;
+       props->max_cqe = nesdev->nesadapter->max_cqe - 1;
+       props->max_mr = nesibdev->max_mr;
+       props->max_mw = nesibdev->max_mr;
+       props->max_pd = nesibdev->max_pd;
+       props->max_sge_rd = 1;
+       switch (nesdev->nesadapter->max_irrq_wr) {
+               case 0:
+                       props->max_qp_rd_atom = 1;
+                       break;
+               case 1:
+                       props->max_qp_rd_atom = 4;
+                       break;
+               case 2:
+                       props->max_qp_rd_atom = 16;
+                       break;
+               case 3:
+                       props->max_qp_rd_atom = 32;
+                       break;
+               default:
+                       props->max_qp_rd_atom = 0;
+       }
+       props->max_qp_init_rd_atom = props->max_qp_wr;
+       props->atomic_cap = IB_ATOMIC_NONE;
+       props->max_map_per_fmr = 1;
+
+       return 0;
+}
+
+
+/**
+ * nes_query_port
+ */
+static int nes_query_port(struct ib_device *ibdev, u8 port, struct ib_port_attr *props)
+{
+       memset(props, 0, sizeof(*props));
+
+       props->max_mtu = IB_MTU_2048;
+       props->active_mtu = IB_MTU_2048;
+       props->lid = 1;
+       props->lmc = 0;
+       props->sm_lid = 0;
+       props->sm_sl = 0;
+       props->state = IB_PORT_ACTIVE;
+       props->phys_state = 0;
+       props->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_REINIT_SUP |
+                       IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
+       props->gid_tbl_len = 1;
+       props->pkey_tbl_len = 1;
+       props->qkey_viol_cntr = 0;
+       props->active_width = IB_WIDTH_4X;
+       props->active_speed = 1;
+       props->max_msg_sz = 0x80000000;
+
+       return 0;
+}
+
+
+/**
+ * nes_modify_port
+ */
+static int nes_modify_port(struct ib_device *ibdev, u8 port,
+               int port_modify_mask, struct ib_port_modify *props)
+{
+       return 0;
+}
+
+
+/**
+ * nes_query_pkey
+ */
+static int nes_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
+{
+       *pkey = 0;
+       return 0;
+}
+
+
+/**
+ * nes_query_gid
+ */
+static int nes_query_gid(struct ib_device *ibdev, u8 port,
+               int index, union ib_gid *gid)
+{
+       struct nes_vnic *nesvnic = to_nesvnic(ibdev);
+
+       memset(&(gid->raw[0]), 0, sizeof(gid->raw));
+       memcpy(&(gid->raw[0]), nesvnic->netdev->dev_addr, 6);
+
+       return 0;
+}
+
+
+/**
+ * nes_alloc_ucontext - Allocate the user context data structure. This keeps track
+ * of all objects associated with a particular user-mode client.
+ */
+static struct ib_ucontext *nes_alloc_ucontext(struct ib_device *ibdev,
+               struct ib_udata *udata)
+{
+       struct nes_vnic *nesvnic = to_nesvnic(ibdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_alloc_ucontext_req req;
+       struct nes_alloc_ucontext_resp uresp;
+       struct nes_ucontext *nes_ucontext;
+       struct nes_ib_device *nesibdev = nesvnic->nesibdev;
+
+
+       if (ib_copy_from_udata(&req, udata, sizeof(struct nes_alloc_ucontext_req))) {
+               printk(KERN_ERR PFX "Invalid structure size on allocate user context.\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       if (req.userspace_ver != NES_ABI_USERSPACE_VER) {
+               printk(KERN_ERR PFX "Invalid userspace driver version detected. Detected version %d, should be %d\n",
+                       req.userspace_ver, NES_ABI_USERSPACE_VER);
+               return ERR_PTR(-EINVAL);
+       }
+
+
+       memset(&uresp, 0, sizeof uresp);
+
+       uresp.max_qps = nesibdev->max_qp;
+       uresp.max_pds = nesibdev->max_pd;
+       uresp.wq_size = nesdev->nesadapter->max_qp_wr * 2;
+       uresp.virtwq = nesadapter->virtwq;
+       uresp.kernel_ver = NES_ABI_KERNEL_VER;
+
+       nes_ucontext = kzalloc(sizeof *nes_ucontext, GFP_KERNEL);
+       if (!nes_ucontext)
+               return ERR_PTR(-ENOMEM);
+
+       nes_ucontext->nesdev = nesdev;
+       nes_ucontext->mmap_wq_offset = uresp.max_pds;
+       nes_ucontext->mmap_cq_offset = nes_ucontext->mmap_wq_offset +
+                       ((sizeof(struct nes_hw_qp_wqe) * uresp.max_qps * 2) + PAGE_SIZE-1) /
+                       PAGE_SIZE;
+
+
+       if (ib_copy_to_udata(udata, &uresp, sizeof uresp)) {
+               kfree(nes_ucontext);
+               return ERR_PTR(-EFAULT);
+       }
+
+       INIT_LIST_HEAD(&nes_ucontext->cq_reg_mem_list);
+       INIT_LIST_HEAD(&nes_ucontext->qp_reg_mem_list);
+       atomic_set(&nes_ucontext->usecnt, 1);
+       return &nes_ucontext->ibucontext;
+}
+
+
+/**
+ * nes_dealloc_ucontext
+ */
+static int nes_dealloc_ucontext(struct ib_ucontext *context)
+{
+       /* struct nes_vnic *nesvnic = to_nesvnic(context->device); */
+       /* struct nes_device *nesdev = nesvnic->nesdev; */
+       struct nes_ucontext *nes_ucontext = to_nesucontext(context);
+
+       if (!atomic_dec_and_test(&nes_ucontext->usecnt))
+         return 0;
+       kfree(nes_ucontext);
+       return 0;
+}
+
+
+/**
+ * nes_mmap
+ */
+static int nes_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
+{
+       unsigned long index;
+       struct nes_vnic *nesvnic = to_nesvnic(context->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       /* struct nes_adapter *nesadapter = nesdev->nesadapter; */
+       struct nes_ucontext *nes_ucontext;
+       struct nes_qp *nesqp;
+
+       nes_ucontext = to_nesucontext(context);
+
+
+       if (vma->vm_pgoff >= nes_ucontext->mmap_wq_offset) {
+               index = (vma->vm_pgoff - nes_ucontext->mmap_wq_offset) * PAGE_SIZE;
+               index /= ((sizeof(struct nes_hw_qp_wqe) * nesdev->nesadapter->max_qp_wr * 2) +
+                               PAGE_SIZE-1) & (~(PAGE_SIZE-1));
+               if (!test_bit(index, nes_ucontext->allocated_wqs)) {
+                       nes_debug(NES_DBG_MMAP, "wq %lu not allocated\n", index);
+                       return -EFAULT;
+               }
+               nesqp = nes_ucontext->mmap_nesqp[index];
+               if (nesqp == NULL) {
+                       nes_debug(NES_DBG_MMAP, "wq %lu has a NULL QP base.\n", index);
+                       return -EFAULT;
+               }
+               if (remap_pfn_range(vma, vma->vm_start,
+                               virt_to_phys(nesqp->hwqp.sq_vbase) >> PAGE_SHIFT,
+                               vma->vm_end - vma->vm_start,
+                               vma->vm_page_prot)) {
+                       nes_debug(NES_DBG_MMAP, "remap_pfn_range failed.\n");
+                       return -EAGAIN;
+               }
+               vma->vm_private_data = nesqp;
+               return 0;
+       } else {
+               index = vma->vm_pgoff;
+               if (!test_bit(index, nes_ucontext->allocated_doorbells))
+                       return -EFAULT;
+
+               vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+               if (io_remap_pfn_range(vma, vma->vm_start,
+                               (nesdev->doorbell_start +
+                               ((nes_ucontext->mmap_db_index[index] - nesdev->base_doorbell_index) * 4096))
+                               >> PAGE_SHIFT, PAGE_SIZE, vma->vm_page_prot))
+                       return -EAGAIN;
+               vma->vm_private_data = nes_ucontext;
+               return 0;
+       }
+
+       return -ENOSYS;
+}
+
+
+/**
+ * nes_alloc_pd
+ */
+static struct ib_pd *nes_alloc_pd(struct ib_device *ibdev,
+               struct ib_ucontext *context, struct ib_udata *udata)
+{
+       struct nes_pd *nespd;
+       struct nes_vnic *nesvnic = to_nesvnic(ibdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_ucontext *nesucontext;
+       struct nes_alloc_pd_resp uresp;
+       u32 pd_num = 0;
+       int err;
+
+       nes_debug(NES_DBG_PD, "nesvnic=%p, netdev=%p %s, ibdev=%p, context=%p, netdev refcnt=%u\n",
+                       nesvnic, nesdev->netdev[0], nesdev->netdev[0]->name, ibdev, context,
+                       atomic_read(&nesvnic->netdev->refcnt));
+
+       err = nes_alloc_resource(nesadapter, nesadapter->allocated_pds,
+                       nesadapter->max_pd, &pd_num, &nesadapter->next_pd);
+       if (err) {
+               return ERR_PTR(err);
+       }
+
+       nespd = kzalloc(sizeof (struct nes_pd), GFP_KERNEL);
+       if (!nespd) {
+               nes_free_resource(nesadapter, nesadapter->allocated_pds, pd_num);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       nes_debug(NES_DBG_PD, "Allocating PD (%p) for ib device %s\n",
+                       nespd, nesvnic->nesibdev->ibdev.name);
+
+       nespd->pd_id = (pd_num << (PAGE_SHIFT-12)) + nesadapter->base_pd;
+
+       if (context) {
+               nesucontext = to_nesucontext(context);
+               nespd->mmap_db_index = find_next_zero_bit(nesucontext->allocated_doorbells,
+                               NES_MAX_USER_DB_REGIONS, nesucontext->first_free_db);
+               nes_debug(NES_DBG_PD, "find_first_zero_biton doorbells returned %u, mapping pd_id %u.\n",
+                               nespd->mmap_db_index, nespd->pd_id);
+               if (nespd->mmap_db_index > NES_MAX_USER_DB_REGIONS) {
+                       nes_debug(NES_DBG_PD, "mmap_db_index > MAX\n");
+                       nes_free_resource(nesadapter, nesadapter->allocated_pds, pd_num);
+                       kfree(nespd);
+                       return ERR_PTR(-ENOMEM);
+               }
+
+               uresp.pd_id = nespd->pd_id;
+               uresp.mmap_db_index = nespd->mmap_db_index;
+               if (ib_copy_to_udata(udata, &uresp, sizeof (struct nes_alloc_pd_resp))) {
+                       nes_free_resource(nesadapter, nesadapter->allocated_pds, pd_num);
+                       kfree(nespd);
+                       return ERR_PTR(-EFAULT);
+               }
+
+               set_bit(nespd->mmap_db_index, nesucontext->allocated_doorbells);
+               nesucontext->mmap_db_index[nespd->mmap_db_index] = nespd->pd_id;
+               nesucontext->first_free_db = nespd->mmap_db_index + 1;
+       }
+
+       nes_debug(NES_DBG_PD, "PD%u structure located @%p.\n", nespd->pd_id, nespd);
+       return &nespd->ibpd;
+}
+
+
+/**
+ * nes_dealloc_pd
+ */
+static int nes_dealloc_pd(struct ib_pd *ibpd)
+{
+       struct nes_ucontext *nesucontext;
+       struct nes_pd *nespd = to_nespd(ibpd);
+       struct nes_vnic *nesvnic = to_nesvnic(ibpd->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+
+       if ((ibpd->uobject) && (ibpd->uobject->context)) {
+               nesucontext = to_nesucontext(ibpd->uobject->context);
+               nes_debug(NES_DBG_PD, "Clearing bit %u from allocated doorbells\n",
+                               nespd->mmap_db_index);
+               clear_bit(nespd->mmap_db_index, nesucontext->allocated_doorbells);
+               nesucontext->mmap_db_index[nespd->mmap_db_index] = 0;
+               if (nesucontext->first_free_db > nespd->mmap_db_index) {
+                       nesucontext->first_free_db = nespd->mmap_db_index;
+               }
+       }
+
+       nes_debug(NES_DBG_PD, "Deallocating PD%u structure located @%p.\n",
+                       nespd->pd_id, nespd);
+       nes_free_resource(nesadapter, nesadapter->allocated_pds,
+                       (nespd->pd_id-nesadapter->base_pd)>>(PAGE_SHIFT-12));
+       kfree(nespd);
+
+       return 0;
+}
+
+
+/**
+ * nes_create_ah
+ */
+static struct ib_ah *nes_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
+
+/**
+ * nes_destroy_ah
+ */
+static int nes_destroy_ah(struct ib_ah *ah)
+{
+       return -ENOSYS;
+}
+
+
+/**
+ * nes_get_encoded_size
+ */
+static inline u8 nes_get_encoded_size(int *size)
+{
+       u8 encoded_size = 0;
+       if (*size <= 32) {
+               *size = 32;
+               encoded_size = 1;
+       } else if (*size <= 128) {
+               *size = 128;
+               encoded_size = 2;
+       } else if (*size <= 512) {
+               *size = 512;
+               encoded_size = 3;
+       }
+       return (encoded_size);
+}
+
+
+
+/**
+ * nes_setup_virt_qp
+ */
+static int nes_setup_virt_qp(struct nes_qp *nesqp, struct nes_pbl *nespbl,
+               struct nes_vnic *nesvnic, int sq_size, int rq_size)
+{
+       unsigned long flags;
+       void *mem;
+       __le64 *pbl = NULL;
+       __le64 *tpbl;
+       __le64 *pblbuffer;
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       u32 pbl_entries;
+       u8 rq_pbl_entries;
+       u8 sq_pbl_entries;
+
+       pbl_entries = nespbl->pbl_size >> 3;
+       nes_debug(NES_DBG_QP, "Userspace PBL, pbl_size=%u, pbl_entries = %d pbl_vbase=%p, pbl_pbase=%p\n",
+                       nespbl->pbl_size, pbl_entries,
+                       (void *)nespbl->pbl_vbase,
+                       (void *)nespbl->pbl_pbase);
+       pbl = (__le64 *) nespbl->pbl_vbase; /* points to first pbl entry */
+       /* now lets set the sq_vbase as well as rq_vbase addrs we will assign */
+       /* the first pbl to be fro the rq_vbase... */
+       rq_pbl_entries = (rq_size * sizeof(struct nes_hw_qp_wqe)) >> 12;
+       sq_pbl_entries = (sq_size * sizeof(struct nes_hw_qp_wqe)) >> 12;
+       nesqp->hwqp.sq_pbase = (le32_to_cpu(((__le32 *)pbl)[0])) | ((u64)((le32_to_cpu(((__le32 *)pbl)[1]))) << 32);
+       if (!nespbl->page) {
+               nes_debug(NES_DBG_QP, "QP nespbl->page is NULL \n");
+               kfree(nespbl);
+               return -ENOMEM;
+       }
+
+       nesqp->hwqp.sq_vbase = kmap(nespbl->page);
+       nesqp->page = nespbl->page;
+       if (!nesqp->hwqp.sq_vbase) {
+               nes_debug(NES_DBG_QP, "QP sq_vbase kmap failed\n");
+               kfree(nespbl);
+               return -ENOMEM;
+       }
+
+       /* Now to get to sq.. we need to calculate how many */
+       /* PBL entries were used by the rq.. */
+       pbl += sq_pbl_entries;
+       nesqp->hwqp.rq_pbase = (le32_to_cpu(((__le32 *)pbl)[0])) | ((u64)((le32_to_cpu(((__le32 *)pbl)[1]))) << 32);
+       /* nesqp->hwqp.rq_vbase = bus_to_virt(*pbl); */
+       /*nesqp->hwqp.rq_vbase = phys_to_virt(*pbl); */
+
+       nes_debug(NES_DBG_QP, "QP sq_vbase= %p sq_pbase=%p rq_vbase=%p rq_pbase=%p\n",
+                       nesqp->hwqp.sq_vbase, (void *)nesqp->hwqp.sq_pbase,
+                       nesqp->hwqp.rq_vbase, (void *)nesqp->hwqp.rq_pbase);
+       spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+       if (!nesadapter->free_256pbl) {
+               pci_free_consistent(nesdev->pcidev, nespbl->pbl_size, nespbl->pbl_vbase,
+                               nespbl->pbl_pbase);
+               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+               kunmap(nesqp->page);
+               kfree(nespbl);
+               return -ENOMEM;
+       }
+       nesadapter->free_256pbl--;
+       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+
+       nesqp->pbl_vbase = pci_alloc_consistent(nesdev->pcidev, 256, &nesqp->pbl_pbase);
+       pblbuffer = nesqp->pbl_vbase;
+       if (!nesqp->pbl_vbase) {
+               /* memory allocated during nes_reg_user_mr() */
+               pci_free_consistent(nesdev->pcidev, nespbl->pbl_size, nespbl->pbl_vbase,
+                                   nespbl->pbl_pbase);
+               kfree(nespbl);
+               spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+               nesadapter->free_256pbl++;
+               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+               kunmap(nesqp->page);
+               return -ENOMEM;
+       }
+       memset(nesqp->pbl_vbase, 0, 256);
+       /* fill in the page address in the pbl buffer.. */
+       tpbl = pblbuffer + 16;
+       pbl = (__le64 *)nespbl->pbl_vbase;
+       while (sq_pbl_entries--)
+               *tpbl++ = *pbl++;
+       tpbl = pblbuffer;
+       while (rq_pbl_entries--)
+               *tpbl++ = *pbl++;
+
+       /* done with memory allocated during nes_reg_user_mr() */
+       pci_free_consistent(nesdev->pcidev, nespbl->pbl_size, nespbl->pbl_vbase,
+                           nespbl->pbl_pbase);
+       kfree(nespbl);
+
+       nesqp->qp_mem_size =
+                       max((u32)sizeof(struct nes_qp_context), ((u32)256)) + 256;     /* this is Q2 */
+       /* Round up to a multiple of a page */
+       nesqp->qp_mem_size += PAGE_SIZE - 1;
+       nesqp->qp_mem_size &= ~(PAGE_SIZE - 1);
+
+       mem = pci_alloc_consistent(nesdev->pcidev, nesqp->qp_mem_size,
+                       &nesqp->hwqp.q2_pbase);
+
+       if (!mem) {
+               pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
+               nesqp->pbl_vbase = NULL;
+               spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+               nesadapter->free_256pbl++;
+               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+               kunmap(nesqp->page);
+               return -ENOMEM;
+       }
+       nesqp->hwqp.q2_vbase = mem;
+       mem += 256;
+       memset(nesqp->hwqp.q2_vbase, 0, 256);
+       nesqp->nesqp_context = mem;
+       memset(nesqp->nesqp_context, 0, sizeof(*nesqp->nesqp_context));
+       nesqp->nesqp_context_pbase = nesqp->hwqp.q2_pbase + 256;
+
+       return 0;
+}
+
+
+/**
+ * nes_setup_mmap_qp
+ */
+static int nes_setup_mmap_qp(struct nes_qp *nesqp, struct nes_vnic *nesvnic,
+               int sq_size, int rq_size)
+{
+       void *mem;
+       struct nes_device *nesdev = nesvnic->nesdev;
+
+       nesqp->qp_mem_size = (sizeof(struct nes_hw_qp_wqe) * sq_size) +
+                       (sizeof(struct nes_hw_qp_wqe) * rq_size) +
+                       max((u32)sizeof(struct nes_qp_context), ((u32)256)) +
+                       256; /* this is Q2 */
+       /* Round up to a multiple of a page */
+       nesqp->qp_mem_size += PAGE_SIZE - 1;
+       nesqp->qp_mem_size &= ~(PAGE_SIZE - 1);
+
+       mem = pci_alloc_consistent(nesdev->pcidev, nesqp->qp_mem_size,
+                       &nesqp->hwqp.sq_pbase);
+       if (!mem)
+               return -ENOMEM;
+       nes_debug(NES_DBG_QP, "PCI consistent memory for "
+                       "host descriptor rings located @ %p (pa = 0x%08lX.) size = %u.\n",
+                       mem, (unsigned long)nesqp->hwqp.sq_pbase, nesqp->qp_mem_size);
+
+       memset(mem, 0, nesqp->qp_mem_size);
+
+       nesqp->hwqp.sq_vbase = mem;
+       mem += sizeof(struct nes_hw_qp_wqe) * sq_size;
+
+       nesqp->hwqp.rq_vbase = mem;
+       nesqp->hwqp.rq_pbase = nesqp->hwqp.sq_pbase +
+                       sizeof(struct nes_hw_qp_wqe) * sq_size;
+       mem += sizeof(struct nes_hw_qp_wqe) * rq_size;
+
+       nesqp->hwqp.q2_vbase = mem;
+       nesqp->hwqp.q2_pbase = nesqp->hwqp.rq_pbase +
+                       sizeof(struct nes_hw_qp_wqe) * rq_size;
+       mem += 256;
+       memset(nesqp->hwqp.q2_vbase, 0, 256);
+
+       nesqp->nesqp_context = mem;
+       nesqp->nesqp_context_pbase = nesqp->hwqp.q2_pbase + 256;
+       memset(nesqp->nesqp_context, 0, sizeof(*nesqp->nesqp_context));
+       return 0;
+}
+
+
+/**
+ * nes_free_qp_mem() is to free up the qp's pci_alloc_consistent() memory.
+ */
+static inline void nes_free_qp_mem(struct nes_device *nesdev,
+               struct nes_qp *nesqp, int virt_wqs)
+{
+       unsigned long flags;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       if (!virt_wqs) {
+               pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
+                               nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
+       }else {
+               spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+               nesadapter->free_256pbl++;
+               spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+               pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size, nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
+               pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase );
+               nesqp->pbl_vbase = NULL;
+               kunmap(nesqp->page);
+       }
+}
+
+
+/**
+ * nes_create_qp
+ */
+static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
+               struct ib_qp_init_attr *init_attr, struct ib_udata *udata)
+{
+       u64 u64temp= 0;
+       u64 u64nesqp = 0;
+       struct nes_pd *nespd = to_nespd(ibpd);
+       struct nes_vnic *nesvnic = to_nesvnic(ibpd->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_qp *nesqp;
+       struct nes_cq *nescq;
+       struct nes_ucontext *nes_ucontext;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_cqp_request *cqp_request;
+       struct nes_create_qp_req req;
+       struct nes_create_qp_resp uresp;
+       struct nes_pbl  *nespbl = NULL;
+       u32 qp_num = 0;
+       u32 opcode = 0;
+       /* u32 counter = 0; */
+       void *mem;
+       unsigned long flags;
+       int ret;
+       int err;
+       int virt_wqs = 0;
+       int sq_size;
+       int rq_size;
+       u8 sq_encoded_size;
+       u8 rq_encoded_size;
+       /* int counter; */
+
+       atomic_inc(&qps_created);
+       switch (init_attr->qp_type) {
+               case IB_QPT_RC:
+                       if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
+                               init_attr->cap.max_inline_data = 0;
+                       } else {
+                               init_attr->cap.max_inline_data = 64;
+                       }
+                       sq_size = init_attr->cap.max_send_wr;
+                       rq_size = init_attr->cap.max_recv_wr;
+
+                       // check if the encoded sizes are OK or not...
+                       sq_encoded_size = nes_get_encoded_size(&sq_size);
+                       rq_encoded_size = nes_get_encoded_size(&rq_size);
+
+                       if ((!sq_encoded_size) || (!rq_encoded_size)) {
+                               nes_debug(NES_DBG_QP, "ERROR bad rq (%u) or sq (%u) size\n",
+                                               rq_size, sq_size);
+                               return ERR_PTR(-EINVAL);
+                       }
+
+                       init_attr->cap.max_send_wr = sq_size -2;
+                       init_attr->cap.max_recv_wr = rq_size -1;
+                       nes_debug(NES_DBG_QP, "RQ size=%u, SQ Size=%u\n", rq_size, sq_size);
+
+                       ret = nes_alloc_resource(nesadapter, nesadapter->allocated_qps,
+                                       nesadapter->max_qp, &qp_num, &nesadapter->next_qp);
+                       if (ret) {
+                               return ERR_PTR(ret);
+                       }
+
+                       /* Need 512 (actually now 1024) byte alignment on this structure */
+                       mem = kzalloc(sizeof(*nesqp)+NES_SW_CONTEXT_ALIGN-1, GFP_KERNEL);
+                       if (!mem) {
+                               nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                               nes_debug(NES_DBG_QP, "Unable to allocate QP\n");
+                               return ERR_PTR(-ENOMEM);
+                       }
+                       u64nesqp = (unsigned long)mem;
+                       u64nesqp += ((u64)NES_SW_CONTEXT_ALIGN) - 1;
+                       u64temp = ((u64)NES_SW_CONTEXT_ALIGN) - 1;
+                       u64nesqp &= ~u64temp;
+                       nesqp = (struct nes_qp *)(unsigned long)u64nesqp;
+                       /* nes_debug(NES_DBG_QP, "nesqp=%p, allocated buffer=%p.  Rounded to closest %u\n",
+                                       nesqp, mem, NES_SW_CONTEXT_ALIGN); */
+                       nesqp->allocated_buffer = mem;
+
+                       if (udata) {
+                               if (ib_copy_from_udata(&req, udata, sizeof(struct nes_create_qp_req))) {
+                                       nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                                       kfree(nesqp->allocated_buffer);
+                                       nes_debug(NES_DBG_QP, "ib_copy_from_udata() Failed \n");
+                                       return NULL;
+                               }
+                               if (req.user_wqe_buffers) {
+                                       virt_wqs = 1;
+                               }
+                               if ((ibpd->uobject) && (ibpd->uobject->context)) {
+                                       nesqp->user_mode = 1;
+                                       nes_ucontext = to_nesucontext(ibpd->uobject->context);
+                                       if (virt_wqs) {
+                                               err = 1;
+                                               list_for_each_entry(nespbl, &nes_ucontext->qp_reg_mem_list, list) {
+                                                       if (nespbl->user_base == (unsigned long )req.user_wqe_buffers) {
+                                                               list_del(&nespbl->list);
+                                                               err = 0;
+                                                               nes_debug(NES_DBG_QP, "Found PBL for virtual QP. nespbl=%p. user_base=0x%lx\n",
+                                                                         nespbl, nespbl->user_base);
+                                                               break;
+                                                       }
+                                               }
+                                               if (err) {
+                                                       nes_debug(NES_DBG_QP, "Didn't Find PBL for virtual QP. address = %llx.\n",
+                                                                 (long long unsigned int)req.user_wqe_buffers);
+                                                       nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                                                       kfree(nesqp->allocated_buffer);
+                                                       return ERR_PTR(-ENOMEM);
+                                               }
+                                       }
+
+                                       nes_ucontext = to_nesucontext(ibpd->uobject->context);
+                                       nesqp->mmap_sq_db_index =
+                                               find_next_zero_bit(nes_ucontext->allocated_wqs,
+                                                                  NES_MAX_USER_WQ_REGIONS, nes_ucontext->first_free_wq);
+                                       /* nes_debug(NES_DBG_QP, "find_first_zero_biton wqs returned %u\n",
+                                                       nespd->mmap_db_index); */
+                                       if (nesqp->mmap_sq_db_index > NES_MAX_USER_WQ_REGIONS) {
+                                               nes_debug(NES_DBG_QP,
+                                                         "db index > max user regions, failing create QP\n");
+                                               nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                                               if (virt_wqs) {
+                                                       pci_free_consistent(nesdev->pcidev, nespbl->pbl_size, nespbl->pbl_vbase,
+                                                                           nespbl->pbl_pbase);
+                                                       kfree(nespbl);
+                                               }
+                                               kfree(nesqp->allocated_buffer);
+                                               return ERR_PTR(-ENOMEM);
+                                       }
+                                       set_bit(nesqp->mmap_sq_db_index, nes_ucontext->allocated_wqs);
+                                       nes_ucontext->mmap_nesqp[nesqp->mmap_sq_db_index] = nesqp;
+                                       nes_ucontext->first_free_wq = nesqp->mmap_sq_db_index + 1;
+                               } else {
+                                       nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                                       kfree(nesqp->allocated_buffer);
+                                       return ERR_PTR(-EFAULT);
+                               }
+                       }
+                       err = (!virt_wqs) ? nes_setup_mmap_qp(nesqp, nesvnic, sq_size, rq_size) :
+                                       nes_setup_virt_qp(nesqp, nespbl, nesvnic, sq_size, rq_size);
+                       if (err) {
+                               nes_debug(NES_DBG_QP,
+                                         "error geting qp mem code = %d\n", err);
+                               nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                               kfree(nesqp->allocated_buffer);
+                               return ERR_PTR(-ENOMEM);
+                       }
+
+                       nesqp->hwqp.sq_size = sq_size;
+                       nesqp->hwqp.sq_encoded_size = sq_encoded_size;
+                       nesqp->hwqp.sq_head = 1;
+                       nesqp->hwqp.rq_size = rq_size;
+                       nesqp->hwqp.rq_encoded_size = rq_encoded_size;
+                       /* nes_debug(NES_DBG_QP, "nesqp->nesqp_context_pbase = %p\n",
+                                       (void *)nesqp->nesqp_context_pbase);
+                       */
+                       nesqp->hwqp.qp_id = qp_num;
+                       nesqp->ibqp.qp_num = nesqp->hwqp.qp_id;
+                       nesqp->nespd = nespd;
+
+                       nescq = to_nescq(init_attr->send_cq);
+                       nesqp->nesscq = nescq;
+                       nescq = to_nescq(init_attr->recv_cq);
+                       nesqp->nesrcq = nescq;
+
+                       nesqp->nesqp_context->misc |= cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) <<
+                                       NES_QPCONTEXT_MISC_PCI_FCN_SHIFT);
+                       nesqp->nesqp_context->misc |= cpu_to_le32((u32)nesqp->hwqp.rq_encoded_size <<
+                                       NES_QPCONTEXT_MISC_RQ_SIZE_SHIFT);
+                       nesqp->nesqp_context->misc |= cpu_to_le32((u32)nesqp->hwqp.sq_encoded_size <<
+                                       NES_QPCONTEXT_MISC_SQ_SIZE_SHIFT);
+                               nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_PRIV_EN);
+                               nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_FAST_REGISTER_EN);
+                       nesqp->nesqp_context->cqs = cpu_to_le32(nesqp->nesscq->hw_cq.cq_number +
+                                       ((u32)nesqp->nesrcq->hw_cq.cq_number << 16));
+                       u64temp = (u64)nesqp->hwqp.sq_pbase;
+                       nesqp->nesqp_context->sq_addr_low = cpu_to_le32((u32)u64temp);
+                       nesqp->nesqp_context->sq_addr_high = cpu_to_le32((u32)(u64temp >> 32));
+
+
+                       if (!virt_wqs) {
+                               u64temp = (u64)nesqp->hwqp.sq_pbase;
+                               nesqp->nesqp_context->sq_addr_low = cpu_to_le32((u32)u64temp);
+                               nesqp->nesqp_context->sq_addr_high = cpu_to_le32((u32)(u64temp >> 32));
+                               u64temp = (u64)nesqp->hwqp.rq_pbase;
+                               nesqp->nesqp_context->rq_addr_low = cpu_to_le32((u32)u64temp);
+                               nesqp->nesqp_context->rq_addr_high = cpu_to_le32((u32)(u64temp >> 32));
+                       } else {
+                               u64temp = (u64)nesqp->pbl_pbase;
+                               nesqp->nesqp_context->rq_addr_low = cpu_to_le32((u32)u64temp);
+                               nesqp->nesqp_context->rq_addr_high = cpu_to_le32((u32)(u64temp >> 32));
+                       }
+
+                       /* nes_debug(NES_DBG_QP, "next_qp_nic_index=%u, using nic_index=%d\n",
+                                       nesvnic->next_qp_nic_index,
+                                       nesvnic->qp_nic_index[nesvnic->next_qp_nic_index]); */
+                       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                       nesqp->nesqp_context->misc2 |= cpu_to_le32(
+                                       (u32)nesvnic->qp_nic_index[nesvnic->next_qp_nic_index] <<
+                                       NES_QPCONTEXT_MISC2_NIC_INDEX_SHIFT);
+                       nesvnic->next_qp_nic_index++;
+                       if ((nesvnic->next_qp_nic_index > 3) ||
+                                       (nesvnic->qp_nic_index[nesvnic->next_qp_nic_index] == 0xf)) {
+                               nesvnic->next_qp_nic_index = 0;
+                       }
+                       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+
+                       nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32((u32)nesqp->nespd->pd_id << 16);
+                       u64temp = (u64)nesqp->hwqp.q2_pbase;
+                       nesqp->nesqp_context->q2_addr_low = cpu_to_le32((u32)u64temp);
+                       nesqp->nesqp_context->q2_addr_high = cpu_to_le32((u32)(u64temp >> 32));
+                       nesqp->nesqp_context->aeq_token_low =  cpu_to_le32((u32)((unsigned long)(nesqp)));
+                       nesqp->nesqp_context->aeq_token_high =  cpu_to_le32((u32)(upper_32_bits((unsigned long)(nesqp))));
+                       nesqp->nesqp_context->ird_ord_sizes = cpu_to_le32(NES_QPCONTEXT_ORDIRD_ALSMM |
+                                       ((((u32)nesadapter->max_irrq_wr) <<
+                                       NES_QPCONTEXT_ORDIRD_IRDSIZE_SHIFT) & NES_QPCONTEXT_ORDIRD_IRDSIZE_MASK));
+                       if (disable_mpa_crc) {
+                               nes_debug(NES_DBG_QP, "Disabling MPA crc checking due to module option.\n");
+                               nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32(NES_QPCONTEXT_ORDIRD_RNMC);
+                       }
+
+
+                       /* Create the QP */
+                       cqp_request = nes_get_cqp_request(nesdev);
+                       if (cqp_request == NULL) {
+                               nes_debug(NES_DBG_QP, "Failed to get a cqp_request\n");
+                               nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                               nes_free_qp_mem(nesdev, nesqp,virt_wqs);
+                               kfree(nesqp->allocated_buffer);
+                               return ERR_PTR(-ENOMEM);
+                       }
+                       cqp_request->waiting = 1;
+                       cqp_wqe = &cqp_request->cqp_wqe;
+
+                       if (!virt_wqs) {
+                               opcode = NES_CQP_CREATE_QP | NES_CQP_QP_TYPE_IWARP |
+                                       NES_CQP_QP_IWARP_STATE_IDLE;
+                       } else {
+                               opcode = NES_CQP_CREATE_QP | NES_CQP_QP_TYPE_IWARP | NES_CQP_QP_VIRT_WQS |
+                                       NES_CQP_QP_IWARP_STATE_IDLE;
+                       }
+                       opcode |= NES_CQP_QP_CQS_VALID;
+                       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+                       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
+                       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
+
+                       u64temp = (u64)nesqp->nesqp_context_pbase;
+                       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
+
+                       atomic_set(&cqp_request->refcount, 2);
+                       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+                       /* Wait for CQP */
+                       nes_debug(NES_DBG_QP, "Waiting for create iWARP QP%u to complete.\n",
+                                       nesqp->hwqp.qp_id);
+                       ret = wait_event_timeout(cqp_request->waitq,
+                                       (cqp_request->request_done != 0), NES_EVENT_TIMEOUT);
+                       nes_debug(NES_DBG_QP, "Create iwarp QP%u completed, wait_event_timeout ret=%u,"
+                                       " nesdev->cqp_head = %u, nesdev->cqp.sq_tail = %u,"
+                                       " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
+                                       nesqp->hwqp.qp_id, ret, nesdev->cqp.sq_head, nesdev->cqp.sq_tail,
+                                       cqp_request->major_code, cqp_request->minor_code);
+                       if ((!ret) || (cqp_request->major_code)) {
+                               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                                       if (cqp_request->dynamic) {
+                                               kfree(cqp_request);
+                                       } else {
+                                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                                       }
+                               }
+                               nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                               nes_free_qp_mem(nesdev, nesqp,virt_wqs);
+                               kfree(nesqp->allocated_buffer);
+                               if (!ret) {
+                                       return ERR_PTR(-ETIME);
+                               } else {
+                                       return ERR_PTR(-EIO);
+                               }
+                       } else {
+                               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                                       if (cqp_request->dynamic) {
+                                               kfree(cqp_request);
+                                       } else {
+                                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                                       }
+                               }
+                       }
+
+                       if (ibpd->uobject) {
+                               uresp.mmap_sq_db_index = nesqp->mmap_sq_db_index;
+                               uresp.actual_sq_size = sq_size;
+                               uresp.actual_rq_size = rq_size;
+                               uresp.qp_id = nesqp->hwqp.qp_id;
+                               uresp.nes_drv_opt = nes_drv_opt;
+                               if (ib_copy_to_udata(udata, &uresp, sizeof uresp)) {
+                                       nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
+                                       nes_free_qp_mem(nesdev, nesqp,virt_wqs);
+                                       kfree(nesqp->allocated_buffer);
+                                       return ERR_PTR(-EFAULT);
+                               }
+                       }
+
+                       nes_debug(NES_DBG_QP, "QP%u structure located @%p.Size = %u.\n",
+                                       nesqp->hwqp.qp_id, nesqp, (u32)sizeof(*nesqp));
+                       spin_lock_init(&nesqp->lock);
+                       init_waitqueue_head(&nesqp->state_waitq);
+                       init_waitqueue_head(&nesqp->kick_waitq);
+                       nes_add_ref(&nesqp->ibqp);
+                       break;
+               default:
+                       nes_debug(NES_DBG_QP, "Invalid QP type: %d\n", init_attr->qp_type);
+                       return ERR_PTR(-EINVAL);
+                       break;
+       }
+
+       /* update the QP table */
+       nesdev->nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = nesqp;
+       nes_debug(NES_DBG_QP, "netdev refcnt=%u\n",
+                       atomic_read(&nesvnic->netdev->refcnt));
+
+       return &nesqp->ibqp;
+}
+
+
+/**
+ * nes_destroy_qp
+ */
+static int nes_destroy_qp(struct ib_qp *ibqp)
+{
+       struct nes_qp *nesqp = to_nesqp(ibqp);
+       /* struct nes_vnic *nesvnic = to_nesvnic(ibqp->device); */
+       struct nes_ucontext *nes_ucontext;
+       struct ib_qp_attr attr;
+       struct iw_cm_id *cm_id;
+       struct iw_cm_event cm_event;
+       int ret;
+
+       atomic_inc(&sw_qps_destroyed);
+       nesqp->destroyed = 1;
+
+       /* Blow away the connection if it exists. */
+       if (nesqp->ibqp_state >= IB_QPS_INIT && nesqp->ibqp_state <= IB_QPS_RTS) {
+               /* if (nesqp->ibqp_state == IB_QPS_RTS) { */
+               attr.qp_state = IB_QPS_ERR;
+               nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
+       }
+
+       if (((nesqp->ibqp_state == IB_QPS_INIT) ||
+                       (nesqp->ibqp_state == IB_QPS_RTR)) && (nesqp->cm_id)) {
+               cm_id = nesqp->cm_id;
+               cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
+               cm_event.status = IW_CM_EVENT_STATUS_TIMEOUT;
+               cm_event.local_addr = cm_id->local_addr;
+               cm_event.remote_addr = cm_id->remote_addr;
+               cm_event.private_data = NULL;
+               cm_event.private_data_len = 0;
+
+               nes_debug(NES_DBG_QP, "Generating a CM Timeout Event for "
+                               "QP%u. cm_id = %p, refcount = %u. \n",
+                               nesqp->hwqp.qp_id, cm_id, atomic_read(&nesqp->refcount));
+
+               cm_id->rem_ref(cm_id);
+               ret = cm_id->event_handler(cm_id, &cm_event);
+               if (ret)
+                       nes_debug(NES_DBG_QP, "OFA CM event_handler returned, ret=%d\n", ret);
+       }
+
+
+       if (nesqp->user_mode) {
+               if ((ibqp->uobject)&&(ibqp->uobject->context)) {
+                       nes_ucontext = to_nesucontext(ibqp->uobject->context);
+                       clear_bit(nesqp->mmap_sq_db_index, nes_ucontext->allocated_wqs);
+                       nes_ucontext->mmap_nesqp[nesqp->mmap_sq_db_index] = NULL;
+                       if (nes_ucontext->first_free_wq > nesqp->mmap_sq_db_index) {
+                               nes_ucontext->first_free_wq = nesqp->mmap_sq_db_index;
+                       }
+               }
+               if (nesqp->pbl_pbase)
+                       kunmap(nesqp->page);
+       }
+
+       nes_rem_ref(&nesqp->ibqp);
+       return 0;
+}
+
+
+/**
+ * nes_create_cq
+ */
+static struct ib_cq *nes_create_cq(struct ib_device *ibdev, int entries,
+               int comp_vector,
+               struct ib_ucontext *context, struct ib_udata *udata)
+{
+       u64 u64temp;
+       struct nes_vnic *nesvnic = to_nesvnic(ibdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_cq *nescq;
+       struct nes_ucontext *nes_ucontext = NULL;
+       struct nes_cqp_request *cqp_request;
+       void *mem = NULL;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_pbl *nespbl = NULL;
+       struct nes_create_cq_req req;
+       struct nes_create_cq_resp resp;
+       u32 cq_num = 0;
+       u32 opcode = 0;
+       u32 pbl_entries = 1;
+       int err;
+       unsigned long flags;
+       int ret;
+
+       err = nes_alloc_resource(nesadapter, nesadapter->allocated_cqs,
+                       nesadapter->max_cq, &cq_num, &nesadapter->next_cq);
+       if (err) {
+               return ERR_PTR(err);
+       }
+
+       nescq = kzalloc(sizeof(struct nes_cq), GFP_KERNEL);
+       if (!nescq) {
+               nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+               nes_debug(NES_DBG_CQ, "Unable to allocate nes_cq struct\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       nescq->hw_cq.cq_size = max(entries + 1, 5);
+       nescq->hw_cq.cq_number = cq_num;
+       nescq->ibcq.cqe = nescq->hw_cq.cq_size - 1;
+
+
+       if (context) {
+               nes_ucontext = to_nesucontext(context);
+               if (ib_copy_from_udata(&req, udata, sizeof (struct nes_create_cq_req))) {
+                       nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+                       kfree(nescq);
+                       return ERR_PTR(-EFAULT);
+               }
+               nesvnic->mcrq_ucontext = nes_ucontext;
+               nes_ucontext->mcrqf = req.mcrqf;
+               if (nes_ucontext->mcrqf) {
+                       if (nes_ucontext->mcrqf & 0x80000000)
+                               nescq->hw_cq.cq_number = nesvnic->nic.qp_id + 12 + (nes_ucontext->mcrqf & 0xf) - 1;
+                       else if (nes_ucontext->mcrqf & 0x40000000)
+                               nescq->hw_cq.cq_number = nes_ucontext->mcrqf & 0xffff;
+                       else
+                               nescq->hw_cq.cq_number = nesvnic->mcrq_qp_id + nes_ucontext->mcrqf-1;
+                       nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+               }
+               nes_debug(NES_DBG_CQ, "CQ Virtual Address = %08lX, size = %u.\n",
+                               (unsigned long)req.user_cq_buffer, entries);
+               list_for_each_entry(nespbl, &nes_ucontext->cq_reg_mem_list, list) {
+                       if (nespbl->user_base == (unsigned long )req.user_cq_buffer) {
+                               list_del(&nespbl->list);
+                               err = 0;
+                               nes_debug(NES_DBG_CQ, "Found PBL for virtual CQ. nespbl=%p.\n",
+                                               nespbl);
+                               break;
+                       }
+               }
+               if (err) {
+                       nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+                       kfree(nescq);
+                       return ERR_PTR(err);
+               }
+
+               pbl_entries = nespbl->pbl_size >> 3;
+               nescq->cq_mem_size = 0;
+       } else {
+               nescq->cq_mem_size = nescq->hw_cq.cq_size * sizeof(struct nes_hw_cqe);
+               nes_debug(NES_DBG_CQ, "Attempting to allocate pci memory (%u entries, %u bytes) for CQ%u.\n",
+                               entries, nescq->cq_mem_size, nescq->hw_cq.cq_number);
+
+               /* allocate the physical buffer space */
+               mem = pci_alloc_consistent(nesdev->pcidev, nescq->cq_mem_size,
+                               &nescq->hw_cq.cq_pbase);
+               if (!mem) {
+                       printk(KERN_ERR PFX "Unable to allocate pci memory for cq\n");
+                       nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+                       kfree(nescq);
+                       return ERR_PTR(-ENOMEM);
+               }
+
+               memset(mem, 0, nescq->cq_mem_size);
+               nescq->hw_cq.cq_vbase = mem;
+               nescq->hw_cq.cq_head = 0;
+               nes_debug(NES_DBG_CQ, "CQ%u virtual address @ %p, phys = 0x%08X\n",
+                               nescq->hw_cq.cq_number, nescq->hw_cq.cq_vbase,
+                               (u32)nescq->hw_cq.cq_pbase);
+       }
+
+       nescq->hw_cq.ce_handler = nes_iwarp_ce_handler;
+       spin_lock_init(&nescq->lock);
+
+       /* send CreateCQ request to CQP */
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_CQ, "Failed to get a cqp_request.\n");
+               if (!context)
+                       pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size, mem,
+                                       nescq->hw_cq.cq_pbase);
+               nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+               kfree(nescq);
+               return ERR_PTR(-ENOMEM);
+       }
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+
+       opcode = NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
+                       NES_CQP_CQ_CHK_OVERFLOW |
+                       NES_CQP_CQ_CEQE_MASK | ((u32)nescq->hw_cq.cq_size << 16);
+
+       spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+
+       if (pbl_entries != 1) {
+               if (pbl_entries > 32) {
+                       /* use 4k pbl */
+                       nes_debug(NES_DBG_CQ, "pbl_entries=%u, use a 4k PBL\n", pbl_entries);
+                       if (nesadapter->free_4kpbl == 0) {
+                               if (cqp_request->dynamic) {
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                                       kfree(cqp_request);
+                               } else {
+                                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               }
+                               if (!context)
+                                       pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size, mem,
+                                                       nescq->hw_cq.cq_pbase);
+                               nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+                               kfree(nescq);
+                               return ERR_PTR(-ENOMEM);
+                       } else {
+                               opcode |= (NES_CQP_CQ_VIRT | NES_CQP_CQ_4KB_CHUNK);
+                               nescq->virtual_cq = 2;
+                               nesadapter->free_4kpbl--;
+                       }
+               } else {
+                       /* use 256 byte pbl */
+                       nes_debug(NES_DBG_CQ, "pbl_entries=%u, use a 256 byte PBL\n", pbl_entries);
+                       if (nesadapter->free_256pbl == 0) {
+                               if (cqp_request->dynamic) {
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                                       kfree(cqp_request);
+                               } else {
+                                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               }
+                               if (!context)
+                                       pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size, mem,
+                                                       nescq->hw_cq.cq_pbase);
+                               nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+                               kfree(nescq);
+                               return ERR_PTR(-ENOMEM);
+                       } else {
+                               opcode |= NES_CQP_CQ_VIRT;
+                               nescq->virtual_cq = 1;
+                               nesadapter->free_256pbl--;
+                       }
+               }
+       }
+
+       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+                       (nescq->hw_cq.cq_number | ((u32)nesdev->ceq_index << 16)));
+
+       if (context) {
+               if (pbl_entries != 1)
+                       u64temp = (u64)nespbl->pbl_pbase;
+               else
+                       u64temp = le64_to_cpu(nespbl->pbl_vbase[0]);
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX,
+                               nes_ucontext->mmap_db_index[0]);
+       } else {
+               u64temp = (u64)nescq->hw_cq.cq_pbase;
+               cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
+       }
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
+       u64temp = (u64)(unsigned long)&nescq->hw_cq;
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] =
+                       cpu_to_le32((u32)(u64temp >> 1));
+       cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
+                       cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       nes_debug(NES_DBG_CQ, "Waiting for create iWARP CQ%u to complete.\n",
+                       nescq->hw_cq.cq_number);
+       ret = wait_event_timeout(cqp_request->waitq, (0 != cqp_request->request_done),
+                       NES_EVENT_TIMEOUT * 2);
+       nes_debug(NES_DBG_CQ, "Create iWARP CQ%u completed, wait_event_timeout ret = %d.\n",
+                       nescq->hw_cq.cq_number, ret);
+       if ((!ret) || (cqp_request->major_code)) {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+               nes_debug(NES_DBG_CQ, "iWARP CQ%u create timeout expired, major code = 0x%04X,"
+                               " minor code = 0x%04X\n",
+                               nescq->hw_cq.cq_number, cqp_request->major_code, cqp_request->minor_code);
+               if (!context)
+                       pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size, mem,
+                                       nescq->hw_cq.cq_pbase);
+               nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+               kfree(nescq);
+               return ERR_PTR(-EIO);
+       } else {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+       }
+
+       if (context) {
+               /* free the nespbl */
+               pci_free_consistent(nesdev->pcidev, nespbl->pbl_size, nespbl->pbl_vbase,
+                               nespbl->pbl_pbase);
+               kfree(nespbl);
+               resp.cq_id = nescq->hw_cq.cq_number;
+               resp.cq_size = nescq->hw_cq.cq_size;
+               resp.mmap_db_index = 0;
+               if (ib_copy_to_udata(udata, &resp, sizeof resp)) {
+                       nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
+                       kfree(nescq);
+                       return ERR_PTR(-EFAULT);
+               }
+       }
+
+       return &nescq->ibcq;
+}
+
+
+/**
+ * nes_destroy_cq
+ */
+static int nes_destroy_cq(struct ib_cq *ib_cq)
+{
+       struct nes_cq *nescq;
+       struct nes_device *nesdev;
+       struct nes_vnic *nesvnic;
+       struct nes_adapter *nesadapter;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_cqp_request *cqp_request;
+       unsigned long flags;
+       u32 opcode = 0;
+       int ret;
+
+       if (ib_cq == NULL)
+               return 0;
+
+       nescq = to_nescq(ib_cq);
+       nesvnic = to_nesvnic(ib_cq->device);
+       nesdev = nesvnic->nesdev;
+       nesadapter = nesdev->nesadapter;
+
+       nes_debug(NES_DBG_CQ, "Destroy CQ%u\n", nescq->hw_cq.cq_number);
+
+       /* Send DestroyCQ request to CQP */
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_CQ, "Failed to get a cqp_request.\n");
+               return -ENOMEM;
+       }
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+       opcode = NES_CQP_DESTROY_CQ | (nescq->hw_cq.cq_size << 16);
+       spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+       if (nescq->virtual_cq == 1) {
+               nesadapter->free_256pbl++;
+               if (nesadapter->free_256pbl > nesadapter->max_256pbl) {
+                       printk(KERN_ERR PFX "%s: free 256B PBLs(%u) has exceeded the max(%u)\n",
+                                       __FUNCTION__, nesadapter->free_256pbl, nesadapter->max_256pbl);
+               }
+       } else if (nescq->virtual_cq == 2) {
+               nesadapter->free_4kpbl++;
+               if (nesadapter->free_4kpbl > nesadapter->max_4kpbl) {
+                       printk(KERN_ERR PFX "%s: free 4K PBLs(%u) has exceeded the max(%u)\n",
+                                       __FUNCTION__, nesadapter->free_4kpbl, nesadapter->max_4kpbl);
+               }
+               opcode |= NES_CQP_CQ_4KB_CHUNK;
+       }
+
+       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
+               (nescq->hw_cq.cq_number | ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 16)));
+       nes_free_resource(nesadapter, nesadapter->allocated_cqs, nescq->hw_cq.cq_number);
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       nes_debug(NES_DBG_CQ, "Waiting for destroy iWARP CQ%u to complete.\n",
+                       nescq->hw_cq.cq_number);
+       ret = wait_event_timeout(cqp_request->waitq, (0 != cqp_request->request_done),
+                       NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_CQ, "Destroy iWARP CQ%u completed, wait_event_timeout ret = %u,"
+                       " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
+                       nescq->hw_cq.cq_number, ret, cqp_request->major_code,
+                       cqp_request->minor_code);
+       if ((!ret) || (cqp_request->major_code)) {
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+               if (!ret) {
+                       nes_debug(NES_DBG_CQ, "iWARP CQ%u destroy timeout expired\n",
+                                       nescq->hw_cq.cq_number);
+                       ret = -ETIME;
+               } else {
+                       nes_debug(NES_DBG_CQ, "iWARP CQ%u destroy failed\n",
+                                       nescq->hw_cq.cq_number);
+                       ret = -EIO;
+               }
+       } else {
+               ret = 0;
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+       }
+
+       if (nescq->cq_mem_size)
+               pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size,
+                               (void *)nescq->hw_cq.cq_vbase, nescq->hw_cq.cq_pbase);
+       kfree(nescq);
+
+       return ret;
+}
+
+
+/**
+ * nes_reg_mr
+ */
+static int nes_reg_mr(struct nes_device *nesdev, struct nes_pd *nespd,
+               u32 stag, u64 region_length, struct nes_root_vpbl *root_vpbl,
+               dma_addr_t single_buffer, u16 pbl_count, u16 residual_page_count,
+               int acc, u64 *iova_start)
+{
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_cqp_request *cqp_request;
+       unsigned long flags;
+       int ret;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       /* int count; */
+       u32 opcode = 0;
+       u16 major_code;
+
+       /* Register the region with the adapter */
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_MR, "Failed to get a cqp_request.\n");
+               return -ENOMEM;
+       }
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+
+       spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+       /* track PBL resources */
+       if (pbl_count != 0) {
+               if (pbl_count > 1) {
+                       /* Two level PBL */
+                       if ((pbl_count+1) > nesadapter->free_4kpbl) {
+                               nes_debug(NES_DBG_MR, "Out of 4KB Pbls for two level request.\n");
+                               if (cqp_request->dynamic) {
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                                       kfree(cqp_request);
+                               } else {
+                                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               }
+                               return -ENOMEM;
+                       } else {
+                               nesadapter->free_4kpbl -= pbl_count+1;
+                       }
+               } else if (residual_page_count > 32) {
+                       if (pbl_count > nesadapter->free_4kpbl) {
+                               nes_debug(NES_DBG_MR, "Out of 4KB Pbls.\n");
+                               if (cqp_request->dynamic) {
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                                       kfree(cqp_request);
+                               } else {
+                                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               }
+                               return -ENOMEM;
+                       } else {
+                               nesadapter->free_4kpbl -= pbl_count;
+                       }
+               } else {
+                       if (pbl_count > nesadapter->free_256pbl) {
+                               nes_debug(NES_DBG_MR, "Out of 256B Pbls.\n");
+                               if (cqp_request->dynamic) {
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                                       kfree(cqp_request);
+                               } else {
+                                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                                       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+                               }
+                               return -ENOMEM;
+                       } else {
+                               nesadapter->free_256pbl -= pbl_count;
+                       }
+               }
+       }
+
+       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+
+       opcode = NES_CQP_REGISTER_STAG | NES_CQP_STAG_RIGHTS_LOCAL_READ |
+                                       NES_CQP_STAG_VA_TO | NES_CQP_STAG_MR;
+       if (acc & IB_ACCESS_LOCAL_WRITE)
+               opcode |= NES_CQP_STAG_RIGHTS_LOCAL_WRITE;
+       if (acc & IB_ACCESS_REMOTE_WRITE)
+               opcode |= NES_CQP_STAG_RIGHTS_REMOTE_WRITE | NES_CQP_STAG_REM_ACC_EN;
+       if (acc & IB_ACCESS_REMOTE_READ)
+               opcode |= NES_CQP_STAG_RIGHTS_REMOTE_READ | NES_CQP_STAG_REM_ACC_EN;
+       if (acc & IB_ACCESS_MW_BIND)
+               opcode |= NES_CQP_STAG_RIGHTS_WINDOW_BIND | NES_CQP_STAG_REM_ACC_EN;
+
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_VA_LOW_IDX, *iova_start);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_LEN_LOW_IDX, region_length);
+
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX] =
+                       cpu_to_le32((u32)(region_length >> 8) & 0xff000000);
+       cqp_wqe->wqe_words[NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX] |=
+                       cpu_to_le32(nespd->pd_id & 0x00007fff);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_STAG_IDX, stag);
+
+       if (pbl_count == 0) {
+               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_PA_LOW_IDX, single_buffer);
+       } else {
+               set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_PA_LOW_IDX, root_vpbl->pbl_pbase);
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_PBL_BLK_COUNT_IDX, pbl_count);
+               set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_PBL_LEN_IDX,
+                               (((pbl_count - 1) * 4096) + (residual_page_count*8)));
+
+               if ((pbl_count > 1) || (residual_page_count > 32))
+                       cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(NES_CQP_STAG_PBL_BLK_SIZE);
+       }
+       barrier();
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       ret = wait_event_timeout(cqp_request->waitq, (0 != cqp_request->request_done),
+                       NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_MR, "Register STag 0x%08X completed, wait_event_timeout ret = %u,"
+                       " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
+                       stag, ret, cqp_request->major_code, cqp_request->minor_code);
+       major_code = cqp_request->major_code;
+       if (atomic_dec_and_test(&cqp_request->refcount)) {
+               if (cqp_request->dynamic) {
+                       kfree(cqp_request);
+               } else {
+                       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+               }
+       }
+       if (!ret)
+               return -ETIME;
+       else if (major_code)
+               return -EIO;
+       else
+               return 0;
+
+       return 0;
+}
+
+
+/**
+ * nes_reg_phys_mr
+ */
+static struct ib_mr *nes_reg_phys_mr(struct ib_pd *ib_pd,
+               struct ib_phys_buf *buffer_list, int num_phys_buf, int acc,
+               u64 * iova_start)
+{
+       u64 region_length;
+       struct nes_pd *nespd = to_nespd(ib_pd);
+       struct nes_vnic *nesvnic = to_nesvnic(ib_pd->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_mr *nesmr;
+       struct ib_mr *ibmr;
+       struct nes_vpbl vpbl;
+       struct nes_root_vpbl root_vpbl;
+       u32 stag;
+       u32 i;
+       u32 stag_index = 0;
+       u32 next_stag_index = 0;
+       u32 driver_key = 0;
+       u32 root_pbl_index = 0;
+       u32 cur_pbl_index = 0;
+       int err = 0, pbl_depth = 0;
+       int ret = 0;
+       u16 pbl_count = 0;
+       u8 single_page = 1;
+       u8 stag_key = 0;
+
+       pbl_depth = 0;
+       region_length = 0;
+       vpbl.pbl_vbase = NULL;
+       root_vpbl.pbl_vbase = NULL;
+       root_vpbl.pbl_pbase = 0;
+
+       get_random_bytes(&next_stag_index, sizeof(next_stag_index));
+       stag_key = (u8)next_stag_index;
+
+       driver_key = 0;
+
+       next_stag_index >>= 8;
+       next_stag_index %= nesadapter->max_mr;
+       if (num_phys_buf > (1024*512)) {
+               return ERR_PTR(-E2BIG);
+       }
+
+       err = nes_alloc_resource(nesadapter, nesadapter->allocated_mrs, nesadapter->max_mr,
+                       &stag_index, &next_stag_index);
+       if (err) {
+               return ERR_PTR(err);
+       }
+
+       nesmr = kzalloc(sizeof(*nesmr), GFP_KERNEL);
+       if (!nesmr) {
+               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       for (i = 0; i < num_phys_buf; i++) {
+
+               if ((i & 0x01FF) == 0) {
+                       if (root_pbl_index == 1) {
+                               /* Allocate the root PBL */
+                               root_vpbl.pbl_vbase = pci_alloc_consistent(nesdev->pcidev, 8192,
+                                               &root_vpbl.pbl_pbase);
+                               nes_debug(NES_DBG_MR, "Allocating root PBL, va = %p, pa = 0x%08X\n",
+                                               root_vpbl.pbl_vbase, (unsigned int)root_vpbl.pbl_pbase);
+                               if (!root_vpbl.pbl_vbase) {
+                                       pci_free_consistent(nesdev->pcidev, 4096, vpbl.pbl_vbase,
+                                                       vpbl.pbl_pbase);
+                                       nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                                       kfree(nesmr);
+                                       return ERR_PTR(-ENOMEM);
+                               }
+                               root_vpbl.leaf_vpbl = kzalloc(sizeof(*root_vpbl.leaf_vpbl)*1024, GFP_KERNEL);
+                               if (!root_vpbl.leaf_vpbl) {
+                                       pci_free_consistent(nesdev->pcidev, 8192, root_vpbl.pbl_vbase,
+                                                       root_vpbl.pbl_pbase);
+                                       pci_free_consistent(nesdev->pcidev, 4096, vpbl.pbl_vbase,
+                                                       vpbl.pbl_pbase);
+                                       nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                                       kfree(nesmr);
+                                       return ERR_PTR(-ENOMEM);
+                               }
+                               root_vpbl.pbl_vbase[0].pa_low = cpu_to_le32((u32)vpbl.pbl_pbase);
+                               root_vpbl.pbl_vbase[0].pa_high =
+                                               cpu_to_le32((u32)((((u64)vpbl.pbl_pbase) >> 32)));
+                               root_vpbl.leaf_vpbl[0] = vpbl;
+                       }
+                       /* Allocate a 4K buffer for the PBL */
+                       vpbl.pbl_vbase = pci_alloc_consistent(nesdev->pcidev, 4096,
+                                       &vpbl.pbl_pbase);
+                       nes_debug(NES_DBG_MR, "Allocating leaf PBL, va = %p, pa = 0x%016lX\n",
+                                       vpbl.pbl_vbase, (unsigned long)vpbl.pbl_pbase);
+                       if (!vpbl.pbl_vbase) {
+                               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                               ibmr = ERR_PTR(-ENOMEM);
+                               kfree(nesmr);
+                               goto reg_phys_err;
+                       }
+                       /* Fill in the root table */
+                       if (1 <= root_pbl_index) {
+                               root_vpbl.pbl_vbase[root_pbl_index].pa_low =
+                                               cpu_to_le32((u32)vpbl.pbl_pbase);
+                               root_vpbl.pbl_vbase[root_pbl_index].pa_high =
+                                               cpu_to_le32((u32)((((u64)vpbl.pbl_pbase) >> 32)));
+                               root_vpbl.leaf_vpbl[root_pbl_index] = vpbl;
+                       }
+                       root_pbl_index++;
+                       cur_pbl_index = 0;
+               }
+               if (buffer_list[i].addr & ~PAGE_MASK) {
+                       /* TODO: Unwind allocated buffers */
+                       nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                       nes_debug(NES_DBG_MR, "Unaligned Memory Buffer: 0x%x\n",
+                                       (unsigned int) buffer_list[i].addr);
+                       ibmr = ERR_PTR(-EINVAL);
+                       kfree(nesmr);
+                       goto reg_phys_err;
+               }
+
+               if (!buffer_list[i].size) {
+                       nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                       nes_debug(NES_DBG_MR, "Invalid Buffer Size\n");
+                       ibmr = ERR_PTR(-EINVAL);
+                       kfree(nesmr);
+                       goto reg_phys_err;
+               }
+
+               region_length += buffer_list[i].size;
+               if ((i != 0) && (single_page)) {
+                       if ((buffer_list[i-1].addr+PAGE_SIZE) != buffer_list[i].addr)
+                               single_page = 0;
+               }
+               vpbl.pbl_vbase[cur_pbl_index].pa_low = cpu_to_le32((u32)buffer_list[i].addr);
+               vpbl.pbl_vbase[cur_pbl_index++].pa_high =
+                               cpu_to_le32((u32)((((u64)buffer_list[i].addr) >> 32)));
+       }
+
+       stag = stag_index << 8;
+       stag |= driver_key;
+       stag += (u32)stag_key;
+
+       nes_debug(NES_DBG_MR, "Registering STag 0x%08X, VA = 0x%016lX,"
+                       " length = 0x%016lX, index = 0x%08X\n",
+                       stag, (unsigned long)*iova_start, (unsigned long)region_length, stag_index);
+
+       region_length -= (*iova_start)&PAGE_MASK;
+
+       /* Make the leaf PBL the root if only one PBL */
+       if (root_pbl_index == 1) {
+               root_vpbl.pbl_pbase = vpbl.pbl_pbase;
+       }
+
+       if (single_page) {
+               pbl_count = 0;
+       } else {
+               pbl_count = root_pbl_index;
+       }
+       ret = nes_reg_mr(nesdev, nespd, stag, region_length, &root_vpbl,
+                       buffer_list[0].addr, pbl_count, (u16)cur_pbl_index, acc, iova_start);
+
+       if (ret == 0) {
+               nesmr->ibmr.rkey = stag;
+               nesmr->ibmr.lkey = stag;
+               nesmr->mode = IWNES_MEMREG_TYPE_MEM;
+               ibmr = &nesmr->ibmr;
+               nesmr->pbl_4k = ((pbl_count > 1) || (cur_pbl_index > 32)) ? 1 : 0;
+               nesmr->pbls_used = pbl_count;
+               if (pbl_count > 1) {
+                       nesmr->pbls_used++;
+               }
+       } else {
+               kfree(nesmr);
+               ibmr = ERR_PTR(-ENOMEM);
+       }
+
+       reg_phys_err:
+       /* free the resources */
+       if (root_pbl_index == 1) {
+               /* single PBL case */
+               pci_free_consistent(nesdev->pcidev, 4096, vpbl.pbl_vbase, vpbl.pbl_pbase);
+       } else {
+               for (i=0; i<root_pbl_index; i++) {
+                       pci_free_consistent(nesdev->pcidev, 4096, root_vpbl.leaf_vpbl[i].pbl_vbase,
+                                       root_vpbl.leaf_vpbl[i].pbl_pbase);
+               }
+               kfree(root_vpbl.leaf_vpbl);
+               pci_free_consistent(nesdev->pcidev, 8192, root_vpbl.pbl_vbase,
+                               root_vpbl.pbl_pbase);
+       }
+
+       return ibmr;
+}
+
+
+/**
+ * nes_get_dma_mr
+ */
+static struct ib_mr *nes_get_dma_mr(struct ib_pd *pd, int acc)
+{
+       struct ib_phys_buf bl;
+       u64 kva = 0;
+
+       nes_debug(NES_DBG_MR, "\n");
+
+       bl.size = (u64)0xffffffffffULL;
+       bl.addr = 0;
+       return nes_reg_phys_mr(pd, &bl, 1, acc, &kva);
+}
+
+
+/**
+ * nes_reg_user_mr
+ */
+static struct ib_mr *nes_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
+               u64 virt, int acc, struct ib_udata *udata)
+{
+       u64 iova_start;
+       __le64 *pbl;
+       u64 region_length;
+       dma_addr_t last_dma_addr = 0;
+       dma_addr_t first_dma_addr = 0;
+       struct nes_pd *nespd = to_nespd(pd);
+       struct nes_vnic *nesvnic = to_nesvnic(pd->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct ib_mr *ibmr = ERR_PTR(-EINVAL);
+       struct ib_umem_chunk *chunk;
+       struct nes_ucontext *nes_ucontext;
+       struct nes_pbl *nespbl;
+       struct nes_mr *nesmr;
+       struct ib_umem *region;
+       struct nes_mem_reg_req req;
+       struct nes_vpbl vpbl;
+       struct nes_root_vpbl root_vpbl;
+       int nmap_index, page_index;
+       int page_count = 0;
+       int err, pbl_depth = 0;
+       int chunk_pages;
+       int ret;
+       u32 stag;
+       u32 stag_index = 0;
+       u32 next_stag_index;
+       u32 driver_key;
+       u32 root_pbl_index = 0;
+       u32 cur_pbl_index = 0;
+       u32 skip_pages;
+       u16 pbl_count;
+       u8 single_page = 1;
+       u8 stag_key;
+
+       region = ib_umem_get(pd->uobject->context, start, length, acc);
+       if (IS_ERR(region)) {
+               return (struct ib_mr *)region;
+       }
+
+       nes_debug(NES_DBG_MR, "User base = 0x%lX, Virt base = 0x%lX, length = %u,"
+                       " offset = %u, page size = %u.\n",
+                       (unsigned long int)start, (unsigned long int)virt, (u32)length,
+                       region->offset, region->page_size);
+
+       skip_pages = ((u32)region->offset) >> 12;
+
+       if (ib_copy_from_udata(&req, udata, sizeof(req)))
+               return ERR_PTR(-EFAULT);
+       nes_debug(NES_DBG_MR, "Memory Registration type = %08X.\n", req.reg_type);
+
+       switch (req.reg_type) {
+               case IWNES_MEMREG_TYPE_MEM:
+                       pbl_depth = 0;
+                       region_length = 0;
+                       vpbl.pbl_vbase = NULL;
+                       root_vpbl.pbl_vbase = NULL;
+                       root_vpbl.pbl_pbase = 0;
+
+                       get_random_bytes(&next_stag_index, sizeof(next_stag_index));
+                       stag_key = (u8)next_stag_index;
+
+                       driver_key = next_stag_index & 0x70000000;
+
+                       next_stag_index >>= 8;
+                       next_stag_index %= nesadapter->max_mr;
+
+                       err = nes_alloc_resource(nesadapter, nesadapter->allocated_mrs,
+                                       nesadapter->max_mr, &stag_index, &next_stag_index);
+                       if (err) {
+                               ib_umem_release(region);
+                               return ERR_PTR(err);
+                       }
+
+                       nesmr = kzalloc(sizeof(*nesmr), GFP_KERNEL);
+                       if (!nesmr) {
+                               ib_umem_release(region);
+                               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                               return ERR_PTR(-ENOMEM);
+                       }
+                       nesmr->region = region;
+
+                       list_for_each_entry(chunk, &region->chunk_list, list) {
+                               nes_debug(NES_DBG_MR, "Chunk: nents = %u, nmap = %u .\n",
+                                               chunk->nents, chunk->nmap);
+                               for (nmap_index = 0; nmap_index < chunk->nmap; ++nmap_index) {
+                                       if (sg_dma_address(&chunk->page_list[nmap_index]) & ~PAGE_MASK) {
+                                               ib_umem_release(region);
+                                               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                                               nes_debug(NES_DBG_MR, "Unaligned Memory Buffer: 0x%x\n",
+                                                               (unsigned int) sg_dma_address(&chunk->page_list[nmap_index]));
+                                               ibmr = ERR_PTR(-EINVAL);
+                                               kfree(nesmr);
+                                               goto reg_user_mr_err;
+                                       }
+
+                                       if (!sg_dma_len(&chunk->page_list[nmap_index])) {
+                                               ib_umem_release(region);
+                                               nes_free_resource(nesadapter, nesadapter->allocated_mrs,
+                                                               stag_index);
+                                               nes_debug(NES_DBG_MR, "Invalid Buffer Size\n");
+                                               ibmr = ERR_PTR(-EINVAL);
+                                               kfree(nesmr);
+                                               goto reg_user_mr_err;
+                                       }
+
+                                       region_length += sg_dma_len(&chunk->page_list[nmap_index]);
+                                       chunk_pages = sg_dma_len(&chunk->page_list[nmap_index]) >> 12;
+                                       region_length -= skip_pages << 12;
+                                       for (page_index=skip_pages; page_index < chunk_pages; page_index++) {
+                                               skip_pages = 0;
+                                               if ((page_count!=0)&&(page_count<<12)-(region->offset&(4096-1))>=region->length)
+                                                       goto enough_pages;
+                                               if ((page_count&0x01FF) == 0) {
+                                                       if (page_count>(1024*512)) {
+                                                               ib_umem_release(region);
+                                                               pci_free_consistent(nesdev->pcidev, 4096, vpbl.pbl_vbase,
+                                                                               vpbl.pbl_pbase);
+                                                               nes_free_resource(nesadapter,
+                                                                               nesadapter->allocated_mrs, stag_index);
+                                                               kfree(nesmr);
+                                                               ibmr = ERR_PTR(-E2BIG);
+                                                               goto reg_user_mr_err;
+                                                       }
+                                                       if (root_pbl_index == 1) {
+                                                               root_vpbl.pbl_vbase = pci_alloc_consistent(nesdev->pcidev,
+                                                                               8192, &root_vpbl.pbl_pbase);
+                                                               nes_debug(NES_DBG_MR, "Allocating root PBL, va = %p, pa = 0x%08X\n",
+                                                                               root_vpbl.pbl_vbase, (unsigned int)root_vpbl.pbl_pbase);
+                                                               if (!root_vpbl.pbl_vbase) {
+                                                                       ib_umem_release(region);
+                                                                       pci_free_consistent(nesdev->pcidev, 4096, vpbl.pbl_vbase,
+                                                                                       vpbl.pbl_pbase);
+                                                                       nes_free_resource(nesadapter, nesadapter->allocated_mrs,
+                                                                                       stag_index);
+                                                                       kfree(nesmr);
+                                                                       ibmr = ERR_PTR(-ENOMEM);
+                                                                       goto reg_user_mr_err;
+                                                               }
+                                                               root_vpbl.leaf_vpbl = kzalloc(sizeof(*root_vpbl.leaf_vpbl)*1024,
+                                                                               GFP_KERNEL);
+                                                               if (!root_vpbl.leaf_vpbl) {
+                                                                       ib_umem_release(region);
+                                                                       pci_free_consistent(nesdev->pcidev, 8192, root_vpbl.pbl_vbase,
+                                                                                       root_vpbl.pbl_pbase);
+                                                                       pci_free_consistent(nesdev->pcidev, 4096, vpbl.pbl_vbase,
+                                                                                       vpbl.pbl_pbase);
+                                                                       nes_free_resource(nesadapter, nesadapter->allocated_mrs,
+                                                                                       stag_index);
+                                                                       kfree(nesmr);
+                                                                       ibmr = ERR_PTR(-ENOMEM);
+                                                                       goto reg_user_mr_err;
+                                                               }
+                                                               root_vpbl.pbl_vbase[0].pa_low =
+                                                                               cpu_to_le32((u32)vpbl.pbl_pbase);
+                                                               root_vpbl.pbl_vbase[0].pa_high =
+                                                                               cpu_to_le32((u32)((((u64)vpbl.pbl_pbase) >> 32)));
+                                                               root_vpbl.leaf_vpbl[0] = vpbl;
+                                                       }
+                                                       vpbl.pbl_vbase = pci_alloc_consistent(nesdev->pcidev, 4096,
+                                                                       &vpbl.pbl_pbase);
+                                                       nes_debug(NES_DBG_MR, "Allocating leaf PBL, va = %p, pa = 0x%08X\n",
+                                                                       vpbl.pbl_vbase, (unsigned int)vpbl.pbl_pbase);
+                                                       if (!vpbl.pbl_vbase) {
+                                                               ib_umem_release(region);
+                                                               nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
+                                                               ibmr = ERR_PTR(-ENOMEM);
+                                                               kfree(nesmr);
+                                                               goto reg_user_mr_err;
+                                                       }
+                                                       if (1 <= root_pbl_index) {
+                                                               root_vpbl.pbl_vbase[root_pbl_index].pa_low =
+                                                                               cpu_to_le32((u32)vpbl.pbl_pbase);
+                                                               root_vpbl.pbl_vbase[root_pbl_index].pa_high =
+                                                                               cpu_to_le32((u32)((((u64)vpbl.pbl_pbase)>>32)));
+                                                               root_vpbl.leaf_vpbl[root_pbl_index] = vpbl;
+                                                       }
+                                                       root_pbl_index++;
+                                                       cur_pbl_index = 0;
+                                               }
+                                               if (single_page) {
+                                                       if (page_count != 0) {
+                                                               if ((last_dma_addr+4096) !=
+                                                                               (sg_dma_address(&chunk->page_list[nmap_index])+
+                                                                               (page_index*4096)))
+                                                                       single_page = 0;
+                                                               last_dma_addr = sg_dma_address(&chunk->page_list[nmap_index])+
+                                                                               (page_index*4096);
+                                                       } else {
+                                                               first_dma_addr = sg_dma_address(&chunk->page_list[nmap_index])+
+                                                                               (page_index*4096);
+                                                               last_dma_addr = first_dma_addr;
+                                                       }
+                                               }
+
+                                               vpbl.pbl_vbase[cur_pbl_index].pa_low =
+                                                               cpu_to_le32((u32)(sg_dma_address(&chunk->page_list[nmap_index])+
+                                                               (page_index*4096)));
+                                               vpbl.pbl_vbase[cur_pbl_index].pa_high =
+                                                               cpu_to_le32((u32)((((u64)(sg_dma_address(&chunk->page_list[nmap_index])+
+                                                               (page_index*4096))) >> 32)));
+                                               cur_pbl_index++;
+                                               page_count++;
+                                       }
+                               }
+                       }
+                       enough_pages:
+                       nes_debug(NES_DBG_MR, "calculating stag, stag_index=0x%08x, driver_key=0x%08x,"
+                                       " stag_key=0x%08x\n",
+                                       stag_index, driver_key, stag_key);
+                       stag = stag_index << 8;
+                       stag |= driver_key;
+                       stag += (u32)stag_key;
+                       if (stag == 0) {
+                               stag = 1;
+                       }
+
+                       iova_start = virt;
+                       /* Make the leaf PBL the root if only one PBL */
+                       if (root_pbl_index == 1) {
+                               root_vpbl.pbl_pbase = vpbl.pbl_pbase;
+                       }
+
+                       if (single_page) {
+                               pbl_count = 0;
+                       } else {
+                               pbl_count = root_pbl_index;
+                               first_dma_addr = 0;
+                       }
+                       nes_debug(NES_DBG_MR, "Registering STag 0x%08X, VA = 0x%08X, length = 0x%08X,"
+                                       " index = 0x%08X, region->length=0x%08llx, pbl_count = %u\n",
+                                       stag, (unsigned int)iova_start,
+                                       (unsigned int)region_length, stag_index,
+                                       (unsigned long long)region->length, pbl_count);
+                       ret = nes_reg_mr( nesdev, nespd, stag, region->length, &root_vpbl,
+                                       first_dma_addr, pbl_count, (u16)cur_pbl_index, acc, &iova_start);
+
+                       nes_debug(NES_DBG_MR, "ret=%d\n", ret);
+
+                       if (ret == 0) {
+                               nesmr->ibmr.rkey = stag;
+                               nesmr->ibmr.lkey = stag;
+                               nesmr->mode = IWNES_MEMREG_TYPE_MEM;
+                               ibmr = &nesmr->ibmr;
+                               nesmr->pbl_4k = ((pbl_count > 1) || (cur_pbl_index > 32)) ? 1 : 0;
+                               nesmr->pbls_used = pbl_count;
+                               if (pbl_count > 1) {
+                                       nesmr->pbls_used++;
+                               }
+                       } else {
+                               ib_umem_release(region);
+                               kfree(nesmr);
+                               ibmr = ERR_PTR(-ENOMEM);
+                       }
+
+                       reg_user_mr_err:
+                       /* free the resources */
+                       if (root_pbl_index == 1) {
+                               pci_free_consistent(nesdev->pcidev, 4096, vpbl.pbl_vbase,
+                                               vpbl.pbl_pbase);
+                       } else {
+                               for (page_index=0; page_index<root_pbl_index; page_index++) {
+                                       pci_free_consistent(nesdev->pcidev, 4096,
+                                                       root_vpbl.leaf_vpbl[page_index].pbl_vbase,
+                                                       root_vpbl.leaf_vpbl[page_index].pbl_pbase);
+                               }
+                               kfree(root_vpbl.leaf_vpbl);
+                               pci_free_consistent(nesdev->pcidev, 8192, root_vpbl.pbl_vbase,
+                                               root_vpbl.pbl_pbase);
+                       }
+
+                       nes_debug(NES_DBG_MR, "Leaving, ibmr=%p", ibmr);
+
+                       return ibmr;
+                       break;
+               case IWNES_MEMREG_TYPE_QP:
+               case IWNES_MEMREG_TYPE_CQ:
+                       nespbl = kzalloc(sizeof(*nespbl), GFP_KERNEL);
+                       if (!nespbl) {
+                               nes_debug(NES_DBG_MR, "Unable to allocate PBL\n");
+                               ib_umem_release(region);
+                               return ERR_PTR(-ENOMEM);
+                       }
+                       nesmr = kzalloc(sizeof(*nesmr), GFP_KERNEL);
+                       if (!nesmr) {
+                               ib_umem_release(region);
+                               kfree(nespbl);
+                               nes_debug(NES_DBG_MR, "Unable to allocate nesmr\n");
+                               return ERR_PTR(-ENOMEM);
+                       }
+                       nesmr->region = region;
+                       nes_ucontext = to_nesucontext(pd->uobject->context);
+                       pbl_depth = region->length >> 12;
+                       pbl_depth += (region->length & (4096-1)) ? 1 : 0;
+                       nespbl->pbl_size = pbl_depth*sizeof(u64);
+                       if (req.reg_type == IWNES_MEMREG_TYPE_QP) {
+                               nes_debug(NES_DBG_MR, "Attempting to allocate QP PBL memory");
+                       } else {
+                               nes_debug(NES_DBG_MR, "Attempting to allocate CP PBL memory");
+                       }
+
+                       nes_debug(NES_DBG_MR, " %u bytes, %u entries.\n",
+                                       nespbl->pbl_size, pbl_depth);
+                       pbl = pci_alloc_consistent(nesdev->pcidev, nespbl->pbl_size,
+                                       &nespbl->pbl_pbase);
+                       if (!pbl) {
+                               ib_umem_release(region);
+                               kfree(nesmr);
+                               kfree(nespbl);
+                               nes_debug(NES_DBG_MR, "Unable to allocate PBL memory\n");
+                               return ERR_PTR(-ENOMEM);
+                       }
+
+                       nespbl->pbl_vbase = (u64 *)pbl;
+                       nespbl->user_base = start;
+                       nes_debug(NES_DBG_MR, "Allocated PBL memory, %u bytes, pbl_pbase=%p,"
+                                       " pbl_vbase=%p user_base=0x%lx\n",
+                                       nespbl->pbl_size, (void *)nespbl->pbl_pbase,
+                                       (void*)nespbl->pbl_vbase, nespbl->user_base);
+
+                       list_for_each_entry(chunk, &region->chunk_list, list) {
+                               for (nmap_index = 0; nmap_index < chunk->nmap; ++nmap_index) {
+                                       chunk_pages = sg_dma_len(&chunk->page_list[nmap_index]) >> 12;
+                                       chunk_pages += (sg_dma_len(&chunk->page_list[nmap_index]) & (4096-1)) ? 1 : 0;
+                                       nespbl->page = sg_page(&chunk->page_list[0]);
+                                       for (page_index=0; page_index<chunk_pages; page_index++) {
+                                               ((__le32 *)pbl)[0] = cpu_to_le32((u32)
+                                                               (sg_dma_address(&chunk->page_list[nmap_index])+
+                                                               (page_index*4096)));
+                                               ((__le32 *)pbl)[1] = cpu_to_le32(((u64)
+                                                               (sg_dma_address(&chunk->page_list[nmap_index])+
+                                                               (page_index*4096)))>>32);
+                                               nes_debug(NES_DBG_MR, "pbl=%p, *pbl=0x%016llx, 0x%08x%08x\n", pbl,
+                                                               (unsigned long long)*pbl,
+                                                               le32_to_cpu(((__le32 *)pbl)[1]), le32_to_cpu(((__le32 *)pbl)[0]));
+                                               pbl++;
+                                       }
+                               }
+                       }
+                       if (req.reg_type == IWNES_MEMREG_TYPE_QP) {
+                               list_add_tail(&nespbl->list, &nes_ucontext->qp_reg_mem_list);
+                       } else {
+                               list_add_tail(&nespbl->list, &nes_ucontext->cq_reg_mem_list);
+                       }
+                       nesmr->ibmr.rkey = -1;
+                       nesmr->ibmr.lkey = -1;
+                       nesmr->mode = req.reg_type;
+                       return &nesmr->ibmr;
+                       break;
+       }
+
+       return ERR_PTR(-ENOSYS);
+}
+
+
+/**
+ * nes_dereg_mr
+ */
+static int nes_dereg_mr(struct ib_mr *ib_mr)
+{
+       struct nes_mr *nesmr = to_nesmr(ib_mr);
+       struct nes_vnic *nesvnic = to_nesvnic(ib_mr->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       struct nes_cqp_request *cqp_request;
+       unsigned long flags;
+       int ret;
+       u16 major_code;
+       u16 minor_code;
+
+       if (nesmr->region) {
+               ib_umem_release(nesmr->region);
+       }
+       if (nesmr->mode != IWNES_MEMREG_TYPE_MEM) {
+               kfree(nesmr);
+               return 0;
+       }
+
+       /* Deallocate the region with the adapter */
+
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_MR, "Failed to get a cqp_request.\n");
+               return -ENOMEM;
+       }
+       cqp_request->waiting = 1;
+       cqp_wqe = &cqp_request->cqp_wqe;
+
+       spin_lock_irqsave(&nesadapter->pbl_lock, flags);
+       if (nesmr->pbls_used != 0) {
+               if (nesmr->pbl_4k) {
+                       nesadapter->free_4kpbl += nesmr->pbls_used;
+                       if (nesadapter->free_4kpbl > nesadapter->max_4kpbl) {
+                               printk(KERN_ERR PFX "free 4KB PBLs(%u) has exceeded the max(%u)\n",
+                                               nesadapter->free_4kpbl, nesadapter->max_4kpbl);
+                       }
+               } else {
+                       nesadapter->free_256pbl += nesmr->pbls_used;
+                       if (nesadapter->free_256pbl > nesadapter->max_256pbl) {
+                               printk(KERN_ERR PFX "free 256B PBLs(%u) has exceeded the max(%u)\n",
+                                               nesadapter->free_256pbl, nesadapter->max_256pbl);
+                       }
+               }
+       }
+
+       spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                       NES_CQP_DEALLOCATE_STAG | NES_CQP_STAG_VA_TO |
+                       NES_CQP_STAG_DEALLOC_PBLS | NES_CQP_STAG_MR);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_STAG_IDX, ib_mr->rkey);
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       nes_debug(NES_DBG_MR, "Waiting for deallocate STag 0x%08X completed\n", ib_mr->rkey);
+       ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
+                       NES_EVENT_TIMEOUT);
+       nes_debug(NES_DBG_MR, "Deallocate STag 0x%08X completed, wait_event_timeout ret = %u,"
+                       " CQP Major:Minor codes = 0x%04X:0x%04X\n",
+                       ib_mr->rkey, ret, cqp_request->major_code, cqp_request->minor_code);
+
+       nes_free_resource(nesadapter, nesadapter->allocated_mrs,
+                       (ib_mr->rkey & 0x0fffff00) >> 8);
+
+       kfree(nesmr);
+
+       major_code = cqp_request->major_code;
+       minor_code = cqp_request->minor_code;
+       if (atomic_dec_and_test(&cqp_request->refcount)) {
+               if (cqp_request->dynamic) {
+                       kfree(cqp_request);
+               } else {
+                       spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                       list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                       spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+               }
+       }
+       if (!ret) {
+               nes_debug(NES_DBG_MR, "Timeout waiting to destroy STag,"
+                               " ib_mr=%p, rkey = 0x%08X\n",
+                               ib_mr, ib_mr->rkey);
+               return -ETIME;
+       } else if (major_code) {
+               nes_debug(NES_DBG_MR, "Error (0x%04X:0x%04X) while attempting"
+                               " to destroy STag, ib_mr=%p, rkey = 0x%08X\n",
+                               major_code, minor_code, ib_mr, ib_mr->rkey);
+               return -EIO;
+       } else
+               return 0;
+}
+
+
+/**
+ * show_rev
+ */
+static ssize_t show_rev(struct class_device *cdev, char *buf)
+{
+       struct nes_ib_device *nesibdev =
+                       container_of(cdev, struct nes_ib_device, ibdev.class_dev);
+       struct nes_vnic *nesvnic = nesibdev->nesvnic;
+
+       nes_debug(NES_DBG_INIT, "\n");
+       return sprintf(buf, "%x\n", nesvnic->nesdev->nesadapter->hw_rev);
+}
+
+
+/**
+ * show_fw_ver
+ */
+static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
+{
+       struct nes_ib_device *nesibdev =
+                       container_of(cdev, struct nes_ib_device, ibdev.class_dev);
+       struct nes_vnic *nesvnic = nesibdev->nesvnic;
+
+       nes_debug(NES_DBG_INIT, "\n");
+       return sprintf(buf, "%x.%x.%x\n",
+                       (int)(nesvnic->nesdev->nesadapter->fw_ver >> 32),
+                       (int)(nesvnic->nesdev->nesadapter->fw_ver >> 16) & 0xffff,
+                       (int)(nesvnic->nesdev->nesadapter->fw_ver & 0xffff));
+}
+
+
+/**
+ * show_hca
+ */
+static ssize_t show_hca(struct class_device *cdev, char *buf)
+{
+       nes_debug(NES_DBG_INIT, "\n");
+       return sprintf(buf, "NES020\n");
+}
+
+
+/**
+ * show_board
+ */
+static ssize_t show_board(struct class_device *cdev, char *buf)
+{
+       nes_debug(NES_DBG_INIT, "\n");
+       return sprintf(buf, "%.*s\n", 32, "NES020 Board ID");
+}
+
+
+static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
+static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
+static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
+static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
+
+static struct class_device_attribute *nes_class_attributes[] = {
+       &class_device_attr_hw_rev,
+       &class_device_attr_fw_ver,
+       &class_device_attr_hca_type,
+       &class_device_attr_board_id
+};
+
+
+/**
+ * nes_query_qp
+ */
+static int nes_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
+               int attr_mask, struct ib_qp_init_attr *init_attr)
+{
+       struct nes_qp *nesqp = to_nesqp(ibqp);
+
+       nes_debug(NES_DBG_QP, "\n");
+
+       attr->qp_access_flags = 0;
+       attr->cap.max_send_wr = nesqp->hwqp.sq_size;
+       attr->cap.max_recv_wr = nesqp->hwqp.rq_size;
+       attr->cap.max_recv_sge = 1;
+       if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
+               init_attr->cap.max_inline_data = 0;
+       } else {
+               init_attr->cap.max_inline_data = 64;
+       }
+
+       init_attr->event_handler = nesqp->ibqp.event_handler;
+       init_attr->qp_context = nesqp->ibqp.qp_context;
+       init_attr->send_cq = nesqp->ibqp.send_cq;
+       init_attr->recv_cq = nesqp->ibqp.recv_cq;
+       init_attr->srq = nesqp->ibqp.srq = nesqp->ibqp.srq;
+       init_attr->cap = attr->cap;
+
+       return 0;
+}
+
+
+/**
+ * nes_hw_modify_qp
+ */
+int nes_hw_modify_qp(struct nes_device *nesdev, struct nes_qp *nesqp,
+               u32 next_iwarp_state, u32 wait_completion)
+{
+       struct nes_hw_cqp_wqe *cqp_wqe;
+       /* struct iw_cm_id *cm_id = nesqp->cm_id; */
+       /* struct iw_cm_event cm_event; */
+       struct nes_cqp_request *cqp_request;
+       unsigned long flags;
+       int ret;
+       u16 major_code;
+
+       nes_debug(NES_DBG_MOD_QP, "QP%u, refcount=%d\n",
+                       nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount));
+
+       cqp_request = nes_get_cqp_request(nesdev);
+       if (cqp_request == NULL) {
+               nes_debug(NES_DBG_MOD_QP, "Failed to get a cqp_request.\n");
+               return -ENOMEM;
+       }
+       if (wait_completion) {
+               cqp_request->waiting = 1;
+       } else {
+               cqp_request->waiting = 0;
+       }
+       cqp_wqe = &cqp_request->cqp_wqe;
+
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
+                       NES_CQP_MODIFY_QP | NES_CQP_QP_TYPE_IWARP | next_iwarp_state);
+       nes_debug(NES_DBG_MOD_QP, "using next_iwarp_state=%08x, wqe_words=%08x\n",
+                       next_iwarp_state, le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX]));
+       nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
+       set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
+       set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, (u64)nesqp->nesqp_context_pbase);
+
+       atomic_set(&cqp_request->refcount, 2);
+       nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
+
+       /* Wait for CQP */
+       if (wait_completion) {
+               /* nes_debug(NES_DBG_MOD_QP, "Waiting for modify iWARP QP%u to complete.\n",
+                               nesqp->hwqp.qp_id); */
+               ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
+                               NES_EVENT_TIMEOUT);
+               nes_debug(NES_DBG_MOD_QP, "Modify iwarp QP%u completed, wait_event_timeout ret=%u, "
+                               "CQP Major:Minor codes = 0x%04X:0x%04X.\n",
+                               nesqp->hwqp.qp_id, ret, cqp_request->major_code, cqp_request->minor_code);
+               major_code = cqp_request->major_code;
+               if (major_code) {
+                       nes_debug(NES_DBG_MOD_QP, "Modify iwarp QP%u failed"
+                                       "CQP Major:Minor codes = 0x%04X:0x%04X, intended next state = 0x%08X.\n",
+                                       nesqp->hwqp.qp_id, cqp_request->major_code,
+                                       cqp_request->minor_code, next_iwarp_state);
+               }
+               if (atomic_dec_and_test(&cqp_request->refcount)) {
+                       if (cqp_request->dynamic) {
+                               kfree(cqp_request);
+                       } else {
+                               spin_lock_irqsave(&nesdev->cqp.lock, flags);
+                               list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
+                               spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
+                       }
+               }
+               if (!ret)
+                       return -ETIME;
+               else if (major_code)
+                       return -EIO;
+               else
+                       return 0;
+       } else {
+               return 0;
+       }
+}
+
+
+/**
+ * nes_modify_qp
+ */
+int nes_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
+               int attr_mask, struct ib_udata *udata)
+{
+       struct nes_qp *nesqp = to_nesqp(ibqp);
+       struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       /* u32 cqp_head; */
+       /* u32 counter; */
+       u32 next_iwarp_state = 0;
+       int err;
+       unsigned long qplockflags;
+       int ret;
+       u16 original_last_aeq;
+       u8 issue_modify_qp = 0;
+       u8 issue_disconnect = 0;
+       u8 dont_wait = 0;
+
+       nes_debug(NES_DBG_MOD_QP, "QP%u: QP State=%u, cur QP State=%u,"
+                       " iwarp_state=0x%X, refcount=%d\n",
+                       nesqp->hwqp.qp_id, attr->qp_state, nesqp->ibqp_state,
+                       nesqp->iwarp_state, atomic_read(&nesqp->refcount));
+
+       nes_add_ref(&nesqp->ibqp);
+       spin_lock_irqsave(&nesqp->lock, qplockflags);
+
+       nes_debug(NES_DBG_MOD_QP, "QP%u: hw_iwarp_state=0x%X, hw_tcp_state=0x%X,"
+                       " QP Access Flags=0x%X, attr_mask = 0x%0x\n",
+                       nesqp->hwqp.qp_id, nesqp->hw_iwarp_state,
+                       nesqp->hw_tcp_state, attr->qp_access_flags, attr_mask);
+
+       if (attr_mask & IB_QP_STATE) {
+               switch (attr->qp_state) {
+                       case IB_QPS_INIT:
+                               nes_debug(NES_DBG_MOD_QP, "QP%u: new state = init\n",
+                                               nesqp->hwqp.qp_id);
+                               if (nesqp->iwarp_state > (u32)NES_CQP_QP_IWARP_STATE_IDLE) {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return -EINVAL;
+                               }
+                               next_iwarp_state = NES_CQP_QP_IWARP_STATE_IDLE;
+                               issue_modify_qp = 1;
+                               break;
+                       case IB_QPS_RTR:
+                               nes_debug(NES_DBG_MOD_QP, "QP%u: new state = rtr\n",
+                                               nesqp->hwqp.qp_id);
+                               if (nesqp->iwarp_state>(u32)NES_CQP_QP_IWARP_STATE_IDLE) {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return -EINVAL;
+                               }
+                               next_iwarp_state = NES_CQP_QP_IWARP_STATE_IDLE;
+                               issue_modify_qp = 1;
+                               break;
+                       case IB_QPS_RTS:
+                               nes_debug(NES_DBG_MOD_QP, "QP%u: new state = rts\n",
+                                               nesqp->hwqp.qp_id);
+                               if (nesqp->iwarp_state>(u32)NES_CQP_QP_IWARP_STATE_RTS) {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return -EINVAL;
+                               }
+                               if (nesqp->cm_id == NULL) {
+                                       nes_debug(NES_DBG_MOD_QP, "QP%u: Failing attempt to move QP to RTS without a CM_ID. \n",
+                                                       nesqp->hwqp.qp_id );
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return -EINVAL;
+                               }
+                               next_iwarp_state = NES_CQP_QP_IWARP_STATE_RTS;
+                               if (nesqp->iwarp_state != NES_CQP_QP_IWARP_STATE_RTS)
+                                       next_iwarp_state |= NES_CQP_QP_CONTEXT_VALID |
+                                                       NES_CQP_QP_ARP_VALID | NES_CQP_QP_ORD_VALID;
+                               issue_modify_qp = 1;
+                               nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_ESTABLISHED;
+                               nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_RTS;
+                               nesqp->hte_added = 1;
+                               break;
+                       case IB_QPS_SQD:
+                               issue_modify_qp = 1;
+                               nes_debug(NES_DBG_MOD_QP, "QP%u: new state=closing. SQ head=%u, SQ tail=%u\n",
+                                               nesqp->hwqp.qp_id, nesqp->hwqp.sq_head, nesqp->hwqp.sq_tail);
+                               if (nesqp->iwarp_state == (u32)NES_CQP_QP_IWARP_STATE_CLOSING) {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return 0;
+                               } else {
+                                       if (nesqp->iwarp_state > (u32)NES_CQP_QP_IWARP_STATE_CLOSING) {
+                                               nes_debug(NES_DBG_MOD_QP, "QP%u: State change to closing"
+                                                               " ignored due to current iWARP state\n",
+                                                               nesqp->hwqp.qp_id);
+                                               spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                               nes_rem_ref(&nesqp->ibqp);
+                                               return -EINVAL;
+                                       }
+                                       if (nesqp->hw_iwarp_state != NES_AEQE_IWARP_STATE_RTS) {
+                                               nes_debug(NES_DBG_MOD_QP, "QP%u: State change to closing"
+                                                               " already done based on hw state.\n",
+                                                               nesqp->hwqp.qp_id);
+                                               issue_modify_qp = 0;
+                                               nesqp->in_disconnect = 0;
+                                       }
+                                       switch (nesqp->hw_iwarp_state) {
+                                               case NES_AEQE_IWARP_STATE_CLOSING:
+                                                       next_iwarp_state = NES_CQP_QP_IWARP_STATE_CLOSING;
+                                               case NES_AEQE_IWARP_STATE_TERMINATE:
+                                                       next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE;
+                                                       break;
+                                               case NES_AEQE_IWARP_STATE_ERROR:
+                                                       next_iwarp_state = NES_CQP_QP_IWARP_STATE_ERROR;
+                                                       break;
+                                               default:
+                                                       next_iwarp_state = NES_CQP_QP_IWARP_STATE_CLOSING;
+                                                       nesqp->in_disconnect = 1;
+                                                       nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_CLOSING;
+                                                       break;
+                                       }
+                               }
+                               break;
+                       case IB_QPS_SQE:
+                               nes_debug(NES_DBG_MOD_QP, "QP%u: new state = terminate\n",
+                                               nesqp->hwqp.qp_id);
+                               if (nesqp->iwarp_state>=(u32)NES_CQP_QP_IWARP_STATE_TERMINATE) {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return -EINVAL;
+                               }
+                               /* next_iwarp_state = (NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000); */
+                               next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE;
+                               nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_TERMINATE;
+                               issue_modify_qp = 1;
+                               nesqp->in_disconnect = 1;
+                               break;
+                       case IB_QPS_ERR:
+                       case IB_QPS_RESET:
+                               if (nesqp->iwarp_state == (u32)NES_CQP_QP_IWARP_STATE_ERROR) {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_rem_ref(&nesqp->ibqp);
+                                       return -EINVAL;
+                               }
+                               nes_debug(NES_DBG_MOD_QP, "QP%u: new state = error\n",
+                                               nesqp->hwqp.qp_id);
+                               next_iwarp_state = NES_CQP_QP_IWARP_STATE_ERROR;
+                               /* next_iwarp_state = (NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000); */
+                                       if (nesqp->hte_added) {
+                                               nes_debug(NES_DBG_MOD_QP, "set CQP_QP_DEL_HTE\n");
+                                               next_iwarp_state |= NES_CQP_QP_DEL_HTE;
+                                               nesqp->hte_added = 0;
+                                       }
+                               if ((nesqp->hw_tcp_state > NES_AEQE_TCP_STATE_CLOSED) &&
+                                               (nesqp->hw_tcp_state != NES_AEQE_TCP_STATE_TIME_WAIT)) {
+                                       next_iwarp_state |= NES_CQP_QP_RESET;
+                                       nesqp->in_disconnect = 1;
+                               } else {
+                                       nes_debug(NES_DBG_MOD_QP, "QP%u NOT setting NES_CQP_QP_RESET since TCP state = %u\n",
+                                                       nesqp->hwqp.qp_id, nesqp->hw_tcp_state);
+                                       dont_wait = 1;
+                               }
+                               issue_modify_qp = 1;
+                               nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_ERROR;
+                               break;
+                       default:
+                               spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                               nes_rem_ref(&nesqp->ibqp);
+                               return -EINVAL;
+                               break;
+               }
+
+               nesqp->ibqp_state = attr->qp_state;
+               if (((nesqp->iwarp_state & NES_CQP_QP_IWARP_STATE_MASK) ==
+                               (u32)NES_CQP_QP_IWARP_STATE_RTS) &&
+                               ((next_iwarp_state & NES_CQP_QP_IWARP_STATE_MASK) >
+                               (u32)NES_CQP_QP_IWARP_STATE_RTS)) {
+                       nesqp->iwarp_state = next_iwarp_state & NES_CQP_QP_IWARP_STATE_MASK;
+                       nes_debug(NES_DBG_MOD_QP, "Change nesqp->iwarp_state=%08x\n",
+                                       nesqp->iwarp_state);
+                       issue_disconnect = 1;
+               } else {
+                       nesqp->iwarp_state = next_iwarp_state & NES_CQP_QP_IWARP_STATE_MASK;
+                       nes_debug(NES_DBG_MOD_QP, "Change nesqp->iwarp_state=%08x\n",
+                                       nesqp->iwarp_state);
+               }
+       }
+
+       if (attr_mask & IB_QP_ACCESS_FLAGS) {
+               if (attr->qp_access_flags & IB_ACCESS_LOCAL_WRITE) {
+                       nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_WRITE_EN |
+                                       NES_QPCONTEXT_MISC_RDMA_READ_EN);
+                       issue_modify_qp = 1;
+               }
+               if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE) {
+                       nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_WRITE_EN);
+                       issue_modify_qp = 1;
+               }
+               if (attr->qp_access_flags & IB_ACCESS_REMOTE_READ) {
+                       nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_READ_EN);
+                       issue_modify_qp = 1;
+               }
+               if (attr->qp_access_flags & IB_ACCESS_MW_BIND) {
+                       nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_WBIND_EN);
+                       issue_modify_qp = 1;
+               }
+
+               if (nesqp->user_mode) {
+                       nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_WRITE_EN |
+                                       NES_QPCONTEXT_MISC_RDMA_READ_EN);
+                       issue_modify_qp = 1;
+               }
+       }
+
+       original_last_aeq = nesqp->last_aeq;
+       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+
+       nes_debug(NES_DBG_MOD_QP, "issue_modify_qp=%u\n", issue_modify_qp);
+
+       ret = 0;
+
+
+       if (issue_modify_qp) {
+               nes_debug(NES_DBG_MOD_QP, "call nes_hw_modify_qp\n");
+               ret = nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 1);
+               if (ret)
+                       nes_debug(NES_DBG_MOD_QP, "nes_hw_modify_qp (next_iwarp_state = 0x%08X)"
+                                       " failed for QP%u.\n",
+                                       next_iwarp_state, nesqp->hwqp.qp_id);
+
+       }
+
+       if ((issue_modify_qp) && (nesqp->ibqp_state > IB_QPS_RTS)) {
+               nes_debug(NES_DBG_MOD_QP, "QP%u Issued ModifyQP refcount (%d),"
+                               " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
+                               nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
+                               original_last_aeq, nesqp->last_aeq);
+               if ((!ret) ||
+                               ((original_last_aeq != NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) &&
+                               (ret))) {
+                       if (dont_wait) {
+                               if (nesqp->cm_id && nesqp->hw_tcp_state != 0) {
+                                       nes_debug(NES_DBG_MOD_QP, "QP%u Queuing fake disconnect for QP refcount (%d),"
+                                                       " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
+                                                       nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
+                                                       original_last_aeq, nesqp->last_aeq);
+                                       /* this one is for the cm_disconnect thread */
+                                       nes_add_ref(&nesqp->ibqp);
+                                       spin_lock_irqsave(&nesqp->lock, qplockflags);
+                                       nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
+                                       nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_cm_disconn(nesqp);
+                               } else {
+                                       nes_debug(NES_DBG_MOD_QP, "QP%u No fake disconnect, QP refcount=%d\n",
+                                                       nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount));
+                                       nes_rem_ref(&nesqp->ibqp);
+                               }
+                       } else {
+                               spin_lock_irqsave(&nesqp->lock, qplockflags);
+                               if (nesqp->cm_id) {
+                                       /* These two are for the timer thread */
+                                       if (atomic_inc_return(&nesqp->close_timer_started) == 1) {
+                                               nes_add_ref(&nesqp->ibqp);
+                                               nesqp->cm_id->add_ref(nesqp->cm_id);
+                                               nes_debug(NES_DBG_MOD_QP, "QP%u Not decrementing QP refcount (%d),"
+                                                               " need ae to finish up, original_last_aeq = 0x%04X."
+                                                               " last_aeq = 0x%04X, scheduling timer.\n",
+                                                               nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
+                                                               original_last_aeq, nesqp->last_aeq);
+                                               schedule_nes_timer(nesqp->cm_node, (struct sk_buff *) nesqp, NES_TIMER_TYPE_CLOSE, 1, 0);
+                                       }
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                               } else {
+                                       spin_unlock_irqrestore(&nesqp->lock, qplockflags);
+                                       nes_debug(NES_DBG_MOD_QP, "QP%u Not decrementing QP refcount (%d),"
+                                                       " need ae to finish up, original_last_aeq = 0x%04X."
+                                                       " last_aeq = 0x%04X.\n",
+                                                       nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
+                                                       original_last_aeq, nesqp->last_aeq);
+                               }
+                       }
+               } else {
+                       nes_debug(NES_DBG_MOD_QP, "QP%u Decrementing QP refcount (%d), No ae to finish up,"
+                                       " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
+                                       nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
+                                       original_last_aeq, nesqp->last_aeq);
+                       nes_rem_ref(&nesqp->ibqp);
+               }
+       } else {
+               nes_debug(NES_DBG_MOD_QP, "QP%u Decrementing QP refcount (%d), No ae to finish up,"
+                               " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
+                               nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
+                               original_last_aeq, nesqp->last_aeq);
+               nes_rem_ref(&nesqp->ibqp);
+       }
+
+       err = 0;
+
+       nes_debug(NES_DBG_MOD_QP, "QP%u Leaving, refcount=%d\n",
+                       nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount));
+
+       return err;
+}
+
+
+/**
+ * nes_muticast_attach
+ */
+static int nes_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
+{
+       nes_debug(NES_DBG_INIT, "\n");
+       return -ENOSYS;
+}
+
+
+/**
+ * nes_multicast_detach
+ */
+static int nes_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
+{
+       nes_debug(NES_DBG_INIT, "\n");
+       return -ENOSYS;
+}
+
+
+/**
+ * nes_process_mad
+ */
+static int nes_process_mad(struct ib_device *ibdev, int mad_flags,
+               u8 port_num, struct ib_wc *in_wc, struct ib_grh *in_grh,
+               struct ib_mad *in_mad, struct ib_mad *out_mad)
+{
+       nes_debug(NES_DBG_INIT, "\n");
+       return -ENOSYS;
+}
+
+static inline void
+fill_wqe_sg_send(struct nes_hw_qp_wqe *wqe, struct ib_send_wr *ib_wr, u32 uselkey)
+{
+       int sge_index;
+       int total_payload_length = 0;
+       for (sge_index = 0; sge_index < ib_wr->num_sge; sge_index++) {
+               set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_FRAG0_LOW_IDX+(sge_index*4),
+                       ib_wr->sg_list[sge_index].addr);
+               set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_LENGTH0_IDX + (sge_index*4),
+                       ib_wr->sg_list[sge_index].length);
+               if (uselkey)
+                       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_STAG0_IDX + (sge_index*4),
+                                               (ib_wr->sg_list[sge_index].lkey));
+               else
+                       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_STAG0_IDX + (sge_index*4), 0);
+
+               total_payload_length += ib_wr->sg_list[sge_index].length;
+       }
+       nes_debug(NES_DBG_IW_TX, "UC UC UC, sending total_payload_length=%u \n",
+                       total_payload_length);
+       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX,
+                               total_payload_length);
+}
+
+/**
+ * nes_post_send
+ */
+static int nes_post_send(struct ib_qp *ibqp, struct ib_send_wr *ib_wr,
+               struct ib_send_wr **bad_wr)
+{
+       u64 u64temp;
+       unsigned long flags = 0;
+       struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_qp *nesqp = to_nesqp(ibqp);
+       struct nes_hw_qp_wqe *wqe;
+       int err;
+       u32 qsize = nesqp->hwqp.sq_size;
+       u32 head;
+       u32 wqe_misc;
+       u32 wqe_count;
+       u32 counter;
+       u32 total_payload_length;
+
+       err = 0;
+       wqe_misc = 0;
+       wqe_count = 0;
+       total_payload_length = 0;
+
+       if (nesqp->ibqp_state > IB_QPS_RTS)
+               return -EINVAL;
+
+               spin_lock_irqsave(&nesqp->lock, flags);
+
+       head = nesqp->hwqp.sq_head;
+
+       while (ib_wr) {
+               /* Check for SQ overflow */
+               if (((head + (2 * qsize) - nesqp->hwqp.sq_tail) % qsize) == (qsize - 1)) {
+                       err = -EINVAL;
+                       break;
+               }
+
+               wqe = &nesqp->hwqp.sq_vbase[head];
+               /* nes_debug(NES_DBG_IW_TX, "processing sq wqe for QP%u at %p, head = %u.\n",
+                               nesqp->hwqp.qp_id, wqe, head); */
+               nes_fill_init_qp_wqe(wqe, nesqp, head);
+               u64temp = (u64)(ib_wr->wr_id);
+               set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX,
+                                       u64temp);
+                       switch (ib_wr->opcode) {
+                               case IB_WR_SEND:
+                                       if (ib_wr->send_flags & IB_SEND_SOLICITED) {
+                                               wqe_misc = NES_IWARP_SQ_OP_SENDSE;
+                                       } else {
+                                               wqe_misc = NES_IWARP_SQ_OP_SEND;
+                                       }
+                                       if (ib_wr->num_sge > nesdev->nesadapter->max_sge) {
+                                               err = -EINVAL;
+                                               break;
+                                       }
+                                       if (ib_wr->send_flags & IB_SEND_FENCE) {
+                                               wqe_misc |= NES_IWARP_SQ_WQE_LOCAL_FENCE;
+                                       }
+                                       if ((ib_wr->send_flags & IB_SEND_INLINE) &&
+                                                       ((nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) == 0) &&
+                                                       (ib_wr->sg_list[0].length <= 64)) {
+                                               memcpy(&wqe->wqe_words[NES_IWARP_SQ_WQE_IMM_DATA_START_IDX],
+                                                              (void *)(unsigned long)ib_wr->sg_list[0].addr, ib_wr->sg_list[0].length);
+                                               set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX,
+                                                               ib_wr->sg_list[0].length);
+                                               wqe_misc |= NES_IWARP_SQ_WQE_IMM_DATA;
+                                       } else {
+                                               fill_wqe_sg_send(wqe, ib_wr, 1);
+                                       }
+
+                                       break;
+                               case IB_WR_RDMA_WRITE:
+                                       wqe_misc = NES_IWARP_SQ_OP_RDMAW;
+                                       if (ib_wr->num_sge > nesdev->nesadapter->max_sge) {
+                                               nes_debug(NES_DBG_IW_TX, "Exceeded max sge, ib_wr=%u, max=%u\n",
+                                                               ib_wr->num_sge,
+                                                               nesdev->nesadapter->max_sge);
+                                               err = -EINVAL;
+                                               break;
+                                       }
+                                       if (ib_wr->send_flags & IB_SEND_FENCE) {
+                                               wqe_misc |= NES_IWARP_SQ_WQE_LOCAL_FENCE;
+                                       }
+
+                                       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_RDMA_STAG_IDX,
+                                                       ib_wr->wr.rdma.rkey);
+                                       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX,
+                                                       ib_wr->wr.rdma.remote_addr);
+
+                                       if ((ib_wr->send_flags & IB_SEND_INLINE) &&
+                                                       ((nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) == 0) &&
+                                                       (ib_wr->sg_list[0].length <= 64)) {
+                                               memcpy(&wqe->wqe_words[NES_IWARP_SQ_WQE_IMM_DATA_START_IDX],
+                                                              (void *)(unsigned long)ib_wr->sg_list[0].addr, ib_wr->sg_list[0].length);
+                                               set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX,
+                                                               ib_wr->sg_list[0].length);
+                                               wqe_misc |= NES_IWARP_SQ_WQE_IMM_DATA;
+                                       } else {
+                                               fill_wqe_sg_send(wqe, ib_wr, 1);
+                                       }
+                                       wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX] =
+                                                       wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX];
+                                       break;
+                               case IB_WR_RDMA_READ:
+                                       /* iWARP only supports 1 sge for RDMA reads */
+                                       if (ib_wr->num_sge > 1) {
+                                               nes_debug(NES_DBG_IW_TX, "Exceeded max sge, ib_wr=%u, max=1\n",
+                                                               ib_wr->num_sge);
+                                               err = -EINVAL;
+                                               break;
+                                       }
+                                       wqe_misc = NES_IWARP_SQ_OP_RDMAR;
+                                       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX,
+                                                       ib_wr->wr.rdma.remote_addr);
+                                       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_RDMA_STAG_IDX,
+                                                       ib_wr->wr.rdma.rkey);
+                                       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX,
+                                                       ib_wr->sg_list->length);
+                                       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_FRAG0_LOW_IDX,
+                                                       ib_wr->sg_list->addr);
+                                       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_STAG0_IDX,
+                                                       ib_wr->sg_list->lkey);
+                                       break;
+                               default:
+                                       /* error */
+                                       err = -EINVAL;
+                                       break;
+                       }
+
+               if (ib_wr->send_flags & IB_SEND_SIGNALED) {
+                       wqe_misc |= NES_IWARP_SQ_WQE_SIGNALED_COMPL;
+               }
+               wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] = cpu_to_le32(wqe_misc);
+
+               ib_wr = ib_wr->next;
+               head++;
+               wqe_count++;
+               if (head >= qsize)
+                       head = 0;
+
+       }
+
+       nesqp->hwqp.sq_head = head;
+       barrier();
+       while (wqe_count) {
+               counter = min(wqe_count, ((u32)255));
+               wqe_count -= counter;
+               nes_write32(nesdev->regs + NES_WQE_ALLOC,
+                               (counter << 24) | 0x00800000 | nesqp->hwqp.qp_id);
+       }
+
+               spin_unlock_irqrestore(&nesqp->lock, flags);
+
+       if (err)
+               *bad_wr = ib_wr;
+       return err;
+}
+
+
+/**
+ * nes_post_recv
+ */
+static int nes_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *ib_wr,
+               struct ib_recv_wr **bad_wr)
+{
+       u64 u64temp;
+       unsigned long flags = 0;
+       struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_qp *nesqp = to_nesqp(ibqp);
+       struct nes_hw_qp_wqe *wqe;
+       int err = 0;
+       int sge_index;
+       u32 qsize = nesqp->hwqp.rq_size;
+       u32 head;
+       u32 wqe_count = 0;
+       u32 counter;
+       u32 total_payload_length;
+
+       if (nesqp->ibqp_state > IB_QPS_RTS)
+               return -EINVAL;
+
+               spin_lock_irqsave(&nesqp->lock, flags);
+
+       head = nesqp->hwqp.rq_head;
+
+       while (ib_wr) {
+               if (ib_wr->num_sge > nesdev->nesadapter->max_sge) {
+                       err = -EINVAL;
+                       break;
+               }
+               /* Check for RQ overflow */
+               if (((head + (2 * qsize) - nesqp->hwqp.rq_tail) % qsize) == (qsize - 1)) {
+                       err = -EINVAL;
+                       break;
+               }
+
+               nes_debug(NES_DBG_IW_RX, "ibwr sge count = %u.\n", ib_wr->num_sge);
+               wqe = &nesqp->hwqp.rq_vbase[head];
+
+               /* nes_debug(NES_DBG_IW_RX, "QP%u:processing rq wqe at %p, head = %u.\n",
+                               nesqp->hwqp.qp_id, wqe, head); */
+               nes_fill_init_qp_wqe(wqe, nesqp, head);
+               u64temp = (u64)(ib_wr->wr_id);
+               set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX,
+                                       u64temp);
+               total_payload_length = 0;
+               for (sge_index=0; sge_index < ib_wr->num_sge; sge_index++) {
+                       set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_RQ_WQE_FRAG0_LOW_IDX+(sge_index*4),
+                                       ib_wr->sg_list[sge_index].addr);
+                       set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_RQ_WQE_LENGTH0_IDX+(sge_index*4),
+                                       ib_wr->sg_list[sge_index].length);
+                       set_wqe_32bit_value(wqe->wqe_words,NES_IWARP_RQ_WQE_STAG0_IDX+(sge_index*4),
+                                       ib_wr->sg_list[sge_index].lkey);
+
+                       total_payload_length += ib_wr->sg_list[sge_index].length;
+               }
+               set_wqe_32bit_value(wqe->wqe_words, NES_IWARP_RQ_WQE_TOTAL_PAYLOAD_IDX,
+                                       total_payload_length);
+
+               ib_wr = ib_wr->next;
+               head++;
+               wqe_count++;
+               if (head >= qsize)
+                       head = 0;
+       }
+
+       nesqp->hwqp.rq_head = head;
+       barrier();
+       while (wqe_count) {
+               counter = min(wqe_count, ((u32)255));
+               wqe_count -= counter;
+               nes_write32(nesdev->regs+NES_WQE_ALLOC, (counter<<24) | nesqp->hwqp.qp_id);
+       }
+
+               spin_unlock_irqrestore(&nesqp->lock, flags);
+
+       if (err)
+               *bad_wr = ib_wr;
+       return err;
+}
+
+
+/**
+ * nes_poll_cq
+ */
+static int nes_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
+{
+       u64 u64temp;
+       u64 wrid;
+       /* u64 u64temp; */
+       unsigned long flags = 0;
+       struct nes_vnic *nesvnic = to_nesvnic(ibcq->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_cq *nescq = to_nescq(ibcq);
+       struct nes_qp *nesqp;
+       struct nes_hw_cqe cqe;
+       u32 head;
+       u32 wq_tail;
+       u32 cq_size;
+       u32 cqe_count = 0;
+       u32 wqe_index;
+       u32 u32temp;
+       /* u32 counter; */
+
+       nes_debug(NES_DBG_CQ, "\n");
+
+               spin_lock_irqsave(&nescq->lock, flags);
+
+       head = nescq->hw_cq.cq_head;
+       cq_size = nescq->hw_cq.cq_size;
+
+       while (cqe_count < num_entries) {
+               if (le32_to_cpu(nescq->hw_cq.cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]) &
+                               NES_CQE_VALID) {
+                       cqe = nescq->hw_cq.cq_vbase[head];
+                       nescq->hw_cq.cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX] = 0;
+                       u32temp = le32_to_cpu(cqe.cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX]);
+                       wqe_index = u32temp &
+                                       (nesdev->nesadapter->max_qp_wr - 1);
+                       u32temp &= ~(NES_SW_CONTEXT_ALIGN-1);
+                       /* parse CQE, get completion context from WQE (either rq or sq */
+                       u64temp = (((u64)(le32_to_cpu(cqe.cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX])))<<32) |
+                                       ((u64)u32temp);
+                       nesqp = *((struct nes_qp **)&u64temp);
+                       memset(entry, 0, sizeof *entry);
+                       if (cqe.cqe_words[NES_CQE_ERROR_CODE_IDX] == 0) {
+                               entry->status = IB_WC_SUCCESS;
+                       } else {
+                               entry->status = IB_WC_WR_FLUSH_ERR;
+                       }
+
+                       entry->qp = &nesqp->ibqp;
+                       entry->src_qp = nesqp->hwqp.qp_id;
+
+                       if (le32_to_cpu(cqe.cqe_words[NES_CQE_OPCODE_IDX]) & NES_CQE_SQ) {
+                               if (nesqp->skip_lsmm) {
+                                       nesqp->skip_lsmm = 0;
+                                       wq_tail = nesqp->hwqp.sq_tail++;
+                               }
+
+                               /* Working on a SQ Completion*/
+                               wq_tail = wqe_index;
+                               nesqp->hwqp.sq_tail = (wqe_index+1)&(nesqp->hwqp.sq_size - 1);
+                               wrid = (((u64)(cpu_to_le32((u32)nesqp->hwqp.sq_vbase[wq_tail].
+                                               wqe_words[NES_IWARP_SQ_WQE_COMP_SCRATCH_HIGH_IDX]))) << 32) |
+                                               ((u64)(cpu_to_le32((u32)nesqp->hwqp.sq_vbase[wq_tail].
+                                               wqe_words[NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX])));
+                               entry->byte_len = le32_to_cpu(nesqp->hwqp.sq_vbase[wq_tail].
+                                               wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX]);
+
+                               switch (le32_to_cpu(nesqp->hwqp.sq_vbase[wq_tail].
+                                               wqe_words[NES_IWARP_SQ_WQE_MISC_IDX]) & 0x3f) {
+                                       case NES_IWARP_SQ_OP_RDMAW:
+                                               nes_debug(NES_DBG_CQ, "Operation = RDMA WRITE.\n");
+                                               entry->opcode = IB_WC_RDMA_WRITE;
+                                               break;
+                                       case NES_IWARP_SQ_OP_RDMAR:
+                                               nes_debug(NES_DBG_CQ, "Operation = RDMA READ.\n");
+                                               entry->opcode = IB_WC_RDMA_READ;
+                                               entry->byte_len = le32_to_cpu(nesqp->hwqp.sq_vbase[wq_tail].
+                                                               wqe_words[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX]);
+                                               break;
+                                       case NES_IWARP_SQ_OP_SENDINV:
+                                       case NES_IWARP_SQ_OP_SENDSEINV:
+                                       case NES_IWARP_SQ_OP_SEND:
+                                       case NES_IWARP_SQ_OP_SENDSE:
+                                               nes_debug(NES_DBG_CQ, "Operation = Send.\n");
+                                               entry->opcode = IB_WC_SEND;
+                                               break;
+                               }
+                       } else {
+                               /* Working on a RQ Completion*/
+                               wq_tail = wqe_index;
+                                       nesqp->hwqp.rq_tail = (wqe_index+1)&(nesqp->hwqp.rq_size - 1);
+                               entry->byte_len = le32_to_cpu(cqe.cqe_words[NES_CQE_PAYLOAD_LENGTH_IDX]);
+                               wrid = ((u64)(le32_to_cpu(nesqp->hwqp.rq_vbase[wq_tail].wqe_words[NES_IWARP_RQ_WQE_COMP_SCRATCH_LOW_IDX]))) |
+                                       ((u64)(le32_to_cpu(nesqp->hwqp.rq_vbase[wq_tail].wqe_words[NES_IWARP_RQ_WQE_COMP_SCRATCH_HIGH_IDX]))<<32);
+                                       entry->opcode = IB_WC_RECV;
+                       }
+                       entry->wr_id = wrid;
+
+                       if (++head >= cq_size)
+                               head = 0;
+                       cqe_count++;
+                       nescq->polled_completions++;
+                       if ((nescq->polled_completions > (cq_size / 2)) ||
+                                       (nescq->polled_completions == 255)) {
+                               nes_debug(NES_DBG_CQ, "CQ%u Issuing CQE Allocate since more than half of cqes"
+                                               " are pending %u of %u.\n",
+                                               nescq->hw_cq.cq_number, nescq->polled_completions, cq_size);
+                               nes_write32(nesdev->regs+NES_CQE_ALLOC,
+                                               nescq->hw_cq.cq_number | (nescq->polled_completions << 16));
+                               nescq->polled_completions = 0;
+                       }
+                       entry++;
+               } else
+                       break;
+       }
+
+       if (nescq->polled_completions) {
+               nes_write32(nesdev->regs+NES_CQE_ALLOC,
+                               nescq->hw_cq.cq_number | (nescq->polled_completions << 16));
+               nescq->polled_completions = 0;
+       }
+
+       nescq->hw_cq.cq_head = head;
+       nes_debug(NES_DBG_CQ, "Reporting %u completions for CQ%u.\n",
+                       cqe_count, nescq->hw_cq.cq_number);
+
+               spin_unlock_irqrestore(&nescq->lock, flags);
+
+       return cqe_count;
+}
+
+
+/**
+ * nes_req_notify_cq
+ */
+static int nes_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags)
+               {
+       struct nes_vnic *nesvnic = to_nesvnic(ibcq->device);
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_cq *nescq = to_nescq(ibcq);
+       u32 cq_arm;
+
+       nes_debug(NES_DBG_CQ, "Requesting notification for CQ%u.\n",
+                       nescq->hw_cq.cq_number);
+
+       cq_arm = nescq->hw_cq.cq_number;
+       if ((notify_flags & IB_CQ_SOLICITED_MASK) == IB_CQ_NEXT_COMP)
+               cq_arm |= NES_CQE_ALLOC_NOTIFY_NEXT;
+       else if ((notify_flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED)
+               cq_arm |= NES_CQE_ALLOC_NOTIFY_SE;
+       else
+               return -EINVAL;
+
+       nes_write32(nesdev->regs+NES_CQE_ALLOC, cq_arm);
+       nes_read32(nesdev->regs+NES_CQE_ALLOC);
+
+       return 0;
+}
+
+
+/**
+ * nes_init_ofa_device
+ */
+struct nes_ib_device *nes_init_ofa_device(struct net_device *netdev)
+{
+       struct nes_ib_device *nesibdev;
+       struct nes_vnic *nesvnic = netdev_priv(netdev);
+       struct nes_device *nesdev = nesvnic->nesdev;
+
+       nesibdev = (struct nes_ib_device *)ib_alloc_device(sizeof(struct nes_ib_device));
+       if (nesibdev == NULL) {
+               return NULL;
+       }
+       strlcpy(nesibdev->ibdev.name, "nes%d", IB_DEVICE_NAME_MAX);
+       nesibdev->ibdev.owner = THIS_MODULE;
+
+       nesibdev->ibdev.node_type = RDMA_NODE_RNIC;
+       memset(&nesibdev->ibdev.node_guid, 0, sizeof(nesibdev->ibdev.node_guid));
+       memcpy(&nesibdev->ibdev.node_guid, netdev->dev_addr, 6);
+
+       nesibdev->ibdev.uverbs_cmd_mask =
+                       (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
+                       (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
+                       (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
+                       (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
+                       (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
+                       (1ull << IB_USER_VERBS_CMD_REG_MR) |
+                       (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
+                       (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
+                       (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
+                       (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
+                       (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
+                       (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
+                       (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
+                       (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
+                       (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
+                       (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
+                       (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
+                       (1ull << IB_USER_VERBS_CMD_ALLOC_MW) |
+                       (1ull << IB_USER_VERBS_CMD_BIND_MW) |
+                       (1ull << IB_USER_VERBS_CMD_DEALLOC_MW) |
+                       (1ull << IB_USER_VERBS_CMD_POST_RECV) |
+                       (1ull << IB_USER_VERBS_CMD_POST_SEND);
+
+       nesibdev->ibdev.phys_port_cnt = 1;
+       nesibdev->ibdev.num_comp_vectors = 1;
+       nesibdev->ibdev.dma_device = &nesdev->pcidev->dev;
+       nesibdev->ibdev.class_dev.dev = &nesdev->pcidev->dev;
+       nesibdev->ibdev.query_device = nes_query_device;
+       nesibdev->ibdev.query_port = nes_query_port;
+       nesibdev->ibdev.modify_port = nes_modify_port;
+       nesibdev->ibdev.query_pkey = nes_query_pkey;
+       nesibdev->ibdev.query_gid = nes_query_gid;
+       nesibdev->ibdev.alloc_ucontext = nes_alloc_ucontext;
+       nesibdev->ibdev.dealloc_ucontext = nes_dealloc_ucontext;
+       nesibdev->ibdev.mmap = nes_mmap;
+       nesibdev->ibdev.alloc_pd = nes_alloc_pd;
+       nesibdev->ibdev.dealloc_pd = nes_dealloc_pd;
+       nesibdev->ibdev.create_ah = nes_create_ah;
+       nesibdev->ibdev.destroy_ah = nes_destroy_ah;
+       nesibdev->ibdev.create_qp = nes_create_qp;
+       nesibdev->ibdev.modify_qp = nes_modify_qp;
+       nesibdev->ibdev.query_qp = nes_query_qp;
+       nesibdev->ibdev.destroy_qp = nes_destroy_qp;
+       nesibdev->ibdev.create_cq = nes_create_cq;
+       nesibdev->ibdev.destroy_cq = nes_destroy_cq;
+       nesibdev->ibdev.poll_cq = nes_poll_cq;
+       nesibdev->ibdev.get_dma_mr = nes_get_dma_mr;
+       nesibdev->ibdev.reg_phys_mr = nes_reg_phys_mr;
+       nesibdev->ibdev.reg_user_mr = nes_reg_user_mr;
+       nesibdev->ibdev.dereg_mr = nes_dereg_mr;
+       nesibdev->ibdev.alloc_mw = nes_alloc_mw;
+       nesibdev->ibdev.dealloc_mw = nes_dealloc_mw;
+       nesibdev->ibdev.bind_mw = nes_bind_mw;
+
+       nesibdev->ibdev.alloc_fmr = nes_alloc_fmr;
+       nesibdev->ibdev.unmap_fmr = nes_unmap_fmr;
+       nesibdev->ibdev.dealloc_fmr = nes_dealloc_fmr;
+       nesibdev->ibdev.map_phys_fmr = nes_map_phys_fmr;
+
+       nesibdev->ibdev.attach_mcast = nes_multicast_attach;
+       nesibdev->ibdev.detach_mcast = nes_multicast_detach;
+       nesibdev->ibdev.process_mad = nes_process_mad;
+
+       nesibdev->ibdev.req_notify_cq = nes_req_notify_cq;
+       nesibdev->ibdev.post_send = nes_post_send;
+       nesibdev->ibdev.post_recv = nes_post_recv;
+
+       nesibdev->ibdev.iwcm = kzalloc(sizeof(*nesibdev->ibdev.iwcm), GFP_KERNEL);
+       if (nesibdev->ibdev.iwcm == NULL) {
+               ib_dealloc_device(&nesibdev->ibdev);
+               return NULL;
+       }
+       nesibdev->ibdev.iwcm->add_ref = nes_add_ref;
+       nesibdev->ibdev.iwcm->rem_ref = nes_rem_ref;
+       nesibdev->ibdev.iwcm->get_qp = nes_get_qp;
+       nesibdev->ibdev.iwcm->connect = nes_connect;
+       nesibdev->ibdev.iwcm->accept = nes_accept;
+       nesibdev->ibdev.iwcm->reject = nes_reject;
+       nesibdev->ibdev.iwcm->create_listen = nes_create_listen;
+       nesibdev->ibdev.iwcm->destroy_listen = nes_destroy_listen;
+
+       return nesibdev;
+}
+
+
+/**
+ * nes_destroy_ofa_device
+ */
+void nes_destroy_ofa_device(struct nes_ib_device *nesibdev)
+{
+       if (nesibdev == NULL)
+               return;
+
+       nes_unregister_ofa_device(nesibdev);
+
+       kfree(nesibdev->ibdev.iwcm);
+       ib_dealloc_device(&nesibdev->ibdev);
+}
+
+
+/**
+ * nes_register_ofa_device
+ */
+int nes_register_ofa_device(struct nes_ib_device *nesibdev)
+{
+       struct nes_vnic *nesvnic = nesibdev->nesvnic;
+       struct nes_device *nesdev = nesvnic->nesdev;
+       struct nes_adapter *nesadapter = nesdev->nesadapter;
+       int i, ret;
+
+       ret = ib_register_device(&nesvnic->nesibdev->ibdev);
+       if (ret) {
+               return ret;
+       }
+
+       /* Get the resources allocated to this device */
+       nesibdev->max_cq = (nesadapter->max_cq-NES_FIRST_QPN) / nesadapter->port_count;
+       nesibdev->max_mr = nesadapter->max_mr / nesadapter->port_count;
+       nesibdev->max_qp = (nesadapter->max_qp-NES_FIRST_QPN) / nesadapter->port_count;
+       nesibdev->max_pd = nesadapter->max_pd / nesadapter->port_count;
+
+       for (i = 0; i < ARRAY_SIZE(nes_class_attributes); ++i) {
+               ret = class_device_create_file(&nesibdev->ibdev.class_dev, nes_class_attributes[i]);
+               if (ret) {
+                       while (i > 0) {
+                               i--;
+                               class_device_remove_file(&nesibdev->ibdev.class_dev,
+                                               nes_class_attributes[i]);
+                       }
+                       ib_unregister_device(&nesibdev->ibdev);
+                       return ret;
+               }
+       }
+
+       nesvnic->of_device_registered = 1;
+
+       return 0;
+}
+
+
+/**
+ * nes_unregister_ofa_device
+ */
+void nes_unregister_ofa_device(struct nes_ib_device *nesibdev)
+{
+       struct nes_vnic *nesvnic = nesibdev->nesvnic;
+       int i;
+
+       if (nesibdev == NULL)
+               return;
+
+       for (i = 0; i < ARRAY_SIZE(nes_class_attributes); ++i) {
+               class_device_remove_file(&nesibdev->ibdev.class_dev, nes_class_attributes[i]);
+       }
+
+       if (nesvnic->of_device_registered) {
+               ib_unregister_device(&nesibdev->ibdev);
+       }
+
+       nesvnic->of_device_registered = 0;
+}
diff --git a/drivers/infiniband/hw/nes/nes_verbs.h b/drivers/infiniband/hw/nes/nes_verbs.h
new file mode 100644 (file)
index 0000000..6c6b4da
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
+ * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef NES_VERBS_H
+#define NES_VERBS_H
+
+struct nes_device;
+
+#define NES_MAX_USER_DB_REGIONS  4096
+#define NES_MAX_USER_WQ_REGIONS  4096
+
+struct nes_ucontext {
+       struct ib_ucontext ibucontext;
+       struct nes_device  *nesdev;
+       unsigned long      mmap_wq_offset;
+       unsigned long      mmap_cq_offset; /* to be removed */
+       int                index;               /* rnic index (minor) */
+       unsigned long      allocated_doorbells[BITS_TO_LONGS(NES_MAX_USER_DB_REGIONS)];
+       u16                mmap_db_index[NES_MAX_USER_DB_REGIONS];
+       u16                first_free_db;
+       unsigned long      allocated_wqs[BITS_TO_LONGS(NES_MAX_USER_WQ_REGIONS)];
+       struct nes_qp      *mmap_nesqp[NES_MAX_USER_WQ_REGIONS];
+       u16                first_free_wq;
+       struct list_head   cq_reg_mem_list;
+       struct list_head   qp_reg_mem_list;
+       u32                mcrqf;
+       atomic_t           usecnt;
+};
+
+struct nes_pd {
+       struct ib_pd ibpd;
+       u16          pd_id;
+       atomic_t     sqp_count;
+       u16          mmap_db_index;
+};
+
+struct nes_mr {
+       union {
+               struct ib_mr  ibmr;
+               struct ib_mw  ibmw;
+               struct ib_fmr ibfmr;
+       };
+       struct ib_umem    *region;
+       u16               pbls_used;
+       u8                mode;
+       u8                pbl_4k;
+};
+
+struct nes_hw_pb {
+       __le32 pa_low;
+       __le32 pa_high;
+};
+
+struct nes_vpbl {
+       dma_addr_t       pbl_pbase;
+       struct nes_hw_pb *pbl_vbase;
+};
+
+struct nes_root_vpbl {
+       dma_addr_t       pbl_pbase;
+       struct nes_hw_pb *pbl_vbase;
+       struct nes_vpbl  *leaf_vpbl;
+};
+
+struct nes_fmr {
+       struct nes_mr        nesmr;
+       u32                  leaf_pbl_cnt;
+       struct nes_root_vpbl root_vpbl;
+       struct ib_qp         *ib_qp;
+       int                  access_rights;
+       struct ib_fmr_attr   attr;
+};
+
+struct nes_av;
+
+struct nes_cq {
+       struct ib_cq     ibcq;
+       struct nes_hw_cq hw_cq;
+       u32              polled_completions;
+       u32              cq_mem_size;
+       spinlock_t       lock;
+       u8               virtual_cq;
+       u8               pad[3];
+};
+
+struct nes_wq {
+       spinlock_t lock;
+};
+
+struct iw_cm_id;
+struct ietf_mpa_frame;
+
+struct nes_qp {
+       struct ib_qp          ibqp;
+       void                  *allocated_buffer;
+       struct iw_cm_id       *cm_id;
+       struct workqueue_struct *wq;
+       struct work_struct    disconn_work;
+       struct nes_cq         *nesscq;
+       struct nes_cq         *nesrcq;
+       struct nes_pd         *nespd;
+       void *cm_node; /* handle of the node this QP is associated with */
+       struct ietf_mpa_frame *ietf_frame;
+       dma_addr_t            ietf_frame_pbase;
+       wait_queue_head_t     state_waitq;
+       unsigned long         socket;
+       struct nes_hw_qp      hwqp;
+       struct work_struct    work;
+       struct work_struct    ae_work;
+       enum ib_qp_state      ibqp_state;
+       u32                   iwarp_state;
+       u32                   hte_index;
+       u32                   last_aeq;
+       u32                   qp_mem_size;
+       atomic_t              refcount;
+       atomic_t              close_timer_started;
+       u32                   mmap_sq_db_index;
+       u32                   mmap_rq_db_index;
+       spinlock_t            lock;
+       struct nes_qp_context *nesqp_context;
+       dma_addr_t            nesqp_context_pbase;
+       void                  *pbl_vbase;
+       dma_addr_t            pbl_pbase;
+       struct page           *page;
+       wait_queue_head_t     kick_waitq;
+       u16                   in_disconnect;
+       u16                   private_data_len;
+       u8                    active_conn;
+       u8                    skip_lsmm;
+       u8                    user_mode;
+       u8                    hte_added;
+       u8                    hw_iwarp_state;
+       u8                    flush_issued;
+       u8                    hw_tcp_state;
+       u8                    disconn_pending;
+       u8                    destroyed;
+};
+#endif                 /* NES_VERBS_H */
index a082466f4a83d58858120addcd7dbb77c73fb47f..09f5371137a13aba0e5c7add61c1f1d0e3115ef6 100644 (file)
@@ -680,12 +680,7 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
                neigh = *to_ipoib_neigh(skb->dst->neighbour);
 
-               if (ipoib_cm_get(neigh)) {
-                       if (ipoib_cm_up(neigh)) {
-                               ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
-                               goto out;
-                       }
-               } else if (neigh->ah) {
+               if (neigh->ah)
                        if (unlikely((memcmp(&neigh->dgid.raw,
                                            skb->dst->neighbour->ha + 4,
                                            sizeof(union ib_gid))) ||
@@ -706,6 +701,12 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
                                goto out;
                        }
 
+               if (ipoib_cm_get(neigh)) {
+                       if (ipoib_cm_up(neigh)) {
+                               ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
+                               goto out;
+                       }
+               } else if (neigh->ah) {
                        ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(skb->dst->neighbour->ha));
                        goto out;
                }
@@ -813,11 +814,9 @@ static void ipoib_neigh_cleanup(struct neighbour *n)
        struct ipoib_ah *ah = NULL;
 
        neigh = *to_ipoib_neigh(n);
-       if (neigh) {
+       if (neigh)
                priv = netdev_priv(neigh->dev);
-               ipoib_dbg(priv, "neigh_destructor for bonding device: %s\n",
-                         n->dev->name);
-       } else
+       else
                return;
        ipoib_dbg(priv,
                  "neigh_cleanup for %06x " IPOIB_GID_FMT "\n",
index 195ce7c123191896aa2946b0dc2499f13d23cbfb..fd4a49fc4773eecb1bcf8d714c29cb83479eb963 100644 (file)
@@ -204,6 +204,22 @@ out:
        return ret;
 }
 
+static int srp_new_cm_id(struct srp_target_port *target)
+{
+       struct ib_cm_id *new_cm_id;
+
+       new_cm_id = ib_create_cm_id(target->srp_host->dev->dev,
+                                   srp_cm_handler, target);
+       if (IS_ERR(new_cm_id))
+               return PTR_ERR(new_cm_id);
+
+       if (target->cm_id)
+               ib_destroy_cm_id(target->cm_id);
+       target->cm_id = new_cm_id;
+
+       return 0;
+}
+
 static int srp_create_target_ib(struct srp_target_port *target)
 {
        struct ib_qp_init_attr *init_attr;
@@ -436,6 +452,7 @@ static void srp_remove_work(struct work_struct *work)
 
 static int srp_connect_target(struct srp_target_port *target)
 {
+       int retries = 3;
        int ret;
 
        ret = srp_lookup_path(target);
@@ -468,6 +485,21 @@ static int srp_connect_target(struct srp_target_port *target)
                case SRP_DLID_REDIRECT:
                        break;
 
+               case SRP_STALE_CONN:
+                       /* Our current CM id was stale, and is now in timewait.
+                        * Try to reconnect with a new one.
+                        */
+                       if (!retries-- || srp_new_cm_id(target)) {
+                               shost_printk(KERN_ERR, target->scsi_host, PFX
+                                            "giving up on stale connection\n");
+                               target->status = -ECONNRESET;
+                               return target->status;
+                       }
+
+                       shost_printk(KERN_ERR, target->scsi_host, PFX
+                                    "retrying stale connection\n");
+                       break;
+
                default:
                        return target->status;
                }
@@ -507,7 +539,6 @@ static void srp_reset_req(struct srp_target_port *target, struct srp_request *re
 
 static int srp_reconnect_target(struct srp_target_port *target)
 {
-       struct ib_cm_id *new_cm_id;
        struct ib_qp_attr qp_attr;
        struct srp_request *req, *tmp;
        struct ib_wc wc;
@@ -526,14 +557,9 @@ static int srp_reconnect_target(struct srp_target_port *target)
         * Now get a new local CM ID so that we avoid confusing the
         * target in case things are really fouled up.
         */
-       new_cm_id = ib_create_cm_id(target->srp_host->dev->dev,
-                                   srp_cm_handler, target);
-       if (IS_ERR(new_cm_id)) {
-               ret = PTR_ERR(new_cm_id);
+       ret = srp_new_cm_id(target);
+       if (ret)
                goto err;
-       }
-       ib_destroy_cm_id(target->cm_id);
-       target->cm_id = new_cm_id;
 
        qp_attr.qp_state = IB_QPS_RESET;
        ret = ib_modify_qp(target->qp, &qp_attr, IB_QP_STATE);
@@ -1171,6 +1197,11 @@ static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
                target->status = -ECONNRESET;
                break;
 
+       case IB_CM_REJ_STALE_CONN:
+               shost_printk(KERN_WARNING, shost, "  REJ reason: stale connection\n");
+               target->status = SRP_STALE_CONN;
+               break;
+
        default:
                shost_printk(KERN_WARNING, shost, "  REJ reason 0x%x\n",
                             event->param.rej_rcvd.reason);
@@ -1862,11 +1893,9 @@ static ssize_t srp_create_target(struct class_device *class_dev,
        if (ret)
                goto err;
 
-       target->cm_id = ib_create_cm_id(host->dev->dev, srp_cm_handler, target);
-       if (IS_ERR(target->cm_id)) {
-               ret = PTR_ERR(target->cm_id);
+       ret = srp_new_cm_id(target);
+       if (ret)
                goto err_free;
-       }
 
        target->qp_in_error = 0;
        ret = srp_connect_target(target);
index 4a3c1f37e4c206bea4674e76576596ac5a851bca..cb6eb816024a881061d0ac48c4a423fa118fd2e8 100644 (file)
@@ -54,6 +54,7 @@ enum {
 
        SRP_PORT_REDIRECT       = 1,
        SRP_DLID_REDIRECT       = 2,
+       SRP_STALE_CONN          = 3,
 
        SRP_MAX_LUN             = 512,
        SRP_DEF_SG_TABLESIZE    = 12,
index 1dc2ac9f3d1cce12d1516c07b567c4656b28ee54..c5600ac5feb3aa6c99dba80628d501d515488ebf 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/init.h>
 #include <linux/gameport.h>
 #include <linux/wait.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/kthread.h>
index e5f4da9283406920945cee029758f3d0f8fbab94..05e3494cf8b87f4bb80fc9b904cda36099e6b6e5 100644 (file)
@@ -42,7 +42,6 @@
 #include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/input.h>
-#include <linux/irq.h>
 
 #include <asm/portmux.h>
 #include <asm/mach/bf54x_keys.h>
index e6696b3c9416c066c6c7411e7318df4cb6326e1d..986f93cfc6b8a0211020e8978f374c9c29b272d2 100644 (file)
@@ -17,7 +17,6 @@
  */
 #include <linux/device.h>
 #include <linux/errno.h>
-#include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/input.h>
index 3e99df6be08465affbbb0550fd5be59688f71c39..adc3bd6e7f7bbc9a0d038d748dd3f95794a46f8f 100644 (file)
@@ -141,7 +141,7 @@ static void gscps2_flush(struct gscps2port *ps2port)
 /*
  * gscps2_writeb_output() - write a byte to the port
  *
- * returns 1 on sucess, 0 on error
+ * returns 1 on success, 0 on error
  */
 
 static inline int gscps2_writeb_output(struct gscps2port *ps2port, u8 data)
index 2ae6c6016a8665d79eb4f6dd63d76a3675230f30..28ae15ed12c57a81e5e92a1cda6e421efd3bb284 100644 (file)
@@ -109,7 +109,7 @@ struct h3600_dev {
 static irqreturn_t action_button_handler(int irq, void *dev_id)
 {
        int down = (GPLR & GPIO_BITSY_ACTION_BUTTON) ? 0 : 1;
-       struct input_dev *dev = (struct input_dev *) dev_id;
+       struct input_dev *dev = dev_id;
 
        input_report_key(dev, KEY_ENTER, down);
        input_sync(dev);
@@ -120,7 +120,7 @@ static irqreturn_t action_button_handler(int irq, void *dev_id)
 static irqreturn_t npower_button_handler(int irq, void *dev_id)
 {
        int down = (GPLR & GPIO_BITSY_NPOWER_BUTTON) ? 0 : 1;
-       struct input_dev *dev = (struct input_dev *) dev_id;
+       struct input_dev *dev = dev_id;
 
        /*
         * This interrupt is only called when we release the key. So we have
index ee2b0b9f8f46b873822dc20db69f2625b9a8d650..8325022e2bed5951c04e67efc989aabec005bc6a 100644 (file)
@@ -310,7 +310,7 @@ act2000_command(act2000_card * card, isdn_ctrl * c)
                        }
                        break;
                case ISDN_CMD_DIAL:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        if (!(chan = find_channel(card, c->arg & 0x0f)))
                                break;
@@ -339,7 +339,7 @@ act2000_command(act2000_card * card, isdn_ctrl * c)
                        }
                        return ret;
                case ISDN_CMD_ACCEPTD:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        if (!(chan = find_channel(card, c->arg & 0x0f)))
                                break;
@@ -347,11 +347,11 @@ act2000_command(act2000_card * card, isdn_ctrl * c)
                                actcapi_select_b2_protocol_req(card, chan);
                        return 0;
                case ISDN_CMD_ACCEPTB:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        return 0;
                case ISDN_CMD_HANGUP:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        if (!(chan = find_channel(card, c->arg & 0x0f)))
                                break;
@@ -366,7 +366,7 @@ act2000_command(act2000_card * card, isdn_ctrl * c)
                        }
                        return 0;
                case ISDN_CMD_SETEAZ:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        if (!(chan = find_channel(card, c->arg & 0x0f)))
                                break;
@@ -386,7 +386,7 @@ act2000_command(act2000_card * card, isdn_ctrl * c)
                        actcapi_listen_req(card);
                        return 0;
                case ISDN_CMD_CLREAZ:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        if (!(chan = find_channel(card, c->arg & 0x0f)))
                                break;
@@ -394,14 +394,14 @@ act2000_command(act2000_card * card, isdn_ctrl * c)
                        actcapi_listen_req(card);
                        return 0;
                case ISDN_CMD_SETL2:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        if (!(chan = find_channel(card, c->arg & 0x0f)))
                                break;
                        chan->l2prot = (c->arg >> 8);
                        return 0;
                case ISDN_CMD_SETL3:
-                       if (!card->flags & ACT2000_FLAGS_RUNNING)
+                       if (!(card->flags & ACT2000_FLAGS_RUNNING))
                                return -ENODEV;
                        if ((c->arg >> 8) != ISDN_PROTO_L3_TRANS) {
                                printk(KERN_WARNING "L3 protocol unknown\n");
@@ -524,7 +524,7 @@ if_writecmd(const u_char __user *buf, int len, int id, int channel)
         act2000_card *card = act2000_findcard(id);
 
         if (card) {
-                if (!card->flags & ACT2000_FLAGS_RUNNING)
+                if (!(card->flags & ACT2000_FLAGS_RUNNING))
                         return -ENODEV;
                 return (len);
         }
@@ -539,7 +539,7 @@ if_readstatus(u_char __user * buf, int len, int id, int channel)
         act2000_card *card = act2000_findcard(id);
        
         if (card) {
-                if (!card->flags & ACT2000_FLAGS_RUNNING)
+                if (!(card->flags & ACT2000_FLAGS_RUNNING))
                         return -ENODEV;
                 return (act2000_readstatus(buf, len, card));
         }
@@ -554,7 +554,7 @@ if_sendbuf(int id, int channel, int ack, struct sk_buff *skb)
         act2000_card *card = act2000_findcard(id);
        
         if (card) {
-                if (!card->flags & ACT2000_FLAGS_RUNNING)
+                if (!(card->flags & ACT2000_FLAGS_RUNNING))
                         return -ENODEV;
                return (act2000_sendbuf(card, channel, ack, skb));
         }
index 00a3be5b862bbf87416231c2f91c58851e593c87..091deb9d1c47cfb85e5252effbf019d65aba67e3 100644 (file)
@@ -350,8 +350,8 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
        unsigned char *src, c;
        int procbytes;
 
-       head = atomic_read(&inbuf->head);
-       tail = atomic_read(&inbuf->tail);
+       head = inbuf->head;
+       tail = inbuf->tail;
        gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
 
        if (head != tail) {
@@ -361,7 +361,7 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
                gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
 
                while (numbytes) {
-                       if (atomic_read(&cs->mstate) == MS_LOCKED) {
+                       if (cs->mstate == MS_LOCKED) {
                                procbytes = lock_loop(src, numbytes, inbuf);
                                src += procbytes;
                                numbytes -= procbytes;
@@ -436,7 +436,7 @@ nextbyte:
                }
 
                gig_dbg(DEBUG_INTR, "setting head to %u", head);
-               atomic_set(&inbuf->head, head);
+               inbuf->head = head;
        }
 }
 EXPORT_SYMBOL_GPL(gigaset_m10x_input);
index af7648274b3801564a4314c1623b6fd117fe919f..5255b5e20e132021c46259eb0f44de8c3af3fb10 100644 (file)
@@ -73,6 +73,14 @@ static int gigaset_probe(struct usb_interface *interface,
 /* Function will be called if the device is unplugged */
 static void gigaset_disconnect(struct usb_interface *interface);
 
+/* functions called before/after suspend */
+static int gigaset_suspend(struct usb_interface *intf, pm_message_t message);
+static int gigaset_resume(struct usb_interface *intf);
+
+/* functions called before/after device reset */
+static int gigaset_pre_reset(struct usb_interface *intf);
+static int gigaset_post_reset(struct usb_interface *intf);
+
 static int atread_submit(struct cardstate *, int);
 static void stopurbs(struct bas_bc_state *);
 static int req_submit(struct bc_state *, int, int, int);
@@ -105,8 +113,9 @@ struct bas_cardstate {
        unsigned char           int_in_buf[3];
 
        spinlock_t              lock;           /* locks all following */
-       atomic_t                basstate;       /* bitmap (BS_*) */
+       int                     basstate;       /* bitmap (BS_*) */
        int                     pending;        /* uncompleted base request */
+       wait_queue_head_t       waitqueue;
        int                     rcvbuf_size;    /* size of AT receive buffer */
                                                /* 0: no receive in progress */
        int                     retry_cmd_in;   /* receive req retry count */
@@ -121,10 +130,10 @@ struct bas_cardstate {
 #define BS_ATTIMER     0x020   /* waiting for HD_READY_SEND_ATDATA */
 #define BS_ATRDPEND    0x040   /* urb_cmd_in in use */
 #define BS_ATWRPEND    0x080   /* urb_cmd_out in use */
+#define BS_SUSPEND     0x100   /* USB port suspended */
 
 
 static struct gigaset_driver *driver = NULL;
-static struct cardstate *cardstate = NULL;
 
 /* usb specific object needed to register this driver with the usb subsystem */
 static struct usb_driver gigaset_usb_driver = {
@@ -132,6 +141,11 @@ static struct usb_driver gigaset_usb_driver = {
        .probe =        gigaset_probe,
        .disconnect =   gigaset_disconnect,
        .id_table =     gigaset_table,
+       .suspend =      gigaset_suspend,
+       .resume =       gigaset_resume,
+       .reset_resume = gigaset_post_reset,
+       .pre_reset =    gigaset_pre_reset,
+       .post_reset =   gigaset_post_reset,
 };
 
 /* get message text for usb_submit_urb return code
@@ -248,12 +262,12 @@ static inline void dump_urb(enum debuglevel level, const char *tag,
        if (urb) {
                gig_dbg(level,
                        "  dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, "
-                       "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,",
+                       "hcpriv=0x%08lx, transfer_flags=0x%x,",
                        (unsigned long) urb->dev,
                        usb_pipetype_str(urb->pipe),
                        usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe),
                        usb_pipein(urb->pipe) ? "in" : "out",
-                       urb->status, (unsigned long) urb->hcpriv,
+                       (unsigned long) urb->hcpriv,
                        urb->transfer_flags);
                gig_dbg(level,
                        "  transfer_buffer=0x%08lx[%d], actual_length=%d, "
@@ -355,27 +369,27 @@ static void check_pending(struct bas_cardstate *ucs)
        case 0:
                break;
        case HD_OPEN_ATCHANNEL:
-               if (atomic_read(&ucs->basstate) & BS_ATOPEN)
+               if (ucs->basstate & BS_ATOPEN)
                        ucs->pending = 0;
                break;
        case HD_OPEN_B1CHANNEL:
-               if (atomic_read(&ucs->basstate) & BS_B1OPEN)
+               if (ucs->basstate & BS_B1OPEN)
                        ucs->pending = 0;
                break;
        case HD_OPEN_B2CHANNEL:
-               if (atomic_read(&ucs->basstate) & BS_B2OPEN)
+               if (ucs->basstate & BS_B2OPEN)
                        ucs->pending = 0;
                break;
        case HD_CLOSE_ATCHANNEL:
-               if (!(atomic_read(&ucs->basstate) & BS_ATOPEN))
+               if (!(ucs->basstate & BS_ATOPEN))
                        ucs->pending = 0;
                break;
        case HD_CLOSE_B1CHANNEL:
-               if (!(atomic_read(&ucs->basstate) & BS_B1OPEN))
+               if (!(ucs->basstate & BS_B1OPEN))
                        ucs->pending = 0;
                break;
        case HD_CLOSE_B2CHANNEL:
-               if (!(atomic_read(&ucs->basstate) & BS_B2OPEN))
+               if (!(ucs->basstate & BS_B2OPEN))
                        ucs->pending = 0;
                break;
        case HD_DEVICE_INIT_ACK:                /* no reply expected */
@@ -441,8 +455,8 @@ inline static int update_basstate(struct bas_cardstate *ucs,
        int state;
 
        spin_lock_irqsave(&ucs->lock, flags);
-       state = atomic_read(&ucs->basstate);
-       atomic_set(&ucs->basstate, (state & ~clear) | set);
+       state = ucs->basstate;
+       ucs->basstate = (state & ~clear) | set;
        spin_unlock_irqrestore(&ucs->lock, flags);
        return state;
 }
@@ -459,11 +473,13 @@ static void read_ctrl_callback(struct urb *urb)
        struct inbuf_t *inbuf = urb->context;
        struct cardstate *cs = inbuf->cs;
        struct bas_cardstate *ucs = cs->hw.bas;
+       int status = urb->status;
        int have_data = 0;
        unsigned numbytes;
        int rc;
 
        update_basstate(ucs, 0, BS_ATRDPEND);
+       wake_up(&ucs->waitqueue);
 
        if (!ucs->rcvbuf_size) {
                dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
@@ -472,7 +488,7 @@ static void read_ctrl_callback(struct urb *urb)
 
        del_timer(&ucs->timer_cmd_in);
 
-       switch (urb->status) {
+       switch (status) {
        case 0:                         /* normal completion */
                numbytes = urb->actual_length;
                if (unlikely(numbytes != ucs->rcvbuf_size)) {
@@ -506,12 +522,12 @@ static void read_ctrl_callback(struct urb *urb)
        case -ESHUTDOWN:                /* device shut down */
                /* no action necessary */
                gig_dbg(DEBUG_USBREQ, "%s: %s",
-                       __func__, get_usb_statmsg(urb->status));
+                       __func__, get_usb_statmsg(status));
                break;
 
        default:                        /* severe trouble */
                dev_warn(cs->dev, "control read: %s\n",
-                        get_usb_statmsg(urb->status));
+                        get_usb_statmsg(status));
                if (ucs->retry_cmd_in++ < BAS_RETRY) {
                        dev_notice(cs->dev, "control read: retry %d\n",
                                   ucs->retry_cmd_in);
@@ -550,17 +566,28 @@ static void read_ctrl_callback(struct urb *urb)
 static int atread_submit(struct cardstate *cs, int timeout)
 {
        struct bas_cardstate *ucs = cs->hw.bas;
+       int basstate;
        int ret;
 
        gig_dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)",
                ucs->rcvbuf_size);
 
-       if (update_basstate(ucs, BS_ATRDPEND, 0) & BS_ATRDPEND) {
+       basstate = update_basstate(ucs, BS_ATRDPEND, 0);
+       if (basstate & BS_ATRDPEND) {
                dev_err(cs->dev,
                        "could not submit HD_READ_ATMESSAGE: URB busy\n");
                return -EBUSY;
        }
 
+       if (basstate & BS_SUSPEND) {
+               dev_notice(cs->dev,
+                          "HD_READ_ATMESSAGE not submitted, "
+                          "suspend in progress\n");
+               update_basstate(ucs, 0, BS_ATRDPEND);
+               /* treat like disconnect */
+               return -ENODEV;
+       }
+
        ucs->dr_cmd_in.bRequestType = IN_VENDOR_REQ;
        ucs->dr_cmd_in.bRequest = HD_READ_ATMESSAGE;
        ucs->dr_cmd_in.wValue = 0;
@@ -601,12 +628,13 @@ static void read_int_callback(struct urb *urb)
        struct cardstate *cs = urb->context;
        struct bas_cardstate *ucs = cs->hw.bas;
        struct bc_state *bcs;
+       int status = urb->status;
        unsigned long flags;
        int rc;
        unsigned l;
        int channel;
 
-       switch (urb->status) {
+       switch (status) {
        case 0:                 /* success */
                break;
        case -ENOENT:                   /* cancelled */
@@ -614,7 +642,7 @@ static void read_int_callback(struct urb *urb)
        case -EINPROGRESS:              /* pending */
                /* ignore silently */
                gig_dbg(DEBUG_USBREQ, "%s: %s",
-                       __func__, get_usb_statmsg(urb->status));
+                       __func__, get_usb_statmsg(status));
                return;
        case -ENODEV:                   /* device removed */
        case -ESHUTDOWN:                /* device shut down */
@@ -623,7 +651,7 @@ static void read_int_callback(struct urb *urb)
                return;
        default:                /* severe trouble */
                dev_warn(cs->dev, "interrupt read: %s\n",
-                        get_usb_statmsg(urb->status));
+                        get_usb_statmsg(status));
                //FIXME corrective action? resubmission always ok?
                goto resubmit;
        }
@@ -745,6 +773,7 @@ static void read_int_callback(struct urb *urb)
        }
 
        check_pending(ucs);
+       wake_up(&ucs->waitqueue);
 
 resubmit:
        rc = usb_submit_urb(urb, GFP_ATOMIC);
@@ -766,17 +795,18 @@ static void read_iso_callback(struct urb *urb)
 {
        struct bc_state *bcs;
        struct bas_bc_state *ubc;
+       int status = urb->status;
        unsigned long flags;
        int i, rc;
 
        /* status codes not worth bothering the tasklet with */
-       if (unlikely(urb->status == -ENOENT ||
-                    urb->status == -ECONNRESET ||
-                    urb->status == -EINPROGRESS ||
-                    urb->status == -ENODEV ||
-                    urb->status == -ESHUTDOWN)) {
+       if (unlikely(status == -ENOENT ||
+                    status == -ECONNRESET ||
+                    status == -EINPROGRESS ||
+                    status == -ENODEV ||
+                    status == -ESHUTDOWN)) {
                gig_dbg(DEBUG_ISO, "%s: %s",
-                       __func__, get_usb_statmsg(urb->status));
+                       __func__, get_usb_statmsg(status));
                return;
        }
 
@@ -787,10 +817,11 @@ static void read_iso_callback(struct urb *urb)
        if (likely(ubc->isoindone == NULL)) {
                /* pass URB to tasklet */
                ubc->isoindone = urb;
+               ubc->isoinstatus = status;
                tasklet_schedule(&ubc->rcvd_tasklet);
        } else {
                /* tasklet still busy, drop data and resubmit URB */
-               ubc->loststatus = urb->status;
+               ubc->loststatus = status;
                for (i = 0; i < BAS_NUMFRAMES; i++) {
                        ubc->isoinlost += urb->iso_frame_desc[i].actual_length;
                        if (unlikely(urb->iso_frame_desc[i].status != 0 &&
@@ -800,7 +831,7 @@ static void read_iso_callback(struct urb *urb)
                        urb->iso_frame_desc[i].status = 0;
                        urb->iso_frame_desc[i].actual_length = 0;
                }
-               if (likely(atomic_read(&ubc->running))) {
+               if (likely(ubc->running)) {
                        /* urb->dev is clobbered by USB subsystem */
                        urb->dev = bcs->cs->hw.bas->udev;
                        urb->transfer_flags = URB_ISO_ASAP;
@@ -831,22 +862,24 @@ static void write_iso_callback(struct urb *urb)
 {
        struct isow_urbctx_t *ucx;
        struct bas_bc_state *ubc;
+       int status = urb->status;
        unsigned long flags;
 
        /* status codes not worth bothering the tasklet with */
-       if (unlikely(urb->status == -ENOENT ||
-                    urb->status == -ECONNRESET ||
-                    urb->status == -EINPROGRESS ||
-                    urb->status == -ENODEV ||
-                    urb->status == -ESHUTDOWN)) {
+       if (unlikely(status == -ENOENT ||
+                    status == -ECONNRESET ||
+                    status == -EINPROGRESS ||
+                    status == -ENODEV ||
+                    status == -ESHUTDOWN)) {
                gig_dbg(DEBUG_ISO, "%s: %s",
-                       __func__, get_usb_statmsg(urb->status));
+                       __func__, get_usb_statmsg(status));
                return;
        }
 
        /* pass URB context to tasklet */
        ucx = urb->context;
        ubc = ucx->bcs->hw.bas;
+       ucx->status = status;
 
        spin_lock_irqsave(&ubc->isooutlock, flags);
        ubc->isooutovfl = ubc->isooutdone;
@@ -875,7 +908,7 @@ static int starturbs(struct bc_state *bcs)
                bcs->inputstate |= INS_flag_hunt;
 
        /* submit all isochronous input URBs */
-       atomic_set(&ubc->running, 1);
+       ubc->running = 1;
        for (k = 0; k < BAS_INURBS; k++) {
                urb = ubc->isoinurbs[k];
                if (!urb) {
@@ -932,15 +965,15 @@ static int starturbs(struct bc_state *bcs)
                ubc->isoouturbs[k].limit = -1;
        }
 
-       /* submit two URBs, keep third one */
-       for (k = 0; k < 2; ++k) {
+       /* keep one URB free, submit the others */
+       for (k = 0; k < BAS_OUTURBS-1; ++k) {
                dump_urb(DEBUG_ISO, "Initial isoc write", urb);
                rc = usb_submit_urb(ubc->isoouturbs[k].urb, GFP_ATOMIC);
                if (rc != 0)
                        goto error;
        }
        dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb);
-       ubc->isooutfree = &ubc->isoouturbs[2];
+       ubc->isooutfree = &ubc->isoouturbs[BAS_OUTURBS-1];
        ubc->isooutdone = ubc->isooutovfl = NULL;
        return 0;
  error:
@@ -958,7 +991,7 @@ static void stopurbs(struct bas_bc_state *ubc)
 {
        int k, rc;
 
-       atomic_set(&ubc->running, 0);
+       ubc->running = 0;
 
        for (k = 0; k < BAS_INURBS; ++k) {
                rc = usb_unlink_urb(ubc->isoinurbs[k]);
@@ -1034,7 +1067,7 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
                        }
                        break;
                }
-               ucx->limit = atomic_read(&ubc->isooutbuf->nextread);
+               ucx->limit = ubc->isooutbuf->nextread;
                ifd->status = 0;
                ifd->actual_length = 0;
        }
@@ -1070,6 +1103,7 @@ static void write_iso_tasklet(unsigned long data)
        struct cardstate *cs = bcs->cs;
        struct isow_urbctx_t *done, *next, *ovfl;
        struct urb *urb;
+       int status;
        struct usb_iso_packet_descriptor *ifd;
        int offset;
        unsigned long flags;
@@ -1080,7 +1114,7 @@ static void write_iso_tasklet(unsigned long data)
 
        /* loop while completed URBs arrive in time */
        for (;;) {
-               if (unlikely(!(atomic_read(&ubc->running)))) {
+               if (unlikely(!(ubc->running))) {
                        gig_dbg(DEBUG_ISO, "%s: not running", __func__);
                        return;
                }
@@ -1126,7 +1160,8 @@ static void write_iso_tasklet(unsigned long data)
 
                /* process completed URB */
                urb = done->urb;
-               switch (urb->status) {
+               status = done->status;
+               switch (status) {
                case -EXDEV:                    /* partial completion */
                        gig_dbg(DEBUG_ISO, "%s: URB partially completed",
                                __func__);
@@ -1179,12 +1214,12 @@ static void write_iso_tasklet(unsigned long data)
                        break;
                default:                        /* severe trouble */
                        dev_warn(cs->dev, "isochronous write: %s\n",
-                                get_usb_statmsg(urb->status));
+                                get_usb_statmsg(status));
                }
 
                /* mark the write buffer area covered by this URB as free */
                if (done->limit >= 0)
-                       atomic_set(&ubc->isooutbuf->read, done->limit);
+                       ubc->isooutbuf->read = done->limit;
 
                /* mark URB as free */
                spin_lock_irqsave(&ubc->isooutlock, flags);
@@ -1233,6 +1268,7 @@ static void read_iso_tasklet(unsigned long data)
        struct bas_bc_state *ubc = bcs->hw.bas;
        struct cardstate *cs = bcs->cs;
        struct urb *urb;
+       int status;
        char *rcvbuf;
        unsigned long flags;
        int totleft, numbytes, offset, frame, rc;
@@ -1245,6 +1281,7 @@ static void read_iso_tasklet(unsigned long data)
                        spin_unlock_irqrestore(&ubc->isoinlock, flags);
                        return;
                }
+               status = ubc->isoinstatus;
                ubc->isoindone = NULL;
                if (unlikely(ubc->loststatus != -EINPROGRESS)) {
                        dev_warn(cs->dev,
@@ -1256,15 +1293,15 @@ static void read_iso_tasklet(unsigned long data)
                }
                spin_unlock_irqrestore(&ubc->isoinlock, flags);
 
-               if (unlikely(!(atomic_read(&ubc->running)))) {
+               if (unlikely(!(ubc->running))) {
                        gig_dbg(DEBUG_ISO,
                                "%s: channel not running, "
                                "dropped URB with status: %s",
-                               __func__, get_usb_statmsg(urb->status));
+                               __func__, get_usb_statmsg(status));
                        return;
                }
 
-               switch (urb->status) {
+               switch (status) {
                case 0:                         /* normal completion */
                        break;
                case -EXDEV:                    /* inspect individual frames
@@ -1276,7 +1313,7 @@ static void read_iso_tasklet(unsigned long data)
                case -ECONNRESET:
                case -EINPROGRESS:
                        gig_dbg(DEBUG_ISO, "%s: %s",
-                               __func__, get_usb_statmsg(urb->status));
+                               __func__, get_usb_statmsg(status));
                        continue;               /* -> skip */
                case -EPIPE:
                        dev_err(cs->dev, "isochronous read stalled\n");
@@ -1284,7 +1321,7 @@ static void read_iso_tasklet(unsigned long data)
                        continue;               /* -> skip */
                default:                        /* severe trouble */
                        dev_warn(cs->dev, "isochronous read: %s\n",
-                                get_usb_statmsg(urb->status));
+                                get_usb_statmsg(status));
                        goto error;
                }
 
@@ -1406,6 +1443,8 @@ static void req_timeout(unsigned long data)
                dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
                         pending);
        }
+
+       wake_up(&ucs->waitqueue);
 }
 
 /* write_ctrl_callback
@@ -1418,11 +1457,12 @@ static void req_timeout(unsigned long data)
 static void write_ctrl_callback(struct urb *urb)
 {
        struct bas_cardstate *ucs = urb->context;
+       int status = urb->status;
        int rc;
        unsigned long flags;
 
        /* check status */
-       switch (urb->status) {
+       switch (status) {
        case 0:                                 /* normal completion */
                spin_lock_irqsave(&ucs->lock, flags);
                switch (ucs->pending) {
@@ -1441,20 +1481,22 @@ static void write_ctrl_callback(struct urb *urb)
        case -ESHUTDOWN:                /* device shut down */
                /* ignore silently */
                gig_dbg(DEBUG_USBREQ, "%s: %s",
-                       __func__, get_usb_statmsg(urb->status));
+                       __func__, get_usb_statmsg(status));
                break;
 
        default:                                /* any failure */
-               if (++ucs->retry_ctrl > BAS_RETRY) {
+               /* don't retry if suspend requested */
+               if (++ucs->retry_ctrl > BAS_RETRY ||
+                   (ucs->basstate & BS_SUSPEND)) {
                        dev_err(&ucs->interface->dev,
                                "control request 0x%02x failed: %s\n",
                                ucs->dr_ctrl.bRequest,
-                               get_usb_statmsg(urb->status));
+                               get_usb_statmsg(status));
                        break;          /* give up */
                }
                dev_notice(&ucs->interface->dev,
                           "control request 0x%02x: %s, retry %d\n",
-                          ucs->dr_ctrl.bRequest, get_usb_statmsg(urb->status),
+                          ucs->dr_ctrl.bRequest, get_usb_statmsg(status),
                           ucs->retry_ctrl);
                /* urb->dev is clobbered by USB subsystem */
                urb->dev = ucs->udev;
@@ -1474,6 +1516,7 @@ static void write_ctrl_callback(struct urb *urb)
        del_timer(&ucs->timer_ctrl);
        ucs->pending = 0;
        spin_unlock_irqrestore(&ucs->lock, flags);
+       wake_up(&ucs->waitqueue);
 }
 
 /* req_submit
@@ -1548,37 +1591,46 @@ static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
  */
 static int gigaset_init_bchannel(struct bc_state *bcs)
 {
+       struct cardstate *cs = bcs->cs;
        int req, ret;
        unsigned long flags;
 
-       spin_lock_irqsave(&bcs->cs->lock, flags);
-       if (unlikely(!bcs->cs->connected)) {
+       spin_lock_irqsave(&cs->lock, flags);
+       if (unlikely(!cs->connected)) {
                gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
-               spin_unlock_irqrestore(&bcs->cs->lock, flags);
+               spin_unlock_irqrestore(&cs->lock, flags);
                return -ENODEV;
        }
 
+       if (cs->hw.bas->basstate & BS_SUSPEND) {
+               dev_notice(cs->dev,
+                          "not starting isochronous I/O, "
+                          "suspend in progress\n");
+               spin_unlock_irqrestore(&cs->lock, flags);
+               return -EHOSTUNREACH;
+       }
+
        if ((ret = starturbs(bcs)) < 0) {
-               dev_err(bcs->cs->dev,
+               dev_err(cs->dev,
                        "could not start isochronous I/O for channel B%d: %s\n",
                        bcs->channel + 1,
                        ret == -EFAULT ? "null URB" : get_usb_rcmsg(ret));
                if (ret != -ENODEV)
                        error_hangup(bcs);
-               spin_unlock_irqrestore(&bcs->cs->lock, flags);
+               spin_unlock_irqrestore(&cs->lock, flags);
                return ret;
        }
 
        req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
        if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
-               dev_err(bcs->cs->dev, "could not open channel B%d\n",
+               dev_err(cs->dev, "could not open channel B%d\n",
                        bcs->channel + 1);
                stopurbs(bcs->hw.bas);
                if (ret != -ENODEV)
                        error_hangup(bcs);
        }
 
-       spin_unlock_irqrestore(&bcs->cs->lock, flags);
+       spin_unlock_irqrestore(&cs->lock, flags);
        return ret;
 }
 
@@ -1594,20 +1646,20 @@ static int gigaset_init_bchannel(struct bc_state *bcs)
  */
 static int gigaset_close_bchannel(struct bc_state *bcs)
 {
+       struct cardstate *cs = bcs->cs;
        int req, ret;
        unsigned long flags;
 
-       spin_lock_irqsave(&bcs->cs->lock, flags);
-       if (unlikely(!bcs->cs->connected)) {
-               spin_unlock_irqrestore(&bcs->cs->lock, flags);
+       spin_lock_irqsave(&cs->lock, flags);
+       if (unlikely(!cs->connected)) {
+               spin_unlock_irqrestore(&cs->lock, flags);
                gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
                return -ENODEV;
        }
 
-       if (!(atomic_read(&bcs->cs->hw.bas->basstate) &
-             (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
+       if (!(cs->hw.bas->basstate & (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
                /* channel not running: just signal common.c */
-               spin_unlock_irqrestore(&bcs->cs->lock, flags);
+               spin_unlock_irqrestore(&cs->lock, flags);
                gigaset_bchannel_down(bcs);
                return 0;
        }
@@ -1615,10 +1667,10 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
        /* channel running: tell device to close it */
        req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
        if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
-               dev_err(bcs->cs->dev, "closing channel B%d failed\n",
+               dev_err(cs->dev, "closing channel B%d failed\n",
                        bcs->channel + 1);
 
-       spin_unlock_irqrestore(&bcs->cs->lock, flags);
+       spin_unlock_irqrestore(&cs->lock, flags);
        return ret;
 }
 
@@ -1665,12 +1717,14 @@ static void write_command_callback(struct urb *urb)
 {
        struct cardstate *cs = urb->context;
        struct bas_cardstate *ucs = cs->hw.bas;
+       int status = urb->status;
        unsigned long flags;
 
        update_basstate(ucs, 0, BS_ATWRPEND);
+       wake_up(&ucs->waitqueue);
 
        /* check status */
-       switch (urb->status) {
+       switch (status) {
        case 0:                                 /* normal completion */
                break;
        case -ENOENT:                   /* cancelled */
@@ -1680,26 +1734,33 @@ static void write_command_callback(struct urb *urb)
        case -ESHUTDOWN:                /* device shut down */
                /* ignore silently */
                gig_dbg(DEBUG_USBREQ, "%s: %s",
-                       __func__, get_usb_statmsg(urb->status));
+                       __func__, get_usb_statmsg(status));
                return;
        default:                                /* any failure */
                if (++ucs->retry_cmd_out > BAS_RETRY) {
                        dev_warn(cs->dev,
                                 "command write: %s, "
                                 "giving up after %d retries\n",
-                                get_usb_statmsg(urb->status),
+                                get_usb_statmsg(status),
                                 ucs->retry_cmd_out);
                        break;
                }
+               if (ucs->basstate & BS_SUSPEND) {
+                       dev_warn(cs->dev,
+                                "command write: %s, "
+                                "won't retry - suspend requested\n",
+                                get_usb_statmsg(status));
+                       break;
+               }
                if (cs->cmdbuf == NULL) {
                        dev_warn(cs->dev,
                                 "command write: %s, "
                                 "cannot retry - cmdbuf gone\n",
-                                get_usb_statmsg(urb->status));
+                                get_usb_statmsg(status));
                        break;
                }
                dev_notice(cs->dev, "command write: %s, retry %d\n",
-                          get_usb_statmsg(urb->status), ucs->retry_cmd_out);
+                          get_usb_statmsg(status), ucs->retry_cmd_out);
                if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
                        /* resubmitted - bypass regular exit block */
                        return;
@@ -1799,8 +1860,14 @@ static int start_cbsend(struct cardstate *cs)
        int rc;
        int retval = 0;
 
+       /* check if suspend requested */
+       if (ucs->basstate & BS_SUSPEND) {
+               gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "suspending");
+               return -EHOSTUNREACH;
+       }
+
        /* check if AT channel is open */
-       if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
+       if (!(ucs->basstate & BS_ATOPEN)) {
                gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open");
                rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
                if (rc < 0) {
@@ -1816,8 +1883,7 @@ static int start_cbsend(struct cardstate *cs)
        /* try to send first command in queue */
        spin_lock_irqsave(&cs->cmdlock, flags);
 
-       while ((cb = cs->cmdbuf) != NULL &&
-              atomic_read(&ucs->basstate) & BS_ATREADY) {
+       while ((cb = cs->cmdbuf) != NULL && (ucs->basstate & BS_ATREADY)) {
                ucs->retry_cmd_out = 0;
                rc = atwrite_submit(cs, cb->buf, cb->len);
                if (unlikely(rc)) {
@@ -1855,7 +1921,7 @@ static int gigaset_write_cmd(struct cardstate *cs,
        unsigned long flags;
        int rc;
 
-       gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
+       gigaset_dbg_buffer(cs->mstate != MS_LOCKED ?
                             DEBUG_TRANSCMD : DEBUG_LOCKCMD,
                           "CMD Transmit", len, buf);
 
@@ -1970,7 +2036,7 @@ static int gigaset_freebcshw(struct bc_state *bcs)
                return 0;
 
        /* kill URBs and tasklets before freeing - better safe than sorry */
-       atomic_set(&ubc->running, 0);
+       ubc->running = 0;
        gig_dbg(DEBUG_INIT, "%s: killing iso URBs", __func__);
        for (i = 0; i < BAS_OUTURBS; ++i) {
                usb_kill_urb(ubc->isoouturbs[i].urb);
@@ -2005,7 +2071,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
                return 0;
        }
 
-       atomic_set(&ubc->running, 0);
+       ubc->running = 0;
        atomic_set(&ubc->corrbytes, 0);
        spin_lock_init(&ubc->isooutlock);
        for (i = 0; i < BAS_OUTURBS; ++i) {
@@ -2050,7 +2116,7 @@ static void gigaset_reinitbcshw(struct bc_state *bcs)
 {
        struct bas_bc_state *ubc = bcs->hw.bas;
 
-       atomic_set(&bcs->hw.bas->running, 0);
+       bcs->hw.bas->running = 0;
        atomic_set(&bcs->hw.bas->corrbytes, 0);
        bcs->hw.bas->numsub = 0;
        spin_lock_init(&ubc->isooutlock);
@@ -2081,10 +2147,11 @@ static int gigaset_initcshw(struct cardstate *cs)
        spin_lock_init(&ucs->lock);
        ucs->pending = 0;
 
-       atomic_set(&ucs->basstate, 0);
+       ucs->basstate = 0;
        init_timer(&ucs->timer_ctrl);
        init_timer(&ucs->timer_atrdy);
        init_timer(&ucs->timer_cmd_in);
+       init_waitqueue_head(&ucs->waitqueue);
 
        return 1;
 }
@@ -2102,7 +2169,7 @@ static void freeurbs(struct cardstate *cs)
        int i, j;
 
        gig_dbg(DEBUG_INIT, "%s: killing URBs", __func__);
-       for (j = 0; j < 2; ++j) {
+       for (j = 0; j < BAS_CHANNELS; ++j) {
                ubc = cs->bcs[j].hw.bas;
                for (i = 0; i < BAS_OUTURBS; ++i) {
                        usb_kill_urb(ubc->isoouturbs[i].urb);
@@ -2179,11 +2246,11 @@ static int gigaset_probe(struct usb_interface *interface,
                 __func__, le16_to_cpu(udev->descriptor.idVendor),
                 le16_to_cpu(udev->descriptor.idProduct));
 
-       cs = gigaset_getunassignedcs(driver);
-       if (!cs) {
-               dev_err(&udev->dev, "no free cardstate\n");
+       /* allocate memory for our device state and intialize it */
+       cs = gigaset_initcs(driver, BAS_CHANNELS, 0, 0, cidmode,
+                           GIGASET_MODULENAME);
+       if (!cs)
                return -ENODEV;
-       }
        ucs = cs->hw.bas;
 
        /* save off device structure ptrs for later use */
@@ -2203,7 +2270,7 @@ static int gigaset_probe(struct usb_interface *interface,
            !(ucs->urb_ctrl = usb_alloc_urb(0, GFP_KERNEL)))
                goto allocerr;
 
-       for (j = 0; j < 2; ++j) {
+       for (j = 0; j < BAS_CHANNELS; ++j) {
                ubc = cs->bcs[j].hw.bas;
                for (i = 0; i < BAS_OUTURBS; ++i)
                        if (!(ubc->isoouturbs[i].urb =
@@ -2237,7 +2304,7 @@ static int gigaset_probe(struct usb_interface *interface,
 
        /* tell common part that the device is ready */
        if (startmode == SM_LOCKED)
-               atomic_set(&cs->mstate, MS_LOCKED);
+               cs->mstate = MS_LOCKED;
 
        /* save address of controller structure */
        usb_set_intfdata(interface, cs);
@@ -2252,7 +2319,7 @@ allocerr:
 error:
        freeurbs(cs);
        usb_set_intfdata(interface, NULL);
-       gigaset_unassign(cs);
+       gigaset_freecs(cs);
        return -ENODEV;
 }
 
@@ -2272,11 +2339,10 @@ static void gigaset_disconnect(struct usb_interface *interface)
        dev_info(cs->dev, "disconnecting Gigaset base\n");
 
        /* mark base as not ready, all channels disconnected */
-       atomic_set(&ucs->basstate, 0);
+       ucs->basstate = 0;
 
        /* tell LL all channels are down */
-       //FIXME shouldn't gigaset_stop() do this?
-       for (j = 0; j < 2; ++j)
+       for (j = 0; j < BAS_CHANNELS; ++j)
                gigaset_bchannel_down(cs->bcs + j);
 
        /* stop driver (common part) */
@@ -2295,9 +2361,113 @@ static void gigaset_disconnect(struct usb_interface *interface)
        ucs->interface = NULL;
        ucs->udev = NULL;
        cs->dev = NULL;
-       gigaset_unassign(cs);
+       gigaset_freecs(cs);
 }
 
+/* gigaset_suspend
+ * This function is called before the USB connection is suspended.
+ */
+static int gigaset_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       struct cardstate *cs = usb_get_intfdata(intf);
+       struct bas_cardstate *ucs = cs->hw.bas;
+       int rc;
+
+       /* set suspend flag; this stops AT command/response traffic */
+       if (update_basstate(ucs, BS_SUSPEND, 0) & BS_SUSPEND) {
+               gig_dbg(DEBUG_SUSPEND, "already suspended");
+               return 0;
+       }
+
+       /* wait a bit for blocking conditions to go away */
+       rc = wait_event_timeout(ucs->waitqueue,
+                       !(ucs->basstate &
+                         (BS_B1OPEN|BS_B2OPEN|BS_ATRDPEND|BS_ATWRPEND)),
+                       BAS_TIMEOUT*HZ/10);
+       gig_dbg(DEBUG_SUSPEND, "wait_event_timeout() -> %d", rc);
+
+       /* check for conditions preventing suspend */
+       if (ucs->basstate & (BS_B1OPEN|BS_B2OPEN|BS_ATRDPEND|BS_ATWRPEND)) {
+               dev_warn(cs->dev, "cannot suspend:\n");
+               if (ucs->basstate & BS_B1OPEN)
+                       dev_warn(cs->dev, " B channel 1 open\n");
+               if (ucs->basstate & BS_B2OPEN)
+                       dev_warn(cs->dev, " B channel 2 open\n");
+               if (ucs->basstate & BS_ATRDPEND)
+                       dev_warn(cs->dev, " receiving AT reply\n");
+               if (ucs->basstate & BS_ATWRPEND)
+                       dev_warn(cs->dev, " sending AT command\n");
+               update_basstate(ucs, 0, BS_SUSPEND);
+               return -EBUSY;
+       }
+
+       /* close AT channel if open */
+       if (ucs->basstate & BS_ATOPEN) {
+               gig_dbg(DEBUG_SUSPEND, "closing AT channel");
+               rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, 0);
+               if (rc) {
+                       update_basstate(ucs, 0, BS_SUSPEND);
+                       return rc;
+               }
+               wait_event_timeout(ucs->waitqueue, !ucs->pending,
+                                  BAS_TIMEOUT*HZ/10);
+               /* in case of timeout, proceed anyway */
+       }
+
+       /* kill all URBs and timers that might still be pending */
+       usb_kill_urb(ucs->urb_ctrl);
+       usb_kill_urb(ucs->urb_int_in);
+       del_timer_sync(&ucs->timer_ctrl);
+
+       gig_dbg(DEBUG_SUSPEND, "suspend complete");
+       return 0;
+}
+
+/* gigaset_resume
+ * This function is called after the USB connection has been resumed.
+ */
+static int gigaset_resume(struct usb_interface *intf)
+{
+       struct cardstate *cs = usb_get_intfdata(intf);
+       struct bas_cardstate *ucs = cs->hw.bas;
+       int rc;
+
+       /* resubmit interrupt URB for spontaneous messages from base */
+       rc = usb_submit_urb(ucs->urb_int_in, GFP_KERNEL);
+       if (rc) {
+               dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
+                       get_usb_rcmsg(rc));
+               return rc;
+       }
+
+       /* clear suspend flag to reallow activity */
+       update_basstate(ucs, 0, BS_SUSPEND);
+
+       gig_dbg(DEBUG_SUSPEND, "resume complete");
+       return 0;
+}
+
+/* gigaset_pre_reset
+ * This function is called before the USB connection is reset.
+ */
+static int gigaset_pre_reset(struct usb_interface *intf)
+{
+       /* handle just like suspend */
+       return gigaset_suspend(intf, PMSG_ON);
+}
+
+/* gigaset_post_reset
+ * This function is called after the USB connection has been reset.
+ */
+static int gigaset_post_reset(struct usb_interface *intf)
+{
+       /* FIXME: send HD_DEVICE_INIT_ACK? */
+
+       /* resume operations */
+       return gigaset_resume(intf);
+}
+
+
 static const struct gigaset_ops gigops = {
        gigaset_write_cmd,
        gigaset_write_room,
@@ -2330,12 +2500,6 @@ static int __init bas_gigaset_init(void)
                                       &gigops, THIS_MODULE)) == NULL)
                goto error;
 
-       /* allocate memory for our device state and intialize it */
-       cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode,
-                                  GIGASET_MODULENAME);
-       if (!cardstate)
-               goto error;
-
        /* register this driver with the USB subsystem */
        result = usb_register(&gigaset_usb_driver);
        if (result < 0) {
@@ -2347,9 +2511,7 @@ static int __init bas_gigaset_init(void)
        info(DRIVER_DESC);
        return 0;
 
-error: if (cardstate)
-               gigaset_freecs(cardstate);
-       cardstate = NULL;
+error:
        if (driver)
                gigaset_freedriver(driver);
        driver = NULL;
@@ -2361,43 +2523,50 @@ error:  if (cardstate)
  */
 static void __exit bas_gigaset_exit(void)
 {
-       struct bas_cardstate *ucs = cardstate->hw.bas;
+       struct bas_cardstate *ucs;
+       int i;
 
        gigaset_blockdriver(driver); /* => probe will fail
                                      * => no gigaset_start any more
                                      */
 
-       gigaset_shutdown(cardstate);
-       /* from now on, no isdn callback should be possible */
-
-       /* close all still open channels */
-       if (atomic_read(&ucs->basstate) & BS_B1OPEN) {
-               gig_dbg(DEBUG_INIT, "closing B1 channel");
-               usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
-                               HD_CLOSE_B1CHANNEL, OUT_VENDOR_REQ, 0, 0,
-                               NULL, 0, BAS_TIMEOUT);
-       }
-       if (atomic_read(&ucs->basstate) & BS_B2OPEN) {
-               gig_dbg(DEBUG_INIT, "closing B2 channel");
-               usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
-                               HD_CLOSE_B2CHANNEL, OUT_VENDOR_REQ, 0, 0,
-                               NULL, 0, BAS_TIMEOUT);
-       }
-       if (atomic_read(&ucs->basstate) & BS_ATOPEN) {
-               gig_dbg(DEBUG_INIT, "closing AT channel");
-               usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
-                               HD_CLOSE_ATCHANNEL, OUT_VENDOR_REQ, 0, 0,
-                               NULL, 0, BAS_TIMEOUT);
+       /* stop all connected devices */
+       for (i = 0; i < driver->minors; i++) {
+               if (gigaset_shutdown(driver->cs + i) < 0)
+                       continue;               /* no device */
+               /* from now on, no isdn callback should be possible */
+
+               /* close all still open channels */
+               ucs = driver->cs[i].hw.bas;
+               if (ucs->basstate & BS_B1OPEN) {
+                       gig_dbg(DEBUG_INIT, "closing B1 channel");
+                       usb_control_msg(ucs->udev,
+                                       usb_sndctrlpipe(ucs->udev, 0),
+                                       HD_CLOSE_B1CHANNEL, OUT_VENDOR_REQ,
+                                       0, 0, NULL, 0, BAS_TIMEOUT);
+               }
+               if (ucs->basstate & BS_B2OPEN) {
+                       gig_dbg(DEBUG_INIT, "closing B2 channel");
+                       usb_control_msg(ucs->udev,
+                                       usb_sndctrlpipe(ucs->udev, 0),
+                                       HD_CLOSE_B2CHANNEL, OUT_VENDOR_REQ,
+                                       0, 0, NULL, 0, BAS_TIMEOUT);
+               }
+               if (ucs->basstate & BS_ATOPEN) {
+                       gig_dbg(DEBUG_INIT, "closing AT channel");
+                       usb_control_msg(ucs->udev,
+                                       usb_sndctrlpipe(ucs->udev, 0),
+                                       HD_CLOSE_ATCHANNEL, OUT_VENDOR_REQ,
+                                       0, 0, NULL, 0, BAS_TIMEOUT);
+               }
+               ucs->basstate = 0;
        }
-       atomic_set(&ucs->basstate, 0);
 
        /* deregister this driver with the USB subsystem */
        usb_deregister(&gigaset_usb_driver);
        /* this will call the disconnect-callback */
        /* from now on, no disconnect/probe callback should be running */
 
-       gigaset_freecs(cardstate);
-       cardstate = NULL;
        gigaset_freedriver(driver);
        driver = NULL;
 }
index acd417197d03dd6f46078bff2eff31fb05bf5414..aacedec4986fc7e98cc9f827b935274acc645a41 100644 (file)
@@ -31,7 +31,6 @@ MODULE_PARM_DESC(debug, "debug level");
 /* driver state flags */
 #define VALID_MINOR    0x01
 #define VALID_ID       0x02
-#define ASSIGNED       0x04
 
 void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
                        size_t len, const unsigned char *buf)
@@ -178,7 +177,7 @@ int gigaset_get_channel(struct bc_state *bcs)
        unsigned long flags;
 
        spin_lock_irqsave(&bcs->cs->lock, flags);
-       if (bcs->use_count) {
+       if (bcs->use_count || !try_module_get(bcs->cs->driver->owner)) {
                gig_dbg(DEBUG_ANY, "could not allocate channel %d",
                        bcs->channel);
                spin_unlock_irqrestore(&bcs->cs->lock, flags);
@@ -203,6 +202,7 @@ void gigaset_free_channel(struct bc_state *bcs)
        }
        --bcs->use_count;
        bcs->busy = 0;
+       module_put(bcs->cs->driver->owner);
        gig_dbg(DEBUG_ANY, "freed channel %d", bcs->channel);
        spin_unlock_irqrestore(&bcs->cs->lock, flags);
 }
@@ -356,31 +356,28 @@ static struct cardstate *alloc_cs(struct gigaset_driver *drv)
 {
        unsigned long flags;
        unsigned i;
+       struct cardstate *cs;
        struct cardstate *ret = NULL;
 
        spin_lock_irqsave(&drv->lock, flags);
+       if (drv->blocked)
+               goto exit;
        for (i = 0; i < drv->minors; ++i) {
-               if (!(drv->flags[i] & VALID_MINOR)) {
-                       if (try_module_get(drv->owner)) {
-                               drv->flags[i] = VALID_MINOR;
-                               ret = drv->cs + i;
-                       }
+               cs = drv->cs + i;
+               if (!(cs->flags & VALID_MINOR)) {
+                       cs->flags = VALID_MINOR;
+                       ret = cs;
                        break;
                }
        }
+exit:
        spin_unlock_irqrestore(&drv->lock, flags);
        return ret;
 }
 
 static void free_cs(struct cardstate *cs)
 {
-       unsigned long flags;
-       struct gigaset_driver *drv = cs->driver;
-       spin_lock_irqsave(&drv->lock, flags);
-       if (drv->flags[cs->minor_index] & VALID_MINOR)
-               module_put(drv->owner);
-       drv->flags[cs->minor_index] = 0;
-       spin_unlock_irqrestore(&drv->lock, flags);
+       cs->flags = 0;
 }
 
 static void make_valid(struct cardstate *cs, unsigned mask)
@@ -388,7 +385,7 @@ static void make_valid(struct cardstate *cs, unsigned mask)
        unsigned long flags;
        struct gigaset_driver *drv = cs->driver;
        spin_lock_irqsave(&drv->lock, flags);
-       drv->flags[cs->minor_index] |= mask;
+       cs->flags |= mask;
        spin_unlock_irqrestore(&drv->lock, flags);
 }
 
@@ -397,7 +394,7 @@ static void make_invalid(struct cardstate *cs, unsigned mask)
        unsigned long flags;
        struct gigaset_driver *drv = cs->driver;
        spin_lock_irqsave(&drv->lock, flags);
-       drv->flags[cs->minor_index] &= ~mask;
+       cs->flags &= ~mask;
        spin_unlock_irqrestore(&drv->lock, flags);
 }
 
@@ -501,11 +498,11 @@ static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
                               struct cardstate *cs, int inputstate)
 /* inbuf->read must be allocated before! */
 {
-       atomic_set(&inbuf->head, 0);
-       atomic_set(&inbuf->tail, 0);
+       inbuf->head = 0;
+       inbuf->tail = 0;
        inbuf->cs = cs;
        inbuf->bcs = bcs; /*base driver: NULL*/
-       inbuf->rcvbuf = NULL; //FIXME
+       inbuf->rcvbuf = NULL;
        inbuf->inputstate = inputstate;
 }
 
@@ -521,8 +518,8 @@ int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
                return 0;
 
        bytesleft = numbytes;
-       tail = atomic_read(&inbuf->tail);
-       head = atomic_read(&inbuf->head);
+       tail = inbuf->tail;
+       head = inbuf->head;
        gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
 
        while (bytesleft) {
@@ -546,7 +543,7 @@ int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
                src += n;
        }
        gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
-       atomic_set(&inbuf->tail, tail);
+       inbuf->tail = tail;
        return numbytes != bytesleft;
 }
 EXPORT_SYMBOL_GPL(gigaset_fill_inbuf);
@@ -668,7 +665,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
 
        tasklet_init(&cs->event_tasklet, &gigaset_handle_event,
                     (unsigned long) cs);
-       atomic_set(&cs->commands_pending, 0);
+       cs->commands_pending = 0;
        cs->cur_at_seq = 0;
        cs->gotfwver = -1;
        cs->open_count = 0;
@@ -688,8 +685,8 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
        init_waitqueue_head(&cs->waitqueue);
        cs->waiting = 0;
 
-       atomic_set(&cs->mode, M_UNKNOWN);
-       atomic_set(&cs->mstate, MS_UNINITIALIZED);
+       cs->mode = M_UNKNOWN;
+       cs->mstate = MS_UNINITIALIZED;
 
        for (i = 0; i < channels; ++i) {
                gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
@@ -806,8 +803,8 @@ static void cleanup_cs(struct cardstate *cs)
 
        spin_lock_irqsave(&cs->lock, flags);
 
-       atomic_set(&cs->mode, M_UNKNOWN);
-       atomic_set(&cs->mstate, MS_UNINITIALIZED);
+       cs->mode = M_UNKNOWN;
+       cs->mstate = MS_UNINITIALIZED;
 
        clear_at_state(&cs->at_state);
        dealloc_at_states(cs);
@@ -817,8 +814,8 @@ static void cleanup_cs(struct cardstate *cs)
        kfree(cs->inbuf->rcvbuf);
        cs->inbuf->rcvbuf = NULL;
        cs->inbuf->inputstate = INS_command;
-       atomic_set(&cs->inbuf->head, 0);
-       atomic_set(&cs->inbuf->tail, 0);
+       cs->inbuf->head = 0;
+       cs->inbuf->tail = 0;
 
        cb = cs->cmdbuf;
        while (cb) {
@@ -832,7 +829,7 @@ static void cleanup_cs(struct cardstate *cs)
        cs->gotfwver = -1;
        cs->dle = 0;
        cs->cur_at_seq = 0;
-       atomic_set(&cs->commands_pending, 0);
+       cs->commands_pending = 0;
        cs->cbytes = 0;
 
        spin_unlock_irqrestore(&cs->lock, flags);
@@ -862,7 +859,7 @@ int gigaset_start(struct cardstate *cs)
        cs->connected = 1;
        spin_unlock_irqrestore(&cs->lock, flags);
 
-       if (atomic_read(&cs->mstate) != MS_LOCKED) {
+       if (cs->mstate != MS_LOCKED) {
                cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
                cs->ops->baud_rate(cs, B115200);
                cs->ops->set_line_ctrl(cs, CS8);
@@ -893,10 +890,17 @@ error:
 }
 EXPORT_SYMBOL_GPL(gigaset_start);
 
-void gigaset_shutdown(struct cardstate *cs)
+/* gigaset_shutdown
+ * check if a device is associated to the cardstate structure and stop it
+ * return value: 0 if ok, -1 if no device was associated
+ */
+int gigaset_shutdown(struct cardstate *cs)
 {
        mutex_lock(&cs->mutex);
 
+       if (!(cs->flags & VALID_MINOR))
+               return -1;
+
        cs->waiting = 1;
 
        if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL)) {
@@ -913,6 +917,7 @@ void gigaset_shutdown(struct cardstate *cs)
 
 exit:
        mutex_unlock(&cs->mutex);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(gigaset_shutdown);
 
@@ -954,13 +959,11 @@ struct cardstate *gigaset_get_cs_by_id(int id)
        list_for_each_entry(drv, &drivers, list) {
                spin_lock(&drv->lock);
                for (i = 0; i < drv->minors; ++i) {
-                       if (drv->flags[i] & VALID_ID) {
-                               cs = drv->cs + i;
-                               if (cs->myid == id)
-                                       ret = cs;
-                       }
-                       if (ret)
+                       cs = drv->cs + i;
+                       if ((cs->flags & VALID_ID) && cs->myid == id) {
+                               ret = cs;
                                break;
+                       }
                }
                spin_unlock(&drv->lock);
                if (ret)
@@ -983,10 +986,9 @@ void gigaset_debugdrivers(void)
                spin_lock(&drv->lock);
                for (i = 0; i < drv->minors; ++i) {
                        gig_dbg(DEBUG_DRIVER, "  index %u", i);
-                       gig_dbg(DEBUG_DRIVER, "    flags 0x%02x",
-                               drv->flags[i]);
                        cs = drv->cs + i;
                        gig_dbg(DEBUG_DRIVER, "    cardstate %p", cs);
+                       gig_dbg(DEBUG_DRIVER, "    flags 0x%02x", cs->flags);
                        gig_dbg(DEBUG_DRIVER, "    minor_index %u",
                                cs->minor_index);
                        gig_dbg(DEBUG_DRIVER, "    driver %p", cs->driver);
@@ -1010,7 +1012,7 @@ static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
                        continue;
                index = minor - drv->minor;
                spin_lock(&drv->lock);
-               if (drv->flags[index] & VALID_MINOR)
+               if (drv->cs[index].flags & VALID_MINOR)
                        ret = drv->cs + index;
                spin_unlock(&drv->lock);
                if (ret)
@@ -1038,7 +1040,6 @@ void gigaset_freedriver(struct gigaset_driver *drv)
        gigaset_if_freedriver(drv);
 
        kfree(drv->cs);
-       kfree(drv->flags);
        kfree(drv);
 }
 EXPORT_SYMBOL_GPL(gigaset_freedriver);
@@ -1080,12 +1081,8 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
        if (!drv->cs)
                goto error;
 
-       drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
-       if (!drv->flags)
-               goto error;
-
        for (i = 0; i < minors; ++i) {
-               drv->flags[i] = 0;
+               drv->cs[i].flags = 0;
                drv->cs[i].driver = drv;
                drv->cs[i].ops = drv->ops;
                drv->cs[i].minor_index = i;
@@ -1106,53 +1103,9 @@ error:
 }
 EXPORT_SYMBOL_GPL(gigaset_initdriver);
 
-/* For drivers without fixed assignment device<->cardstate (usb) */
-struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv)
-{
-       unsigned long flags;
-       struct cardstate *cs = NULL;
-       unsigned i;
-
-       spin_lock_irqsave(&drv->lock, flags);
-       if (drv->blocked)
-               goto exit;
-       for (i = 0; i < drv->minors; ++i) {
-               if ((drv->flags[i] & VALID_MINOR) &&
-                   !(drv->flags[i] & ASSIGNED)) {
-                       drv->flags[i] |= ASSIGNED;
-                       cs = drv->cs + i;
-                       break;
-               }
-       }
-exit:
-       spin_unlock_irqrestore(&drv->lock, flags);
-       return cs;
-}
-EXPORT_SYMBOL_GPL(gigaset_getunassignedcs);
-
-void gigaset_unassign(struct cardstate *cs)
-{
-       unsigned long flags;
-       unsigned *minor_flags;
-       struct gigaset_driver *drv;
-
-       if (!cs)
-               return;
-       drv = cs->driver;
-       spin_lock_irqsave(&drv->lock, flags);
-       minor_flags = drv->flags + cs->minor_index;
-       if (*minor_flags & VALID_MINOR)
-               *minor_flags &= ~ASSIGNED;
-       spin_unlock_irqrestore(&drv->lock, flags);
-}
-EXPORT_SYMBOL_GPL(gigaset_unassign);
-
 void gigaset_blockdriver(struct gigaset_driver *drv)
 {
-       unsigned long flags;
-       spin_lock_irqsave(&drv->lock, flags);
        drv->blocked = 1;
-       spin_unlock_irqrestore(&drv->lock, flags);
 }
 EXPORT_SYMBOL_GPL(gigaset_blockdriver);
 
index cec1ef342fcc31369ebf0f1a7c2f8a56437b5dff..5cbf64d850eefbbb4405d670d969f5938e38148e 100644 (file)
@@ -735,7 +735,7 @@ static void disconnect(struct at_state_t **at_state_p)
        /* revert to selected idle mode */
        if (!cs->cidmode) {
                cs->at_state.pending_commands |= PC_UMMODE;
-               atomic_set(&cs->commands_pending, 1); //FIXME
+               cs->commands_pending = 1;
                gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
        }
        spin_unlock_irqrestore(&cs->lock, flags);
@@ -793,15 +793,15 @@ static void init_failed(struct cardstate *cs, int mode)
        struct at_state_t *at_state;
 
        cs->at_state.pending_commands &= ~PC_INIT;
-       atomic_set(&cs->mode, mode);
-       atomic_set(&cs->mstate, MS_UNINITIALIZED);
+       cs->mode = mode;
+       cs->mstate = MS_UNINITIALIZED;
        gigaset_free_channels(cs);
        for (i = 0; i < cs->channels; ++i) {
                at_state = &cs->bcs[i].at_state;
                if (at_state->pending_commands & PC_CID) {
                        at_state->pending_commands &= ~PC_CID;
                        at_state->pending_commands |= PC_NOCID;
-                       atomic_set(&cs->commands_pending, 1);
+                       cs->commands_pending = 1;
                }
        }
 }
@@ -812,11 +812,11 @@ static void schedule_init(struct cardstate *cs, int state)
                gig_dbg(DEBUG_CMD, "not scheduling PC_INIT again");
                return;
        }
-       atomic_set(&cs->mstate, state);
-       atomic_set(&cs->mode, M_UNKNOWN);
+       cs->mstate = state;
+       cs->mode = M_UNKNOWN;
        gigaset_block_channels(cs);
        cs->at_state.pending_commands |= PC_INIT;
-       atomic_set(&cs->commands_pending, 1);
+       cs->commands_pending = 1;
        gig_dbg(DEBUG_CMD, "Scheduling PC_INIT");
 }
 
@@ -953,13 +953,13 @@ static void start_dial(struct at_state_t *at_state, void *data, unsigned seq_ind
 
        at_state->pending_commands |= PC_CID;
        gig_dbg(DEBUG_CMD, "Scheduling PC_CID");
-       atomic_set(&cs->commands_pending, 1);
+       cs->commands_pending = 1;
        return;
 
 error:
        at_state->pending_commands |= PC_NOCID;
        gig_dbg(DEBUG_CMD, "Scheduling PC_NOCID");
-       atomic_set(&cs->commands_pending, 1);
+       cs->commands_pending = 1;
        return;
 }
 
@@ -973,12 +973,12 @@ static void start_accept(struct at_state_t *at_state)
        if (retval == 0) {
                at_state->pending_commands |= PC_ACCEPT;
                gig_dbg(DEBUG_CMD, "Scheduling PC_ACCEPT");
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
        } else {
-               //FIXME
+               /* error reset */
                at_state->pending_commands |= PC_HUP;
                gig_dbg(DEBUG_CMD, "Scheduling PC_HUP");
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
        }
 }
 
@@ -986,7 +986,7 @@ static void do_start(struct cardstate *cs)
 {
        gigaset_free_channels(cs);
 
-       if (atomic_read(&cs->mstate) != MS_LOCKED)
+       if (cs->mstate != MS_LOCKED)
                schedule_init(cs, MS_INIT);
 
        cs->isdn_up = 1;
@@ -1000,9 +1000,9 @@ static void do_start(struct cardstate *cs)
 
 static void finish_shutdown(struct cardstate *cs)
 {
-       if (atomic_read(&cs->mstate) != MS_LOCKED) {
-               atomic_set(&cs->mstate, MS_UNINITIALIZED);
-               atomic_set(&cs->mode, M_UNKNOWN);
+       if (cs->mstate != MS_LOCKED) {
+               cs->mstate = MS_UNINITIALIZED;
+               cs->mode = M_UNKNOWN;
        }
 
        /* Tell the LL that the device is not available .. */
@@ -1022,10 +1022,10 @@ static void do_shutdown(struct cardstate *cs)
 {
        gigaset_block_channels(cs);
 
-       if (atomic_read(&cs->mstate) == MS_READY) {
-               atomic_set(&cs->mstate, MS_SHUTDOWN);
+       if (cs->mstate == MS_READY) {
+               cs->mstate = MS_SHUTDOWN;
                cs->at_state.pending_commands |= PC_SHUTDOWN;
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
                gig_dbg(DEBUG_CMD, "Scheduling PC_SHUTDOWN");
        } else
                finish_shutdown(cs);
@@ -1120,7 +1120,7 @@ static void handle_icall(struct cardstate *cs, struct bc_state *bcs,
                 * In fact it doesn't.
                 */
                at_state->pending_commands |= PC_HUP;
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
                break;
        }
 }
@@ -1130,7 +1130,7 @@ static int do_lock(struct cardstate *cs)
        int mode;
        int i;
 
-       switch (atomic_read(&cs->mstate)) {
+       switch (cs->mstate) {
        case MS_UNINITIALIZED:
        case MS_READY:
                if (cs->cur_at_seq || !list_empty(&cs->temp_at_states) ||
@@ -1152,20 +1152,20 @@ static int do_lock(struct cardstate *cs)
                return -EBUSY;
        }
 
-       mode = atomic_read(&cs->mode);
-       atomic_set(&cs->mstate, MS_LOCKED);
-       atomic_set(&cs->mode, M_UNKNOWN);
+       mode = cs->mode;
+       cs->mstate = MS_LOCKED;
+       cs->mode = M_UNKNOWN;
 
        return mode;
 }
 
 static int do_unlock(struct cardstate *cs)
 {
-       if (atomic_read(&cs->mstate) != MS_LOCKED)
+       if (cs->mstate != MS_LOCKED)
                return -EINVAL;
 
-       atomic_set(&cs->mstate, MS_UNINITIALIZED);
-       atomic_set(&cs->mode, M_UNKNOWN);
+       cs->mstate = MS_UNINITIALIZED;
+       cs->mode = M_UNKNOWN;
        gigaset_free_channels(cs);
        if (cs->connected)
                schedule_init(cs, MS_INIT);
@@ -1198,17 +1198,17 @@ static void do_action(int action, struct cardstate *cs,
        case ACT_INIT:
                cs->at_state.pending_commands &= ~PC_INIT;
                cs->cur_at_seq = SEQ_NONE;
-               atomic_set(&cs->mode, M_UNIMODEM);
+               cs->mode = M_UNIMODEM;
                spin_lock_irqsave(&cs->lock, flags);
                if (!cs->cidmode) {
                        spin_unlock_irqrestore(&cs->lock, flags);
                        gigaset_free_channels(cs);
-                       atomic_set(&cs->mstate, MS_READY);
+                       cs->mstate = MS_READY;
                        break;
                }
                spin_unlock_irqrestore(&cs->lock, flags);
                cs->at_state.pending_commands |= PC_CIDMODE;
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
                gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
                break;
        case ACT_FAILINIT:
@@ -1234,22 +1234,20 @@ static void do_action(int action, struct cardstate *cs,
                        | INS_command;
                break;
        case ACT_CMODESET:
-               if (atomic_read(&cs->mstate) == MS_INIT ||
-                   atomic_read(&cs->mstate) == MS_RECOVER) {
+               if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) {
                        gigaset_free_channels(cs);
-                       atomic_set(&cs->mstate, MS_READY);
+                       cs->mstate = MS_READY;
                }
-               atomic_set(&cs->mode, M_CID);
+               cs->mode = M_CID;
                cs->cur_at_seq = SEQ_NONE;
                break;
        case ACT_UMODESET:
-               atomic_set(&cs->mode, M_UNIMODEM);
+               cs->mode = M_UNIMODEM;
                cs->cur_at_seq = SEQ_NONE;
                break;
        case ACT_FAILCMODE:
                cs->cur_at_seq = SEQ_NONE;
-               if (atomic_read(&cs->mstate) == MS_INIT ||
-                   atomic_read(&cs->mstate) == MS_RECOVER) {
+               if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) {
                        init_failed(cs, M_UNKNOWN);
                        break;
                }
@@ -1307,7 +1305,7 @@ static void do_action(int action, struct cardstate *cs,
        case ACT_CONNECT:
                if (cs->onechannel) {
                        at_state->pending_commands |= PC_DLE1;
-                       atomic_set(&cs->commands_pending, 1);
+                       cs->commands_pending = 1;
                        break;
                }
                bcs->chstate |= CHS_D_UP;
@@ -1333,7 +1331,7 @@ static void do_action(int action, struct cardstate *cs,
                         * DLE only used for M10x with one B channel.
                         */
                        at_state->pending_commands |= PC_DLE0;
-                       atomic_set(&cs->commands_pending, 1);
+                       cs->commands_pending = 1;
                } else
                        disconnect(p_at_state);
                break;
@@ -1369,7 +1367,7 @@ static void do_action(int action, struct cardstate *cs,
                         "Could not enter DLE mode. Trying to hang up.\n");
                channel = cs->curchannel;
                cs->bcs[channel].at_state.pending_commands |= PC_HUP;
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
                break;
 
        case ACT_CID: /* got cid; start dialing */
@@ -1379,7 +1377,7 @@ static void do_action(int action, struct cardstate *cs,
                        cs->bcs[channel].at_state.cid = ev->parameter;
                        cs->bcs[channel].at_state.pending_commands |=
                                PC_DIAL;
-                       atomic_set(&cs->commands_pending, 1);
+                       cs->commands_pending = 1;
                        break;
                }
                /* fall through */
@@ -1411,14 +1409,14 @@ static void do_action(int action, struct cardstate *cs,
        case ACT_ABORTDIAL:     /* error/timeout during dial preparation */
                cs->cur_at_seq = SEQ_NONE;
                at_state->pending_commands |= PC_HUP;
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
                break;
 
        case ACT_REMOTEREJECT:  /* DISCONNECT_IND after dialling */
        case ACT_CONNTIMEOUT:   /* timeout waiting for ZSAU=ACTIVE */
        case ACT_REMOTEHUP:     /* DISCONNECT_IND with established connection */
                at_state->pending_commands |= PC_HUP;
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
                break;
        case ACT_GETSTRING: /* warning: RING, ZDLE, ...
                               are not handled properly anymore */
@@ -1515,7 +1513,7 @@ static void do_action(int action, struct cardstate *cs,
                break;
        case ACT_HUP:
                at_state->pending_commands |= PC_HUP;
-               atomic_set(&cs->commands_pending, 1);
+               cs->commands_pending = 1;
                gig_dbg(DEBUG_CMD, "Scheduling PC_HUP");
                break;
 
@@ -1558,7 +1556,7 @@ static void do_action(int action, struct cardstate *cs,
                                cs->at_state.pending_commands |= PC_UMMODE;
                                gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
                        }
-                       atomic_set(&cs->commands_pending, 1);
+                       cs->commands_pending = 1;
                }
                spin_unlock_irqrestore(&cs->lock, flags);
                cs->waiting = 0;
@@ -1741,7 +1739,7 @@ static void process_command_flags(struct cardstate *cs)
        int sequence;
        unsigned long flags;
 
-       atomic_set(&cs->commands_pending, 0);
+       cs->commands_pending = 0;
 
        if (cs->cur_at_seq) {
                gig_dbg(DEBUG_CMD, "not searching scheduled commands: busy");
@@ -1779,7 +1777,7 @@ static void process_command_flags(struct cardstate *cs)
                                ~(PC_DLE1 | PC_ACCEPT | PC_DIAL);
                        if (at_state->cid > 0)
                                at_state->pending_commands |= PC_HUP;
-                       if (atomic_read(&cs->mstate) == MS_RECOVER) {
+                       if (cs->mstate == MS_RECOVER) {
                                if (at_state->pending_commands & PC_CID) {
                                        at_state->pending_commands |= PC_NOCID;
                                        at_state->pending_commands &= ~PC_CID;
@@ -1793,7 +1791,7 @@ static void process_command_flags(struct cardstate *cs)
        if (cs->at_state.pending_commands == PC_UMMODE
            && !cs->cidmode
            && list_empty(&cs->temp_at_states)
-           && atomic_read(&cs->mode) == M_CID) {
+           && cs->mode == M_CID) {
                sequence = SEQ_UMMODE;
                at_state = &cs->at_state;
                for (i = 0; i < cs->channels; ++i) {
@@ -1860,7 +1858,7 @@ static void process_command_flags(struct cardstate *cs)
        }
        if (cs->at_state.pending_commands & PC_CIDMODE) {
                cs->at_state.pending_commands &= ~PC_CIDMODE;
-               if (atomic_read(&cs->mode) == M_UNIMODEM) {
+               if (cs->mode == M_UNIMODEM) {
                        cs->retry_count = 1;
                        schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE);
                        return;
@@ -1886,11 +1884,11 @@ static void process_command_flags(struct cardstate *cs)
                        return;
                }
                if (bcs->at_state.pending_commands & PC_CID) {
-                       switch (atomic_read(&cs->mode)) {
+                       switch (cs->mode) {
                        case M_UNIMODEM:
                                cs->at_state.pending_commands |= PC_CIDMODE;
                                gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
-                               atomic_set(&cs->commands_pending, 1);
+                               cs->commands_pending = 1;
                                return;
 #ifdef GIG_MAYINITONDIAL
                        case M_UNKNOWN:
@@ -1926,7 +1924,7 @@ static void process_events(struct cardstate *cs)
        for (i = 0; i < 2 * MAX_EVENTS; ++i) {
                tail = cs->ev_tail;
                if (tail == head) {
-                       if (!check_flags && !atomic_read(&cs->commands_pending))
+                       if (!check_flags && !cs->commands_pending)
                                break;
                        check_flags = 0;
                        spin_unlock_irqrestore(&cs->ev_lock, flags);
@@ -1934,7 +1932,7 @@ static void process_events(struct cardstate *cs)
                        spin_lock_irqsave(&cs->ev_lock, flags);
                        tail = cs->ev_tail;
                        if (tail == head) {
-                               if (!atomic_read(&cs->commands_pending))
+                               if (!cs->commands_pending)
                                        break;
                                continue;
                        }
@@ -1971,7 +1969,7 @@ void gigaset_handle_event(unsigned long data)
        struct cardstate *cs = (struct cardstate *) data;
 
        /* handle incoming data on control/common channel */
-       if (atomic_read(&cs->inbuf->head) != atomic_read(&cs->inbuf->tail)) {
+       if (cs->inbuf->head != cs->inbuf->tail) {
                gig_dbg(DEBUG_INTR, "processing new data");
                cs->ops->handle_input(cs->inbuf);
        }
index 02bdaf22d7ea10b28cbe779dd6097ce52b318b17..f365993161fcc6a2a8432e4d890c9ddef45b628a 100644 (file)
 
 extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
 
-/* any combination of these can be given with the 'debug=' parameter to insmod,
- * e.g. 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and
- * DEBUG_INTR.
- */
+/* debug flags, combine by adding/bitwise OR */
 enum debuglevel {
-       DEBUG_REG         = 0x0002, /* serial port I/O register operations */
-       DEBUG_OPEN        = 0x0004, /* open/close serial port */
-       DEBUG_INTR        = 0x0008, /* interrupt processing */
-       DEBUG_INTR_DUMP   = 0x0010, /* Activating hexdump debug output on
-                                      interrupt requests, not available as
-                                      run-time option */
+       DEBUG_INTR        = 0x00008, /* interrupt processing */
        DEBUG_CMD         = 0x00020, /* sent/received LL commands */
        DEBUG_STREAM      = 0x00040, /* application data stream I/O events */
        DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */
        DEBUG_LLDATA      = 0x00100, /* sent/received LL data */
-       DEBUG_INTR_0      = 0x00200, /* serial port interrupt processing */
        DEBUG_DRIVER      = 0x00400, /* driver structure */
        DEBUG_HDLC        = 0x00800, /* M10x HDLC processing */
        DEBUG_WRITE       = 0x01000, /* M105 data write */
@@ -93,7 +84,7 @@ enum debuglevel {
        DEBUG_MCMD        = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */
        DEBUG_INIT        = 0x08000, /* (de)allocation+initialization of data
                                        structures */
-       DEBUG_LOCK        = 0x10000, /* semaphore operations */
+       DEBUG_SUSPEND     = 0x10000, /* suspend/resume processing */
        DEBUG_OUTPUT      = 0x20000, /* output to device */
        DEBUG_ISO         = 0x40000, /* isochronous transfers */
        DEBUG_IF          = 0x80000, /* character device operations */
@@ -191,6 +182,9 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
 #define        HD_OPEN_ATCHANNEL               (0x28)          // 3070
 #define        HD_CLOSE_ATCHANNEL              (0x29)          // 3070
 
+/* number of B channels supported by base driver */
+#define BAS_CHANNELS   2
+
 /* USB frames for isochronous transfer */
 #define BAS_FRAMETIME  1       /* number of milliseconds between frames */
 #define BAS_NUMFRAMES  8       /* number of frames per URB */
@@ -313,7 +307,7 @@ struct inbuf_t {
        struct bc_state         *bcs;
        struct cardstate        *cs;
        int                     inputstate;
-       atomic_t                head, tail;
+       int                     head, tail;
        unsigned char           data[RBUFSIZE];
 };
 
@@ -335,9 +329,9 @@ struct inbuf_t {
  *   are also filled with that value
  */
 struct isowbuf_t {
-       atomic_t        read;
-       atomic_t        nextread;
-       atomic_t        write;
+       int             read;
+       int             nextread;
+       int             write;
        atomic_t        writesem;
        int             wbits;
        unsigned char   data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD];
@@ -350,11 +344,13 @@ struct isowbuf_t {
  * - urb: pointer to the URB itself
  * - bcs: pointer to the B Channel control structure
  * - limit: end of write buffer area covered by this URB
+ * - status: URB completion status
  */
 struct isow_urbctx_t {
        struct urb *urb;
        struct bc_state *bcs;
        int limit;
+       int status;
 };
 
 /* AT state structure
@@ -439,14 +435,15 @@ struct cardstate {
        unsigned minor_index;
        struct device *dev;
        struct device *tty_dev;
+       unsigned flags;
 
        const struct gigaset_ops *ops;
 
        /* Stuff to handle communication */
        wait_queue_head_t waitqueue;
        int waiting;
-       atomic_t mode;                  /* see M_XXXX */
-       atomic_t mstate;                /* Modem state: see MS_XXXX */
+       int mode;                       /* see M_XXXX */
+       int mstate;                     /* Modem state: see MS_XXXX */
                                        /* only changed by the event layer */
        int cmd_result;
 
@@ -503,7 +500,7 @@ struct cardstate {
                                           processed */
        int curchannel;                 /* channel those commands are meant
                                           for */
-       atomic_t commands_pending;      /* flag(s) in xxx.commands_pending have
+       int commands_pending;           /* flag(s) in xxx.commands_pending have
                                           been set */
        struct tasklet_struct event_tasklet;
                                        /* tasklet for serializing AT commands.
@@ -543,7 +540,6 @@ struct gigaset_driver {
        unsigned minor;
        unsigned minors;
        struct cardstate *cs;
-       unsigned *flags;
        int blocked;
 
        const struct gigaset_ops *ops;
@@ -559,7 +555,7 @@ struct cmdbuf_t {
 
 struct bas_bc_state {
        /* isochronous output state */
-       atomic_t        running;
+       int             running;
        atomic_t        corrbytes;
        spinlock_t      isooutlock;
        struct isow_urbctx_t    isoouturbs[BAS_OUTURBS];
@@ -574,6 +570,7 @@ struct bas_bc_state {
        struct urb *isoinurbs[BAS_INURBS];
        unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
        struct urb *isoindone;          /* completed isoc read URB */
+       int isoinstatus;                /* status of completed URB */
        int loststatus;                 /* status of dropped URB */
        unsigned isoinlost;             /* number of bytes lost */
        /* state of bit unstuffing algorithm
@@ -770,10 +767,6 @@ void gigaset_freedriver(struct gigaset_driver *drv);
 void gigaset_debugdrivers(void);
 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
 struct cardstate *gigaset_get_cs_by_id(int id);
-
-/* For drivers without fixed assignment device<->cardstate (usb) */
-struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv);
-void gigaset_unassign(struct cardstate *cs);
 void gigaset_blockdriver(struct gigaset_driver *drv);
 
 /* Allocate and initialize card state. Calls hardware dependent
@@ -792,7 +785,7 @@ int gigaset_start(struct cardstate *cs);
 void gigaset_stop(struct cardstate *cs);
 
 /* Tell common.c that the driver is being unloaded. */
-void gigaset_shutdown(struct cardstate *cs);
+int gigaset_shutdown(struct cardstate *cs);
 
 /* Tell common.c that an skb has been sent. */
 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
index eb50f3dab5f77908ecc6111da0911b1a3370b9c2..af195b07c191b6b02b09c57548f6477334672a92 100644 (file)
@@ -28,12 +28,11 @@ static int if_lock(struct cardstate *cs, int *arg)
                return -EINVAL;
 
        if (cmd < 0) {
-               *arg = atomic_read(&cs->mstate) == MS_LOCKED; //FIXME remove?
+               *arg = cs->mstate == MS_LOCKED;
                return 0;
        }
 
-       if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
-           && cs->connected) {
+       if (!cmd && cs->mstate == MS_LOCKED && cs->connected) {
                cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
                cs->ops->baud_rate(cs, B115200);
                cs->ops->set_line_ctrl(cs, CS8);
@@ -104,7 +103,7 @@ static int if_config(struct cardstate *cs, int *arg)
        if (*arg != 1)
                return -EINVAL;
 
-       if (atomic_read(&cs->mstate) != MS_LOCKED)
+       if (cs->mstate != MS_LOCKED)
                return -EBUSY;
 
        if (!cs->connected) {
@@ -162,7 +161,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
        tty->driver_data = NULL;
 
        cs = gigaset_get_cs_by_tty(tty);
-       if (!cs)
+       if (!cs || !try_module_get(cs->driver->owner))
                return -ENODEV;
 
        if (mutex_lock_interruptible(&cs->mutex))
@@ -208,6 +207,8 @@ static void if_close(struct tty_struct *tty, struct file *filp)
        }
 
        mutex_unlock(&cs->mutex);
+
+       module_put(cs->driver->owner);
 }
 
 static int if_ioctl(struct tty_struct *tty, struct file *file,
@@ -364,7 +365,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
-       else if (atomic_read(&cs->mstate) != MS_LOCKED) {
+       else if (cs->mstate != MS_LOCKED) {
                warn("can't write to unlocked device");
                retval = -EBUSY;
        } else if (!cs->connected) {
@@ -398,9 +399,9 @@ static int if_write_room(struct tty_struct *tty)
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
-       else if (atomic_read(&cs->mstate) != MS_LOCKED) {
+       else if (cs->mstate != MS_LOCKED) {
                warn("can't write to unlocked device");
-               retval = -EBUSY; //FIXME
+               retval = -EBUSY;
        } else if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't write to unplugged device");
                retval = -EBUSY; //FIXME
@@ -430,7 +431,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
-       else if (atomic_read(&cs->mstate) != MS_LOCKED) {
+       else if (cs->mstate != MS_LOCKED) {
                warn("can't write to unlocked device");
                retval = -EBUSY;
        } else if (!cs->connected) {
index e0505f238807ab4f3fbd285cb499bc15191f034f..e30a7773f93cefecdf315db52daf65c12948f4be 100644 (file)
@@ -23,9 +23,9 @@
  */
 void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle)
 {
-       atomic_set(&iwb->read, 0);
-       atomic_set(&iwb->nextread, 0);
-       atomic_set(&iwb->write, 0);
+       iwb->read = 0;
+       iwb->nextread = 0;
+       iwb->write = 0;
        atomic_set(&iwb->writesem, 1);
        iwb->wbits = 0;
        iwb->idle = idle;
@@ -39,8 +39,8 @@ static inline int isowbuf_freebytes(struct isowbuf_t *iwb)
 {
        int read, write, freebytes;
 
-       read = atomic_read(&iwb->read);
-       write = atomic_read(&iwb->write);
+       read = iwb->read;
+       write = iwb->write;
        if ((freebytes = read - write) > 0) {
                /* no wraparound: need padding space within regular area */
                return freebytes - BAS_OUTBUFPAD;
@@ -62,7 +62,7 @@ static inline int isowbuf_poscmp(struct isowbuf_t *iwb, int a, int b)
        int read;
        if (a == b)
                return 0;
-       read = atomic_read(&iwb->read);
+       read = iwb->read;
        if (a < b) {
                if (a < read && read <= b)
                        return +1;
@@ -91,18 +91,18 @@ static inline int isowbuf_startwrite(struct isowbuf_t *iwb)
 #ifdef CONFIG_GIGASET_DEBUG
        gig_dbg(DEBUG_ISO,
                "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d",
-               __func__, iwb->data[atomic_read(&iwb->write)], iwb->wbits);
+               __func__, iwb->data[iwb->write], iwb->wbits);
 #endif
        return 1;
 }
 
 /* finish writing
- * release the write semaphore and update the maximum buffer fill level
+ * release the write semaphore
  * returns the current write position
  */
 static inline int isowbuf_donewrite(struct isowbuf_t *iwb)
 {
-       int write = atomic_read(&iwb->write);
+       int write = iwb->write;
        atomic_inc(&iwb->writesem);
        return write;
 }
@@ -116,7 +116,7 @@ static inline int isowbuf_donewrite(struct isowbuf_t *iwb)
  */
 static inline void isowbuf_putbits(struct isowbuf_t *iwb, u32 data, int nbits)
 {
-       int write = atomic_read(&iwb->write);
+       int write = iwb->write;
        data <<= iwb->wbits;
        data |= iwb->data[write];
        nbits += iwb->wbits;
@@ -128,7 +128,7 @@ static inline void isowbuf_putbits(struct isowbuf_t *iwb, u32 data, int nbits)
        }
        iwb->wbits = nbits;
        iwb->data[write] = data & 0xff;
-       atomic_set(&iwb->write, write);
+       iwb->write = write;
 }
 
 /* put final flag on HDLC bitstream
@@ -142,7 +142,7 @@ static inline void isowbuf_putflag(struct isowbuf_t *iwb)
        /* add two flags, thus reliably covering one byte */
        isowbuf_putbits(iwb, 0x7e7e, 8);
        /* recover the idle flag byte */
-       write = atomic_read(&iwb->write);
+       write = iwb->write;
        iwb->idle = iwb->data[write];
        gig_dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle);
        /* mask extraneous bits in buffer */
@@ -160,8 +160,8 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
        int read, write, limit, src, dst;
        unsigned char pbyte;
 
-       read = atomic_read(&iwb->nextread);
-       write = atomic_read(&iwb->write);
+       read = iwb->nextread;
+       write = iwb->write;
        if (likely(read == write)) {
                /* return idle frame */
                return read < BAS_OUTBUFPAD ?
@@ -176,7 +176,7 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
                err("invalid size %d", size);
                return -EINVAL;
        }
-       src = atomic_read(&iwb->read);
+       src = iwb->read;
        if (unlikely(limit > BAS_OUTBUFSIZE + BAS_OUTBUFPAD ||
                     (read < src && limit >= src))) {
                err("isoc write buffer frame reservation violated");
@@ -191,7 +191,8 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
                        if (!isowbuf_startwrite(iwb))
                                return -EBUSY;
                        /* write position could have changed */
-                       if (limit >= (write = atomic_read(&iwb->write))) {
+                       write = iwb->write;
+                       if (limit >= write) {
                                pbyte = iwb->data[write]; /* save
                                                             partial byte */
                                limit = write + BAS_OUTBUFPAD;
@@ -213,7 +214,7 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
                                        __func__, pbyte, limit);
                                iwb->data[limit] = pbyte; /* restore
                                                             partial byte */
-                               atomic_set(&iwb->write, limit);
+                               iwb->write = limit;
                        }
                        isowbuf_donewrite(iwb);
                }
@@ -233,7 +234,7 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
                        limit = src;
                }
        }
-       atomic_set(&iwb->nextread, limit);
+       iwb->nextread = limit;
        return read;
 }
 
@@ -477,7 +478,7 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
        unsigned char c;
 
        if (unlikely(count <= 0))
-               return atomic_read(&iwb->write); /* better ideas? */
+               return iwb->write;
 
        if (isowbuf_freebytes(iwb) < count ||
            !isowbuf_startwrite(iwb)) {
@@ -486,13 +487,13 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
        }
 
        gig_dbg(DEBUG_STREAM, "put %d bytes", count);
-       write = atomic_read(&iwb->write);
+       write = iwb->write;
        do {
                c = bitrev8(*in++);
                iwb->data[write++] = c;
                write %= BAS_OUTBUFSIZE;
        } while (--count > 0);
-       atomic_set(&iwb->write, write);
+       iwb->write = write;
        iwb->idle = c;
 
        return isowbuf_donewrite(iwb);
@@ -947,8 +948,8 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
        unsigned tail, head, numbytes;
        unsigned char *src;
 
-       head = atomic_read(&inbuf->head);
-       while (head != (tail = atomic_read(&inbuf->tail))) {
+       head = inbuf->head;
+       while (head != (tail = inbuf->tail)) {
                gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
                if (head > tail)
                        tail = RBUFSIZE;
@@ -956,7 +957,7 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
                numbytes = tail - head;
                gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
 
-               if (atomic_read(&cs->mstate) == MS_LOCKED) {
+               if (cs->mstate == MS_LOCKED) {
                        gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response",
                                           numbytes, src);
                        gigaset_if_receive(inbuf->cs, src, numbytes);
@@ -970,7 +971,7 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
                if (head == RBUFSIZE)
                        head = 0;
                gig_dbg(DEBUG_INTR, "setting head to %u", head);
-               atomic_set(&inbuf->head, head);
+               inbuf->head = head;
        }
 }
 
index ea44302e6e7ecad6cb9a1e3b7f7f8ee94961a692..fceeb1d57682849b3e438e63a265d4fd036efe78 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/tty.h>
 #include <linux/poll.h>
+#include <linux/completion.h>
 
 /* Version Information */
 #define DRIVER_AUTHOR "Tilman Schmidt"
@@ -48,7 +49,7 @@ struct ser_cardstate {
        struct platform_device  dev;
        struct tty_struct       *tty;
        atomic_t                refcnt;
-       struct mutex            dead_mutex;
+       struct completion       dead_cmp;
 };
 
 static struct platform_driver device_driver = {
@@ -240,7 +241,7 @@ static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
        struct cmdbuf_t *cb;
        unsigned long flags;
 
-       gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
+       gigaset_dbg_buffer(cs->mstate != MS_LOCKED ?
                             DEBUG_TRANSCMD : DEBUG_LOCKCMD,
                           "CMD Transmit", len, buf);
 
@@ -498,7 +499,7 @@ static struct cardstate *cs_get(struct tty_struct *tty)
 static void cs_put(struct cardstate *cs)
 {
        if (atomic_dec_and_test(&cs->hw.ser->refcnt))
-               mutex_unlock(&cs->hw.ser->dead_mutex);
+               complete(&cs->hw.ser->dead_cmp);
 }
 
 /*
@@ -527,8 +528,8 @@ gigaset_tty_open(struct tty_struct *tty)
 
        cs->dev = &cs->hw.ser->dev.dev;
        cs->hw.ser->tty = tty;
-       mutex_init(&cs->hw.ser->dead_mutex);
        atomic_set(&cs->hw.ser->refcnt, 1);
+       init_completion(&cs->hw.ser->dead_cmp);
 
        tty->disc_data = cs;
 
@@ -536,14 +537,13 @@ gigaset_tty_open(struct tty_struct *tty)
         * startup system and notify the LL that we are ready to run
         */
        if (startmode == SM_LOCKED)
-               atomic_set(&cs->mstate, MS_LOCKED);
+               cs->mstate = MS_LOCKED;
        if (!gigaset_start(cs)) {
                tasklet_kill(&cs->write_tasklet);
                goto error;
        }
 
        gig_dbg(DEBUG_INIT, "Startup of HLL done");
-       mutex_lock(&cs->hw.ser->dead_mutex);
        return 0;
 
 error:
@@ -577,7 +577,7 @@ gigaset_tty_close(struct tty_struct *tty)
        else {
                /* wait for running methods to finish */
                if (!atomic_dec_and_test(&cs->hw.ser->refcnt))
-                       mutex_lock(&cs->hw.ser->dead_mutex);
+                       wait_for_completion(&cs->hw.ser->dead_cmp);
        }
 
        /* stop operations */
@@ -714,8 +714,8 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
                return;
        }
 
-       tail = atomic_read(&inbuf->tail);
-       head = atomic_read(&inbuf->head);
+       tail = inbuf->tail;
+       head = inbuf->head;
        gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
                head, tail, count);
 
@@ -742,7 +742,7 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
        }
 
        gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
-       atomic_set(&inbuf->tail, tail);
+       inbuf->tail = tail;
 
        /* Everything was received .. Push data into handler */
        gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
index ca4bee173cfb05e5857dffa3c9763ec559a803b6..77d20ab0cd4d422b31226c9093a08eedb22ad937 100644 (file)
@@ -104,12 +104,17 @@ MODULE_DEVICE_TABLE(usb, gigaset_table);
  * flags per packet.
  */
 
+/* functions called if a device of this driver is connected/disconnected */
 static int gigaset_probe(struct usb_interface *interface,
                         const struct usb_device_id *id);
 static void gigaset_disconnect(struct usb_interface *interface);
 
+/* functions called before/after suspend */
+static int gigaset_suspend(struct usb_interface *intf, pm_message_t message);
+static int gigaset_resume(struct usb_interface *intf);
+static int gigaset_pre_reset(struct usb_interface *intf);
+
 static struct gigaset_driver *driver = NULL;
-static struct cardstate *cardstate = NULL;
 
 /* usb specific object needed to register this driver with the usb subsystem */
 static struct usb_driver gigaset_usb_driver = {
@@ -117,12 +122,17 @@ static struct usb_driver gigaset_usb_driver = {
        .probe =        gigaset_probe,
        .disconnect =   gigaset_disconnect,
        .id_table =     gigaset_table,
+       .suspend =      gigaset_suspend,
+       .resume =       gigaset_resume,
+       .reset_resume = gigaset_resume,
+       .pre_reset =    gigaset_pre_reset,
+       .post_reset =   gigaset_resume,
 };
 
 struct usb_cardstate {
        struct usb_device       *udev;          /* usb device pointer */
        struct usb_interface    *interface;     /* interface for this device */
-       atomic_t                busy;           /* bulk output in progress */
+       int                     busy;           /* bulk output in progress */
 
        /* Output buffer */
        unsigned char           *bulk_out_buffer;
@@ -314,7 +324,7 @@ static void gigaset_modem_fill(unsigned long data)
 
        gig_dbg(DEBUG_OUTPUT, "modem_fill");
 
-       if (atomic_read(&cs->hw.usb->busy)) {
+       if (cs->hw.usb->busy) {
                gig_dbg(DEBUG_OUTPUT, "modem_fill: busy");
                return;
        }
@@ -361,18 +371,13 @@ static void gigaset_read_int_callback(struct urb *urb)
 {
        struct inbuf_t *inbuf = urb->context;
        struct cardstate *cs = inbuf->cs;
-       int resubmit = 0;
+       int status = urb->status;
        int r;
        unsigned numbytes;
        unsigned char *src;
        unsigned long flags;
 
-       if (!urb->status) {
-               if (!cs->connected) {
-                       err("%s: disconnected", __func__); /* should never happen */
-                       return;
-               }
-
+       if (!status) {
                numbytes = urb->actual_length;
 
                if (numbytes) {
@@ -389,28 +394,26 @@ static void gigaset_read_int_callback(struct urb *urb)
                        }
                } else
                        gig_dbg(DEBUG_INTR, "Received zero block length");
-               resubmit = 1;
        } else {
                /* The urb might have been killed. */
-               gig_dbg(DEBUG_ANY, "%s - nonzero read bulk status received: %d",
-                       __func__, urb->status);
-               if (urb->status != -ENOENT) { /* not killed */
-                       if (!cs->connected) {
-                               err("%s: disconnected", __func__); /* should never happen */
-                               return;
-                       }
-                       resubmit = 1;
-               }
+               gig_dbg(DEBUG_ANY, "%s - nonzero status received: %d",
+                       __func__, status);
+               if (status == -ENOENT || status == -ESHUTDOWN)
+                       /* killed or endpoint shutdown: don't resubmit */
+                       return;
        }
 
-       if (resubmit) {
-               spin_lock_irqsave(&cs->lock, flags);
-               r = cs->connected ? usb_submit_urb(urb, GFP_ATOMIC) : -ENODEV;
+       /* resubmit URB */
+       spin_lock_irqsave(&cs->lock, flags);
+       if (!cs->connected) {
                spin_unlock_irqrestore(&cs->lock, flags);
-               if (r)
-                       dev_err(cs->dev, "error %d when resubmitting urb.\n",
-                               -r);
+               err("%s: disconnected", __func__);
+               return;
        }
+       r = usb_submit_urb(urb, GFP_ATOMIC);
+       spin_unlock_irqrestore(&cs->lock, flags);
+       if (r)
+               dev_err(cs->dev, "error %d resubmitting URB\n", -r);
 }
 
 
@@ -418,19 +421,28 @@ static void gigaset_read_int_callback(struct urb *urb)
 static void gigaset_write_bulk_callback(struct urb *urb)
 {
        struct cardstate *cs = urb->context;
+       int status = urb->status;
        unsigned long flags;
 
-       if (urb->status)
+       switch (status) {
+       case 0:                 /* normal completion */
+               break;
+       case -ENOENT:           /* killed */
+               gig_dbg(DEBUG_ANY, "%s: killed", __func__);
+               cs->hw.usb->busy = 0;
+               return;
+       default:
                dev_err(cs->dev, "bulk transfer failed (status %d)\n",
-                       -urb->status);
+                       -status);
                /* That's all we can do. Communication problems
                   are handled by timeouts or network protocols. */
+       }
 
        spin_lock_irqsave(&cs->lock, flags);
        if (!cs->connected) {
                err("%s: not connected", __func__);
        } else {
-               atomic_set(&cs->hw.usb->busy, 0);
+               cs->hw.usb->busy = 0;
                tasklet_schedule(&cs->write_tasklet);
        }
        spin_unlock_irqrestore(&cs->lock, flags);
@@ -478,14 +490,14 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
 
                        cb->offset += count;
                        cb->len -= count;
-                       atomic_set(&ucs->busy, 1);
+                       ucs->busy = 1;
 
                        spin_lock_irqsave(&cs->lock, flags);
                        status = cs->connected ? usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC) : -ENODEV;
                        spin_unlock_irqrestore(&cs->lock, flags);
 
                        if (status) {
-                               atomic_set(&ucs->busy, 0);
+                               ucs->busy = 0;
                                err("could not submit urb (error %d)\n",
                                    -status);
                                cb->len = 0; /* skip urb => remove cb+wakeup
@@ -504,7 +516,7 @@ static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
        struct cmdbuf_t *cb;
        unsigned long flags;
 
-       gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
+       gigaset_dbg_buffer(cs->mstate != MS_LOCKED ?
                             DEBUG_TRANSCMD : DEBUG_LOCKCMD,
                           "CMD Transmit", len, buf);
 
@@ -641,7 +653,7 @@ static int write_modem(struct cardstate *cs)
        count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
        skb_copy_from_linear_data(bcs->tx_skb, ucs->bulk_out_buffer, count);
        skb_pull(bcs->tx_skb, count);
-       atomic_set(&ucs->busy, 1);
+       ucs->busy = 1;
        gig_dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count);
 
        spin_lock_irqsave(&cs->lock, flags);
@@ -659,7 +671,7 @@ static int write_modem(struct cardstate *cs)
 
        if (ret) {
                err("could not submit urb (error %d)\n", -ret);
-               atomic_set(&ucs->busy, 0);
+               ucs->busy = 0;
        }
 
        if (!bcs->tx_skb->len) {
@@ -680,53 +692,44 @@ static int gigaset_probe(struct usb_interface *interface,
 {
        int retval;
        struct usb_device *udev = interface_to_usbdev(interface);
-       unsigned int ifnum;
-       struct usb_host_interface *hostif;
+       struct usb_host_interface *hostif = interface->cur_altsetting;
        struct cardstate *cs = NULL;
        struct usb_cardstate *ucs = NULL;
        struct usb_endpoint_descriptor *endpoint;
        int buffer_size;
-       int alt;
 
-       gig_dbg(DEBUG_ANY,
-               "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
-               __func__, le16_to_cpu(udev->descriptor.idVendor),
-               le16_to_cpu(udev->descriptor.idProduct));
-
-       retval = -ENODEV; //FIXME
+       gig_dbg(DEBUG_ANY, "%s: Check if device matches ...", __func__);
 
        /* See if the device offered us matches what we can accept */
        if ((le16_to_cpu(udev->descriptor.idVendor)  != USB_M105_VENDOR_ID) ||
-           (le16_to_cpu(udev->descriptor.idProduct) != USB_M105_PRODUCT_ID))
+           (le16_to_cpu(udev->descriptor.idProduct) != USB_M105_PRODUCT_ID)) {
+               gig_dbg(DEBUG_ANY, "device ID (0x%x, 0x%x) not for me - skip",
+                       le16_to_cpu(udev->descriptor.idVendor),
+                       le16_to_cpu(udev->descriptor.idProduct));
                return -ENODEV;
-
-       /* this starts to become ascii art... */
-       hostif = interface->cur_altsetting;
-       alt = hostif->desc.bAlternateSetting;
-       ifnum = hostif->desc.bInterfaceNumber; // FIXME ?
-
-       if (alt != 0 || ifnum != 0) {
-               dev_warn(&udev->dev, "ifnum %d, alt %d\n", ifnum, alt);
+       }
+       if (hostif->desc.bInterfaceNumber != 0) {
+               gig_dbg(DEBUG_ANY, "interface %d not for me - skip",
+                       hostif->desc.bInterfaceNumber);
+               return -ENODEV;
+       }
+       if (hostif->desc.bAlternateSetting != 0) {
+               dev_notice(&udev->dev, "unsupported altsetting %d - skip",
+                          hostif->desc.bAlternateSetting);
                return -ENODEV;
        }
-
-       /* Reject application specific intefaces
-        *
-        */
        if (hostif->desc.bInterfaceClass != 255) {
-               dev_info(&udev->dev,
-               "%s: Device matched but iface_desc[%d]->bInterfaceClass==%d!\n",
-                        __func__, ifnum, hostif->desc.bInterfaceClass);
+               dev_notice(&udev->dev, "unsupported interface class %d - skip",
+                          hostif->desc.bInterfaceClass);
                return -ENODEV;
        }
 
        dev_info(&udev->dev, "%s: Device matched ... !\n", __func__);
 
-       cs = gigaset_getunassignedcs(driver);
-       if (!cs) {
-               dev_warn(&udev->dev, "no free cardstate\n");
+       /* allocate memory for our device state and intialize it */
+       cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
+       if (!cs)
                return -ENODEV;
-       }
        ucs = cs->hw.usb;
 
        /* save off device structure ptrs for later use */
@@ -759,7 +762,7 @@ static int gigaset_probe(struct usb_interface *interface,
 
        endpoint = &hostif->endpoint[1].desc;
 
-       atomic_set(&ucs->busy, 0);
+       ucs->busy = 0;
 
        ucs->read_urb = usb_alloc_urb(0, GFP_KERNEL);
        if (!ucs->read_urb) {
@@ -792,7 +795,7 @@ static int gigaset_probe(struct usb_interface *interface,
 
        /* tell common part that the device is ready */
        if (startmode == SM_LOCKED)
-               atomic_set(&cs->mstate, MS_LOCKED);
+               cs->mstate = MS_LOCKED;
 
        if (!gigaset_start(cs)) {
                tasklet_kill(&cs->write_tasklet);
@@ -813,7 +816,7 @@ error:
        usb_put_dev(ucs->udev);
        ucs->udev = NULL;
        ucs->interface = NULL;
-       gigaset_unassign(cs);
+       gigaset_freecs(cs);
        return retval;
 }
 
@@ -824,6 +827,9 @@ static void gigaset_disconnect(struct usb_interface *interface)
 
        cs = usb_get_intfdata(interface);
        ucs = cs->hw.usb;
+
+       dev_info(cs->dev, "disconnecting Gigaset USB adapter\n");
+
        usb_kill_urb(ucs->read_urb);
 
        gigaset_stop(cs);
@@ -831,7 +837,7 @@ static void gigaset_disconnect(struct usb_interface *interface)
        usb_set_intfdata(interface, NULL);
        tasklet_kill(&cs->write_tasklet);
 
-       usb_kill_urb(ucs->bulk_out_urb);        /* FIXME: only if active? */
+       usb_kill_urb(ucs->bulk_out_urb);
 
        kfree(ucs->bulk_out_buffer);
        usb_free_urb(ucs->bulk_out_urb);
@@ -844,7 +850,53 @@ static void gigaset_disconnect(struct usb_interface *interface)
        ucs->interface = NULL;
        ucs->udev = NULL;
        cs->dev = NULL;
-       gigaset_unassign(cs);
+       gigaset_freecs(cs);
+}
+
+/* gigaset_suspend
+ * This function is called before the USB connection is suspended or reset.
+ */
+static int gigaset_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       struct cardstate *cs = usb_get_intfdata(intf);
+
+       /* stop activity */
+       cs->connected = 0;      /* prevent rescheduling */
+       usb_kill_urb(cs->hw.usb->read_urb);
+       tasklet_kill(&cs->write_tasklet);
+       usb_kill_urb(cs->hw.usb->bulk_out_urb);
+
+       gig_dbg(DEBUG_SUSPEND, "suspend complete");
+       return 0;
+}
+
+/* gigaset_resume
+ * This function is called after the USB connection has been resumed or reset.
+ */
+static int gigaset_resume(struct usb_interface *intf)
+{
+       struct cardstate *cs = usb_get_intfdata(intf);
+       int rc;
+
+       /* resubmit interrupt URB */
+       cs->connected = 1;
+       rc = usb_submit_urb(cs->hw.usb->read_urb, GFP_KERNEL);
+       if (rc) {
+               dev_err(cs->dev, "Could not submit read URB (error %d)\n", -rc);
+               return rc;
+       }
+
+       gig_dbg(DEBUG_SUSPEND, "resume complete");
+       return 0;
+}
+
+/* gigaset_pre_reset
+ * This function is called before the USB connection is reset.
+ */
+static int gigaset_pre_reset(struct usb_interface *intf)
+{
+       /* same as suspend */
+       return gigaset_suspend(intf, PMSG_ON);
 }
 
 static const struct gigaset_ops ops = {
@@ -880,11 +932,6 @@ static int __init usb_gigaset_init(void)
                                       &ops, THIS_MODULE)) == NULL)
                goto error;
 
-       /* allocate memory for our device state and intialize it */
-       cardstate = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
-       if (!cardstate)
-               goto error;
-
        /* register this driver with the USB subsystem */
        result = usb_register(&gigaset_usb_driver);
        if (result < 0) {
@@ -897,9 +944,7 @@ static int __init usb_gigaset_init(void)
        info(DRIVER_DESC);
        return 0;
 
-error: if (cardstate)
-               gigaset_freecs(cardstate);
-       cardstate = NULL;
+error:
        if (driver)
                gigaset_freedriver(driver);
        driver = NULL;
@@ -913,11 +958,16 @@ error:    if (cardstate)
  */
 static void __exit usb_gigaset_exit(void)
 {
+       int i;
+
        gigaset_blockdriver(driver); /* => probe will fail
                                      * => no gigaset_start any more
                                      */
 
-       gigaset_shutdown(cardstate);
+       /* stop all connected devices */
+       for (i = 0; i < driver->minors; i++)
+               gigaset_shutdown(driver->cs + i);
+
        /* from now on, no isdn callback should be possible */
 
        /* deregister this driver with the USB subsystem */
@@ -925,8 +975,6 @@ static void __exit usb_gigaset_exit(void)
        /* this will call the disconnect-callback */
        /* from now on, no disconnect/probe callback should be running */
 
-       gigaset_freecs(cardstate);
-       cardstate = NULL;
        gigaset_freedriver(driver);
        driver = NULL;
 }
index 0db9cc661e28b7b224e49fd6a2cf34e191f92250..84318ec8d13eefc65d23e7b99764da500b395d88 100644 (file)
@@ -1188,7 +1188,7 @@ int SuperTraceASSIGN (void* AdapterHandle, byte* data) {
 
     if ((features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) &&
         (features[0] & DIVA_XDI_EXTENDED_FEATURE_MANAGEMENT_DMA)) {
-      dword rx_dma_magic;
+      dword uninitialized_var(rx_dma_magic);
       if ((pC->dma_handle = diva_get_dma_descriptor (pC->request, &rx_dma_magic)) >= 0) {
         pC->xbuffer[0] = LLI;
         pC->xbuffer[1] = 8;
index a19b7ffe9aceabdfbbf3fb5d7b5af01d4c0c8749..e39c5c1f623edf096ba9fb7c86ba34bc4a3849e7 100644 (file)
@@ -106,7 +106,7 @@ DbgRegister (char *drvName, char *drvTag, unsigned long dbgMask)
   return (1) ;
  }
 /*
- * Check if we registered whith an old maint driver (see debuglib.h)
+ * Check if we registered with an old maint driver (see debuglib.h)
  */
  if ( myDriverDebugHandle.dbg_end != NULL
    /* location of 'dbg_prt' in _OldDbgHandle_ struct */
index 11b3b9edd1d6f8f1a15dcd9137f02add7f73d887..016410cf227340e679e81a88f662e7fc8a1b14cb 100644 (file)
@@ -177,7 +177,7 @@ DBG_DECL(PRV3)
 } }
 #endif
 /*
- * For event level debug use a separate define, the paramete are
+ * For event level debug use a separate define, the parameter are
  * different and cause compiler errors on some systems.
  */
 #define DBG_EVL_ID(args) \
index ce8df38789087c4f7c85b056ba033644d3a1be00..10760b3c5eb56bda220b5b6b0d7390241d2b0a6d 100644 (file)
@@ -285,7 +285,7 @@ byte pr_dpc(ADAPTER * a)
                 a->ram_in(a, &RcIn->RcId),
                 a->ram_in(a, &RcIn->RcCh),
                 a->ram_inw(a, &RcIn->Reference),
-                tmp[0],  /* type of extended informtion */
+                tmp[0],  /* type of extended information */
                 tmp[1]); /* extended information        */
         a->ram_out(a, &RcIn->Rc, 0);
       }
index ffa2afa77c2f199b8b2128d86d29597472f77694..1403a5458e68f9227af58ad9849177203befcc80 100644 (file)
@@ -515,12 +515,11 @@ diva_xdi_read(void *adapter, void *os_handle, void __user *dst,
 
 irqreturn_t diva_os_irq_wrapper(int irq, void *context)
 {
-       diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) context;
+       diva_os_xdi_adapter_t *a = context;
        diva_xdi_clear_interrupts_proc_t clear_int_proc;
 
-       if (!a || !a->xdi_adapter.diva_isr_handler) {
+       if (!a || !a->xdi_adapter.diva_isr_handler)
                return IRQ_NONE;
-       }
 
        if ((clear_int_proc = a->clear_interrupts_proc)) {
                (*clear_int_proc) (a);
index ccd35d047ec8c314dc337e827ca3ad58b45ae767..1ff98e7eb794cee276872c713672f1d5af951de6 100644 (file)
@@ -4941,7 +4941,7 @@ void sig_ind(PLCI   * plci)
       /* b = IE1                */
       /* S = IE1 length + cont. */
       /* b = IE2                */
-      /* S = IE2 lenght + cont. */
+      /* S = IE2 length + cont. */
       sendf(plci->appl,
         _MANUFACTURER_I,
         Id,
@@ -9027,7 +9027,7 @@ static byte AddInfo(byte   **add_i,
    /* facility is a nested structure */
    /* FTY can be more than once      */
 
-  if(esc_chi[0] && !(esc_chi[esc_chi[0]])&0x7f )
+       if (esc_chi[0] && !(esc_chi[esc_chi[0]] & 0x7f))
   {
     add_i[0] = (byte   *)"\x02\x02\x00"; /* use neither b nor d channel */
   }
index 035d158779df75f328eca89c77a3e968497fb0ba..0f1db1f669b28028162fcf205bb69c5bd4749359 100644 (file)
@@ -263,11 +263,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
                outl(idx, cs->hw.avm.cfg_reg + 4);
                while (cnt < count) {
 #ifdef __powerpc__
-#ifdef CONFIG_APUS
-                       *ptr++ = in_le32((unsigned *)(cs->hw.avm.isac +_IO_BASE));
-#else
                        *ptr++ = in_be32((unsigned *)(cs->hw.avm.isac +_IO_BASE));
-#endif /* CONFIG_APUS */
 #else
                        *ptr++ = inl(cs->hw.avm.isac);
 #endif /* __powerpc__ */
@@ -328,11 +324,7 @@ hdlc_fill_fifo(struct BCState *bcs)
        if (cs->subtyp == AVM_FRITZ_PCI) {
                while (cnt<count) {
 #ifdef __powerpc__
-#ifdef CONFIG_APUS
-                       out_le32((unsigned *)(cs->hw.avm.isac +_IO_BASE), *ptr++);
-#else
                        out_be32((unsigned *)(cs->hw.avm.isac +_IO_BASE), *ptr++);
-#endif /* CONFIG_APUS */
 #else
                        outl(*ptr++, cs->hw.avm.isac);
 #endif /* __powerpc__ */
index f85450146bdcb8e18e8c192199c086f063c1efa1..d3999a8e9f88cb55516cde292fd04af447ae32b5 100644 (file)
@@ -541,7 +541,7 @@ hycapi_rx_capipkt(hysdn_card * card, unsigned char *buf, unsigned short len)
        }
        ctrl = &cinfo->capi_ctrl;
        if(len < CAPI_MSG_BASELEN) {
-               printk(KERN_ERR "HYSDN Card%d: invalid CAPI-message, lenght %d!\n",
+               printk(KERN_ERR "HYSDN Card%d: invalid CAPI-message, length %d!\n",
                       card->myid, len);
                return;
        }       
index 9cb6e5021adb93af85012396cf857b2fb82242f2..133eb18e65cca989dcd3f0755ae3d0f98f1c9a47 100644 (file)
@@ -1917,7 +1917,6 @@ isdn_tty_modem_init(void)
                info->owner = THIS_MODULE;
 #endif
                spin_lock_init(&info->readlock);
-               init_MUTEX(&info->write_sem);
                sprintf(info->last_cause, "0000");
                sprintf(info->last_num, "none");
                info->last_dir = 0;
index a943d078bacc2991bdd52e8680b4648c3aafb866..f93de4a303550afa4ea48b3ca6af7f7e4568a446 100644 (file)
@@ -834,7 +834,7 @@ isdn_tty_cmd_FCLASS2(char **p, modem_info * info)
                char *rp = &f->resolution;
 
                p[0] += 2;
-               if (!info->faxonline & 1)       /* not outgoing connection */
+               if (!(info->faxonline & 1))     /* not outgoing connection */
                        PARSE_ERROR1;
 
                for (i = 0; (((*p[0] >= '0') && (*p[0] <= '9')) || (*p[0] == ',')) && (i < 4); i++) {
index 82d957bde299453dcbd0b53173fc4e5efe18e5b2..bf7997abc4ac6da27bf972677ac3283e7e68d49c 100644 (file)
@@ -1302,7 +1302,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_DIAL:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        if (card->leased)
                                break;
@@ -1328,7 +1328,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_ACCEPTD:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        if (c->arg < ICN_BCH) {
                                a = c->arg + 1;
@@ -1348,7 +1348,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_ACCEPTB:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        if (c->arg < ICN_BCH) {
                                a = c->arg + 1;
@@ -1366,7 +1366,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_HANGUP:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        if (c->arg < ICN_BCH) {
                                a = c->arg + 1;
@@ -1375,7 +1375,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_SETEAZ:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        if (card->leased)
                                break;
@@ -1391,7 +1391,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_CLREAZ:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        if (card->leased)
                                break;
@@ -1405,7 +1405,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_SETL2:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        if ((c->arg & 255) < ICN_BCH) {
                                a = c->arg;
@@ -1424,7 +1424,7 @@ icn_command(isdn_ctrl * c, icn_card * card)
                        }
                        break;
                case ISDN_CMD_SETL3:
-                       if (!card->flags & ICN_FLAGS_RUNNING)
+                       if (!(card->flags & ICN_FLAGS_RUNNING))
                                return -ENODEV;
                        return 0;
                default:
@@ -1471,7 +1471,7 @@ if_writecmd(const u_char __user *buf, int len, int id, int channel)
        icn_card *card = icn_findcard(id);
 
        if (card) {
-               if (!card->flags & ICN_FLAGS_RUNNING)
+               if (!(card->flags & ICN_FLAGS_RUNNING))
                        return -ENODEV;
                return (icn_writecmd(buf, len, 1, card));
        }
@@ -1486,7 +1486,7 @@ if_readstatus(u_char __user *buf, int len, int id, int channel)
        icn_card *card = icn_findcard(id);
 
        if (card) {
-               if (!card->flags & ICN_FLAGS_RUNNING)
+               if (!(card->flags & ICN_FLAGS_RUNNING))
                        return -ENODEV;
                return (icn_readstatus(buf, len, card));
        }
@@ -1501,7 +1501,7 @@ if_sendbuf(int id, int channel, int ack, struct sk_buff *skb)
        icn_card *card = icn_findcard(id);
 
        if (card) {
-               if (!card->flags & ICN_FLAGS_RUNNING)
+               if (!(card->flags & ICN_FLAGS_RUNNING))
                        return -ENODEV;
                return (icn_sendbuf(channel, ack, skb, card));
        }
index bb92e3cd9334a0bdf2822d28ef47bf0739ef2303..655ef9a3f4df2a023d319967e9aa99dda93e4dc8 100644 (file)
@@ -1184,7 +1184,7 @@ isdnloop_command(isdn_ctrl * c, isdnloop_card * card)
                        }
                        break;
                case ISDN_CMD_DIAL:
-                       if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+                       if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                                return -ENODEV;
                        if (card->leased)
                                break;
@@ -1210,7 +1210,7 @@ isdnloop_command(isdn_ctrl * c, isdnloop_card * card)
                        }
                        break;
                case ISDN_CMD_ACCEPTD:
-                       if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+                       if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                                return -ENODEV;
                        if (c->arg < ISDNLOOP_BCH) {
                                a = c->arg + 1;
@@ -1238,7 +1238,7 @@ isdnloop_command(isdn_ctrl * c, isdnloop_card * card)
                        }
                        break;
                case ISDN_CMD_ACCEPTB:
-                       if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+                       if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                                return -ENODEV;
                        if (c->arg < ISDNLOOP_BCH) {
                                a = c->arg + 1;
@@ -1264,7 +1264,7 @@ isdnloop_command(isdn_ctrl * c, isdnloop_card * card)
                                i = isdnloop_writecmd(cbuf, strlen(cbuf), 0, card);
                                break;
                case ISDN_CMD_HANGUP:
-                               if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+                               if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                                        return -ENODEV;
                                if (c->arg < ISDNLOOP_BCH) {
                                        a = c->arg + 1;
@@ -1273,7 +1273,7 @@ isdnloop_command(isdn_ctrl * c, isdnloop_card * card)
                                }
                                break;
                case ISDN_CMD_SETEAZ:
-                               if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+                               if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                                        return -ENODEV;
                                if (card->leased)
                                        break;
@@ -1303,7 +1303,7 @@ isdnloop_command(isdn_ctrl * c, isdnloop_card * card)
                                }
                                break;
                case ISDN_CMD_SETL2:
-                               if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+                               if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                                        return -ENODEV;
                                if ((c->arg & 255) < ISDNLOOP_BCH) {
                                        a = c->arg;
@@ -1395,7 +1395,7 @@ if_readstatus(u_char __user *buf, int len, int id, int channel)
        isdnloop_card *card = isdnloop_findcard(id);
 
        if (card) {
-               if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+               if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                        return -ENODEV;
                return (isdnloop_readstatus(buf, len, card));
        }
@@ -1410,7 +1410,7 @@ if_sendbuf(int id, int channel, int ack, struct sk_buff *skb)
        isdnloop_card *card = isdnloop_findcard(id);
 
        if (card) {
-               if (!card->flags & ISDNLOOP_FLAGS_RUNNING)
+               if (!(card->flags & ISDNLOOP_FLAGS_RUNNING))
                        return -ENODEV;
                /* ack request stored in skb scratch area */
                *(skb->head) = ack;
index 64c66b3769c99edf05af6ae8d104a70a8240f2e1..4a938780dfc380e187b058afcd4da96be6cdf3f8 100644 (file)
@@ -137,12 +137,14 @@ err_out:
 EXPORT_SYMBOL_GPL(led_classdev_register);
 
 /**
- * led_classdev_unregister - unregisters a object of led_properties class.
+ * __led_classdev_unregister - unregisters a object of led_properties class.
  * @led_cdev: the led device to unregister
+ * @suspended: indicates whether system-wide suspend or resume is in progress
  *
  * Unregisters a previously registered via led_classdev_register object.
  */
-void led_classdev_unregister(struct led_classdev *led_cdev)
+void __led_classdev_unregister(struct led_classdev *led_cdev,
+                                     bool suspended)
 {
        device_remove_file(led_cdev->dev, &dev_attr_brightness);
 #ifdef CONFIG_LEDS_TRIGGERS
@@ -153,13 +155,16 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
        up_write(&led_cdev->trigger_lock);
 #endif
 
-       device_unregister(led_cdev->dev);
+       if (suspended)
+               device_pm_schedule_removal(led_cdev->dev);
+       else
+               device_unregister(led_cdev->dev);
 
        down_write(&leds_list_lock);
        list_del(&led_cdev->node);
        up_write(&leds_list_lock);
 }
-EXPORT_SYMBOL_GPL(led_classdev_unregister);
+EXPORT_SYMBOL_GPL(__led_classdev_unregister);
 
 static int __init leds_init(void)
 {
index e2eec38c83c2ef21248353d132e3308810e1e17d..84f85e23cca7a65a86b3ffa3647953373c5339b3 100644 (file)
@@ -52,57 +52,82 @@ struct lguest_device {
 /*D:130
  * Device configurations
  *
- * The configuration information for a device consists of a series of fields.
- * We don't really care what they are: the Launcher set them up, and the driver
- * will look at them during setup.
+ * The configuration information for a device consists of one or more
+ * virtqueues, a feature bitmaks, and some configuration bytes.  The
+ * configuration bytes don't really matter to us: the Launcher sets them up, and
+ * the driver will look at them during setup.
  *
- * For us these fields come immediately after that device's descriptor in the
- * lguest_devices page.
- *
- * Each field starts with a "type" byte, a "length" byte, then that number of
- * bytes of configuration information.  The device descriptor tells us the
- * total configuration length so we know when we've reached the last field. */
+ * A convenient routine to return the device's virtqueue config array:
+ * immediately after the descriptor. */
+static struct lguest_vqconfig *lg_vq(const struct lguest_device_desc *desc)
+{
+       return (void *)(desc + 1);
+}
 
-/* type + length bytes */
-#define FHDR_LEN 2
+/* The features come immediately after the virtqueues. */
+static u8 *lg_features(const struct lguest_device_desc *desc)
+{
+       return (void *)(lg_vq(desc) + desc->num_vq);
+}
 
-/* This finds the first field of a given type for a device's configuration. */
-static void *lg_find(struct virtio_device *vdev, u8 type, unsigned int *len)
+/* The config space comes after the two feature bitmasks. */
+static u8 *lg_config(const struct lguest_device_desc *desc)
 {
-       struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
-       int i;
-
-       for (i = 0; i < desc->config_len; i += FHDR_LEN + desc->config[i+1]) {
-               if (desc->config[i] == type) {
-                       /* Mark it used, so Host can know we looked at it, and
-                        * also so we won't find the same one twice. */
-                       desc->config[i] |= 0x80;
-                       /* Remember, the second byte is the length. */
-                       *len = desc->config[i+1];
-                       /* We return a pointer to the field header. */
-                       return desc->config + i;
-               }
-       }
+       return lg_features(desc) + desc->feature_len * 2;
+}
 
-       /* Not found: return NULL for failure. */
-       return NULL;
+/* The total size of the config page used by this device (incl. desc) */
+static unsigned desc_size(const struct lguest_device_desc *desc)
+{
+       return sizeof(*desc)
+               + desc->num_vq * sizeof(struct lguest_vqconfig)
+               + desc->feature_len * 2
+               + desc->config_len;
+}
+
+/* This tests (and acknowleges) a feature bit. */
+static bool lg_feature(struct virtio_device *vdev, unsigned fbit)
+{
+       struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
+       u8 *features;
+
+       /* Obviously if they ask for a feature off the end of our feature
+        * bitmap, it's not set. */
+       if (fbit / 8 > desc->feature_len)
+               return false;
+
+       /* The feature bitmap comes after the virtqueues. */
+       features = lg_features(desc);
+       if (!(features[fbit / 8] & (1 << (fbit % 8))))
+               return false;
+
+       /* We set the matching bit in the other half of the bitmap to tell the
+        * Host we want to use this feature.  We don't use this yet, but we
+        * could in future. */
+       features[desc->feature_len + fbit / 8] |= (1 << (fbit % 8));
+       return true;
 }
 
 /* Once they've found a field, getting a copy of it is easy. */
-static void lg_get(struct virtio_device *vdev, void *token,
+static void lg_get(struct virtio_device *vdev, unsigned int offset,
                   void *buf, unsigned len)
 {
-       /* Check they didn't ask for more than the length of the field! */
-       BUG_ON(len > ((u8 *)token)[1]);
-       memcpy(buf, token + FHDR_LEN, len);
+       struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
+
+       /* Check they didn't ask for more than the length of the config! */
+       BUG_ON(offset + len > desc->config_len);
+       memcpy(buf, lg_config(desc) + offset, len);
 }
 
 /* Setting the contents is also trivial. */
-static void lg_set(struct virtio_device *vdev, void *token,
+static void lg_set(struct virtio_device *vdev, unsigned int offset,
                   const void *buf, unsigned len)
 {
-       BUG_ON(len > ((u8 *)token)[1]);
-       memcpy(token + FHDR_LEN, buf, len);
+       struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
+
+       /* Check they didn't ask for more than the length of the config! */
+       BUG_ON(offset + len > desc->config_len);
+       memcpy(lg_config(desc) + offset, buf, len);
 }
 
 /* The operations to get and set the status word just access the status field
@@ -114,9 +139,20 @@ static u8 lg_get_status(struct virtio_device *vdev)
 
 static void lg_set_status(struct virtio_device *vdev, u8 status)
 {
+       BUG_ON(!status);
        to_lgdev(vdev)->desc->status = status;
 }
 
+/* To reset the device, we (ab)use the NOTIFY hypercall, with the descriptor
+ * address of the device.  The Host will zero the status and all the
+ * features. */
+static void lg_reset(struct virtio_device *vdev)
+{
+       unsigned long offset = (void *)to_lgdev(vdev)->desc - lguest_devices;
+
+       hcall(LHCALL_NOTIFY, (max_pfn<<PAGE_SHIFT) + offset, 0, 0);
+}
+
 /*
  * Virtqueues
  *
@@ -165,39 +201,29 @@ static void lg_notify(struct virtqueue *vq)
  *
  * So we provide devices with a "find virtqueue and set it up" function. */
 static struct virtqueue *lg_find_vq(struct virtio_device *vdev,
-                                   bool (*callback)(struct virtqueue *vq))
+                                   unsigned index,
+                                   void (*callback)(struct virtqueue *vq))
 {
+       struct lguest_device *ldev = to_lgdev(vdev);
        struct lguest_vq_info *lvq;
        struct virtqueue *vq;
-       unsigned int len;
-       void *token;
        int err;
 
-       /* Look for a field of the correct type to mark a virtqueue.  Note that
-        * if this succeeds, then the type will be changed so it won't be found
-        * again, and future lg_find_vq() calls will find the next
-        * virtqueue (if any). */
-       token = vdev->config->find(vdev, VIRTIO_CONFIG_F_VIRTQUEUE, &len);
-       if (!token)
+       /* We must have this many virtqueues. */
+       if (index >= ldev->desc->num_vq)
                return ERR_PTR(-ENOENT);
 
        lvq = kmalloc(sizeof(*lvq), GFP_KERNEL);
        if (!lvq)
                return ERR_PTR(-ENOMEM);
 
-       /* Note: we could use a configuration space inside here, just like we
-        * do for the device.  This would allow expansion in future, because
-        * our configuration system is designed to be expansible.  But this is
-        * way easier. */
-       if (len != sizeof(lvq->config)) {
-               dev_err(&vdev->dev, "Unexpected virtio config len %u\n", len);
-               err = -EIO;
-               goto free_lvq;
-       }
-       /* Make a copy of the "struct lguest_vqconfig" field.  We need a copy
-        * because the config space might not be aligned correctly. */
-       vdev->config->get(vdev, token, &lvq->config, sizeof(lvq->config));
+       /* Make a copy of the "struct lguest_vqconfig" entry, which sits after
+        * the descriptor.  We need a copy because the config space might not
+        * be aligned correctly. */
+       memcpy(&lvq->config, lg_vq(ldev->desc)+index, sizeof(lvq->config));
 
+       printk("Mapping virtqueue %i addr %lx\n", index,
+              (unsigned long)lvq->config.pfn << PAGE_SHIFT);
        /* Figure out how many pages the ring will take, and map that memory */
        lvq->pages = lguest_map((unsigned long)lvq->config.pfn << PAGE_SHIFT,
                                DIV_ROUND_UP(vring_size(lvq->config.num,
@@ -259,11 +285,12 @@ static void lg_del_vq(struct virtqueue *vq)
 
 /* The ops structure which hooks everything together. */
 static struct virtio_config_ops lguest_config_ops = {
-       .find = lg_find,
+       .feature = lg_feature,
        .get = lg_get,
        .set = lg_set,
        .get_status = lg_get_status,
        .set_status = lg_set_status,
+       .reset = lg_reset,
        .find_vq = lg_find_vq,
        .del_vq = lg_del_vq,
 };
@@ -329,13 +356,14 @@ static void scan_devices(void)
        struct lguest_device_desc *d;
 
        /* We start at the page beginning, and skip over each entry. */
-       for (i = 0; i < PAGE_SIZE; i += sizeof(*d) + d->config_len) {
+       for (i = 0; i < PAGE_SIZE; i += desc_size(d)) {
                d = lguest_devices + i;
 
                /* Once we hit a zero, stop. */
                if (d->type == 0)
                        break;
 
+               printk("Device at %i has size %u\n", i, desc_size(d));
                add_lguest_device(d);
        }
 }
index 7ce0ea64465ccd666b5b2c234db58ac497cd7e03..28958101061f9a922cf4c79f7cd41c8ec3472e45 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/completion.h>
 #include <linux/device.h>
 #include <linux/kthread.h>
+#include <linux/platform_device.h>
 
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
index 18dde2a27209e91ba85a7a9adf4b933780e7732f..936788272a5f671e435ca220f8ecf5d4f9e9093b 100644 (file)
@@ -78,12 +78,14 @@ struct media_bay_info {
        int                             cached_gpio;
        int                             sleeping;
        struct semaphore                lock;
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
        void __iomem                    *cd_base;
-       int                             cd_index;
        int                             cd_irq;
        int                             cd_retry;
 #endif
+#if defined(CONFIG_BLK_DEV_IDE_PMAC) || defined(CONFIG_MAC_FLOPPY)
+       int                             cd_index;
+#endif
 };
 
 #define MAX_BAYS       2
@@ -91,7 +93,7 @@ struct media_bay_info {
 static struct media_bay_info media_bays[MAX_BAYS];
 int media_bay_count = 0;
 
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
 /* check the busy bit in the media-bay ide interface
    (assumes the media-bay contains an ide device) */
 #define MB_IDE_READY(i)        ((readb(media_bays[i].cd_base + 0x70) & 0x80) == 0)
@@ -401,7 +403,7 @@ static void poll_media_bay(struct media_bay_info* bay)
                                set_mb_power(bay, id != MB_NO);
                                bay->content_id = id;
                                if (id == MB_NO) {
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
                                        bay->cd_retry = 0;
 #endif
                                        printk(KERN_INFO "media bay %d is empty\n", bay->index);
@@ -414,9 +416,9 @@ static void poll_media_bay(struct media_bay_info* bay)
        }
 }
 
+#ifdef CONFIG_MAC_FLOPPY
 int check_media_bay(struct device_node *which_bay, int what)
 {
-#ifdef CONFIG_BLK_DEV_IDE
        int     i;
 
        for (i=0; i<media_bay_count; i++)
@@ -426,14 +428,14 @@ int check_media_bay(struct device_node *which_bay, int what)
                        media_bays[i].cd_index = -1;
                        return -EINVAL;
                }
-#endif /* CONFIG_BLK_DEV_IDE */
        return -ENODEV;
 }
 EXPORT_SYMBOL(check_media_bay);
+#endif /* CONFIG_MAC_FLOPPY */
 
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
 int check_media_bay_by_base(unsigned long base, int what)
 {
-#ifdef CONFIG_BLK_DEV_IDE
        int     i;
 
        for (i=0; i<media_bay_count; i++)
@@ -443,15 +445,13 @@ int check_media_bay_by_base(unsigned long base, int what)
                        media_bays[i].cd_index = -1;
                        return -EINVAL;
                } 
-#endif
-       
+
        return -ENODEV;
 }
 
 int media_bay_set_ide_infos(struct device_node* which_bay, unsigned long base,
-       int irq, int index)
+                           int irq, int index)
 {
-#ifdef CONFIG_BLK_DEV_IDE
        int     i;
 
        for (i=0; i<media_bay_count; i++) {
@@ -483,10 +483,10 @@ int media_bay_set_ide_infos(struct device_node* which_bay, unsigned long base,
                        return -ENODEV;
                }
        }
-#endif /* CONFIG_BLK_DEV_IDE */
-       
+
        return -ENODEV;
 }
+#endif /* CONFIG_BLK_DEV_IDE_PMAC */
 
 static void media_bay_step(int i)
 {
@@ -521,14 +521,13 @@ static void media_bay_step(int i)
                bay->state = mb_resetting;
                MBDBG("mediabay%d: waiting reset (kind:%d)\n", i, bay->content_id);
                break;
-           
        case mb_resetting:
                if (bay->content_id != MB_CD) {
                        MBDBG("mediabay%d: bay is up (kind:%d)\n", i, bay->content_id);
                        bay->state = mb_up;
                        break;
                }
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
                MBDBG("mediabay%d: waiting IDE reset (kind:%d)\n", i, bay->content_id);
                bay->ops->un_reset_ide(bay);
                bay->timer = msecs_to_jiffies(MB_IDE_WAIT);
@@ -536,16 +535,14 @@ static void media_bay_step(int i)
 #else
                printk(KERN_DEBUG "media-bay %d is ide (not compiled in kernel)\n", i);
                set_mb_power(bay, 0);
-#endif /* CONFIG_BLK_DEV_IDE */
+#endif /* CONFIG_BLK_DEV_IDE_PMAC */
                break;
-           
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
        case mb_ide_resetting:
                bay->timer = msecs_to_jiffies(MB_IDE_TIMEOUT);
                bay->state = mb_ide_waiting;
                MBDBG("mediabay%d: waiting IDE ready (kind:%d)\n", i, bay->content_id);
                break;
-           
        case mb_ide_waiting:
                if (bay->cd_base == NULL) {
                        bay->timer = 0;
@@ -587,15 +584,14 @@ static void media_bay_step(int i)
                        bay->timer = 0;
                }
                break;
-#endif /* CONFIG_BLK_DEV_IDE */
-
+#endif /* CONFIG_BLK_DEV_IDE_PMAC */
        case mb_powering_down:
                bay->state = mb_empty;
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
                if (bay->cd_index >= 0) {
                        printk(KERN_DEBUG "Unregistering mb %d ide, index:%d\n", i,
                               bay->cd_index);
-                       ide_unregister(bay->cd_index);
+                       ide_unregister(bay->cd_index, 1, 1);
                        bay->cd_index = -1;
                }
                if (bay->cd_retry) {
@@ -607,7 +603,7 @@ static void media_bay_step(int i)
                                bay->content_id = MB_NO;
                        }
                }
-#endif /* CONFIG_BLK_DEV_IDE */    
+#endif /* CONFIG_BLK_DEV_IDE_PMAC */
                MBDBG("mediabay%d: end of power down\n", i);
                break;
        }
@@ -739,7 +735,7 @@ static int media_bay_resume(struct macio_dev *mdev)
                bay->last_value = bay->content_id;
                bay->value_count = msecs_to_jiffies(MB_STABLE_DELAY);
                bay->timer = msecs_to_jiffies(MB_POWER_DELAY);
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
                bay->cd_retry = 0;
 #endif
                do {
@@ -829,7 +825,7 @@ static int __init media_bay_init(void)
        for (i=0; i<MAX_BAYS; i++) {
                memset((char *)&media_bays[i], 0, sizeof(struct media_bay_info));
                media_bays[i].content_id        = -1;
-#ifdef CONFIG_BLK_DEV_IDE
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
                media_bays[i].cd_index          = -1;
 #endif
        }
index d409f67594828e5501e754edc1fb60e5337b2f3d..8ba49385c3ff4fd149c21980eabf0cc1996ee32b 100644 (file)
@@ -12,7 +12,7 @@
  *  - maybe add timeout to commands ?
  *  - blocking version of time functions
  *  - polling version of i2c commands (including timer that works with
- *    interrutps off)
+ *    interrupts off)
  *  - maybe avoid some data copies with i2c by directly using the smu cmd
  *    buffer and a lower level internal interface
  *  - understand SMU -> CPU events and implement reception of them via
@@ -179,7 +179,7 @@ static irqreturn_t smu_db_intr(int irq, void *arg)
                /* CPU might have brought back the cache line, so we need
                 * to flush again before peeking at the SMU response. We
                 * flush the entire buffer for now as we haven't read the
-                * reply lenght (it's only 2 cache lines anyway)
+                * reply length (it's only 2 cache lines anyway)
                 */
                faddr = (unsigned long)smu->cmd_buf;
                flush_inval_dcache_range(faddr, faddr + 256);
index 01b8eca7ccd56e33cb5dcf27605bddffd1a27f64..6e6dd17ab572f81bd775293ad907b8024407d2ee 100644 (file)
@@ -111,7 +111,7 @@ static enum macii_state {
 static struct adb_request *current_req; /* first request struct in the queue */
 static struct adb_request *last_req;     /* last request struct in the queue */
 static unsigned char reply_buf[16];        /* storage for autopolled replies */
-static unsigned char *reply_ptr;      /* next byte in req->data or reply_buf */
+static unsigned char *reply_ptr;     /* next byte in reply_buf or req->reply */
 static int reading_reply;        /* store reply in reply_buf else req->reply */
 static int data_index;      /* index of the next byte to send from req->data */
 static int reply_len; /* number of bytes received in reply_buf or req->reply */
index 1b1ef3130e6e8cbbe32ea6d659882b92a408d59e..a0585fb6da94304758e7294f7b5288f0bbe1846f 100644 (file)
@@ -237,7 +237,7 @@ static struct page *read_sb_page(mddev_t *mddev, long offset, unsigned long inde
        if (!page)
                return ERR_PTR(-ENOMEM);
 
-       ITERATE_RDEV(mddev, rdev, tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                if (! test_bit(In_sync, &rdev->flags)
                    || test_bit(Faulty, &rdev->flags))
                        continue;
@@ -261,7 +261,7 @@ static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
        struct list_head *tmp;
        mddev_t *mddev = bitmap->mddev;
 
-       ITERATE_RDEV(mddev, rdev, tmp)
+       rdev_for_each(rdev, tmp, mddev)
                if (test_bit(In_sync, &rdev->flags)
                    && !test_bit(Faulty, &rdev->flags)) {
                        int size = PAGE_SIZE;
@@ -1348,14 +1348,38 @@ void bitmap_close_sync(struct bitmap *bitmap)
         */
        sector_t sector = 0;
        int blocks;
-       if (!bitmap) return;
+       if (!bitmap)
+               return;
        while (sector < bitmap->mddev->resync_max_sectors) {
                bitmap_end_sync(bitmap, sector, &blocks, 0);
-/*
-               if (sector < 500) printk("bitmap_close_sync: sec %llu blks %d\n",
-                                        (unsigned long long)sector, blocks);
-*/             sector += blocks;
+               sector += blocks;
+       }
+}
+
+void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector)
+{
+       sector_t s = 0;
+       int blocks;
+
+       if (!bitmap)
+               return;
+       if (sector == 0) {
+               bitmap->last_end_sync = jiffies;
+               return;
+       }
+       if (time_before(jiffies, (bitmap->last_end_sync
+                                 + bitmap->daemon_sleep * HZ)))
+               return;
+       wait_event(bitmap->mddev->recovery_wait,
+                  atomic_read(&bitmap->mddev->recovery_active) == 0);
+
+       sector &= ~((1ULL << CHUNK_BLOCK_SHIFT(bitmap)) - 1);
+       s = 0;
+       while (s < sector && s < bitmap->mddev->resync_max_sectors) {
+               bitmap_end_sync(bitmap, s, &blocks, 0);
+               s += blocks;
        }
+       bitmap->last_end_sync = jiffies;
 }
 
 static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
@@ -1565,3 +1589,4 @@ EXPORT_SYMBOL(bitmap_start_sync);
 EXPORT_SYMBOL(bitmap_end_sync);
 EXPORT_SYMBOL(bitmap_unplug);
 EXPORT_SYMBOL(bitmap_close_sync);
+EXPORT_SYMBOL(bitmap_cond_end_sync);
index cf2ddce341181cb19eb485afb1d1a5925128a57c..d107ddceefcd4651eabaca68f34cf608c4046a56 100644 (file)
@@ -294,7 +294,7 @@ static int run(mddev_t *mddev)
        }
        conf->nfaults = 0;
 
-       ITERATE_RDEV(mddev, rdev, tmp)
+       rdev_for_each(rdev, tmp, mddev)
                conf->rdev = rdev;
 
        mddev->array_size = mddev->size;
index 3dac1cfb81896655f953939a447bb731e9539747..0b8511776b3e75276e9a472ea759e0aa304fff48 100644 (file)
@@ -122,7 +122,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
        cnt = 0;
        conf->array_size = 0;
 
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                int j = rdev->raid_disk;
                dev_info_t *disk = conf->disks + j;
 
index c28a120b4161ea7324eae5160ed2a4c2fc7e0ab6..5fc326d3970e511faf3e6f1a0b4fde30ac0f8f67 100644 (file)
@@ -195,7 +195,7 @@ static DEFINE_SPINLOCK(all_mddevs_lock);
  * Any code which breaks out of this loop while own
  * a reference to the current mddev and must mddev_put it.
  */
-#define ITERATE_MDDEV(mddev,tmp)                                       \
+#define for_each_mddev(mddev,tmp)                                      \
                                                                        \
        for (({ spin_lock(&all_mddevs_lock);                            \
                tmp = all_mddevs.next;                                  \
@@ -275,6 +275,7 @@ static mddev_t * mddev_find(dev_t unit)
        spin_lock_init(&new->write_lock);
        init_waitqueue_head(&new->sb_wait);
        new->reshape_position = MaxSector;
+       new->resync_max = MaxSector;
 
        new->queue = blk_alloc_queue(GFP_KERNEL);
        if (!new->queue) {
@@ -310,7 +311,7 @@ static mdk_rdev_t * find_rdev_nr(mddev_t *mddev, int nr)
        mdk_rdev_t * rdev;
        struct list_head *tmp;
 
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                if (rdev->desc_nr == nr)
                        return rdev;
        }
@@ -322,7 +323,7 @@ static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev)
        struct list_head *tmp;
        mdk_rdev_t *rdev;
 
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                if (rdev->bdev->bd_dev == dev)
                        return rdev;
        }
@@ -773,12 +774,16 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
        __u64 ev1 = md_event(sb);
 
        rdev->raid_disk = -1;
-       rdev->flags = 0;
+       clear_bit(Faulty, &rdev->flags);
+       clear_bit(In_sync, &rdev->flags);
+       clear_bit(WriteMostly, &rdev->flags);
+       clear_bit(BarriersNotsupp, &rdev->flags);
+
        if (mddev->raid_disks == 0) {
                mddev->major_version = 0;
                mddev->minor_version = sb->minor_version;
                mddev->patch_version = sb->patch_version;
-               mddev->persistent = ! sb->not_persistent;
+               mddev->external = 0;
                mddev->chunk_size = sb->chunk_size;
                mddev->ctime = sb->ctime;
                mddev->utime = sb->utime;
@@ -904,7 +909,7 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
        sb->size  = mddev->size;
        sb->raid_disks = mddev->raid_disks;
        sb->md_minor = mddev->md_minor;
-       sb->not_persistent = !mddev->persistent;
+       sb->not_persistent = 0;
        sb->utime = mddev->utime;
        sb->state = 0;
        sb->events_hi = (mddev->events>>32);
@@ -938,7 +943,7 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
                sb->state |= (1<<MD_SB_BITMAP_PRESENT);
 
        sb->disks[0].state = (1<<MD_DISK_REMOVED);
-       ITERATE_RDEV(mddev,rdev2,tmp) {
+       rdev_for_each(rdev2, tmp, mddev) {
                mdp_disk_t *d;
                int desc_nr;
                if (rdev2->raid_disk >= 0 && test_bit(In_sync, &rdev2->flags)
@@ -1153,11 +1158,15 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
        __u64 ev1 = le64_to_cpu(sb->events);
 
        rdev->raid_disk = -1;
-       rdev->flags = 0;
+       clear_bit(Faulty, &rdev->flags);
+       clear_bit(In_sync, &rdev->flags);
+       clear_bit(WriteMostly, &rdev->flags);
+       clear_bit(BarriersNotsupp, &rdev->flags);
+
        if (mddev->raid_disks == 0) {
                mddev->major_version = 1;
                mddev->patch_version = 0;
-               mddev->persistent = 1;
+               mddev->external = 0;
                mddev->chunk_size = le32_to_cpu(sb->chunksize) << 9;
                mddev->ctime = le64_to_cpu(sb->ctime) & ((1ULL << 32)-1);
                mddev->utime = le64_to_cpu(sb->utime) & ((1ULL << 32)-1);
@@ -1286,7 +1295,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
        }
 
        max_dev = 0;
-       ITERATE_RDEV(mddev,rdev2,tmp)
+       rdev_for_each(rdev2, tmp, mddev)
                if (rdev2->desc_nr+1 > max_dev)
                        max_dev = rdev2->desc_nr+1;
 
@@ -1295,7 +1304,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
        for (i=0; i<max_dev;i++)
                sb->dev_roles[i] = cpu_to_le16(0xfffe);
        
-       ITERATE_RDEV(mddev,rdev2,tmp) {
+       rdev_for_each(rdev2, tmp, mddev) {
                i = rdev2->desc_nr;
                if (test_bit(Faulty, &rdev2->flags))
                        sb->dev_roles[i] = cpu_to_le16(0xfffe);
@@ -1333,8 +1342,8 @@ static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2)
        struct list_head *tmp, *tmp2;
        mdk_rdev_t *rdev, *rdev2;
 
-       ITERATE_RDEV(mddev1,rdev,tmp)
-               ITERATE_RDEV(mddev2, rdev2, tmp2)
+       rdev_for_each(rdev, tmp, mddev1)
+               rdev_for_each(rdev2, tmp2, mddev2)
                        if (rdev->bdev->bd_contains ==
                            rdev2->bdev->bd_contains)
                                return 1;
@@ -1401,7 +1410,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
                goto fail;
        }
        list_add(&rdev->same_set, &mddev->disks);
-       bd_claim_by_disk(rdev->bdev, rdev, mddev->gendisk);
+       bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk);
        return 0;
 
  fail:
@@ -1410,10 +1419,11 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
        return err;
 }
 
-static void delayed_delete(struct work_struct *ws)
+static void md_delayed_delete(struct work_struct *ws)
 {
        mdk_rdev_t *rdev = container_of(ws, mdk_rdev_t, del_work);
        kobject_del(&rdev->kobj);
+       kobject_put(&rdev->kobj);
 }
 
 static void unbind_rdev_from_array(mdk_rdev_t * rdev)
@@ -1432,7 +1442,8 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev)
        /* We need to delay this, otherwise we can deadlock when
         * writing to 'remove' to "dev/state"
         */
-       INIT_WORK(&rdev->del_work, delayed_delete);
+       INIT_WORK(&rdev->del_work, md_delayed_delete);
+       kobject_get(&rdev->kobj);
        schedule_work(&rdev->del_work);
 }
 
@@ -1441,7 +1452,7 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev)
  * otherwise reused by a RAID array (or any other kernel
  * subsystem), by bd_claiming the device.
  */
-static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
+static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared)
 {
        int err = 0;
        struct block_device *bdev;
@@ -1453,13 +1464,15 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
                        __bdevname(dev, b));
                return PTR_ERR(bdev);
        }
-       err = bd_claim(bdev, rdev);
+       err = bd_claim(bdev, shared ? (mdk_rdev_t *)lock_rdev : rdev);
        if (err) {
                printk(KERN_ERR "md: could not bd_claim %s.\n",
                        bdevname(bdev, b));
                blkdev_put(bdev);
                return err;
        }
+       if (!shared)
+               set_bit(AllReserved, &rdev->flags);
        rdev->bdev = bdev;
        return err;
 }
@@ -1503,7 +1516,7 @@ static void export_array(mddev_t *mddev)
        struct list_head *tmp;
        mdk_rdev_t *rdev;
 
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                if (!rdev->mddev) {
                        MD_BUG();
                        continue;
@@ -1581,17 +1594,17 @@ static void md_print_devices(void)
        printk("md:     **********************************\n");
        printk("md:     * <COMPLETE RAID STATE PRINTOUT> *\n");
        printk("md:     **********************************\n");
-       ITERATE_MDDEV(mddev,tmp) {
+       for_each_mddev(mddev, tmp) {
 
                if (mddev->bitmap)
                        bitmap_print_sb(mddev->bitmap);
                else
                        printk("%s: ", mdname(mddev));
-               ITERATE_RDEV(mddev,rdev,tmp2)
+               rdev_for_each(rdev, tmp2, mddev)
                        printk("<%s>", bdevname(rdev->bdev,b));
                printk("\n");
 
-               ITERATE_RDEV(mddev,rdev,tmp2)
+               rdev_for_each(rdev, tmp2, mddev)
                        print_rdev(rdev);
        }
        printk("md:     **********************************\n");
@@ -1610,7 +1623,7 @@ static void sync_sbs(mddev_t * mddev, int nospares)
        mdk_rdev_t *rdev;
        struct list_head *tmp;
 
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                if (rdev->sb_events == mddev->events ||
                    (nospares &&
                     rdev->raid_disk < 0 &&
@@ -1696,18 +1709,20 @@ repeat:
                MD_BUG();
                mddev->events --;
        }
-       sync_sbs(mddev, nospares);
 
        /*
         * do not write anything to disk if using
         * nonpersistent superblocks
         */
        if (!mddev->persistent) {
-               clear_bit(MD_CHANGE_PENDING, &mddev->flags);
+               if (!mddev->external)
+                       clear_bit(MD_CHANGE_PENDING, &mddev->flags);
+
                spin_unlock_irq(&mddev->write_lock);
                wake_up(&mddev->sb_wait);
                return;
        }
+       sync_sbs(mddev, nospares);
        spin_unlock_irq(&mddev->write_lock);
 
        dprintk(KERN_INFO 
@@ -1715,7 +1730,7 @@ repeat:
                mdname(mddev),mddev->in_sync);
 
        bitmap_update_sb(mddev->bitmap);
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                char b[BDEVNAME_SIZE];
                dprintk(KERN_INFO "md: ");
                if (rdev->sb_loaded != 1)
@@ -1785,7 +1800,7 @@ static ssize_t
 state_show(mdk_rdev_t *rdev, char *page)
 {
        char *sep = "";
-       int len=0;
+       size_t len = 0;
 
        if (test_bit(Faulty, &rdev->flags)) {
                len+= sprintf(page+len, "%sfaulty",sep);
@@ -1887,20 +1902,45 @@ static ssize_t
 slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
 {
        char *e;
+       int err;
+       char nm[20];
        int slot = simple_strtoul(buf, &e, 10);
        if (strncmp(buf, "none", 4)==0)
                slot = -1;
        else if (e==buf || (*e && *e!= '\n'))
                return -EINVAL;
-       if (rdev->mddev->pers)
-               /* Cannot set slot in active array (yet) */
-               return -EBUSY;
-       if (slot >= rdev->mddev->raid_disks)
-               return -ENOSPC;
-       rdev->raid_disk = slot;
-       /* assume it is working */
-       rdev->flags = 0;
-       set_bit(In_sync, &rdev->flags);
+       if (rdev->mddev->pers) {
+               /* Setting 'slot' on an active array requires also
+                * updating the 'rd%d' link, and communicating
+                * with the personality with ->hot_*_disk.
+                * For now we only support removing
+                * failed/spare devices.  This normally happens automatically,
+                * but not when the metadata is externally managed.
+                */
+               if (slot != -1)
+                       return -EBUSY;
+               if (rdev->raid_disk == -1)
+                       return -EEXIST;
+               /* personality does all needed checks */
+               if (rdev->mddev->pers->hot_add_disk == NULL)
+                       return -EINVAL;
+               err = rdev->mddev->pers->
+                       hot_remove_disk(rdev->mddev, rdev->raid_disk);
+               if (err)
+                       return err;
+               sprintf(nm, "rd%d", rdev->raid_disk);
+               sysfs_remove_link(&rdev->mddev->kobj, nm);
+               set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
+               md_wakeup_thread(rdev->mddev->thread);
+       } else {
+               if (slot >= rdev->mddev->raid_disks)
+                       return -ENOSPC;
+               rdev->raid_disk = slot;
+               /* assume it is working */
+               clear_bit(Faulty, &rdev->flags);
+               clear_bit(WriteMostly, &rdev->flags);
+               set_bit(In_sync, &rdev->flags);
+       }
        return len;
 }
 
@@ -1923,6 +1963,10 @@ offset_store(mdk_rdev_t *rdev, const char *buf, size_t len)
                return -EINVAL;
        if (rdev->mddev->pers)
                return -EBUSY;
+       if (rdev->size && rdev->mddev->external)
+               /* Must set offset before size, so overlap checks
+                * can be sane */
+               return -EBUSY;
        rdev->data_offset = offset;
        return len;
 }
@@ -1936,16 +1980,69 @@ rdev_size_show(mdk_rdev_t *rdev, char *page)
        return sprintf(page, "%llu\n", (unsigned long long)rdev->size);
 }
 
+static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2)
+{
+       /* check if two start/length pairs overlap */
+       if (s1+l1 <= s2)
+               return 0;
+       if (s2+l2 <= s1)
+               return 0;
+       return 1;
+}
+
 static ssize_t
 rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
 {
        char *e;
        unsigned long long size = simple_strtoull(buf, &e, 10);
+       unsigned long long oldsize = rdev->size;
        if (e==buf || (*e && *e != '\n'))
                return -EINVAL;
        if (rdev->mddev->pers)
                return -EBUSY;
        rdev->size = size;
+       if (size > oldsize && rdev->mddev->external) {
+               /* need to check that all other rdevs with the same ->bdev
+                * do not overlap.  We need to unlock the mddev to avoid
+                * a deadlock.  We have already changed rdev->size, and if
+                * we have to change it back, we will have the lock again.
+                */
+               mddev_t *mddev;
+               int overlap = 0;
+               struct list_head *tmp, *tmp2;
+
+               mddev_unlock(rdev->mddev);
+               for_each_mddev(mddev, tmp) {
+                       mdk_rdev_t *rdev2;
+
+                       mddev_lock(mddev);
+                       rdev_for_each(rdev2, tmp2, mddev)
+                               if (test_bit(AllReserved, &rdev2->flags) ||
+                                   (rdev->bdev == rdev2->bdev &&
+                                    rdev != rdev2 &&
+                                    overlaps(rdev->data_offset, rdev->size,
+                                           rdev2->data_offset, rdev2->size))) {
+                                       overlap = 1;
+                                       break;
+                               }
+                       mddev_unlock(mddev);
+                       if (overlap) {
+                               mddev_put(mddev);
+                               break;
+                       }
+               }
+               mddev_lock(rdev->mddev);
+               if (overlap) {
+                       /* Someone else could have slipped in a size
+                        * change here, but doing so is just silly.
+                        * We put oldsize back because we *know* it is
+                        * safe, and trust userspace not to race with
+                        * itself
+                        */
+                       rdev->size = oldsize;
+                       return -EBUSY;
+               }
+       }
        if (size < rdev->mddev->size || rdev->mddev->size == 0)
                rdev->mddev->size = size;
        return len;
@@ -1980,12 +2077,18 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
 {
        struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr);
        mdk_rdev_t *rdev = container_of(kobj, mdk_rdev_t, kobj);
+       int rv;
 
        if (!entry->store)
                return -EIO;
        if (!capable(CAP_SYS_ADMIN))
                return -EACCES;
-       return entry->store(rdev, page, length);
+       rv = mddev_lock(rdev->mddev);
+       if (!rv) {
+               rv = entry->store(rdev, page, length);
+               mddev_unlock(rdev->mddev);
+       }
+       return rv;
 }
 
 static void rdev_free(struct kobject *ko)
@@ -2029,7 +2132,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
        if ((err = alloc_disk_sb(rdev)))
                goto abort_free;
 
-       err = lock_rdev(rdev, newdev);
+       err = lock_rdev(rdev, newdev, super_format == -2);
        if (err)
                goto abort_free;
 
@@ -2099,7 +2202,7 @@ static void analyze_sbs(mddev_t * mddev)
        char b[BDEVNAME_SIZE];
 
        freshest = NULL;
-       ITERATE_RDEV(mddev,rdev,tmp)
+       rdev_for_each(rdev, tmp, mddev)
                switch (super_types[mddev->major_version].
                        load_super(rdev, freshest, mddev->minor_version)) {
                case 1:
@@ -2120,7 +2223,7 @@ static void analyze_sbs(mddev_t * mddev)
                validate_super(mddev, freshest);
 
        i = 0;
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                if (rdev != freshest)
                        if (super_types[mddev->major_version].
                            validate_super(mddev, rdev)) {
@@ -2215,7 +2318,7 @@ level_show(mddev_t *mddev, char *page)
 static ssize_t
 level_store(mddev_t *mddev, const char *buf, size_t len)
 {
-       int rv = len;
+       ssize_t rv = len;
        if (mddev->pers)
                return -EBUSY;
        if (len == 0)
@@ -2425,6 +2528,8 @@ array_state_show(mddev_t *mddev, char *page)
                case 0:
                        if (mddev->in_sync)
                                st = clean;
+                       else if (test_bit(MD_CHANGE_CLEAN, &mddev->flags))
+                               st = write_pending;
                        else if (mddev->safemode)
                                st = active_idle;
                        else
@@ -2455,11 +2560,9 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
                break;
        case clear:
                /* stopping an active array */
-               if (mddev->pers) {
-                       if (atomic_read(&mddev->active) > 1)
-                               return -EBUSY;
-                       err = do_md_stop(mddev, 0);
-               }
+               if (atomic_read(&mddev->active) > 1)
+                       return -EBUSY;
+               err = do_md_stop(mddev, 0);
                break;
        case inactive:
                /* stopping an active array */
@@ -2467,7 +2570,8 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
                        if (atomic_read(&mddev->active) > 1)
                                return -EBUSY;
                        err = do_md_stop(mddev, 2);
-               }
+               } else
+                       err = 0; /* already inactive */
                break;
        case suspended:
                break; /* not supported yet */
@@ -2495,9 +2599,15 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
                        restart_array(mddev);
                        spin_lock_irq(&mddev->write_lock);
                        if (atomic_read(&mddev->writes_pending) == 0) {
-                               mddev->in_sync = 1;
-                               set_bit(MD_CHANGE_CLEAN, &mddev->flags);
-                       }
+                               if (mddev->in_sync == 0) {
+                                       mddev->in_sync = 1;
+                                       if (mddev->persistent)
+                                               set_bit(MD_CHANGE_CLEAN,
+                                                       &mddev->flags);
+                               }
+                               err = 0;
+                       } else
+                               err = -EBUSY;
                        spin_unlock_irq(&mddev->write_lock);
                } else {
                        mddev->ro = 0;
@@ -2508,7 +2618,8 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
        case active:
                if (mddev->pers) {
                        restart_array(mddev);
-                       clear_bit(MD_CHANGE_CLEAN, &mddev->flags);
+                       if (mddev->external)
+                               clear_bit(MD_CHANGE_CLEAN, &mddev->flags);
                        wake_up(&mddev->sb_wait);
                        err = 0;
                } else {
@@ -2574,7 +2685,9 @@ new_dev_store(mddev_t *mddev, const char *buf, size_t len)
                        if (err < 0)
                                goto out;
                }
-       } else
+       } else if (mddev->external)
+               rdev = md_import_device(dev, -2, -1);
+       else
                rdev = md_import_device(dev, -1, -1);
 
        if (IS_ERR(rdev))
@@ -2659,7 +2772,9 @@ __ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store);
 
 
 /* Metdata version.
- * This is either 'none' for arrays with externally managed metadata,
+ * This is one of
+ *   'none' for arrays with no metadata (good luck...)
+ *   'external' for arrays with externally managed metadata,
  * or N.M for internally known formats
  */
 static ssize_t
@@ -2668,6 +2783,8 @@ metadata_show(mddev_t *mddev, char *page)
        if (mddev->persistent)
                return sprintf(page, "%d.%d\n",
                               mddev->major_version, mddev->minor_version);
+       else if (mddev->external)
+               return sprintf(page, "external:%s\n", mddev->metadata_type);
        else
                return sprintf(page, "none\n");
 }
@@ -2682,6 +2799,21 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
 
        if (cmd_match(buf, "none")) {
                mddev->persistent = 0;
+               mddev->external = 0;
+               mddev->major_version = 0;
+               mddev->minor_version = 90;
+               return len;
+       }
+       if (strncmp(buf, "external:", 9) == 0) {
+               size_t namelen = len-9;
+               if (namelen >= sizeof(mddev->metadata_type))
+                       namelen = sizeof(mddev->metadata_type)-1;
+               strncpy(mddev->metadata_type, buf+9, namelen);
+               mddev->metadata_type[namelen] = 0;
+               if (namelen && mddev->metadata_type[namelen-1] == '\n')
+                       mddev->metadata_type[--namelen] = 0;
+               mddev->persistent = 0;
+               mddev->external = 1;
                mddev->major_version = 0;
                mddev->minor_version = 90;
                return len;
@@ -2698,6 +2830,7 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
        mddev->major_version = major;
        mddev->minor_version = minor;
        mddev->persistent = 1;
+       mddev->external = 0;
        return len;
 }
 
@@ -2864,6 +2997,43 @@ sync_completed_show(mddev_t *mddev, char *page)
 
 static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed);
 
+static ssize_t
+max_sync_show(mddev_t *mddev, char *page)
+{
+       if (mddev->resync_max == MaxSector)
+               return sprintf(page, "max\n");
+       else
+               return sprintf(page, "%llu\n",
+                              (unsigned long long)mddev->resync_max);
+}
+static ssize_t
+max_sync_store(mddev_t *mddev, const char *buf, size_t len)
+{
+       if (strncmp(buf, "max", 3) == 0)
+               mddev->resync_max = MaxSector;
+       else {
+               char *ep;
+               unsigned long long max = simple_strtoull(buf, &ep, 10);
+               if (ep == buf || (*ep != 0 && *ep != '\n'))
+                       return -EINVAL;
+               if (max < mddev->resync_max &&
+                   test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
+                       return -EBUSY;
+
+               /* Must be a multiple of chunk_size */
+               if (mddev->chunk_size) {
+                       if (max & (sector_t)((mddev->chunk_size>>9)-1))
+                               return -EINVAL;
+               }
+               mddev->resync_max = max;
+       }
+       wake_up(&mddev->recovery_wait);
+       return len;
+}
+
+static struct md_sysfs_entry md_max_sync =
+__ATTR(sync_max, S_IRUGO|S_IWUSR, max_sync_show, max_sync_store);
+
 static ssize_t
 suspend_lo_show(mddev_t *mddev, char *page)
 {
@@ -2974,6 +3144,7 @@ static struct attribute *md_redundancy_attrs[] = {
        &md_sync_max.attr,
        &md_sync_speed.attr,
        &md_sync_completed.attr,
+       &md_max_sync.attr,
        &md_suspend_lo.attr,
        &md_suspend_hi.attr,
        &md_bitmap.attr,
@@ -3118,8 +3289,11 @@ static int do_md_run(mddev_t * mddev)
        /*
         * Analyze all RAID superblock(s)
         */
-       if (!mddev->raid_disks)
+       if (!mddev->raid_disks) {
+               if (!mddev->persistent)
+                       return -EINVAL;
                analyze_sbs(mddev);
+       }
 
        chunk_size = mddev->chunk_size;
 
@@ -3143,7 +3317,7 @@ static int do_md_run(mddev_t * mddev)
                }
 
                /* devices must have minimum size of one chunk */
-               ITERATE_RDEV(mddev,rdev,tmp) {
+               rdev_for_each(rdev, tmp, mddev) {
                        if (test_bit(Faulty, &rdev->flags))
                                continue;
                        if (rdev->size < chunk_size / 1024) {
@@ -3170,7 +3344,7 @@ static int do_md_run(mddev_t * mddev)
         * the only valid external interface is through the md
         * device.
         */
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                if (test_bit(Faulty, &rdev->flags))
                        continue;
                sync_blockdev(rdev->bdev);
@@ -3236,8 +3410,8 @@ static int do_md_run(mddev_t * mddev)
                mdk_rdev_t *rdev2;
                struct list_head *tmp2;
                int warned = 0;
-               ITERATE_RDEV(mddev, rdev, tmp) {
-                       ITERATE_RDEV(mddev, rdev2, tmp2) {
+               rdev_for_each(rdev, tmp, mddev) {
+                       rdev_for_each(rdev2, tmp2, mddev) {
                                if (rdev < rdev2 &&
                                    rdev->bdev->bd_contains ==
                                    rdev2->bdev->bd_contains) {
@@ -3297,7 +3471,7 @@ static int do_md_run(mddev_t * mddev)
        mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */
        mddev->in_sync = 1;
 
-       ITERATE_RDEV(mddev,rdev,tmp)
+       rdev_for_each(rdev, tmp, mddev)
                if (rdev->raid_disk >= 0) {
                        char nm[20];
                        sprintf(nm, "rd%d", rdev->raid_disk);
@@ -3330,7 +3504,7 @@ static int do_md_run(mddev_t * mddev)
        if (mddev->degraded && !mddev->sync_thread) {
                struct list_head *rtmp;
                int spares = 0;
-               ITERATE_RDEV(mddev,rdev,rtmp)
+               rdev_for_each(rdev, rtmp, mddev)
                        if (rdev->raid_disk >= 0 &&
                            !test_bit(In_sync, &rdev->flags) &&
                            !test_bit(Faulty, &rdev->flags))
@@ -3507,14 +3681,14 @@ static int do_md_stop(mddev_t * mddev, int mode)
                }
                mddev->bitmap_offset = 0;
 
-               ITERATE_RDEV(mddev,rdev,tmp)
+               rdev_for_each(rdev, tmp, mddev)
                        if (rdev->raid_disk >= 0) {
                                char nm[20];
                                sprintf(nm, "rd%d", rdev->raid_disk);
                                sysfs_remove_link(&mddev->kobj, nm);
                        }
 
-               /* make sure all delayed_delete calls have finished */
+               /* make sure all md_delayed_delete calls have finished */
                flush_scheduled_work();
 
                export_array(mddev);
@@ -3523,7 +3697,10 @@ static int do_md_stop(mddev_t * mddev, int mode)
                mddev->size = 0;
                mddev->raid_disks = 0;
                mddev->recovery_cp = 0;
+               mddev->resync_max = MaxSector;
                mddev->reshape_position = MaxSector;
+               mddev->external = 0;
+               mddev->persistent = 0;
 
        } else if (mddev->pers)
                printk(KERN_INFO "md: %s switched to read-only mode.\n",
@@ -3546,7 +3723,7 @@ static void autorun_array(mddev_t *mddev)
 
        printk(KERN_INFO "md: running: ");
 
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                char b[BDEVNAME_SIZE];
                printk("<%s>", bdevname(rdev->bdev,b));
        }
@@ -3589,7 +3766,7 @@ static void autorun_devices(int part)
                printk(KERN_INFO "md: considering %s ...\n",
                        bdevname(rdev0->bdev,b));
                INIT_LIST_HEAD(&candidates);
-               ITERATE_RDEV_PENDING(rdev,tmp)
+               rdev_for_each_list(rdev, tmp, pending_raid_disks)
                        if (super_90_load(rdev, rdev0, 0) >= 0) {
                                printk(KERN_INFO "md:  adding %s ...\n",
                                        bdevname(rdev->bdev,b));
@@ -3632,7 +3809,8 @@ static void autorun_devices(int part)
                        mddev_unlock(mddev);
                } else {
                        printk(KERN_INFO "md: created %s\n", mdname(mddev));
-                       ITERATE_RDEV_GENERIC(candidates,rdev,tmp) {
+                       mddev->persistent = 1;
+                       rdev_for_each_list(rdev, tmp, candidates) {
                                list_del_init(&rdev->same_set);
                                if (bind_rdev_to_array(rdev, mddev))
                                        export_rdev(rdev);
@@ -3643,7 +3821,7 @@ static void autorun_devices(int part)
                /* on success, candidates will be empty, on error
                 * it won't...
                 */
-               ITERATE_RDEV_GENERIC(candidates,rdev,tmp)
+               rdev_for_each_list(rdev, tmp, candidates)
                        export_rdev(rdev);
                mddev_put(mddev);
        }
@@ -3673,7 +3851,7 @@ static int get_array_info(mddev_t * mddev, void __user * arg)
        struct list_head *tmp;
 
        nr=working=active=failed=spare=0;
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                nr++;
                if (test_bit(Faulty, &rdev->flags))
                        failed++;
@@ -3919,8 +4097,6 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
                else
                        rdev->raid_disk = -1;
 
-               rdev->flags = 0;
-
                if (rdev->raid_disk < mddev->raid_disks)
                        if (info->state & (1<<MD_DISK_SYNC))
                                set_bit(In_sync, &rdev->flags);
@@ -4165,13 +4341,15 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
        else
                mddev->recovery_cp = 0;
        mddev->persistent    = ! info->not_persistent;
+       mddev->external      = 0;
 
        mddev->layout        = info->layout;
        mddev->chunk_size    = info->chunk_size;
 
        mddev->max_disks     = MD_SB_DISKS;
 
-       mddev->flags         = 0;
+       if (mddev->persistent)
+               mddev->flags         = 0;
        set_bit(MD_CHANGE_DEVS, &mddev->flags);
 
        mddev->default_bitmap_offset = MD_SB_BYTES >> 9;
@@ -4213,7 +4391,7 @@ static int update_size(mddev_t *mddev, unsigned long size)
         */
        if (mddev->sync_thread)
                return -EBUSY;
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                sector_t avail;
                avail = rdev->size * 2;
 
@@ -4471,9 +4649,10 @@ static int md_ioctl(struct inode *inode, struct file *file,
         */
        /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY,
         * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */
-       if (!mddev->raid_disks && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY
-                       && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE
-                       && cmd != GET_BITMAP_FILE) {
+       if ((!mddev->raid_disks && !mddev->external)
+           && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY
+           && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE
+           && cmd != GET_BITMAP_FILE) {
                err = -ENODEV;
                goto abort_unlock;
        }
@@ -4757,7 +4936,7 @@ static void status_unused(struct seq_file *seq)
 
        seq_printf(seq, "unused devices: ");
 
-       ITERATE_RDEV_PENDING(rdev,tmp) {
+       rdev_for_each_list(rdev, tmp, pending_raid_disks) {
                char b[BDEVNAME_SIZE];
                i++;
                seq_printf(seq, "%s ",
@@ -4953,7 +5132,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
                }
 
                size = 0;
-               ITERATE_RDEV(mddev,rdev,tmp2) {
+               rdev_for_each(rdev, tmp2, mddev) {
                        char b[BDEVNAME_SIZE];
                        seq_printf(seq, " %s[%d]",
                                bdevname(rdev->bdev,b), rdev->desc_nr);
@@ -4982,7 +5161,10 @@ static int md_seq_show(struct seq_file *seq, void *v)
                                           mddev->major_version,
                                           mddev->minor_version);
                        }
-               } else
+               } else if (mddev->external)
+                       seq_printf(seq, " super external:%s",
+                                  mddev->metadata_type);
+               else
                        seq_printf(seq, " super non-persistent");
 
                if (mddev->pers) {
@@ -5106,7 +5288,7 @@ static int is_mddev_idle(mddev_t *mddev)
        long curr_events;
 
        idle = 1;
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
                curr_events = disk_stat_read(disk, sectors[0]) + 
                                disk_stat_read(disk, sectors[1]) - 
@@ -5283,7 +5465,7 @@ void md_do_sync(mddev_t *mddev)
                        set_bit(MD_RECOVERY_INTR, &mddev->recovery);
                        goto skip;
                }
-               ITERATE_MDDEV(mddev2,tmp) {
+               for_each_mddev(mddev2, tmp) {
                        if (mddev2 == mddev)
                                continue;
                        if (mddev2->curr_resync && 
@@ -5333,7 +5515,7 @@ void md_do_sync(mddev_t *mddev)
                /* recovery follows the physical size of devices */
                max_sectors = mddev->size << 1;
                j = MaxSector;
-               ITERATE_RDEV(mddev,rdev,rtmp)
+               rdev_for_each(rdev, rtmp, mddev)
                        if (rdev->raid_disk >= 0 &&
                            !test_bit(Faulty, &rdev->flags) &&
                            !test_bit(In_sync, &rdev->flags) &&
@@ -5381,8 +5563,16 @@ void md_do_sync(mddev_t *mddev)
                sector_t sectors;
 
                skipped = 0;
+               if (j >= mddev->resync_max) {
+                       sysfs_notify(&mddev->kobj, NULL, "sync_completed");
+                       wait_event(mddev->recovery_wait,
+                                  mddev->resync_max > j
+                                  || kthread_should_stop());
+               }
+               if (kthread_should_stop())
+                       goto interrupted;
                sectors = mddev->pers->sync_request(mddev, j, &skipped,
-                                           currspeed < speed_min(mddev));
+                                                 currspeed < speed_min(mddev));
                if (sectors == 0) {
                        set_bit(MD_RECOVERY_ERR, &mddev->recovery);
                        goto out;
@@ -5424,15 +5614,9 @@ void md_do_sync(mddev_t *mddev)
                }
 
 
-               if (kthread_should_stop()) {
-                       /*
-                        * got a signal, exit.
-                        */
-                       printk(KERN_INFO 
-                               "md: md_do_sync() got signal ... exiting\n");
-                       set_bit(MD_RECOVERY_INTR, &mddev->recovery);
-                       goto out;
-               }
+               if (kthread_should_stop())
+                       goto interrupted;
+
 
                /*
                 * this loop exits only if either when we are slower than
@@ -5484,7 +5668,7 @@ void md_do_sync(mddev_t *mddev)
                } else {
                        if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery))
                                mddev->curr_resync = MaxSector;
-                       ITERATE_RDEV(mddev,rdev,rtmp)
+                       rdev_for_each(rdev, rtmp, mddev)
                                if (rdev->raid_disk >= 0 &&
                                    !test_bit(Faulty, &rdev->flags) &&
                                    !test_bit(In_sync, &rdev->flags) &&
@@ -5496,9 +5680,22 @@ void md_do_sync(mddev_t *mddev)
 
  skip:
        mddev->curr_resync = 0;
+       mddev->resync_max = MaxSector;
+       sysfs_notify(&mddev->kobj, NULL, "sync_completed");
        wake_up(&resync_wait);
        set_bit(MD_RECOVERY_DONE, &mddev->recovery);
        md_wakeup_thread(mddev->thread);
+       return;
+
+ interrupted:
+       /*
+        * got a signal, exit.
+        */
+       printk(KERN_INFO
+              "md: md_do_sync() got signal ... exiting\n");
+       set_bit(MD_RECOVERY_INTR, &mddev->recovery);
+       goto out;
+
 }
 EXPORT_SYMBOL_GPL(md_do_sync);
 
@@ -5509,8 +5706,9 @@ static int remove_and_add_spares(mddev_t *mddev)
        struct list_head *rtmp;
        int spares = 0;
 
-       ITERATE_RDEV(mddev,rdev,rtmp)
+       rdev_for_each(rdev, rtmp, mddev)
                if (rdev->raid_disk >= 0 &&
+                   !mddev->external &&
                    (test_bit(Faulty, &rdev->flags) ||
                     ! test_bit(In_sync, &rdev->flags)) &&
                    atomic_read(&rdev->nr_pending)==0) {
@@ -5524,7 +5722,7 @@ static int remove_and_add_spares(mddev_t *mddev)
                }
 
        if (mddev->degraded) {
-               ITERATE_RDEV(mddev,rdev,rtmp)
+               rdev_for_each(rdev, rtmp, mddev)
                        if (rdev->raid_disk < 0
                            && !test_bit(Faulty, &rdev->flags)) {
                                rdev->recovery_offset = 0;
@@ -5589,7 +5787,7 @@ void md_check_recovery(mddev_t *mddev)
        }
 
        if ( ! (
-               mddev->flags ||
+               (mddev->flags && !mddev->external) ||
                test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
                test_bit(MD_RECOVERY_DONE, &mddev->recovery) ||
                (mddev->safemode == 1) ||
@@ -5605,7 +5803,8 @@ void md_check_recovery(mddev_t *mddev)
                if (mddev->safemode && !atomic_read(&mddev->writes_pending) &&
                    !mddev->in_sync && mddev->recovery_cp == MaxSector) {
                        mddev->in_sync = 1;
-                       set_bit(MD_CHANGE_CLEAN, &mddev->flags);
+                       if (mddev->persistent)
+                               set_bit(MD_CHANGE_CLEAN, &mddev->flags);
                }
                if (mddev->safemode == 1)
                        mddev->safemode = 0;
@@ -5637,7 +5836,7 @@ void md_check_recovery(mddev_t *mddev)
                         * information must be scrapped
                         */
                        if (!mddev->degraded)
-                               ITERATE_RDEV(mddev,rdev,rtmp)
+                               rdev_for_each(rdev, rtmp, mddev)
                                        rdev->saved_raid_disk = -1;
 
                        mddev->recovery = 0;
@@ -5714,7 +5913,7 @@ static int md_notify_reboot(struct notifier_block *this,
 
                printk(KERN_INFO "md: stopping all md devices.\n");
 
-               ITERATE_MDDEV(mddev,tmp)
+               for_each_mddev(mddev, tmp)
                        if (mddev_trylock(mddev)) {
                                do_md_stop (mddev, 1);
                                mddev_unlock(mddev);
@@ -5848,7 +6047,7 @@ static __exit void md_exit(void)
        unregister_reboot_notifier(&md_notifier);
        unregister_sysctl_table(raid_table_header);
        remove_proc_entry("mdstat", NULL);
-       ITERATE_MDDEV(mddev,tmp) {
+       for_each_mddev(mddev, tmp) {
                struct gendisk *disk = mddev->gendisk;
                if (!disk)
                        continue;
index adef299908cf79b8323de234882730fc4a82b220..b61d5767aae7c61c3960a09e16c26becb3a1712f 100644 (file)
@@ -1,13 +1,10 @@
-#ident "$Id: mktables.c,v 1.2 2002/12/12 22:41:27 hpa Exp $"
-/* ----------------------------------------------------------------------- *
+/* -*- linux-c -*- ------------------------------------------------------- *
  *
- *   Copyright 2002 H. Peter Anvin - All Rights Reserved
+ *   Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
  *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
- *   Bostom MA 02111-1307, USA; either version 2 of the License, or
- *   (at your option) any later version; incorporated herein by reference.
+ *   This file is part of the Linux kernel, and is made available under
+ *   the terms of the GNU General Public License version 2 or (at your
+ *   option) any later version; incorporated herein by reference.
  *
  * ----------------------------------------------------------------------- */
 
 
 static uint8_t gfmul(uint8_t a, uint8_t b)
 {
-  uint8_t v = 0;
-
-  while ( b ) {
-    if ( b & 1 ) v ^= a;
-    a = (a << 1) ^ (a & 0x80 ? 0x1d : 0);
-    b >>= 1;
-  }
-  return v;
+       uint8_t v = 0;
+
+       while (b) {
+               if (b & 1)
+                       v ^= a;
+               a = (a << 1) ^ (a & 0x80 ? 0x1d : 0);
+               b >>= 1;
+       }
+
+       return v;
 }
 
 static uint8_t gfpow(uint8_t a, int b)
 {
-  uint8_t v = 1;
-
-  b %= 255;
-  if ( b < 0 )
-    b += 255;
-
-  while ( b ) {
-    if ( b & 1 ) v = gfmul(v,a);
-    a = gfmul(a,a);
-    b >>= 1;
-  }
-  return v;
+       uint8_t v = 1;
+
+       b %= 255;
+       if (b < 0)
+               b += 255;
+
+       while (b) {
+               if (b & 1)
+                       v = gfmul(v, a);
+               a = gfmul(a, a);
+               b >>= 1;
+       }
+
+       return v;
 }
 
 int main(int argc, char *argv[])
 {
-  int i, j, k;
-  uint8_t v;
-  uint8_t exptbl[256], invtbl[256];
-
-  printf("#include \"raid6.h\"\n");
-
-  /* Compute multiplication table */
-  printf("\nconst u8  __attribute__((aligned(256)))\n"
-        "raid6_gfmul[256][256] =\n"
-        "{\n");
-  for ( i = 0 ; i < 256 ; i++ ) {
-    printf("\t{\n");
-    for ( j = 0 ; j < 256 ; j += 8 ) {
-      printf("\t\t");
-      for ( k = 0 ; k < 8 ; k++ ) {
-       printf("0x%02x, ", gfmul(i,j+k));
-      }
-      printf("\n");
-    }
-    printf("\t},\n");
-  }
-  printf("};\n");
-
-  /* Compute power-of-2 table (exponent) */
-  v = 1;
-  printf("\nconst u8 __attribute__((aligned(256)))\n"
-        "raid6_gfexp[256] =\n"
-        "{\n");
-  for ( i = 0 ; i < 256 ; i += 8 ) {
-    printf("\t");
-    for ( j = 0 ; j < 8 ; j++ ) {
-      exptbl[i+j] = v;
-      printf("0x%02x, ", v);
-      v = gfmul(v,2);
-      if ( v == 1 ) v = 0;     /* For entry 255, not a real entry */
-    }
-    printf("\n");
-  }
-  printf("};\n");
-
-  /* Compute inverse table x^-1 == x^254 */
-  printf("\nconst u8 __attribute__((aligned(256)))\n"
-        "raid6_gfinv[256] =\n"
-        "{\n");
-  for ( i = 0 ; i < 256 ; i += 8 ) {
-    printf("\t");
-    for ( j = 0 ; j < 8 ; j++ ) {
-      invtbl[i+j] = v = gfpow(i+j,254);
-      printf("0x%02x, ", v);
-    }
-    printf("\n");
-  }
-  printf("};\n");
-
-  /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
-  printf("\nconst u8 __attribute__((aligned(256)))\n"
-        "raid6_gfexi[256] =\n"
-        "{\n");
-  for ( i = 0 ; i < 256 ; i += 8 ) {
-    printf("\t");
-    for ( j = 0 ; j < 8 ; j++ ) {
-      printf("0x%02x, ", invtbl[exptbl[i+j]^1]);
-    }
-    printf("\n");
-  }
-  printf("};\n\n");
-
-  return 0;
+       int i, j, k;
+       uint8_t v;
+       uint8_t exptbl[256], invtbl[256];
+
+       printf("#include \"raid6.h\"\n");
+
+       /* Compute multiplication table */
+       printf("\nconst u8  __attribute__((aligned(256)))\n"
+               "raid6_gfmul[256][256] =\n"
+               "{\n");
+       for (i = 0; i < 256; i++) {
+               printf("\t{\n");
+               for (j = 0; j < 256; j += 8) {
+                       printf("\t\t");
+                       for (k = 0; k < 8; k++)
+                               printf("0x%02x,%c", gfmul(i, j + k),
+                                      (k == 7) ? '\n' : ' ');
+               }
+               printf("\t},\n");
+       }
+       printf("};\n");
+
+       /* Compute power-of-2 table (exponent) */
+       v = 1;
+       printf("\nconst u8 __attribute__((aligned(256)))\n"
+              "raid6_gfexp[256] =\n" "{\n");
+       for (i = 0; i < 256; i += 8) {
+               printf("\t");
+               for (j = 0; j < 8; j++) {
+                       exptbl[i + j] = v;
+                       printf("0x%02x,%c", v, (j == 7) ? '\n' : ' ');
+                       v = gfmul(v, 2);
+                       if (v == 1)
+                               v = 0;  /* For entry 255, not a real entry */
+               }
+       }
+       printf("};\n");
+
+       /* Compute inverse table x^-1 == x^254 */
+       printf("\nconst u8 __attribute__((aligned(256)))\n"
+              "raid6_gfinv[256] =\n" "{\n");
+       for (i = 0; i < 256; i += 8) {
+               printf("\t");
+               for (j = 0; j < 8; j++) {
+                       invtbl[i + j] = v = gfpow(i + j, 254);
+                       printf("0x%02x,%c", v, (j == 7) ? '\n' : ' ');
+               }
+       }
+       printf("};\n");
+
+       /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
+       printf("\nconst u8 __attribute__((aligned(256)))\n"
+              "raid6_gfexi[256] =\n" "{\n");
+       for (i = 0; i < 256; i += 8) {
+               printf("\t");
+               for (j = 0; j < 8; j++)
+                       printf("0x%02x,%c", invtbl[exptbl[i + j] ^ 1],
+                              (j == 7) ? '\n' : ' ');
+       }
+       printf("};\n");
+
+       return 0;
 }
index eb631ebed6860b3f19ae8c3161a10e509d448d3e..3f299d835a2b1956e210c0a383e65f2d9c70874f 100644 (file)
@@ -436,7 +436,7 @@ static int multipath_run (mddev_t *mddev)
        }
 
        conf->working_disks = 0;
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                disk_idx = rdev->raid_disk;
                if (disk_idx < 0 ||
                    disk_idx >= mddev->raid_disks)
index f8e591708d1fa7768fda354aa8da006b1f26d549..818b4828409667d5a40b53efb734575dd00ee3a2 100644 (file)
@@ -72,11 +72,11 @@ static int create_strip_zones (mddev_t *mddev)
         */
        conf->nr_strip_zones = 0;
  
-       ITERATE_RDEV(mddev,rdev1,tmp1) {
+       rdev_for_each(rdev1, tmp1, mddev) {
                printk("raid0: looking at %s\n",
                        bdevname(rdev1->bdev,b));
                c = 0;
-               ITERATE_RDEV(mddev,rdev2,tmp2) {
+               rdev_for_each(rdev2, tmp2, mddev) {
                        printk("raid0:   comparing %s(%llu)",
                               bdevname(rdev1->bdev,b),
                               (unsigned long long)rdev1->size);
@@ -124,7 +124,7 @@ static int create_strip_zones (mddev_t *mddev)
        cnt = 0;
        smallest = NULL;
        zone->dev = conf->devlist;
-       ITERATE_RDEV(mddev, rdev1, tmp1) {
+       rdev_for_each(rdev1, tmp1, mddev) {
                int j = rdev1->raid_disk;
 
                if (j < 0 || j >= mddev->raid_disks) {
@@ -293,7 +293,7 @@ static int raid0_run (mddev_t *mddev)
 
        /* calculate array device size */
        mddev->array_size = 0;
-       ITERATE_RDEV(mddev,rdev,tmp)
+       rdev_for_each(rdev, tmp, mddev)
                mddev->array_size += rdev->size;
 
        printk("raid0 : md_size is %llu blocks.\n", 
index 4a69c416e045c97f24ef4582c9d3b9f83588ba15..5c7fef091cec800da3f3cb482f7e97f574cb43c6 100644 (file)
@@ -1684,6 +1684,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
        if (!go_faster && conf->nr_waiting)
                msleep_interruptible(1000);
 
+       bitmap_cond_end_sync(mddev->bitmap, sector_nr);
        raise_barrier(conf);
 
        conf->next_resync = sector_nr;
@@ -1766,6 +1767,8 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
                return rv;
        }
 
+       if (max_sector > mddev->resync_max)
+               max_sector = mddev->resync_max; /* Don't do IO beyond here */
        nr_sectors = 0;
        sync_blocks = 0;
        do {
@@ -1884,7 +1887,7 @@ static int run(mddev_t *mddev)
        if (!conf->r1bio_pool)
                goto out_no_mem;
 
-       ITERATE_RDEV(mddev, rdev, tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                disk_idx = rdev->raid_disk;
                if (disk_idx >= mddev->raid_disks
                    || disk_idx < 0)
index 5cdcc938620050b39fb30593565847859d6ad1a4..017f58113c33604e381a5fcc7c75f01344f67841 100644 (file)
@@ -1657,6 +1657,9 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
                return (max_sector - sector_nr) + sectors_skipped;
        }
 
+       if (max_sector > mddev->resync_max)
+               max_sector = mddev->resync_max; /* Don't do IO beyond here */
+
        /* make sure whole request will fit in a chunk - if chunks
         * are meaningful
         */
@@ -1670,6 +1673,8 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
        if (!go_faster && conf->nr_waiting)
                msleep_interruptible(1000);
 
+       bitmap_cond_end_sync(mddev->bitmap, sector_nr);
+
        /* Again, very different code for resync and recovery.
         * Both must result in an r10bio with a list of bios that
         * have bi_end_io, bi_sector, bi_bdev set,
@@ -2021,7 +2026,7 @@ static int run(mddev_t *mddev)
                goto out_free_conf;
        }
 
-       ITERATE_RDEV(mddev, rdev, tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                disk_idx = rdev->raid_disk;
                if (disk_idx >= mddev->raid_disks
                    || disk_idx < 0)
index e8c8157b02fcb5e99a09786b977e30226e56ed95..2d6f1a51359cc490dcfd4f9b6bc5b1add12cf9a0 100644 (file)
@@ -3159,7 +3159,8 @@ static void raid5_activate_delayed(raid5_conf_t *conf)
                                atomic_inc(&conf->preread_active_stripes);
                        list_add_tail(&sh->lru, &conf->handle_list);
                }
-       }
+       } else
+               blk_plug_device(conf->mddev->queue);
 }
 
 static void activate_bit_delay(raid5_conf_t *conf)
@@ -3549,7 +3550,8 @@ static int make_request(struct request_queue *q, struct bio * bi)
                                goto retry;
                        }
                        finish_wait(&conf->wait_for_overlap, &w);
-                       handle_stripe(sh, NULL);
+                       set_bit(STRIPE_HANDLE, &sh->state);
+                       clear_bit(STRIPE_DELAYED, &sh->state);
                        release_stripe(sh);
                } else {
                        /* cannot get stripe for read-ahead, just give-up */
@@ -3698,6 +3700,25 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
                release_stripe(sh);
                first_sector += STRIPE_SECTORS;
        }
+       /* If this takes us to the resync_max point where we have to pause,
+        * then we need to write out the superblock.
+        */
+       sector_nr += conf->chunk_size>>9;
+       if (sector_nr >= mddev->resync_max) {
+               /* Cannot proceed until we've updated the superblock... */
+               wait_event(conf->wait_for_overlap,
+                          atomic_read(&conf->reshape_stripes) == 0);
+               mddev->reshape_position = conf->expand_progress;
+               set_bit(MD_CHANGE_DEVS, &mddev->flags);
+               md_wakeup_thread(mddev->thread);
+               wait_event(mddev->sb_wait,
+                          !test_bit(MD_CHANGE_DEVS, &mddev->flags)
+                          || kthread_should_stop());
+               spin_lock_irq(&conf->device_lock);
+               conf->expand_lo = mddev->reshape_position;
+               spin_unlock_irq(&conf->device_lock);
+               wake_up(&conf->wait_for_overlap);
+       }
        return conf->chunk_size>>9;
 }
 
@@ -3734,6 +3755,12 @@ static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *ski
        if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
                return reshape_request(mddev, sector_nr, skipped);
 
+       /* No need to check resync_max as we never do more than one
+        * stripe, and as resync_max will always be on a chunk boundary,
+        * if the check in md_do_sync didn't fire, there is no chance
+        * of overstepping resync_max here
+        */
+
        /* if there is too many failed drives and we are trying
         * to resync, then assert that we are finished, because there is
         * nothing we can do.
@@ -3753,6 +3780,9 @@ static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *ski
                return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
        }
 
+
+       bitmap_cond_end_sync(mddev->bitmap, sector_nr);
+
        pd_idx = stripe_to_pdidx(sector_nr, conf, raid_disks);
        sh = get_active_stripe(conf, sector_nr, raid_disks, pd_idx, 1);
        if (sh == NULL) {
@@ -3864,7 +3894,7 @@ static int  retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio)
  * During the scan, completed stripes are saved for us by the interrupt
  * handler, so that they will not have to wait for our next wakeup.
  */
-static void raid5d (mddev_t *mddev)
+static void raid5d(mddev_t *mddev)
 {
        struct stripe_head *sh;
        raid5_conf_t *conf = mddev_to_conf(mddev);
@@ -3889,12 +3919,6 @@ static void raid5d (mddev_t *mddev)
                        activate_bit_delay(conf);
                }
 
-               if (list_empty(&conf->handle_list) &&
-                   atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD &&
-                   !blk_queue_plugged(mddev->queue) &&
-                   !list_empty(&conf->delayed_list))
-                       raid5_activate_delayed(conf);
-
                while ((bio = remove_bio_from_retry(conf))) {
                        int ok;
                        spin_unlock_irq(&conf->device_lock);
@@ -4108,7 +4132,7 @@ static int run(mddev_t *mddev)
 
        pr_debug("raid5: run(%s) called.\n", mdname(mddev));
 
-       ITERATE_RDEV(mddev,rdev,tmp) {
+       rdev_for_each(rdev, tmp, mddev) {
                raid_disk = rdev->raid_disk;
                if (raid_disk >= conf->raid_disks
                    || raid_disk < 0)
@@ -4521,7 +4545,7 @@ static int raid5_start_reshape(mddev_t *mddev)
        if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
                return -EBUSY;
 
-       ITERATE_RDEV(mddev, rdev, rtmp)
+       rdev_for_each(rdev, rtmp, mddev)
                if (rdev->raid_disk < 0 &&
                    !test_bit(Faulty, &rdev->flags))
                        spares++;
@@ -4543,7 +4567,7 @@ static int raid5_start_reshape(mddev_t *mddev)
        /* Add some new drives, as many as will fit.
         * We know there are enough to make the newly sized array work.
         */
-       ITERATE_RDEV(mddev, rdev, rtmp)
+       rdev_for_each(rdev, rtmp, mddev)
                if (rdev->raid_disk < 0 &&
                    !test_bit(Faulty, &rdev->flags)) {
                        if (raid5_add_disk(mddev, rdev)) {
index 0d5cd57accd72fc38dc29d41b4725e4bd12880a0..559cc41b258566d4b0437241559156fbbc574721 100644 (file)
@@ -1,12 +1,10 @@
 /* -*- linux-c -*- ------------------------------------------------------- *
  *
- *   Copyright 2002 H. Peter Anvin - All Rights Reserved
+ *   Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
  *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
- *   Bostom MA 02111-1307, USA; either version 2 of the License, or
- *   (at your option) any later version; incorporated herein by reference.
+ *   This file is part of the Linux kernel, and is made available under
+ *   the terms of the GNU General Public License version 2 or (at your
+ *   option) any later version; incorporated herein by reference.
  *
  * ----------------------------------------------------------------------- */
 
@@ -30,67 +28,87 @@ char *dataptrs[NDISKS];
 char data[NDISKS][PAGE_SIZE];
 char recovi[PAGE_SIZE], recovj[PAGE_SIZE];
 
-void makedata(void)
+static void makedata(void)
 {
        int i, j;
 
-       for (  i = 0 ; i < NDISKS ; i++ ) {
-               for ( j = 0 ; j < PAGE_SIZE ; j++ ) {
+       for (i = 0; i < NDISKS; i++) {
+               for (j = 0; j < PAGE_SIZE; j++)
                        data[i][j] = rand();
-               }
+
                dataptrs[i] = data[i];
        }
 }
 
+static char disk_type(int d)
+{
+       switch (d) {
+       case NDISKS-2:
+               return 'P';
+       case NDISKS-1:
+               return 'Q';
+       default:
+               return 'D';
+       }
+}
+
+static int test_disks(int i, int j)
+{
+       int erra, errb;
+
+       memset(recovi, 0xf0, PAGE_SIZE);
+       memset(recovj, 0xba, PAGE_SIZE);
+
+       dataptrs[i] = recovi;
+       dataptrs[j] = recovj;
+
+       raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
+
+       erra = memcmp(data[i], recovi, PAGE_SIZE);
+       errb = memcmp(data[j], recovj, PAGE_SIZE);
+
+       if (i < NDISKS-2 && j == NDISKS-1) {
+               /* We don't implement the DQ failure scenario, since it's
+                  equivalent to a RAID-5 failure (XOR, then recompute Q) */
+               erra = errb = 0;
+       } else {
+               printf("algo=%-8s  faila=%3d(%c)  failb=%3d(%c)  %s\n",
+                      raid6_call.name,
+                      i, disk_type(i),
+                      j, disk_type(j),
+                      (!erra && !errb) ? "OK" :
+                      !erra ? "ERRB" :
+                      !errb ? "ERRA" : "ERRAB");
+       }
+
+       dataptrs[i] = data[i];
+       dataptrs[j] = data[j];
+
+       return erra || errb;
+}
+
 int main(int argc, char *argv[])
 {
-       const struct raid6_calls * const * algo;
+       const struct raid6_calls *const *algo;
        int i, j;
-       int erra, errb;
+       int err = 0;
 
        makedata();
 
-       for ( algo = raid6_algos ; *algo ; algo++ ) {
-               if ( !(*algo)->valid || (*algo)->valid() ) {
+       for (algo = raid6_algos; *algo; algo++) {
+               if (!(*algo)->valid || (*algo)->valid()) {
                        raid6_call = **algo;
 
                        /* Nuke syndromes */
                        memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
 
                        /* Generate assumed good syndrome */
-                       raid6_call.gen_syndrome(NDISKS, PAGE_SIZE, (void **)&dataptrs);
-
-                       for ( i = 0 ; i < NDISKS-1 ; i++ ) {
-                               for ( j = i+1 ; j < NDISKS ; j++ ) {
-                                       memset(recovi, 0xf0, PAGE_SIZE);
-                                       memset(recovj, 0xba, PAGE_SIZE);
-
-                                       dataptrs[i] = recovi;
-                                       dataptrs[j] = recovj;
-
-                                       raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
-
-                                       erra = memcmp(data[i], recovi, PAGE_SIZE);
-                                       errb = memcmp(data[j], recovj, PAGE_SIZE);
-
-                                       if ( i < NDISKS-2 && j == NDISKS-1 ) {
-                                               /* We don't implement the DQ failure scenario, since it's
-                                                  equivalent to a RAID-5 failure (XOR, then recompute Q) */
-                                       } else {
-                                               printf("algo=%-8s  faila=%3d(%c)  failb=%3d(%c)  %s\n",
-                                                      raid6_call.name,
-                                                      i, (i==NDISKS-2)?'P':'D',
-                                                      j, (j==NDISKS-1)?'Q':(j==NDISKS-2)?'P':'D',
-                                                      (!erra && !errb) ? "OK" :
-                                                      !erra ? "ERRB" :
-                                                      !errb ? "ERRA" :
-                                                      "ERRAB");
-                                       }
-
-                                       dataptrs[i] = data[i];
-                                       dataptrs[j] = data[j];
-                               }
-                       }
+                       raid6_call.gen_syndrome(NDISKS, PAGE_SIZE,
+                                               (void **)&dataptrs);
+
+                       for (i = 0; i < NDISKS-1; i++)
+                               for (j = i+1; j < NDISKS; j++)
+                                       err += test_disks(i, j);
                }
                printf("\n");
        }
@@ -99,5 +117,8 @@ int main(int argc, char *argv[])
        /* Pick the best algorithm test */
        raid6_select_algo();
 
-       return 0;
+       if (err)
+               printf("\n*** ERRORS FOUND ***\n");
+
+       return err;
 }
index 7d04a6fd1acb03affddb06faada0a40018066a19..168a8d3a5e556e889b7b44033b06531addb9faf8 100644 (file)
@@ -388,7 +388,7 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
        }
        dev->revision &= 0xf;
 
-       /* remap the memory from virtual to physical adress */
+       /* remap the memory from virtual to physical address */
 
        err = pci_request_region(pci, 0, "saa7146");
        if (err < 0)
index a33eb5988c42e8aa1fcf64c1959084617c3d8e8e..ed3f8268ed11445e60fce10500a66e15d3e3be53 100644 (file)
@@ -681,7 +681,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                                        drop = 1;
                                                /* else: destination address matches the MAC address of our receiver device */
                                        }
-                                       /* else: promiscious mode; pass everything up the stack */
+                                       /* else: promiscuous mode; pass everything up the stack */
 
                                        if (drop) {
 #ifdef ULE_DEBUG
index 28ddd146c1c52a208222945cd816a0504db3431b..850b8c6f457783e0a9282b230615b772d7e5104c 100644 (file)
@@ -22,7 +22,6 @@ obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
 obj-$(CONFIG_VIDEO_TVAUDIO) += tvaudio.o
 obj-$(CONFIG_VIDEO_TDA7432) += tda7432.o
 obj-$(CONFIG_VIDEO_TDA9875) += tda9875.o
-obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
 
 obj-$(CONFIG_VIDEO_SAA6588) += saa6588.o
 obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o
index 63a47cd4c161110796503cfc3a83fa5412e9ba7a..7374c02dd183fc1a5d457b8899828dab9c195dd8 100644 (file)
@@ -4344,7 +4344,7 @@ static void rv605_muxsel(struct bttv *btv, unsigned int input)
        gpio_bits(0x200,0x000);
        mdelay(1);
 
-       /* create a new conection */
+       /* create a new connection */
        gpio_bits(0x480,0x080);
        gpio_bits(0x480,0x480);
        mdelay(1);
index 5c2c4029ff86bd76a3872152b198b58259e73936..84b9e4f2b3b3fcef7c25b2b60d88df30925d44f6 100644 (file)
@@ -326,7 +326,7 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind)
        // initialize
        err = indycam_write_block(client, 0, sizeof(initseq), (u8 *)&initseq);
        if (err) {
-               printk(KERN_ERR "IndyCam initalization failed\n");
+               printk(KERN_ERR "IndyCam initialization failed\n");
                err = -EIO;
                goto out_detach_client;
        }
index b630c26cfe856b9b45ead161d34ee013fddbeadc..58bab653330fee8ce0b6e26d618cd02c3c9fb37e 100644 (file)
@@ -369,7 +369,7 @@ static struct dvb_tuner_ops mt2032_tuner_ops = {
        .get_frequency     = microtune_get_frequency,
 };
 
-// Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
+// Initialization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
 static int mt2032_init(struct dvb_frontend *fe)
 {
        struct microtune_priv *priv = fe->tuner_priv;
index 074533e9c21ee69079ed0de2ea15df86bed86b04..1a9a4baf12b84664821c42b862789f68a4fcf20d 100644 (file)
@@ -27,7 +27,7 @@
    might want to increase this - however the driver operation will not
    be impaired if it is too small.  Instead additional units just
    won't have an ID assigned and it might not be possible to specify
-   module paramters for those extra units. */
+   module parameters for those extra units. */
 #define PVR_NUM 20
 
 #endif /* __PVRUSB2_H */
index 7300ace8f44ed1331bb5f385b3821dfb749aedf9..f991d72fe10808d29263e7c0cb6411e9f93bc0b1 100644 (file)
@@ -542,7 +542,7 @@ int pwc_handle_frame(struct pwc_device *pdev)
        }
 
        if (pdev->read_frame != NULL) {
-               /* Decompression is a lenghty process, so it's outside of the lock.
+               /* Decompression is a lengthy process, so it's outside of the lock.
                   This gives the isoc_handler the opportunity to fill more frames
                   in the mean time.
                */
index e0ff811fab6f3e69a69af355e287f4d6db29c92e..ca05cd65508765559524b104dc7805ab5dad278f 100644 (file)
@@ -57,7 +57,7 @@ static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
 
        dprintk("adr:0x%02x, i:%d, o:%d, g:%d\n", client->addr, i, o, g);
 
-       /* check if the paramters are valid */
+       /* check if the parameters are valid */
        if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0)
                return -1;
 
diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c
deleted file mode 100644 (file)
index 9fa5b70..0000000
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/timer.h>
-#include <linux/delay.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/i2c.h>
-#include <linux/videodev.h>
-#include <linux/init.h>
-#include <linux/kdev_t.h>
-#include <linux/sound.h>
-#include <linux/soundcard.h>
-
-#include <asm/semaphore.h>
-#include <asm/uaccess.h>
-
-
-#define DEV_MAX  4
-
-static int devnr = -1;
-module_param(devnr, int, 0644);
-
-MODULE_AUTHOR("Gerd Knorr");
-MODULE_LICENSE("GPL");
-
-/* ----------------------------------------------------------------------- */
-
-struct TVMIXER {
-       struct i2c_client *dev;
-       int minor;
-       int count;
-};
-
-static struct TVMIXER devices[DEV_MAX];
-
-static int tvmixer_adapters(struct i2c_adapter *adap);
-static int tvmixer_clients(struct i2c_client *client);
-
-/* ----------------------------------------------------------------------- */
-
-static int mix_to_v4l(int i)
-{
-       int r;
-
-       r = ((i & 0xff) * 65536 + 50) / 100;
-       if (r > 65535) r = 65535;
-       if (r <     0) r =     0;
-       return r;
-}
-
-static int v4l_to_mix(int i)
-{
-       int r;
-
-       r = (i * 100 + 32768) / 65536;
-       if (r > 100) r = 100;
-       if (r <   0) r =   0;
-       return r | (r << 8);
-}
-
-static int v4l_to_mix2(int l, int r)
-{
-       r = (r * 100 + 32768) / 65536;
-       if (r > 100) r = 100;
-       if (r <   0) r =   0;
-       l = (l * 100 + 32768) / 65536;
-       if (l > 100) l = 100;
-       if (l <   0) l =   0;
-       return (r << 8) | l;
-}
-
-static int tvmixer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-{
-       struct video_audio va;
-       int left,right,ret,val = 0;
-       struct TVMIXER *mix = file->private_data;
-       struct i2c_client *client = mix->dev;
-       void __user *argp = (void __user *)arg;
-       int __user *p = argp;
-
-       if (NULL == client)
-               return -ENODEV;
-
-       if (cmd == SOUND_MIXER_INFO) {
-               mixer_info info;
-               strlcpy(info.id, "tv card", sizeof(info.id));
-               strlcpy(info.name, client->name, sizeof(info.name));
-               info.modify_counter = 42 /* FIXME */;
-               if (copy_to_user(argp, &info, sizeof(info)))
-                       return -EFAULT;
-               return 0;
-       }
-       if (cmd == SOUND_OLD_MIXER_INFO) {
-               _old_mixer_info info;
-               strlcpy(info.id, "tv card", sizeof(info.id));
-               strlcpy(info.name, client->name, sizeof(info.name));
-               if (copy_to_user(argp, &info, sizeof(info)))
-                       return -EFAULT;
-               return 0;
-       }
-       if (cmd == OSS_GETVERSION)
-               return put_user(SOUND_VERSION, p);
-
-       if (_SIOC_DIR(cmd) & _SIOC_WRITE)
-               if (get_user(val, p))
-                       return -EFAULT;
-
-       /* read state */
-       memset(&va,0,sizeof(va));
-       client->driver->command(client,VIDIOCGAUDIO,&va);
-
-       switch (cmd) {
-       case MIXER_READ(SOUND_MIXER_RECMASK):
-       case MIXER_READ(SOUND_MIXER_CAPS):
-       case MIXER_READ(SOUND_MIXER_RECSRC):
-       case MIXER_WRITE(SOUND_MIXER_RECSRC):
-               ret = 0;
-               break;
-
-       case MIXER_READ(SOUND_MIXER_STEREODEVS):
-               ret = SOUND_MASK_VOLUME;
-               break;
-       case MIXER_READ(SOUND_MIXER_DEVMASK):
-               ret = SOUND_MASK_VOLUME;
-               if (va.flags & VIDEO_AUDIO_BASS)
-                       ret |= SOUND_MASK_BASS;
-               if (va.flags & VIDEO_AUDIO_TREBLE)
-                       ret |= SOUND_MASK_TREBLE;
-               break;
-
-       case MIXER_WRITE(SOUND_MIXER_VOLUME):
-               left  = mix_to_v4l(val);
-               right = mix_to_v4l(val >> 8);
-               va.volume  = max(left,right);
-               va.balance = (32768*min(left,right)) / (va.volume ? va.volume : 1);
-               va.balance = (left<right) ? (65535-va.balance) : va.balance;
-               if (va.volume)
-                       va.flags &= ~VIDEO_AUDIO_MUTE;
-               client->driver->command(client,VIDIOCSAUDIO,&va);
-               client->driver->command(client,VIDIOCGAUDIO,&va);
-               /* fall throuth */
-       case MIXER_READ(SOUND_MIXER_VOLUME):
-               left  = (min(65536 - va.balance,32768) *
-                        va.volume) / 32768;
-               right = (min(va.balance,(u16)32768) *
-                        va.volume) / 32768;
-               ret = v4l_to_mix2(left,right);
-               break;
-
-       case MIXER_WRITE(SOUND_MIXER_BASS):
-               va.bass = mix_to_v4l(val);
-               client->driver->command(client,VIDIOCSAUDIO,&va);
-               client->driver->command(client,VIDIOCGAUDIO,&va);
-               /* fall throuth  */
-       case MIXER_READ(SOUND_MIXER_BASS):
-               ret = v4l_to_mix(va.bass);
-               break;
-
-       case MIXER_WRITE(SOUND_MIXER_TREBLE):
-               va.treble = mix_to_v4l(val);
-               client->driver->command(client,VIDIOCSAUDIO,&va);
-               client->driver->command(client,VIDIOCGAUDIO,&va);
-               /* fall throuth */
-       case MIXER_READ(SOUND_MIXER_TREBLE):
-               ret = v4l_to_mix(va.treble);
-               break;
-
-       default:
-               return -EINVAL;
-       }
-       if (put_user(ret, p))
-               return -EFAULT;
-       return 0;
-}
-
-static int tvmixer_open(struct inode *inode, struct file *file)
-{
-       int i, minor = iminor(inode);
-       struct TVMIXER *mix = NULL;
-       struct i2c_client *client = NULL;
-
-       for (i = 0; i < DEV_MAX; i++) {
-               if (devices[i].minor == minor) {
-                       mix = devices+i;
-                       client = mix->dev;
-                       break;
-               }
-       }
-
-       if (NULL == client)
-               return -ENODEV;
-
-       /* lock bttv in memory while the mixer is in use  */
-       file->private_data = mix;
-       if (client->adapter->owner)
-               try_module_get(client->adapter->owner);
-       return 0;
-}
-
-static int tvmixer_release(struct inode *inode, struct file *file)
-{
-       struct TVMIXER *mix = file->private_data;
-       struct i2c_client *client;
-
-       client = mix->dev;
-       if (NULL == client) {
-               return -ENODEV;
-       }
-
-       module_put(client->adapter->owner);
-       return 0;
-}
-
-static struct i2c_driver driver = {
-       .driver = {
-               .name    = "tvmixer",
-       },
-       .id              = I2C_DRIVERID_TVMIXER,
-       .detach_adapter  = tvmixer_adapters,
-       .attach_adapter  = tvmixer_adapters,
-       .detach_client   = tvmixer_clients,
-};
-
-static const struct file_operations tvmixer_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .ioctl          = tvmixer_ioctl,
-       .open           = tvmixer_open,
-       .release        = tvmixer_release,
-};
-
-/* ----------------------------------------------------------------------- */
-
-static int tvmixer_adapters(struct i2c_adapter *adap)
-{
-       struct i2c_client *client;
-
-       list_for_each_entry(client, &adap->clients, list)
-               tvmixer_clients(client);
-       return 0;
-}
-
-static int tvmixer_clients(struct i2c_client *client)
-{
-       struct video_audio va;
-       int i,minor;
-
-       if (!(client->adapter->class & I2C_CLASS_TV_ANALOG))
-               return -1;
-
-       /* unregister ?? */
-       for (i = 0; i < DEV_MAX; i++) {
-               if (devices[i].dev == client) {
-                       /* unregister */
-                       unregister_sound_mixer(devices[i].minor);
-                       devices[i].dev = NULL;
-                       devices[i].minor = -1;
-                       printk("tvmixer: %s unregistered (#1)\n",
-                              client->name);
-                       return 0;
-               }
-       }
-
-       /* look for a free slot */
-       for (i = 0; i < DEV_MAX; i++)
-               if (NULL == devices[i].dev)
-                       break;
-       if (i == DEV_MAX) {
-               printk(KERN_WARNING "tvmixer: DEV_MAX too small\n");
-               return -1;
-       }
-
-       /* audio chip with mixer ??? */
-       if (NULL == client->driver->command)
-               return -1;
-       memset(&va,0,sizeof(va));
-       if (0 != client->driver->command(client,VIDIOCGAUDIO,&va))
-               return -1;
-       if (0 == (va.flags & VIDEO_AUDIO_VOLUME))
-               return -1;
-
-       /* everything is fine, register */
-       if ((minor = register_sound_mixer(&tvmixer_fops,devnr)) < 0) {
-               printk(KERN_ERR "tvmixer: cannot allocate mixer device\n");
-               return -1;
-       }
-
-       devices[i].minor = minor;
-       devices[i].count = 0;
-       devices[i].dev   = client;
-       printk("tvmixer: %s (%s) registered with minor %d\n",
-              client->name,client->adapter->name,minor);
-
-       return 0;
-}
-
-/* ----------------------------------------------------------------------- */
-
-static int __init tvmixer_init_module(void)
-{
-       int i;
-
-       for (i = 0; i < DEV_MAX; i++)
-               devices[i].minor = -1;
-
-       return i2c_add_driver(&driver);
-}
-
-static void __exit tvmixer_cleanup_module(void)
-{
-       int i;
-
-       i2c_del_driver(&driver);
-       for (i = 0; i < DEV_MAX; i++) {
-               if (devices[i].minor != -1) {
-                       unregister_sound_mixer(devices[i].minor);
-                       printk("tvmixer: %s unregistered (#2)\n",
-                              devices[i].dev->name);
-               }
-       }
-}
-
-module_init(tvmixer_init_module);
-module_exit(tvmixer_cleanup_module);
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
index d847273eeba0c247c4f707a4fed3b00feef04b3e..5e7b795013706591aff8dfb09099d9dd60a8fff1 100644 (file)
@@ -258,7 +258,7 @@ static void qcm_hsv2rgb(u16 hue, u16 sat, u16 val, u16 *r, u16 *g, u16 *b)
        unsigned int p;
 
        /*
-       the registers controling gain are 8 bit of which
+       the registers controlling gain are 8 bit of which
        we affect only the last 4 bits with our gain.
        we know that if saturation is 0, (unsaturated) then
        we're grayscale (center axis of the colour cone) so
index b52b826a30be8b5fb38f03ed38de20dc3e338ee9..df52f8a602155c6c32e26011f6dd93f0c6c7b097 100644 (file)
@@ -131,7 +131,7 @@ static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
 /* Function prototypes */
 static void usbvision_release(struct usb_usbvision *usbvision);
 
-/* Default initalization of device driver parameters */
+/* Default initialization of device driver parameters */
 /* Set the default format for ISOC endpoint */
 static int isocMode = ISOC_MODE_COMPRESS;
 /* Set the default Debug Mode of the device driver */
index 8ef31ed7d3f1133edfe514ba0b34445d3aaed3a6..a9133858e913552e62474792ad6b647a0865edd5 100644 (file)
@@ -566,7 +566,7 @@ vpx3220_init_client (struct i2c_client *client)
 }
 
 /* -----------------------------------------------------------------------
- * Client managment code
+ * Client management code
  */
 
 /*
index 6e0ac4c5c379683187645e104e467b82c171b196..690281bb59ee616f71db4393d7b63a4080455284 100644 (file)
@@ -1270,7 +1270,7 @@ zoran_setup_videocodec (struct zoran *zr,
 }
 
 /*
- *   Scan for a Buz card (actually for the PCI contoler ZR36057),
+ *   Scan for a Buz card (actually for the PCI controller ZR36057),
  *   request the irq and map the io memory
  */
 static int __devinit
index 9f622e00c479b573875bd062886afa8688063c5c..faae4ec3ea0bf5288f12a1c52a78ce75e12bd7c2 100644 (file)
@@ -161,7 +161,7 @@ zr36050_wait_end (struct zr36050 *ptr)
                udelay(1);
                if (i++ > 200000) {     // 200ms, there is for sure something wrong!!!
                        dprintk(1,
-                               "%s: timout at wait_end (last status: 0x%02x)\n",
+                               "%s: timeout at wait_end (last status: 0x%02x)\n",
                                ptr->name, ptr->status1);
                        break;
                }
index 1ef14fef08e624a85c2a2733fb39fa04c2685344..7849b65969d0741e624b350aa80e79eb18d50321 100644 (file)
@@ -163,7 +163,7 @@ zr36060_wait_end (struct zr36060 *ptr)
                udelay(1);
                if (i++ > 200000) {     // 200ms, there is for sure something wrong!!!
                        dprintk(1,
-                               "%s: timout at wait_end (last status: 0x%02x)\n",
+                               "%s: timeout at wait_end (last status: 0x%02x)\n",
                                ptr->name, ptr->status);
                        break;
                }
index 6be1f6b65777a07208da7ad26eb084c7c8308b7e..af9da03e95e571f7677f5092d6dd7e123eedd59a 100644 (file)
 #define PL_LOGINFO_SUB_CODE_FRAME_XFER_ERROR                 (0x00000400) /* Bits 0-3 encode Transport Status Register (offset 0x08) */
                                                                           /* Bit 0 is Status Bit 0: FrameXferErr */
                                                                           /* Bit 1 & 2 are Status Bits 16 and 17: FrameXmitErrStatus */
-                                                                          /* Bit 3 is Status Bit 18 WriteDataLenghtGTDataLengthErr */
+                                                                          /* Bit 3 is Status Bit 18 WriteDataLengthGTDataLengthErr */
 
 #define PL_LOGINFO_SUB_CODE_TX_FM_CONNECTED_LOW              (0x00000500)
 #define PL_LOGINFO_SUB_CODE_SATA_NON_NCQ_RW_ERR_BIT_SET      (0x00000600)
index 6029509702d35e02b92f76fc1546007c39ee5299..e630b50966ec5ba0192a36acb9e22a328e9b5675 100644 (file)
@@ -1708,7 +1708,7 @@ mptctl_replace_fw (unsigned long arg)
  *
  * Outputs:    None.
  * Return:     0 if successful
- *             -EBUSY  if previous command timout and IOC reset is not complete.
+ *             -EBUSY  if previous command timeout and IOC reset is not complete.
  *             -EFAULT if data unavailable
  *             -ENODEV if no such device/adapter
  *             -ETIME  if timer expires
@@ -1748,7 +1748,7 @@ mptctl_mpt_command (unsigned long arg)
  *
  * Outputs:    None.
  * Return:     0 if successful
- *             -EBUSY  if previous command timout and IOC reset is not complete.
+ *             -EBUSY  if previous command timeout and IOC reset is not complete.
  *             -EFAULT if data unavailable
  *             -ENODEV if no such device/adapter
  *             -ETIME  if timer expires
@@ -2316,7 +2316,7 @@ done_free_mem:
  * Outputs:    None.
  * Return:     0 if successful
  *             -EFAULT if data unavailable
- *             -EBUSY  if previous command timout and IOC reset is not complete.
+ *             -EBUSY  if previous command timeout and IOC reset is not complete.
  *             -ENODEV if no such device/adapter
  *             -ETIME  if timer expires
  *             -ENOMEM if memory allocation error
@@ -2553,7 +2553,7 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
  * Outputs:    None.
  * Return:     0 if successful
  *             -EFAULT if data unavailable
- *             -EBUSY  if previous command timout and IOC reset is not complete.
+ *             -EBUSY  if previous command timeout and IOC reset is not complete.
  *             -ENODEV if no such device/adapter
  *             -ETIME  if timer expires
  *             -ENOMEM if memory allocation error
index 5c614ec38cc494da6671db10a964302cca993127..af1de0ccee2f54c37c3567585e9e73db6f83bfe4 100644 (file)
@@ -1736,7 +1736,7 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, i
  fail_out:
 
        /*
-        * Free task managment mf, and corresponding tm flags
+        * Free task management mf, and corresponding tm flags
         */
        mpt_free_msg_frame(ioc, mf);
        hd->tmPending = 0;
index 7814a06ae970f515cc43e21051e0bb13a09c53a9..da715e11c1b28cc493de7047e1772074c804e981 100644 (file)
@@ -916,7 +916,7 @@ static int i2o_parse_hrt(struct i2o_controller *c)
  *     status block. The status block could then be accessed through
  *     c->status_block.
  *
- *     Returns 0 on sucess or negative error code on failure.
+ *     Returns 0 on success or negative error code on failure.
  */
 int i2o_status_get(struct i2o_controller *c)
 {
index 7dce318df1bdb1751b061bbddc258ec4648743dc..3bd883166e3d5b9ab41c8952ad15b361b027ad75 100644 (file)
@@ -33,7 +33,6 @@
  *  Sam Lin        - GPS support
  */
 
-#include <linux/autoconf.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -255,7 +254,7 @@ ASUS_LED(gled, "gaming");
  * method is searched within the scope of the handle, can be NULL. The output
  * of the method is written is output, which can also be NULL
  *
- * returns 1 if write is successful, 0 else.
+ * returns 0 if write is successful, -1 else.
  */
 static int write_acpi_int(acpi_handle handle, const char *method, int val,
                          struct acpi_buffer *output)
@@ -264,13 +263,19 @@ static int write_acpi_int(acpi_handle handle, const char *method, int val,
        union acpi_object in_obj;       //the only param we use
        acpi_status status;
 
+       if (!handle)
+               return 0;
+
        params.count = 1;
        params.pointer = &in_obj;
        in_obj.type = ACPI_TYPE_INTEGER;
        in_obj.integer.value = val;
 
        status = acpi_evaluate_object(handle, (char *)method, &params, output);
-       return (status == AE_OK);
+       if (status == AE_OK)
+               return 0;
+       else
+               return -1;
 }
 
 static int read_wireless_status(int mask)
@@ -322,7 +327,7 @@ static void write_status(acpi_handle handle, int out, int mask)
 
        switch (mask) {
        case MLED_ON:
-               out = !out & 0x1;
+               out = !(out & 0x1);
                break;
        case GLED_ON:
                out = (out & 0x1) + 1;
@@ -336,7 +341,7 @@ static void write_status(acpi_handle handle, int out, int mask)
                break;
        }
 
-       if (handle && !write_acpi_int(handle, NULL, out, NULL))
+       if (write_acpi_int(handle, NULL, out, NULL))
                printk(ASUS_WARNING " write failed %x\n", mask);
 }
 
@@ -416,7 +421,7 @@ static int set_brightness(struct backlight_device *bd, int value)
        value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
        /* 0 <= value <= 15 */
 
-       if (!write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
+       if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
                printk(ASUS_WARNING "Error changing brightness\n");
                ret = -EIO;
        }
@@ -546,7 +551,7 @@ static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
 
        rv = parse_arg(buf, count, &value);
        if (rv > 0) {
-               if (!write_acpi_int(ledd_set_handle, NULL, value, NULL))
+               if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
                        printk(ASUS_WARNING "LED display write failed\n");
                else
                        hotk->ledd_status = (u32) value;
@@ -591,7 +596,7 @@ static ssize_t store_bluetooth(struct device *dev,
 static void set_display(int value)
 {
        /* no sanity check needed for now */
-       if (!write_acpi_int(display_set_handle, NULL, value, NULL))
+       if (write_acpi_int(display_set_handle, NULL, value, NULL))
                printk(ASUS_WARNING "Error setting display\n");
        return;
 }
@@ -648,7 +653,7 @@ static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
  */
 static void set_light_sens_switch(int value)
 {
-       if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
+       if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
                printk(ASUS_WARNING "Error setting light sensor switch\n");
        hotk->light_switch = value;
 }
@@ -673,7 +678,7 @@ static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
 
 static void set_light_sens_level(int value)
 {
-       if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
+       if (write_acpi_int(ls_level_handle, NULL, value, NULL))
                printk(ASUS_WARNING "Error setting light sensor level\n");
        hotk->light_level = value;
 }
@@ -861,7 +866,7 @@ static int asus_hotk_get_info(void)
                printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
 
        /* We have to write 0 on init this far for all ASUS models */
-       if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
+       if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
                printk(ASUS_ERR "Hotkey initialization failed\n");
                return -ENODEV;
        }
index c8d62c268b11729dd2916105d26a8105fd01c905..1cfd7f3f129400fd9d8d22d429689d6d29234d4a 100644 (file)
@@ -50,7 +50,6 @@
 #include <linux/dmi.h>
 #include <linux/backlight.h>
 #include <linux/platform_device.h>
-#include <linux/autoconf.h>
 
 #define FUJITSU_DRIVER_VERSION "0.3"
 
index 552b7957a92a1ad1ea284aedf0e02ad36d102a1c..c884730c5eafc55701486be80c13450f1f6a09e8 100644 (file)
@@ -129,27 +129,28 @@ module_param(cpoint_count, int, 0644);
 MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\
                                "crash point is to be hit to trigger action");
 
-unsigned int jp_do_irq(unsigned int irq)
+static unsigned int jp_do_irq(unsigned int irq)
 {
        lkdtm_handler();
        jprobe_return();
        return 0;
 }
 
-irqreturn_t jp_handle_irq_event(unsigned int irq, struct irqaction *action)
+static irqreturn_t jp_handle_irq_event(unsigned int irq,
+                                      struct irqaction *action)
 {
        lkdtm_handler();
        jprobe_return();
        return 0;
 }
 
-void jp_tasklet_action(struct softirq_action *a)
+static void jp_tasklet_action(struct softirq_action *a)
 {
        lkdtm_handler();
        jprobe_return();
 }
 
-void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
+static void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
 {
        lkdtm_handler();
        jprobe_return();
@@ -157,23 +158,24 @@ void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
 
 struct scan_control;
 
-unsigned long jp_shrink_inactive_list(unsigned long max_scan,
-                               struct zone *zone, struct scan_control *sc)
+static unsigned long jp_shrink_inactive_list(unsigned long max_scan,
+                                            struct zone *zone,
+                                            struct scan_control *sc)
 {
        lkdtm_handler();
        jprobe_return();
        return 0;
 }
 
-int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim,
-                               const enum hrtimer_mode mode)
+static int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim,
+                           const enum hrtimer_mode mode)
 {
        lkdtm_handler();
        jprobe_return();
        return 0;
 }
 
-int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd)
+static int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd)
 {
        lkdtm_handler();
        jprobe_return();
@@ -270,7 +272,7 @@ void lkdtm_handler(void)
        }
 }
 
-int lkdtm_module_init(void)
+static int __init lkdtm_module_init(void)
 {
        int ret;
 
@@ -331,7 +333,7 @@ int lkdtm_module_init(void)
        return 0;
 }
 
-void lkdtm_module_exit(void)
+static void __exit lkdtm_module_exit(void)
 {
         unregister_jprobe(&lkdtm);
         printk(KERN_INFO "lkdtm : Crash point unregistered\n");
index 83679c7629253b2ed0b4b106ea0e17e3073ef0df..de898c6938f37acd6194d27c3706c36b193716a5 100644 (file)
@@ -58,7 +58,6 @@
 #include <linux/dmi.h>
 #include <linux/backlight.h>
 #include <linux/platform_device.h>
-#include <linux/autoconf.h>
 
 #define MSI_DRIVER_VERSION "0.5"
 
index cd221fd0fb94b89a4c54ac3cc52da09cf7a13dee..7fa61e907e1c115b16f14936ffea65f865816f4e 100644 (file)
@@ -25,7 +25,7 @@
 #include <asm/atomic.h>
 #include <asm/io.h>
 
-#define PHANTOM_VERSION                "n0.9.7"
+#define PHANTOM_VERSION                "n0.9.8"
 
 #define PHANTOM_MAX_MINORS     8
 
@@ -456,8 +456,9 @@ static int phantom_resume(struct pci_dev *pdev)
 #endif
 
 static struct pci_device_id phantom_pci_tbl[] __devinitdata = {
-       { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050),
-               .class = PCI_CLASS_BRIDGE_OTHER << 8, .class_mask = 0xffff00 },
+       { .vendor = PCI_VENDOR_ID_PLX, .device = PCI_DEVICE_ID_PLX_9050,
+         .subvendor = PCI_VENDOR_ID_PLX, .subdevice = PCI_DEVICE_ID_PLX_9050,
+         .class = PCI_CLASS_BRIDGE_OTHER << 8, .class_mask = 0xffff00 },
        { 0, }
 };
 MODULE_DEVICE_TABLE(pci, phantom_pci_tbl);
index b0f68031b49dfa926dd8ccc62ff91d058638a65a..899e3f75f288dd853a50f61e9c15772ea3d60b01 100644 (file)
@@ -73,7 +73,7 @@
        if (debug) printk(KERN_WARNING DRV_PFX  msg);   \
 } while (0)
 
-#define SONY_LAPTOP_DRIVER_VERSION     "0.5"
+#define SONY_LAPTOP_DRIVER_VERSION     "0.6"
 
 #define SONY_NC_CLASS          "sony-nc"
 #define SONY_NC_HID            "SNY5001"
@@ -146,68 +146,70 @@ struct sony_laptop_keypress {
  * and input layer indexes in the keymap
  */
 static int sony_laptop_input_index[] = {
-       -1,     /* no event */
-       -1,     /* SONYPI_EVENT_JOGDIAL_DOWN */
-       -1,     /* SONYPI_EVENT_JOGDIAL_UP */
-       -1,     /* SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
-       -1,     /* SONYPI_EVENT_JOGDIAL_UP_PRESSED */
-       -1,     /* SONYPI_EVENT_JOGDIAL_PRESSED */
-       -1,     /* SONYPI_EVENT_JOGDIAL_RELEASED */
-        0,     /* SONYPI_EVENT_CAPTURE_PRESSED */
-        1,     /* SONYPI_EVENT_CAPTURE_RELEASED */
-        2,     /* SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
-        3,     /* SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
-        4,     /* SONYPI_EVENT_FNKEY_ESC */
-        5,     /* SONYPI_EVENT_FNKEY_F1 */
-        6,     /* SONYPI_EVENT_FNKEY_F2 */
-        7,     /* SONYPI_EVENT_FNKEY_F3 */
-        8,     /* SONYPI_EVENT_FNKEY_F4 */
-        9,     /* SONYPI_EVENT_FNKEY_F5 */
-       10,     /* SONYPI_EVENT_FNKEY_F6 */
-       11,     /* SONYPI_EVENT_FNKEY_F7 */
-       12,     /* SONYPI_EVENT_FNKEY_F8 */
-       13,     /* SONYPI_EVENT_FNKEY_F9 */
-       14,     /* SONYPI_EVENT_FNKEY_F10 */
-       15,     /* SONYPI_EVENT_FNKEY_F11 */
-       16,     /* SONYPI_EVENT_FNKEY_F12 */
-       17,     /* SONYPI_EVENT_FNKEY_1 */
-       18,     /* SONYPI_EVENT_FNKEY_2 */
-       19,     /* SONYPI_EVENT_FNKEY_D */
-       20,     /* SONYPI_EVENT_FNKEY_E */
-       21,     /* SONYPI_EVENT_FNKEY_F */
-       22,     /* SONYPI_EVENT_FNKEY_S */
-       23,     /* SONYPI_EVENT_FNKEY_B */
-       24,     /* SONYPI_EVENT_BLUETOOTH_PRESSED */
-       25,     /* SONYPI_EVENT_PKEY_P1 */
-       26,     /* SONYPI_EVENT_PKEY_P2 */
-       27,     /* SONYPI_EVENT_PKEY_P3 */
-       28,     /* SONYPI_EVENT_BACK_PRESSED */
-       -1,     /* SONYPI_EVENT_LID_CLOSED */
-       -1,     /* SONYPI_EVENT_LID_OPENED */
-       29,     /* SONYPI_EVENT_BLUETOOTH_ON */
-       30,     /* SONYPI_EVENT_BLUETOOTH_OFF */
-       31,     /* SONYPI_EVENT_HELP_PRESSED */
-       32,     /* SONYPI_EVENT_FNKEY_ONLY */
-       33,     /* SONYPI_EVENT_JOGDIAL_FAST_DOWN */
-       34,     /* SONYPI_EVENT_JOGDIAL_FAST_UP */
-       35,     /* SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
-       36,     /* SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
-       37,     /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
-       38,     /* SONYPI_EVENT_JOGDIAL_VFAST_UP */
-       39,     /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
-       40,     /* SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
-       41,     /* SONYPI_EVENT_ZOOM_PRESSED */
-       42,     /* SONYPI_EVENT_THUMBPHRASE_PRESSED */
-       43,     /* SONYPI_EVENT_MEYE_FACE */
-       44,     /* SONYPI_EVENT_MEYE_OPPOSITE */
-       45,     /* SONYPI_EVENT_MEMORYSTICK_INSERT */
-       46,     /* SONYPI_EVENT_MEMORYSTICK_EJECT */
-       -1,     /* SONYPI_EVENT_ANYBUTTON_RELEASED */
-       -1,     /* SONYPI_EVENT_BATTERY_INSERT */
-       -1,     /* SONYPI_EVENT_BATTERY_REMOVE */
-       -1,     /* SONYPI_EVENT_FNKEY_RELEASED */
-       47,     /* SONYPI_EVENT_WIRELESS_ON */
-       48,     /* SONYPI_EVENT_WIRELESS_OFF */
+       -1,     /*  0 no event */
+       -1,     /*  1 SONYPI_EVENT_JOGDIAL_DOWN */
+       -1,     /*  2 SONYPI_EVENT_JOGDIAL_UP */
+       -1,     /*  3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
+       -1,     /*  4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
+       -1,     /*  5 SONYPI_EVENT_JOGDIAL_PRESSED */
+       -1,     /*  6 SONYPI_EVENT_JOGDIAL_RELEASED */
+        0,     /*  7 SONYPI_EVENT_CAPTURE_PRESSED */
+        1,     /*  8 SONYPI_EVENT_CAPTURE_RELEASED */
+        2,     /*  9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
+        3,     /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
+        4,     /* 11 SONYPI_EVENT_FNKEY_ESC */
+        5,     /* 12 SONYPI_EVENT_FNKEY_F1 */
+        6,     /* 13 SONYPI_EVENT_FNKEY_F2 */
+        7,     /* 14 SONYPI_EVENT_FNKEY_F3 */
+        8,     /* 15 SONYPI_EVENT_FNKEY_F4 */
+        9,     /* 16 SONYPI_EVENT_FNKEY_F5 */
+       10,     /* 17 SONYPI_EVENT_FNKEY_F6 */
+       11,     /* 18 SONYPI_EVENT_FNKEY_F7 */
+       12,     /* 19 SONYPI_EVENT_FNKEY_F8 */
+       13,     /* 20 SONYPI_EVENT_FNKEY_F9 */
+       14,     /* 21 SONYPI_EVENT_FNKEY_F10 */
+       15,     /* 22 SONYPI_EVENT_FNKEY_F11 */
+       16,     /* 23 SONYPI_EVENT_FNKEY_F12 */
+       17,     /* 24 SONYPI_EVENT_FNKEY_1 */
+       18,     /* 25 SONYPI_EVENT_FNKEY_2 */
+       19,     /* 26 SONYPI_EVENT_FNKEY_D */
+       20,     /* 27 SONYPI_EVENT_FNKEY_E */
+       21,     /* 28 SONYPI_EVENT_FNKEY_F */
+       22,     /* 29 SONYPI_EVENT_FNKEY_S */
+       23,     /* 30 SONYPI_EVENT_FNKEY_B */
+       24,     /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
+       25,     /* 32 SONYPI_EVENT_PKEY_P1 */
+       26,     /* 33 SONYPI_EVENT_PKEY_P2 */
+       27,     /* 34 SONYPI_EVENT_PKEY_P3 */
+       28,     /* 35 SONYPI_EVENT_BACK_PRESSED */
+       -1,     /* 36 SONYPI_EVENT_LID_CLOSED */
+       -1,     /* 37 SONYPI_EVENT_LID_OPENED */
+       29,     /* 38 SONYPI_EVENT_BLUETOOTH_ON */
+       30,     /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
+       31,     /* 40 SONYPI_EVENT_HELP_PRESSED */
+       32,     /* 41 SONYPI_EVENT_FNKEY_ONLY */
+       33,     /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
+       34,     /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
+       35,     /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
+       36,     /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
+       37,     /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
+       38,     /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
+       39,     /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
+       40,     /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
+       41,     /* 50 SONYPI_EVENT_ZOOM_PRESSED */
+       42,     /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
+       43,     /* 52 SONYPI_EVENT_MEYE_FACE */
+       44,     /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
+       45,     /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
+       46,     /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
+       -1,     /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
+       -1,     /* 57 SONYPI_EVENT_BATTERY_INSERT */
+       -1,     /* 58 SONYPI_EVENT_BATTERY_REMOVE */
+       -1,     /* 59 SONYPI_EVENT_FNKEY_RELEASED */
+       47,     /* 60 SONYPI_EVENT_WIRELESS_ON */
+       48,     /* 61 SONYPI_EVENT_WIRELESS_OFF */
+       49,     /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
+       50,     /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
 };
 
 static int sony_laptop_input_keycode_map[] = {
@@ -260,6 +262,8 @@ static int sony_laptop_input_keycode_map[] = {
        KEY_RESERVED,   /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
        KEY_WLAN,       /* 47 SONYPI_EVENT_WIRELESS_ON */
        KEY_WLAN,       /* 48 SONYPI_EVENT_WIRELESS_OFF */
+       KEY_ZOOMIN,     /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
+       KEY_ZOOMOUT     /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
 };
 
 /* release buttons after a short delay if pressed */
@@ -311,7 +315,7 @@ static void sony_laptop_report_input_event(u8 event)
                break;
 
        default:
-               if (event > ARRAY_SIZE (sony_laptop_input_keycode_map)) {
+               if (event > ARRAY_SIZE(sony_laptop_input_index)) {
                        dprintk("sony_laptop_report_input_event, event not known: %d\n", event);
                        break;
                }
@@ -875,6 +879,15 @@ static const struct dmi_system_id sony_nc_ids[] = {
                                DMI_MATCH(DMI_PRODUCT_NAME, "VGN-C"),
                        },
                },
+               {
+                       .ident = "Sony Vaio N Series",
+                       .callback = sony_nc_C_enable,
+                       .driver_data = sony_C_events,
+                       .matches = {
+                               DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
+                               DMI_MATCH(DMI_PRODUCT_NAME, "VGN-N"),
+                       },
+               },
                { }
 };
 
@@ -1169,10 +1182,12 @@ static struct acpi_driver sony_nc_driver = {
 #define SONYPI_DEVICE_TYPE1    0x00000001
 #define SONYPI_DEVICE_TYPE2    0x00000002
 #define SONYPI_DEVICE_TYPE3    0x00000004
+#define SONYPI_DEVICE_TYPE4    0x00000008
 
 #define SONYPI_TYPE1_OFFSET    0x04
 #define SONYPI_TYPE2_OFFSET    0x12
 #define SONYPI_TYPE3_OFFSET    0x12
+#define SONYPI_TYPE4_OFFSET    0x12
 
 struct sony_pic_ioport {
        struct acpi_resource_io io1;
@@ -1185,18 +1200,33 @@ struct sony_pic_irq {
        struct list_head                list;
 };
 
+struct sonypi_eventtypes {
+       u8                      data;
+       unsigned long           mask;
+       struct sonypi_event     *events;
+};
+
+struct device_ctrl {
+       int                             model;
+       int                             (*handle_irq)(const u8, const u8);
+       u16                             evport_offset;
+       u8                              has_camera;
+       u8                              has_bluetooth;
+       u8                              has_wwan;
+       struct sonypi_eventtypes        *event_types;
+};
+
 struct sony_pic_dev {
-       int                     model;
-       u16                     evport_offset;
-       u8                      camera_power;
-       u8                      bluetooth_power;
-       u8                      wwan_power;
+       struct device_ctrl      *control;
        struct acpi_device      *acpi_dev;
        struct sony_pic_irq     *cur_irq;
        struct sony_pic_ioport  *cur_ioport;
        struct list_head        interrupts;
        struct list_head        ioports;
        struct mutex            lock;
+       u8                      camera_power;
+       u8                      bluetooth_power;
+       u8                      wwan_power;
 };
 
 static struct sony_pic_dev spic_dev = {
@@ -1253,6 +1283,7 @@ static struct sonypi_event sonypi_joggerev[] = {
 static struct sonypi_event sonypi_captureev[] = {
        { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
        { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
+       { 0x40, SONYPI_EVENT_CAPTURE_PRESSED },
        { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
        { 0, 0 }
 };
@@ -1289,7 +1320,6 @@ static struct sonypi_event sonypi_pkeyev[] = {
        { 0x01, SONYPI_EVENT_PKEY_P1 },
        { 0x02, SONYPI_EVENT_PKEY_P2 },
        { 0x04, SONYPI_EVENT_PKEY_P3 },
-       { 0x5c, SONYPI_EVENT_PKEY_P1 },
        { 0, 0 }
 };
 
@@ -1331,6 +1361,8 @@ static struct sonypi_event sonypi_lidev[] = {
 /* The set of possible zoom events */
 static struct sonypi_event sonypi_zoomev[] = {
        { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
+       { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED },
+       { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED },
        { 0, 0 }
 };
 
@@ -1361,76 +1393,58 @@ static struct sonypi_event sonypi_batteryev[] = {
        { 0, 0 }
 };
 
-static struct sonypi_eventtypes {
-       int                     model;
-       u8                      data;
-       unsigned long           mask;
-       struct sonypi_event *   events;
-} sony_pic_eventtypes[] = {
-       { SONYPI_DEVICE_TYPE1, 0, 0xffffffff, sonypi_releaseev },
-       { SONYPI_DEVICE_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
-       { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev },
-       { SONYPI_DEVICE_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
-       { SONYPI_DEVICE_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
-       { SONYPI_DEVICE_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
-       { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
-       { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
-       { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
-       { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
-
-       { SONYPI_DEVICE_TYPE2, 0, 0xffffffff, sonypi_releaseev },
-       { SONYPI_DEVICE_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev },
-       { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
-       { SONYPI_DEVICE_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
-       { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
-       { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
-       { SONYPI_DEVICE_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
-       { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
-       { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev },
-       { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
-       { SONYPI_DEVICE_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
-       { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
-       { SONYPI_DEVICE_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
-       { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
-
-       { SONYPI_DEVICE_TYPE3, 0, 0xffffffff, sonypi_releaseev },
-       { SONYPI_DEVICE_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
-       { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
-       { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
-       { SONYPI_DEVICE_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
-       { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
-       { 0 }
+static struct sonypi_eventtypes type1_events[] = {
+       { 0, 0xffffffff, sonypi_releaseev },
+       { 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
+       { 0x30, SONYPI_LID_MASK, sonypi_lidev },
+       { 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
+       { 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
+       { 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
+       { 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
+       { 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
+       { 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
+       { 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
+       { 0 },
+};
+static struct sonypi_eventtypes type2_events[] = {
+       { 0, 0xffffffff, sonypi_releaseev },
+       { 0x38, SONYPI_LID_MASK, sonypi_lidev },
+       { 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
+       { 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
+       { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
+       { 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
+       { 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
+       { 0x11, SONYPI_BACK_MASK, sonypi_backev },
+       { 0x21, SONYPI_HELP_MASK, sonypi_helpev },
+       { 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
+       { 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
+       { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
+       { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
+       { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
+       { 0 },
+};
+static struct sonypi_eventtypes type3_events[] = {
+       { 0, 0xffffffff, sonypi_releaseev },
+       { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
+       { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
+       { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
+       { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
+       { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
+       { 0 },
+};
+static struct sonypi_eventtypes type4_events[] = {
+       { 0, 0xffffffff, sonypi_releaseev },
+       { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
+       { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
+       { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
+       { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
+       { 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev },
+       { 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev },
+       { 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev },
+       { 0 },
 };
 
-static int sony_pic_detect_device_type(void)
-{
-       struct pci_dev *pcidev;
-       int model = 0;
-
-       if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                                    PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
-               model = SONYPI_DEVICE_TYPE1;
-
-       else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                                         PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
-               model = SONYPI_DEVICE_TYPE3;
-
-       else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                                         PCI_DEVICE_ID_INTEL_ICH7_1, NULL)))
-               model = SONYPI_DEVICE_TYPE3;
-
-       else
-               model = SONYPI_DEVICE_TYPE2;
-
-       if (pcidev)
-               pci_dev_put(pcidev);
-
-       printk(KERN_INFO DRV_PFX "detected Type%d model\n",
-                       model == SONYPI_DEVICE_TYPE1 ? 1 :
-                       model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
-       return model;
-}
-
+/* low level spic calls */
 #define ITERATIONS_LONG                10000
 #define ITERATIONS_SHORT       10
 #define wait_on_command(command, iterations) {                         \
@@ -1451,7 +1465,7 @@ static u8 sony_pic_call1(u8 dev)
        outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
        v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4);
        v2 = inb_p(spic_dev.cur_ioport->io1.minimum);
-       dprintk("sony_pic_call1: 0x%.4x\n", (v2 << 8) | v1);
+       dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev, (v2 << 8) | v1);
        return v2;
 }
 
@@ -1466,7 +1480,7 @@ static u8 sony_pic_call2(u8 dev, u8 fn)
                        ITERATIONS_LONG);
        outb(fn, spic_dev.cur_ioport->io1.minimum);
        v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
-       dprintk("sony_pic_call2: 0x%.4x\n", v1);
+       dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev, fn, v1);
        return v1;
 }
 
@@ -1481,10 +1495,105 @@ static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
        wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
        outb(v, spic_dev.cur_ioport->io1.minimum);
        v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
-       dprintk("sony_pic_call3: 0x%.4x\n", v1);
+       dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
+                       dev, fn, v, v1);
        return v1;
 }
 
+/*
+ * minidrivers for SPIC models
+ */
+static int type4_handle_irq(const u8 data_mask, const u8 ev)
+{
+       /*
+        * 0x31 could mean we have to take some extra action and wait for
+        * the next irq for some Type4 models, it will generate a new
+        * irq and we can read new data from the device:
+        *  - 0x5c and 0x5f requires 0xA0
+        *  - 0x61 requires 0xB3
+        */
+       if (data_mask == 0x31) {
+               if (ev == 0x5c || ev == 0x5f)
+                       sony_pic_call1(0xA0);
+               else if (ev == 0x61)
+                       sony_pic_call1(0xB3);
+               return 0;
+       }
+       return 1;
+}
+
+static struct device_ctrl spic_types[] = {
+       {
+               .model = SONYPI_DEVICE_TYPE1,
+               .handle_irq = NULL,
+               .evport_offset = SONYPI_TYPE1_OFFSET,
+               .event_types = type1_events,
+       },
+       {
+               .model = SONYPI_DEVICE_TYPE2,
+               .handle_irq = NULL,
+               .evport_offset = SONYPI_TYPE2_OFFSET,
+               .event_types = type2_events,
+       },
+       {
+               .model = SONYPI_DEVICE_TYPE3,
+               .handle_irq = NULL,
+               .evport_offset = SONYPI_TYPE3_OFFSET,
+               .event_types = type3_events,
+       },
+       {
+               .model = SONYPI_DEVICE_TYPE4,
+               .handle_irq = type4_handle_irq,
+               .evport_offset = SONYPI_TYPE4_OFFSET,
+               .event_types = type4_events,
+       },
+};
+
+static void sony_pic_detect_device_type(struct sony_pic_dev *dev)
+{
+       struct pci_dev *pcidev;
+
+       pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+                       PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
+       if (pcidev) {
+               dev->control = &spic_types[0];
+               goto out;
+       }
+
+       pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+                       PCI_DEVICE_ID_INTEL_ICH6_1, NULL);
+       if (pcidev) {
+               dev->control = &spic_types[2];
+               goto out;
+       }
+
+       pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+                       PCI_DEVICE_ID_INTEL_ICH7_1, NULL);
+       if (pcidev) {
+               dev->control = &spic_types[3];
+               goto out;
+       }
+
+       pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+                       PCI_DEVICE_ID_INTEL_ICH8_4, NULL);
+       if (pcidev) {
+               dev->control = &spic_types[3];
+               goto out;
+       }
+
+       /* default */
+       dev->control = &spic_types[1];
+
+out:
+       if (pcidev)
+               pci_dev_put(pcidev);
+
+       printk(KERN_INFO DRV_PFX "detected Type%d model\n",
+                       dev->control->model == SONYPI_DEVICE_TYPE1 ? 1 :
+                       dev->control->model == SONYPI_DEVICE_TYPE2 ? 2 :
+                       dev->control->model == SONYPI_DEVICE_TYPE3 ? 3 : 4);
+}
+
 /* camera tests and poweron/poweroff */
 #define SONYPI_CAMERA_PICTURE          5
 #define SONYPI_CAMERA_CONTROL          0x10
@@ -2253,7 +2362,7 @@ static int sony_pic_enable(struct acpi_device *device,
        buffer.pointer = resource;
 
        /* setup Type 1 resources */
-       if (spic_dev.model == SONYPI_DEVICE_TYPE1) {
+       if (spic_dev.control->model == SONYPI_DEVICE_TYPE1) {
 
                /* setup io resources */
                resource->res1.type = ACPI_RESOURCE_TYPE_IO;
@@ -2335,39 +2444,49 @@ static irqreturn_t sony_pic_irq(int irq, void *dev_id)
        if (dev->cur_ioport->io2.minimum)
                data_mask = inb_p(dev->cur_ioport->io2.minimum);
        else
-               data_mask = inb_p(dev->cur_ioport->io1.minimum + dev->evport_offset);
+               data_mask = inb_p(dev->cur_ioport->io1.minimum +
+                               dev->control->evport_offset);
 
        dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
-                       ev, data_mask, dev->cur_ioport->io1.minimum, dev->evport_offset);
+                       ev, data_mask, dev->cur_ioport->io1.minimum,
+                       dev->control->evport_offset);
 
        if (ev == 0x00 || ev == 0xff)
                return IRQ_HANDLED;
 
-       for (i = 0; sony_pic_eventtypes[i].model; i++) {
-
-               if (spic_dev.model != sony_pic_eventtypes[i].model)
-                       continue;
+       for (i = 0; dev->control->event_types[i].mask; i++) {
 
-               if ((data_mask & sony_pic_eventtypes[i].data) !=
-                   sony_pic_eventtypes[i].data)
+               if ((data_mask & dev->control->event_types[i].data) !=
+                   dev->control->event_types[i].data)
                        continue;
 
-               if (!(mask & sony_pic_eventtypes[i].mask))
+               if (!(mask & dev->control->event_types[i].mask))
                        continue;
 
-               for (j = 0; sony_pic_eventtypes[i].events[j].event; j++) {
-                       if (ev == sony_pic_eventtypes[i].events[j].data) {
+               for (j = 0; dev->control->event_types[i].events[j].event; j++) {
+                       if (ev == dev->control->event_types[i].events[j].data) {
                                device_event =
-                                       sony_pic_eventtypes[i].events[j].event;
+                                       dev->control->
+                                               event_types[i].events[j].event;
                                goto found;
                        }
                }
        }
+       /* Still not able to decode the event try to pass
+        * it over to the minidriver
+        */
+       if (dev->control->handle_irq &&
+                       dev->control->handle_irq(data_mask, ev) == 0)
+               return IRQ_HANDLED;
+
+       dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
+                       ev, data_mask, dev->cur_ioport->io1.minimum,
+                       dev->control->evport_offset);
        return IRQ_HANDLED;
 
 found:
        sony_laptop_report_input_event(device_event);
-       acpi_bus_generate_proc_event(spic_dev.acpi_dev, 1, device_event);
+       acpi_bus_generate_proc_event(dev->acpi_dev, 1, device_event);
        sonypi_compat_report_event(device_event);
 
        return IRQ_HANDLED;
@@ -2429,23 +2548,9 @@ static int sony_pic_add(struct acpi_device *device)
 
        spic_dev.acpi_dev = device;
        strcpy(acpi_device_class(device), "sony/hotkey");
-       spic_dev.model = sony_pic_detect_device_type();
+       sony_pic_detect_device_type(&spic_dev);
        mutex_init(&spic_dev.lock);
 
-       /* model specific characteristics */
-       switch(spic_dev.model) {
-               case SONYPI_DEVICE_TYPE1:
-                       spic_dev.evport_offset = SONYPI_TYPE1_OFFSET;
-                       break;
-               case SONYPI_DEVICE_TYPE3:
-                       spic_dev.evport_offset = SONYPI_TYPE3_OFFSET;
-                       break;
-               case SONYPI_DEVICE_TYPE2:
-               default:
-                       spic_dev.evport_offset = SONYPI_TYPE2_OFFSET;
-                       break;
-       }
-
        /* read _PRS resources */
        result = sony_pic_possible_resources(device);
        if (result) {
index be4b9948c762e33b577cbd192dd836ff50c75e46..eeaaa9dce6ef62607ee510e580d647554bca8611 100644 (file)
@@ -4,7 +4,7 @@
  * block2mtd.c - create an mtd from a block device
  *
  * Copyright (C) 2001,2002     Simon Evans <spse@secret.org.uk>
- * Copyright (C) 2004-2006     Jörn Engel <joern@wh.fh-wedel.de>
+ * Copyright (C) 2004-2006     Joern Engel <joern@wh.fh-wedel.de>
  *
  * Licence: GPL
  */
@@ -485,5 +485,5 @@ module_init(block2mtd_init);
 module_exit(block2mtd_exit);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Simon Evans <spse@secret.org.uk> and others");
+MODULE_AUTHOR("Joern Engel <joern@lazybastard.org>");
 MODULE_DESCRIPTION("Emulate an MTD using a block device");
index c73e96bfafc636047bbe9bebef7067b4a79d4bb3..90acf57c19bd29962197cf9ed83fa332e3888a4c 100644 (file)
@@ -376,7 +376,7 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
         * hardware restriction. */
        if (doc->mfr) {
                if (doc->mfr == mfr && doc->id == id)
-                       return 1;       /* This is another the same the first */
+                       return 1;       /* This is the same as the first */
                else
                        printk(KERN_WARNING
                               "Flash chip at floor %d, chip %d is different:\n",
index 56cc1ca7ffd5e7d8c552c47d3d0089fe4014c2e6..180298b92a7af9a80c229a9969a30852b233fb90 100644 (file)
@@ -2,7 +2,7 @@
  * $Id: phram.c,v 1.16 2005/11/07 11:14:25 gleixner Exp $
  *
  * Copyright (c) ????          Jochen Schäuble <psionic@psionic.de>
- * Copyright (c) 2003-2004     Jörn Engel <joern@wh.fh-wedel.de>
+ * Copyright (c) 2003-2004     Joern Engel <joern@wh.fh-wedel.de>
  *
  * Usage:
  *
@@ -299,5 +299,5 @@ module_init(init_phram);
 module_exit(cleanup_phram);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Jörn Engel <joern@wh.fh-wedel.de>");
+MODULE_AUTHOR("Joern Engel <joern@wh.fh-wedel.de>");
 MODULE_DESCRIPTION("MTD driver for physical RAM");
index d884f2be28f6574fb45f19a7cd423bee4a81a1de..2a8fde9b92f02110b0729a62754eaa2dbf7204e6 100644 (file)
@@ -4,7 +4,7 @@
  * $Id: mtx-1_flash.c,v 1.2 2005/11/07 11:14:27 gleixner Exp $
  *
  * (C) 2005 Bruno Randolf <bruno.randolf@4g-systems.biz>
- * (C) 2005 Jörn Engel <joern@wohnheim.fh-wedel.de>
+ * (C) 2005 Joern Engel <joern@wohnheim.fh-wedel.de>
  *
  */
 
index e3744eb8eccba4a68f3780379911a1eff7df2ef5..dd38011ee0b7326096973b694a3339467bc984f5 100644 (file)
@@ -20,7 +20,7 @@
  *
  *     02-12-2002 TG   Cleanup of module params
  *
- *     02-20-2002 TG   adjusted for different rd/wr adress support
+ *     02-20-2002 TG   adjusted for different rd/wr address support
  *                     added support for read device ready/busy line
  *                     added page_cache
  *
@@ -144,7 +144,7 @@ static int __init autcpu12_init(void)
                goto out;
        }
 
-       /* map physical adress */
+       /* map physical address */
        autcpu12_fio_base = ioremap(AUTCPU12_PHYS_SMC, SZ_1K);
        if (!autcpu12_fio_base) {
                printk("Ioremap autcpu12 SmartMedia Card failed\n");
@@ -227,7 +227,7 @@ static void __exit autcpu12_cleanup(void)
        /* Release resources, unregister device */
        nand_release(autcpu12_mtd);
 
-       /* unmap physical adress */
+       /* unmap physical address */
        iounmap(autcpu12_fio_base);
 
        /* Free the MTD device structure */
index 1657ecd74881ee4eebd9ce1752ef692a11c05c8b..a52f3a737c39a606e0832b3db47f19effa274a83 100644 (file)
@@ -4,7 +4,7 @@
  *     http://blackfin.uclinux.org/
  *     Bryan Wu <bryan.wu@analog.com>
  *
- * Blackfin BF5xx on-chip NAND flash controler driver
+ * Blackfin BF5xx on-chip NAND flash controller driver
  *
  * Derived from drivers/mtd/nand/s3c2410.c
  * Copyright (c) 2007 Ben Dooks <ben@simtec.co.uk>
index 89deff007116388b718c5828f476ce4bb507c841..19e1594421a476cae392e4b5f2b6b48c6fb18bb3 100644 (file)
@@ -337,7 +337,7 @@ static void __exit cs553x_cleanup(void)
                nand_release(cs553x_mtd[i]);
                cs553x_mtd[i] = NULL;
 
-               /* unmap physical adress */
+               /* unmap physical address */
                iounmap(mmio_base);
 
                /* Free the MTD device structure */
index 0146cdc48039617259a72c5a8c094d6a53c18cc5..ba67bbec20d3a4fbab3ac9733d05ee7cc3f61229 100644 (file)
@@ -125,7 +125,7 @@ static int __init ep7312_init(void)
                return -ENOMEM;
        }
 
-       /* map physical adress */
+       /* map physical address */
        ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
        if (!ep7312_fio_base) {
                printk("ioremap EDB7312 NAND flash failed\n");
index e29c1da7f56e82530a987beb96ab84a735a2b637..ddd4fc019042ff72250c887944a3410ec6b69459 100644 (file)
@@ -89,7 +89,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
                             struct mtd_oob_ops *ops);
 
 /*
- * For devices which display every fart in the system on a seperate LED. Is
+ * For devices which display every fart in the system on a separate LED. Is
  * compiled away when LED support is disabled.
  */
 DEFINE_LED_TRIGGER(nand_led_trigger);
index 10490b48d9f75844c81a00dc8f32825475345afc..bb885d1fcab5e9bbb87a085f0af76a76ea5e88bb 100644 (file)
@@ -210,7 +210,7 @@ MODULE_PARM_DESC(overridesize,   "Specifies the NAND Flash size overriding the I
 #define STATE_CMD_RESET        0x0000000C /* reset */
 #define STATE_CMD_MASK         0x0000000F /* command states mask */
 
-/* After an addres is input, the simulator goes to one of these states */
+/* After an address is input, the simulator goes to one of these states */
 #define STATE_ADDR_PAGE        0x00000010 /* full (row, column) address is accepted */
 #define STATE_ADDR_SEC         0x00000020 /* sector address was accepted */
 #define STATE_ADDR_ZERO        0x00000030 /* one byte zero address was accepted */
index 66f76e9618ddd9005edcb60faf2b66ea2ec539b2..2bd0737572c6fe9146a5b26d6f4147a2e76daea8 100644 (file)
@@ -8,7 +8,7 @@
  *
  * Changelog:
  *     21-Sep-2004  BJD  Initial version
- *     23-Sep-2004  BJD  Mulitple device support
+ *     23-Sep-2004  BJD  Multiple device support
  *     28-Sep-2004  BJD  Fixed ECC placement for Hardware mode
  *     12-Oct-2004  BJD  Fixed errors in use of platform data
  *     18-Feb-2005  BJD  Fix sparse errors
index 51c7288ab49a0fe4e0d251ba35c680e651378c58..033f8800b1e69224d81c15dd670bc24e95190a7f 100644 (file)
@@ -165,7 +165,7 @@ static int __init sharpsl_nand_init(void)
                return -ENOMEM;
        }
 
-       /* map physical adress */
+       /* map physical address */
        sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000);
        if (!sharpsl_io_base) {
                printk("ioremap to access Sharp SL NAND chip failed\n");
index 067262ee8df0fa2683c7a7bfd8582919fc0f5909..0513cbc8834d66b78d7e0c85d1f6532447048044 100644 (file)
@@ -429,7 +429,7 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
        }
 }
 
-/* calc_chain_lenght: Walk through a Virtual Unit Chain and estimate chain length */
+/* calc_chain_length: Walk through a Virtual Unit Chain and estimate chain length */
 static int calc_chain_length(struct NFTLrecord *nftl, unsigned int first_block)
 {
        unsigned int length = 0, block = first_block;
index 389980f0e59e7385d608e3cc2b7aed58ac2be115..7d170cd381c39191d7d9bfae65b296026de49934 100644 (file)
@@ -814,8 +814,8 @@ config ULTRA32
          will be called smc-ultra32.
 
 config BFIN_MAC
-       tristate "Blackfin 536/537 on-chip mac support"
-       depends on NET_ETHERNET && (BF537 || BF536) && (!BF537_PORT_H)
+       tristate "Blackfin 527/536/537 on-chip mac support"
+       depends on NET_ETHERNET && (BF527 || BF537 || BF536) && (!BF537_PORT_H)
        select CRC32
        select MII
        select PHYLIB
@@ -828,7 +828,7 @@ config BFIN_MAC
 
 config BFIN_MAC_USE_L1
        bool "Use L1 memory for rx/tx packets"
-       depends on BFIN_MAC && BF537
+       depends on BFIN_MAC && (BF527 || BF537)
        default y
        help
          To get maximum network performance, you should use L1 memory as rx/tx buffers.
@@ -855,7 +855,8 @@ config BFIN_RX_DESC_NUM
 config BFIN_MAC_RMII
        bool "RMII PHY Interface (EXPERIMENTAL)"
        depends on BFIN_MAC && EXPERIMENTAL
-       default n
+       default y if BFIN527_EZKIT
+       default n if BFIN537_STAMP
        help
          Use Reduced PHY MII Interface
 
@@ -919,8 +920,7 @@ config ENC28J60
        ---help---
          Support for the Microchip EN28J60 ethernet chip.
 
-         To compile this driver as a module, choose M here and read
-         <file:Documentation/networking/net-modules.txt>.  The module will be
+         To compile this driver as a module, choose M here. The module will be
          called enc28j60.
 
 config ENC28J60_WRITEVERIFY
@@ -1199,7 +1199,7 @@ config NE2_MCA
 
 config IBMLANA
        tristate "IBM LAN Adapter/A support"
-       depends on MCA && MCA_LEGACY
+       depends on MCA
        ---help---
          This is a Micro Channel Ethernet adapter.  You need to set
          CONFIG_MCA to use this driver.  It is both available as an in-kernel
@@ -2040,8 +2040,7 @@ config IGB
          More specific information on configuring the driver is in
          <file:Documentation/networking/e1000.txt>.
 
-         To compile this driver as a module, choose M here and read
-         <file:Documentation/networking/net-modules.txt>.  The module
+         To compile this driver as a module, choose M here. The module
          will be called igb.
 
 source "drivers/net/ixp2000/Kconfig"
@@ -3113,6 +3112,7 @@ config VIRTIO_NET
        tristate "Virtio network driver (EXPERIMENTAL)"
        depends on EXPERIMENTAL && VIRTIO
        ---help---
-         This is the virtual network driver for lguest.  Say Y or M.
+         This is the virtual network driver for virtio.  It can be used with
+          lguest or QEMU based VMMs (like KVM or Xen).  Say Y or M.
 
 endif # NETDEVICES
index 25b114a4e2b16f57373481da83b6066090518543..0ae0d83e5d2254b1db9b531103a3f88d4b50b7e3 100644 (file)
@@ -384,7 +384,7 @@ static void reset_phy(struct net_device *dev)
        /* Wait until PHY reset is complete */
        do {
                read_phy(lp->phy_address, MII_BMCR, &bmcr);
-       } while (!(bmcr && BMCR_RESET));
+       } while (!(bmcr & BMCR_RESET));
 
        disable_mdi();
        spin_unlock_irq(&lp->lock);
index 7495a9ee8f4bff6dde5b7c7666398d35882059fd..194949afacd05142655f7d1a42e00b8b894f6697 100644 (file)
@@ -137,11 +137,12 @@ static int ax_initial_check(struct net_device *dev)
 static void ax_reset_8390(struct net_device *dev)
 {
        struct ei_device *ei_local = netdev_priv(dev);
+       struct ax_device  *ax = to_ax_dev(dev);
        unsigned long reset_start_time = jiffies;
        void __iomem *addr = (void __iomem *)dev->base_addr;
 
        if (ei_debug > 1)
-               printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
+               dev_dbg(&ax->dev->dev, "resetting the 8390 t=%ld\n", jiffies);
 
        ei_outb(ei_inb(addr + NE_RESET), addr + NE_RESET);
 
@@ -151,7 +152,7 @@ static void ax_reset_8390(struct net_device *dev)
        /* This check _should_not_ be necessary, omit eventually. */
        while ((ei_inb(addr + EN0_ISR) & ENISR_RESET) == 0) {
                if (jiffies - reset_start_time > 2*HZ/100) {
-                       printk(KERN_WARNING "%s: %s did not complete.\n",
+                       dev_warn(&ax->dev->dev, "%s: %s did not complete.\n",
                               __FUNCTION__, dev->name);
                        break;
                }
@@ -165,13 +166,15 @@ static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
                            int ring_page)
 {
        struct ei_device *ei_local = netdev_priv(dev);
+       struct ax_device  *ax = to_ax_dev(dev);
        void __iomem *nic_base = ei_local->mem;
 
        /* This *shouldn't* happen. If it does, it's the last thing you'll see */
        if (ei_status.dmaing) {
-               printk(KERN_EMERG "%s: DMAing conflict in %s [DMAstat:%d][irqlock:%d].\n",
+               dev_err(&ax->dev->dev, "%s: DMAing conflict in %s "
+                       "[DMAstat:%d][irqlock:%d].\n",
                        dev->name, __FUNCTION__,
-                      ei_status.dmaing, ei_status.irqlock);
+                       ei_status.dmaing, ei_status.irqlock);
                return;
        }
 
@@ -204,13 +207,16 @@ static void ax_block_input(struct net_device *dev, int count,
                           struct sk_buff *skb, int ring_offset)
 {
        struct ei_device *ei_local = netdev_priv(dev);
+       struct ax_device  *ax = to_ax_dev(dev);
        void __iomem *nic_base = ei_local->mem;
        char *buf = skb->data;
 
        if (ei_status.dmaing) {
-               printk(KERN_EMERG "%s: DMAing conflict in ax_block_input "
+               dev_err(&ax->dev->dev,
+                       "%s: DMAing conflict in %s "
                        "[DMAstat:%d][irqlock:%d].\n",
-                       dev->name, ei_status.dmaing, ei_status.irqlock);
+                       dev->name, __FUNCTION__,
+                       ei_status.dmaing, ei_status.irqlock);
                return;
        }
 
@@ -239,6 +245,7 @@ static void ax_block_output(struct net_device *dev, int count,
                            const unsigned char *buf, const int start_page)
 {
        struct ei_device *ei_local = netdev_priv(dev);
+       struct ax_device  *ax = to_ax_dev(dev);
        void __iomem *nic_base = ei_local->mem;
        unsigned long dma_start;
 
@@ -251,7 +258,7 @@ static void ax_block_output(struct net_device *dev, int count,
 
        /* This *shouldn't* happen. If it does, it's the last thing you'll see */
        if (ei_status.dmaing) {
-               printk(KERN_EMERG "%s: DMAing conflict in %s."
+               dev_err(&ax->dev->dev, "%s: DMAing conflict in %s."
                        "[DMAstat:%d][irqlock:%d]\n",
                        dev->name, __FUNCTION__,
                       ei_status.dmaing, ei_status.irqlock);
@@ -281,7 +288,8 @@ static void ax_block_output(struct net_device *dev, int count,
 
        while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) {
                if (jiffies - dma_start > 2*HZ/100) {           /* 20ms */
-                       printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
+                       dev_warn(&ax->dev->dev,
+                                "%s: timeout waiting for Tx RDC.\n", dev->name);
                        ax_reset_8390(dev);
                        ax_NS8390_init(dev,1);
                        break;
@@ -424,10 +432,11 @@ static void
 ax_phy_write(struct net_device *dev, int phy_addr, int reg, int value)
 {
        struct ei_device *ei = (struct ei_device *) netdev_priv(dev);
+       struct ax_device  *ax = to_ax_dev(dev);
        unsigned long flags;
 
-       printk(KERN_DEBUG "%s: %p, %04x, %04x %04x\n",
-              __FUNCTION__, dev, phy_addr, reg, value);
+       dev_dbg(&ax->dev->dev, "%s: %p, %04x, %04x %04x\n",
+               __FUNCTION__, dev, phy_addr, reg, value);
 
        spin_lock_irqsave(&ei->page_lock, flags);
 
@@ -750,14 +759,11 @@ static int ax_init_dev(struct net_device *dev, int first_init)
        ax_NS8390_init(dev, 0);
 
        if (first_init) {
-               printk("AX88796: %dbit, irq %d, %lx, MAC: ",
-                      ei_status.word16 ? 16:8, dev->irq, dev->base_addr);
-
-               for (i = 0; i < ETHER_ADDR_LEN; i++)
-                       printk("%2.2x%c", dev->dev_addr[i],
-                              (i < (ETHER_ADDR_LEN-1) ? ':' : ' '));
+               DECLARE_MAC_BUF(mac);
 
-               printk("\n");
+               dev_info(&ax->dev->dev, "%dbit, irq %d, %lx, MAC: %s\n",
+                        ei_status.word16 ? 16:8, dev->irq, dev->base_addr,
+                        print_mac(mac, dev->dev_addr));
        }
 
        ret = register_netdev(dev);
index eb971755a3ff34c5b8f76d5b8b63bf5f3a83aad0..c993a32b3f50c1b0389a90ee193aa7bb24e94ba4 100644 (file)
@@ -1,34 +1,11 @@
 /*
- * File:       drivers/net/bfin_mac.c
- * Based on:
- * Maintainer:
- *             Bryan Wu <bryan.wu@analog.com>
+ * Blackfin On-Chip MAC Driver
  *
- * Original author:
- *             Luke Yang <luke.yang@analog.com>
+ * Copyright 2004-2007 Analog Devices Inc.
  *
- * Created:
- * Description:
+ * Enter bugs at http://blackfin.uclinux.org/
  *
- * Modified:
- *             Copyright 2004-2006 Analog Devices Inc.
- *
- * Bugs:       Enter bugs at http://blackfin.uclinux.org/
- *
- * This program is free software ;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ;  either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ;  see the file COPYING.
- * If not, write to the Free Software Foundation,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under the GPL-2 or later.
  */
 
 #include <linux/init.h>
@@ -65,7 +42,7 @@
 #define DRV_NAME       "bfin_mac"
 #define DRV_VERSION    "1.1"
 #define DRV_AUTHOR     "Bryan Wu, Luke Yang"
-#define DRV_DESC       "Blackfin BF53[67] on-chip Ethernet MAC driver"
+#define DRV_DESC       "Blackfin BF53[67] BF527 on-chip Ethernet MAC driver"
 
 MODULE_AUTHOR(DRV_AUTHOR);
 MODULE_LICENSE("GPL");
@@ -296,7 +273,7 @@ static void mdio_poll(void)
 
        /* poll the STABUSY bit */
        while ((bfin_read_EMAC_STAADD()) & STABUSY) {
-               mdelay(10);
+               udelay(1);
                if (timeout_cnt-- < 0) {
                        printk(KERN_ERR DRV_NAME
                        ": wait MDC/MDIO transaction to complete timeout\n");
@@ -412,20 +389,26 @@ static void bf537_adjust_link(struct net_device *dev)
        spin_unlock_irqrestore(&lp->lock, flags);
 }
 
+/* MDC  = 2.5 MHz */
+#define MDC_CLK 2500000
+
 static int mii_probe(struct net_device *dev)
 {
        struct bf537mac_local *lp = netdev_priv(dev);
        struct phy_device *phydev = NULL;
        unsigned short sysctl;
        int i;
+       u32 sclk, mdc_div;
 
        /* Enable PHY output early */
        if (!(bfin_read_VR_CTL() & PHYCLKOE))
                bfin_write_VR_CTL(bfin_read_VR_CTL() | PHYCLKOE);
 
-       /* MDC  = 2.5 MHz */
+       sclk = get_sclk();
+       mdc_div = ((sclk / MDC_CLK) / 2) - 1;
+
        sysctl = bfin_read_EMAC_SYSCTL();
-       sysctl |= SET_MDCDIV(24);
+       sysctl = (sysctl & ~MDCDIV) | SET_MDCDIV(mdc_div);
        bfin_write_EMAC_SYSCTL(sysctl);
 
        /* search for connect PHY device */
@@ -477,8 +460,10 @@ static int mii_probe(struct net_device *dev)
        lp->phydev = phydev;
 
        printk(KERN_INFO "%s: attached PHY driver [%s] "
-              "(mii_bus:phy_addr=%s, irq=%d)\n",
-              DRV_NAME, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
+              "(mii_bus:phy_addr=%s, irq=%d, mdc_clk=%dHz(mdc_div=%d)"
+              "@sclk=%dMHz)\n",
+              DRV_NAME, phydev->drv->name, phydev->dev.bus_id, phydev->irq,
+              MDC_CLK, mdc_div, sclk/1000000);
 
        return 0;
 }
@@ -551,7 +536,7 @@ static void adjust_tx_list(void)
         */
        if (current_tx_ptr->next->next == tx_list_head) {
                while (tx_list_head->status.status_word == 0) {
-                       mdelay(10);
+                       mdelay(1);
                        if (tx_list_head->status.status_word != 0
                            || !(bfin_read_DMA2_IRQ_STATUS() & 0x08)) {
                                goto adjust_head;
@@ -666,6 +651,12 @@ static void bf537mac_rx(struct net_device *dev)
        current_rx_ptr->skb = new_skb;
        current_rx_ptr->desc_a.start_addr = (unsigned long)new_skb->data - 2;
 
+       /* Invidate the data cache of skb->data range when it is write back
+        * cache. It will prevent overwritting the new data from DMA
+        */
+       blackfin_dcache_invalidate_range((unsigned long)new_skb->head,
+                                        (unsigned long)new_skb->end);
+
        len = (unsigned short)((current_rx_ptr->status.status_word) & RX_FRLEN);
        skb_put(skb, len);
        blackfin_dcache_invalidate_range((unsigned long)skb->head,
@@ -767,7 +758,7 @@ static void bf537mac_enable(void)
 
 #if defined(CONFIG_BFIN_MAC_RMII)
        opmode |= RMII; /* For Now only 100MBit are supported */
-#ifdef CONFIG_BF_REV_0_2
+#if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) && CONFIG_BF_REV_0_2
        opmode |= TE;
 #endif
 #endif
@@ -792,6 +783,39 @@ static void bf537mac_timeout(struct net_device *dev)
        netif_wake_queue(dev);
 }
 
+static void bf537mac_multicast_hash(struct net_device *dev)
+{
+       u32 emac_hashhi, emac_hashlo;
+       struct dev_mc_list *dmi = dev->mc_list;
+       char *addrs;
+       int i;
+       u32 crc;
+
+       emac_hashhi = emac_hashlo = 0;
+
+       for (i = 0; i < dev->mc_count; i++) {
+               addrs = dmi->dmi_addr;
+               dmi = dmi->next;
+
+               /* skip non-multicast addresses */
+               if (!(*addrs & 1))
+                       continue;
+
+               crc = ether_crc(ETH_ALEN, addrs);
+               crc >>= 26;
+
+               if (crc & 0x20)
+                       emac_hashhi |= 1 << (crc & 0x1f);
+               else
+                       emac_hashlo |= 1 << (crc & 0x1f);
+       }
+
+       bfin_write_EMAC_HASHHI(emac_hashhi);
+       bfin_write_EMAC_HASHLO(emac_hashlo);
+
+       return;
+}
+
 /*
  * This routine will, depending on the values passed to it,
  * either make it accept multicast packets, go into
@@ -807,11 +831,17 @@ static void bf537mac_set_multicast_list(struct net_device *dev)
                sysctl = bfin_read_EMAC_OPMODE();
                sysctl |= RAF;
                bfin_write_EMAC_OPMODE(sysctl);
-       } else if (dev->flags & IFF_ALLMULTI || dev->mc_count) {
+       } else if (dev->flags & IFF_ALLMULTI) {
                /* accept all multicast */
                sysctl = bfin_read_EMAC_OPMODE();
                sysctl |= PAM;
                bfin_write_EMAC_OPMODE(sysctl);
+       } else if (dev->mc_count) {
+               /* set up multicast hash table */
+               sysctl = bfin_read_EMAC_OPMODE();
+               sysctl |= HM;
+               bfin_write_EMAC_OPMODE(sysctl);
+               bf537mac_multicast_hash(dev);
        } else {
                /* clear promisc or multicast mode */
                sysctl = bfin_read_EMAC_OPMODE();
@@ -860,10 +890,10 @@ static int bf537mac_open(struct net_device *dev)
                return retval;
 
        phy_start(lp->phydev);
+       phy_write(lp->phydev, MII_BMCR, BMCR_RESET);
        setup_system_regs(dev);
        bf537mac_disable();
        bf537mac_enable();
-
        pr_debug("hardware init finished\n");
        netif_start_queue(dev);
        netif_carrier_on(dev);
@@ -886,6 +916,7 @@ static int bf537mac_close(struct net_device *dev)
        netif_carrier_off(dev);
 
        phy_stop(lp->phydev);
+       phy_write(lp->phydev, MII_BMCR, BMCR_PDOWN);
 
        /* clear everything */
        bf537mac_shutdown(dev);
@@ -970,7 +1001,7 @@ static int __init bf537mac_probe(struct net_device *dev)
        /* register irq handler */
        if (request_irq
            (IRQ_MAC_RX, bf537mac_interrupt, IRQF_DISABLED | IRQF_SHARED,
-            "BFIN537_MAC_RX", dev)) {
+            "EMAC_RX", dev)) {
                printk(KERN_WARNING DRV_NAME
                       ": Unable to attach BlackFin MAC RX interrupt\n");
                return -EBUSY;
index 5970ea7142cd53c3e5f1d4234110a484f8af0191..f774d5a36942aa4dcaf6f1e6078b9aa84d521ebf 100644 (file)
@@ -1,34 +1,11 @@
 /*
- * File:       drivers/net/bfin_mac.c
- * Based on:
- * Maintainer:
- *             Bryan Wu <bryan.wu@analog.com>
+ * Blackfin On-Chip MAC Driver
  *
- * Original author:
- *             Luke Yang <luke.yang@analog.com>
+ * Copyright 2004-2007 Analog Devices Inc.
  *
- * Created:
- * Description:
+ * Enter bugs at http://blackfin.uclinux.org/
  *
- * Modified:
- *             Copyright 2004-2006 Analog Devices Inc.
- *
- * Bugs:       Enter bugs at http://blackfin.uclinux.org/
- *
- * This program is free software ;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ;  either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ;  see the file COPYING.
- * If not, write to the Free Software Foundation,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under the GPL-2 or later.
  */
 
 #define BFIN_MAC_CSUM_OFFLOAD
index 2039f7838f2df713a0afe9a4bbe1aecc8955e617..0942d82f7cbf721f62c364941a13b31373668c5b 100644 (file)
@@ -1464,10 +1464,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                        dev_set_allmulti(slave_dev, 1);
                }
 
+               netif_tx_lock_bh(bond_dev);
                /* upload master's mc_list to new slave */
                for (dmi = bond_dev->mc_list; dmi; dmi = dmi->next) {
                        dev_mc_add (slave_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
                }
+               netif_tx_unlock_bh(bond_dev);
        }
 
        if (bond->params.mode == BOND_MODE_8023AD) {
@@ -1821,7 +1823,9 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
                }
 
                /* flush master's mc_list from slave */
+               netif_tx_lock_bh(bond_dev);
                bond_mc_list_flush(bond_dev, slave_dev);
+               netif_tx_unlock_bh(bond_dev);
        }
 
        netdev_set_master(slave_dev, NULL);
@@ -1942,7 +1946,9 @@ static int bond_release_all(struct net_device *bond_dev)
                        }
 
                        /* flush master's mc_list from slave */
+                       netif_tx_lock_bh(bond_dev);
                        bond_mc_list_flush(bond_dev, slave_dev);
+                       netif_tx_unlock_bh(bond_dev);
                }
 
                netdev_set_master(slave_dev, NULL);
@@ -2795,14 +2801,11 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
        }
 
        if (do_failover) {
-               rtnl_lock();
                write_lock_bh(&bond->curr_slave_lock);
 
                bond_select_active_slave(bond);
 
                write_unlock_bh(&bond->curr_slave_lock);
-               rtnl_unlock();
-
        }
 
 re_arm:
@@ -2859,8 +2862,6 @@ void bond_activebackup_arp_mon(struct work_struct *work)
 
                                slave->link = BOND_LINK_UP;
 
-                               rtnl_lock();
-
                                write_lock_bh(&bond->curr_slave_lock);
 
                                if ((!bond->curr_active_slave) &&
@@ -2896,7 +2897,6 @@ void bond_activebackup_arp_mon(struct work_struct *work)
                                }
 
                                write_unlock_bh(&bond->curr_slave_lock);
-                               rtnl_unlock();
                        }
                } else {
                        read_lock(&bond->curr_slave_lock);
@@ -2966,7 +2966,6 @@ void bond_activebackup_arp_mon(struct work_struct *work)
                               bond->dev->name,
                               slave->dev->name);
 
-                       rtnl_lock();
                        write_lock_bh(&bond->curr_slave_lock);
 
                        bond_select_active_slave(bond);
@@ -2974,8 +2973,6 @@ void bond_activebackup_arp_mon(struct work_struct *work)
 
                        write_unlock_bh(&bond->curr_slave_lock);
 
-                       rtnl_unlock();
-
                        bond->current_arp_slave = slave;
 
                        if (slave) {
@@ -2993,13 +2990,10 @@ void bond_activebackup_arp_mon(struct work_struct *work)
                               bond->primary_slave->dev->name);
 
                        /* primary is up so switch to it */
-                       rtnl_lock();
                        write_lock_bh(&bond->curr_slave_lock);
                        bond_change_active_slave(bond, bond->primary_slave);
                        write_unlock_bh(&bond->curr_slave_lock);
 
-                       rtnl_unlock();
-
                        slave = bond->primary_slave;
                        slave->jiffies = jiffies;
                } else {
@@ -3769,42 +3763,45 @@ static struct net_device_stats *bond_get_stats(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct net_device_stats *stats = &(bond->stats), *sstats;
+       struct net_device_stats local_stats;
        struct slave *slave;
        int i;
 
-       memset(stats, 0, sizeof(struct net_device_stats));
+       memset(&local_stats, 0, sizeof(struct net_device_stats));
 
        read_lock_bh(&bond->lock);
 
        bond_for_each_slave(bond, slave, i) {
                sstats = slave->dev->get_stats(slave->dev);
-               stats->rx_packets += sstats->rx_packets;
-               stats->rx_bytes += sstats->rx_bytes;
-               stats->rx_errors += sstats->rx_errors;
-               stats->rx_dropped += sstats->rx_dropped;
+               local_stats.rx_packets += sstats->rx_packets;
+               local_stats.rx_bytes += sstats->rx_bytes;
+               local_stats.rx_errors += sstats->rx_errors;
+               local_stats.rx_dropped += sstats->rx_dropped;
 
-               stats->tx_packets += sstats->tx_packets;
-               stats->tx_bytes += sstats->tx_bytes;
-               stats->tx_errors += sstats->tx_errors;
-               stats->tx_dropped += sstats->tx_dropped;
+               local_stats.tx_packets += sstats->tx_packets;
+               local_stats.tx_bytes += sstats->tx_bytes;
+               local_stats.tx_errors += sstats->tx_errors;
+               local_stats.tx_dropped += sstats->tx_dropped;
 
-               stats->multicast += sstats->multicast;
-               stats->collisions += sstats->collisions;
+               local_stats.multicast += sstats->multicast;
+               local_stats.collisions += sstats->collisions;
 
-               stats->rx_length_errors += sstats->rx_length_errors;
-               stats->rx_over_errors += sstats->rx_over_errors;
-               stats->rx_crc_errors += sstats->rx_crc_errors;
-               stats->rx_frame_errors += sstats->rx_frame_errors;
-               stats->rx_fifo_errors += sstats->rx_fifo_errors;
-               stats->rx_missed_errors += sstats->rx_missed_errors;
+               local_stats.rx_length_errors += sstats->rx_length_errors;
+               local_stats.rx_over_errors += sstats->rx_over_errors;
+               local_stats.rx_crc_errors += sstats->rx_crc_errors;
+               local_stats.rx_frame_errors += sstats->rx_frame_errors;
+               local_stats.rx_fifo_errors += sstats->rx_fifo_errors;
+               local_stats.rx_missed_errors += sstats->rx_missed_errors;
 
-               stats->tx_aborted_errors += sstats->tx_aborted_errors;
-               stats->tx_carrier_errors += sstats->tx_carrier_errors;
-               stats->tx_fifo_errors += sstats->tx_fifo_errors;
-               stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
-               stats->tx_window_errors += sstats->tx_window_errors;
+               local_stats.tx_aborted_errors += sstats->tx_aborted_errors;
+               local_stats.tx_carrier_errors += sstats->tx_carrier_errors;
+               local_stats.tx_fifo_errors += sstats->tx_fifo_errors;
+               local_stats.tx_heartbeat_errors += sstats->tx_heartbeat_errors;
+               local_stats.tx_window_errors += sstats->tx_window_errors;
        }
 
+       memcpy(stats, &local_stats, sizeof(struct net_device_stats));
+
        read_unlock_bh(&bond->lock);
 
        return stats;
@@ -3937,8 +3934,6 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
        struct bonding *bond = bond_dev->priv;
        struct dev_mc_list *dmi;
 
-       write_lock_bh(&bond->lock);
-
        /*
         * Do promisc before checking multicast_mode
         */
@@ -3959,6 +3954,8 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
                bond_set_allmulti(bond, -1);
        }
 
+       read_lock(&bond->lock);
+
        bond->flags = bond_dev->flags;
 
        /* looking for addresses to add to slaves' mc list */
@@ -3979,7 +3976,7 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
        bond_mc_list_destroy(bond);
        bond_mc_list_copy(bond_dev->mc_list, bond, GFP_ATOMIC);
 
-       write_unlock_bh(&bond->lock);
+       read_unlock(&bond->lock);
 }
 
 /*
@@ -4526,7 +4523,9 @@ static void bond_free_all(void)
                struct net_device *bond_dev = bond->dev;
 
                bond_work_cancel_all(bond);
+               netif_tx_lock_bh(bond_dev);
                bond_mc_list_destroy(bond);
+               netif_tx_unlock_bh(bond_dev);
                /* Release the bonded slaves */
                bond_release_all(bond_dev);
                bond_deinit(bond_dev);
@@ -4549,14 +4548,19 @@ static void bond_free_all(void)
 int bond_parse_parm(const char *buf, struct bond_parm_tbl *tbl)
 {
        int mode = -1, i, rv;
-       char modestr[BOND_MAX_MODENAME_LEN + 1] = { 0, };
+       char *p, modestr[BOND_MAX_MODENAME_LEN + 1] = { 0, };
 
-       rv = sscanf(buf, "%d", &mode);
-       if (!rv) {
+       for (p = (char *)buf; *p; p++)
+               if (!(isdigit(*p) || isspace(*p)))
+                       break;
+
+       if (*p)
                rv = sscanf(buf, "%20s", modestr);
-               if (!rv)
-                       return -1;
-       }
+       else
+               rv = sscanf(buf, "%d", &mode);
+
+       if (!rv)
+               return -1;
 
        for (i = 0; tbl[i].modename; i++) {
                if (mode == tbl[i].mode)
@@ -4883,14 +4887,16 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
        down_write(&bonding_rwsem);
 
        /* Check to see if the bond already exists. */
-       list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
-               if (strnicmp(bond->dev->name, name, IFNAMSIZ) == 0) {
-                       printk(KERN_ERR DRV_NAME
+       if (name) {
+               list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
+                       if (strnicmp(bond->dev->name, name, IFNAMSIZ) == 0) {
+                               printk(KERN_ERR DRV_NAME
                               ": cannot add bond %s; it already exists\n",
-                              name);
-                       res = -EPERM;
-                       goto out_rtnl;
-               }
+                                      name);
+                               res = -EPERM;
+                               goto out_rtnl;
+                       }
+       }
 
        bond_dev = alloc_netdev(sizeof(struct bonding), name ? name : "",
                                ether_setup);
index 6d83be49899a496fe5125ad3e95d081634a7c269..67ccad69d445f097675c9c724b7a632bca10a4cd 100644 (file)
@@ -22,8 +22,8 @@
 #include "bond_3ad.h"
 #include "bond_alb.h"
 
-#define DRV_VERSION    "3.2.3"
-#define DRV_RELDATE    "December 6, 2007"
+#define DRV_VERSION    "3.2.4"
+#define DRV_RELDATE    "January 28, 2008"
 #define DRV_NAME       "bonding"
 #define DRV_DESCRIPTION        "Ethernet Channel Bonding Driver"
 
index d48c396bdabb9858f15f8f0264557bb68890d9e4..901c824bfe6d5bda0f8a9d85a97b00bc91c1bf50 100644 (file)
@@ -1070,9 +1070,7 @@ void *cxgb_alloc_mem(unsigned long size)
  */
 void cxgb_free_mem(void *addr)
 {
-       unsigned long p = (unsigned long)addr;
-
-       if (p >= VMALLOC_START && p < VMALLOC_END)
+       if (is_vmalloc_addr(addr))
                vfree(addr);
        else
                kfree(addr);
index 84c1ffa8e2d38561bf68f40b5d506782f2b9aea0..4c4d6e877ea698baf6ed92bbfc606f1b389dc476 100644 (file)
@@ -452,7 +452,7 @@ void t3_mc5_intr_handler(struct mc5 *mc5)
        t3_write_reg(adap, A_MC5_DB_INT_CAUSE, cause);
 }
 
-void __devinit t3_mc5_prep(struct adapter *adapter, struct mc5 *mc5, int mode)
+void t3_mc5_prep(struct adapter *adapter, struct mc5 *mc5, int mode)
 {
 #define K * 1024
 
index cb684d30831fcc228da571e80ec9b96b0ee47a8b..9ca8c66abd16193fddea7d0a5118ba2db2175505 100644 (file)
@@ -2836,7 +2836,7 @@ void t3_sge_init(struct adapter *adap, struct sge_params *p)
  *     defaults for the assorted SGE parameters, which admins can change until
  *     they are used to initialize the SGE.
  */
-void __devinit t3_sge_prep(struct adapter *adap, struct sge_params *p)
+void t3_sge_prep(struct adapter *adap, struct sge_params *p)
 {
        int i;
 
index 7469935877bd746370dc183ec7eaabbfc813b3da..a99496a431c423f260b41fc6ae06fa4cd3ae1dcf 100644 (file)
@@ -2675,7 +2675,7 @@ void t3_tp_set_max_rxsize(struct adapter *adap, unsigned int size)
                     V_PMMAXXFERLEN0(size) | V_PMMAXXFERLEN1(size));
 }
 
-static void __devinit init_mtus(unsigned short mtus[])
+static void init_mtus(unsigned short mtus[])
 {
        /*
         * See draft-mathis-plpmtud-00.txt for the values.  The min is 88 so
@@ -2703,7 +2703,7 @@ static void __devinit init_mtus(unsigned short mtus[])
 /*
  * Initial congestion control parameters.
  */
-static void __devinit init_cong_ctrl(unsigned short *a, unsigned short *b)
+static void init_cong_ctrl(unsigned short *a, unsigned short *b)
 {
        a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
        a[9] = 2;
@@ -3354,8 +3354,7 @@ out_err:
  *     Determines a card's PCI mode and associated parameters, such as speed
  *     and width.
  */
-static void __devinit get_pci_mode(struct adapter *adapter,
-                                  struct pci_params *p)
+static void get_pci_mode(struct adapter *adapter, struct pci_params *p)
 {
        static unsigned short speed_map[] = { 33, 66, 100, 133 };
        u32 pci_mode, pcie_cap;
@@ -3395,8 +3394,7 @@ static void __devinit get_pci_mode(struct adapter *adapter,
  *     capabilities and default speed/duplex/flow-control/autonegotiation
  *     settings.
  */
-static void __devinit init_link_config(struct link_config *lc,
-                                      unsigned int caps)
+static void init_link_config(struct link_config *lc, unsigned int caps)
 {
        lc->supported = caps;
        lc->requested_speed = lc->speed = SPEED_INVALID;
@@ -3419,7 +3417,7 @@ static void __devinit init_link_config(struct link_config *lc,
  *     Calculates the size of an MC7 memory in bytes from the value of its
  *     configuration register.
  */
-static unsigned int __devinit mc7_calc_size(u32 cfg)
+static unsigned int mc7_calc_size(u32 cfg)
 {
        unsigned int width = G_WIDTH(cfg);
        unsigned int banks = !!(cfg & F_BKS) + 1;
@@ -3430,8 +3428,8 @@ static unsigned int __devinit mc7_calc_size(u32 cfg)
        return MBs << 20;
 }
 
-static void __devinit mc7_prep(struct adapter *adapter, struct mc7 *mc7,
-                              unsigned int base_addr, const char *name)
+static void mc7_prep(struct adapter *adapter, struct mc7 *mc7,
+                    unsigned int base_addr, const char *name)
 {
        u32 cfg;
 
@@ -3517,7 +3515,7 @@ static int t3_reset_adapter(struct adapter *adapter)
        return 0;
 }
 
-static int __devinit init_parity(struct adapter *adap)
+static int init_parity(struct adapter *adap)
 {
                int i, err, addr;
 
@@ -3552,8 +3550,8 @@ static int __devinit init_parity(struct adapter *adap)
  * for some adapter tunables, take PHYs out of reset, and initialize the MDIO
  * interface.
  */
-int __devinit t3_prep_adapter(struct adapter *adapter,
-                             const struct adapter_info *ai, int reset)
+int t3_prep_adapter(struct adapter *adapter, const struct adapter_info *ai,
+                   int reset)
 {
        int ret;
        unsigned int i, j = 0;
index 51cf577035bed0c466a45a4470102c3db56ef6db..36ba6dc96acc8494605c41315a8acecaa13f702f 100644 (file)
@@ -94,7 +94,7 @@
  *     enabled.  82557 pads with 7Eh, while the later controllers pad
  *     with 00h.
  *
- *     IV.  Recieve
+ *     IV.  Receive
  *
  *     The Receive Frame Area (RFA) comprises a ring of Receive Frame
  *     Descriptors (RFD) + data buffer, thus forming the simplified mode
  *     and Rx indication and re-allocation happen in the same context,
  *     therefore no locking is required.  A software-generated interrupt
  *     is generated from the watchdog to recover from a failed allocation
- *     senario where all Rx resources have been indicated and none re-
+ *     scenario where all Rx resources have been indicated and none re-
  *     placed.
  *
  *     V.   Miscellaneous
@@ -954,7 +954,7 @@ static void e100_get_defaults(struct nic *nic)
        /* Quadwords to DMA into FIFO before starting frame transmit */
        nic->tx_threshold = 0xE0;
 
-       /* no interrupt for every tx completion, delay = 256us if not 557*/
+       /* no interrupt for every tx completion, delay = 256us if not 557 */
        nic->tx_command = cpu_to_le16(cb_tx | cb_tx_sf |
                ((nic->mac >= mac_82558_D101_A4) ? cb_cid : cb_i));
 
@@ -1497,7 +1497,7 @@ static void e100_update_stats(struct nic *nic)
                &s->complete;
 
        /* Device's stats reporting may take several microseconds to
-        * complete, so where always waiting for results of the
+        * complete, so we're always waiting for results of the
         * previous command. */
 
        if(*complete == cpu_to_le32(cuc_dump_reset_complete)) {
@@ -1958,7 +1958,7 @@ static void e100_rx_clean(struct nic *nic, unsigned int *work_done,
 
        if(restart_required) {
                // ack the rnr?
-               writeb(stat_ack_rnr, &nic->csr->scb.stat_ack);
+               iowrite8(stat_ack_rnr, &nic->csr->scb.stat_ack);
                e100_start_receiver(nic, nic->rx_to_clean);
                if(work_done)
                        (*work_done)++;
@@ -2774,7 +2774,7 @@ static void __devexit e100_remove(struct pci_dev *pdev)
                struct nic *nic = netdev_priv(netdev);
                unregister_netdev(netdev);
                e100_free(nic);
-               iounmap(nic->csr);
+               pci_iounmap(pdev, nic->csr);
                free_netdev(netdev);
                pci_release_regions(pdev);
                pci_disable_device(pdev);
@@ -2858,17 +2858,17 @@ static void e100_shutdown(struct pci_dev *pdev)
 /**
  * e100_io_error_detected - called when PCI error is detected.
  * @pdev: Pointer to PCI device
- * @state: The current pci conneection state
+ * @state: The current pci connection state
  */
 static pci_ers_result_t e100_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct nic *nic = netdev_priv(netdev);
 
-       /* Similar to calling e100_down(), but avoids adpater I/O. */
+       /* Similar to calling e100_down(), but avoids adapter I/O. */
        netdev->stop(netdev);
 
-       /* Detach; put netif into state similar to hotplug unplug. */
+       /* Detach; put netif into state similar to hotplug unplug. */
        napi_enable(&nic->napi);
        netif_device_detach(netdev);
        pci_disable_device(pdev);
index 8c87940a9ce86341eacda17d1a3ad94106e32921..7c5b05a82f0e7c9a27b77a9f3d943fcf3baf2931 100644 (file)
@@ -853,7 +853,7 @@ e1000_reset(struct e1000_adapter *adapter)
 /**
  *  Dump the eeprom for users having checksum issues
  **/
-void e1000_dump_eeprom(struct e1000_adapter *adapter)
+static void e1000_dump_eeprom(struct e1000_adapter *adapter)
 {
        struct net_device *netdev = adapter->netdev;
        struct ethtool_eeprom eeprom;
index f2175ea46b830a438380a54d0571bb3c92683586..6232c3e96689668cb15748e88a82ddc856c1714f 100644 (file)
@@ -63,6 +63,7 @@
 #define E1000_WUFC_EX   0x00000004 /* Directed Exact Wakeup Enable */
 #define E1000_WUFC_MC   0x00000008 /* Directed Multicast Wakeup Enable */
 #define E1000_WUFC_BC   0x00000010 /* Broadcast Wakeup Enable */
+#define E1000_WUFC_ARP  0x00000020 /* ARP Request Packet Wakeup Enable */
 
 /* Extended Device Control */
 #define E1000_CTRL_EXT_SDP7_DATA 0x00000080 /* Value of SW Defineable Pin 7 */
index 6d9c27fd0b53b86953ecf3548d59c4825de1e626..f77a7427d3a079bf9ad714bf9cfc8f416851fb59 100644 (file)
@@ -690,8 +690,8 @@ err_setup:
        return err;
 }
 
-bool reg_pattern_test_array(struct e1000_adapter *adapter, u64 *data,
-                           int reg, int offset, u32 mask, u32 write)
+static bool reg_pattern_test_array(struct e1000_adapter *adapter, u64 *data,
+                                  int reg, int offset, u32 mask, u32 write)
 {
        int i;
        u32 read;
@@ -1632,7 +1632,8 @@ static void e1000_get_wol(struct net_device *netdev,
                return;
 
        wol->supported = WAKE_UCAST | WAKE_MCAST |
-                        WAKE_BCAST | WAKE_MAGIC;
+                        WAKE_BCAST | WAKE_MAGIC |
+                        WAKE_PHY | WAKE_ARP;
 
        /* apply any specific unsupported masks here */
        if (adapter->flags & FLAG_NO_WAKE_UCAST) {
@@ -1651,6 +1652,10 @@ static void e1000_get_wol(struct net_device *netdev,
                wol->wolopts |= WAKE_BCAST;
        if (adapter->wol & E1000_WUFC_MAG)
                wol->wolopts |= WAKE_MAGIC;
+       if (adapter->wol & E1000_WUFC_LNKC)
+               wol->wolopts |= WAKE_PHY;
+       if (adapter->wol & E1000_WUFC_ARP)
+               wol->wolopts |= WAKE_ARP;
 }
 
 static int e1000_set_wol(struct net_device *netdev,
@@ -1658,7 +1663,7 @@ static int e1000_set_wol(struct net_device *netdev,
 {
        struct e1000_adapter *adapter = netdev_priv(netdev);
 
-       if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
+       if (wol->wolopts & WAKE_MAGICSECURE)
                return -EOPNOTSUPP;
 
        if (!(adapter->flags & FLAG_HAS_WOL))
@@ -1675,6 +1680,10 @@ static int e1000_set_wol(struct net_device *netdev,
                adapter->wol |= E1000_WUFC_BC;
        if (wol->wolopts & WAKE_MAGIC)
                adapter->wol |= E1000_WUFC_MAG;
+       if (wol->wolopts & WAKE_PHY)
+               adapter->wol |= E1000_WUFC_LNKC;
+       if (wol->wolopts & WAKE_ARP)
+               adapter->wol |= E1000_WUFC_ARP;
 
        return 0;
 }
index 0a2cb7960c9e8d8dcb85063773a3d800068a9a9d..f58f017ee47ae837a45e3f0fcba3e2bafcf81d06 100644 (file)
@@ -945,11 +945,7 @@ static int e1000_request_irq(struct e1000_adapter *adapter)
        int irq_flags = IRQF_SHARED;
        int err;
 
-       err = pci_enable_msi(adapter->pdev);
-       if (err) {
-               ndev_warn(netdev,
-                "Unable to allocate MSI interrupt Error: %d\n", err);
-       } else {
+       if (!pci_enable_msi(adapter->pdev)) {
                adapter->flags |= FLAG_MSI_ENABLED;
                handler = e1000_intr_msi;
                irq_flags = 0;
@@ -958,10 +954,12 @@ static int e1000_request_irq(struct e1000_adapter *adapter)
        err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
                          netdev);
        if (err) {
+               ndev_err(netdev,
+                      "Unable to allocate %s interrupt (return: %d)\n",
+                       adapter->flags & FLAG_MSI_ENABLED ? "MSI":"INTx",
+                       err);
                if (adapter->flags & FLAG_MSI_ENABLED)
                        pci_disable_msi(adapter->pdev);
-               ndev_err(netdev,
-                      "Unable to allocate interrupt Error: %d\n", err);
        }
 
        return err;
index d5459a8056b1a4f60f8207b1651385e5ff2856d1..2eb82aba4a8bc7c0a2ee5e26b959a1c33dbce4ba 100644 (file)
@@ -9,7 +9,7 @@
  * Many modifications, and currently maintained, by
  *  Philip Blundell <philb@gnu.org>
  * Added the Compaq LTE  Alan Cox <alan@redhat.com>
- * Added MCA support Adam Fritzler <mid@auk.cx>
+ * Added MCA support Adam Fritzler
  *
  * Note - this driver is experimental still - it has problems on faster
  * machines. Someone needs to sit down and go through it line by line with
index 5f82a4647eee4dcec3240be6ec51932926efae16..88fb53eba715368e9685ff5dbd6db275bc826626 100644 (file)
@@ -458,4 +458,7 @@ void ehea_set_ethtool_ops(struct net_device *netdev);
 int ehea_sense_port_attr(struct ehea_port *port);
 int ehea_set_portspeed(struct ehea_port *port, u32 port_speed);
 
+extern u64 ehea_driver_flags;
+extern struct work_struct ehea_rereg_mr_task;
+
 #endif /* __EHEA_H__ */
index 679f40ee957263af5ee375f5e76df76e42b45c52..d768852233663008eaf4cd5a9e324af68da3627b 100644 (file)
@@ -40,7 +40,7 @@ static int ehea_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
                return ret;
 
        if (netif_carrier_ok(dev)) {
-               switch(port->port_speed) {
+               switch (port->port_speed) {
                case EHEA_SPEED_10M: cmd->speed = SPEED_10; break;
                case EHEA_SPEED_100M: cmd->speed = SPEED_100; break;
                case EHEA_SPEED_1G: cmd->speed = SPEED_1000; break;
@@ -78,7 +78,7 @@ static int ehea_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
                goto doit;
        }
 
-       switch(cmd->speed) {
+       switch (cmd->speed) {
        case SPEED_10:
                if (cmd->duplex == DUPLEX_FULL)
                        sp = H_SPEED_10M_F;
index 1af7ca499ec517232e7c83dc845f2f336c07430c..567981b4b2cc351a01a54460ea512f970203ef8a 100644 (file)
 #ifndef __EHEA_HW_H__
 #define __EHEA_HW_H__
 
-#define QPX_SQA_VALUE   EHEA_BMASK_IBM(48,63)
-#define QPX_RQ1A_VALUE  EHEA_BMASK_IBM(48,63)
-#define QPX_RQ2A_VALUE  EHEA_BMASK_IBM(48,63)
-#define QPX_RQ3A_VALUE  EHEA_BMASK_IBM(48,63)
+#define QPX_SQA_VALUE   EHEA_BMASK_IBM(48, 63)
+#define QPX_RQ1A_VALUE  EHEA_BMASK_IBM(48, 63)
+#define QPX_RQ2A_VALUE  EHEA_BMASK_IBM(48, 63)
+#define QPX_RQ3A_VALUE  EHEA_BMASK_IBM(48, 63)
 
 #define QPTEMM_OFFSET(x) offsetof(struct ehea_qptemm, x)
 
index 869e1604b16ea0e4b5555acbe77dff969f42cb5b..c051c7e09b9a0b600f4202e5febba3b5ee0f7723 100644 (file)
@@ -6,9 +6,9 @@
  *  (C) Copyright IBM Corp. 2006
  *
  *  Authors:
- *       Christoph Raisch <raisch@de.ibm.com>
- *       Jan-Bernd Themann <themann@de.ibm.com>
- *       Thomas Klein <tklein@de.ibm.com>
+ *      Christoph Raisch <raisch@de.ibm.com>
+ *      Jan-Bernd Themann <themann@de.ibm.com>
+ *      Thomas Klein <tklein@de.ibm.com>
  *
  *
  * This program is free software; you can redistribute it and/or modify
@@ -54,11 +54,11 @@ static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
 static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
 static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
 static int sq_entries = EHEA_DEF_ENTRIES_SQ;
-static int use_mcs = 0;
-static int use_lro = 0;
+static int use_mcs;
+static int use_lro;
 static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
 static int num_tx_qps = EHEA_NUM_TX_QP;
-static int prop_carrier_state = 0;
+static int prop_carrier_state;
 
 module_param(msg_level, int, 0);
 module_param(rq1_entries, int, 0);
@@ -94,9 +94,9 @@ MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
 MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
                 "Default = 0");
 
-static int port_name_cnt = 0;
+static int port_name_cnt;
 static LIST_HEAD(adapter_list);
-u64 ehea_driver_flags = 0;
+u64 ehea_driver_flags;
 struct work_struct ehea_rereg_mr_task;
 
 struct semaphore dlpar_mem_lock;
@@ -121,12 +121,13 @@ static struct of_platform_driver ehea_driver = {
        .remove = ehea_remove,
 };
 
-void ehea_dump(void *adr, int len, char *msg) {
+void ehea_dump(void *adr, int len, char *msg)
+{
        int x;
        unsigned char *deb = adr;
        for (x = 0; x < len; x += 16) {
                printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
-                         deb, x, *((u64*)&deb[0]), *((u64*)&deb[8]));
+                         deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
                deb += 16;
        }
 }
@@ -518,7 +519,8 @@ static int ehea_proc_rwqes(struct net_device *dev,
                last_wqe_index = wqe_index;
                rmb();
                if (!ehea_check_cqe(cqe, &rq)) {
-                       if (rq == 1) {  /* LL RQ1 */
+                       if (rq == 1) {
+                               /* LL RQ1 */
                                skb = get_skb_by_index_ll(skb_arr_rq1,
                                                          skb_arr_rq1_len,
                                                          wqe_index);
@@ -531,10 +533,11 @@ static int ehea_proc_rwqes(struct net_device *dev,
                                        if (!skb)
                                                break;
                                }
-                               skb_copy_to_linear_data(skb, ((char*)cqe) + 64,
+                               skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
                                                 cqe->num_bytes_transfered - 4);
                                ehea_fill_skb(dev, skb, cqe);
-                       } else if (rq == 2) {  /* RQ2 */
+                       } else if (rq == 2) {
+                               /* RQ2 */
                                skb = get_skb_by_index(skb_arr_rq2,
                                                       skb_arr_rq2_len, cqe);
                                if (unlikely(!skb)) {
@@ -544,7 +547,8 @@ static int ehea_proc_rwqes(struct net_device *dev,
                                }
                                ehea_fill_skb(dev, skb, cqe);
                                processed_rq2++;
-                       } else {  /* RQ3 */
+                       } else {
+                               /* RQ3 */
                                skb = get_skb_by_index(skb_arr_rq3,
                                                       skb_arr_rq3_len, cqe);
                                if (unlikely(!skb)) {
@@ -592,7 +596,7 @@ static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
        unsigned long flags;
 
        cqe = ehea_poll_cq(send_cq);
-       while(cqe && (quota > 0)) {
+       while (cqe && (quota > 0)) {
                ehea_inc_cq(send_cq);
 
                cqe_counter++;
@@ -643,7 +647,8 @@ static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
 
 static int ehea_poll(struct napi_struct *napi, int budget)
 {
-       struct ehea_port_res *pr = container_of(napi, struct ehea_port_res, napi);
+       struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
+                                               napi);
        struct net_device *dev = pr->port->netdev;
        struct ehea_cqe *cqe;
        struct ehea_cqe *cqe_skb = NULL;
@@ -743,8 +748,9 @@ int ehea_sense_port_attr(struct ehea_port *port)
        u64 hret;
        struct hcp_ehea_port_cb0 *cb0;
 
-       cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);   /* May be called via */
-       if (!cb0) {                             /* ehea_neq_tasklet() */
+       /* may be called via ehea_neq_tasklet() */
+       cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
+       if (!cb0) {
                ehea_error("no mem for cb0");
                ret = -ENOMEM;
                goto out;
@@ -762,7 +768,7 @@ int ehea_sense_port_attr(struct ehea_port *port)
        /* MAC address */
        port->mac_addr = cb0->port_mac_addr << 16;
 
-       if (!is_valid_ether_addr((u8*)&port->mac_addr)) {
+       if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
                ret = -EADDRNOTAVAIL;
                goto out_free;
        }
@@ -994,7 +1000,7 @@ static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
 
 static void ehea_neq_tasklet(unsigned long data)
 {
-       struct ehea_adapter *adapter = (struct ehea_adapter*)data;
+       struct ehea_adapter *adapter = (struct ehea_adapter *)data;
        struct ehea_eqe *eqe;
        u64 event_mask;
 
@@ -1204,7 +1210,7 @@ int ehea_rem_smrs(struct ehea_port_res *pr)
 
 static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
 {
-       int arr_size = sizeof(void*) * max_q_entries;
+       int arr_size = sizeof(void *) * max_q_entries;
 
        q_skba->arr = vmalloc(arr_size);
        if (!q_skba->arr)
@@ -1489,7 +1495,7 @@ static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
 
        nfrags = skb_shinfo(skb)->nr_frags;
        sg1entry = &swqe->u.immdata_desc.sg_entry;
-       sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list;
+       sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
        swqe->descriptors = 0;
        sg1entry_contains_frag_data = 0;
 
@@ -1542,7 +1548,7 @@ static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
                                     reg_type, port->mac_addr, 0, hcallid);
        if (hret != H_SUCCESS) {
                ehea_error("%sregistering bc address failed (tagged)",
-                           hcallid == H_REG_BCMC ? "" : "de");
+                          hcallid == H_REG_BCMC ? "" : "de");
                ret = -EIO;
                goto out_herr;
        }
@@ -1732,7 +1738,7 @@ static void ehea_allmulti(struct net_device *dev, int enable)
                }
 }
 
-static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr)
+static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
 {
        struct ehea_mc_list *ehea_mcl_entry;
        u64 hret;
@@ -1791,11 +1797,10 @@ static void ehea_set_multicast_list(struct net_device *dev)
                        goto out;
                }
 
-               for (i = 0, k_mcl_entry = dev->mc_list;
-                    i < dev->mc_count;
-                    i++, k_mcl_entry = k_mcl_entry->next) {
+               for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
+                            k_mcl_entry = k_mcl_entry->next)
                        ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
-               }
+
        }
 out:
        return;
@@ -1925,12 +1930,12 @@ static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
 
        if ((skb->protocol == htons(ETH_P_IP)) &&
            (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
-               tcp = (struct tcphdr*)(skb_network_header(skb) + (ip_hdr(skb)->ihl * 4));
+               tcp = (struct tcphdr *)(skb_network_header(skb) +
+                                       (ip_hdr(skb)->ihl * 4));
                tmp = (tcp->source + (tcp->dest << 16)) % 31;
                tmp += ip_hdr(skb)->daddr % 31;
                return tmp % num_qps;
-       }
-       else
+       } else
                return 0;
 }
 
@@ -2122,7 +2127,7 @@ int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
        u64 hret;
        u16 dummy16 = 0;
        u64 dummy64 = 0;
-       struct hcp_modify_qp_cb0cb0;
+       struct hcp_modify_qp_cb0 *cb0;
 
        cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
        if (!cb0) {
@@ -2248,7 +2253,7 @@ static int ehea_clean_all_portres(struct ehea_port *port)
        int ret = 0;
        int i;
 
-       for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
+       for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
                ret |= ehea_clean_portres(port, &port->port_res[i]);
 
        ret |= ehea_destroy_eq(port->qp_eq);
@@ -2300,7 +2305,7 @@ static int ehea_up(struct net_device *dev)
                goto out_clean_pr;
        }
 
-       for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
+       for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
                ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
                if (ret) {
                        ehea_error("activate_qp failed");
@@ -2308,7 +2313,7 @@ static int ehea_up(struct net_device *dev)
                }
        }
 
-       for(i = 0; i < port->num_def_qps; i++) {
+       for (i = 0; i < port->num_def_qps; i++) {
                ret = ehea_fill_port_res(&port->port_res[i]);
                if (ret) {
                        ehea_error("out_free_irqs");
@@ -2425,7 +2430,7 @@ int ehea_stop_qps(struct net_device *dev)
 {
        struct ehea_port *port = netdev_priv(dev);
        struct ehea_adapter *adapter = port->adapter;
-       struct hcp_modify_qp_cb0cb0;
+       struct hcp_modify_qp_cb0 *cb0;
        int ret = -EIO;
        int dret;
        int i;
@@ -2490,7 +2495,7 @@ out:
        return ret;
 }
 
-void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res * pr)
+void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
 {
        struct ehea_qp qp = *orig_qp;
        struct ehea_qp_init_attr *init_attr = &qp.init_attr;
@@ -2530,7 +2535,7 @@ int ehea_restart_qps(struct net_device *dev)
        int ret = 0;
        int i;
 
-       struct hcp_modify_qp_cb0cb0;
+       struct hcp_modify_qp_cb0 *cb0;
        u64 hret;
        u64 dummy64 = 0;
        u16 dummy16 = 0;
@@ -2804,34 +2809,6 @@ static void __devinit logical_port_release(struct device *dev)
        of_node_put(port->ofdev.node);
 }
 
-static int ehea_driver_sysfs_add(struct device *dev,
-                                struct device_driver *driver)
-{
-       int ret;
-
-       ret = sysfs_create_link(&driver->kobj, &dev->kobj,
-                               kobject_name(&dev->kobj));
-       if (ret == 0) {
-               ret = sysfs_create_link(&dev->kobj, &driver->kobj,
-                                       "driver");
-               if (ret)
-                       sysfs_remove_link(&driver->kobj,
-                                         kobject_name(&dev->kobj));
-       }
-       return ret;
-}
-
-static void ehea_driver_sysfs_remove(struct device *dev,
-                                    struct device_driver *driver)
-{
-       struct device_driver *drv = driver;
-
-       if (drv) {
-               sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
-               sysfs_remove_link(&dev->kobj, "driver");
-       }
-}
-
 static struct device *ehea_register_port(struct ehea_port *port,
                                         struct device_node *dn)
 {
@@ -2856,16 +2833,8 @@ static struct device *ehea_register_port(struct ehea_port *port,
                goto out_unreg_of_dev;
        }
 
-       ret = ehea_driver_sysfs_add(&port->ofdev.dev, &ehea_driver.driver);
-       if (ret) {
-               ehea_error("failed to register sysfs driver link");
-               goto out_rem_dev_file;
-       }
-
        return &port->ofdev.dev;
 
-out_rem_dev_file:
-       device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
 out_unreg_of_dev:
        of_device_unregister(&port->ofdev);
 out:
@@ -2874,7 +2843,6 @@ out:
 
 static void ehea_unregister_port(struct ehea_port *port)
 {
-       ehea_driver_sysfs_remove(&port->ofdev.dev, &ehea_driver.driver);
        device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
        of_device_unregister(&port->ofdev);
 }
@@ -3109,7 +3077,7 @@ static ssize_t ehea_probe_port(struct device *dev,
        of_node_put(eth_dn);
 
        if (port) {
-               for (i=0; i < EHEA_MAX_PORTS; i++)
+               for (i = 0; i < EHEA_MAX_PORTS; i++)
                        if (!adapter->port[i]) {
                                adapter->port[i] = port;
                                break;
@@ -3144,7 +3112,7 @@ static ssize_t ehea_remove_port(struct device *dev,
 
                ehea_shutdown_single_port(port);
 
-               for (i=0; i < EHEA_MAX_PORTS; i++)
+               for (i = 0; i < EHEA_MAX_PORTS; i++)
                        if (adapter->port[i] == port) {
                                adapter->port[i] = NULL;
                                break;
@@ -3313,7 +3281,7 @@ static int ehea_reboot_notifier(struct notifier_block *nb,
 }
 
 static struct notifier_block ehea_reboot_nb = {
-        .notifier_call = ehea_reboot_notifier,
+       .notifier_call = ehea_reboot_notifier,
 };
 
 static int check_module_parm(void)
index 95c4a7f9cc88aacbaf64cbbbec35f089bcc2adbd..156eb6320b4ee209369a80f5ec83f4740b7c63bf 100644 (file)
@@ -6,9 +6,9 @@
  *  (C) Copyright IBM Corp. 2006
  *
  *  Authors:
- *       Christoph Raisch <raisch@de.ibm.com>
- *       Jan-Bernd Themann <themann@de.ibm.com>
- *       Thomas Klein <tklein@de.ibm.com>
+ *      Christoph Raisch <raisch@de.ibm.com>
+ *      Jan-Bernd Themann <themann@de.ibm.com>
+ *      Thomas Klein <tklein@de.ibm.com>
  *
  *
  * This program is free software; you can redistribute it and/or modify
@@ -38,11 +38,11 @@ static inline u16 get_order_of_qentries(u16 queue_entries)
 }
 
 /* Defines for H_CALL H_ALLOC_RESOURCE */
-#define H_ALL_RES_TYPE_QP        1
-#define H_ALL_RES_TYPE_CQ        2
-#define H_ALL_RES_TYPE_EQ        3
-#define H_ALL_RES_TYPE_MR        5
-#define H_ALL_RES_TYPE_MW        6
+#define H_ALL_RES_TYPE_QP       1
+#define H_ALL_RES_TYPE_CQ       2
+#define H_ALL_RES_TYPE_EQ       3
+#define H_ALL_RES_TYPE_MR       5
+#define H_ALL_RES_TYPE_MW       6
 
 static long ehea_plpar_hcall_norets(unsigned long opcode,
                                    unsigned long arg1,
@@ -137,77 +137,77 @@ u64 ehea_h_query_ehea_qp(const u64 adapter_handle, const u8 qp_category,
                         const u64 qp_handle, const u64 sel_mask, void *cb_addr)
 {
        return ehea_plpar_hcall_norets(H_QUERY_HEA_QP,
-                                      adapter_handle,          /* R4 */
-                                      qp_category,             /* R5 */
-                                      qp_handle,               /* R6 */
-                                      sel_mask,                /* R7 */
+                                      adapter_handle,          /* R4 */
+                                      qp_category,             /* R5 */
+                                      qp_handle,               /* R6 */
+                                      sel_mask,                /* R7 */
                                       virt_to_abs(cb_addr),    /* R8 */
                                       0, 0);
 }
 
 /* input param R5 */
-#define H_ALL_RES_QP_EQPO         EHEA_BMASK_IBM(9, 11)
-#define H_ALL_RES_QP_QPP          EHEA_BMASK_IBM(12, 12)
-#define H_ALL_RES_QP_RQR          EHEA_BMASK_IBM(13, 15)
-#define H_ALL_RES_QP_EQEG         EHEA_BMASK_IBM(16, 16)
-#define H_ALL_RES_QP_LL_QP        EHEA_BMASK_IBM(17, 17)
-#define H_ALL_RES_QP_DMA128       EHEA_BMASK_IBM(19, 19)
-#define H_ALL_RES_QP_HSM          EHEA_BMASK_IBM(20, 21)
-#define H_ALL_RES_QP_SIGT         EHEA_BMASK_IBM(22, 23)
-#define H_ALL_RES_QP_TENURE       EHEA_BMASK_IBM(48, 55)
-#define H_ALL_RES_QP_RES_TYP      EHEA_BMASK_IBM(56, 63)
+#define H_ALL_RES_QP_EQPO        EHEA_BMASK_IBM(9, 11)
+#define H_ALL_RES_QP_QPP         EHEA_BMASK_IBM(12, 12)
+#define H_ALL_RES_QP_RQR         EHEA_BMASK_IBM(13, 15)
+#define H_ALL_RES_QP_EQEG        EHEA_BMASK_IBM(16, 16)
+#define H_ALL_RES_QP_LL_QP       EHEA_BMASK_IBM(17, 17)
+#define H_ALL_RES_QP_DMA128      EHEA_BMASK_IBM(19, 19)
+#define H_ALL_RES_QP_HSM         EHEA_BMASK_IBM(20, 21)
+#define H_ALL_RES_QP_SIGT        EHEA_BMASK_IBM(22, 23)
+#define H_ALL_RES_QP_TENURE      EHEA_BMASK_IBM(48, 55)
+#define H_ALL_RES_QP_RES_TYP     EHEA_BMASK_IBM(56, 63)
 
 /* input param R9  */
-#define H_ALL_RES_QP_TOKEN        EHEA_BMASK_IBM(0, 31)
-#define H_ALL_RES_QP_PD           EHEA_BMASK_IBM(32,63)
+#define H_ALL_RES_QP_TOKEN       EHEA_BMASK_IBM(0, 31)
+#define H_ALL_RES_QP_PD                  EHEA_BMASK_IBM(32, 63)
 
 /* input param R10 */
-#define H_ALL_RES_QP_MAX_SWQE     EHEA_BMASK_IBM(4, 7)
-#define H_ALL_RES_QP_MAX_R1WQE    EHEA_BMASK_IBM(12, 15)
-#define H_ALL_RES_QP_MAX_R2WQE    EHEA_BMASK_IBM(20, 23)
-#define H_ALL_RES_QP_MAX_R3WQE    EHEA_BMASK_IBM(28, 31)
+#define H_ALL_RES_QP_MAX_SWQE    EHEA_BMASK_IBM(4, 7)
+#define H_ALL_RES_QP_MAX_R1WQE   EHEA_BMASK_IBM(12, 15)
+#define H_ALL_RES_QP_MAX_R2WQE   EHEA_BMASK_IBM(20, 23)
+#define H_ALL_RES_QP_MAX_R3WQE   EHEA_BMASK_IBM(28, 31)
 /* Max Send Scatter Gather Elements */
-#define H_ALL_RES_QP_MAX_SSGE     EHEA_BMASK_IBM(37, 39)
-#define H_ALL_RES_QP_MAX_R1SGE    EHEA_BMASK_IBM(45, 47)
+#define H_ALL_RES_QP_MAX_SSGE    EHEA_BMASK_IBM(37, 39)
+#define H_ALL_RES_QP_MAX_R1SGE   EHEA_BMASK_IBM(45, 47)
 /* Max Receive SG Elements RQ1 */
-#define H_ALL_RES_QP_MAX_R2SGE    EHEA_BMASK_IBM(53, 55)
-#define H_ALL_RES_QP_MAX_R3SGE    EHEA_BMASK_IBM(61, 63)
+#define H_ALL_RES_QP_MAX_R2SGE   EHEA_BMASK_IBM(53, 55)
+#define H_ALL_RES_QP_MAX_R3SGE   EHEA_BMASK_IBM(61, 63)
 
 /* input param R11 */
-#define H_ALL_RES_QP_SWQE_IDL     EHEA_BMASK_IBM(0, 7)
+#define H_ALL_RES_QP_SWQE_IDL    EHEA_BMASK_IBM(0, 7)
 /* max swqe immediate data length */
-#define H_ALL_RES_QP_PORT_NUM     EHEA_BMASK_IBM(48, 63)
+#define H_ALL_RES_QP_PORT_NUM    EHEA_BMASK_IBM(48, 63)
 
 /* input param R12 */
-#define H_ALL_RES_QP_TH_RQ2       EHEA_BMASK_IBM(0, 15)
+#define H_ALL_RES_QP_TH_RQ2      EHEA_BMASK_IBM(0, 15)
 /* Threshold RQ2 */
-#define H_ALL_RES_QP_TH_RQ3       EHEA_BMASK_IBM(16, 31)
+#define H_ALL_RES_QP_TH_RQ3      EHEA_BMASK_IBM(16, 31)
 /* Threshold RQ3 */
 
 /* output param R6 */
-#define H_ALL_RES_QP_ACT_SWQE     EHEA_BMASK_IBM(0, 15)
-#define H_ALL_RES_QP_ACT_R1WQE    EHEA_BMASK_IBM(16, 31)
-#define H_ALL_RES_QP_ACT_R2WQE    EHEA_BMASK_IBM(32, 47)
-#define H_ALL_RES_QP_ACT_R3WQE    EHEA_BMASK_IBM(48, 63)
+#define H_ALL_RES_QP_ACT_SWQE    EHEA_BMASK_IBM(0, 15)
+#define H_ALL_RES_QP_ACT_R1WQE   EHEA_BMASK_IBM(16, 31)
+#define H_ALL_RES_QP_ACT_R2WQE   EHEA_BMASK_IBM(32, 47)
+#define H_ALL_RES_QP_ACT_R3WQE   EHEA_BMASK_IBM(48, 63)
 
 /* output param, R7 */
-#define H_ALL_RES_QP_ACT_SSGE     EHEA_BMASK_IBM(0, 7)
-#define H_ALL_RES_QP_ACT_R1SGE    EHEA_BMASK_IBM(8, 15)
-#define H_ALL_RES_QP_ACT_R2SGE    EHEA_BMASK_IBM(16, 23)
-#define H_ALL_RES_QP_ACT_R3SGE    EHEA_BMASK_IBM(24, 31)
+#define H_ALL_RES_QP_ACT_SSGE    EHEA_BMASK_IBM(0, 7)
+#define H_ALL_RES_QP_ACT_R1SGE   EHEA_BMASK_IBM(8, 15)
+#define H_ALL_RES_QP_ACT_R2SGE   EHEA_BMASK_IBM(16, 23)
+#define H_ALL_RES_QP_ACT_R3SGE   EHEA_BMASK_IBM(24, 31)
 #define H_ALL_RES_QP_ACT_SWQE_IDL EHEA_BMASK_IBM(32, 39)
 
 /* output param R8,R9 */
-#define H_ALL_RES_QP_SIZE_SQ      EHEA_BMASK_IBM(0, 31)
-#define H_ALL_RES_QP_SIZE_RQ1     EHEA_BMASK_IBM(32, 63)
-#define H_ALL_RES_QP_SIZE_RQ2     EHEA_BMASK_IBM(0, 31)
-#define H_ALL_RES_QP_SIZE_RQ3     EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_QP_SIZE_SQ     EHEA_BMASK_IBM(0, 31)
+#define H_ALL_RES_QP_SIZE_RQ1    EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_QP_SIZE_RQ2    EHEA_BMASK_IBM(0, 31)
+#define H_ALL_RES_QP_SIZE_RQ3    EHEA_BMASK_IBM(32, 63)
 
 /* output param R11,R12 */
-#define H_ALL_RES_QP_LIOBN_SQ     EHEA_BMASK_IBM(0, 31)
-#define H_ALL_RES_QP_LIOBN_RQ1    EHEA_BMASK_IBM(32, 63)
-#define H_ALL_RES_QP_LIOBN_RQ2    EHEA_BMASK_IBM(0, 31)
-#define H_ALL_RES_QP_LIOBN_RQ3    EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_QP_LIOBN_SQ    EHEA_BMASK_IBM(0, 31)
+#define H_ALL_RES_QP_LIOBN_RQ1   EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_QP_LIOBN_RQ2   EHEA_BMASK_IBM(0, 31)
+#define H_ALL_RES_QP_LIOBN_RQ3   EHEA_BMASK_IBM(32, 63)
 
 u64 ehea_h_alloc_resource_qp(const u64 adapter_handle,
                             struct ehea_qp_init_attr *init_attr, const u32 pd,
@@ -334,28 +334,28 @@ u64 ehea_h_alloc_resource_cq(const u64 adapter_handle,
 }
 
 /* Defines for H_CALL H_ALLOC_RESOURCE */
-#define H_ALL_RES_TYPE_QP        1
-#define H_ALL_RES_TYPE_CQ        2
-#define H_ALL_RES_TYPE_EQ        3
-#define H_ALL_RES_TYPE_MR        5
-#define H_ALL_RES_TYPE_MW        6
+#define H_ALL_RES_TYPE_QP       1
+#define H_ALL_RES_TYPE_CQ       2
+#define H_ALL_RES_TYPE_EQ       3
+#define H_ALL_RES_TYPE_MR       5
+#define H_ALL_RES_TYPE_MW       6
 
 /*  input param R5 */
-#define H_ALL_RES_EQ_NEQ             EHEA_BMASK_IBM(0, 0)
+#define H_ALL_RES_EQ_NEQ            EHEA_BMASK_IBM(0, 0)
 #define H_ALL_RES_EQ_NON_NEQ_ISN     EHEA_BMASK_IBM(6, 7)
 #define H_ALL_RES_EQ_INH_EQE_GEN     EHEA_BMASK_IBM(16, 16)
-#define H_ALL_RES_EQ_RES_TYPE        EHEA_BMASK_IBM(56, 63)
+#define H_ALL_RES_EQ_RES_TYPE       EHEA_BMASK_IBM(56, 63)
 /*  input param R6 */
-#define H_ALL_RES_EQ_MAX_EQE         EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_EQ_MAX_EQE        EHEA_BMASK_IBM(32, 63)
 
 /*  output param R6 */
-#define H_ALL_RES_EQ_LIOBN           EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_EQ_LIOBN          EHEA_BMASK_IBM(32, 63)
 
 /*  output param R7 */
-#define H_ALL_RES_EQ_ACT_EQE         EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_EQ_ACT_EQE        EHEA_BMASK_IBM(32, 63)
 
 /*  output param R8 */
-#define H_ALL_RES_EQ_ACT_PS          EHEA_BMASK_IBM(32, 63)
+#define H_ALL_RES_EQ_ACT_PS         EHEA_BMASK_IBM(32, 63)
 
 /*  output param R9 */
 #define H_ALL_RES_EQ_ACT_EQ_IST_C    EHEA_BMASK_IBM(30, 31)
@@ -453,12 +453,12 @@ u64 ehea_h_register_smr(const u64 adapter_handle, const u64 orig_mr_handle,
 
        hret = ehea_plpar_hcall9(H_REGISTER_SMR,
                                 outs,
-                                adapter_handle       ,          /* R4 */
-                                orig_mr_handle,                 /* R5 */
-                                vaddr_in,                       /* R6 */
-                                (((u64)access_ctrl) << 32ULL),  /* R7 */
-                                pd,                             /* R8 */
-                                0, 0, 0, 0);                    /* R9-R12 */
+                                adapter_handle       ,          /* R4 */
+                                orig_mr_handle,                 /* R5 */
+                                vaddr_in,                       /* R6 */
+                                (((u64)access_ctrl) << 32ULL),  /* R7 */
+                                pd,                             /* R8 */
+                                0, 0, 0, 0);                    /* R9-R12 */
 
        mr->handle = outs[0];
        mr->lkey = (u32)outs[2];
@@ -471,11 +471,11 @@ u64 ehea_h_disable_and_get_hea(const u64 adapter_handle, const u64 qp_handle)
        u64 outs[PLPAR_HCALL9_BUFSIZE];
 
        return ehea_plpar_hcall9(H_DISABLE_AND_GET_HEA,
-                                        outs,
+                                outs,
                                 adapter_handle,                /* R4 */
                                 H_DISABLE_GET_EHEA_WQE_P,      /* R5 */
                                 qp_handle,                     /* R6 */
-                                0, 0, 0, 0, 0, 0);             /* R7-R12 */
+                                0, 0, 0, 0, 0, 0);             /* R7-R12 */
 }
 
 u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle,
@@ -483,9 +483,9 @@ u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle,
 {
        return ehea_plpar_hcall_norets(H_FREE_RESOURCE,
                                       adapter_handle,     /* R4 */
-                                      res_handle,         /* R5 */
+                                      res_handle,         /* R5 */
                                       force_bit,
-                                      0, 0, 0, 0);        /* R7-R10 */
+                                      0, 0, 0, 0);        /* R7-R10 */
 }
 
 u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr,
@@ -493,13 +493,13 @@ u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr,
                             const u32 pd, u64 *mr_handle, u32 *lkey)
 {
        u64 hret;
-       u64 outs[PLPAR_HCALL9_BUFSIZE];
+       u64 outs[PLPAR_HCALL9_BUFSIZE];
 
        hret = ehea_plpar_hcall9(H_ALLOC_HEA_RESOURCE,
                                 outs,
                                 adapter_handle,                   /* R4 */
                                 5,                                /* R5 */
-                                vaddr,                            /* R6 */
+                                vaddr,                            /* R6 */
                                 length,                           /* R7 */
                                 (((u64) access_ctrl) << 32ULL),   /* R8 */
                                 pd,                               /* R9 */
@@ -619,8 +619,8 @@ u64 ehea_h_error_data(const u64 adapter_handle, const u64 ressource_handle,
                      void *rblock)
 {
        return ehea_plpar_hcall_norets(H_ERROR_DATA,
-                                      adapter_handle,          /* R4 */
-                                      ressource_handle,        /* R5 */
-                                      virt_to_abs(rblock),     /* R6 */
-                                      0, 0, 0, 0);             /* R7-R12 */
+                                      adapter_handle,          /* R4 */
+                                      ressource_handle,        /* R5 */
+                                      virt_to_abs(rblock),     /* R6 */
+                                      0, 0, 0, 0);             /* R7-R12 */
 }
index faa191d23b8614f095bb0a39bc93673304cb330d..f3628c803567674c4b5650a9d71389b5aea0290e 100644 (file)
@@ -93,7 +93,7 @@ static inline void hcp_epas_ctor(struct h_epas *epas, u64 paddr_kernel,
 static inline void hcp_epas_dtor(struct h_epas *epas)
 {
        if (epas->kernel.addr)
-               iounmap((void __iomem*)((u64)epas->kernel.addr & PAGE_MASK));
+               iounmap((void __iomem *)((u64)epas->kernel.addr & PAGE_MASK));
 
        epas->user.addr = 0;
        epas->kernel.addr = 0;
@@ -388,23 +388,23 @@ u64 ehea_h_modify_ehea_qp(const u64 adapter_handle,
                          const u64 qp_handle,
                          const u64 sel_mask,
                          void *cb_addr,
-                         u64 * inv_attr_id,
-                         u64 * proc_mask, u16 * out_swr, u16 * out_rwr);
+                         u64 *inv_attr_id,
+                         u64 *proc_mask, u16 *out_swr, u16 *out_rwr);
 
 u64 ehea_h_alloc_resource_eq(const u64 adapter_handle,
-                            struct ehea_eq_attr *eq_attr, u64 * eq_handle);
+                            struct ehea_eq_attr *eq_attr, u64 *eq_handle);
 
 u64 ehea_h_alloc_resource_cq(const u64 adapter_handle,
                             struct ehea_cq_attr *cq_attr,
-                            u64 * cq_handle, struct h_epas *epas);
+                            u64 *cq_handle, struct h_epas *epas);
 
 u64 ehea_h_alloc_resource_qp(const u64 adapter_handle,
                             struct ehea_qp_init_attr *init_attr,
                             const u32 pd,
-                            u64 * qp_handle, struct h_epas *h_epas);
+                            u64 *qp_handle, struct h_epas *h_epas);
 
-#define H_REG_RPAGE_PAGE_SIZE          EHEA_BMASK_IBM(48,55)
-#define H_REG_RPAGE_QT                 EHEA_BMASK_IBM(62,63)
+#define H_REG_RPAGE_PAGE_SIZE          EHEA_BMASK_IBM(48, 55)
+#define H_REG_RPAGE_QT                 EHEA_BMASK_IBM(62, 63)
 
 u64 ehea_h_register_rpage(const u64 adapter_handle,
                          const u8 pagesize,
@@ -426,7 +426,7 @@ u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle,
 
 u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr,
                             const u64 length, const u32 access_ctrl,
-                            const u32 pd, u64 * mr_handle, u32 * lkey);
+                            const u32 pd, u64 *mr_handle, u32 *lkey);
 
 u64 ehea_h_register_rpage_mr(const u64 adapter_handle, const u64 mr_handle,
                             const u8 pagesize, const u8 queue_type,
@@ -439,8 +439,8 @@ u64 ehea_h_register_smr(const u64 adapter_handle, const u64 orig_mr_handle,
 u64 ehea_h_query_ehea(const u64 adapter_handle, void *cb_addr);
 
 /* output param R5 */
-#define H_MEHEAPORT_CAT                EHEA_BMASK_IBM(40,47)
-#define H_MEHEAPORT_PN         EHEA_BMASK_IBM(48,63)
+#define H_MEHEAPORT_CAT                EHEA_BMASK_IBM(40, 47)
+#define H_MEHEAPORT_PN         EHEA_BMASK_IBM(48, 63)
 
 u64 ehea_h_query_ehea_port(const u64 adapter_handle, const u16 port_num,
                           const u8 cb_cat, const u64 select_mask,
index 83b76432b41a8cc6c299ad3530b4e4bd98b5ac2a..d522e905f460585364a659d8f8cfb2c11d818d14 100644 (file)
@@ -33,8 +33,6 @@
 
 
 struct ehea_busmap ehea_bmap = { 0, 0, NULL };
-extern u64 ehea_driver_flags;
-extern struct work_struct ehea_rereg_mr_task;
 
 
 static void *hw_qpageit_get_inc(struct hw_queue *queue)
@@ -65,7 +63,7 @@ static int hw_queue_ctor(struct hw_queue *queue, const u32 nr_of_pages,
        }
 
        queue->queue_length = nr_of_pages * pagesize;
-       queue->queue_pages = kmalloc(nr_of_pages * sizeof(void*), GFP_KERNEL);
+       queue->queue_pages = kmalloc(nr_of_pages * sizeof(void *), GFP_KERNEL);
        if (!queue->queue_pages) {
                ehea_error("no mem for queue_pages");
                return -ENOMEM;
@@ -78,11 +76,11 @@ static int hw_queue_ctor(struct hw_queue *queue, const u32 nr_of_pages,
         */
        i = 0;
        while (i < nr_of_pages) {
-               u8 *kpage = (u8*)get_zeroed_page(GFP_KERNEL);
+               u8 *kpage = (u8 *)get_zeroed_page(GFP_KERNEL);
                if (!kpage)
                        goto out_nomem;
                for (k = 0; k < pages_per_kpage && i < nr_of_pages; k++) {
-                       (queue->queue_pages)[i] = (struct ehea_page*)kpage;
+                       (queue->queue_pages)[i] = (struct ehea_page *)kpage;
                        kpage += pagesize;
                        i++;
                }
@@ -235,8 +233,8 @@ int ehea_destroy_cq(struct ehea_cq *cq)
                return 0;
 
        hcp_epas_dtor(&cq->epas);
-
-       if ((hret = ehea_destroy_cq_res(cq, NORMAL_FREE)) == H_R_STATE) {
+       hret = ehea_destroy_cq_res(cq, NORMAL_FREE);
+       if (hret == H_R_STATE) {
                ehea_error_data(cq->adapter, cq->fw_handle);
                hret = ehea_destroy_cq_res(cq, FORCE_FREE);
        }
@@ -301,13 +299,13 @@ struct ehea_eq *ehea_create_eq(struct ehea_adapter *adapter,
                if (i == (eq->attr.nr_pages - 1)) {
                        /* last page */
                        vpage = hw_qpageit_get_inc(&eq->hw_queue);
-                       if ((hret != H_SUCCESS) || (vpage)) {
+                       if ((hret != H_SUCCESS) || (vpage))
                                goto out_kill_hwq;
-                       }
+
                } else {
-                       if ((hret != H_PAGE_REGISTERED) || (!vpage)) {
+                       if ((hret != H_PAGE_REGISTERED) || (!vpage))
                                goto out_kill_hwq;
-                       }
+
                }
        }
 
@@ -331,7 +329,7 @@ struct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq)
        unsigned long flags;
 
        spin_lock_irqsave(&eq->spinlock, flags);
-       eqe = (struct ehea_eqe*)hw_eqit_eq_get_inc_valid(&eq->hw_queue);
+       eqe = (struct ehea_eqe *)hw_eqit_eq_get_inc_valid(&eq->hw_queue);
        spin_unlock_irqrestore(&eq->spinlock, flags);
 
        return eqe;
@@ -364,7 +362,8 @@ int ehea_destroy_eq(struct ehea_eq *eq)
 
        hcp_epas_dtor(&eq->epas);
 
-       if ((hret = ehea_destroy_eq_res(eq, NORMAL_FREE)) == H_R_STATE) {
+       hret = ehea_destroy_eq_res(eq, NORMAL_FREE);
+       if (hret == H_R_STATE) {
                ehea_error_data(eq->adapter, eq->fw_handle);
                hret = ehea_destroy_eq_res(eq, FORCE_FREE);
        }
@@ -546,7 +545,8 @@ int ehea_destroy_qp(struct ehea_qp *qp)
 
        hcp_epas_dtor(&qp->epas);
 
-       if ((hret = ehea_destroy_qp_res(qp, NORMAL_FREE)) == H_R_STATE) {
+       hret = ehea_destroy_qp_res(qp, NORMAL_FREE);
+       if (hret == H_R_STATE) {
                ehea_error_data(qp->adapter, qp->fw_handle);
                hret = ehea_destroy_qp_res(qp, FORCE_FREE);
        }
@@ -559,7 +559,7 @@ int ehea_destroy_qp(struct ehea_qp *qp)
        return 0;
 }
 
-int ehea_create_busmap( void )
+int ehea_create_busmap(void)
 {
        u64 vaddr = EHEA_BUSMAP_START;
        unsigned long high_section_index = 0;
@@ -595,7 +595,7 @@ int ehea_create_busmap( void )
        return 0;
 }
 
-void ehea_destroy_busmap( void )
+void ehea_destroy_busmap(void)
 {
        vfree(ehea_bmap.vaddr);
 }
index bc62d389c166578fe179567968009bc8b6752b60..0bb6f92fa2f8ed7743c07dd883d67bfcb7e74b6e 100644 (file)
@@ -41,8 +41,8 @@
 #define EHEA_SECTSIZE          (1UL << 24)
 #define EHEA_PAGES_PER_SECTION (EHEA_SECTSIZE >> EHEA_PAGESHIFT)
 
-#if (1UL << SECTION_SIZE_BITS) < EHEA_SECTSIZE
-#error eHEA module can't work if kernel sectionsize < ehea sectionsize
+#if ((1UL << SECTION_SIZE_BITS) < EHEA_SECTSIZE)
+#error eHEA module cannot work if kernel sectionsize < ehea sectionsize
 #endif
 
 /* Some abbreviations used here:
@@ -188,8 +188,8 @@ struct ehea_eqe {
        u64 entry;
 };
 
-#define ERROR_DATA_LENGTH  EHEA_BMASK_IBM(52,63)
-#define ERROR_DATA_TYPE    EHEA_BMASK_IBM(0,7)
+#define ERROR_DATA_LENGTH  EHEA_BMASK_IBM(52, 63)
+#define ERROR_DATA_TYPE    EHEA_BMASK_IBM(0, 7)
 
 static inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset)
 {
@@ -279,7 +279,7 @@ static inline void *hw_qeit_eq_get_inc(struct hw_queue *queue)
 static inline void *hw_eqit_eq_get_inc_valid(struct hw_queue *queue)
 {
        void *retvalue = hw_qeit_get(queue);
-       u32 qe = *(u8*)retvalue;
+       u32 qe = *(u8 *)retvalue;
        if ((qe >> 7) == (queue->toggle_state & 1))
                hw_qeit_eq_get_inc(queue);
        else
@@ -364,7 +364,7 @@ struct ehea_cq *ehea_create_cq(struct ehea_adapter *adapter, int cqe,
 
 int ehea_destroy_cq(struct ehea_cq *cq);
 
-struct ehea_qp *ehea_create_qp(struct ehea_adapter * adapter, u32 pd,
+struct ehea_qp *ehea_create_qp(struct ehea_adapter *adapter, u32 pd,
                               struct ehea_qp_init_attr *init_attr);
 
 int ehea_destroy_qp(struct ehea_qp *qp);
@@ -378,8 +378,8 @@ int ehea_rem_mr(struct ehea_mr *mr);
 
 void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle);
 
-int ehea_create_busmap( void );
-void ehea_destroy_busmap( void );
+int ehea_create_busmap(void);
+void ehea_destroy_busmap(void);
 u64 ehea_map_vaddr(void *caddr);
 
 #endif /* __EHEA_QMR_H__ */
index 7667a62ac31f33c822c03f6ad11619d54e91d7ac..d4843d014bc90752483711708b414cc0b804dd5d 100644 (file)
@@ -13,7 +13,7 @@
  * Copyright (C) 2004 Andrew de Quincey (wol support)
  * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane
  *             IRQ rate fixes, bigendian fixes, cleanups, verification)
- * Copyright (c) 2004,5,6 NVIDIA Corporation
+ * Copyright (c) 2004,2005,2006,2007,2008 NVIDIA Corporation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -226,7 +226,7 @@ enum {
 #define NVREG_MISC1_HD         0x02
 #define NVREG_MISC1_FORCE      0x3b0f3c
 
-       NvRegMacReset = 0x3c,
+       NvRegMacReset = 0x34,
 #define NVREG_MAC_RESET_ASSERT 0x0F3
        NvRegTransmitterControl = 0x084,
 #define NVREG_XMITCTL_START    0x01
@@ -277,7 +277,9 @@ enum {
 #define NVREG_MCASTADDRA_FORCE 0x01
        NvRegMulticastAddrB = 0xB4,
        NvRegMulticastMaskA = 0xB8,
+#define NVREG_MCASTMASKA_NONE          0xffffffff
        NvRegMulticastMaskB = 0xBC,
+#define NVREG_MCASTMASKB_NONE          0xffff
 
        NvRegPhyInterface = 0xC0,
 #define PHY_RGMII              0x10000000
@@ -316,13 +318,13 @@ enum {
        NvRegTxRingPhysAddrHigh = 0x148,
        NvRegRxRingPhysAddrHigh = 0x14C,
        NvRegTxPauseFrame = 0x170,
-#define NVREG_TX_PAUSEFRAME_DISABLE    0x1ff0080
-#define NVREG_TX_PAUSEFRAME_ENABLE     0x0c00030
+#define NVREG_TX_PAUSEFRAME_DISABLE    0x01ff0080
+#define NVREG_TX_PAUSEFRAME_ENABLE     0x01800010
        NvRegMIIStatus = 0x180,
 #define NVREG_MIISTAT_ERROR            0x0001
 #define NVREG_MIISTAT_LINKCHANGE       0x0008
-#define NVREG_MIISTAT_MASK             0x000f
-#define NVREG_MIISTAT_MASK2            0x000f
+#define NVREG_MIISTAT_MASK_RW          0x0007
+#define NVREG_MIISTAT_MASK_ALL         0x000f
        NvRegMIIMask = 0x184,
 #define NVREG_MII_LINKCHANGE           0x0008
 
@@ -471,9 +473,9 @@ union ring_type {
 #define NV_RX_AVAIL            (1<<31)
 
 #define NV_RX2_CHECKSUMMASK    (0x1C000000)
-#define NV_RX2_CHECKSUMOK1     (0x10000000)
-#define NV_RX2_CHECKSUMOK2     (0x14000000)
-#define NV_RX2_CHECKSUMOK3     (0x18000000)
+#define NV_RX2_CHECKSUM_IP     (0x10000000)
+#define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
+#define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
 #define NV_RX2_DESCRIPTORVALID (1<<29)
 #define NV_RX2_SUBSTRACT1      (1<<25)
 #define NV_RX2_ERROR1          (1<<18)
@@ -622,6 +624,9 @@ union ring_type {
 #define NV_MSI_X_VECTOR_TX    0x1
 #define NV_MSI_X_VECTOR_OTHER 0x2
 
+#define NV_RESTART_TX         0x1
+#define NV_RESTART_RX         0x2
+
 /* statistics */
 struct nv_ethtool_str {
        char name[ETH_GSTRING_LEN];
@@ -1059,7 +1064,7 @@ static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
        u32 reg;
        int retval;
 
-       writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
+       writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
 
        reg = readl(base + NvRegMIIControl);
        if (reg & NVREG_MIICTL_INUSE) {
@@ -1430,16 +1435,30 @@ static void nv_mac_reset(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
        u8 __iomem *base = get_hwbase(dev);
+       u32 temp1, temp2, temp3;
 
        dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
+
        writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
        pci_push(base);
+
+       /* save registers since they will be cleared on reset */
+       temp1 = readl(base + NvRegMacAddrA);
+       temp2 = readl(base + NvRegMacAddrB);
+       temp3 = readl(base + NvRegTransmitPoll);
+
        writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
        pci_push(base);
        udelay(NV_MAC_RESET_DELAY);
        writel(0, base + NvRegMacReset);
        pci_push(base);
        udelay(NV_MAC_RESET_DELAY);
+
+       /* restore saved registers */
+       writel(temp1, base + NvRegMacAddrA);
+       writel(temp2, base + NvRegMacAddrB);
+       writel(temp3, base + NvRegTransmitPoll);
+
        writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
        pci_push(base);
 }
@@ -2375,14 +2394,9 @@ static int nv_rx_process(struct net_device *dev, int limit)
                                                goto next_pkt;
                                        }
                                }
-                               if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK2)/*ip and tcp */ {
+                               if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
+                                   ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP))   /*ip and udp */
                                        skb->ip_summed = CHECKSUM_UNNECESSARY;
-                               } else {
-                                       if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK1 ||
-                                           (flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK3) {
-                                               skb->ip_summed = CHECKSUM_UNNECESSARY;
-                                       }
-                               }
                        } else {
                                dev_kfree_skb(skb);
                                goto next_pkt;
@@ -2474,14 +2488,9 @@ static int nv_rx_process_optimized(struct net_device *dev, int limit)
                                }
                        }
 
-                       if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK2)/*ip and tcp */ {
+                       if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
+                           ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP))   /*ip and udp */
                                skb->ip_summed = CHECKSUM_UNNECESSARY;
-                       } else {
-                               if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK1 ||
-                                   (flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK3) {
-                                       skb->ip_summed = CHECKSUM_UNNECESSARY;
-                               }
-                       }
 
                        /* got a valid packet - forward it to the network core */
                        skb_put(skb, len);
@@ -2703,6 +2712,9 @@ static void nv_set_multicast(struct net_device *dev)
                        addr[1] = alwaysOn[1];
                        mask[0] = alwaysOn[0] | alwaysOff[0];
                        mask[1] = alwaysOn[1] | alwaysOff[1];
+               } else {
+                       mask[0] = NVREG_MCASTMASKA_NONE;
+                       mask[1] = NVREG_MCASTMASKB_NONE;
                }
        }
        addr[0] |= NVREG_MCASTADDRA_FORCE;
@@ -2772,6 +2784,7 @@ static int nv_update_linkspeed(struct net_device *dev)
        int mii_status;
        int retval = 0;
        u32 control_1000, status_1000, phyreg, pause_flags, txreg;
+       u32 txrxFlags = 0;
 
        /* BMSR_LSTATUS is latched, read it twice:
         * we want the current value.
@@ -2867,6 +2880,16 @@ set_speed:
        np->duplex = newdup;
        np->linkspeed = newls;
 
+       /* The transmitter and receiver must be restarted for safe update */
+       if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
+               txrxFlags |= NV_RESTART_TX;
+               nv_stop_tx(dev);
+       }
+       if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
+               txrxFlags |= NV_RESTART_RX;
+               nv_stop_rx(dev);
+       }
+
        if (np->gigabit == PHY_GIGABIT) {
                phyreg = readl(base + NvRegRandomSeed);
                phyreg &= ~(0x3FF00);
@@ -2955,6 +2978,11 @@ set_speed:
        }
        nv_update_pause(dev, pause_flags);
 
+       if (txrxFlags & NV_RESTART_TX)
+               nv_start_tx(dev);
+       if (txrxFlags & NV_RESTART_RX)
+               nv_start_rx(dev);
+
        return retval;
 }
 
@@ -2981,7 +3009,7 @@ static void nv_link_irq(struct net_device *dev)
        u32 miistat;
 
        miistat = readl(base + NvRegMIIStatus);
-       writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
+       writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
        dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
 
        if (miistat & (NVREG_MIISTAT_LINKCHANGE))
@@ -4813,8 +4841,8 @@ static int nv_open(struct net_device *dev)
                nv_mac_reset(dev);
        writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
        writel(0, base + NvRegMulticastAddrB);
-       writel(0, base + NvRegMulticastMaskA);
-       writel(0, base + NvRegMulticastMaskB);
+       writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
+       writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
        writel(0, base + NvRegPacketFilterFlags);
 
        writel(0, base + NvRegTransmitterControl);
@@ -4856,7 +4884,7 @@ static int nv_open(struct net_device *dev)
 
        writel(0, base + NvRegMIIMask);
        writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
-       writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
+       writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
 
        writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
        writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
@@ -4894,7 +4922,7 @@ static int nv_open(struct net_device *dev)
 
        nv_disable_hw_interrupts(dev, np->irqmask);
        pci_push(base);
-       writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
+       writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
        writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
        pci_push(base);
 
@@ -4908,8 +4936,8 @@ static int nv_open(struct net_device *dev)
        spin_lock_irq(&np->lock);
        writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
        writel(0, base + NvRegMulticastAddrB);
-       writel(0, base + NvRegMulticastMaskA);
-       writel(0, base + NvRegMulticastMaskB);
+       writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
+       writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
        writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
        /* One manual link speed update: Interrupts are enabled, future link
         * speed changes cause interrupts and are handled by nv_link_irq().
@@ -4917,7 +4945,7 @@ static int nv_open(struct net_device *dev)
        {
                u32 miistat;
                miistat = readl(base + NvRegMIIStatus);
-               writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
+               writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
                dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
        }
        /* set linkspeed to invalid value, thus force nv_update_linkspeed
@@ -5285,7 +5313,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
                phystate &= ~NVREG_ADAPTCTL_RUNNING;
                writel(phystate, base + NvRegAdapterControl);
        }
-       writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
+       writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
 
        if (id->driver_data & DEV_HAS_MGMT_UNIT) {
                /* management unit running on the mac? */
@@ -5603,35 +5631,35 @@ static struct pci_device_id pci_tbl[] = {
        },
        {       /* MCP77 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_32),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {       /* MCP77 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_33),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {       /* MCP77 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_34),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {       /* MCP77 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_35),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {       /* MCP79 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_36),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {       /* MCP79 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_37),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {       /* MCP79 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_38),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {       /* MCP79 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_39),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
        },
        {0,},
 };
index 100bf410bf5fdf655446798073c53dfed60929ff..6a647d95e6eafbba7a33547aff6af936b0a6218f 100644 (file)
@@ -127,7 +127,7 @@ int gfar_mdio_reset(struct mii_bus *bus)
        struct gfar_mii __iomem *regs = (void __iomem *)bus->priv;
        unsigned int timeout = PHY_INIT_TIMEOUT;
 
-       spin_lock_bh(&bus->mdio_lock);
+       mutex_lock(&bus->mdio_lock);
 
        /* Reset the management interface */
        gfar_write(&regs->miimcfg, MIIMCFG_RESET);
@@ -140,7 +140,7 @@ int gfar_mdio_reset(struct mii_bus *bus)
                        timeout--)
                cpu_relax();
 
-       spin_unlock_bh(&bus->mdio_lock);
+       mutex_unlock(&bus->mdio_lock);
 
        if(timeout <= 0) {
                printk(KERN_ERR "%s: The MII Bus is stuck!\n",
index 11b83dae00ac762f8732ccefaf92ab92716a9959..e04bf992644197f4eb211e1ff42122cb7e2fbcb2 100644 (file)
@@ -262,8 +262,8 @@ static void tm_isr(struct scc_priv *priv);
 
 static int io[MAX_NUM_DEVS] __initdata = { 0, };
 
-/* Beware! hw[] is also used in cleanup_module(). */
-static struct scc_hardware hw[NUM_TYPES] __initdata_or_module = HARDWARE;
+/* Beware! hw[] is also used in dmascc_exit(). */
+static struct scc_hardware hw[NUM_TYPES] = HARDWARE;
 
 
 /* Global variables */
index 46e2c52c7862f436248d85942e6c4cb418b16023..95e3464068db540c1d2a3f530960586ee2d0cfe0 100644 (file)
@@ -901,12 +901,12 @@ static short ibmlana_adapter_ids[] __initdata = {
        0x0000
 };
 
-static char *ibmlana_adapter_names[] __initdata = {
+static char *ibmlana_adapter_names[] __devinitdata = {
        "IBM LAN Adapter/A",
        NULL
 };
 
-static int ibmlana_init_one(struct device *kdev)
+static int __devinit ibmlana_init_one(struct device *kdev)
 {
        struct mca_device *mdev = to_mca_device(kdev);
        struct net_device *dev;
index f3c144d5d72fb5606d3c621ef3bc1b6c22660900..d4eb8e2d87202b681cff99ff6cd8ec1eec1f3664 100644 (file)
@@ -438,7 +438,6 @@ static int igb_request_irq(struct igb_adapter *adapter)
        if (adapter->msix_entries) {
                err = igb_request_msix(adapter);
                if (!err) {
-                       struct e1000_hw *hw = &adapter->hw;
                        /* enable IAM, auto-mask,
                         * DO NOT USE EIAME or IAME in legacy mode */
                        wr32(E1000_IAM, IMS_ENABLE_MASK);
index e489c6661ee8b6372dd63860cdf039f0c7389c9e..07876578887fb66661cdbcfb925aa2ba29619c28 100644 (file)
@@ -173,13 +173,13 @@ struct st_fifo {
 
 struct frame_cb {
        void *start; /* Start of frame in DMA mem */
-       int len;     /* Lenght of frame in DMA mem */
+       int len;     /* Length of frame in DMA mem */
 };
 
 struct tx_fifo {
        struct frame_cb queue[MAX_TX_WINDOW]; /* Info about frames in queue */
        int             ptr;                  /* Currently being sent */
-       int             len;                  /* Lenght of queue */
+       int             len;                  /* Length of queue */
        int             free;                 /* Next free slot */
        void           *tail;                 /* Next free start in DMA mem */
 };
index bbdc97ff83cae11df92933f9cb7cb4b55cef2f5e..29398a4f73fd2cd004005846076f4bef1137470d 100644 (file)
@@ -231,13 +231,13 @@ struct st_fifo {
 
 struct frame_cb {
        void *start; /* Start of frame in DMA mem */
-       int len;     /* Lenght of frame in DMA mem */
+       int len;     /* Length of frame in DMA mem */
 };
 
 struct tx_fifo {
        struct frame_cb queue[MAX_TX_WINDOW]; /* Info about frames in queue */
        int             ptr;                  /* Currently being sent */
-       int             len;                  /* Lenght of queue */
+       int             len;                  /* Length of queue */
        int             free;                 /* Next free slot */
        void           *tail;                 /* Next free start in DMA mem */
 };
index 204b1b34ffc7a69a7b7908049529018e7a93026b..9d012f0dbd3089594d7d38cd1845886d06373d83 100644 (file)
@@ -54,13 +54,13 @@ struct st_fifo {
 
 struct frame_cb {
        void *start;            /* Start of frame in DMA mem */
-       int len;                /* Lenght of frame in DMA mem */
+       int len;                /* Length of frame in DMA mem */
 };
 
 struct tx_fifo {
        struct frame_cb queue[MAX_TX_WINDOW + 2];       /* Info about frames in queue */
        int ptr;                /* Currently being sent */
-       int len;                /* Lenght of queue */
+       int len;                /* Length of queue */
        int free;               /* Next free slot */
        void *tail;             /* Next free start in DMA mem */
 };
index 419861cbc65ecb23ae1172b6559b402bc0caa8d6..58d3bb622da6eabf5e7b5018c03fa83809019205 100644 (file)
@@ -1020,7 +1020,7 @@ static const struct ethtool_ops ops = {
        .get_link = veth_get_link,
 };
 
-static struct net_device * __init veth_probe_one(int vlan,
+static struct net_device *veth_probe_one(int vlan,
                struct vio_dev *vio_dev)
 {
        struct net_device *dev;
index a021a6e72641ef179b5e09764a9ad3fa59f2cebe..d0bf206632ca60754edbeb80977e4b359c8ff731 100644 (file)
@@ -136,8 +136,6 @@ struct ixgbe_ring {
        u16 head;
        u16 tail;
 
-       /* To protect race between sender and clean_tx_irq */
-       spinlock_t tx_lock;
 
        struct ixgbe_queue_stats stats;
 
@@ -174,7 +172,6 @@ struct ixgbe_adapter {
        struct vlan_group *vlgrp;
        u16 bd_number;
        u16 rx_buf_len;
-       atomic_t irq_sem;
        struct work_struct reset_task;
 
        /* TX */
@@ -244,6 +241,7 @@ extern const char ixgbe_driver_version[];
 
 extern int ixgbe_up(struct ixgbe_adapter *adapter);
 extern void ixgbe_down(struct ixgbe_adapter *adapter);
+extern void ixgbe_reinit_locked(struct ixgbe_adapter *adapter);
 extern void ixgbe_reset(struct ixgbe_adapter *adapter);
 extern void ixgbe_update_stats(struct ixgbe_adapter *adapter);
 extern void ixgbe_set_ethtool_ops(struct net_device *netdev);
index 36353447716ddeedbe75095a7f3ee1c96f1ebd03..a119cbd8dbb8b2aad03186d12a8e2150f3752a1b 100644 (file)
@@ -103,21 +103,41 @@ static int ixgbe_get_settings(struct net_device *netdev,
                              struct ethtool_cmd *ecmd)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
+       struct ixgbe_hw *hw = &adapter->hw;
+       u32 link_speed = 0;
+       bool link_up;
 
-       ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
-       ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
-       ecmd->port = PORT_FIBRE;
+       ecmd->supported = SUPPORTED_10000baseT_Full;
+       ecmd->autoneg = AUTONEG_ENABLE;
        ecmd->transceiver = XCVR_EXTERNAL;
+       if (hw->phy.media_type == ixgbe_media_type_copper) {
+               ecmd->supported |= (SUPPORTED_1000baseT_Full |
+                                   SUPPORTED_TP | SUPPORTED_Autoneg);
+
+               ecmd->advertising = (ADVERTISED_TP | ADVERTISED_Autoneg);
+               if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
+                       ecmd->advertising |= ADVERTISED_10000baseT_Full;
+               if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
+                       ecmd->advertising |= ADVERTISED_1000baseT_Full;
+
+               ecmd->port = PORT_TP;
+       } else {
+               ecmd->supported |= SUPPORTED_FIBRE;
+               ecmd->advertising = (ADVERTISED_10000baseT_Full |
+                                    ADVERTISED_FIBRE);
+               ecmd->port = PORT_FIBRE;
+       }
 
-       if (netif_carrier_ok(adapter->netdev)) {
-               ecmd->speed = SPEED_10000;
+       adapter->hw.mac.ops.check_link(hw, &(link_speed), &link_up);
+       if (link_up) {
+               ecmd->speed = (link_speed == IXGBE_LINK_SPEED_10GB_FULL) ?
+                               SPEED_10000 : SPEED_1000;
                ecmd->duplex = DUPLEX_FULL;
        } else {
                ecmd->speed = -1;
                ecmd->duplex = -1;
        }
 
-       ecmd->autoneg = AUTONEG_DISABLE;
        return 0;
 }
 
@@ -125,17 +145,17 @@ static int ixgbe_set_settings(struct net_device *netdev,
                              struct ethtool_cmd *ecmd)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
+       struct ixgbe_hw *hw = &adapter->hw;
 
-       if (ecmd->autoneg == AUTONEG_ENABLE ||
-           ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
-               return -EINVAL;
-
-       if (netif_running(adapter->netdev)) {
-               ixgbe_down(adapter);
-               ixgbe_reset(adapter);
-               ixgbe_up(adapter);
-       } else {
-               ixgbe_reset(adapter);
+       switch (hw->phy.media_type) {
+       case ixgbe_media_type_fiber:
+               if ((ecmd->autoneg == AUTONEG_ENABLE) ||
+                   (ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL))
+                       return -EINVAL;
+               /* in this case we currently only support 10Gb/FULL */
+               break;
+       default:
+               break;
        }
 
        return 0;
@@ -147,7 +167,7 @@ static void ixgbe_get_pauseparam(struct net_device *netdev,
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
 
-       pause->autoneg = AUTONEG_DISABLE;
+       pause->autoneg = (hw->fc.type == ixgbe_fc_full ? 1 : 0);
 
        if (hw->fc.type == ixgbe_fc_rx_pause) {
                pause->rx_pause = 1;
@@ -165,10 +185,8 @@ static int ixgbe_set_pauseparam(struct net_device *netdev,
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
 
-       if (pause->autoneg == AUTONEG_ENABLE)
-               return -EINVAL;
-
-       if (pause->rx_pause && pause->tx_pause)
+       if ((pause->autoneg == AUTONEG_ENABLE) ||
+           (pause->rx_pause && pause->tx_pause))
                hw->fc.type = ixgbe_fc_full;
        else if (pause->rx_pause && !pause->tx_pause)
                hw->fc.type = ixgbe_fc_rx_pause;
@@ -176,15 +194,15 @@ static int ixgbe_set_pauseparam(struct net_device *netdev,
                hw->fc.type = ixgbe_fc_tx_pause;
        else if (!pause->rx_pause && !pause->tx_pause)
                hw->fc.type = ixgbe_fc_none;
+       else
+               return -EINVAL;
 
        hw->fc.original_type = hw->fc.type;
 
-       if (netif_running(adapter->netdev)) {
-               ixgbe_down(adapter);
-               ixgbe_up(adapter);
-       } else {
+       if (netif_running(netdev))
+               ixgbe_reinit_locked(adapter);
+       else
                ixgbe_reset(adapter);
-       }
 
        return 0;
 }
@@ -203,12 +221,10 @@ static int ixgbe_set_rx_csum(struct net_device *netdev, u32 data)
        else
                adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
 
-       if (netif_running(netdev)) {
-               ixgbe_down(adapter);
-               ixgbe_up(adapter);
-       } else {
+       if (netif_running(netdev))
+               ixgbe_reinit_locked(adapter);
+       else
                ixgbe_reset(adapter);
-       }
 
        return 0;
 }
@@ -662,7 +678,10 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
                return 0;
        }
 
-       if (netif_running(adapter->netdev))
+       while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
+               msleep(1);
+
+       if (netif_running(netdev))
                ixgbe_down(adapter);
 
        /*
@@ -733,6 +752,7 @@ err_setup:
        if (netif_running(adapter->netdev))
                ixgbe_up(adapter);
 
+       clear_bit(__IXGBE_RESETTING, &adapter->state);
        return err;
 }
 
@@ -820,11 +840,8 @@ static int ixgbe_nway_reset(struct net_device *netdev)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
 
-       if (netif_running(netdev)) {
-               ixgbe_down(adapter);
-               ixgbe_reset(adapter);
-               ixgbe_up(adapter);
-       }
+       if (netif_running(netdev))
+               ixgbe_reinit_locked(adapter);
 
        return 0;
 }
index 3732dd6c4b2a81fe5de5ed2883f51f082aa9b897..ead49e54f31b8fef4349d5ec551d537db5d87a27 100644 (file)
@@ -87,6 +87,25 @@ MODULE_VERSION(DRV_VERSION);
 
 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
 
+static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
+{
+       u32 ctrl_ext;
+
+       /* Let firmware take over control of h/w */
+       ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
+       IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
+                       ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
+}
+
+static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
+{
+       u32 ctrl_ext;
+
+       /* Let firmware know the driver has taken over */
+       ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
+       IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
+                       ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
+}
 
 #ifdef DEBUG
 /**
@@ -165,6 +184,15 @@ static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
        return false;
 }
 
+#define IXGBE_MAX_TXD_PWR      14
+#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
+
+/* Tx Descriptors needed, worst case */
+#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
+                        (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
+#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
+       MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1)   /* for context */
+
 /**
  * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  * @adapter: board private structure
@@ -177,18 +205,34 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
        struct ixgbe_tx_buffer *tx_buffer_info;
        unsigned int i, eop;
        bool cleaned = false;
-       int count = 0;
+       unsigned int total_tx_bytes = 0, total_tx_packets = 0;
 
        i = tx_ring->next_to_clean;
        eop = tx_ring->tx_buffer_info[i].next_to_watch;
        eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
        while (eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) {
-               for (cleaned = false; !cleaned;) {
+               cleaned = false;
+               while (!cleaned) {
                        tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
                        tx_buffer_info = &tx_ring->tx_buffer_info[i];
                        cleaned = (i == eop);
 
                        tx_ring->stats.bytes += tx_buffer_info->length;
+                       if (cleaned) {
+                               struct sk_buff *skb = tx_buffer_info->skb;
+#ifdef NETIF_F_TSO
+                               unsigned int segs, bytecount;
+                               segs = skb_shinfo(skb)->gso_segs ?: 1;
+                               /* multiply data chunks by size of headers */
+                               bytecount = ((segs - 1) * skb_headlen(skb)) +
+                                           skb->len;
+                               total_tx_packets += segs;
+                               total_tx_bytes += bytecount;
+#else
+                               total_tx_packets++;
+                               total_tx_bytes += skb->len;
+#endif
+                       }
                        ixgbe_unmap_and_free_tx_resource(adapter,
                                                         tx_buffer_info);
                        tx_desc->wb.status = 0;
@@ -204,29 +248,36 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
                eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
 
                /* weight of a sort for tx, avoid endless transmit cleanup */
-               if (count++ >= tx_ring->work_limit)
+               if (total_tx_packets >= tx_ring->work_limit)
                        break;
        }
 
        tx_ring->next_to_clean = i;
 
-#define TX_WAKE_THRESHOLD 32
-       spin_lock(&tx_ring->tx_lock);
-
-       if (cleaned && netif_carrier_ok(netdev) &&
-           (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD) &&
-           !test_bit(__IXGBE_DOWN, &adapter->state))
-               netif_wake_queue(netdev);
-
-       spin_unlock(&tx_ring->tx_lock);
+#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
+       if (total_tx_packets && netif_carrier_ok(netdev) &&
+           (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
+               /* Make sure that anybody stopping the queue after this
+                * sees the new next_to_clean.
+                */
+               smp_mb();
+               if (netif_queue_stopped(netdev) &&
+                   !test_bit(__IXGBE_DOWN, &adapter->state)) {
+                       netif_wake_queue(netdev);
+                       adapter->restart_queue++;
+               }
+       }
 
        if (adapter->detect_tx_hung)
                if (ixgbe_check_tx_hang(adapter, tx_ring, eop, eop_desc))
                        netif_stop_queue(netdev);
 
-       if (count >= tx_ring->work_limit)
+       if (total_tx_packets >= tx_ring->work_limit)
                IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->eims_value);
 
+       adapter->net_stats.tx_bytes += total_tx_bytes;
+       adapter->net_stats.tx_packets += total_tx_packets;
+       cleaned = total_tx_packets ? true : false;
        return cleaned;
 }
 
@@ -255,25 +306,40 @@ static void ixgbe_receive_skb(struct ixgbe_adapter *adapter,
        }
 }
 
+/**
+ * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
+ * @adapter: address of board private structure
+ * @status_err: hardware indication of status of receive
+ * @skb: skb currently being received and modified
+ **/
 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
                                         u32 status_err,
                                         struct sk_buff *skb)
 {
        skb->ip_summed = CHECKSUM_NONE;
 
-       /* Ignore Checksum bit is set */
+       /* Ignore Checksum bit is set, or rx csum disabled */
        if ((status_err & IXGBE_RXD_STAT_IXSM) ||
-                    !(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
+           !(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
                return;
-       /* TCP/UDP checksum error bit is set */
-       if (status_err & (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE)) {
-               /* let the stack verify checksum errors */
+
+       /* if IP and error */
+       if ((status_err & IXGBE_RXD_STAT_IPCS) &&
+           (status_err & IXGBE_RXDADV_ERR_IPE)) {
                adapter->hw_csum_rx_error++;
                return;
        }
+
+       if (!(status_err & IXGBE_RXD_STAT_L4CS))
+               return;
+
+       if (status_err & IXGBE_RXDADV_ERR_TCPE) {
+               adapter->hw_csum_rx_error++;
+               return;
+       }
+
        /* It must be a TCP or UDP packet with a valid checksum */
-       if (status_err & (IXGBE_RXD_STAT_L4CS | IXGBE_RXD_STAT_UDPCS))
-               skb->ip_summed = CHECKSUM_UNNECESSARY;
+       skb->ip_summed = CHECKSUM_UNNECESSARY;
        adapter->hw_csum_rx_good++;
 }
 
@@ -379,6 +445,7 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_adapter *adapter,
        u16 hdr_info, vlan_tag;
        bool is_vlan, cleaned = false;
        int cleaned_count = 0;
+       unsigned int total_rx_bytes = 0, total_rx_packets = 0;
 
        i = rx_ring->next_to_clean;
        upper_len = 0;
@@ -458,6 +525,11 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_adapter *adapter,
                }
 
                ixgbe_rx_checksum(adapter, staterr, skb);
+
+               /* probably a little skewed due to removing CRC */
+               total_rx_bytes += skb->len;
+               total_rx_packets++;
+
                skb->protocol = eth_type_trans(skb, netdev);
                ixgbe_receive_skb(adapter, skb, is_vlan, vlan_tag);
                netdev->last_rx = jiffies;
@@ -486,6 +558,9 @@ next_desc:
        if (cleaned_count)
                ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
 
+       adapter->net_stats.rx_bytes += total_rx_bytes;
+       adapter->net_stats.rx_packets += total_rx_packets;
+
        return cleaned;
 }
 
@@ -535,7 +610,9 @@ static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
                if (!test_bit(__IXGBE_DOWN, &adapter->state))
                        mod_timer(&adapter->watchdog_timer, jiffies);
        }
-       IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
+
+       if (!test_bit(__IXGBE_DOWN, &adapter->state))
+               IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
 
        return IRQ_HANDLED;
 }
@@ -713,7 +790,6 @@ static irqreturn_t ixgbe_intr(int irq, void *data)
        if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
                /* Disable interrupts and register for poll. The flush of the
                 * posted write is intentionally left out. */
-               atomic_inc(&adapter->irq_sem);
                IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
                __netif_rx_schedule(netdev, &adapter->napi);
        }
@@ -801,7 +877,6 @@ static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  **/
 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
 {
-       atomic_inc(&adapter->irq_sem);
        IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
        IXGBE_WRITE_FLUSH(&adapter->hw);
        synchronize_irq(adapter->pdev->irq);
@@ -813,15 +888,13 @@ static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  **/
 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
 {
-       if (atomic_dec_and_test(&adapter->irq_sem)) {
-               if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
-                       IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC,
-                                       (IXGBE_EIMS_ENABLE_MASK &
-                                        ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC)));
-               IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS,
-                               IXGBE_EIMS_ENABLE_MASK);
-               IXGBE_WRITE_FLUSH(&adapter->hw);
-       }
+       if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
+               IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC,
+                               (IXGBE_EIMS_ENABLE_MASK &
+                                ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC)));
+       IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS,
+                       IXGBE_EIMS_ENABLE_MASK);
+       IXGBE_WRITE_FLUSH(&adapter->hw);
 }
 
 /**
@@ -1040,7 +1113,8 @@ static void ixgbe_vlan_rx_register(struct net_device *netdev,
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
        u32 ctrl;
 
-       ixgbe_irq_disable(adapter);
+       if (!test_bit(__IXGBE_DOWN, &adapter->state))
+               ixgbe_irq_disable(adapter);
        adapter->vlgrp = grp;
 
        if (grp) {
@@ -1051,7 +1125,8 @@ static void ixgbe_vlan_rx_register(struct net_device *netdev,
                IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
        }
 
-       ixgbe_irq_enable(adapter);
+       if (!test_bit(__IXGBE_DOWN, &adapter->state))
+               ixgbe_irq_enable(adapter);
 }
 
 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
@@ -1066,9 +1141,13 @@ static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
 
-       ixgbe_irq_disable(adapter);
+       if (!test_bit(__IXGBE_DOWN, &adapter->state))
+               ixgbe_irq_disable(adapter);
+
        vlan_group_set_device(adapter->vlgrp, vid, NULL);
-       ixgbe_irq_enable(adapter);
+
+       if (!test_bit(__IXGBE_DOWN, &adapter->state))
+               ixgbe_irq_enable(adapter);
 
        /* remove VID from filter table */
        ixgbe_set_vfta(&adapter->hw, vid, 0, false);
@@ -1170,6 +1249,8 @@ static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
        u32 txdctl, rxdctl, mhadd;
        int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
 
+       ixgbe_get_hw_control(adapter);
+
        if (adapter->flags & (IXGBE_FLAG_MSIX_ENABLED |
                              IXGBE_FLAG_MSI_ENABLED)) {
                if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
@@ -1224,6 +1305,16 @@ static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
        return 0;
 }
 
+void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
+{
+       WARN_ON(in_interrupt());
+       while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
+               msleep(1);
+       ixgbe_down(adapter);
+       ixgbe_up(adapter);
+       clear_bit(__IXGBE_RESETTING, &adapter->state);
+}
+
 int ixgbe_up(struct ixgbe_adapter *adapter)
 {
        /* hardware has been reset, we need to reload some things */
@@ -1408,7 +1499,6 @@ void ixgbe_down(struct ixgbe_adapter *adapter)
        msleep(10);
 
        napi_disable(&adapter->napi);
-       atomic_set(&adapter->irq_sem, 0);
 
        ixgbe_irq_disable(adapter);
 
@@ -1447,6 +1537,8 @@ static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
        pci_enable_wake(pdev, PCI_D3hot, 0);
        pci_enable_wake(pdev, PCI_D3cold, 0);
 
+       ixgbe_release_hw_control(adapter);
+
        pci_disable_device(pdev);
 
        pci_set_power_state(pdev, pci_choose_state(pdev, state));
@@ -1481,7 +1573,8 @@ static int ixgbe_clean(struct napi_struct *napi, int budget)
        /* If budget not fully consumed, exit the polling mode */
        if (work_done < budget) {
                netif_rx_complete(netdev, napi);
-               ixgbe_irq_enable(adapter);
+               if (!test_bit(__IXGBE_DOWN, &adapter->state))
+                       ixgbe_irq_enable(adapter);
        }
 
        return work_done;
@@ -1506,8 +1599,7 @@ static void ixgbe_reset_task(struct work_struct *work)
 
        adapter->tx_timeout_count++;
 
-       ixgbe_down(adapter);
-       ixgbe_up(adapter);
+       ixgbe_reinit_locked(adapter);
 }
 
 /**
@@ -1590,7 +1682,6 @@ static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
                return -ENOMEM;
        }
 
-       atomic_set(&adapter->irq_sem, 1);
        set_bit(__IXGBE_DOWN, &adapter->state);
 
        return 0;
@@ -1634,7 +1725,6 @@ int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
        txdr->next_to_use = 0;
        txdr->next_to_clean = 0;
        txdr->work_limit = txdr->count;
-       spin_lock_init(&txdr->tx_lock);
 
        return 0;
 }
@@ -1828,10 +1918,8 @@ static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
 
        netdev->mtu = new_mtu;
 
-       if (netif_running(netdev)) {
-               ixgbe_down(adapter);
-               ixgbe_up(adapter);
-       }
+       if (netif_running(netdev))
+               ixgbe_reinit_locked(adapter);
 
        return 0;
 }
@@ -1852,14 +1940,8 @@ static int ixgbe_open(struct net_device *netdev)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
        int err;
-       u32 ctrl_ext;
        u32 num_rx_queues = adapter->num_rx_queues;
 
-       /* Let firmware know the driver has taken over */
-       ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
-       IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
-                       ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
-
 try_intr_reinit:
        /* allocate transmit descriptors */
        err = ixgbe_setup_all_tx_resources(adapter);
@@ -1910,6 +1992,7 @@ try_intr_reinit:
        return 0;
 
 err_up:
+       ixgbe_release_hw_control(adapter);
        ixgbe_free_irq(adapter);
 err_req_irq:
        ixgbe_free_all_rx_resources(adapter);
@@ -1935,7 +2018,6 @@ err_setup_tx:
 static int ixgbe_close(struct net_device *netdev)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
-       u32 ctrl_ext;
 
        ixgbe_down(adapter);
        ixgbe_free_irq(adapter);
@@ -1943,9 +2025,7 @@ static int ixgbe_close(struct net_device *netdev)
        ixgbe_free_all_tx_resources(adapter);
        ixgbe_free_all_rx_resources(adapter);
 
-       ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
-       IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
-                       ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
+       ixgbe_release_hw_control(adapter);
 
        return 0;
 }
@@ -1957,22 +2037,26 @@ static int ixgbe_close(struct net_device *netdev)
 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
 {
        struct ixgbe_hw *hw = &adapter->hw;
-       u64 good_rx, missed_rx, bprc;
+       u64 total_mpc = 0;
+       u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
 
        adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
-       good_rx = IXGBE_READ_REG(hw, IXGBE_GPRC);
-       missed_rx = IXGBE_READ_REG(hw, IXGBE_MPC(0));
-       missed_rx += IXGBE_READ_REG(hw, IXGBE_MPC(1));
-       missed_rx += IXGBE_READ_REG(hw, IXGBE_MPC(2));
-       missed_rx += IXGBE_READ_REG(hw, IXGBE_MPC(3));
-       missed_rx += IXGBE_READ_REG(hw, IXGBE_MPC(4));
-       missed_rx += IXGBE_READ_REG(hw, IXGBE_MPC(5));
-       missed_rx += IXGBE_READ_REG(hw, IXGBE_MPC(6));
-       missed_rx += IXGBE_READ_REG(hw, IXGBE_MPC(7));
-       adapter->stats.gprc += (good_rx - missed_rx);
-
-       adapter->stats.mpc[0] += missed_rx;
+       for (i = 0; i < 8; i++) {
+               /* for packet buffers not used, the register should read 0 */
+               mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
+               missed_rx += mpc;
+               adapter->stats.mpc[i] += mpc;
+               total_mpc += adapter->stats.mpc[i];
+               adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
+       }
+       adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
+       /* work around hardware counting issue */
+       adapter->stats.gprc -= missed_rx;
+
+       /* 82598 hardware only has a 32 bit counter in the high register */
        adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
+       adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
+       adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
        bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
        adapter->stats.bprc += bprc;
        adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
@@ -1984,35 +2068,37 @@ void ixgbe_update_stats(struct ixgbe_adapter *adapter)
        adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
        adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
        adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
-
        adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
        adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
-       adapter->stats.lxontxc += IXGBE_READ_REG(hw, IXGBE_LXONTXC);
        adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
-       adapter->stats.lxofftxc += IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
+       lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
+       adapter->stats.lxontxc += lxon;
+       lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
+       adapter->stats.lxofftxc += lxoff;
        adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
        adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
-       adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
-       adapter->stats.rnbc[0] += IXGBE_READ_REG(hw, IXGBE_RNBC(0));
+       adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
+       /*
+        * 82598 errata - tx of flow control packets is included in tx counters
+        */
+       xon_off_tot = lxon + lxoff;
+       adapter->stats.gptc -= xon_off_tot;
+       adapter->stats.mptc -= xon_off_tot;
+       adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
        adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
        adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
        adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
-       adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
        adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
        adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
+       adapter->stats.ptc64 -= xon_off_tot;
        adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
        adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
        adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
        adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
        adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
-       adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
        adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
 
        /* Fill out the OS statistics structure */
-       adapter->net_stats.rx_packets = adapter->stats.gprc;
-       adapter->net_stats.tx_packets = adapter->stats.gptc;
-       adapter->net_stats.rx_bytes = adapter->stats.gorc;
-       adapter->net_stats.tx_bytes = adapter->stats.gotc;
        adapter->net_stats.multicast = adapter->stats.mprc;
 
        /* Rx Errors */
@@ -2021,8 +2107,7 @@ void ixgbe_update_stats(struct ixgbe_adapter *adapter)
        adapter->net_stats.rx_dropped = 0;
        adapter->net_stats.rx_length_errors = adapter->stats.rlec;
        adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
-       adapter->net_stats.rx_missed_errors = adapter->stats.mpc[0];
-
+       adapter->net_stats.rx_missed_errors = total_mpc;
 }
 
 /**
@@ -2076,15 +2161,6 @@ static void ixgbe_watchdog(unsigned long data)
                          round_jiffies(jiffies + 2 * HZ));
 }
 
-#define IXGBE_MAX_TXD_PWR      14
-#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
-
-/* Tx Descriptors needed, worst case */
-#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
-                        (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
-#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
-       MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1)   /* for context */
-
 static int ixgbe_tso(struct ixgbe_adapter *adapter,
                         struct ixgbe_ring *tx_ring, struct sk_buff *skb,
                         u32 tx_flags, u8 *hdr_len)
@@ -2356,6 +2432,37 @@ static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
        writel(i, adapter->hw.hw_addr + tx_ring->tail);
 }
 
+static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
+                                struct ixgbe_ring *tx_ring, int size)
+{
+       struct ixgbe_adapter *adapter = netdev_priv(netdev);
+
+       netif_stop_queue(netdev);
+       /* Herbert's original patch had:
+        *  smp_mb__after_netif_stop_queue();
+        * but since that doesn't exist yet, just open code it. */
+       smp_mb();
+
+       /* We need to check again in a case another CPU has just
+        * made room available. */
+       if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
+               return -EBUSY;
+
+       /* A reprieve! - use start_queue because it doesn't call schedule */
+       netif_wake_queue(netdev);
+       ++adapter->restart_queue;
+       return 0;
+}
+
+static int ixgbe_maybe_stop_tx(struct net_device *netdev,
+                              struct ixgbe_ring *tx_ring, int size)
+{
+       if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
+               return 0;
+       return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
+}
+
+
 static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
@@ -2363,7 +2470,6 @@ static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        unsigned int len = skb->len;
        unsigned int first;
        unsigned int tx_flags = 0;
-       unsigned long flags = 0;
        u8 hdr_len;
        int tso;
        unsigned int mss = 0;
@@ -2389,14 +2495,10 @@ static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        for (f = 0; f < nr_frags; f++)
                count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
 
-       spin_lock_irqsave(&tx_ring->tx_lock, flags);
-       if (IXGBE_DESC_UNUSED(tx_ring) < (count + 2)) {
+       if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
                adapter->tx_busy++;
-               netif_stop_queue(netdev);
-               spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
                return NETDEV_TX_BUSY;
        }
-       spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
        if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
                tx_flags |= IXGBE_TX_FLAGS_VLAN;
                tx_flags |= (vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT);
@@ -2423,11 +2525,7 @@ static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 
        netdev->trans_start = jiffies;
 
-       spin_lock_irqsave(&tx_ring->tx_lock, flags);
-       /* Make sure there is space in the ring for the next send. */
-       if (IXGBE_DESC_UNUSED(tx_ring) < DESC_NEEDED)
-               netif_stop_queue(netdev);
-       spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
+       ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
 
        return NETDEV_TX_OK;
 }
@@ -2697,6 +2795,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
        return 0;
 
 err_register:
+       ixgbe_release_hw_control(adapter);
 err_hw_init:
 err_sw_init:
 err_eeprom:
@@ -2732,6 +2831,8 @@ static void __devexit ixgbe_remove(struct pci_dev *pdev)
 
        unregister_netdev(netdev);
 
+       ixgbe_release_hw_control(adapter);
+
        kfree(adapter->tx_ring);
        kfree(adapter->rx_ring);
 
index c429a5002dd6c3116b343d2ab7e1100314a70d87..0c5447dac03b4a483c8294fe2cfb3b23fab7f1e4 100644 (file)
@@ -148,7 +148,7 @@ static void __NS8390_init(struct net_device *dev, int startp);
  *
  *     "The author (me) didn't use spin_lock_irqsave because the slowness of the
  *     card means that approach caused horrible problems like losing serial data
- *     at 38400 baud on some chips. Rememeber many 8390 nics on PCI were ISA
+ *     at 38400 baud on some chips. Remember many 8390 nics on PCI were ISA
  *     chips with FPGA front ends.
  *     
  *     Ok the logic behind the 8390 is very simple:
index e10528ed90814b626751d5488e5bb26233bed360..81bf005ff280dd4b556c0c599a9670bc473c47bd 100644 (file)
@@ -1084,7 +1084,7 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        return phy_mii_ioctl(phydev, if_mii(rq), cmd);
 }
 
-static int __devinit macb_probe(struct platform_device *pdev)
+static int __init macb_probe(struct platform_device *pdev)
 {
        struct eth_platform_data *pdata;
        struct resource *regs;
@@ -1248,7 +1248,7 @@ err_out:
        return err;
 }
 
-static int __devexit macb_remove(struct platform_device *pdev)
+static int __exit macb_remove(struct platform_device *pdev)
 {
        struct net_device *dev;
        struct macb *bp;
@@ -1276,8 +1276,7 @@ static int __devexit macb_remove(struct platform_device *pdev)
 }
 
 static struct platform_driver macb_driver = {
-       .probe          = macb_probe,
-       .remove         = __devexit_p(macb_remove),
+       .remove         = __exit_p(macb_remove),
        .driver         = {
                .name           = "macb",
        },
@@ -1285,7 +1284,7 @@ static struct platform_driver macb_driver = {
 
 static int __init macb_init(void)
 {
-       return platform_driver_register(&macb_driver);
+       return platform_driver_probe(&macb_driver, macb_probe);
 }
 
 static void __exit macb_exit(void)
index aafc3ce59cbbd78206ee3121477aa16723bbeb82..6d343efb2717311c1049d4962e7ae9a1ca042653 100644 (file)
@@ -4,8 +4,6 @@
  * for more details.
  */
 
-#define DEBUG
-
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
 #include <asm/mips-boards/simint.h>
 
-#include "mipsnet.h"           /* actual device IO mapping */
+#define MIPSNET_VERSION "2007-11-17"
+
+/*
+ * Net status/control block as seen by sw in the core.
+ */
+struct mipsnet_regs {
+       /*
+        * Device info for probing, reads as MIPSNET%d where %d is some
+        * form of version.
+        */
+       u64 devId;              /*0x00 */
 
-#define MIPSNET_VERSION "2005-06-20"
+       /*
+        * read only busy flag.
+        * Set and cleared by the Net Device to indicate that an rx or a tx
+        * is in progress.
+        */
+       u32 busy;               /*0x08 */
 
-#define mipsnet_reg_address(dev, field) (dev->base_addr + field_offset(field))
+       /*
+        * Set by the Net Device.
+        * The device will set it once data has been received.
+        * The value is the number of bytes that should be read from
+        * rxDataBuffer.  The value will decrease till 0 until all the data
+        * from rxDataBuffer has been read.
+        */
+       u32 rxDataCount;        /*0x0c */
+#define MIPSNET_MAX_RXTX_DATACOUNT (1 << 16)
+
+       /*
+        * Settable from the MIPS core, cleared by the Net Device.
+        * The core should set the number of bytes it wants to send,
+        * then it should write those bytes of data to txDataBuffer.
+        * The device will clear txDataCount has been processed (not
+        * necessarily sent).
+        */
+       u32 txDataCount;        /*0x10 */
+
+       /*
+        * Interrupt control
+        *
+        * Used to clear the interrupted generated by this dev.
+        * Write a 1 to clear the interrupt. (except bit31).
+        *
+        * Bit0 is set if it was a tx-done interrupt.
+        * Bit1 is set when new rx-data is available.
+        *    Until this bit is cleared there will be no other RXs.
+        *
+        * Bit31 is used for testing, it clears after a read.
+        *    Writing 1 to this bit will cause an interrupt to be generated.
+        *    To clear the test interrupt, write 0 to this register.
+        */
+       u32 interruptControl;   /*0x14 */
+#define MIPSNET_INTCTL_TXDONE     (1u << 0)
+#define MIPSNET_INTCTL_RXDONE     (1u << 1)
+#define MIPSNET_INTCTL_TESTBIT    (1u << 31)
+
+       /*
+        * Readonly core-specific interrupt info for the device to signal
+        * the core. The meaning of the contents of this field might change.
+        */
+       /* XXX: the whole memIntf interrupt scheme is messy: the device
+        * should have no control what so ever of what VPE/register set is
+        * being used.
+        * The MemIntf should only expose interrupt lines, and something in
+        * the config should be responsible for the line<->core/vpe bindings.
+        */
+       u32 interruptInfo;      /*0x18 */
+
+       /*
+        * This is where the received data is read out.
+        * There is more data to read until rxDataReady is 0.
+        * Only 1 byte at this regs offset is used.
+        */
+       u32 rxDataBuffer;       /*0x1c */
+
+       /*
+        * This is where the data to transmit is written.
+        * Data should be written for the amount specified in the
+        * txDataCount register.
+        * Only 1 byte at this regs offset is used.
+        */
+       u32 txDataBuffer;       /*0x20 */
+};
+
+#define regaddr(dev, field) \
+  (dev->base_addr + offsetof(struct mipsnet_regs, field))
 
 static char mipsnet_string[] = "mipsnet";
 
@@ -29,32 +109,27 @@ static char mipsnet_string[] = "mipsnet";
 static int ioiocpy_frommipsnet(struct net_device *dev, unsigned char *kdata,
                        int len)
 {
-       uint32_t available_len = inl(mipsnet_reg_address(dev, rxDataCount));
-
-       if (available_len < len)
-               return -EFAULT;
-
        for (; len > 0; len--, kdata++)
-               *kdata = inb(mipsnet_reg_address(dev, rxDataBuffer));
+               *kdata = inb(regaddr(dev, rxDataBuffer));
 
-       return inl(mipsnet_reg_address(dev, rxDataCount));
+       return inl(regaddr(dev, rxDataCount));
 }
 
-static inline ssize_t mipsnet_put_todevice(struct net_device *dev,
+static inline void mipsnet_put_todevice(struct net_device *dev,
        struct sk_buff *skb)
 {
        int count_to_go = skb->len;
        char *buf_ptr = skb->data;
 
-       outl(skb->len, mipsnet_reg_address(dev, txDataCount));
+       outl(skb->len, regaddr(dev, txDataCount));
 
        for (; count_to_go; buf_ptr++, count_to_go--)
-               outb(*buf_ptr, mipsnet_reg_address(dev, txDataBuffer));
+               outb(*buf_ptr, regaddr(dev, txDataBuffer));
 
        dev->stats.tx_packets++;
        dev->stats.tx_bytes += skb->len;
 
-       return skb->len;
+       dev_kfree_skb(skb);
 }
 
 static int mipsnet_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -69,18 +144,20 @@ static int mipsnet_xmit(struct sk_buff *skb, struct net_device *dev)
        return 0;
 }
 
-static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t count)
+static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t len)
 {
        struct sk_buff *skb;
-       size_t len = count;
 
-       skb = alloc_skb(len + 2, GFP_KERNEL);
+       if (!len)
+               return len;
+
+       skb = dev_alloc_skb(len + NET_IP_ALIGN);
        if (!skb) {
                dev->stats.rx_dropped++;
                return -ENOMEM;
        }
 
-       skb_reserve(skb, 2);
+       skb_reserve(skb, NET_IP_ALIGN);
        if (ioiocpy_frommipsnet(dev, skb_put(skb, len), len))
                return -EFAULT;
 
@@ -92,50 +169,42 @@ static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t count)
        dev->stats.rx_packets++;
        dev->stats.rx_bytes += len;
 
-       return count;
+       return len;
 }
 
 static irqreturn_t mipsnet_interrupt(int irq, void *dev_id)
 {
        struct net_device *dev = dev_id;
-
-       irqreturn_t retval = IRQ_NONE;
-       uint64_t interruptFlags;
-
-       if (irq == dev->irq) {
-               retval = IRQ_HANDLED;
-
-               interruptFlags =
-                   inl(mipsnet_reg_address(dev, interruptControl));
-
-               if (interruptFlags & MIPSNET_INTCTL_TXDONE) {
-                       outl(MIPSNET_INTCTL_TXDONE,
-                            mipsnet_reg_address(dev, interruptControl));
-                       /* only one packet at a time, we are done. */
-                       netif_wake_queue(dev);
-               } else if (interruptFlags & MIPSNET_INTCTL_RXDONE) {
-                       mipsnet_get_fromdev(dev,
-                                   inl(mipsnet_reg_address(dev, rxDataCount)));
-                       outl(MIPSNET_INTCTL_RXDONE,
-                            mipsnet_reg_address(dev, interruptControl));
-
-               } else if (interruptFlags & MIPSNET_INTCTL_TESTBIT) {
-                       /*
-                        * TESTBIT is cleared on read.
-                        * And takes effect after a write with 0
-                        */
-                       outl(0, mipsnet_reg_address(dev, interruptControl));
-               } else {
-                       /* Maybe shared IRQ, just ignore, no clearing. */
-                       retval = IRQ_NONE;
-               }
-
-       } else {
-               printk(KERN_INFO "%s: %s(): irq %d for unknown device\n",
-                      dev->name, __FUNCTION__, irq);
-               retval = IRQ_NONE;
+       u32 int_flags;
+       irqreturn_t ret = IRQ_NONE;
+
+       if (irq != dev->irq)
+               goto out_badirq;
+
+       /* TESTBIT is cleared on read. */
+       int_flags = inl(regaddr(dev, interruptControl));
+       if (int_flags & MIPSNET_INTCTL_TESTBIT) {
+               /* TESTBIT takes effect after a write with 0. */
+               outl(0, regaddr(dev, interruptControl));
+               ret = IRQ_HANDLED;
+       } else if (int_flags & MIPSNET_INTCTL_TXDONE) {
+               /* Only one packet at a time, we are done. */
+               dev->stats.tx_packets++;
+               netif_wake_queue(dev);
+               outl(MIPSNET_INTCTL_TXDONE,
+                    regaddr(dev, interruptControl));
+               ret = IRQ_HANDLED;
+       } else if (int_flags & MIPSNET_INTCTL_RXDONE) {
+               mipsnet_get_fromdev(dev, inl(regaddr(dev, rxDataCount)));
+               outl(MIPSNET_INTCTL_RXDONE, regaddr(dev, interruptControl));
+               ret = IRQ_HANDLED;
        }
-       return retval;
+       return ret;
+
+out_badirq:
+       printk(KERN_INFO "%s: %s(): irq %d for unknown device\n",
+              dev->name, __FUNCTION__, irq);
+       return ret;
 }
 
 static int mipsnet_open(struct net_device *dev)
@@ -144,18 +213,15 @@ static int mipsnet_open(struct net_device *dev)
 
        err = request_irq(dev->irq, &mipsnet_interrupt,
                          IRQF_SHARED, dev->name, (void *) dev);
-
        if (err) {
-               release_region(dev->base_addr, MIPSNET_IO_EXTENT);
+               release_region(dev->base_addr, sizeof(struct mipsnet_regs));
                return err;
        }
 
        netif_start_queue(dev);
 
        /* test interrupt handler */
-       outl(MIPSNET_INTCTL_TESTBIT,
-            mipsnet_reg_address(dev, interruptControl));
-
+       outl(MIPSNET_INTCTL_TESTBIT, regaddr(dev, interruptControl));
 
        return 0;
 }
@@ -163,7 +229,7 @@ static int mipsnet_open(struct net_device *dev)
 static int mipsnet_close(struct net_device *dev)
 {
        netif_stop_queue(dev);
-
+       free_irq(dev->irq, dev);
        return 0;
 }
 
@@ -194,10 +260,11 @@ static int __init mipsnet_probe(struct device *dev)
         */
        netdev->base_addr = 0x4200;
        netdev->irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_MB0 +
-                     inl(mipsnet_reg_address(netdev, interruptInfo));
+                     inl(regaddr(netdev, interruptInfo));
 
        /* Get the io region now, get irq on open() */
-       if (!request_region(netdev->base_addr, MIPSNET_IO_EXTENT, "mipsnet")) {
+       if (!request_region(netdev->base_addr, sizeof(struct mipsnet_regs),
+                           "mipsnet")) {
                err = -EBUSY;
                goto out_free_netdev;
        }
@@ -217,7 +284,7 @@ static int __init mipsnet_probe(struct device *dev)
        return 0;
 
 out_free_region:
-       release_region(netdev->base_addr, MIPSNET_IO_EXTENT);
+       release_region(netdev->base_addr, sizeof(struct mipsnet_regs));
 
 out_free_netdev:
        free_netdev(netdev);
@@ -231,7 +298,7 @@ static int __devexit mipsnet_device_remove(struct device *device)
        struct net_device *dev = dev_get_drvdata(device);
 
        unregister_netdev(dev);
-       release_region(dev->base_addr, MIPSNET_IO_EXTENT);
+       release_region(dev->base_addr, sizeof(struct mipsnet_regs));
        free_netdev(dev);
        dev_set_drvdata(device, NULL);
 
diff --git a/drivers/net/mipsnet.h b/drivers/net/mipsnet.h
deleted file mode 100644 (file)
index 0132c67..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
- */
-#ifndef __MIPSNET_H
-#define __MIPSNET_H
-
-/*
- *  Id of this Net device, as seen by the core.
- */
-#define MIPS_NET_DEV_ID ((uint64_t)       \
-                            ((uint64_t) 'M' <<  0)| \
-                            ((uint64_t) 'I' <<  8)| \
-                            ((uint64_t) 'P' << 16)| \
-                            ((uint64_t) 'S' << 24)| \
-                            ((uint64_t) 'N' << 32)| \
-                            ((uint64_t) 'E' << 40)| \
-                            ((uint64_t) 'T' << 48)| \
-                            ((uint64_t) '0' << 56))
-
-/*
- * Net status/control block as seen by sw in the core.
- * (Why not use bit fields? can't be bothered with cross-platform struct
- *  packing.)
- */
-struct net_control_block {
-       /*
-        * dev info for probing
-        * reads as MIPSNET%d where %d is some form of version
-        */
-       uint64_t devId;         /* 0x00 */
-
-       /*
-        * read only busy flag.
-        * Set and cleared by the Net Device to indicate that an rx or a tx
-        * is in progress.
-        */
-       uint32_t busy;          /* 0x08 */
-
-       /*
-        * Set by the Net Device.
-        * The device will set it once data has been received.
-        * The value is the number of bytes that should be read from
-        * rxDataBuffer.  The value will decrease till 0 until all the data
-        * from rxDataBuffer has been read.
-        */
-       uint32_t rxDataCount;   /* 0x0c */
-#define MIPSNET_MAX_RXTX_DATACOUNT (1<<16)
-
-       /*
-        * Settable from the MIPS core, cleared by the Net Device.  The core
-        * should set the number of bytes it wants to send, then it should
-        * write those bytes of data to txDataBuffer.  The device will clear
-        * txDataCount has been processed (not necessarily sent).
-        */
-       uint32_t txDataCount;   /* 0x10 */
-
-       /*
-        * Interrupt control
-        *
-        * Used to clear the interrupted generated by this dev.
-        * Write a 1 to clear the interrupt. (except bit31).
-        *
-        * Bit0 is set if it was a tx-done interrupt.
-        * Bit1 is set when new rx-data is available.
-        *      Until this bit is cleared there will be no other RXs.
-        *
-        * Bit31 is used for testing, it clears after a read.
-        *    Writing 1 to this bit will cause an interrupt to be generated.
-        *    To clear the test interrupt, write 0 to this register.
-        */
-       uint32_t interruptControl;      /*0x14 */
-#define MIPSNET_INTCTL_TXDONE     ((uint32_t)(1 <<  0))
-#define MIPSNET_INTCTL_RXDONE     ((uint32_t)(1 <<  1))
-#define MIPSNET_INTCTL_TESTBIT    ((uint32_t)(1 << 31))
-#define MIPSNET_INTCTL_ALLSOURCES      (MIPSNET_INTCTL_TXDONE | \
-                                        MIPSNET_INTCTL_RXDONE | \
-                                        MIPSNET_INTCTL_TESTBIT)
-
-       /*
-        * Readonly core-specific interrupt info for the device to signal the
-        * core.  The meaning of the contents of this field might change.
-        *
-        * TODO: the whole memIntf interrupt scheme is messy: the device should
-        *       have no control what so ever of what VPE/register set is being
-        *       used.  The MemIntf should only expose interrupt lines, and
-        *       something in the config should be responsible for the
-        *       line<->core/vpe bindings.
-        */
-       uint32_t interruptInfo; /* 0x18 */
-
-       /*
-        *  This is where the received data is read out.
-        *  There is more data to read until rxDataReady is 0.
-        *  Only 1 byte at this regs offset is used.
-        */
-       uint32_t rxDataBuffer;  /* 0x1c */
-
-       /*
-        * This is where the data to transmit is written.  Data should be
-        * written for the amount specified in the txDataCount register.  Only
-        * 1 byte at this regs offset is used.
-        */
-       uint32_t txDataBuffer;  /* 0x20 */
-};
-
-#define MIPSNET_IO_EXTENT 0x40 /* being generous */
-
-#define field_offset(field) (offsetof(struct net_control_block, field))
-
-#endif /* __MIPSNET_H */
index 535a4461d88c6d720758e15d7fd21a67676a0fd9..61dc4951d6b0a61b2e1af9e535d0c14384c79e8e 100644 (file)
@@ -617,9 +617,6 @@ int mlx4_QUERY_ADAPTER(struct mlx4_dev *dev, struct mlx4_adapter *adapter)
        int err;
 
 #define QUERY_ADAPTER_OUT_SIZE             0x100
-#define QUERY_ADAPTER_VENDOR_ID_OFFSET     0x00
-#define QUERY_ADAPTER_DEVICE_ID_OFFSET     0x04
-#define QUERY_ADAPTER_REVISION_ID_OFFSET   0x08
 #define QUERY_ADAPTER_INTA_PIN_OFFSET      0x10
 #define QUERY_ADAPTER_VSD_OFFSET           0x20
 
@@ -633,9 +630,6 @@ int mlx4_QUERY_ADAPTER(struct mlx4_dev *dev, struct mlx4_adapter *adapter)
        if (err)
                goto out;
 
-       MLX4_GET(adapter->vendor_id, outbox,   QUERY_ADAPTER_VENDOR_ID_OFFSET);
-       MLX4_GET(adapter->device_id, outbox,   QUERY_ADAPTER_DEVICE_ID_OFFSET);
-       MLX4_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET);
        MLX4_GET(adapter->inta_pin, outbox,    QUERY_ADAPTER_INTA_PIN_OFFSET);
 
        get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4,
index 7e1dd9e25cfbabb9fa995d51c2c1fbf149518de6..e16dec890413dddbfcce48e7b79686f068703c8c 100644 (file)
@@ -99,9 +99,6 @@ struct mlx4_dev_cap {
 };
 
 struct mlx4_adapter {
-       u32  vendor_id;
-       u32  device_id;
-       u32  revision_id;
        char board_id[MLX4_BOARD_ID_LEN];
        u8   inta_pin;
 };
index 89b3f0b7cdc0f81a42a79eb2ecca2df0092e78ea..08bfc130a33eb7d63dac009d338e4464a34b4499 100644 (file)
@@ -71,7 +71,7 @@ MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
 
 #endif /* CONFIG_PCI_MSI */
 
-static const char mlx4_version[] __devinitdata =
+static char mlx4_version[] __devinitdata =
        DRV_NAME ": Mellanox ConnectX core driver v"
        DRV_VERSION " (" DRV_RELDATE ")\n";
 
@@ -163,7 +163,7 @@ static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
        return 0;
 }
 
-static int __devinit mlx4_load_fw(struct mlx4_dev *dev)
+static int mlx4_load_fw(struct mlx4_dev *dev)
 {
        struct mlx4_priv *priv = mlx4_priv(dev);
        int err;
@@ -197,8 +197,8 @@ err_free:
        return err;
 }
 
-static int __devinit mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
-                                         int cmpt_entry_sz)
+static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
+                               int cmpt_entry_sz)
 {
        struct mlx4_priv *priv = mlx4_priv(dev);
        int err;
@@ -534,7 +534,6 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
        }
 
        priv->eq_table.inta_pin = adapter.inta_pin;
-       dev->rev_id             = adapter.revision_id;
        memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
 
        return 0;
@@ -688,7 +687,7 @@ err_uar_table_free:
        return err;
 }
 
-static void __devinit mlx4_enable_msi_x(struct mlx4_dev *dev)
+static void mlx4_enable_msi_x(struct mlx4_dev *dev)
 {
        struct mlx4_priv *priv = mlx4_priv(dev);
        struct msix_entry entries[MLX4_NUM_EQ];
index 0c05a10bae3bfcd290b2797b006a2b33df09ab11..9c9e308d0917d2e26161221a0a9f393db91289d3 100644 (file)
@@ -122,7 +122,7 @@ static void mlx4_buddy_free(struct mlx4_buddy *buddy, u32 seg, int order)
        spin_unlock(&buddy->lock);
 }
 
-static int __devinit mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
+static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
 {
        int i, s;
 
index 651c2699d5e1cdf0eeb914ac21c89a19ce7961f7..b528ce77c4069997d67ffaac2e0c00b1b6f5d383 100644 (file)
@@ -1652,6 +1652,11 @@ static void eth_tx_fill_frag_descs(struct mv643xx_private *mp,
        }
 }
 
+static inline __be16 sum16_as_be(__sum16 sum)
+{
+       return (__force __be16)sum;
+}
+
 /**
  * eth_tx_submit_descs_for_skb - submit data from an skb to the tx hw
  *
@@ -1689,7 +1694,7 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
        desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
 
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               BUG_ON(skb->protocol != ETH_P_IP);
+               BUG_ON(skb->protocol != htons(ETH_P_IP));
 
                cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM |
                           ETH_GEN_IP_V_4_CHECKSUM  |
@@ -1698,10 +1703,10 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
                switch (ip_hdr(skb)->protocol) {
                case IPPROTO_UDP:
                        cmd_sts |= ETH_UDP_FRAME;
-                       desc->l4i_chk = udp_hdr(skb)->check;
+                       desc->l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check));
                        break;
                case IPPROTO_TCP:
-                       desc->l4i_chk = tcp_hdr(skb)->check;
+                       desc->l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check));
                        break;
                default:
                        BUG();
index c329a4f5840c7c22ee80a2882343888ea13ffbde..0a3e60418e53372beec40c8d50a1a78e086c8534 100644 (file)
@@ -203,22 +203,8 @@ skbuff at an offset of "+2", 16-byte aligning the IP header.
 IIId. Synchronization
 
 Most operations are synchronized on the np->lock irq spinlock, except the
-performance critical codepaths:
-
-The rx process only runs in the interrupt handler. Access from outside
-the interrupt handler is only permitted after disable_irq().
-
-The rx process usually runs under the netif_tx_lock. If np->intr_tx_reap
-is set, then access is permitted under spin_lock_irq(&np->lock).
-
-Thus configuration functions that want to access everything must call
-       disable_irq(dev->irq);
-       netif_tx_lock_bh(dev);
-       spin_lock_irq(&np->lock);
-
-IV. Notes
-
-NatSemi PCI network controllers are very uncommon.
+recieve and transmit paths which are synchronised using a combination of
+hardware descriptor ownership, disabling interrupts and NAPI poll scheduling.
 
 IVb. References
 
index bb88a41b759103e5601b22a4831f81f225513245..2e39e0285d8f9d2a6a9712ce33249749ede49377 100644 (file)
 
 #define LRO_MAX_AGGR 64
 
+#define PE_MIN_MTU     64
+#define PE_MAX_MTU     1500
+#define PE_DEF_MTU     ETH_DATA_LEN
+
 #define DEFAULT_MSG_ENABLE       \
        (NETIF_MSG_DRV          | \
         NETIF_MSG_PROBE        | \
@@ -82,8 +86,6 @@
                                 & ((ring)->size - 1))
 #define RING_AVAIL(ring)       ((ring->size) - RING_USED(ring))
 
-#define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
-
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
 MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
@@ -175,6 +177,24 @@ static int mac_to_intf(struct pasemi_mac *mac)
        return -1;
 }
 
+static void pasemi_mac_intf_disable(struct pasemi_mac *mac)
+{
+       unsigned int flags;
+
+       flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
+       flags &= ~PAS_MAC_CFG_PCFG_PE;
+       write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
+}
+
+static void pasemi_mac_intf_enable(struct pasemi_mac *mac)
+{
+       unsigned int flags;
+
+       flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
+       flags |= PAS_MAC_CFG_PCFG_PE;
+       write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
+}
+
 static int pasemi_get_mac_addr(struct pasemi_mac *mac)
 {
        struct pci_dev *pdev = mac->pdev;
@@ -221,6 +241,33 @@ static int pasemi_get_mac_addr(struct pasemi_mac *mac)
        return 0;
 }
 
+static int pasemi_mac_set_mac_addr(struct net_device *dev, void *p)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       struct sockaddr *addr = p;
+       unsigned int adr0, adr1;
+
+       if (!is_valid_ether_addr(addr->sa_data))
+               return -EINVAL;
+
+       memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+
+       adr0 = dev->dev_addr[2] << 24 |
+              dev->dev_addr[3] << 16 |
+              dev->dev_addr[4] << 8 |
+              dev->dev_addr[5];
+       adr1 = read_mac_reg(mac, PAS_MAC_CFG_ADR1);
+       adr1 &= ~0xffff;
+       adr1 |= dev->dev_addr[0] << 8 | dev->dev_addr[1];
+
+       pasemi_mac_intf_disable(mac);
+       write_mac_reg(mac, PAS_MAC_CFG_ADR0, adr0);
+       write_mac_reg(mac, PAS_MAC_CFG_ADR1, adr1);
+       pasemi_mac_intf_enable(mac);
+
+       return 0;
+}
+
 static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
                       void **tcph, u64 *hdr_flags, void *data)
 {
@@ -453,7 +500,7 @@ static void pasemi_mac_free_tx_resources(struct pasemi_mac *mac)
 
 }
 
-static void pasemi_mac_free_rx_resources(struct pasemi_mac *mac)
+static void pasemi_mac_free_rx_buffers(struct pasemi_mac *mac)
 {
        struct pasemi_mac_rxring *rx = rx_ring(mac);
        unsigned int i;
@@ -473,7 +520,12 @@ static void pasemi_mac_free_rx_resources(struct pasemi_mac *mac)
        }
 
        for (i = 0; i < RX_RING_SIZE; i++)
-               RX_DESC(rx, i) = 0;
+               RX_BUFF(rx, i) = 0;
+}
+
+static void pasemi_mac_free_rx_resources(struct pasemi_mac *mac)
+{
+       pasemi_mac_free_rx_buffers(mac);
 
        dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64),
                          rx_ring(mac)->buffers, rx_ring(mac)->buf_dma);
@@ -503,14 +555,14 @@ static void pasemi_mac_replenish_rx_ring(const struct net_device *dev,
                /* Entry in use? */
                WARN_ON(*buff);
 
-               skb = dev_alloc_skb(BUF_SIZE);
+               skb = dev_alloc_skb(mac->bufsz);
                skb_reserve(skb, LOCAL_SKB_ALIGN);
 
                if (unlikely(!skb))
                        break;
 
                dma = pci_map_single(mac->dma_pdev, skb->data,
-                                    BUF_SIZE - LOCAL_SKB_ALIGN,
+                                    mac->bufsz - LOCAL_SKB_ALIGN,
                                     PCI_DMA_FROMDEVICE);
 
                if (unlikely(dma_mapping_error(dma))) {
@@ -520,7 +572,7 @@ static void pasemi_mac_replenish_rx_ring(const struct net_device *dev,
 
                info->skb = skb;
                info->dma = dma;
-               *buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma);
+               *buff = XCT_RXB_LEN(mac->bufsz) | XCT_RXB_ADDR(dma);
                fill++;
        }
 
@@ -650,7 +702,7 @@ static int pasemi_mac_clean_rx(struct pasemi_mac_rxring *rx,
 
                len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
 
-               pci_unmap_single(pdev, dma, BUF_SIZE-LOCAL_SKB_ALIGN,
+               pci_unmap_single(pdev, dma, mac->bufsz - LOCAL_SKB_ALIGN,
                                 PCI_DMA_FROMDEVICE);
 
                if (macrx & XCT_MACRX_CRC) {
@@ -874,24 +926,6 @@ static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
        return IRQ_HANDLED;
 }
 
-static void pasemi_mac_intf_disable(struct pasemi_mac *mac)
-{
-       unsigned int flags;
-
-       flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
-       flags &= ~PAS_MAC_CFG_PCFG_PE;
-       write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
-}
-
-static void pasemi_mac_intf_enable(struct pasemi_mac *mac)
-{
-       unsigned int flags;
-
-       flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
-       flags |= PAS_MAC_CFG_PCFG_PE;
-       write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
-}
-
 static void pasemi_adjust_link(struct net_device *dev)
 {
        struct pasemi_mac *mac = netdev_priv(dev);
@@ -1148,11 +1182,71 @@ out_rx_resources:
 
 #define MAX_RETRIES 5000
 
+static void pasemi_mac_pause_txchan(struct pasemi_mac *mac)
+{
+       unsigned int sta, retries;
+       int txch = tx_ring(mac)->chan.chno;
+
+       write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch),
+                     PAS_DMA_TXCHAN_TCMDSTA_ST);
+
+       for (retries = 0; retries < MAX_RETRIES; retries++) {
+               sta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch));
+               if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT))
+                       break;
+               cond_resched();
+       }
+
+       if (sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)
+               dev_err(&mac->dma_pdev->dev,
+                       "Failed to stop tx channel, tcmdsta %08x\n", sta);
+
+       write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch), 0);
+}
+
+static void pasemi_mac_pause_rxchan(struct pasemi_mac *mac)
+{
+       unsigned int sta, retries;
+       int rxch = rx_ring(mac)->chan.chno;
+
+       write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch),
+                     PAS_DMA_RXCHAN_CCMDSTA_ST);
+       for (retries = 0; retries < MAX_RETRIES; retries++) {
+               sta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch));
+               if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT))
+                       break;
+               cond_resched();
+       }
+
+       if (sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)
+               dev_err(&mac->dma_pdev->dev,
+                       "Failed to stop rx channel, ccmdsta 08%x\n", sta);
+       write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch), 0);
+}
+
+static void pasemi_mac_pause_rxint(struct pasemi_mac *mac)
+{
+       unsigned int sta, retries;
+
+       write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
+                     PAS_DMA_RXINT_RCMDSTA_ST);
+       for (retries = 0; retries < MAX_RETRIES; retries++) {
+               sta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
+               if (!(sta & PAS_DMA_RXINT_RCMDSTA_ACT))
+                       break;
+               cond_resched();
+       }
+
+       if (sta & PAS_DMA_RXINT_RCMDSTA_ACT)
+               dev_err(&mac->dma_pdev->dev,
+                       "Failed to stop rx interface, rcmdsta %08x\n", sta);
+       write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
+}
+
 static int pasemi_mac_close(struct net_device *dev)
 {
        struct pasemi_mac *mac = netdev_priv(dev);
        unsigned int sta;
-       int retries;
        int rxch, txch;
 
        rxch = rx_ring(mac)->chan.chno;
@@ -1190,51 +1284,10 @@ static int pasemi_mac_close(struct net_device *dev)
        pasemi_mac_clean_tx(tx_ring(mac));
        pasemi_mac_clean_rx(rx_ring(mac), RX_RING_SIZE);
 
-       /* Disable interface */
-       write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch),
-                     PAS_DMA_TXCHAN_TCMDSTA_ST);
-       write_dma_reg( PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
-                     PAS_DMA_RXINT_RCMDSTA_ST);
-       write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch),
-                     PAS_DMA_RXCHAN_CCMDSTA_ST);
-
-       for (retries = 0; retries < MAX_RETRIES; retries++) {
-               sta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(rxch));
-               if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT))
-                       break;
-               cond_resched();
-       }
-
-       if (sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)
-               dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel\n");
-
-       for (retries = 0; retries < MAX_RETRIES; retries++) {
-               sta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch));
-               if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT))
-                       break;
-               cond_resched();
-       }
-
-       if (sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)
-               dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n");
-
-       for (retries = 0; retries < MAX_RETRIES; retries++) {
-               sta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
-               if (!(sta & PAS_DMA_RXINT_RCMDSTA_ACT))
-                       break;
-               cond_resched();
-       }
-
-       if (sta & PAS_DMA_RXINT_RCMDSTA_ACT)
-               dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n");
-
-       /* Then, disable the channel. This must be done separately from
-        * stopping, since you can't disable when active.
-        */
-
-       write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch), 0);
-       write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch), 0);
-       write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
+       pasemi_mac_pause_txchan(mac);
+       pasemi_mac_pause_rxint(mac);
+       pasemi_mac_pause_rxchan(mac);
+       pasemi_mac_intf_disable(mac);
 
        free_irq(mac->tx->chan.irq, mac->tx);
        free_irq(mac->rx->chan.irq, mac->rx);
@@ -1388,6 +1441,62 @@ static int pasemi_mac_poll(struct napi_struct *napi, int budget)
        return pkts;
 }
 
+static int pasemi_mac_change_mtu(struct net_device *dev, int new_mtu)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int reg;
+       unsigned int rcmdsta;
+       int running;
+
+       if (new_mtu < PE_MIN_MTU || new_mtu > PE_MAX_MTU)
+               return -EINVAL;
+
+       running = netif_running(dev);
+
+       if (running) {
+               /* Need to stop the interface, clean out all already
+                * received buffers, free all unused buffers on the RX
+                * interface ring, then finally re-fill the rx ring with
+                * the new-size buffers and restart.
+                */
+
+               napi_disable(&mac->napi);
+               netif_tx_disable(dev);
+               pasemi_mac_intf_disable(mac);
+
+               rcmdsta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
+               pasemi_mac_pause_rxint(mac);
+               pasemi_mac_clean_rx(rx_ring(mac), RX_RING_SIZE);
+               pasemi_mac_free_rx_buffers(mac);
+       }
+
+       /* Change maxf, i.e. what size frames are accepted.
+        * Need room for ethernet header and CRC word
+        */
+       reg = read_mac_reg(mac, PAS_MAC_CFG_MACCFG);
+       reg &= ~PAS_MAC_CFG_MACCFG_MAXF_M;
+       reg |= PAS_MAC_CFG_MACCFG_MAXF(new_mtu + ETH_HLEN + 4);
+       write_mac_reg(mac, PAS_MAC_CFG_MACCFG, reg);
+
+       dev->mtu = new_mtu;
+       /* MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
+       mac->bufsz = new_mtu + ETH_HLEN + ETH_FCS_LEN + LOCAL_SKB_ALIGN + 128;
+
+       if (running) {
+               write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
+                             rcmdsta | PAS_DMA_RXINT_RCMDSTA_EN);
+
+               rx_ring(mac)->next_to_fill = 0;
+               pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE-1);
+
+               napi_enable(&mac->napi);
+               netif_start_queue(dev);
+               pasemi_mac_intf_enable(mac);
+       }
+
+       return 0;
+}
+
 static int __devinit
 pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -1475,6 +1584,12 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        dev->stop = pasemi_mac_close;
        dev->hard_start_xmit = pasemi_mac_start_tx;
        dev->set_multicast_list = pasemi_mac_set_rx_mode;
+       dev->set_mac_address = pasemi_mac_set_mac_addr;
+       dev->mtu = PE_DEF_MTU;
+       /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
+       mac->bufsz = dev->mtu + ETH_HLEN + ETH_FCS_LEN + LOCAL_SKB_ALIGN + 128;
+
+       dev->change_mtu = pasemi_mac_change_mtu;
 
        if (err)
                goto out;
index 8bee2a664c83760d12a897eb4230331f6e99c229..99e7b9329a6fb5366936d62f399b513a676b5897 100644 (file)
@@ -59,6 +59,7 @@ struct pasemi_mac {
        struct phy_device *phydev;
        struct napi_struct napi;
 
+       int             bufsz; /* RX ring buffer size */
        u8              type;
 #define MAC_TYPE_GMAC  1
 #define MAC_TYPE_XAUI  2
@@ -96,6 +97,9 @@ struct pasemi_mac_buffer {
 /* MAC CFG register offsets */
 enum {
        PAS_MAC_CFG_PCFG = 0x80,
+       PAS_MAC_CFG_MACCFG = 0x84,
+       PAS_MAC_CFG_ADR0 = 0x8c,
+       PAS_MAC_CFG_ADR1 = 0x90,
        PAS_MAC_CFG_TXP = 0x98,
        PAS_MAC_IPC_CHNL = 0x208,
 };
@@ -130,6 +134,18 @@ enum {
 #define PAS_MAC_CFG_PCFG_SPD_100M      0x00000001
 #define PAS_MAC_CFG_PCFG_SPD_1G                0x00000002
 #define PAS_MAC_CFG_PCFG_SPD_10G       0x00000003
+
+#define PAS_MAC_CFG_MACCFG_TXT_M       0x70000000
+#define PAS_MAC_CFG_MACCFG_TXT_S       28
+#define PAS_MAC_CFG_MACCFG_PRES_M      0x0f000000
+#define PAS_MAC_CFG_MACCFG_PRES_S      24
+#define PAS_MAC_CFG_MACCFG_MAXF_M      0x00ffff00
+#define PAS_MAC_CFG_MACCFG_MAXF_S      8
+#define PAS_MAC_CFG_MACCFG_MAXF(x)     (((x) << PAS_MAC_CFG_MACCFG_MAXF_S) & \
+                                        PAS_MAC_CFG_MACCFG_MAXF_M)
+#define PAS_MAC_CFG_MACCFG_MINF_M      0x000000ff
+#define PAS_MAC_CFG_MACCFG_MINF_S      0
+
 #define PAS_MAC_CFG_TXP_FCF            0x01000000
 #define PAS_MAC_CFG_TXP_FCE            0x00800000
 #define PAS_MAC_CFG_TXP_FC             0x00400000
index ed402e00e730e1c0c2eadfa1ac13a5cfe3cb9aa9..fffc49befe042c7b514745d688cfd5817a44a9dc 100644 (file)
@@ -541,7 +541,7 @@ static void netdrv_hw_start (struct net_device *dev);
 #define NETDRV_W32_F(reg, val32)       do { writel ((val32), ioaddr + (reg)); readl (ioaddr + (reg)); } while (0)
 
 
-#if MMIO_FLUSH_AUDIT_COMPLETE
+#ifdef MMIO_FLUSH_AUDIT_COMPLETE
 
 /* write MMIO register */
 #define NETDRV_W8(reg, val8)   writeb ((val8), ioaddr + (reg))
@@ -603,7 +603,7 @@ static int __devinit netdrv_init_board (struct pci_dev *pdev,
                return -ENOMEM;
        }
        SET_NETDEV_DEV(dev, &pdev->dev);
-       tp = dev->priv;
+       tp = netdev_priv(dev);
 
        /* enable device (incl. PCI PM wakeup), and bus-mastering */
        rc = pci_enable_device (pdev);
@@ -759,7 +759,7 @@ static int __devinit netdrv_init_one (struct pci_dev *pdev,
                return i;
        }
 
-       tp = dev->priv;
+       tp = netdev_priv(dev);
 
        assert (ioaddr != NULL);
        assert (dev != NULL);
@@ -783,7 +783,7 @@ static int __devinit netdrv_init_one (struct pci_dev *pdev,
        dev->base_addr = (unsigned long) ioaddr;
 
        /* dev->priv/tp zeroed and aligned in alloc_etherdev */
-       tp = dev->priv;
+       tp = netdev_priv(dev);
 
        /* note: tp->chipset set in netdrv_init_board */
        tp->drv_flags = PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
@@ -841,7 +841,7 @@ static void __devexit netdrv_remove_one (struct pci_dev *pdev)
 
        assert (dev != NULL);
 
-       np = dev->priv;
+       np = netdev_priv(dev);
        assert (np != NULL);
 
        unregister_netdev (dev);
@@ -974,7 +974,7 @@ static void mdio_sync (void *mdio_addr)
 
 static int mdio_read (struct net_device *dev, int phy_id, int location)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *mdio_addr = tp->mmio_addr + Config4;
        int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
        int retval = 0;
@@ -1017,7 +1017,7 @@ static int mdio_read (struct net_device *dev, int phy_id, int location)
 static void mdio_write (struct net_device *dev, int phy_id, int location,
                        int value)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *mdio_addr = tp->mmio_addr + Config4;
        int mii_cmd =
            (0x5002 << 16) | (phy_id << 23) | (location << 18) | value;
@@ -1060,7 +1060,7 @@ static void mdio_write (struct net_device *dev, int phy_id, int location,
 
 static int netdrv_open (struct net_device *dev)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        int retval;
 #ifdef NETDRV_DEBUG
        void *ioaddr = tp->mmio_addr;
@@ -1121,7 +1121,7 @@ static int netdrv_open (struct net_device *dev)
 /* Start the hardware at open or resume. */
 static void netdrv_hw_start (struct net_device *dev)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *ioaddr = tp->mmio_addr;
        u32 i;
 
@@ -1191,7 +1191,7 @@ static void netdrv_hw_start (struct net_device *dev)
 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
 static void netdrv_init_ring (struct net_device *dev)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        int i;
 
        DPRINTK ("ENTER\n");
@@ -1213,7 +1213,7 @@ static void netdrv_init_ring (struct net_device *dev)
 static void netdrv_timer (unsigned long data)
 {
        struct net_device *dev = (struct net_device *) data;
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *ioaddr = tp->mmio_addr;
        int next_tick = 60 * HZ;
        int mii_lpa;
@@ -1252,9 +1252,10 @@ static void netdrv_timer (unsigned long data)
 }
 
 
-static void netdrv_tx_clear (struct netdrv_private *tp)
+static void netdrv_tx_clear (struct net_device *dev)
 {
        int i;
+       struct netdrv_private *tp = netdev_priv(dev);
 
        atomic_set (&tp->cur_tx, 0);
        atomic_set (&tp->dirty_tx, 0);
@@ -1278,7 +1279,7 @@ static void netdrv_tx_clear (struct netdrv_private *tp)
 
 static void netdrv_tx_timeout (struct net_device *dev)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *ioaddr = tp->mmio_addr;
        int i;
        u8 tmp8;
@@ -1311,7 +1312,7 @@ static void netdrv_tx_timeout (struct net_device *dev)
        /* Stop a shared interrupt from scavenging while we are. */
        spin_lock_irqsave (&tp->lock, flags);
 
-       netdrv_tx_clear (tp);
+       netdrv_tx_clear (dev);
 
        spin_unlock_irqrestore (&tp->lock, flags);
 
@@ -1325,7 +1326,7 @@ static void netdrv_tx_timeout (struct net_device *dev)
 
 static int netdrv_start_xmit (struct sk_buff *skb, struct net_device *dev)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *ioaddr = tp->mmio_addr;
        int entry;
 
@@ -1525,7 +1526,7 @@ static void netdrv_rx_interrupt (struct net_device *dev,
                DPRINTK ("%s:  netdrv_rx() status %4.4x, size %4.4x,"
                         " cur %4.4x.\n", dev->name, rx_status,
                         rx_size, cur_rx);
-#if NETDRV_DEBUG > 2
+#if defined(NETDRV_DEBUG) && (NETDRV_DEBUG > 2)
                {
                        int i;
                        DPRINTK ("%s: Frame contents ", dev->name);
@@ -1648,7 +1649,7 @@ static void netdrv_weird_interrupt (struct net_device *dev,
 static irqreturn_t netdrv_interrupt (int irq, void *dev_instance)
 {
        struct net_device *dev = (struct net_device *) dev_instance;
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        int boguscnt = max_interrupt_work;
        void *ioaddr = tp->mmio_addr;
        int status = 0, link_changed = 0; /* avoid bogus "uninit" warning */
@@ -1711,7 +1712,7 @@ static irqreturn_t netdrv_interrupt (int irq, void *dev_instance)
 
 static int netdrv_close (struct net_device *dev)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *ioaddr = tp->mmio_addr;
        unsigned long flags;
 
@@ -1738,10 +1739,10 @@ static int netdrv_close (struct net_device *dev)
 
        spin_unlock_irqrestore (&tp->lock, flags);
 
-       synchronize_irq ();
+       synchronize_irq (dev->irq);
        free_irq (dev->irq, dev);
 
-       netdrv_tx_clear (tp);
+       netdrv_tx_clear (dev);
 
        pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
                            tp->rx_ring, tp->rx_ring_dma);
@@ -1762,7 +1763,7 @@ static int netdrv_close (struct net_device *dev)
 
 static int netdrv_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        struct mii_ioctl_data *data = if_mii(rq);
        unsigned long flags;
        int rc = 0;
@@ -1805,7 +1806,7 @@ static int netdrv_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
 
 static void netdrv_set_rx_mode (struct net_device *dev)
 {
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *ioaddr = tp->mmio_addr;
        u32 mc_filter[2];       /* Multicast hash filter */
        int i, rx_mode;
@@ -1862,7 +1863,7 @@ static void netdrv_set_rx_mode (struct net_device *dev)
 static int netdrv_suspend (struct pci_dev *pdev, pm_message_t state)
 {
        struct net_device *dev = pci_get_drvdata (pdev);
-       struct netdrv_private *tp = dev->priv;
+       struct netdrv_private *tp = netdev_priv(dev);
        void *ioaddr = tp->mmio_addr;
        unsigned long flags;
 
@@ -1892,7 +1893,7 @@ static int netdrv_suspend (struct pci_dev *pdev, pm_message_t state)
 static int netdrv_resume (struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata (pdev);
-       struct netdrv_private *tp = dev->priv;
+       /*struct netdrv_private *tp = netdev_priv(dev);*/
 
        if (!netif_running(dev))
                return 0;
index 36a7ba3134ce7468b643138f3d57ea95334b95bc..3b78a3819bb3d2ae33cb47e1da8cbddb58739013 100644 (file)
@@ -230,10 +230,11 @@ static char mii_preamble_required = 0;
 static int tc574_config(struct pcmcia_device *link);
 static void tc574_release(struct pcmcia_device *link);
 
-static void mdio_sync(kio_addr_t ioaddr, int bits);
-static int mdio_read(kio_addr_t ioaddr, int phy_id, int location);
-static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value);
-static unsigned short read_eeprom(kio_addr_t ioaddr, int index);
+static void mdio_sync(unsigned int ioaddr, int bits);
+static int mdio_read(unsigned int ioaddr, int phy_id, int location);
+static void mdio_write(unsigned int ioaddr, int phy_id, int location,
+                      int value);
+static unsigned short read_eeprom(unsigned int ioaddr, int index);
 static void tc574_wait_for_completion(struct net_device *dev, int cmd);
 
 static void tc574_reset(struct net_device *dev);
@@ -341,7 +342,7 @@ static int tc574_config(struct pcmcia_device *link)
        tuple_t tuple;
        __le16 buf[32];
        int last_fn, last_ret, i, j;
-       kio_addr_t ioaddr;
+       unsigned int ioaddr;
        __be16 *phys_addr;
        char *cardname;
        __u32 config;
@@ -515,7 +516,7 @@ static int tc574_resume(struct pcmcia_device *link)
 
 static void dump_status(struct net_device *dev)
 {
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        EL3WINDOW(1);
        printk(KERN_INFO "  irq status %04x, rx status %04x, tx status "
                   "%02x, tx free %04x\n", inw(ioaddr+EL3_STATUS),
@@ -544,7 +545,7 @@ static void tc574_wait_for_completion(struct net_device *dev, int cmd)
 /* Read a word from the EEPROM using the regular EEPROM access register.
    Assume that we are in register window zero.
  */
-static unsigned short read_eeprom(kio_addr_t ioaddr, int index)
+static unsigned short read_eeprom(unsigned int ioaddr, int index)
 {
        int timer;
        outw(EEPROM_Read + index, ioaddr + Wn0EepromCmd);
@@ -572,9 +573,9 @@ static unsigned short read_eeprom(kio_addr_t ioaddr, int index)
 
 /* Generate the preamble required for initial synchronization and
    a few older transceivers. */
-static void mdio_sync(kio_addr_t ioaddr, int bits)
+static void mdio_sync(unsigned int ioaddr, int bits)
 {
-       kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
+       unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt;
 
        /* Establish sync by sending at least 32 logic ones. */
        while (-- bits >= 0) {
@@ -583,12 +584,12 @@ static void mdio_sync(kio_addr_t ioaddr, int bits)
        }
 }
 
-static int mdio_read(kio_addr_t ioaddr, int phy_id, int location)
+static int mdio_read(unsigned int ioaddr, int phy_id, int location)
 {
        int i;
        int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
        unsigned int retval = 0;
-       kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
+       unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt;
 
        if (mii_preamble_required)
                mdio_sync(ioaddr, 32);
@@ -608,10 +609,10 @@ static int mdio_read(kio_addr_t ioaddr, int phy_id, int location)
        return (retval>>1) & 0xffff;
 }
 
-static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value)
+static void mdio_write(unsigned int ioaddr, int phy_id, int location, int value)
 {
        int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
-       kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
+       unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt;
        int i;
 
        if (mii_preamble_required)
@@ -637,7 +638,7 @@ static void tc574_reset(struct net_device *dev)
 {
        struct el3_private *lp = netdev_priv(dev);
        int i;
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        unsigned long flags;
 
        tc574_wait_for_completion(dev, TotalReset|0x10);
@@ -695,7 +696,7 @@ static void tc574_reset(struct net_device *dev)
        mdio_write(ioaddr, lp->phys, 4, lp->advertising);
        if (!auto_polarity) {
                /* works for TDK 78Q2120 series MII's */
-               int i = mdio_read(ioaddr, lp->phys, 16) | 0x20;
+               i = mdio_read(ioaddr, lp->phys, 16) | 0x20;
                mdio_write(ioaddr, lp->phys, 16, i);
        }
 
@@ -741,7 +742,7 @@ static int el3_open(struct net_device *dev)
 static void el3_tx_timeout(struct net_device *dev)
 {
        struct el3_private *lp = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        
        printk(KERN_NOTICE "%s: Transmit timed out!\n", dev->name);
        dump_status(dev);
@@ -756,7 +757,7 @@ static void el3_tx_timeout(struct net_device *dev)
 static void pop_tx_status(struct net_device *dev)
 {
        struct el3_private *lp = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        int i;
     
        /* Clear the Tx status stack. */
@@ -779,7 +780,7 @@ static void pop_tx_status(struct net_device *dev)
 
 static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        struct el3_private *lp = netdev_priv(dev);
        unsigned long flags;
 
@@ -813,7 +814,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *) dev_id;
        struct el3_private *lp = netdev_priv(dev);
-       kio_addr_t ioaddr;
+       unsigned int ioaddr;
        unsigned status;
        int work_budget = max_interrupt_work;
        int handled = 0;
@@ -907,7 +908,7 @@ static void media_check(unsigned long arg)
 {
        struct net_device *dev = (struct net_device *) arg;
        struct el3_private *lp = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        unsigned long flags;
        unsigned short /* cable, */ media, partner;
 
@@ -996,7 +997,7 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
 static void update_stats(struct net_device *dev)
 {
        struct el3_private *lp = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        u8 rx, tx, up;
 
        DEBUG(2, "%s: updating the statistics.\n", dev->name);
@@ -1033,7 +1034,7 @@ static void update_stats(struct net_device *dev)
 static int el3_rx(struct net_device *dev, int worklimit)
 {
        struct el3_private *lp = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        short rx_status;
        
        DEBUG(3, "%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
@@ -1094,7 +1095,7 @@ static const struct ethtool_ops netdev_ethtool_ops = {
 static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
        struct el3_private *lp = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        u16 *data = (u16 *)&rq->ifr_ifru;
        int phy = lp->phys & 0x1f;
 
@@ -1148,7 +1149,7 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
 static void set_rx_mode(struct net_device *dev)
 {
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
 
        if (dev->flags & IFF_PROMISC)
                outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
@@ -1161,7 +1162,7 @@ static void set_rx_mode(struct net_device *dev)
 
 static int el3_close(struct net_device *dev)
 {
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        struct el3_private *lp = netdev_priv(dev);
        struct pcmcia_device *link = lp->p_dev;
 
index e862d14ece79a6afe1069150a1e65fe3bed6acae..1b1abb19c911d1623e722a8ef18056adbfeb11a8 100644 (file)
@@ -145,7 +145,7 @@ DRV_NAME ".c " DRV_VERSION " 2001/10/13 00:08:50 (David Hinds)";
 static int tc589_config(struct pcmcia_device *link);
 static void tc589_release(struct pcmcia_device *link);
 
-static u16 read_eeprom(kio_addr_t ioaddr, int index);
+static u16 read_eeprom(unsigned int ioaddr, int index);
 static void tc589_reset(struct net_device *dev);
 static void media_check(unsigned long arg);
 static int el3_config(struct net_device *dev, struct ifmap *map);
@@ -254,7 +254,7 @@ static int tc589_config(struct pcmcia_device *link)
     __le16 buf[32];
     __be16 *phys_addr;
     int last_fn, last_ret, i, j, multi = 0, fifo;
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
     DECLARE_MAC_BUF(mac);
     
@@ -403,7 +403,7 @@ static void tc589_wait_for_completion(struct net_device *dev, int cmd)
   Read a word from the EEPROM using the regular EEPROM access register.
   Assume that we are in register window zero.
 */
-static u16 read_eeprom(kio_addr_t ioaddr, int index)
+static u16 read_eeprom(unsigned int ioaddr, int index)
 {
     int i;
     outw(EEPROM_READ + index, ioaddr + 10);
@@ -421,7 +421,7 @@ static u16 read_eeprom(kio_addr_t ioaddr, int index)
 static void tc589_set_xcvr(struct net_device *dev, int if_port)
 {
     struct el3_private *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     
     EL3WINDOW(0);
     switch (if_port) {
@@ -443,7 +443,7 @@ static void tc589_set_xcvr(struct net_device *dev, int if_port)
 
 static void dump_status(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     EL3WINDOW(1);
     printk(KERN_INFO "  irq status %04x, rx status %04x, tx status "
           "%02x  tx free %04x\n", inw(ioaddr+EL3_STATUS),
@@ -459,7 +459,7 @@ static void dump_status(struct net_device *dev)
 /* Reset and restore all of the 3c589 registers. */
 static void tc589_reset(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int i;
     
     EL3WINDOW(0);
@@ -567,7 +567,7 @@ static int el3_open(struct net_device *dev)
 static void el3_tx_timeout(struct net_device *dev)
 {
     struct el3_private *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     
     printk(KERN_WARNING "%s: Transmit timed out!\n", dev->name);
     dump_status(dev);
@@ -582,7 +582,7 @@ static void el3_tx_timeout(struct net_device *dev)
 static void pop_tx_status(struct net_device *dev)
 {
     struct el3_private *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int i;
     
     /* Clear the Tx status stack. */
@@ -604,7 +604,7 @@ static void pop_tx_status(struct net_device *dev)
 
 static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     struct el3_private *priv = netdev_priv(dev);
     unsigned long flags;
 
@@ -641,7 +641,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
 {
     struct net_device *dev = (struct net_device *) dev_id;
     struct el3_private *lp = netdev_priv(dev);
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     __u16 status;
     int i = 0, handled = 1;
     
@@ -727,7 +727,7 @@ static void media_check(unsigned long arg)
 {
     struct net_device *dev = (struct net_device *)(arg);
     struct el3_private *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u16 media, errs;
     unsigned long flags;
 
@@ -828,7 +828,7 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
 static void update_stats(struct net_device *dev)
 {
     struct el3_private *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     DEBUG(2, "%s: updating the statistics.\n", dev->name);
     /* Turn off statistics updates while reading. */
@@ -855,7 +855,7 @@ static void update_stats(struct net_device *dev)
 static int el3_rx(struct net_device *dev)
 {
     struct el3_private *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int worklimit = 32;
     short rx_status;
     
@@ -909,7 +909,7 @@ static void set_multicast_list(struct net_device *dev)
 {
     struct el3_private *lp = netdev_priv(dev);
     struct pcmcia_device *link = lp->p_dev;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u16 opts = SetRxFilter | RxStation | RxBroadcast;
 
     if (!pcmcia_dev_present(link)) return;
@@ -924,7 +924,7 @@ static int el3_close(struct net_device *dev)
 {
     struct el3_private *lp = netdev_priv(dev);
     struct pcmcia_device *link = lp->p_dev;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     
     DEBUG(1, "%s: shutting down ethercard.\n", dev->name);
 
index 6d342f6c14f643a67a8ee6d78429a1480828f32f..e8a63e483a2be034f9c4a057d0b3cc8457ac645a 100644 (file)
@@ -96,8 +96,8 @@ static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);
 static void ei_watchdog(u_long arg);
 static void axnet_reset_8390(struct net_device *dev);
 
-static int mdio_read(kio_addr_t addr, int phy_id, int loc);
-static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value);
+static int mdio_read(unsigned int addr, int phy_id, int loc);
+static void mdio_write(unsigned int addr, int phy_id, int loc, int value);
 
 static void get_8390_hdr(struct net_device *,
                         struct e8390_pkt_hdr *, int);
@@ -203,7 +203,7 @@ static void axnet_detach(struct pcmcia_device *link)
 static int get_prom(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int i, j;
 
     /* This is based on drivers/net/ne.c */
@@ -473,7 +473,7 @@ static int axnet_resume(struct pcmcia_device *link)
 #define MDIO_MASK              0x0f
 #define MDIO_ENB_IN            0x02
 
-static void mdio_sync(kio_addr_t addr)
+static void mdio_sync(unsigned int addr)
 {
     int bits;
     for (bits = 0; bits < 32; bits++) {
@@ -482,7 +482,7 @@ static void mdio_sync(kio_addr_t addr)
     }
 }
 
-static int mdio_read(kio_addr_t addr, int phy_id, int loc)
+static int mdio_read(unsigned int addr, int phy_id, int loc)
 {
     u_int cmd = (0xf6<<10)|(phy_id<<5)|loc;
     int i, retval = 0;
@@ -501,7 +501,7 @@ static int mdio_read(kio_addr_t addr, int phy_id, int loc)
     return (retval>>1) & 0xffff;
 }
 
-static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value)
+static void mdio_write(unsigned int addr, int phy_id, int loc, int value)
 {
     u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
     int i;
@@ -575,7 +575,7 @@ static int axnet_close(struct net_device *dev)
 
 static void axnet_reset_8390(struct net_device *dev)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
     int i;
 
     ei_status.txing = ei_status.dmaing = 0;
@@ -610,8 +610,8 @@ static void ei_watchdog(u_long arg)
 {
     struct net_device *dev = (struct net_device *)(arg);
     axnet_dev_t *info = PRIV(dev);
-    kio_addr_t nic_base = dev->base_addr;
-    kio_addr_t mii_addr = nic_base + AXNET_MII_EEP;
+    unsigned int nic_base = dev->base_addr;
+    unsigned int mii_addr = nic_base + AXNET_MII_EEP;
     u_short link;
 
     if (!netif_device_present(dev)) goto reschedule;
@@ -681,7 +681,7 @@ static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
     axnet_dev_t *info = PRIV(dev);
     u16 *data = (u16 *)&rq->ifr_ifru;
-    kio_addr_t mii_addr = dev->base_addr + AXNET_MII_EEP;
+    unsigned int mii_addr = dev->base_addr + AXNET_MII_EEP;
     switch (cmd) {
     case SIOCGMIIPHY:
        data[0] = info->phy_id;
@@ -703,7 +703,7 @@ static void get_8390_hdr(struct net_device *dev,
                         struct e8390_pkt_hdr *hdr,
                         int ring_page)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
 
     outb_p(0, nic_base + EN0_RSARLO);          /* On page boundary */
     outb_p(ring_page, nic_base + EN0_RSARHI);
@@ -721,7 +721,7 @@ static void get_8390_hdr(struct net_device *dev,
 static void block_input(struct net_device *dev, int count,
                        struct sk_buff *skb, int ring_offset)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
     int xfer_count = count;
     char *buf = skb->data;
 
@@ -744,7 +744,7 @@ static void block_input(struct net_device *dev, int count,
 static void block_output(struct net_device *dev, int count,
                         const u_char *buf, const int start_page)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
 
 #ifdef PCMCIA_DEBUG
     if (ei_debug > 4)
@@ -991,7 +991,7 @@ static int ax_open(struct net_device *dev)
  *
  * Opposite of ax_open(). Only used when "ifconfig <devname> down" is done.
  */
-int ax_close(struct net_device *dev)
+static int ax_close(struct net_device *dev)
 {
        unsigned long flags;
 
@@ -1014,7 +1014,7 @@ int ax_close(struct net_device *dev)
  * completed (or failed) - i.e. never posted a Tx related interrupt.
  */
 
-void ei_tx_timeout(struct net_device *dev)
+static void ei_tx_timeout(struct net_device *dev)
 {
        long e8390_base = dev->base_addr;
        struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
@@ -1087,8 +1087,8 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
        
        ei_local->irqlock = 1;
 
-       send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
-       
+       send_length = max(length, ETH_ZLEN);
+
        /*
         * We have two Tx slots available for use. Find the first free
         * slot, and then perform some sanity checks. With two Tx bufs,
index 949c6df74c97d18eeada6281d3d2e25f4449fa27..8f328a03847b8340ae02d92bf2060ac5252c7ff7 100644 (file)
@@ -298,7 +298,8 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 static int mfc_try_io_port(struct pcmcia_device *link)
 {
     int i, ret;
-    static const kio_addr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+    static const unsigned int serial_base[5] =
+       { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
 
     for (i = 0; i < 5; i++) {
        link->io.BasePort2 = serial_base[i];
@@ -316,7 +317,7 @@ static int mfc_try_io_port(struct pcmcia_device *link)
 static int ungermann_try_io_port(struct pcmcia_device *link)
 {
     int ret;
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     /*
        Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360
        0x380,0x3c0 only for ioport.
@@ -342,7 +343,7 @@ static int fmvj18x_config(struct pcmcia_device *link)
     cisparse_t parse;
     u_short buf[32];
     int i, last_fn = 0, last_ret = 0, ret;
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     cardtype_t cardtype;
     char *card_name = "unknown";
     u_char *node_id;
@@ -610,7 +611,7 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
     u_char __iomem *base;
     int i, j;
     struct net_device *dev = link->priv;
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
 
     /* Allocate a small memory window */
     req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
@@ -735,7 +736,7 @@ static irqreturn_t fjn_interrupt(int dummy, void *dev_id)
 {
     struct net_device *dev = dev_id;
     local_info_t *lp = netdev_priv(dev);
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     unsigned short tx_stat, rx_stat;
 
     ioaddr = dev->base_addr;
@@ -789,7 +790,7 @@ static irqreturn_t fjn_interrupt(int dummy, void *dev_id)
 static void fjn_tx_timeout(struct net_device *dev)
 {
     struct local_info_t *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     printk(KERN_NOTICE "%s: transmit timed out with status %04x, %s?\n",
           dev->name, htons(inw(ioaddr + TX_STATUS)),
@@ -819,7 +820,7 @@ static void fjn_tx_timeout(struct net_device *dev)
 static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
     struct local_info_t *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     short length = skb->len;
     
     if (length < ETH_ZLEN)
@@ -892,7 +893,7 @@ static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev)
 static void fjn_reset(struct net_device *dev)
 {
     struct local_info_t *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int i;
 
     DEBUG(4, "fjn_reset(%s) called.\n",dev->name);
@@ -971,7 +972,7 @@ static void fjn_reset(struct net_device *dev)
 static void fjn_rx(struct net_device *dev)
 {
     struct local_info_t *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int boguscount = 10;       /* 5 -> 10: by agy 19940922 */
 
     DEBUG(4, "%s: in rx_packet(), rx_status %02x.\n",
@@ -1125,7 +1126,7 @@ static int fjn_close(struct net_device *dev)
 {
     struct local_info_t *lp = netdev_priv(dev);
     struct pcmcia_device *link = lp->p_dev;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     DEBUG(4, "fjn_close('%s').\n", dev->name);
 
@@ -1168,7 +1169,7 @@ static struct net_device_stats *fjn_get_stats(struct net_device *dev)
 
 static void set_rx_mode(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_char mc_filter[8];                /* Multicast hash filter */
     u_long flags;
     int i;
@@ -1197,8 +1198,7 @@ static void set_rx_mode(struct net_device *dev)
        outb(1, ioaddr + RX_MODE);      /* Ignore almost all multicasts. */
     } else {
        struct dev_mc_list *mclist;
-       int i;
-       
+
        memset(mc_filter, 0, sizeof(mc_filter));
        for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
             i++, mclist = mclist->next) {
index a355a93b908b05222e97b992d4b46a04e55810f8..cfcbea9b7e2e374e36e45e986aac3d5d69af4681 100644 (file)
@@ -518,7 +518,7 @@ mace_read
        assuming that during normal operation, the MACE is always in
        bank 0.
 ---------------------------------------------------------------------------- */
-static int mace_read(mace_private *lp, kio_addr_t ioaddr, int reg)
+static int mace_read(mace_private *lp, unsigned int ioaddr, int reg)
 {
   int data = 0xFF;
   unsigned long flags;
@@ -545,7 +545,8 @@ mace_write
        are assuming that during normal operation, the MACE is always in
        bank 0.
 ---------------------------------------------------------------------------- */
-static void mace_write(mace_private *lp, kio_addr_t ioaddr, int reg, int data)
+static void mace_write(mace_private *lp, unsigned int ioaddr, int reg,
+                      int data)
 {
   unsigned long flags;
 
@@ -567,7 +568,7 @@ static void mace_write(mace_private *lp, kio_addr_t ioaddr, int reg, int data)
 mace_init
        Resets the MACE chip.
 ---------------------------------------------------------------------------- */
-static int mace_init(mace_private *lp, kio_addr_t ioaddr, char *enet_addr)
+static int mace_init(mace_private *lp, unsigned int ioaddr, char *enet_addr)
 {
   int i;
   int ct = 0;
@@ -657,7 +658,7 @@ static int nmclan_config(struct pcmcia_device *link)
   tuple_t tuple;
   u_char buf[64];
   int i, last_ret, last_fn;
-  kio_addr_t ioaddr;
+  unsigned int ioaddr;
   DECLARE_MAC_BUF(mac);
 
   DEBUG(0, "nmclan_config(0x%p)\n", link);
@@ -839,7 +840,7 @@ mace_open
 ---------------------------------------------------------------------------- */
 static int mace_open(struct net_device *dev)
 {
-  kio_addr_t ioaddr = dev->base_addr;
+  unsigned int ioaddr = dev->base_addr;
   mace_private *lp = netdev_priv(dev);
   struct pcmcia_device *link = lp->p_dev;
 
@@ -862,7 +863,7 @@ mace_close
 ---------------------------------------------------------------------------- */
 static int mace_close(struct net_device *dev)
 {
-  kio_addr_t ioaddr = dev->base_addr;
+  unsigned int ioaddr = dev->base_addr;
   mace_private *lp = netdev_priv(dev);
   struct pcmcia_device *link = lp->p_dev;
 
@@ -935,7 +936,7 @@ static void mace_tx_timeout(struct net_device *dev)
 static int mace_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
   mace_private *lp = netdev_priv(dev);
-  kio_addr_t ioaddr = dev->base_addr;
+  unsigned int ioaddr = dev->base_addr;
 
   netif_stop_queue(dev);
 
@@ -996,7 +997,7 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id)
 {
   struct net_device *dev = (struct net_device *) dev_id;
   mace_private *lp = netdev_priv(dev);
-  kio_addr_t ioaddr;
+  unsigned int ioaddr;
   int status;
   int IntrCnt = MACE_MAX_IR_ITERATIONS;
 
@@ -1140,7 +1141,7 @@ mace_rx
 static int mace_rx(struct net_device *dev, unsigned char RxCnt)
 {
   mace_private *lp = netdev_priv(dev);
-  kio_addr_t ioaddr = dev->base_addr;
+  unsigned int ioaddr = dev->base_addr;
   unsigned char rx_framecnt;
   unsigned short rx_status;
 
@@ -1302,7 +1303,7 @@ update_stats
        card's SRAM fast enough.  If this happens, something is
        seriously wrong with the hardware.
 ---------------------------------------------------------------------------- */
-static void update_stats(kio_addr_t ioaddr, struct net_device *dev)
+static void update_stats(unsigned int ioaddr, struct net_device *dev)
 {
   mace_private *lp = netdev_priv(dev);
 
@@ -1448,7 +1449,7 @@ static void restore_multicast_list(struct net_device *dev)
   mace_private *lp = netdev_priv(dev);
   int num_addrs = lp->multicast_num_addrs;
   int *ladrf = lp->multicast_ladrf;
-  kio_addr_t ioaddr = dev->base_addr;
+  unsigned int ioaddr = dev->base_addr;
   int i;
 
   DEBUG(2, "%s: restoring Rx mode to %d addresses.\n",
@@ -1540,7 +1541,7 @@ static void set_multicast_list(struct net_device *dev)
 
 static void restore_multicast_list(struct net_device *dev)
 {
-  kio_addr_t ioaddr = dev->base_addr;
+  unsigned int ioaddr = dev->base_addr;
   mace_private *lp = netdev_priv(dev);
 
   DEBUG(2, "%s: restoring Rx mode to %d addresses.\n", dev->name,
index 9ba56aa26a1b2326f8a684b1c68166297e781185..6323988dfa1d162423839f5805fda55de61aab00 100644 (file)
@@ -349,7 +349,7 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
 static hw_info_t *get_prom(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_char prom[32];
     int i, j;
 
@@ -425,7 +425,7 @@ static hw_info_t *get_dl10019(struct pcmcia_device *link)
 static hw_info_t *get_ax88190(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int i, j;
 
     /* Not much of a test, but the alternatives are messy */
@@ -521,7 +521,7 @@ static int pcnet_config(struct pcmcia_device *link)
     int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
     int has_shmem = 0;
     u_short buf[64];
-    hw_info_t *hw_info;
+    hw_info_t *local_hw_info;
     DECLARE_MAC_BUF(mac);
 
     DEBUG(0, "pcnet_config(0x%p)\n", link);
@@ -590,23 +590,23 @@ static int pcnet_config(struct pcmcia_device *link)
        dev->if_port = 0;
     }
 
-    hw_info = get_hwinfo(link);
-    if (hw_info == NULL)
-       hw_info = get_prom(link);
-    if (hw_info == NULL)
-       hw_info = get_dl10019(link);
-    if (hw_info == NULL)
-       hw_info = get_ax88190(link);
-    if (hw_info == NULL)
-       hw_info = get_hwired(link);
-
-    if (hw_info == NULL) {
+    local_hw_info = get_hwinfo(link);
+    if (local_hw_info == NULL)
+       local_hw_info = get_prom(link);
+    if (local_hw_info == NULL)
+       local_hw_info = get_dl10019(link);
+    if (local_hw_info == NULL)
+       local_hw_info = get_ax88190(link);
+    if (local_hw_info == NULL)
+       local_hw_info = get_hwired(link);
+
+    if (local_hw_info == NULL) {
        printk(KERN_NOTICE "pcnet_cs: unable to read hardware net"
               " address for io base %#3lx\n", dev->base_addr);
        goto failed;
     }
 
-    info->flags = hw_info->flags;
+    info->flags = local_hw_info->flags;
     /* Check for user overrides */
     info->flags |= (delay_output) ? DELAY_OUTPUT : 0;
     if ((link->manf_id == MANFID_SOCKET) &&
@@ -756,7 +756,7 @@ static int pcnet_resume(struct pcmcia_device *link)
 #define MDIO_DATA_READ         0x10
 #define MDIO_MASK              0x0f
 
-static void mdio_sync(kio_addr_t addr)
+static void mdio_sync(unsigned int addr)
 {
     int bits, mask = inb(addr) & MDIO_MASK;
     for (bits = 0; bits < 32; bits++) {
@@ -765,7 +765,7 @@ static void mdio_sync(kio_addr_t addr)
     }
 }
 
-static int mdio_read(kio_addr_t addr, int phy_id, int loc)
+static int mdio_read(unsigned int addr, int phy_id, int loc)
 {
     u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
     int i, retval = 0, mask = inb(addr) & MDIO_MASK;
@@ -784,7 +784,7 @@ static int mdio_read(kio_addr_t addr, int phy_id, int loc)
     return (retval>>1) & 0xffff;
 }
 
-static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value)
+static void mdio_write(unsigned int addr, int phy_id, int loc, int value)
 {
     u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
     int i, mask = inb(addr) & MDIO_MASK;
@@ -818,10 +818,10 @@ static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value)
 
 #define DL19FDUPLX     0x0400  /* DL10019 Full duplex mode */
 
-static int read_eeprom(kio_addr_t ioaddr, int location)
+static int read_eeprom(unsigned int ioaddr, int location)
 {
     int i, retval = 0;
-    kio_addr_t ee_addr = ioaddr + DLINK_EEPROM;
+    unsigned int ee_addr = ioaddr + DLINK_EEPROM;
     int read_cmd = location | (EE_READ_CMD << 8);
 
     outb(0, ee_addr);
@@ -852,10 +852,10 @@ static int read_eeprom(kio_addr_t ioaddr, int location)
     In ASIC mode, EE_ADOT is used to output the data to the ASIC.
 */
 
-static void write_asic(kio_addr_t ioaddr, int location, short asic_data)
+static void write_asic(unsigned int ioaddr, int location, short asic_data)
 {
        int i;
-       kio_addr_t ee_addr = ioaddr + DLINK_EEPROM;
+       unsigned int ee_addr = ioaddr + DLINK_EEPROM;
        short dataval;
        int read_cmd = location | (EE_READ_CMD << 8);
 
@@ -897,7 +897,7 @@ static void write_asic(kio_addr_t ioaddr, int location, short asic_data)
 
 static void set_misc_reg(struct net_device *dev)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
     pcnet_dev_t *info = PRIV(dev);
     u_char tmp;
 
@@ -936,7 +936,7 @@ static void set_misc_reg(struct net_device *dev)
 static void mii_phy_probe(struct net_device *dev)
 {
     pcnet_dev_t *info = PRIV(dev);
-    kio_addr_t mii_addr = dev->base_addr + DLINK_GPIO;
+    unsigned int mii_addr = dev->base_addr + DLINK_GPIO;
     int i;
     u_int tmp, phyid;
 
@@ -1014,7 +1014,7 @@ static int pcnet_close(struct net_device *dev)
 
 static void pcnet_reset_8390(struct net_device *dev)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
     int i;
 
     ei_status.txing = ei_status.dmaing = 0;
@@ -1074,8 +1074,8 @@ static void ei_watchdog(u_long arg)
 {
     struct net_device *dev = (struct net_device *)arg;
     pcnet_dev_t *info = PRIV(dev);
-    kio_addr_t nic_base = dev->base_addr;
-    kio_addr_t mii_addr = nic_base + DLINK_GPIO;
+    unsigned int nic_base = dev->base_addr;
+    unsigned int mii_addr = nic_base + DLINK_GPIO;
     u_short link;
 
     if (!netif_device_present(dev)) goto reschedule;
@@ -1177,7 +1177,7 @@ static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
     pcnet_dev_t *info = PRIV(dev);
     u16 *data = (u16 *)&rq->ifr_ifru;
-    kio_addr_t mii_addr = dev->base_addr + DLINK_GPIO;
+    unsigned int mii_addr = dev->base_addr + DLINK_GPIO;
     switch (cmd) {
     case SIOCGMIIPHY:
        data[0] = info->phy_id;
@@ -1199,7 +1199,7 @@ static void dma_get_8390_hdr(struct net_device *dev,
                             struct e8390_pkt_hdr *hdr,
                             int ring_page)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
 
     if (ei_status.dmaing) {
        printk(KERN_NOTICE "%s: DMAing conflict in dma_block_input."
@@ -1230,7 +1230,7 @@ static void dma_get_8390_hdr(struct net_device *dev,
 static void dma_block_input(struct net_device *dev, int count,
                            struct sk_buff *skb, int ring_offset)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
     int xfer_count = count;
     char *buf = skb->data;
 
@@ -1285,7 +1285,7 @@ static void dma_block_input(struct net_device *dev, int count,
 static void dma_block_output(struct net_device *dev, int count,
                             const u_char *buf, const int start_page)
 {
-    kio_addr_t nic_base = dev->base_addr;
+    unsigned int nic_base = dev->base_addr;
     pcnet_dev_t *info = PRIV(dev);
 #ifdef PCMCIA_DEBUG
     int retries = 0;
index c9868e9dac4caa70675f9367498e93dc8a63ae99..f18eca9831e88f8169ad944d7e8f363cd5b26300 100644 (file)
@@ -295,7 +295,7 @@ static int s9k_config(struct net_device *dev, struct ifmap *map);
 static void smc_set_xcvr(struct net_device *dev, int if_port);
 static void smc_reset(struct net_device *dev);
 static void media_check(u_long arg);
-static void mdio_sync(kio_addr_t addr);
+static void mdio_sync(unsigned int addr);
 static int mdio_read(struct net_device *dev, int phy_id, int loc);
 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
 static int smc_link_ok(struct net_device *dev);
@@ -601,8 +601,8 @@ static void mot_config(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
-    kio_addr_t iouart = link->io.BasePort2;
+    unsigned int ioaddr = dev->base_addr;
+    unsigned int iouart = link->io.BasePort2;
 
     /* Set UART base address and force map with COR bit 1 */
     writeb(iouart & 0xff,        smc->base + MOT_UART + CISREG_IOBASE_0);
@@ -621,7 +621,7 @@ static void mot_config(struct pcmcia_device *link)
 static int mot_setup(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int i, wait, loop;
     u_int addr;
 
@@ -754,7 +754,7 @@ free_cfg_mem:
 static int osi_config(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    static const kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
+    static const unsigned int com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
     int i, j;
 
     link->conf.Attributes |= CONF_ENABLE_SPKR;
@@ -900,7 +900,7 @@ static int smc91c92_resume(struct pcmcia_device *link)
 static int check_sig(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int width;
     u_short s;
 
@@ -960,7 +960,7 @@ static int smc91c92_config(struct pcmcia_device *link)
     struct smc_private *smc = netdev_priv(dev);
     char *name;
     int i, j, rev;
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     u_long mir;
     DECLARE_MAC_BUF(mac);
 
@@ -1136,7 +1136,7 @@ static void smc91c92_release(struct pcmcia_device *link)
 #define MDIO_DATA_WRITE1       (MDIO_DIR_WRITE | MDIO_DATA_OUT)
 #define MDIO_DATA_READ         0x02
 
-static void mdio_sync(kio_addr_t addr)
+static void mdio_sync(unsigned int addr)
 {
     int bits;
     for (bits = 0; bits < 32; bits++) {
@@ -1147,7 +1147,7 @@ static void mdio_sync(kio_addr_t addr)
 
 static int mdio_read(struct net_device *dev, int phy_id, int loc)
 {
-    kio_addr_t addr = dev->base_addr + MGMT;
+    unsigned int addr = dev->base_addr + MGMT;
     u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
     int i, retval = 0;
 
@@ -1167,7 +1167,7 @@ static int mdio_read(struct net_device *dev, int phy_id, int loc)
 
 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
 {
-    kio_addr_t addr = dev->base_addr + MGMT;
+    unsigned int addr = dev->base_addr + MGMT;
     u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
     int i;
 
@@ -1193,7 +1193,7 @@ static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
 #ifdef PCMCIA_DEBUG
 static void smc_dump(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_short i, w, save;
     save = inw(ioaddr + BANK_SELECT);
     for (w = 0; w < 4; w++) {
@@ -1248,7 +1248,7 @@ static int smc_close(struct net_device *dev)
 {
     struct smc_private *smc = netdev_priv(dev);
     struct pcmcia_device *link = smc->p_dev;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     DEBUG(0, "%s: smc_close(), status %4.4x.\n",
          dev->name, inw(ioaddr + BANK_SELECT));
@@ -1285,7 +1285,7 @@ static void smc_hardware_send_packet(struct net_device * dev)
 {
     struct smc_private *smc = netdev_priv(dev);
     struct sk_buff *skb = smc->saved_skb;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_char packet_no;
 
     if (!skb) {
@@ -1349,7 +1349,7 @@ static void smc_hardware_send_packet(struct net_device * dev)
 static void smc_tx_timeout(struct net_device *dev)
 {
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
           "Tx_status %2.2x status %4.4x.\n",
@@ -1364,7 +1364,7 @@ static void smc_tx_timeout(struct net_device *dev)
 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_short num_pages;
     short time_out, ir;
     unsigned long flags;
@@ -1434,7 +1434,7 @@ static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
 static void smc_tx_err(struct net_device * dev)
 {
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
     int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
     int tx_status;
@@ -1478,7 +1478,7 @@ static void smc_tx_err(struct net_device * dev)
 static void smc_eph_irq(struct net_device *dev)
 {
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_short card_stats, ephs;
 
     SMC_SELECT_BANK(0);
@@ -1513,7 +1513,7 @@ static irqreturn_t smc_interrupt(int irq, void *dev_id)
 {
     struct net_device *dev = dev_id;
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     u_short saved_bank, saved_pointer, mask, status;
     unsigned int handled = 1;
     char bogus_cnt = INTR_WORK;                /* Work we are willing to do. */
@@ -1633,7 +1633,7 @@ irq_done:
 static void smc_rx(struct net_device *dev)
 {
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int rx_status;
     int packet_length; /* Caution: not frame length, rather words
                           to transfer from the chip. */
@@ -1738,7 +1738,7 @@ static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
 
 static void set_rx_mode(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     struct smc_private *smc = netdev_priv(dev);
     u_int multicast_table[ 2 ] = { 0, };
     unsigned long flags;
@@ -1804,7 +1804,7 @@ static int s9k_config(struct net_device *dev, struct ifmap *map)
 static void smc_set_xcvr(struct net_device *dev, int if_port)
 {
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_short saved_bank;
 
     saved_bank = inw(ioaddr + BANK_SELECT);
@@ -1827,7 +1827,7 @@ static void smc_set_xcvr(struct net_device *dev, int if_port)
 
 static void smc_reset(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     struct smc_private *smc = netdev_priv(dev);
     int i;
 
@@ -1904,7 +1904,7 @@ static void media_check(u_long arg)
 {
     struct net_device *dev = (struct net_device *) arg;
     struct smc_private *smc = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u_short i, media, saved_bank;
     u_short link;
     unsigned long flags;
@@ -2021,7 +2021,7 @@ reschedule:
 
 static int smc_link_ok(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     struct smc_private *smc = netdev_priv(dev);
 
     if (smc->cfg & CFG_MII_SELECT) {
@@ -2035,7 +2035,7 @@ static int smc_link_ok(struct net_device *dev)
 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
 {
     u16 tmp;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
        SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
@@ -2057,7 +2057,7 @@ static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
 {
     u16 tmp;
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     if (ecmd->speed != SPEED_10)
        return -EINVAL;
@@ -2100,7 +2100,7 @@ static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
 static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 {
        struct smc_private *smc = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        u16 saved_bank = inw(ioaddr + BANK_SELECT);
        int ret;
 
@@ -2118,7 +2118,7 @@ static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 {
        struct smc_private *smc = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        u16 saved_bank = inw(ioaddr + BANK_SELECT);
        int ret;
 
@@ -2136,7 +2136,7 @@ static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 static u32 smc_get_link(struct net_device *dev)
 {
        struct smc_private *smc = netdev_priv(dev);
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
        u16 saved_bank = inw(ioaddr + BANK_SELECT);
        u32 ret;
 
@@ -2164,7 +2164,7 @@ static int smc_nway_reset(struct net_device *dev)
 {
        struct smc_private *smc = netdev_priv(dev);
        if (smc->cfg & CFG_MII_SELECT) {
-               kio_addr_t ioaddr = dev->base_addr;
+               unsigned int ioaddr = dev->base_addr;
                u16 saved_bank = inw(ioaddr + BANK_SELECT);
                int res;
 
@@ -2196,7 +2196,7 @@ static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
        struct mii_ioctl_data *mii = if_mii(rq);
        int rc = 0;
        u16 saved_bank;
-       kio_addr_t ioaddr = dev->base_addr;
+       unsigned int ioaddr = dev->base_addr;
 
        if (!netif_running(dev))
                return -EINVAL;
index 1f09bea6db5ab8024c87f6dc37ff13a1707f3a2d..d041f831a18d7d392f426b3dde3c75576bc30158 100644 (file)
@@ -273,12 +273,12 @@ INT_MODULE_PARM(lockup_hack,      0);  /* anti lockup hack */
 static unsigned maxrx_bytes = 22000;
 
 /* MII management prototypes */
-static void mii_idle(kio_addr_t ioaddr);
-static void mii_putbit(kio_addr_t ioaddr, unsigned data);
-static int  mii_getbit(kio_addr_t ioaddr);
-static void mii_wbits(kio_addr_t ioaddr, unsigned data, int len);
-static unsigned mii_rd(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg);
-static void mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg,
+static void mii_idle(unsigned int ioaddr);
+static void mii_putbit(unsigned int ioaddr, unsigned data);
+static int  mii_getbit(unsigned int ioaddr);
+static void mii_wbits(unsigned int ioaddr, unsigned data, int len);
+static unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg);
+static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg,
                   unsigned data, int len);
 
 /*
@@ -403,7 +403,7 @@ next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
 static void
 PrintRegisters(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     if (pc_debug > 1) {
        int i, page;
@@ -439,7 +439,7 @@ PrintRegisters(struct net_device *dev)
  * Turn around for read
  */
 static void
-mii_idle(kio_addr_t ioaddr)
+mii_idle(unsigned int ioaddr)
 {
     PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
     udelay(1);
@@ -451,7 +451,7 @@ mii_idle(kio_addr_t ioaddr)
  * Write a bit to MDI/O
  */
 static void
-mii_putbit(kio_addr_t ioaddr, unsigned data)
+mii_putbit(unsigned int ioaddr, unsigned data)
 {
   #if 1
     if (data) {
@@ -484,7 +484,7 @@ mii_putbit(kio_addr_t ioaddr, unsigned data)
  * Get a bit from MDI/O
  */
 static int
-mii_getbit(kio_addr_t ioaddr)
+mii_getbit(unsigned int ioaddr)
 {
     unsigned d;
 
@@ -497,7 +497,7 @@ mii_getbit(kio_addr_t ioaddr)
 }
 
 static void
-mii_wbits(kio_addr_t ioaddr, unsigned data, int len)
+mii_wbits(unsigned int ioaddr, unsigned data, int len)
 {
     unsigned m = 1 << (len-1);
     for (; m; m >>= 1)
@@ -505,7 +505,7 @@ mii_wbits(kio_addr_t ioaddr, unsigned data, int len)
 }
 
 static unsigned
-mii_rd(kio_addr_t ioaddr,      u_char phyaddr, u_char phyreg)
+mii_rd(unsigned int ioaddr,    u_char phyaddr, u_char phyreg)
 {
     int i;
     unsigned data=0, m;
@@ -527,7 +527,8 @@ mii_rd(kio_addr_t ioaddr,   u_char phyaddr, u_char phyreg)
 }
 
 static void
-mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len)
+mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, unsigned data,
+       int len)
 {
     int i;
 
@@ -726,7 +727,7 @@ xirc2ps_config(struct pcmcia_device * link)
     local_info_t *local = netdev_priv(dev);
     tuple_t tuple;
     cisparse_t parse;
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     int err, i;
     u_char buf[64];
     cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
@@ -1104,7 +1105,7 @@ xirc2ps_interrupt(int irq, void *dev_id)
 {
     struct net_device *dev = (struct net_device *)dev_id;
     local_info_t *lp = netdev_priv(dev);
-    kio_addr_t ioaddr;
+    unsigned int ioaddr;
     u_char saved_page;
     unsigned bytes_rcvd;
     unsigned int_status, eth_status, rx_status, tx_status;
@@ -1209,7 +1210,7 @@ xirc2ps_interrupt(int irq, void *dev_id)
                    unsigned i;
                    u_long *p = skb_put(skb, pktlen);
                    register u_long a;
-                   kio_addr_t edpreg = ioaddr+XIRCREG_EDP-2;
+                   unsigned int edpreg = ioaddr+XIRCREG_EDP-2;
                    for (i=0; i < len ; i += 4, p++) {
                        a = inl(edpreg);
                        __asm__("rorl $16,%0\n\t"
@@ -1346,7 +1347,7 @@ static int
 do_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
     local_info_t *lp = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     int okay;
     unsigned freespace;
     unsigned pktlen = skb->len;
@@ -1415,7 +1416,7 @@ do_get_stats(struct net_device *dev)
 static void
 set_addresses(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     local_info_t *lp = netdev_priv(dev);
     struct dev_mc_list *dmi = dev->mc_list;
     unsigned char *addr;
@@ -1459,7 +1460,7 @@ set_addresses(struct net_device *dev)
 static void
 set_multicast_list(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     SelectPage(0x42);
     if (dev->flags & IFF_PROMISC) { /* snoop */
@@ -1543,7 +1544,7 @@ static int
 do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
     local_info_t *local = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     u16 *data = (u16 *)&rq->ifr_ifru;
 
     DEBUG(1, "%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
@@ -1575,7 +1576,7 @@ static void
 hardreset(struct net_device *dev)
 {
     local_info_t *local = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     SelectPage(4);
     udelay(1);
@@ -1592,7 +1593,7 @@ static void
 do_reset(struct net_device *dev, int full)
 {
     local_info_t *local = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     unsigned value;
 
     DEBUG(0, "%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
@@ -1753,7 +1754,7 @@ static int
 init_mii(struct net_device *dev)
 {
     local_info_t *local = netdev_priv(dev);
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     unsigned control, status, linkpartner;
     int i;
 
@@ -1826,7 +1827,7 @@ static void
 do_powerdown(struct net_device *dev)
 {
 
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
 
     DEBUG(0, "do_powerdown(%p)\n", dev);
 
@@ -1838,7 +1839,7 @@ do_powerdown(struct net_device *dev)
 static int
 do_stop(struct net_device *dev)
 {
-    kio_addr_t ioaddr = dev->base_addr;
+    unsigned int ioaddr = dev->base_addr;
     local_info_t *lp = netdev_priv(dev);
     struct pcmcia_device *link = lp->p_dev;
 
index 7fe03ce774b1e99d4c07f3b877f6a8a7d3d06841..f4ca0591231d233f63a2d98cb6036f106fde21c4 100644 (file)
@@ -60,6 +60,11 @@ config ICPLUS_PHY
        ---help---
          Currently supports the IP175C PHY.
 
+config REALTEK_PHY
+       tristate "Drivers for Realtek PHYs"
+       ---help---
+         Supports the Realtek 821x PHY.
+
 config FIXED_PHY
        bool "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
        ---help---
index 3d6cc7b67a800f209fc26b354a69c2eba3e8501c..5997d6ef702b979742d30642099411bb6aea815c 100644 (file)
@@ -12,5 +12,6 @@ obj-$(CONFIG_SMSC_PHY)                += smsc.o
 obj-$(CONFIG_VITESSE_PHY)      += vitesse.o
 obj-$(CONFIG_BROADCOM_PHY)     += broadcom.o
 obj-$(CONFIG_ICPLUS_PHY)       += icplus.o
+obj-$(CONFIG_REALTEK_PHY)      += realtek.o
 obj-$(CONFIG_FIXED_PHY)                += fixed.o
 obj-$(CONFIG_MDIO_BITBANG)     += mdio-bitbang.o
index 29666c85ed55936683e4cfc4b7dc0a1f03efb8dd..5b80358af65840926a1de33d4517e41396d6f835 100644 (file)
@@ -141,6 +141,20 @@ static struct phy_driver bcm5461_driver = {
        .driver         = { .owner = THIS_MODULE },
 };
 
+static struct phy_driver bcm5482_driver = {
+    .phy_id            = 0x0143bcb0,
+       .phy_id_mask    = 0xfffffff0,
+       .name           = "Broadcom BCM5482",
+       .features       = PHY_GBIT_FEATURES,
+       .flags          = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
+       .config_init    = bcm54xx_config_init,
+       .config_aneg    = genphy_config_aneg,
+       .read_status    = genphy_read_status,
+       .ack_interrupt  = bcm54xx_ack_interrupt,
+       .config_intr    = bcm54xx_config_intr,
+       .driver         = { .owner = THIS_MODULE },
+};
+
 static int __init broadcom_init(void)
 {
        int ret;
@@ -154,8 +168,13 @@ static int __init broadcom_init(void)
        ret = phy_driver_register(&bcm5461_driver);
        if (ret)
                goto out_5461;
+       ret = phy_driver_register(&bcm5482_driver);
+       if (ret)
+               goto out_5482;
        return ret;
 
+out_5482:
+       phy_driver_unregister(&bcm5461_driver);
 out_5461:
        phy_driver_unregister(&bcm5421_driver);
 out_5421:
@@ -166,6 +185,7 @@ out_5411:
 
 static void __exit broadcom_exit(void)
 {
+       phy_driver_unregister(&bcm5482_driver);
        phy_driver_unregister(&bcm5461_driver);
        phy_driver_unregister(&bcm5421_driver);
        phy_driver_unregister(&bcm5411_driver);
index c30196d0ad1681de95f5c14df66d8568c1200bd9..6e9f619c491f74837a7f356943683094169e28bf 100644 (file)
@@ -49,7 +49,7 @@ int mdiobus_register(struct mii_bus *bus)
        int i;
        int err = 0;
 
-       spin_lock_init(&bus->mdio_lock);
+       mutex_init(&bus->mdio_lock);
 
        if (NULL == bus || NULL == bus->name ||
                        NULL == bus->read ||
index 7c9e6e349503eaf2a7b91448a05a73d19e499bb8..12fccb1c76dc0c147e3291aaad803c8d5dbc9caf 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
-#include <linux/spinlock.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/mii.h>
@@ -72,9 +71,11 @@ int phy_read(struct phy_device *phydev, u16 regnum)
        int retval;
        struct mii_bus *bus = phydev->bus;
 
-       spin_lock_bh(&bus->mdio_lock);
+       BUG_ON(in_interrupt());
+
+       mutex_lock(&bus->mdio_lock);
        retval = bus->read(bus, phydev->addr, regnum);
-       spin_unlock_bh(&bus->mdio_lock);
+       mutex_unlock(&bus->mdio_lock);
 
        return retval;
 }
@@ -95,9 +96,11 @@ int phy_write(struct phy_device *phydev, u16 regnum, u16 val)
        int err;
        struct mii_bus *bus = phydev->bus;
 
-       spin_lock_bh(&bus->mdio_lock);
+       BUG_ON(in_interrupt());
+
+       mutex_lock(&bus->mdio_lock);
        err = bus->write(bus, phydev->addr, regnum, val);
-       spin_unlock_bh(&bus->mdio_lock);
+       mutex_unlock(&bus->mdio_lock);
 
        return err;
 }
@@ -428,7 +431,7 @@ int phy_start_aneg(struct phy_device *phydev)
 {
        int err;
 
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
 
        if (AUTONEG_DISABLE == phydev->autoneg)
                phy_sanitize_settings(phydev);
@@ -449,13 +452,14 @@ int phy_start_aneg(struct phy_device *phydev)
        }
 
 out_unlock:
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
        return err;
 }
 EXPORT_SYMBOL(phy_start_aneg);
 
 
 static void phy_change(struct work_struct *work);
+static void phy_state_machine(struct work_struct *work);
 static void phy_timer(unsigned long data);
 
 /**
@@ -476,6 +480,7 @@ void phy_start_machine(struct phy_device *phydev,
 {
        phydev->adjust_state = handler;
 
+       INIT_WORK(&phydev->state_queue, phy_state_machine);
        init_timer(&phydev->phy_timer);
        phydev->phy_timer.function = &phy_timer;
        phydev->phy_timer.data = (unsigned long) phydev;
@@ -493,11 +498,12 @@ void phy_start_machine(struct phy_device *phydev,
 void phy_stop_machine(struct phy_device *phydev)
 {
        del_timer_sync(&phydev->phy_timer);
+       cancel_work_sync(&phydev->state_queue);
 
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
        if (phydev->state > PHY_UP)
                phydev->state = PHY_UP;
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 
        phydev->adjust_state = NULL;
 }
@@ -541,9 +547,9 @@ static void phy_force_reduction(struct phy_device *phydev)
  */
 void phy_error(struct phy_device *phydev)
 {
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
        phydev->state = PHY_HALTED;
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 }
 
 /**
@@ -705,10 +711,10 @@ static void phy_change(struct work_struct *work)
        if (err)
                goto phy_err;
 
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
        if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state))
                phydev->state = PHY_CHANGELINK;
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 
        atomic_dec(&phydev->irq_disable);
        enable_irq(phydev->irq);
@@ -735,7 +741,7 @@ phy_err:
  */
 void phy_stop(struct phy_device *phydev)
 {
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
 
        if (PHY_HALTED == phydev->state)
                goto out_unlock;
@@ -751,7 +757,7 @@ void phy_stop(struct phy_device *phydev)
        phydev->state = PHY_HALTED;
 
 out_unlock:
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 
        /*
         * Cannot call flush_scheduled_work() here as desired because
@@ -773,7 +779,7 @@ out_unlock:
  */
 void phy_start(struct phy_device *phydev)
 {
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
 
        switch (phydev->state) {
                case PHY_STARTING:
@@ -787,19 +793,26 @@ void phy_start(struct phy_device *phydev)
                default:
                        break;
        }
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 }
 EXPORT_SYMBOL(phy_stop);
 EXPORT_SYMBOL(phy_start);
 
-/* PHY timer which handles the state machine */
-static void phy_timer(unsigned long data)
+/**
+ * phy_state_machine - Handle the state machine
+ * @work: work_struct that describes the work to be done
+ *
+ * Description: Scheduled by the state_queue workqueue each time
+ *   phy_timer is triggered.
+ */
+static void phy_state_machine(struct work_struct *work)
 {
-       struct phy_device *phydev = (struct phy_device *)data;
+       struct phy_device *phydev =
+                       container_of(work, struct phy_device, state_queue);
        int needs_aneg = 0;
        int err = 0;
 
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
 
        if (phydev->adjust_state)
                phydev->adjust_state(phydev->attached_dev);
@@ -965,7 +978,7 @@ static void phy_timer(unsigned long data)
                        break;
        }
 
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 
        if (needs_aneg)
                err = phy_start_aneg(phydev);
@@ -976,3 +989,14 @@ static void phy_timer(unsigned long data)
        mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ);
 }
 
+/* PHY timer which schedules the state machine work */
+static void phy_timer(unsigned long data)
+{
+       struct phy_device *phydev = (struct phy_device *)data;
+
+       /*
+        * PHY I/O operations can potentially sleep so we ensure that
+        * it's done from a process context
+        */
+       schedule_work(&phydev->state_queue);
+}
index 5b9e1751e1b414fc0e50a99b13e0770cf69811a0..f4c4fd85425f6807bf8258da78cb14bb7ee7bd35 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
-#include <linux/spinlock.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/mii.h>
@@ -80,7 +79,7 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
 
        dev->state = PHY_DOWN;
 
-       spin_lock_init(&dev->lock);
+       mutex_init(&dev->lock);
 
        return dev;
 }
@@ -656,7 +655,7 @@ static int phy_probe(struct device *dev)
        if (!(phydrv->flags & PHY_HAS_INTERRUPT))
                phydev->irq = PHY_POLL;
 
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
 
        /* Start out supporting everything. Eventually,
         * a controller will attach, and may modify one
@@ -670,7 +669,7 @@ static int phy_probe(struct device *dev)
        if (phydev->drv->probe)
                err = phydev->drv->probe(phydev);
 
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 
        return err;
 
@@ -682,9 +681,9 @@ static int phy_remove(struct device *dev)
 
        phydev = to_phy_device(dev);
 
-       spin_lock_bh(&phydev->lock);
+       mutex_lock(&phydev->lock);
        phydev->state = PHY_DOWN;
-       spin_unlock_bh(&phydev->lock);
+       mutex_unlock(&phydev->lock);
 
        if (phydev->drv->remove)
                phydev->drv->remove(phydev);
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
new file mode 100644 (file)
index 0000000..a052a67
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * drivers/net/phy/realtek.c
+ *
+ * Driver for Realtek PHYs
+ *
+ * Author: Johnson Leung <r58129@freescale.com>
+ *
+ * Copyright (c) 2004 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ *
+ */
+#include <linux/phy.h>
+
+#define RTL821x_PHYSR          0x11
+#define RTL821x_PHYSR_DUPLEX   0x2000
+#define RTL821x_PHYSR_SPEED    0xc000
+#define RTL821x_INER           0x12
+#define RTL821x_INER_INIT      0x6400
+#define RTL821x_INSR           0x13
+
+MODULE_DESCRIPTION("Realtek PHY driver");
+MODULE_AUTHOR("Johnson Leung");
+MODULE_LICENSE("GPL");
+
+static int rtl821x_ack_interrupt(struct phy_device *phydev)
+{
+       int err;
+
+       err = phy_read(phydev, RTL821x_INSR);
+
+       return (err < 0) ? err : 0;
+}
+
+static int rtl821x_config_intr(struct phy_device *phydev)
+{
+       int err;
+
+       if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+               err = phy_write(phydev, RTL821x_INER,
+                               RTL821x_INER_INIT);
+       else
+               err = phy_write(phydev, RTL821x_INER, 0);
+
+       return err;
+}
+
+/* RTL8211B */
+static struct phy_driver rtl821x_driver = {
+       .phy_id         = 0x001cc912,
+       .name           = "RTL821x Gigabit Ethernet",
+       .phy_id_mask    = 0x001fffff,
+       .features       = PHY_GBIT_FEATURES,
+       .flags          = PHY_HAS_INTERRUPT,
+       .config_aneg    = &genphy_config_aneg,
+       .read_status    = &genphy_read_status,
+       .ack_interrupt  = &rtl821x_ack_interrupt,
+       .config_intr    = &rtl821x_config_intr,
+       .driver         = { .owner = THIS_MODULE,},
+};
+
+static int __init realtek_init(void)
+{
+       int ret;
+
+       ret = phy_driver_register(&rtl821x_driver);
+
+       return ret;
+}
+
+static void __exit realtek_exit(void)
+{
+       phy_driver_unregister(&rtl821x_driver);
+}
+
+module_init(realtek_init);
+module_exit(realtek_exit);
index 1b51bb668d39ac2fb6ecb8b44a3797f06556eea3..5aa0a80896945c994ec574e0c5cb8d035eda5466 100644 (file)
@@ -2468,9 +2468,10 @@ static int __init pppol2tp_init(void)
 
 out:
        return err;
-
+#ifdef CONFIG_PROC_FS
 out_unregister_pppox_proto:
        unregister_pppox_proto(PX_PROTO_OL2TP);
+#endif
 out_unregister_pppol2tp_proto:
        proto_unregister(&pppol2tp_sk_proto);
        goto out;
index 5fab7d7b5d74a430dd9e72870ba347fa38d07f47..6179a0a2032c0ec50681d8f02bb5a693baf6b8d4 100644 (file)
@@ -8118,7 +8118,7 @@ static void initiate_new_session(struct lro *lro, u8 *l2h,
        lro->iph = ip;
        lro->tcph = tcp;
        lro->tcp_next_seq = tcp_pyld_len + ntohl(tcp->seq);
-       lro->tcp_ack = ntohl(tcp->ack_seq);
+       lro->tcp_ack = tcp->ack_seq;
        lro->sg_num = 1;
        lro->total_len = ntohs(ip->tot_len);
        lro->frags_len = 0;
@@ -8127,10 +8127,10 @@ static void initiate_new_session(struct lro *lro, u8 *l2h,
         * already been done.
         */
        if (tcp->doff == 8) {
-               u32 *ptr;
-               ptr = (u32 *)(tcp+1);
+               __be32 *ptr;
+               ptr = (__be32 *)(tcp+1);
                lro->saw_ts = 1;
-               lro->cur_tsval = *(ptr+1);
+               lro->cur_tsval = ntohl(*(ptr+1));
                lro->cur_tsecr = *(ptr+2);
        }
        lro->in_use = 1;
@@ -8156,7 +8156,7 @@ static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro)
 
        /* Update tsecr field if this session has timestamps enabled */
        if (lro->saw_ts) {
-               u32 *ptr = (u32 *)(tcp + 1);
+               __be32 *ptr = (__be32 *)(tcp + 1);
                *(ptr+2) = lro->cur_tsecr;
        }
 
@@ -8181,10 +8181,10 @@ static void aggregate_new_rx(struct lro *lro, struct iphdr *ip,
        lro->window = tcp->window;
 
        if (lro->saw_ts) {
-               u32 *ptr;
+               __be32 *ptr;
                /* Update tsecr and tsval from this packet */
-               ptr = (u32 *) (tcp + 1);
-               lro->cur_tsval = *(ptr + 1);
+               ptr = (__be32 *)(tcp+1);
+               lro->cur_tsval = ntohl(*(ptr+1));
                lro->cur_tsecr = *(ptr + 2);
        }
 }
@@ -8235,11 +8235,11 @@ static int verify_l3_l4_lro_capable(struct lro *l_lro, struct iphdr *ip,
 
                /* Ensure timestamp value increases monotonically */
                if (l_lro)
-                       if (l_lro->cur_tsval > *((u32 *)(ptr+2)))
+                       if (l_lro->cur_tsval > ntohl(*((__be32 *)(ptr+2))))
                                return -1;
 
                /* timestamp echo reply should be non-zero */
-               if (*((u32 *)(ptr+6)) == 0)
+               if (*((__be32 *)(ptr+6)) == 0)
                        return -1;
        }
 
index 9f6016c6f135a1fc9c7336bf8fd0df4ebba98b76..64b88eb48287d2d583897af67889e6474beebaa6 100644 (file)
@@ -809,7 +809,7 @@ struct lro {
        int             in_use;
        __be16          window;
        u32             cur_tsval;
-       u32             cur_tsecr;
+       __be32          cur_tsecr;
        u8              saw_ts;
 };
 
index b570402f7feda2a06fc975a5aaf82e19b1f45432..2e9e88be7b33f59558a06a22f06fee363805755d 100644 (file)
@@ -326,7 +326,7 @@ static const struct {
        { "SiS 191 PCI Gigabit Ethernet adapter" },
 };
 
-static struct pci_device_id sis190_pci_tbl[] __devinitdata = {
+static struct pci_device_id sis190_pci_tbl[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0190), 0, 0, 0 },
        { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0191), 0, 0, 1 },
        { 0, },
index 62b01328c496c4e3678bf8b5b7fe7e1950470895..889f987246104a7765930e2b953e4c0826d9e2e3 100644 (file)
@@ -598,7 +598,7 @@ static void ess_send_alc_req(struct s_smc *smc)
        req->cmd.sba_cmd = REQUEST_ALLOCATION ;
 
        /*
-        * set the parameter type and parameter lenght of all used
+        * set the parameter type and parameter length of all used
         * parameters
         */
 
index a45205da8033d6eb8aea4d56df39fe4375ffb99b..76dc8adc9441ea3f563d72b63491259d2ad3563f 100644 (file)
@@ -398,7 +398,7 @@ static void copy_tx_mac(struct s_smc *smc, u_long td, struct fddi_mac *mac,
 /* u_long td;           transmit descriptor */
 /* struct fddi_mac *mac; mac frame pointer */
 /* unsigned off;        start address within buffer memory */
-/* int len ;            lenght of the frame including the FC */
+/* int len ;            length of the frame including the FC */
 {
        int     i ;
        u_int   *p ;
index 8a430a36654705fdc5fba5be36b20d3342db5aa4..46e339315656b793315097cc722b1cf726b29791 100644 (file)
@@ -1185,7 +1185,7 @@ void process_receive(struct s_smc *smc)
 
                DB_RX("frame length = %d",len,0,4) ;
                /*
-                * check the frame_lenght and all error flags
+                * check the frame_length and all error flags
                 */
                if (rfsw & (RX_MSRABT|RX_FS_E|RX_FS_CRC|RX_FS_IMPL)){
                        if (rfsw & RD_S_MSRABT) {
index 626190eb91e7ba567ea3c35ef9d26dac2aaf9b7e..9a6295909e43c318d4fa4da46995d2121e362920 100644 (file)
@@ -623,6 +623,7 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
        static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
        static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA };
 
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
        reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
        /* Turn on/off phy power saving */
        if (onoff)
@@ -634,7 +635,8 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
                reg1 |= coma_mode[port];
 
        sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
-       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
+       sky2_pci_read32(hw, PCI_DEV_REG1);
 
        udelay(100);
 }
@@ -855,7 +857,7 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
        sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
 
        /* On chips without ram buffer, pause is controled by MAC level */
-       if (sky2_read8(hw, B2_E_0) == 0) {
+       if (!(hw->flags & SKY2_HW_RAM_BUFFER)) {
                sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 768/8);
                sky2_write8(hw, SK_REG(port, RX_GMF_UP_THR), 1024/8);
 
@@ -1192,7 +1194,7 @@ static struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2)
        struct sk_buff *skb;
        int i;
 
-       if (sky2->hw->flags & SKY2_HW_FIFO_HANG_CHECK) {
+       if (sky2->hw->flags & SKY2_HW_RAM_BUFFER) {
                unsigned char *start;
                /*
                 * Workaround for a bug in FIFO that cause hang
@@ -1385,6 +1387,7 @@ static int sky2_up(struct net_device *dev)
        if (ramsize > 0) {
                u32 rxspace;
 
+               hw->flags |= SKY2_HW_RAM_BUFFER;
                pr_debug(PFX "%s: ram buffer %dK\n", dev->name, ramsize);
                if (ramsize < 16)
                        rxspace = ramsize / 2;
@@ -1422,6 +1425,7 @@ static int sky2_up(struct net_device *dev)
        imask |= portirq_msk[port];
        sky2_write32(hw, B0_IMSK, imask);
 
+       sky2_set_multicast(dev);
        return 0;
 
 err_out:
@@ -2023,7 +2027,7 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
 
        synchronize_irq(hw->pdev->irq);
 
-       if (sky2_read8(hw, B2_E_0) == 0)
+       if (!(hw->flags & SKY2_HW_RAM_BUFFER))
                sky2_set_tx_stfwd(hw, port);
 
        ctl = gma_read16(hw, port, GM_GP_CTRL);
@@ -2436,6 +2440,7 @@ static void sky2_hw_intr(struct sky2_hw *hw)
        if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
                u16 pci_err;
 
+               sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
                pci_err = sky2_pci_read16(hw, PCI_STATUS);
                if (net_ratelimit())
                        dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
@@ -2443,12 +2448,14 @@ static void sky2_hw_intr(struct sky2_hw *hw)
 
                sky2_pci_write16(hw, PCI_STATUS,
                                      pci_err | PCI_STATUS_ERROR_BITS);
+               sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
        }
 
        if (status & Y2_IS_PCI_EXP) {
                /* PCI-Express uncorrectable Error occurred */
                u32 err;
 
+               sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
                err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
                sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
                             0xfffffffful);
@@ -2456,6 +2463,7 @@ static void sky2_hw_intr(struct sky2_hw *hw)
                        dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
 
                sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
+               sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
        }
 
        if (status & Y2_HWE_L1_MASK)
@@ -2559,7 +2567,7 @@ static void sky2_watchdog(unsigned long arg)
                        ++active;
 
                        /* For chips with Rx FIFO, check if stuck */
-                       if ((hw->flags & SKY2_HW_FIFO_HANG_CHECK) &&
+                       if ((hw->flags & SKY2_HW_RAM_BUFFER) &&
                             sky2_rx_hung(dev)) {
                                pr_info(PFX "%s: receiver hang detected\n",
                                        dev->name);
@@ -2715,11 +2723,7 @@ static int __devinit sky2_init(struct sky2_hw *hw)
 
        switch(hw->chip_id) {
        case CHIP_ID_YUKON_XL:
-               hw->flags = SKY2_HW_GIGABIT
-                       | SKY2_HW_NEWER_PHY;
-               if (hw->chip_rev < 3)
-                       hw->flags |= SKY2_HW_FIFO_HANG_CHECK;
-
+               hw->flags = SKY2_HW_GIGABIT | SKY2_HW_NEWER_PHY;
                break;
 
        case CHIP_ID_YUKON_EC_U:
@@ -2745,7 +2749,7 @@ static int __devinit sky2_init(struct sky2_hw *hw)
                        dev_err(&hw->pdev->dev, "unsupported revision Yukon-EC rev A1\n");
                        return -EOPNOTSUPP;
                }
-               hw->flags = SKY2_HW_GIGABIT | SKY2_HW_FIFO_HANG_CHECK;
+               hw->flags = SKY2_HW_GIGABIT;
                break;
 
        case CHIP_ID_YUKON_FE:
@@ -2831,6 +2835,7 @@ static void sky2_reset(struct sky2_hw *hw)
        }
 
        sky2_power_on(hw);
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
 
        for (i = 0; i < hw->ports; i++) {
                sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
@@ -3554,8 +3559,6 @@ static int sky2_set_ringparam(struct net_device *dev,
                err = sky2_up(dev);
                if (err)
                        dev_close(dev);
-               else
-                       sky2_set_multicast(dev);
        }
 
        return err;
@@ -4389,8 +4392,6 @@ static int sky2_resume(struct pci_dev *pdev)
                                dev_close(dev);
                                goto out;
                        }
-
-                       sky2_set_multicast(dev);
                }
        }
 
index 2bced1a0898f45a1b08bb60d941c938619d7c7e0..5ab5c1c7c5aa76ed30d8c6850b09192afac5d6db 100644 (file)
@@ -2045,7 +2045,7 @@ struct sky2_hw {
 #define SKY2_HW_FIBRE_PHY      0x00000002
 #define SKY2_HW_GIGABIT                0x00000004
 #define SKY2_HW_NEWER_PHY      0x00000008
-#define SKY2_HW_FIFO_HANG_CHECK        0x00000010
+#define SKY2_HW_RAM_BUFFER     0x00000010
 #define SKY2_HW_NEW_LE         0x00000020      /* new LSOv2 format */
 #define SKY2_HW_AUTO_TX_SUM    0x00000040      /* new IP decode for Tx */
 #define SKY2_HW_ADV_POWER_CTL  0x00000080      /* additional PHY power regs */
index fe3ac6f9ae89cd77d26328f50654ba95b180ddd9..0e4a88d16327914a42af9116cdbc8db42443dd27 100644 (file)
@@ -1075,7 +1075,7 @@ static const struct ethtool_ops bigmac_ethtool_ops = {
        .get_link               = bigmac_get_link,
 };
 
-static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
+static int __devinit bigmac_ether_init(struct sbus_dev *qec_sdev)
 {
        struct net_device *dev;
        static int version_printed;
index ff23c6489efd33033d4cfd3f287cdd343805f0a7..e811331d4608a86abc8514848cdacddf73b83123 100644 (file)
@@ -747,7 +747,7 @@ static inline void qec_init_once(struct sunqec *qecp, struct sbus_dev *qsdev)
                    qecp->gregs + GLOB_RSIZE);
 }
 
-static u8 __init qec_get_burst(struct device_node *dp)
+static u8 __devinit qec_get_burst(struct device_node *dp)
 {
        u8 bsizes, bsizes_more;
 
@@ -767,7 +767,7 @@ static u8 __init qec_get_burst(struct device_node *dp)
        return bsizes;
 }
 
-static struct sunqec * __init get_qec(struct sbus_dev *child_sdev)
+static struct sunqec * __devinit get_qec(struct sbus_dev *child_sdev)
 {
        struct sbus_dev *qec_sdev = child_sdev->parent;
        struct sunqec *qecp;
@@ -823,7 +823,7 @@ fail:
        return NULL;
 }
 
-static int __init qec_ether_init(struct sbus_dev *sdev)
+static int __devinit qec_ether_init(struct sbus_dev *sdev)
 {
        static unsigned version_printed;
        struct net_device *dev;
index 4a0035f7a842471df9e39e0dfd8bef3d896b24cc..6415ce15c2efef51721b0a50b181ee296f98ad28 100644 (file)
@@ -1130,7 +1130,7 @@ static struct vio_driver_ops vnet_vio_ops = {
        .handshake_complete     = vnet_handshake_complete,
 };
 
-static void print_version(void)
+static void __devinit print_version(void)
 {
        static int version_printed;
 
index c99ce74a7aff7251c3821314fab0e43be38ffd2f..3af5b92b48c8f1c18ba24b75df46e44ed04959e5 100644 (file)
@@ -465,7 +465,7 @@ static struct pci_driver tlan_driver = {
 
 static int __init tlan_probe(void)
 {
-       static int      pad_allocated;
+       int rc = -ENODEV;
 
        printk(KERN_INFO "%s", tlan_banner);
 
@@ -473,17 +473,22 @@ static int __init tlan_probe(void)
 
        if (TLanPadBuffer == NULL) {
                printk(KERN_ERR "TLAN: Could not allocate memory for pad buffer.\n");
-               return -ENOMEM;
+               rc = -ENOMEM;
+               goto err_out;
        }
 
        memset(TLanPadBuffer, 0, TLAN_MIN_FRAME_SIZE);
-       pad_allocated = 1;
 
        TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
 
        /* Use new style PCI probing. Now the kernel will
           do most of this for us */
-       pci_register_driver(&tlan_driver);
+       rc = pci_register_driver(&tlan_driver);
+
+       if (rc != 0) {
+               printk(KERN_ERR "TLAN: Could not register pci driver.\n");
+               goto err_out_pci_free;
+       }
 
        TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
        TLan_EisaProbe();
@@ -493,11 +498,17 @@ static int __init tlan_probe(void)
                 tlan_have_pci, tlan_have_eisa);
 
        if (TLanDevicesInstalled == 0) {
-               pci_unregister_driver(&tlan_driver);
-               pci_free_consistent(NULL, TLAN_MIN_FRAME_SIZE, TLanPadBuffer, TLanPadBufferDMA);
-               return -ENODEV;
+               rc = -ENODEV;
+               goto  err_out_pci_unreg;
        }
        return 0;
+
+err_out_pci_unreg:
+       pci_unregister_driver(&tlan_driver);
+err_out_pci_free:
+       pci_free_consistent(NULL, TLAN_MIN_FRAME_SIZE, TLanPadBuffer, TLanPadBufferDMA);
+err_out:
+       return rc;
 }
 
 
index 124cfd4fbcf4f7004941dadefff88345c9320a11..7a7de0469eae098412036df35e8b9b636e291622 100644 (file)
@@ -10,7 +10,7 @@
  *      - Madge Smart 16/4 PCI Mk2
  *
  *  Maintainer(s):
- *    AF       Adam Fritzler           mid@auk.cx
+ *    AF       Adam Fritzler
  *
  *  Modification History:
  *     30-Dec-99       AF      Split off from the tms380tr driver.
index 0ee6e4f085b157dedcb306337011c7043f016fc6..b0a473b89133b03199a6822de64cd37592418556 100644 (file)
@@ -2,7 +2,7 @@
  * abyss.h: Header for the abyss tms380tr module
  *
  * Authors:
- * - Adam Fritzler <mid@auk.cx>
+ * - Adam Fritzler
  */
 
 #ifndef __LINUX_MADGETR_H
index 5a4151362fc064034389861794e2cee6cc0e0ddb..c9c5a2b1ed9e9ea6a49d8e5f2af22e9799adb403 100644 (file)
@@ -11,7 +11,7 @@
  *     - Madge Smart 16/4 Ringnode MC32 (??)
  *
  *  Maintainer(s):
- *    AF       Adam Fritzler           mid@auk.cx
+ *    AF       Adam Fritzler
  *
  *  Modification History:
  *     16-Jan-00       AF      Created
index 2dd822203809053248721d79f93d65a869c7cfca..fe88e272c531c85020204516e0aeae60853938d9 100644 (file)
@@ -2,7 +2,7 @@
  * madgemc.h: Header for the madgemc tms380tr module
  *
  * Authors:
- * - Adam Fritzler <mid@auk.cx>
+ * - Adam Fritzler
  */
 
 #ifndef __LINUX_MADGEMC_H
index e7b4adc5c4e79d3ed3faee86b992669b895c56e3..433c994ea9d87e2daf5aa2504e42a8f4b791a8d3 100644 (file)
@@ -434,7 +434,7 @@ static int __devinit olympic_init(struct net_device *dev)
 
 }
 
-static int olympic_open(struct net_device *dev) 
+static int __devinit olympic_open(struct net_device *dev) 
 {
        struct olympic_private *olympic_priv=netdev_priv(dev);
        u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio,*init_srb;
index ca6b65919b3d0bf00806b64349cef355a7edb919..00ea94513460d5e118b811a3496625b98ad4a9cb 100644 (file)
@@ -12,7 +12,7 @@
  *     - Proteon 1392, 1392+
  *
  *  Maintainer(s):
- *    AF        Adam Fritzler           mid@auk.cx
+ *    AF        Adam Fritzler
  *    JF       Jochen Friedrich        jochen@scram.de
  *
  *  Modification History:
index 32e8d5a9f958fa354067b98da188dbebe5a23b57..41b6999a0f33487719f56898a489c9748b975f7f 100644 (file)
@@ -13,7 +13,7 @@
  *     - SysKonnect TR4/16(+) ISA      (SK-4190)
  *
  *  Maintainer(s):
- *    AF        Adam Fritzler           mid@auk.cx
+ *    AF        Adam Fritzler
  *    JF       Jochen Friedrich        jochen@scram.de
  *
  *  Modification History:
index d5fa36d3651591d62b8f1fb3cb305500b187d551..d07c4523c847a1ceb3c4e98876c1cce025459b2c 100644 (file)
@@ -30,7 +30,7 @@
  *  Maintainer(s):
  *    JS       Jay Schulist            jschlst@samba.org
  *    CG       Christoph Goos          cgoos@syskonnect.de
- *    AF       Adam Fritzler           mid@auk.cx
+ *    AF       Adam Fritzler
  *    MLP       Mike Phillips           phillim@amtrak.com
  *    JF       Jochen Friedrich        jochen@scram.de
  *     
index 7daf74e31ccd58a2426c5c33512e93ecec2f2e7e..7af76d7088490f61b57af4adcf832c7b16a018f7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Authors:
  * - Christoph Goos <cgoos@syskonnect.de>
- * - Adam Fritzler <mid@auk.cx>
+ * - Adam Fritzler
  */
 
 #ifndef __LINUX_TMS380TR_H
index 1c18f782f522225fb0467b8fcb460a4aa33afa98..5f0ee880cfff1f7fa4d7c5096265322f043bef39 100644 (file)
@@ -14,7 +14,7 @@
  *      - 3Com 3C339 Token Link Velocity
  *
  *  Maintainer(s):
- *    AF       Adam Fritzler           mid@auk.cx
+ *    AF       Adam Fritzler
  *
  *  Modification History:
  *     30-Dec-99       AF      Split off from the tms380tr driver.
index 8fc7274642eb41f851e78af59d66fb5468954090..6b93d016911650e0ef778ffeaf3dd9c06e370069 100644 (file)
@@ -441,7 +441,7 @@ static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev)
        spin_unlock_irqrestore(&card->lock,flags);
        trigger_transmit(card);
 
-       return -EIO;
+       return NETDEV_TX_BUSY;
 }
 
 
index 46339f6bcd004b9ca6b443cad05df2c82742cf32..038c1ef94d2e72e7332a4e28a86cbd82be14788a 100644 (file)
@@ -529,9 +529,13 @@ static int tun_set_iff(struct file *file, struct ifreq *ifr)
 
        if (ifr->ifr_flags & IFF_NO_PI)
                tun->flags |= TUN_NO_PI;
+       else
+               tun->flags &= ~TUN_NO_PI;
 
        if (ifr->ifr_flags & IFF_ONE_QUEUE)
                tun->flags |= TUN_ONE_QUEUE;
+       else
+               tun->flags &= ~TUN_ONE_QUEUE;
 
        file->private_data = tun;
        tun->attached = 1;
index 4ffd8739f8b72aacaff9f0aa908b0b3cc00e135f..fba0811d2608824bfebd0535b37cc21d14dd9859 100644 (file)
@@ -2084,8 +2084,10 @@ static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
        if (!ugeth)
                return;
 
-       if (ugeth->uccf)
+       if (ugeth->uccf) {
                ucc_fast_free(ugeth->uccf);
+               ugeth->uccf = NULL;
+       }
 
        if (ugeth->p_thread_data_tx) {
                qe_muram_free(ugeth->thread_dat_tx_offset);
@@ -2305,10 +2307,6 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
        ug_info = ugeth->ug_info;
        uf_info = &ug_info->uf_info;
 
-       /* Create CQs for hash tables */
-       INIT_LIST_HEAD(&ugeth->group_hash_q);
-       INIT_LIST_HEAD(&ugeth->ind_hash_q);
-
        if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
              (uf_info->bd_mem_part == MEM_PART_MURAM))) {
                if (netif_msg_probe(ugeth))
@@ -3668,6 +3666,23 @@ static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
        return IRQ_HANDLED;
 }
 
+#ifdef CONFIG_NET_POLL_CONTROLLER
+/*
+ * Polling 'interrupt' - used by things like netconsole to send skbs
+ * without having to re-enable interrupts. It's not called while
+ * the interrupt routine is executing.
+ */
+static void ucc_netpoll(struct net_device *dev)
+{
+       struct ucc_geth_private *ugeth = netdev_priv(dev);
+       int irq = ugeth->ug_info->uf_info.irq;
+
+       disable_irq(irq);
+       ucc_geth_irq_handler(irq, dev);
+       enable_irq(irq);
+}
+#endif /* CONFIG_NET_POLL_CONTROLLER */
+
 /* Called when something needs to use the ethernet device */
 /* Returns 0 for success. */
 static int ucc_geth_open(struct net_device *dev)
@@ -3990,6 +4005,10 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
        ugeth = netdev_priv(dev);
        spin_lock_init(&ugeth->lock);
 
+       /* Create CQs for hash tables */
+       INIT_LIST_HEAD(&ugeth->group_hash_q);
+       INIT_LIST_HEAD(&ugeth->ind_hash_q);
+
        dev_set_drvdata(device, dev);
 
        /* Set the dev->base_addr to the gfar reg region */
@@ -4006,6 +4025,9 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
 #ifdef CONFIG_UGETH_NAPI
        netif_napi_add(dev, &ugeth->napi, ucc_geth_poll, UCC_GETH_DEV_WEIGHT);
 #endif                         /* CONFIG_UGETH_NAPI */
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       dev->poll_controller = ucc_netpoll;
+#endif
        dev->stop = ucc_geth_close;
 //    dev->change_mtu = ucc_geth_change_mtu;
        dev->mtu = 1500;
@@ -4040,9 +4062,10 @@ static int ucc_geth_remove(struct of_device* ofdev)
        struct net_device *dev = dev_get_drvdata(device);
        struct ucc_geth_private *ugeth = netdev_priv(dev);
 
-       dev_set_drvdata(device, NULL);
-       ucc_geth_memclean(ugeth);
+       unregister_netdev(dev);
        free_netdev(dev);
+       ucc_geth_memclean(ugeth);
+       dev_set_drvdata(device, NULL);
 
        return 0;
 }
index e3ba14a19915d0ab5b01837c9429339761c216eb..c69e654d539fcaae8df42cd7065af9e857c8d292 100644 (file)
@@ -109,7 +109,7 @@ int uec_mdio_reset(struct mii_bus *bus)
        struct ucc_mii_mng __iomem *regs = (void __iomem *)bus->priv;
        unsigned int timeout = PHY_INIT_TIMEOUT;
 
-       spin_lock_bh(&bus->mdio_lock);
+       mutex_lock(&bus->mdio_lock);
 
        /* Reset the management interface */
        out_be32(&regs->miimcfg, MIIMCFG_RESET_MANAGEMENT);
@@ -121,7 +121,7 @@ int uec_mdio_reset(struct mii_bus *bus)
        while ((in_be32(&regs->miimind) & MIIMIND_BUSY) && timeout--)
                cpu_relax();
 
-       spin_unlock_bh(&bus->mdio_lock);
+       mutex_unlock(&bus->mdio_lock);
 
        if (timeout <= 0) {
                printk(KERN_ERR "%s: The MII Bus is stuck!\n", bus->name);
index 33cbc306226c67a9a98019d34c4b7eb1ba52b0d5..7e1f00131f91160833e023f416ae2834afeb52cf 100644 (file)
@@ -926,7 +926,6 @@ static int rtl8150_probe(struct usb_interface *intf,
        netdev->set_multicast_list = rtl8150_set_multicast;
        netdev->set_mac_address = rtl8150_set_mac_address;
        netdev->get_stats = rtl8150_netdev_stats;
-       netdev->mtu = RTL8150_MTU;
        SET_ETHTOOL_OPS(netdev, &ops);
        dev->intr_interval = 100;       /* 100ms */
 
index 87c180b563d36dc6623c52df7a5fb2111e8155c1..7c851b1e6daa4ba99e4d107213fca4abb34c76b4 100644 (file)
@@ -606,7 +606,7 @@ static int rhine_napipoll(struct napi_struct *napi, int budget)
 }
 #endif
 
-static void rhine_hw_init(struct net_device *dev, long pioaddr)
+static void __devinit rhine_hw_init(struct net_device *dev, long pioaddr)
 {
        struct rhine_private *rp = netdev_priv(dev);
 
index 35cd65d6b9edcdad5080e31ba52cc56b77b6b777..8c9fb824cbd4015afe9685ba9b8bc20a0c4b13e8 100644 (file)
@@ -8,7 +8,6 @@
  * for 64bit hardware platforms.
  *
  * TODO
- *     Big-endian support
  *     rx_copybreak/alignment
  *     Scatter gather
  *     More testing
@@ -681,7 +680,7 @@ static void velocity_rx_reset(struct velocity_info *vptr)
         *      Init state, all RD entries belong to the NIC
         */
        for (i = 0; i < vptr->options.numrx; ++i)
-               vptr->rd_ring[i].rdesc0.owner = OWNED_BY_NIC;
+               vptr->rd_ring[i].rdesc0.len |= OWNED_BY_NIC;
 
        writew(vptr->options.numrx, &regs->RBRDU);
        writel(vptr->rd_pool_dma, &regs->RDBaseLo);
@@ -777,7 +776,7 @@ static void velocity_init_registers(struct velocity_info *vptr,
 
                vptr->int_mask = INT_MASK_DEF;
 
-               writel(cpu_to_le32(vptr->rd_pool_dma), &regs->RDBaseLo);
+               writel(vptr->rd_pool_dma, &regs->RDBaseLo);
                writew(vptr->options.numrx - 1, &regs->RDCSize);
                mac_rx_queue_run(regs);
                mac_rx_queue_wake(regs);
@@ -785,7 +784,7 @@ static void velocity_init_registers(struct velocity_info *vptr,
                writew(vptr->options.numtx - 1, &regs->TDCSize);
 
                for (i = 0; i < vptr->num_txq; i++) {
-                       writel(cpu_to_le32(vptr->td_pool_dma[i]), &(regs->TDBaseLo[i]));
+                       writel(vptr->td_pool_dma[i], &regs->TDBaseLo[i]);
                        mac_tx_queue_run(regs, i);
                }
 
@@ -1195,7 +1194,7 @@ static inline void velocity_give_many_rx_descs(struct velocity_info *vptr)
        dirty = vptr->rd_dirty - unusable;
        for (avail = vptr->rd_filled & 0xfffc; avail; avail--) {
                dirty = (dirty > 0) ? dirty - 1 : vptr->options.numrx - 1;
-               vptr->rd_ring[dirty].rdesc0.owner = OWNED_BY_NIC;
+               vptr->rd_ring[dirty].rdesc0.len |= OWNED_BY_NIC;
        }
 
        writew(vptr->rd_filled & 0xfffc, &regs->RBRDU);
@@ -1210,7 +1209,7 @@ static int velocity_rx_refill(struct velocity_info *vptr)
                struct rx_desc *rd = vptr->rd_ring + dirty;
 
                /* Fine for an all zero Rx desc at init time as well */
-               if (rd->rdesc0.owner == OWNED_BY_NIC)
+               if (rd->rdesc0.len & OWNED_BY_NIC)
                        break;
 
                if (!vptr->rd_info[dirty].skb) {
@@ -1413,7 +1412,7 @@ static int velocity_rx_srv(struct velocity_info *vptr, int status)
                if (!vptr->rd_info[rd_curr].skb)
                        break;
 
-               if (rd->rdesc0.owner == OWNED_BY_NIC)
+               if (rd->rdesc0.len & OWNED_BY_NIC)
                        break;
 
                rmb();
@@ -1421,7 +1420,7 @@ static int velocity_rx_srv(struct velocity_info *vptr, int status)
                /*
                 *      Don't drop CE or RL error frame although RXOK is off
                 */
-               if ((rd->rdesc0.RSR & RSR_RXOK) || (!(rd->rdesc0.RSR & RSR_RXOK) && (rd->rdesc0.RSR & (RSR_CE | RSR_RL)))) {
+               if (rd->rdesc0.RSR & (RSR_RXOK | RSR_CE | RSR_RL)) {
                        if (velocity_receive_frame(vptr, rd_curr) < 0)
                                stats->rx_dropped++;
                } else {
@@ -1433,7 +1432,7 @@ static int velocity_rx_srv(struct velocity_info *vptr, int status)
                        stats->rx_dropped++;
                }
 
-               rd->inten = 1;
+               rd->size |= RX_INTEN;
 
                vptr->dev->last_rx = jiffies;
 
@@ -1554,7 +1553,7 @@ static int velocity_receive_frame(struct velocity_info *vptr, int idx)
        struct net_device_stats *stats = &vptr->stats;
        struct velocity_rd_info *rd_info = &(vptr->rd_info[idx]);
        struct rx_desc *rd = &(vptr->rd_ring[idx]);
-       int pkt_len = rd->rdesc0.len;
+       int pkt_len = le16_to_cpu(rd->rdesc0.len) & 0x3fff;
        struct sk_buff *skb;
 
        if (rd->rdesc0.RSR & (RSR_STP | RSR_EDP)) {
@@ -1637,8 +1636,7 @@ static int velocity_alloc_rx_buf(struct velocity_info *vptr, int idx)
         */
 
        *((u32 *) & (rd->rdesc0)) = 0;
-       rd->len = cpu_to_le32(vptr->rx_buf_sz);
-       rd->inten = 1;
+       rd->size = cpu_to_le16(vptr->rx_buf_sz) | RX_INTEN;
        rd->pa_low = cpu_to_le32(rd_info->skb_dma);
        rd->pa_high = 0;
        return 0;
@@ -1674,7 +1672,7 @@ static int velocity_tx_srv(struct velocity_info *vptr, u32 status)
                        td = &(vptr->td_rings[qnum][idx]);
                        tdinfo = &(vptr->td_infos[qnum][idx]);
 
-                       if (td->tdesc0.owner == OWNED_BY_NIC)
+                       if (td->tdesc0.len & OWNED_BY_NIC)
                                break;
 
                        if ((works++ > 15))
@@ -1874,7 +1872,7 @@ static void velocity_free_tx_buf(struct velocity_info *vptr, struct velocity_td_
 
                for (i = 0; i < tdinfo->nskb_dma; i++) {
 #ifdef VELOCITY_ZERO_COPY_SUPPORT
-                       pci_unmap_single(vptr->pdev, tdinfo->skb_dma[i], td->tdesc1.len, PCI_DMA_TODEVICE);
+                       pci_unmap_single(vptr->pdev, tdinfo->skb_dma[i], le16_to_cpu(td->tdesc1.len), PCI_DMA_TODEVICE);
 #else
                        pci_unmap_single(vptr->pdev, tdinfo->skb_dma[i], skb->len, PCI_DMA_TODEVICE);
 #endif
@@ -2067,8 +2065,8 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
        struct velocity_td_info *tdinfo;
        unsigned long flags;
        int index;
-
        int pktlen = skb->len;
+       __le16 len = cpu_to_le16(pktlen);
 
 #ifdef VELOCITY_ZERO_COPY_SUPPORT
        if (skb_shinfo(skb)->nr_frags > 6 && __skb_linearize(skb)) {
@@ -2083,9 +2081,8 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
        td_ptr = &(vptr->td_rings[qnum][index]);
        tdinfo = &(vptr->td_infos[qnum][index]);
 
-       td_ptr->tdesc1.TCPLS = TCPLS_NORMAL;
        td_ptr->tdesc1.TCR = TCR0_TIC;
-       td_ptr->td_buf[0].queue = 0;
+       td_ptr->td_buf[0].size &= ~TD_QUEUE;
 
        /*
         *      Pad short frames.
@@ -2093,16 +2090,16 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
        if (pktlen < ETH_ZLEN) {
                /* Cannot occur until ZC support */
                pktlen = ETH_ZLEN;
+               len = cpu_to_le16(ETH_ZLEN);
                skb_copy_from_linear_data(skb, tdinfo->buf, skb->len);
                memset(tdinfo->buf + skb->len, 0, ETH_ZLEN - skb->len);
                tdinfo->skb = skb;
                tdinfo->skb_dma[0] = tdinfo->buf_dma;
-               td_ptr->tdesc0.pktsize = pktlen;
+               td_ptr->tdesc0.len = len;
                td_ptr->td_buf[0].pa_low = cpu_to_le32(tdinfo->skb_dma[0]);
                td_ptr->td_buf[0].pa_high = 0;
-               td_ptr->td_buf[0].bufsize = td_ptr->tdesc0.pktsize;
+               td_ptr->td_buf[0].size = len;   /* queue is 0 anyway */
                tdinfo->nskb_dma = 1;
-               td_ptr->tdesc1.CMDZ = 2;
        } else
 #ifdef VELOCITY_ZERO_COPY_SUPPORT
        if (skb_shinfo(skb)->nr_frags > 0) {
@@ -2111,36 +2108,35 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
                if (nfrags > 6) {
                        skb_copy_from_linear_data(skb, tdinfo->buf, skb->len);
                        tdinfo->skb_dma[0] = tdinfo->buf_dma;
-                       td_ptr->tdesc0.pktsize =
+                       td_ptr->tdesc0.len = len;
                        td_ptr->td_buf[0].pa_low = cpu_to_le32(tdinfo->skb_dma[0]);
                        td_ptr->td_buf[0].pa_high = 0;
-                       td_ptr->td_buf[0].bufsize = td_ptr->tdesc0.pktsize;
+                       td_ptr->td_buf[0].size = len;   /* queue is 0 anyway */
                        tdinfo->nskb_dma = 1;
-                       td_ptr->tdesc1.CMDZ = 2;
                } else {
                        int i = 0;
                        tdinfo->nskb_dma = 0;
-                       tdinfo->skb_dma[i] = pci_map_single(vptr->pdev, skb->data, skb->len - skb->data_len, PCI_DMA_TODEVICE);
+                       tdinfo->skb_dma[i] = pci_map_single(vptr->pdev, skb->data,
+                                               skb_headlen(skb), PCI_DMA_TODEVICE);
 
-                       td_ptr->tdesc0.pktsize = pktlen;
+                       td_ptr->tdesc0.len = len;
 
                        /* FIXME: support 48bit DMA later */
                        td_ptr->td_buf[i].pa_low = cpu_to_le32(tdinfo->skb_dma);
                        td_ptr->td_buf[i].pa_high = 0;
-                       td_ptr->td_buf[i].bufsize = skb->len->skb->data_len;
+                       td_ptr->td_buf[i].size = cpu_to_le16(skb_headlen(skb));
 
                        for (i = 0; i < nfrags; i++) {
                                skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
-                               void *addr = ((void *) page_address(frag->page + frag->page_offset));
+                               void *addr = (void *)page_address(frag->page) + frag->page_offset;
 
                                tdinfo->skb_dma[i + 1] = pci_map_single(vptr->pdev, addr, frag->size, PCI_DMA_TODEVICE);
 
                                td_ptr->td_buf[i + 1].pa_low = cpu_to_le32(tdinfo->skb_dma[i + 1]);
                                td_ptr->td_buf[i + 1].pa_high = 0;
-                               td_ptr->td_buf[i + 1].bufsize = frag->size;
+                               td_ptr->td_buf[i + 1].size = cpu_to_le16(frag->size);
                        }
                        tdinfo->nskb_dma = i - 1;
-                       td_ptr->tdesc1.CMDZ = i;
                }
 
        } else
@@ -2152,18 +2148,16 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
                 */
                tdinfo->skb = skb;
                tdinfo->skb_dma[0] = pci_map_single(vptr->pdev, skb->data, pktlen, PCI_DMA_TODEVICE);
-               td_ptr->tdesc0.pktsize = pktlen;
+               td_ptr->tdesc0.len = len;
                td_ptr->td_buf[0].pa_low = cpu_to_le32(tdinfo->skb_dma[0]);
                td_ptr->td_buf[0].pa_high = 0;
-               td_ptr->td_buf[0].bufsize = td_ptr->tdesc0.pktsize;
+               td_ptr->td_buf[0].size = len;
                tdinfo->nskb_dma = 1;
-               td_ptr->tdesc1.CMDZ = 2;
        }
+       td_ptr->tdesc1.cmd = TCPLS_NORMAL + (tdinfo->nskb_dma + 1) * 16;
 
        if (vptr->vlgrp && vlan_tx_tag_present(skb)) {
-               td_ptr->tdesc1.pqinf.VID = vlan_tx_tag_get(skb);
-               td_ptr->tdesc1.pqinf.priority = 0;
-               td_ptr->tdesc1.pqinf.CFI = 0;
+               td_ptr->tdesc1.vlan = cpu_to_le16(vlan_tx_tag_get(skb));
                td_ptr->tdesc1.TCR |= TCR0_VETAG;
        }
 
@@ -2185,7 +2179,7 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
 
                if (prev < 0)
                        prev = vptr->options.numtx - 1;
-               td_ptr->tdesc0.owner = OWNED_BY_NIC;
+               td_ptr->tdesc0.len |= OWNED_BY_NIC;
                vptr->td_used[qnum]++;
                vptr->td_curr[qnum] = (index + 1) % vptr->options.numtx;
 
@@ -2193,7 +2187,7 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
                        netif_stop_queue(dev);
 
                td_ptr = &(vptr->td_rings[qnum][prev]);
-               td_ptr->td_buf[0].queue = 1;
+               td_ptr->td_buf[0].size |= TD_QUEUE;
                mac_tx_queue_wake(vptr->mac_regs, qnum);
        }
        dev->trans_start = jiffies;
@@ -3410,7 +3404,7 @@ static int velocity_suspend(struct pci_dev *pdev, pm_message_t state)
                velocity_save_context(vptr, &vptr->context);
                velocity_shutdown(vptr);
                velocity_set_wol(vptr);
-               pci_enable_wake(pdev, 3, 1);
+               pci_enable_wake(pdev, PCI_D3hot, 1);
                pci_set_power_state(pdev, PCI_D3hot);
        } else {
                velocity_save_context(vptr, &vptr->context);
index aa9179623d9048957f50037cd0c7f7a285532342..7387be4f428d66aa1ea29324c718e498303b25d9 100644 (file)
  * Bits in the RSR0 register
  */
 
-#define RSR_DETAG          0x0080
-#define RSR_SNTAG          0x0040
-#define RSR_RXER           0x0020
-#define RSR_RL             0x0010
-#define RSR_CE             0x0008
-#define RSR_FAE            0x0004
-#define RSR_CRC            0x0002
-#define RSR_VIDM           0x0001
+#define RSR_DETAG      cpu_to_le16(0x0080)
+#define RSR_SNTAG      cpu_to_le16(0x0040)
+#define RSR_RXER       cpu_to_le16(0x0020)
+#define RSR_RL         cpu_to_le16(0x0010)
+#define RSR_CE         cpu_to_le16(0x0008)
+#define RSR_FAE                cpu_to_le16(0x0004)
+#define RSR_CRC                cpu_to_le16(0x0002)
+#define RSR_VIDM       cpu_to_le16(0x0001)
 
 /*
  * Bits in the RSR1 register
  */
 
-#define RSR_RXOK           0x8000      // rx OK
-#define RSR_PFT            0x4000      // Perfect filtering address match
-#define RSR_MAR            0x2000      // MAC accept multicast address packet
-#define RSR_BAR            0x1000      // MAC accept broadcast address packet
-#define RSR_PHY            0x0800      // MAC accept physical address packet
-#define RSR_VTAG           0x0400      // 802.1p/1q tagging packet indicator
-#define RSR_STP            0x0200      // start of packet
-#define RSR_EDP            0x0100      // end of packet
-
-/*
- * Bits in the RSR1 register
- */
-
-#define RSR1_RXOK           0x80       // rx OK
-#define RSR1_PFT            0x40       // Perfect filtering address match
-#define RSR1_MAR            0x20       // MAC accept multicast address packet
-#define RSR1_BAR            0x10       // MAC accept broadcast address packet
-#define RSR1_PHY            0x08       // MAC accept physical address packet
-#define RSR1_VTAG           0x04       // 802.1p/1q tagging packet indicator
-#define RSR1_STP            0x02       // start of packet
-#define RSR1_EDP            0x01       // end of packet
+#define RSR_RXOK       cpu_to_le16(0x8000) // rx OK
+#define RSR_PFT                cpu_to_le16(0x4000) // Perfect filtering address match
+#define RSR_MAR                cpu_to_le16(0x2000) // MAC accept multicast address packet
+#define RSR_BAR                cpu_to_le16(0x1000) // MAC accept broadcast address packet
+#define RSR_PHY                cpu_to_le16(0x0800) // MAC accept physical address packet
+#define RSR_VTAG       cpu_to_le16(0x0400) // 802.1p/1q tagging packet indicator
+#define RSR_STP                cpu_to_le16(0x0200) // start of packet
+#define RSR_EDP                cpu_to_le16(0x0100) // end of packet
 
 /*
  * Bits in the CSM register
  * Bits in the TSR0 register
  */
 
-#define TSR0_ABT            0x0080     // Tx abort because of excessive collision
-#define TSR0_OWT            0x0040     // Jumbo frame Tx abort
-#define TSR0_OWC            0x0020     // Out of window collision
-#define TSR0_COLS           0x0010     // experience collision in this transmit event
-#define TSR0_NCR3           0x0008     // collision retry counter[3]
-#define TSR0_NCR2           0x0004     // collision retry counter[2]
-#define TSR0_NCR1           0x0002     // collision retry counter[1]
-#define TSR0_NCR0           0x0001     // collision retry counter[0]
-#define TSR0_TERR           0x8000     //
-#define TSR0_FDX            0x4000     // current transaction is serviced by full duplex mode
-#define TSR0_GMII           0x2000     // current transaction is serviced by GMII mode
-#define TSR0_LNKFL          0x1000     // packet serviced during link down
-#define TSR0_SHDN           0x0400     // shutdown case
-#define TSR0_CRS            0x0200     // carrier sense lost
-#define TSR0_CDH            0x0100     // AQE test fail (CD heartbeat)
-
-/*
- * Bits in the TSR1 register
- */
-
-#define TSR1_TERR           0x80       //
-#define TSR1_FDX            0x40       // current transaction is serviced by full duplex mode
-#define TSR1_GMII           0x20       // current transaction is serviced by GMII mode
-#define TSR1_LNKFL          0x10       // packet serviced during link down
-#define TSR1_SHDN           0x04       // shutdown case
-#define TSR1_CRS            0x02       // carrier sense lost
-#define TSR1_CDH            0x01       // AQE test fail (CD heartbeat)
+#define TSR0_ABT       cpu_to_le16(0x0080) // Tx abort because of excessive collision
+#define TSR0_OWT       cpu_to_le16(0x0040) // Jumbo frame Tx abort
+#define TSR0_OWC       cpu_to_le16(0x0020) // Out of window collision
+#define TSR0_COLS      cpu_to_le16(0x0010) // experience collision in this transmit event
+#define TSR0_NCR3      cpu_to_le16(0x0008) // collision retry counter[3]
+#define TSR0_NCR2      cpu_to_le16(0x0004) // collision retry counter[2]
+#define TSR0_NCR1      cpu_to_le16(0x0002) // collision retry counter[1]
+#define TSR0_NCR0      cpu_to_le16(0x0001) // collision retry counter[0]
+#define TSR0_TERR      cpu_to_le16(0x8000) //
+#define TSR0_FDX       cpu_to_le16(0x4000) // current transaction is serviced by full duplex mode
+#define TSR0_GMII      cpu_to_le16(0x2000) // current transaction is serviced by GMII mode
+#define TSR0_LNKFL     cpu_to_le16(0x1000) // packet serviced during link down
+#define TSR0_SHDN      cpu_to_le16(0x0400) // shutdown case
+#define TSR0_CRS       cpu_to_le16(0x0200) // carrier sense lost
+#define TSR0_CDH       cpu_to_le16(0x0100) // AQE test fail (CD heartbeat)
 
 //
 // Bits in the TCR0 register
  */
 
 struct rdesc0 {
-       u16 RSR;                /* Receive status */
-       u16 len:14;             /* Received packet length */
-       u16 reserved:1;
-       u16 owner:1;            /* Who owns this buffer ? */
+       __le16 RSR;             /* Receive status */
+       __le16 len;             /* bits 0--13; bit 15 - owner */
 };
 
 struct rdesc1 {
-       u16 PQTAG;
+       __le16 PQTAG;
        u8 CSM;
        u8 IPKT;
 };
 
+enum {
+       RX_INTEN = __constant_cpu_to_le16(0x8000)
+};
+
 struct rx_desc {
        struct rdesc0 rdesc0;
        struct rdesc1 rdesc1;
-       u32 pa_low;             /* Low 32 bit PCI address */
-       u16 pa_high;            /* Next 16 bit PCI address (48 total) */
-       u16 len:15;             /* Frame size */
-       u16 inten:1;            /* Enable interrupt */
+       __le32 pa_low;          /* Low 32 bit PCI address */
+       __le16 pa_high;         /* Next 16 bit PCI address (48 total) */
+       __le16 size;            /* bits 0--14 - frame size, bit 15 - enable int. */
 } __attribute__ ((__packed__));
 
 /*
@@ -223,32 +199,24 @@ struct rx_desc {
  */
 
 struct tdesc0 {
-       u16 TSR;                /* Transmit status register */
-       u16 pktsize:14;         /* Size of frame */
-       u16 reserved:1;
-       u16 owner:1;            /* Who owns the buffer */
+       __le16 TSR;             /* Transmit status register */
+       __le16 len;             /* bits 0--13 - size of frame, bit 15 - owner */
 };
 
-struct pqinf {                 /* Priority queue info */
-       u16 VID:12;
-       u16 CFI:1;
-       u16 priority:3;
-} __attribute__ ((__packed__));
-
 struct tdesc1 {
-       struct pqinf pqinf;
+       __le16 vlan;
        u8 TCR;
-       u8 TCPLS:2;
-       u8 reserved:2;
-       u8 CMDZ:4;
+       u8 cmd;                 /* bits 0--1 - TCPLS, bits 4--7 - CMDZ */
 } __attribute__ ((__packed__));
 
+enum {
+       TD_QUEUE = __constant_cpu_to_le16(0x8000)
+};
+
 struct td_buf {
-       u32 pa_low;
-       u16 pa_high;
-       u16 bufsize:14;
-       u16 reserved:1;
-       u16 queue:1;
+       __le32 pa_low;
+       __le16 pa_high;
+       __le16 size;            /* bits 0--13 - size, bit 15 - queue */
 } __attribute__ ((__packed__));
 
 struct tx_desc {
@@ -276,7 +244,7 @@ struct velocity_td_info {
 
 enum  velocity_owner {
        OWNED_BY_HOST = 0,
-       OWNED_BY_NIC = 1
+       OWNED_BY_NIC = __constant_cpu_to_le16(0x8000)
 };
 
 
@@ -1012,45 +980,45 @@ struct mac_regs {
        volatile u8 RCR;
        volatile u8 TCR;
 
-       volatile u32 CR0Set;            /* 0x08 */
-       volatile u32 CR0Clr;            /* 0x0C */
+       volatile __le32 CR0Set;         /* 0x08 */
+       volatile __le32 CR0Clr;         /* 0x0C */
 
        volatile u8 MARCAM[8];          /* 0x10 */
 
-       volatile u32 DecBaseHi;         /* 0x18 */
-       volatile u16 DbfBaseHi;         /* 0x1C */
-       volatile u16 reserved_1E;
+       volatile __le32 DecBaseHi;      /* 0x18 */
+       volatile __le16 DbfBaseHi;      /* 0x1C */
+       volatile __le16 reserved_1E;
 
-       volatile u16 ISRCTL;            /* 0x20 */
+       volatile __le16 ISRCTL;         /* 0x20 */
        volatile u8 TXESR;
        volatile u8 RXESR;
 
-       volatile u32 ISR;               /* 0x24 */
-       volatile u32 IMR;
+       volatile __le32 ISR;            /* 0x24 */
+       volatile __le32 IMR;
 
-       volatile u32 TDStatusPort;      /* 0x2C */
+       volatile __le32 TDStatusPort;   /* 0x2C */
 
-       volatile u16 TDCSRSet;          /* 0x30 */
+       volatile __le16 TDCSRSet;       /* 0x30 */
        volatile u8 RDCSRSet;
        volatile u8 reserved_33;
-       volatile u16 TDCSRClr;
+       volatile __le16 TDCSRClr;
        volatile u8 RDCSRClr;
        volatile u8 reserved_37;
 
-       volatile u32 RDBaseLo;          /* 0x38 */
-       volatile u16 RDIdx;             /* 0x3C */
-       volatile u16 reserved_3E;
+       volatile __le32 RDBaseLo;       /* 0x38 */
+       volatile __le16 RDIdx;          /* 0x3C */
+       volatile __le16 reserved_3E;
 
-       volatile u32 TDBaseLo[4];       /* 0x40 */
+       volatile __le32 TDBaseLo[4];    /* 0x40 */
 
-       volatile u16 RDCSize;           /* 0x50 */
-       volatile u16 TDCSize;           /* 0x52 */
-       volatile u16 TDIdx[4];          /* 0x54 */
-       volatile u16 tx_pause_timer;    /* 0x5C */
-       volatile u16 RBRDU;             /* 0x5E */
+       volatile __le16 RDCSize;        /* 0x50 */
+       volatile __le16 TDCSize;        /* 0x52 */
+       volatile __le16 TDIdx[4];       /* 0x54 */
+       volatile __le16 tx_pause_timer; /* 0x5C */
+       volatile __le16 RBRDU;          /* 0x5E */
 
-       volatile u32 FIFOTest0;         /* 0x60 */
-       volatile u32 FIFOTest1;         /* 0x64 */
+       volatile __le32 FIFOTest0;      /* 0x60 */
+       volatile __le32 FIFOTest1;      /* 0x64 */
 
        volatile u8 CAMADDR;            /* 0x68 */
        volatile u8 CAMCR;              /* 0x69 */
@@ -1063,18 +1031,18 @@ struct mac_regs {
        volatile u8 PHYSR1;
        volatile u8 MIICR;
        volatile u8 MIIADR;
-       volatile u16 MIIDATA;
+       volatile __le16 MIIDATA;
 
-       volatile u16 SoftTimer0;        /* 0x74 */
-       volatile u16 SoftTimer1;
+       volatile __le16 SoftTimer0;     /* 0x74 */
+       volatile __le16 SoftTimer1;
 
        volatile u8 CFGA;               /* 0x78 */
        volatile u8 CFGB;
        volatile u8 CFGC;
        volatile u8 CFGD;
 
-       volatile u16 DCFG;              /* 0x7C */
-       volatile u16 MCFG;
+       volatile __le16 DCFG;           /* 0x7C */
+       volatile __le16 MCFG;
 
        volatile u8 TBIST;              /* 0x80 */
        volatile u8 RBIST;
@@ -1086,9 +1054,9 @@ struct mac_regs {
        volatile u8 rev_id;
        volatile u8 PORSTS;
 
-       volatile u32 MIBData;           /* 0x88 */
+       volatile __le32 MIBData;        /* 0x88 */
 
-       volatile u16 EEWrData;
+       volatile __le16 EEWrData;
 
        volatile u8 reserved_8E;
        volatile u8 BPMDWr;
@@ -1098,7 +1066,7 @@ struct mac_regs {
        volatile u8 EECHKSUM;           /* 0x92 */
        volatile u8 EECSR;
 
-       volatile u16 EERdData;          /* 0x94 */
+       volatile __le16 EERdData;       /* 0x94 */
        volatile u8 EADDR;
        volatile u8 EMBCMD;
 
@@ -1112,22 +1080,22 @@ struct mac_regs {
        volatile u8 DEBUG;
        volatile u8 CHIPGCR;
 
-       volatile u16 WOLCRSet;          /* 0xA0 */
+       volatile __le16 WOLCRSet;       /* 0xA0 */
        volatile u8 PWCFGSet;
        volatile u8 WOLCFGSet;
 
-       volatile u16 WOLCRClr;          /* 0xA4 */
+       volatile __le16 WOLCRClr;       /* 0xA4 */
        volatile u8 PWCFGCLR;
        volatile u8 WOLCFGClr;
 
-       volatile u16 WOLSRSet;          /* 0xA8 */
-       volatile u16 reserved_AA;
+       volatile __le16 WOLSRSet;       /* 0xA8 */
+       volatile __le16 reserved_AA;
 
-       volatile u16 WOLSRClr;          /* 0xAC */
-       volatile u16 reserved_AE;
+       volatile __le16 WOLSRClr;       /* 0xAC */
+       volatile __le16 reserved_AE;
 
-       volatile u16 PatternCRC[8];     /* 0xB0 */
-       volatile u32 ByteMask[4][4];    /* 0xC0 */
+       volatile __le16 PatternCRC[8];  /* 0xB0 */
+       volatile __le32 ByteMask[4][4]; /* 0xC0 */
 } __attribute__ ((__packed__));
 
 
@@ -1238,12 +1206,12 @@ typedef u8 MCAM_ADDR[ETH_ALEN];
 struct arp_packet {
        u8 dest_mac[ETH_ALEN];
        u8 src_mac[ETH_ALEN];
-       u16 type;
-       u16 ar_hrd;
-       u16 ar_pro;
+       __be16 type;
+       __be16 ar_hrd;
+       __be16 ar_pro;
        u8 ar_hln;
        u8 ar_pln;
-       u16 ar_op;
+       __be16 ar_op;
        u8 ar_sha[ETH_ALEN];
        u8 ar_sip[4];
        u8 ar_tha[ETH_ALEN];
@@ -1253,7 +1221,7 @@ struct arp_packet {
 struct _magic_packet {
        u8 dest_mac[6];
        u8 src_mac[6];
-       u16 type;
+       __be16 type;
        u8 MAC[16][6];
        u8 password[6];
 } __attribute__ ((__packed__));
index 5413dbf3d4ac25ab688bb1a965ccf981f230addc..fdc23678117bdd31157a13c6d428d2c1951dc778 100644 (file)
 #include <linux/virtio_net.h>
 #include <linux/scatterlist.h>
 
+static int napi_weight = 128;
+module_param(napi_weight, int, 0444);
+
+static int csum = 1, gso = 1;
+module_param(csum, bool, 0444);
+module_param(gso, bool, 0444);
+
 /* FIXME: MTU in config. */
 #define MAX_PACKET_LEN (ETH_HLEN+ETH_DATA_LEN)
 
@@ -52,13 +59,14 @@ static inline void vnet_hdr_to_sg(struct scatterlist *sg, struct sk_buff *skb)
        sg_init_one(sg, skb_vnet_hdr(skb), sizeof(struct virtio_net_hdr));
 }
 
-static bool skb_xmit_done(struct virtqueue *rvq)
+static void skb_xmit_done(struct virtqueue *svq)
 {
-       struct virtnet_info *vi = rvq->vdev->priv;
+       struct virtnet_info *vi = svq->vdev->priv;
 
-       /* In case we were waiting for output buffers. */
+       /* Suppress further interrupts. */
+       svq->vq_ops->disable_cb(svq);
+       /* We were waiting for more output buffers. */
        netif_wake_queue(vi->dev);
-       return true;
 }
 
 static void receive_skb(struct net_device *dev, struct sk_buff *skb,
@@ -83,28 +91,16 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
 
        if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
                pr_debug("Needs csum!\n");
-               skb->ip_summed = CHECKSUM_PARTIAL;
-               skb->csum_start = hdr->csum_start;
-               skb->csum_offset = hdr->csum_offset;
-               if (skb->csum_start > skb->len - 2
-                   || skb->csum_offset > skb->len - 2) {
-                       if (net_ratelimit())
-                               printk(KERN_WARNING "%s: csum=%u/%u len=%u\n",
-                                      dev->name, skb->csum_start,
-                                      skb->csum_offset, skb->len);
+               if (!skb_partial_csum_set(skb,hdr->csum_start,hdr->csum_offset))
                        goto frame_err;
-               }
        }
 
        if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
                pr_debug("GSO!\n");
-               switch (hdr->gso_type) {
+               switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
                case VIRTIO_NET_HDR_GSO_TCPV4:
                        skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
                        break;
-               case VIRTIO_NET_HDR_GSO_TCPV4_ECN:
-                       skb_shinfo(skb)->gso_type = SKB_GSO_TCP_ECN;
-                       break;
                case VIRTIO_NET_HDR_GSO_UDP:
                        skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
                        break;
@@ -118,6 +114,9 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
                        goto frame_err;
                }
 
+               if (hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN)
+                       skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
+
                skb_shinfo(skb)->gso_size = hdr->gso_size;
                if (skb_shinfo(skb)->gso_size == 0) {
                        if (net_ratelimit())
@@ -170,12 +169,14 @@ static void try_fill_recv(struct virtnet_info *vi)
        vi->rvq->vq_ops->kick(vi->rvq);
 }
 
-static bool skb_recv_done(struct virtqueue *rvq)
+static void skb_recv_done(struct virtqueue *rvq)
 {
        struct virtnet_info *vi = rvq->vdev->priv;
-       netif_rx_schedule(vi->dev, &vi->napi);
-       /* Suppress further interrupts. */
-       return false;
+       /* Schedule NAPI, Suppress further interrupts if successful. */
+       if (netif_rx_schedule_prep(vi->dev, &vi->napi)) {
+               rvq->vq_ops->disable_cb(rvq);
+               __netif_rx_schedule(vi->dev, &vi->napi);
+       }
 }
 
 static int virtnet_poll(struct napi_struct *napi, int budget)
@@ -201,7 +202,7 @@ again:
        /* Out of packets? */
        if (received < budget) {
                netif_rx_complete(vi->dev, napi);
-               if (unlikely(!vi->rvq->vq_ops->restart(vi->rvq))
+               if (unlikely(!vi->rvq->vq_ops->enable_cb(vi->rvq))
                    && netif_rx_reschedule(vi->dev, napi))
                        goto again;
        }
@@ -236,8 +237,6 @@ static int start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        pr_debug("%s: xmit %p %s\n", dev->name, skb, print_mac(mac, dest));
 
-       free_old_xmit_skbs(vi);
-
        /* Encode metadata header at front. */
        hdr = skb_vnet_hdr(skb);
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
@@ -250,10 +249,9 @@ static int start_xmit(struct sk_buff *skb, struct net_device *dev)
        }
 
        if (skb_is_gso(skb)) {
+               hdr->hdr_len = skb_transport_header(skb) - skb->data;
                hdr->gso_size = skb_shinfo(skb)->gso_size;
-               if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN)
-                       hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4_ECN;
-               else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
+               if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
                        hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
                else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
                        hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
@@ -261,19 +259,34 @@ static int start_xmit(struct sk_buff *skb, struct net_device *dev)
                        hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
                else
                        BUG();
+               if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN)
+                       hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN;
        } else {
                hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
-               hdr->gso_size = 0;
+               hdr->gso_size = hdr->hdr_len = 0;
        }
 
        vnet_hdr_to_sg(sg, skb);
        num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
        __skb_queue_head(&vi->send, skb);
+
+again:
+       /* Free up any pending old buffers before queueing new ones. */
+       free_old_xmit_skbs(vi);
        err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb);
        if (err) {
                pr_debug("%s: virtio not prepared to send\n", dev->name);
-               skb_unlink(skb, &vi->send);
                netif_stop_queue(dev);
+
+               /* Activate callback for using skbs: if this fails it
+                * means some were used in the meantime. */
+               if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) {
+                       printk("Unlikely: restart svq failed\n");
+                       netif_start_queue(dev);
+                       goto again;
+               }
+               __skb_unlink(skb, &vi->send);
+
                return NETDEV_TX_BUSY;
        }
        vi->svq->vq_ops->kick(vi->svq);
@@ -285,45 +298,33 @@ static int virtnet_open(struct net_device *dev)
 {
        struct virtnet_info *vi = netdev_priv(dev);
 
-       try_fill_recv(vi);
-
-       /* If we didn't even get one input buffer, we're useless. */
-       if (vi->num == 0)
-               return -ENOMEM;
-
        napi_enable(&vi->napi);
+
+       /* If all buffers were filled by other side before we napi_enabled, we
+        * won't get another interrupt, so process any outstanding packets
+        * now.  virtnet_poll wants re-enable the queue, so we disable here.
+        * We synchronize against interrupts via NAPI_STATE_SCHED */
+       if (netif_rx_schedule_prep(dev, &vi->napi)) {
+               vi->rvq->vq_ops->disable_cb(vi->rvq);
+               __netif_rx_schedule(dev, &vi->napi);
+       }
        return 0;
 }
 
 static int virtnet_close(struct net_device *dev)
 {
        struct virtnet_info *vi = netdev_priv(dev);
-       struct sk_buff *skb;
 
        napi_disable(&vi->napi);
 
-       /* networking core has neutered skb_xmit_done/skb_recv_done, so don't
-        * worry about races vs. get(). */
-       vi->rvq->vq_ops->shutdown(vi->rvq);
-       while ((skb = __skb_dequeue(&vi->recv)) != NULL) {
-               kfree_skb(skb);
-               vi->num--;
-       }
-       vi->svq->vq_ops->shutdown(vi->svq);
-       while ((skb = __skb_dequeue(&vi->send)) != NULL)
-               kfree_skb(skb);
-
-       BUG_ON(vi->num != 0);
        return 0;
 }
 
 static int virtnet_probe(struct virtio_device *vdev)
 {
        int err;
-       unsigned int len;
        struct net_device *dev;
        struct virtnet_info *vi;
-       void *token;
 
        /* Allocate ourselves a network device with room for our info */
        dev = alloc_etherdev(sizeof(struct virtnet_info));
@@ -331,7 +332,6 @@ static int virtnet_probe(struct virtio_device *vdev)
                return -ENOMEM;
 
        /* Set up network device as normal. */
-       ether_setup(dev);
        dev->open = virtnet_open;
        dev->stop = virtnet_close;
        dev->hard_start_xmit = start_xmit;
@@ -339,42 +339,37 @@ static int virtnet_probe(struct virtio_device *vdev)
        SET_NETDEV_DEV(dev, &vdev->dev);
 
        /* Do we support "hardware" checksums? */
-       token = vdev->config->find(vdev, VIRTIO_CONFIG_NET_F, &len);
-       if (virtio_use_bit(vdev, token, len, VIRTIO_NET_F_NO_CSUM)) {
+       if (csum && vdev->config->feature(vdev, VIRTIO_NET_F_CSUM)) {
                /* This opens up the world of extra features. */
                dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
-               if (virtio_use_bit(vdev, token, len, VIRTIO_NET_F_TSO4))
-                       dev->features |= NETIF_F_TSO;
-               if (virtio_use_bit(vdev, token, len, VIRTIO_NET_F_UFO))
-                       dev->features |= NETIF_F_UFO;
-               if (virtio_use_bit(vdev, token, len, VIRTIO_NET_F_TSO4_ECN))
-                       dev->features |= NETIF_F_TSO_ECN;
-               if (virtio_use_bit(vdev, token, len, VIRTIO_NET_F_TSO6))
-                       dev->features |= NETIF_F_TSO6;
+               if (gso && vdev->config->feature(vdev, VIRTIO_NET_F_GSO)) {
+                       dev->features |= NETIF_F_TSO | NETIF_F_UFO
+                               | NETIF_F_TSO_ECN | NETIF_F_TSO6;
+               }
        }
 
        /* Configuration may specify what MAC to use.  Otherwise random. */
-       token = vdev->config->find(vdev, VIRTIO_CONFIG_NET_MAC_F, &len);
-       if (token) {
-               dev->addr_len = len;
-               vdev->config->get(vdev, token, dev->dev_addr, len);
+       if (vdev->config->feature(vdev, VIRTIO_NET_F_MAC)) {
+               vdev->config->get(vdev,
+                                 offsetof(struct virtio_net_config, mac),
+                                 dev->dev_addr, dev->addr_len);
        } else
                random_ether_addr(dev->dev_addr);
 
        /* Set up our device-specific information */
        vi = netdev_priv(dev);
-       netif_napi_add(dev, &vi->napi, virtnet_poll, 16);
+       netif_napi_add(dev, &vi->napi, virtnet_poll, napi_weight);
        vi->dev = dev;
        vi->vdev = vdev;
 
        /* We expect two virtqueues, receive then send. */
-       vi->rvq = vdev->config->find_vq(vdev, skb_recv_done);
+       vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done);
        if (IS_ERR(vi->rvq)) {
                err = PTR_ERR(vi->rvq);
                goto free;
        }
 
-       vi->svq = vdev->config->find_vq(vdev, skb_xmit_done);
+       vi->svq = vdev->config->find_vq(vdev, 1, skb_xmit_done);
        if (IS_ERR(vi->svq)) {
                err = PTR_ERR(vi->svq);
                goto free_recv;
@@ -389,10 +384,22 @@ static int virtnet_probe(struct virtio_device *vdev)
                pr_debug("virtio_net: registering device failed\n");
                goto free_send;
        }
+
+       /* Last of all, set up some receive buffers. */
+       try_fill_recv(vi);
+
+       /* If we didn't even get one input buffer, we're useless. */
+       if (vi->num == 0) {
+               err = -ENOMEM;
+               goto unregister;
+       }
+
        pr_debug("virtnet: registered device %s\n", dev->name);
        vdev->priv = vi;
        return 0;
 
+unregister:
+       unregister_netdev(dev);
 free_send:
        vdev->config->del_vq(vi->svq);
 free_recv:
@@ -405,6 +412,20 @@ free:
 static void virtnet_remove(struct virtio_device *vdev)
 {
        struct virtnet_info *vi = vdev->priv;
+       struct sk_buff *skb;
+
+       /* Stop all the virtqueues. */
+       vdev->config->reset(vdev);
+
+       /* Free our skbs in send and recv queues, if any. */
+       while ((skb = __skb_dequeue(&vi->recv)) != NULL) {
+               kfree_skb(skb);
+               vi->num--;
+       }
+       while ((skb = __skb_dequeue(&vi->send)) != NULL)
+               kfree_skb(skb);
+
+       BUG_ON(vi->num != 0);
 
        vdev->config->del_vq(vi->svq);
        vdev->config->del_vq(vi->rvq);
index d347d59db656057cffdc3c27260d8866188374be..d14e6678deed2456be4df506a4094aaf4be20f68 100644 (file)
@@ -322,7 +322,7 @@ static int cycx_data_boot(void __iomem *addr, u8 *code, u32 len)
        void __iomem *pt_boot_cmd = addr + CMD_OFFSET;
        u32 i;
 
-       /* boot buffer lenght */
+       /* boot buffer length */
        writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));
        writew(GEN_DEFPAR, pt_boot_cmd);
 
@@ -353,7 +353,7 @@ static int cycx_code_boot(void __iomem *addr, u8 *code, u32 len)
        void __iomem *pt_boot_cmd = addr + CMD_OFFSET;
        u32 i;
 
-       /* boot buffer lenght */
+       /* boot buffer length */
        writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));
        writew(GEN_DEFPAR, pt_boot_cmd);
 
index d553e6f328513a56f633bf35d2e562c5d979f08f..39951d0c34d6598b44a9d701fe3c5f1df2df5ceb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Generic HDLC support routines for Linux
  *
- * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
+ * Copyright (C) 1999 - 2008 Krzysztof Halasa <khc@pm.waw.pl>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License
@@ -39,7 +39,7 @@
 #include <net/net_namespace.h>
 
 
-static const char* version = "HDLC support module revision 1.21";
+static const char* version = "HDLC support module revision 1.22";
 
 #undef DEBUG_LINK
 
@@ -66,19 +66,15 @@ static struct net_device_stats *hdlc_get_stats(struct net_device *dev)
 static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
                    struct packet_type *p, struct net_device *orig_dev)
 {
-       struct hdlc_device_desc *desc = dev_to_desc(dev);
+       struct hdlc_device *hdlc = dev_to_hdlc(dev);
 
        if (dev->nd_net != &init_net) {
                kfree_skb(skb);
                return 0;
        }
 
-       if (desc->netif_rx)
-               return desc->netif_rx(skb);
-
-       desc->stats.rx_dropped++; /* Shouldn't happen */
-       dev_kfree_skb(skb);
-       return NET_RX_DROP;
+       BUG_ON(!hdlc->proto->netif_rx);
+       return hdlc->proto->netif_rx(skb);
 }
 
 
@@ -87,7 +83,7 @@ static inline void hdlc_proto_start(struct net_device *dev)
 {
        hdlc_device *hdlc = dev_to_hdlc(dev);
        if (hdlc->proto->start)
-               return hdlc->proto->start(dev);
+               hdlc->proto->start(dev);
 }
 
 
@@ -96,7 +92,7 @@ static inline void hdlc_proto_stop(struct net_device *dev)
 {
        hdlc_device *hdlc = dev_to_hdlc(dev);
        if (hdlc->proto->stop)
-               return hdlc->proto->stop(dev);
+               hdlc->proto->stop(dev);
 }
 
 
@@ -263,8 +259,7 @@ static void hdlc_setup(struct net_device *dev)
 struct net_device *alloc_hdlcdev(void *priv)
 {
        struct net_device *dev;
-       dev = alloc_netdev(sizeof(struct hdlc_device_desc) +
-                          sizeof(hdlc_device), "hdlc%d", hdlc_setup);
+       dev = alloc_netdev(sizeof(struct hdlc_device), "hdlc%d", hdlc_setup);
        if (dev)
                dev_to_hdlc(dev)->priv = priv;
        return dev;
@@ -281,7 +276,7 @@ void unregister_hdlc_device(struct net_device *dev)
 
 
 int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
-                        int (*rx)(struct sk_buff *skb), size_t size)
+                        size_t size)
 {
        detach_hdlc_protocol(dev);
 
@@ -297,7 +292,6 @@ int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
                        return -ENOBUFS;
                }
        dev_to_hdlc(dev)->proto = proto;
-       dev_to_desc(dev)->netif_rx = rx;
        return 0;
 }
 
index 038a6e748bbffdcfdd39bca117709f65f5510bb0..7133c688cf20569e71aed38b83ca3db4bcd59896 100644 (file)
@@ -250,7 +250,7 @@ static int cisco_rx(struct sk_buff *skb)
        return NET_RX_DROP;
 
  rx_error:
-       dev_to_desc(dev)->stats.rx_errors++; /* Mark error */
+       dev_to_hdlc(dev)->stats.rx_errors++; /* Mark error */
        dev_kfree_skb_any(skb);
        return NET_RX_DROP;
 }
@@ -314,6 +314,7 @@ static struct hdlc_proto proto = {
        .stop           = cisco_stop,
        .type_trans     = cisco_type_trans,
        .ioctl          = cisco_ioctl,
+       .netif_rx       = cisco_rx,
        .module         = THIS_MODULE,
 };
 
@@ -360,7 +361,7 @@ static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
                if (result)
                        return result;
 
-               result = attach_hdlc_protocol(dev, &proto, cisco_rx,
+               result = attach_hdlc_protocol(dev, &proto,
                                              sizeof(struct cisco_state));
                if (result)
                        return result;
index 071a64cacd5c29cdedfc959c922bea885a7a7cc2..c4ab0326f91103b03dcd01dd7b1a153101ef4ea9 100644 (file)
@@ -42,7 +42,6 @@
 #include <linux/init.h>
 #include <linux/skbuff.h>
 #include <linux/pkt_sched.h>
-#include <linux/random.h>
 #include <linux/inetdevice.h>
 #include <linux/lapb.h>
 #include <linux/rtnetlink.h>
@@ -136,6 +135,10 @@ typedef struct pvc_device_struct {
        }state;
 }pvc_device;
 
+struct pvc_desc {
+       struct net_device_stats stats;
+       pvc_device *pvc;
+};
 
 struct frad_state {
        fr_proto settings;
@@ -171,17 +174,20 @@ static inline void dlci_to_q922(u8 *hdr, u16 dlci)
 }
 
 
-static inline struct frad_state * state(hdlc_device *hdlc)
+static inline struct frad_state* state(hdlc_device *hdlc)
 {
        return(struct frad_state *)(hdlc->state);
 }
 
-
-static __inline__ pvc_device* dev_to_pvc(struct net_device *dev)
+static inline struct pvc_desc* pvcdev_to_desc(struct net_device *dev)
 {
        return dev->priv;
 }
 
+static inline struct net_device_stats* pvc_get_stats(struct net_device *dev)
+{
+       return &pvcdev_to_desc(dev)->stats;
+}
 
 static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci)
 {
@@ -351,7 +357,7 @@ static int fr_hard_header(struct sk_buff **skb_p, u16 dlci)
 
 static int pvc_open(struct net_device *dev)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
+       pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
 
        if ((pvc->frad->flags & IFF_UP) == 0)
                return -EIO;  /* Frad must be UP in order to activate PVC */
@@ -371,7 +377,7 @@ static int pvc_open(struct net_device *dev)
 
 static int pvc_close(struct net_device *dev)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
+       pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
 
        if (--pvc->open_count == 0) {
                hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
@@ -390,7 +396,7 @@ static int pvc_close(struct net_device *dev)
 
 static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
+       pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
        fr_proto_pvc_info info;
 
        if (ifr->ifr_settings.type == IF_GET_PROTO) {
@@ -416,17 +422,9 @@ static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        return -EINVAL;
 }
 
-
-static inline struct net_device_stats *pvc_get_stats(struct net_device *dev)
-{
-       return &dev_to_desc(dev)->stats;
-}
-
-
-
 static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
+       pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
        struct net_device_stats *stats = pvc_get_stats(dev);
 
        if (pvc->state.active) {
@@ -957,7 +955,7 @@ static int fr_rx(struct sk_buff *skb)
 
 
        if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
-               dev_to_desc(frad)->stats.rx_dropped++;
+               dev_to_hdlc(frad)->stats.rx_dropped++;
                return NET_RX_DROP;
        }
 
@@ -1018,7 +1016,7 @@ static int fr_rx(struct sk_buff *skb)
        }
 
  rx_error:
-       dev_to_desc(frad)->stats.rx_errors++; /* Mark error */
+       dev_to_hdlc(frad)->stats.rx_errors++; /* Mark error */
        dev_kfree_skb_any(skb);
        return NET_RX_DROP;
 }
@@ -1109,11 +1107,10 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
        used = pvc_is_used(pvc);
 
        if (type == ARPHRD_ETHER)
-               dev = alloc_netdev(sizeof(struct net_device_stats),
-                                  "pvceth%d", ether_setup);
+               dev = alloc_netdev(sizeof(struct pvc_desc), "pvceth%d",
+                                  ether_setup);
        else
-               dev = alloc_netdev(sizeof(struct net_device_stats),
-                                  "pvc%d", pvc_setup);
+               dev = alloc_netdev(sizeof(struct pvc_desc), "pvc%d", pvc_setup);
 
        if (!dev) {
                printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n",
@@ -1122,10 +1119,9 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
                return -ENOBUFS;
        }
 
-       if (type == ARPHRD_ETHER) {
-               memcpy(dev->dev_addr, "\x00\x01", 2);
-                get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2);
-       } else {
+       if (type == ARPHRD_ETHER)
+               random_ether_addr(dev->dev_addr);
+       else {
                *(__be16*)dev->dev_addr = htons(dlci);
                dlci_to_q922(dev->broadcast, dlci);
        }
@@ -1137,7 +1133,7 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
        dev->change_mtu = pvc_change_mtu;
        dev->mtu = HDLC_MAX_MTU;
        dev->tx_queue_len = 0;
-       dev->priv = pvc;
+       pvcdev_to_desc(dev)->pvc = pvc;
 
        result = dev_alloc_name(dev, dev->name);
        if (result < 0) {
@@ -1219,6 +1215,7 @@ static struct hdlc_proto proto = {
        .stop           = fr_stop,
        .detach         = fr_destroy,
        .ioctl          = fr_ioctl,
+       .netif_rx       = fr_rx,
        .module         = THIS_MODULE,
 };
 
@@ -1277,7 +1274,7 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
                        return result;
 
                if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */
-                       result = attach_hdlc_protocol(dev, &proto, fr_rx,
+                       result = attach_hdlc_protocol(dev, &proto,
                                                      sizeof(struct frad_state));
                        if (result)
                                return result;
index 519e1550e2e785fb99349b676f13a83bb497336e..10396d9686f4f7a5413d647772ff947831bedf52 100644 (file)
@@ -122,7 +122,7 @@ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
                if (result)
                        return result;
 
-               result = attach_hdlc_protocol(dev, &proto, NULL,
+               result = attach_hdlc_protocol(dev, &proto,
                                              sizeof(struct ppp_state));
                if (result)
                        return result;
index e23bc6656267401270488809d0a73d886203adb8..bbbb819d764cbc068f4fb9646cba63c8c2b226f6 100644 (file)
@@ -82,7 +82,7 @@ static int raw_ioctl(struct net_device *dev, struct ifreq *ifr)
                if (result)
                        return result;
 
-               result = attach_hdlc_protocol(dev, &proto, NULL,
+               result = attach_hdlc_protocol(dev, &proto,
                                              sizeof(raw_hdlc_proto));
                if (result)
                        return result;
index 8895394e60062071fc986a7b0acd4218fdbe3ef4..d20c685f67111281699dcc1449b366dc22fb04e9 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/init.h>
 #include <linux/skbuff.h>
 #include <linux/pkt_sched.h>
-#include <linux/random.h>
 #include <linux/inetdevice.h>
 #include <linux/lapb.h>
 #include <linux/rtnetlink.h>
@@ -96,7 +95,7 @@ static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
                if (result)
                        return result;
 
-               result = attach_hdlc_protocol(dev, &proto, NULL,
+               result = attach_hdlc_protocol(dev, &proto,
                                              sizeof(raw_hdlc_proto));
                if (result)
                        return result;
@@ -107,8 +106,7 @@ static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
                ether_setup(dev);
                dev->change_mtu = old_ch_mtu;
                dev->tx_queue_len = old_qlen;
-               memcpy(dev->dev_addr, "\x00\x01", 2);
-                get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2);
+               random_ether_addr(dev->dev_addr);
                netif_dormant_off(dev);
                return 0;
        }
index cd7b22f50edc562d9fa9f35bf809656fc834227b..c15cc11e399bed72fac105edbb1270469c9e8eb5 100644 (file)
@@ -164,17 +164,17 @@ static void x25_close(struct net_device *dev)
 
 static int x25_rx(struct sk_buff *skb)
 {
-       struct hdlc_device_desc *desc = dev_to_desc(skb->dev);
+       struct hdlc_device *hdlc = dev_to_hdlc(skb->dev);
 
        if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
-               desc->stats.rx_dropped++;
+               hdlc->stats.rx_dropped++;
                return NET_RX_DROP;
        }
 
        if (lapb_data_received(skb->dev, skb) == LAPB_OK)
                return NET_RX_SUCCESS;
 
-       desc->stats.rx_errors++;
+       hdlc->stats.rx_errors++;
        dev_kfree_skb_any(skb);
        return NET_RX_DROP;
 }
@@ -184,6 +184,7 @@ static struct hdlc_proto proto = {
        .open           = x25_open,
        .close          = x25_close,
        .ioctl          = x25_ioctl,
+       .netif_rx       = x25_rx,
        .module         = THIS_MODULE,
 };
 
@@ -211,8 +212,7 @@ static int x25_ioctl(struct net_device *dev, struct ifreq *ifr)
                if (result)
                        return result;
 
-               if ((result = attach_hdlc_protocol(dev, &proto,
-                                                  x25_rx, 0)) != 0)
+               if ((result = attach_hdlc_protocol(dev, &proto, 0)))
                        return result;
                dev->hard_start_xmit = x25_xmit;
                dev->type = ARPHRD_X25;
index d6599d219193aab8aa1abb3ed85d8908a332bbe9..ddc87149fe31d098730a27eee9b7df871f5d18f9 100644 (file)
@@ -153,7 +153,7 @@ static int          ath5k_pci_resume(struct pci_dev *pdev);
 #define ath5k_pci_resume NULL
 #endif /* CONFIG_PM */
 
-static struct pci_driver ath5k_pci_drv_id = {
+static struct pci_driver ath5k_pci_driver = {
        .name           = "ath5k_pci",
        .id_table       = ath5k_pci_id_table,
        .probe          = ath5k_pci_probe,
@@ -329,7 +329,7 @@ init_ath5k_pci(void)
 
        ath5k_debug_init();
 
-       ret = pci_register_driver(&ath5k_pci_drv_id);
+       ret = pci_register_driver(&ath5k_pci_driver);
        if (ret) {
                printk(KERN_ERR "ath5k_pci: can't register pci driver\n");
                return ret;
@@ -341,7 +341,7 @@ init_ath5k_pci(void)
 static void __exit
 exit_ath5k_pci(void)
 {
-       pci_unregister_driver(&ath5k_pci_drv_id);
+       pci_unregister_driver(&ath5k_pci_driver);
 
        ath5k_debug_finish();
 }
index 32a24f5c4fa61c5a0ce26364a79a032487e4435d..08a011f0834a045e8547a421654bc496bd367341 100644 (file)
@@ -724,6 +724,7 @@ struct b43_wldev {
        bool short_preamble;    /* TRUE, if short preamble is enabled. */
        bool short_slot;        /* TRUE, if short slot timing is enabled. */
        bool radio_hw_enable;   /* saved state of radio hardware enabled state */
+       bool suspend_in_progress;       /* TRUE, if we are in a suspend/resume cycle */
 
        /* PHY/Radio device. */
        struct b43_phy phy;
index 8a708b77925df438ab5eb959b15edd025da31c96..3dfb28a34be9f8259c75bf5490a703cd88303a02 100644 (file)
@@ -337,7 +337,7 @@ static inline int txring_to_priority(struct b43_dmaring *ring)
        return idx_to_prio[index];
 }
 
-u16 b43_dmacontroller_base(int dma64bit, int controller_idx)
+static u16 b43_dmacontroller_base(enum b43_dmatype type, int controller_idx)
 {
        static const u16 map64[] = {
                B43_MMIO_DMA64_BASE0,
@@ -356,7 +356,7 @@ u16 b43_dmacontroller_base(int dma64bit, int controller_idx)
                B43_MMIO_DMA32_BASE5,
        };
 
-       if (dma64bit) {
+       if (type == B43_DMA_64BIT) {
                B43_WARN_ON(!(controller_idx >= 0 &&
                              controller_idx < ARRAY_SIZE(map64)));
                return map64[controller_idx];
@@ -437,7 +437,7 @@ static int alloc_ringmemory(struct b43_dmaring *ring)
         * 02, which uses 64-bit DMA, needs the ring buffer in very low memory,
         * which accounts for the GFP_DMA flag below.
         */
-       if (ring->dma64)
+       if (ring->type == B43_DMA_64BIT)
                flags |= GFP_DMA;
        ring->descbase = dma_alloc_coherent(dev, B43_DMA_RINGMEMSIZE,
                                            &(ring->dmabase), flags);
@@ -459,7 +459,8 @@ static void free_ringmemory(struct b43_dmaring *ring)
 }
 
 /* Reset the RX DMA channel */
-int b43_dmacontroller_rx_reset(struct b43_wldev *dev, u16 mmio_base, int dma64)
+static int b43_dmacontroller_rx_reset(struct b43_wldev *dev, u16 mmio_base,
+                                     enum b43_dmatype type)
 {
        int i;
        u32 value;
@@ -467,12 +468,13 @@ int b43_dmacontroller_rx_reset(struct b43_wldev *dev, u16 mmio_base, int dma64)
 
        might_sleep();
 
-       offset = dma64 ? B43_DMA64_RXCTL : B43_DMA32_RXCTL;
+       offset = (type == B43_DMA_64BIT) ? B43_DMA64_RXCTL : B43_DMA32_RXCTL;
        b43_write32(dev, mmio_base + offset, 0);
        for (i = 0; i < 10; i++) {
-               offset = dma64 ? B43_DMA64_RXSTATUS : B43_DMA32_RXSTATUS;
+               offset = (type == B43_DMA_64BIT) ? B43_DMA64_RXSTATUS :
+                                                  B43_DMA32_RXSTATUS;
                value = b43_read32(dev, mmio_base + offset);
-               if (dma64) {
+               if (type == B43_DMA_64BIT) {
                        value &= B43_DMA64_RXSTAT;
                        if (value == B43_DMA64_RXSTAT_DISABLED) {
                                i = -1;
@@ -496,7 +498,8 @@ int b43_dmacontroller_rx_reset(struct b43_wldev *dev, u16 mmio_base, int dma64)
 }
 
 /* Reset the TX DMA channel */
-int b43_dmacontroller_tx_reset(struct b43_wldev *dev, u16 mmio_base, int dma64)
+static int b43_dmacontroller_tx_reset(struct b43_wldev *dev, u16 mmio_base,
+                                     enum b43_dmatype type)
 {
        int i;
        u32 value;
@@ -505,9 +508,10 @@ int b43_dmacontroller_tx_reset(struct b43_wldev *dev, u16 mmio_base, int dma64)
        might_sleep();
 
        for (i = 0; i < 10; i++) {
-               offset = dma64 ? B43_DMA64_TXSTATUS : B43_DMA32_TXSTATUS;
+               offset = (type == B43_DMA_64BIT) ? B43_DMA64_TXSTATUS :
+                                                  B43_DMA32_TXSTATUS;
                value = b43_read32(dev, mmio_base + offset);
-               if (dma64) {
+               if (type == B43_DMA_64BIT) {
                        value &= B43_DMA64_TXSTAT;
                        if (value == B43_DMA64_TXSTAT_DISABLED ||
                            value == B43_DMA64_TXSTAT_IDLEWAIT ||
@@ -522,12 +526,13 @@ int b43_dmacontroller_tx_reset(struct b43_wldev *dev, u16 mmio_base, int dma64)
                }
                msleep(1);
        }
-       offset = dma64 ? B43_DMA64_TXCTL : B43_DMA32_TXCTL;
+       offset = (type == B43_DMA_64BIT) ? B43_DMA64_TXCTL : B43_DMA32_TXCTL;
        b43_write32(dev, mmio_base + offset, 0);
        for (i = 0; i < 10; i++) {
-               offset = dma64 ? B43_DMA64_TXSTATUS : B43_DMA32_TXSTATUS;
+               offset = (type == B43_DMA_64BIT) ? B43_DMA64_TXSTATUS :
+                                                  B43_DMA32_TXSTATUS;
                value = b43_read32(dev, mmio_base + offset);
-               if (dma64) {
+               if (type == B43_DMA_64BIT) {
                        value &= B43_DMA64_TXSTAT;
                        if (value == B43_DMA64_TXSTAT_DISABLED) {
                                i = -1;
@@ -552,6 +557,33 @@ int b43_dmacontroller_tx_reset(struct b43_wldev *dev, u16 mmio_base, int dma64)
        return 0;
 }
 
+/* Check if a DMA mapping address is invalid. */
+static bool b43_dma_mapping_error(struct b43_dmaring *ring,
+                                 dma_addr_t addr,
+                                 size_t buffersize)
+{
+       if (unlikely(dma_mapping_error(addr)))
+               return 1;
+
+       switch (ring->type) {
+       case B43_DMA_30BIT:
+               if ((u64)addr + buffersize > (1ULL << 30))
+                       return 1;
+               break;
+       case B43_DMA_32BIT:
+               if ((u64)addr + buffersize > (1ULL << 32))
+                       return 1;
+               break;
+       case B43_DMA_64BIT:
+               /* Currently we can't have addresses beyond
+                * 64bit in the kernel. */
+               break;
+       }
+
+       /* The address is OK. */
+       return 0;
+}
+
 static int setup_rx_descbuffer(struct b43_dmaring *ring,
                               struct b43_dmadesc_generic *desc,
                               struct b43_dmadesc_meta *meta, gfp_t gfp_flags)
@@ -567,7 +599,7 @@ static int setup_rx_descbuffer(struct b43_dmaring *ring,
        if (unlikely(!skb))
                return -ENOMEM;
        dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0);
-       if (dma_mapping_error(dmaaddr)) {
+       if (b43_dma_mapping_error(ring, dmaaddr, ring->rx_buffersize)) {
                /* ugh. try to realloc in zone_dma */
                gfp_flags |= GFP_DMA;
 
@@ -580,7 +612,7 @@ static int setup_rx_descbuffer(struct b43_dmaring *ring,
                                         ring->rx_buffersize, 0);
        }
 
-       if (dma_mapping_error(dmaaddr)) {
+       if (b43_dma_mapping_error(ring, dmaaddr, ring->rx_buffersize)) {
                dev_kfree_skb_any(skb);
                return -EIO;
        }
@@ -645,7 +677,7 @@ static int dmacontroller_setup(struct b43_dmaring *ring)
        u32 trans = ssb_dma_translation(ring->dev->dev);
 
        if (ring->tx) {
-               if (ring->dma64) {
+               if (ring->type == B43_DMA_64BIT) {
                        u64 ringbase = (u64) (ring->dmabase);
 
                        addrext = ((ringbase >> 32) & SSB_DMA_TRANSLATION_MASK)
@@ -677,7 +709,7 @@ static int dmacontroller_setup(struct b43_dmaring *ring)
                err = alloc_initial_descbuffers(ring);
                if (err)
                        goto out;
-               if (ring->dma64) {
+               if (ring->type == B43_DMA_64BIT) {
                        u64 ringbase = (u64) (ring->dmabase);
 
                        addrext = ((ringbase >> 32) & SSB_DMA_TRANSLATION_MASK)
@@ -722,16 +754,16 @@ static void dmacontroller_cleanup(struct b43_dmaring *ring)
 {
        if (ring->tx) {
                b43_dmacontroller_tx_reset(ring->dev, ring->mmio_base,
-                                          ring->dma64);
-               if (ring->dma64) {
+                                          ring->type);
+               if (ring->type == B43_DMA_64BIT) {
                        b43_dma_write(ring, B43_DMA64_TXRINGLO, 0);
                        b43_dma_write(ring, B43_DMA64_TXRINGHI, 0);
                } else
                        b43_dma_write(ring, B43_DMA32_TXRING, 0);
        } else {
                b43_dmacontroller_rx_reset(ring->dev, ring->mmio_base,
-                                          ring->dma64);
-               if (ring->dma64) {
+                                          ring->type);
+               if (ring->type == B43_DMA_64BIT) {
                        b43_dma_write(ring, B43_DMA64_RXRINGLO, 0);
                        b43_dma_write(ring, B43_DMA64_RXRINGHI, 0);
                } else
@@ -786,7 +818,8 @@ static u64 supported_dma_mask(struct b43_wldev *dev)
 static
 struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev,
                                      int controller_index,
-                                     int for_tx, int dma64)
+                                     int for_tx,
+                                     enum b43_dmatype type)
 {
        struct b43_dmaring *ring;
        int err;
@@ -796,6 +829,7 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev,
        ring = kzalloc(sizeof(*ring), GFP_KERNEL);
        if (!ring)
                goto out;
+       ring->type = type;
 
        nr_slots = B43_RXRING_SLOTS;
        if (for_tx)
@@ -818,7 +852,7 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev,
                                          b43_txhdr_size(dev),
                                          DMA_TO_DEVICE);
 
-               if (dma_mapping_error(dma_test)) {
+               if (b43_dma_mapping_error(ring, dma_test, b43_txhdr_size(dev))) {
                        /* ugh realloc */
                        kfree(ring->txhdr_cache);
                        ring->txhdr_cache = kcalloc(nr_slots,
@@ -832,7 +866,8 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev,
                                                  b43_txhdr_size(dev),
                                                  DMA_TO_DEVICE);
 
-                       if (dma_mapping_error(dma_test))
+                       if (b43_dma_mapping_error(ring, dma_test,
+                                                 b43_txhdr_size(dev)))
                                goto err_kfree_txhdr_cache;
                }
 
@@ -843,10 +878,9 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev,
 
        ring->dev = dev;
        ring->nr_slots = nr_slots;
-       ring->mmio_base = b43_dmacontroller_base(dma64, controller_index);
+       ring->mmio_base = b43_dmacontroller_base(type, controller_index);
        ring->index = controller_index;
-       ring->dma64 = !!dma64;
-       if (dma64)
+       if (type == B43_DMA_64BIT)
                ring->ops = &dma64_ops;
        else
                ring->ops = &dma32_ops;
@@ -896,8 +930,8 @@ static void b43_destroy_dmaring(struct b43_dmaring *ring)
        if (!ring)
                return;
 
-       b43dbg(ring->dev->wl, "DMA-%s 0x%04X (%s) max used slots: %d/%d\n",
-              (ring->dma64) ? "64" : "32",
+       b43dbg(ring->dev->wl, "DMA-%u 0x%04X (%s) max used slots: %d/%d\n",
+              (unsigned int)(ring->type),
               ring->mmio_base,
               (ring->tx) ? "TX" : "RX", ring->max_used_slots, ring->nr_slots);
        /* Device IRQs are disabled prior entering this function,
@@ -941,12 +975,22 @@ int b43_dma_init(struct b43_wldev *dev)
        struct b43_dmaring *ring;
        int err;
        u64 dmamask;
-       int dma64 = 0;
+       enum b43_dmatype type;
 
        dmamask = supported_dma_mask(dev);
-       if (dmamask == DMA_64BIT_MASK)
-               dma64 = 1;
-
+       switch (dmamask) {
+       default:
+               B43_WARN_ON(1);
+       case DMA_30BIT_MASK:
+               type = B43_DMA_30BIT;
+               break;
+       case DMA_32BIT_MASK:
+               type = B43_DMA_32BIT;
+               break;
+       case DMA_64BIT_MASK:
+               type = B43_DMA_64BIT;
+               break;
+       }
        err = ssb_dma_set_mask(dev->dev, dmamask);
        if (err) {
                b43err(dev->wl, "The machine/kernel does not support "
@@ -958,52 +1002,51 @@ int b43_dma_init(struct b43_wldev *dev)
 
        err = -ENOMEM;
        /* setup TX DMA channels. */
-       ring = b43_setup_dmaring(dev, 0, 1, dma64);
+       ring = b43_setup_dmaring(dev, 0, 1, type);
        if (!ring)
                goto out;
        dma->tx_ring0 = ring;
 
-       ring = b43_setup_dmaring(dev, 1, 1, dma64);
+       ring = b43_setup_dmaring(dev, 1, 1, type);
        if (!ring)
                goto err_destroy_tx0;
        dma->tx_ring1 = ring;
 
-       ring = b43_setup_dmaring(dev, 2, 1, dma64);
+       ring = b43_setup_dmaring(dev, 2, 1, type);
        if (!ring)
                goto err_destroy_tx1;
        dma->tx_ring2 = ring;
 
-       ring = b43_setup_dmaring(dev, 3, 1, dma64);
+       ring = b43_setup_dmaring(dev, 3, 1, type);
        if (!ring)
                goto err_destroy_tx2;
        dma->tx_ring3 = ring;
 
-       ring = b43_setup_dmaring(dev, 4, 1, dma64);
+       ring = b43_setup_dmaring(dev, 4, 1, type);
        if (!ring)
                goto err_destroy_tx3;
        dma->tx_ring4 = ring;
 
-       ring = b43_setup_dmaring(dev, 5, 1, dma64);
+       ring = b43_setup_dmaring(dev, 5, 1, type);
        if (!ring)
                goto err_destroy_tx4;
        dma->tx_ring5 = ring;
 
        /* setup RX DMA channels. */
-       ring = b43_setup_dmaring(dev, 0, 0, dma64);
+       ring = b43_setup_dmaring(dev, 0, 0, type);
        if (!ring)
                goto err_destroy_tx5;
        dma->rx_ring0 = ring;
 
        if (dev->dev->id.revision < 5) {
-               ring = b43_setup_dmaring(dev, 3, 0, dma64);
+               ring = b43_setup_dmaring(dev, 3, 0, type);
                if (!ring)
                        goto err_destroy_rx0;
                dma->rx_ring3 = ring;
        }
 
-       b43dbg(dev->wl, "%d-bit DMA initialized\n",
-              (dmamask == DMA_64BIT_MASK) ? 64 :
-              (dmamask == DMA_32BIT_MASK) ? 32 : 30);
+       b43dbg(dev->wl, "%u-bit DMA initialized\n",
+              (unsigned int)type);
        err = 0;
       out:
        return err;
@@ -1146,7 +1189,7 @@ static int dma_tx_fragment(struct b43_dmaring *ring,
 
        meta_hdr->dmaaddr = map_descbuffer(ring, (unsigned char *)header,
                                           hdrsize, 1);
-       if (dma_mapping_error(meta_hdr->dmaaddr)) {
+       if (b43_dma_mapping_error(ring, meta_hdr->dmaaddr, hdrsize)) {
                ring->current_slot = old_top_slot;
                ring->used_slots = old_used_slots;
                return -EIO;
@@ -1165,7 +1208,7 @@ static int dma_tx_fragment(struct b43_dmaring *ring,
 
        meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
        /* create a bounce buffer in zone_dma on mapping failure. */
-       if (dma_mapping_error(meta->dmaaddr)) {
+       if (b43_dma_mapping_error(ring, meta->dmaaddr, skb->len)) {
                bounce_skb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
                if (!bounce_skb) {
                        ring->current_slot = old_top_slot;
@@ -1179,7 +1222,7 @@ static int dma_tx_fragment(struct b43_dmaring *ring,
                skb = bounce_skb;
                meta->skb = skb;
                meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
-               if (dma_mapping_error(meta->dmaaddr)) {
+               if (b43_dma_mapping_error(ring, meta->dmaaddr, skb->len)) {
                        ring->current_slot = old_top_slot;
                        ring->used_slots = old_used_slots;
                        err = -EIO;
index 58db03ac536e596e060e94815a0fb0bfbe87d0c0..c0d6b69e650128fa68dc7825f8cf00c10e23f073 100644 (file)
@@ -203,6 +203,12 @@ struct b43_dma_ops {
        void (*set_current_rxslot) (struct b43_dmaring * ring, int slot);
 };
 
+enum b43_dmatype {
+       B43_DMA_30BIT   = 30,
+       B43_DMA_32BIT   = 32,
+       B43_DMA_64BIT   = 64,
+};
+
 struct b43_dmaring {
        /* Lowlevel DMA ops. */
        const struct b43_dma_ops *ops;
@@ -235,8 +241,8 @@ struct b43_dmaring {
        int index;
        /* Boolean. Is this a TX ring? */
        bool tx;
-       /* Boolean. 64bit DMA if true, 32bit DMA otherwise. */
-       bool dma64;
+       /* The type of DMA engine used. */
+       enum b43_dmatype type;
        /* Boolean. Is this ring stopped at ieee80211 level? */
        bool stopped;
        /* Lock, only used for TX. */
@@ -255,8 +261,7 @@ static inline u32 b43_dma_read(struct b43_dmaring *ring, u16 offset)
        return b43_read32(ring->dev, ring->mmio_base + offset);
 }
 
-static inline
-    void b43_dma_write(struct b43_dmaring *ring, u16 offset, u32 value)
+static inline void b43_dma_write(struct b43_dmaring *ring, u16 offset, u32 value)
 {
        b43_write32(ring->dev, ring->mmio_base + offset, value);
 }
@@ -264,13 +269,6 @@ static inline
 int b43_dma_init(struct b43_wldev *dev);
 void b43_dma_free(struct b43_wldev *dev);
 
-int b43_dmacontroller_rx_reset(struct b43_wldev *dev,
-                              u16 dmacontroller_mmio_base, int dma64);
-int b43_dmacontroller_tx_reset(struct b43_wldev *dev,
-                              u16 dmacontroller_mmio_base, int dma64);
-
-u16 b43_dmacontroller_base(int dma64bit, int dmacontroller_idx);
-
 void b43_dma_tx_suspend(struct b43_wldev *dev);
 void b43_dma_tx_resume(struct b43_wldev *dev);
 
index 4b590d8c65ff08317fc6405546545e64bc104115..0908335892dbba7214fc1d995d7a9af2da7f54e5 100644 (file)
@@ -116,7 +116,10 @@ static void b43_unregister_led(struct b43_led *led)
 {
        if (!led->dev)
                return;
-       led_classdev_unregister(&led->led_dev);
+       if (led->dev->suspend_in_progress)
+               led_classdev_unregister_suspended(&led->led_dev);
+       else
+               led_classdev_unregister(&led->led_dev);
        b43_led_turn_off(led->dev, led->index, led->activelow);
        led->dev = NULL;
 }
index 64c154d080d865fdde6a792e7ea5008af459a25b..ef65c41af00fc022e4841baa843571f1ae107fda 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/wireless.h>
 #include <linux/workqueue.h>
 #include <linux/skbuff.h>
+#include <linux/io.h>
 #include <linux/dma-mapping.h>
 #include <asm/unaligned.h>
 
@@ -2554,10 +2555,10 @@ static int b43_rng_read(struct hwrng *rng, u32 * data)
        return (sizeof(u16));
 }
 
-static void b43_rng_exit(struct b43_wl *wl)
+static void b43_rng_exit(struct b43_wl *wl, bool suspended)
 {
        if (wl->rng_initialized)
-               hwrng_unregister(&wl->rng);
+               __hwrng_unregister(&wl->rng, suspended);
 }
 
 static int b43_rng_init(struct b43_wl *wl)
@@ -3417,8 +3418,10 @@ static void b43_wireless_core_exit(struct b43_wldev *dev)
        macctl |= B43_MACCTL_PSM_JMP0;
        b43_write32(dev, B43_MMIO_MACCTL, macctl);
 
-       b43_leds_exit(dev);
-       b43_rng_exit(dev->wl);
+       if (!dev->suspend_in_progress) {
+               b43_leds_exit(dev);
+               b43_rng_exit(dev->wl, false);
+       }
        b43_dma_free(dev);
        b43_chip_exit(dev);
        b43_radio_turn_off(dev, 1);
@@ -3534,11 +3537,13 @@ static int b43_wireless_core_init(struct b43_wldev *dev)
        ssb_bus_powerup(bus, 1);        /* Enable dynamic PCTL */
        b43_upload_card_macaddress(dev);
        b43_security_init(dev);
-       b43_rng_init(wl);
+       if (!dev->suspend_in_progress)
+               b43_rng_init(wl);
 
        b43_set_status(dev, B43_STAT_INITIALIZED);
 
-       b43_leds_init(dev);
+       if (!dev->suspend_in_progress)
+               b43_leds_init(dev);
 out:
        return err;
 
@@ -4135,6 +4140,7 @@ static int b43_suspend(struct ssb_device *dev, pm_message_t state)
        b43dbg(wl, "Suspending...\n");
 
        mutex_lock(&wl->mutex);
+       wldev->suspend_in_progress = true;
        wldev->suspend_init_status = b43_status(wldev);
        if (wldev->suspend_init_status >= B43_STAT_STARTED)
                b43_wireless_core_stop(wldev);
@@ -4166,15 +4172,17 @@ static int b43_resume(struct ssb_device *dev)
        if (wldev->suspend_init_status >= B43_STAT_STARTED) {
                err = b43_wireless_core_start(wldev);
                if (err) {
+                       b43_leds_exit(wldev);
+                       b43_rng_exit(wldev->wl, true);
                        b43_wireless_core_exit(wldev);
                        b43err(wl, "Resume failed at core start\n");
                        goto out;
                }
        }
-       mutex_unlock(&wl->mutex);
-
        b43dbg(wl, "Device resumed.\n");
-      out:
+ out:
+       wldev->suspend_in_progress = false;
+       mutex_unlock(&wl->mutex);
        return err;
 }
 
index 83161d9af813a06a73a7733ea1180217be531094..6e08405e8026cfca7e1a0f74f0418315b89c2bed 100644 (file)
@@ -1164,7 +1164,7 @@ static int dma_tx_fragment(struct b43legacy_dmaring *ring,
 {
        const struct b43legacy_dma_ops *ops = ring->ops;
        u8 *header;
-       int slot;
+       int slot, old_top_slot, old_used_slots;
        int err;
        struct b43legacy_dmadesc_generic *desc;
        struct b43legacy_dmadesc_meta *meta;
@@ -1174,6 +1174,9 @@ static int dma_tx_fragment(struct b43legacy_dmaring *ring,
 #define SLOTS_PER_PACKET  2
        B43legacy_WARN_ON(skb_shinfo(skb)->nr_frags != 0);
 
+       old_top_slot = ring->current_slot;
+       old_used_slots = ring->used_slots;
+
        /* Get a slot for the header. */
        slot = request_slot(ring);
        desc = ops->idx2desc(ring, slot, &meta_hdr);
@@ -1181,9 +1184,14 @@ static int dma_tx_fragment(struct b43legacy_dmaring *ring,
 
        header = &(ring->txhdr_cache[slot * sizeof(
                               struct b43legacy_txhdr_fw3)]);
-       b43legacy_generate_txhdr(ring->dev, header,
+       err = b43legacy_generate_txhdr(ring->dev, header,
                                 skb->data, skb->len, ctl,
                                 generate_cookie(ring, slot));
+       if (unlikely(err)) {
+               ring->current_slot = old_top_slot;
+               ring->used_slots = old_used_slots;
+               return err;
+       }
 
        meta_hdr->dmaaddr = map_descbuffer(ring, (unsigned char *)header,
                                       sizeof(struct b43legacy_txhdr_fw3), 1);
@@ -1206,6 +1214,8 @@ static int dma_tx_fragment(struct b43legacy_dmaring *ring,
        if (dma_mapping_error(meta->dmaaddr)) {
                bounce_skb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
                if (!bounce_skb) {
+                       ring->current_slot = old_top_slot;
+                       ring->used_slots = old_used_slots;
                        err = -ENOMEM;
                        goto out_unmap_hdr;
                }
@@ -1216,6 +1226,8 @@ static int dma_tx_fragment(struct b43legacy_dmaring *ring,
                meta->skb = skb;
                meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
                if (dma_mapping_error(meta->dmaaddr)) {
+                       ring->current_slot = old_top_slot;
+                       ring->used_slots = old_used_slots;
                        err = -EIO;
                        goto out_free_bounce;
                }
@@ -1282,6 +1294,13 @@ int b43legacy_dma_tx(struct b43legacy_wldev *dev,
        B43legacy_BUG_ON(ring->stopped);
 
        err = dma_tx_fragment(ring, skb, ctl);
+       if (unlikely(err == -ENOKEY)) {
+               /* Drop this packet, as we don't have the encryption key
+                * anymore and must not transmit it unencrypted. */
+               dev_kfree_skb_any(skb);
+               err = 0;
+               goto out_unlock;
+       }
        if (unlikely(err)) {
                b43legacyerr(dev->wl, "DMA tx mapping failure\n");
                goto out_unlock;
index aa20d5d56e2f479d625c2411c53228ebaa3876e9..53f7f2e97615d0c80b6c918474b9a9ed2684f333 100644 (file)
@@ -3160,8 +3160,6 @@ static int b43legacy_wireless_core_init(struct b43legacy_wldev *dev)
        b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x0414, 0x01F4);
 
        ssb_bus_powerup(bus, 1); /* Enable dynamic PCTL */
-       memset(wl->bssid, 0, ETH_ALEN);
-       memset(wl->mac_addr, 0, ETH_ALEN);
        b43legacy_upload_card_macaddress(dev);
        b43legacy_security_init(dev);
        b43legacy_rng_init(wl);
@@ -3263,6 +3261,13 @@ static int b43legacy_op_start(struct ieee80211_hw *hw)
         * LEDs that are registered later depend on it. */
        b43legacy_rfkill_init(dev);
 
+       /* Kill all old instance specific information to make sure
+        * the card won't use it in the short timeframe between start
+        * and mac80211 reconfiguring it. */
+       memset(wl->bssid, 0, ETH_ALEN);
+       memset(wl->mac_addr, 0, ETH_ALEN);
+       wl->filter_flags = 0;
+
        mutex_lock(&wl->mutex);
 
        if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED) {
index e4f4c5c39e334ebf4c37c0e903b66ec989f71b82..bcdd54eb2edb52683804712201f8ee78260c853b 100644 (file)
@@ -181,7 +181,7 @@ union txhdr_union {
        struct b43legacy_txhdr_fw3 txhdr_fw3;
 };
 
-static void pio_tx_write_fragment(struct b43legacy_pioqueue *queue,
+static int pio_tx_write_fragment(struct b43legacy_pioqueue *queue,
                                  struct sk_buff *skb,
                                  struct b43legacy_pio_txpacket *packet,
                                  size_t txhdr_size)
@@ -189,14 +189,17 @@ static void pio_tx_write_fragment(struct b43legacy_pioqueue *queue,
        union txhdr_union txhdr_data;
        u8 *txhdr = NULL;
        unsigned int octets;
+       int err;
 
        txhdr = (u8 *)(&txhdr_data.txhdr_fw3);
 
        B43legacy_WARN_ON(skb_shinfo(skb)->nr_frags != 0);
-       b43legacy_generate_txhdr(queue->dev,
+       err = b43legacy_generate_txhdr(queue->dev,
                                 txhdr, skb->data, skb->len,
                                 &packet->txstat.control,
                                 generate_cookie(queue, packet));
+       if (err)
+               return err;
 
        tx_start(queue);
        octets = skb->len + txhdr_size;
@@ -204,6 +207,8 @@ static void pio_tx_write_fragment(struct b43legacy_pioqueue *queue,
                octets--;
        tx_data(queue, txhdr, (u8 *)skb->data, octets);
        tx_complete(queue, skb);
+
+       return 0;
 }
 
 static void free_txpacket(struct b43legacy_pio_txpacket *packet,
@@ -226,6 +231,7 @@ static int pio_tx_packet(struct b43legacy_pio_txpacket *packet)
        struct b43legacy_pioqueue *queue = packet->queue;
        struct sk_buff *skb = packet->skb;
        u16 octets;
+       int err;
 
        octets = (u16)skb->len + sizeof(struct b43legacy_txhdr_fw3);
        if (queue->tx_devq_size < octets) {
@@ -247,8 +253,14 @@ static int pio_tx_packet(struct b43legacy_pio_txpacket *packet)
        if (queue->tx_devq_used + octets > queue->tx_devq_size)
                return -EBUSY;
        /* Now poke the device. */
-       pio_tx_write_fragment(queue, skb, packet,
+       err = pio_tx_write_fragment(queue, skb, packet,
                              sizeof(struct b43legacy_txhdr_fw3));
+       if (unlikely(err == -ENOKEY)) {
+               /* Drop this packet, as we don't have the encryption key
+                * anymore and must not transmit it unencrypted. */
+               free_txpacket(packet, 1);
+               return 0;
+       }
 
        /* Account for the packet size.
         * (We must not overflow the device TX queue)
@@ -486,6 +498,9 @@ void b43legacy_pio_handle_txstatus(struct b43legacy_wldev *dev,
        queue = parse_cookie(dev, status->cookie, &packet);
        B43legacy_WARN_ON(!queue);
 
+       if (!packet->skb)
+               return;
+
        queue->tx_devq_packets--;
        queue->tx_devq_used -= (packet->skb->len +
                                sizeof(struct b43legacy_txhdr_fw3));
index e20c552442d53892bef644b8d4485dcc66972851..d84408a82db9ef6aa50857a3ad2fa4b4e4da2439 100644 (file)
@@ -181,7 +181,7 @@ static u8 b43legacy_calc_fallback_rate(u8 bitrate)
        return 0;
 }
 
-static void generate_txhdr_fw3(struct b43legacy_wldev *dev,
+static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
                               struct b43legacy_txhdr_fw3 *txhdr,
                               const unsigned char *fragment_data,
                               unsigned int fragment_len,
@@ -252,6 +252,13 @@ static void generate_txhdr_fw3(struct b43legacy_wldev *dev,
                        iv_len = min((size_t)txctl->iv_len,
                                     ARRAY_SIZE(txhdr->iv));
                        memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
+               } else {
+                       /* This key is invalid. This might only happen
+                        * in a short timeframe after machine resume before
+                        * we were able to reconfigure keys.
+                        * Drop this packet completely. Do not transmit it
+                        * unencrypted to avoid leaking information. */
+                       return -ENOKEY;
                }
        }
        b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
@@ -345,16 +352,18 @@ static void generate_txhdr_fw3(struct b43legacy_wldev *dev,
        /* Apply the bitfields */
        txhdr->mac_ctl = cpu_to_le32(mac_ctl);
        txhdr->phy_ctl = cpu_to_le16(phy_ctl);
+
+       return 0;
 }
 
-void b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
+int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
                              u8 *txhdr,
                              const unsigned char *fragment_data,
                              unsigned int fragment_len,
                              const struct ieee80211_tx_control *txctl,
                              u16 cookie)
 {
-       generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
+       return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
                           fragment_data, fragment_len,
                           txctl, cookie);
 }
index 8a155d0a5d1fbb2c4b7d4528ce7ae900d8a261be..bab47928a0c9b776e5febd7b546e6da3d635827a 100644 (file)
@@ -76,7 +76,7 @@ struct b43legacy_txhdr_fw3 {
 
 
 
-void b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
+int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
                              u8 *txhdr,
                              const unsigned char *fragment_data,
                              unsigned int fragment_len,
index 2ab107f457937b96b339711d6c7eaa6ffa8f79c0..5bf9e00b070c4478706ff094c8828c80b8efb7cd 100644 (file)
@@ -162,7 +162,7 @@ that only one external action is invoked at a time.
 #include <linux/firmware.h>
 #include <linux/acpi.h>
 #include <linux/ctype.h>
-#include <linux/latency.h>
+#include <linux/pm_qos_params.h>
 
 #include "ipw2100.h"
 
@@ -1701,7 +1701,7 @@ static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
        /* the ipw2100 hardware really doesn't want power management delays
         * longer than 175usec
         */
-       modify_acceptable_latency("ipw2100", 175);
+       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", 175);
 
        /* If the interrupt is enabled, turn it off... */
        spin_lock_irqsave(&priv->low_lock, flags);
@@ -1856,7 +1856,8 @@ static void ipw2100_down(struct ipw2100_priv *priv)
        ipw2100_disable_interrupts(priv);
        spin_unlock_irqrestore(&priv->low_lock, flags);
 
-       modify_acceptable_latency("ipw2100", INFINITE_LATENCY);
+       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
+                       PM_QOS_DEFAULT_VALUE);
 
        /* We have to signal any supplicant if we are disassociating */
        if (associated)
@@ -6554,7 +6555,8 @@ static int __init ipw2100_init(void)
        if (ret)
                goto out;
 
-       set_acceptable_latency("ipw2100", INFINITE_LATENCY);
+       pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
+                       PM_QOS_DEFAULT_VALUE);
 #ifdef CONFIG_IPW2100_DEBUG
        ipw2100_debug_level = debug;
        ret = driver_create_file(&ipw2100_pci_driver.driver,
@@ -6576,7 +6578,7 @@ static void __exit ipw2100_exit(void)
                           &driver_attr_debug_level);
 #endif
        pci_unregister_driver(&ipw2100_pci_driver);
-       remove_acceptable_latency("ipw2100");
+       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100");
 }
 
 module_init(ipw2100_init);
index 4fdeb53232486a1fac23eae1735c53fc338fd8f8..8d4d91d35fd29f14ed3b8c21323da34c7122c264 100644 (file)
@@ -238,9 +238,10 @@ void iwl3945_hw_rx_statistics(struct iwl3945_priv *priv, struct iwl3945_rx_mem_b
        priv->last_statistics_time = jiffies;
 }
 
-void iwl3945_add_radiotap(struct iwl3945_priv *priv, struct sk_buff *skb,
-                         struct iwl3945_rx_frame_hdr *rx_hdr,
-                         struct ieee80211_rx_status *stats)
+static void iwl3945_add_radiotap(struct iwl3945_priv *priv,
+                                struct sk_buff *skb,
+                                struct iwl3945_rx_frame_hdr *rx_hdr,
+                                struct ieee80211_rx_status *stats)
 {
        /* First cache any information we need before we overwrite
         * the information provided in the skb from the hardware */
index 569347ff377b18e7cb494152734f471f454fd3f0..d727de8b96fef956d3020bdde0428336ebb9d7a1 100644 (file)
@@ -4658,17 +4658,30 @@ void iwl4965_set_ht_add_station(struct iwl4965_priv *priv, u8 index,
                                struct ieee80211_ht_info *sta_ht_inf)
 {
        __le32 sta_flags;
+       u8 mimo_ps_mode;
 
        if (!sta_ht_inf || !sta_ht_inf->ht_supported)
                goto done;
 
+       mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
+
        sta_flags = priv->stations[index].sta.station_flags;
 
-       if (((sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS >> 2))
-                                               == IWL_MIMO_PS_DYNAMIC)
+       sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
+
+       switch (mimo_ps_mode) {
+       case WLAN_HT_CAP_MIMO_PS_STATIC:
+               sta_flags |= STA_FLG_MIMO_DIS_MSK;
+               break;
+       case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
                sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
-       else
-               sta_flags &= ~STA_FLG_RTS_MIMO_PROT_MSK;
+               break;
+       case WLAN_HT_CAP_MIMO_PS_DISABLED:
+               break;
+       default:
+               IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
+               break;
+       }
 
        sta_flags |= cpu_to_le32(
              (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
@@ -4679,7 +4692,7 @@ void iwl4965_set_ht_add_station(struct iwl4965_priv *priv, u8 index,
        if (iwl4965_is_fat_tx_allowed(priv, sta_ht_inf))
                sta_flags |= STA_FLG_FAT_EN_MSK;
        else
-               sta_flags &= (~STA_FLG_FAT_EN_MSK);
+               sta_flags &= ~STA_FLG_FAT_EN_MSK;
 
        priv->stations[index].sta.station_flags = sta_flags;
  done:
index cb009f4c401fd9db96d5b2129eed5e02980f41d9..8993cca81b40c033cb561188aeb37210caaffa57 100644 (file)
@@ -147,9 +147,6 @@ static inline struct ieee80211_conf *ieee80211_get_hw_conf(
 
 #define QOS_CONTROL_LEN 2
 
-#define IEEE80211_STYPE_BACK_REQ       0x0080
-#define IEEE80211_STYPE_BACK           0x0090
-
 
 static inline int ieee80211_is_management(u16 fc)
 {
index 33239f197984302f53125191546a176f67b46892..5ee1ad69898b6f36aed5b84a2270b9431274e1ab 100644 (file)
@@ -4207,13 +4207,13 @@ static u8 ratio2dB[100] = {
  * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
 int iwl3945_calc_db_from_ratio(int sig_ratio)
 {
-       /* Anything above 1000:1 just report as 60 dB */
-       if (sig_ratio > 1000)
+       /* 1000:1 or higher just report as 60 dB */
+       if (sig_ratio >= 1000)
                return 60;
 
-       /* Above 100:1, divide by 10 and use table,
+       /* 100:1 or higher, divide by 10 and use table,
         *   add 20 dB to make up for divide by 10 */
-       if (sig_ratio > 100)
+       if (sig_ratio >= 100)
                return (20 + (int)ratio2dB[sig_ratio/10]);
 
        /* We shouldn't see this */
@@ -6330,6 +6330,11 @@ static int __iwl3945_up(struct iwl3945_priv *priv)
                return -ENODEV;
        }
 
+       if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
+               IWL_ERROR("ucode not available for device bringup\n");
+               return -EIO;
+       }
+
        /* If platform's RF_KILL switch is NOT set to KILL */
        if (iwl3945_read32(priv, CSR_GP_CNTRL) &
                                CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
@@ -6342,11 +6347,6 @@ static int __iwl3945_up(struct iwl3945_priv *priv)
                }
        }
 
-       if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
-               IWL_ERROR("ucode not available for device bringup\n");
-               return -EIO;
-       }
-
        iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
 
        rc = iwl3945_hw_nic_init(priv);
index bf3a60c037aa915b8a6f67fe2a045221b26d9770..f423241b95674ad7cca340fa591f27c48a10bd13 100644 (file)
@@ -6755,6 +6755,11 @@ static int __iwl4965_up(struct iwl4965_priv *priv)
                return -ENODEV;
        }
 
+       if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
+               IWL_ERROR("ucode not available for device bringup\n");
+               return -EIO;
+       }
+
        /* If platform's RF_KILL switch is NOT set to KILL */
        if (iwl4965_read32(priv, CSR_GP_CNTRL) &
                                CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
@@ -6767,11 +6772,6 @@ static int __iwl4965_up(struct iwl4965_priv *priv)
                }
        }
 
-       if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
-               IWL_ERROR("ucode not available for device bringup\n");
-               return -EIO;
-       }
-
        iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
 
        rc = iwl4965_hw_nic_init(priv);
index 9a61188b62e92cf2fe9984c5ca58f4ac8cbd8570..69f94c92b32d8986a5221658b180d09c94b0a6d7 100644 (file)
@@ -1473,7 +1473,7 @@ int lbs_get_scan(struct net_device *dev, struct iw_request_info *info,
  *  Called via lbs_prepare_and_send_command(priv, CMD_802_11_SCAN, ...)
  *  from cmd.c
  *
- *  Sends a fixed lenght data part (specifying the BSS type and BSSID filters)
+ *  Sends a fixed length data part (specifying the BSS type and BSSID filters)
  *  as well as a variable number/length of TLVs to the firmware.
  *
  *  @param priv       A pointer to struct lbs_private structure
index d2fa079fbc4c140f0719192d73a984be10f0cd65..f479c1af67822dfdf3813c22e8e9f60846401da7 100644 (file)
@@ -195,7 +195,7 @@ static int netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
 static void netwave_detach(struct pcmcia_device *p_dev);    /* Destroy instance */
 
 /* Hardware configuration */
-static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
+static void netwave_doreset(unsigned int iobase, u_char __iomem *ramBase);
 static void netwave_reset(struct net_device *dev);
 
 /* Misc device stuff */
@@ -309,7 +309,7 @@ static inline void wait_WOC(unsigned int iobase)
 }
 
 static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase, 
-                            kio_addr_t iobase) {
+                            unsigned int iobase) {
     u_short resultBuffer;
 
     /* if time since last snapshot is > 1 sec. (100 jiffies?)  then take 
@@ -340,7 +340,7 @@ static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
 static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
 {      
     unsigned long flags;
-    kio_addr_t iobase = dev->base_addr;
+    unsigned int iobase = dev->base_addr;
     netwave_private *priv = netdev_priv(dev);
     u_char __iomem *ramBase = priv->ramBase;
     struct iw_statistics* wstats;
@@ -471,7 +471,7 @@ static int netwave_set_nwid(struct net_device *dev,
                            char *extra)
 {
        unsigned long flags;
-       kio_addr_t iobase = dev->base_addr;
+       unsigned int iobase = dev->base_addr;
        netwave_private *priv = netdev_priv(dev);
        u_char __iomem *ramBase = priv->ramBase;
 
@@ -518,7 +518,7 @@ static int netwave_set_scramble(struct net_device *dev,
                                char *key)
 {
        unsigned long flags;
-       kio_addr_t iobase = dev->base_addr;
+       unsigned int iobase = dev->base_addr;
        netwave_private *priv = netdev_priv(dev);
        u_char __iomem *ramBase = priv->ramBase;
 
@@ -621,7 +621,7 @@ static int netwave_get_snap(struct net_device *dev,
                            char *extra)
 {
        unsigned long flags;
-       kio_addr_t iobase = dev->base_addr;
+       unsigned int iobase = dev->base_addr;
        netwave_private *priv = netdev_priv(dev);
        u_char __iomem *ramBase = priv->ramBase;
 
@@ -874,7 +874,7 @@ static int netwave_resume(struct pcmcia_device *link)
  *
  *    Proper hardware reset of the card.
  */
-static void netwave_doreset(kio_addr_t ioBase, u_char __iomem *ramBase)
+static void netwave_doreset(unsigned int ioBase, u_char __iomem *ramBase)
 {
     /* Reset card */
     wait_WOC(ioBase);
@@ -892,7 +892,7 @@ static void netwave_reset(struct net_device *dev) {
     /* u_char state; */
     netwave_private *priv = netdev_priv(dev);
     u_char __iomem *ramBase = priv->ramBase;
-    kio_addr_t iobase = dev->base_addr;
+    unsigned int iobase = dev->base_addr;
 
     DEBUG(0, "netwave_reset: Done with hardware reset\n");
 
@@ -973,7 +973,7 @@ static int netwave_hw_xmit(unsigned char* data, int len,
        
     netwave_private *priv = netdev_priv(dev);
     u_char __iomem * ramBase = priv->ramBase;
-    kio_addr_t iobase = dev->base_addr;
+    unsigned int iobase = dev->base_addr;
 
     /* Disable interrupts & save flags */
     spin_lock_irqsave(&priv->spinlock, flags);
@@ -1065,7 +1065,7 @@ static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
  */
 static irqreturn_t netwave_interrupt(int irq, void* dev_id)
 {
-    kio_addr_t iobase;
+    unsigned int iobase;
     u_char __iomem *ramBase;
     struct net_device *dev = (struct net_device *)dev_id;
     struct netwave_private *priv = netdev_priv(dev);
@@ -1235,7 +1235,7 @@ static int netwave_rx(struct net_device *dev)
 {
     netwave_private *priv = netdev_priv(dev);
     u_char __iomem *ramBase = priv->ramBase;
-    kio_addr_t iobase = dev->base_addr;
+    unsigned int iobase = dev->base_addr;
     u_char rxStatus;
     struct sk_buff *skb = NULL;
     unsigned int curBuffer,
@@ -1388,7 +1388,7 @@ module_exit(exit_netwave_cs);
  */
 static void set_multicast_list(struct net_device *dev)
 {
-    kio_addr_t iobase = dev->base_addr;
+    unsigned int iobase = dev->base_addr;
     netwave_private *priv = netdev_priv(dev);
     u_char __iomem * ramBase = priv->ramBase;
     u_char  rcvMode = 0;
index c2037b2a05bf664c5e37192bb6cc9f37956230e6..06eea6ab7bf065278f46d12bae48149d0c579d53 100644 (file)
@@ -149,7 +149,7 @@ psa_write(struct net_device *       dev,
   net_local *lp = netdev_priv(dev);
   u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
   int          count = 0;
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   /* As there seem to have no flag PSA_BUSY as in the ISA model, we are
    * oblige to verify this address to know when the PSA is ready... */
   volatile u_char __iomem *verify = lp->mem + PSA_ADDR +
@@ -708,7 +708,7 @@ static void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqua
 /* Perform a handover to a new WavePoint */
 static void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
 {
-  kio_addr_t           base = lp->dev->base_addr;
+  unsigned int         base = lp->dev->base_addr;
   mm_t                  m;
   unsigned long         flags;
 
@@ -821,7 +821,7 @@ wv_82593_cmd(struct net_device *    dev,
             int        cmd,
             int        result)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   int          status;
   int          wait_completed;
   long         spin;
@@ -945,7 +945,7 @@ read_ringbuf(struct net_device *    dev,
             char *     buf,
             int        len)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   int          ring_ptr = addr;
   int          chunk_len;
   char *       buf_ptr = buf;
@@ -1096,7 +1096,7 @@ wv_psa_show(psa_t *       p)
 static void
 wv_mmc_show(struct net_device *        dev)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   net_local *  lp = netdev_priv(dev);
   mmr_t                m;
 
@@ -1275,7 +1275,7 @@ wv_packet_info(u_char *           p,              /* Packet to dump */
 static inline void
 wv_init_info(struct net_device *       dev)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   psa_t                psa;
   DECLARE_MAC_BUF(mac);
 
@@ -1294,7 +1294,7 @@ wv_init_info(struct net_device *  dev)
 
 #ifdef DEBUG_BASIC_SHOW
   /* Now, let's go for the basic stuff */
-  printk(KERN_NOTICE "%s: WaveLAN: port %#lx, irq %d, "
+  printk(KERN_NOTICE "%s: WaveLAN: port %#x, irq %d, "
         "hw_addr %s",
         dev->name, base, dev->irq,
         print_mac(mac, dev->dev_addr));
@@ -1828,7 +1828,7 @@ static int wavelan_set_nwid(struct net_device *dev,
                            union iwreq_data *wrqu,
                            char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        psa_t psa;
        mm_t m;
@@ -1918,7 +1918,7 @@ static int wavelan_set_freq(struct net_device *dev,
                            union iwreq_data *wrqu,
                            char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        unsigned long flags;
        int ret;
@@ -1948,7 +1948,7 @@ static int wavelan_get_freq(struct net_device *dev,
                            union iwreq_data *wrqu,
                            char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        psa_t psa;
        unsigned long flags;
@@ -1994,7 +1994,7 @@ static int wavelan_set_sens(struct net_device *dev,
                            union iwreq_data *wrqu,
                            char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        psa_t psa;
        unsigned long flags;
@@ -2060,7 +2060,7 @@ static int wavelan_set_encode(struct net_device *dev,
                              union iwreq_data *wrqu,
                              char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        unsigned long flags;
        psa_t psa;
@@ -2130,7 +2130,7 @@ static int wavelan_get_encode(struct net_device *dev,
                              union iwreq_data *wrqu,
                              char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        psa_t psa;
        unsigned long flags;
@@ -2349,7 +2349,7 @@ static int wavelan_get_range(struct net_device *dev,
                             union iwreq_data *wrqu,
                             char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        struct iw_range *range = (struct iw_range *) extra;
        unsigned long flags;
@@ -2425,7 +2425,7 @@ static int wavelan_set_qthr(struct net_device *dev,
                            union iwreq_data *wrqu,
                            char *extra)
 {
-       kio_addr_t base = dev->base_addr;
+       unsigned int base = dev->base_addr;
        net_local *lp = netdev_priv(dev);
        psa_t psa;
        unsigned long flags;
@@ -2701,7 +2701,7 @@ static const struct iw_handler_def        wavelan_handler_def =
 static iw_stats *
 wavelan_get_wireless_stats(struct net_device * dev)
 {
-  kio_addr_t           base = dev->base_addr;
+  unsigned int         base = dev->base_addr;
   net_local *          lp = netdev_priv(dev);
   mmr_t                        m;
   iw_stats *           wstats;
@@ -2764,7 +2764,7 @@ wv_start_of_frame(struct net_device *     dev,
                  int           rfp,    /* end of frame */
                  int           wrap)   /* start of buffer */
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   int          rp;
   int          len;
 
@@ -2925,7 +2925,7 @@ wv_packet_read(struct net_device *                dev,
 static inline void
 wv_packet_rcv(struct net_device *      dev)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   net_local *  lp = netdev_priv(dev);
   int          newrfp;
   int          rp;
@@ -3062,7 +3062,7 @@ wv_packet_write(struct net_device *       dev,
                short           length)
 {
   net_local *          lp = netdev_priv(dev);
-  kio_addr_t           base = dev->base_addr;
+  unsigned int         base = dev->base_addr;
   unsigned long                flags;
   int                  clen = length;
   register u_short     xmtdata_base = TX_BASE;
@@ -3183,7 +3183,7 @@ wavelan_packet_xmit(struct sk_buff *      skb,
 static inline int
 wv_mmc_init(struct net_device *        dev)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   psa_t                psa;
   mmw_t                m;
   int          configured;
@@ -3377,7 +3377,7 @@ wv_mmc_init(struct net_device *   dev)
 static int
 wv_ru_stop(struct net_device * dev)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   net_local *  lp = netdev_priv(dev);
   unsigned long        flags;
   int          status;
@@ -3440,7 +3440,7 @@ wv_ru_stop(struct net_device *    dev)
 static int
 wv_ru_start(struct net_device *        dev)
 {
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
   net_local *  lp = netdev_priv(dev);
   unsigned long        flags;
 
@@ -3528,7 +3528,7 @@ wv_ru_start(struct net_device *   dev)
 static int
 wv_82593_config(struct net_device *    dev)
 {
-  kio_addr_t                   base = dev->base_addr;
+  unsigned int                 base = dev->base_addr;
   net_local *                  lp = netdev_priv(dev);
   struct i82593_conf_block     cfblk;
   int                          ret = TRUE;
@@ -3765,7 +3765,7 @@ static int
 wv_hw_config(struct net_device *       dev)
 {
   net_local *          lp = netdev_priv(dev);
-  kio_addr_t           base = dev->base_addr;
+  unsigned int         base = dev->base_addr;
   unsigned long                flags;
   int                  ret = FALSE;
 
@@ -4047,7 +4047,7 @@ wavelan_interrupt(int             irq,
 {
   struct net_device *  dev = dev_id;
   net_local *  lp;
-  kio_addr_t   base;
+  unsigned int base;
   int          status0;
   u_int                tx_status;
 
@@ -4306,7 +4306,7 @@ static void
 wavelan_watchdog(struct net_device *   dev)
 {
   net_local *          lp = netdev_priv(dev);
-  kio_addr_t           base = dev->base_addr;
+  unsigned int         base = dev->base_addr;
   unsigned long                flags;
   int                  aborted = FALSE;
 
@@ -4382,7 +4382,7 @@ wavelan_open(struct net_device *  dev)
 {
   net_local *  lp = netdev_priv(dev);
   struct pcmcia_device *       link = lp->link;
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
 
 #ifdef DEBUG_CALLBACK_TRACE
   printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
@@ -4436,7 +4436,7 @@ static int
 wavelan_close(struct net_device *      dev)
 {
   struct pcmcia_device *       link = ((net_local *)netdev_priv(dev))->link;
-  kio_addr_t   base = dev->base_addr;
+  unsigned int base = dev->base_addr;
 
 #ifdef DEBUG_CALLBACK_TRACE
   printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
index f5ef03cf9879de87cdfee0f3dc61fa50a1c1dee9..21bda2031e7e3c7e90d33c86ebeaab2f76e20e17 100644 (file)
@@ -4,5 +4,4 @@
 
 obj-y   := nubus.o
 
-obj-$(CONFIG_MODULES) += nubus_syms.o 
 obj-$(CONFIG_PROC_FS) += proc.o
index e503c9c980321ccb81e11c3a5efa0eae780c6da3..2f047e573d86cda7210d2346582324b5f126518e 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/module.h>
 #include <asm/setup.h>
 #include <asm/system.h>
 #include <asm/page.h>
@@ -186,6 +187,7 @@ void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent* dirent,
                len--;
        }
 }
+EXPORT_SYMBOL(nubus_get_rsrc_mem);
 
 void nubus_get_rsrc_str(void *dest, const struct nubus_dirent* dirent,
                        int len)
@@ -200,6 +202,7 @@ void nubus_get_rsrc_str(void *dest, const struct nubus_dirent* dirent,
                len--;
        }
 }
+EXPORT_SYMBOL(nubus_get_rsrc_str);
 
 int nubus_get_root_dir(const struct nubus_board* board,
                       struct nubus_dir* dir)
@@ -209,6 +212,7 @@ int nubus_get_root_dir(const struct nubus_board* board,
        dir->mask = board->lanes;
        return 0;
 }
+EXPORT_SYMBOL(nubus_get_root_dir);
 
 /* This is a slyly renamed version of the above */
 int nubus_get_func_dir(const struct nubus_dev* dev,
@@ -219,6 +223,7 @@ int nubus_get_func_dir(const struct nubus_dev* dev,
        dir->mask = dev->board->lanes;
        return 0;
 }
+EXPORT_SYMBOL(nubus_get_func_dir);
 
 int nubus_get_board_dir(const struct nubus_board* board,
                        struct nubus_dir* dir)
@@ -237,6 +242,7 @@ int nubus_get_board_dir(const struct nubus_board* board,
                return -1;
        return 0;
 }
+EXPORT_SYMBOL(nubus_get_board_dir);
 
 int nubus_get_subdir(const struct nubus_dirent *ent,
                     struct nubus_dir *dir)
@@ -246,6 +252,7 @@ int nubus_get_subdir(const struct nubus_dirent *ent,
        dir->mask = ent->mask;
        return 0;
 }
+EXPORT_SYMBOL(nubus_get_subdir);
 
 int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent)
 {
@@ -274,12 +281,14 @@ int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent)
        ent->mask  = nd->mask;
        return 0;
 }
+EXPORT_SYMBOL(nubus_readdir);
 
 int nubus_rewinddir(struct nubus_dir* dir)
 {
        dir->ptr = dir->base;
        return 0;
 }
+EXPORT_SYMBOL(nubus_rewinddir);
 
 /* Driver interface functions, more or less like in pci.c */
 
@@ -303,6 +312,7 @@ nubus_find_device(unsigned short category,
        }
        return NULL;
 }
+EXPORT_SYMBOL(nubus_find_device);
 
 struct nubus_dev*
 nubus_find_type(unsigned short category,
@@ -320,6 +330,7 @@ nubus_find_type(unsigned short category,
        }
        return NULL;
 }
+EXPORT_SYMBOL(nubus_find_type);
 
 struct nubus_dev*
 nubus_find_slot(unsigned int slot,
@@ -335,6 +346,7 @@ nubus_find_slot(unsigned int slot,
        }
        return NULL;
 }
+EXPORT_SYMBOL(nubus_find_slot);
 
 int
 nubus_find_rsrc(struct nubus_dir* dir, unsigned char rsrc_type,
@@ -346,13 +358,14 @@ nubus_find_rsrc(struct nubus_dir* dir, unsigned char rsrc_type,
        }       
        return -1;
 }
+EXPORT_SYMBOL(nubus_find_rsrc);
 
 /* Initialization functions - decide which slots contain stuff worth
    looking at, and print out lots and lots of information from the
    resource blocks. */
 
 /* FIXME: A lot of this stuff will eventually be useful after
-   initializaton, for intelligently probing Ethernet and video chips,
+   initialization, for intelligently probing Ethernet and video chips,
    among other things.  The rest of it should go in the /proc code.
    For now, we just use it to give verbose boot logs. */
 
diff --git a/drivers/nubus/nubus_syms.c b/drivers/nubus/nubus_syms.c
deleted file mode 100644 (file)
index 9204f04..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Exported symbols for NuBus services
-
-   (c) 1999 David Huggins-Daines <dhd@debian.org> */
-
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/nubus.h>
-
-#ifdef CONFIG_PROC_FS
-EXPORT_SYMBOL(nubus_proc_attach_device);
-EXPORT_SYMBOL(nubus_proc_detach_device);
-#endif
-
-MODULE_LICENSE("GPL");
-
-EXPORT_SYMBOL(nubus_find_device);
-EXPORT_SYMBOL(nubus_find_type);
-EXPORT_SYMBOL(nubus_find_slot);
-EXPORT_SYMBOL(nubus_get_root_dir);
-EXPORT_SYMBOL(nubus_get_board_dir);
-EXPORT_SYMBOL(nubus_get_func_dir);
-EXPORT_SYMBOL(nubus_readdir);
-EXPORT_SYMBOL(nubus_find_rsrc);
-EXPORT_SYMBOL(nubus_rewinddir);
-EXPORT_SYMBOL(nubus_get_subdir);
-EXPORT_SYMBOL(nubus_get_rsrc_mem);
-EXPORT_SYMBOL(nubus_get_rsrc_str);
-
index 5271a4a7af26f7884283bac95457c0c1ef8a04f1..e07492be1f4ac36a418896f77f45a4a25fffdaa7 100644 (file)
@@ -22,6 +22,8 @@
 #include <linux/nubus.h>
 #include <linux/proc_fs.h>
 #include <linux/init.h>
+#include <linux/module.h>
+
 #include <asm/uaccess.h>
 #include <asm/byteorder.h>
 
@@ -140,6 +142,7 @@ int nubus_proc_attach_device(struct nubus_dev *dev)
 
        return 0;
 }
+EXPORT_SYMBOL(nubus_proc_attach_device);
 
 /* FIXME: this is certainly broken! */
 int nubus_proc_detach_device(struct nubus_dev *dev)
@@ -154,6 +157,7 @@ int nubus_proc_detach_device(struct nubus_dev *dev)
        }
        return 0;
 }
+EXPORT_SYMBOL(nubus_proc_detach_device);
 
 void __init proc_bus_nubus_add_devices(void)
 {
index 7c60cbd85dc8505883e14ad9091f456badfdb427..d08b284de196b2e807518ac656d678e585f9560c 100644 (file)
@@ -363,7 +363,7 @@ ccio_alloc_range(struct ioc *ioc, size_t size)
        if (pages_needed <= 8) {
                /*
                 * LAN traffic will not thrash the TLB IFF the same NIC
-                * uses 8 adjacent pages to map seperate payload data.
+                * uses 8 adjacent pages to map separate payload data.
                 * ie the same byte in the resource bit map.
                 */
 #if 0
@@ -941,7 +941,7 @@ ccio_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
        ** w/o this association, we wouldn't have coherent DMA!
        ** Access to the virtual address is what forces a two pass algorithm.
        */
-       coalesced = iommu_coalesce_chunks(ioc, sglist, nents, ccio_alloc_range);
+       coalesced = iommu_coalesce_chunks(ioc, dev, sglist, nents, ccio_alloc_range);
 
        /*
        ** Program the I/O Pdir
@@ -1589,7 +1589,7 @@ static int __init ccio_probe(struct parisc_device *dev)
 }
 
 /**
- * ccio_init - ccio initalization procedure.
+ * ccio_init - ccio initialization procedure.
  *
  * Register this driver.
  */
index a728a7cd2fc80156ae3fd1b1d358e6b87934eb87..65eee67aa2ae66d9ac9130c9ee7efb6fab896a74 100644 (file)
@@ -95,7 +95,7 @@ static struct parisc_driver hppb_driver = {
 };
 
 /**
- * hppb_init - HP-PB bus initalization procedure.
+ * hppb_init - HP-PB bus initialization procedure.
  *
  * Register this driver.   
  */
index 0a1f99a2e93edf262b904fe886f1c2fc074c6de4..97ba8286c5969285294c2dd886a0e375071f4878 100644 (file)
@@ -95,12 +95,14 @@ iommu_fill_pdir(struct ioc *ioc, struct scatterlist *startsg, int nents,
 */
 
 static inline unsigned int
-iommu_coalesce_chunks(struct ioc *ioc, struct scatterlist *startsg, int nents,
+iommu_coalesce_chunks(struct ioc *ioc, struct device *dev,
+                     struct scatterlist *startsg, int nents,
                      int (*iommu_alloc_range)(struct ioc *, size_t))
 {
        struct scatterlist *contig_sg;     /* contig chunk head */
        unsigned long dma_offset, dma_len; /* start/len of DMA stream */
        unsigned int n_mappings = 0;
+       unsigned int max_seg_size = dma_get_max_seg_size(dev);
 
        while (nents > 0) {
 
@@ -142,6 +144,9 @@ iommu_coalesce_chunks(struct ioc *ioc, struct scatterlist *startsg, int nents,
                                            IOVP_SIZE) > DMA_CHUNK_SIZE))
                                break;
 
+                       if (startsg->length + dma_len > max_seg_size)
+                               break;
+
                        /*
                        ** Next see if we can append the next chunk (i.e.
                        ** it must end on one page and begin on another
index e527a0e1d6c01820c7fa24d911d9e5bacb6e33a4..d06627c3f353a607f7730b300af68a3d607b83b6 100644 (file)
@@ -946,7 +946,7 @@ sba_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
        ** w/o this association, we wouldn't have coherent DMA!
        ** Access to the virtual address is what forces a two pass algorithm.
        */
-       coalesced = iommu_coalesce_chunks(ioc, sglist, nents, sba_alloc_range);
+       coalesced = iommu_coalesce_chunks(ioc, dev, sglist, nents, sba_alloc_range);
 
        /*
        ** Program the I/O Pdir
index e9743d3efaf682a8a5db6b07d6f841cf7dc2c05d..238628d3a854aa6e45deeaedd3e5dc6372ee1594 100644 (file)
@@ -1540,6 +1540,38 @@ static void __devinit detect_and_report_smsc (void)
        smsc_check(0x3f0,0x44);
        smsc_check(0x370,0x44);
 }
+
+static void __devinit detect_and_report_it87(void)
+{
+       u16 dev;
+       u8 r;
+       if (verbose_probing)
+               printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...\n");
+       if (!request_region(0x2e, 1, __FUNCTION__))
+               return;
+       outb(0x87, 0x2e);
+       outb(0x01, 0x2e);
+       outb(0x55, 0x2e);
+       outb(0x55, 0x2e);
+       outb(0x20, 0x2e);
+       dev = inb(0x2f) << 8;
+       outb(0x21, 0x2e);
+       dev |= inb(0x2f);
+       if (dev == 0x8712 || dev == 0x8705 || dev == 0x8715 ||
+           dev == 0x8716 || dev == 0x8718 || dev == 0x8726) {
+               printk(KERN_INFO "IT%04X SuperIO detected.\n", dev);
+               outb(0x07, 0x2E);       /* Parallel Port */
+               outb(0x03, 0x2F);
+               outb(0xF0, 0x2E);       /* BOOT 0x80 off */
+               r = inb(0x2f);
+               outb(0xF0, 0x2E);
+               outb(r | 8, 0x2F);
+               outb(0x02, 0x2E);       /* Lock */
+               outb(0x02, 0x2F);
+
+               release_region(0x2e, 1);
+       }
+}
 #endif /* CONFIG_PARPORT_PC_SUPERIO */
 
 static int get_superio_dma (struct parport *p)
@@ -2767,6 +2799,7 @@ enum parport_pc_pci_cards {
        netmos_9755,
        netmos_9805,
        netmos_9815,
+       quatech_sppxp100,
 };
 
 
@@ -2843,6 +2876,7 @@ static struct parport_pc_pci {
         /* netmos_9755 */               { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */
        /* netmos_9805 */               { 1, { { 0, -1 }, } }, /* untested */
        /* netmos_9815 */               { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */
+       /* quatech_sppxp100 */          { 1, { { 0, 1 }, } },
 };
 
 static const struct pci_device_id parport_pc_pci_tbl[] = {
@@ -2926,6 +2960,9 @@ static const struct pci_device_id parport_pc_pci_tbl[] = {
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
        { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
+       /* Quatech SPPXP-100 Parallel port PCI ExpressCard */
+       { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
        { 0, } /* terminate list */
 };
 MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl);
@@ -3159,24 +3196,25 @@ static void __init parport_pc_find_ports (int autoirq, int autodma)
        int count = 0, err;
 
 #ifdef CONFIG_PARPORT_PC_SUPERIO
-       detect_and_report_winbond ();
-       detect_and_report_smsc ();
+       detect_and_report_it87();
+       detect_and_report_winbond();
+       detect_and_report_smsc();
 #endif
 
        /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
-       count += parport_pc_init_superio (autoirq, autodma);
+       count += parport_pc_init_superio(autoirq, autodma);
 
        /* PnP ports, skip detection if SuperIO already found them */
        if (!count) {
-               err = pnp_register_driver (&parport_pc_pnp_driver);
+               err = pnp_register_driver(&parport_pc_pnp_driver);
                if (!err)
                        pnp_registered_parport = 1;
        }
 
        /* ISA ports and whatever (see asm/parport.h). */
-       parport_pc_find_nonpci_ports (autoirq, autodma);
+       parport_pc_find_nonpci_ports(autoirq, autodma);
 
-       err = pci_register_driver (&parport_pc_pci_driver);
+       err = pci_register_driver(&parport_pc_pci_driver);
        if (!err)
                pci_registered_parport = 1;
 }
index bd6ad8b38168a43b3def14876deb7095b6117da9..e2e95b36a603e227be8d0d6b03b30996c9f00c6f 100644 (file)
@@ -77,7 +77,7 @@ static struct parport_pc_pci cards[] __devinitdata = {
        /* titan_110l */                { 1, { { 3, -1 }, } },
        /* titan_210l */                { 1, { { 3, -1 }, } },
        /* netmos_9xx5_combo */         { 1, { { 2, -1 }, }, netmos_parallel_init },
-       /* netmos_9855 */               { 1, { { 0, -1 }, }, netmos_parallel_init },
+       /* netmos_9855 */               { 1, { { 2, -1 }, }, netmos_parallel_init },
        /* avlab_1s1p     */            { 1, { { 1, 2}, } },
        /* avlab_1s2p     */            { 2, { { 1, 2}, { 3, 4 },} },
        /* avlab_2s1p     */            { 1, { { 2, 3}, } },
@@ -185,7 +185,7 @@ static struct pciserial_board pci_parport_serial_boards[] __devinitdata = {
                .uart_offset    = 8,
        },
        [netmos_9855] = {
-               .flags          = FL_BASE2 | FL_BASE_BARS,
+               .flags          = FL_BASE4 | FL_BASE_BARS,
                .num_ports      = 1,
                .base_baud      = 115200,
                .uart_offset    = 8,
index 853a15f44f8889f7f1b5d401df730677633232f6..cd565bb4e1a990ba303aa308a6094c7466b3e331 100644 (file)
@@ -163,7 +163,7 @@ static ssize_t parport_read_device_id (struct parport *port, char *buffer,
        idlens[1] = idlens[0]+2;
        if (belen != lelen) {
                int off = 2;
-               /* Don't try lenghts of 0x100 and 0x200 as 1 and 2 */
+               /* Don't try lengths of 0x100 and 0x200 as 1 and 2 */
                if (idlens[0] <= 2)
                        off = 0;
                idlens[off] = max(belen, lelen);
index f697f3d728eb6317ad048cd087ceb26af8962117..9f04d17576d6fb37e1f58368dfa5326264369208 100644 (file)
@@ -13,6 +13,9 @@ obj-$(CONFIG_HOTPLUG) += hotplug.o
 
 # Build the PCI Hotplug drivers if we were asked to
 obj-$(CONFIG_HOTPLUG_PCI) += hotplug/
+ifdef CONFIG_HOTPLUG_PCI
+obj-y += hotplug-pci.o
+endif
 
 # Build the PCI MSI interrupt support
 obj-$(CONFIG_PCI_MSI) += msi.o
index 9e5ea074ad20f56d041a2fbf82d19ab27f7dca43..ef5a6a245f5fa36363d513e5aa35fef248a499a4 100644 (file)
@@ -108,6 +108,7 @@ int pci_bus_add_device(struct pci_dev *dev)
 void pci_bus_add_devices(struct pci_bus *bus)
 {
        struct pci_dev *dev;
+       struct pci_bus *child_bus;
        int retval;
 
        list_for_each_entry(dev, &bus->devices, bus_list) {
@@ -138,11 +139,19 @@ void pci_bus_add_devices(struct pci_bus *bus)
                               up_write(&pci_bus_sem);
                        }
                        pci_bus_add_devices(dev->subordinate);
-                       retval = sysfs_create_link(&dev->subordinate->class_dev.kobj,
-                                                  &dev->dev.kobj, "bridge");
+
+                       /* register the bus with sysfs as the parent is now
+                        * properly registered. */
+                       child_bus = dev->subordinate;
+                       child_bus->dev.parent = child_bus->bridge;
+                       retval = device_register(&child_bus->dev);
+                       if (!retval)
+                               retval = device_create_file(&child_bus->dev,
+                                                       &dev_attr_cpuaffinity);
                        if (retval)
-                               dev_err(&dev->dev, "Error creating sysfs "
-                                       "bridge symlink, continuing...\n");
+                               dev_err(&dev->dev, "Error registering pci_bus"
+                                       " device bridge symlink,"
+                                       " continuing...\n");
                }
        }
 }
@@ -204,7 +213,6 @@ void pci_walk_bus(struct pci_bus *top, void (*cb)(struct pci_dev *, void *),
        }
        up_read(&pci_bus_sem);
 }
-EXPORT_SYMBOL_GPL(pci_walk_bus);
 
 EXPORT_SYMBOL(pci_bus_alloc_resource);
 EXPORT_SYMBOL_GPL(pci_bus_add_device);
index 5dfdfdac92e1bc83862707aab71d356d47a36eff..8ed26480371fcf2dc877a0e9d1bc8d3f24fcab11 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <linux/pci.h>
 #include <linux/dmar.h>
+#include "iova.h"
+#include "intel-iommu.h"
 
 #undef PREFIX
 #define PREFIX "DMAR:"
@@ -263,8 +265,8 @@ parse_dmar_table(void)
        if (!dmar)
                return -ENODEV;
 
-       if (!dmar->width) {
-               printk (KERN_WARNING PREFIX "Zero: Invalid DMAR haw\n");
+       if (dmar->width < PAGE_SHIFT_4K - 1) {
+               printk(KERN_WARNING PREFIX "Invalid DMAR haw\n");
                return -EINVAL;
        }
 
@@ -301,11 +303,24 @@ parse_dmar_table(void)
 int __init dmar_table_init(void)
 {
 
-       parse_dmar_table();
+       int ret;
+
+       ret = parse_dmar_table();
+       if (ret) {
+               printk(KERN_INFO PREFIX "parse DMAR table failure.\n");
+               return ret;
+       }
+
        if (list_empty(&dmar_drhd_units)) {
                printk(KERN_INFO PREFIX "No DMAR devices found\n");
                return -ENODEV;
        }
+
+       if (list_empty(&dmar_rmrr_units)) {
+               printk(KERN_INFO PREFIX "No RMRR found\n");
+               return -ENODEV;
+       }
+
        return 0;
 }
 
diff --git a/drivers/pci/hotplug-pci.c b/drivers/pci/hotplug-pci.c
new file mode 100644 (file)
index 0000000..a590ef6
--- /dev/null
@@ -0,0 +1,20 @@
+/* Core PCI functionality used only by PCI hotplug */
+
+#include <linux/pci.h>
+#include "pci.h"
+
+
+unsigned int pci_do_scan_bus(struct pci_bus *bus)
+{
+       unsigned int max;
+
+       max = pci_scan_child_bus(bus);
+
+       /*
+        * Make the discovered devices available.
+        */
+       pci_bus_add_devices(bus);
+
+       return max;
+}
+EXPORT_SYMBOL(pci_do_scan_bus);
index a64449d489d635b9743ce79f2cf52c8904feb125..2cdd8326f1363d5916db000f1af7f2f6a5b22a2a 100644 (file)
@@ -3,8 +3,8 @@
 #
 
 menuconfig HOTPLUG_PCI
-       tristate "Support for PCI Hotplug (EXPERIMENTAL)"
-       depends on PCI && EXPERIMENTAL && HOTPLUG
+       tristate "Support for PCI Hotplug"
+       depends on PCI && HOTPLUG
        ---help---
          Say Y here if you have a motherboard with a PCI Hotplug controller.
          This allows you to add and remove PCI cards while the machine is
index 34a1891191fd4c06261de07a8671512869e3d08d..9bdbe1a6688f728b815014607e8bb8a5ef6ef562 100644 (file)
@@ -3,7 +3,6 @@
 #
 
 obj-$(CONFIG_HOTPLUG_PCI)              += pci_hotplug.o
-obj-$(CONFIG_HOTPLUG_PCI_FAKE)         += fakephp.o 
 obj-$(CONFIG_HOTPLUG_PCI_COMPAQ)       += cpqphp.o
 obj-$(CONFIG_HOTPLUG_PCI_IBM)          += ibmphp.o
 obj-$(CONFIG_HOTPLUG_PCI_ACPI)         += acpiphp.o
@@ -16,6 +15,9 @@ obj-$(CONFIG_HOTPLUG_PCI_RPA)         += rpaphp.o
 obj-$(CONFIG_HOTPLUG_PCI_RPA_DLPAR)    += rpadlpar_io.o
 obj-$(CONFIG_HOTPLUG_PCI_SGI)          += sgi_hotplug.o
 
+# Link this last so it doesn't claim devices that have a real hotplug driver
+obj-$(CONFIG_HOTPLUG_PCI_FAKE)         += fakephp.o
+
 pci_hotplug-objs       :=      pci_hotplug_core.o
 
 ifdef CONFIG_HOTPLUG_PCI_CPCI
index 1ef417cca2db2a370be207ce8db51146e5386cd5..7a29164d4b325aa2ee4219398b679b066f0e27a6 100644 (file)
@@ -113,7 +113,6 @@ struct acpiphp_slot {
        u8              device;         /* pci device# */
 
        u32             sun;            /* ACPI _SUN (slot unique number) */
-       u32             slotno;         /* slot number relative to bridge */
        u32             flags;          /* see below */
 };
 
index ff1b1c71291a84412086b25db6b99c0a1efc29d3..cf22f9e01e005721257bd61c7a2894008f65b497 100644 (file)
@@ -102,7 +102,7 @@ static int is_ejectable(acpi_handle handle)
 }
 
 
-/* callback routine to check the existence of ejectable slots */
+/* callback routine to check for the existence of ejectable slots */
 static acpi_status
 is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
@@ -117,7 +117,7 @@ is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
        }
 }
 
-/* callback routine to check for the existance of a pci dock device */
+/* callback routine to check for the existence of a pci dock device */
 static acpi_status
 is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
@@ -1528,7 +1528,6 @@ check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
                acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
                dbg("%s: re-enumerating slots under %s\n",
                        __FUNCTION__, objname);
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
                acpiphp_check_bridge(bridge);
        }
        return AE_OK ;
index d7a293e3faf5debc9fb8d3df0b571bde3e663c33..94b640146d4456b4aa0b96b1022f7efcfadbd256 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/init.h>
 #include <linux/string.h>
 #include <linux/slab.h>
+#include <linux/workqueue.h>
 #include "../pci.h"
 
 #if !defined(MODULE)
@@ -63,10 +64,16 @@ struct dummy_slot {
        struct list_head node;
        struct hotplug_slot *slot;
        struct pci_dev *dev;
+       struct work_struct remove_work;
+       unsigned long removed;
 };
 
 static int debug;
 static LIST_HEAD(slot_list);
+static struct workqueue_struct *dummyphp_wq;
+
+static void pci_rescan_worker(struct work_struct *work);
+static DECLARE_WORK(pci_rescan_work, pci_rescan_worker);
 
 static int enable_slot (struct hotplug_slot *slot);
 static int disable_slot (struct hotplug_slot *slot);
@@ -109,7 +116,7 @@ static int add_slot(struct pci_dev *dev)
        slot->name = &dev->dev.bus_id[0];
        dbg("slot->name = %s\n", slot->name);
 
-       dslot = kmalloc(sizeof(struct dummy_slot), GFP_KERNEL);
+       dslot = kzalloc(sizeof(struct dummy_slot), GFP_KERNEL);
        if (!dslot)
                goto error_info;
 
@@ -164,6 +171,14 @@ static void remove_slot(struct dummy_slot *dslot)
                err("Problem unregistering a slot %s\n", dslot->slot->name);
 }
 
+/* called from the single-threaded workqueue handler to remove a slot */
+static void remove_slot_worker(struct work_struct *work)
+{
+       struct dummy_slot *dslot =
+               container_of(work, struct dummy_slot, remove_work);
+       remove_slot(dslot);
+}
+
 /**
  * pci_rescan_slot - Rescan slot
  * @temp: Device template. Should be set: bus and devfn.
@@ -267,11 +282,17 @@ static inline void pci_rescan(void) {
        pci_rescan_buses(&pci_root_buses);
 }
 
+/* called from the single-threaded workqueue handler to rescan all pci buses */
+static void pci_rescan_worker(struct work_struct *work)
+{
+       pci_rescan();
+}
 
 static int enable_slot(struct hotplug_slot *hotplug_slot)
 {
        /* mis-use enable_slot for rescanning of the pci bus */
-       pci_rescan();
+       cancel_work_sync(&pci_rescan_work);
+       queue_work(dummyphp_wq, &pci_rescan_work);
        return -ENODEV;
 }
 
@@ -306,6 +327,10 @@ static int disable_slot(struct hotplug_slot *slot)
                err("Can't remove PCI devices with other PCI devices behind it yet.\n");
                return -ENODEV;
        }
+       if (test_and_set_bit(0, &dslot->removed)) {
+               dbg("Slot already scheduled for removal\n");
+               return -ENODEV;
+       }
        /* search for subfunctions and disable them first */
        if (!(dslot->dev->devfn & 7)) {
                for (func = 1; func < 8; func++) {
@@ -328,8 +353,9 @@ static int disable_slot(struct hotplug_slot *slot)
        /* remove the device from the pci core */
        pci_remove_bus_device(dslot->dev);
 
-       /* blow away this sysfs entry and other parts. */
-       remove_slot(dslot);
+       /* queue work item to blow away this sysfs entry and other parts. */
+       INIT_WORK(&dslot->remove_work, remove_slot_worker);
+       queue_work(dummyphp_wq, &dslot->remove_work);
 
        return 0;
 }
@@ -340,6 +366,7 @@ static void cleanup_slots (void)
        struct list_head *next;
        struct dummy_slot *dslot;
 
+       destroy_workqueue(dummyphp_wq);
        list_for_each_safe (tmp, next, &slot_list) {
                dslot = list_entry (tmp, struct dummy_slot, node);
                remove_slot(dslot);
@@ -351,6 +378,10 @@ static int __init dummyphp_init(void)
 {
        info(DRIVER_DESC "\n");
 
+       dummyphp_wq = create_singlethread_workqueue(MY_NAME);
+       if (!dummyphp_wq)
+               return -ENOMEM;
+
        return pci_scan_buses();
 }
 
index a90c28d0c69df75c3cb62b2ca19d3073b49839d1..87b6b8b280e65024fe112e06f1fe59e75a297aeb 100644 (file)
@@ -761,10 +761,13 @@ static void ibm_unconfigure_device(struct pci_func *func)
        debug("func->device << 3 | 0x0  = %x\n", func->device << 3 | 0x0);
 
        for (j = 0; j < 0x08; j++) {
-               temp = pci_find_slot(func->busno, (func->device << 3) | j);
-               if (temp)
+               temp = pci_get_bus_and_slot(func->busno, (func->device << 3) | j);
+               if (temp) {
                        pci_remove_bus_device(temp);
+                       pci_dev_put(temp);
+               }
        }
+       pci_dev_put(func->dev);
 }
 
 /*
@@ -823,7 +826,7 @@ static int ibm_configure_device(struct pci_func *func)
        if (!(bus_structure_fixup(func->busno)))
                flag = 1;
        if (func->dev == NULL)
-               func->dev = pci_find_slot(func->busno,
+               func->dev = pci_get_bus_and_slot(func->busno,
                                PCI_DEVFN(func->device, func->function));
 
        if (func->dev == NULL) {
@@ -836,7 +839,7 @@ static int ibm_configure_device(struct pci_func *func)
                if (num)
                        pci_bus_add_devices(bus);
 
-               func->dev = pci_find_slot(func->busno,
+               func->dev = pci_get_bus_and_slot(func->busno,
                                PCI_DEVFN(func->device, func->function));
                if (func->dev == NULL) {
                        err("ERROR... : pci_dev still NULL\n");
index 47bb0e1ff3faff303a72cbe17963da8e34f675fc..dd59a050260fe81035bd42193b1c5613d8c70b84 100644 (file)
@@ -137,7 +137,7 @@ static int get_##name (struct hotplug_slot *slot, type *value)              \
        int retval = 0;                                                 \
        if (try_module_get(ops->owner)) {                               \
                if (ops->get_##name)                                    \
-                       retval = ops->get_##name (slot, value);         \
+                       retval = ops->get_##name(slot, value);          \
                else                                                    \
                        *value = slot->info->name;                      \
                module_put(ops->owner);                                 \
@@ -625,7 +625,7 @@ int pci_hp_register (struct hotplug_slot *slot)
        if ((slot->info == NULL) || (slot->ops == NULL))
                return -EINVAL;
        if (slot->release == NULL) {
-               dbg("Why are you trying to register a hotplug slot"
+               dbg("Why are you trying to register a hotplug slot "
                    "without a proper release function?\n");
                return -EINVAL;
        }
index 7959c222dc24e939c7734fc201fab8491004a3b0..ca656b27a500bb1eb861284fae3a193d2d3181ec 100644 (file)
@@ -82,24 +82,18 @@ struct event_info {
 };
 
 struct controller {
-       struct controller *next;
        struct mutex crit_sect;         /* critical section mutex */
        struct mutex ctrl_lock;         /* controller lock */
        int num_slots;                  /* Number of slots on ctlr */
        int slot_num_inc;               /* 1 or -1 */
        struct pci_dev *pci_dev;
        struct list_head slot_list;
-       struct slot *slot;
        struct hpc_ops *hpc_ops;
        wait_queue_head_t queue;        /* sleep & wake process */
-       u8 bus;
-       u8 device;
-       u8 function;
        u8 slot_device_offset;
        u32 first_slot;         /* First physical slot number */  /* PCIE only has 1 slot */
        u8 slot_bus;            /* Bus where the slots handled by this controller sit */
        u8 ctrlcap;
-       u16 vendor_id;
        u8 cap_base;
        struct timer_list poll_timer;
        volatile int cmd_busy;
@@ -161,6 +155,9 @@ extern int pciehp_configure_device(struct slot *p_slot);
 extern int pciehp_unconfigure_device(struct slot *p_slot);
 extern void pciehp_queue_pushbutton_work(struct work_struct *work);
 int pcie_init(struct controller *ctrl, struct pcie_device *dev);
+int pciehp_enable_slot(struct slot *p_slot);
+int pciehp_disable_slot(struct slot *p_slot);
+int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev);
 
 static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device)
 {
index 6462ac3b405fcc722f1f57e345e441a94138410a..7f4836b8e71e31e9c68071d120114d9a4b8a3317 100644 (file)
@@ -453,13 +453,9 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
 
        pci_set_drvdata(pdev, ctrl);
 
-       ctrl->bus = pdev->bus->number;  /* ctrl bus */
-       ctrl->slot_bus = pdev->subordinate->number;  /* bus controlled by this HPC */
-
-       ctrl->device = PCI_SLOT(pdev->devfn);
-       ctrl->function = PCI_FUNC(pdev->devfn);
-       dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", __FUNCTION__,
-               ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
+       dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n",
+           __FUNCTION__, pdev->bus->number, PCI_SLOT(pdev->devfn),
+           PCI_FUNC(pdev->devfn), pdev->irq);
 
        /* Setup the slot information structures */
        rc = init_slots(ctrl);
@@ -471,6 +467,11 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
        t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
 
        t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
+       if (value) {
+               rc = pciehp_enable_slot(t_slot);
+               if (rc) /* -ENODEV: shouldn't happen, but deal with it */
+                       value = 0;
+       }
        if ((POWER_CTRL(ctrl->ctrlcap)) && !value) {
                rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
                if (rc)
@@ -509,6 +510,24 @@ static int pciehp_suspend (struct pcie_device *dev, pm_message_t state)
 static int pciehp_resume (struct pcie_device *dev)
 {
        printk("%s ENTRY\n", __FUNCTION__);
+       if (pciehp_force) {
+               struct pci_dev *pdev = dev->port;
+               struct controller *ctrl = pci_get_drvdata(pdev);
+               struct slot *t_slot;
+               u8 status;
+
+               /* reinitialize the chipset's event detection logic */
+               pcie_init_hardware_part2(ctrl, dev);
+
+               t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
+
+               /* Check if slot is occupied */
+               t_slot->hpc_ops->get_adapter_status(t_slot, &status);
+               if (status)
+                       pciehp_enable_slot(t_slot);
+               else
+                       pciehp_disable_slot(t_slot);
+       }
        return 0;
 }
 #endif
index f1e0966cee95b164d458c3126466d62f063cf00c..b23061c56115f9c65e5fb6dadedf3a1d5339d725 100644 (file)
@@ -37,8 +37,6 @@
 #include "pciehp.h"
 
 static void interrupt_event_handler(struct work_struct *work);
-static int pciehp_enable_slot(struct slot *p_slot);
-static int pciehp_disable_slot(struct slot *p_slot);
 
 static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
 {
@@ -197,12 +195,6 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot)
                            __FUNCTION__);
                        return;
                }
-               /*
-                * After turning power off, we must wait for at least
-                * 1 second before taking any action that relies on
-                * power having been removed from the slot/adapter.
-                */
-               msleep(1000);
        }
 }
 
@@ -215,15 +207,12 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot)
  */
 static int board_added(struct slot *p_slot)
 {
-       u8 hp_slot;
        int retval = 0;
        struct controller *ctrl = p_slot->ctrl;
 
-       hp_slot = p_slot->device - ctrl->slot_device_offset;
-
        dbg("%s: slot device, slot offset, hp slot = %d, %d ,%d\n",
                        __FUNCTION__, p_slot->device,
-                       ctrl->slot_device_offset, hp_slot);
+                       ctrl->slot_device_offset, p_slot->hp_slot);
 
        if (POWER_CTRL(ctrl->ctrlcap)) {
                /* Power on slot */
@@ -281,8 +270,6 @@ err_exit:
  */
 static int remove_board(struct slot *p_slot)
 {
-       u8 device;
-       u8 hp_slot;
        int retval = 0;
        struct controller *ctrl = p_slot->ctrl;
 
@@ -290,11 +277,7 @@ static int remove_board(struct slot *p_slot)
        if (retval)
                return retval;
 
-       device = p_slot->device;
-       hp_slot = p_slot->device - ctrl->slot_device_offset;
-       p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
-
-       dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
+       dbg("In %s, hp_slot = %d\n", __FUNCTION__, p_slot->hp_slot);
 
        if (POWER_CTRL(ctrl->ctrlcap)) {
                /* power off slot */
@@ -621,12 +604,6 @@ int pciehp_disable_slot(struct slot *p_slot)
                        mutex_unlock(&p_slot->ctrl->crit_sect);
                        return -EINVAL;
                }
-               /*
-                * After turning power off, we must wait for at least
-                * 1 second before taking any action that relies on
-                * power having been removed from the slot/adapter.
-                */
-               msleep(1000);
        }
 
        ret = remove_board(p_slot);
index 06d025b8b13f6a8f276e396bfc36a742c5a676a4..6eba9b2cfb90b359fc1fb92b45408846b4694f6f 100644 (file)
@@ -636,15 +636,57 @@ static int hpc_power_on_slot(struct slot * slot)
        return retval;
 }
 
+static inline int pcie_mask_bad_dllp(struct controller *ctrl)
+{
+       struct pci_dev *dev = ctrl->pci_dev;
+       int pos;
+       u32 reg;
+
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
+       if (!pos)
+               return 0;
+       pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &reg);
+       if (reg & PCI_ERR_COR_BAD_DLLP)
+               return 0;
+       reg |= PCI_ERR_COR_BAD_DLLP;
+       pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg);
+       return 1;
+}
+
+static inline void pcie_unmask_bad_dllp(struct controller *ctrl)
+{
+       struct pci_dev *dev = ctrl->pci_dev;
+       u32 reg;
+       int pos;
+
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
+       if (!pos)
+               return;
+       pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &reg);
+       if (!(reg & PCI_ERR_COR_BAD_DLLP))
+               return;
+       reg &= ~PCI_ERR_COR_BAD_DLLP;
+       pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg);
+}
+
 static int hpc_power_off_slot(struct slot * slot)
 {
        struct controller *ctrl = slot->ctrl;
        u16 slot_cmd;
        u16 cmd_mask;
        int retval = 0;
+       int changed;
 
        dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot);
 
+       /*
+        * Set Bad DLLP Mask bit in Correctable Error Mask
+        * Register. This is the workaround against Bad DLLP error
+        * that sometimes happens during turning power off the slot
+        * which conforms to PCI Express 1.0a spec.
+        */
+       changed = pcie_mask_bad_dllp(ctrl);
+
        slot_cmd = POWER_OFF;
        cmd_mask = PWR_CTRL;
        /*
@@ -674,6 +716,16 @@ static int hpc_power_off_slot(struct slot * slot)
        dbg("%s: SLOTCTRL %x write cmd %x\n",
            __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
 
+       /*
+        * After turning power off, we must wait for at least 1 second
+        * before taking any action that relies on power having been
+        * removed from the slot/adapter.
+        */
+       msleep(1000);
+
+       if (changed)
+               pcie_unmask_bad_dllp(ctrl);
+
        return retval;
 }
 
@@ -1067,13 +1119,143 @@ int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
 }
 #endif
 
-int pcie_init(struct controller * ctrl, struct pcie_device *dev)
+static int pcie_init_hardware_part1(struct controller *ctrl,
+                                   struct pcie_device *dev)
+{
+       int rc;
+       u16 temp_word;
+       u32 slot_cap;
+       u16 slot_status;
+
+       rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap);
+       if (rc) {
+               err("%s: Cannot read SLOTCAP register\n", __FUNCTION__);
+               return -1;
+       }
+
+       /* Mask Hot-plug Interrupt Enable */
+       rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
+       if (rc) {
+               err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
+               return -1;
+       }
+
+       dbg("%s: SLOTCTRL %x value read %x\n",
+           __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word);
+       temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) |
+               0x00;
+
+       rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
+       if (rc) {
+               err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
+               return -1;
+       }
+
+       rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
+       if (rc) {
+               err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
+               return -1;
+       }
+
+       temp_word = 0x1F; /* Clear all events */
+       rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
+       if (rc) {
+               err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
+               return -1;
+       }
+       return 0;
+}
+
+int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
 {
        int rc;
        u16 temp_word;
-       u16 cap_reg;
        u16 intr_enable = 0;
        u32 slot_cap;
+       u16 slot_status;
+
+       rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
+       if (rc) {
+               err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
+               goto abort;
+       }
+
+       intr_enable = intr_enable | PRSN_DETECT_ENABLE;
+
+       rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap);
+       if (rc) {
+               err("%s: Cannot read SLOTCAP register\n", __FUNCTION__);
+               goto abort;
+       }
+
+       if (ATTN_BUTTN(slot_cap))
+               intr_enable = intr_enable | ATTN_BUTTN_ENABLE;
+
+       if (POWER_CTRL(slot_cap))
+               intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE;
+
+       if (MRL_SENS(slot_cap))
+               intr_enable = intr_enable | MRL_DETECT_ENABLE;
+
+       temp_word = (temp_word & ~intr_enable) | intr_enable;
+
+       if (pciehp_poll_mode) {
+               temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0;
+       } else {
+               temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE;
+       }
+
+       /*
+        * Unmask Hot-plug Interrupt Enable for the interrupt
+        * notification mechanism case.
+        */
+       rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
+       if (rc) {
+               err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
+               goto abort;
+       }
+       rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
+       if (rc) {
+               err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
+               goto abort_disable_intr;
+       }
+
+       temp_word =  0x1F; /* Clear all events */
+       rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
+       if (rc) {
+               err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
+               goto abort_disable_intr;
+       }
+
+       if (pciehp_force) {
+               dbg("Bypassing BIOS check for pciehp use on %s\n",
+                               pci_name(ctrl->pci_dev));
+       } else {
+               rc = pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev);
+               if (rc)
+                       goto abort_disable_intr;
+       }
+
+       return 0;
+
+       /* We end up here for the many possible ways to fail this API. */
+abort_disable_intr:
+       rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
+       if (!rc) {
+               temp_word &= ~(intr_enable | HP_INTR_ENABLE);
+               rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
+       }
+       if (rc)
+               err("%s : disabling interrupts failed\n", __FUNCTION__);
+abort:
+       return -1;
+}
+
+int pcie_init(struct controller *ctrl, struct pcie_device *dev)
+{
+       int rc;
+       u16 cap_reg;
+       u32 slot_cap;
        int cap_base;
        u16 slot_status, slot_ctrl;
        struct pci_dev *pdev;
@@ -1084,9 +1266,10 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
        dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n",
                        __FUNCTION__, pdev->vendor, pdev->device);
 
-       if ((cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP)) == 0) {
+       cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP);
+       if (cap_base == 0) {
                dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __FUNCTION__);
-               goto abort_free_ctlr;
+               goto abort;
        }
 
        ctrl->cap_base = cap_base;
@@ -1096,7 +1279,7 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
        rc = pciehp_readw(ctrl, CAPREG, &cap_reg);
        if (rc) {
                err("%s: Cannot read CAPREG register\n", __FUNCTION__);
-               goto abort_free_ctlr;
+               goto abort;
        }
        dbg("%s: CAPREG offset %x cap_reg %x\n",
            __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg);
@@ -1106,26 +1289,26 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
                && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) {
                dbg("%s : This is not a root port or the port is not "
                    "connected to a slot\n", __FUNCTION__);
-               goto abort_free_ctlr;
+               goto abort;
        }
 
        rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap);
        if (rc) {
                err("%s: Cannot read SLOTCAP register\n", __FUNCTION__);
-               goto abort_free_ctlr;
+               goto abort;
        }
        dbg("%s: SLOTCAP offset %x slot_cap %x\n",
            __FUNCTION__, ctrl->cap_base + SLOTCAP, slot_cap);
 
        if (!(slot_cap & HP_CAP)) {
                dbg("%s : This slot is not hot-plug capable\n", __FUNCTION__);
-               goto abort_free_ctlr;
+               goto abort;
        }
        /* For debugging purpose */
        rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
        if (rc) {
                err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
-               goto abort_free_ctlr;
+               goto abort;
        }
        dbg("%s: SLOTSTATUS offset %x slot_status %x\n",
            __FUNCTION__, ctrl->cap_base + SLOTSTATUS, slot_status);
@@ -1133,7 +1316,7 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
        rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
        if (rc) {
                err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
-               goto abort_free_ctlr;
+               goto abort;
        }
        dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n",
            __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
@@ -1161,36 +1344,9 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
        ctrl->first_slot = slot_cap >> 19;
        ctrl->ctrlcap = slot_cap & 0x0000007f;
 
-       /* Mask Hot-plug Interrupt Enable */
-       rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
-       if (rc) {
-               err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
-               goto abort_free_ctlr;
-       }
-
-       dbg("%s: SLOTCTRL %x value read %x\n",
-           __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word);
-       temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) |
-               0x00;
-
-       rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
-       if (rc) {
-               err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
-               goto abort_free_ctlr;
-       }
-
-       rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
-       if (rc) {
-               err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
-               goto abort_free_ctlr;
-       }
-
-       temp_word = 0x1F; /* Clear all events */
-       rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
-       if (rc) {
-               err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
-               goto abort_free_ctlr;
-       }
+       rc = pcie_init_hardware_part1(ctrl, dev);
+       if (rc)
+               goto abort;
 
        if (pciehp_poll_mode) {
                /* Install interrupt polling timer. Start with 10 sec delay */
@@ -1206,7 +1362,7 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
                if (rc) {
                        err("Can't get irq %d for the hotplug controller\n",
                            ctrl->pci_dev->irq);
-                       goto abort_free_ctlr;
+                       goto abort;
                }
        }
        dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number,
@@ -1224,82 +1380,16 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
                }
        }
 
-       rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
-       if (rc) {
-               err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
-               goto abort_free_irq;
+       rc = pcie_init_hardware_part2(ctrl, dev);
+       if (rc == 0) {
+               ctrl->hpc_ops = &pciehp_hpc_ops;
+               return 0;
        }
-
-       intr_enable = intr_enable | PRSN_DETECT_ENABLE;
-
-       if (ATTN_BUTTN(slot_cap))
-               intr_enable = intr_enable | ATTN_BUTTN_ENABLE;
-
-       if (POWER_CTRL(slot_cap))
-               intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE;
-
-       if (MRL_SENS(slot_cap))
-               intr_enable = intr_enable | MRL_DETECT_ENABLE;
-
-       temp_word = (temp_word & ~intr_enable) | intr_enable;
-
-       if (pciehp_poll_mode) {
-               temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0;
-       } else {
-               temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE;
-       }
-
-       /*
-        * Unmask Hot-plug Interrupt Enable for the interrupt
-        * notification mechanism case.
-        */
-       rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
-       if (rc) {
-               err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
-               goto abort_free_irq;
-       }
-       rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
-       if (rc) {
-               err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
-               goto abort_disable_intr;
-       }
-
-       temp_word =  0x1F; /* Clear all events */
-       rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
-       if (rc) {
-               err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
-               goto abort_disable_intr;
-       }
-
-       if (pciehp_force) {
-               dbg("Bypassing BIOS check for pciehp use on %s\n",
-                               pci_name(ctrl->pci_dev));
-       } else {
-               rc = pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev);
-               if (rc)
-                       goto abort_disable_intr;
-       }
-
-       ctrl->hpc_ops = &pciehp_hpc_ops;
-
-       return 0;
-
-       /* We end up here for the many possible ways to fail this API. */
-abort_disable_intr:
-       rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
-       if (!rc) {
-               temp_word &= ~(intr_enable | HP_INTR_ENABLE);
-               rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
-       }
-       if (rc)
-               err("%s : disabling interrupts failed\n", __FUNCTION__);
-
 abort_free_irq:
        if (pciehp_poll_mode)
                del_timer_sync(&ctrl->poll_timer);
        else
                free_irq(ctrl->pci_dev->irq, ctrl);
-
-abort_free_ctlr:
+abort:
        return -1;
 }
index c424aded13fb43fb108d41870d1c4f46c207de28..dd50713966d1b011bc480aa9d2cab642c63bb7c9 100644 (file)
@@ -105,12 +105,7 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
        }
 
        /* Find Advanced Error Reporting Enhanced Capability */
-       pos = 256;
-       do {
-               pci_read_config_dword(dev, pos, &reg32);
-               if (PCI_EXT_CAP_ID(reg32) == PCI_EXT_CAP_ID_ERR)
-                       break;
-       } while ((pos = PCI_EXT_CAP_NEXT(reg32)));
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
        if (!pos)
                return;
 
@@ -248,11 +243,15 @@ int pciehp_unconfigure_device(struct slot *p_slot)
        u8 bctl = 0;
        u8 presence = 0;
        struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
+       u16 command;
 
        dbg("%s: bus/dev = %x/%x\n", __FUNCTION__, p_slot->bus,
                                p_slot->device);
+       ret = p_slot->hpc_ops->get_adapter_status(p_slot, &presence);
+       if (ret)
+               presence = 0;
 
-       for (j=0; j<8 ; j++) {
+       for (j = 0; j < 8; j++) {
                struct pci_dev* temp = pci_get_slot(parent,
                                (p_slot->device << 3) | j);
                if (!temp)
@@ -263,21 +262,26 @@ int pciehp_unconfigure_device(struct slot *p_slot)
                        pci_dev_put(temp);
                        continue;
                }
-               if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
-                       ret = p_slot->hpc_ops->get_adapter_status(p_slot,
-                                                               &presence);
-                       if (!ret && presence) {
-                               pci_read_config_byte(temp, PCI_BRIDGE_CONTROL,
-                                       &bctl);
-                               if (bctl & PCI_BRIDGE_CTL_VGA) {
-                                       err("Cannot remove display device %s\n",
-                                               pci_name(temp));
-                                       pci_dev_put(temp);
-                                       continue;
-                               }
+               if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE && presence) {
+                       pci_read_config_byte(temp, PCI_BRIDGE_CONTROL, &bctl);
+                       if (bctl & PCI_BRIDGE_CTL_VGA) {
+                               err("Cannot remove display device %s\n",
+                                   pci_name(temp));
+                               pci_dev_put(temp);
+                               continue;
                        }
                }
                pci_remove_bus_device(temp);
+               /*
+                * Ensure that no new Requests will be generated from
+                * the device.
+                */
+               if (presence) {
+                       pci_read_config_word(temp, PCI_COMMAND, &command);
+                       command &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_SERR);
+                       command |= PCI_COMMAND_INTX_DISABLE;
+                       pci_write_config_word(temp, PCI_COMMAND, command);
+               }
                pci_dev_put(temp);
        }
        /*
@@ -288,4 +292,3 @@ int pciehp_unconfigure_device(struct slot *p_slot)
 
        return rc;
 }
-
index c822a779653fd8cdf86e6d4056c5d1000c1a3897..7d5921b1ee7820960afcc6b2b0ae9d711172ea49 100644 (file)
@@ -74,7 +74,6 @@ struct slot {
        u32 type;
        u32 power_domain;
        char *name;
-       char *location;
        struct device_node *dn;
        struct pci_bus *bus;
        struct list_head *pci_devs;
index 0de84533cd80ffc196845677790fcea7211670ce..6571e9b4c2ec95b9f25df46bfd292a20e8160b2b 100644 (file)
@@ -64,19 +64,6 @@ int rpaphp_get_sensor_state(struct slot *slot, int *state)
        return rc;
 }
 
-static void set_slot_name(struct slot *slot)
-{
-       struct pci_bus *bus = slot->bus;
-       struct pci_dev *bridge;
-
-       bridge = bus->self;
-       if (bridge)
-               strcpy(slot->name, pci_name(bridge));
-       else
-               sprintf(slot->name, "%04x:%02x:00.0", pci_domain_nr(bus),
-                       bus->number);
-}
-
 /**
  * rpaphp_enable_slot - record slot state, config pci device
  * @slot: target &slot
@@ -115,7 +102,6 @@ int rpaphp_enable_slot(struct slot *slot)
        info->adapter_status = EMPTY;
        slot->bus = bus;
        slot->pci_devs = &bus->devices;
-       set_slot_name(slot);
 
        /* if there's an adapter in the slot, go add the pci devices */
        if (state == PRESENT) {
index d4ee8723fcb3d6f609b2ac24570e3464648280cd..8ad3debb3794a742db476d28f41ee5aef906a204 100644 (file)
 #include <asm/rtas.h>
 #include "rpaphp.h"
 
-static ssize_t location_read_file (struct hotplug_slot *php_slot, char *buf)
+static ssize_t address_read_file (struct hotplug_slot *php_slot, char *buf)
 {
-       char *value;
-       int retval = -ENOENT;
+       int retval;
        struct slot *slot = (struct slot *)php_slot->private;
+       struct pci_bus *bus;
 
        if (!slot)
-               return retval;
+               return -ENOENT;
+
+       bus = slot->bus;
+       if (!bus)
+               return -ENOENT;
+
+       if (bus->self)
+               retval = sprintf(buf, pci_name(bus->self));
+       else
+               retval = sprintf(buf, "%04x:%02x:00.0",
+                       pci_domain_nr(bus), bus->number);
 
-       value = slot->location;
-       retval = sprintf (buf, "%s\n", value);
        return retval;
 }
 
-static struct hotplug_slot_attribute php_attr_location = {
-       .attr = {.name = "phy_location", .mode = S_IFREG | S_IRUGO},
-       .show = location_read_file,
+static struct hotplug_slot_attribute php_attr_address = {
+       .attr = {.name = "address", .mode = S_IFREG | S_IRUGO},
+       .show = address_read_file,
 };
 
 /* free up the memory used by a slot */
@@ -64,7 +72,6 @@ void dealloc_slot_struct(struct slot *slot)
        kfree(slot->hotplug_slot->info);
        kfree(slot->hotplug_slot->name);
        kfree(slot->hotplug_slot);
-       kfree(slot->location);
        kfree(slot);
 }
 
@@ -83,16 +90,13 @@ struct slot *alloc_slot_struct(struct device_node *dn,
                                           GFP_KERNEL);
        if (!slot->hotplug_slot->info)
                goto error_hpslot;
-       slot->hotplug_slot->name = kmalloc(BUS_ID_SIZE + 1, GFP_KERNEL);
+       slot->hotplug_slot->name = kmalloc(strlen(drc_name) + 1, GFP_KERNEL);
        if (!slot->hotplug_slot->name)
                goto error_info;        
-       slot->location = kmalloc(strlen(drc_name) + 1, GFP_KERNEL);
-       if (!slot->location)
-               goto error_name;
        slot->name = slot->hotplug_slot->name;
+       strcpy(slot->name, drc_name);
        slot->dn = dn;
        slot->index = drc_index;
-       strcpy(slot->location, drc_name);
        slot->power_domain = power_domain;
        slot->hotplug_slot->private = slot;
        slot->hotplug_slot->ops = &rpaphp_hotplug_slot_ops;
@@ -100,8 +104,6 @@ struct slot *alloc_slot_struct(struct device_node *dn,
        
        return (slot);
 
-error_name:
-       kfree(slot->hotplug_slot->name);
 error_info:
        kfree(slot->hotplug_slot->info);
 error_hpslot:
@@ -133,8 +135,8 @@ int rpaphp_deregister_slot(struct slot *slot)
 
        list_del(&slot->rpaphp_slot_list);
        
-       /* remove "phy_location" file */
-       sysfs_remove_file(&php_slot->kobj, &php_attr_location.attr);
+       /* remove "address" file */
+       sysfs_remove_file(&php_slot->kobj, &php_attr_address.attr);
 
        retval = pci_hp_deregister(php_slot);
        if (retval)
@@ -166,8 +168,8 @@ int rpaphp_register_slot(struct slot *slot)
                return retval;
        }
 
-       /* create "phy_location" file */
-       retval = sysfs_create_file(&php_slot->kobj, &php_attr_location.attr);
+       /* create "address" file */
+       retval = sysfs_create_file(&php_slot->kobj, &php_attr_address.attr);
        if (retval) {
                err("sysfs_create_file failed with error %d\n", retval);
                goto sysfs_fail;
@@ -175,8 +177,7 @@ int rpaphp_register_slot(struct slot *slot)
 
        /* add slot to our internal list */
        list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
-       info("Slot [%s](PCI location=%s) registered\n", slot->name,
-                       slot->location);
+       info("Slot [%s] registered\n", slot->name);
        return 0;
 
 sysfs_fail:
index 5183a45d45b50f6a02b5ada18cdeb9e9a0893624..e8aa138128ce7c740a2d8a7c227791cc8df75a2c 100644 (file)
@@ -597,7 +597,7 @@ static void hpc_release_ctlr(struct controller *ctrl)
        cleanup_slots(ctrl);
 
        /*
-        * Mask SERR and System Interrut generation
+        * Mask SERR and System Interrupt generation
         */
        serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
        serr_int |= (GLOBAL_INTR_MASK  | GLOBAL_SERR_MASK |
index e079a5237c9424e7064e1c0892377f2d9b78536b..31fa6c92aa5ef04142dc30b5dc9277a35f46f150 100644 (file)
@@ -1088,7 +1088,7 @@ static void dmar_init_reserved_ranges(void)
        int i;
        u64 addr, size;
 
-       init_iova_domain(&reserved_iova_list);
+       init_iova_domain(&reserved_iova_list, DMA_32BIT_PFN);
 
        /* IOAPIC ranges shouldn't be accessed by DMA */
        iova = reserve_iova(&reserved_iova_list, IOVA_PFN(IOAPIC_RANGE_START),
@@ -1142,7 +1142,7 @@ static int domain_init(struct dmar_domain *domain, int guest_width)
        int adjust_width, agaw;
        unsigned long sagaw;
 
-       init_iova_domain(&domain->iovad);
+       init_iova_domain(&domain->iovad, DMA_32BIT_PFN);
        spin_lock_init(&domain->mapping_lock);
 
        domain_reserve_special_ranges(domain);
@@ -1781,7 +1781,7 @@ __intel_alloc_iova(struct device *dev, struct dmar_domain *domain,
                /*
                 * First try to allocate an io virtual address in
                 * DMA_32BIT_MASK and if that fails then try allocating
-                * from higer range
+                * from higher range
                 */
                iova = iommu_alloc_iova(domain, size, DMA_32BIT_MASK);
                if (!iova)
index 459ad1f9dc549f5d84635c93429a1dafdd44a978..0e4862675ad23450787577713e31331c078fa826 100644 (file)
 
 #include <linux/types.h>
 #include <linux/msi.h>
+#include <linux/sysdev.h>
 #include "iova.h"
 #include <linux/io.h>
 
+/*
+ * We need a fixed PAGE_SIZE of 4K irrespective of
+ * arch PAGE_SIZE for IOMMU page tables.
+ */
+#define PAGE_SHIFT_4K          (12)
+#define PAGE_SIZE_4K           (1UL << PAGE_SHIFT_4K)
+#define PAGE_MASK_4K           (((u64)-1) << PAGE_SHIFT_4K)
+#define PAGE_ALIGN_4K(addr)    (((addr) + PAGE_SIZE_4K - 1) & PAGE_MASK_4K)
+
+#define IOVA_PFN(addr)         ((addr) >> PAGE_SHIFT_4K)
+#define DMA_32BIT_PFN          IOVA_PFN(DMA_32BIT_MASK)
+#define DMA_64BIT_PFN          IOVA_PFN(DMA_64BIT_MASK)
+
 /*
  * Intel IOMMU register specification per version 1.0 public spec.
  */
index a84571c293609bdd3c2d743e73676cde24ce1151..8de7ab6c6d0c11f4772bc1622a303e3c224e1109 100644 (file)
@@ -9,19 +9,19 @@
 #include "iova.h"
 
 void
-init_iova_domain(struct iova_domain *iovad)
+init_iova_domain(struct iova_domain *iovad, unsigned long pfn_32bit)
 {
        spin_lock_init(&iovad->iova_alloc_lock);
        spin_lock_init(&iovad->iova_rbtree_lock);
        iovad->rbroot = RB_ROOT;
        iovad->cached32_node = NULL;
-
+       iovad->dma_32bit_pfn = pfn_32bit;
 }
 
 static struct rb_node *
 __get_cached_rbnode(struct iova_domain *iovad, unsigned long *limit_pfn)
 {
-       if ((*limit_pfn != DMA_32BIT_PFN) ||
+       if ((*limit_pfn != iovad->dma_32bit_pfn) ||
                (iovad->cached32_node == NULL))
                return rb_last(&iovad->rbroot);
        else {
@@ -37,7 +37,7 @@ static void
 __cached_rbnode_insert_update(struct iova_domain *iovad,
        unsigned long limit_pfn, struct iova *new)
 {
-       if (limit_pfn != DMA_32BIT_PFN)
+       if (limit_pfn != iovad->dma_32bit_pfn)
                return;
        iovad->cached32_node = &new->node;
 }
index ae3028d5a9415e76a076928704c67755e3fe06ec..d521b5b7319c42ebdbade15a45fb41486309611d 100644 (file)
 #include <linux/rbtree.h>
 #include <linux/dma-mapping.h>
 
-/*
- * We need a fixed PAGE_SIZE of 4K irrespective of
- * arch PAGE_SIZE for IOMMU page tables.
- */
-#define PAGE_SHIFT_4K          (12)
-#define PAGE_SIZE_4K           (1UL << PAGE_SHIFT_4K)
-#define PAGE_MASK_4K           (((u64)-1) << PAGE_SHIFT_4K)
-#define PAGE_ALIGN_4K(addr)    (((addr) + PAGE_SIZE_4K - 1) & PAGE_MASK_4K)
-
 /* IO virtual address start page frame number */
 #define IOVA_START_PFN         (1)
 
-#define IOVA_PFN(addr)         ((addr) >> PAGE_SHIFT_4K)
-#define DMA_32BIT_PFN  IOVA_PFN(DMA_32BIT_MASK)
-#define DMA_64BIT_PFN  IOVA_PFN(DMA_64BIT_MASK)
-
 /* iova structure */
 struct iova {
        struct rb_node  node;
@@ -44,6 +31,7 @@ struct iova_domain {
        spinlock_t      iova_rbtree_lock; /* Lock to protect update of rbtree */
        struct rb_root  rbroot;         /* iova domain rbtree root */
        struct rb_node  *cached32_node; /* Save last alloced node */
+       unsigned long   dma_32bit_pfn;
 };
 
 struct iova *alloc_iova_mem(void);
@@ -56,7 +44,7 @@ struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size,
 struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo,
        unsigned long pfn_hi);
 void copy_reserved_iova(struct iova_domain *from, struct iova_domain *to);
-void init_iova_domain(struct iova_domain *iovad);
+void init_iova_domain(struct iova_domain *iovad, unsigned long pfn_32bit);
 struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn);
 void put_iova_domain(struct iova_domain *iovad);
 
index 07c9f09c856dba943a15f7e794ba8e1eaef78387..26938da8f4380c5fd0bdb1786c71f8adb8418046 100644 (file)
 
 static int pci_msi_enable = 1;
 
+/* Arch hooks */
+
+int __attribute__ ((weak))
+arch_msi_check_device(struct pci_dev *dev, int nvec, int type)
+{
+       return 0;
+}
+
+int __attribute__ ((weak))
+arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *entry)
+{
+       return 0;
+}
+
+int __attribute__ ((weak))
+arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
+{
+       struct msi_desc *entry;
+       int ret;
+
+       list_for_each_entry(entry, &dev->msi_list, list) {
+               ret = arch_setup_msi_irq(dev, entry);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+void __attribute__ ((weak)) arch_teardown_msi_irq(unsigned int irq)
+{
+       return;
+}
+
+void __attribute__ ((weak))
+arch_teardown_msi_irqs(struct pci_dev *dev)
+{
+       struct msi_desc *entry;
+
+       list_for_each_entry(entry, &dev->msi_list, list) {
+               if (entry->irq != 0)
+                       arch_teardown_msi_irq(entry->irq);
+       }
+}
+
 static void msi_set_enable(struct pci_dev *dev, int enable)
 {
        int pos;
@@ -230,7 +275,6 @@ static void pci_intx_for_msi(struct pci_dev *dev, int enable)
                pci_intx(dev, enable);
 }
 
-#ifdef CONFIG_PM
 static void __pci_restore_msi_state(struct pci_dev *dev)
 {
        int pos;
@@ -288,7 +332,7 @@ void pci_restore_msi_state(struct pci_dev *dev)
        __pci_restore_msi_state(dev);
        __pci_restore_msix_state(dev);
 }
-#endif /* CONFIG_PM */
+EXPORT_SYMBOL_GPL(pci_restore_msi_state);
 
 /**
  * msi_capability_init - configure device's MSI capability structure
@@ -683,49 +727,3 @@ void pci_msi_init_pci_dev(struct pci_dev *dev)
 {
        INIT_LIST_HEAD(&dev->msi_list);
 }
-
-
-/* Arch hooks */
-
-int __attribute__ ((weak))
-arch_msi_check_device(struct pci_dev* dev, int nvec, int type)
-{
-       return 0;
-}
-
-int __attribute__ ((weak))
-arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *entry)
-{
-       return 0;
-}
-
-int __attribute__ ((weak))
-arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
-{
-       struct msi_desc *entry;
-       int ret;
-
-       list_for_each_entry(entry, &dev->msi_list, list) {
-               ret = arch_setup_msi_irq(dev, entry);
-               if (ret)
-                       return ret;
-       }
-
-       return 0;
-}
-
-void __attribute__ ((weak)) arch_teardown_msi_irq(unsigned int irq)
-{
-       return;
-}
-
-void __attribute__ ((weak))
-arch_teardown_msi_irqs(struct pci_dev *dev)
-{
-       struct msi_desc *entry;
-
-       list_for_each_entry(entry, &dev->msi_list, list) {
-               if (entry->irq != 0)
-                       arch_teardown_msi_irq(entry->irq);
-       }
-}
index 5c6a5d043007ebec1418fe2d9a70cf5071cc06eb..e569645d59e2f3ef429cac60e1da67840277a348 100644 (file)
@@ -156,13 +156,13 @@ run_osc_out:
 }
 
 /**
- * pci_osc_support_set - register OS support to Firmware
+ * __pci_osc_support_set - register OS support to Firmware
  * @flags: OS support bits
  *
  * Update OS support fields and doing a _OSC Query to obtain an update
  * from Firmware on supported control bits.
  **/
-acpi_status pci_osc_support_set(u32 flags)
+acpi_status __pci_osc_support_set(u32 flags, const char *hid)
 {
        u32 temp;
        acpi_status retval;
@@ -176,7 +176,7 @@ acpi_status pci_osc_support_set(u32 flags)
        temp = ctrlset_buf[OSC_CONTROL_TYPE];
        ctrlset_buf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
        ctrlset_buf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
-       acpi_get_devices ( PCI_ROOT_HID_STRING,
+       acpi_get_devices(hid,
                        acpi_query_osc,
                        ctrlset_buf,
                        (void **) &retval );
@@ -188,7 +188,6 @@ acpi_status pci_osc_support_set(u32 flags)
        }
        return AE_OK;
 }
-EXPORT_SYMBOL(pci_osc_support_set);
 
 /**
  * pci_osc_control_set - commit requested control to Firmware
index c4fa35d1dd7721d7a8288b1bcba6978b6b9412a5..e571c72e67531017f140ee6e323e89644f7320b0 100644 (file)
@@ -186,13 +186,11 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
            set_cpus_allowed(current, node_to_cpumask(node));
        /* And set default memory allocation policy */
        oldpol = current->mempolicy;
-       current->mempolicy = &default_policy;
-       mpol_get(current->mempolicy);
+       current->mempolicy = NULL;      /* fall back to system default policy */
 #endif
        error = drv->probe(dev, id);
 #ifdef CONFIG_NUMA
        set_cpus_allowed(current, oldmask);
-       mpol_free(current->mempolicy);
        current->mempolicy = oldpol;
 #endif
        return error;
index 7d1877341aada287783065bf15ab9f6349b2b07a..8dcf1458aa2fafe6e0433efd1dfb515ce503271a 100644 (file)
@@ -358,7 +358,7 @@ pci_read_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
                   char *buf, loff_t off, size_t count)
 {
         struct pci_bus *bus = to_pci_bus(container_of(kobj,
-                                                      struct class_device,
+                                                      struct device,
                                                      kobj));
 
         /* Only support 1, 2 or 4 byte accesses */
@@ -383,7 +383,7 @@ pci_write_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
                    char *buf, loff_t off, size_t count)
 {
         struct pci_bus *bus = to_pci_bus(container_of(kobj,
-                                                     struct class_device,
+                                                     struct device,
                                                      kobj));
         /* Only support 1, 2 or 4 byte accesses */
         if (count != 1 && count != 2 && count != 4)
@@ -407,7 +407,7 @@ pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr,
                     struct vm_area_struct *vma)
 {
         struct pci_bus *bus = to_pci_bus(container_of(kobj,
-                                                      struct class_device,
+                                                      struct device,
                                                      kobj));
 
         return pci_mmap_legacy_page_range(bus, vma);
index 7d4ce906d207b5f9a40d7e6de1d398dbf6130216..ae3df46eaabf29db0f1af949e8926f0abbb8ec1a 100644 (file)
@@ -314,6 +314,24 @@ int pci_find_ht_capability(struct pci_dev *dev, int ht_cap)
 }
 EXPORT_SYMBOL_GPL(pci_find_ht_capability);
 
+void pcie_wait_pending_transaction(struct pci_dev *dev)
+{
+       int pos;
+       u16 reg16;
+
+       pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
+       if (!pos)
+               return;
+       while (1) {
+               pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &reg16);
+               if (!(reg16 & PCI_EXP_DEVSTA_TRPND))
+                       break;
+               cpu_relax();
+       }
+
+}
+EXPORT_SYMBOL_GPL(pcie_wait_pending_transaction);
+
 /**
  * pci_find_parent_resource - return resource region of parent bus of given region
  * @dev: PCI device structure contains resources to be searched
@@ -353,7 +371,7 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
  * Restore the BAR values for a given device, so as to make it
  * accessible by its driver.
  */
-void
+static void
 pci_restore_bars(struct pci_dev *dev)
 {
        int i, numres;
@@ -551,6 +569,7 @@ static int pci_save_pcie_state(struct pci_dev *dev)
        int pos, i = 0;
        struct pci_cap_saved_state *save_state;
        u16 *cap;
+       int found = 0;
 
        pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
        if (pos <= 0)
@@ -559,6 +578,8 @@ static int pci_save_pcie_state(struct pci_dev *dev)
        save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
        if (!save_state)
                save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
+       else
+               found = 1;
        if (!save_state) {
                dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
                return -ENOMEM;
@@ -569,7 +590,9 @@ static int pci_save_pcie_state(struct pci_dev *dev)
        pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
        pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
        pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
-       pci_add_saved_cap(dev, save_state);
+       save_state->cap_nr = PCI_CAP_ID_EXP;
+       if (!found)
+               pci_add_saved_cap(dev, save_state);
        return 0;
 }
 
@@ -597,14 +620,17 @@ static int pci_save_pcix_state(struct pci_dev *dev)
        int pos, i = 0;
        struct pci_cap_saved_state *save_state;
        u16 *cap;
+       int found = 0;
 
        pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
        if (pos <= 0)
                return 0;
 
-       save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
+       save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
        if (!save_state)
                save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
+       else
+               found = 1;
        if (!save_state) {
                dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
                return -ENOMEM;
@@ -612,7 +638,9 @@ static int pci_save_pcix_state(struct pci_dev *dev)
        cap = (u16 *)&save_state->data[0];
 
        pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]);
-       pci_add_saved_cap(dev, save_state);
+       save_state->cap_nr = PCI_CAP_ID_PCIX;
+       if (!found)
+               pci_add_saved_cap(dev, save_state);
        return 0;
 }
 
@@ -713,29 +741,51 @@ int pci_reenable_device(struct pci_dev *dev)
        return 0;
 }
 
-/**
- * pci_enable_device_bars - Initialize some of a device for use
- * @dev: PCI device to be initialized
- * @bars: bitmask of BAR's that must be configured
- *
- *  Initialize device before it's used by a driver. Ask low-level code
- *  to enable selected I/O and memory resources. Wake up the device if it
- *  was suspended. Beware, this function can fail.
- */
-int
-pci_enable_device_bars(struct pci_dev *dev, int bars)
+static int __pci_enable_device_flags(struct pci_dev *dev,
+                                    resource_size_t flags)
 {
        int err;
+       int i, bars = 0;
 
        if (atomic_add_return(1, &dev->enable_cnt) > 1)
                return 0;               /* already enabled */
 
+       for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
+               if (dev->resource[i].flags & flags)
+                       bars |= (1 << i);
+
        err = do_pci_enable_device(dev, bars);
        if (err < 0)
                atomic_dec(&dev->enable_cnt);
        return err;
 }
 
+/**
+ * pci_enable_device_io - Initialize a device for use with IO space
+ * @dev: PCI device to be initialized
+ *
+ *  Initialize device before it's used by a driver. Ask low-level code
+ *  to enable I/O resources. Wake up the device if it was suspended.
+ *  Beware, this function can fail.
+ */
+int pci_enable_device_io(struct pci_dev *dev)
+{
+       return __pci_enable_device_flags(dev, IORESOURCE_IO);
+}
+
+/**
+ * pci_enable_device_mem - Initialize a device for use with Memory space
+ * @dev: PCI device to be initialized
+ *
+ *  Initialize device before it's used by a driver. Ask low-level code
+ *  to enable Memory resources. Wake up the device if it was suspended.
+ *  Beware, this function can fail.
+ */
+int pci_enable_device_mem(struct pci_dev *dev)
+{
+       return __pci_enable_device_flags(dev, IORESOURCE_MEM);
+}
+
 /**
  * pci_enable_device - Initialize device before it's used by a driver.
  * @dev: PCI device to be initialized
@@ -749,7 +799,7 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
  */
 int pci_enable_device(struct pci_dev *dev)
 {
-       return pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
+       return __pci_enable_device_flags(dev, IORESOURCE_MEM | IORESOURCE_IO);
 }
 
 /*
@@ -885,6 +935,9 @@ pci_disable_device(struct pci_dev *dev)
        if (atomic_sub_return(1, &dev->enable_cnt) != 0)
                return;
 
+       /* Wait for all transactions are finished before disabling the device */
+       pcie_wait_pending_transaction(dev);
+
        pci_read_config_word(dev, PCI_COMMAND, &pci_command);
        if (pci_command & PCI_COMMAND_MASTER) {
                pci_command &= ~PCI_COMMAND_MASTER;
@@ -1398,6 +1451,22 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
 }
 #endif
 
+#ifndef HAVE_ARCH_PCI_SET_DMA_MAX_SEGMENT_SIZE
+int pci_set_dma_max_seg_size(struct pci_dev *dev, unsigned int size)
+{
+       return dma_set_max_seg_size(&dev->dev, size);
+}
+EXPORT_SYMBOL(pci_set_dma_max_seg_size);
+#endif
+
+#ifndef HAVE_ARCH_PCI_SET_DMA_SEGMENT_BOUNDARY
+int pci_set_dma_seg_boundary(struct pci_dev *dev, unsigned long mask)
+{
+       return dma_set_seg_boundary(&dev->dev, mask);
+}
+EXPORT_SYMBOL(pci_set_dma_seg_boundary);
+#endif
+
 /**
  * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count
  * @dev: PCI device to query
@@ -1619,9 +1688,9 @@ early_param("pci", pci_setup);
 
 device_initcall(pci_init);
 
-EXPORT_SYMBOL_GPL(pci_restore_bars);
 EXPORT_SYMBOL(pci_reenable_device);
-EXPORT_SYMBOL(pci_enable_device_bars);
+EXPORT_SYMBOL(pci_enable_device_io);
+EXPORT_SYMBOL(pci_enable_device_mem);
 EXPORT_SYMBOL(pci_enable_device);
 EXPORT_SYMBOL(pcim_enable_device);
 EXPORT_SYMBOL(pcim_pin_device);
index fc87e14b50de9a15b491ed800320fd9e01f6e7e5..eabeb1f2ec998b0cf39de823b7c0bfd7a237b6ba 100644 (file)
@@ -6,8 +6,10 @@ extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
 extern void pci_cleanup_rom(struct pci_dev *dev);
 
 /* Firmware callbacks */
-extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
-extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state);
+extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev,
+                                               pm_message_t state);
+extern int (*platform_pci_set_power_state)(struct pci_dev *dev,
+                                               pci_power_t state);
 
 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
@@ -45,12 +47,6 @@ static inline void pci_no_msi(void) { }
 static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { }
 #endif
 
-#if defined(CONFIG_PCI_MSI) && defined(CONFIG_PM)
-void pci_restore_msi_state(struct pci_dev *dev);
-#else
-static inline void pci_restore_msi_state(struct pci_dev *dev) {}
-#endif
-
 #ifdef CONFIG_PCIEAER
 void pci_no_aer(void);
 #else
@@ -68,14 +64,14 @@ static inline int pci_no_d1d2(struct pci_dev *dev)
 }
 extern int pcie_mch_quirk;
 extern struct device_attribute pci_dev_attrs[];
-extern struct class_device_attribute class_device_attr_cpuaffinity;
+extern struct device_attribute dev_attr_cpuaffinity;
 
 /**
  * pci_match_one_device - Tell if a PCI device structure has a matching
  *                        PCI device id structure
  * @id: single PCI device id structure to match
  * @dev: the PCI device structure to match against
- * 
+ *
  * Returns the matching pci_device_id structure or %NULL if there is no match.
  */
 static inline const struct pci_device_id *
index 1a1eb45a779e3862f8ef634cd425d4f117444661..8c199ae84f6dbadc59d46d876448b3f522bd849b 100644 (file)
@@ -31,26 +31,16 @@ int aer_osc_setup(struct pcie_device *pciedev)
 {
        acpi_status status = AE_NOT_FOUND;
        struct pci_dev *pdev = pciedev->port;
-       acpi_handle handle = DEVICE_ACPI_HANDLE(&pdev->dev);
-       struct pci_bus *parent;
+       acpi_handle handle = 0;
 
-       while (!handle) {
-               if (!pdev || !pdev->bus->parent)
-                       break;
-               parent = pdev->bus->parent;
-               if (!parent->self)
-                       /* Parent must be a host bridge */
-                       handle = acpi_get_pci_rootbridge_handle(
-                                       pci_domain_nr(parent),
-                                       parent->number);
-               else
-                       handle = DEVICE_ACPI_HANDLE(
-                                       &(parent->self->dev));
-               pdev = parent->self;
-       }
+       /* Find root host bridge */
+       while (pdev->bus && pdev->bus->self)
+               pdev = pdev->bus->self;
+       handle = acpi_get_pci_rootbridge_handle(
+               pci_domain_nr(pdev->bus), pdev->bus->number);
 
        if (handle) {
-               pci_osc_support_set(OSC_EXT_PCI_CONFIG_SUPPORT);
+               pcie_osc_support_set(OSC_EXT_PCI_CONFIG_SUPPORT);
                status = pci_osc_control_set(handle,
                                        OSC_PCI_EXPRESS_AER_CONTROL |
                                        OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
index b20a9b81dae2df5e9cca491b4c1504def575858c..23d9eb073296dea5e974141c008ee2154b9b6257 100644 (file)
@@ -192,9 +192,8 @@ static int get_port_device_capability(struct pci_dev *dev)
                if (reg32 & SLOT_HP_CAPABLE_MASK)
                        services |= PCIE_PORT_SERVICE_HP;
        } 
-       /* PME Capable */
-       pos = pci_find_capability(dev, PCI_CAP_ID_PME);
-       if (pos) 
+       /* PME Capable - root port capability */
+       if (((reg16 >> 4) & PORT_TYPE_MASK) == PCIE_RC_PORT)
                services |= PCIE_PORT_SERVICE_PME;
        
        pos = PCI_CFG_SPACE_SIZE;
index 5fd585293e7954c777094b6331e5a5fae9c094ca..4d23b9fb551bc129239f07404e04f6a4102ae092 100644 (file)
@@ -53,7 +53,7 @@ static void pci_create_legacy_files(struct pci_bus *b)
                b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
                b->legacy_io->read = pci_read_legacy_io;
                b->legacy_io->write = pci_write_legacy_io;
-               class_device_create_bin_file(&b->class_dev, b->legacy_io);
+               device_create_bin_file(&b->dev, b->legacy_io);
 
                /* Allocated above after the legacy_io struct */
                b->legacy_mem = b->legacy_io + 1;
@@ -61,15 +61,15 @@ static void pci_create_legacy_files(struct pci_bus *b)
                b->legacy_mem->size = 1024*1024;
                b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
                b->legacy_mem->mmap = pci_mmap_legacy_mem;
-               class_device_create_bin_file(&b->class_dev, b->legacy_mem);
+               device_create_bin_file(&b->dev, b->legacy_mem);
        }
 }
 
 void pci_remove_legacy_files(struct pci_bus *b)
 {
        if (b->legacy_io) {
-               class_device_remove_bin_file(&b->class_dev, b->legacy_io);
-               class_device_remove_bin_file(&b->class_dev, b->legacy_mem);
+               device_remove_bin_file(&b->dev, b->legacy_io);
+               device_remove_bin_file(&b->dev, b->legacy_mem);
                kfree(b->legacy_io); /* both are allocated here */
        }
 }
@@ -81,26 +81,27 @@ void pci_remove_legacy_files(struct pci_bus *bus) { return; }
 /*
  * PCI Bus Class Devices
  */
-static ssize_t pci_bus_show_cpuaffinity(struct class_device *class_dev,
+static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
+                                       struct device_attribute *attr,
                                        char *buf)
 {
        int ret;
        cpumask_t cpumask;
 
-       cpumask = pcibus_to_cpumask(to_pci_bus(class_dev));
+       cpumask = pcibus_to_cpumask(to_pci_bus(dev));
        ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask);
        if (ret < PAGE_SIZE)
                buf[ret++] = '\n';
        return ret;
 }
-CLASS_DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL);
+DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL);
 
 /*
  * PCI Bus Class
  */
-static void release_pcibus_dev(struct class_device *class_dev)
+static void release_pcibus_dev(struct device *dev)
 {
-       struct pci_bus *pci_bus = to_pci_bus(class_dev);
+       struct pci_bus *pci_bus = to_pci_bus(dev);
 
        if (pci_bus->bridge)
                put_device(pci_bus->bridge);
@@ -109,7 +110,7 @@ static void release_pcibus_dev(struct class_device *class_dev)
 
 static struct class pcibus_class = {
        .name           = "pci_bus",
-       .release        = &release_pcibus_dev,
+       .dev_release    = &release_pcibus_dev,
 };
 
 static int __init pcibus_class_init(void)
@@ -392,7 +393,6 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
 {
        struct pci_bus *child;
        int i;
-       int retval;
 
        /*
         * Allocate a new bus, and inherit stuff from the parent..
@@ -408,15 +408,12 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
        child->bus_flags = parent->bus_flags;
        child->bridge = get_device(&bridge->dev);
 
-       child->class_dev.class = &pcibus_class;
-       sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr);
-       retval = class_device_register(&child->class_dev);
-       if (retval)
-               goto error_register;
-       retval = class_device_create_file(&child->class_dev,
-                                         &class_device_attr_cpuaffinity);
-       if (retval)
-               goto error_file_create;
+       /* initialize some portions of the bus device, but don't register it
+        * now as the parent is not properly set up yet.  This device will get
+        * registered later in pci_bus_add_devices()
+        */
+       child->dev.class = &pcibus_class;
+       sprintf(child->dev.bus_id, "%04x:%02x", pci_domain_nr(child), busnr);
 
        /*
         * Set up the primary, secondary and subordinate
@@ -434,15 +431,9 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
        bridge->subordinate = child;
 
        return child;
-
-error_file_create:
-       class_device_unregister(&child->class_dev);
-error_register:
-       kfree(child);
-       return NULL;
 }
 
-struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr)
+struct pci_bus *__ref pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr)
 {
        struct pci_bus *child;
 
@@ -471,8 +462,6 @@ static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)
        }
 }
 
-unsigned int pci_scan_child_bus(struct pci_bus *bus);
-
 /*
  * If it's a bridge, configure it and scan the bus behind it.
  * For CardBus bridges, we don't scan behind as the devices will
@@ -641,13 +630,13 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass
                    (child->number > bus->subordinate) ||
                    (child->number < bus->number) ||
                    (child->subordinate < bus->number)) {
-                       pr_debug("PCI: Bus #%02x (-#%02x) is %s"
+                       pr_debug("PCI: Bus #%02x (-#%02x) is %s "
                                "hidden behind%s bridge #%02x (-#%02x)\n",
                                child->number, child->subordinate,
                                (bus->number > child->subordinate &&
                                 bus->subordinate < child->number) ?
-                                       "wholly " : " partially",
-                               bus->self->transparent ? " transparent" : " ",
+                                       "wholly" : "partially",
+                               bus->self->transparent ? " transparent" : "",
                                bus->number, bus->subordinate);
                }
                bus = bus->parent;
@@ -944,8 +933,12 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 
        set_dev_node(&dev->dev, pcibus_to_node(bus));
        dev->dev.dma_mask = &dev->dma_mask;
+       dev->dev.dma_parms = &dev->dma_parms;
        dev->dev.coherent_dma_mask = 0xffffffffull;
 
+       pci_set_dma_max_seg_size(dev, 65536);
+       pci_set_dma_seg_boundary(dev, 0xffffffff);
+
        /* Fix up broken headers */
        pci_fixup_device(pci_fixup_header, dev);
 
@@ -959,7 +952,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
        up_write(&pci_bus_sem);
 }
 
-struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn)
+struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
 {
        struct pci_dev *dev;
 
@@ -971,6 +964,7 @@ struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn)
 
        return dev;
 }
+EXPORT_SYMBOL(pci_scan_single_device);
 
 /**
  * pci_scan_slot - scan a PCI slot on a bus for devices.
@@ -1050,20 +1044,6 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus)
        return max;
 }
 
-unsigned int __devinit pci_do_scan_bus(struct pci_bus *bus)
-{
-       unsigned int max;
-
-       max = pci_scan_child_bus(bus);
-
-       /*
-        * Make the discovered devices available.
-        */
-       pci_bus_add_devices(bus);
-
-       return max;
-}
-
 struct pci_bus * pci_create_bus(struct device *parent,
                int bus, struct pci_ops *ops, void *sysdata)
 {
@@ -1103,32 +1083,27 @@ struct pci_bus * pci_create_bus(struct device *parent,
                goto dev_reg_err;
        b->bridge = get_device(dev);
 
-       b->class_dev.class = &pcibus_class;
-       sprintf(b->class_dev.class_id, "%04x:%02x", pci_domain_nr(b), bus);
-       error = class_device_register(&b->class_dev);
+       b->dev.class = &pcibus_class;
+       b->dev.parent = b->bridge;
+       sprintf(b->dev.bus_id, "%04x:%02x", pci_domain_nr(b), bus);
+       error = device_register(&b->dev);
        if (error)
                goto class_dev_reg_err;
-       error = class_device_create_file(&b->class_dev, &class_device_attr_cpuaffinity);
+       error = device_create_file(&b->dev, &dev_attr_cpuaffinity);
        if (error)
-               goto class_dev_create_file_err;
+               goto dev_create_file_err;
 
        /* Create legacy_io and legacy_mem files for this bus */
        pci_create_legacy_files(b);
 
-       error = sysfs_create_link(&b->class_dev.kobj, &b->bridge->kobj, "bridge");
-       if (error)
-               goto sys_create_link_err;
-
        b->number = b->secondary = bus;
        b->resource[0] = &ioport_resource;
        b->resource[1] = &iomem_resource;
 
        return b;
 
-sys_create_link_err:
-       class_device_remove_file(&b->class_dev, &class_device_attr_cpuaffinity);
-class_dev_create_file_err:
-       class_device_unregister(&b->class_dev);
+dev_create_file_err:
+       device_unregister(&b->dev);
 class_dev_reg_err:
        device_unregister(dev);
 dev_reg_err:
@@ -1140,7 +1115,6 @@ err_out:
        kfree(b);
        return NULL;
 }
-EXPORT_SYMBOL_GPL(pci_create_bus);
 
 struct pci_bus *pci_scan_bus_parented(struct device *parent,
                int bus, struct pci_ops *ops, void *sysdata)
@@ -1156,10 +1130,8 @@ EXPORT_SYMBOL(pci_scan_bus_parented);
 
 #ifdef CONFIG_HOTPLUG
 EXPORT_SYMBOL(pci_add_new_bus);
-EXPORT_SYMBOL(pci_do_scan_bus);
 EXPORT_SYMBOL(pci_scan_slot);
 EXPORT_SYMBOL(pci_scan_bridge);
-EXPORT_SYMBOL(pci_scan_single_device);
 EXPORT_SYMBOL_GPL(pci_scan_child_bus);
 #endif
 
index 716439e25dd283fcf4ecce43c9966bd33d044a27..68aeeb7206de61bfefb9d0b6e2ac8250da933a62 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/smp_lock.h>
 #include <linux/capability.h>
 #include <asm/uaccess.h>
 #include <asm/byteorder.h>
@@ -202,15 +203,18 @@ struct pci_filp_private {
        int write_combine;
 };
 
-static int proc_bus_pci_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd,
+                              unsigned long arg)
 {
-       const struct proc_dir_entry *dp = PDE(inode);
+       const struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
        struct pci_dev *dev = dp->data;
 #ifdef HAVE_PCI_MMAP
        struct pci_filp_private *fpriv = file->private_data;
 #endif /* HAVE_PCI_MMAP */
        int ret = 0;
 
+       lock_kernel();
+
        switch (cmd) {
        case PCIIOC_CONTROLLER:
                ret = pci_domain_nr(dev->bus);
@@ -239,6 +243,7 @@ static int proc_bus_pci_ioctl(struct inode *inode, struct file *file, unsigned i
                break;
        };
 
+       unlock_kernel();
        return ret;
 }
 
@@ -291,7 +296,7 @@ static const struct file_operations proc_bus_pci_operations = {
        .llseek         = proc_bus_pci_lseek,
        .read           = proc_bus_pci_read,
        .write          = proc_bus_pci_write,
-       .ioctl          = proc_bus_pci_ioctl,
+       .unlocked_ioctl = proc_bus_pci_ioctl,
 #ifdef HAVE_PCI_MMAP
        .open           = proc_bus_pci_open,
        .release        = proc_bus_pci_release,
@@ -370,7 +375,7 @@ static int show_device(struct seq_file *m, void *v)
        return 0;
 }
 
-static struct seq_operations proc_bus_pci_devices_op = {
+static const struct seq_operations proc_bus_pci_devices_op = {
        .start  = pci_seq_start,
        .next   = pci_seq_next,
        .stop   = pci_seq_stop,
@@ -480,7 +485,3 @@ static int __init pci_proc_init(void)
 
 __initcall(pci_proc_init);
 
-#ifdef CONFIG_HOTPLUG
-EXPORT_SYMBOL(pci_proc_detach_bus);
-#endif
-
index 72e0bd5d80aced43ef522ff52efdeebd65b86aa6..0a953d43b9a207961a6d41dbb1872d105f978982 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/acpi.h>
+#include <linux/kallsyms.h>
 #include "pci.h"
 
 /* The Mellanox Tavor device gives false positive parity errors
@@ -46,14 +47,14 @@ static void quirk_passive_release(struct pci_dev *dev)
        while ((d = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, d))) {
                pci_read_config_byte(d, 0x82, &dlc);
                if (!(dlc & 1<<1)) {
-                       printk(KERN_ERR "PCI: PIIX3: Enabling Passive Release on %s\n", pci_name(d));
+                       dev_err(&d->dev, "PIIX3: Enabling Passive Release\n");
                        dlc |= 1<<1;
                        pci_write_config_byte(d, 0x82, dlc);
                }
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82441,      quirk_passive_release );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82441,      quirk_passive_release );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82441,      quirk_passive_release);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82441,      quirk_passive_release);
 
 /*  The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a workaround
     but VIA don't answer queries. If you happen to have good contacts at VIA
@@ -68,20 +69,20 @@ static void __devinit quirk_isa_dma_hangs(struct pci_dev *dev)
 {
        if (!isa_dma_bridge_buggy) {
                isa_dma_bridge_buggy=1;
-               printk(KERN_INFO "Activating ISA DMA hang workarounds.\n");
+               dev_info(&dev->dev, "Activating ISA DMA hang workarounds\n");
        }
 }
        /*
         * Its not totally clear which chipsets are the problematic ones
         * We know 82C586 and 82C596 variants are affected.
         */
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C586_0,     quirk_isa_dma_hangs );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C596,       quirk_isa_dma_hangs );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82371SB_0,  quirk_isa_dma_hangs );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M1533,         quirk_isa_dma_hangs );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,     PCI_DEVICE_ID_NEC_CBUS_1,       quirk_isa_dma_hangs );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,     PCI_DEVICE_ID_NEC_CBUS_2,       quirk_isa_dma_hangs );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,     PCI_DEVICE_ID_NEC_CBUS_3,       quirk_isa_dma_hangs );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C586_0,     quirk_isa_dma_hangs);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C596,       quirk_isa_dma_hangs);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82371SB_0,  quirk_isa_dma_hangs);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M1533,         quirk_isa_dma_hangs);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,     PCI_DEVICE_ID_NEC_CBUS_1,       quirk_isa_dma_hangs);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,     PCI_DEVICE_ID_NEC_CBUS_2,       quirk_isa_dma_hangs);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,     PCI_DEVICE_ID_NEC_CBUS_3,       quirk_isa_dma_hangs);
 
 int pci_pci_problems;
 EXPORT_SYMBOL(pci_pci_problems);
@@ -92,12 +93,12 @@ EXPORT_SYMBOL(pci_pci_problems);
 static void __devinit quirk_nopcipci(struct pci_dev *dev)
 {
        if ((pci_pci_problems & PCIPCI_FAIL)==0) {
-               printk(KERN_INFO "Disabling direct PCI/PCI transfers.\n");
+               dev_info(&dev->dev, "Disabling direct PCI/PCI transfers\n");
                pci_pci_problems |= PCIPCI_FAIL;
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_5597,          quirk_nopcipci );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_496,           quirk_nopcipci );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_5597,          quirk_nopcipci);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_496,           quirk_nopcipci);
 
 static void __devinit quirk_nopciamd(struct pci_dev *dev)
 {
@@ -105,11 +106,11 @@ static void __devinit quirk_nopciamd(struct pci_dev *dev)
        pci_read_config_byte(dev, 0x08, &rev);
        if (rev == 0x13) {
                /* Erratum 24 */
-               printk(KERN_INFO "Chipset erratum: Disabling direct PCI/AGP transfers.\n");
+               dev_info(&dev->dev, "Chipset erratum: Disabling direct PCI/AGP transfers\n");
                pci_pci_problems |= PCIAGP_FAIL;
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_8151_0,       quirk_nopciamd );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_8151_0,       quirk_nopciamd);
 
 /*
  *     Triton requires workarounds to be used by the drivers
@@ -117,14 +118,14 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,        PCI_DEVICE_ID_AMD_8151_0,       quirk_nopci
 static void __devinit quirk_triton(struct pci_dev *dev)
 {
        if ((pci_pci_problems&PCIPCI_TRITON)==0) {
-               printk(KERN_INFO "Limiting direct PCI/PCI transfers.\n");
+               dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
                pci_pci_problems |= PCIPCI_TRITON;
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82437,      quirk_triton ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82437VX,    quirk_triton ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82439,      quirk_triton ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82439TX,    quirk_triton ); 
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82437,      quirk_triton);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82437VX,    quirk_triton);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82439,      quirk_triton);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82439TX,    quirk_triton);
 
 /*
  *     VIA Apollo KT133 needs PCI latency patch
@@ -139,25 +140,22 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,      PCI_DEVICE_ID_INTEL_82439TX,    quir
 static void quirk_vialatency(struct pci_dev *dev)
 {
        struct pci_dev *p;
-       u8 rev;
        u8 busarb;
        /* Ok we have a potential problem chipset here. Now see if we have
           a buggy southbridge */
           
        p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, NULL);
        if (p!=NULL) {
-               pci_read_config_byte(p, PCI_CLASS_REVISION, &rev);
                /* 0x40 - 0x4f == 686B, 0x10 - 0x2f == 686A; thanks Dan Hollis */
                /* Check for buggy part revisions */
-               if (rev < 0x40 || rev > 0x42)
+               if (p->revision < 0x40 || p->revision > 0x42)
                        goto exit;
        } else {
                p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL);
                if (p==NULL)    /* No problem parts */
                        goto exit;
-               pci_read_config_byte(p, PCI_CLASS_REVISION, &rev);
                /* Check for buggy part revisions */
-               if (rev < 0x10 || rev > 0x12) 
+               if (p->revision < 0x10 || p->revision > 0x12)
                        goto exit;
        }
        
@@ -180,17 +178,17 @@ static void quirk_vialatency(struct pci_dev *dev)
        busarb &= ~(1<<5);
        busarb |= (1<<4);
        pci_write_config_byte(dev, 0x76, busarb);
-       printk(KERN_INFO "Applying VIA southbridge workaround.\n");
+       dev_info(&dev->dev, "Applying VIA southbridge workaround\n");
 exit:
        pci_dev_put(p);
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8363_0,       quirk_vialatency );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8371_1,       quirk_vialatency );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8361,         quirk_vialatency );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8363_0,       quirk_vialatency);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8371_1,       quirk_vialatency);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8361,         quirk_vialatency);
 /* Must restore this on a resume from RAM */
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8363_0,       quirk_vialatency );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8371_1,       quirk_vialatency );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8361,         quirk_vialatency );
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8363_0,       quirk_vialatency);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8371_1,       quirk_vialatency);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8361,         quirk_vialatency);
 
 /*
  *     VIA Apollo VP3 needs ETBF on BT848/878
@@ -198,20 +196,20 @@ DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,       PCI_DEVICE_ID_VIA_8361,         quirk_viala
 static void __devinit quirk_viaetbf(struct pci_dev *dev)
 {
        if ((pci_pci_problems&PCIPCI_VIAETBF)==0) {
-               printk(KERN_INFO "Limiting direct PCI/PCI transfers.\n");
+               dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
                pci_pci_problems |= PCIPCI_VIAETBF;
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C597_0,     quirk_viaetbf );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C597_0,     quirk_viaetbf);
 
 static void __devinit quirk_vsfx(struct pci_dev *dev)
 {
        if ((pci_pci_problems&PCIPCI_VSFX)==0) {
-               printk(KERN_INFO "Limiting direct PCI/PCI transfers.\n");
+               dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
                pci_pci_problems |= PCIPCI_VSFX;
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C576,       quirk_vsfx );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C576,       quirk_vsfx);
 
 /*
  *     Ali Magik requires workarounds to be used by the drivers
@@ -222,12 +220,12 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,        PCI_DEVICE_ID_VIA_82C576,       quirk_vsfx
 static void __init quirk_alimagik(struct pci_dev *dev)
 {
        if ((pci_pci_problems&PCIPCI_ALIMAGIK)==0) {
-               printk(KERN_INFO "Limiting direct PCI/PCI transfers.\n");
+               dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
                pci_pci_problems |= PCIPCI_ALIMAGIK|PCIPCI_TRITON;
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M1647,         quirk_alimagik );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M1651,         quirk_alimagik );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M1647,         quirk_alimagik);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M1651,         quirk_alimagik);
 
 /*
  *     Natoma has some interesting boundary conditions with Zoran stuff
@@ -236,16 +234,16 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,         PCI_DEVICE_ID_AL_M1651,         quirk_alimag
 static void __devinit quirk_natoma(struct pci_dev *dev)
 {
        if ((pci_pci_problems&PCIPCI_NATOMA)==0) {
-               printk(KERN_INFO "Limiting direct PCI/PCI transfers.\n");
+               dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
                pci_pci_problems |= PCIPCI_NATOMA;
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82441,      quirk_natoma ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443LX_0,  quirk_natoma ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443LX_1,  quirk_natoma ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443BX_0,  quirk_natoma ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443BX_1,  quirk_natoma ); 
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443BX_2,  quirk_natoma );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82441,      quirk_natoma);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443LX_0,  quirk_natoma);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443LX_1,  quirk_natoma);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443BX_0,  quirk_natoma);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443BX_1,  quirk_natoma);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443BX_2,  quirk_natoma);
 
 /*
  *  This chip can cause PCI parity errors if config register 0xA0 is read
@@ -255,7 +253,7 @@ static void __devinit quirk_citrine(struct pci_dev *dev)
 {
        dev->cfg_size = 0xA0;
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM,    PCI_DEVICE_ID_IBM_CITRINE,      quirk_citrine );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM,    PCI_DEVICE_ID_IBM_CITRINE,      quirk_citrine);
 
 /*
  *  S3 868 and 968 chips report region size equal to 32M, but they decode 64M.
@@ -270,8 +268,8 @@ static void __devinit quirk_s3_64M(struct pci_dev *dev)
                r->end = 0x3ffffff;
        }
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3,     PCI_DEVICE_ID_S3_868,           quirk_s3_64M );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3,     PCI_DEVICE_ID_S3_968,           quirk_s3_64M );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3,     PCI_DEVICE_ID_S3_868,           quirk_s3_64M);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3,     PCI_DEVICE_ID_S3_968,           quirk_s3_64M);
 
 static void __devinit quirk_io_region(struct pci_dev *dev, unsigned region,
        unsigned size, int nr, const char *name)
@@ -292,7 +290,7 @@ static void __devinit quirk_io_region(struct pci_dev *dev, unsigned region,
                pcibios_bus_to_resource(dev, res, &bus_region);
 
                pci_claim_resource(dev, nr);
-               printk("PCI quirk: region %04x-%04x claimed by %s\n", region, region + size - 1, name);
+               dev_info(&dev->dev, "quirk: region %04x-%04x claimed by %s\n", region, region + size - 1, name);
        }
 }      
 
@@ -302,12 +300,12 @@ static void __devinit quirk_io_region(struct pci_dev *dev, unsigned region,
  */
 static void __devinit quirk_ati_exploding_mce(struct pci_dev *dev)
 {
-       printk(KERN_INFO "ATI Northbridge, reserving I/O ports 0x3b0 to 0x3bb.\n");
+       dev_info(&dev->dev, "ATI Northbridge, reserving I/O ports 0x3b0 to 0x3bb\n");
        /* Mae rhaid i ni beidio ag edrych ar y lleoliadiau I/O hyn */
        request_region(0x3b0, 0x0C, "RadeonIGP");
        request_region(0x3d3, 0x01, "RadeonIGP");
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI,     PCI_DEVICE_ID_ATI_RS100,   quirk_ati_exploding_mce );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI,     PCI_DEVICE_ID_ATI_RS100,   quirk_ati_exploding_mce);
 
 /*
  * Let's make the southbridge information explicit instead
@@ -329,7 +327,7 @@ static void __devinit quirk_ali7101_acpi(struct pci_dev *dev)
        pci_read_config_word(dev, 0xE2, &region);
        quirk_io_region(dev, region, 32, PCI_BRIDGE_RESOURCES+1, "ali7101 SMB");
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL,     PCI_DEVICE_ID_AL_M7101,         quirk_ali7101_acpi );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL,     PCI_DEVICE_ID_AL_M7101,         quirk_ali7101_acpi);
 
 static void piix4_io_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
 {
@@ -354,7 +352,7 @@ static void piix4_io_quirk(struct pci_dev *dev, const char *name, unsigned int p
         * let's get enough confirmation reports first. 
         */
        base &= -size;
-       printk("%s PIO at %04x-%04x\n", name, base, base + size - 1);
+       dev_info(&dev->dev, "%s PIO at %04x-%04x\n", name, base, base + size - 1);
 }
 
 static void piix4_mem_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
@@ -379,7 +377,7 @@ static void piix4_mem_quirk(struct pci_dev *dev, const char *name, unsigned int
         * reserve it, but let's get enough confirmation reports first. 
         */
        base &= -size;
-       printk("%s MMIO at %04x-%04x\n", name, base, base + size - 1);
+       dev_info(&dev->dev, "%s MMIO at %04x-%04x\n", name, base, base + size - 1);
 }
 
 /*
@@ -418,8 +416,8 @@ static void __devinit quirk_piix4_acpi(struct pci_dev *dev)
        piix4_io_quirk(dev, "PIIX4 devres I", 0x78, 1 << 20);
        piix4_io_quirk(dev, "PIIX4 devres J", 0x7c, 1 << 20);
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82371AB_3,  quirk_piix4_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82443MX_3,  quirk_piix4_acpi );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82371AB_3,  quirk_piix4_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82443MX_3,  quirk_piix4_acpi);
 
 /*
  * ICH4, ICH4-M, ICH5, ICH5-M ACPI: Three IO regions pointed to by longwords at
@@ -436,16 +434,16 @@ static void __devinit quirk_ich4_lpc_acpi(struct pci_dev *dev)
        pci_read_config_dword(dev, 0x58, &region);
        quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES+1, "ICH4 GPIO");
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801AA_0,                quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801AB_0,                quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801BA_0,                quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801BA_10,       quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801CA_0,                quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801CA_12,       quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801DB_0,                quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801DB_12,       quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801EB_0,                quirk_ich4_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ESB_1,            quirk_ich4_lpc_acpi );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801AA_0,                quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801AB_0,                quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801BA_0,                quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801BA_10,       quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801CA_0,                quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801CA_12,       quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801DB_0,                quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801DB_12,       quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801EB_0,                quirk_ich4_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ESB_1,            quirk_ich4_lpc_acpi);
 
 static void __devinit quirk_ich6_lpc_acpi(struct pci_dev *dev)
 {
@@ -457,20 +455,20 @@ static void __devinit quirk_ich6_lpc_acpi(struct pci_dev *dev)
        pci_read_config_dword(dev, 0x48, &region);
        quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES+1, "ICH6 GPIO");
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH7_0, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH7_1, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH7_31, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_0, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_2, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_3, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_1, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_4, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_2, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_4, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_7, quirk_ich6_lpc_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_8, quirk_ich6_lpc_acpi );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH7_0, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH7_1, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH7_31, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_0, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_2, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_3, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_1, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH8_4, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_2, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_4, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_7, quirk_ich6_lpc_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH9_8, quirk_ich6_lpc_acpi);
 
 /*
  * VIA ACPI: One IO region pointed to by longword at
@@ -486,7 +484,7 @@ static void __devinit quirk_vt82c586_acpi(struct pci_dev *dev)
                quirk_io_region(dev, region, 256, PCI_BRIDGE_RESOURCES, "vt82c586 ACPI");
        }
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C586_3,     quirk_vt82c586_acpi );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C586_3,     quirk_vt82c586_acpi);
 
 /*
  * VIA VT82C686 ACPI: Three IO region pointed to by (long)words at
@@ -509,7 +507,7 @@ static void __devinit quirk_vt82c686_acpi(struct pci_dev *dev)
        smb &= PCI_BASE_ADDRESS_IO_MASK;
        quirk_io_region(dev, smb, 16, PCI_BRIDGE_RESOURCES + 2, "vt82c686 SMB");
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C686_4,     quirk_vt82c686_acpi );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C686_4,     quirk_vt82c686_acpi);
 
 /*
  * VIA VT8235 ISA Bridge: Two IO regions pointed to by words at
@@ -551,14 +549,14 @@ static void quirk_via_ioapic(struct pci_dev *dev)
        else
                tmp = 0x1f; /* all known bits (4-0) routed to external APIC */
                
-       printk(KERN_INFO "PCI: %sbling Via external APIC routing\n",
+       dev_info(&dev->dev, "%sbling VIA external APIC routing\n",
               tmp == 0 ? "Disa" : "Ena");
 
        /* Offset 0x58: External APIC IRQ output control */
        pci_write_config_byte (dev, 0x58, tmp);
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C686,       quirk_via_ioapic );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C686,       quirk_via_ioapic );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C686,       quirk_via_ioapic);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C686,       quirk_via_ioapic);
 
 /*
  * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit.
@@ -573,7 +571,7 @@ static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
 
        pci_read_config_byte(dev, 0x5B, &misc_control2);
        if (!(misc_control2 & BYPASS_APIC_DEASSERT)) {
-               printk(KERN_INFO "PCI: Bypassing VIA 8237 APIC De-Assert Message\n");
+               dev_info(&dev->dev, "Bypassing VIA 8237 APIC De-Assert Message\n");
                pci_write_config_byte(dev, 0x5B, misc_control2|BYPASS_APIC_DEASSERT);
        }
 }
@@ -592,18 +590,18 @@ DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,       PCI_DEVICE_ID_VIA_8237,         quirk_via_v
 static void __devinit quirk_amd_ioapic(struct pci_dev *dev)
 {
        if (dev->revision >= 0x02) {
-               printk(KERN_WARNING "I/O APIC: AMD Erratum #22 may be present. In the event of instability try\n");
-               printk(KERN_WARNING "        : booting with the \"noapic\" option.\n");
+               dev_warn(&dev->dev, "I/O APIC: AMD Erratum #22 may be present. In the event of instability try\n");
+               dev_warn(&dev->dev, "        : booting with the \"noapic\" option\n");
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_VIPER_7410,   quirk_amd_ioapic );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_VIPER_7410,   quirk_amd_ioapic);
 
 static void __init quirk_ioapic_rmw(struct pci_dev *dev)
 {
        if (dev->devfn == 0 && dev->bus->number == 0)
                sis_apic_bug = 1;
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,      PCI_ANY_ID,                     quirk_ioapic_rmw );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,      PCI_ANY_ID,                     quirk_ioapic_rmw);
 
 #define AMD8131_revA0        0x01
 #define AMD8131_revB0        0x11
@@ -617,7 +615,7 @@ static void quirk_amd_8131_ioapic(struct pci_dev *dev)
                 return;
 
         if (dev->revision == AMD8131_revA0 || dev->revision == AMD8131_revB0) {
-                printk(KERN_INFO "Fixing up AMD8131 IOAPIC mode\n"); 
+                dev_info(&dev->dev, "Fixing up AMD8131 IOAPIC mode\n");
                 pci_read_config_byte( dev, AMD8131_MISC, &tmp);
                 tmp &= ~(1 << AMD8131_NIOAMODE_BIT);
                 pci_write_config_byte( dev, AMD8131_MISC, tmp);
@@ -634,8 +632,8 @@ DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk
 static void __init quirk_amd_8131_mmrbc(struct pci_dev *dev)
 {
        if (dev->subordinate && dev->revision <= 0x12) {
-               printk(KERN_INFO "AMD8131 rev %x detected, disabling PCI-X "
-                               "MMRBC\n", dev->revision);
+               dev_info(&dev->dev, "AMD8131 rev %x detected; "
+                       "disabling PCI-X MMRBC\n", dev->revision);
                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MMRBC;
        }
 }
@@ -660,8 +658,8 @@ static void __devinit quirk_via_acpi(struct pci_dev *d)
        if (irq && (irq != 2))
                d->irq = irq;
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C586_3,     quirk_via_acpi );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C686_4,     quirk_via_acpi );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C586_3,     quirk_via_acpi);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C686_4,     quirk_via_acpi);
 
 
 /*
@@ -742,8 +740,8 @@ static void quirk_via_vlink(struct pci_dev *dev)
 
        pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
        if (new_irq != irq) {
-               printk(KERN_INFO "PCI: VIA VLink IRQ fixup for %s, from %d to %d\n",
-                       pci_name(dev), irq, new_irq);
+               dev_info(&dev->dev, "VIA VLink IRQ fixup, from %d to %d\n",
+                       irq, new_irq);
                udelay(15);     /* unknown if delay really needed */
                pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
        }
@@ -761,7 +759,7 @@ static void __devinit quirk_vt82c598_id(struct pci_dev *dev)
        pci_write_config_byte(dev, 0xfc, 0);
        pci_read_config_word(dev, PCI_DEVICE_ID, &dev->device);
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C597_0,     quirk_vt82c598_id );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C597_0,     quirk_vt82c598_id);
 
 /*
  * CardBus controllers have a legacy base address that enables them
@@ -791,15 +789,15 @@ static void quirk_amd_ordering(struct pci_dev *dev)
        pci_read_config_dword(dev, 0x4C, &pcic);
        if ((pcic&6)!=6) {
                pcic |= 6;
-               printk(KERN_WARNING "BIOS failed to enable PCI standards compliance, fixing this error.\n");
+               dev_warn(&dev->dev, "BIOS failed to enable PCI standards compliance; fixing this error\n");
                pci_write_config_dword(dev, 0x4C, pcic);
                pci_read_config_dword(dev, 0x84, &pcic);
                pcic |= (1<<23);        /* Required in this mode */
                pci_write_config_dword(dev, 0x84, pcic);
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD,    PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD,    PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
 
 /*
  *     DreamWorks provided workaround for Dunord I-3000 problem
@@ -814,7 +812,7 @@ static void __devinit quirk_dunord ( struct pci_dev * dev )
        r->start = 0;
        r->end = 0xffffff;
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DUNORD, PCI_DEVICE_ID_DUNORD_I3000,     quirk_dunord );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DUNORD, PCI_DEVICE_ID_DUNORD_I3000,     quirk_dunord);
 
 /*
  * i82380FB mobile docking controller: its PCI-to-PCI bridge
@@ -826,8 +824,8 @@ static void __devinit quirk_transparent_bridge(struct pci_dev *dev)
 {
        dev->transparent = 1;
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82380FB,    quirk_transparent_bridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA,        0x605,  quirk_transparent_bridge );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82380FB,    quirk_transparent_bridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA,        0x605,  quirk_transparent_bridge);
 
 /*
  * Common misconfiguration of the MediaGX/Geode PCI master that will
@@ -841,12 +839,12 @@ static void quirk_mediagx_master(struct pci_dev *dev)
        pci_read_config_byte(dev, 0x41, &reg);
        if (reg & 2) {
                reg &= ~2;
-               printk(KERN_INFO "PCI: Fixup for MediaGX/Geode Slave Disconnect Boundary (0x41=0x%02x)\n", reg);
+               dev_info(&dev->dev, "Fixup for MediaGX/Geode Slave Disconnect Boundary (0x41=0x%02x)\n", reg);
                 pci_write_config_byte(dev, 0x41, reg);
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX,   PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX,  PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX,   PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX,  PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
 
 /*
  *     Ensure C0 rev restreaming is off. This is normally done by
@@ -863,11 +861,11 @@ static void quirk_disable_pxb(struct pci_dev *pdev)
        if (config & (1<<6)) {
                config &= ~(1<<6);
                pci_write_config_word(pdev, 0x40, config);
-               printk(KERN_INFO "PCI: C0 revision 450NX. Disabling PCI restreaming.\n");
+               dev_info(&pdev->dev, "C0 revision 450NX. Disabling PCI restreaming\n");
        }
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82454NX,    quirk_disable_pxb );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82454NX,    quirk_disable_pxb );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82454NX,    quirk_disable_pxb);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82454NX,    quirk_disable_pxb);
 
 
 static void __devinit quirk_sb600_sata(struct pci_dev *pdev)
@@ -902,7 +900,7 @@ static void __devinit quirk_svwks_csb5ide(struct pci_dev *pdev)
                /* PCI layer will sort out resources */
        }
 }
-DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, quirk_svwks_csb5ide );
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, quirk_svwks_csb5ide);
 
 /*
  *     Intel 82801CAM ICH3-M datasheet says IDE modes must be the same
@@ -914,7 +912,7 @@ static void __init quirk_ide_samemode(struct pci_dev *pdev)
        pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
 
        if (((prog & 1) && !(prog & 4)) || ((prog & 4) && !(prog & 1))) {
-               printk(KERN_INFO "PCI: IDE mode mismatch; forcing legacy mode\n");
+               dev_info(&pdev->dev, "IDE mode mismatch; forcing legacy mode\n");
                prog &= ~5;
                pdev->class &= ~5;
                pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
@@ -929,7 +927,7 @@ static void __init quirk_eisa_bridge(struct pci_dev *dev)
 {
        dev->class = PCI_CLASS_BRIDGE_EISA << 8;
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82375,      quirk_eisa_bridge );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82375,      quirk_eisa_bridge);
 
 
 /*
@@ -1022,6 +1020,11 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
                        case 0x12bd: /* HP D530 */
                                asus_hides_smbus = 1;
                        }
+               else if (dev->device == PCI_DEVICE_ID_INTEL_82875_HB)
+                       switch (dev->subsystem_device) {
+                       case 0x12bf: /* HP xw4100 */
+                               asus_hides_smbus = 1;
+                       }
                else if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB)
                        switch (dev->subsystem_device) {
                        case 0x099c: /* HP Compaq nx6110 */
@@ -1049,17 +1052,18 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
                        }
        }
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82845_HB,   asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82845G_HB,  asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82850_HB,   asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82865_HB,   asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_7205_0,     asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_E7501_MCH,  asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82845_HB,   asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82845G_HB,  asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82850_HB,   asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82865_HB,   asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82875_HB,   asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_7205_0,     asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_E7501_MCH,  asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge);
 
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82810_IG3,  asus_hides_smbus_hostbridge );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82810_IG3,  asus_hides_smbus_hostbridge);
 
 static void asus_hides_smbus_lpc(struct pci_dev *dev)
 {
@@ -1073,25 +1077,25 @@ static void asus_hides_smbus_lpc(struct pci_dev *dev)
                pci_write_config_word(dev, 0xF2, val & (~0x8));
                pci_read_config_word(dev, 0xF2, &val);
                if (val & 0x8)
-                       printk(KERN_INFO "PCI: i801 SMBus device continues to play 'hide and seek'! 0x%x\n", val);
+                       dev_info(&dev->dev, "i801 SMBus device continues to play 'hide and seek'! 0x%x\n", val);
                else
-                       printk(KERN_INFO "PCI: Enabled i801 SMBus device\n");
+                       dev_info(&dev->dev, "Enabled i801 SMBus device\n");
        }
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801AA_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801BA_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801EB_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801AA_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801BA_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_0,  asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801EB_0,  asus_hides_smbus_lpc );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801AA_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801BA_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801EB_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801AA_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801BA_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_0,  asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_82801EB_0,  asus_hides_smbus_lpc);
 
 static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
 {
@@ -1106,10 +1110,10 @@ static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
        val=readl(base + 0x3418); /* read the Function Disable register, dword mode only */
        writel(val & 0xFFFFFFF7, base + 0x3418); /* enable the SMBus device */
        iounmap(base);
-       printk(KERN_INFO "PCI: Enabled ICH6/i801 SMBus device\n");
+       dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n");
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6 );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6 );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6);
 
 /*
  * SiS 96x south bridge: BIOS typically hides SMBus device...
@@ -1119,18 +1123,18 @@ static void quirk_sis_96x_smbus(struct pci_dev *dev)
        u8 val = 0;
        pci_read_config_byte(dev, 0x77, &val);
        if (val & 0x10) {
-               printk(KERN_INFO "Enabling SiS 96x SMBus.\n");
+               dev_info(&dev->dev, "Enabling SiS 96x SMBus\n");
                pci_write_config_byte(dev, 0x77, val & ~0x10);
        }
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_961,           quirk_sis_96x_smbus );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_962,           quirk_sis_96x_smbus );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_963,           quirk_sis_96x_smbus );
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_LPC,           quirk_sis_96x_smbus );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_961,           quirk_sis_96x_smbus );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_962,           quirk_sis_96x_smbus );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_963,           quirk_sis_96x_smbus );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_LPC,           quirk_sis_96x_smbus );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_961,           quirk_sis_96x_smbus);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_962,           quirk_sis_96x_smbus);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_963,           quirk_sis_96x_smbus);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_LPC,           quirk_sis_96x_smbus);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_961,           quirk_sis_96x_smbus);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_962,           quirk_sis_96x_smbus);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_963,           quirk_sis_96x_smbus);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_LPC,           quirk_sis_96x_smbus);
 
 /*
  * ... This is further complicated by the fact that some SiS96x south
@@ -1163,8 +1167,8 @@ static void quirk_sis_503(struct pci_dev *dev)
        dev->device = devid;
        quirk_sis_96x_smbus(dev);
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_503,           quirk_sis_503 );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_503,           quirk_sis_503 );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_503,           quirk_sis_503);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI,     PCI_DEVICE_ID_SI_503,           quirk_sis_503);
 
 
 /*
@@ -1191,13 +1195,13 @@ static void asus_hides_ac97_lpc(struct pci_dev *dev)
                pci_write_config_byte(dev, 0x50, val & (~0xc0));
                pci_read_config_byte(dev, 0x50, &val);
                if (val & 0xc0)
-                       printk(KERN_INFO "PCI: onboard AC97/MC97 devices continue to play 'hide and seek'! 0x%x\n", val);
+                       dev_info(&dev->dev, "Onboard AC97/MC97 devices continue to play 'hide and seek'! 0x%x\n", val);
                else
-                       printk(KERN_INFO "PCI: enabled onboard AC97/MC97 devices\n");
+                       dev_info(&dev->dev, "Enabled onboard AC97/MC97 devices\n");
        }
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc );
-DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
+DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
 
 #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
 
@@ -1292,7 +1296,7 @@ static void __init quirk_alder_ioapic(struct pci_dev *pdev)
        }
 
 }
-DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_EESSC,      quirk_alder_ioapic );
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_EESSC,      quirk_alder_ioapic);
 #endif
 
 int pcie_mch_quirk;
@@ -1302,9 +1306,9 @@ static void __devinit quirk_pcie_mch(struct pci_dev *pdev)
 {
        pcie_mch_quirk = 1;
 }
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_E7520_MCH,  quirk_pcie_mch );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_E7320_MCH,  quirk_pcie_mch );
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_E7525_MCH,  quirk_pcie_mch );
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_E7520_MCH,  quirk_pcie_mch);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_E7320_MCH,  quirk_pcie_mch);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_E7525_MCH,  quirk_pcie_mch);
 
 
 /*
@@ -1314,11 +1318,8 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_E7525_MCH,  quir
 static void __devinit quirk_pcie_pxh(struct pci_dev *dev)
 {
        pci_msi_off(dev);
-
        dev->no_msi = 1;
-
-       printk(KERN_WARNING "PCI: PXH quirk detected, "
-               "disabling MSI for SHPC device\n");
+       dev_warn(&dev->dev, "PXH quirk detected; SHPC device MSI disabled\n");
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_PXHD_0,     quirk_pcie_pxh);
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_PXHD_1,     quirk_pcie_pxh);
@@ -1399,7 +1400,7 @@ static void __devinit quirk_netmos(struct pci_dev *dev)
        case PCI_DEVICE_ID_NETMOS_9855:
                if ((dev->class >> 8) == PCI_CLASS_COMMUNICATION_SERIAL &&
                    num_parallel) {
-                       printk(KERN_INFO "PCI: Netmos %04x (%u parallel, "
+                       dev_info(&dev->dev, "Netmos %04x (%u parallel, "
                                "%u serial); changing class SERIAL to OTHER "
                                "(use parport_serial)\n",
                                dev->device, num_parallel, num_serial);
@@ -1412,9 +1413,10 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETMOS, PCI_ANY_ID, quirk_netmos);
 
 static void __devinit quirk_e100_interrupt(struct pci_dev *dev)
 {
-       u16 command;
+       u16 command, pmcsr;
        u8 __iomem *csr;
        u8 cmd_hi;
+       int pm;
 
        switch (dev->device) {
        /* PCI IDs taken from drivers/net/e100.c */
@@ -1448,18 +1450,28 @@ static void __devinit quirk_e100_interrupt(struct pci_dev *dev)
        if (!(command & PCI_COMMAND_MEMORY) || !pci_resource_start(dev, 0))
                return;
 
+       /*
+        * Check that the device is in the D0 power state. If it's not,
+        * there is no point to look any further.
+        */
+       pm = pci_find_capability(dev, PCI_CAP_ID_PM);
+       if (pm) {
+               pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
+               if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0)
+                       return;
+       }
+
        /* Convert from PCI bus to resource space.  */
        csr = ioremap(pci_resource_start(dev, 0), 8);
        if (!csr) {
-               printk(KERN_WARNING "PCI: Can't map %s e100 registers\n",
-                       pci_name(dev));
+               dev_warn(&dev->dev, "Can't map e100 registers\n");
                return;
        }
 
        cmd_hi = readb(csr + 3);
        if (cmd_hi == 0) {
-               printk(KERN_WARNING "PCI: Firmware left %s e100 interrupts "
-                       "enabled, disabling\n", pci_name(dev));
+               dev_warn(&dev->dev, "Firmware left e100 interrupts enabled; "
+                       "disabling\n");
                writeb(1, csr + 3);
        }
 
@@ -1474,7 +1486,7 @@ static void __devinit fixup_rev1_53c810(struct pci_dev* dev)
         */
 
        if (dev->class == PCI_CLASS_NOT_DEFINED) {
-               printk(KERN_INFO "NCR 53c810 rev 1 detected, setting PCI class.\n");
+               dev_info(&dev->dev, "NCR 53c810 rev 1 detected; setting PCI class\n");
                dev->class = PCI_CLASS_STORAGE_SCSI;
        }
 }
@@ -1485,7 +1497,11 @@ static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, struct pci_f
        while (f < end) {
                if ((f->vendor == dev->vendor || f->vendor == (u16) PCI_ANY_ID) &&
                    (f->device == dev->device || f->device == (u16) PCI_ANY_ID)) {
-                       pr_debug("PCI: Calling quirk %p for %s\n", f->hook, pci_name(dev));
+#ifdef DEBUG
+                       dev_dbg(&dev->dev, "calling quirk 0x%p", f->hook);
+                       print_fn_descriptor_symbol(": %s()\n",
+                               (unsigned long) f->hook);
+#endif
                        f->hook(dev);
                }
                f++;
@@ -1553,7 +1569,7 @@ static void __devinit quirk_p64h2_1k_io(struct pci_dev *dev)
        pci_read_config_word(dev, 0x40, &en1k);
 
        if (en1k & 0x200) {
-               printk(KERN_INFO "PCI: Enable I/O Space to 1 KB Granularity\n");
+               dev_info(&dev->dev, "Enable I/O Space to 1KB granularity\n");
 
                pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo);
                pci_read_config_byte(dev, PCI_IO_LIMIT, &io_limit_lo);
@@ -1585,7 +1601,7 @@ static void __devinit quirk_p64h2_1k_io_fix_iobl(struct pci_dev *dev)
                iobl_adr_1k = iobl_adr | (res->start >> 8) | (res->end & 0xfc00);
 
                if (iobl_adr != iobl_adr_1k) {
-                       printk(KERN_INFO "PCI: Fixing P64H2 IOBL_ADR from 0x%x to 0x%x for 1 KB Granularity\n",
+                       dev_info(&dev->dev, "Fixing P64H2 IOBL_ADR from 0x%x to 0x%x for 1KB granularity\n",
                                iobl_adr,iobl_adr_1k);
                        pci_write_config_word(dev, PCI_IO_BASE, iobl_adr_1k);
                }
@@ -1603,9 +1619,8 @@ static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
        if (pci_read_config_byte(dev, 0xf41, &b) == 0) {
                if (!(b & 0x20)) {
                        pci_write_config_byte(dev, 0xf41, b | 0x20);
-                       printk(KERN_INFO
-                              "PCI: Linking AER extended capability on %s\n",
-                              pci_name(dev));
+                       dev_info(&dev->dev,
+                              "Linking AER extended capability\n");
                }
        }
 }
@@ -1614,6 +1629,34 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA,  PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
 DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA,  PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
                        quirk_nvidia_ck804_pcie_aer_ext_cap);
 
+static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
+{
+       /*
+        * Disable PCI Bus Parking and PCI Master read caching on CX700
+        * which causes unspecified timing errors with a VT6212L on the PCI
+        * bus leading to USB2.0 packet loss. The defaults are that these
+        * features are turned off but some BIOSes turn them on.
+        */
+
+       uint8_t b;
+       if (pci_read_config_byte(dev, 0x76, &b) == 0) {
+               if (b & 0x40) {
+                       /* Turn off PCI Bus Parking */
+                       pci_write_config_byte(dev, 0x76, b ^ 0x40);
+
+                       /* Turn off PCI Master read caching */
+                       pci_write_config_byte(dev, 0x72, 0x0);
+                       pci_write_config_byte(dev, 0x75, 0x1);
+                       pci_write_config_byte(dev, 0x77, 0x0);
+
+                       printk(KERN_INFO
+                               "PCI: VIA CX700 PCI parking/caching fixup on %s\n",
+                               pci_name(dev));
+               }
+       }
+}
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_VIA, 0x324e, quirk_via_cx700_pci_parking_caching);
+
 #ifdef CONFIG_PCI_MSI
 /* Some chipsets do not support MSI. We cannot easily rely on setting
  * PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually
@@ -1624,7 +1667,7 @@ DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA,  PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
 static void __init quirk_disable_all_msi(struct pci_dev *dev)
 {
        pci_no_msi();
-       printk(KERN_WARNING "PCI: MSI quirk detected. MSI deactivated.\n");
+       dev_warn(&dev->dev, "MSI quirk detected; MSI disabled\n");
 }
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_disable_all_msi);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS400_200, quirk_disable_all_msi);
@@ -1635,9 +1678,8 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3351, quirk_disab
 static void __devinit quirk_disable_msi(struct pci_dev *dev)
 {
        if (dev->subordinate) {
-               printk(KERN_WARNING "PCI: MSI quirk detected. "
-                      "PCI_BUS_FLAGS_NO_MSI set for %s subordinate bus.\n",
-                      pci_name(dev));
+               dev_warn(&dev->dev, "MSI quirk detected; "
+                       "subordinate MSI disabled\n");
                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
        }
 }
@@ -1656,9 +1698,9 @@ static int __devinit msi_ht_cap_enabled(struct pci_dev *dev)
                if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
                                         &flags) == 0)
                {
-                       printk(KERN_INFO "PCI: Found %s HT MSI Mapping on %s\n",
+                       dev_info(&dev->dev, "Found %s HT MSI Mapping\n",
                                flags & HT_MSI_FLAGS_ENABLE ?
-                               "enabled" : "disabled", pci_name(dev));
+                               "enabled" : "disabled");
                        return (flags & HT_MSI_FLAGS_ENABLE) != 0;
                }
 
@@ -1672,17 +1714,40 @@ static int __devinit msi_ht_cap_enabled(struct pci_dev *dev)
 static void __devinit quirk_msi_ht_cap(struct pci_dev *dev)
 {
        if (dev->subordinate && !msi_ht_cap_enabled(dev)) {
-               printk(KERN_WARNING "PCI: MSI quirk detected. "
-                      "MSI disabled on chipset %s.\n",
-                      pci_name(dev));
+               dev_warn(&dev->dev, "MSI quirk detected; "
+                       "subordinate MSI disabled\n");
                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
        }
 }
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT2000_PCIE,
                        quirk_msi_ht_cap);
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS,
-                       PCI_DEVICE_ID_SERVERWORKS_HT1000_PXB,
-                       quirk_msi_ht_cap);
+
+
+/*
+ *  Force enable MSI mapping capability on HT bridges
+ */
+static void __devinit quirk_msi_ht_cap_enable(struct pci_dev *dev)
+{
+       int pos, ttl = 48;
+
+       pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
+       while (pos && ttl--) {
+               u8 flags;
+
+               if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS, &flags) == 0) {
+                       printk(KERN_INFO "PCI: Enabling HT MSI Mapping on %s\n",
+                              pci_name(dev));
+
+                       pci_write_config_byte(dev, pos + HT_MSI_FLAGS,
+                                             flags | HT_MSI_FLAGS_ENABLE);
+               }
+               pos = pci_find_next_ht_capability(dev, pos,
+                                                 HT_CAPTYPE_MSI_MAPPING);
+       }
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS,
+                        PCI_DEVICE_ID_SERVERWORKS_HT1000_PXB,
+                        quirk_msi_ht_cap_enable);
 
 /* The nVidia CK804 chipset may have 2 HT MSI mappings.
  * MSI are supported if the MSI capability set in any of these mappings.
@@ -1701,9 +1766,8 @@ static void __devinit quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
        if (!pdev)
                return;
        if (!msi_ht_cap_enabled(dev) && !msi_ht_cap_enabled(pdev)) {
-               printk(KERN_WARNING "PCI: MSI quirk detected. "
-                      "MSI disabled on chipset %s.\n",
-                      pci_name(dev));
+               dev_warn(&dev->dev, "MSI quirk detected; "
+                       "subordinate MSI disabled\n");
                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
        }
        pci_dev_put(pdev);
@@ -1715,6 +1779,23 @@ static void __devinit quirk_msi_intx_disable_bug(struct pci_dev *dev)
 {
        dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
 }
+static void __devinit quirk_msi_intx_disable_ati_bug(struct pci_dev *dev)
+{
+       struct pci_dev *p;
+
+       /* SB700 MSI issue will be fixed at HW level from revision A21,
+        * we need check PCI REVISION ID of SMBus controller to get SB700
+        * revision.
+        */
+       p = pci_get_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
+                          NULL);
+       if (!p)
+               return;
+
+       if ((p->revision < 0x3B) && (p->revision >= 0x30))
+               dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
+       pci_dev_put(p);
+}
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
                        PCI_DEVICE_ID_TIGON3_5780,
                        quirk_msi_intx_disable_bug);
@@ -1735,17 +1816,15 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
                        quirk_msi_intx_disable_bug);
 
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4390,
-                       quirk_msi_intx_disable_bug);
+                       quirk_msi_intx_disable_ati_bug);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4391,
-                       quirk_msi_intx_disable_bug);
+                       quirk_msi_intx_disable_ati_bug);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4392,
-                       quirk_msi_intx_disable_bug);
+                       quirk_msi_intx_disable_ati_bug);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4393,
-                       quirk_msi_intx_disable_bug);
+                       quirk_msi_intx_disable_ati_bug);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4394,
-                       quirk_msi_intx_disable_bug);
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4395,
-                       quirk_msi_intx_disable_bug);
+                       quirk_msi_intx_disable_ati_bug);
 
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4373,
                        quirk_msi_intx_disable_bug);
index 430281b2e9212400af4b8bf3dd9aa1fa72c41855..9684e1bde277a1e012fae641363178f394071323 100644 (file)
@@ -74,10 +74,8 @@ void pci_remove_bus(struct pci_bus *pci_bus)
        list_del(&pci_bus->node);
        up_write(&pci_bus_sem);
        pci_remove_legacy_files(pci_bus);
-       class_device_remove_file(&pci_bus->class_dev,
-               &class_device_attr_cpuaffinity);
-       sysfs_remove_link(&pci_bus->class_dev.kobj, "bridge");
-       class_device_unregister(&pci_bus->class_dev);
+       device_remove_file(&pci_bus->dev, &dev_attr_cpuaffinity);
+       device_unregister(&pci_bus->dev);
 }
 EXPORT_SYMBOL(pci_remove_bus);
 
index dbbcc04abd1af1fe06eafc7be1a647d847233e25..a98b2470b9ea5f85b95a3ae3c9da79aeafb29363 100644 (file)
@@ -162,6 +162,7 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
        return rom;
 }
 
+#if 0
 /**
  * pci_map_rom_copy - map a PCI ROM to kernel space, create a copy
  * @pdev: pointer to pci device struct
@@ -196,6 +197,7 @@ void __iomem *pci_map_rom_copy(struct pci_dev *pdev, size_t *size)
 
        return (void __iomem *)(unsigned long)res->start;
 }
+#endif  /*  0  */
 
 /**
  * pci_unmap_rom - unmap the ROM from kernel space
@@ -218,6 +220,7 @@ void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom)
                pci_disable_rom(pdev);
 }
 
+#if 0
 /**
  * pci_remove_rom - disable the ROM and remove its sysfs attribute
  * @pdev: pointer to pci device struct
@@ -236,6 +239,7 @@ void pci_remove_rom(struct pci_dev *pdev)
                            IORESOURCE_ROM_COPY)))
                pci_disable_rom(pdev);
 }
+#endif  /*  0  */
 
 /**
  * pci_cleanup_rom - internal routine for freeing the ROM copy created
@@ -256,6 +260,4 @@ void pci_cleanup_rom(struct pci_dev *pdev)
 }
 
 EXPORT_SYMBOL(pci_map_rom);
-EXPORT_SYMBOL(pci_map_rom_copy);
 EXPORT_SYMBOL(pci_unmap_rom);
-EXPORT_SYMBOL(pci_remove_rom);
index 401e03c920bdf034c3849ea01c03d6a5adc8fabc..262b0439abe9e41a476629d9ac35927f2491620f 100644 (file)
@@ -89,8 +89,9 @@ void pci_setup_cardbus(struct pci_bus *bus)
                 * The IO resource is allocated a range twice as large as it
                 * would normally need.  This allows us to set both IO regs.
                 */
-               printk("  IO window: %08lx-%08lx\n",
-                       region.start, region.end);
+               printk(KERN_INFO "  IO window: 0x%08lx-0x%08lx\n",
+                      (unsigned long)region.start,
+                      (unsigned long)region.end);
                pci_write_config_dword(bridge, PCI_CB_IO_BASE_0,
                                        region.start);
                pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_0,
@@ -99,8 +100,9 @@ void pci_setup_cardbus(struct pci_bus *bus)
 
        pcibios_resource_to_bus(bridge, &region, bus->resource[1]);
        if (bus->resource[1]->flags & IORESOURCE_IO) {
-               printk("  IO window: %08lx-%08lx\n",
-                       region.start, region.end);
+               printk(KERN_INFO "  IO window: 0x%08lx-0x%08lx\n",
+                      (unsigned long)region.start,
+                      (unsigned long)region.end);
                pci_write_config_dword(bridge, PCI_CB_IO_BASE_1,
                                        region.start);
                pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_1,
@@ -109,8 +111,9 @@ void pci_setup_cardbus(struct pci_bus *bus)
 
        pcibios_resource_to_bus(bridge, &region, bus->resource[2]);
        if (bus->resource[2]->flags & IORESOURCE_MEM) {
-               printk("  PREFETCH window: %08lx-%08lx\n",
-                       region.start, region.end);
+               printk(KERN_INFO "  PREFETCH window: 0x%08lx-0x%08lx\n",
+                      (unsigned long)region.start,
+                      (unsigned long)region.end);
                pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0,
                                        region.start);
                pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_0,
@@ -119,8 +122,9 @@ void pci_setup_cardbus(struct pci_bus *bus)
 
        pcibios_resource_to_bus(bridge, &region, bus->resource[3]);
        if (bus->resource[3]->flags & IORESOURCE_MEM) {
-               printk("  MEM window: %08lx-%08lx\n",
-                       region.start, region.end);
+               printk(KERN_INFO "  MEM window: 0x%08lx-0x%08lx\n",
+                      (unsigned long)region.start,
+                      (unsigned long)region.end);
                pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1,
                                        region.start);
                pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_1,
@@ -145,7 +149,7 @@ pci_setup_bridge(struct pci_bus *bus)
 {
        struct pci_dev *bridge = bus->self;
        struct pci_bus_region region;
-       u32 l, io_upper16;
+       u32 l, bu, lu, io_upper16;
 
        DBG(KERN_INFO "PCI: Bridge: %s\n", pci_name(bridge));
 
@@ -159,7 +163,8 @@ pci_setup_bridge(struct pci_bus *bus)
                /* Set up upper 16 bits of I/O base/limit. */
                io_upper16 = (region.end & 0xffff0000) | (region.start >> 16);
                DBG(KERN_INFO "  IO window: %04lx-%04lx\n",
-                               region.start, region.end);
+                   (unsigned long)region.start,
+                   (unsigned long)region.end);
        }
        else {
                /* Clear upper 16 bits of I/O base/limit. */
@@ -180,8 +185,9 @@ pci_setup_bridge(struct pci_bus *bus)
        if (bus->resource[1]->flags & IORESOURCE_MEM) {
                l = (region.start >> 16) & 0xfff0;
                l |= region.end & 0xfff00000;
-               DBG(KERN_INFO "  MEM window: %08lx-%08lx\n",
-                               region.start, region.end);
+               DBG(KERN_INFO "  MEM window: 0x%08lx-0x%08lx\n",
+                   (unsigned long)region.start,
+                   (unsigned long)region.end);
        }
        else {
                l = 0x0000fff0;
@@ -195,12 +201,18 @@ pci_setup_bridge(struct pci_bus *bus)
        pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, 0);
 
        /* Set up PREF base/limit. */
+       bu = lu = 0;
        pcibios_resource_to_bus(bridge, &region, bus->resource[2]);
        if (bus->resource[2]->flags & IORESOURCE_PREFETCH) {
                l = (region.start >> 16) & 0xfff0;
                l |= region.end & 0xfff00000;
-               DBG(KERN_INFO "  PREFETCH window: %08lx-%08lx\n",
-                               region.start, region.end);
+#ifdef CONFIG_RESOURCES_64BIT
+               bu = region.start >> 32;
+               lu = region.end >> 32;
+#endif
+               DBG(KERN_INFO "  PREFETCH window: 0x%016llx-0x%016llx\n",
+                   (unsigned long long)region.start,
+                   (unsigned long long)region.end);
        }
        else {
                l = 0x0000fff0;
@@ -208,8 +220,9 @@ pci_setup_bridge(struct pci_bus *bus)
        }
        pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l);
 
-       /* Clear out the upper 32 bits of PREF base. */
-       pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, 0);
+       /* Set the upper 32 bits of PREF base & limit. */
+       pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu);
+       pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu);
 
        pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
 }
@@ -323,8 +336,8 @@ static void pbus_size_io(struct pci_bus *bus)
 static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long type)
 {
        struct pci_dev *dev;
-       unsigned long min_align, align, size;
-       unsigned long aligns[12];       /* Alignments from 1Mb to 2Gb */
+       resource_size_t min_align, align, size;
+       resource_size_t aligns[12];     /* Alignments from 1Mb to 2Gb */
        int order, max_order;
        struct resource *b_res = find_free_bus_resource(bus, type);
 
@@ -340,7 +353,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long
                
                for (i = 0; i < PCI_NUM_RESOURCES; i++) {
                        struct resource *r = &dev->resource[i];
-                       unsigned long r_size;
+                       resource_size_t r_size;
 
                        if (r->parent || (r->flags & mask) != type)
                                continue;
@@ -350,10 +363,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long
                        order = __ffs(align) - 20;
                        if (order > 11) {
                                printk(KERN_WARNING "PCI: region %s/%d "
-                                      "too large: %llx-%llx\n",
+                                      "too large: 0x%016llx-0x%016llx\n",
                                        pci_name(dev), i,
-                                       (unsigned long long)r->start,
-                                       (unsigned long long)r->end);
+                                      (unsigned long long)r->start,
+                                      (unsigned long long)r->end);
                                r->flags = 0;
                                continue;
                        }
@@ -372,8 +385,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long
        align = 0;
        min_align = 0;
        for (order = 0; order <= max_order; order++) {
-               unsigned long align1 = 1UL << (order + 20);
-
+#ifdef CONFIG_RESOURCES_64BIT
+               resource_size_t align1 = 1ULL << (order + 20);
+#else
+               resource_size_t align1 = 1U << (order + 20);
+#endif
                if (!align)
                        min_align = align1;
                else if (ALIGN(align + min_align, min_align) < align1)
@@ -440,7 +456,7 @@ pci_bus_size_cardbus(struct pci_bus *bus)
        }
 }
 
-void pci_bus_size_bridges(struct pci_bus *bus)
+void __ref pci_bus_size_bridges(struct pci_bus *bus)
 {
        struct pci_dev *dev;
        unsigned long mask, prefmask;
@@ -495,7 +511,7 @@ void pci_bus_size_bridges(struct pci_bus *bus)
 }
 EXPORT_SYMBOL(pci_bus_size_bridges);
 
-void pci_bus_assign_resources(struct pci_bus *bus)
+void __ref pci_bus_assign_resources(struct pci_bus *bus)
 {
        struct pci_bus *b;
        struct pci_dev *dev;
index 6dfd86167e39107fe92058b92a5ade8d90784566..4be7ccf7e3ae9f4984b3ccae7563e23beb601d5b 100644 (file)
@@ -51,10 +51,12 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
 
        pcibios_resource_to_bus(dev, &region, res);
 
-       pr_debug("  got res [%llx:%llx] bus [%lx:%lx] flags %lx for "
+       pr_debug("  got res [%llx:%llx] bus [%llx:%llx] flags %lx for "
                 "BAR %d of %s\n", (unsigned long long)res->start,
                 (unsigned long long)res->end,
-                region.start, region.end, res->flags, resno, pci_name(dev));
+                (unsigned long long)region.start,
+                (unsigned long long)region.end,
+                (unsigned long)res->flags, resno, pci_name(dev));
 
        new = region.start | (res->flags & PCI_REGION_FLAG_MASK);
        if (res->flags & IORESOURCE_IO)
@@ -125,7 +127,6 @@ int pci_claim_resource(struct pci_dev *dev, int resource)
 
        return err;
 }
-EXPORT_SYMBOL_GPL(pci_claim_resource);
 
 int pci_assign_resource(struct pci_dev *dev, int resno)
 {
index 2ac050d7f8cffbc12e57384ee96894917236c73e..645d7a60e412ce3d970044ca89a823db3e21007c 100644 (file)
@@ -34,7 +34,6 @@ sys_pciconfig_read(unsigned long bus, unsigned long dfn,
        if (!dev)
                goto error;
 
-       lock_kernel();
        switch (len) {
        case 1:
                cfg_ret = pci_user_read_config_byte(dev, off, &byte);
@@ -47,10 +46,8 @@ sys_pciconfig_read(unsigned long bus, unsigned long dfn,
                break;
        default:
                err = -EINVAL;
-               unlock_kernel();
                goto error;
        };
-       unlock_kernel();
 
        err = -EIO;
        if (cfg_ret != PCIBIOS_SUCCESSFUL)
@@ -107,7 +104,6 @@ sys_pciconfig_write(unsigned long bus, unsigned long dfn,
        if (!dev)
                return -ENODEV;
 
-       lock_kernel();
        switch(len) {
        case 1:
                err = get_user(byte, (u8 __user *)buf);
@@ -140,7 +136,6 @@ sys_pciconfig_write(unsigned long bus, unsigned long dfn,
                err = -EINVAL;
                break;
        }
-       unlock_kernel();
        pci_dev_put(dev);
        return err;
 }
index eb6abd3f9221a896f1375ff855c2ac419491e630..385e145e1acc5688bed7b7869fe6aa40020ada9d 100644 (file)
@@ -21,9 +21,9 @@
 #include <asm/hardware.h>
 #include <asm/io.h>
 #include <asm/sizes.h>
+#include <asm/gpio.h>
 
 #include <asm/arch/board.h>
-#include <asm/arch/gpio.h>
 #include <asm/arch/at91rm9200_mc.h>
 
 
@@ -56,7 +56,7 @@ struct at91_cf_socket {
 
 static inline int at91_cf_present(struct at91_cf_socket *cf)
 {
-       return !at91_get_gpio_value(cf->board->det_pin);
+       return !gpio_get_value(cf->board->det_pin);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -100,9 +100,9 @@ static int at91_cf_get_status(struct pcmcia_socket *s, u_int *sp)
                int vcc = cf->board->vcc_pin;
 
                *sp = SS_DETECT | SS_3VCARD;
-               if (!rdy || at91_get_gpio_value(rdy))
+               if (!rdy || gpio_get_value(rdy))
                        *sp |= SS_READY;
-               if (!vcc || at91_get_gpio_value(vcc))
+               if (!vcc || gpio_get_value(vcc))
                        *sp |= SS_POWERON;
        } else
                *sp = 0;
@@ -121,10 +121,10 @@ at91_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
        if (cf->board->vcc_pin) {
                switch (s->Vcc) {
                        case 0:
-                               at91_set_gpio_value(cf->board->vcc_pin, 0);
+                               gpio_set_value(cf->board->vcc_pin, 0);
                                break;
                        case 33:
-                               at91_set_gpio_value(cf->board->vcc_pin, 1);
+                               gpio_set_value(cf->board->vcc_pin, 1);
                                break;
                        default:
                                return -EINVAL;
@@ -132,7 +132,7 @@ at91_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
        }
 
        /* toggle reset if needed */
-       at91_set_gpio_value(cf->board->rst_pin, s->flags & SS_RESET);
+       gpio_set_value(cf->board->rst_pin, s->flags & SS_RESET);
 
        pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n",
                driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask);
@@ -239,11 +239,24 @@ static int __init at91_cf_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, cf);
 
        /* must be a GPIO; ergo must trigger on both edges */
-       status = request_irq(board->det_pin, at91_cf_irq, 0, driver_name, cf);
+       status = gpio_request(board->det_pin, "cf_det");
        if (status < 0)
                goto fail0;
+       status = request_irq(board->det_pin, at91_cf_irq, 0, driver_name, cf);
+       if (status < 0)
+               goto fail00;
        device_init_wakeup(&pdev->dev, 1);
 
+       status = gpio_request(board->rst_pin, "cf_rst");
+       if (status < 0)
+               goto fail0a;
+
+       if (board->vcc_pin) {
+               status = gpio_request(board->vcc_pin, "cf_vcc");
+               if (status < 0)
+                       goto fail0b;
+       }
+
        /*
         * The card driver will request this irq later as needed.
         * but it causes lots of "irqNN: nobody cared" messages
@@ -251,16 +264,20 @@ static int __init at91_cf_probe(struct platform_device *pdev)
         * (Note:  DK board doesn't wire the IRQ pin...)
         */
        if (board->irq_pin) {
+               status = gpio_request(board->irq_pin, "cf_irq");
+               if (status < 0)
+                       goto fail0c;
                status = request_irq(board->irq_pin, at91_cf_irq,
                                IRQF_SHARED, driver_name, cf);
                if (status < 0)
-                       goto fail0a;
+                       goto fail0d;
                cf->socket.pci_irq = board->irq_pin;
        } else
                cf->socket.pci_irq = NR_IRQS + 1;
 
        /* pcmcia layer only remaps "real" memory not iospace */
-       cf->socket.io_offset = (unsigned long) ioremap(cf->phys_baseaddr + CF_IO_PHYS, SZ_2K);
+       cf->socket.io_offset = (unsigned long)
+                       ioremap(cf->phys_baseaddr + CF_IO_PHYS, SZ_2K);
        if (!cf->socket.io_offset) {
                status = -ENXIO;
                goto fail1;
@@ -296,11 +313,21 @@ fail2:
 fail1:
        if (cf->socket.io_offset)
                iounmap((void __iomem *) cf->socket.io_offset);
-       if (board->irq_pin)
+       if (board->irq_pin) {
                free_irq(board->irq_pin, cf);
+fail0d:
+               gpio_free(board->irq_pin);
+       }
+fail0c:
+       if (board->vcc_pin)
+               gpio_free(board->vcc_pin);
+fail0b:
+       gpio_free(board->rst_pin);
 fail0a:
        device_init_wakeup(&pdev->dev, 0);
        free_irq(board->det_pin, cf);
+fail00:
+       gpio_free(board->det_pin);
 fail0:
        kfree(cf);
        return status;
@@ -313,13 +340,18 @@ static int __exit at91_cf_remove(struct platform_device *pdev)
        struct resource         *io = cf->socket.io[0].res;
 
        pcmcia_unregister_socket(&cf->socket);
-       if (board->irq_pin)
+       release_mem_region(io->start, io->end + 1 - io->start);
+       iounmap((void __iomem *) cf->socket.io_offset);
+       if (board->irq_pin) {
                free_irq(board->irq_pin, cf);
+               gpio_free(board->irq_pin);
+       }
+       if (board->vcc_pin)
+               gpio_free(board->vcc_pin);
+       gpio_free(board->rst_pin);
        device_init_wakeup(&pdev->dev, 0);
        free_irq(board->det_pin, cf);
-       iounmap((void __iomem *) cf->socket.io_offset);
-       release_mem_region(io->start, io->end + 1 - io->start);
-
+       gpio_free(board->det_pin);
        kfree(cf);
        return 0;
 }
index a1bd763b4e336e94b277a6fe650adf2107044807..714baaeb6da1257a264c903b4b36d67570c15486 100644 (file)
@@ -143,7 +143,7 @@ int read_cb_mem(struct pcmcia_socket * s, int space, u_int addr, u_int len, void
        /* Config space? */
        if (space == 0) {
                if (addr + len > 0x100)
-                       goto fail;
+                       goto failput;
                for (; len; addr++, ptr++, len--)
                        pci_read_config_byte(dev, addr, ptr);
                return 0;
@@ -171,6 +171,8 @@ int read_cb_mem(struct pcmcia_socket * s, int space, u_int addr, u_int len, void
        memcpy_fromio(ptr, s->cb_cis_virt + addr, len);
        return 0;
 
+failput:
+       pci_dev_put(dev);
 fail:
        memset(ptr, 0xff, len);
        return -1;
index 15c18f5246d6d21bbd2c849892ef0f88d536395c..5a85871f5ee919ff3bdb18f10be8715132b037de 100644 (file)
@@ -865,11 +865,12 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
        ds_dbg(1, "trying to load CIS file %s\n", filename);
 
        if (strlen(filename) > 14) {
-               printk(KERN_WARNING "pcmcia: CIS filename is too long\n");
+               printk(KERN_WARNING "pcmcia: CIS filename is too long [%s]\n",
+                       filename);
                return -EINVAL;
        }
 
-       snprintf(path, 20, "%s", filename);
+       snprintf(path, sizeof(path), "%s", filename);
 
        if (request_firmware(&fw, path, &dev->dev) == 0) {
                if (fw->size >= CISTPL_MAX_CIS_SIZE) {
@@ -1130,8 +1131,6 @@ static int runtime_suspend(struct device *dev)
        down(&dev->sem);
        rc = pcmcia_dev_suspend(dev, PMSG_SUSPEND);
        up(&dev->sem);
-       if (!rc)
-               dev->power.power_state.event = PM_EVENT_SUSPEND;
        return rc;
 }
 
@@ -1142,8 +1141,6 @@ static void runtime_resume(struct device *dev)
        down(&dev->sem);
        rc = pcmcia_dev_resume(dev);
        up(&dev->sem);
-       if (!rc)
-               dev->power.power_state.event = PM_EVENT_ON;
 }
 
 /************************ per-device sysfs output ***************************/
@@ -1265,6 +1262,9 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
        struct pcmcia_driver *p_drv = NULL;
        int ret = 0;
 
+       if (p_dev->suspended)
+               return 0;
+
        ds_dbg(2, "suspending %s\n", dev->bus_id);
 
        if (dev->driver)
@@ -1301,6 +1301,9 @@ static int pcmcia_dev_resume(struct device * dev)
         struct pcmcia_driver *p_drv = NULL;
        int ret = 0;
 
+       if (!p_dev->suspended)
+               return 0;
+
        ds_dbg(2, "resuming %s\n", dev->bus_id);
 
        if (dev->driver)
index df21e2d16f87858632d6f8f44343eefcf8df6b8c..749515534cc0ea2c4394c32ae1af6c2724ffe898 100644 (file)
@@ -82,7 +82,7 @@ struct socket_info {
                                    1 = empty socket, 
                                    2 = card but not initialized,
                                    3 = operational card */
-       kio_addr_t io_base;     /* base io address of the socket */
+       unsigned int io_base;   /* base io address of the socket */
        
        struct pcmcia_socket socket;
        struct pci_dev *dev;    /* The PCI device for the socket */
index 839bb1c0db58c9af53211483cc735370217cd3d6..32a2ab119798ccfc2f18c1df52377b7da2009ad3 100644 (file)
@@ -164,7 +164,7 @@ struct i82365_socket {
     u_short            type, flags;
     struct pcmcia_socket       socket;
     unsigned int       number;
-    kio_addr_t         ioaddr;
+    unsigned int       ioaddr;
     u_short            psock;
     u_char             cs_irq, intr;
     union {
@@ -238,7 +238,7 @@ static u_char i365_get(u_short sock, u_short reg)
     unsigned long flags;
     spin_lock_irqsave(&bus_lock,flags);
     {
-       kio_addr_t port = socket[sock].ioaddr;
+       unsigned int port = socket[sock].ioaddr;
        u_char val;
        reg = I365_REG(socket[sock].psock, reg);
        outb(reg, port); val = inb(port+1);
@@ -252,7 +252,7 @@ static void i365_set(u_short sock, u_short reg, u_char data)
     unsigned long flags;
     spin_lock_irqsave(&bus_lock,flags);
     {
-       kio_addr_t port = socket[sock].ioaddr;
+       unsigned int port = socket[sock].ioaddr;
        u_char val = I365_REG(socket[sock].psock, reg);
        outb(val, port); outb(data, port+1);
        spin_unlock_irqrestore(&bus_lock,flags);
@@ -588,7 +588,7 @@ static int to_cycles(int ns)
 
 /*====================================================================*/
 
-static int __init identify(kio_addr_t port, u_short sock)
+static int __init identify(unsigned int port, u_short sock)
 {
     u_char val;
     int type = -1;
@@ -659,7 +659,7 @@ static int __init identify(kio_addr_t port, u_short sock)
 static int __init is_alive(u_short sock)
 {
     u_char stat;
-    kio_addr_t start, stop;
+    unsigned int start, stop;
     
     stat = i365_get(sock, I365_STATUS);
     start = i365_get_pair(sock, I365_IO(0)+I365_W_START);
@@ -678,7 +678,7 @@ static int __init is_alive(u_short sock)
 
 /*====================================================================*/
 
-static void __init add_socket(kio_addr_t port, int psock, int type)
+static void __init add_socket(unsigned int port, int psock, int type)
 {
     socket[sockets].ioaddr = port;
     socket[sockets].psock = psock;
@@ -698,7 +698,7 @@ static void __init add_pcic(int ns, int type)
     base = sockets-ns;
     if (base == 0) printk("\n");
     printk(KERN_INFO "  %s", pcic[type].name);
-    printk(" ISA-to-PCMCIA at port %#lx ofs 0x%02x",
+    printk(" ISA-to-PCMCIA at port %#x ofs 0x%02x",
               t->ioaddr, t->psock*0x40);
     printk(", %d socket%s\n", ns, ((ns > 1) ? "s" : ""));
 
@@ -772,7 +772,7 @@ static struct pnp_dev *i82365_pnpdev;
 static void __init isa_probe(void)
 {
     int i, j, sock, k, ns, id;
-    kio_addr_t port;
+    unsigned int port;
 #ifdef CONFIG_PNP
     struct isapnp_device_id *devid;
     struct pnp_dev *dev;
@@ -1053,7 +1053,7 @@ static int i365_set_io_map(u_short sock, struct pccard_io_map *io)
     u_char map, ioctl;
     
     debug(1, "SetIOMap(%d, %d, %#2.2x, %d ns, "
-         "%#lx-%#lx)\n", sock, io->map, io->flags,
+         "%#x-%#x)\n", sock, io->map, io->flags,
          io->speed, io->start, io->stop);
     map = io->map;
     if ((map > 1) || (io->start > 0xffff) || (io->stop > 0xffff) ||
index 91da15b5a81ea0e3df861a7923fae76b9538faea..3616da22715239ca658d0bd5816e01eb170d94f5 100644 (file)
@@ -58,7 +58,7 @@ typedef struct pcc_socket {
        u_short                 type, flags;
        struct pcmcia_socket    socket;
        unsigned int            number;
-       kio_addr_t              ioaddr;
+       unsigned int            ioaddr;
        u_long                  mapaddr;
        u_long                  base;   /* PCC register base */
        u_char                  cs_irq1, cs_irq2, intr;
@@ -298,7 +298,8 @@ static int __init is_alive(u_short sock)
        return 0;
 }
 
-static void add_pcc_socket(ulong base, int irq, ulong mapaddr, kio_addr_t ioaddr)
+static void add_pcc_socket(ulong base, int irq, ulong mapaddr,
+                          unsigned int ioaddr)
 {
        pcc_socket_t *t = &socket[pcc_sockets];
 
@@ -738,7 +739,7 @@ static int __init init_m32r_pcc(void)
 #else  /* CONFIG_PLAT_USRV */
        {
                ulong base, mapaddr;
-               kio_addr_t ioaddr;
+               unsigned int ioaddr;
 
                for (i = 0 ; i < M32R_MAX_PCC ; i++) {
                        base = (ulong)PLD_CFRSTCR;
index c5e0d89c3ecefecf09cc03e5558b4c0aff4ca315..2b42b7155e34a9571b89df20dd990bfb76b5ba46 100644 (file)
@@ -65,7 +65,7 @@ typedef struct pcc_socket {
        u_short                 type, flags;
        struct pcmcia_socket    socket;
        unsigned int            number;
-       kio_addr_t              ioaddr;
+       unsigned int            ioaddr;
        u_long                  mapaddr;
        u_long                  base;   /* PCC register base */
        u_char                  cs_irq, intr;
@@ -310,7 +310,8 @@ static int __init is_alive(u_short sock)
        return 0;
 }
 
-static void add_pcc_socket(ulong base, int irq, ulong mapaddr, kio_addr_t ioaddr)
+static void add_pcc_socket(ulong base, int irq, ulong mapaddr,
+                          unsigned int ioaddr)
 {
        pcc_socket_t *t = &socket[pcc_sockets];
 
@@ -368,7 +369,7 @@ static irqreturn_t pcc_interrupt(int irq, void *dev)
                        handled = 1;
                        irc = pcc_get(i, PCIRC);
                        irc >>=16;
-                       debug(2, "m32r-pcc:interrput: socket %d pcirc 0x%02x ", i, irc);
+                       debug(2, "m32r-pcc:interrupt: socket %d pcirc 0x%02x ", i, irc);
                        if (!irc)
                                continue;
 
@@ -491,7 +492,7 @@ static int _pcc_set_io_map(u_short sock, struct pccard_io_map *io)
        u_char map;
 
        debug(3, "m32r-pcc: SetIOMap(%d, %d, %#2.2x, %d ns, "
-                 "%#lx-%#lx)\n", sock, io->map, io->flags,
+                 "%#x-%#x)\n", sock, io->map, io->flags,
                  io->speed, io->start, io->stop);
        map = io->map;
 
index d182760f035b1e7f8fed9d516ec4d02bdf9baa0b..ac70d2cb7dd409764deb755e13e821d366702d5f 100644 (file)
@@ -851,7 +851,7 @@ static int m8xx_set_socket(struct pcmcia_socket *sock, socket_state_t * state)
           I tried to control the CxOE signal with SS_OUTPUT_ENA,
           but the reset signal seems connected via the 541.
           If the CxOE is left high are some signals tristated and
-          no pullups are present -> the cards act wierd.
+          no pullups are present -> the cards act weird.
           So right now the buffers are enabled if the power is on. */
 
        if (state->Vcc || state->Vpp)
@@ -1174,8 +1174,10 @@ static int __init m8xx_probe(struct of_device *ofdev,
 
        pcmcia_schlvl = irq_of_parse_and_map(np, 0);
        hwirq = irq_map[pcmcia_schlvl].hwirq;
-       if (pcmcia_schlvl < 0)
+       if (pcmcia_schlvl < 0) {
+               iounmap(pcmcia);
                return -EINVAL;
+       }
 
        m8xx_pgcrx[0] = &pcmcia->pcmc_pgcra;
        m8xx_pgcrx[1] = &pcmcia->pcmc_pgcrb;
@@ -1189,6 +1191,7 @@ static int __init m8xx_probe(struct of_device *ofdev,
                        driver_name, socket)) {
                pcmcia_error("Cannot allocate IRQ %u for SCHLVL!\n",
                             pcmcia_schlvl);
+               iounmap(pcmcia);
                return -1;
        }
 
@@ -1284,6 +1287,7 @@ static int m8xx_remove(struct of_device *ofdev)
        }
        for (i = 0; i < PCMCIA_SOCKETS_NO; i++)
                pcmcia_unregister_socket(&socket[i].socket);
+       iounmap(pcmcia);
 
        free_irq(pcmcia_schlvl, NULL);
 
index 0ce39de834c477785a0b04ba580c80cffc4dd41e..1d128fbd1a92d9f4dcdaed4a3065c3365b5fce68 100644 (file)
@@ -65,23 +65,23 @@ extern int ds_pc_debug;
  * Special stuff for managing IO windows, because they are scarce
  */
 
-static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
-                         ioaddr_t num, u_int lines)
+static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
+                         unsigned int *base, unsigned int num, u_int lines)
 {
        int i;
-       kio_addr_t try, align;
+       unsigned int try, align;
 
        align = (*base) ? (lines ? 1<<lines : 0) : 1;
        if (align && (align < num)) {
                if (*base) {
-                       ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
+                       ds_dbg(s, 0, "odd IO request: num %#x align %#x\n",
                               num, align);
                        align = 0;
                } else
                        while (align && (align < num)) align <<= 1;
        }
        if (*base & ~(align-1)) {
-               ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
+               ds_dbg(s, 0, "odd IO request: base %#x align %#x\n",
                       *base, align);
                align = 0;
        }
@@ -132,8 +132,8 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
 } /* alloc_io_space */
 
 
-static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
-                            ioaddr_t num)
+static void release_io_space(struct pcmcia_socket *s, unsigned int base,
+                            unsigned int num)
 {
        int i;
 
index bfcaad6021cf05dead89b7a63052b282f457158d..a8d1007077213c96cdc6fe02b7c75d7b198fcde3 100644 (file)
@@ -186,15 +186,16 @@ static int sub_interval(struct resource_map *map, u_long base, u_long num)
 ======================================================================*/
 
 #ifdef CONFIG_PCMCIA_PROBE
-static void do_io_probe(struct pcmcia_socket *s, kio_addr_t base, kio_addr_t num)
+static void do_io_probe(struct pcmcia_socket *s, unsigned int base,
+                       unsigned int num)
 {
     struct resource *res;
     struct socket_data *s_data = s->resource_data;
-    kio_addr_t i, j, bad;
+    unsigned int i, j, bad;
     int any;
     u_char *b, hole, most;
 
-    printk(KERN_INFO "cs: IO port probe %#lx-%#lx:",
+    printk(KERN_INFO "cs: IO port probe %#x-%#x:",
           base, base+num-1);
 
     /* First, what does a floating port look like? */
@@ -233,7 +234,7 @@ static void do_io_probe(struct pcmcia_socket *s, kio_addr_t base, kio_addr_t num
        } else {
            if (bad) {
                sub_interval(&s_data->io_db, bad, i-bad);
-               printk(" %#lx-%#lx", bad, i-1);
+               printk(" %#x-%#x", bad, i-1);
                bad = 0;
            }
        }
@@ -244,7 +245,7 @@ static void do_io_probe(struct pcmcia_socket *s, kio_addr_t base, kio_addr_t num
            return;
        } else {
            sub_interval(&s_data->io_db, bad, i-bad);
-           printk(" %#lx-%#lx", bad, i-1);
+           printk(" %#x-%#x", bad, i-1);
        }
     }
 
index af485ae386024fbf560d260b52a83db25e1a5b2f..6284c35dabc687f6ee1fc5afbf89bda6276ffd46 100644 (file)
@@ -101,7 +101,7 @@ static struct pcmcia_low_level jornada720_pcmcia_ops = {
   .socket_suspend      = sa1111_pcmcia_socket_suspend,
 };
 
-int __init pcmcia_jornada720_init(struct device *dev)
+int __devinit pcmcia_jornada720_init(struct device *dev)
 {
        int ret = -ENODEV;
 
index 749ac3710914e519c122284a4bd0f32670b990ee..5792bd5c54f93a4a3a3394d665145209b2f5c5e8 100644 (file)
@@ -719,7 +719,7 @@ static int tcic_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io)
     u_short base, len, ioctl;
     
     debug(1, "SetIOMap(%d, %d, %#2.2x, %d ns, "
-         "%#lx-%#lx)\n", psock, io->map, io->flags,
+         "%#x-%#x)\n", psock, io->map, io->flags,
          io->speed, io->start, io->stop);
     if ((io->map > 1) || (io->start > 0xffff) || (io->stop > 0xffff) ||
        (io->stop < io->start)) return -EINVAL;
index a262762c5b8836e0dc5091317e43359b67443fc9..12a1645a2e4352b3a3cc8e07941a9888dd5567cb 100644 (file)
@@ -161,8 +161,7 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state)
                        return error;
        }
 
-       if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE) &&
-           pnp_can_disable(pnp_dev)) {
+       if (pnp_can_disable(pnp_dev)) {
                error = pnp_stop_dev(pnp_dev);
                if (error)
                        return error;
@@ -185,14 +184,17 @@ static int pnp_bus_resume(struct device *dev)
        if (pnp_dev->protocol && pnp_dev->protocol->resume)
                pnp_dev->protocol->resume(pnp_dev);
 
-       if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) {
+       if (pnp_can_write(pnp_dev)) {
                error = pnp_start_dev(pnp_dev);
                if (error)
                        return error;
        }
 
-       if (pnp_drv->resume)
-               return pnp_drv->resume(pnp_dev);
+       if (pnp_drv->resume) {
+               error = pnp_drv->resume(pnp_dev);
+               if (error)
+                       return error;
+       }
 
        return 0;
 }
index 31548044fdde9a7ef63d1b154c882b83b034397f..982658477a58b4695df2ac979b00090cba9b1101 100644 (file)
 #include <linux/errno.h>
 #include <linux/list.h>
 #include <linux/types.h>
+#include <linux/pnp.h>
 #include <linux/stat.h>
 #include <linux/ctype.h>
 #include <linux/slab.h>
+#include <linux/mutex.h>
+
 #include <asm/uaccess.h>
 
 #include "base.h"
@@ -315,8 +318,6 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
        return ret;
 }
 
-extern struct semaphore pnp_res_mutex;
-
 static ssize_t
 pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                          const char *ubuf, size_t count)
@@ -361,10 +362,10 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                goto done;
        }
        if (!strnicmp(buf, "get", 3)) {
-               down(&pnp_res_mutex);
+               mutex_lock(&pnp_res_mutex);
                if (pnp_can_read(dev))
                        dev->protocol->get(dev, &dev->res);
-               up(&pnp_res_mutex);
+               mutex_unlock(&pnp_res_mutex);
                goto done;
        }
        if (!strnicmp(buf, "set", 3)) {
@@ -373,7 +374,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                        goto done;
                buf += 3;
                pnp_init_resource_table(&dev->res);
-               down(&pnp_res_mutex);
+               mutex_lock(&pnp_res_mutex);
                while (1) {
                        while (isspace(*buf))
                                ++buf;
@@ -455,7 +456,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                        }
                        break;
                }
-               up(&pnp_res_mutex);
+               mutex_unlock(&pnp_res_mutex);
                goto done;
        }
 
index c6b3d4e63ccc62a9ae6e4df684c016eb598fe184..c28caf272c1167f13c761da916af4a0983d878da 100644 (file)
 #include <linux/pnp.h>
 #include <linux/slab.h>
 #include <linux/bitmap.h>
+#include <linux/mutex.h>
 #include "base.h"
 
-DECLARE_MUTEX(pnp_res_mutex);
+DEFINE_MUTEX(pnp_res_mutex);
 
 static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
 {
@@ -297,7 +298,7 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
        if (!pnp_can_configure(dev))
                return -ENODEV;
 
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        pnp_clean_resource_table(&dev->res);    /* start with a fresh slate */
        if (dev->independent) {
                port = dev->independent->port;
@@ -366,12 +367,12 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
        } else if (dev->dependent)
                goto fail;
 
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        return 1;
 
 fail:
        pnp_clean_resource_table(&dev->res);
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        return 0;
 }
 
@@ -396,7 +397,7 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
                return -ENOMEM;
        *bak = dev->res;
 
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        dev->res = *res;
        if (!(mode & PNP_CONFIG_FORCE)) {
                for (i = 0; i < PNP_MAX_PORT; i++) {
@@ -416,14 +417,14 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
                                goto fail;
                }
        }
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
 
        kfree(bak);
        return 0;
 
 fail:
        dev->res = *bak;
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        kfree(bak);
        return -EINVAL;
 }
@@ -513,7 +514,7 @@ int pnp_activate_dev(struct pnp_dev *dev)
        int error;
 
        if (dev->active)
-               return 0;       /* the device is already active */
+               return 0;
 
        /* ensure resources are allocated */
        if (pnp_auto_config_dev(dev))
@@ -524,7 +525,7 @@ int pnp_activate_dev(struct pnp_dev *dev)
                return error;
 
        dev->active = 1;
-       return 1;
+       return 0;
 }
 
 /**
@@ -538,7 +539,7 @@ int pnp_disable_dev(struct pnp_dev *dev)
        int error;
 
        if (!dev->active)
-               return 0;       /* the device is already disabled */
+               return 0;
 
        error = pnp_stop_dev(dev);
        if (error)
@@ -547,11 +548,11 @@ int pnp_disable_dev(struct pnp_dev *dev)
        dev->active = 0;
 
        /* release the resources so that other devices can use them */
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        pnp_clean_resource_table(&dev->res);
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
 
-       return 1;
+       return 0;
 }
 
 /**
index 6b9840cce0f4a8cdf9b1a2a51c48e186e53015f2..6aa231ef642d3e366b13984a56e524851d9251fa 100644 (file)
@@ -391,8 +391,8 @@ acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
                                   pnpacpi_allocated_resource, res);
 }
 
-static void pnpacpi_parse_dma_option(struct pnp_option *option,
-                                    struct acpi_resource_dma *p)
+static __init void pnpacpi_parse_dma_option(struct pnp_option *option,
+                                           struct acpi_resource_dma *p)
 {
        int i;
        struct pnp_dma *dma;
@@ -411,8 +411,8 @@ static void pnpacpi_parse_dma_option(struct pnp_option *option,
        pnp_register_dma_resource(option, dma);
 }
 
-static void pnpacpi_parse_irq_option(struct pnp_option *option,
-                                    struct acpi_resource_irq *p)
+static __init void pnpacpi_parse_irq_option(struct pnp_option *option,
+                                           struct acpi_resource_irq *p)
 {
        int i;
        struct pnp_irq *irq;
@@ -431,8 +431,8 @@ static void pnpacpi_parse_irq_option(struct pnp_option *option,
        pnp_register_irq_resource(option, irq);
 }
 
-static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
-                                        struct acpi_resource_extended_irq *p)
+static __init void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
+                                       struct acpi_resource_extended_irq *p)
 {
        int i;
        struct pnp_irq *irq;
@@ -451,8 +451,8 @@ static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
        pnp_register_irq_resource(option, irq);
 }
 
-static void pnpacpi_parse_port_option(struct pnp_option *option,
-                                     struct acpi_resource_io *io)
+static __init void pnpacpi_parse_port_option(struct pnp_option *option,
+                                            struct acpi_resource_io *io)
 {
        struct pnp_port *port;
 
@@ -470,8 +470,8 @@ static void pnpacpi_parse_port_option(struct pnp_option *option,
        pnp_register_port_resource(option, port);
 }
 
-static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
-                                           struct acpi_resource_fixed_io *io)
+static __init void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
+                                       struct acpi_resource_fixed_io *io)
 {
        struct pnp_port *port;
 
@@ -487,8 +487,8 @@ static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
        pnp_register_port_resource(option, port);
 }
 
-static void pnpacpi_parse_mem24_option(struct pnp_option *option,
-                                      struct acpi_resource_memory24 *p)
+static __init void pnpacpi_parse_mem24_option(struct pnp_option *option,
+                                             struct acpi_resource_memory24 *p)
 {
        struct pnp_mem *mem;
 
@@ -508,8 +508,8 @@ static void pnpacpi_parse_mem24_option(struct pnp_option *option,
        pnp_register_mem_resource(option, mem);
 }
 
-static void pnpacpi_parse_mem32_option(struct pnp_option *option,
-                                      struct acpi_resource_memory32 *p)
+static __init void pnpacpi_parse_mem32_option(struct pnp_option *option,
+                                             struct acpi_resource_memory32 *p)
 {
        struct pnp_mem *mem;
 
@@ -529,8 +529,8 @@ static void pnpacpi_parse_mem32_option(struct pnp_option *option,
        pnp_register_mem_resource(option, mem);
 }
 
-static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
-                                        struct acpi_resource_fixed_memory32 *p)
+static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
+                                       struct acpi_resource_fixed_memory32 *p)
 {
        struct pnp_mem *mem;
 
@@ -549,8 +549,8 @@ static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
        pnp_register_mem_resource(option, mem);
 }
 
-static void pnpacpi_parse_address_option(struct pnp_option *option,
-                                        struct acpi_resource *r)
+static __init void pnpacpi_parse_address_option(struct pnp_option *option,
+                                               struct acpi_resource *r)
 {
        struct acpi_resource_address64 addr, *p = &addr;
        acpi_status status;
@@ -596,8 +596,8 @@ struct acpipnp_parse_option_s {
        struct pnp_dev *dev;
 };
 
-static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
-                                          void *data)
+static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
+                                                 void *data)
 {
        int priority = 0;
        struct acpipnp_parse_option_s *parse_data = data;
@@ -696,8 +696,8 @@ static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
        return AE_OK;
 }
 
-acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
-                                              struct pnp_dev * dev)
+acpi_status __init pnpacpi_parse_resource_option_data(acpi_handle handle,
+                                                     struct pnp_dev *dev)
 {
        acpi_status status;
        struct acpipnp_parse_option_s parse_data;
index e33e03f710841998591b0b8c649f3fb2e2db189e..f7e67197a56847c9d937ab0cb2efd595ee3fc306 100644 (file)
@@ -315,7 +315,7 @@ struct pnp_protocol pnpbios_protocol = {
        .disable = pnpbios_disable_resources,
 };
 
-static int insert_device(struct pnp_bios_node *node)
+static int __init insert_device(struct pnp_bios_node *node)
 {
        struct list_head *pos;
        struct pnp_dev *dev;
index 3fabf11b002722f92ae50e8c591a3b13450b554c..caade3531416f6a7392595f7b5fd432fa2a05660 100644 (file)
@@ -262,8 +262,8 @@ len_err:
  * Resource Configuration Options
  */
 
-static void pnpbios_parse_mem_option(unsigned char *p, int size,
-                                    struct pnp_option *option)
+static __init void pnpbios_parse_mem_option(unsigned char *p, int size,
+                                           struct pnp_option *option)
 {
        struct pnp_mem *mem;
 
@@ -278,8 +278,8 @@ static void pnpbios_parse_mem_option(unsigned char *p, int size,
        pnp_register_mem_resource(option, mem);
 }
 
-static void pnpbios_parse_mem32_option(unsigned char *p, int size,
-                                      struct pnp_option *option)
+static __init void pnpbios_parse_mem32_option(unsigned char *p, int size,
+                                             struct pnp_option *option)
 {
        struct pnp_mem *mem;
 
@@ -294,8 +294,8 @@ static void pnpbios_parse_mem32_option(unsigned char *p, int size,
        pnp_register_mem_resource(option, mem);
 }
 
-static void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size,
-                                            struct pnp_option *option)
+static __init void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size,
+                                                   struct pnp_option *option)
 {
        struct pnp_mem *mem;
 
@@ -309,7 +309,7 @@ static void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size,
        pnp_register_mem_resource(option, mem);
 }
 
-static void pnpbios_parse_irq_option(unsigned char *p, int size,
+static __init void pnpbios_parse_irq_option(unsigned char *p, int size,
                                     struct pnp_option *option)
 {
        struct pnp_irq *irq;
@@ -327,7 +327,7 @@ static void pnpbios_parse_irq_option(unsigned char *p, int size,
        pnp_register_irq_resource(option, irq);
 }
 
-static void pnpbios_parse_dma_option(unsigned char *p, int size,
+static __init void pnpbios_parse_dma_option(unsigned char *p, int size,
                                     struct pnp_option *option)
 {
        struct pnp_dma *dma;
@@ -340,8 +340,8 @@ static void pnpbios_parse_dma_option(unsigned char *p, int size,
        pnp_register_dma_resource(option, dma);
 }
 
-static void pnpbios_parse_port_option(unsigned char *p, int size,
-                                     struct pnp_option *option)
+static __init void pnpbios_parse_port_option(unsigned char *p, int size,
+                                            struct pnp_option *option)
 {
        struct pnp_port *port;
 
@@ -356,8 +356,8 @@ static void pnpbios_parse_port_option(unsigned char *p, int size,
        pnp_register_port_resource(option, port);
 }
 
-static void pnpbios_parse_fixed_port_option(unsigned char *p, int size,
-                                           struct pnp_option *option)
+static __init void pnpbios_parse_fixed_port_option(unsigned char *p, int size,
+                                                  struct pnp_option *option)
 {
        struct pnp_port *port;
 
@@ -371,9 +371,9 @@ static void pnpbios_parse_fixed_port_option(unsigned char *p, int size,
        pnp_register_port_resource(option, port);
 }
 
-static unsigned char *pnpbios_parse_resource_option_data(unsigned char *p,
-                                                        unsigned char *end,
-                                                        struct pnp_dev *dev)
+static __init unsigned char *
+pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
+                                       struct pnp_dev *dev)
 {
        unsigned int len, tag;
        int priority = 0;
@@ -781,7 +781,8 @@ len_err:
  * Core Parsing Functions
  */
 
-int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node *node)
+int __init pnpbios_parse_data_stream(struct pnp_dev *dev,
+                                       struct pnp_bios_node *node)
 {
        unsigned char *p = (char *)node->data;
        unsigned char *end = (char *)(node->data + node->size);
index e903b8c2b1fa5e200e2140d609deb643ea49d195..4065139753b6c4b6e9e1becf06df11234bde8b5f 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/slab.h>
 #include <linux/pnp.h>
 #include <linux/io.h>
+#include <linux/dmi.h>
 #include <linux/kallsyms.h>
 #include "base.h"
 
@@ -108,6 +109,46 @@ static void quirk_sb16audio_resources(struct pnp_dev *dev)
                       "pnp: SB audio device quirk - increasing port range\n");
 }
 
+static void quirk_supermicro_h8dce_system(struct pnp_dev *dev)
+{
+       int i;
+       static struct dmi_system_id supermicro_h8dce[] = {
+               {
+                       .ident = "Supermicro H8DCE",
+                       .matches = {
+                               DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
+                               DMI_MATCH(DMI_PRODUCT_NAME, "H8DCE"),
+                       },
+               },
+               { }
+       };
+
+       if (!dmi_check_system(supermicro_h8dce))
+               return;
+
+       /*
+        * On the Supermicro H8DCE, there's a system device with resources
+        * that overlap BAR 6 of the built-in SATA PCI adapter.  If the PNP
+        * system device claims them, the sata_nv driver won't be able to.
+        * More details at:
+        *     https://bugzilla.redhat.com/show_bug.cgi?id=280641
+        *     https://bugzilla.redhat.com/show_bug.cgi?id=313491
+        *     http://lkml.org/lkml/2008/1/9/449
+        *     http://thread.gmane.org/gmane.linux.acpi.devel/27312
+        */
+       for (i = 0; i < PNP_MAX_MEM; i++) {
+               if (pnp_mem_valid(dev, i) && pnp_mem_len(dev, i) &&
+                   (pnp_mem_start(dev, i) & 0xdfef0000) == 0xdfef0000) {
+                       dev_warn(&dev->dev, "disabling 0x%llx-0x%llx to prevent"
+                               " conflict with sata_nv PCI device\n",
+                               (unsigned long long) pnp_mem_start(dev, i),
+                               (unsigned long long) (pnp_mem_start(dev, i) +
+                                       pnp_mem_len(dev, i) - 1));
+                       pnp_mem_flags(dev, i) = 0;
+               }
+       }
+}
+
 /*
  *  PnP Quirks
  *  Cards or devices that need some tweaking due to incomplete resource info
@@ -128,6 +169,8 @@ static struct pnp_fixup pnp_fixups[] = {
        {"CTL0043", quirk_sb16audio_resources},
        {"CTL0044", quirk_sb16audio_resources},
        {"CTL0045", quirk_sb16audio_resources},
+       {"PNP0c01", quirk_supermicro_h8dce_system},
+       {"PNP0c02", quirk_supermicro_h8dce_system},
        {""}
 };
 
index 7e29b90a4f6377d51351828a8bf3daded4ad9d49..a4892275659dc02ffb1d12b85d0774a86bda8b08 100644 (file)
@@ -13,7 +13,7 @@
 #include <linux/power_supply.h>
 #include <linux/apm-emulation.h>
 
-static DEFINE_MUTEX(apm_mutex);
+
 #define PSY_PROP(psy, prop, val) psy->get_property(psy, \
                         POWER_SUPPLY_PROP_##prop, val)
 
@@ -22,8 +22,15 @@ static DEFINE_MUTEX(apm_mutex);
 
 #define MPSY_PROP(prop, val) _MPSY_PROP(POWER_SUPPLY_PROP_##prop, val)
 
+static DEFINE_MUTEX(apm_mutex);
 static struct power_supply *main_battery;
 
+enum apm_source {
+       SOURCE_ENERGY,
+       SOURCE_CHARGE,
+       SOURCE_VOLTAGE,
+};
+
 struct find_bat_param {
        struct power_supply *main;
        struct power_supply *bat;
@@ -107,7 +114,7 @@ static void find_main_battery(void)
        }
 }
 
-static int calculate_time(int status, int using_charge)
+static int do_calculate_time(int status, enum apm_source source)
 {
        union power_supply_propval full;
        union power_supply_propval empty;
@@ -126,20 +133,37 @@ static int calculate_time(int status, int using_charge)
                        return -1;
        }
 
-       if (using_charge) {
+       if (!I.intval)
+               return 0;
+
+       switch (source) {
+       case SOURCE_CHARGE:
                full_prop = POWER_SUPPLY_PROP_CHARGE_FULL;
                full_design_prop = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
                empty_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
                empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
                cur_avg_prop = POWER_SUPPLY_PROP_CHARGE_AVG;
                cur_now_prop = POWER_SUPPLY_PROP_CHARGE_NOW;
-       } else {
+               break;
+       case SOURCE_ENERGY:
                full_prop = POWER_SUPPLY_PROP_ENERGY_FULL;
                full_design_prop = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
                empty_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY;
                empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
                cur_avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG;
                cur_now_prop = POWER_SUPPLY_PROP_ENERGY_NOW;
+               break;
+       case SOURCE_VOLTAGE:
+               full_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX;
+               full_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN;
+               empty_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN;
+               empty_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN;
+               cur_avg_prop = POWER_SUPPLY_PROP_VOLTAGE_AVG;
+               cur_now_prop = POWER_SUPPLY_PROP_VOLTAGE_NOW;
+               break;
+       default:
+               printk(KERN_ERR "Unsupported source: %d\n", source);
+               return -1;
        }
 
        if (_MPSY_PROP(full_prop, &full)) {
@@ -166,7 +190,26 @@ static int calculate_time(int status, int using_charge)
                return -((cur.intval - empty.intval) * 60L) / I.intval;
 }
 
-static int calculate_capacity(int using_charge)
+static int calculate_time(int status)
+{
+       int time;
+
+       time = do_calculate_time(status, SOURCE_ENERGY);
+       if (time != -1)
+               return time;
+
+       time = do_calculate_time(status, SOURCE_CHARGE);
+       if (time != -1)
+               return time;
+
+       time = do_calculate_time(status, SOURCE_VOLTAGE);
+       if (time != -1)
+               return time;
+
+       return -1;
+}
+
+static int calculate_capacity(enum apm_source source)
 {
        enum power_supply_property full_prop, empty_prop;
        enum power_supply_property full_design_prop, empty_design_prop;
@@ -174,20 +217,33 @@ static int calculate_capacity(int using_charge)
        union power_supply_propval empty, full, cur;
        int ret;
 
-       if (using_charge) {
+       switch (source) {
+       case SOURCE_CHARGE:
                full_prop = POWER_SUPPLY_PROP_CHARGE_FULL;
                empty_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
                full_design_prop = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
                empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN;
                now_prop = POWER_SUPPLY_PROP_CHARGE_NOW;
                avg_prop = POWER_SUPPLY_PROP_CHARGE_AVG;
-       } else {
+               break;
+       case SOURCE_ENERGY:
                full_prop = POWER_SUPPLY_PROP_ENERGY_FULL;
                empty_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY;
                full_design_prop = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
                empty_design_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN;
                now_prop = POWER_SUPPLY_PROP_ENERGY_NOW;
                avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG;
+       case SOURCE_VOLTAGE:
+               full_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX;
+               empty_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN;
+               full_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN;
+               empty_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN;
+               now_prop = POWER_SUPPLY_PROP_VOLTAGE_NOW;
+               avg_prop = POWER_SUPPLY_PROP_VOLTAGE_AVG;
+               break;
+       default:
+               printk(KERN_ERR "Unsupported source: %d\n", source);
+               return -1;
        }
 
        if (_MPSY_PROP(full_prop, &full)) {
@@ -254,10 +310,12 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
                info->battery_life = capacity.intval;
        } else {
                /* try calculate using energy */
-               info->battery_life = calculate_capacity(0);
+               info->battery_life = calculate_capacity(SOURCE_ENERGY);
                /* if failed try calculate using charge instead */
                if (info->battery_life == -1)
-                       info->battery_life = calculate_capacity(1);
+                       info->battery_life = calculate_capacity(SOURCE_CHARGE);
+               if (info->battery_life == -1)
+                       info->battery_life = calculate_capacity(SOURCE_VOLTAGE);
        }
 
        /* charging status */
@@ -280,22 +338,16 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
 
        if (status.intval == POWER_SUPPLY_STATUS_CHARGING) {
                if (!MPSY_PROP(TIME_TO_FULL_AVG, &time_to_full) ||
-                               !MPSY_PROP(TIME_TO_FULL_NOW, &time_to_full)) {
+                               !MPSY_PROP(TIME_TO_FULL_NOW, &time_to_full))
                        info->time = time_to_full.intval / 60;
-               } else {
-                       info->time = calculate_time(status.intval, 0);
-                       if (info->time == -1)
-                               info->time = calculate_time(status.intval, 1);
-               }
+               else
+                       info->time = calculate_time(status.intval);
        } else {
                if (!MPSY_PROP(TIME_TO_EMPTY_AVG, &time_to_empty) ||
-                             !MPSY_PROP(TIME_TO_EMPTY_NOW, &time_to_empty)) {
+                             !MPSY_PROP(TIME_TO_EMPTY_NOW, &time_to_empty))
                        info->time = time_to_empty.intval / 60;
-               } else {
-                       info->time = calculate_time(status.intval, 0);
-                       if (info->time == -1)
-                               info->time = calculate_time(status.intval, 1);
-               }
+               else
+                       info->time = calculate_time(status.intval);
        }
 
        mutex_unlock(&apm_mutex);
index c998e68d060f912ffe49b90edf482a1cc8640746..af7a231092a461052af4408f6e127901622e4f29 100644 (file)
@@ -226,14 +226,6 @@ static int olpc_bat_get_property(struct power_supply *psy,
                        return ret;
                val->intval = ec_byte;
                break;
-       case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
-               if (ec_byte & BAT_STAT_FULL)
-                       val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
-               else if (ec_byte & BAT_STAT_LOW)
-                       val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
-               else
-                       val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
-               break;
        case POWER_SUPPLY_PROP_TEMP:
                ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
                if (ret)
@@ -265,7 +257,6 @@ static enum power_supply_property olpc_bat_props[] = {
        POWER_SUPPLY_PROP_VOLTAGE_AVG,
        POWER_SUPPLY_PROP_CURRENT_AVG,
        POWER_SUPPLY_PROP_CAPACITY,
-       POWER_SUPPLY_PROP_CAPACITY_LEVEL,
        POWER_SUPPLY_PROP_TEMP,
        POWER_SUPPLY_PROP_TEMP_AMBIENT,
        POWER_SUPPLY_PROP_MANUFACTURER,
index c058f285be1a2c8e850ebfec9b9db0a3d29ef017..c8aa55b81fd86458f7c5dbcdcbc486a81c8cb5a7 100644 (file)
@@ -32,6 +32,18 @@ static struct pda_power_pdata *pdata;
 static struct resource *ac_irq, *usb_irq;
 static struct timer_list charger_timer;
 static struct timer_list supply_timer;
+static struct timer_list polling_timer;
+static int polling;
+
+enum {
+       PDA_PSY_OFFLINE = 0,
+       PDA_PSY_ONLINE = 1,
+       PDA_PSY_TO_CHANGE,
+};
+static int new_ac_status = -1;
+static int new_usb_status = -1;
+static int ac_status = -1;
+static int usb_status = -1;
 
 static int pda_power_get_property(struct power_supply *psy,
                                  enum power_supply_property psp,
@@ -61,36 +73,44 @@ static char *pda_power_supplied_to[] = {
        "backup-battery",
 };
 
-static struct power_supply pda_power_supplies[] = {
-       {
-               .name = "ac",
-               .type = POWER_SUPPLY_TYPE_MAINS,
-               .supplied_to = pda_power_supplied_to,
-               .num_supplicants = ARRAY_SIZE(pda_power_supplied_to),
-               .properties = pda_power_props,
-               .num_properties = ARRAY_SIZE(pda_power_props),
-               .get_property = pda_power_get_property,
-       },
-       {
-               .name = "usb",
-               .type = POWER_SUPPLY_TYPE_USB,
-               .supplied_to = pda_power_supplied_to,
-               .num_supplicants = ARRAY_SIZE(pda_power_supplied_to),
-               .properties = pda_power_props,
-               .num_properties = ARRAY_SIZE(pda_power_props),
-               .get_property = pda_power_get_property,
-       },
+static struct power_supply pda_psy_ac = {
+       .name = "ac",
+       .type = POWER_SUPPLY_TYPE_MAINS,
+       .supplied_to = pda_power_supplied_to,
+       .num_supplicants = ARRAY_SIZE(pda_power_supplied_to),
+       .properties = pda_power_props,
+       .num_properties = ARRAY_SIZE(pda_power_props),
+       .get_property = pda_power_get_property,
 };
 
+static struct power_supply pda_psy_usb = {
+       .name = "usb",
+       .type = POWER_SUPPLY_TYPE_USB,
+       .supplied_to = pda_power_supplied_to,
+       .num_supplicants = ARRAY_SIZE(pda_power_supplied_to),
+       .properties = pda_power_props,
+       .num_properties = ARRAY_SIZE(pda_power_props),
+       .get_property = pda_power_get_property,
+};
+
+static void update_status(void)
+{
+       if (pdata->is_ac_online)
+               new_ac_status = !!pdata->is_ac_online();
+
+       if (pdata->is_usb_online)
+               new_usb_status = !!pdata->is_usb_online();
+}
+
 static void update_charger(void)
 {
        if (!pdata->set_charge)
                return;
 
-       if (pdata->is_ac_online && pdata->is_ac_online()) {
+       if (new_ac_status > 0) {
                dev_dbg(dev, "charger on (AC)\n");
                pdata->set_charge(PDA_POWER_CHARGE_AC);
-       } else if (pdata->is_usb_online && pdata->is_usb_online()) {
+       } else if (new_usb_status > 0) {
                dev_dbg(dev, "charger on (USB)\n");
                pdata->set_charge(PDA_POWER_CHARGE_USB);
        } else {
@@ -99,34 +119,81 @@ static void update_charger(void)
        }
 }
 
-static void supply_timer_func(unsigned long power_supply_ptr)
+static void supply_timer_func(unsigned long unused)
 {
-       void *power_supply = (void *)power_supply_ptr;
+       if (ac_status == PDA_PSY_TO_CHANGE) {
+               ac_status = new_ac_status;
+               power_supply_changed(&pda_psy_ac);
+       }
 
-       power_supply_changed(power_supply);
+       if (usb_status == PDA_PSY_TO_CHANGE) {
+               usb_status = new_usb_status;
+               power_supply_changed(&pda_psy_usb);
+       }
 }
 
-static void charger_timer_func(unsigned long power_supply_ptr)
+static void psy_changed(void)
 {
        update_charger();
 
-       /* Okay, charger set. Now wait a bit before notifying supplicants,
-        * charge power should stabilize. */
-       supply_timer.data = power_supply_ptr;
+       /*
+        * Okay, charger set. Now wait a bit before notifying supplicants,
+        * charge power should stabilize.
+        */
        mod_timer(&supply_timer,
                  jiffies + msecs_to_jiffies(pdata->wait_for_charger));
 }
 
+static void charger_timer_func(unsigned long unused)
+{
+       update_status();
+       psy_changed();
+}
+
 static irqreturn_t power_changed_isr(int irq, void *power_supply)
 {
-       /* Wait a bit before reading ac/usb line status and setting charger,
-        * because ac/usb status readings may lag from irq. */
-       charger_timer.data = (unsigned long)power_supply;
+       if (power_supply == &pda_psy_ac)
+               ac_status = PDA_PSY_TO_CHANGE;
+       else if (power_supply == &pda_psy_usb)
+               usb_status = PDA_PSY_TO_CHANGE;
+       else
+               return IRQ_NONE;
+
+       /*
+        * Wait a bit before reading ac/usb line status and setting charger,
+        * because ac/usb status readings may lag from irq.
+        */
        mod_timer(&charger_timer,
                  jiffies + msecs_to_jiffies(pdata->wait_for_status));
+
        return IRQ_HANDLED;
 }
 
+static void polling_timer_func(unsigned long unused)
+{
+       int changed = 0;
+
+       dev_dbg(dev, "polling...\n");
+
+       update_status();
+
+       if (!ac_irq && new_ac_status != ac_status) {
+               ac_status = PDA_PSY_TO_CHANGE;
+               changed = 1;
+       }
+
+       if (!usb_irq && new_usb_status != usb_status) {
+               usb_status = PDA_PSY_TO_CHANGE;
+               changed = 1;
+       }
+
+       if (changed)
+               psy_changed();
+
+       mod_timer(&polling_timer,
+                 jiffies + msecs_to_jiffies(pdata->polling_interval));
+}
+
 static int pda_power_probe(struct platform_device *pdev)
 {
        int ret = 0;
@@ -142,6 +209,7 @@ static int pda_power_probe(struct platform_device *pdev)
 
        pdata = pdev->dev.platform_data;
 
+       update_status();
        update_charger();
 
        if (!pdata->wait_for_status)
@@ -150,86 +218,138 @@ static int pda_power_probe(struct platform_device *pdev)
        if (!pdata->wait_for_charger)
                pdata->wait_for_charger = 500;
 
+       if (!pdata->polling_interval)
+               pdata->polling_interval = 2000;
+
        setup_timer(&charger_timer, charger_timer_func, 0);
        setup_timer(&supply_timer, supply_timer_func, 0);
 
        ac_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ac");
        usb_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "usb");
-       if (!ac_irq && !usb_irq) {
-               dev_err(dev, "no ac/usb irq specified\n");
-               ret = -ENODEV;
-               goto noirqs;
-       }
 
        if (pdata->supplied_to) {
-               pda_power_supplies[0].supplied_to = pdata->supplied_to;
-               pda_power_supplies[1].supplied_to = pdata->supplied_to;
-               pda_power_supplies[0].num_supplicants = pdata->num_supplicants;
-               pda_power_supplies[1].num_supplicants = pdata->num_supplicants;
+               pda_psy_ac.supplied_to = pdata->supplied_to;
+               pda_psy_ac.num_supplicants = pdata->num_supplicants;
+               pda_psy_usb.supplied_to = pdata->supplied_to;
+               pda_psy_usb.num_supplicants = pdata->num_supplicants;
        }
 
-       ret = power_supply_register(&pdev->dev, &pda_power_supplies[0]);
-       if (ret) {
-               dev_err(dev, "failed to register %s power supply\n",
-                       pda_power_supplies[0].name);
-               goto supply0_failed;
-       }
+       if (pdata->is_ac_online) {
+               ret = power_supply_register(&pdev->dev, &pda_psy_ac);
+               if (ret) {
+                       dev_err(dev, "failed to register %s power supply\n",
+                               pda_psy_ac.name);
+                       goto ac_supply_failed;
+               }
 
-       ret = power_supply_register(&pdev->dev, &pda_power_supplies[1]);
-       if (ret) {
-               dev_err(dev, "failed to register %s power supply\n",
-                       pda_power_supplies[1].name);
-               goto supply1_failed;
+               if (ac_irq) {
+                       ret = request_irq(ac_irq->start, power_changed_isr,
+                                         get_irq_flags(ac_irq), ac_irq->name,
+                                         &pda_psy_ac);
+                       if (ret) {
+                               dev_err(dev, "request ac irq failed\n");
+                               goto ac_irq_failed;
+                       }
+               } else {
+                       polling = 1;
+               }
        }
 
-       if (ac_irq) {
-               ret = request_irq(ac_irq->start, power_changed_isr,
-                                 get_irq_flags(ac_irq), ac_irq->name,
-                                 &pda_power_supplies[0]);
+       if (pdata->is_usb_online) {
+               ret = power_supply_register(&pdev->dev, &pda_psy_usb);
                if (ret) {
-                       dev_err(dev, "request ac irq failed\n");
-                       goto ac_irq_failed;
+                       dev_err(dev, "failed to register %s power supply\n",
+                               pda_psy_usb.name);
+                       goto usb_supply_failed;
                }
-       }
 
-       if (usb_irq) {
-               ret = request_irq(usb_irq->start, power_changed_isr,
-                                 get_irq_flags(usb_irq), usb_irq->name,
-                                 &pda_power_supplies[1]);
-               if (ret) {
-                       dev_err(dev, "request usb irq failed\n");
-                       goto usb_irq_failed;
+               if (usb_irq) {
+                       ret = request_irq(usb_irq->start, power_changed_isr,
+                                         get_irq_flags(usb_irq),
+                                         usb_irq->name, &pda_psy_usb);
+                       if (ret) {
+                               dev_err(dev, "request usb irq failed\n");
+                               goto usb_irq_failed;
+                       }
+               } else {
+                       polling = 1;
                }
        }
 
-       goto success;
+       if (polling) {
+               dev_dbg(dev, "will poll for status\n");
+               setup_timer(&polling_timer, polling_timer_func, 0);
+               mod_timer(&polling_timer,
+                         jiffies + msecs_to_jiffies(pdata->polling_interval));
+       }
+
+       if (ac_irq || usb_irq)
+               device_init_wakeup(&pdev->dev, 1);
+
+       return 0;
 
 usb_irq_failed:
-       if (ac_irq)
-               free_irq(ac_irq->start, &pda_power_supplies[0]);
+       if (pdata->is_usb_online)
+               power_supply_unregister(&pda_psy_usb);
+usb_supply_failed:
+       if (pdata->is_ac_online && ac_irq)
+               free_irq(ac_irq->start, &pda_psy_ac);
 ac_irq_failed:
-       power_supply_unregister(&pda_power_supplies[1]);
-supply1_failed:
-       power_supply_unregister(&pda_power_supplies[0]);
-supply0_failed:
-noirqs:
+       if (pdata->is_ac_online)
+               power_supply_unregister(&pda_psy_ac);
+ac_supply_failed:
 wrongid:
-success:
        return ret;
 }
 
 static int pda_power_remove(struct platform_device *pdev)
 {
-       if (usb_irq)
-               free_irq(usb_irq->start, &pda_power_supplies[1]);
-       if (ac_irq)
-               free_irq(ac_irq->start, &pda_power_supplies[0]);
+       if (pdata->is_usb_online && usb_irq)
+               free_irq(usb_irq->start, &pda_psy_usb);
+       if (pdata->is_ac_online && ac_irq)
+               free_irq(ac_irq->start, &pda_psy_ac);
+
+       if (polling)
+               del_timer_sync(&polling_timer);
        del_timer_sync(&charger_timer);
        del_timer_sync(&supply_timer);
-       power_supply_unregister(&pda_power_supplies[1]);
-       power_supply_unregister(&pda_power_supplies[0]);
+
+       if (pdata->is_usb_online)
+               power_supply_unregister(&pda_psy_usb);
+       if (pdata->is_ac_online)
+               power_supply_unregister(&pda_psy_ac);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int pda_power_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       if (device_may_wakeup(&pdev->dev)) {
+               if (ac_irq)
+                       enable_irq_wake(ac_irq->start);
+               if (usb_irq)
+                       enable_irq_wake(usb_irq->start);
+       }
+
+       return 0;
+}
+
+static int pda_power_resume(struct platform_device *pdev)
+{
+       if (device_may_wakeup(&pdev->dev)) {
+               if (usb_irq)
+                       disable_irq_wake(usb_irq->start);
+               if (ac_irq)
+                       disable_irq_wake(ac_irq->start);
+       }
+
        return 0;
 }
+#else
+#define pda_power_suspend NULL
+#define pda_power_resume NULL
+#endif /* CONFIG_PM */
 
 static struct platform_driver pda_power_pdrv = {
        .driver = {
@@ -237,6 +357,8 @@ static struct platform_driver pda_power_pdrv = {
        },
        .probe = pda_power_probe,
        .remove = pda_power_remove,
+       .suspend = pda_power_suspend,
+       .resume = pda_power_resume,
 };
 
 static int __init pda_power_init(void)
index 7f8f3590b02e6934e6066e5d63bb40a6f7440af9..fa3034f85c382d4a3dc3b5bdb6ed36469c46042a 100644 (file)
  *  You may use this code as per GPL version 2
  */
 
+#include <linux/kernel.h>
 #include <linux/power_supply.h>
 
+#include "power_supply.h"
+
 /* Battery specific LEDs triggers. */
 
 static void power_supply_update_bat_leds(struct power_supply *psy)
@@ -46,28 +49,20 @@ static int power_supply_create_bat_triggers(struct power_supply *psy)
 {
        int rc = 0;
 
-       psy->charging_full_trig_name = kmalloc(strlen(psy->name) +
-                                 sizeof("-charging-or-full"), GFP_KERNEL);
+       psy->charging_full_trig_name = kasprintf(GFP_KERNEL,
+                                       "%s-charging-or-full", psy->name);
        if (!psy->charging_full_trig_name)
                goto charging_full_failed;
 
-       psy->charging_trig_name = kmalloc(strlen(psy->name) +
-                                         sizeof("-charging"), GFP_KERNEL);
+       psy->charging_trig_name = kasprintf(GFP_KERNEL,
+                                       "%s-charging", psy->name);
        if (!psy->charging_trig_name)
                goto charging_failed;
 
-       psy->full_trig_name = kmalloc(strlen(psy->name) +
-                                     sizeof("-full"), GFP_KERNEL);
+       psy->full_trig_name = kasprintf(GFP_KERNEL, "%s-full", psy->name);
        if (!psy->full_trig_name)
                goto full_failed;
 
-       strcpy(psy->charging_full_trig_name, psy->name);
-       strcat(psy->charging_full_trig_name, "-charging-or-full");
-       strcpy(psy->charging_trig_name, psy->name);
-       strcat(psy->charging_trig_name, "-charging");
-       strcpy(psy->full_trig_name, psy->name);
-       strcat(psy->full_trig_name, "-full");
-
        led_trigger_register_simple(psy->charging_full_trig_name,
                                    &psy->charging_full_trig);
        led_trigger_register_simple(psy->charging_trig_name,
@@ -118,14 +113,10 @@ static int power_supply_create_gen_triggers(struct power_supply *psy)
 {
        int rc = 0;
 
-       psy->online_trig_name = kmalloc(strlen(psy->name) + sizeof("-online"),
-                                       GFP_KERNEL);
+       psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online", psy->name);
        if (!psy->online_trig_name)
                goto online_failed;
 
-       strcpy(psy->online_trig_name, psy->name);
-       strcat(psy->online_trig_name, "-online");
-
        led_trigger_register_simple(psy->online_trig_name, &psy->online_trig);
 
        goto success;
index 249f61bae6396105b2466739c504dd2b6557b775..ad2bed0174d63944356a2befb4bef2eb3a562036 100644 (file)
@@ -14,6 +14,8 @@
 #include <linux/ctype.h>
 #include <linux/power_supply.h>
 
+#include "power_supply.h"
+
 /*
  * This is because the name "current" breaks the device attr macro.
  * The "current" word resolves to "(get_current())" so instead of
@@ -46,10 +48,8 @@ static ssize_t power_supply_show_property(struct device *dev,
                "Unspecified failure"
        };
        static char *technology_text[] = {
-               "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd"
-       };
-       static char *capacity_level_text[] = {
-               "Unknown", "Critical", "Low", "Normal", "High", "Full"
+               "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd",
+               "LiMn"
        };
        ssize_t ret;
        struct power_supply *psy = dev_get_drvdata(dev);
@@ -71,9 +71,6 @@ static ssize_t power_supply_show_property(struct device *dev,
                return sprintf(buf, "%s\n", health_text[value.intval]);
        else if (off == POWER_SUPPLY_PROP_TECHNOLOGY)
                return sprintf(buf, "%s\n", technology_text[value.intval]);
-       else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL)
-               return sprintf(buf, "%s\n",
-                              capacity_level_text[value.intval]);
        else if (off >= POWER_SUPPLY_PROP_MODEL_NAME)
                return sprintf(buf, "%s\n", value.strval);
 
@@ -88,6 +85,8 @@ static struct device_attribute power_supply_attrs[] = {
        POWER_SUPPLY_ATTR(present),
        POWER_SUPPLY_ATTR(online),
        POWER_SUPPLY_ATTR(technology),
+       POWER_SUPPLY_ATTR(voltage_max),
+       POWER_SUPPLY_ATTR(voltage_min),
        POWER_SUPPLY_ATTR(voltage_max_design),
        POWER_SUPPLY_ATTR(voltage_min_design),
        POWER_SUPPLY_ATTR(voltage_now),
@@ -117,6 +116,7 @@ static struct device_attribute power_supply_attrs[] = {
        /* Properties of type `const char *' */
        POWER_SUPPLY_ATTR(model_name),
        POWER_SUPPLY_ATTR(manufacturer),
+       POWER_SUPPLY_ATTR(serial_number),
 };
 
 static ssize_t power_supply_show_static_attrs(struct device *dev,
@@ -159,8 +159,7 @@ dynamics_failed:
                           &power_supply_attrs[psy->properties[j]]);
 statics_failed:
        while (i--)
-               device_remove_file(psy->dev,
-                          &power_supply_static_attrs[psy->properties[i]]);
+               device_remove_file(psy->dev, &power_supply_static_attrs[i]);
 succeed:
        return rc;
 }
@@ -170,8 +169,7 @@ void power_supply_remove_attrs(struct power_supply *psy)
        int i;
 
        for (i = 0; i < ARRAY_SIZE(power_supply_static_attrs); i++)
-               device_remove_file(psy->dev,
-                           &power_supply_static_attrs[i]);
+               device_remove_file(psy->dev, &power_supply_static_attrs[i]);
 
        for (i = 0; i < psy->num_properties; i++)
                device_remove_file(psy->dev,
index 87b3493d88e5bea0f93b3fc0ef412bbb1232a722..6f2f90ebb020db95256f2bc135414ada5ca77d83 100644 (file)
@@ -78,23 +78,21 @@ static const struct avset_video_mode {
        u32 aspect;
        u32 x;
        u32 y;
-       u32 interlace;
-       u32 freq;
 } video_mode_table[] = {
        {     0, }, /* auto */
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480I,       A_N,  720,  480, 1, 60},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480P,       A_N,  720,  480, 0, 60},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_60HZ,  A_N, 1280,  720, 0, 60},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_60HZ, A_W, 1920, 1080, 1, 60},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_60HZ, A_W, 1920, 1080, 0, 60},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576I,       A_N,  720,  576, 1, 50},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576P,       A_N,  720,  576, 0, 50},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_50HZ,  A_N, 1280,  720, 0, 50},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_50HZ, A_W, 1920, 1080, 1, 50},
-       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_50HZ, A_W, 1920, 1080, 0, 50},
-       {  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WXGA,       A_W, 1280,  768, 0, 60},
-       {  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_SXGA,       A_N, 1280, 1024, 0, 60},
-       {  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WUXGA,      A_W, 1920, 1200, 0, 60},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480I,       A_N,  720,  480},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480P,       A_N,  720,  480},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_60HZ,  A_N, 1280,  720},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_60HZ, A_W, 1920, 1080},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_60HZ, A_W, 1920, 1080},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576I,       A_N,  720,  576},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576P,       A_N,  720,  576},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_50HZ,  A_N, 1280,  720},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_50HZ, A_W, 1920, 1080},
+       {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_50HZ, A_W, 1920, 1080},
+       {  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WXGA,       A_W, 1280,  768},
+       {  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_SXGA,       A_N, 1280, 1024},
+       {  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WUXGA,      A_W, 1920, 1200},
 };
 
 /* supported CIDs */
@@ -544,7 +542,7 @@ static void ps3av_set_videomode_packet(u32 id)
 
 static void ps3av_set_videomode_cont(u32 id, u32 old_id)
 {
-       static int vesa = 0;
+       static int vesa;
        int res;
 
        /* video signal off */
@@ -554,9 +552,9 @@ static void ps3av_set_videomode_cont(u32 id, u32 old_id)
         * AV backend needs non-VESA mode setting at least one time
         * when VESA mode is used.
         */
-       if (vesa == 0 && (id & PS3AV_MODE_MASK) >= 11) {
+       if (vesa == 0 && (id & PS3AV_MODE_MASK) >= PS3AV_MODE_WXGA) {
                /* vesa mode */
-               ps3av_set_videomode_packet(2);  /* 480P */
+               ps3av_set_videomode_packet(PS3AV_MODE_480P);
        }
        vesa = 1;
 
@@ -596,20 +594,21 @@ static const struct {
        unsigned mask : 19;
        unsigned id :  4;
 } ps3av_preferred_modes[] = {
-       { .mask = PS3AV_RESBIT_WUXGA            << SHIFT_VESA,  .id = 13 },
-       { .mask = PS3AV_RESBIT_1920x1080P       << SHIFT_60,    .id = 5 },
-       { .mask = PS3AV_RESBIT_1920x1080P       << SHIFT_50,    .id = 10 },
-       { .mask = PS3AV_RESBIT_1920x1080I       << SHIFT_60,    .id = 4 },
-       { .mask = PS3AV_RESBIT_1920x1080I       << SHIFT_50,    .id = 9 },
-       { .mask = PS3AV_RESBIT_SXGA             << SHIFT_VESA,  .id = 12 },
-       { .mask = PS3AV_RESBIT_WXGA             << SHIFT_VESA,  .id = 11 },
-       { .mask = PS3AV_RESBIT_1280x720P        << SHIFT_60,    .id = 3 },
-       { .mask = PS3AV_RESBIT_1280x720P        << SHIFT_50,    .id = 8 },
-       { .mask = PS3AV_RESBIT_720x480P         << SHIFT_60,    .id = 2 },
-       { .mask = PS3AV_RESBIT_720x576P         << SHIFT_50,    .id = 7 },
+       { PS3AV_RESBIT_WUXGA      << SHIFT_VESA, PS3AV_MODE_WUXGA   },
+       { PS3AV_RESBIT_1920x1080P << SHIFT_60,   PS3AV_MODE_1080P60 },
+       { PS3AV_RESBIT_1920x1080P << SHIFT_50,   PS3AV_MODE_1080P50 },
+       { PS3AV_RESBIT_1920x1080I << SHIFT_60,   PS3AV_MODE_1080I60 },
+       { PS3AV_RESBIT_1920x1080I << SHIFT_50,   PS3AV_MODE_1080I50 },
+       { PS3AV_RESBIT_SXGA       << SHIFT_VESA, PS3AV_MODE_SXGA    },
+       { PS3AV_RESBIT_WXGA       << SHIFT_VESA, PS3AV_MODE_WXGA    },
+       { PS3AV_RESBIT_1280x720P  << SHIFT_60,   PS3AV_MODE_720P60  },
+       { PS3AV_RESBIT_1280x720P  << SHIFT_50,   PS3AV_MODE_720P50  },
+       { PS3AV_RESBIT_720x480P   << SHIFT_60,   PS3AV_MODE_480P    },
+       { PS3AV_RESBIT_720x576P   << SHIFT_50,   PS3AV_MODE_576P    },
 };
 
-static int ps3av_resbit2id(u32 res_50, u32 res_60, u32 res_vesa)
+static enum ps3av_mode_num ps3av_resbit2id(u32 res_50, u32 res_60,
+                                          u32 res_vesa)
 {
        unsigned int i;
        u32 res_all;
@@ -638,9 +637,9 @@ static int ps3av_resbit2id(u32 res_50, u32 res_60, u32 res_vesa)
        return 0;
 }
 
-static int ps3av_hdmi_get_id(struct ps3av_info_monitor *info)
+static enum ps3av_mode_num ps3av_hdmi_get_id(struct ps3av_info_monitor *info)
 {
-       int id;
+       enum ps3av_mode_num id;
 
        if (safe_mode)
                return PS3AV_DEFAULT_HDMI_MODE_ID_REG_60;
@@ -854,7 +853,7 @@ int ps3av_set_video_mode(u32 id)
 
        /* auto mode */
        option = id & ~PS3AV_MODE_MASK;
-       if ((id & PS3AV_MODE_MASK) == 0) {
+       if ((id & PS3AV_MODE_MASK) == PS3AV_MODE_AUTO) {
                id = ps3av_auto_videomode(&ps3av->av_hw_conf);
                if (id < 1) {
                        printk(KERN_ERR "%s: invalid id :%d\n", __func__, id);
@@ -889,36 +888,6 @@ int ps3av_get_mode(void)
 
 EXPORT_SYMBOL_GPL(ps3av_get_mode);
 
-int ps3av_get_scanmode(int id)
-{
-       int size;
-
-       id = id & PS3AV_MODE_MASK;
-       size = ARRAY_SIZE(video_mode_table);
-       if (id > size - 1 || id < 0) {
-               printk(KERN_ERR "%s: invalid mode %d\n", __func__, id);
-               return -EINVAL;
-       }
-       return video_mode_table[id].interlace;
-}
-
-EXPORT_SYMBOL_GPL(ps3av_get_scanmode);
-
-int ps3av_get_refresh_rate(int id)
-{
-       int size;
-
-       id = id & PS3AV_MODE_MASK;
-       size = ARRAY_SIZE(video_mode_table);
-       if (id > size - 1 || id < 0) {
-               printk(KERN_ERR "%s: invalid mode %d\n", __func__, id);
-               return -EINVAL;
-       }
-       return video_mode_table[id].freq;
-}
-
-EXPORT_SYMBOL_GPL(ps3av_get_refresh_rate);
-
 /* get resolution by video_mode */
 int ps3av_video_mode2res(u32 id, u32 *xres, u32 *yres)
 {
@@ -990,7 +959,7 @@ static int ps3av_probe(struct ps3_system_bus_device *dev)
                return -ENOMEM;
 
        mutex_init(&ps3av->mutex);
-       ps3av->ps3av_mode = 0;
+       ps3av->ps3av_mode = PS3AV_MODE_AUTO;
        ps3av->dev = dev;
 
        INIT_WORK(&ps3av->work, ps3avd);
index 45e4b9648176f07f27ba05ac53d3d8e07639ba22..6402d699072b5a28a11069a5188dd2e34245a079 100644 (file)
@@ -20,6 +20,10 @@ menuconfig RTC_CLASS
 
 if RTC_CLASS
 
+if GEN_RTC || RTC
+comment "Conflicting RTC option has been selected, check GEN_RTC and RTC"
+endif
+
 config RTC_HCTOSYS
        bool "Set system time from RTC on startup and resume"
        depends on RTC_CLASS = y
@@ -49,7 +53,7 @@ config RTC_HCTOSYS_DEVICE
 
          If the clock you specify here is not battery backed, it may still
          be useful to reinitialize system time when resuming from system
-         sleep states.  Do not specify an RTC here unless it stays powered
+         sleep states. Do not specify an RTC here unless it stays powered
          during all this system's supported sleep states.
 
 config RTC_DEBUG
@@ -142,7 +146,7 @@ config RTC_DRV_DS1307
          will be called rtc-ds1307.
 
 config RTC_DRV_DS1374
-       tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock"
+       tristate "Dallas/Maxim DS1374"
        depends on RTC_CLASS && I2C
        help
          If you say yes here you get support for Dallas Semiconductor
@@ -162,7 +166,7 @@ config RTC_DRV_DS1672
          will be called rtc-ds1672.
 
 config RTC_DRV_MAX6900
-       tristate "Maxim 6900"
+       tristate "Maxim MAX6900"
        help
          If you say yes here you will get support for the
          Maxim MAX6900 I2C RTC chip.
@@ -180,10 +184,10 @@ config RTC_DRV_RS5C372
          will be called rtc-rs5c372.
 
 config RTC_DRV_ISL1208
-       tristate "Intersil 1208"
+       tristate "Intersil ISL1208"
        help
          If you say yes here you get support for the
-         Intersil 1208 RTC chip.
+         Intersil ISL1208 RTC chip.
 
          This driver can also be built as a module. If so, the module
          will be called rtc-isl1208.
@@ -220,7 +224,7 @@ config RTC_DRV_PCF8583
          will be called rtc-pcf8583.
 
 config RTC_DRV_M41T80
-       tristate "ST M41T80 series RTC"
+       tristate "ST M41T80/81/82/83/84/85/87"
        help
          If you say Y here you will get support for the
          ST M41T80 RTC chips series. Currently following chips are
@@ -252,23 +256,32 @@ comment "SPI RTC drivers"
 
 if SPI_MASTER
 
-config RTC_DRV_RS5C348
-       tristate "Ricoh RS5C348A/B"
+config RTC_DRV_MAX6902
+       tristate "Maxim MAX6902"
        help
-         If you say yes here you get support for the
-         Ricoh RS5C348A and RS5C348B RTC chips.
+         If you say yes here you will get support for the
+         Maxim MAX6902 SPI RTC chip.
 
          This driver can also be built as a module. If so, the module
-         will be called rtc-rs5c348.
+         will be called rtc-max6902.
 
-config RTC_DRV_MAX6902
-       tristate "Maxim 6902"
+config RTC_DRV_R9701
+       tristate "Epson RTC-9701JE"
        help
          If you say yes here you will get support for the
-         Maxim MAX6902 SPI RTC chip.
+         Epson RTC-9701JE SPI RTC chip.
 
          This driver can also be built as a module. If so, the module
-         will be called rtc-max6902.
+         will be called rtc-r9701.
+
+config RTC_DRV_RS5C348
+       tristate "Ricoh RS5C348A/B"
+       help
+         If you say yes here you get support for the
+         Ricoh RS5C348A and RS5C348B RTC chips.
+
+         This driver can also be built as a module. If so, the module
+         will be called rtc-rs5c348.
 
 endif # SPI_MASTER
 
@@ -302,34 +315,50 @@ config RTC_DRV_DS1216
        help
          If you say yes here you get support for the Dallas DS1216 RTC chips.
 
-config RTC_DRV_DS1553
-       tristate "Dallas DS1553"
+config RTC_DRV_DS1302
+       tristate "Dallas DS1302"
+       depends on SH_SECUREEDGE5410
+       help
+         If you say yes here you get support for the Dallas DS1302 RTC chips.
+
+config RTC_DRV_DS1511
+       tristate "Dallas DS1511"
+       depends on RTC_CLASS
        help
          If you say yes here you get support for the
-         Dallas DS1553 timekeeping chip.
+         Dallas DS1511 timekeeping/watchdog chip.
 
          This driver can also be built as a module. If so, the module
-         will be called rtc-ds1553.
+         will be called rtc-ds1511.
 
-config RTC_DRV_STK17TA8
-       tristate "Simtek STK17TA8"
-       depends on RTC_CLASS
+config RTC_DRV_DS1553
+       tristate "Maxim/Dallas DS1553"
        help
          If you say yes here you get support for the
-         Simtek STK17TA8 timekeeping chip.
+         Maxim/Dallas DS1553 timekeeping chip.
 
          This driver can also be built as a module. If so, the module
-         will be called rtc-stk17ta8.
+         will be called rtc-ds1553.
 
 config RTC_DRV_DS1742
-       tristate "Dallas DS1742/1743"
+       tristate "Maxim/Dallas DS1742/1743"
        help
          If you say yes here you get support for the
-         Dallas DS1742/1743 timekeeping chip.
+         Maxim/Dallas DS1742/1743 timekeeping chip.
 
          This driver can also be built as a module. If so, the module
          will be called rtc-ds1742.
 
+config RTC_DRV_STK17TA8
+       tristate "Simtek STK17TA8"
+       depends on RTC_CLASS
+       help
+         If you say yes here you get support for the
+         Simtek STK17TA8 timekeeping chip.
+
+         This driver can also be built as a module. If so, the module
+         will be called rtc-stk17ta8.
+
 config RTC_DRV_M48T86
        tristate "ST M48T86/Dallas DS12887"
        help
@@ -440,10 +469,47 @@ config RTC_DRV_AT32AP700X
          AT32AP700x family processors.
 
 config RTC_DRV_AT91RM9200
-       tristate "AT91RM9200"
-       depends on ARCH_AT91RM9200
-       help
-         Driver for the Atmel AT91RM9200's internal RTC (Realtime Clock).
+       tristate "AT91RM9200 or AT91SAM9RL"
+       depends on ARCH_AT91RM9200 || ARCH_AT91SAM9RL
+       help
+         Driver for the internal RTC (Realtime Clock) module found on
+         Atmel AT91RM9200's and AT91SAM9RL chips.  On SAM9RL chips
+         this is powered by the backup power supply.
+
+config RTC_DRV_AT91SAM9
+       tristate "AT91SAM9x"
+       depends on ARCH_AT91 && !(ARCH_AT91RM9200 || ARCH_AT91X40)
+       help
+         RTC driver for the Atmel AT91SAM9x internal RTT (Real Time Timer).
+         These timers are powered by the backup power supply (such as a
+         small coin cell battery), but do not need to be used as RTCs.
+
+         (On AT91SAM9rl chips you probably want to use the dedicated RTC
+         module and leave the RTT available for other uses.)
+
+config RTC_DRV_AT91SAM9_RTT
+       int
+       range 0 1
+       default 0
+       prompt "RTT module Number" if ARCH_AT91SAM9263
+       depends on RTC_DRV_AT91SAM9
+       help
+         More than one RTT module is available.  You can choose which
+         one will be used as an RTC.  The default of zero is normally
+         OK to use, though some systems use that for non-RTC purposes.
+
+config RTC_DRV_AT91SAM9_GPBR
+       int
+       range 0 3 if !ARCH_AT91SAM9263
+       range 0 15 if ARCH_AT91SAM9263
+       default 0
+       prompt "Backup Register Number"
+       depends on RTC_DRV_AT91SAM9
+       help
+         The RTC driver needs to use one of the General Purpose Backup
+         Registers (GPBRs) as well as the RTT.  You can choose which one
+         will be used.  The default of zero is normally OK to use, but
+         on some systems other software needs to use that register.
 
 config RTC_DRV_BFIN
        tristate "Blackfin On-Chip RTC"
index 465db4dd50b2e97232098c1287bbbcacc31db3cc..ec703f34ab864da930d3eadbe594d0ca67fb5bfa 100644 (file)
@@ -19,11 +19,14 @@ rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
 
 obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
+obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
 obj-$(CONFIG_RTC_DRV_BFIN)     += rtc-bfin.o
 obj-$(CONFIG_RTC_DRV_CMOS)     += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_DS1216)   += rtc-ds1216.o
+obj-$(CONFIG_RTC_DRV_DS1302)   += rtc-ds1302.o
 obj-$(CONFIG_RTC_DRV_DS1307)   += rtc-ds1307.o
 obj-$(CONFIG_RTC_DRV_DS1374)   += rtc-ds1374.o
+obj-$(CONFIG_RTC_DRV_DS1511)   += rtc-ds1511.o
 obj-$(CONFIG_RTC_DRV_DS1553)   += rtc-ds1553.o
 obj-$(CONFIG_RTC_DRV_DS1672)   += rtc-ds1672.o
 obj-$(CONFIG_RTC_DRV_DS1742)   += rtc-ds1742.o
@@ -38,6 +41,7 @@ obj-$(CONFIG_RTC_DRV_OMAP)    += rtc-omap.o
 obj-$(CONFIG_RTC_DRV_PCF8563)  += rtc-pcf8563.o
 obj-$(CONFIG_RTC_DRV_PCF8583)  += rtc-pcf8583.o
 obj-$(CONFIG_RTC_DRV_PL031)    += rtc-pl031.o
+obj-$(CONFIG_RTC_DRV_R9701)    += rtc-r9701.o
 obj-$(CONFIG_RTC_DRV_RS5C313)  += rtc-rs5c313.o
 obj-$(CONFIG_RTC_DRV_RS5C348)  += rtc-rs5c348.o
 obj-$(CONFIG_RTC_DRV_RS5C372)  += rtc-rs5c372.o
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
new file mode 100644 (file)
index 0000000..bbf10ec
--- /dev/null
@@ -0,0 +1,520 @@
+/*
+ * "RTT as Real Time Clock" driver for AT91SAM9 SoC family
+ *
+ * (C) 2007 Michel Benoit
+ *
+ * Based on rtc-at91rm9200.c by Rick Bronson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/time.h>
+#include <linux/rtc.h>
+#include <linux/interrupt.h>
+#include <linux/ioctl.h>
+
+#include <asm/mach/time.h>
+#include <asm/arch/board.h>
+#include <asm/arch/at91_rtt.h>
+
+
+/*
+ * This driver uses two configurable hardware resources that live in the
+ * AT91SAM9 backup power domain (intended to be powered at all times)
+ * to implement the Real Time Clock interfaces
+ *
+ *  - A "Real-time Timer" (RTT) counts up in seconds from a base time.
+ *    We can't assign the counter value (CRTV) ... but we can reset it.
+ *
+ *  - One of the "General Purpose Backup Registers" (GPBRs) holds the
+ *    base time, normally an offset from the beginning of the POSIX
+ *    epoch (1970-Jan-1 00:00:00 UTC).  Some systems also include the
+ *    local timezone's offset.
+ *
+ * The RTC's value is the RTT counter plus that offset.  The RTC's alarm
+ * is likewise a base (ALMV) plus that offset.
+ *
+ * Not all RTTs will be used as RTCs; some systems have multiple RTTs to
+ * choose from, or a "real" RTC module.  All systems have multiple GPBR
+ * registers available, likewise usable for more than "RTC" support.
+ */
+
+/*
+ * We store ALARM_DISABLED in ALMV to record that no alarm is set.
+ * It's also the reset value for that field.
+ */
+#define ALARM_DISABLED ((u32)~0)
+
+
+struct sam9_rtc {
+       void __iomem            *rtt;
+       struct rtc_device       *rtcdev;
+       u32                     imr;
+};
+
+#define rtt_readl(rtc, field) \
+       __raw_readl((rtc)->rtt + AT91_RTT_ ## field)
+#define rtt_writel(rtc, field, val) \
+       __raw_writel((val), (rtc)->rtt + AT91_RTT_ ## field)
+
+#define gpbr_readl(rtc) \
+       at91_sys_read(AT91_GPBR + 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR)
+#define gpbr_writel(rtc, val) \
+       at91_sys_write(AT91_GPBR + 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR, (val))
+
+/*
+ * Read current time and date in RTC
+ */
+static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
+{
+       struct sam9_rtc *rtc = dev_get_drvdata(dev);
+       u32 secs, secs2;
+       u32 offset;
+
+       /* read current time offset */
+       offset = gpbr_readl(rtc);
+       if (offset == 0)
+               return -EILSEQ;
+
+       /* reread the counter to help sync the two clock domains */
+       secs = rtt_readl(rtc, VR);
+       secs2 = rtt_readl(rtc, VR);
+       if (secs != secs2)
+               secs = rtt_readl(rtc, VR);
+
+       rtc_time_to_tm(offset + secs, tm);
+
+       dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "readtime",
+               1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
+               tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+       return 0;
+}
+
+/*
+ * Set current time and date in RTC
+ */
+static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
+{
+       struct sam9_rtc *rtc = dev_get_drvdata(dev);
+       int err;
+       u32 offset, alarm, mr;
+       unsigned long secs;
+
+       dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "settime",
+               1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
+               tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+       err = rtc_tm_to_time(tm, &secs);
+       if (err != 0)
+               return err;
+
+       mr = rtt_readl(rtc, MR);
+
+       /* disable interrupts */
+       rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
+
+       /* read current time offset */
+       offset = gpbr_readl(rtc);
+
+       /* store the new base time in a battery backup register */
+       secs += 1;
+       gpbr_writel(rtc, secs);
+
+       /* adjust the alarm time for the new base */
+       alarm = rtt_readl(rtc, AR);
+       if (alarm != ALARM_DISABLED) {
+               if (offset > secs) {
+                       /* time jumped backwards, increase time until alarm */
+                       alarm += (offset - secs);
+               } else if ((alarm + offset) > secs) {
+                       /* time jumped forwards, decrease time until alarm */
+                       alarm -= (secs - offset);
+               } else {
+                       /* time jumped past the alarm, disable alarm */
+                       alarm = ALARM_DISABLED;
+                       mr &= ~AT91_RTT_ALMIEN;
+               }
+               rtt_writel(rtc, AR, alarm);
+       }
+
+       /* reset the timer, and re-enable interrupts */
+       rtt_writel(rtc, MR, mr | AT91_RTT_RTTRST);
+
+       return 0;
+}
+
+static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct sam9_rtc *rtc = dev_get_drvdata(dev);
+       struct rtc_time *tm = &alrm->time;
+       u32 alarm = rtt_readl(rtc, AR);
+       u32 offset;
+
+       offset = gpbr_readl(rtc);
+       if (offset == 0)
+               return -EILSEQ;
+
+       memset(alrm, 0, sizeof(alrm));
+       if (alarm != ALARM_DISABLED && offset != 0) {
+               rtc_time_to_tm(offset + alarm, tm);
+
+               dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "readalarm",
+                       1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
+                       tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+               if (rtt_readl(rtc, MR) & AT91_RTT_ALMIEN)
+                       alrm->enabled = 1;
+       }
+
+       return 0;
+}
+
+static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct sam9_rtc *rtc = dev_get_drvdata(dev);
+       struct rtc_time *tm = &alrm->time;
+       unsigned long secs;
+       u32 offset;
+       u32 mr;
+       int err;
+
+       err = rtc_tm_to_time(tm, &secs);
+       if (err != 0)
+               return err;
+
+       offset = gpbr_readl(rtc);
+       if (offset == 0) {
+               /* time is not set */
+               return -EILSEQ;
+       }
+       mr = rtt_readl(rtc, MR);
+       rtt_writel(rtc, MR, mr & ~AT91_RTT_ALMIEN);
+
+       /* alarm in the past? finish and leave disabled */
+       if (secs <= offset) {
+               rtt_writel(rtc, AR, ALARM_DISABLED);
+               return 0;
+       }
+
+       /* else set alarm and maybe enable it */
+       rtt_writel(rtc, AR, secs - offset);
+       if (alrm->enabled)
+               rtt_writel(rtc, MR, mr | AT91_RTT_ALMIEN);
+
+       dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "setalarm",
+               tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour,
+               tm->tm_min, tm->tm_sec);
+
+       return 0;
+}
+
+/*
+ * Handle commands from user-space
+ */
+static int at91_rtc_ioctl(struct device *dev, unsigned int cmd,
+                       unsigned long arg)
+{
+       struct sam9_rtc *rtc = dev_get_drvdata(dev);
+       int ret = 0;
+       u32 mr = rtt_readl(rtc, MR);
+
+       dev_dbg(dev, "ioctl: cmd=%08x, arg=%08lx, mr %08x\n", cmd, arg, mr);
+
+       switch (cmd) {
+       case RTC_AIE_OFF:               /* alarm off */
+               rtt_writel(rtc, MR, mr & ~AT91_RTT_ALMIEN);
+               break;
+       case RTC_AIE_ON:                /* alarm on */
+               rtt_writel(rtc, MR, mr | AT91_RTT_ALMIEN);
+               break;
+       case RTC_UIE_OFF:               /* update off */
+               rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
+               break;
+       case RTC_UIE_ON:                /* update on */
+               rtt_writel(rtc, MR, mr | AT91_RTT_RTTINCIEN);
+               break;
+       default:
+               ret = -ENOIOCTLCMD;
+               break;
+       }
+
+       return ret;
+}
+
+/*
+ * Provide additional RTC information in /proc/driver/rtc
+ */
+static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
+{
+       struct sam9_rtc *rtc = dev_get_drvdata(dev);
+       u32 mr = mr = rtt_readl(rtc, MR);
+
+       seq_printf(seq, "update_IRQ\t: %s\n",
+                       (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
+       return 0;
+}
+
+/*
+ * IRQ handler for the RTC
+ */
+static irqreturn_t at91_rtc_interrupt(int irq, void *_rtc)
+{
+       struct sam9_rtc *rtc = _rtc;
+       u32 sr, mr;
+       unsigned long events = 0;
+
+       /* Shared interrupt may be for another device.  Note: reading
+        * SR clears it, so we must only read it in this irq handler!
+        */
+       mr = rtt_readl(rtc, MR) & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+       sr = rtt_readl(rtc, SR) & mr;
+       if (!sr)
+               return IRQ_NONE;
+
+       /* alarm status */
+       if (sr & AT91_RTT_ALMS)
+               events |= (RTC_AF | RTC_IRQF);
+
+       /* timer update/increment */
+       if (sr & AT91_RTT_RTTINC)
+               events |= (RTC_UF | RTC_IRQF);
+
+       rtc_update_irq(rtc->rtcdev, 1, events);
+
+       pr_debug("%s: num=%ld, events=0x%02lx\n", __FUNCTION__,
+               events >> 8, events & 0x000000FF);
+
+       return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops at91_rtc_ops = {
+       .ioctl          = at91_rtc_ioctl,
+       .read_time      = at91_rtc_readtime,
+       .set_time       = at91_rtc_settime,
+       .read_alarm     = at91_rtc_readalarm,
+       .set_alarm      = at91_rtc_setalarm,
+       .proc           = at91_rtc_proc,
+};
+
+/*
+ * Initialize and install RTC driver
+ */
+static int __init at91_rtc_probe(struct platform_device *pdev)
+{
+       struct resource *r;
+       struct sam9_rtc *rtc;
+       int             ret;
+       u32             mr;
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!r)
+               return -ENODEV;
+
+       rtc = kzalloc(sizeof *rtc, GFP_KERNEL);
+       if (!rtc)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, rtc);
+       rtc->rtt = (void __force __iomem *) (AT91_VA_BASE_SYS - AT91_BASE_SYS);
+       rtc->rtt += r->start;
+
+       mr = rtt_readl(rtc, MR);
+
+       /* unless RTT is counting at 1 Hz, re-initialize it */
+       if ((mr & AT91_RTT_RTPRES) != AT91_SLOW_CLOCK) {
+               mr = AT91_RTT_RTTRST | (AT91_SLOW_CLOCK & AT91_RTT_RTPRES);
+               gpbr_writel(rtc, 0);
+       }
+
+       /* disable all interrupts (same as on shutdown path) */
+       mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+       rtt_writel(rtc, MR, mr);
+
+       rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev,
+                               &at91_rtc_ops, THIS_MODULE);
+       if (IS_ERR(rtc->rtcdev)) {
+               ret = PTR_ERR(rtc->rtcdev);
+               goto fail;
+       }
+
+       /* register irq handler after we know what name we'll use */
+       ret = request_irq(AT91_ID_SYS, at91_rtc_interrupt,
+                               IRQF_DISABLED | IRQF_SHARED,
+                               rtc->rtcdev->dev.bus_id, rtc);
+       if (ret) {
+               dev_dbg(&pdev->dev, "can't share IRQ %d?\n", AT91_ID_SYS);
+               rtc_device_unregister(rtc->rtcdev);
+               goto fail;
+       }
+
+       /* NOTE:  sam9260 rev A silicon has a ROM bug which resets the
+        * RTT on at least some reboots.  If you have that chip, you must
+        * initialize the time from some external source like a GPS, wall
+        * clock, discrete RTC, etc
+        */
+
+       if (gpbr_readl(rtc) == 0)
+               dev_warn(&pdev->dev, "%s: SET TIME!\n",
+                               rtc->rtcdev->dev.bus_id);
+
+       return 0;
+
+fail:
+       platform_set_drvdata(pdev, NULL);
+       kfree(rtc);
+       return ret;
+}
+
+/*
+ * Disable and remove the RTC driver
+ */
+static int __exit at91_rtc_remove(struct platform_device *pdev)
+{
+       struct sam9_rtc *rtc = platform_get_drvdata(pdev);
+       u32             mr = rtt_readl(rtc, MR);
+
+       /* disable all interrupts */
+       rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
+       free_irq(AT91_ID_SYS, rtc);
+
+       rtc_device_unregister(rtc->rtcdev);
+
+       platform_set_drvdata(pdev, NULL);
+       kfree(rtc);
+       return 0;
+}
+
+static void at91_rtc_shutdown(struct platform_device *pdev)
+{
+       struct sam9_rtc *rtc = platform_get_drvdata(pdev);
+       u32             mr = rtt_readl(rtc, MR);
+
+       rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+       rtt_writel(rtc, MR, mr & ~rtc->imr);
+}
+
+#ifdef CONFIG_PM
+
+/* AT91SAM9 RTC Power management control */
+
+static int at91_rtc_suspend(struct platform_device *pdev,
+                                       pm_message_t state)
+{
+       struct sam9_rtc *rtc = platform_get_drvdata(pdev);
+       u32             mr = rtt_readl(rtc, MR);
+
+       /*
+        * This IRQ is shared with DBGU and other hardware which isn't
+        * necessarily a wakeup event source.
+        */
+       rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+       if (rtc->imr) {
+               if (device_may_wakeup(&pdev->dev) && (mr & AT91_RTT_ALMIEN)) {
+                       enable_irq_wake(AT91_ID_SYS);
+                       /* don't let RTTINC cause wakeups */
+                       if (mr & AT91_RTT_RTTINCIEN)
+                               rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
+               } else
+                       rtt_writel(rtc, MR, mr & ~rtc->imr);
+       }
+
+       return 0;
+}
+
+static int at91_rtc_resume(struct platform_device *pdev)
+{
+       struct sam9_rtc *rtc = platform_get_drvdata(pdev);
+       u32             mr;
+
+       if (rtc->imr) {
+               if (device_may_wakeup(&pdev->dev))
+                       disable_irq_wake(AT91_ID_SYS);
+               mr = rtt_readl(rtc, MR);
+               rtt_writel(rtc, MR, mr | rtc->imr);
+       }
+
+       return 0;
+}
+#else
+#define at91_rtc_suspend       NULL
+#define at91_rtc_resume                NULL
+#endif
+
+static struct platform_driver at91_rtc_driver = {
+       .driver.name    = "rtc-at91sam9",
+       .driver.owner   = THIS_MODULE,
+       .remove         = __exit_p(at91_rtc_remove),
+       .shutdown       = at91_rtc_shutdown,
+       .suspend        = at91_rtc_suspend,
+       .resume         = at91_rtc_resume,
+};
+
+/* Chips can have more than one RTT module, and they can be used for more
+ * than just RTCs.  So we can't just register as "the" RTT driver.
+ *
+ * A normal approach in such cases is to create a library to allocate and
+ * free the modules.  Here we just use bus_find_device() as like such a
+ * library, binding directly ... no runtime "library" footprint is needed.
+ */
+static int __init at91_rtc_match(struct device *dev, void *v)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       int ret;
+
+       /* continue searching if this isn't the RTT we need */
+       if (strcmp("at91_rtt", pdev->name) != 0
+                       || pdev->id != CONFIG_RTC_DRV_AT91SAM9_RTT)
+               goto fail;
+
+       /* else we found it ... but fail unless we can bind to the RTC driver */
+       if (dev->driver) {
+               dev_dbg(dev, "busy, can't use as RTC!\n");
+               goto fail;
+       }
+       dev->driver = &at91_rtc_driver.driver;
+       if (device_attach(dev) == 0) {
+               dev_dbg(dev, "can't attach RTC!\n");
+               goto fail;
+       }
+       ret = at91_rtc_probe(pdev);
+       if (ret == 0)
+               return true;
+
+       dev_dbg(dev, "RTC probe err %d!\n", ret);
+fail:
+       return false;
+}
+
+static int __init at91_rtc_init(void)
+{
+       int status;
+       struct device *rtc;
+
+       status = platform_driver_register(&at91_rtc_driver);
+       if (status)
+               return status;
+       rtc = bus_find_device(&platform_bus_type, NULL,
+                       NULL, at91_rtc_match);
+       if (!rtc)
+               platform_driver_unregister(&at91_rtc_driver);
+       return rtc ? 0 : -ENODEV;
+}
+module_init(at91_rtc_init);
+
+static void __exit at91_rtc_exit(void)
+{
+       platform_driver_unregister(&at91_rtc_driver);
+}
+module_exit(at91_rtc_exit);
+
+
+MODULE_AUTHOR("Michel Benoit");
+MODULE_DESCRIPTION("RTC driver for Atmel AT91SAM9x");
+MODULE_LICENSE("GPL");
index 1aa709dda0d67d0fbb9e5d660211e207b22ca3ba..d90ba860d21678863610a69a3dc9a74f5b9e53bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Blackfin On-Chip Real Time Clock Driver
- *  Supports BF53[123]/BF53[467]/BF54[2489]
+ *  Supports BF52[257]/BF53[123]/BF53[467]/BF54[24789]
  *
  * Copyright 2004-2007 Analog Devices Inc.
  *
  * writes to clear status registers complete immediately.
  */
 
-#include <linux/module.h>
-#include <linux/kernel.h>
 #include <linux/bcd.h>
-#include <linux/rtc.h>
+#include <linux/completion.h>
+#include <linux/delay.h>
 #include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/rtc.h>
 #include <linux/seq_file.h>
-#include <linux/interrupt.h>
-#include <linux/spinlock.h>
-#include <linux/delay.h>
 
 #include <asm/blackfin.h>
 
-#define stamp(fmt, args...) pr_debug("%s:%i: " fmt "\n", __FUNCTION__, __LINE__, ## args)
-#define stampit() stamp("here i am")
+#define dev_dbg_stamp(dev) dev_dbg(dev, "%s:%i: here i am\n", __func__, __LINE__)
 
 struct bfin_rtc {
        struct rtc_device *rtc_dev;
        struct rtc_time rtc_alarm;
-       spinlock_t lock;
+       u16 rtc_wrote_regs;
 };
 
 /* Bit values for the ISTAT / ICTL registers */
@@ -72,7 +71,7 @@ struct bfin_rtc {
 #define SEC_BITS_OFF    0
 
 /* Some helper functions to convert between the common RTC notion of time
- * and the internal Blackfin notion that is stored in 32bits.
+ * and the internal Blackfin notion that is encoded in 32bits.
  */
 static inline u32 rtc_time_to_bfin(unsigned long now)
 {
@@ -97,7 +96,10 @@ static inline void rtc_bfin_to_tm(u32 rtc_bfin, struct rtc_time *tm)
        rtc_time_to_tm(rtc_bfin_to_time(rtc_bfin), tm);
 }
 
-/* Wait for the previous write to a RTC register to complete.
+/**
+ *     bfin_rtc_sync_pending - make sure pending writes have complete
+ *
+ * Wait for the previous write to a RTC register to complete.
  * Unfortunately, we can't sleep here as that introduces a race condition when
  * turning on interrupt events.  Consider this:
  *  - process sets alarm
@@ -112,188 +114,202 @@ static inline void rtc_bfin_to_tm(u32 rtc_bfin, struct rtc_time *tm)
  * If anyone can point out the obvious solution here, i'm listening :).  This
  * shouldn't be an issue on an SMP or preempt system as this function should
  * only be called with the rtc lock held.
+ *
+ * Other options:
+ *  - disable PREN so the sync happens at 32.768kHZ ... but this changes the
+ *    inc rate for all RTC registers from 1HZ to 32.768kHZ ...
+ *  - use the write complete IRQ
  */
-static void rtc_bfin_sync_pending(void)
+/*
+static void bfin_rtc_sync_pending_polled(void)
 {
-       stampit();
-       while (!(bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_COMPLETE)) {
+       while (!(bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_COMPLETE))
                if (!(bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_PENDING))
                        break;
-       }
        bfin_write_RTC_ISTAT(RTC_ISTAT_WRITE_COMPLETE);
 }
+*/
+static DECLARE_COMPLETION(bfin_write_complete);
+static void bfin_rtc_sync_pending(struct device *dev)
+{
+       dev_dbg_stamp(dev);
+       while (bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_PENDING)
+               wait_for_completion_timeout(&bfin_write_complete, HZ * 5);
+       dev_dbg_stamp(dev);
+}
 
-static void rtc_bfin_reset(struct bfin_rtc *rtc)
+/**
+ *     bfin_rtc_reset - set RTC to sane/known state
+ *
+ * Initialize the RTC.  Enable pre-scaler to scale RTC clock
+ * to 1Hz and clear interrupt/status registers.
+ */
+static void bfin_rtc_reset(struct device *dev)
 {
-       /* Initialize the RTC. Enable pre-scaler to scale RTC clock
-        * to 1Hz and clear interrupt/status registers. */
-       spin_lock_irq(&rtc->lock);
-       rtc_bfin_sync_pending();
+       struct bfin_rtc *rtc = dev_get_drvdata(dev);
+       dev_dbg_stamp(dev);
+       bfin_rtc_sync_pending(dev);
        bfin_write_RTC_PREN(0x1);
-       bfin_write_RTC_ICTL(0);
+       bfin_write_RTC_ICTL(RTC_ISTAT_WRITE_COMPLETE);
        bfin_write_RTC_SWCNT(0);
        bfin_write_RTC_ALARM(0);
        bfin_write_RTC_ISTAT(0xFFFF);
-       spin_unlock_irq(&rtc->lock);
+       rtc->rtc_wrote_regs = 0;
 }
 
+/**
+ *     bfin_rtc_interrupt - handle interrupt from RTC
+ *
+ * Since we handle all RTC events here, we have to make sure the requested
+ * interrupt is enabled (in RTC_ICTL) as the event status register (RTC_ISTAT)
+ * always gets updated regardless of the interrupt being enabled.  So when one
+ * even we care about (e.g. stopwatch) goes off, we don't want to turn around
+ * and say that other events have happened as well (e.g. second).  We do not
+ * have to worry about pending writes to the RTC_ICTL register as interrupts
+ * only fire if they are enabled in the RTC_ICTL register.
+ */
 static irqreturn_t bfin_rtc_interrupt(int irq, void *dev_id)
 {
-       struct platform_device *pdev = to_platform_device(dev_id);
-       struct bfin_rtc *rtc = platform_get_drvdata(pdev);
+       struct device *dev = dev_id;
+       struct bfin_rtc *rtc = dev_get_drvdata(dev);
        unsigned long events = 0;
-       u16 rtc_istat;
-
-       stampit();
+       bool write_complete = false;
+       u16 rtc_istat, rtc_ictl;
 
-       spin_lock_irq(&rtc->lock);
+       dev_dbg_stamp(dev);
 
        rtc_istat = bfin_read_RTC_ISTAT();
+       rtc_ictl = bfin_read_RTC_ICTL();
 
-       if (rtc_istat & (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY)) {
-               bfin_write_RTC_ISTAT(RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY);
-               events |= RTC_AF | RTC_IRQF;
+       if (rtc_istat & RTC_ISTAT_WRITE_COMPLETE) {
+               bfin_write_RTC_ISTAT(RTC_ISTAT_WRITE_COMPLETE);
+               write_complete = true;
+               complete(&bfin_write_complete);
        }
 
-       if (rtc_istat & RTC_ISTAT_STOPWATCH) {
-               bfin_write_RTC_ISTAT(RTC_ISTAT_STOPWATCH);
-               events |= RTC_PF | RTC_IRQF;
-               bfin_write_RTC_SWCNT(rtc->rtc_dev->irq_freq);
+       if (rtc_ictl & (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY)) {
+               if (rtc_istat & (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY)) {
+                       bfin_write_RTC_ISTAT(RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY);
+                       events |= RTC_AF | RTC_IRQF;
+               }
        }
 
-       if (rtc_istat & RTC_ISTAT_SEC) {
-               bfin_write_RTC_ISTAT(RTC_ISTAT_SEC);
-               events |= RTC_UF | RTC_IRQF;
+       if (rtc_ictl & RTC_ISTAT_STOPWATCH) {
+               if (rtc_istat & RTC_ISTAT_STOPWATCH) {
+                       bfin_write_RTC_ISTAT(RTC_ISTAT_STOPWATCH);
+                       events |= RTC_PF | RTC_IRQF;
+                       bfin_write_RTC_SWCNT(rtc->rtc_dev->irq_freq);
+               }
        }
 
-       rtc_update_irq(rtc->rtc_dev, 1, events);
+       if (rtc_ictl & RTC_ISTAT_SEC) {
+               if (rtc_istat & RTC_ISTAT_SEC) {
+                       bfin_write_RTC_ISTAT(RTC_ISTAT_SEC);
+                       events |= RTC_UF | RTC_IRQF;
+               }
+       }
 
-       spin_unlock_irq(&rtc->lock);
+       if (events)
+               rtc_update_irq(rtc->rtc_dev, 1, events);
 
-       return IRQ_HANDLED;
+       if (write_complete || events)
+               return IRQ_HANDLED;
+       else
+               return IRQ_NONE;
 }
 
 static int bfin_rtc_open(struct device *dev)
 {
-       struct bfin_rtc *rtc = dev_get_drvdata(dev);
        int ret;
 
-       stampit();
+       dev_dbg_stamp(dev);
 
-       ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, IRQF_DISABLED, "rtc-bfin", dev);
-       if (unlikely(ret)) {
-               dev_err(dev, "request RTC IRQ failed with %d\n", ret);
-               return ret;
-       }
-
-       rtc_bfin_reset(rtc);
+       ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, IRQF_SHARED, to_platform_device(dev)->name, dev);
+       if (!ret)
+               bfin_rtc_reset(dev);
 
        return ret;
 }
 
 static void bfin_rtc_release(struct device *dev)
 {
-       struct bfin_rtc *rtc = dev_get_drvdata(dev);
-       stampit();
-       rtc_bfin_reset(rtc);
+       dev_dbg_stamp(dev);
+       bfin_rtc_reset(dev);
        free_irq(IRQ_RTC, dev);
 }
 
+static void bfin_rtc_int_set(struct bfin_rtc *rtc, u16 rtc_int)
+{
+       bfin_write_RTC_ISTAT(rtc_int);
+       bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() | rtc_int);
+}
+static void bfin_rtc_int_clear(struct bfin_rtc *rtc, u16 rtc_int)
+{
+       bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() & rtc_int);
+}
+static void bfin_rtc_int_set_alarm(struct bfin_rtc *rtc)
+{
+       /* Blackfin has different bits for whether the alarm is
+        * more than 24 hours away.
+        */
+       bfin_rtc_int_set(rtc, (rtc->rtc_alarm.tm_yday == -1 ? RTC_ISTAT_ALARM : RTC_ISTAT_ALARM_DAY));
+}
 static int bfin_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
 {
        struct bfin_rtc *rtc = dev_get_drvdata(dev);
+       int ret = 0;
+
+       dev_dbg_stamp(dev);
 
-       stampit();
+       bfin_rtc_sync_pending(dev);
 
        switch (cmd) {
        case RTC_PIE_ON:
-               stampit();
-               spin_lock_irq(&rtc->lock);
-               rtc_bfin_sync_pending();
-               bfin_write_RTC_ISTAT(RTC_ISTAT_STOPWATCH);
+               dev_dbg_stamp(dev);
+               bfin_rtc_int_set(rtc, RTC_ISTAT_STOPWATCH);
                bfin_write_RTC_SWCNT(rtc->rtc_dev->irq_freq);
-               bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() | RTC_ISTAT_STOPWATCH);
-               spin_unlock_irq(&rtc->lock);
-               return 0;
+               break;
        case RTC_PIE_OFF:
-               stampit();
-               spin_lock_irq(&rtc->lock);
-               rtc_bfin_sync_pending();
-               bfin_write_RTC_SWCNT(0);
-               bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() & ~RTC_ISTAT_STOPWATCH);
-               spin_unlock_irq(&rtc->lock);
-               return 0;
+               dev_dbg_stamp(dev);
+               bfin_rtc_int_clear(rtc, ~RTC_ISTAT_STOPWATCH);
+               break;
 
        case RTC_UIE_ON:
-               stampit();
-               spin_lock_irq(&rtc->lock);
-               rtc_bfin_sync_pending();
-               bfin_write_RTC_ISTAT(RTC_ISTAT_SEC);
-               bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() | RTC_ISTAT_SEC);
-               spin_unlock_irq(&rtc->lock);
-               return 0;
+               dev_dbg_stamp(dev);
+               bfin_rtc_int_set(rtc, RTC_ISTAT_SEC);
+               break;
        case RTC_UIE_OFF:
-               stampit();
-               spin_lock_irq(&rtc->lock);
-               rtc_bfin_sync_pending();
-               bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() & ~RTC_ISTAT_SEC);
-               spin_unlock_irq(&rtc->lock);
-               return 0;
-
-       case RTC_AIE_ON: {
-               unsigned long rtc_alarm;
-               u16 which_alarm;
-               int ret = 0;
-
-               stampit();
-
-               spin_lock_irq(&rtc->lock);
-
-               rtc_bfin_sync_pending();
-               if (rtc->rtc_alarm.tm_yday == -1) {
-                       struct rtc_time now;
-                       rtc_bfin_to_tm(bfin_read_RTC_STAT(), &now);
-                       now.tm_sec = rtc->rtc_alarm.tm_sec;
-                       now.tm_min = rtc->rtc_alarm.tm_min;
-                       now.tm_hour = rtc->rtc_alarm.tm_hour;
-                       ret = rtc_tm_to_time(&now, &rtc_alarm);
-                       which_alarm = RTC_ISTAT_ALARM;
-               } else {
-                       ret = rtc_tm_to_time(&rtc->rtc_alarm, &rtc_alarm);
-                       which_alarm = RTC_ISTAT_ALARM_DAY;
-               }
-               if (ret == 0) {
-                       bfin_write_RTC_ISTAT(which_alarm);
-                       bfin_write_RTC_ALARM(rtc_time_to_bfin(rtc_alarm));
-                       bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() | which_alarm);
-               }
-
-               spin_unlock_irq(&rtc->lock);
-
-               return ret;
-       }
+               dev_dbg_stamp(dev);
+               bfin_rtc_int_clear(rtc, ~RTC_ISTAT_SEC);
+               break;
+
+       case RTC_AIE_ON:
+               dev_dbg_stamp(dev);
+               bfin_rtc_int_set_alarm(rtc);
+               break;
        case RTC_AIE_OFF:
-               stampit();
-               spin_lock_irq(&rtc->lock);
-               rtc_bfin_sync_pending();
-               bfin_write_RTC_ICTL(bfin_read_RTC_ICTL() & ~(RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY));
-               spin_unlock_irq(&rtc->lock);
-               return 0;
+               dev_dbg_stamp(dev);
+               bfin_rtc_int_clear(rtc, ~(RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY));
+               break;
+
+       default:
+               dev_dbg_stamp(dev);
+               ret = -ENOIOCTLCMD;
        }
 
-       return -ENOIOCTLCMD;
+       return ret;
 }
 
 static int bfin_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
        struct bfin_rtc *rtc = dev_get_drvdata(dev);
 
-       stampit();
+       dev_dbg_stamp(dev);
+
+       if (rtc->rtc_wrote_regs & 0x1)
+               bfin_rtc_sync_pending(dev);
 
-       spin_lock_irq(&rtc->lock);
-       rtc_bfin_sync_pending();
        rtc_bfin_to_tm(bfin_read_RTC_STAT(), tm);
-       spin_unlock_irq(&rtc->lock);
 
        return 0;
 }
@@ -304,64 +320,79 @@ static int bfin_rtc_set_time(struct device *dev, struct rtc_time *tm)
        int ret;
        unsigned long now;
 
-       stampit();
-
-       spin_lock_irq(&rtc->lock);
+       dev_dbg_stamp(dev);
 
        ret = rtc_tm_to_time(tm, &now);
        if (ret == 0) {
-               rtc_bfin_sync_pending();
+               if (rtc->rtc_wrote_regs & 0x1)
+                       bfin_rtc_sync_pending(dev);
                bfin_write_RTC_STAT(rtc_time_to_bfin(now));
+               rtc->rtc_wrote_regs = 0x1;
        }
 
-       spin_unlock_irq(&rtc->lock);
-
        return ret;
 }
 
 static int bfin_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
        struct bfin_rtc *rtc = dev_get_drvdata(dev);
-       stampit();
-       memcpy(&alrm->time, &rtc->rtc_alarm, sizeof(struct rtc_time));
-       alrm->pending = !!(bfin_read_RTC_ICTL() & (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY));
+       dev_dbg_stamp(dev);
+       alrm->time = rtc->rtc_alarm;
+       bfin_rtc_sync_pending(dev);
+       alrm->enabled = !!(bfin_read_RTC_ICTL() & (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY));
        return 0;
 }
 
 static int bfin_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
        struct bfin_rtc *rtc = dev_get_drvdata(dev);
-       stampit();
-       memcpy(&rtc->rtc_alarm, &alrm->time, sizeof(struct rtc_time));
+       unsigned long rtc_alarm;
+
+       dev_dbg_stamp(dev);
+
+       if (rtc_tm_to_time(&alrm->time, &rtc_alarm))
+               return -EINVAL;
+
+       rtc->rtc_alarm = alrm->time;
+
+       bfin_rtc_sync_pending(dev);
+       bfin_write_RTC_ALARM(rtc_time_to_bfin(rtc_alarm));
+       if (alrm->enabled)
+               bfin_rtc_int_set_alarm(rtc);
+
        return 0;
 }
 
 static int bfin_rtc_proc(struct device *dev, struct seq_file *seq)
 {
-#define yesno(x) (x ? "yes" : "no")
+#define yesno(x) ((x) ? "yes" : "no")
        u16 ictl = bfin_read_RTC_ICTL();
-       stampit();
-       seq_printf(seq, "alarm_IRQ\t: %s\n", yesno(ictl & RTC_ISTAT_ALARM));
-       seq_printf(seq, "wkalarm_IRQ\t: %s\n", yesno(ictl & RTC_ISTAT_ALARM_DAY));
-       seq_printf(seq, "seconds_IRQ\t: %s\n", yesno(ictl & RTC_ISTAT_SEC));
-       seq_printf(seq, "periodic_IRQ\t: %s\n", yesno(ictl & RTC_ISTAT_STOPWATCH));
-#ifdef DEBUG
-       seq_printf(seq, "RTC_STAT\t: 0x%08X\n", bfin_read_RTC_STAT());
-       seq_printf(seq, "RTC_ICTL\t: 0x%04X\n", bfin_read_RTC_ICTL());
-       seq_printf(seq, "RTC_ISTAT\t: 0x%04X\n", bfin_read_RTC_ISTAT());
-       seq_printf(seq, "RTC_SWCNT\t: 0x%04X\n", bfin_read_RTC_SWCNT());
-       seq_printf(seq, "RTC_ALARM\t: 0x%08X\n", bfin_read_RTC_ALARM());
-       seq_printf(seq, "RTC_PREN\t: 0x%04X\n", bfin_read_RTC_PREN());
-#endif
+       dev_dbg_stamp(dev);
+       seq_printf(seq,
+               "alarm_IRQ\t: %s\n"
+               "wkalarm_IRQ\t: %s\n"
+               "seconds_IRQ\t: %s\n"
+               "periodic_IRQ\t: %s\n",
+               yesno(ictl & RTC_ISTAT_ALARM),
+               yesno(ictl & RTC_ISTAT_ALARM_DAY),
+               yesno(ictl & RTC_ISTAT_SEC),
+               yesno(ictl & RTC_ISTAT_STOPWATCH));
        return 0;
+#undef yesno
 }
 
+/**
+ *     bfin_irq_set_freq - make sure hardware supports requested freq
+ *     @dev: pointer to RTC device structure
+ *     @freq: requested frequency rate
+ *
+ *     The Blackfin RTC can only generate periodic events at 1 per
+ *     second (1 Hz), so reject any attempt at changing it.
+ */
 static int bfin_irq_set_freq(struct device *dev, int freq)
 {
-       struct bfin_rtc *rtc = dev_get_drvdata(dev);
-       stampit();
-       rtc->rtc_dev->irq_freq = freq;
-       return 0;
+       dev_dbg_stamp(dev);
+       return -ENOTTY;
 }
 
 static struct rtc_class_ops bfin_rtc_ops = {
@@ -381,27 +412,24 @@ static int __devinit bfin_rtc_probe(struct platform_device *pdev)
        struct bfin_rtc *rtc;
        int ret = 0;
 
-       stampit();
+       dev_dbg_stamp(&pdev->dev);
 
        rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
        if (unlikely(!rtc))
                return -ENOMEM;
 
-       spin_lock_init(&rtc->lock);
-
        rtc->rtc_dev = rtc_device_register(pdev->name, &pdev->dev, &bfin_rtc_ops, THIS_MODULE);
        if (unlikely(IS_ERR(rtc))) {
                ret = PTR_ERR(rtc->rtc_dev);
                goto err;
        }
-       rtc->rtc_dev->irq_freq = 0;
-       rtc->rtc_dev->max_user_freq = (2 << 16); /* stopwatch is an unsigned 16 bit reg */
+       rtc->rtc_dev->irq_freq = 1;
 
        platform_set_drvdata(pdev, rtc);
 
        return 0;
 
-err:
+ err:
        kfree(rtc);
        return ret;
 }
@@ -428,7 +456,6 @@ static struct platform_driver bfin_rtc_driver = {
 
 static int __init bfin_rtc_init(void)
 {
-       stampit();
        return platform_driver_register(&bfin_rtc_driver);
 }
 
index 29cf1457ca10f507104a5a54d9fedd88f0544a95..e059f94c79eb2663632feff0e7a990d7aaa0a42c 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/mod_devicetable.h>
 
+#ifdef CONFIG_HPET_EMULATE_RTC
+#include <asm/hpet.h>
+#endif
+
 /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
 #include <asm-generic/rtc.h>
 
+#ifndef CONFIG_HPET_EMULATE_RTC
+#define is_hpet_enabled()                      0
+#define hpet_set_alarm_time(hrs, min, sec)     do { } while (0)
+#define hpet_set_periodic_freq(arg)            0
+#define hpet_mask_rtc_irq_bit(arg)             do { } while (0)
+#define hpet_set_rtc_irq_bit(arg)              do { } while (0)
+#define hpet_rtc_timer_init()                  do { } while (0)
+#define hpet_register_irq_handler(h)           0
+#define hpet_unregister_irq_handler(h)         do { } while (0)
+extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id);
+#endif
 
 struct cmos_rtc {
        struct rtc_device       *rtc;
@@ -199,6 +214,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
        sec = t->time.tm_sec;
        sec = (sec < 60) ? BIN2BCD(sec) : 0xff;
 
+       hpet_set_alarm_time(t->time.tm_hour, t->time.tm_min, t->time.tm_sec);
        spin_lock_irq(&rtc_lock);
 
        /* next rtc irq must not be from previous alarm setting */
@@ -252,7 +268,8 @@ static int cmos_irq_set_freq(struct device *dev, int freq)
        f = 16 - f;
 
        spin_lock_irqsave(&rtc_lock, flags);
-       CMOS_WRITE(RTC_REF_CLCK_32KHZ | f, RTC_FREQ_SELECT);
+       if (!hpet_set_periodic_freq(freq))
+               CMOS_WRITE(RTC_REF_CLCK_32KHZ | f, RTC_FREQ_SELECT);
        spin_unlock_irqrestore(&rtc_lock, flags);
 
        return 0;
@@ -314,28 +331,37 @@ cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
        switch (cmd) {
        case RTC_AIE_OFF:       /* alarm off */
                rtc_control &= ~RTC_AIE;
+               hpet_mask_rtc_irq_bit(RTC_AIE);
                break;
        case RTC_AIE_ON:        /* alarm on */
                rtc_control |= RTC_AIE;
+               hpet_set_rtc_irq_bit(RTC_AIE);
                break;
        case RTC_UIE_OFF:       /* update off */
                rtc_control &= ~RTC_UIE;
+               hpet_mask_rtc_irq_bit(RTC_UIE);
                break;
        case RTC_UIE_ON:        /* update on */
                rtc_control |= RTC_UIE;
+               hpet_set_rtc_irq_bit(RTC_UIE);
                break;
        case RTC_PIE_OFF:       /* periodic off */
                rtc_control &= ~RTC_PIE;
+               hpet_mask_rtc_irq_bit(RTC_PIE);
                break;
        case RTC_PIE_ON:        /* periodic on */
                rtc_control |= RTC_PIE;
+               hpet_set_rtc_irq_bit(RTC_PIE);
                break;
        }
-       CMOS_WRITE(rtc_control, RTC_CONTROL);
+       if (!is_hpet_enabled())
+               CMOS_WRITE(rtc_control, RTC_CONTROL);
+
        rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
        rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
        if (is_intr(rtc_intr))
                rtc_update_irq(cmos->rtc, 1, rtc_intr);
+
        spin_unlock_irqrestore(&rtc_lock, flags);
        return 0;
 }
@@ -393,15 +419,111 @@ static const struct rtc_class_ops cmos_rtc_ops = {
 
 /*----------------------------------------------------------------*/
 
+/*
+ * All these chips have at least 64 bytes of address space, shared by
+ * RTC registers and NVRAM.  Most of those bytes of NVRAM are used
+ * by boot firmware.  Modern chips have 128 or 256 bytes.
+ */
+
+#define NVRAM_OFFSET   (RTC_REG_D + 1)
+
+static ssize_t
+cmos_nvram_read(struct kobject *kobj, struct bin_attribute *attr,
+               char *buf, loff_t off, size_t count)
+{
+       int     retval;
+
+       if (unlikely(off >= attr->size))
+               return 0;
+       if ((off + count) > attr->size)
+               count = attr->size - off;
+
+       spin_lock_irq(&rtc_lock);
+       for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++)
+               *buf++ = CMOS_READ(off);
+       spin_unlock_irq(&rtc_lock);
+
+       return retval;
+}
+
+static ssize_t
+cmos_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
+               char *buf, loff_t off, size_t count)
+{
+       struct cmos_rtc *cmos;
+       int             retval;
+
+       cmos = dev_get_drvdata(container_of(kobj, struct device, kobj));
+       if (unlikely(off >= attr->size))
+               return -EFBIG;
+       if ((off + count) > attr->size)
+               count = attr->size - off;
+
+       /* NOTE:  on at least PCs and Ataris, the boot firmware uses a
+        * checksum on part of the NVRAM data.  That's currently ignored
+        * here.  If userspace is smart enough to know what fields of
+        * NVRAM to update, updating checksums is also part of its job.
+        */
+       spin_lock_irq(&rtc_lock);
+       for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) {
+               /* don't trash RTC registers */
+               if (off == cmos->day_alrm
+                               || off == cmos->mon_alrm
+                               || off == cmos->century)
+                       buf++;
+               else
+                       CMOS_WRITE(*buf++, off);
+       }
+       spin_unlock_irq(&rtc_lock);
+
+       return retval;
+}
+
+static struct bin_attribute nvram = {
+       .attr = {
+               .name   = "nvram",
+               .mode   = S_IRUGO | S_IWUSR,
+               .owner  = THIS_MODULE,
+       },
+
+       .read   = cmos_nvram_read,
+       .write  = cmos_nvram_write,
+       /* size gets set up later */
+};
+
+/*----------------------------------------------------------------*/
+
 static struct cmos_rtc cmos_rtc;
 
 static irqreturn_t cmos_interrupt(int irq, void *p)
 {
        u8              irqstat;
+       u8              rtc_control;
 
        spin_lock(&rtc_lock);
-       irqstat = CMOS_READ(RTC_INTR_FLAGS);
-       irqstat &= (CMOS_READ(RTC_CONTROL) & RTC_IRQMASK) | RTC_IRQF;
+       /*
+        * In this case it is HPET RTC interrupt handler
+        * calling us, with the interrupt information
+        * passed as arg1, instead of irq.
+        */
+       if (is_hpet_enabled())
+               irqstat = (unsigned long)irq & 0xF0;
+       else {
+               irqstat = CMOS_READ(RTC_INTR_FLAGS);
+               rtc_control = CMOS_READ(RTC_CONTROL);
+               irqstat &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
+       }
+
+       /* All Linux RTC alarms should be treated as if they were oneshot.
+        * Similar code may be needed in system wakeup paths, in case the
+        * alarm woke the system.
+        */
+       if (irqstat & RTC_AIE) {
+               rtc_control = CMOS_READ(RTC_CONTROL);
+               rtc_control &= ~RTC_AIE;
+               CMOS_WRITE(rtc_control, RTC_CONTROL);
+               CMOS_READ(RTC_INTR_FLAGS);
+       }
        spin_unlock(&rtc_lock);
 
        if (is_intr(irqstat)) {
@@ -412,11 +534,9 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
 }
 
 #ifdef CONFIG_PNP
-#define        is_pnp()        1
 #define        INITSECTION
 
 #else
-#define        is_pnp()        0
 #define        INITSECTION     __init
 #endif
 
@@ -426,6 +546,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
        struct cmos_rtc_board_info      *info = dev->platform_data;
        int                             retval = 0;
        unsigned char                   rtc_control;
+       unsigned                        address_space;
 
        /* there can be only one ... */
        if (cmos_rtc.dev)
@@ -450,15 +571,36 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
        cmos_rtc.irq = rtc_irq;
        cmos_rtc.iomem = ports;
 
+       /* Heuristic to deduce NVRAM size ... do what the legacy NVRAM
+        * driver did, but don't reject unknown configs.   Old hardware
+        * won't address 128 bytes, and for now we ignore the way newer
+        * chips can address 256 bytes (using two more i/o ports).
+        */
+#if    defined(CONFIG_ATARI)
+       address_space = 64;
+#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__)
+       address_space = 128;
+#else
+#warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes.
+       address_space = 128;
+#endif
+
        /* For ACPI systems extension info comes from the FADT.  On others,
         * board specific setup provides it as appropriate.  Systems where
         * the alarm IRQ isn't automatically a wakeup IRQ (like ACPI, and
         * some almost-clones) can provide hooks to make that behave.
+        *
+        * Note that ACPI doesn't preclude putting these registers into
+        * "extended" areas of the chip, including some that we won't yet
+        * expect CMOS_READ and friends to handle.
         */
        if (info) {
-               cmos_rtc.day_alrm = info->rtc_day_alarm;
-               cmos_rtc.mon_alrm = info->rtc_mon_alarm;
-               cmos_rtc.century = info->rtc_century;
+               if (info->rtc_day_alarm && info->rtc_day_alarm < 128)
+                       cmos_rtc.day_alrm = info->rtc_day_alarm;
+               if (info->rtc_mon_alarm && info->rtc_mon_alarm < 128)
+                       cmos_rtc.mon_alrm = info->rtc_mon_alarm;
+               if (info->rtc_century && info->rtc_century < 128)
+                       cmos_rtc.century = info->rtc_century;
 
                if (info->wake_on && info->wake_off) {
                        cmos_rtc.wake_on = info->wake_on;
@@ -485,8 +627,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
         * doesn't use 32KHz here ... for portability we might need to
         * do something about other clock frequencies.
         */
-       CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT);
        cmos_rtc.rtc->irq_freq = 1024;
+       if (!hpet_set_periodic_freq(cmos_rtc.rtc->irq_freq))
+               CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT);
 
        /* disable irqs.
         *
@@ -509,19 +652,39 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
                goto cleanup1;
        }
 
-       if (is_valid_irq(rtc_irq))
-               retval = request_irq(rtc_irq, cmos_interrupt, IRQF_DISABLED,
-                               cmos_rtc.rtc->dev.bus_id,
+       if (is_valid_irq(rtc_irq)) {
+               irq_handler_t rtc_cmos_int_handler;
+
+               if (is_hpet_enabled()) {
+                       int err;
+
+                       rtc_cmos_int_handler = hpet_rtc_interrupt;
+                       err = hpet_register_irq_handler(cmos_interrupt);
+                       if (err != 0) {
+                               printk(KERN_WARNING "hpet_register_irq_handler "
+                                               " failed in rtc_init().");
+                               goto cleanup1;
+                       }
+               } else
+                       rtc_cmos_int_handler = cmos_interrupt;
+
+               retval = request_irq(rtc_irq, rtc_cmos_int_handler,
+                               IRQF_DISABLED, cmos_rtc.rtc->dev.bus_id,
                                cmos_rtc.rtc);
-       if (retval < 0) {
-               dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
-               goto cleanup1;
+               if (retval < 0) {
+                       dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
+                       goto cleanup1;
+               }
        }
+       hpet_rtc_timer_init();
 
-       /* REVISIT optionally make 50 or 114 bytes NVRAM available,
-        * like rtc-ds1553, rtc-ds1742 ... this will often include
-        * registers for century, and day/month alarm.
-        */
+       /* export at least the first block of NVRAM */
+       nvram.size = address_space - NVRAM_OFFSET;
+       retval = sysfs_create_bin_file(&dev->kobj, &nvram);
+       if (retval < 0) {
+               dev_dbg(dev, "can't create nvram file? %d\n", retval);
+               goto cleanup2;
+       }
 
        pr_info("%s: alarms up to one %s%s\n",
                        cmos_rtc.rtc->dev.bus_id,
@@ -536,6 +699,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 
        return 0;
 
+cleanup2:
+       if (is_valid_irq(rtc_irq))
+               free_irq(rtc_irq, cmos_rtc.rtc);
 cleanup1:
        cmos_rtc.dev = NULL;
        rtc_device_unregister(cmos_rtc.rtc);
@@ -563,8 +729,12 @@ static void __exit cmos_do_remove(struct device *dev)
 
        cmos_do_shutdown();
 
-       if (is_valid_irq(cmos->irq))
+       sysfs_remove_bin_file(&dev->kobj, &nvram);
+
+       if (is_valid_irq(cmos->irq)) {
                free_irq(cmos->irq, cmos->rtc);
+               hpet_unregister_irq_handler(cmos_interrupt);
+       }
 
        rtc_device_unregister(cmos->rtc);
        cmos->rtc = NULL;
@@ -659,9 +829,12 @@ static int cmos_resume(struct device *dev)
 
 /*----------------------------------------------------------------*/
 
-/* The "CMOS" RTC normally lives on the platform_bus.  On ACPI systems,
- * the device node will always be created as a PNPACPI device.  Plus
- * pre-ACPI PCs probably list it in the PNPBIOS tables.
+/* On non-x86 systems, a "CMOS" RTC lives most naturally on platform_bus.
+ * ACPI systems always list these as PNPACPI devices, and pre-ACPI PCs
+ * probably list them in similar PNPBIOS tables; so PNP is more common.
+ *
+ * We don't use legacy "poke at the hardware" probing.  Ancient PCs that
+ * predate even PNPBIOS should set up platform_bus devices.
  */
 
 #ifdef CONFIG_PNP
index 025c60a17a4a3c9841d4105bf0344a92f9c31510..90dfa0df747acb9314b4ed115c2eec0dee1eae0d 100644 (file)
@@ -246,6 +246,15 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
        /* if the driver does not provide the ioctl interface
         * or if that particular ioctl was not implemented
         * (-ENOIOCTLCMD), we will try to emulate here.
+        *
+        * Drivers *SHOULD NOT* provide ioctl implementations
+        * for these requests.  Instead, provide methods to
+        * support the following code, so that the RTC's main
+        * features are accessible without using ioctls.
+        *
+        * RTC and alarm times will be in UTC, by preference,
+        * but dual-booting with MS-Windows implies RTCs must
+        * use the local wall clock time.
         */
 
        switch (cmd) {
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
new file mode 100644 (file)
index 0000000..7b002ce
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+ * Dallas DS1302 RTC Support
+ *
+ *  Copyright (C) 2002  David McCullough
+ *  Copyright (C) 2003 - 2007  Paul Mundt
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License version 2.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/time.h>
+#include <linux/rtc.h>
+#include <linux/spinlock.h>
+#include <linux/io.h>
+#include <linux/bcd.h>
+#include <asm/rtc.h>
+
+#define DRV_NAME       "rtc-ds1302"
+#define DRV_VERSION    "0.1.0"
+
+#define        RTC_CMD_READ    0x81            /* Read command */
+#define        RTC_CMD_WRITE   0x80            /* Write command */
+
+#define RTC_ADDR_RAM0  0x20            /* Address of RAM0 */
+#define RTC_ADDR_TCR   0x08            /* Address of trickle charge register */
+#define        RTC_ADDR_YEAR   0x06            /* Address of year register */
+#define        RTC_ADDR_DAY    0x05            /* Address of day of week register */
+#define        RTC_ADDR_MON    0x04            /* Address of month register */
+#define        RTC_ADDR_DATE   0x03            /* Address of day of month register */
+#define        RTC_ADDR_HOUR   0x02            /* Address of hour register */
+#define        RTC_ADDR_MIN    0x01            /* Address of minute register */
+#define        RTC_ADDR_SEC    0x00            /* Address of second register */
+
+#define        RTC_RESET       0x1000
+#define        RTC_IODATA      0x0800
+#define        RTC_SCLK        0x0400
+
+#ifdef CONFIG_SH_SECUREEDGE5410
+#include <asm/snapgear.h>
+#define set_dp(x)      SECUREEDGE_WRITE_IOPORT(x, 0x1c00)
+#define get_dp()       SECUREEDGE_READ_IOPORT()
+#else
+#error "Add support for your platform"
+#endif
+
+struct ds1302_rtc {
+       struct rtc_device *rtc_dev;
+       spinlock_t lock;
+};
+
+static void ds1302_sendbits(unsigned int val)
+{
+       int i;
+
+       for (i = 8; (i); i--, val >>= 1) {
+               set_dp((get_dp() & ~RTC_IODATA) | ((val & 0x1) ?
+                       RTC_IODATA : 0));
+               set_dp(get_dp() | RTC_SCLK);    /* clock high */
+               set_dp(get_dp() & ~RTC_SCLK);   /* clock low */
+       }
+}
+
+static unsigned int ds1302_recvbits(void)
+{
+       unsigned int val;
+       int i;
+
+       for (i = 0, val = 0; (i < 8); i++) {
+               val |= (((get_dp() & RTC_IODATA) ? 1 : 0) << i);
+               set_dp(get_dp() | RTC_SCLK);    /* clock high */
+               set_dp(get_dp() & ~RTC_SCLK);   /* clock low */
+       }
+
+       return val;
+}
+
+static unsigned int ds1302_readbyte(unsigned int addr)
+{
+       unsigned int val;
+
+       set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
+
+       set_dp(get_dp() | RTC_RESET);
+       ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_READ);
+       val = ds1302_recvbits();
+       set_dp(get_dp() & ~RTC_RESET);
+
+       return val;
+}
+
+static void ds1302_writebyte(unsigned int addr, unsigned int val)
+{
+       set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
+       set_dp(get_dp() | RTC_RESET);
+       ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_WRITE);
+       ds1302_sendbits(val);
+       set_dp(get_dp() & ~RTC_RESET);
+}
+
+static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+       struct ds1302_rtc *rtc = dev_get_drvdata(dev);
+
+       spin_lock_irq(&rtc->lock);
+
+       tm->tm_sec      = BCD2BIN(ds1302_readbyte(RTC_ADDR_SEC));
+       tm->tm_min      = BCD2BIN(ds1302_readbyte(RTC_ADDR_MIN));
+       tm->tm_hour     = BCD2BIN(ds1302_readbyte(RTC_ADDR_HOUR));
+       tm->tm_wday     = BCD2BIN(ds1302_readbyte(RTC_ADDR_DAY));
+       tm->tm_mday     = BCD2BIN(ds1302_readbyte(RTC_ADDR_DATE));
+       tm->tm_mon      = BCD2BIN(ds1302_readbyte(RTC_ADDR_MON)) - 1;
+       tm->tm_year     = BCD2BIN(ds1302_readbyte(RTC_ADDR_YEAR));
+
+       if (tm->tm_year < 70)
+               tm->tm_year += 100;
+
+       spin_unlock_irq(&rtc->lock);
+
+       dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
+               "mday=%d, mon=%d, year=%d, wday=%d\n",
+               __FUNCTION__,
+               tm->tm_sec, tm->tm_min, tm->tm_hour,
+               tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
+
+       if (rtc_valid_tm(tm) < 0)
+               dev_err(dev, "invalid date\n");
+
+       return 0;
+}
+
+static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+       struct ds1302_rtc *rtc = dev_get_drvdata(dev);
+
+       spin_lock_irq(&rtc->lock);
+
+       /* Stop RTC */
+       ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);
+
+       ds1302_writebyte(RTC_ADDR_SEC, BIN2BCD(tm->tm_sec));
+       ds1302_writebyte(RTC_ADDR_MIN, BIN2BCD(tm->tm_min));
+       ds1302_writebyte(RTC_ADDR_HOUR, BIN2BCD(tm->tm_hour));
+       ds1302_writebyte(RTC_ADDR_DAY, BIN2BCD(tm->tm_wday));
+       ds1302_writebyte(RTC_ADDR_DATE, BIN2BCD(tm->tm_mday));
+       ds1302_writebyte(RTC_ADDR_MON, BIN2BCD(tm->tm_mon + 1));
+       ds1302_writebyte(RTC_ADDR_YEAR, BIN2BCD(tm->tm_year % 100));
+
+       /* Start RTC */
+       ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
+
+       spin_unlock_irq(&rtc->lock);
+
+       return 0;
+}
+
+static int ds1302_rtc_ioctl(struct device *dev, unsigned int cmd,
+                           unsigned long arg)
+{
+       switch (cmd) {
+#ifdef RTC_SET_CHARGE
+       case RTC_SET_CHARGE:
+       {
+               struct ds1302_rtc *rtc = dev_get_drvdata(dev);
+               int tcs_val;
+
+               if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int)))
+                       return -EFAULT;
+
+               spin_lock_irq(&rtc->lock);
+               ds1302_writebyte(RTC_ADDR_TCR, (0xa0 | tcs_val * 0xf));
+               spin_unlock_irq(&rtc->lock);
+               return 0;
+       }
+#endif
+       }
+
+       return -ENOIOCTLCMD;
+}
+
+static struct rtc_class_ops ds1302_rtc_ops = {
+       .read_time      = ds1302_rtc_read_time,
+       .set_time       = ds1302_rtc_set_time,
+       .ioctl          = ds1302_rtc_ioctl,
+};
+
+static int __devinit ds1302_rtc_probe(struct platform_device *pdev)
+{
+       struct ds1302_rtc *rtc;
+       int ret;
+
+       /* Reset */
+       set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
+
+       /* Write a magic value to the DS1302 RAM, and see if it sticks. */
+       ds1302_writebyte(RTC_ADDR_RAM0, 0x42);
+       if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42)
+               return -ENODEV;
+
+       rtc = kzalloc(sizeof(struct ds1302_rtc), GFP_KERNEL);
+       if (unlikely(!rtc))
+               return -ENOMEM;
+
+       spin_lock_init(&rtc->lock);
+       rtc->rtc_dev = rtc_device_register("ds1302", &pdev->dev,
+                                          &ds1302_rtc_ops, THIS_MODULE);
+       if (IS_ERR(rtc->rtc_dev)) {
+               ret = PTR_ERR(rtc->rtc_dev);
+               goto out;
+       }
+
+       platform_set_drvdata(pdev, rtc);
+
+       return 0;
+out:
+       kfree(rtc);
+       return ret;
+}
+
+static int __devexit ds1302_rtc_remove(struct platform_device *pdev)
+{
+       struct ds1302_rtc *rtc = platform_get_drvdata(pdev);
+
+       if (likely(rtc->rtc_dev))
+               rtc_device_unregister(rtc->rtc_dev);
+
+       platform_set_drvdata(pdev, NULL);
+
+       kfree(rtc);
+
+       return 0;
+}
+
+static struct platform_driver ds1302_platform_driver = {
+       .driver         = {
+               .name   = DRV_NAME,
+               .owner  = THIS_MODULE,
+       },
+       .probe          = ds1302_rtc_probe,
+       .remove         = __devexit_p(ds1302_rtc_remove),
+};
+
+static int __init ds1302_rtc_init(void)
+{
+       return platform_driver_register(&ds1302_platform_driver);
+}
+
+static void __exit ds1302_rtc_exit(void)
+{
+       platform_driver_unregister(&ds1302_platform_driver);
+}
+
+module_init(ds1302_rtc_init);
+module_exit(ds1302_rtc_exit);
+
+MODULE_DESCRIPTION("Dallas DS1302 RTC driver");
+MODULE_VERSION(DRV_VERSION);
+MODULE_AUTHOR("Paul Mundt, David McCullough");
+MODULE_LICENSE("GPL v2");
index bc1c7fe94ad3eceaf352e49eb2e6843de924a6e5..f389a28720d2da4302c05a1ef56e2fc5530272a7 100644 (file)
@@ -256,7 +256,7 @@ ds1307_nvram_read(struct kobject *kobj, struct bin_attribute *attr,
        struct i2c_msg          msg[2];
        int                     result;
 
-       client = to_i2c_client(container_of(kobj, struct device, kobj));
+       client = kobj_to_i2c_client(kobj);
        ds1307 = i2c_get_clientdata(client);
 
        if (unlikely(off >= NVRAM_SIZE))
@@ -294,7 +294,7 @@ ds1307_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
        u8                      buffer[NVRAM_SIZE + 1];
        int                     ret;
 
-       client = to_i2c_client(container_of(kobj, struct device, kobj));
+       client = kobj_to_i2c_client(kobj);
 
        if (unlikely(off >= NVRAM_SIZE))
                return -EFBIG;
@@ -412,11 +412,6 @@ read_rtc:
         */
        tmp = ds1307->regs[DS1307_REG_SECS];
        switch (ds1307->type) {
-       case ds_1340:
-               /* FIXME read register with DS1340_BIT_OSF, use that to
-                * trigger the "set time" warning (*after* restarting the
-                * oscillator!) instead of this weaker ds1307/m41t00 test.
-                */
        case ds_1307:
        case m41t00:
                /* clock halted?  turn it on, so clock can tick. */
@@ -440,6 +435,24 @@ read_rtc:
                        goto read_rtc;
                }
                break;
+       case ds_1340:
+               /* clock halted?  turn it on, so clock can tick. */
+               if (tmp & DS1340_BIT_nEOSC)
+                       i2c_smbus_write_byte_data(client, DS1307_REG_SECS, 0);
+
+               tmp = i2c_smbus_read_byte_data(client, DS1340_REG_FLAG);
+               if (tmp < 0) {
+                       pr_debug("read error %d\n", tmp);
+                       err = -EIO;
+                       goto exit_free;
+               }
+
+               /* oscillator fault?  clear flag, and warn */
+               if (tmp & DS1340_BIT_OSF) {
+                       i2c_smbus_write_byte_data(client, DS1340_REG_FLAG, 0);
+                       dev_warn(&client->dev, "SET TIME!\n");
+               }
+               break;
        case ds_1337:
        case ds_1339:
                break;
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
new file mode 100644 (file)
index 0000000..d74b808
--- /dev/null
@@ -0,0 +1,656 @@
+/*
+ * An rtc driver for the Dallas DS1511
+ *
+ * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
+ * Copyright (C) 2007 Andrew Sharp <andy.sharp@onstor.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Real time clock driver for the Dallas 1511 chip, which also
+ * contains a watchdog timer.  There is a tiny amount of code that
+ * platform code could use to mess with the watchdog device a little
+ * bit, but not a full watchdog driver.
+ */
+
+#include <linux/bcd.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/rtc.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+
+#define DRV_VERSION "0.6"
+
+enum ds1511reg {
+       DS1511_SEC = 0x0,
+       DS1511_MIN = 0x1,
+       DS1511_HOUR = 0x2,
+       DS1511_DOW = 0x3,
+       DS1511_DOM = 0x4,
+       DS1511_MONTH = 0x5,
+       DS1511_YEAR = 0x6,
+       DS1511_CENTURY = 0x7,
+       DS1511_AM1_SEC = 0x8,
+       DS1511_AM2_MIN = 0x9,
+       DS1511_AM3_HOUR = 0xa,
+       DS1511_AM4_DATE = 0xb,
+       DS1511_WD_MSEC = 0xc,
+       DS1511_WD_SEC = 0xd,
+       DS1511_CONTROL_A = 0xe,
+       DS1511_CONTROL_B = 0xf,
+       DS1511_RAMADDR_LSB = 0x10,
+       DS1511_RAMDATA = 0x13
+};
+
+#define DS1511_BLF1    0x80
+#define DS1511_BLF2    0x40
+#define DS1511_PRS     0x20
+#define DS1511_PAB     0x10
+#define DS1511_TDF     0x08
+#define DS1511_KSF     0x04
+#define DS1511_WDF     0x02
+#define DS1511_IRQF    0x01
+#define DS1511_TE      0x80
+#define DS1511_CS      0x40
+#define DS1511_BME     0x20
+#define DS1511_TPE     0x10
+#define DS1511_TIE     0x08
+#define DS1511_KIE     0x04
+#define DS1511_WDE     0x02
+#define DS1511_WDS     0x01
+#define DS1511_RAM_MAX 0xff
+
+#define RTC_CMD                DS1511_CONTROL_B
+#define RTC_CMD1       DS1511_CONTROL_A
+
+#define RTC_ALARM_SEC  DS1511_AM1_SEC
+#define RTC_ALARM_MIN  DS1511_AM2_MIN
+#define RTC_ALARM_HOUR DS1511_AM3_HOUR
+#define RTC_ALARM_DATE DS1511_AM4_DATE
+
+#define RTC_SEC                DS1511_SEC
+#define RTC_MIN                DS1511_MIN
+#define RTC_HOUR       DS1511_HOUR
+#define RTC_DOW                DS1511_DOW
+#define RTC_DOM                DS1511_DOM
+#define RTC_MON                DS1511_MONTH
+#define RTC_YEAR       DS1511_YEAR
+#define RTC_CENTURY    DS1511_CENTURY
+
+#define RTC_TIE        DS1511_TIE
+#define RTC_TE DS1511_TE
+
+struct rtc_plat_data {
+       struct rtc_device *rtc;
+       void __iomem *ioaddr;           /* virtual base address */
+       unsigned long baseaddr;         /* physical base address */
+       int size;                               /* amount of memory mapped */
+       int irq;
+       unsigned int irqen;
+       int alrm_sec;
+       int alrm_min;
+       int alrm_hour;
+       int alrm_mday;
+};
+
+static DEFINE_SPINLOCK(ds1511_lock);
+
+static __iomem char *ds1511_base;
+static u32 reg_spacing = 1;
+
+ static noinline void
+rtc_write(uint8_t val, uint32_t reg)
+{
+       writeb(val, ds1511_base + (reg * reg_spacing));
+}
+
+ static inline void
+rtc_write_alarm(uint8_t val, enum ds1511reg reg)
+{
+       rtc_write((val | 0x80), reg);
+}
+
+ static noinline uint8_t
+rtc_read(enum ds1511reg reg)
+{
+       return readb(ds1511_base + (reg * reg_spacing));
+}
+
+ static inline void
+rtc_disable_update(void)
+{
+       rtc_write((rtc_read(RTC_CMD) & ~RTC_TE), RTC_CMD);
+}
+
+ static void
+rtc_enable_update(void)
+{
+       rtc_write((rtc_read(RTC_CMD) | RTC_TE), RTC_CMD);
+}
+
+/*
+ * #define DS1511_WDOG_RESET_SUPPORT
+ *
+ * Uncomment this if you want to use these routines in
+ * some platform code.
+ */
+#ifdef DS1511_WDOG_RESET_SUPPORT
+/*
+ * just enough code to set the watchdog timer so that it
+ * will reboot the system
+ */
+ void
+ds1511_wdog_set(unsigned long deciseconds)
+{
+       /*
+        * the wdog timer can take 99.99 seconds
+        */
+       deciseconds %= 10000;
+       /*
+        * set the wdog values in the wdog registers
+        */
+       rtc_write(BIN2BCD(deciseconds % 100), DS1511_WD_MSEC);
+       rtc_write(BIN2BCD(deciseconds / 100), DS1511_WD_SEC);
+       /*
+        * set wdog enable and wdog 'steering' bit to issue a reset
+        */
+       rtc_write(DS1511_WDE | DS1511_WDS, RTC_CMD);
+}
+
+ void
+ds1511_wdog_disable(void)
+{
+       /*
+        * clear wdog enable and wdog 'steering' bits
+        */
+       rtc_write(rtc_read(RTC_CMD) & ~(DS1511_WDE | DS1511_WDS), RTC_CMD);
+       /*
+        * clear the wdog counter
+        */
+       rtc_write(0, DS1511_WD_MSEC);
+       rtc_write(0, DS1511_WD_SEC);
+}
+#endif
+
+/*
+ * set the rtc chip's idea of the time.
+ * stupidly, some callers call with year unmolested;
+ * and some call with  year = year - 1900.  thanks.
+ */
+ int
+ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
+{
+       u8 mon, day, dow, hrs, min, sec, yrs, cen;
+       unsigned int flags;
+
+       /*
+        * won't have to change this for a while
+        */
+       if (rtc_tm->tm_year < 1900) {
+               rtc_tm->tm_year += 1900;
+       }
+
+       if (rtc_tm->tm_year < 1970) {
+               return -EINVAL;
+       }
+       yrs = rtc_tm->tm_year % 100;
+       cen = rtc_tm->tm_year / 100;
+       mon = rtc_tm->tm_mon + 1;   /* tm_mon starts at zero */
+       day = rtc_tm->tm_mday;
+       dow = rtc_tm->tm_wday & 0x7; /* automatic BCD */
+       hrs = rtc_tm->tm_hour;
+       min = rtc_tm->tm_min;
+       sec = rtc_tm->tm_sec;
+
+       if ((mon > 12) || (day == 0)) {
+               return -EINVAL;
+       }
+
+       if (day > rtc_month_days(rtc_tm->tm_mon, rtc_tm->tm_year)) {
+               return -EINVAL;
+       }
+
+       if ((hrs >= 24) || (min >= 60) || (sec >= 60)) {
+               return -EINVAL;
+       }
+
+       /*
+        * each register is a different number of valid bits
+        */
+       sec = BIN2BCD(sec) & 0x7f;
+       min = BIN2BCD(min) & 0x7f;
+       hrs = BIN2BCD(hrs) & 0x3f;
+       day = BIN2BCD(day) & 0x3f;
+       mon = BIN2BCD(mon) & 0x1f;
+       yrs = BIN2BCD(yrs) & 0xff;
+       cen = BIN2BCD(cen) & 0xff;
+
+       spin_lock_irqsave(&ds1511_lock, flags);
+       rtc_disable_update();
+       rtc_write(cen, RTC_CENTURY);
+       rtc_write(yrs, RTC_YEAR);
+       rtc_write((rtc_read(RTC_MON) & 0xe0) | mon, RTC_MON);
+       rtc_write(day, RTC_DOM);
+       rtc_write(hrs, RTC_HOUR);
+       rtc_write(min, RTC_MIN);
+       rtc_write(sec, RTC_SEC);
+       rtc_write(dow, RTC_DOW);
+       rtc_enable_update();
+       spin_unlock_irqrestore(&ds1511_lock, flags);
+
+       return 0;
+}
+
+ int
+ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
+{
+       unsigned int century;
+       unsigned int flags;
+
+       spin_lock_irqsave(&ds1511_lock, flags);
+       rtc_disable_update();
+
+       rtc_tm->tm_sec = rtc_read(RTC_SEC) & 0x7f;
+       rtc_tm->tm_min = rtc_read(RTC_MIN) & 0x7f;
+       rtc_tm->tm_hour = rtc_read(RTC_HOUR) & 0x3f;
+       rtc_tm->tm_mday = rtc_read(RTC_DOM) & 0x3f;
+       rtc_tm->tm_wday = rtc_read(RTC_DOW) & 0x7;
+       rtc_tm->tm_mon = rtc_read(RTC_MON) & 0x1f;
+       rtc_tm->tm_year = rtc_read(RTC_YEAR) & 0x7f;
+       century = rtc_read(RTC_CENTURY);
+
+       rtc_enable_update();
+       spin_unlock_irqrestore(&ds1511_lock, flags);
+
+       rtc_tm->tm_sec = BCD2BIN(rtc_tm->tm_sec);
+       rtc_tm->tm_min = BCD2BIN(rtc_tm->tm_min);
+       rtc_tm->tm_hour = BCD2BIN(rtc_tm->tm_hour);
+       rtc_tm->tm_mday = BCD2BIN(rtc_tm->tm_mday);
+       rtc_tm->tm_wday = BCD2BIN(rtc_tm->tm_wday);
+       rtc_tm->tm_mon = BCD2BIN(rtc_tm->tm_mon);
+       rtc_tm->tm_year = BCD2BIN(rtc_tm->tm_year);
+       century = BCD2BIN(century) * 100;
+
+       /*
+        * Account for differences between how the RTC uses the values
+        * and how they are defined in a struct rtc_time;
+        */
+       century += rtc_tm->tm_year;
+       rtc_tm->tm_year = century - 1900;
+
+       rtc_tm->tm_mon--;
+
+       if (rtc_valid_tm(rtc_tm) < 0) {
+               dev_err(dev, "retrieved date/time is not valid.\n");
+               rtc_time_to_tm(0, rtc_tm);
+       }
+       return 0;
+}
+
+/*
+ * write the alarm register settings
+ *
+ * we only have the use to interrupt every second, otherwise
+ * known as the update interrupt, or the interrupt if the whole
+ * date/hours/mins/secs matches.  the ds1511 has many more
+ * permutations, but the kernel doesn't.
+ */
+ static void
+ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&pdata->rtc->irq_lock, flags);
+       rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
+              0x80 : BIN2BCD(pdata->alrm_mday) & 0x3f,
+              RTC_ALARM_DATE);
+       rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
+              0x80 : BIN2BCD(pdata->alrm_hour) & 0x3f,
+              RTC_ALARM_HOUR);
+       rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
+              0x80 : BIN2BCD(pdata->alrm_min) & 0x7f,
+              RTC_ALARM_MIN);
+       rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
+              0x80 : BIN2BCD(pdata->alrm_sec) & 0x7f,
+              RTC_ALARM_SEC);
+       rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD);
+       rtc_read(RTC_CMD1);     /* clear interrupts */
+       spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags);
+}
+
+ static int
+ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+
+       if (pdata->irq < 0) {
+               return -EINVAL;
+       }
+       pdata->alrm_mday = alrm->time.tm_mday;
+       pdata->alrm_hour = alrm->time.tm_hour;
+       pdata->alrm_min = alrm->time.tm_min;
+       pdata->alrm_sec = alrm->time.tm_sec;
+       if (alrm->enabled) {
+               pdata->irqen |= RTC_AF;
+       }
+       ds1511_rtc_update_alarm(pdata);
+       return 0;
+}
+
+ static int
+ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+
+       if (pdata->irq < 0) {
+               return -EINVAL;
+       }
+       alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday;
+       alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour;
+       alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min;
+       alrm->time.tm_sec = pdata->alrm_sec < 0 ? 0 : pdata->alrm_sec;
+       alrm->enabled = (pdata->irqen & RTC_AF) ? 1 : 0;
+       return 0;
+}
+
+ static irqreturn_t
+ds1511_interrupt(int irq, void *dev_id)
+{
+       struct platform_device *pdev = dev_id;
+       struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+       unsigned long events = RTC_IRQF;
+
+       /*
+        * read and clear interrupt
+        */
+       if (!(rtc_read(RTC_CMD1) & DS1511_IRQF)) {
+               return IRQ_NONE;
+       }
+       if (rtc_read(RTC_ALARM_SEC) & 0x80) {
+               events |= RTC_UF;
+       } else {
+               events |= RTC_AF;
+       }
+       rtc_update_irq(pdata->rtc, 1, events);
+       return IRQ_HANDLED;
+}
+
+ static void
+ds1511_rtc_release(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+
+       if (pdata->irq >= 0) {
+               pdata->irqen = 0;
+               ds1511_rtc_update_alarm(pdata);
+       }
+}
+
+ static int
+ds1511_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+
+       if (pdata->irq < 0) {
+               return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */
+       }
+       switch (cmd) {
+       case RTC_AIE_OFF:
+               pdata->irqen &= ~RTC_AF;
+               ds1511_rtc_update_alarm(pdata);
+               break;
+       case RTC_AIE_ON:
+               pdata->irqen |= RTC_AF;
+               ds1511_rtc_update_alarm(pdata);
+               break;
+       case RTC_UIE_OFF:
+               pdata->irqen &= ~RTC_UF;
+               ds1511_rtc_update_alarm(pdata);
+               break;
+       case RTC_UIE_ON:
+               pdata->irqen |= RTC_UF;
+               ds1511_rtc_update_alarm(pdata);
+               break;
+       default:
+               return -ENOIOCTLCMD;
+       }
+       return 0;
+}
+
+static const struct rtc_class_ops ds1511_rtc_ops = {
+       .read_time      = ds1511_rtc_read_time,
+       .set_time       = ds1511_rtc_set_time,
+       .read_alarm     = ds1511_rtc_read_alarm,
+       .set_alarm      = ds1511_rtc_set_alarm,
+       .release        = ds1511_rtc_release,
+       .ioctl          = ds1511_rtc_ioctl,
+};
+
+ static ssize_t
+ds1511_nvram_read(struct kobject *kobj, struct bin_attribute *ba,
+                               char *buf, loff_t pos, size_t size)
+{
+       ssize_t count;
+
+       /*
+        * if count is more than one, turn on "burst" mode
+        * turn it off when you're done
+        */
+       if (size > 1) {
+               rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD);
+       }
+       if (pos > DS1511_RAM_MAX) {
+               pos = DS1511_RAM_MAX;
+       }
+       if (size + pos > DS1511_RAM_MAX + 1) {
+               size = DS1511_RAM_MAX - pos + 1;
+       }
+       rtc_write(pos, DS1511_RAMADDR_LSB);
+       for (count = 0; size > 0; count++, size--) {
+               *buf++ = rtc_read(DS1511_RAMDATA);
+       }
+       if (count > 1) {
+               rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD);
+       }
+       return count;
+}
+
+ static ssize_t
+ds1511_nvram_write(struct kobject *kobj, struct bin_attribute *bin_attr,
+                               char *buf, loff_t pos, size_t size)
+{
+       ssize_t count;
+
+       /*
+        * if count is more than one, turn on "burst" mode
+        * turn it off when you're done
+        */
+       if (size > 1) {
+               rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD);
+       }
+       if (pos > DS1511_RAM_MAX) {
+               pos = DS1511_RAM_MAX;
+       }
+       if (size + pos > DS1511_RAM_MAX + 1) {
+               size = DS1511_RAM_MAX - pos + 1;
+       }
+       rtc_write(pos, DS1511_RAMADDR_LSB);
+       for (count = 0; size > 0; count++, size--) {
+               rtc_write(*buf++, DS1511_RAMDATA);
+       }
+       if (count > 1) {
+               rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD);
+       }
+       return count;
+}
+
+static struct bin_attribute ds1511_nvram_attr = {
+       .attr = {
+               .name = "nvram",
+               .mode = S_IRUGO | S_IWUGO,
+               .owner = THIS_MODULE,
+       },
+       .size = DS1511_RAM_MAX,
+       .read = ds1511_nvram_read,
+       .write = ds1511_nvram_write,
+};
+
+ static int __devinit
+ds1511_rtc_probe(struct platform_device *pdev)
+{
+       struct rtc_device *rtc;
+       struct resource *res;
+       struct rtc_plat_data *pdata = NULL;
+       int ret = 0;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               return -ENODEV;
+       }
+       pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+       if (!pdata) {
+               return -ENOMEM;
+       }
+       pdata->irq = -1;
+       pdata->size = res->end - res->start + 1;
+       if (!request_mem_region(res->start, pdata->size, pdev->name)) {
+               ret = -EBUSY;
+               goto out;
+       }
+       pdata->baseaddr = res->start;
+       pdata->size = pdata->size;
+       ds1511_base = ioremap(pdata->baseaddr, pdata->size);
+       if (!ds1511_base) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       pdata->ioaddr = ds1511_base;
+       pdata->irq = platform_get_irq(pdev, 0);
+
+       /*
+        * turn on the clock and the crystal, etc.
+        */
+       rtc_write(0, RTC_CMD);
+       rtc_write(0, RTC_CMD1);
+       /*
+        * clear the wdog counter
+        */
+       rtc_write(0, DS1511_WD_MSEC);
+       rtc_write(0, DS1511_WD_SEC);
+       /*
+        * start the clock
+        */
+       rtc_enable_update();
+
+       /*
+        * check for a dying bat-tree
+        */
+       if (rtc_read(RTC_CMD1) & DS1511_BLF1) {
+               dev_warn(&pdev->dev, "voltage-low detected.\n");
+       }
+
+       /*
+        * if the platform has an interrupt in mind for this device,
+        * then by all means, set it
+        */
+       if (pdata->irq >= 0) {
+               rtc_read(RTC_CMD1);
+               if (request_irq(pdata->irq, ds1511_interrupt,
+                       IRQF_DISABLED | IRQF_SHARED, pdev->name, pdev) < 0) {
+
+                       dev_warn(&pdev->dev, "interrupt not available.\n");
+                       pdata->irq = -1;
+               }
+       }
+
+       rtc = rtc_device_register(pdev->name, &pdev->dev, &ds1511_rtc_ops,
+               THIS_MODULE);
+       if (IS_ERR(rtc)) {
+               ret = PTR_ERR(rtc);
+               goto out;
+       }
+       pdata->rtc = rtc;
+       platform_set_drvdata(pdev, pdata);
+       ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
+       if (ret) {
+               goto out;
+       }
+       return 0;
+ out:
+       if (pdata->rtc) {
+               rtc_device_unregister(pdata->rtc);
+       }
+       if (pdata->irq >= 0) {
+               free_irq(pdata->irq, pdev);
+       }
+       if (ds1511_base) {
+               iounmap(ds1511_base);
+               ds1511_base = NULL;
+       }
+       if (pdata->baseaddr) {
+               release_mem_region(pdata->baseaddr, pdata->size);
+       }
+
+       kfree(pdata);
+       return ret;
+}
+
+ static int __devexit
+ds1511_rtc_remove(struct platform_device *pdev)
+{
+       struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
+
+       sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
+       rtc_device_unregister(pdata->rtc);
+       pdata->rtc = NULL;
+       if (pdata->irq >= 0) {
+               /*
+                * disable the alarm interrupt
+                */
+               rtc_write(rtc_read(RTC_CMD) & ~RTC_TIE, RTC_CMD);
+               rtc_read(RTC_CMD1);
+               free_irq(pdata->irq, pdev);
+       }
+       iounmap(pdata->ioaddr);
+       ds1511_base = NULL;
+       release_mem_region(pdata->baseaddr, pdata->size);
+       kfree(pdata);
+       return 0;
+}
+
+static struct platform_driver ds1511_rtc_driver = {
+       .probe          = ds1511_rtc_probe,
+       .remove         = __devexit_p(ds1511_rtc_remove),
+       .driver         = {
+               .name   = "ds1511",
+               .owner  = THIS_MODULE,
+       },
+};
+
+ static int __init
+ds1511_rtc_init(void)
+{
+       return platform_driver_register(&ds1511_rtc_driver);
+}
+
+ static void __exit
+ds1511_rtc_exit(void)
+{
+       return platform_driver_unregister(&ds1511_rtc_driver);
+}
+
+module_init(ds1511_rtc_init);
+module_exit(ds1511_rtc_exit);
+
+MODULE_AUTHOR("Andrew Sharp <andy.sharp@onstor.com>");
+MODULE_DESCRIPTION("Dallas DS1511 RTC driver");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRV_VERSION);
index c973ba94c422bc182c8b994dfd877dac967030bc..8b3997007506bbc44a0205e586acfd8f75e042ae 100644 (file)
@@ -163,27 +163,17 @@ static int pcf8583_read_mem(struct i2c_client *client, struct rtc_mem *mem)
 
 static int pcf8583_write_mem(struct i2c_client *client, struct rtc_mem *mem)
 {
-       unsigned char addr[1];
-       struct i2c_msg msgs[2] = {
-               {
-                       .addr = client->addr,
-                       .flags = 0,
-                       .len = 1,
-                       .buf = addr,
-               }, {
-                       .addr = client->addr,
-                       .flags = I2C_M_NOSTART,
-                       .len = mem->nr,
-                       .buf = mem->data,
-               }
-       };
+       unsigned char buf[9];
+       int ret;
 
-       if (mem->loc < 8)
+       if (mem->loc < 8 || mem->nr > 8)
                return -EINVAL;
 
-       addr[0] = mem->loc;
+       buf[0] = mem->loc;
+       memcpy(buf + 1, mem->data, mem->nr);
 
-       return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO;
+       ret = i2c_master_send(client, buf, mem->nr + 1);
+       return ret == mem->nr + 1 ? 0 : -EIO;
 }
 
 static int pcf8583_rtc_read_time(struct device *dev, struct rtc_time *tm)
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
new file mode 100644 (file)
index 0000000..a64626a
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * Driver for Epson RTC-9701JE
+ *
+ * Copyright (C) 2008 Magnus Damm
+ *
+ * Based on rtc-max6902.c
+ *
+ * Copyright (C) 2006 8D Technologies inc.
+ * Copyright (C) 2004 Compulab Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/rtc.h>
+#include <linux/spi/spi.h>
+#include <linux/bcd.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+
+#define RSECCNT        0x00    /* Second Counter */
+#define RMINCNT        0x01    /* Minute Counter */
+#define RHRCNT 0x02    /* Hour Counter */
+#define RWKCNT 0x03    /* Week Counter */
+#define RDAYCNT        0x04    /* Day Counter */
+#define RMONCNT        0x05    /* Month Counter */
+#define RYRCNT 0x06    /* Year Counter */
+#define R100CNT        0x07    /* Y100 Counter */
+#define RMINAR 0x08    /* Minute Alarm */
+#define RHRAR  0x09    /* Hour Alarm */
+#define RWKAR  0x0a    /* Week/Day Alarm */
+#define RTIMCNT        0x0c    /* Interval Timer */
+#define REXT   0x0d    /* Extension Register */
+#define RFLAG  0x0e    /* RTC Flag Register */
+#define RCR    0x0f    /* RTC Control Register */
+
+static int write_reg(struct device *dev, int address, unsigned char data)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       unsigned char buf[2];
+
+       buf[0] = address & 0x7f;
+       buf[1] = data;
+
+       return spi_write(spi, buf, ARRAY_SIZE(buf));
+}
+
+static int read_regs(struct device *dev, unsigned char *regs, int no_regs)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       u8 txbuf[1], rxbuf[1];
+       int k, ret;
+
+       ret = 0;
+
+       for (k = 0; ret == 0 && k < no_regs; k++) {
+               txbuf[0] = 0x80 | regs[k];
+               ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1);
+               regs[k] = rxbuf[0];
+       }
+
+       return ret;
+}
+
+static int r9701_get_datetime(struct device *dev, struct rtc_time *dt)
+{
+       unsigned long time;
+       int ret;
+       unsigned char buf[] = { RSECCNT, RMINCNT, RHRCNT,
+                               RDAYCNT, RMONCNT, RYRCNT };
+
+       ret = read_regs(dev, buf, ARRAY_SIZE(buf));
+       if (ret)
+               return ret;
+
+       memset(dt, 0, sizeof(*dt));
+
+       dt->tm_sec = BCD2BIN(buf[0]); /* RSECCNT */
+       dt->tm_min = BCD2BIN(buf[1]); /* RMINCNT */
+       dt->tm_hour = BCD2BIN(buf[2]); /* RHRCNT */
+
+       dt->tm_mday = BCD2BIN(buf[3]); /* RDAYCNT */
+       dt->tm_mon = BCD2BIN(buf[4]) - 1; /* RMONCNT */
+       dt->tm_year = BCD2BIN(buf[5]) + 100; /* RYRCNT */
+
+       /* the rtc device may contain illegal values on power up
+        * according to the data sheet. make sure they are valid.
+        */
+
+       return rtc_valid_tm(dt);
+}
+
+static int r9701_set_datetime(struct device *dev, struct rtc_time *dt)
+{
+       int ret, year;
+
+       year = dt->tm_year + 1900;
+       if (year >= 2100 || year < 2000)
+               return -EINVAL;
+
+       ret = write_reg(dev, RHRCNT, BIN2BCD(dt->tm_hour));
+       ret = ret ? ret : write_reg(dev, RMINCNT, BIN2BCD(dt->tm_min));
+       ret = ret ? ret : write_reg(dev, RSECCNT, BIN2BCD(dt->tm_sec));
+       ret = ret ? ret : write_reg(dev, RDAYCNT, BIN2BCD(dt->tm_mday));
+       ret = ret ? ret : write_reg(dev, RMONCNT, BIN2BCD(dt->tm_mon + 1));
+       ret = ret ? ret : write_reg(dev, RYRCNT, BIN2BCD(dt->tm_year - 100));
+       ret = ret ? ret : write_reg(dev, RWKCNT, 1 << dt->tm_wday);
+
+       return ret;
+}
+
+static const struct rtc_class_ops r9701_rtc_ops = {
+       .read_time      = r9701_get_datetime,
+       .set_time       = r9701_set_datetime,
+};
+
+static int __devinit r9701_probe(struct spi_device *spi)
+{
+       struct rtc_device *rtc;
+       unsigned char tmp;
+       int res;
+
+       rtc = rtc_device_register("r9701",
+                               &spi->dev, &r9701_rtc_ops, THIS_MODULE);
+       if (IS_ERR(rtc))
+               return PTR_ERR(rtc);
+
+       dev_set_drvdata(&spi->dev, rtc);
+
+       tmp = R100CNT;
+       res = read_regs(&spi->dev, &tmp, 1);
+       if (res || tmp != 0x20) {
+               rtc_device_unregister(rtc);
+               return res;
+       }
+
+       return 0;
+}
+
+static int __devexit r9701_remove(struct spi_device *spi)
+{
+       struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
+
+       rtc_device_unregister(rtc);
+       return 0;
+}
+
+static struct spi_driver r9701_driver = {
+       .driver = {
+               .name   = "rtc-r9701",
+               .owner  = THIS_MODULE,
+       },
+       .probe  = r9701_probe,
+       .remove = __devexit_p(r9701_remove),
+};
+
+static __init int r9701_init(void)
+{
+       return spi_register_driver(&r9701_driver);
+}
+module_init(r9701_init);
+
+static __exit void r9701_exit(void)
+{
+       spi_unregister_driver(&r9701_driver);
+}
+module_exit(r9701_exit);
+
+MODULE_DESCRIPTION("r9701 spi RTC driver");
+MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
+MODULE_LICENSE("GPL");
index e2041b4d0c8569ba93791a166520145e8cdaa9cd..86766f1f24965f07c7b2efce8a8d793e1e06445d 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/rtc.h>
 #include <linux/bcd.h>
 #include <linux/clk.h>
+#include <linux/log2.h>
 
 #include <asm/hardware.h>
 #include <asm/uaccess.h>
@@ -309,9 +310,7 @@ static int s3c_rtc_ioctl(struct device *dev,
                break;
 
        case RTC_IRQP_SET:
-               /* check for power of 2 */
-
-               if ((arg & (arg-1)) != 0 || arg < 1) {
+               if (!is_power_of_2(arg)) {
                        ret = -EINVAL;
                        goto exit;
                }
index 2eb38520f0c8cf267f57360ae16970623e316588..ee253cc45de1e1b1ed0df26ce7c3e73d243b30b2 100644 (file)
@@ -357,23 +357,15 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM
 static int sa1100_rtc_suspend(struct platform_device *pdev, pm_message_t state)
 {
-       if (pdev->dev.power.power_state.event != state.event) {
-               if (state.event == PM_EVENT_SUSPEND &&
-                   device_may_wakeup(&pdev->dev))
-                       enable_irq_wake(IRQ_RTCAlrm);
-
-               pdev->dev.power.power_state = state;
-       }
+       if (device_may_wakeup(&pdev->dev))
+               enable_irq_wake(IRQ_RTCAlrm);
        return 0;
 }
 
 static int sa1100_rtc_resume(struct platform_device *pdev)
 {
-       if (pdev->dev.power.power_state.event != PM_EVENT_ON) {
-               if (device_may_wakeup(&pdev->dev))
-                       disable_irq_wake(IRQ_RTCAlrm);
-               pdev->dev.power.power_state = PMSG_ON;
-       }
+       if (device_may_wakeup(&pdev->dev))
+               disable_irq_wake(IRQ_RTCAlrm);
        return 0;
 }
 #else
index 2ae0e8304d3aa83bd7f75cdd6052b4394ba31a8b..4d27ccc4fc069c174d5785ddfa7ad27aa55b35b4 100644 (file)
 
 /* device attributes */
 
+/*
+ * NOTE:  RTC times displayed in sysfs use the RTC's timezone.  That's
+ * ideally UTC.  However, PCs that also boot to MS-Windows normally use
+ * the local time and change to match daylight savings time.  That affects
+ * attributes including date, time, since_epoch, and wakealarm.
+ */
+
 static ssize_t
 rtc_sysfs_show_name(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -113,13 +120,13 @@ rtc_sysfs_show_wakealarm(struct device *dev, struct device_attribute *attr,
        unsigned long alarm;
        struct rtc_wkalrm alm;
 
-       /* Don't show disabled alarms; but the RTC could leave the
-        * alarm enabled after it's already triggered.  Alarms are
-        * conceptually one-shot, even though some common hardware
-        * (PCs) doesn't actually work that way.
+       /* Don't show disabled alarms.  For uniformity, RTC alarms are
+        * conceptually one-shot, even though some common RTCs (on PCs)
+        * don't actually work that way.
         *
-        * REVISIT maybe we should require RTC implementations to
-        * disable the RTC alarm after it triggers, for uniformity.
+        * NOTE: RTC implementations where the alarm doesn't match an
+        * exact YYYY-MM-DD HH:MM[:SS] date *must* disable their RTC
+        * alarms after they trigger, to ensure one-shot semantics.
         */
        retval = rtc_read_alarm(to_rtc_device(dev), &alm);
        if (retval == 0 && alm.enabled) {
index d640427c74c816172b38cfae6bb2529f7b344e37..d984e0fae63054fe1c53a249534a85603ea8887d 100644 (file)
@@ -1057,12 +1057,11 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
                if (device->features & DASD_FEATURE_ERPLOG) {
                        dasd_log_sense(cqr, irb);
                }
-               /* If we have no sense data, or we just don't want complex ERP
-                * for this request, but if we have retries left, then just
-                * reset this request and retry it in the fastpath
+               /*
+                * If we don't want complex ERP for this request, then just
+                * reset this and retry it in the fastpath
                 */
-               if (!(cqr->irb.esw.esw0.erw.cons &&
-                     test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) &&
+               if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
                    cqr->retries > 0) {
                        DEV_MESSAGE(KERN_DEBUG, device,
                                    "default ERP in fastpath (%i retries left)",
@@ -1707,7 +1706,7 @@ static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
 
        req = (struct request *) cqr->callback_data;
        dasd_profile_end(cqr->block, cqr, req);
-       status = cqr->memdev->discipline->free_cp(cqr, req);
+       status = cqr->block->base->discipline->free_cp(cqr, req);
        if (status <= 0)
                error = status ? status : -EIO;
        dasd_end_request(req, error);
@@ -1742,12 +1741,8 @@ restart:
 
                /*  Process requests that may be recovered */
                if (cqr->status == DASD_CQR_NEED_ERP) {
-                       if (cqr->irb.esw.esw0.erw.cons &&
-                           test_bit(DASD_CQR_FLAGS_USE_ERP,
-                                    &cqr->flags)) {
-                               erp_fn = base->discipline->erp_action(cqr);
-                               erp_fn(cqr);
-                       }
+                       erp_fn = base->discipline->erp_action(cqr);
+                       erp_fn(cqr);
                        goto restart;
                }
 
index c361ab69ec0023c3eae201d50b4d10a2acb6b595..f69714a0e9e7bf3ed750e3b497ce429d2f459ffb 100644 (file)
@@ -164,7 +164,7 @@ dasd_3990_erp_alternate_path(struct dasd_ccw_req * erp)
 
                /* reset status to submit the request again... */
                erp->status = DASD_CQR_FILLED;
-               erp->retries = 1;
+               erp->retries = 10;
        } else {
                DEV_MESSAGE(KERN_ERR, device,
                            "No alternate channel path left (lpum=%x / "
@@ -301,8 +301,7 @@ dasd_3990_erp_action_4(struct dasd_ccw_req * erp, char *sense)
                erp->function = dasd_3990_erp_action_4;
 
        } else {
-
-               if (sense[25] == 0x1D) {        /* state change pending */
+               if (sense && (sense[25] == 0x1D)) { /* state change pending */
 
                        DEV_MESSAGE(KERN_INFO, device,
                                    "waiting for state change pending "
@@ -311,7 +310,7 @@ dasd_3990_erp_action_4(struct dasd_ccw_req * erp, char *sense)
 
                        dasd_3990_erp_block_queue(erp, 30*HZ);
 
-                } else if (sense[25] == 0x1E) {        /* busy */
+               } else if (sense && (sense[25] == 0x1E)) {      /* busy */
                        DEV_MESSAGE(KERN_INFO, device,
                                    "busy - redriving request later, "
                                    "%d retries left",
@@ -2119,6 +2118,34 @@ dasd_3990_erp_inspect_32(struct dasd_ccw_req * erp, char *sense)
  *****************************************************************************
  */
 
+/*
+ * DASD_3990_ERP_CONTROL_CHECK
+ *
+ * DESCRIPTION
+ *   Does a generic inspection if a control check occured and sets up
+ *   the related error recovery procedure
+ *
+ * PARAMETER
+ *   erp               pointer to the currently created default ERP
+ *
+ * RETURN VALUES
+ *   erp_filled                pointer to the erp
+ */
+
+static struct dasd_ccw_req *
+dasd_3990_erp_control_check(struct dasd_ccw_req *erp)
+{
+       struct dasd_device *device = erp->startdev;
+
+       if (erp->refers->irb.scsw.cstat & (SCHN_STAT_INTF_CTRL_CHK
+                                          | SCHN_STAT_CHN_CTRL_CHK)) {
+               DEV_MESSAGE(KERN_DEBUG, device, "%s",
+                           "channel or interface control check");
+               erp = dasd_3990_erp_action_4(erp, NULL);
+       }
+       return erp;
+}
+
 /*
  * DASD_3990_ERP_INSPECT
  *
@@ -2145,8 +2172,11 @@ dasd_3990_erp_inspect(struct dasd_ccw_req * erp)
        if (erp_new)
                return erp_new;
 
+       /* check if no concurrent sens is available */
+       if (!erp->refers->irb.esw.esw0.erw.cons)
+               erp_new = dasd_3990_erp_control_check(erp);
        /* distinguish between 24 and 32 byte sense data */
-       if (sense[27] & DASD_SENSE_BIT_0) {
+       else if (sense[27] & DASD_SENSE_BIT_0) {
 
                /* inspect the 24 byte sense data */
                erp_new = dasd_3990_erp_inspect_24(erp, sense);
@@ -2285,6 +2315,17 @@ dasd_3990_erp_error_match(struct dasd_ccw_req *cqr1, struct dasd_ccw_req *cqr2)
                //      return 0;       /* CCW doesn't match */
        }
 
+       if (cqr1->irb.esw.esw0.erw.cons != cqr2->irb.esw.esw0.erw.cons)
+               return 0;
+
+       if ((cqr1->irb.esw.esw0.erw.cons == 0) &&
+           (cqr2->irb.esw.esw0.erw.cons == 0)) {
+               if ((cqr1->irb.scsw.cstat & (SCHN_STAT_INTF_CTRL_CHK |
+                                            SCHN_STAT_CHN_CTRL_CHK)) ==
+                   (cqr2->irb.scsw.cstat & (SCHN_STAT_INTF_CTRL_CHK |
+                                            SCHN_STAT_CHN_CTRL_CHK)))
+                       return 1; /* match with ifcc*/
+       }
        /* check sense data; byte 0-2,25,27 */
        if (!((memcmp (cqr1->irb.ecw, cqr2->irb.ecw, 3) == 0) &&
              (cqr1->irb.ecw[27] == cqr2->irb.ecw[27]) &&
@@ -2560,17 +2601,6 @@ dasd_3990_erp_action(struct dasd_ccw_req * cqr)
 
                return cqr;
        }
-       /* check if sense data are available */
-       if (!cqr->irb.ecw) {
-               DEV_MESSAGE(KERN_DEBUG, device,
-                           "ERP called witout sense data avail ..."
-                           "request %p - NO ERP possible", cqr);
-
-               cqr->status = DASD_CQR_FAILED;
-
-               return cqr;
-
-       }
 
        /* check if error happened before */
        erp = dasd_3990_erp_in_erp(cqr);
index 7779bfce1c3181518f2f11debd7a70081be40753..3faf0538b328d8b029357c7aa15cd0d397e3a78e 100644 (file)
@@ -415,6 +415,8 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        dev_info->gd->queue = dev_info->dcssblk_queue;
        dev_info->gd->private_data = dev_info;
        dev_info->gd->driverfs_dev = &dev_info->dev;
+       blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request);
+       blk_queue_hardsect_size(dev_info->dcssblk_queue, 4096);
        /*
         * load the segment
         */
@@ -472,9 +474,6 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        if (rc)
                goto unregister_dev;
 
-       blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request);
-       blk_queue_hardsect_size(dev_info->dcssblk_queue, 4096);
-
        add_disk(dev_info->gd);
 
        switch (dev_info->segment_type) {
index e3b3d390b4a3b2294f23428c6e5b70b688298f23..2e616e33891d9816cbda04295eff5b5ec0d963d9 100644 (file)
@@ -332,7 +332,7 @@ sclp_tty_write_string(const unsigned char *str, int count)
                if (sclp_ttybuf == NULL) {
                        while (list_empty(&sclp_tty_pages)) {
                                spin_unlock_irqrestore(&sclp_tty_lock, flags);
-                               if (in_interrupt())
+                               if (in_atomic())
                                        sclp_sync_wait();
                                else
                                        wait_event(sclp_tty_waitq,
index 40cd21bc5cc4dc936191b3b68e1e9febc4c62710..68071622d4bb13bf768ef2494dd040f2972508d7 100644 (file)
@@ -400,7 +400,7 @@ __sclp_vt220_write(const unsigned char *buf, int count, int do_schedule,
                        while (list_empty(&sclp_vt220_empty)) {
                                spin_unlock_irqrestore(&sclp_vt220_lock,
                                                       flags);
-                               if (in_interrupt())
+                               if (in_atomic())
                                        sclp_sync_wait();
                                else
                                        wait_event(sclp_vt220_waitq,
index 3964056a9a4745f05b607c86a1a837eaa961c0eb..03914fa811740084be75306421803bd74285f6e2 100644 (file)
@@ -391,12 +391,24 @@ ccwgroup_remove (struct device *dev)
        return 0;
 }
 
+static void ccwgroup_shutdown(struct device *dev)
+{
+       struct ccwgroup_device *gdev;
+       struct ccwgroup_driver *gdrv;
+
+       gdev = to_ccwgroupdev(dev);
+       gdrv = to_ccwgroupdrv(dev->driver);
+       if (gdrv && gdrv->shutdown)
+               gdrv->shutdown(gdev);
+}
+
 static struct bus_type ccwgroup_bus_type = {
        .name   = "ccwgroup",
        .match  = ccwgroup_bus_match,
        .uevent = ccwgroup_uevent,
        .probe  = ccwgroup_probe,
        .remove = ccwgroup_remove,
+       .shutdown = ccwgroup_shutdown,
 };
 
 /**
index e7ba16a74ef7bf49cb4b19c5cb91b9b5a8cc12d5..007aaeb4f53214533f7dc8c6b8bca62922d28442 100644 (file)
 
 static void *sei_page;
 
+static int chsc_error_from_response(int response)
+{
+       switch (response) {
+       case 0x0001:
+               return 0;
+       case 0x0002:
+       case 0x0003:
+       case 0x0006:
+       case 0x0007:
+       case 0x0008:
+       case 0x000a:
+               return -EINVAL;
+       case 0x0004:
+               return -EOPNOTSUPP;
+       default:
+               return -EIO;
+       }
+}
+
 struct chsc_ssd_area {
        struct chsc_header request;
        u16 :10;
@@ -75,11 +94,11 @@ int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
                ret = (ccode == 3) ? -ENODEV : -EBUSY;
                goto out_free;
        }
-       if (ssd_area->response.code != 0x0001) {
+       ret = chsc_error_from_response(ssd_area->response.code);
+       if (ret != 0) {
                CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
                              schid.ssid, schid.sch_no,
                              ssd_area->response.code);
-               ret = -EIO;
                goto out_free;
        }
        if (!ssd_area->sch_valid) {
@@ -717,36 +736,15 @@ __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
                return (ccode == 3) ? -ENODEV : -EBUSY;
 
        switch (secm_area->response.code) {
-       case 0x0001: /* Success. */
-               ret = 0;
-               break;
-       case 0x0003: /* Invalid block. */
-       case 0x0007: /* Invalid format. */
-       case 0x0008: /* Other invalid block. */
-               CIO_CRW_EVENT(2, "Error in chsc request block!\n");
-               ret = -EINVAL;
-               break;
-       case 0x0004: /* Command not provided in model. */
-               CIO_CRW_EVENT(2, "Model does not provide secm\n");
-               ret = -EOPNOTSUPP;
-               break;
-       case 0x0102: /* cub adresses incorrect */
-               CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
-               ret = -EINVAL;
-               break;
-       case 0x0103: /* key error */
-               CIO_CRW_EVENT(2, "Access key error in secm\n");
+       case 0x0102:
+       case 0x0103:
                ret = -EINVAL;
-               break;
-       case 0x0105: /* error while starting */
-               CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
-               ret = -EIO;
-               break;
        default:
-               CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
-                             secm_area->response.code);
-               ret = -EIO;
+               ret = chsc_error_from_response(secm_area->response.code);
        }
+       if (ret != 0)
+               CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
+                             secm_area->response.code);
        return ret;
 }
 
@@ -827,27 +825,14 @@ int chsc_determine_channel_path_description(struct chp_id chpid,
                goto out;
        }
 
-       switch (scpd_area->response.code) {
-       case 0x0001: /* Success. */
+       ret = chsc_error_from_response(scpd_area->response.code);
+       if (ret == 0)
+               /* Success. */
                memcpy(desc, &scpd_area->desc,
                       sizeof(struct channel_path_desc));
-               ret = 0;
-               break;
-       case 0x0003: /* Invalid block. */
-       case 0x0007: /* Invalid format. */
-       case 0x0008: /* Other invalid block. */
-               CIO_CRW_EVENT(2, "Error in chsc request block!\n");
-               ret = -EINVAL;
-               break;
-       case 0x0004: /* Command not provided in model. */
-               CIO_CRW_EVENT(2, "Model does not provide scpd\n");
-               ret = -EOPNOTSUPP;
-               break;
-       default:
-               CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
+       else
+               CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
                              scpd_area->response.code);
-               ret = -EIO;
-       }
 out:
        free_page((unsigned long)scpd_area);
        return ret;
@@ -923,8 +908,9 @@ int chsc_get_channel_measurement_chars(struct channel_path *chp)
                goto out;
        }
 
-       switch (scmc_area->response.code) {
-       case 0x0001: /* Success. */
+       ret = chsc_error_from_response(scmc_area->response.code);
+       if (ret == 0) {
+               /* Success. */
                if (!scmc_area->not_valid) {
                        chp->cmg = scmc_area->cmg;
                        chp->shared = scmc_area->shared;
@@ -935,22 +921,9 @@ int chsc_get_channel_measurement_chars(struct channel_path *chp)
                        chp->cmg = -1;
                        chp->shared = -1;
                }
-               ret = 0;
-               break;
-       case 0x0003: /* Invalid block. */
-       case 0x0007: /* Invalid format. */
-       case 0x0008: /* Invalid bit combination. */
-               CIO_CRW_EVENT(2, "Error in chsc request block!\n");
-               ret = -EINVAL;
-               break;
-       case 0x0004: /* Command not provided. */
-               CIO_CRW_EVENT(2, "Model does not provide scmc\n");
-               ret = -EOPNOTSUPP;
-               break;
-       default:
-               CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
+       } else {
+               CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
                              scmc_area->response.code);
-               ret = -EIO;
        }
 out:
        free_page((unsigned long)scmc_area);
@@ -1002,21 +975,17 @@ chsc_enable_facility(int operation_code)
                ret = (ret == 3) ? -ENODEV : -EBUSY;
                goto out;
        }
+
        switch (sda_area->response.code) {
-       case 0x0001: /* everything ok */
-               ret = 0;
-               break;
-       case 0x0003: /* invalid request block */
-       case 0x0007:
-               ret = -EINVAL;
-               break;
-       case 0x0004: /* command not provided */
-       case 0x0101: /* facility not provided */
+       case 0x0101:
                ret = -EOPNOTSUPP;
                break;
-       default: /* something went wrong */
-               ret = -EIO;
+       default:
+               ret = chsc_error_from_response(sda_area->response.code);
        }
+       if (ret != 0)
+               CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
+                             operation_code, sda_area->response.code);
  out:
        free_page((unsigned long)sda_area);
        return ret;
@@ -1041,33 +1010,27 @@ chsc_determine_css_characteristics(void)
        } __attribute__ ((packed)) *scsc_area;
 
        scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
-       if (!scsc_area) {
-               CIO_MSG_EVENT(0, "Was not able to determine available "
-                             "CHSCs due to no memory.\n");
+       if (!scsc_area)
                return -ENOMEM;
-       }
 
        scsc_area->request.length = 0x0010;
        scsc_area->request.code = 0x0010;
 
        result = chsc(scsc_area);
        if (result) {
-               CIO_MSG_EVENT(0, "Was not able to determine available CHSCs, "
-                             "cc=%i.\n", result);
-               result = -EIO;
+               result = (result == 3) ? -ENODEV : -EBUSY;
                goto exit;
        }
 
-       if (scsc_area->response.code != 1) {
-               CIO_MSG_EVENT(0, "Was not able to determine "
-                             "available CHSCs.\n");
-               result = -EIO;
-               goto exit;
-       }
-       memcpy(&css_general_characteristics, scsc_area->general_char,
-              sizeof(css_general_characteristics));
-       memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
-              sizeof(css_chsc_characteristics));
+       result = chsc_error_from_response(scsc_area->response.code);
+       if (result == 0) {
+               memcpy(&css_general_characteristics, scsc_area->general_char,
+                      sizeof(css_general_characteristics));
+               memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
+                      sizeof(css_chsc_characteristics));
+       } else
+               CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
+                             scsc_area->response.code);
 exit:
        free_page ((unsigned long) scsc_area);
        return result;
index 918b8b89cf9a26c3fef86b8cd6d6f9d04a17b851..dc4d87f77f6c4bbb45dd1e15fe9582c5cf3f474f 100644 (file)
 #include "ioasm.h"
 #include "io_sch.h"
 
-/*
- * Input :
- *   devno - device number
- *   ps           - pointer to sense ID data area
- * Output : none
+/**
+ * vm_vdev_to_cu_type - Convert vm virtual device into control unit type
+ *                     for certain devices.
+ * @class: virtual device class
+ * @type: virtual device type
+ *
+ * Returns control unit type if a match was made or %0xffff otherwise.
  */
-static void
-VM_virtual_device_info (__u16 devno, struct senseid *ps)
+static int vm_vdev_to_cu_type(int class, int type)
 {
        static struct {
-               int vrdcvcla, vrdcvtyp, cu_type;
+               int class, type, cu_type;
        } vm_devices[] = {
                { 0x08, 0x01, 0x3480 },
                { 0x08, 0x02, 0x3430 },
@@ -68,8 +69,26 @@ VM_virtual_device_info (__u16 devno, struct senseid *ps)
                { 0x40, 0xc0, 0x5080 },
                { 0x80, 0x00, 0x3215 },
        };
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
+               if (class == vm_devices[i].class && type == vm_devices[i].type)
+                       return vm_devices[i].cu_type;
+
+       return 0xffff;
+}
+
+/**
+ * diag_get_dev_info - retrieve device information via DIAG X'210'
+ * @devno: device number
+ * @ps: pointer to sense ID data area
+ *
+ * Returns zero on success, non-zero otherwise.
+ */
+static int diag_get_dev_info(u16 devno, struct senseid *ps)
+{
        struct diag210 diag_data;
-       int ccode, i;
+       int ccode;
 
        CIO_TRACE_EVENT (4, "VMvdinf");
 
@@ -79,21 +98,21 @@ VM_virtual_device_info (__u16 devno, struct senseid *ps)
        };
 
        ccode = diag210 (&diag_data);
-       ps->reserved = 0xff;
+       if ((ccode == 0) || (ccode == 2)) {
+               ps->reserved = 0xff;
 
-       /* Special case for bloody osa devices. */
-       if (diag_data.vrdcvcla == 0x02 &&
-           diag_data.vrdcvtyp == 0x20) {
-               ps->cu_type = 0x3088;
-               ps->cu_model = 0x60;
-               return;
-       }
-       for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
-               if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
-                   diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
-                       ps->cu_type = vm_devices[i].cu_type;
-                       return;
+               /* Special case for osa devices. */
+               if (diag_data.vrdcvcla == 0x02 && diag_data.vrdcvtyp == 0x20) {
+                       ps->cu_type = 0x3088;
+                       ps->cu_model = 0x60;
+                       return 0;
                }
+               ps->cu_type = vm_vdev_to_cu_type(diag_data.vrdcvcla,
+                                               diag_data.vrdcvtyp);
+               if (ps->cu_type != 0xffff)
+                       return 0;
+       }
+
        CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
                      "vdev class : %02X, vdev type : %04X \n ...  "
                      "rdev class : %02X, rdev type : %04X, "
@@ -102,6 +121,8 @@ VM_virtual_device_info (__u16 devno, struct senseid *ps)
                      diag_data.vrdcvcla, diag_data.vrdcvtyp,
                      diag_data.vrdcrccl, diag_data.vrdccrty,
                      diag_data.vrdccrmd);
+
+       return -ENODEV;
 }
 
 /*
@@ -130,6 +151,7 @@ __ccw_device_sense_id_start(struct ccw_device *cdev)
        /* Try on every path. */
        ret = -ENODEV;
        while (cdev->private->imask != 0) {
+               cdev->private->senseid.cu_type = 0xFFFF;
                if ((sch->opm & cdev->private->imask) != 0 &&
                    cdev->private->iretry > 0) {
                        cdev->private->iretry--;
@@ -153,7 +175,6 @@ ccw_device_sense_id_start(struct ccw_device *cdev)
        int ret;
 
        memset (&cdev->private->senseid, 0, sizeof (struct senseid));
-       cdev->private->senseid.cu_type = 0xFFFF;
        cdev->private->imask = 0x80;
        cdev->private->iretry = 5;
        ret = __ccw_device_sense_id_start(cdev);
@@ -173,13 +194,7 @@ ccw_device_check_sense_id(struct ccw_device *cdev)
 
        sch = to_subchannel(cdev->dev.parent);
        irb = &cdev->private->irb;
-       /* Did we get a proper answer ? */
-       if (cdev->private->senseid.cu_type != 0xFFFF && 
-           cdev->private->senseid.reserved == 0xFF) {
-               if (irb->scsw.count < sizeof (struct senseid) - 8)
-                       cdev->private->flags.esid = 1;
-               return 0; /* Success */
-       }
+
        /* Check the error cases. */
        if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
                /* Retry Sense ID if requested. */
@@ -231,6 +246,15 @@ ccw_device_check_sense_id(struct ccw_device *cdev)
                                      sch->schid.ssid, sch->schid.sch_no);
                return -EACCES;
        }
+
+       /* Did we get a proper answer ? */
+       if (irb->scsw.cc == 0 && cdev->private->senseid.cu_type != 0xFFFF &&
+           cdev->private->senseid.reserved == 0xFF) {
+               if (irb->scsw.count < sizeof(struct senseid) - 8)
+                       cdev->private->flags.esid = 1;
+               return 0; /* Success */
+       }
+
        /* Hmm, whatever happened, try again. */
        CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
                      "subchannel 0.%x.%04x returns status %02X%02X\n",
@@ -283,20 +307,17 @@ ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
                        break;
                /* fall through. */
        default:                /* Sense ID failed. Try asking VM. */
-               if (MACHINE_IS_VM) {
-                       VM_virtual_device_info (cdev->private->dev_id.devno,
+               if (MACHINE_IS_VM)
+                       ret = diag_get_dev_info(cdev->private->dev_id.devno,
                                                &cdev->private->senseid);
-                       if (cdev->private->senseid.cu_type != 0xFFFF) {
-                               /* Got the device information from VM. */
-                               ccw_device_sense_id_done(cdev, 0);
-                               return;
-                       }
-               }
-               /*
-                * If we can't couldn't identify the device type we
-                *  consider the device "not operational".
-                */
-               ccw_device_sense_id_done(cdev, -ENODEV);
+               else
+                       /*
+                        * If we can't couldn't identify the device type we
+                        *  consider the device "not operational".
+                        */
+                       ret = -ENODEV;
+
+               ccw_device_sense_id_done(cdev, ret);
                break;
        }
 }
index 19343f9675c31ba368c0f57d2ebfd66de06cf625..291ff6235fe2f0e234a5be1747fc57231a09d25c 100644 (file)
@@ -422,7 +422,7 @@ void s390_adjust_jiffies(void)
 /*
  * calibrate the delay loop
  */
-void __init calibrate_delay(void)
+void __cpuinit calibrate_delay(void)
 {
        s390_adjust_jiffies();
        /* Print the good old Bogomips line .. */
index d85cb73a9f69f217cdcf9e9c779bde8dc3da3947..00a0ba040dba58ad7203d392123077bd629a7812 100644 (file)
@@ -1,6 +1,6 @@
 /* NCR53C9x.c:  Defines and structures for the NCR53C9x generic driver.
  *
- * Originaly esp.h:  Defines and structures for the Sparc ESP 
+ * Originally esp.h:  Defines and structures for the Sparc ESP 
  *                   (Enhanced SCSI Processor) driver under Linux.
  *
  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
index 23f27c9c989501e3d078f6a8532240b24bafe97f..5ac3a3e8dfafcb57020edf4855690f0961550703 100644 (file)
@@ -46,8 +46,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
     struct Scsi_Host *instance = cmd->device->host;
 
     /* don't allow DMA if the physical address is bad */
-    if (addr & A2091_XFER_MASK ||
-       (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
+    if (addr & A2091_XFER_MASK)
     {
        HDATA(instance)->dma_bounce_len = (cmd->SCp.this_residual + 511)
            & ~0x1ff;
index d7255c8bf2811a87ba866145182972e9c44d4f57..3aeec963940bd7e386c0f2e0cc22939df31dd06f 100644 (file)
@@ -54,8 +54,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
      * end of a physical memory chunk, then allocate a bounce
      * buffer
      */
-    if (addr & A3000_XFER_MASK ||
-       (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
+    if (addr & A3000_XFER_MASK)
     {
        HDATA(a3000_host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
            & ~0x1ff;
index 0e8267c1e9155a29df404823454a47268442a667..fb0886140dd788efa31f220558247e16439fab98 100644 (file)
@@ -449,9 +449,6 @@ static int aac_slave_configure(struct scsi_device *sdev)
                else if (depth < 2)
                        depth = 2;
                scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth);
-               if (!(((struct aac_dev *)host->hostdata)->adapter_info.options &
-                               AAC_OPT_NEW_COMM))
-                       blk_queue_max_segment_size(sdev->request_queue, 65536);
        } else
                scsi_adjust_queue_depth(sdev, 0, 1);
 
@@ -1133,6 +1130,12 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
        if (error < 0)
                goto out_deinit;
 
+       if (!(aac->adapter_info.options & AAC_OPT_NEW_COMM)) {
+               error = pci_set_dma_max_seg_size(pdev, 65536);
+               if (error)
+                       goto out_deinit;
+       }
+
        /*
         * Lets override negotiations and drop the maximum SG limit to 34
         */
index 190568ebea3c12e15131bfb6868c212c9463caa0..5a1471c370fa70f601a845fb66e762701bc2d1a8 100644 (file)
@@ -21,7 +21,7 @@
  *  Modified by Chris Faulhaber <jedgar@fxp.org>
  *        Added module command-line options
  *        19-Jul-99
- *  Modified by Adam Fritzler <mid@auk.cx>
+ *  Modified by Adam Fritzler
  *        Added proper detection of the AHA-1640 (MCA version of AHA-1540)
  */
 
index e4f70c563bc295cc6b0a6a022f83998708964183..4c549540a35dcccfce967d2e53f498a8a987801c 100644 (file)
@@ -44,13 +44,8 @@ clean-files += aic79xx_seq.h aic79xx_reg.h aic79xx_reg_print.c
 
 # Dependencies for generated files need to be listed explicitly
 
-$(obj)/aic7xxx_core.o: $(obj)/aic7xxx_seq.h
-$(obj)/aic7xxx_core.o: $(obj)/aic7xxx_reg.h
-$(obj)/aic79xx_core.o: $(obj)/aic79xx_seq.h
-$(obj)/aic79xx_core.o: $(obj)/aic79xx_reg.h
-
-$(addprefix $(obj)/,$(aic7xxx-y)): $(obj)/aic7xxx_seq.h
-$(addprefix $(obj)/,$(aic79xx-y)): $(obj)/aic79xx_seq.h
+$(addprefix $(src)/,$(aic7xxx-y:.o=.c)): $(obj)/aic7xxx_seq.h $(obj)/aic7xxx_reg.h
+$(addprefix $(src)/,$(aic79xx-y:.o=.c)): $(obj)/aic79xx_seq.h $(obj)/aic79xx_reg.h
 
 aic7xxx-gen-$(CONFIG_AIC7XXX_BUILD_FIRMWARE)   := $(obj)/aic7xxx_reg.h
 aic7xxx-gen-$(CONFIG_AIC7XXX_REG_PRETTY_PRINT) += $(obj)/aic7xxx_reg_print.c
index 2ceb67f4af2a6ab1cfb7dac81fe3e86b4a2d5c2d..45e55575a0fad6c997f725d1489e815af31c4fff 100644 (file)
@@ -417,7 +417,7 @@ ahd_targetcmd_offset(struct ahd_softc *ahd, u_int index)
               - (uint8_t *)ahd->qoutfifo);
 }
 
-/*********************** Miscelaneous Support Functions ***********************/
+/*********************** Miscellaneous Support Functions ***********************/
 static __inline struct ahd_initiator_tinfo *
                        ahd_fetch_transinfo(struct ahd_softc *ahd,
                                            char channel, u_int our_id,
index 01465479290135bcd4d03719880bc360fc28947e..72fccd9f40df544e0686f8ea2681c34efb7bb448 100644 (file)
@@ -325,7 +325,7 @@ MODULE_PARM_DESC(aic79xx,
 "      verbose                 Enable verbose/diagnostic logging\n"
 "      allow_memio             Allow device registers to be memory mapped\n"
 "      debug                   Bitmask of debug values to enable\n"
-"      no_reset                Supress initial bus resets\n"
+"      no_reset                Suppress initial bus resets\n"
 "      extended                Enable extended geometry on all controllers\n"
 "      periodic_otag           Send an ordered tagged transaction\n"
 "                              periodically to prevent tag starvation.\n"
index df853676e66a8d7174c81862e65559c99fd45121..c9f79fdf913105d77046db61619c6432a4123dd6 100644 (file)
@@ -979,7 +979,7 @@ ahd_aic790X_setup(struct ahd_softc *ahd)
                          |  AHD_FAINT_LED_BUG;
 
                /*
-                * IO Cell paramter setup.
+                * IO Cell parameter setup.
                 */
                AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
 
@@ -1006,7 +1006,7 @@ ahd_aic790X_setup(struct ahd_softc *ahd)
                        ahd->bugs |= AHD_INTCOLLISION_BUG|AHD_ABORT_LQI_BUG;
 
                /*
-                * IO Cell paramter setup.
+                * IO Cell parameter setup.
                 */
                AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
                AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVB);
index 8e1954cdd84f67cd114491ad0c0072d3aaec175f..cba2f23bbe7954974aab44408b480269d16bae92 100644 (file)
@@ -229,7 +229,7 @@ ahc_name(struct ahc_softc *ahc)
        return (ahc->name);
 }
 
-/*********************** Miscelaneous Support Functions ***********************/
+/*********************** Miscellaneous Support Functions ***********************/
 
 static __inline void   ahc_update_residual(struct ahc_softc *ahc,
                                            struct scb *scb);
index 99a3b33a3233591834e670c95b8152af9df3d12d..282aff6f852e85bb5b9bae950e2da1f423e5df34 100644 (file)
@@ -347,7 +347,7 @@ MODULE_PARM_DESC(aic7xxx,
 "      debug                   Bitmask of debug values to enable\n"
 "      no_probe                Toggle EISA/VLB controller probing\n"
 "      probe_eisa_vl           Toggle EISA/VLB controller probing\n"
-"      no_reset                Supress initial bus resets\n"
+"      no_reset                Suppress initial bus resets\n"
 "      extended                Enable extended geometry on all controllers\n"
 "      periodic_otag           Send an ordered tagged transaction\n"
 "                              periodically to prevent tag starvation.\n"
index 3bfd9296bbfaaa75dc314d9be939c05eb2688b82..93984c9dfe14fd695d23659665d596a549b461c7 100644 (file)
@@ -6472,7 +6472,7 @@ do_aic7xxx_isr(int irq, void *dev_id)
   unsigned long cpu_flags;
   struct aic7xxx_host *p;
   
-  p = (struct aic7xxx_host *)dev_id;
+  p = dev_id;
   if(!p)
     return IRQ_NONE;
   spin_lock_irqsave(p->host->host_lock, cpu_flags);
index 37741e9b5c3b297380f4203376041333b4958ad2..91f85226d08fc352ec7bbfe7cecaf585dae63cf7 100644 (file)
@@ -54,8 +54,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
     static int scsi_alloc_out_of_range = 0;
 
     /* use bounce buffer if the physical address is bad */
-    if (addr & HDATA(cmd->device->host)->dma_xfer_mask ||
-       (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
+    if (addr & HDATA(cmd->device->host)->dma_xfer_mask)
     {
        HDATA(cmd->device->host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
            & ~0x1ff;
index d63f11e95abf7f428ec6fb903af3720e04c0a701..bd62131b97a1d431eef230ab0efd9ed487a7234f 100644 (file)
@@ -539,9 +539,9 @@ out:
                srp_iu_put(iue);
 }
 
-static irqreturn_t ibmvstgt_interrupt(int irq, void *data)
+static irqreturn_t ibmvstgt_interrupt(int dummy, void *data)
 {
-       struct srp_target *target = (struct srp_target *) data;
+       struct srp_target *target = data;
        struct vio_port *vport = target_to_port(target);
 
        vio_disable_interrupts(vport->dma_dev);
index 5ed00069846d93863a51a3e9ad0de62c847d3d39..68e5c632c5d55ca7b909643c3cf2f2a1adff3889 100644 (file)
@@ -287,7 +287,7 @@ static int idescsi_end_request(ide_drive_t *, int, int);
 static ide_startstop_t
 idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
 {
-       if (HWIF(drive)->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
+       if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
                /* force an abort */
                HWIF(drive)->OUTB(WIN_IDLEIMMEDIATE,IDE_COMMAND_REG);
 
@@ -423,7 +423,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
        }
 
        /* Clear the interrupt */
-       stat = drive->hwif->INB(IDE_STATUS_REG);
+       stat = ide_read_status(drive);
 
        if ((stat & DRQ_STAT) == 0) {
                /* No more interrupts */
@@ -588,19 +588,14 @@ static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
                hwif->sg_mapped = 0;
        }
 
-       SELECT_DRIVE(drive);
-
        ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK, bcount, dma);
 
        if (dma)
                set_bit(PC_DMA_OK, &pc->flags);
 
        if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags)) {
-               BUG_ON(HWGROUP(drive)->handler != NULL);
-               ide_set_handler(drive, &idescsi_transfer_pc,
-                               get_timeout(pc), idescsi_expiry);
-               /* Issue the packet command */
-               HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
+               ide_execute_command(drive, WIN_PACKETCMD, &idescsi_transfer_pc,
+                                   get_timeout(pc), idescsi_expiry);
                return ide_started;
        } else {
                /* Issue the packet command */
index 73270ff892d9699c63cd5388ae0ace773dcfc3de..2074701f7e7612959568535cfaec21bdc05b76b7 100644 (file)
@@ -7053,7 +7053,7 @@ static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
  * where it can accept new commands.
 
  * Return value:
- *     0 on sucess / -EIO on failure
+ *     0 on success / -EIO on failure
  **/
 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
 {
index 7505cca8e68e3d1825e06c9a977e948c3a0dacf2..bb152fb9fec7dc4b3260c2b4add978ba4af0e314 100644 (file)
@@ -1309,7 +1309,7 @@ ips_intr_copperhead(ips_ha_t * ha)
                        cstatus.value = (*ha->func.statupd) (ha);
 
                if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
-                       /* Spurious Interupt ? */
+                       /* Spurious Interrupt ? */
                        continue;
                }
 
index f26b9538affe232079d94cd4b9179815af441958..83567b9755b4bf9946f0be2764715d7e85c2f9d2 100644 (file)
@@ -325,7 +325,7 @@ struct lpfc_vport {
 
 #define WORKER_MBOX_TMO                0x100   /* hba: MBOX timeout */
 #define WORKER_HB_TMO                  0x200   /* hba: Heart beat timeout */
-#define WORKER_FABRIC_BLOCK_TMO        0x400   /* hba: fabric block timout */
+#define WORKER_FABRIC_BLOCK_TMO        0x400   /* hba: fabric block timeout */
 #define WORKER_RAMP_DOWN_QUEUE         0x800   /* hba: Decrease Q depth */
 #define WORKER_RAMP_UP_QUEUE           0x1000  /* hba: Increase Q depth */
 
index 3205f7488d1c49b6f24b17391f77ccf6a25e5908..6cfeba7454d46e534b35f88b36d50a20d73f721e 100644 (file)
@@ -1894,7 +1894,7 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
        uint16_t iotag;
        int bars = pci_select_bars(pdev, IORESOURCE_MEM);
 
-       if (pci_enable_device_bars(pdev, bars))
+       if (pci_enable_device_mem(pdev))
                goto out;
        if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
                goto out_disable_device;
@@ -2296,10 +2296,9 @@ static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
        struct Scsi_Host *shost = pci_get_drvdata(pdev);
        struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
        struct lpfc_sli *psli = &phba->sli;
-       int bars = pci_select_bars(pdev, IORESOURCE_MEM);
 
        dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
-       if (pci_enable_device_bars(pdev, bars)) {
+       if (pci_enable_device_mem(pdev)) {
                printk(KERN_ERR "lpfc: Cannot re-enable "
                        "PCI device after reset.\n");
                return PCI_ERS_RESULT_DISCONNECT;
index dfc63f6ccd7bac89c8a98a41afa5e7042cea2250..7a9be4c5b7cb224128faaacba8d4dc8f9cbb3a0a 100644 (file)
@@ -880,7 +880,7 @@ lpfc_mbox_get(struct lpfc_hba * phba)
 void
 lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
 {
-       /* This function expects to be called from interupt context */
+       /* This function expects to be called from interrupt context */
        spin_lock(&phba->hbalock);
        list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
        spin_unlock(&phba->hbalock);
index 6db77c00e3eed4b802eeab7b9ec662194522d526..9f041929aca52ee1d978c2652c995125798fa9ce 100644 (file)
@@ -3464,12 +3464,12 @@ megaraid_mbox_setup_device_map(adapter_t *adapter)
 /*
  * START: Interface for the common management module
  *
- * This is the module, which interfaces with the common mangement module to
+ * This is the module, which interfaces with the common management module to
  * provide support for ioctl and sysfs
  */
 
 /**
- * megaraid_cmm_register - register with the mangement module
+ * megaraid_cmm_register - register with the management module
  * @adapter            : HBA soft state
  *
  * Register with the management module, which allows applications to issue
@@ -3557,7 +3557,7 @@ megaraid_cmm_register(adapter_t *adapter)
 
 
 /**
- * megaraid_cmm_unregister - un-register with the mangement module
+ * megaraid_cmm_unregister - un-register with the management module
  * @adapter            : HBA soft state
  *
  * Un-register with the management module.
@@ -3579,7 +3579,7 @@ megaraid_cmm_unregister(adapter_t *adapter)
  * @kioc               : CMM interface packet
  * @action             : command action
  *
- * This routine is invoked whenever the Common Mangement Module (CMM) has a
+ * This routine is invoked whenever the Common Management Module (CMM) has a
  * command for us. The 'action' parameter specifies if this is a new command
  * or otherwise.
  */
@@ -3944,7 +3944,7 @@ megaraid_sysfs_get_ldmap_timeout(unsigned long data)
  *
  * This routine will be called whenever user reads the logical drive
  * attributes, go get the current logical drive mapping table from the
- * firmware. We use the managment API's to issue commands to the controller.
+ * firmware. We use the management API's to issue commands to the controller.
  *
  * NOTE: The commands issuance functionality is not generalized and
  * implemented in context of "get ld map" command only. If required, the
index 672c759ac24d7719c3371c191d572e25bd8c4d4f..77a62a1b12c3e52cf76df0c3f65f58e607d293b8 100644 (file)
@@ -31,7 +31,6 @@
 #include <linux/moduleparam.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
-#include <linux/mutex.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/uio.h>
index 4b82b2021981a5598c4861867d6d31236bc8f532..d8b99351b053b256e3ad0bd4af7854ef5f77ba65 100644 (file)
@@ -130,7 +130,7 @@ static int fdomain_config(struct pcmcia_device *link)
     cisparse_t parse;
     int i, last_ret, last_fn;
     u_char tuple_data[64];
-    char str[16];
+    char str[22];
     struct Scsi_Host *host;
 
     DEBUG(0, "fdomain_config(0x%p)\n", link);
index 6f129da3758942fec786136fecd4eed5a9b5e4d0..b72c7f170854a9b8f93e9a0ceb7929684e770633 100644 (file)
@@ -2268,6 +2268,7 @@ typedef struct scsi_qla_host {
        spinlock_t              hardware_lock ____cacheline_aligned;
 
        int             bars;
+       int             mem_only;
        device_reg_t __iomem *iobase;           /* Base I/O address */
        resource_size_t pio_address;
 #define MIN_IOBASE_LEN         0x100
index eb0784c9ff83af88fa9c291eaed5281041cb541b..6226d88479f59fa2a1ded8423180281a98393ab0 100644 (file)
@@ -1094,7 +1094,7 @@ qla2x00_sns_rnn_id(scsi_qla_host_t *ha)
 }
 
 /**
- * qla2x00_mgmt_svr_login() - Login to fabric Managment Service.
+ * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
  * @ha: HA context
  *
  * Returns 0 on success.
index 3954ed2d7b517acbd183f30049625bf43a3750b2..8f69caf8327254dc12d55bff8487d3dfadbf318b 100644 (file)
@@ -1564,7 +1564,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        char pci_info[30];
        char fw_str[30];
        struct scsi_host_template *sht;
-       int bars;
+       int bars, mem_only = 0;
 
        bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
        sht = &qla2x00_driver_template;
@@ -1575,10 +1575,16 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
            pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
                bars = pci_select_bars(pdev, IORESOURCE_MEM);
                sht = &qla24xx_driver_template;
+               mem_only = 1;
        }
 
-       if (pci_enable_device_bars(pdev, bars))
-               goto probe_out;
+       if (mem_only) {
+               if (pci_enable_device_mem(pdev))
+                       goto probe_out;
+       } else {
+               if (pci_enable_device(pdev))
+                       goto probe_out;
+       }
 
        if (pci_find_aer_capability(pdev))
                if (pci_enable_pcie_error_reporting(pdev))
@@ -1601,6 +1607,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
        ha->parent = NULL;
        ha->bars = bars;
+       ha->mem_only = mem_only;
 
        /* Set ISP-type information. */
        qla2x00_set_isp_flags(ha);
@@ -2875,8 +2882,14 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
 {
        pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
        scsi_qla_host_t *ha = pci_get_drvdata(pdev);
+       int rc;
+
+       if (ha->mem_only)
+               rc = pci_enable_device_mem(pdev);
+       else
+               rc = pci_enable_device(pdev);
 
-       if (pci_enable_device_bars(pdev, ha->bars)) {
+       if (rc) {
                qla_printk(KERN_WARNING, ha,
                    "Can't re-enable PCI device after reset.\n");
 
index accaf690eaf0c393f620750d705c650cbee04705..d6be0762eb918977b27bd428f7057a8e25bba3af 100644 (file)
 #define MAX_REQS_SERVICED_PER_INTR     16
 
 #define ISCSI_IPADDR_SIZE              4       /* IP address size */
-#define ISCSI_ALIAS_SIZE               32      /* ISCSI Alais name size */
+#define ISCSI_ALIAS_SIZE               32      /* ISCSI Alias name size */
 #define ISCSI_NAME_SIZE                        0xE0    /* ISCSI Name size */
 
 #define LSDW(x) ((u32)((u64)(x)))
index cbe0a17ced5f9b97cde9e21e8c41640b41b16c3b..49925f92555e8a3b485316d5963bc0dd8ef6d49f 100644 (file)
@@ -1098,7 +1098,7 @@ static int qla4xxx_start_firmware(struct scsi_qla_host *ha)
                }
                config_chip = 1;
 
-               /* Reset clears the semaphore, so aquire again */
+               /* Reset clears the semaphore, so acquire again */
                if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
                        return QLA_ERROR;
        }
index b12fb310e3999af497c21778b62f40c46892e8fd..f243fc30c908dce70387e776aa945cde84e5bc4a 100644 (file)
@@ -1569,6 +1569,7 @@ struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
                                         request_fn_proc *request_fn)
 {
        struct request_queue *q;
+       struct device *dev = shost->shost_gendev.parent;
 
        q = blk_init_queue(request_fn, NULL);
        if (!q)
@@ -1583,6 +1584,9 @@ struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
        blk_queue_max_sectors(q, shost->max_sectors);
        blk_queue_bounce_limit(q, scsi_calculate_bounce_limit(shost));
        blk_queue_segment_boundary(q, shost->dma_boundary);
+       dma_set_seg_boundary(dev, shost->dma_boundary);
+
+       blk_queue_max_segment_size(q, dma_get_max_seg_size(dev));
 
        if (!shost->use_clustering)
                clear_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
index 91630baea532e0656883ee2c427b21467a9bf629..3677fbb30b720d50b6777a395125ba03ae1c492b 100644 (file)
@@ -320,7 +320,7 @@ int scsi_tgt_queue_command(struct scsi_cmnd *cmd, u64 itn_id,
 EXPORT_SYMBOL_GPL(scsi_tgt_queue_command);
 
 /*
- * This is run from a interrpt handler normally and the unmap
+ * This is run from a interrupt handler normally and the unmap
  * needs process context so we must queue
  */
 static void scsi_tgt_cmd_done(struct scsi_cmnd *cmd)
index f2149d0bb9997a4caff68d9900eeb6da8de8832a..43a964d635b4e19b30d5d76c4dafcc090e8a5a14 100644 (file)
@@ -6,7 +6,7 @@
  *
  * The SAS transport class contains common code to deal with SAS HBAs,
  * an aproximated representation of SAS topologies in the driver model,
- * and various sysfs attributes to expose these topologies and managment
+ * and various sysfs attributes to expose these topologies and management
  * interfaces to userspace.
  *
  * In addition to the basic SCSI core objects this transport class
index 6a48dfa1efe8552fcaa8453d0800a2d58437c764..0276471cb25ec933819088d784935a69363ec8ac 100644 (file)
@@ -237,6 +237,12 @@ serial21285_set_termios(struct uart_port *port, struct ktermios *termios,
        baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); 
        quot = uart_get_divisor(port, baud);
 
+       if (port->info && port->info->tty) {
+               struct tty_struct *tty = port->info->tty;
+               unsigned int b = port->uartclk / (16 * quot);
+               tty_encode_baud_rate(tty, b, b);
+       }
+
        switch (termios->c_cflag & CSIZE) {
        case CS5:
                h_lcr = 0x00;
@@ -277,8 +283,6 @@ serial21285_set_termios(struct uart_port *port, struct ktermios *termios,
        if (termios->c_iflag & INPCK)
                port->read_status_mask |= RXSTAT_FRAME | RXSTAT_PARITY;
 
-       tty_encode_baud_rate(tty,  baud, baud);
-
        /*
         * Which character status flags should we ignore?
         */
index f94109cbb46e683a6a6f7d2fee29d7915b21cc93..b8a4bd94f51d5501cbf813d38f75147a9e180ab9 100644 (file)
@@ -2047,7 +2047,7 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
         * Oxford Semi 952 rev B workaround
         */
        if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0)
-               quot ++;
+               quot++;
 
        if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) {
                if (baud < 2400)
@@ -2662,16 +2662,17 @@ static int __devinit serial8250_probe(struct platform_device *dev)
        memset(&port, 0, sizeof(struct uart_port));
 
        for (i = 0; p && p->flags != 0; p++, i++) {
-               port.iobase     = p->iobase;
-               port.membase    = p->membase;
-               port.irq        = p->irq;
-               port.uartclk    = p->uartclk;
-               port.regshift   = p->regshift;
-               port.iotype     = p->iotype;
-               port.flags      = p->flags;
-               port.mapbase    = p->mapbase;
-               port.hub6       = p->hub6;
-               port.dev        = &dev->dev;
+               port.iobase             = p->iobase;
+               port.membase            = p->membase;
+               port.irq                = p->irq;
+               port.uartclk            = p->uartclk;
+               port.regshift           = p->regshift;
+               port.iotype             = p->iotype;
+               port.flags              = p->flags;
+               port.mapbase            = p->mapbase;
+               port.hub6               = p->hub6;
+               port.private_data       = p->private_data;
+               port.dev                = &dev->dev;
                if (share_irqs)
                        port.flags |= UPF_SHARE_IRQ;
                ret = serial8250_register_port(&port);
@@ -2812,15 +2813,16 @@ int serial8250_register_port(struct uart_port *port)
        if (uart) {
                uart_remove_one_port(&serial8250_reg, &uart->port);
 
-               uart->port.iobase   = port->iobase;
-               uart->port.membase  = port->membase;
-               uart->port.irq      = port->irq;
-               uart->port.uartclk  = port->uartclk;
-               uart->port.fifosize = port->fifosize;
-               uart->port.regshift = port->regshift;
-               uart->port.iotype   = port->iotype;
-               uart->port.flags    = port->flags | UPF_BOOT_AUTOCONF;
-               uart->port.mapbase  = port->mapbase;
+               uart->port.iobase       = port->iobase;
+               uart->port.membase      = port->membase;
+               uart->port.irq          = port->irq;
+               uart->port.uartclk      = port->uartclk;
+               uart->port.fifosize     = port->fifosize;
+               uart->port.regshift     = port->regshift;
+               uart->port.iotype       = port->iotype;
+               uart->port.flags        = port->flags | UPF_BOOT_AUTOCONF;
+               uart->port.mapbase      = port->mapbase;
+               uart->port.private_data = port->private_data;
                if (port->dev)
                        uart->port.dev = port->dev;
 
index ceb03c9e749f8f918732d88c635de618d1f04125..0a4ac2b6eb5a2a8d5c0a25da3a1a0bdf40c4f317 100644 (file)
@@ -105,6 +105,32 @@ setup_port(struct serial_private *priv, struct uart_port *port,
        return 0;
 }
 
+/*
+ * ADDI-DATA GmbH communication cards <info@addi-data.com>
+ */
+static int addidata_apci7800_setup(struct serial_private *priv,
+                               struct pciserial_board *board,
+                               struct uart_port *port, int idx)
+{
+       unsigned int bar = 0, offset = board->first_offset;
+       bar = FL_GET_BASE(board->flags);
+
+       if (idx < 2) {
+               offset += idx * board->uart_offset;
+       } else if ((idx >= 2) && (idx < 4)) {
+               bar += 1;
+               offset += ((idx - 2) * board->uart_offset);
+       } else if ((idx >= 4) && (idx < 6)) {
+               bar += 2;
+               offset += ((idx - 4) * board->uart_offset);
+       } else if (idx >= 6) {
+               bar += 3;
+               offset += ((idx - 6) * board->uart_offset);
+       }
+
+       return setup_port(priv, port, bar, offset, board->reg_shift);
+}
+
 /*
  * AFAVLAB uses a different mixture of BARs and offsets
  * Not that ugly ;) -- HW
@@ -751,6 +777,16 @@ pci_default_setup(struct serial_private *priv, struct pciserial_board *board,
  * Specific entries must come before more generic entries.
  */
 static struct pci_serial_quirk pci_serial_quirks[] = {
+       /*
+       * ADDI-DATA GmbH communication cards <info@addi-data.com>
+       */
+       {
+               .vendor         = PCI_VENDOR_ID_ADDIDATA_OLD,
+               .device         = PCI_DEVICE_ID_ADDIDATA_APCI7800,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .setup          = addidata_apci7800_setup,
+       },
        /*
         * AFAVLAB cards - these may be called via parport_serial
         *  It is not clear whether this applies to all products.
@@ -1179,6 +1215,12 @@ static struct pciserial_board pci_boards[] __devinitdata = {
                .base_baud      = 115200,
                .uart_offset    = 8,
        },
+       [pbn_b0_8_115200] = {
+               .flags          = FL_BASE0,
+               .num_ports      = 8,
+               .base_baud      = 115200,
+               .uart_offset    = 8,
+       },
 
        [pbn_b0_1_921600] = {
                .flags          = FL_BASE0,
@@ -2696,6 +2738,97 @@ static struct pci_device_id serial_pci_tbl[] = {
                PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_pasemi_1682M },
 
+       /*
+       * ADDI-DATA GmbH communication cards <info@addi-data.com>
+       */
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7500,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_4_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7420,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_2_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7300,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_1_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA_OLD,
+               PCI_DEVICE_ID_ADDIDATA_APCI7800,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b1_8_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7500_2,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_4_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7420_2,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_2_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7300_2,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_1_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7500_3,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_4_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7420_3,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_2_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7300_3,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_1_115200 },
+
+       {       PCI_VENDOR_ID_ADDIDATA,
+               PCI_DEVICE_ID_ADDIDATA_APCI7800_3,
+               PCI_ANY_ID,
+               PCI_ANY_ID,
+               0,
+               0,
+               pbn_b0_8_115200 },
+
        /*
         * These entries match devices with class COMMUNICATION_SERIAL,
         * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL
index 1de098e754978810db03ea655480bb4c9e213e45..6f09cbd7fc488ac53286c92ba1ce0698f11ba0bd 100644 (file)
@@ -414,8 +414,9 @@ static int __devinit check_resources(struct pnp_option *option)
  */
 static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags)
 {
-       if (!(check_name(pnp_dev_name(dev)) || (dev->card && check_name(dev->card->name))))
-               return -ENODEV;
+       if (!(check_name(pnp_dev_name(dev)) ||
+               (dev->card && check_name(dev->card->name))))
+                       return -ENODEV;
 
        if (check_resources(dev->independent))
                return 0;
@@ -452,8 +453,9 @@ serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
                return -ENODEV;
 
 #ifdef SERIAL_DEBUG_PNP
-       printk("Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n",
-              port.iobase, port.mapbase, port.irq, port.iotype);
+       printk(KERN_DEBUG
+               "Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n",
+                      port.iobase, port.mapbase, port.irq, port.iotype);
 #endif
 
        port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
index 8a053ea21e1d57f9a8e3f41ac6e5dbced679504c..6a44fb1dc167c0c74a39ac161f287e68c64e212f 100644 (file)
@@ -877,15 +877,15 @@ config SERIAL_SUNHV
          systems.  Say Y if you want to be able to use this device.
 
 config SERIAL_IP22_ZILOG
-       tristate "IP22 Zilog8530 serial support"
-       depends on SGI_IP22
+       tristate "SGI Zilog8530 serial support"
+       depends on SGI_HAS_ZILOG
        select SERIAL_CORE
        help
-         This driver supports the Zilog8530 serial ports found on SGI IP22
+         This driver supports the Zilog8530 serial ports found on SGI
          systems.  Say Y or M if you want to be able to these serial ports.
 
 config SERIAL_IP22_ZILOG_CONSOLE
-       bool "Console on IP22 Zilog8530 serial port"
+       bool "Console on SGI Zilog8530 serial port"
        depends on SERIAL_IP22_ZILOG=y
        select SERIAL_CORE_CONSOLE
 
@@ -1295,8 +1295,8 @@ config SERIAL_NETX_CONSOLE
        depends on SERIAL_NETX
        select SERIAL_CORE_CONSOLE
        help
-         If you have enabled the serial port on the Motorola IMX
-         CPU you can make it the console by answering Y to this option.
+         If you have enabled the serial port on the Hilscher NetX SoC
+         you can make it the console by answering Y to this option.
 
 config SERIAL_OF_PLATFORM
        tristate "Serial port on Open Firmware platform bus"
@@ -1318,4 +1318,19 @@ config SERIAL_QE
          This driver supports the QE serial ports on Freescale embedded
          PowerPC that contain a QUICC Engine.
 
+config SERIAL_SC26XX
+       tristate "SC2681/SC2692 serial port support"
+       depends on SNI_RM
+       select SERIAL_CORE
+       help
+         This is a driver for the onboard serial ports of
+         older RM400 machines.
+
+config SERIAL_SC26XX_CONSOLE
+       bool "Console on SC2681/SC2692 serial port"
+       depends on SERIAL_SC26XX
+       select SERIAL_CORE_CONSOLE
+       help
+         Support for Console on SC2681/SC2692 serial ports.
+
 endmenu
index 2dd41b4cc8dbf1cc930b852a8d4c0fea67d94db0..640cfe44a56dd309cacc16efa2c86378af5048c2 100644 (file)
@@ -55,6 +55,7 @@ obj-$(CONFIG_SERIAL_M32R_SIO) += m32r_sio.o
 obj-$(CONFIG_SERIAL_MPSC) += mpsc.o
 obj-$(CONFIG_SERIAL_SB1250_DUART) += sb1250-duart.o
 obj-$(CONFIG_ETRAX_SERIAL) += crisv10.o
+obj-$(CONFIG_SERIAL_SC26XX) += sc26xx.o
 obj-$(CONFIG_SERIAL_JSM) += jsm/
 obj-$(CONFIG_SERIAL_TXX9) += serial_txx9.o
 obj-$(CONFIG_SERIAL_VR41XX) += vr41xx_siu.o
index 111da57f533414671f9a924456ebcf1d08b32553..60f52904aad0fc4bfe7142d348c35a434dac1731 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/tty_flip.h>
 #include <linux/platform_device.h>
 #include <linux/atmel_pdc.h>
+#include <linux/atmel_serial.h>
 
 #include <asm/io.h>
 
@@ -45,8 +46,6 @@
 #include <asm/arch/gpio.h>
 #endif
 
-#include "atmel_serial.h"
-
 #if defined(CONFIG_SERIAL_ATMEL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 #define SUPPORT_SYSRQ
 #endif
index b5e4478de0e3b31f3ef6a0adbfce536d5986d6c8..236af9d3385123897985a84ff215cf395b3a2ff0 100644 (file)
@@ -380,7 +380,7 @@ static void cpm_uart_int_rx(struct uart_port *port)
 static irqreturn_t cpm_uart_int(int irq, void *data)
 {
        u8 events;
-       struct uart_port *port = (struct uart_port *)data;
+       struct uart_port *port = data;
        struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
        smc_t __iomem *smcp = pinfo->smcp;
        scc_t __iomem *sccp = pinfo->sccp;
index d31721f2744d69db038b69b7c0f2a9e143cc362d..bbae5a220219836658d3c52ff8460591a855ed62 100644 (file)
@@ -324,7 +324,7 @@ static inline void check_modem_status(struct dz_port *dport)
  */
 static irqreturn_t dz_interrupt(int irq, void *dev)
 {
-       struct dz_port *dport = (struct dz_port *)dev;
+       struct dz_port *dport = dev;
        unsigned short status;
 
        /* get the reason why we just got an irq */
index 0274554967453b632be192c2ae180877d865d73b..c8029e0025c97e400ad8f674dc48d87a49982a4c 100644 (file)
@@ -20,7 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-#include<linux/serial_core.h>
+#include <linux/serial_core.h>
 
 #define BAUD_TABLE_LIMIT       ((sizeof(icom_acfg_baud)/sizeof(int)) - 1)
 static int icom_acfg_baud[] = {
index dc1967176fe228811b77a27fb2fcb82c41c8274c..56af1f566a4cd1b0ebfc7d78f71646ca267face9 100644 (file)
@@ -308,7 +308,7 @@ static void imx_start_tx(struct uart_port *port)
 
 static irqreturn_t imx_rtsint(int irq, void *dev_id)
 {
-       struct imx_port *sport = (struct imx_port *)dev_id;
+       struct imx_port *sport = dev_id;
        unsigned int val = readl(sport->port.membase + USR1) & USR1_RTSS;
        unsigned long flags;
 
@@ -324,7 +324,7 @@ static irqreturn_t imx_rtsint(int irq, void *dev_id)
 
 static irqreturn_t imx_txint(int irq, void *dev_id)
 {
-       struct imx_port *sport = (struct imx_port *)dev_id;
+       struct imx_port *sport = dev_id;
        struct circ_buf *xmit = &sport->port.info->xmit;
        unsigned long flags;
 
index 051fcc2f5ba8a97509789f613de8470a0965faff..e76fc72c9b3610ab54dd2aec9b5814653e2257fe 100644 (file)
@@ -434,7 +434,7 @@ static struct uart_ops mcf_uart_ops = {
 
 static struct mcf_uart mcf_ports[3];
 
-#define        MCF_MAXPORTS    (sizeof(mcf_ports) / sizeof(struct mcf_uart))
+#define        MCF_MAXPORTS    ARRAY_SIZE(mcf_ports)
 
 /****************************************************************************/
 #if defined(CONFIG_SERIAL_MCF_CONSOLE)
index 4d643c9266578d86defb7e9a5b05a138dd161a5b..cb3a91967742b83f96e30c09225f03f4bca80de5 100644 (file)
@@ -612,6 +612,7 @@ static void mpsc_hw_init(struct mpsc_port_info *pi)
 
        /* No preamble, 16x divider, low-latency, */
        writel(0x04400400, pi->mpsc_base + MPSC_MMCRH);
+       mpsc_set_baudrate(pi, pi->default_baud);
 
        if (pi->mirror_regs) {
                pi->MPSC_CHR_1_m = 0;
index 83211013deb87603e3f764106509e4454afad569..e94031731a4797af1d94b9f47db6fc51d0a8bc8c 100644 (file)
@@ -582,7 +582,7 @@ static struct parisc_driver serial_mux_driver = {
 };
 
 /**
- * mux_init - Serial MUX initalization procedure.
+ * mux_init - Serial MUX initialization procedure.
  *
  * Register the Serial MUX driver.
  */
index e773c8e1496245bcaca63984bc9ff07ac055c4f9..45de19366030f248dbda1e33d457e8c75cac7e93 100644 (file)
@@ -1527,7 +1527,7 @@ static inline void s3c2440_serial_exit(void)
 #define s3c2440_uart_inf_at NULL
 #endif /* CONFIG_CPU_S3C2440 */
 
-#if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
+#if defined(CONFIG_CPU_S3C2412)
 
 static int s3c2412_serial_setsource(struct uart_port *port,
                                     struct s3c24xx_uart_clksrc *clk)
diff --git a/drivers/serial/sc26xx.c b/drivers/serial/sc26xx.c
new file mode 100644 (file)
index 0000000..a350b6d
--- /dev/null
@@ -0,0 +1,755 @@
+/*
+ * SC268xx.c: Serial driver for Philiphs SC2681/SC2692 devices.
+ *
+ * Copyright (C) 2006,2007 Thomas Bogendörfer (tsbogend@alpha.franken.de)
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/major.h>
+#include <linux/circ_buf.h>
+#include <linux/serial.h>
+#include <linux/sysrq.h>
+#include <linux/console.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/irq.h>
+
+#if defined(CONFIG_MAGIC_SYSRQ)
+#define SUPPORT_SYSRQ
+#endif
+
+#include <linux/serial_core.h>
+
+#define SC26XX_MAJOR         204
+#define SC26XX_MINOR_START   205
+#define SC26XX_NR            2
+
+struct uart_sc26xx_port {
+       struct uart_port      port[2];
+       u8     dsr_mask[2];
+       u8     cts_mask[2];
+       u8     dcd_mask[2];
+       u8     ri_mask[2];
+       u8     dtr_mask[2];
+       u8     rts_mask[2];
+       u8     imr;
+};
+
+/* register common to both ports */
+#define RD_ISR      0x14
+#define RD_IPR      0x34
+
+#define WR_ACR      0x10
+#define WR_IMR      0x14
+#define WR_OPCR     0x34
+#define WR_OPR_SET  0x38
+#define WR_OPR_CLR  0x3C
+
+/* access common register */
+#define READ_SC(p, r)        readb((p)->membase + RD_##r)
+#define WRITE_SC(p, r, v)    writeb((v), (p)->membase + WR_##r)
+
+/* register per port */
+#define RD_PORT_MRx 0x00
+#define RD_PORT_SR  0x04
+#define RD_PORT_RHR 0x0c
+
+#define WR_PORT_MRx 0x00
+#define WR_PORT_CSR 0x04
+#define WR_PORT_CR  0x08
+#define WR_PORT_THR 0x0c
+
+/* SR bits */
+#define SR_BREAK    (1 << 7)
+#define SR_FRAME    (1 << 6)
+#define SR_PARITY   (1 << 5)
+#define SR_OVERRUN  (1 << 4)
+#define SR_TXRDY    (1 << 2)
+#define SR_RXRDY    (1 << 0)
+
+#define CR_RES_MR   (1 << 4)
+#define CR_RES_RX   (2 << 4)
+#define CR_RES_TX   (3 << 4)
+#define CR_STRT_BRK (6 << 4)
+#define CR_STOP_BRK (7 << 4)
+#define CR_DIS_TX   (1 << 3)
+#define CR_ENA_TX   (1 << 2)
+#define CR_DIS_RX   (1 << 1)
+#define CR_ENA_RX   (1 << 0)
+
+/* ISR bits */
+#define ISR_RXRDYB  (1 << 5)
+#define ISR_TXRDYB  (1 << 4)
+#define ISR_RXRDYA  (1 << 1)
+#define ISR_TXRDYA  (1 << 0)
+
+/* IMR bits */
+#define IMR_RXRDY   (1 << 1)
+#define IMR_TXRDY   (1 << 0)
+
+/* access port register */
+static inline u8 read_sc_port(struct uart_port *p, u8 reg)
+{
+       return readb(p->membase + p->line * 0x20 + reg);
+}
+
+static inline void write_sc_port(struct uart_port *p, u8 reg, u8 val)
+{
+       writeb(val, p->membase + p->line * 0x20 + reg);
+}
+
+#define READ_SC_PORT(p, r)     read_sc_port(p, RD_PORT_##r)
+#define WRITE_SC_PORT(p, r, v) write_sc_port(p, WR_PORT_##r, v)
+
+static void sc26xx_enable_irq(struct uart_port *port, int mask)
+{
+       struct uart_sc26xx_port *up;
+       int line = port->line;
+
+       port -= line;
+       up = container_of(port, struct uart_sc26xx_port, port[0]);
+
+       up->imr |= mask << (line * 4);
+       WRITE_SC(port, IMR, up->imr);
+}
+
+static void sc26xx_disable_irq(struct uart_port *port, int mask)
+{
+       struct uart_sc26xx_port *up;
+       int line = port->line;
+
+       port -= line;
+       up = container_of(port, struct uart_sc26xx_port, port[0]);
+
+       up->imr &= ~(mask << (line * 4));
+       WRITE_SC(port, IMR, up->imr);
+}
+
+static struct tty_struct *receive_chars(struct uart_port *port)
+{
+       struct tty_struct *tty = NULL;
+       int limit = 10000;
+       unsigned char ch;
+       char flag;
+       u8 status;
+
+       if (port->info != NULL)         /* Unopened serial console */
+               tty = port->info->tty;
+
+       while (limit-- > 0) {
+               status = READ_SC_PORT(port, SR);
+               if (!(status & SR_RXRDY))
+                       break;
+               ch = READ_SC_PORT(port, RHR);
+
+               flag = TTY_NORMAL;
+               port->icount.rx++;
+
+               if (unlikely(status & (SR_BREAK | SR_FRAME |
+                                      SR_PARITY | SR_OVERRUN))) {
+                       if (status & SR_BREAK) {
+                               status &= ~(SR_PARITY | SR_FRAME);
+                               port->icount.brk++;
+                               if (uart_handle_break(port))
+                                       continue;
+                       } else if (status & SR_PARITY)
+                               port->icount.parity++;
+                       else if (status & SR_FRAME)
+                               port->icount.frame++;
+                       if (status & SR_OVERRUN)
+                               port->icount.overrun++;
+
+                       status &= port->read_status_mask;
+                       if (status & SR_BREAK)
+                               flag = TTY_BREAK;
+                       else if (status & SR_PARITY)
+                               flag = TTY_PARITY;
+                       else if (status & SR_FRAME)
+                               flag = TTY_FRAME;
+               }
+
+               if (uart_handle_sysrq_char(port, ch))
+                       continue;
+
+               if (status & port->ignore_status_mask)
+                       continue;
+
+               tty_insert_flip_char(tty, ch, flag);
+       }
+       return tty;
+}
+
+static void transmit_chars(struct uart_port *port)
+{
+       struct circ_buf *xmit;
+
+       if (!port->info)
+               return;
+
+       xmit = &port->info->xmit;
+       if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
+               sc26xx_disable_irq(port, IMR_TXRDY);
+               return;
+       }
+       while (!uart_circ_empty(xmit)) {
+               if (!(READ_SC_PORT(port, SR) & SR_TXRDY))
+                       break;
+
+               WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]);
+               xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+               port->icount.tx++;
+       }
+       if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+               uart_write_wakeup(port);
+}
+
+static irqreturn_t sc26xx_interrupt(int irq, void *dev_id)
+{
+       struct uart_sc26xx_port *up = dev_id;
+       struct tty_struct *tty;
+       unsigned long flags;
+       u8 isr;
+
+       spin_lock_irqsave(&up->port[0].lock, flags);
+
+       tty = NULL;
+       isr = READ_SC(&up->port[0], ISR);
+       if (isr & ISR_TXRDYA)
+           transmit_chars(&up->port[0]);
+       if (isr & ISR_RXRDYA)
+           tty = receive_chars(&up->port[0]);
+
+       spin_unlock(&up->port[0].lock);
+
+       if (tty)
+               tty_flip_buffer_push(tty);
+
+       spin_lock(&up->port[1].lock);
+
+       tty = NULL;
+       if (isr & ISR_TXRDYB)
+           transmit_chars(&up->port[1]);
+       if (isr & ISR_RXRDYB)
+           tty = receive_chars(&up->port[1]);
+
+       spin_unlock_irqrestore(&up->port[1].lock, flags);
+
+       if (tty)
+               tty_flip_buffer_push(tty);
+
+       return IRQ_HANDLED;
+}
+
+/* port->lock is not held.  */
+static unsigned int sc26xx_tx_empty(struct uart_port *port)
+{
+       return (READ_SC_PORT(port, SR) & SR_TXRDY) ? TIOCSER_TEMT : 0;
+}
+
+/* port->lock held by caller.  */
+static void sc26xx_set_mctrl(struct uart_port *port, unsigned int mctrl)
+{
+       struct uart_sc26xx_port *up;
+       int line = port->line;
+
+       port -= line;
+       up = container_of(port, struct uart_sc26xx_port, port[0]);
+
+       if (up->dtr_mask[line]) {
+               if (mctrl & TIOCM_DTR)
+                       WRITE_SC(port, OPR_SET, up->dtr_mask[line]);
+               else
+                       WRITE_SC(port, OPR_CLR, up->dtr_mask[line]);
+       }
+       if (up->rts_mask[line]) {
+               if (mctrl & TIOCM_RTS)
+                       WRITE_SC(port, OPR_SET, up->rts_mask[line]);
+               else
+                       WRITE_SC(port, OPR_CLR, up->rts_mask[line]);
+       }
+}
+
+/* port->lock is held by caller and interrupts are disabled.  */
+static unsigned int sc26xx_get_mctrl(struct uart_port *port)
+{
+       struct uart_sc26xx_port *up;
+       int line = port->line;
+       unsigned int mctrl = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
+       u8 ipr;
+
+       port -= line;
+       up = container_of(port, struct uart_sc26xx_port, port[0]);
+       ipr = READ_SC(port, IPR) ^ 0xff;
+
+       if (up->dsr_mask[line]) {
+               mctrl &= ~TIOCM_DSR;
+               mctrl |= ipr & up->dsr_mask[line] ? TIOCM_DSR : 0;
+       }
+       if (up->cts_mask[line]) {
+               mctrl &= ~TIOCM_CTS;
+               mctrl |= ipr & up->cts_mask[line] ? TIOCM_CTS : 0;
+       }
+       if (up->dcd_mask[line]) {
+               mctrl &= ~TIOCM_CAR;
+               mctrl |= ipr & up->dcd_mask[line] ? TIOCM_CAR : 0;
+       }
+       if (up->ri_mask[line]) {
+               mctrl &= ~TIOCM_RNG;
+               mctrl |= ipr & up->ri_mask[line] ? TIOCM_RNG : 0;
+       }
+       return mctrl;
+}
+
+/* port->lock held by caller.  */
+static void sc26xx_stop_tx(struct uart_port *port)
+{
+       return;
+}
+
+/* port->lock held by caller.  */
+static void sc26xx_start_tx(struct uart_port *port)
+{
+       struct circ_buf *xmit = &port->info->xmit;
+
+       while (!uart_circ_empty(xmit)) {
+               if (!(READ_SC_PORT(port, SR) & SR_TXRDY)) {
+                       sc26xx_enable_irq(port, IMR_TXRDY);
+                       break;
+               }
+               WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]);
+               xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+               port->icount.tx++;
+       }
+}
+
+/* port->lock held by caller.  */
+static void sc26xx_stop_rx(struct uart_port *port)
+{
+}
+
+/* port->lock held by caller.  */
+static void sc26xx_enable_ms(struct uart_port *port)
+{
+}
+
+/* port->lock is not held.  */
+static void sc26xx_break_ctl(struct uart_port *port, int break_state)
+{
+       if (break_state == -1)
+               WRITE_SC_PORT(port, CR, CR_STRT_BRK);
+       else
+               WRITE_SC_PORT(port, CR, CR_STOP_BRK);
+}
+
+/* port->lock is not held.  */
+static int sc26xx_startup(struct uart_port *port)
+{
+       sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY);
+       WRITE_SC(port, OPCR, 0);
+
+       /* reset tx and rx */
+       WRITE_SC_PORT(port, CR, CR_RES_RX);
+       WRITE_SC_PORT(port, CR, CR_RES_TX);
+
+       /* start rx/tx */
+       WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX);
+
+       /* enable irqs */
+       sc26xx_enable_irq(port, IMR_RXRDY);
+       return 0;
+}
+
+/* port->lock is not held.  */
+static void sc26xx_shutdown(struct uart_port *port)
+{
+       /* disable interrupst */
+       sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY);
+
+       /* stop tx/rx */
+       WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX);
+}
+
+/* port->lock is not held.  */
+static void sc26xx_set_termios(struct uart_port *port, struct ktermios *termios,
+                             struct ktermios *old)
+{
+       unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
+       unsigned int quot = uart_get_divisor(port, baud);
+       unsigned int iflag, cflag;
+       unsigned long flags;
+       u8 mr1, mr2, csr;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc)
+               udelay(2);
+
+       WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX);
+
+       iflag = termios->c_iflag;
+       cflag = termios->c_cflag;
+
+       port->read_status_mask = SR_OVERRUN;
+       if (iflag & INPCK)
+               port->read_status_mask |= SR_PARITY | SR_FRAME;
+       if (iflag & (BRKINT | PARMRK))
+               port->read_status_mask |= SR_BREAK;
+
+       port->ignore_status_mask = 0;
+       if (iflag & IGNBRK)
+               port->ignore_status_mask |= SR_BREAK;
+       if ((cflag & CREAD) == 0)
+               port->ignore_status_mask |= SR_BREAK | SR_FRAME |
+                                           SR_PARITY | SR_OVERRUN;
+
+       switch (cflag & CSIZE) {
+       case CS5:
+               mr1 = 0x00;
+               break;
+       case CS6:
+               mr1 = 0x01;
+               break;
+       case CS7:
+               mr1 = 0x02;
+               break;
+       default:
+       case CS8:
+               mr1 = 0x03;
+               break;
+       }
+       mr2 = 0x07;
+       if (cflag & CSTOPB)
+               mr2 = 0x0f;
+       if (cflag & PARENB) {
+               if (cflag & PARODD)
+                       mr1 |= (1 << 2);
+       } else
+               mr1 |= (2 << 3);
+
+       switch (baud) {
+       case 50:
+               csr = 0x00;
+               break;
+       case 110:
+               csr = 0x11;
+               break;
+       case 134:
+               csr = 0x22;
+               break;
+       case 200:
+               csr = 0x33;
+               break;
+       case 300:
+               csr = 0x44;
+               break;
+       case 600:
+               csr = 0x55;
+               break;
+       case 1200:
+               csr = 0x66;
+               break;
+       case 2400:
+               csr = 0x88;
+               break;
+       case 4800:
+               csr = 0x99;
+               break;
+       default:
+       case 9600:
+               csr = 0xbb;
+               break;
+       case 19200:
+               csr = 0xcc;
+               break;
+       }
+
+       WRITE_SC_PORT(port, CR, CR_RES_MR);
+       WRITE_SC_PORT(port, MRx, mr1);
+       WRITE_SC_PORT(port, MRx, mr2);
+
+       WRITE_SC(port, ACR, 0x80);
+       WRITE_SC_PORT(port, CSR, csr);
+
+       /* reset tx and rx */
+       WRITE_SC_PORT(port, CR, CR_RES_RX);
+       WRITE_SC_PORT(port, CR, CR_RES_TX);
+
+       WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX);
+       while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc)
+               udelay(2);
+
+       /* XXX */
+       uart_update_timeout(port, cflag,
+                           (port->uartclk / (16 * quot)));
+
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static const char *sc26xx_type(struct uart_port *port)
+{
+       return "SC26XX";
+}
+
+static void sc26xx_release_port(struct uart_port *port)
+{
+}
+
+static int sc26xx_request_port(struct uart_port *port)
+{
+       return 0;
+}
+
+static void sc26xx_config_port(struct uart_port *port, int flags)
+{
+}
+
+static int sc26xx_verify_port(struct uart_port *port, struct serial_struct *ser)
+{
+       return -EINVAL;
+}
+
+static struct uart_ops sc26xx_ops = {
+       .tx_empty       = sc26xx_tx_empty,
+       .set_mctrl      = sc26xx_set_mctrl,
+       .get_mctrl      = sc26xx_get_mctrl,
+       .stop_tx        = sc26xx_stop_tx,
+       .start_tx       = sc26xx_start_tx,
+       .stop_rx        = sc26xx_stop_rx,
+       .enable_ms      = sc26xx_enable_ms,
+       .break_ctl      = sc26xx_break_ctl,
+       .startup        = sc26xx_startup,
+       .shutdown       = sc26xx_shutdown,
+       .set_termios    = sc26xx_set_termios,
+       .type           = sc26xx_type,
+       .release_port   = sc26xx_release_port,
+       .request_port   = sc26xx_request_port,
+       .config_port    = sc26xx_config_port,
+       .verify_port    = sc26xx_verify_port,
+};
+
+static struct uart_port *sc26xx_port;
+
+#ifdef CONFIG_SERIAL_SC26XX_CONSOLE
+static void sc26xx_console_putchar(struct uart_port *port, char c)
+{
+       unsigned long flags;
+       int limit = 1000000;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       while (limit-- > 0) {
+               if (READ_SC_PORT(port, SR) & SR_TXRDY) {
+                       WRITE_SC_PORT(port, THR, c);
+                       break;
+               }
+               udelay(2);
+       }
+
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static void sc26xx_console_write(struct console *con, const char *s, unsigned n)
+{
+       struct uart_port *port = sc26xx_port;
+       int i;
+
+       for (i = 0; i < n; i++) {
+               if (*s == '\n')
+                       sc26xx_console_putchar(port, '\r');
+               sc26xx_console_putchar(port, *s++);
+       }
+}
+
+static int __init sc26xx_console_setup(struct console *con, char *options)
+{
+       struct uart_port *port = sc26xx_port;
+       int baud = 9600;
+       int bits = 8;
+       int parity = 'n';
+       int flow = 'n';
+
+       if (port->type != PORT_SC26XX)
+               return -1;
+
+       printk(KERN_INFO "Console: ttySC%d (SC26XX)\n", con->index);
+       if (options)
+               uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+       return uart_set_options(port, con, baud, parity, bits, flow);
+}
+
+static struct uart_driver sc26xx_reg;
+static struct console sc26xx_console = {
+       .name   =       "ttySC",
+       .write  =       sc26xx_console_write,
+       .device =       uart_console_device,
+       .setup  =       sc26xx_console_setup,
+       .flags  =       CON_PRINTBUFFER,
+       .index  =       -1,
+       .data   =       &sc26xx_reg,
+};
+#define SC26XX_CONSOLE   &sc26xx_console
+#else
+#define SC26XX_CONSOLE   NULL
+#endif
+
+static struct uart_driver sc26xx_reg = {
+       .owner                  = THIS_MODULE,
+       .driver_name            = "SC26xx",
+       .dev_name               = "ttySC",
+       .major                  = SC26XX_MAJOR,
+       .minor                  = SC26XX_MINOR_START,
+       .nr                     = SC26XX_NR,
+       .cons                   = SC26XX_CONSOLE,
+};
+
+static u8 sc26xx_flags2mask(unsigned int flags, unsigned int bitpos)
+{
+       unsigned int bit = (flags >> bitpos) & 15;
+
+       return bit ? (1 << (bit - 1)) : 0;
+}
+
+static void __devinit sc26xx_init_masks(struct uart_sc26xx_port *up,
+                                       int line, unsigned int data)
+{
+       up->dtr_mask[line] = sc26xx_flags2mask(data,  0);
+       up->rts_mask[line] = sc26xx_flags2mask(data,  4);
+       up->dsr_mask[line] = sc26xx_flags2mask(data,  8);
+       up->cts_mask[line] = sc26xx_flags2mask(data, 12);
+       up->dcd_mask[line] = sc26xx_flags2mask(data, 16);
+       up->ri_mask[line]  = sc26xx_flags2mask(data, 20);
+}
+
+static int __devinit sc26xx_probe(struct platform_device *dev)
+{
+       struct resource *res;
+       struct uart_sc26xx_port *up;
+       unsigned int *sc26xx_data = dev->dev.platform_data;
+       int err;
+
+       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       if (!res)
+               return -ENODEV;
+
+       up = kzalloc(sizeof *up, GFP_KERNEL);
+       if (unlikely(!up))
+               return -ENOMEM;
+
+       up->port[0].line = 0;
+       up->port[0].ops = &sc26xx_ops;
+       up->port[0].type = PORT_SC26XX;
+       up->port[0].uartclk = (29491200 / 16); /* arbitrary */
+
+       up->port[0].mapbase = res->start;
+       up->port[0].membase = ioremap_nocache(up->port[0].mapbase, 0x40);
+       up->port[0].iotype = UPIO_MEM;
+       up->port[0].irq = platform_get_irq(dev, 0);
+
+       up->port[0].dev = &dev->dev;
+
+       sc26xx_init_masks(up, 0, sc26xx_data[0]);
+
+       sc26xx_port = &up->port[0];
+
+       up->port[1].line = 1;
+       up->port[1].ops = &sc26xx_ops;
+       up->port[1].type = PORT_SC26XX;
+       up->port[1].uartclk = (29491200 / 16); /* arbitrary */
+
+       up->port[1].mapbase = up->port[0].mapbase;
+       up->port[1].membase = up->port[0].membase;
+       up->port[1].iotype = UPIO_MEM;
+       up->port[1].irq = up->port[0].irq;
+
+       up->port[1].dev = &dev->dev;
+
+       sc26xx_init_masks(up, 1, sc26xx_data[1]);
+
+       err = uart_register_driver(&sc26xx_reg);
+       if (err)
+               goto out_free_port;
+
+       sc26xx_reg.tty_driver->name_base = sc26xx_reg.minor;
+
+       err = uart_add_one_port(&sc26xx_reg, &up->port[0]);
+       if (err)
+               goto out_unregister_driver;
+
+       err = uart_add_one_port(&sc26xx_reg, &up->port[1]);
+       if (err)
+               goto out_remove_port0;
+
+       err = request_irq(up->port[0].irq, sc26xx_interrupt, 0, "sc26xx", up);
+       if (err)
+               goto out_remove_ports;
+
+       dev_set_drvdata(&dev->dev, up);
+       return 0;
+
+out_remove_ports:
+       uart_remove_one_port(&sc26xx_reg, &up->port[1]);
+out_remove_port0:
+       uart_remove_one_port(&sc26xx_reg, &up->port[0]);
+
+out_unregister_driver:
+       uart_unregister_driver(&sc26xx_reg);
+
+out_free_port:
+       kfree(up);
+       sc26xx_port = NULL;
+       return err;
+}
+
+
+static int __exit sc26xx_driver_remove(struct platform_device *dev)
+{
+       struct uart_sc26xx_port *up = dev_get_drvdata(&dev->dev);
+
+       free_irq(up->port[0].irq, up);
+
+       uart_remove_one_port(&sc26xx_reg, &up->port[0]);
+       uart_remove_one_port(&sc26xx_reg, &up->port[1]);
+
+       uart_unregister_driver(&sc26xx_reg);
+
+       kfree(up);
+       sc26xx_port = NULL;
+
+       dev_set_drvdata(&dev->dev, NULL);
+       return 0;
+}
+
+static struct platform_driver sc26xx_driver = {
+       .probe  = sc26xx_probe,
+       .remove = __devexit_p(sc26xx_driver_remove),
+       .driver = {
+               .name   = "SC26xx",
+       },
+};
+
+static int __init sc26xx_init(void)
+{
+       return platform_driver_register(&sc26xx_driver);
+}
+
+static void __exit sc26xx_exit(void)
+{
+       platform_driver_unregister(&sc26xx_driver);
+}
+
+module_init(sc26xx_init);
+module_exit(sc26xx_exit);
+
+
+MODULE_AUTHOR("Thomas Bogendörfer");
+MODULE_DESCRIPTION("SC681/SC2692 serial driver");
+MODULE_VERSION("1.0");
+MODULE_LICENSE("GPL");
index 3bb5d241dd40b2a13424aa42a86acba5ff4b44a3..276da148c57e015a6a148ec60a028d3d2e840ba6 100644 (file)
@@ -371,7 +371,8 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
                 */
                termios->c_cflag &= ~CBAUD;
                if (old) {
-                       termios->c_cflag |= old->c_cflag & CBAUD;
+                       baud = tty_termios_baud_rate(old);
+                       tty_termios_encode_baud_rate(termios, baud, baud);
                        old = NULL;
                        continue;
                }
@@ -380,7 +381,7 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
                 * As a last resort, if the quotient is zero,
                 * default to 9600 bps
                 */
-               termios->c_cflag |= B9600;
+               tty_termios_encode_baud_rate(termios, 9600, 9600);
        }
 
        return 0;
@@ -1977,6 +1978,7 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
 
        if (state->info && state->info->flags & UIF_INITIALIZED) {
                const struct uart_ops *ops = port->ops;
+               int tries;
 
                state->info->flags = (state->info->flags & ~UIF_INITIALIZED)
                                     | UIF_SUSPENDED;
@@ -1990,9 +1992,14 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
                /*
                 * Wait for the transmitter to empty.
                 */
-               while (!ops->tx_empty(port)) {
+               for (tries = 3; !ops->tx_empty(port) && tries; tries--) {
                        msleep(10);
                }
+               if (!tries)
+                       printk(KERN_ERR "%s%s%s%d: Unable to drain transmitter\n",
+                              port->dev ? port->dev->bus_id : "",
+                              port->dev ? ": " : "",
+                              drv->dev_name, port->line);
 
                ops->shutdown(port);
        }
@@ -2029,8 +2036,6 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
        }
        port->suspended = 0;
 
-       uart_change_pm(state, 0);
-
        /*
         * Re-enable the console device after suspending.
         */
@@ -2049,6 +2054,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
                if (state->info && state->info->tty && termios.c_cflag == 0)
                        termios = *state->info->tty->termios;
 
+               uart_change_pm(state, 0);
                port->ops->set_termios(port, &termios, NULL);
                console_start(port->cons);
        }
@@ -2057,6 +2063,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
                const struct uart_ops *ops = port->ops;
                int ret;
 
+               uart_change_pm(state, 0);
                ops->set_mctrl(port, 0);
                ret = ops->startup(port);
                if (ret == 0) {
@@ -2150,10 +2157,11 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
 
                /*
                 * Ensure that the modem control lines are de-activated.
+                * keep the DTR setting that is set in uart_set_options()
                 * We probably don't need a spinlock around this, but
                 */
                spin_lock_irqsave(&port->lock, flags);
-               port->ops->set_mctrl(port, 0);
+               port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR);
                spin_unlock_irqrestore(&port->lock, flags);
 
                /*
index d8b660061c1339855edb1d56af7e87a71490192d..164d2a42eb59fe5a5a58e9ea26d13830d493a28c 100644 (file)
@@ -389,7 +389,7 @@ static void serial_detach(struct pcmcia_device *link)
 /*====================================================================*/
 
 static int setup_serial(struct pcmcia_device *handle, struct serial_info * info,
-                       kio_addr_t iobase, int irq)
+                       unsigned int iobase, int irq)
 {
        struct uart_port port;
        int line;
@@ -456,7 +456,7 @@ next_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
 
 static int simple_config(struct pcmcia_device *link)
 {
-       static const kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+       static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
        static const int size_table[2] = { 8, 16 };
        struct serial_info *info = link->priv;
        struct serial_cfg_mem *cfg_mem;
@@ -480,7 +480,7 @@ static int simple_config(struct pcmcia_device *link)
        /* If the card is already configured, look up the port and irq */
        i = pcmcia_get_configuration_info(link, &config);
        if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) {
-               kio_addr_t port = 0;
+               unsigned int port = 0;
                if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) {
                        port = config.BasePort2;
                        info->slave = 1;
index 80943409edb000cd0c6202934325aaa1706c5f25..bacf68dca01a04443a4f849d6dffb421a9883775 100644 (file)
@@ -142,7 +142,7 @@ static int ulite_transmit(struct uart_port *port, int stat)
 
 static irqreturn_t ulite_isr(int irq, void *dev_id)
 {
-       struct uart_port *port = (struct uart_port *)dev_id;
+       struct uart_port *port = dev_id;
        int busy;
 
        do {
index aaaea81e412aa81abe5f2f1ced1b89152044c4a3..d8107890db152c789a764248a9d9a1078484ee02 100644 (file)
@@ -144,10 +144,10 @@ config SPI_OMAP_UWIRE
          This hooks up to the MicroWire controller on OMAP1 chips.
 
 config SPI_OMAP24XX
-       tristate "McSPI driver for OMAP24xx"
-       depends on SPI_MASTER && ARCH_OMAP24XX
+       tristate "McSPI driver for OMAP24xx/OMAP34xx"
+       depends on SPI_MASTER && (ARCH_OMAP24XX || ARCH_OMAP34XX)
        help
-         SPI master controller for OMAP24xx Multichannel SPI
+         SPI master controller for OMAP24xx/OMAP34xx Multichannel SPI
          (McSPI) modules.
 
 config SPI_PXA2XX
@@ -176,6 +176,13 @@ config SPI_S3C24XX_GPIO
          the inbuilt hardware cannot provide the transfer mode, or
          where the board is using non hardware connected pins.
 
+config SPI_SH_SCI
+       tristate "SuperH SCI SPI controller"
+       depends on SPI_MASTER && SUPERH
+       select SPI_BITBANG
+       help
+         SPI driver for SuperH SCI blocks.
+
 config SPI_TXX9
        tristate "Toshiba TXx9 SPI controller"
        depends on SPI_MASTER && GENERIC_GPIO && CPU_TX49XX
index 41fbac45c323bc25bccd3a9d364279781826d290..7fca043ce723a77698d1946e1f88947c9a1d5008 100644 (file)
@@ -27,6 +27,7 @@ obj-$(CONFIG_SPI_S3C24XX_GPIO)                += spi_s3c24xx_gpio.o
 obj-$(CONFIG_SPI_S3C24XX)              += spi_s3c24xx.o
 obj-$(CONFIG_SPI_TXX9)                 += spi_txx9.o
 obj-$(CONFIG_SPI_XILINX)               += xilinx_spi.o
+obj-$(CONFIG_SPI_SH_SCI)               += spi_sh_sci.o
 #      ... add above this line ...
 
 # SPI protocol drivers (device/link on bus)
index ff10808183a36f4e9d642469e42653d50f13ca24..293b7cab3e57021afcfeddcd2a5b007fbfba229a 100644 (file)
@@ -51,7 +51,9 @@ struct atmel_spi {
        u8                      stopping;
        struct list_head        queue;
        struct spi_transfer     *current_transfer;
-       unsigned long           remaining_bytes;
+       unsigned long           current_remaining_bytes;
+       struct spi_transfer     *next_transfer;
+       unsigned long           next_remaining_bytes;
 
        void                    *buffer;
        dma_addr_t              buffer_dma;
@@ -121,6 +123,48 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
                gpio_set_value(gpio, !active);
 }
 
+static inline int atmel_spi_xfer_is_last(struct spi_message *msg,
+                                       struct spi_transfer *xfer)
+{
+       return msg->transfers.prev == &xfer->transfer_list;
+}
+
+static inline int atmel_spi_xfer_can_be_chained(struct spi_transfer *xfer)
+{
+       return xfer->delay_usecs == 0 && !xfer->cs_change;
+}
+
+static void atmel_spi_next_xfer_data(struct spi_master *master,
+                               struct spi_transfer *xfer,
+                               dma_addr_t *tx_dma,
+                               dma_addr_t *rx_dma,
+                               u32 *plen)
+{
+       struct atmel_spi        *as = spi_master_get_devdata(master);
+       u32                     len = *plen;
+
+       /* use scratch buffer only when rx or tx data is unspecified */
+       if (xfer->rx_buf)
+               *rx_dma = xfer->rx_dma + xfer->len - len;
+       else {
+               *rx_dma = as->buffer_dma;
+               if (len > BUFFER_SIZE)
+                       len = BUFFER_SIZE;
+       }
+       if (xfer->tx_buf)
+               *tx_dma = xfer->tx_dma + xfer->len - len;
+       else {
+               *tx_dma = as->buffer_dma;
+               if (len > BUFFER_SIZE)
+                       len = BUFFER_SIZE;
+               memset(as->buffer, 0, len);
+               dma_sync_single_for_device(&as->pdev->dev,
+                               as->buffer_dma, len, DMA_TO_DEVICE);
+       }
+
+       *plen = len;
+}
+
 /*
  * Submit next transfer for DMA.
  * lock is held, spi irq is blocked
@@ -130,53 +174,78 @@ static void atmel_spi_next_xfer(struct spi_master *master,
 {
        struct atmel_spi        *as = spi_master_get_devdata(master);
        struct spi_transfer     *xfer;
-       u32                     len;
+       u32                     len, remaining, total;
        dma_addr_t              tx_dma, rx_dma;
 
-       xfer = as->current_transfer;
-       if (!xfer || as->remaining_bytes == 0) {
-               if (xfer)
-                       xfer = list_entry(xfer->transfer_list.next,
-                                       struct spi_transfer, transfer_list);
-               else
-                       xfer = list_entry(msg->transfers.next,
-                                       struct spi_transfer, transfer_list);
-               as->remaining_bytes = xfer->len;
-               as->current_transfer = xfer;
-       }
+       if (!as->current_transfer)
+               xfer = list_entry(msg->transfers.next,
+                               struct spi_transfer, transfer_list);
+       else if (!as->next_transfer)
+               xfer = list_entry(as->current_transfer->transfer_list.next,
+                               struct spi_transfer, transfer_list);
+       else
+               xfer = NULL;
 
-       len = as->remaining_bytes;
+       if (xfer) {
+               len = xfer->len;
+               atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len);
+               remaining = xfer->len - len;
 
-       tx_dma = xfer->tx_dma + xfer->len - len;
-       rx_dma = xfer->rx_dma + xfer->len - len;
+               spi_writel(as, RPR, rx_dma);
+               spi_writel(as, TPR, tx_dma);
 
-       /* use scratch buffer only when rx or tx data is unspecified */
-       if (!xfer->rx_buf) {
-               rx_dma = as->buffer_dma;
-               if (len > BUFFER_SIZE)
-                       len = BUFFER_SIZE;
-       }
-       if (!xfer->tx_buf) {
-               tx_dma = as->buffer_dma;
-               if (len > BUFFER_SIZE)
-                       len = BUFFER_SIZE;
-               memset(as->buffer, 0, len);
-               dma_sync_single_for_device(&as->pdev->dev,
-                               as->buffer_dma, len, DMA_TO_DEVICE);
+               if (msg->spi->bits_per_word > 8)
+                       len >>= 1;
+               spi_writel(as, RCR, len);
+               spi_writel(as, TCR, len);
+
+               dev_dbg(&msg->spi->dev,
+                       "  start xfer %p: len %u tx %p/%08x rx %p/%08x\n",
+                       xfer, xfer->len, xfer->tx_buf, xfer->tx_dma,
+                       xfer->rx_buf, xfer->rx_dma);
+       } else {
+               xfer = as->next_transfer;
+               remaining = as->next_remaining_bytes;
        }
 
-       spi_writel(as, RPR, rx_dma);
-       spi_writel(as, TPR, tx_dma);
+       as->current_transfer = xfer;
+       as->current_remaining_bytes = remaining;
 
-       as->remaining_bytes -= len;
-       if (msg->spi->bits_per_word > 8)
-               len >>= 1;
+       if (remaining > 0)
+               len = remaining;
+       else if (!atmel_spi_xfer_is_last(msg, xfer)
+                       && atmel_spi_xfer_can_be_chained(xfer)) {
+               xfer = list_entry(xfer->transfer_list.next,
+                               struct spi_transfer, transfer_list);
+               len = xfer->len;
+       } else
+               xfer = NULL;
 
-       /* REVISIT: when xfer->delay_usecs == 0, the PDC "next transfer"
-        * mechanism might help avoid the IRQ latency between transfers
-        * (and improve the nCS0 errata handling on at91rm9200 chips)
-        *
-        * We're also waiting for ENDRX before we start the next
+       as->next_transfer = xfer;
+
+       if (xfer) {
+               total = len;
+               atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len);
+               as->next_remaining_bytes = total - len;
+
+               spi_writel(as, RNPR, rx_dma);
+               spi_writel(as, TNPR, tx_dma);
+
+               if (msg->spi->bits_per_word > 8)
+                       len >>= 1;
+               spi_writel(as, RNCR, len);
+               spi_writel(as, TNCR, len);
+
+               dev_dbg(&msg->spi->dev,
+                       "  next xfer %p: len %u tx %p/%08x rx %p/%08x\n",
+                       xfer, xfer->len, xfer->tx_buf, xfer->tx_dma,
+                       xfer->rx_buf, xfer->rx_dma);
+       } else {
+               spi_writel(as, RNCR, 0);
+               spi_writel(as, TNCR, 0);
+       }
+
+       /* REVISIT: We're waiting for ENDRX before we start the next
         * transfer because we need to handle some difficult timing
         * issues otherwise. If we wait for ENDTX in one transfer and
         * then starts waiting for ENDRX in the next, it's difficult
@@ -186,17 +255,7 @@ static void atmel_spi_next_xfer(struct spi_master *master,
         *
         * It should be doable, though. Just not now...
         */
-       spi_writel(as, TNCR, 0);
-       spi_writel(as, RNCR, 0);
        spi_writel(as, IER, SPI_BIT(ENDRX) | SPI_BIT(OVRES));
-
-       dev_dbg(&msg->spi->dev,
-               "  start xfer %p: len %u tx %p/%08x rx %p/%08x imr %03x\n",
-               xfer, xfer->len, xfer->tx_buf, xfer->tx_dma,
-               xfer->rx_buf, xfer->rx_dma, spi_readl(as, IMR));
-
-       spi_writel(as, RCR, len);
-       spi_writel(as, TCR, len);
        spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN));
 }
 
@@ -294,6 +353,7 @@ atmel_spi_msg_done(struct spi_master *master, struct atmel_spi *as,
        spin_lock(&as->lock);
 
        as->current_transfer = NULL;
+       as->next_transfer = NULL;
 
        /* continue if needed */
        if (list_empty(&as->queue) || as->stopping)
@@ -377,7 +437,7 @@ atmel_spi_interrupt(int irq, void *dev_id)
 
                spi_writel(as, IDR, pending);
 
-               if (as->remaining_bytes == 0) {
+               if (as->current_remaining_bytes == 0) {
                        msg->actual_length += xfer->len;
 
                        if (!msg->is_dma_mapped)
@@ -387,7 +447,7 @@ atmel_spi_interrupt(int irq, void *dev_id)
                        if (xfer->delay_usecs)
                                udelay(xfer->delay_usecs);
 
-                       if (msg->transfers.prev == &xfer->transfer_list) {
+                       if (atmel_spi_xfer_is_last(msg, xfer)) {
                                /* report completed message */
                                atmel_spi_msg_done(master, as, msg, 0,
                                                xfer->cs_change);
@@ -490,9 +550,14 @@ static int atmel_spi_setup(struct spi_device *spi)
        if (!(spi->mode & SPI_CPHA))
                csr |= SPI_BIT(NCPHA);
 
-       /* TODO: DLYBS and DLYBCT */
-       csr |= SPI_BF(DLYBS, 10);
-       csr |= SPI_BF(DLYBCT, 10);
+       /* DLYBS is mostly irrelevant since we manage chipselect using GPIOs.
+        *
+        * DLYBCT would add delays between words, slowing down transfers.
+        * It could potentially be useful to cope with DMA bottlenecks, but
+        * in those cases it's probably best to just use a lower bitrate.
+        */
+       csr |= SPI_BF(DLYBS, 0);
+       csr |= SPI_BF(DLYBCT, 0);
 
        /* chipselect must have been muxed as GPIO (e.g. in board setup) */
        npcs_pin = (unsigned int)spi->controller_data;
index ea61724ae2256fe33035f77e29cce9a0a67eb48a..a6ba11afb03f798bb7f8520c352b419ff6bb119d 100644 (file)
@@ -915,6 +915,28 @@ static u8 __initdata spi2_txdma_id[] = {
        OMAP24XX_DMA_SPI2_TX1,
 };
 
+#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
+static u8 __initdata spi3_rxdma_id[] = {
+       OMAP24XX_DMA_SPI3_RX0,
+       OMAP24XX_DMA_SPI3_RX1,
+};
+
+static u8 __initdata spi3_txdma_id[] = {
+       OMAP24XX_DMA_SPI3_TX0,
+       OMAP24XX_DMA_SPI3_TX1,
+};
+#endif
+
+#ifdef CONFIG_ARCH_OMAP3
+static u8 __initdata spi4_rxdma_id[] = {
+       OMAP34XX_DMA_SPI4_RX0,
+};
+
+static u8 __initdata spi4_txdma_id[] = {
+       OMAP34XX_DMA_SPI4_TX0,
+};
+#endif
+
 static int __init omap2_mcspi_probe(struct platform_device *pdev)
 {
        struct spi_master       *master;
@@ -935,7 +957,20 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
                txdma_id = spi2_txdma_id;
                num_chipselect = 2;
                break;
-       /* REVISIT omap2430 has a third McSPI ... */
+#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
+       case 3:
+               rxdma_id = spi3_rxdma_id;
+               txdma_id = spi3_txdma_id;
+               num_chipselect = 2;
+               break;
+#endif
+#ifdef CONFIG_ARCH_OMAP3
+       case 4:
+               rxdma_id = spi4_rxdma_id;
+               txdma_id = spi4_txdma_id;
+               num_chipselect = 1;
+               break;
+#endif
        default:
                return -EINVAL;
        }
index eb817b8eb02439eeb12944e89fc2f55749adc009..365e0e355aea302e684451592d9315862f565275 100644 (file)
@@ -1526,17 +1526,6 @@ static void pxa2xx_spi_shutdown(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_PM
-static int suspend_devices(struct device *dev, void *pm_message)
-{
-       pm_message_t *state = pm_message;
-
-       if (dev->power.power_state.event != state->event) {
-               dev_warn(dev, "pm state does not match request\n");
-               return -1;
-       }
-
-       return 0;
-}
 
 static int pxa2xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
 {
@@ -1544,12 +1533,6 @@ static int pxa2xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
        struct ssp_device *ssp = drv_data->ssp;
        int status = 0;
 
-       /* Check all childern for current power state */
-       if (device_for_each_child(&pdev->dev, &state, suspend_devices) != 0) {
-               dev_warn(&pdev->dev, "suspend aborted\n");
-               return -1;
-       }
-
        status = stop_queue(drv_data);
        if (status != 0)
                return status;
index 682a6a48fec31e989dee472420cd37bc766c4b9f..1ad12afc6ba0ace916c817c571b265dc49cc1398 100644 (file)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/autoconf.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/init.h>
@@ -77,39 +76,33 @@ static int spi_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 #ifdef CONFIG_PM
 
-/*
- * NOTE:  the suspend() method for an spi_master controller driver
- * should verify that all its child devices are marked as suspended;
- * suspend requests delivered through sysfs power/state files don't
- * enforce such constraints.
- */
 static int spi_suspend(struct device *dev, pm_message_t message)
 {
-       int                     value;
+       int                     value = 0;
        struct spi_driver       *drv = to_spi_driver(dev->driver);
 
-       if (!drv || !drv->suspend)
-               return 0;
-
        /* suspend will stop irqs and dma; no more i/o */
-       value = drv->suspend(to_spi_device(dev), message);
-       if (value == 0)
-               dev->power.power_state = message;
+       if (drv) {
+               if (drv->suspend)
+                       value = drv->suspend(to_spi_device(dev), message);
+               else
+                       dev_dbg(dev, "... can't suspend\n");
+       }
        return value;
 }
 
 static int spi_resume(struct device *dev)
 {
-       int                     value;
+       int                     value = 0;
        struct spi_driver       *drv = to_spi_driver(dev->driver);
 
-       if (!drv || !drv->resume)
-               return 0;
-
        /* resume may restart the i/o queue */
-       value = drv->resume(to_spi_device(dev));
-       if (value == 0)
-               dev->power.power_state = PMSG_ON;
+       if (drv) {
+               if (drv->resume)
+                       value = drv->resume(to_spi_device(dev));
+               else
+                       dev_dbg(dev, "... can't resume\n");
+       }
        return value;
 }
 
index 7ef39a6e8c065afc97bba75dd26b2b691be95e4b..d853fceb6bf01bebfa9f3386a6dee184dbc21c20 100644 (file)
@@ -1,37 +1,11 @@
 /*
- * File:       drivers/spi/bfin5xx_spi.c
- * Maintainer:
- *             Bryan Wu <bryan.wu@analog.com>
- * Original Author:
- *             Luke Yang (Analog Devices Inc.)
- *
- * Created:    March. 10th 2006
- * Description:        SPI controller driver for Blackfin BF5xx
- * Bugs:       Enter bugs at http://blackfin.uclinux.org/
- *
- * Modified:
- *     March 10, 2006  bfin5xx_spi.c Created. (Luke Yang)
- *      August 7, 2006  added full duplex mode (Axel Weiss & Luke Yang)
- *      July  17, 2007  add support for BF54x SPI0 controller (Bryan Wu)
- *      July  30, 2007  add platfrom_resource interface to support multi-port
- *                      SPI controller (Bryan Wu)
+ * Blackfin On-Chip SPI Driver
  *
  * Copyright 2004-2007 Analog Devices Inc.
  *
- * This program is free software ;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ;  either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Enter bugs at http://blackfin.uclinux.org/
  *
- * You should have received a copy of the GNU General Public License
- * along with this program ;  see the file COPYING.
- * If not, write to the Free Software Foundation,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under the GPL-2 or later.
  */
 
 #include <linux/init.h>
@@ -223,10 +197,9 @@ static void cs_deactive(struct driver_data *drv_data, struct chip_data *chip)
 #define MAX_SPI_SSEL   7
 
 /* stop controller and re-config current chip*/
-static int restore_state(struct driver_data *drv_data)
+static void restore_state(struct driver_data *drv_data)
 {
        struct chip_data *chip = drv_data->cur_chip;
-       int ret = 0;
 
        /* Clear status and disable clock */
        write_STAT(drv_data, BIT_STAT_CLR);
@@ -239,13 +212,6 @@ static int restore_state(struct driver_data *drv_data)
 
        bfin_spi_enable(drv_data);
        cs_active(drv_data, chip);
-
-       if (ret)
-               dev_dbg(&drv_data->pdev->dev,
-                       ": request chip select number %d failed\n",
-                       chip->chip_select_num);
-
-       return ret;
 }
 
 /* used to kick off transfer in rx mode */
@@ -286,32 +252,30 @@ static void u8_writer(struct driver_data *drv_data)
        dev_dbg(&drv_data->pdev->dev,
                "cr8-s is 0x%x\n", read_STAT(drv_data));
 
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        while (drv_data->tx < drv_data->tx_end) {
                write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
                while (read_STAT(drv_data) & BIT_STAT_TXS)
                        cpu_relax();
                ++drv_data->tx;
        }
+
+       /* poll for SPI completion before return */
+       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
+               cpu_relax();
 }
 
 static void u8_cs_chg_writer(struct driver_data *drv_data)
 {
        struct chip_data *chip = drv_data->cur_chip;
 
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        while (drv_data->tx < drv_data->tx_end) {
                cs_active(drv_data, chip);
 
                write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
                while (read_STAT(drv_data) & BIT_STAT_TXS)
                        cpu_relax();
+               while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
+                       cpu_relax();
 
                cs_deactive(drv_data, chip);
 
@@ -350,43 +314,28 @@ static void u8_cs_chg_reader(struct driver_data *drv_data)
 {
        struct chip_data *chip = drv_data->cur_chip;
 
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
-       /* clear TDBR buffer before read(else it will be shifted out) */
-       write_TDBR(drv_data, 0xFFFF);
+       while (drv_data->rx < drv_data->rx_end) {
+               cs_active(drv_data, chip);
+               read_RDBR(drv_data);    /* kick off */
 
-       cs_active(drv_data, chip);
-       dummy_read(drv_data);
+               while (!(read_STAT(drv_data) & BIT_STAT_RXS))
+                       cpu_relax();
+               while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
+                       cpu_relax();
 
-       while (drv_data->rx < drv_data->rx_end - 1) {
+               *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
                cs_deactive(drv_data, chip);
 
-               while (!(read_STAT(drv_data) & BIT_STAT_RXS))
-                       cpu_relax();
-               cs_active(drv_data, chip);
-               *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
                ++drv_data->rx;
        }
-       cs_deactive(drv_data, chip);
-
-       while (!(read_STAT(drv_data) & BIT_STAT_RXS))
-               cpu_relax();
-       *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
-       ++drv_data->rx;
 }
 
 static void u8_duplex(struct driver_data *drv_data)
 {
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        /* in duplex mode, clk is triggered by writing of TDBR */
        while (drv_data->rx < drv_data->rx_end) {
                write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
-               while (read_STAT(drv_data) & BIT_STAT_TXS)
+               while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
                        cpu_relax();
                while (!(read_STAT(drv_data) & BIT_STAT_RXS))
                        cpu_relax();
@@ -400,15 +349,12 @@ static void u8_cs_chg_duplex(struct driver_data *drv_data)
 {
        struct chip_data *chip = drv_data->cur_chip;
 
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        while (drv_data->rx < drv_data->rx_end) {
                cs_active(drv_data, chip);
 
                write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
-               while (read_STAT(drv_data) & BIT_STAT_TXS)
+
+               while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
                        cpu_relax();
                while (!(read_STAT(drv_data) & BIT_STAT_RXS))
                        cpu_relax();
@@ -426,32 +372,30 @@ static void u16_writer(struct driver_data *drv_data)
        dev_dbg(&drv_data->pdev->dev,
                "cr16 is 0x%x\n", read_STAT(drv_data));
 
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        while (drv_data->tx < drv_data->tx_end) {
                write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
                while ((read_STAT(drv_data) & BIT_STAT_TXS))
                        cpu_relax();
                drv_data->tx += 2;
        }
+
+       /* poll for SPI completion before return */
+       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
+               cpu_relax();
 }
 
 static void u16_cs_chg_writer(struct driver_data *drv_data)
 {
        struct chip_data *chip = drv_data->cur_chip;
 
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        while (drv_data->tx < drv_data->tx_end) {
                cs_active(drv_data, chip);
 
                write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
                while ((read_STAT(drv_data) & BIT_STAT_TXS))
                        cpu_relax();
+               while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
+                       cpu_relax();
 
                cs_deactive(drv_data, chip);
 
@@ -519,14 +463,10 @@ static void u16_cs_chg_reader(struct driver_data *drv_data)
 
 static void u16_duplex(struct driver_data *drv_data)
 {
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        /* in duplex mode, clk is triggered by writing of TDBR */
        while (drv_data->tx < drv_data->tx_end) {
                write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
-               while (read_STAT(drv_data) & BIT_STAT_TXS)
+               while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
                        cpu_relax();
                while (!(read_STAT(drv_data) & BIT_STAT_RXS))
                        cpu_relax();
@@ -540,15 +480,11 @@ static void u16_cs_chg_duplex(struct driver_data *drv_data)
 {
        struct chip_data *chip = drv_data->cur_chip;
 
-       /* poll for SPI completion before start */
-       while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
-               cpu_relax();
-
        while (drv_data->tx < drv_data->tx_end) {
                cs_active(drv_data, chip);
 
                write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
-               while (read_STAT(drv_data) & BIT_STAT_TXS)
+               while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
                        cpu_relax();
                while (!(read_STAT(drv_data) & BIT_STAT_RXS))
                        cpu_relax();
@@ -616,7 +552,7 @@ static void giveback(struct driver_data *drv_data)
 
 static irqreturn_t dma_irq_handler(int irq, void *dev_id)
 {
-       struct driver_data *drv_data = (struct driver_data *)dev_id;
+       struct driver_data *drv_data = dev_id;
        struct chip_data *chip = drv_data->cur_chip;
        struct spi_message *msg = drv_data->cur_msg;
 
@@ -978,10 +914,7 @@ static void pump_messages(struct work_struct *work)
 
        /* Setup the SSP using the per chip configuration */
        drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
-       if (restore_state(drv_data)) {
-               spin_unlock_irqrestore(&drv_data->lock, flags);
-               return;
-       };
+       restore_state(drv_data);
 
        list_del_init(&drv_data->cur_msg->queue);
 
@@ -1187,7 +1120,7 @@ static int setup(struct spi_device *spi)
        if ((chip->chip_select_num > 0)
                && (chip->chip_select_num <= spi->master->num_chipselect))
                peripheral_request(ssel[spi->master->bus_num]
-                       [chip->chip_select_num-1], DRV_NAME);
+                       [chip->chip_select_num-1], spi->modalias);
 
        cs_deactive(drv_data, chip);
 
index 2cd8573fb09c0a5f514440de93c8dd6459e6ed6e..1b0647124933cc473ef532e3a59265f6f2dd6a2c 100644 (file)
 #define SPI_FIFO_BYTE_WIDTH            (2)
 #define SPI_FIFO_OVERFLOW_MARGIN       (2)
 
-/* DMA burst lenght for half full/empty request trigger */
+/* DMA burst length for half full/empty request trigger */
 #define SPI_DMA_BLR                    (SPI_FIFO_DEPTH * SPI_FIFO_BYTE_WIDTH / 2)
 
 /* Dummy char output to achieve reads.
@@ -1686,17 +1686,6 @@ static void spi_imx_shutdown(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_PM
-static int suspend_devices(struct device *dev, void *pm_message)
-{
-       pm_message_t *state = pm_message;
-
-       if (dev->power.power_state.event != state->event) {
-               dev_warn(dev, "pm state does not match request\n");
-               return -1;
-       }
-
-       return 0;
-}
 
 static int spi_imx_suspend(struct platform_device *pdev, pm_message_t state)
 {
index 89d6685a5ca4860594773a346e37dbad40021762..6e834b8b9d2785f51427cd11d3a051e9e9471b03 100644 (file)
@@ -237,10 +237,8 @@ static int __init s3c24xx_spi_probe(struct platform_device *pdev)
 {
        struct s3c24xx_spi *hw;
        struct spi_master *master;
-       struct spi_board_info *bi;
        struct resource *res;
        int err = 0;
-       int i;
 
        master = spi_alloc_master(&pdev->dev, sizeof(struct s3c24xx_spi));
        if (master == NULL) {
@@ -348,16 +346,6 @@ static int __init s3c24xx_spi_probe(struct platform_device *pdev)
                goto err_register;
        }
 
-       /* register all the devices associated */
-
-       bi = &hw->pdata->board_info[0];
-       for (i = 0; i < hw->pdata->board_size; i++, bi++) {
-               dev_info(hw->dev, "registering %s\n", bi->modalias);
-
-               bi->controller_data = hw;
-               spi_new_device(master, bi);
-       }
-
        return 0;
 
  err_register:
index 109d82c1abc05a9844578df75f72ad2f80af03ee..82ae7d7eca386bafffa0c7ee7eb8b4c1388630dc 100644 (file)
@@ -100,7 +100,6 @@ static int s3c2410_spigpio_probe(struct platform_device *dev)
        struct spi_master       *master;
        struct s3c2410_spigpio  *sp;
        int ret;
-       int i;
 
        master = spi_alloc_master(&dev->dev, sizeof(struct s3c2410_spigpio));
        if (master == NULL) {
@@ -143,17 +142,6 @@ static int s3c2410_spigpio_probe(struct platform_device *dev)
        if (ret)
                goto err_no_bitbang;
 
-       /* register the chips to go with the board */
-
-       for (i = 0; i < sp->info->board_size; i++) {
-               dev_info(&dev->dev, "registering %p: %s\n",
-                        &sp->info->board_info[i],
-                        sp->info->board_info[i].modalias);
-
-               sp->info->board_info[i].controller_data = sp;
-               spi_new_device(master, sp->info->board_info + i);
-       }
-
        return 0;
 
  err_no_bitbang:
diff --git a/drivers/spi/spi_sh_sci.c b/drivers/spi/spi_sh_sci.c
new file mode 100644 (file)
index 0000000..3dbe71b
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * SH SCI SPI interface
+ *
+ * Copyright (c) 2008 Magnus Damm
+ *
+ * Based on S3C24XX GPIO based SPI driver, which is:
+ *   Copyright (c) 2006 Ben Dooks
+ *   Copyright (c) 2006 Simtec Electronics
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+
+#include <linux/spi/spi.h>
+#include <linux/spi/spi_bitbang.h>
+
+#include <asm/spi.h>
+#include <asm/io.h>
+
+struct sh_sci_spi {
+       struct spi_bitbang bitbang;
+
+       void __iomem *membase;
+       unsigned char val;
+       struct sh_spi_info *info;
+       struct platform_device *dev;
+};
+
+#define SCSPTR(sp)     (sp->membase + 0x1c)
+#define PIN_SCK                (1 << 2)
+#define PIN_TXD                (1 << 0)
+#define PIN_RXD                PIN_TXD
+#define PIN_INIT       ((1 << 1) | (1 << 3) | PIN_SCK | PIN_TXD)
+
+static inline void setbits(struct sh_sci_spi *sp, int bits, int on)
+{
+       /*
+        * We are the only user of SCSPTR so no locking is required.
+        * Reading bit 2 and 0 in SCSPTR gives pin state as input.
+        * Writing the same bits sets the output value.
+        * This makes regular read-modify-write difficult so we
+        * use sp->val to keep track of the latest register value.
+        */
+
+       if (on)
+               sp->val |= bits;
+       else
+               sp->val &= ~bits;
+
+       iowrite8(sp->val, SCSPTR(sp));
+}
+
+static inline void setsck(struct spi_device *dev, int on)
+{
+       setbits(spi_master_get_devdata(dev->master), PIN_SCK, on);
+}
+
+static inline void setmosi(struct spi_device *dev, int on)
+{
+       setbits(spi_master_get_devdata(dev->master), PIN_TXD, on);
+}
+
+static inline u32 getmiso(struct spi_device *dev)
+{
+       struct sh_sci_spi *sp = spi_master_get_devdata(dev->master);
+
+       return (ioread8(SCSPTR(sp)) & PIN_RXD) ? 1 : 0;
+}
+
+#define spidelay(x) ndelay(x)
+
+#define EXPAND_BITBANG_TXRX
+#include <linux/spi/spi_bitbang.h>
+
+static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi,
+                                     unsigned nsecs, u32 word, u8 bits)
+{
+       return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
+}
+
+static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi,
+                                     unsigned nsecs, u32 word, u8 bits)
+{
+       return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
+}
+
+static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi,
+                                     unsigned nsecs, u32 word, u8 bits)
+{
+       return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
+}
+
+static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi,
+                                     unsigned nsecs, u32 word, u8 bits)
+{
+       return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
+}
+
+static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
+{
+       struct sh_sci_spi *sp = spi_master_get_devdata(dev->master);
+
+       if (sp->info && sp->info->chip_select)
+               (sp->info->chip_select)(sp->info, dev->chip_select, value);
+}
+
+static int sh_sci_spi_probe(struct platform_device *dev)
+{
+       struct resource *r;
+       struct spi_master *master;
+       struct sh_sci_spi *sp;
+       int ret;
+
+       master = spi_alloc_master(&dev->dev, sizeof(struct sh_sci_spi));
+       if (master == NULL) {
+               dev_err(&dev->dev, "failed to allocate spi master\n");
+               ret = -ENOMEM;
+               goto err0;
+       }
+
+       sp = spi_master_get_devdata(master);
+
+       platform_set_drvdata(dev, sp);
+       sp->info = dev->dev.platform_data;
+
+       /* setup spi bitbang adaptor */
+       sp->bitbang.master = spi_master_get(master);
+       sp->bitbang.master->bus_num = sp->info->bus_num;
+       sp->bitbang.master->num_chipselect = sp->info->num_chipselect;
+       sp->bitbang.chipselect = sh_sci_spi_chipselect;
+
+       sp->bitbang.txrx_word[SPI_MODE_0] = sh_sci_spi_txrx_mode0;
+       sp->bitbang.txrx_word[SPI_MODE_1] = sh_sci_spi_txrx_mode1;
+       sp->bitbang.txrx_word[SPI_MODE_2] = sh_sci_spi_txrx_mode2;
+       sp->bitbang.txrx_word[SPI_MODE_3] = sh_sci_spi_txrx_mode3;
+
+       r = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       if (r == NULL) {
+               ret = -ENOENT;
+               goto err1;
+       }
+       sp->membase = ioremap(r->start, r->end - r->start + 1);
+       if (!sp->membase) {
+               ret = -ENXIO;
+               goto err1;
+       }
+       sp->val = ioread8(SCSPTR(sp));
+       setbits(sp, PIN_INIT, 1);
+
+       ret = spi_bitbang_start(&sp->bitbang);
+       if (!ret)
+               return 0;
+
+       setbits(sp, PIN_INIT, 0);
+       iounmap(sp->membase);
+ err1:
+       spi_master_put(sp->bitbang.master);
+ err0:
+       return ret;
+}
+
+static int sh_sci_spi_remove(struct platform_device *dev)
+{
+       struct sh_sci_spi *sp = platform_get_drvdata(dev);
+
+       iounmap(sp->membase);
+       setbits(sp, PIN_INIT, 0);
+       spi_bitbang_stop(&sp->bitbang);
+       spi_master_put(sp->bitbang.master);
+       return 0;
+}
+
+static struct platform_driver sh_sci_spi_drv = {
+       .probe          = sh_sci_spi_probe,
+       .remove         = sh_sci_spi_remove,
+       .driver         = {
+               .name   = "spi_sh_sci",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init sh_sci_spi_init(void)
+{
+       return platform_driver_register(&sh_sci_spi_drv);
+}
+module_init(sh_sci_spi_init);
+
+static void __exit sh_sci_spi_exit(void)
+{
+       platform_driver_unregister(&sh_sci_spi_drv);
+}
+module_exit(sh_sci_spi_exit);
+
+MODULE_DESCRIPTION("SH SCI SPI Driver");
+MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
+MODULE_LICENSE("GPL");
index 1a31f7a72848d0cb8329c95c73b94f18efe27b51..2d27d6d6d08ebe40fdf4b02e4c4a66b601307e11 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Broadcom 43xx PCI-SSB bridge module
  *
- * This technically is a seperate PCI driver module, but
+ * This technically is a separate PCI driver module, but
  * because of its small size we include it in the SSB core
  * instead of creating a standalone module.
  *
index cc246faa35909116bb61d19541d47059c99ea0fb..2a77e9d42c687acc4773d68a4a2aa8b1176ff461 100644 (file)
@@ -417,30 +417,28 @@ static void uio_vma_close(struct vm_area_struct *vma)
        idev->vma_count--;
 }
 
-static struct page *uio_vma_nopage(struct vm_area_struct *vma,
-                                  unsigned long address, int *type)
+static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        struct uio_device *idev = vma->vm_private_data;
-       struct page* page = NOPAGE_SIGBUS;
+       struct page *page;
 
        int mi = uio_find_mem_index(vma);
        if (mi < 0)
-               return page;
+               return VM_FAULT_SIGBUS;
 
        if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL)
                page = virt_to_page(idev->info->mem[mi].addr);
        else
                page = vmalloc_to_page((void*)idev->info->mem[mi].addr);
        get_page(page);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return page;
+       vmf->page = page;
+       return 0;
 }
 
 static struct vm_operations_struct uio_vm_ops = {
        .open = uio_vma_open,
        .close = uio_vma_close,
-       .nopage = uio_vma_nopage,
+       .fault = uio_vma_fault,
 };
 
 static int uio_mmap_physical(struct vm_area_struct *vma)
index 7a6499008b897e65450b16bdee378cffe7f54856..755823cdf62a992b83d24fb894d186ed58e0761e 100644 (file)
@@ -42,6 +42,10 @@ config USB_ARCH_HAS_OHCI
        default y if PPC_MPC52xx
        # MIPS:
        default y if SOC_AU1X00
+       # SH:
+       default y if CPU_SUBTYPE_SH7720
+       default y if CPU_SUBTYPE_SH7721
+       default y if CPU_SUBTYPE_SH7763
        # more:
        default PCI
 
@@ -50,6 +54,7 @@ config USB_ARCH_HAS_EHCI
        boolean
        default y if PPC_83xx
        default y if SOC_AU1200
+       default y if ARCH_IXP4XX
        default PCI
 
 # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
index b450cbaa3a0baf91d445c5a43b0dd8d66b701646..86e64035edb01b04ec7439c1c450bad641a14085 100644 (file)
@@ -2,10 +2,7 @@
 # USB/ATM DSL configuration
 #
 
-menu "USB DSL modem support"
-       depends on USB
-
-config USB_ATM
+menuconfig USB_ATM
        tristate "USB DSL modem support"
        depends on USB && ATM
        select CRC32
@@ -18,6 +15,8 @@ config USB_ATM
          To compile this driver as a module, choose M here: the
          module will be called usbatm.
 
+if USB_ATM
+
 config USB_SPEEDTOUCH
        tristate "Speedtouch USB support"
        depends on USB_ATM
@@ -70,4 +69,4 @@ config USB_XUSBATM
          To compile this driver as a module, choose M here: the
          module will be called xusbatm.
 
-endmenu
+endif # USB_ATM
index 389c5b164eb2557a89775fbd9785540647c0af21..c5ec1a55eee3e9956806a1b48222fc67dc6e76f4 100644 (file)
@@ -999,7 +999,7 @@ static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
                bi.dwAddress = swab32(blockidx->PageAddress);
 
                uea_dbg(INS_TO_USBDEV(sc),
-                      "sending block %u for DSP page %u size %u adress %x\n",
+                      "sending block %u for DSP page %u size %u address %x\n",
                       blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
 
                /* send block info through the IDMA pipe */
@@ -1990,7 +1990,7 @@ static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
        return;
 
 bad2:
-       uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
+       uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
                        "Function : %d, Subfunction : %d\n",
                        E1_FUNCTION_TYPE(cmv->bFunction),
                        E1_FUNCTION_SUBTYPE(cmv->bFunction));
@@ -2038,7 +2038,7 @@ static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
        return;
 
 bad2:
-       uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
+       uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
                        "Function : %d, Subfunction : %d\n",
                        E4_FUNCTION_TYPE(cmv->wFunction),
                        E4_FUNCTION_SUBTYPE(cmv->wFunction));
index 912d97aaf9bf7b7ad52068dc850a8332aa4a76e5..bcc42136c93fcc15d31b193317163805de50dd50 100644 (file)
@@ -496,10 +496,19 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
           otherwise it is scheduled, and with high data rates data can get lost. */
        tty->low_latency = 1;
 
+       if (usb_autopm_get_interface(acm->control)) {
+               mutex_unlock(&open_mutex);
+               return -EIO;
+       }
+
+       mutex_lock(&acm->mutex);
+       mutex_unlock(&open_mutex);
        if (acm->used++) {
+               usb_autopm_put_interface(acm->control);
                goto done;
         }
 
+
        acm->ctrlurb->dev = acm->dev;
        if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
                dbg("usb_submit_urb(ctrl irq) failed");
@@ -526,14 +535,15 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
 
 done:
 err_out:
-       mutex_unlock(&open_mutex);
+       mutex_unlock(&acm->mutex);
        return rv;
 
 full_bailout:
        usb_kill_urb(acm->ctrlurb);
 bail_out:
+       usb_autopm_put_interface(acm->control);
        acm->used--;
-       mutex_unlock(&open_mutex);
+       mutex_unlock(&acm->mutex);
        return -EIO;
 }
 
@@ -570,6 +580,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
                        usb_kill_urb(acm->writeurb);
                        for (i = 0; i < nr; i++)
                                usb_kill_urb(acm->ru[i].urb);
+                       usb_autopm_put_interface(acm->control);
                } else
                        acm_tty_unregister(acm);
        }
@@ -904,7 +915,7 @@ next_desc:
        }
        
        if (data_interface_num != call_interface_num)
-               dev_dbg(&intf->dev,"Seperate call control interface. That is not fully supported.\n");
+               dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n");
 
 skip_normal_probe:
 
@@ -980,6 +991,7 @@ skip_normal_probe:
        spin_lock_init(&acm->throttle_lock);
        spin_lock_init(&acm->write_lock);
        spin_lock_init(&acm->read_lock);
+       mutex_init(&acm->mutex);
        acm->write_ready = 1;
        acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
 
@@ -1096,6 +1108,25 @@ alloc_fail:
        return -ENOMEM;
 }
 
+static void stop_data_traffic(struct acm *acm)
+{
+       int i;
+
+       tasklet_disable(&acm->urb_task);
+
+       usb_kill_urb(acm->ctrlurb);
+       usb_kill_urb(acm->writeurb);
+       for (i = 0; i < acm->rx_buflimit; i++)
+               usb_kill_urb(acm->ru[i].urb);
+
+       INIT_LIST_HEAD(&acm->filled_read_bufs);
+       INIT_LIST_HEAD(&acm->spare_read_bufs);
+
+       tasklet_enable(&acm->urb_task);
+
+       cancel_work_sync(&acm->work);
+}
+
 static void acm_disconnect(struct usb_interface *intf)
 {
        struct acm *acm = usb_get_intfdata(intf);
@@ -1123,19 +1154,7 @@ static void acm_disconnect(struct usb_interface *intf)
        usb_set_intfdata(acm->control, NULL);
        usb_set_intfdata(acm->data, NULL);
 
-       tasklet_disable(&acm->urb_task);
-
-       usb_kill_urb(acm->ctrlurb);
-       usb_kill_urb(acm->writeurb);
-       for (i = 0; i < acm->rx_buflimit; i++)
-               usb_kill_urb(acm->ru[i].urb);
-
-       INIT_LIST_HEAD(&acm->filled_read_bufs);
-       INIT_LIST_HEAD(&acm->spare_read_bufs);
-
-       tasklet_enable(&acm->urb_task);
-
-       flush_scheduled_work(); /* wait for acm_softint */
+       stop_data_traffic(acm);
 
        acm_write_buffers_free(acm);
        usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
@@ -1156,6 +1175,46 @@ static void acm_disconnect(struct usb_interface *intf)
                tty_hangup(acm->tty);
 }
 
+static int acm_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       struct acm *acm = usb_get_intfdata(intf);
+
+       if (acm->susp_count++)
+               return 0;
+       /*
+       we treat opened interfaces differently,
+       we must guard against open
+       */
+       mutex_lock(&acm->mutex);
+
+       if (acm->used)
+               stop_data_traffic(acm);
+
+       mutex_unlock(&acm->mutex);
+       return 0;
+}
+
+static int acm_resume(struct usb_interface *intf)
+{
+       struct acm *acm = usb_get_intfdata(intf);
+       int rv = 0;
+
+       if (--acm->susp_count)
+               return 0;
+
+       mutex_lock(&acm->mutex);
+       if (acm->used) {
+               rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
+               if (rv < 0)
+               goto err_out;
+
+               tasklet_schedule(&acm->urb_task);
+       }
+
+err_out:
+       mutex_unlock(&acm->mutex);
+       return rv;
+}
 /*
  * USB driver structure.
  */
@@ -1208,7 +1267,10 @@ static struct usb_driver acm_driver = {
        .name =         "cdc_acm",
        .probe =        acm_probe,
        .disconnect =   acm_disconnect,
+       .suspend =      acm_suspend,
+       .resume =       acm_resume,
        .id_table =     acm_ids,
+       .supports_autosuspend = 1,
 };
 
 /*
index 09f7765dbf8dc74ad223f42a3455d4dddb221c8d..8df6a57dcf9e4ca188b368f62ca2f0b4b86df4c6 100644 (file)
@@ -107,6 +107,7 @@ struct acm {
        int write_used;                                 /* number of non-empty write buffers */
        int write_ready;                                /* write urb is not running */
        spinlock_t write_lock;
+       struct mutex mutex;
        struct usb_cdc_line_coding line;                /* bits, stop, parity */
        struct work_struct work;                        /* work queue entry for line discipline waking up */
        struct tasklet_struct urb_task;                 /* rx processing */
@@ -120,6 +121,7 @@ struct acm {
        unsigned char throttle;                         /* throttled by tty layer */
        unsigned char clocal;                           /* termios CLOCAL */
        unsigned int ctrl_caps;                         /* control capabilities from the class specific header */
+       unsigned int susp_count;                        /* number of suspended interfaces */
 };
 
 #define CDC_DATA_INTERFACE_TYPE        0x0a
index 97b09f282705bb4c4249e733d89ea3ca43876cd2..5c33cdb9cac7131a0e4d2715ecbcec538903406f 100644 (file)
@@ -9,6 +9,21 @@ config USB_DEBUG
          of debug messages to the system log. Select this if you are having a
          problem with USB support and want to see more of what is going on.
 
+config USB_ANNOUNCE_NEW_DEVICES
+       bool "USB announce new devices"
+       depends on USB
+       default N
+       help
+         Say Y here if you want the USB core to always announce the
+         idVendor, idProduct, Manufacturer, Product, and SerialNumber
+         strings for every new USB device to the syslog.  This option is
+         usually used by distro vendors to help with debugging and to
+         let users know what specific device was added to the machine
+         in what location.
+
+         If you do not want this kind of information sent to the system
+         log, or have any doubts about this, say N here.
+
 comment "Miscellaneous USB options"
        depends on USB
 
index 28d4972f7ad5493f449dd1ae0fe07cab446bb264..cadb2dc1d28ae4ccee6cec683979938d874f6008 100644 (file)
@@ -53,11 +53,13 @@ int hcd_buffer_create(struct usb_hcd *hcd)
        char            name[16];
        int             i, size;
 
-       if (!hcd->self.controller->dma_mask)
+       if (!hcd->self.controller->dma_mask &&
+           !(hcd->driver->flags & HCD_LOCAL_MEM))
                return 0;
 
-       for (i = 0; i < HCD_BUFFER_POOLS; i++) { 
-               if (!(size = pool_max [i]))
+       for (i = 0; i < HCD_BUFFER_POOLS; i++) {
+               size = pool_max[i];
+               if (!size)
                        continue;
                snprintf(name, sizeof name, "buffer-%d", size);
                hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
@@ -80,10 +82,10 @@ int hcd_buffer_create(struct usb_hcd *hcd)
  */
 void hcd_buffer_destroy(struct usb_hcd *hcd)
 {
-       int             i;
+       int i;
 
-       for (i = 0; i < HCD_BUFFER_POOLS; i++) { 
-               struct dma_pool         *pool = hcd->pool[i];
+       for (i = 0; i < HCD_BUFFER_POOLS; i++) {
+               struct dma_pool *pool = hcd->pool[i];
                if (pool) {
                        dma_pool_destroy(pool);
                        hcd->pool[i] = NULL;
@@ -107,7 +109,8 @@ void *hcd_buffer_alloc(
        int                     i;
 
        /* some USB hosts just use PIO */
-       if (!bus->controller->dma_mask) {
+       if (!bus->controller->dma_mask &&
+           !(hcd->driver->flags & HCD_LOCAL_MEM)) {
                *dma = ~(dma_addr_t) 0;
                return kmalloc(size, mem_flags);
        }
@@ -132,7 +135,8 @@ void hcd_buffer_free(
        if (!addr)
                return;
 
-       if (!bus->controller->dma_mask) {
+       if (!bus->controller->dma_mask &&
+           !(hcd->driver->flags & HCD_LOCAL_MEM)) {
                kfree(addr);
                return;
        }
index 1a8edcee7f303af3d1f3a5c6931ca5f9a7620dc0..a92122a216bcc8dbb4f7ea092fa3108cdaaba36a 100644 (file)
@@ -238,7 +238,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
 
        /* Allocate space for the right(?) number of endpoints */
        num_ep = num_ep_orig = alt->desc.bNumEndpoints;
-       alt->desc.bNumEndpoints = 0;            // Use as a counter
+       alt->desc.bNumEndpoints = 0;            /* Use as a counter */
        if (num_ep > USB_MAXENDPOINTS) {
                dev_warn(ddev, "too many endpoints for config %d interface %d "
                    "altsetting %d: %d, using maximum allowed: %d\n",
@@ -246,7 +246,8 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
                num_ep = USB_MAXENDPOINTS;
        }
 
-       if (num_ep > 0) {       /* Can't allocate 0 bytes */
+       if (num_ep > 0) {
+               /* Can't allocate 0 bytes */
                len = sizeof(struct usb_host_endpoint) * num_ep;
                alt->endpoint = kzalloc(len, GFP_KERNEL);
                if (!alt->endpoint)
@@ -475,8 +476,9 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
        return 0;
 }
 
-// hub-only!! ... and only exported for reset/reinit path.
-// otherwise used internally on disconnect/destroy path
+/* hub-only!! ... and only exported for reset/reinit path.
+ * otherwise used internally on disconnect/destroy path
+ */
 void usb_destroy_configuration(struct usb_device *dev)
 {
        int c, i;
@@ -498,7 +500,7 @@ void usb_destroy_configuration(struct usb_device *dev)
                kfree(cf->string);
                for (i = 0; i < cf->desc.bNumInterfaces; i++) {
                        if (cf->intf_cache[i])
-                               kref_put(&cf->intf_cache[i]->ref, 
+                               kref_put(&cf->intf_cache[i]->ref,
                                          usb_release_interface_cache);
                }
        }
@@ -525,7 +527,7 @@ int usb_get_configuration(struct usb_device *dev)
        unsigned int cfgno, length;
        unsigned char *buffer;
        unsigned char *bigbuffer;
-       struct usb_config_descriptor *desc;
+       struct usb_config_descriptor *desc;
 
        cfgno = 0;
        if (dev->authorized == 0)       /* Not really an error */
index 87c794d60aa021ee3b6f1108e2cef34fb519f4c4..83d9dc379d968c7ecc87f759251f16e926ff4d89 100644 (file)
@@ -89,7 +89,7 @@ static const char *format_string_serialnumber =
 static const char *format_bandwidth =
 /* B:  Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */
   "B:  Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n";
-  
+
 static const char *format_device1 =
 /* D:  Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */
   "D:  Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n";
@@ -101,7 +101,7 @@ static const char *format_device2 =
 static const char *format_config =
 /* C:  #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */
   "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n";
-  
+
 static const char *format_iad =
 /* A:  FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */
   "A:  FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n";
@@ -122,7 +122,7 @@ static const char *format_endpt =
  */
 
 static DECLARE_WAIT_QUEUE_HEAD(deviceconndiscwq);
-static unsigned int conndiscevcnt = 0;
+static unsigned int conndiscevcnt;
 
 /* this struct stores the poll state for <mountpoint>/devices pollers */
 struct usb_device_status {
@@ -172,12 +172,8 @@ static const char *class_decode(const int class)
        return clas_info[ix].class_name;
 }
 
-static char *usb_dump_endpoint_descriptor(
-       int speed,
-       char *start,
-       char *end,
-       const struct usb_endpoint_descriptor *desc
-)
+static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
+                               const struct usb_endpoint_descriptor *desc)
 {
        char dir, unit, *type;
        unsigned interval, bandwidth = 1;
@@ -235,22 +231,24 @@ static char *usb_dump_endpoint_descriptor(
 
        start += sprintf(start, format_endpt, desc->bEndpointAddress, dir,
                         desc->bmAttributes, type,
-                        (le16_to_cpu(desc->wMaxPacketSize) & 0x07ff) * bandwidth,
+                        (le16_to_cpu(desc->wMaxPacketSize) & 0x07ff) *
+                        bandwidth,
                         interval, unit);
        return start;
 }
 
 static char *usb_dump_interface_descriptor(char *start, char *end,
-       const struct usb_interface_cache *intfc,
-       const struct usb_interface *iface,
-       int setno)
+                                       const struct usb_interface_cache *intfc,
+                                       const struct usb_interface *iface,
+                                       int setno)
 {
-       const struct usb_interface_descriptor *desc = &intfc->altsetting[setno].desc;
+       const struct usb_interface_descriptor *desc;
        const char *driver_name = "";
        int active = 0;
 
        if (start > end)
                return start;
+       desc = &intfc->altsetting[setno].desc;
        if (iface) {
                driver_name = (iface->dev.driver
                                ? iface->dev.driver->name
@@ -270,14 +268,10 @@ static char *usb_dump_interface_descriptor(char *start, char *end,
        return start;
 }
 
-static char *usb_dump_interface(
-       int speed,
-       char *start,
-       char *end,
-       const struct usb_interface_cache *intfc,
-       const struct usb_interface *iface,
-       int setno
-) {
+static char *usb_dump_interface(int speed, char *start, char *end,
+                               const struct usb_interface_cache *intfc,
+                               const struct usb_interface *iface, int setno)
+{
        const struct usb_host_interface *desc = &intfc->altsetting[setno];
        int i;
 
@@ -292,7 +286,7 @@ static char *usb_dump_interface(
 }
 
 static char *usb_dump_iad_descriptor(char *start, char *end,
-       const struct usb_interface_assoc_descriptor *iad)
+                       const struct usb_interface_assoc_descriptor *iad)
 {
        if (start > end)
                return start;
@@ -311,13 +305,15 @@ static char *usb_dump_iad_descriptor(char *start, char *end,
  * 1. marking active interface altsettings (code lists all, but should mark
  *    which ones are active, if any)
  */
-
-static char *usb_dump_config_descriptor(char *start, char *end, const struct usb_config_descriptor *desc, int active)
+static char *usb_dump_config_descriptor(char *start, char *end,
+                               const struct usb_config_descriptor *desc,
+                               int active)
 {
        if (start > end)
                return start;
        start += sprintf(start, format_config,
-                        active ? '*' : ' ',    /* mark active/actual/current cfg. */
+                        /* mark active/actual/current cfg. */
+                        active ? '*' : ' ',
                         desc->bNumInterfaces,
                         desc->bConfigurationValue,
                         desc->bmAttributes,
@@ -325,13 +321,8 @@ static char *usb_dump_config_descriptor(char *start, char *end, const struct usb
        return start;
 }
 
-static char *usb_dump_config (
-       int speed,
-       char *start,
-       char *end,
-       const struct usb_host_config *config,
-       int active
-)
+static char *usb_dump_config(int speed, char *start, char *end,
+                            const struct usb_host_config *config, int active)
 {
        int i, j;
        struct usb_interface_cache *intfc;
@@ -339,7 +330,8 @@ static char *usb_dump_config (
 
        if (start > end)
                return start;
-       if (!config)            /* getting these some in 2.3.7; none in 2.3.6 */
+       if (!config)
+               /* getting these some in 2.3.7; none in 2.3.6 */
                return start + sprintf(start, "(null Cfg. desc.)\n");
        start = usb_dump_config_descriptor(start, end, &config->desc, active);
        for (i = 0; i < USB_MAXIADS; i++) {
@@ -364,7 +356,8 @@ static char *usb_dump_config (
 /*
  * Dump the different USB descriptors.
  */
-static char *usb_dump_device_descriptor(char *start, char *end, const struct usb_device_descriptor *desc)
+static char *usb_dump_device_descriptor(char *start, char *end,
+                               const struct usb_device_descriptor *desc)
 {
        u16 bcdUSB = le16_to_cpu(desc->bcdUSB);
        u16 bcdDevice = le16_to_cpu(desc->bcdDevice);
@@ -374,7 +367,7 @@ static char *usb_dump_device_descriptor(char *start, char *end, const struct usb
        start += sprintf(start, format_device1,
                          bcdUSB >> 8, bcdUSB & 0xff,
                          desc->bDeviceClass,
-                         class_decode (desc->bDeviceClass),
+                         class_decode(desc->bDeviceClass),
                          desc->bDeviceSubClass,
                          desc->bDeviceProtocol,
                          desc->bMaxPacketSize0,
@@ -391,12 +384,14 @@ static char *usb_dump_device_descriptor(char *start, char *end, const struct usb
 /*
  * Dump the different strings that this device holds.
  */
-static char *usb_dump_device_strings(char *start, char *end, struct usb_device *dev)
+static char *usb_dump_device_strings(char *start, char *end,
+                                    struct usb_device *dev)
 {
        if (start > end)
                return start;
        if (dev->manufacturer)
-               start += sprintf(start, format_string_manufacturer, dev->manufacturer);
+               start += sprintf(start, format_string_manufacturer,
+                                dev->manufacturer);
        if (start > end)
                goto out;
        if (dev->product)
@@ -405,7 +400,8 @@ static char *usb_dump_device_strings(char *start, char *end, struct usb_device *
                goto out;
 #ifdef ALLOW_SERIAL_NUMBER
        if (dev->serial)
-               start += sprintf(start, format_string_serialnumber, dev->serial);
+               start += sprintf(start, format_string_serialnumber,
+                                dev->serial);
 #endif
  out:
        return start;
@@ -417,12 +413,12 @@ static char *usb_dump_desc(char *start, char *end, struct usb_device *dev)
 
        if (start > end)
                return start;
-               
+
        start = usb_dump_device_descriptor(start, end, &dev->descriptor);
 
        if (start > end)
                return start;
-       
+
        start = usb_dump_device_strings(start, end, dev);
 
        for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
@@ -439,7 +435,8 @@ static char *usb_dump_desc(char *start, char *end, struct usb_device *dev)
 
 #ifdef PROC_EXTRA /* TBD: may want to add this code later */
 
-static char *usb_dump_hub_descriptor(char *start, char *end, const struct usb_hub_descriptor * desc)
+static char *usb_dump_hub_descriptor(char *start, char *end,
+                                    const struct usb_hub_descriptor *desc)
 {
        int leng = USB_DT_HUB_NONVAR_SIZE;
        unsigned char *ptr = (unsigned char *)desc;
@@ -455,13 +452,16 @@ static char *usb_dump_hub_descriptor(char *start, char *end, const struct usb_hu
        return start;
 }
 
-static char *usb_dump_string(char *start, char *end, const struct usb_device *dev, char *id, int index)
+static char *usb_dump_string(char *start, char *end,
+                            const struct usb_device *dev, char *id, int index)
 {
        if (start > end)
                return start;
        start += sprintf(start, "Interface:");
-       if (index <= dev->maxstring && dev->stringindex && dev->stringindex[index])
-               start += sprintf(start, "%s: %.100s ", id, dev->stringindex[index]);
+       if (index <= dev->maxstring && dev->stringindex &&
+           dev->stringindex[index])
+               start += sprintf(start, "%s: %.100s ", id,
+                                dev->stringindex[index]);
        return start;
 }
 
@@ -476,8 +476,10 @@ static char *usb_dump_string(char *start, char *end, const struct usb_device *de
  * file_offset - the offset into the devices file on completion
  * The caller must own the device lock.
  */
-static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *skip_bytes, loff_t *file_offset,
-                               struct usb_device *usbdev, struct usb_bus *bus, int level, int index, int count)
+static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
+                              loff_t *skip_bytes, loff_t *file_offset,
+                              struct usb_device *usbdev, struct usb_bus *bus,
+                              int level, int index, int count)
 {
        int chix;
        int ret, cnt = 0;
@@ -485,17 +487,19 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
        char *pages_start, *data_end, *speed;
        unsigned int length;
        ssize_t total_written = 0;
-       
+
        /* don't bother with anything else if we're not writing any data */
        if (*nbytes <= 0)
                return 0;
-       
+
        if (level > MAX_TOPO_LEVEL)
                return 0;
-       /* allocate 2^1 pages = 8K (on i386); should be more than enough for one device */
-        if (!(pages_start = (char*) __get_free_pages(GFP_KERNEL,1)))
-                return -ENOMEM;
-               
+       /* allocate 2^1 pages = 8K (on i386);
+        * should be more than enough for one device */
+       pages_start = (char *)__get_free_pages(GFP_KERNEL, 1);
+       if (!pages_start)
+               return -ENOMEM;
+
        if (usbdev->parent && usbdev->parent->devnum != -1)
                parent_devnum = usbdev->parent->devnum;
        /*
@@ -541,15 +545,16 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
                                bus->bandwidth_allocated, max,
                                (100 * bus->bandwidth_allocated + max / 2)
                                        / max,
-                                bus->bandwidth_int_reqs,
-                                bus->bandwidth_isoc_reqs);
-       
+                               bus->bandwidth_int_reqs,
+                               bus->bandwidth_isoc_reqs);
+
        }
-       data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256, usbdev);
-       
+       data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256,
+                                usbdev);
+
        if (data_end > (pages_start + (2 * PAGE_SIZE) - 256))
                data_end += sprintf(data_end, "(truncated)\n");
-       
+
        length = data_end - pages_start;
        /* if we can start copying some data to the user */
        if (length > *skip_bytes) {
@@ -567,17 +572,18 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
                *skip_bytes = 0;
        } else
                *skip_bytes -= length;
-       
+
        free_pages((unsigned long)pages_start, 1);
-       
+
        /* Now look at all of this device's children. */
        for (chix = 0; chix < usbdev->maxchild; chix++) {
                struct usb_device *childdev = usbdev->children[chix];
 
                if (childdev) {
                        usb_lock_device(childdev);
-                       ret = usb_device_dump(buffer, nbytes, skip_bytes, file_offset, childdev,
-                                       bus, level + 1, chix, ++cnt);
+                       ret = usb_device_dump(buffer, nbytes, skip_bytes,
+                                             file_offset, childdev, bus,
+                                             level + 1, chix, ++cnt);
                        usb_unlock_device(childdev);
                        if (ret == -EFAULT)
                                return total_written;
@@ -587,7 +593,8 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
        return total_written;
 }
 
-static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
+static ssize_t usb_device_read(struct file *file, char __user *buf,
+                              size_t nbytes, loff_t *ppos)
 {
        struct usb_bus *bus;
        ssize_t ret, total_written = 0;
@@ -607,7 +614,8 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
                if (!bus->root_hub)
                        continue;
                usb_lock_device(bus->root_hub);
-               ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0);
+               ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos,
+                                     bus->root_hub, bus, 0, 0, 0);
                usb_unlock_device(bus->root_hub);
                if (ret < 0) {
                        mutex_unlock(&usb_bus_list_lock);
@@ -620,7 +628,8 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
 }
 
 /* Kernel lock for "lastev" protection */
-static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait)
+static unsigned int usb_device_poll(struct file *file,
+                                   struct poll_table_struct *wait)
 {
        struct usb_device_status *st = file->private_data;
        unsigned int mask = 0;
@@ -629,7 +638,8 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
        if (!st) {
                st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);
 
-               /* we may have dropped BKL - need to check for having lost the race */
+               /* we may have dropped BKL -
+                * need to check for having lost the race */
                if (file->private_data) {
                        kfree(st);
                        st = file->private_data;
@@ -652,7 +662,7 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
        }
 lost_race:
        if (file->f_mode & FMODE_READ)
-                poll_wait(file, &deviceconndiscwq, wait);
+               poll_wait(file, &deviceconndiscwq, wait);
        if (st->lastev != conndiscevcnt)
                mask |= POLLIN;
        st->lastev = conndiscevcnt;
@@ -662,18 +672,18 @@ lost_race:
 
 static int usb_device_open(struct inode *inode, struct file *file)
 {
-        file->private_data = NULL;
-        return 0;
+       file->private_data = NULL;
+       return 0;
 }
 
 static int usb_device_release(struct inode *inode, struct file *file)
 {
        kfree(file->private_data);
        file->private_data = NULL;
-        return 0;
+       return 0;
 }
 
-static loff_t usb_device_lseek(struct file * file, loff_t offset, int orig)
+static loff_t usb_device_lseek(struct file *file, loff_t offset, int orig)
 {
        loff_t ret;
 
index 1f4f6d02fe25598e22a62b785b1b7140913b7c12..ae94176c64e41245efa23335d6a4787741ef9e7f 100644 (file)
@@ -75,14 +75,14 @@ struct async {
        u32 secid;
 };
 
-static int usbfs_snoop = 0;
-module_param (usbfs_snoop, bool, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic");
+static int usbfs_snoop;
+module_param(usbfs_snoop, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic");
 
 #define snoop(dev, format, arg...)                             \
        do {                                                    \
                if (usbfs_snoop)                                \
-                       dev_info( dev , format , ## arg);       \
+                       dev_info(dev , format , ## arg);        \
        } while (0)
 
 #define USB_DEVICE_DEV         MKDEV(USB_DEVICE_MAJOR, 0)
@@ -90,7 +90,7 @@ MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic");
 
 #define        MAX_USBFS_BUFFER_SIZE   16384
 
-static inline int connected (struct dev_state *ps)
+static inline int connected(struct dev_state *ps)
 {
        return (!list_empty(&ps->list) &&
                        ps->dev->state != USB_STATE_NOTATTACHED);
@@ -120,7 +120,8 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig)
        return ret;
 }
 
-static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
+static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
+                          loff_t *ppos)
 {
        struct dev_state *ps = file->private_data;
        struct usb_device *dev = ps->dev;
@@ -140,7 +141,8 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
        }
 
        if (pos < sizeof(struct usb_device_descriptor)) {
-               struct usb_device_descriptor temp_desc ; /* 18 bytes - fits on the stack */
+               /* 18 bytes - fits on the stack */
+               struct usb_device_descriptor temp_desc;
 
                memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor));
                le16_to_cpus(&temp_desc.bcdUSB);
@@ -210,17 +212,17 @@ err:
 
 static struct async *alloc_async(unsigned int numisoframes)
 {
-        unsigned int assize = sizeof(struct async) + numisoframes * sizeof(struct usb_iso_packet_descriptor);
-        struct async *as = kzalloc(assize, GFP_KERNEL);
+       struct async *as;
 
-        if (!as)
-                return NULL;
+       as = kzalloc(sizeof(struct async), GFP_KERNEL);
+       if (!as)
+               return NULL;
        as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL);
        if (!as->urb) {
                kfree(as);
                return NULL;
        }
-        return as;
+       return as;
 }
 
 static void free_async(struct async *as)
@@ -234,52 +236,54 @@ static void free_async(struct async *as)
 
 static inline void async_newpending(struct async *as)
 {
-        struct dev_state *ps = as->ps;
-        unsigned long flags;
-        
-        spin_lock_irqsave(&ps->lock, flags);
-        list_add_tail(&as->asynclist, &ps->async_pending);
-        spin_unlock_irqrestore(&ps->lock, flags);
+       struct dev_state *ps = as->ps;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ps->lock, flags);
+       list_add_tail(&as->asynclist, &ps->async_pending);
+       spin_unlock_irqrestore(&ps->lock, flags);
 }
 
 static inline void async_removepending(struct async *as)
 {
-        struct dev_state *ps = as->ps;
-        unsigned long flags;
-        
-        spin_lock_irqsave(&ps->lock, flags);
-        list_del_init(&as->asynclist);
-        spin_unlock_irqrestore(&ps->lock, flags);
+       struct dev_state *ps = as->ps;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ps->lock, flags);
+       list_del_init(&as->asynclist);
+       spin_unlock_irqrestore(&ps->lock, flags);
 }
 
 static inline struct async *async_getcompleted(struct dev_state *ps)
 {
-        unsigned long flags;
-        struct async *as = NULL;
-
-        spin_lock_irqsave(&ps->lock, flags);
-        if (!list_empty(&ps->async_completed)) {
-                as = list_entry(ps->async_completed.next, struct async, asynclist);
-                list_del_init(&as->asynclist);
-        }
-        spin_unlock_irqrestore(&ps->lock, flags);
-        return as;
+       unsigned long flags;
+       struct async *as = NULL;
+
+       spin_lock_irqsave(&ps->lock, flags);
+       if (!list_empty(&ps->async_completed)) {
+               as = list_entry(ps->async_completed.next, struct async,
+                               asynclist);
+               list_del_init(&as->asynclist);
+       }
+       spin_unlock_irqrestore(&ps->lock, flags);
+       return as;
 }
 
-static inline struct async *async_getpending(struct dev_state *ps, void __user *userurb)
+static inline struct async *async_getpending(struct dev_state *ps,
+                                            void __user *userurb)
 {
-        unsigned long flags;
-        struct async *as;
+       unsigned long flags;
+       struct async *as;
 
-        spin_lock_irqsave(&ps->lock, flags);
+       spin_lock_irqsave(&ps->lock, flags);
        list_for_each_entry(as, &ps->async_pending, asynclist)
                if (as->userurb == userurb) {
                        list_del_init(&as->asynclist);
                        spin_unlock_irqrestore(&ps->lock, flags);
                        return as;
                }
-        spin_unlock_irqrestore(&ps->lock, flags);
-        return NULL;
+       spin_unlock_irqrestore(&ps->lock, flags);
+       return NULL;
 }
 
 static void snoop_urb(struct urb *urb, void __user *userurb)
@@ -298,19 +302,19 @@ static void snoop_urb(struct urb *urb, void __user *userurb)
        dev_info(&urb->dev->dev, "actual_length=%d\n", urb->actual_length);
        dev_info(&urb->dev->dev, "data: ");
        for (j = 0; j < urb->transfer_buffer_length; ++j)
-               printk ("%02x ", data[j]);
+               printk("%02x ", data[j]);
        printk("\n");
 }
 
 static void async_completed(struct urb *urb)
 {
-        struct async *as = urb->context;
-        struct dev_state *ps = as->ps;
+       struct async *as = urb->context;
+       struct dev_state *ps = as->ps;
        struct siginfo sinfo;
 
-        spin_lock(&ps->lock);
-        list_move_tail(&as->asynclist, &ps->async_completed);
-        spin_unlock(&ps->lock);
+       spin_lock(&ps->lock);
+       list_move_tail(&as->asynclist, &ps->async_completed);
+       spin_unlock(&ps->lock);
        as->status = urb->status;
        if (as->signr) {
                sinfo.si_signo = as->signr;
@@ -325,7 +329,7 @@ static void async_completed(struct urb *urb)
        wake_up(&ps->wait);
 }
 
-static void destroy_async (struct dev_state *ps, struct list_head *list)
+static void destroy_async(struct dev_state *ps, struct list_head *list)
 {
        struct async *as;
        unsigned long flags;
@@ -348,7 +352,8 @@ static void destroy_async (struct dev_state *ps, struct list_head *list)
        }
 }
 
-static void destroy_async_on_interface (struct dev_state *ps, unsigned int ifnum)
+static void destroy_async_on_interface(struct dev_state *ps,
+                                      unsigned int ifnum)
 {
        struct list_head *p, *q, hitlist;
        unsigned long flags;
@@ -364,7 +369,7 @@ static void destroy_async_on_interface (struct dev_state *ps, unsigned int ifnum
 
 static inline void destroy_all_async(struct dev_state *ps)
 {
-               destroy_async(ps, &ps->async_pending);
+       destroy_async(ps, &ps->async_pending);
 }
 
 /*
@@ -373,15 +378,15 @@ static inline void destroy_all_async(struct dev_state *ps)
  * they're also undone when devices disconnect.
  */
 
-static int driver_probe (struct usb_interface *intf,
-                        const struct usb_device_id *id)
+static int driver_probe(struct usb_interface *intf,
+                       const struct usb_device_id *id)
 {
        return -ENODEV;
 }
 
 static void driver_disconnect(struct usb_interface *intf)
 {
-       struct dev_state *ps = usb_get_intfdata (intf);
+       struct dev_state *ps = usb_get_intfdata(intf);
        unsigned int ifnum = intf->altsetting->desc.bInterfaceNumber;
 
        if (!ps)
@@ -396,16 +401,31 @@ static void driver_disconnect(struct usb_interface *intf)
        else
                warn("interface number %u out of range", ifnum);
 
-       usb_set_intfdata (intf, NULL);
+       usb_set_intfdata(intf, NULL);
 
        /* force async requests to complete */
        destroy_async_on_interface(ps, ifnum);
 }
 
+/* The following routines are merely placeholders.  There is no way
+ * to inform a user task about suspend or resumes.
+ */
+static int driver_suspend(struct usb_interface *intf, pm_message_t msg)
+{
+       return 0;
+}
+
+static int driver_resume(struct usb_interface *intf)
+{
+       return 0;
+}
+
 struct usb_driver usbfs_driver = {
        .name =         "usbfs",
        .probe =        driver_probe,
        .disconnect =   driver_disconnect,
+       .suspend =      driver_suspend,
+       .resume =       driver_resume,
 };
 
 static int claimintf(struct dev_state *ps, unsigned int ifnum)
@@ -459,15 +479,16 @@ static int checkintf(struct dev_state *ps, unsigned int ifnum)
        if (test_bit(ifnum, &ps->ifclaimed))
                return 0;
        /* if not yet claimed, claim it for the driver */
-       dev_warn(&ps->dev->dev, "usbfs: process %d (%s) did not claim interface %u before use\n",
-              task_pid_nr(current), current->comm, ifnum);
+       dev_warn(&ps->dev->dev, "usbfs: process %d (%s) did not claim "
+                "interface %u before use\n", task_pid_nr(current),
+                current->comm, ifnum);
        return claimintf(ps, ifnum);
 }
 
 static int findintfep(struct usb_device *dev, unsigned int ep)
 {
        unsigned int i, j, e;
-        struct usb_interface *intf;
+       struct usb_interface *intf;
        struct usb_host_interface *alts;
        struct usb_endpoint_descriptor *endpt;
 
@@ -478,7 +499,7 @@ static int findintfep(struct usb_device *dev, unsigned int ep)
        for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
                intf = dev->actconfig->interface[i];
                for (j = 0; j < intf->num_altsetting; j++) {
-                        alts = &intf->altsetting[j];
+                       alts = &intf->altsetting[j];
                        for (e = 0; e < alts->desc.bNumEndpoints; e++) {
                                endpt = &alts->endpoint[e].desc;
                                if (endpt->bEndpointAddress == ep)
@@ -486,10 +507,11 @@ static int findintfep(struct usb_device *dev, unsigned int ep)
                        }
                }
        }
-       return -ENOENT; 
+       return -ENOENT;
 }
 
-static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsigned int index)
+static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
+                          unsigned int index)
 {
        int ret = 0;
 
@@ -502,7 +524,8 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig
        index &= 0xff;
        switch (requesttype & USB_RECIP_MASK) {
        case USB_RECIP_ENDPOINT:
-               if ((ret = findintfep(ps->dev, index)) >= 0)
+               ret = findintfep(ps->dev, index);
+               if (ret >= 0)
                        ret = checkintf(ps, ret);
                break;
 
@@ -546,7 +569,8 @@ static int usbdev_open(struct inode *inode, struct file *file)
        mutex_lock(&usbfs_mutex);
 
        ret = -ENOMEM;
-       if (!(ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL)))
+       ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL);
+       if (!ps)
                goto out;
 
        ret = -ENOENT;
@@ -627,15 +651,18 @@ static int proc_control(struct dev_state *ps, void __user *arg)
 
        if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
                return -EFAULT;
-       if ((ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex)))
+       ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex);
+       if (ret)
                return ret;
        if (ctrl.wLength > PAGE_SIZE)
                return -EINVAL;
-       if (!(tbuf = (unsigned char *)__get_free_page(GFP_KERNEL)))
+       tbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
+       if (!tbuf)
                return -ENOMEM;
        tmo = ctrl.timeout;
        if (ctrl.bRequestType & 0x80) {
-               if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, ctrl.wLength)) {
+               if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data,
+                                              ctrl.wLength)) {
                        free_page((unsigned long)tbuf);
                        return -EINVAL;
                }
@@ -646,14 +673,15 @@ static int proc_control(struct dev_state *ps, void __user *arg)
                                ctrl.wIndex, ctrl.wLength);
 
                usb_unlock_device(dev);
-               i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType,
-                                      ctrl.wValue, ctrl.wIndex, tbuf, ctrl.wLength, tmo);
+               i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest,
+                                   ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
+                                   tbuf, ctrl.wLength, tmo);
                usb_lock_device(dev);
                if ((i > 0) && ctrl.wLength) {
                        if (usbfs_snoop) {
                                dev_info(&dev->dev, "control read: data ");
                                for (j = 0; j < i; ++j)
-                                       printk("%02x ", (unsigned char)(tbuf)[j]);
+                                       printk("%02x ", (u8)(tbuf)[j]);
                                printk("\n");
                        }
                        if (copy_to_user(ctrl.data, tbuf, i)) {
@@ -680,12 +708,13 @@ static int proc_control(struct dev_state *ps, void __user *arg)
                        printk("\n");
                }
                usb_unlock_device(dev);
-               i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType,
-                                      ctrl.wValue, ctrl.wIndex, tbuf, ctrl.wLength, tmo);
+               i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest,
+                                   ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
+                                   tbuf, ctrl.wLength, tmo);
                usb_lock_device(dev);
        }
        free_page((unsigned long)tbuf);
-       if (i<0 && i != -EPIPE) {
+       if (i < 0 && i != -EPIPE) {
                dev_printk(KERN_DEBUG, &dev->dev, "usbfs: USBDEVFS_CONTROL "
                           "failed cmd %s rqt %u rq %u len %u ret %d\n",
                           current->comm, ctrl.bRequestType, ctrl.bRequest,
@@ -705,9 +734,11 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
 
        if (copy_from_user(&bulk, arg, sizeof(bulk)))
                return -EFAULT;
-       if ((ret = findintfep(ps->dev, bulk.ep)) < 0)
+       ret = findintfep(ps->dev, bulk.ep);
+       if (ret < 0)
                return ret;
-       if ((ret = checkintf(ps, ret)))
+       ret = checkintf(ps, ret);
+       if (ret)
                return ret;
        if (bulk.ep & USB_DIR_IN)
                pipe = usb_rcvbulkpipe(dev, bulk.ep & 0x7f);
@@ -735,7 +766,7 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
                        if (usbfs_snoop) {
                                dev_info(&dev->dev, "bulk read: data ");
                                for (j = 0; j < len2; ++j)
-                                       printk("%02x ", (unsigned char)(tbuf)[j]);
+                                       printk("%02x ", (u8)(tbuf)[j]);
                                printk("\n");
                        }
                        if (copy_to_user(bulk.data, tbuf, len2)) {
@@ -775,9 +806,11 @@ static int proc_resetep(struct dev_state *ps, void __user *arg)
 
        if (get_user(ep, (unsigned int __user *)arg))
                return -EFAULT;
-       if ((ret = findintfep(ps->dev, ep)) < 0)
+       ret = findintfep(ps->dev, ep);
+       if (ret < 0)
                return ret;
-       if ((ret = checkintf(ps, ret)))
+       ret = checkintf(ps, ret);
+       if (ret)
                return ret;
        usb_settoggle(ps->dev, ep & 0xf, !(ep & USB_DIR_IN), 0);
        return 0;
@@ -791,18 +824,19 @@ static int proc_clearhalt(struct dev_state *ps, void __user *arg)
 
        if (get_user(ep, (unsigned int __user *)arg))
                return -EFAULT;
-       if ((ret = findintfep(ps->dev, ep)) < 0)
+       ret = findintfep(ps->dev, ep);
+       if (ret < 0)
                return ret;
-       if ((ret = checkintf(ps, ret)))
+       ret = checkintf(ps, ret);
+       if (ret)
                return ret;
        if (ep & USB_DIR_IN)
-                pipe = usb_rcvbulkpipe(ps->dev, ep & 0x7f);
-        else
-                pipe = usb_sndbulkpipe(ps->dev, ep & 0x7f);
+               pipe = usb_rcvbulkpipe(ps->dev, ep & 0x7f);
+       else
+               pipe = usb_sndbulkpipe(ps->dev, ep & 0x7f);
 
        return usb_clear_halt(ps->dev, pipe);
 }
-               
 
 static int proc_getdriver(struct dev_state *ps, void __user *arg)
 {
@@ -856,23 +890,23 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
 {
        int u;
        int status = 0;
-       struct usb_host_config *actconfig;
+       struct usb_host_config *actconfig;
 
        if (get_user(u, (int __user *)arg))
                return -EFAULT;
 
-       actconfig = ps->dev->actconfig;
-       /* Don't touch the device if any interfaces are claimed.
-        * It could interfere with other drivers' operations, and if
+       actconfig = ps->dev->actconfig;
+
+       /* Don't touch the device if any interfaces are claimed.
+        * It could interfere with other drivers' operations, and if
         * an interface is claimed by usbfs it could easily deadlock.
         */
-       if (actconfig) {
-               int i;
-               for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) {
-                       if (usb_interface_claimed(actconfig->interface[i])) {
-                               dev_warn (&ps->dev->dev,
+       if (actconfig) {
+               int i;
+
+               for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) {
+                       if (usb_interface_claimed(actconfig->interface[i])) {
+                               dev_warn(&ps->dev->dev,
                                        "usbfs: interface %d claimed by %s "
                                        "while '%s' sets config #%d\n",
                                        actconfig->interface[i]
@@ -881,11 +915,11 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
                                        actconfig->interface[i]
                                                ->dev.driver->name,
                                        current->comm, u);
-                               status = -EBUSY;
+                               status = -EBUSY;
                                break;
                        }
-               }
-       }
+               }
+       }
 
        /* SET_CONFIGURATION is often abused as a "cheap" driver reset,
         * so avoid usb_set_configuration()'s kick to sysfs
@@ -901,8 +935,8 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
 }
 
 static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
-                            struct usbdevfs_iso_packet_desc __user *iso_frame_desc,
-                            void __user *arg)
+                       struct usbdevfs_iso_packet_desc __user *iso_frame_desc,
+                       void __user *arg)
 {
        struct usbdevfs_iso_packet_desc *isopkt = NULL;
        struct usb_host_endpoint *ep;
@@ -917,12 +951,16 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
                return -EINVAL;
        if (!uurb->buffer)
                return -EINVAL;
-       if (uurb->signr != 0 && (uurb->signr < SIGRTMIN || uurb->signr > SIGRTMAX))
+       if (uurb->signr != 0 && (uurb->signr < SIGRTMIN ||
+                                uurb->signr > SIGRTMAX))
                return -EINVAL;
-       if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) {
-               if ((ifnum = findintfep(ps->dev, uurb->endpoint)) < 0)
+       if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL &&
+           (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) {
+               ifnum = findintfep(ps->dev, uurb->endpoint);
+               if (ifnum < 0)
                        return ifnum;
-               if ((ret = checkintf(ps, ifnum)))
+               ret = checkintf(ps, ifnum);
+               if (ret)
                        return ret;
        }
        if ((uurb->endpoint & USB_ENDPOINT_DIR_MASK) != 0) {
@@ -938,10 +976,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
        case USBDEVFS_URB_TYPE_CONTROL:
                if (!usb_endpoint_xfer_control(&ep->desc))
                        return -EINVAL;
-               /* min 8 byte setup packet, max 8 byte setup plus an arbitrary data stage */
-               if (uurb->buffer_length < 8 || uurb->buffer_length > (8 + MAX_USBFS_BUFFER_SIZE))
+               /* min 8 byte setup packet,
+                * max 8 byte setup plus an arbitrary data stage */
+               if (uurb->buffer_length < 8 ||
+                   uurb->buffer_length > (8 + MAX_USBFS_BUFFER_SIZE))
                        return -EINVAL;
-               if (!(dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL)))
+               dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
+               if (!dr)
                        return -ENOMEM;
                if (copy_from_user(dr, uurb->buffer, 8)) {
                        kfree(dr);
@@ -951,7 +992,9 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
                        kfree(dr);
                        return -EINVAL;
                }
-               if ((ret = check_ctrlrecip(ps, dr->bRequestType, le16_to_cpup(&dr->wIndex)))) {
+               ret = check_ctrlrecip(ps, dr->bRequestType,
+                                     le16_to_cpup(&dr->wIndex));
+               if (ret) {
                        kfree(dr);
                        return ret;
                }
@@ -997,11 +1040,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
 
        case USBDEVFS_URB_TYPE_ISO:
                /* arbitrary limit */
-               if (uurb->number_of_packets < 1 || uurb->number_of_packets > 128)
+               if (uurb->number_of_packets < 1 ||
+                   uurb->number_of_packets > 128)
                        return -EINVAL;
                if (!usb_endpoint_xfer_isoc(&ep->desc))
                        return -EINVAL;
-               isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) * uurb->number_of_packets;
+               isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) *
+                                  uurb->number_of_packets;
                if (!(isopkt = kmalloc(isofrmlen, GFP_KERNEL)))
                        return -ENOMEM;
                if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) {
@@ -1009,7 +1054,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
                        return -EFAULT;
                }
                for (totlen = u = 0; u < uurb->number_of_packets; u++) {
-                       /* arbitrary limit, sufficient for USB 2.0 high-bandwidth iso */
+                       /* arbitrary limit,
+                        * sufficient for USB 2.0 high-bandwidth iso */
                        if (isopkt[u].length > 8192) {
                                kfree(isopkt);
                                return -EINVAL;
@@ -1039,25 +1085,27 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
        default:
                return -EINVAL;
        }
-       if (!(as = alloc_async(uurb->number_of_packets))) {
+       as = alloc_async(uurb->number_of_packets);
+       if (!as) {
                kfree(isopkt);
                kfree(dr);
                return -ENOMEM;
        }
-       if (!(as->urb->transfer_buffer = kmalloc(uurb->buffer_length, GFP_KERNEL))) {
+       as->urb->transfer_buffer = kmalloc(uurb->buffer_length, GFP_KERNEL);
+       if (!as->urb->transfer_buffer) {
                kfree(isopkt);
                kfree(dr);
                free_async(as);
                return -ENOMEM;
        }
-        as->urb->dev = ps->dev;
-        as->urb->pipe = (uurb->type << 30) |
+       as->urb->dev = ps->dev;
+       as->urb->pipe = (uurb->type << 30) |
                        __create_pipe(ps->dev, uurb->endpoint & 0xf) |
                        (uurb->endpoint & USB_DIR_IN);
-        as->urb->transfer_flags = uurb->flags |
+       as->urb->transfer_flags = uurb->flags |
                        (is_in ? URB_DIR_IN : URB_DIR_OUT);
        as->urb->transfer_buffer_length = uurb->buffer_length;
-       as->urb->setup_packet = (unsigned char*)dr;
+       as->urb->setup_packet = (unsigned char *)dr;
        as->urb->start_frame = uurb->start_frame;
        as->urb->number_of_packets = uurb->number_of_packets;
        if (uurb->type == USBDEVFS_URB_TYPE_ISO ||
@@ -1065,8 +1113,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
                as->urb->interval = 1 << min(15, ep->desc.bInterval - 1);
        else
                as->urb->interval = ep->desc.bInterval;
-        as->urb->context = as;
-        as->urb->complete = async_completed;
+       as->urb->context = as;
+       as->urb->complete = async_completed;
        for (totlen = u = 0; u < uurb->number_of_packets; u++) {
                as->urb->iso_frame_desc[u].offset = totlen;
                as->urb->iso_frame_desc[u].length = isopkt[u].length;
@@ -1074,7 +1122,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
        }
        kfree(isopkt);
        as->ps = ps;
-        as->userurb = arg;
+       as->userurb = arg;
        if (uurb->endpoint & USB_DIR_IN)
                as->userbuffer = uurb->buffer;
        else
@@ -1093,14 +1141,15 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
                }
        }
        snoop_urb(as->urb, as->userurb);
-        async_newpending(as);
-        if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) {
-               dev_printk(KERN_DEBUG, &ps->dev->dev, "usbfs: usb_submit_urb returned %d\n", ret);
-                async_removepending(as);
-                free_async(as);
-                return ret;
-        }
-        return 0;
+       async_newpending(as);
+       if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) {
+               dev_printk(KERN_DEBUG, &ps->dev->dev,
+                          "usbfs: usb_submit_urb returned %d\n", ret);
+               async_removepending(as);
+               free_async(as);
+               return ret;
+       }
+       return 0;
 }
 
 static int proc_submiturb(struct dev_state *ps, void __user *arg)
@@ -1110,7 +1159,9 @@ static int proc_submiturb(struct dev_state *ps, void __user *arg)
        if (copy_from_user(&uurb, arg, sizeof(uurb)))
                return -EFAULT;
 
-       return proc_do_submiturb(ps, &uurb, (((struct usbdevfs_urb __user *)arg)->iso_frame_desc), arg);
+       return proc_do_submiturb(ps, &uurb,
+                       (((struct usbdevfs_urb __user *)arg)->iso_frame_desc),
+                       arg);
 }
 
 static int proc_unlinkurb(struct dev_state *ps, void __user *arg)
@@ -1132,7 +1183,8 @@ static int processcompl(struct async *as, void __user * __user *arg)
        unsigned int i;
 
        if (as->userbuffer)
-               if (copy_to_user(as->userbuffer, urb->transfer_buffer, urb->transfer_buffer_length))
+               if (copy_to_user(as->userbuffer, urb->transfer_buffer,
+                                urb->transfer_buffer_length))
                        return -EFAULT;
        if (put_user(as->status, &userurb->status))
                return -EFAULT;
@@ -1159,16 +1211,17 @@ static int processcompl(struct async *as, void __user * __user *arg)
        return 0;
 }
 
-static struct asyncreap_as(struct dev_state *ps)
+static struct async *reap_as(struct dev_state *ps)
 {
-        DECLARE_WAITQUEUE(wait, current);
+       DECLARE_WAITQUEUE(wait, current);
        struct async *as = NULL;
        struct usb_device *dev = ps->dev;
 
        add_wait_queue(&ps->wait, &wait);
        for (;;) {
                __set_current_state(TASK_INTERRUPTIBLE);
-               if ((as = async_getcompleted(ps)))
+               as = async_getcompleted(ps);
+               if (as)
                        break;
                if (signal_pending(current))
                        break;
@@ -1232,10 +1285,12 @@ static int proc_submiturb_compat(struct dev_state *ps, void __user *arg)
 {
        struct usbdevfs_urb uurb;
 
-       if (get_urb32(&uurb,(struct usbdevfs_urb32 __user *)arg))
+       if (get_urb32(&uurb, (struct usbdevfs_urb32 __user *)arg))
                return -EFAULT;
 
-       return proc_do_submiturb(ps, &uurb, ((struct usbdevfs_urb32 __user *)arg)->iso_frame_desc, arg);
+       return proc_do_submiturb(ps, &uurb,
+                       ((struct usbdevfs_urb32 __user *)arg)->iso_frame_desc,
+                       arg);
 }
 
 static int processcompl_compat(struct async *as, void __user * __user *arg)
@@ -1246,7 +1301,8 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
        unsigned int i;
 
        if (as->userbuffer)
-               if (copy_to_user(as->userbuffer, urb->transfer_buffer, urb->transfer_buffer_length))
+               if (copy_to_user(as->userbuffer, urb->transfer_buffer,
+                                urb->transfer_buffer_length))
                        return -EFAULT;
        if (put_user(as->status, &userurb->status))
                return -EFAULT;
@@ -1337,16 +1393,16 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
        struct usb_driver       *driver = NULL;
 
        /* alloc buffer */
-       if ((size = _IOC_SIZE (ctl->ioctl_code)) > 0) {
-               if ((buf = kmalloc (size, GFP_KERNEL)) == NULL)
+       if ((size = _IOC_SIZE(ctl->ioctl_code)) > 0) {
+               if ((buf = kmalloc(size, GFP_KERNEL)) == NULL)
                        return -ENOMEM;
                if ((_IOC_DIR(ctl->ioctl_code) & _IOC_WRITE)) {
-                       if (copy_from_user (buf, ctl->data, size)) {
+                       if (copy_from_user(buf, ctl->data, size)) {
                                kfree(buf);
                                return -EFAULT;
                        }
                } else {
-                       memset (buf, 0, size);
+                       memset(buf, 0, size);
                }
        }
 
@@ -1357,15 +1413,15 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
 
        if (ps->dev->state != USB_STATE_CONFIGURED)
                retval = -EHOSTUNREACH;
-       else if (!(intf = usb_ifnum_to_if (ps->dev, ctl->ifno)))
-               retval = -EINVAL;
+       else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno)))
+               retval = -EINVAL;
        else switch (ctl->ioctl_code) {
 
        /* disconnect kernel driver from interface */
        case USBDEVFS_DISCONNECT:
                if (intf->dev.driver) {
                        driver = to_usb_driver(intf->dev.driver);
-                       dev_dbg (&intf->dev, "disconnect by usbfs\n");
+                       dev_dbg(&intf->dev, "disconnect by usbfs\n");
                        usb_driver_release_interface(driver, intf);
                } else
                        retval = -ENODATA;
@@ -1373,9 +1429,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
 
        /* let kernel drivers try to (re)bind to the interface */
        case USBDEVFS_CONNECT:
-               usb_unlock_device(ps->dev);
-               retval = bus_rescan_devices(intf->dev.bus);
-               usb_lock_device(ps->dev);
+               if (!intf->dev.driver)
+                       retval = device_attach(&intf->dev);
+               else
+                       retval = -EBUSY;
                break;
 
        /* talk directly to the interface's driver */
@@ -1385,7 +1442,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
                if (driver == NULL || driver->ioctl == NULL) {
                        retval = -ENOTTY;
                } else {
-                       retval = driver->ioctl (intf, ctl->ioctl_code, buf);
+                       retval = driver->ioctl(intf, ctl->ioctl_code, buf);
                        if (retval == -ENOIOCTLCMD)
                                retval = -ENOTTY;
                }
@@ -1393,9 +1450,9 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
 
        /* cleanup and return */
        if (retval >= 0
-                       && (_IOC_DIR (ctl->ioctl_code) & _IOC_READ) != 0
+                       && (_IOC_DIR(ctl->ioctl_code) & _IOC_READ) != 0
                        && size > 0
-                       && copy_to_user (ctl->data, buf, size) != 0)
+                       && copy_to_user(ctl->data, buf, size) != 0)
                retval = -EFAULT;
 
        kfree(buf);
@@ -1406,7 +1463,7 @@ static int proc_ioctl_default(struct dev_state *ps, void __user *arg)
 {
        struct usbdevfs_ioctl   ctrl;
 
-       if (copy_from_user(&ctrl, arg, sizeof (ctrl)))
+       if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
                return -EFAULT;
        return proc_ioctl(ps, &ctrl);
 }
@@ -1434,7 +1491,8 @@ static int proc_ioctl_compat(struct dev_state *ps, compat_uptr_t arg)
  * are assuming that somehow the configuration has been prevented from
  * changing.  But there's no mechanism to ensure that...
  */
-static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+static int usbdev_ioctl(struct inode *inode, struct file *file,
+                       unsigned int cmd, unsigned long arg)
 {
        struct dev_state *ps = file->private_data;
        struct usb_device *dev = ps->dev;
@@ -1577,7 +1635,8 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
 }
 
 /* No kernel lock - fine */
-static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wait)
+static unsigned int usbdev_poll(struct file *file,
+                               struct poll_table_struct *wait)
 {
        struct dev_state *ps = file->private_data;
        unsigned int mask = 0;
@@ -1648,7 +1707,7 @@ int __init usb_devio_init(void)
        int retval;
 
        retval = register_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX,
-                       "usb_device");
+                                       "usb_device");
        if (retval) {
                err("unable to register minors for usb_device");
                goto out;
index 7c3aaa9c5402bf55a0738e0b310943fa81dde777..801b6f142fa7f874650a99c4d28c268c887a3114 100644 (file)
@@ -202,10 +202,10 @@ static int usb_probe_interface(struct device *dev)
        intf = to_usb_interface(dev);
        udev = interface_to_usbdev(intf);
 
-       if (udev->authorized == 0) {
-               dev_err(&intf->dev, "Device is not authorized for usage\n");
-               return -ENODEV;
-       }
+       if (udev->authorized == 0) {
+               dev_err(&intf->dev, "Device is not authorized for usage\n");
+               return -ENODEV;
+       }
 
        id = usb_match_id(intf, driver->id_table);
        if (!id)
@@ -299,7 +299,7 @@ static int usb_unbind_interface(struct device *dev)
  * lock.
  */
 int usb_driver_claim_interface(struct usb_driver *driver,
-                               struct usb_interface *iface, voidpriv)
+                               struct usb_interface *iface, void *priv)
 {
        struct device *dev = &iface->dev;
        struct usb_device *udev = interface_to_usbdev(iface);
@@ -325,7 +325,7 @@ int usb_driver_claim_interface(struct usb_driver *driver,
 
        return retval;
 }
-EXPORT_SYMBOL(usb_driver_claim_interface);
+EXPORT_SYMBOL_GPL(usb_driver_claim_interface);
 
 /**
  * usb_driver_release_interface - unbind a driver from an interface
@@ -370,7 +370,7 @@ void usb_driver_release_interface(struct usb_driver *driver,
        iface->needs_remote_wakeup = 0;
        usb_pm_unlock(udev);
 }
-EXPORT_SYMBOL(usb_driver_release_interface);
+EXPORT_SYMBOL_GPL(usb_driver_release_interface);
 
 /* returns 0 if no match, 1 if match */
 int usb_match_device(struct usb_device *dev, const struct usb_device_id *id)
@@ -398,7 +398,7 @@ int usb_match_device(struct usb_device *dev, const struct usb_device_id *id)
                return 0;
 
        if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
-           (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass))
+           (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
                return 0;
 
        if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
@@ -534,15 +534,15 @@ const struct usb_device_id *usb_match_id(struct usb_interface *interface,
           id->driver_info is the way to create an entry that
           indicates that the driver want to examine every
           device and interface. */
-       for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass ||
-              id->driver_info; id++) {
+       for (; id->idVendor || id->idProduct || id->bDeviceClass ||
+              id->bInterfaceClass || id->driver_info; id++) {
                if (usb_match_one_id(interface, id))
                        return id;
        }
 
        return NULL;
 }
-EXPORT_SYMBOL_GPL_FUTURE(usb_match_id);
+EXPORT_SYMBOL_GPL(usb_match_id);
 
 static int usb_device_match(struct device *dev, struct device_driver *drv)
 {
@@ -586,7 +586,7 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
        struct usb_device *usb_dev;
 
        /* driver is often null here; dev_dbg() would oops */
-       pr_debug ("usb %s: uevent\n", dev->bus_id);
+       pr_debug("usb %s: uevent\n", dev->bus_id);
 
        if (is_usb_device(dev))
                usb_dev = to_usb_device(dev);
@@ -596,11 +596,11 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
 
        if (usb_dev->devnum < 0) {
-               pr_debug ("usb %s: already deleted?\n", dev->bus_id);
+               pr_debug("usb %s: already deleted?\n", dev->bus_id);
                return -ENODEV;
        }
        if (!usb_dev->bus) {
-               pr_debug ("usb %s: bus removed?\n", dev->bus_id);
+               pr_debug("usb %s: bus removed?\n", dev->bus_id);
                return -ENODEV;
        }
 
@@ -745,7 +745,7 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner,
 
        return retval;
 }
-EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver);
+EXPORT_SYMBOL_GPL(usb_register_driver);
 
 /**
  * usb_deregister - unregister a USB interface driver
@@ -769,7 +769,7 @@ void usb_deregister(struct usb_driver *driver)
 
        usbfs_update_special();
 }
-EXPORT_SYMBOL_GPL_FUTURE(usb_deregister);
+EXPORT_SYMBOL_GPL(usb_deregister);
 
 #ifdef CONFIG_PM
 
@@ -854,8 +854,10 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg)
                        dev_err(&intf->dev, "%s error %d\n",
                                        "suspend", status);
        } else {
-               // FIXME else if there's no suspend method, disconnect...
-               // Not possible if auto_pm is set...
+               /*
+                * FIXME else if there's no suspend method, disconnect...
+                * Not possible if auto_pm is set...
+                */
                dev_warn(&intf->dev, "no suspend for driver %s?\n",
                                driver->name);
                mark_quiesced(intf);
@@ -894,7 +896,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
                                dev_err(&intf->dev, "%s error %d\n",
                                                "reset_resume", status);
                } else {
-                       // status = -EOPNOTSUPP;
+                       /* status = -EOPNOTSUPP; */
                        dev_warn(&intf->dev, "no %s for driver %s?\n",
                                        "reset_resume", driver->name);
                }
@@ -905,7 +907,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
                                dev_err(&intf->dev, "%s error %d\n",
                                                "resume", status);
                } else {
-                       // status = -EOPNOTSUPP;
+                       /* status = -EOPNOTSUPP; */
                        dev_warn(&intf->dev, "no %s for driver %s?\n",
                                        "resume", driver->name);
                }
@@ -1175,7 +1177,7 @@ static int usb_resume_both(struct usb_device *udev)
                         * so if a root hub's controller is suspended
                         * then we're stuck. */
                        status = usb_resume_device(udev);
-               }
+               }
        } else {
 
                /* Needed for setting udev->dev.power.power_state.event,
index 5d860bc9b42143f6729a9df40521ec42943b21b1..8133c99c6c5caf7cb1f384c71360f15e6c4fbf54 100644 (file)
@@ -204,7 +204,7 @@ int usb_register_dev(struct usb_interface *intf,
 exit:
        return retval;
 }
-EXPORT_SYMBOL(usb_register_dev);
+EXPORT_SYMBOL_GPL(usb_register_dev);
 
 /**
  * usb_deregister_dev - deregister a USB device's dynamic minor.
@@ -245,4 +245,4 @@ void usb_deregister_dev(struct usb_interface *intf,
        intf->minor = -1;
        destroy_usb_class();
 }
-EXPORT_SYMBOL(usb_deregister_dev);
+EXPORT_SYMBOL_GPL(usb_deregister_dev);
index 3fb9af80cbf4319e133f1434453a38ae538944d2..84760ddbc3325cba6cfdc8b219c3d70f32e0a5ab 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * (C) Copyright David Brownell 2000-2002
- * 
+ *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation; either version 2 of the License, or (at your
@@ -55,7 +55,7 @@
  *
  * Store this function in the HCD's struct pci_driver as probe().
  */
-int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
+int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
        struct hc_driver        *driver;
        struct usb_hcd          *hcd;
@@ -64,66 +64,71 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
        if (usb_disabled())
                return -ENODEV;
 
-       if (!id || !(driver = (struct hc_driver *) id->driver_data))
+       if (!id)
+               return -EINVAL;
+       driver = (struct hc_driver *)id->driver_data;
+       if (!driver)
                return -EINVAL;
 
-       if (pci_enable_device (dev) < 0)
+       if (pci_enable_device(dev) < 0)
                return -ENODEV;
        dev->current_state = PCI_D0;
        dev->dev.power.power_state = PMSG_ON;
-       
-        if (!dev->irq) {
-               dev_err (&dev->dev,
+
+       if (!dev->irq) {
+               dev_err(&dev->dev,
                        "Found HC with no IRQ.  Check BIOS/PCI %s setup!\n",
                        pci_name(dev));
-               retval = -ENODEV;
+               retval = -ENODEV;
                goto err1;
-        }
+       }
 
-       hcd = usb_create_hcd (driver, &dev->dev, pci_name(dev));
+       hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
        if (!hcd) {
                retval = -ENOMEM;
                goto err1;
        }
 
-       if (driver->flags & HCD_MEMORY) {       // EHCI, OHCI
-               hcd->rsrc_start = pci_resource_start (dev, 0);
-               hcd->rsrc_len = pci_resource_len (dev, 0);
-               if (!request_mem_region (hcd->rsrc_start, hcd->rsrc_len,
+       if (driver->flags & HCD_MEMORY) {
+               /* EHCI, OHCI */
+               hcd->rsrc_start = pci_resource_start(dev, 0);
+               hcd->rsrc_len = pci_resource_len(dev, 0);
+               if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
                                driver->description)) {
-                       dev_dbg (&dev->dev, "controller already in use\n");
+                       dev_dbg(&dev->dev, "controller already in use\n");
                        retval = -EBUSY;
                        goto err2;
                }
-               hcd->regs = ioremap_nocache (hcd->rsrc_start, hcd->rsrc_len);
+               hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
                if (hcd->regs == NULL) {
-                       dev_dbg (&dev->dev, "error mapping memory\n");
+                       dev_dbg(&dev->dev, "error mapping memory\n");
                        retval = -EFAULT;
                        goto err3;
                }
 
-       } else {                                // UHCI
+       } else {
+               /* UHCI */
                int     region;
 
                for (region = 0; region < PCI_ROM_RESOURCE; region++) {
-                       if (!(pci_resource_flags (dev, region) &
+                       if (!(pci_resource_flags(dev, region) &
                                        IORESOURCE_IO))
                                continue;
 
-                       hcd->rsrc_start = pci_resource_start (dev, region);
-                       hcd->rsrc_len = pci_resource_len (dev, region);
-                       if (request_region (hcd->rsrc_start, hcd->rsrc_len,
+                       hcd->rsrc_start = pci_resource_start(dev, region);
+                       hcd->rsrc_len = pci_resource_len(dev, region);
+                       if (request_region(hcd->rsrc_start, hcd->rsrc_len,
                                        driver->description))
                                break;
                }
                if (region == PCI_ROM_RESOURCE) {
-                       dev_dbg (&dev->dev, "no i/o regions available\n");
+                       dev_dbg(&dev->dev, "no i/o regions available\n");
                        retval = -EBUSY;
                        goto err1;
                }
        }
 
-       pci_set_master (dev);
+       pci_set_master(dev);
 
        retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
        if (retval != 0)
@@ -132,19 +137,19 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
 
  err4:
        if (driver->flags & HCD_MEMORY) {
-               iounmap (hcd->regs);
+               iounmap(hcd->regs);
  err3:
-               release_mem_region (hcd->rsrc_start, hcd->rsrc_len);
+               release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
        } else
-               release_region (hcd->rsrc_start, hcd->rsrc_len);
+               release_region(hcd->rsrc_start, hcd->rsrc_len);
  err2:
-       usb_put_hcd (hcd);
+       usb_put_hcd(hcd);
  err1:
-       pci_disable_device (dev);
-       dev_err (&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
+       pci_disable_device(dev);
+       dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
        return retval;
-} 
-EXPORT_SYMBOL (usb_hcd_pci_probe);
+}
+EXPORT_SYMBOL_GPL(usb_hcd_pci_probe);
 
 
 /* may be called without controller electrically present */
@@ -161,7 +166,7 @@ EXPORT_SYMBOL (usb_hcd_pci_probe);
  *
  * Store this function in the HCD's struct pci_driver as remove().
  */
-void usb_hcd_pci_remove (struct pci_dev *dev)
+void usb_hcd_pci_remove(struct pci_dev *dev)
 {
        struct usb_hcd          *hcd;
 
@@ -169,17 +174,17 @@ void usb_hcd_pci_remove (struct pci_dev *dev)
        if (!hcd)
                return;
 
-       usb_remove_hcd (hcd);
+       usb_remove_hcd(hcd);
        if (hcd->driver->flags & HCD_MEMORY) {
-               iounmap (hcd->regs);
-               release_mem_region (hcd->rsrc_start, hcd->rsrc_len);
+               iounmap(hcd->regs);
+               release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
        } else {
-               release_region (hcd->rsrc_start, hcd->rsrc_len);
+               release_region(hcd->rsrc_start, hcd->rsrc_len);
        }
-       usb_put_hcd (hcd);
+       usb_put_hcd(hcd);
        pci_disable_device(dev);
 }
-EXPORT_SYMBOL (usb_hcd_pci_remove);
+EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
 
 
 #ifdef CONFIG_PM
@@ -191,7 +196,7 @@ EXPORT_SYMBOL (usb_hcd_pci_remove);
  *
  * Store this function in the HCD's struct pci_driver as suspend().
  */
-int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
+int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message)
 {
        struct usb_hcd          *hcd;
        int                     retval = 0;
@@ -246,12 +251,18 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
 
                /* no DMA or IRQs except when HC is active */
                if (dev->current_state == PCI_D0) {
-                       pci_save_state (dev);
-                       pci_disable_device (dev);
+                       pci_save_state(dev);
+                       pci_disable_device(dev);
+               }
+
+               if (message.event == PM_EVENT_FREEZE ||
+                               message.event == PM_EVENT_PRETHAW) {
+                       dev_dbg(hcd->self.controller, "--> no state change\n");
+                       goto done;
                }
 
                if (!has_pci_pm) {
-                       dev_dbg (hcd->self.controller, "--> PCI D0/legacy\n");
+                       dev_dbg(hcd->self.controller, "--> PCI D0/legacy\n");
                        goto done;
                }
 
@@ -260,30 +271,30 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
                 * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset
                 * some device state (e.g. as part of clock reinit).
                 */
-               retval = pci_set_power_state (dev, PCI_D3hot);
+               retval = pci_set_power_state(dev, PCI_D3hot);
                suspend_report_result(pci_set_power_state, retval);
                if (retval == 0) {
                        int wake = device_can_wakeup(&hcd->self.root_hub->dev);
 
                        wake = wake && device_may_wakeup(hcd->self.controller);
 
-                       dev_dbg (hcd->self.controller, "--> PCI D3%s\n",
+                       dev_dbg(hcd->self.controller, "--> PCI D3%s\n",
                                        wake ? "/wakeup" : "");
 
                        /* Ignore these return values.  We rely on pci code to
                         * reject requests the hardware can't implement, rather
                         * than coding the same thing.
                         */
-                       (void) pci_enable_wake (dev, PCI_D3hot, wake);
-                       (void) pci_enable_wake (dev, PCI_D3cold, wake);
+                       (void) pci_enable_wake(dev, PCI_D3hot, wake);
+                       (void) pci_enable_wake(dev, PCI_D3cold, wake);
                } else {
-                       dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n",
+                       dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n",
                                        retval);
-                       (void) usb_hcd_pci_resume (dev);
+                       (void) usb_hcd_pci_resume(dev);
                }
 
        } else if (hcd->state != HC_STATE_HALT) {
-               dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n",
+               dev_dbg(hcd->self.controller, "hcd state %d; not suspended\n",
                        hcd->state);
                WARN_ON(1);
                retval = -EINVAL;
@@ -298,7 +309,7 @@ done:
                if (machine_is(powermac)) {
                        struct device_node      *of_node;
 
-                       of_node = pci_device_to_OF_node (dev);
+                       of_node = pci_device_to_OF_node(dev);
                        if (of_node)
                                pmac_call_feature(PMAC_FTR_USB_ENABLE,
                                                        of_node, 0, 0);
@@ -308,7 +319,7 @@ done:
 
        return retval;
 }
-EXPORT_SYMBOL (usb_hcd_pci_suspend);
+EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend);
 
 /**
  * usb_hcd_pci_resume - power management resume of a PCI-based HCD
@@ -316,14 +327,14 @@ EXPORT_SYMBOL (usb_hcd_pci_suspend);
  *
  * Store this function in the HCD's struct pci_driver as resume().
  */
-int usb_hcd_pci_resume (struct pci_dev *dev)
+int usb_hcd_pci_resume(struct pci_dev *dev)
 {
        struct usb_hcd          *hcd;
        int                     retval;
 
        hcd = pci_get_drvdata(dev);
        if (hcd->state != HC_STATE_SUSPENDED) {
-               dev_dbg (hcd->self.controller, 
+               dev_dbg(hcd->self.controller,
                                "can't resume, not suspended!\n");
                return 0;
        }
@@ -333,9 +344,9 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
        if (machine_is(powermac)) {
                struct device_node *of_node;
 
-               of_node = pci_device_to_OF_node (dev);
+               of_node = pci_device_to_OF_node(dev);
                if (of_node)
-                       pmac_call_feature (PMAC_FTR_USB_ENABLE,
+                       pmac_call_feature(PMAC_FTR_USB_ENABLE,
                                                of_node, 0, 1);
        }
 #endif
@@ -374,8 +385,8 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
                }
 #endif
                /* yes, ignore these results too... */
-               (void) pci_enable_wake (dev, dev->current_state, 0);
-               (void) pci_enable_wake (dev, PCI_D3cold, 0);
+               (void) pci_enable_wake(dev, dev->current_state, 0);
+               (void) pci_enable_wake(dev, PCI_D3cold, 0);
        } else {
                /* Same basic cases: clean (powered/not), dirty */
                dev_dbg(hcd->self.controller, "PCI legacy resume\n");
@@ -386,14 +397,14 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
         * but that won't re-enable bus mastering.  Yet pci_disable_device()
         * explicitly disables bus mastering...
         */
-       retval = pci_enable_device (dev);
+       retval = pci_enable_device(dev);
        if (retval < 0) {
-               dev_err (hcd->self.controller,
+               dev_err(hcd->self.controller,
                        "can't re-enable after resume, %d!\n", retval);
                return retval;
        }
-       pci_set_master (dev);
-       pci_restore_state (dev);
+       pci_set_master(dev);
+       pci_restore_state(dev);
 
        dev->dev.power.power_state = PMSG_ON;
 
@@ -402,15 +413,15 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
        if (hcd->driver->resume) {
                retval = hcd->driver->resume(hcd);
                if (retval) {
-                       dev_err (hcd->self.controller,
+                       dev_err(hcd->self.controller,
                                "PCI post-resume error %d!\n", retval);
-                       usb_hc_died (hcd);
+                       usb_hc_died(hcd);
                }
        }
 
        return retval;
 }
-EXPORT_SYMBOL (usb_hcd_pci_resume);
+EXPORT_SYMBOL_GPL(usb_hcd_pci_resume);
 
 #endif /* CONFIG_PM */
 
@@ -418,7 +429,7 @@ EXPORT_SYMBOL (usb_hcd_pci_resume);
  * usb_hcd_pci_shutdown - shutdown host controller
  * @dev: USB Host Controller being shutdown
  */
-void usb_hcd_pci_shutdown (struct pci_dev *dev)
+void usb_hcd_pci_shutdown(struct pci_dev *dev)
 {
        struct usb_hcd          *hcd;
 
@@ -429,5 +440,5 @@ void usb_hcd_pci_shutdown (struct pci_dev *dev)
        if (hcd->driver->shutdown)
                hcd->driver->shutdown(hcd);
 }
-EXPORT_SYMBOL (usb_hcd_pci_shutdown);
+EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown);
 
index d5ed3fa9e304b5d76b859b31203ab6bb866a3aa1..e52ed1663b3c566ae5d0aa53799faa46f2f00324 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/mutex.h>
 #include <asm/irq.h>
 #include <asm/byteorder.h>
+#include <asm/unaligned.h>
 #include <linux/platform_device.h>
 #include <linux/workqueue.h>
 
@@ -131,8 +132,8 @@ static const u8 usb2_rh_dev_descriptor [18] = {
        0x01,       /*  __u8  bDeviceProtocol; [ usb 2.0 single TT ]*/
        0x40,       /*  __u8  bMaxPacketSize0; 64 Bytes */
 
-       0x00, 0x00, /*  __le16 idVendor; */
-       0x00, 0x00, /*  __le16 idProduct; */
+       0x6b, 0x1d, /*  __le16 idVendor; Linux Foundation */
+       0x02, 0x00, /*  __le16 idProduct; device 0x0002 */
        KERNEL_VER, KERNEL_REL, /*  __le16 bcdDevice */
 
        0x03,       /*  __u8  iManufacturer; */
@@ -154,8 +155,8 @@ static const u8 usb11_rh_dev_descriptor [18] = {
        0x00,       /*  __u8  bDeviceProtocol; [ low/full speeds only ] */
        0x40,       /*  __u8  bMaxPacketSize0; 64 Bytes */
 
-       0x00, 0x00, /*  __le16 idVendor; */
-       0x00, 0x00, /*  __le16 idProduct; */
+       0x6b, 0x1d, /*  __le16 idVendor; Linux Foundation */
+       0x01, 0x00, /*  __le16 idProduct; device 0x0001 */
        KERNEL_VER, KERNEL_REL, /*  __le16 bcdDevice */
 
        0x03,       /*  __u8  iManufacturer; */
@@ -807,13 +808,13 @@ static int usb_register_bus(struct usb_bus *bus)
        }
        set_bit (busnum, busmap.busmap);
        bus->busnum = busnum;
-       bus->class_dev = class_device_create(usb_host_class, NULL, MKDEV(0,0),
-                                            bus->controller, "usb_host%d",
-                                            busnum);
-       result = PTR_ERR(bus->class_dev);
-       if (IS_ERR(bus->class_dev))
+
+       bus->dev = device_create(usb_host_class, bus->controller, MKDEV(0, 0),
+                                "usb_host%d", busnum);
+       result = PTR_ERR(bus->dev);
+       if (IS_ERR(bus->dev))
                goto error_create_class_dev;
-       class_set_devdata(bus->class_dev, bus);
+       dev_set_drvdata(bus->dev, bus);
 
        /* Add it to the local list of buses */
        list_add (&bus->bus_list, &usb_bus_list);
@@ -857,7 +858,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
 
        clear_bit (bus->busnum, busmap.busmap);
 
-       class_device_unregister(bus->class_dev);
+       device_unregister(bus->dev);
 }
 
 /**
@@ -970,7 +971,7 @@ long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
                return -1;
        }
 }
-EXPORT_SYMBOL (usb_calc_bus_time);
+EXPORT_SYMBOL_GPL(usb_calc_bus_time);
 
 
 /*-------------------------------------------------------------------------*/
@@ -1112,48 +1113,177 @@ void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb)
 }
 EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep);
 
-static void map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
+/*
+ * Some usb host controllers can only perform dma using a small SRAM area.
+ * The usb core itself is however optimized for host controllers that can dma
+ * using regular system memory - like pci devices doing bus mastering.
+ *
+ * To support host controllers with limited dma capabilites we provide dma
+ * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag.
+ * For this to work properly the host controller code must first use the
+ * function dma_declare_coherent_memory() to point out which memory area
+ * that should be used for dma allocations.
+ *
+ * The HCD_LOCAL_MEM flag then tells the usb code to allocate all data for
+ * dma using dma_alloc_coherent() which in turn allocates from the memory
+ * area pointed out with dma_declare_coherent_memory().
+ *
+ * So, to summarize...
+ *
+ * - We need "local" memory, canonical example being
+ *   a small SRAM on a discrete controller being the
+ *   only memory that the controller can read ...
+ *   (a) "normal" kernel memory is no good, and
+ *   (b) there's not enough to share
+ *
+ * - The only *portable* hook for such stuff in the
+ *   DMA framework is dma_declare_coherent_memory()
+ *
+ * - So we use that, even though the primary requirement
+ *   is that the memory be "local" (hence addressible
+ *   by that device), not "coherent".
+ *
+ */
+
+static int hcd_alloc_coherent(struct usb_bus *bus,
+                             gfp_t mem_flags, dma_addr_t *dma_handle,
+                             void **vaddr_handle, size_t size,
+                             enum dma_data_direction dir)
+{
+       unsigned char *vaddr;
+
+       vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr),
+                                mem_flags, dma_handle);
+       if (!vaddr)
+               return -ENOMEM;
+
+       /*
+        * Store the virtual address of the buffer at the end
+        * of the allocated dma buffer. The size of the buffer
+        * may be uneven so use unaligned functions instead
+        * of just rounding up. It makes sense to optimize for
+        * memory footprint over access speed since the amount
+        * of memory available for dma may be limited.
+        */
+       put_unaligned((unsigned long)*vaddr_handle,
+                     (unsigned long *)(vaddr + size));
+
+       if (dir == DMA_TO_DEVICE)
+               memcpy(vaddr, *vaddr_handle, size);
+
+       *vaddr_handle = vaddr;
+       return 0;
+}
+
+static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle,
+                             void **vaddr_handle, size_t size,
+                             enum dma_data_direction dir)
+{
+       unsigned char *vaddr = *vaddr_handle;
+
+       vaddr = (void *)get_unaligned((unsigned long *)(vaddr + size));
+
+       if (dir == DMA_FROM_DEVICE)
+               memcpy(vaddr, *vaddr_handle, size);
+
+       hcd_buffer_free(bus, size + sizeof(vaddr), *vaddr_handle, *dma_handle);
+
+       *vaddr_handle = vaddr;
+       *dma_handle = 0;
+}
+
+static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
+                          gfp_t mem_flags)
 {
+       enum dma_data_direction dir;
+       int ret = 0;
+
        /* Map the URB's buffers for DMA access.
         * Lower level HCD code should use *_dma exclusively,
         * unless it uses pio or talks to another transport.
         */
-       if (hcd->self.uses_dma && !is_root_hub(urb->dev)) {
-               if (usb_endpoint_xfer_control(&urb->ep->desc)
-                       && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
-                       urb->setup_dma = dma_map_single (
+       if (is_root_hub(urb->dev))
+               return 0;
+
+       if (usb_endpoint_xfer_control(&urb->ep->desc)
+           && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
+               if (hcd->self.uses_dma)
+                       urb->setup_dma = dma_map_single(
                                        hcd->self.controller,
                                        urb->setup_packet,
-                                       sizeof (struct usb_ctrlrequest),
+                                       sizeof(struct usb_ctrlrequest),
+                                       DMA_TO_DEVICE);
+               else if (hcd->driver->flags & HCD_LOCAL_MEM)
+                       ret = hcd_alloc_coherent(
+                                       urb->dev->bus, mem_flags,
+                                       &urb->setup_dma,
+                                       (void **)&urb->setup_packet,
+                                       sizeof(struct usb_ctrlrequest),
                                        DMA_TO_DEVICE);
-               if (urb->transfer_buffer_length != 0
-                       && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
+       }
+
+       dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+       if (ret == 0 && urb->transfer_buffer_length != 0
+           && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
+               if (hcd->self.uses_dma)
                        urb->transfer_dma = dma_map_single (
                                        hcd->self.controller,
                                        urb->transfer_buffer,
                                        urb->transfer_buffer_length,
-                                       usb_urb_dir_in(urb)
-                                           ? DMA_FROM_DEVICE
-                                           : DMA_TO_DEVICE);
+                                       dir);
+               else if (hcd->driver->flags & HCD_LOCAL_MEM) {
+                       ret = hcd_alloc_coherent(
+                                       urb->dev->bus, mem_flags,
+                                       &urb->transfer_dma,
+                                       &urb->transfer_buffer,
+                                       urb->transfer_buffer_length,
+                                       dir);
+
+                       if (ret && usb_endpoint_xfer_control(&urb->ep->desc)
+                           && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
+                               hcd_free_coherent(urb->dev->bus,
+                                       &urb->setup_dma,
+                                       (void **)&urb->setup_packet,
+                                       sizeof(struct usb_ctrlrequest),
+                                       DMA_TO_DEVICE);
+               }
        }
+       return ret;
 }
 
 static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
 {
-       if (hcd->self.uses_dma && !is_root_hub(urb->dev)) {
-               if (usb_endpoint_xfer_control(&urb->ep->desc)
-                       && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
+       enum dma_data_direction dir;
+
+       if (is_root_hub(urb->dev))
+               return;
+
+       if (usb_endpoint_xfer_control(&urb->ep->desc)
+           && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
+               if (hcd->self.uses_dma)
                        dma_unmap_single(hcd->self.controller, urb->setup_dma,
                                        sizeof(struct usb_ctrlrequest),
                                        DMA_TO_DEVICE);
-               if (urb->transfer_buffer_length != 0
-                       && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
+               else if (hcd->driver->flags & HCD_LOCAL_MEM)
+                       hcd_free_coherent(urb->dev->bus, &urb->setup_dma,
+                                       (void **)&urb->setup_packet,
+                                       sizeof(struct usb_ctrlrequest),
+                                       DMA_TO_DEVICE);
+       }
+
+       dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+       if (urb->transfer_buffer_length != 0
+           && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
+               if (hcd->self.uses_dma)
                        dma_unmap_single(hcd->self.controller,
                                        urb->transfer_dma,
                                        urb->transfer_buffer_length,
-                                       usb_urb_dir_in(urb)
-                                           ? DMA_FROM_DEVICE
-                                           : DMA_TO_DEVICE);
+                                       dir);
+               else if (hcd->driver->flags & HCD_LOCAL_MEM)
+                       hcd_free_coherent(urb->dev->bus, &urb->transfer_dma,
+                                       &urb->transfer_buffer,
+                                       urb->transfer_buffer_length,
+                                       dir);
        }
 }
 
@@ -1185,7 +1315,12 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
         * URBs must be submitted in process context with interrupts
         * enabled.
         */
-       map_urb_for_dma(hcd, urb);
+       status = map_urb_for_dma(hcd, urb, mem_flags);
+       if (unlikely(status)) {
+               usbmon_urb_submit_error(&hcd->self, urb, status);
+               goto error;
+       }
+
        if (is_root_hub(urb->dev))
                status = rh_urb_enqueue(hcd, urb);
        else
@@ -1194,6 +1329,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
        if (unlikely(status)) {
                usbmon_urb_submit_error(&hcd->self, urb, status);
                unmap_urb_for_dma(hcd, urb);
+ error:
                urb->hcpriv = NULL;
                INIT_LIST_HEAD(&urb->urb_list);
                atomic_dec(&urb->use_count);
@@ -1291,7 +1427,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
                wake_up (&usb_kill_urb_queue);
        usb_put_urb (urb);
 }
-EXPORT_SYMBOL (usb_hcd_giveback_urb);
+EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb);
 
 /*-------------------------------------------------------------------------*/
 
@@ -1531,7 +1667,7 @@ int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num)
                mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10));
        return status;
 }
-EXPORT_SYMBOL (usb_bus_start_enum);
+EXPORT_SYMBOL_GPL(usb_bus_start_enum);
 
 #endif
 
@@ -1638,7 +1774,7 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
                        "USB Host Controller";
        return hcd;
 }
-EXPORT_SYMBOL (usb_create_hcd);
+EXPORT_SYMBOL_GPL(usb_create_hcd);
 
 static void hcd_release (struct kref *kref)
 {
@@ -1653,14 +1789,14 @@ struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd)
                kref_get (&hcd->kref);
        return hcd;
 }
-EXPORT_SYMBOL (usb_get_hcd);
+EXPORT_SYMBOL_GPL(usb_get_hcd);
 
 void usb_put_hcd (struct usb_hcd *hcd)
 {
        if (hcd)
                kref_put (&hcd->kref, hcd_release);
 }
-EXPORT_SYMBOL (usb_put_hcd);
+EXPORT_SYMBOL_GPL(usb_put_hcd);
 
 /**
  * usb_add_hcd - finish generic HCD structure initialization and register
@@ -1786,7 +1922,7 @@ err_register_bus:
        hcd_buffer_destroy(hcd);
        return retval;
 } 
-EXPORT_SYMBOL (usb_add_hcd);
+EXPORT_SYMBOL_GPL(usb_add_hcd);
 
 /**
  * usb_remove_hcd - shutdown processing for generic HCDs
@@ -1828,7 +1964,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
        usb_deregister_bus(&hcd->self);
        hcd_buffer_destroy(hcd);
 }
-EXPORT_SYMBOL (usb_remove_hcd);
+EXPORT_SYMBOL_GPL(usb_remove_hcd);
 
 void
 usb_hcd_platform_shutdown(struct platform_device* dev)
@@ -1838,7 +1974,7 @@ usb_hcd_platform_shutdown(struct platform_device* dev)
        if (hcd->driver->shutdown)
                hcd->driver->shutdown(hcd);
 }
-EXPORT_SYMBOL (usb_hcd_platform_shutdown);
+EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
 
 /*-------------------------------------------------------------------------*/
 
index 98e24194a4ab61f3be641fd38d9eeb6283bca289..2d1c3d5e47b8b3e791bbbed28f857247da6ad2e9 100644 (file)
@@ -125,7 +125,7 @@ struct usb_hcd {
 
        /* more shared queuing code would be good; it should support
         * smarter scheduling, handle transaction translators, etc;
-        * input size of periodic table to an interrupt scheduler. 
+        * input size of periodic table to an interrupt scheduler.
         * (ohci 32, uhci 1024, ehci 256/512/1024).
         */
 
@@ -133,16 +133,16 @@ struct usb_hcd {
         * this structure.
         */
        unsigned long hcd_priv[0]
-                       __attribute__ ((aligned (sizeof(unsigned long))));
+                       __attribute__ ((aligned(sizeof(unsigned long))));
 };
 
 /* 2.4 does this a bit differently ... */
-static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd)
+static inline struct usb_bus *hcd_to_bus(struct usb_hcd *hcd)
 {
        return &hcd->self;
 }
 
-static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus)
+static inline struct usb_hcd *bus_to_hcd(struct usb_bus *bus)
 {
        return container_of(bus, struct usb_hcd, self);
 }
@@ -165,6 +165,7 @@ struct hc_driver {
 
        int     flags;
 #define        HCD_MEMORY      0x0001          /* HC regs use memory (else I/O) */
+#define        HCD_LOCAL_MEM   0x0002          /* HC needs local memory */
 #define        HCD_USB11       0x0010          /* USB 1.1 */
 #define        HCD_USB2        0x0020          /* USB 2.0 */
 
@@ -201,15 +202,18 @@ struct hc_driver {
                        struct usb_host_endpoint *ep);
 
        /* root hub support */
-       int             (*hub_status_data) (struct usb_hcd *hcd, char *buf);
-       int             (*hub_control) (struct usb_hcd *hcd,
+       int     (*hub_status_data) (struct usb_hcd *hcd, char *buf);
+       int     (*hub_control) (struct usb_hcd *hcd,
                                u16 typeReq, u16 wValue, u16 wIndex,
                                char *buf, u16 wLength);
-       int             (*bus_suspend)(struct usb_hcd *);
-       int             (*bus_resume)(struct usb_hcd *);
-       int             (*start_port_reset)(struct usb_hcd *, unsigned port_num);
-       void            (*hub_irq_enable)(struct usb_hcd *);
+       int     (*bus_suspend)(struct usb_hcd *);
+       int     (*bus_resume)(struct usb_hcd *);
+       int     (*start_port_reset)(struct usb_hcd *, unsigned port_num);
+       void    (*hub_irq_enable)(struct usb_hcd *);
                /* Needed only if port-change IRQs are level-triggered */
+
+               /* force handover of high-speed port to full-speed companion */
+       void    (*relinquish_port)(struct usb_hcd *, int);
 };
 
 extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
@@ -217,56 +221,56 @@ extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
                int status);
 extern void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb);
 
-extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags);
-extern int usb_hcd_unlink_urb (struct urb *urb, int status);
+extern int usb_hcd_submit_urb(struct urb *urb, gfp_t mem_flags);
+extern int usb_hcd_unlink_urb(struct urb *urb, int status);
 extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb,
                int status);
 extern void usb_hcd_flush_endpoint(struct usb_device *udev,
                struct usb_host_endpoint *ep);
 extern void usb_hcd_disable_endpoint(struct usb_device *udev,
                struct usb_host_endpoint *ep);
-extern int usb_hcd_get_frame_number (struct usb_device *udev);
+extern int usb_hcd_get_frame_number(struct usb_device *udev);
 
-extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
+extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
                struct device *dev, char *bus_name);
-extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd);
-extern void usb_put_hcd (struct usb_hcd *hcd);
+extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd);
+extern void usb_put_hcd(struct usb_hcd *hcd);
 extern int usb_add_hcd(struct usb_hcd *hcd,
                unsigned int irqnum, unsigned long irqflags);
 extern void usb_remove_hcd(struct usb_hcd *hcd);
 
 struct platform_device;
-extern void usb_hcd_platform_shutdown(struct platform_devicedev);
+extern void usb_hcd_platform_shutdown(struct platform_device *dev);
 
 #ifdef CONFIG_PCI
 struct pci_dev;
 struct pci_device_id;
-extern int usb_hcd_pci_probe (struct pci_dev *dev,
+extern int usb_hcd_pci_probe(struct pci_dev *dev,
                                const struct pci_device_id *id);
-extern void usb_hcd_pci_remove (struct pci_dev *dev);
+extern void usb_hcd_pci_remove(struct pci_dev *dev);
 
 #ifdef CONFIG_PM
-extern int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t state);
-extern int usb_hcd_pci_resume (struct pci_dev *dev);
+extern int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t state);
+extern int usb_hcd_pci_resume(struct pci_dev *dev);
 #endif /* CONFIG_PM */
 
-extern void usb_hcd_pci_shutdown (struct pci_dev *dev);
+extern void usb_hcd_pci_shutdown(struct pci_dev *dev);
 
 #endif /* CONFIG_PCI */
 
 /* pci-ish (pdev null is ok) buffer alloc/mapping support */
-int hcd_buffer_create (struct usb_hcd *hcd);
-void hcd_buffer_destroy (struct usb_hcd *hcd);
+int hcd_buffer_create(struct usb_hcd *hcd);
+void hcd_buffer_destroy(struct usb_hcd *hcd);
 
-void *hcd_buffer_alloc (struct usb_bus *bus, size_t size,
+void *hcd_buffer_alloc(struct usb_bus *bus, size_t size,
        gfp_t mem_flags, dma_addr_t *dma);
-void hcd_buffer_free (struct usb_bus *bus, size_t size,
+void hcd_buffer_free(struct usb_bus *bus, size_t size,
        void *addr, dma_addr_t dma);
 
 /* generic bus glue, needed for host controllers that don't use PCI */
-extern irqreturn_t usb_hcd_irq (int irq, void *__hcd);
+extern irqreturn_t usb_hcd_irq(int irq, void *__hcd);
 
-extern void usb_hc_died (struct usb_hcd *hcd);
+extern void usb_hc_died(struct usb_hcd *hcd);
 extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd);
 
 /* -------------------------------------------------------------------------- */
@@ -319,9 +323,9 @@ extern void usb_destroy_configuration(struct usb_device *dev);
  * Generic bandwidth allocation constants/support
  */
 #define FRAME_TIME_USECS       1000L
-#define BitTime(bytecount)  (7 * 8 * bytecount / 6)  /* with integer truncation */
+#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
                /* Trying not to use worst-case bit-stuffing
-                   of (7/6 * 8 * bytecount) = 9.33 * bytecount */
+                * of (7/6 * 8 * bytecount) = 9.33 * bytecount */
                /* bytecount = data payload byte count */
 
 #define NS_TO_US(ns)   ((ns + 500L) / 1000L)
@@ -333,9 +337,9 @@ extern void usb_destroy_configuration(struct usb_device *dev);
  */
 #define BW_HOST_DELAY  1000L           /* nanoseconds */
 #define BW_HUB_LS_SETUP        333L            /* nanoseconds */
-                        /* 4 full-speed bit times (est.) */
+                       /* 4 full-speed bit times (est.) */
 
-#define FRAME_TIME_BITS         12000L         /* frame = 1 millisecond */
+#define FRAME_TIME_BITS                        12000L  /* frame = 1 millisecond */
 #define FRAME_TIME_MAX_BITS_ALLOC      (90L * FRAME_TIME_BITS / 100L)
 #define FRAME_TIME_MAX_USECS_ALLOC     (90L * FRAME_TIME_USECS / 100L)
 
@@ -345,16 +349,16 @@ extern void usb_destroy_configuration(struct usb_device *dev);
  * to preallocate bandwidth)
  */
 #define USB2_HOST_DELAY        5       /* nsec, guess */
-#define HS_NSECS(bytes) ( ((55 * 8 * 2083) \
+#define HS_NSECS(bytes) (((55 * 8 * 2083) \
        + (2083UL * (3 + BitTime(bytes))))/1000 \
        + USB2_HOST_DELAY)
-#define HS_NSECS_ISO(bytes) ( ((38 * 8 * 2083) \
+#define HS_NSECS_ISO(bytes) (((38 * 8 * 2083) \
        + (2083UL * (3 + BitTime(bytes))))/1000 \
        + USB2_HOST_DELAY)
 #define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes))
 #define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes))
 
-extern long usb_calc_bus_time (int speed, int is_input,
+extern long usb_calc_bus_time(int speed, int is_input,
                        int isoc, int bytecount);
 
 /*-------------------------------------------------------------------------*/
@@ -370,16 +374,16 @@ extern struct list_head usb_bus_list;
 extern struct mutex usb_bus_list_lock;
 extern wait_queue_head_t usb_kill_urb_queue;
 
-extern void usb_enable_root_hub_irq (struct usb_bus *bus);
+extern void usb_enable_root_hub_irq(struct usb_bus *bus);
 
-extern int usb_find_interface_driver (struct usb_device *dev,
+extern int usb_find_interface_driver(struct usb_device *dev,
        struct usb_interface *interface);
 
 #define usb_endpoint_out(ep_dir)       (!((ep_dir) & USB_DIR_IN))
 
 #ifdef CONFIG_PM
-extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd);
-extern void usb_root_hub_lost_power (struct usb_device *rhdev);
+extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd);
+extern void usb_root_hub_lost_power(struct usb_device *rhdev);
 extern int hcd_bus_suspend(struct usb_device *rhdev);
 extern int hcd_bus_resume(struct usb_device *rhdev);
 #else
@@ -399,13 +403,13 @@ static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd)
  * these are expected to be called from the USB core/hub thread
  * with the kernel lock held
  */
-extern void usbfs_update_special (void);
+extern void usbfs_update_special(void);
 extern int usbfs_init(void);
 extern void usbfs_cleanup(void);
 
 #else /* CONFIG_USB_DEVICEFS */
 
-static inline void usbfs_update_special (void) {}
+static inline void usbfs_update_special(void) {}
 static inline int usbfs_init(void) { return 0; }
 static inline void usbfs_cleanup(void) { }
 
@@ -460,7 +464,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
 /*-------------------------------------------------------------------------*/
 
 /* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */
-// bleech -- resurfaced in 2.4.11 or 2.4.12
+/* bleech -- resurfaced in 2.4.11 or 2.4.12 */
 #define bitmap         DeviceRemovable
 
 
@@ -468,8 +472,8 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
 
 /* random stuff */
 
-#define        RUN_CONTEXT (in_irq () ? "in_irq" \
-               : (in_interrupt () ? "in_interrupt" : "can sleep"))
+#define        RUN_CONTEXT (in_irq() ? "in_irq" \
+               : (in_interrupt() ? "in_interrupt" : "can sleep"))
 
 
 /* This rwsem is for use only by the hub driver and ehci-hcd.
index b04d232d4c6561720f219ff506fcd2a35a9c0caf..68fc5219ca152ae45144cd541f85ff0f0008a8d4 100644 (file)
 #define        USB_PERSIST     0
 #endif
 
+/* if we are in debug mode, always announce new devices */
+#ifdef DEBUG
+#ifndef CONFIG_USB_ANNOUNCE_NEW_DEVICES
+#define CONFIG_USB_ANNOUNCE_NEW_DEVICES
+#endif
+#endif
+
 struct usb_hub {
        struct device           *intfdev;       /* the "interface" device */
        struct usb_device       *hdev;
@@ -487,6 +494,7 @@ void usb_hub_tt_clear_buffer (struct usb_device *udev, int pipe)
        schedule_work (&tt->kevent);
        spin_unlock_irqrestore (&tt->lock, flags);
 }
+EXPORT_SYMBOL_GPL(usb_hub_tt_clear_buffer);
 
 static void hub_power_on(struct usb_hub *hub)
 {
@@ -1027,8 +1035,10 @@ static void recursively_mark_NOTATTACHED(struct usb_device *udev)
                if (udev->children[i])
                        recursively_mark_NOTATTACHED(udev->children[i]);
        }
-       if (udev->state == USB_STATE_SUSPENDED)
+       if (udev->state == USB_STATE_SUSPENDED) {
                udev->discon_suspended = 1;
+               udev->active_duration -= jiffies;
+       }
        udev->state = USB_STATE_NOTATTACHED;
 }
 
@@ -1077,6 +1087,12 @@ void usb_set_device_state(struct usb_device *udev,
                        else
                                device_init_wakeup(&udev->dev, 0);
                }
+               if (udev->state == USB_STATE_SUSPENDED &&
+                       new_state != USB_STATE_SUSPENDED)
+                       udev->active_duration -= jiffies;
+               else if (new_state == USB_STATE_SUSPENDED &&
+                               udev->state != USB_STATE_SUSPENDED)
+                       udev->active_duration += jiffies;
                udev->state = new_state;
        } else
                recursively_mark_NOTATTACHED(udev);
@@ -1207,7 +1223,7 @@ void usb_disconnect(struct usb_device **pdev)
        put_device(&udev->dev);
 }
 
-#ifdef DEBUG
+#ifdef CONFIG_USB_ANNOUNCE_NEW_DEVICES
 static void show_string(struct usb_device *udev, char *id, char *string)
 {
        if (!string)
@@ -1215,12 +1231,24 @@ static void show_string(struct usb_device *udev, char *id, char *string)
        dev_printk(KERN_INFO, &udev->dev, "%s: %s\n", id, string);
 }
 
+static void announce_device(struct usb_device *udev)
+{
+       dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n",
+               le16_to_cpu(udev->descriptor.idVendor),
+               le16_to_cpu(udev->descriptor.idProduct));
+       dev_info(&udev->dev, "New USB device strings: Mfr=%d, Product=%d, "
+               "SerialNumber=%d\n",
+               udev->descriptor.iManufacturer,
+               udev->descriptor.iProduct,
+               udev->descriptor.iSerialNumber);
+       show_string(udev, "Product", udev->product);
+       show_string(udev, "Manufacturer", udev->manufacturer);
+       show_string(udev, "SerialNumber", udev->serial);
+}
 #else
-static inline void show_string(struct usb_device *udev, char *id, char *string)
-{}
+static inline void announce_device(struct usb_device *udev) { }
 #endif
 
-
 #ifdef CONFIG_USB_OTG
 #include "otg_whitelist.h"
 #endif
@@ -1390,14 +1418,7 @@ int usb_new_device(struct usb_device *udev)
        }
 
        /* Tell the world! */
-       dev_dbg(&udev->dev, "new device strings: Mfr=%d, Product=%d, "
-               "SerialNumber=%d\n",
-               udev->descriptor.iManufacturer,
-               udev->descriptor.iProduct,
-               udev->descriptor.iSerialNumber);
-       show_string(udev, "Product", udev->product);
-       show_string(udev, "Manufacturer", udev->manufacturer);
-       show_string(udev, "SerialNumber", udev->serial);
+       announce_device(udev);
        return err;
 
 fail:
@@ -2482,6 +2503,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
 {
        struct usb_device *hdev = hub->hdev;
        struct device *hub_dev = hub->intfdev;
+       struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
        u16 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
        int status, i;
  
@@ -2645,6 +2667,8 @@ loop:
  
 done:
        hub_port_disable(hub, port1, 1);
+       if (hcd->driver->relinquish_port && !hub->hdev->parent)
+               hcd->driver->relinquish_port(hcd, port1);
 }
 
 static void hub_events(void)
@@ -2946,7 +2970,7 @@ static int config_descriptors_changed(struct usb_device *udev)
                if (len < le16_to_cpu(udev->config[index].desc.wTotalLength))
                        len = le16_to_cpu(udev->config[index].desc.wTotalLength);
        }
-       buf = kmalloc (len, GFP_KERNEL);
+       buf = kmalloc(len, GFP_NOIO);
        if (buf == NULL) {
                dev_err(&udev->dev, "no mem to re-read configs after reset\n");
                /* assume the worst */
@@ -3093,7 +3117,7 @@ re_enumerate:
        hub_port_logical_disconnect(parent_hub, port1);
        return -ENODEV;
 }
-EXPORT_SYMBOL(usb_reset_device);
+EXPORT_SYMBOL_GPL(usb_reset_device);
 
 /**
  * usb_reset_composite_device - warn interface drivers and perform a USB port reset
@@ -3110,16 +3134,12 @@ EXPORT_SYMBOL(usb_reset_device);
  * this from a driver probe() routine after downloading new firmware.
  * For calls that might not occur during probe(), drivers should lock
  * the device using usb_lock_device_for_reset().
- *
- * The interface locks are acquired during the pre_reset stage and released
- * during the post_reset stage.  However if iface is not NULL and is
- * currently being probed, we assume that the caller already owns its
- * lock.
  */
 int usb_reset_composite_device(struct usb_device *udev,
                struct usb_interface *iface)
 {
        int ret;
+       int i;
        struct usb_host_config *config = udev->actconfig;
 
        if (udev->state == USB_STATE_NOTATTACHED ||
@@ -3136,16 +3156,11 @@ int usb_reset_composite_device(struct usb_device *udev,
                iface = NULL;
 
        if (config) {
-               int i;
-               struct usb_interface *cintf;
-               struct usb_driver *drv;
-
                for (i = 0; i < config->desc.bNumInterfaces; ++i) {
-                       cintf = config->interface[i];
-                       if (cintf != iface)
-                               down(&cintf->dev.sem);
-                       if (device_is_registered(&cintf->dev) &&
-                                       cintf->dev.driver) {
+                       struct usb_interface *cintf = config->interface[i];
+                       struct usb_driver *drv;
+
+                       if (cintf->dev.driver) {
                                drv = to_usb_driver(cintf->dev.driver);
                                if (drv->pre_reset)
                                        (drv->pre_reset)(cintf);
@@ -3157,25 +3172,20 @@ int usb_reset_composite_device(struct usb_device *udev,
        ret = usb_reset_device(udev);
 
        if (config) {
-               int i;
-               struct usb_interface *cintf;
-               struct usb_driver *drv;
-
                for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) {
-                       cintf = config->interface[i];
-                       if (device_is_registered(&cintf->dev) &&
-                                       cintf->dev.driver) {
+                       struct usb_interface *cintf = config->interface[i];
+                       struct usb_driver *drv;
+
+                       if (cintf->dev.driver) {
                                drv = to_usb_driver(cintf->dev.driver);
                                if (drv->post_reset)
                                        (drv->post_reset)(cintf);
        /* FIXME: Unbind if post_reset returns an error or isn't defined */
                        }
-                       if (cintf != iface)
-                               up(&cintf->dev.sem);
                }
        }
 
        usb_autosuspend_device(udev);
        return ret;
 }
-EXPORT_SYMBOL(usb_reset_composite_device);
+EXPORT_SYMBOL_GPL(usb_reset_composite_device);
index cf9559c6c9b64587829b894286754bb865b8546a..1551aed65e05c7dcc585e07883cd216dd8ed7718 100644 (file)
 #define USB_PORT_FEAT_TEST              21
 #define USB_PORT_FEAT_INDICATOR         22
 
-/* 
+/*
  * Hub Status and Hub Change results
  * See USB 2.0 spec Table 11-19 and Table 11-20
  */
 struct usb_port_status {
        __le16 wPortStatus;
-       __le16 wPortChange;     
+       __le16 wPortChange;
 } __attribute__ ((packed));
 
-/* 
+/*
  * wPortStatus bit field
  * See USB 2.0 spec Table 11-21
  */
@@ -81,7 +81,7 @@ struct usb_port_status {
 #define USB_PORT_STAT_INDICATOR         0x1000
 /* bits 13 to 15 are reserved */
 
-/* 
+/*
  * wPortChange bit field
  * See USB 2.0 spec Table 11-22
  * Bits 0 to 4 shown, bits 5 to 15 are reserved
@@ -93,7 +93,7 @@ struct usb_port_status {
 #define USB_PORT_STAT_C_RESET          0x0010
 
 /*
- * wHubCharacteristics (masks) 
+ * wHubCharacteristics (masks)
  * See USB 2.0 spec Table 11-13, offset 3
  */
 #define HUB_CHAR_LPSM          0x0003 /* D1 .. D0 */
@@ -119,8 +119,8 @@ struct usb_hub_status {
 #define HUB_CHANGE_OVERCURRENT 0x0002
 
 
-/* 
- * Hub descriptor 
+/*
+ * Hub descriptor
  * See USB 2.0 spec Table 11-13
  */
 
@@ -134,7 +134,7 @@ struct usb_hub_descriptor {
        __le16 wHubCharacteristics;
        __u8  bPwrOn2PwrGood;
        __u8  bHubContrCurrent;
-               /* add 1 bit for hub status change; round to bytes */
+               /* add 1 bit for hub status change; round to bytes */
        __u8  DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
        __u8  PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
 } __attribute__ ((packed));
@@ -190,6 +190,6 @@ struct usb_tt_clear {
        u16                     devinfo;
 };
 
-extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe);
+extern void usb_hub_tt_clear_buffer(struct usb_device *dev, int pipe);
 
 #endif /* __LINUX_HUB_H */
index cd4f11157280de78cd5e73e82f043bde7d247182..83a373e9cc3624c66f09bac2c5383221e0eef8d2 100644 (file)
 #include <linux/usbdevice_fs.h>
 #include <linux/parser.h>
 #include <linux/notifier.h>
+#include <linux/seq_file.h>
 #include <asm/byteorder.h>
 #include "usb.h"
 #include "hcd.h"
 
+#define USBFS_DEFAULT_DEVMODE (S_IWUSR | S_IRUGO)
+#define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO)
+#define USBFS_DEFAULT_LISTMODE S_IRUGO
+
 static struct super_operations usbfs_ops;
 static const struct file_operations default_file_operations;
 static struct vfsmount *usbfs_mount;
@@ -57,9 +62,33 @@ static uid_t listuid;        /* = 0 */
 static gid_t devgid;   /* = 0 */
 static gid_t busgid;   /* = 0 */
 static gid_t listgid;  /* = 0 */
-static umode_t devmode = S_IWUSR | S_IRUGO;
-static umode_t busmode = S_IXUGO | S_IRUGO;
-static umode_t listmode = S_IRUGO;
+static umode_t devmode = USBFS_DEFAULT_DEVMODE;
+static umode_t busmode = USBFS_DEFAULT_BUSMODE;
+static umode_t listmode = USBFS_DEFAULT_LISTMODE;
+
+static int usbfs_show_options(struct seq_file *seq, struct vfsmount *mnt)
+{
+       if (devuid != 0)
+               seq_printf(seq, ",devuid=%u", devuid);
+       if (devgid != 0)
+               seq_printf(seq, ",devgid=%u", devgid);
+       if (devmode != USBFS_DEFAULT_DEVMODE)
+               seq_printf(seq, ",devmode=%o", devmode);
+       if (busuid != 0)
+               seq_printf(seq, ",busuid=%u", busuid);
+       if (busgid != 0)
+               seq_printf(seq, ",busgid=%u", busgid);
+       if (busmode != USBFS_DEFAULT_BUSMODE)
+               seq_printf(seq, ",busmode=%o", busmode);
+       if (listuid != 0)
+               seq_printf(seq, ",listuid=%u", listuid);
+       if (listgid != 0)
+               seq_printf(seq, ",listgid=%u", listgid);
+       if (listmode != USBFS_DEFAULT_LISTMODE)
+               seq_printf(seq, ",listmode=%o", listmode);
+
+       return 0;
+}
 
 enum {
        Opt_devuid, Opt_devgid, Opt_devmode,
@@ -93,9 +122,9 @@ static int parse_options(struct super_block *s, char *data)
        devgid = 0;
        busgid = 0;
        listgid = 0;
-       devmode = S_IWUSR | S_IRUGO;
-       busmode = S_IXUGO | S_IRUGO;
-       listmode = S_IRUGO;
+       devmode = USBFS_DEFAULT_DEVMODE;
+       busmode = USBFS_DEFAULT_BUSMODE;
+       listmode = USBFS_DEFAULT_LISTMODE;
 
        while ((p = strsep(&data, ",")) != NULL) {
                substring_t args[MAX_OPT_ARGS];
@@ -418,6 +447,7 @@ static struct super_operations usbfs_ops = {
        .statfs =       simple_statfs,
        .drop_inode =   generic_delete_inode,
        .remount_fs =   remount,
+       .show_options = usbfs_show_options,
 };
 
 static int usbfs_fill_super(struct super_block *sb, void *data, int silent)
index fcd40ecbeecce3276a8a1ecb31a0f204c1bf54f5..fefb92296e8f5a921edf849a30caf808cf904793 100644 (file)
@@ -39,7 +39,7 @@ static void usb_api_blocking_completion(struct urb *urb)
  * own interruptible routines.
  */
 static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
-{ 
+{
        struct api_context ctx;
        unsigned long expire;
        int retval;
@@ -74,9 +74,9 @@ out:
 }
 
 /*-------------------------------------------------------------------*/
-// returns status (negative) or length (positive)
+/* returns status (negative) or length (positive) */
 static int usb_internal_control_msg(struct usb_device *usb_dev,
-                                   unsigned int pipe, 
+                                   unsigned int pipe,
                                    struct usb_ctrlrequest *cmd,
                                    void *data, int len, int timeout)
 {
@@ -87,7 +87,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
        urb = usb_alloc_urb(0, GFP_NOIO);
        if (!urb)
                return -ENOMEM;
-  
+
        usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data,
                             len, usb_api_blocking_completion, NULL);
 
@@ -99,47 +99,51 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
 }
 
 /**
- *     usb_control_msg - Builds a control urb, sends it off and waits for completion
- *     @dev: pointer to the usb device to send the message to
- *     @pipe: endpoint "pipe" to send the message to
- *     @request: USB message request value
- *     @requesttype: USB message request type value
- *     @value: USB message value
- *     @index: USB message index value
- *     @data: pointer to the data to send
- *     @size: length in bytes of the data to send
- *     @timeout: time in msecs to wait for the message to complete before
- *             timing out (if 0 the wait is forever)
- *     Context: !in_interrupt ()
- *
- *     This function sends a simple control message to a specified endpoint
- *     and waits for the message to complete, or timeout.
- *     
- *     If successful, it returns the number of bytes transferred, otherwise a negative error number.
- *
- *     Don't use this function from within an interrupt context, like a
- *     bottom half handler.  If you need an asynchronous message, or need to send
- *     a message from within interrupt context, use usb_submit_urb()
- *      If a thread in your driver uses this call, make sure your disconnect()
- *      method can wait for it to complete.  Since you don't have a handle on
- *      the URB used, you can't cancel the request.
+ * usb_control_msg - Builds a control urb, sends it off and waits for completion
+ * @dev: pointer to the usb device to send the message to
+ * @pipe: endpoint "pipe" to send the message to
+ * @request: USB message request value
+ * @requesttype: USB message request type value
+ * @value: USB message value
+ * @index: USB message index value
+ * @data: pointer to the data to send
+ * @size: length in bytes of the data to send
+ * @timeout: time in msecs to wait for the message to complete before timing
+ *     out (if 0 the wait is forever)
+ *
+ * Context: !in_interrupt ()
+ *
+ * This function sends a simple control message to a specified endpoint and
+ * waits for the message to complete, or timeout.
+ *
+ * If successful, it returns the number of bytes transferred, otherwise a
+ * negative error number.
+ *
+ * Don't use this function from within an interrupt context, like a bottom half
+ * handler.  If you need an asynchronous message, or need to send a message
+ * from within interrupt context, use usb_submit_urb().
+ * If a thread in your driver uses this call, make sure your disconnect()
+ * method can wait for it to complete.  Since you don't have a handle on the
+ * URB used, you can't cancel the request.
  */
-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype,
-                        __u16 value, __u16 index, void *data, __u16 size, int timeout)
+int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
+                   __u8 requesttype, __u16 value, __u16 index, void *data,
+                   __u16 size, int timeout)
 {
-       struct usb_ctrlrequest *dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
+       struct usb_ctrlrequest *dr;
        int ret;
-       
+
+       dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
        if (!dr)
                return -ENOMEM;
 
-       dr->bRequestType= requesttype;
+       dr->bRequestType = requesttype;
        dr->bRequest = request;
        dr->wValue = cpu_to_le16p(&value);
        dr->wIndex = cpu_to_le16p(&index);
        dr->wLength = cpu_to_le16p(&size);
 
-       //dbg("usb_control_msg");       
+       /* dbg("usb_control_msg"); */
 
        ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
 
@@ -147,7 +151,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u
 
        return ret;
 }
-
+EXPORT_SYMBOL_GPL(usb_control_msg);
 
 /**
  * usb_interrupt_msg - Builds an interrupt urb, sends it off and waits for completion
@@ -155,9 +159,11 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u
  * @pipe: endpoint "pipe" to send the message to
  * @data: pointer to the data to send
  * @len: length in bytes of the data to send
- * @actual_length: pointer to a location to put the actual length transferred in bytes
+ * @actual_length: pointer to a location to put the actual length transferred
+ *     in bytes
  * @timeout: time in msecs to wait for the message to complete before
  *     timing out (if 0 the wait is forever)
+ *
  * Context: !in_interrupt ()
  *
  * This function sends a simple interrupt message to a specified endpoint and
@@ -181,38 +187,38 @@ int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
 EXPORT_SYMBOL_GPL(usb_interrupt_msg);
 
 /**
- *     usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion
- *     @usb_dev: pointer to the usb device to send the message to
- *     @pipe: endpoint "pipe" to send the message to
- *     @data: pointer to the data to send
- *     @len: length in bytes of the data to send
- *     @actual_length: pointer to a location to put the actual length transferred in bytes
- *     @timeout: time in msecs to wait for the message to complete before
- *             timing out (if 0 the wait is forever)
- *     Context: !in_interrupt ()
- *
- *     This function sends a simple bulk message to a specified endpoint
- *     and waits for the message to complete, or timeout.
- *     
- *     If successful, it returns 0, otherwise a negative error number.
- *     The number of actual bytes transferred will be stored in the 
- *     actual_length paramater.
- *
- *     Don't use this function from within an interrupt context, like a
- *     bottom half handler.  If you need an asynchronous message, or need to
- *     send a message from within interrupt context, use usb_submit_urb()
- *      If a thread in your driver uses this call, make sure your disconnect()
- *      method can wait for it to complete.  Since you don't have a handle on
- *      the URB used, you can't cancel the request.
- *
- *     Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT
- *     ioctl, users are forced to abuse this routine by using it to submit
- *     URBs for interrupt endpoints.  We will take the liberty of creating
- *     an interrupt URB (with the default interval) if the target is an
- *     interrupt endpoint.
+ * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion
+ * @usb_dev: pointer to the usb device to send the message to
+ * @pipe: endpoint "pipe" to send the message to
+ * @data: pointer to the data to send
+ * @len: length in bytes of the data to send
+ * @actual_length: pointer to a location to put the actual length transferred
+ *     in bytes
+ * @timeout: time in msecs to wait for the message to complete before
+ *     timing out (if 0 the wait is forever)
+ *
+ * Context: !in_interrupt ()
+ *
+ * This function sends a simple bulk message to a specified endpoint
+ * and waits for the message to complete, or timeout.
+ *
+ * If successful, it returns 0, otherwise a negative error number.  The number
+ * of actual bytes transferred will be stored in the actual_length paramater.
+ *
+ * Don't use this function from within an interrupt context, like a bottom half
+ * handler.  If you need an asynchronous message, or need to send a message
+ * from within interrupt context, use usb_submit_urb() If a thread in your
+ * driver uses this call, make sure your disconnect() method can wait for it to
+ * complete.  Since you don't have a handle on the URB used, you can't cancel
+ * the request.
+ *
+ * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl,
+ * users are forced to abuse this routine by using it to submit URBs for
+ * interrupt endpoints.  We will take the liberty of creating an interrupt URB
+ * (with the default interval) if the target is an interrupt endpoint.
  */
-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, 
-                       void *data, int len, int *actual_length, int timeout)
+int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
+                void *data, int len, int *actual_length, int timeout)
 {
        struct urb *urb;
        struct usb_host_endpoint *ep;
@@ -238,29 +244,30 @@ int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
 
        return usb_start_wait_urb(urb, timeout, actual_length);
 }
+EXPORT_SYMBOL_GPL(usb_bulk_msg);
 
 /*-------------------------------------------------------------------*/
 
-static void sg_clean (struct usb_sg_request *io)
+static void sg_clean(struct usb_sg_request *io)
 {
        if (io->urbs) {
                while (io->entries--)
-                       usb_free_urb (io->urbs [io->entries]);
-               kfree (io->urbs);
+                       usb_free_urb(io->urbs [io->entries]);
+               kfree(io->urbs);
                io->urbs = NULL;
        }
        if (io->dev->dev.dma_mask != NULL)
-               usb_buffer_unmap_sg (io->dev, usb_pipein(io->pipe),
-                               io->sg, io->nents);
+               usb_buffer_unmap_sg(io->dev, usb_pipein(io->pipe),
+                                   io->sg, io->nents);
        io->dev = NULL;
 }
 
-static void sg_complete (struct urb *urb)
+static void sg_complete(struct urb *urb)
 {
-       struct usb_sg_request   *io = urb->context;
+       struct usb_sg_request *io = urb->context;
        int status = urb->status;
 
-       spin_lock (&io->lock);
+       spin_lock(&io->lock);
 
        /* In 2.5 we require hcds' endpoint queues not to progress after fault
         * reports, until the completion callback (this!) returns.  That lets
@@ -276,13 +283,13 @@ static void sg_complete (struct urb *urb)
                        && (io->status != -ECONNRESET
                                || status != -ECONNRESET)
                        && urb->actual_length) {
-               dev_err (io->dev->bus->controller,
+               dev_err(io->dev->bus->controller,
                        "dev %s ep%d%s scatterlist error %d/%d\n",
                        io->dev->devpath,
                        usb_endpoint_num(&urb->ep->desc),
                        usb_urb_dir_in(urb) ? "in" : "out",
                        status, io->status);
-               // BUG ();
+               /* BUG (); */
        }
 
        if (io->status == 0 && status && status != -ECONNRESET) {
@@ -294,22 +301,22 @@ static void sg_complete (struct urb *urb)
                 * unlink pending urbs so they won't rx/tx bad data.
                 * careful: unlink can sometimes be synchronous...
                 */
-               spin_unlock (&io->lock);
+               spin_unlock(&io->lock);
                for (i = 0, found = 0; i < io->entries; i++) {
                        if (!io->urbs [i] || !io->urbs [i]->dev)
                                continue;
                        if (found) {
-                               retval = usb_unlink_urb (io->urbs [i]);
+                               retval = usb_unlink_urb(io->urbs [i]);
                                if (retval != -EINPROGRESS &&
                                    retval != -ENODEV &&
                                    retval != -EBUSY)
-                                       dev_err (&io->dev->dev,
+                                       dev_err(&io->dev->dev,
                                                "%s, unlink --> %d\n",
                                                __FUNCTION__, retval);
                        } else if (urb == io->urbs [i])
                                found = 1;
                }
-               spin_lock (&io->lock);
+               spin_lock(&io->lock);
        }
        urb->dev = NULL;
 
@@ -317,9 +324,9 @@ static void sg_complete (struct urb *urb)
        io->bytes += urb->actual_length;
        io->count--;
        if (!io->count)
-               complete (&io->complete);
+               complete(&io->complete);
 
-       spin_unlock (&io->lock);
+       spin_unlock(&io->lock);
 }
 
 
@@ -348,28 +355,21 @@ static void sg_complete (struct urb *urb)
  * The request may be canceled with usb_sg_cancel(), either before or after
  * usb_sg_wait() is called.
  */
-int usb_sg_init (
-       struct usb_sg_request   *io,
-       struct usb_device       *dev,
-       unsigned                pipe, 
-       unsigned                period,
-       struct scatterlist      *sg,
-       int                     nents,
-       size_t                  length,
-       gfp_t                   mem_flags
-)
+int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
+               unsigned pipe, unsigned period, struct scatterlist *sg,
+               int nents, size_t length, gfp_t mem_flags)
 {
-       int                     i;
-       int                     urb_flags;
-       int                     dma;
+       int i;
+       int urb_flags;
+       int dma;
 
        if (!io || !dev || !sg
-                       || usb_pipecontrol (pipe)
-                       || usb_pipeisoc (pipe)
+                       || usb_pipecontrol(pipe)
+                       || usb_pipeisoc(pipe)
                        || nents <= 0)
                return -EINVAL;
 
-       spin_lock_init (&io->lock);
+       spin_lock_init(&io->lock);
        io->dev = dev;
        io->pipe = pipe;
        io->sg = sg;
@@ -381,7 +381,7 @@ int usb_sg_init (
        dma = (dev->dev.dma_mask != NULL);
        if (dma)
                io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe),
-                               sg, nents);
+                                               sg, nents);
        else
                io->entries = nents;
 
@@ -390,30 +390,30 @@ int usb_sg_init (
                return io->entries;
 
        io->count = io->entries;
-       io->urbs = kmalloc (io->entries * sizeof *io->urbs, mem_flags);
+       io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags);
        if (!io->urbs)
                goto nomem;
 
        urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT;
-       if (usb_pipein (pipe))
+       if (usb_pipein(pipe))
                urb_flags |= URB_SHORT_NOT_OK;
 
        for (i = 0; i < io->entries; i++) {
-               unsigned                len;
+               unsigned len;
 
-               io->urbs [i] = usb_alloc_urb (0, mem_flags);
-               if (!io->urbs [i]) {
+               io->urbs[i] = usb_alloc_urb(0, mem_flags);
+               if (!io->urbs[i]) {
                        io->entries = i;
                        goto nomem;
                }
 
-               io->urbs [i]->dev = NULL;
-               io->urbs [i]->pipe = pipe;
-               io->urbs [i]->interval = period;
-               io->urbs [i]->transfer_flags = urb_flags;
+               io->urbs[i]->dev = NULL;
+               io->urbs[i]->pipe = pipe;
+               io->urbs[i]->interval = period;
+               io->urbs[i]->transfer_flags = urb_flags;
 
-               io->urbs [i]->complete = sg_complete;
-               io->urbs [i]->context = io;
+               io->urbs[i]->complete = sg_complete;
+               io->urbs[i]->context = io;
 
                /*
                 * Some systems need to revert to PIO when DMA is temporarily
@@ -432,8 +432,8 @@ int usb_sg_init (
                 * to prevent stale pointers and to help spot bugs.
                 */
                if (dma) {
-                       io->urbs [i]->transfer_dma = sg_dma_address (sg + i);
-                       len = sg_dma_len (sg + i);
+                       io->urbs[i]->transfer_dma = sg_dma_address(sg + i);
+                       len = sg_dma_len(sg + i);
 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU)
                        io->urbs[i]->transfer_buffer = NULL;
 #else
@@ -441,31 +441,31 @@ int usb_sg_init (
 #endif
                } else {
                        /* hc may use _only_ transfer_buffer */
-                       io->urbs [i]->transfer_buffer = sg_virt(&sg[i]);
-                       len = sg [i].length;
+                       io->urbs[i]->transfer_buffer = sg_virt(&sg[i]);
+                       len = sg[i].length;
                }
 
                if (length) {
-                       len = min_t (unsigned, len, length);
+                       len = min_t(unsigned, len, length);
                        length -= len;
                        if (length == 0)
                                io->entries = i + 1;
                }
-               io->urbs [i]->transfer_buffer_length = len;
+               io->urbs[i]->transfer_buffer_length = len;
        }
-       io->urbs [--i]->transfer_flags &= ~URB_NO_INTERRUPT;
+       io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
 
        /* transaction state */
        io->status = 0;
        io->bytes = 0;
-       init_completion (&io->complete);
+       init_completion(&io->complete);
        return 0;
 
 nomem:
-       sg_clean (io);
+       sg_clean(io);
        return -ENOMEM;
 }
-
+EXPORT_SYMBOL_GPL(usb_sg_init);
 
 /**
  * usb_sg_wait - synchronously execute scatter/gather request
@@ -506,31 +506,32 @@ nomem:
  * speed interrupt endpoints, which allow at most one packet per millisecond,
  * of at most 8 or 64 bytes (respectively).
  */
-void usb_sg_wait (struct usb_sg_request *io)
+void usb_sg_wait(struct usb_sg_request *io)
 {
-       int             i, entries = io->entries;
+       int i;
+       int entries = io->entries;
 
        /* queue the urbs.  */
-       spin_lock_irq (&io->lock);
+       spin_lock_irq(&io->lock);
        i = 0;
        while (i < entries && !io->status) {
-               int     retval;
+               int retval;
 
-               io->urbs [i]->dev = io->dev;
-               retval = usb_submit_urb (io->urbs [i], GFP_ATOMIC);
+               io->urbs[i]->dev = io->dev;
+               retval = usb_submit_urb(io->urbs [i], GFP_ATOMIC);
 
                /* after we submit, let completions or cancelations fire;
                 * we handshake using io->status.
                 */
-               spin_unlock_irq (&io->lock);
+               spin_unlock_irq(&io->lock);
                switch (retval) {
                        /* maybe we retrying will recover */
-               case -ENXIO:    // hc didn't queue this one
+               case -ENXIO:    /* hc didn't queue this one */
                case -EAGAIN:
                case -ENOMEM:
                        io->urbs[i]->dev = NULL;
                        retval = 0;
-                       yield ();
+                       yield();
                        break;
 
                        /* no error? continue immediately.
@@ -541,34 +542,35 @@ void usb_sg_wait (struct usb_sg_request *io)
                         */
                case 0:
                        ++i;
-                       cpu_relax ();
+                       cpu_relax();
                        break;
 
                        /* fail any uncompleted urbs */
                default:
-                       io->urbs [i]->dev = NULL;
-                       io->urbs [i]->status = retval;
-                       dev_dbg (&io->dev->dev, "%s, submit --> %d\n",
+                       io->urbs[i]->dev = NULL;
+                       io->urbs[i]->status = retval;
+                       dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
                                __FUNCTION__, retval);
-                       usb_sg_cancel (io);
+                       usb_sg_cancel(io);
                }
-               spin_lock_irq (&io->lock);
+               spin_lock_irq(&io->lock);
                if (retval && (io->status == 0 || io->status == -ECONNRESET))
                        io->status = retval;
        }
        io->count -= entries - i;
        if (io->count == 0)
-               complete (&io->complete);
-       spin_unlock_irq (&io->lock);
+               complete(&io->complete);
+       spin_unlock_irq(&io->lock);
 
        /* OK, yes, this could be packaged as non-blocking.
         * So could the submit loop above ... but it's easier to
         * solve neither problem than to solve both!
         */
-       wait_for_completion (&io->complete);
+       wait_for_completion(&io->complete);
 
-       sg_clean (io);
+       sg_clean(io);
 }
+EXPORT_SYMBOL_GPL(usb_sg_wait);
 
 /**
  * usb_sg_cancel - stop scatter/gather i/o issued by usb_sg_wait()
@@ -578,32 +580,33 @@ void usb_sg_wait (struct usb_sg_request *io)
  * It can also prevents one initialized by usb_sg_init() from starting,
  * so that call just frees resources allocated to the request.
  */
-void usb_sg_cancel (struct usb_sg_request *io)
+void usb_sg_cancel(struct usb_sg_request *io)
 {
-       unsigned long   flags;
+       unsigned long flags;
 
-       spin_lock_irqsave (&io->lock, flags);
+       spin_lock_irqsave(&io->lock, flags);
 
        /* shut everything down, if it didn't already */
        if (!io->status) {
-               int     i;
+               int i;
 
                io->status = -ECONNRESET;
-               spin_unlock (&io->lock);
+               spin_unlock(&io->lock);
                for (i = 0; i < io->entries; i++) {
-                       int     retval;
+                       int retval;
 
                        if (!io->urbs [i]->dev)
                                continue;
-                       retval = usb_unlink_urb (io->urbs [i]);
+                       retval = usb_unlink_urb(io->urbs [i]);
                        if (retval != -EINPROGRESS && retval != -EBUSY)
-                               dev_warn (&io->dev->dev, "%s, unlink --> %d\n",
+                               dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
                                        __FUNCTION__, retval);
                }
-               spin_lock (&io->lock);
+               spin_lock(&io->lock);
        }
-       spin_unlock_irqrestore (&io->lock, flags);
+       spin_unlock_irqrestore(&io->lock, flags);
 }
+EXPORT_SYMBOL_GPL(usb_sg_cancel);
 
 /*-------------------------------------------------------------------*/
 
@@ -629,12 +632,13 @@ void usb_sg_cancel (struct usb_sg_request *io)
  * Returns the number of bytes received on success, or else the status code
  * returned by the underlying usb_control_msg() call.
  */
-int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size)
+int usb_get_descriptor(struct usb_device *dev, unsigned char type,
+                      unsigned char index, void *buf, int size)
 {
        int i;
        int result;
-       
-       memset(buf,0,size);     // Make sure we parse really received data
+
+       memset(buf, 0, size);   /* Make sure we parse really received data */
 
        for (i = 0; i < 3; ++i) {
                /* retry on length 0 or error; some devices are flakey */
@@ -652,6 +656,7 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char
        }
        return result;
 }
+EXPORT_SYMBOL_GPL(usb_get_descriptor);
 
 /**
  * usb_get_string - gets a string descriptor
@@ -708,7 +713,7 @@ static void usb_try_string_workarounds(unsigned char *buf, int *length)
 }
 
 static int usb_string_sub(struct usb_device *dev, unsigned int langid,
-               unsigned int index, unsigned char *buf)
+                         unsigned int index, unsigned char *buf)
 {
        int rc;
 
@@ -751,7 +756,7 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid,
  * @buf: where to put the string
  * @size: how big is "buf"?
  * Context: !in_interrupt ()
- * 
+ *
  * This converts the UTF-16LE encoded strings returned by devices, from
  * usb_get_string_descriptor(), to null-terminated ISO-8859-1 encoded ones
  * that are more usable in most kernel contexts.  Note that all characters
@@ -787,23 +792,23 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
        if (!dev->have_langid) {
                err = usb_string_sub(dev, 0, 0, tbuf);
                if (err < 0) {
-                       dev_err (&dev->dev,
+                       dev_err(&dev->dev,
                                "string descriptor 0 read error: %d\n",
                                err);
                        goto errout;
                } else if (err < 4) {
-                       dev_err (&dev->dev, "string descriptor 0 too short\n");
+                       dev_err(&dev->dev, "string descriptor 0 too short\n");
                        err = -EINVAL;
                        goto errout;
                } else {
                        dev->have_langid = 1;
-                       dev->string_langid = tbuf[2] | (tbuf[3]<< 8);
-                               /* always use the first langid listed */
-                       dev_dbg (&dev->dev, "default language 0x%04x\n",
+                       dev->string_langid = tbuf[2] | (tbuf[3] << 8);
+                       /* always use the first langid listed */
+                       dev_dbg(&dev->dev, "default language 0x%04x\n",
                                dev->string_langid);
                }
        }
-       
+
        err = usb_string_sub(dev, dev->string_langid, index, tbuf);
        if (err < 0)
                goto errout;
@@ -821,12 +826,15 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
        err = idx;
 
        if (tbuf[1] != USB_DT_STRING)
-               dev_dbg(&dev->dev, "wrong descriptor type %02x for string %d (\"%s\")\n", tbuf[1], index, buf);
+               dev_dbg(&dev->dev,
+                       "wrong descriptor type %02x for string %d (\"%s\")\n",
+                       tbuf[1], index, buf);
 
  errout:
        kfree(tbuf);
        return err;
 }
+EXPORT_SYMBOL_GPL(usb_string);
 
 /**
  * usb_cache_string - read a string descriptor and cache it for later use
@@ -842,9 +850,15 @@ char *usb_cache_string(struct usb_device *udev, int index)
        char *smallbuf = NULL;
        int len;
 
-       if (index > 0 && (buf = kmalloc(256, GFP_KERNEL)) != NULL) {
-               if ((len = usb_string(udev, index, buf, 256)) > 0) {
-                       if ((smallbuf = kmalloc(++len, GFP_KERNEL)) == NULL)
+       if (index <= 0)
+               return NULL;
+
+       buf = kmalloc(256, GFP_KERNEL);
+       if (buf) {
+               len = usb_string(udev, index, buf, 256);
+               if (len > 0) {
+                       smallbuf = kmalloc(++len, GFP_KERNEL);
+                       if (!smallbuf)
                                return buf;
                        memcpy(smallbuf, buf, len);
                }
@@ -883,7 +897,7 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
                return -ENOMEM;
 
        ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size);
-       if (ret >= 0) 
+       if (ret >= 0)
                memcpy(&dev->descriptor, desc, size);
        kfree(desc);
        return ret;
@@ -927,6 +941,7 @@ int usb_get_status(struct usb_device *dev, int type, int target, void *data)
        kfree(status);
        return ret;
 }
+EXPORT_SYMBOL_GPL(usb_get_status);
 
 /**
  * usb_clear_halt - tells device to clear endpoint halt/stall condition
@@ -955,8 +970,8 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
 {
        int result;
        int endp = usb_pipeendpoint(pipe);
-       
-       if (usb_pipein (pipe))
+
+       if (usb_pipein(pipe))
                endp |= USB_DIR_IN;
 
        /* we don't care if it wasn't halted first. in fact some devices
@@ -985,6 +1000,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(usb_clear_halt);
 
 /**
  * usb_disable_endpoint -- Disable an endpoint by address
@@ -1038,7 +1054,7 @@ void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf)
        }
 }
 
-/*
+/**
  * usb_disable_device - Disable all the endpoints for a USB device
  * @dev: the device whose endpoints are being disabled
  * @skip_ep0: 0 to disable endpoint 0, 1 to skip it.
@@ -1053,7 +1069,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
        int i;
 
        dev_dbg(&dev->dev, "%s nuking %s URBs\n", __FUNCTION__,
-                       skip_ep0 ? "non-ep0" : "all");
+               skip_ep0 ? "non-ep0" : "all");
        for (i = skip_ep0; i < 16; ++i) {
                usb_disable_endpoint(dev, i);
                usb_disable_endpoint(dev, i + USB_DIR_IN);
@@ -1071,17 +1087,17 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
                        interface = dev->actconfig->interface[i];
                        if (!device_is_registered(&interface->dev))
                                continue;
-                       dev_dbg (&dev->dev, "unregistering interface %s\n",
+                       dev_dbg(&dev->dev, "unregistering interface %s\n",
                                interface->dev.bus_id);
                        usb_remove_sysfs_intf_files(interface);
-                       device_del (&interface->dev);
+                       device_del(&interface->dev);
                }
 
                /* Now that the interfaces are unbound, nobody should
                 * try to access them.
                 */
                for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
-                       put_device (&dev->actconfig->interface[i]->dev);
+                       put_device(&dev->actconfig->interface[i]->dev);
                        dev->actconfig->interface[i] = NULL;
                }
                dev->actconfig = NULL;
@@ -1090,8 +1106,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
        }
 }
 
-
-/*
+/**
  * usb_enable_endpoint - Enable an endpoint for USB communications
  * @dev: the device whose interface is being enabled
  * @ep: the endpoint
@@ -1116,7 +1131,7 @@ void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep)
        ep->enabled = 1;
 }
 
-/*
+/**
  * usb_enable_interface - Enable all the endpoints for an interface
  * @dev: the device whose interface is being enabled
  * @intf: pointer to the interface descriptor
@@ -1172,6 +1187,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
        struct usb_host_interface *alt;
        int ret;
        int manual = 0;
+       unsigned int epaddr;
+       unsigned int pipe;
 
        if (dev->state == USB_STATE_SUSPENDED)
                return -EHOSTUNREACH;
@@ -1226,11 +1243,11 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
                int i;
 
                for (i = 0; i < alt->desc.bNumEndpoints; i++) {
-                       unsigned int epaddr =
-                               alt->endpoint[i].desc.bEndpointAddress;
-                       unsigned int pipe =
-       __create_pipe(dev, USB_ENDPOINT_NUMBER_MASK & epaddr)
-       | (usb_endpoint_out(epaddr) ? USB_DIR_OUT : USB_DIR_IN);
+                       epaddr = alt->endpoint[i].desc.bEndpointAddress;
+                       pipe = __create_pipe(dev,
+                                       USB_ENDPOINT_NUMBER_MASK & epaddr) |
+                                       (usb_endpoint_out(epaddr) ?
+                                       USB_DIR_OUT : USB_DIR_IN);
 
                        usb_clear_halt(dev, pipe);
                }
@@ -1253,6 +1270,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(usb_set_interface);
 
 /**
  * usb_reset_configuration - lightweight device reset
@@ -1328,6 +1346,7 @@ int usb_reset_configuration(struct usb_device *dev)
        }
        return 0;
 }
+EXPORT_SYMBOL_GPL(usb_reset_configuration);
 
 static void usb_release_interface(struct device *dev)
 {
@@ -1357,7 +1376,8 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
                return -ENOMEM;
 
        if (add_uevent_var(env,
-                  "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
+                  "MODALIAS=usb:"
+                  "v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
                   le16_to_cpu(usb_dev->descriptor.idVendor),
                   le16_to_cpu(usb_dev->descriptor.idProduct),
                   le16_to_cpu(usb_dev->descriptor.bcdDevice),
@@ -1387,8 +1407,8 @@ struct device_type usb_if_device_type = {
 };
 
 static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
-                                                      struct usb_host_config *config,
-                                                      u8 inum)
+                                               struct usb_host_config *config,
+                                               u8 inum)
 {
        struct usb_interface_assoc_descriptor *retval = NULL;
        struct usb_interface_assoc_descriptor *intf_assoc;
@@ -1415,7 +1435,6 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
        return retval;
 }
 
-
 /*
  * usb_set_configuration - Makes a particular device setting be current
  * @dev: the device whose configuration is being updated
@@ -1533,12 +1552,12 @@ free_interfaces:
         * getting rid of old interfaces means unbinding their drivers.
         */
        if (dev->state != USB_STATE_ADDRESS)
-               usb_disable_device (dev, 1);    // Skip ep0
-
-       if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
-                       USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
-                       NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) {
+               usb_disable_device(dev, 1);     /* Skip ep0 */
 
+       ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+                             USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
+                             NULL, 0, USB_CTRL_SET_TIMEOUT);
+       if (ret < 0) {
                /* All the old state is gone, so what else can we do?
                 * The device is probably useless now anyway.
                 */
@@ -1585,11 +1604,11 @@ free_interfaces:
                intf->dev.bus = &usb_bus_type;
                intf->dev.type = &usb_if_device_type;
                intf->dev.dma_mask = dev->dev.dma_mask;
-               device_initialize (&intf->dev);
+               device_initialize(&intf->dev);
                mark_quiesced(intf);
-               sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d",
-                        dev->bus->busnum, dev->devpath,
-                        configuration, alt->desc.bInterfaceNumber);
+               sprintf(&intf->dev.bus_id[0], "%d-%s:%d.%d",
+                       dev->bus->busnum, dev->devpath,
+                       configuration, alt->desc.bInterfaceNumber);
        }
        kfree(new_interfaces);
 
@@ -1605,11 +1624,11 @@ free_interfaces:
        for (i = 0; i < nintf; ++i) {
                struct usb_interface *intf = cp->interface[i];
 
-               dev_dbg (&dev->dev,
+               dev_dbg(&dev->dev,
                        "adding %s (config #%d, interface %d)\n",
                        intf->dev.bus_id, configuration,
                        intf->cur_altsetting->desc.bInterfaceNumber);
-               ret = device_add (&intf->dev);
+               ret = device_add(&intf->dev);
                if (ret != 0) {
                        dev_err(&dev->dev, "device_add(%s) --> %d\n",
                                intf->dev.bus_id, ret);
@@ -1677,22 +1696,3 @@ int usb_driver_set_configuration(struct usb_device *udev, int config)
        return 0;
 }
 EXPORT_SYMBOL_GPL(usb_driver_set_configuration);
-
-// synchronous request completion model
-EXPORT_SYMBOL(usb_control_msg);
-EXPORT_SYMBOL(usb_bulk_msg);
-
-EXPORT_SYMBOL(usb_sg_init);
-EXPORT_SYMBOL(usb_sg_cancel);
-EXPORT_SYMBOL(usb_sg_wait);
-
-// synchronous control message convenience routines
-EXPORT_SYMBOL(usb_get_descriptor);
-EXPORT_SYMBOL(usb_get_status);
-EXPORT_SYMBOL(usb_string);
-
-// synchronous calls that also maintain usbcore state
-EXPORT_SYMBOL(usb_clear_halt);
-EXPORT_SYMBOL(usb_reset_configuration);
-EXPORT_SYMBOL(usb_set_interface);
-
index 6b36897ca151998ab28f07c12f0e9baef9e372fe..7542dce3f5a1e2b01bcbd2ef78c08bd870c31b1a 100644 (file)
@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(usb_register_notify);
  * usb_unregister_notify - unregister a notifier callback
  * @nb: pointer to the notifier block for the callback events.
  *
- * usb_register_notifier() must have been previously called for this function
+ * usb_register_notify() must have been previously called for this function
  * to work properly.
  */
 void usb_unregister_notify(struct notifier_block *nb)
index 7f31a495a25d31f327f3bbf63239a9cd5d6a5349..e8cdce571bb1cb3ae4b1748638bf817b86839160 100644 (file)
@@ -14,7 +14,7 @@
  * mostly use of USB_DEVICE() or USB_DEVICE_VER() entries..
  *
  * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING!
- */ 
+ */
 
 static struct usb_device_id whitelist_table [] = {
 
@@ -55,7 +55,7 @@ static int is_targeted(struct usb_device *dev)
                return 1;
 
        /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
-       if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a && 
+       if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
             le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
                return 0;
 
@@ -86,7 +86,7 @@ static int is_targeted(struct usb_device *dev)
                        continue;
 
                if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
-                   (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass))
+                   (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
                        continue;
 
                if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
index 32bd130b1eed33fc542fc39bc5f10c1de4695916..a37ccbd1e007c478022ff02b22beeef3fd81976f 100644 (file)
@@ -72,7 +72,7 @@ set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
        return (value < 0) ? value : count;
 }
 
-static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR, 
+static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR,
                show_bConfigurationValue, set_bConfigurationValue);
 
 /* String fields */
@@ -248,6 +248,41 @@ static void remove_persist_attributes(struct device *dev)
 
 #ifdef CONFIG_USB_SUSPEND
 
+static ssize_t
+show_connected_duration(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       struct usb_device *udev = to_usb_device(dev);
+
+       return sprintf(buf, "%u\n",
+                       jiffies_to_msecs(jiffies - udev->connect_time));
+}
+
+static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL);
+
+/*
+ * If the device is resumed, the last time the device was suspended has
+ * been pre-subtracted from active_duration.  We add the current time to
+ * get the duration that the device was actually active.
+ *
+ * If the device is suspended, the active_duration is up-to-date.
+ */
+static ssize_t
+show_active_duration(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       struct usb_device *udev = to_usb_device(dev);
+       int duration;
+
+       if (udev->state != USB_STATE_SUSPENDED)
+               duration = jiffies_to_msecs(jiffies + udev->active_duration);
+       else
+               duration = jiffies_to_msecs(udev->active_duration);
+       return sprintf(buf, "%u\n", duration);
+}
+
+static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
+
 static ssize_t
 show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -365,12 +400,26 @@ static int add_power_attributes(struct device *dev)
                        rc = sysfs_add_file_to_group(&dev->kobj,
                                        &dev_attr_level.attr,
                                        power_group);
+               if (rc == 0)
+                       rc = sysfs_add_file_to_group(&dev->kobj,
+                                       &dev_attr_connected_duration.attr,
+                                       power_group);
+               if (rc == 0)
+                       rc = sysfs_add_file_to_group(&dev->kobj,
+                                       &dev_attr_active_duration.attr,
+                                       power_group);
        }
        return rc;
 }
 
 static void remove_power_attributes(struct device *dev)
 {
+       sysfs_remove_file_from_group(&dev->kobj,
+                       &dev_attr_active_duration.attr,
+                       power_group);
+       sysfs_remove_file_from_group(&dev->kobj,
+                       &dev_attr_connected_duration.attr,
+                       power_group);
        sysfs_remove_file_from_group(&dev->kobj,
                        &dev_attr_level.attr,
                        power_group);
@@ -601,21 +650,21 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev)
 /* Interface Accociation Descriptor fields */
 #define usb_intf_assoc_attr(field, format_string)                      \
 static ssize_t                                                         \
-show_iad_##field (struct device *dev, struct device_attribute *attr,   \
+show_iad_##field(struct device *dev, struct device_attribute *attr,    \
                char *buf)                                              \
 {                                                                      \
-       struct usb_interface *intf = to_usb_interface (dev);            \
+       struct usb_interface *intf = to_usb_interface(dev);             \
                                                                        \
-       return sprintf (buf, format_string,                             \
-                       intf->intf_assoc->field);               \
+       return sprintf(buf, format_string,                              \
+                       intf->intf_assoc->field);                       \
 }                                                                      \
 static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL);
 
-usb_intf_assoc_attr (bFirstInterface, "%02x\n")
-usb_intf_assoc_attr (bInterfaceCount, "%02d\n")
-usb_intf_assoc_attr (bFunctionClass, "%02x\n")
-usb_intf_assoc_attr (bFunctionSubClass, "%02x\n")
-usb_intf_assoc_attr (bFunctionProtocol, "%02x\n")
+usb_intf_assoc_attr(bFirstInterface, "%02x\n")
+usb_intf_assoc_attr(bInterfaceCount, "%02d\n")
+usb_intf_assoc_attr(bFunctionClass, "%02x\n")
+usb_intf_assoc_attr(bFunctionSubClass, "%02x\n")
+usb_intf_assoc_attr(bFunctionProtocol, "%02x\n")
 
 /* Interface fields */
 #define usb_intf_attr(field, format_string)                            \
index d05ead20081c6cdb2ae9ce6c16be8a99c2862bfc..9d7e63292c01175647503b65e821cdd3b94dc381 100644 (file)
@@ -42,6 +42,7 @@ void usb_init_urb(struct urb *urb)
                INIT_LIST_HEAD(&urb->anchor_list);
        }
 }
+EXPORT_SYMBOL_GPL(usb_init_urb);
 
 /**
  * usb_alloc_urb - creates a new urb for a USB driver to use
@@ -73,6 +74,7 @@ struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
        usb_init_urb(urb);
        return urb;
 }
+EXPORT_SYMBOL_GPL(usb_alloc_urb);
 
 /**
  * usb_free_urb - frees the memory used by a urb when all users of it are finished
@@ -89,6 +91,7 @@ void usb_free_urb(struct urb *urb)
        if (urb)
                kref_put(&urb->kref, urb_destroy);
 }
+EXPORT_SYMBOL_GPL(usb_free_urb);
 
 /**
  * usb_get_urb - increments the reference count of the urb
@@ -100,12 +103,13 @@ void usb_free_urb(struct urb *urb)
  *
  * A pointer to the urb with the incremented reference counter is returned.
  */
-struct urb * usb_get_urb(struct urb *urb)
+struct urb *usb_get_urb(struct urb *urb)
 {
        if (urb)
                kref_get(&urb->kref);
        return urb;
 }
+EXPORT_SYMBOL_GPL(usb_get_urb);
 
 /**
  * usb_anchor_urb - anchors an URB while it is processed
@@ -172,7 +176,7 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
  * describing that request to the USB subsystem.  Request completion will
  * be indicated later, asynchronously, by calling the completion handler.
  * The three types of completion are success, error, and unlink
- * (a software-induced fault, also called "request cancellation").  
+ * (a software-induced fault, also called "request cancellation").
  *
  * URBs may be submitted in interrupt context.
  *
@@ -255,7 +259,7 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
  *       semaphores), or
  *   (c) current->state != TASK_RUNNING, this is the case only after
  *       you've changed it.
- * 
+ *
  * GFP_NOIO is used in the block io path and error handling of storage
  * devices.
  *
@@ -284,7 +288,8 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
 
        if (!urb || urb->hcpriv || !urb->complete)
                return -EINVAL;
-       if (!(dev = urb->dev) || dev->state < USB_STATE_DEFAULT)
+       dev = urb->dev;
+       if ((!dev) || (dev->state < USB_STATE_DEFAULT))
                return -ENODEV;
 
        /* For now, get the endpoint from the pipe.  Eventually drivers
@@ -347,11 +352,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
                        max *= mult;
                }
 
-               if (urb->number_of_packets <= 0)                    
+               if (urb->number_of_packets <= 0)
                        return -EINVAL;
                for (n = 0; n < urb->number_of_packets; n++) {
                        len = urb->iso_frame_desc[n].length;
-                       if (len < 0 || len > max) 
+                       if (len < 0 || len > max)
                                return -EMSGSIZE;
                        urb->iso_frame_desc[n].status = -EXDEV;
                        urb->iso_frame_desc[n].actual_length = 0;
@@ -416,7 +421,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
                /* too big? */
                switch (dev->speed) {
                case USB_SPEED_HIGH:    /* units are microframes */
-                       // NOTE usb handles 2^15
+                       /* NOTE usb handles 2^15 */
                        if (urb->interval > (1024 * 8))
                                urb->interval = 1024 * 8;
                        max = 1024 * 8;
@@ -426,12 +431,12 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
                        if (xfertype == USB_ENDPOINT_XFER_INT) {
                                if (urb->interval > 255)
                                        return -EINVAL;
-                               // NOTE ohci only handles up to 32
+                               /* NOTE ohci only handles up to 32 */
                                max = 128;
                        } else {
                                if (urb->interval > 1024)
                                        urb->interval = 1024;
-                               // NOTE usb and ohci handle up to 2^15
+                               /* NOTE usb and ohci handle up to 2^15 */
                                max = 1024;
                        }
                        break;
@@ -444,6 +449,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
 
        return usb_hcd_submit_urb(urb, mem_flags);
 }
+EXPORT_SYMBOL_GPL(usb_submit_urb);
 
 /*-------------------------------------------------------------------*/
 
@@ -514,6 +520,7 @@ int usb_unlink_urb(struct urb *urb)
                return -EIDRM;
        return usb_hcd_unlink_urb(urb, -ECONNRESET);
 }
+EXPORT_SYMBOL_GPL(usb_unlink_urb);
 
 /**
  * usb_kill_urb - cancel a transfer request and wait for it to finish
@@ -553,6 +560,7 @@ void usb_kill_urb(struct urb *urb)
        --urb->reject;
        mutex_unlock(&reject_mutex);
 }
+EXPORT_SYMBOL_GPL(usb_kill_urb);
 
 /**
  * usb_kill_anchored_urbs - cancel transfer requests en masse
@@ -567,7 +575,8 @@ void usb_kill_anchored_urbs(struct usb_anchor *anchor)
 
        spin_lock_irq(&anchor->lock);
        while (!list_empty(&anchor->urb_list)) {
-               victim = list_entry(anchor->urb_list.prev, struct urb, anchor_list);
+               victim = list_entry(anchor->urb_list.prev, struct urb,
+                                   anchor_list);
                /* we must make sure the URB isn't freed before we kill it*/
                usb_get_urb(victim);
                spin_unlock_irq(&anchor->lock);
@@ -595,11 +604,3 @@ int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
                                  msecs_to_jiffies(timeout));
 }
 EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout);
-
-EXPORT_SYMBOL(usb_init_urb);
-EXPORT_SYMBOL(usb_alloc_urb);
-EXPORT_SYMBOL(usb_free_urb);
-EXPORT_SYMBOL(usb_get_urb);
-EXPORT_SYMBOL(usb_submit_urb);
-EXPORT_SYMBOL(usb_unlink_urb);
-EXPORT_SYMBOL(usb_kill_urb);
index 8f142370103d48400d3adb6cb6b6f36eab5e4070..4e984060c984b4cbb715607f26ab13dfb05d357e 100644 (file)
@@ -96,6 +96,7 @@ struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
 
        return NULL;
 }
+EXPORT_SYMBOL_GPL(usb_ifnum_to_if);
 
 /**
  * usb_altnum_to_altsetting - get the altsetting structure with a given
@@ -115,8 +116,9 @@ struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
  * Don't call this function unless you are bound to the intf interface
  * or you have locked the device!
  */
-struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *intf,
-                                                   unsigned int altnum)
+struct usb_host_interface *usb_altnum_to_altsetting(
+                                       const struct usb_interface *intf,
+                                       unsigned int altnum)
 {
        int i;
 
@@ -126,13 +128,14 @@ struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *
        }
        return NULL;
 }
+EXPORT_SYMBOL_GPL(usb_altnum_to_altsetting);
 
 struct find_interface_arg {
        int minor;
        struct usb_interface *interface;
 };
 
-static int __find_interface(struct device * dev, void * data)
+static int __find_interface(struct device *dev, void *data)
 {
        struct find_interface_arg *arg = data;
        struct usb_interface *intf;
@@ -154,7 +157,7 @@ static int __find_interface(struct device * dev, void * data)
  * @drv: the driver whose current configuration is considered
  * @minor: the minor number of the desired device
  *
- * This walks the driver device list and returns a pointer to the interface 
+ * This walks the driver device list and returns a pointer to the interface
  * with the matching minor.  Note, this only works for devices that share the
  * USB major number.
  */
@@ -170,6 +173,7 @@ struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
                                        __find_interface);
        return argb.interface;
 }
+EXPORT_SYMBOL_GPL(usb_find_interface);
 
 /**
  * usb_release_dev - free a usb device structure when all users of it are finished.
@@ -230,7 +234,7 @@ static int ksuspend_usb_init(void)
         * singlethreaded.  Its job doesn't justify running on more
         * than one CPU.
         */
-       ksuspend_usb_wq = create_freezeable_workqueue("ksuspend_usbd");
+       ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd");
        if (!ksuspend_usb_wq)
                return -ENOMEM;
        return 0;
@@ -269,8 +273,8 @@ static unsigned usb_bus_is_wusb(struct usb_bus *bus)
  *
  * This call may not be used in a non-sleeping context.
  */
-struct usb_device *
-usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
+struct usb_device *usb_alloc_dev(struct usb_device *parent,
+                                struct usb_bus *bus, unsigned port1)
 {
        struct usb_device *dev;
        struct usb_hcd *usb_hcd = container_of(bus, struct usb_hcd, self);
@@ -339,6 +343,8 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
        mutex_init(&dev->pm_mutex);
        INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work);
        dev->autosuspend_delay = usb_autosuspend_delay * HZ;
+       dev->connect_time = jiffies;
+       dev->active_duration = -jiffies;
 #endif
        if (root_hub)   /* Root hub always ok [and always wired] */
                dev->authorized = 1;
@@ -367,6 +373,7 @@ struct usb_device *usb_get_dev(struct usb_device *dev)
                get_device(&dev->dev);
        return dev;
 }
+EXPORT_SYMBOL_GPL(usb_get_dev);
 
 /**
  * usb_put_dev - release a use of the usb device structure
@@ -380,6 +387,7 @@ void usb_put_dev(struct usb_device *dev)
        if (dev)
                put_device(&dev->dev);
 }
+EXPORT_SYMBOL_GPL(usb_put_dev);
 
 /**
  * usb_get_intf - increments the reference count of the usb interface structure
@@ -400,6 +408,7 @@ struct usb_interface *usb_get_intf(struct usb_interface *intf)
                get_device(&intf->dev);
        return intf;
 }
+EXPORT_SYMBOL_GPL(usb_get_intf);
 
 /**
  * usb_put_intf - release a use of the usb interface structure
@@ -414,7 +423,7 @@ void usb_put_intf(struct usb_interface *intf)
        if (intf)
                put_device(&intf->dev);
 }
-
+EXPORT_SYMBOL_GPL(usb_put_intf);
 
 /*                     USB device locking
  *
@@ -461,11 +470,11 @@ int usb_lock_device_for_reset(struct usb_device *udev,
                return -EHOSTUNREACH;
        if (iface) {
                switch (iface->condition) {
-                 case USB_INTERFACE_BINDING:
+               case USB_INTERFACE_BINDING:
                        return 0;
-                 case USB_INTERFACE_BOUND:
+               case USB_INTERFACE_BOUND:
                        break;
-                 default:
+               default:
                        return -EINTR;
                }
        }
@@ -487,7 +496,7 @@ int usb_lock_device_for_reset(struct usb_device *udev,
        }
        return 1;
 }
-
+EXPORT_SYMBOL_GPL(usb_lock_device_for_reset);
 
 static struct usb_device *match_device(struct usb_device *dev,
                                       u16 vendor_id, u16 product_id)
@@ -540,10 +549,10 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
        struct list_head *buslist;
        struct usb_bus *bus;
        struct usb_device *dev = NULL;
-       
+
        mutex_lock(&usb_bus_list_lock);
        for (buslist = usb_bus_list.next;
-            buslist != &usb_bus_list; 
+            buslist != &usb_bus_list;
             buslist = buslist->next) {
                bus = container_of(buslist, struct usb_bus, bus_list);
                if (!bus->root_hub)
@@ -576,6 +585,7 @@ int usb_get_current_frame_number(struct usb_device *dev)
 {
        return usb_hcd_get_frame_number(dev);
 }
+EXPORT_SYMBOL_GPL(usb_get_current_frame_number);
 
 /*-------------------------------------------------------------------*/
 /*
@@ -584,7 +594,7 @@ int usb_get_current_frame_number(struct usb_device *dev)
  */
 
 int __usb_get_extra_descriptor(char *buffer, unsigned size,
-       unsigned char type, void **ptr)
+                              unsigned char type, void **ptr)
 {
        struct usb_descriptor_header *header;
 
@@ -595,7 +605,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
                        printk(KERN_ERR
                                "%s: bogus descriptor, type %d length %d\n",
                                usbcore_name,
-                               header->bDescriptorType, 
+                               header->bDescriptorType,
                                header->bLength);
                        return -1;
                }
@@ -610,6 +620,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
        }
        return -1;
 }
+EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor);
 
 /**
  * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP
@@ -633,17 +644,14 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
  *
  * When the buffer is no longer used, free it with usb_buffer_free().
  */
-void *usb_buffer_alloc(
-       struct usb_device *dev,
-       size_t size,
-       gfp_t mem_flags,
-       dma_addr_t *dma
-)
+void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags,
+                      dma_addr_t *dma)
 {
        if (!dev || !dev->bus)
                return NULL;
        return hcd_buffer_alloc(dev->bus, size, mem_flags, dma);
 }
+EXPORT_SYMBOL_GPL(usb_buffer_alloc);
 
 /**
  * usb_buffer_free - free memory allocated with usb_buffer_alloc()
@@ -656,12 +664,8 @@ void *usb_buffer_alloc(
  * been allocated using usb_buffer_alloc(), and the parameters must match
  * those provided in that allocation request.
  */
-void usb_buffer_free(
-       struct usb_device *dev,
-       size_t size,
-       void *addr,
-       dma_addr_t dma
-)
+void usb_buffer_free(struct usb_device *dev, size_t size, void *addr,
+                    dma_addr_t dma)
 {
        if (!dev || !dev->bus)
                return;
@@ -669,6 +673,7 @@ void usb_buffer_free(
                return;
        hcd_buffer_free(dev->bus, size, addr, dma);
 }
+EXPORT_SYMBOL_GPL(usb_buffer_free);
 
 /**
  * usb_buffer_map - create DMA mapping(s) for an urb
@@ -708,14 +713,15 @@ struct urb *usb_buffer_map(struct urb *urb)
                                        urb->setup_packet,
                                        sizeof(struct usb_ctrlrequest),
                                        DMA_TO_DEVICE);
-       // FIXME generic api broken like pci, can't report errors
-       // if (urb->transfer_dma == DMA_ADDR_INVALID) return 0;
+       /* FIXME generic api broken like pci, can't report errors */
+       /* if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; */
        } else
                urb->transfer_dma = ~0;
        urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP
                                | URB_NO_SETUP_DMA_MAP);
        return urb;
 }
+EXPORT_SYMBOL_GPL(usb_buffer_map);
 #endif  /*  0  */
 
 /* XXX DISABLED, no users currently.  If you wish to re-enable this
@@ -753,6 +759,7 @@ void usb_buffer_dmasync(struct urb *urb)
                                        DMA_TO_DEVICE);
        }
 }
+EXPORT_SYMBOL_GPL(usb_buffer_dmasync);
 #endif
 
 /**
@@ -788,6 +795,7 @@ void usb_buffer_unmap(struct urb *urb)
        urb->transfer_flags &= ~(URB_NO_TRANSFER_DMA_MAP
                                | URB_NO_SETUP_DMA_MAP);
 }
+EXPORT_SYMBOL_GPL(usb_buffer_unmap);
 #endif  /*  0  */
 
 /**
@@ -828,10 +836,11 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
                        || !controller->dma_mask)
                return -1;
 
-       // FIXME generic api broken like pci, can't report errors
+       /* FIXME generic api broken like pci, can't report errors */
        return dma_map_sg(controller, sg, nents,
                        is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
 }
+EXPORT_SYMBOL_GPL(usb_buffer_map_sg);
 
 /* XXX DISABLED, no users currently.  If you wish to re-enable this
  * XXX please determine whether the sync is to transfer ownership of
@@ -865,6 +874,7 @@ void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
        dma_sync_sg(controller, sg, n_hw_ents,
                        is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
 }
+EXPORT_SYMBOL_GPL(usb_buffer_dmasync_sg);
 #endif
 
 /**
@@ -891,6 +901,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
        dma_unmap_sg(controller, sg, n_hw_ents,
                        is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
 }
+EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg);
 
 /* format to disable USB on kernel command line is: nousb */
 __module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444);
@@ -902,6 +913,7 @@ int usb_disabled(void)
 {
        return nousb;
 }
+EXPORT_SYMBOL_GPL(usb_disabled);
 
 /*
  * Init
@@ -918,7 +930,7 @@ static int __init usb_init(void)
        if (retval)
                goto out;
        retval = bus_register(&usb_bus_type);
-       if (retval) 
+       if (retval)
                goto bus_register_failed;
        retval = usb_host_init();
        if (retval)
@@ -983,45 +995,4 @@ static void __exit usb_exit(void)
 
 subsys_initcall(usb_init);
 module_exit(usb_exit);
-
-/*
- * USB may be built into the kernel or be built as modules.
- * These symbols are exported for device (or host controller)
- * driver modules to use.
- */
-
-EXPORT_SYMBOL(usb_disabled);
-
-EXPORT_SYMBOL_GPL(usb_get_intf);
-EXPORT_SYMBOL_GPL(usb_put_intf);
-
-EXPORT_SYMBOL(usb_put_dev);
-EXPORT_SYMBOL(usb_get_dev);
-EXPORT_SYMBOL(usb_hub_tt_clear_buffer);
-
-EXPORT_SYMBOL(usb_lock_device_for_reset);
-
-EXPORT_SYMBOL(usb_find_interface);
-EXPORT_SYMBOL(usb_ifnum_to_if);
-EXPORT_SYMBOL(usb_altnum_to_altsetting);
-
-EXPORT_SYMBOL(__usb_get_extra_descriptor);
-
-EXPORT_SYMBOL(usb_get_current_frame_number);
-
-EXPORT_SYMBOL(usb_buffer_alloc);
-EXPORT_SYMBOL(usb_buffer_free);
-
-#if 0
-EXPORT_SYMBOL(usb_buffer_map);
-EXPORT_SYMBOL(usb_buffer_dmasync);
-EXPORT_SYMBOL(usb_buffer_unmap);
-#endif
-
-EXPORT_SYMBOL(usb_buffer_map_sg);
-#if 0
-EXPORT_SYMBOL(usb_buffer_dmasync_sg);
-#endif
-EXPORT_SYMBOL(usb_buffer_unmap_sg);
-
 MODULE_LICENSE("GPL");
index c52626c51f70bd99859c170739eb20b7695937bb..2375194a9d43a7d9a6440f097e951d2f8b27f56d 100644 (file)
@@ -1,22 +1,23 @@
 /* Functions local to drivers/usb/core/ */
 
-extern int usb_create_sysfs_dev_files (struct usb_device *dev);
-extern void usb_remove_sysfs_dev_files (struct usb_device *dev);
-extern int usb_create_sysfs_intf_files (struct usb_interface *intf);
-extern void usb_remove_sysfs_intf_files (struct usb_interface *intf);
-extern int usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint,
+extern int usb_create_sysfs_dev_files(struct usb_device *dev);
+extern void usb_remove_sysfs_dev_files(struct usb_device *dev);
+extern int usb_create_sysfs_intf_files(struct usb_interface *intf);
+extern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
+extern int usb_create_ep_files(struct device *parent,
+                               struct usb_host_endpoint *endpoint,
                                struct usb_device *udev);
 extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
 
 extern void usb_enable_endpoint(struct usb_device *dev,
                struct usb_host_endpoint *ep);
-extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr);
-extern void usb_disable_interface (struct usb_device *dev,
+extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr);
+extern void usb_disable_interface(struct usb_device *dev,
                struct usb_interface *intf);
 extern void usb_release_interface_cache(struct kref *ref);
-extern void usb_disable_device (struct usb_device *dev, int skip_ep0);
-extern int usb_deauthorize_device (struct usb_device *);
-extern int usb_authorize_device (struct usb_device *);
+extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
+extern int usb_deauthorize_device(struct usb_device *);
+extern int usb_authorize_device(struct usb_device *);
 extern void usb_detect_quirks(struct usb_device *udev);
 
 extern int usb_get_device_descriptor(struct usb_device *dev,
index 77a3759d6fc7552c83f01139cff84d46f6f85b2c..c1395516468618c3683fccac3d27bc22bc5a0759 100644 (file)
 # With help from a special transceiver and a "Mini-AB" jack, systems with
 # both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG).
 #
-menu "USB Gadget Support"
 
-config USB_GADGET
-       tristate "Support for USB Gadgets"
+menuconfig USB_GADGET
+       tristate "USB Gadget Support"
        help
           USB is a master/slave protocol, organized with one master
           host (such as a PC) controlling up to 127 peripheral devices.
@@ -42,6 +41,8 @@ config USB_GADGET
           For more information, see <http://www.linux-usb.org/gadget> and
           the kernel DocBook documentation for this API.
 
+if USB_GADGET
+
 config USB_GADGET_DEBUG
        boolean "Debugging messages"
        depends on USB_GADGET && DEBUG_KERNEL && EXPERIMENTAL
@@ -220,6 +221,16 @@ config USB_M66592
        default USB_GADGET
        select USB_GADGET_SELECTED
 
+config SUPERH_BUILT_IN_M66592
+       boolean "Enable SuperH built-in USB like the M66592"
+       depends on USB_GADGET_M66592 && CPU_SUBTYPE_SH7722
+       help
+          SH7722 has USB like the M66592.
+
+          The transfer rate is very slow when use "Ethernet Gadget".
+          However, this problem is improved if change a value of
+          NET_IP_ALIGN to 4.
+
 config USB_GADGET_GOKU
        boolean "Toshiba TC86C001 'Goku-S'"
        depends on PCI
@@ -538,6 +549,20 @@ config USB_MIDI_GADGET
          Say "y" to link the driver statically, or "m" to build a
          dynamically linked module called "g_midi".
 
+config USB_G_PRINTER
+       tristate "Printer Gadget"
+       help
+         The Printer Gadget channels data between the USB host and a
+         userspace program driving the print engine. The user space
+         program reads and writes the device file /dev/g_printer to
+         receive or send printer data. It can use ioctl calls to
+         the device file to get or set printer status.
+
+         Say "y" to link the driver statically, or "m" to build a
+         dynamically linked module called "g_printer".
+
+         For more information, see Documentation/usb/gadget_printer.txt
+         which includes sample code for accessing the device file.
 
 # put drivers that need isochronous transfer support (for audio
 # or video class gadget drivers), or specific hardware, here.
@@ -546,4 +571,4 @@ config USB_MIDI_GADGET
 
 endchoice
 
-endmenu
+endif # USB_GADGET
index 904e57bf61124e8bb2e996df679a35a3d628c743..c3aab80b6c76e33095556539f15f2377a14d8adf 100644 (file)
@@ -28,6 +28,8 @@ g_midi-objs                   := gmidi.o usbstring.o config.o epautoconf.o
 gadgetfs-objs                  := inode.o
 g_file_storage-objs            := file_storage.o usbstring.o config.o \
                                        epautoconf.o
+g_printer-objs                 := printer.o usbstring.o config.o \
+                                       epautoconf.o
 
 ifeq ($(CONFIG_USB_ETH_RNDIS),y)
        g_ether-objs            += rndis.o
@@ -38,5 +40,6 @@ obj-$(CONFIG_USB_ETH)         += g_ether.o
 obj-$(CONFIG_USB_GADGETFS)     += gadgetfs.o
 obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o
 obj-$(CONFIG_USB_G_SERIAL)     += g_serial.o
+obj-$(CONFIG_USB_G_PRINTER)    += g_printer.o
 obj-$(CONFIG_USB_MIDI_GADGET)  += g_midi.o
 
index c72e9620bf8dc67164dfc64eaa9da2488e834282..b663f23f2642ab5a157039e98c1f92b678927ee1 100644 (file)
@@ -1244,7 +1244,7 @@ udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp)
                /* stop OUT naking */
                if (!ep->in) {
                        if (!use_dma && udc_rxfifo_pending) {
-                               DBG(dev, "udc_queue(): pending bytes in"
+                               DBG(dev, "udc_queue(): pending bytes in "
                                        "rxfifo after nyet\n");
                                /*
                                 * read pending bytes afer nyet:
@@ -2038,6 +2038,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        spin_unlock_irqrestore(&dev->lock, flags);
 
        driver->unbind(&dev->gadget);
+       dev->gadget.dev.driver = NULL;
        dev->driver = NULL;
 
        /* set SD */
index cd62b029d1766e606945e2c8a12e1ecc08fd119f..a83e8b798ec9d30d70ca38bd7cebc37576c217ba 100644 (file)
@@ -21,8 +21,7 @@
  * Boston, MA  02111-1307, USA.
  */
 
-#undef DEBUG
-#undef VERBOSE
+#undef VERBOSE_DEBUG
 #undef PACKET_TRACE
 
 #include <linux/kernel.h>
@@ -46,8 +45,8 @@
 #include <asm/irq.h>
 #include <asm/system.h>
 #include <asm/mach-types.h>
+#include <asm/gpio.h>
 
-#include <asm/arch/gpio.h>
 #include <asm/arch/board.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/at91sam9261_matrix.h>
@@ -580,7 +579,7 @@ static int at91_ep_disable (struct usb_ep * _ep)
  */
 
 static struct usb_request *
-at91_ep_alloc_request(struct usb_ep *_ep, unsigned int gfp_flags)
+at91_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
 {
        struct at91_request *req;
 
@@ -881,6 +880,8 @@ static void clk_off(struct at91_udc *udc)
  */
 static void pullup(struct at91_udc *udc, int is_on)
 {
+       int     active = !udc->board.pullup_active_low;
+
        if (!udc->enabled || !udc->vbus)
                is_on = 0;
        DBG("%sactive\n", is_on ? "" : "in");
@@ -890,7 +891,7 @@ static void pullup(struct at91_udc *udc, int is_on)
                at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM);
                at91_udp_write(udc, AT91_UDP_TXVC, 0);
                if (cpu_is_at91rm9200())
-                       at91_set_gpio_value(udc->board.pullup_pin, 1);
+                       gpio_set_value(udc->board.pullup_pin, active);
                else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
                        u32     txvc = at91_udp_read(udc, AT91_UDP_TXVC);
 
@@ -908,7 +909,7 @@ static void pullup(struct at91_udc *udc, int is_on)
                at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM);
                at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
                if (cpu_is_at91rm9200())
-                       at91_set_gpio_value(udc->board.pullup_pin, 0);
+                       gpio_set_value(udc->board.pullup_pin, !active);
                else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
                        u32     txvc = at91_udp_read(udc, AT91_UDP_TXVC);
 
@@ -1153,7 +1154,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
                        | USB_REQ_GET_STATUS:
                tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
                ep = &udc->ep[tmp];
-               if (tmp > NUM_ENDPOINTS || (tmp && !ep->desc))
+               if (tmp >= NUM_ENDPOINTS || (tmp && !ep->desc))
                        goto stall;
 
                if (tmp) {
@@ -1176,7 +1177,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
                        | USB_REQ_SET_FEATURE:
                tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
                ep = &udc->ep[tmp];
-               if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS)
+               if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS)
                        goto stall;
                if (!ep->desc || ep->is_iso)
                        goto stall;
@@ -1195,7 +1196,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
                        | USB_REQ_CLEAR_FEATURE:
                tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
                ep = &udc->ep[tmp];
-               if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS)
+               if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS)
                        goto stall;
                if (tmp == 0)
                        goto succeed;
@@ -1551,7 +1552,7 @@ static irqreturn_t at91_vbus_irq(int irq, void *_udc)
 
        /* vbus needs at least brief debouncing */
        udelay(10);
-       value = at91_get_gpio_value(udc->board.vbus_pin);
+       value = gpio_get_value(udc->board.vbus_pin);
        if (value != udc->vbus)
                at91_vbus_session(&udc->gadget, value);
 
@@ -1616,6 +1617,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
        local_irq_enable();
 
        driver->unbind(&udc->gadget);
+       udc->gadget.dev.driver = NULL;
+       udc->gadget.dev.driver_data = NULL;
        udc->driver = NULL;
 
        DBG("unbound from %s\n", driver->driver.name);
@@ -1645,12 +1648,12 @@ static int __init at91udc_probe(struct platform_device *pdev)
        }
 
        if (pdev->num_resources != 2) {
-               DBG("invalid num_resources");
+               DBG("invalid num_resources\n");
                return -ENODEV;
        }
        if ((pdev->resource[0].flags != IORESOURCE_MEM)
                        || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
-               DBG("invalid resource type");
+               DBG("invalid resource type\n");
                return -ENODEV;
        }
 
@@ -1672,10 +1675,26 @@ static int __init at91udc_probe(struct platform_device *pdev)
        udc->pdev = pdev;
        udc->enabled = 0;
 
+       /* rm9200 needs manual D+ pullup; off by default */
+       if (cpu_is_at91rm9200()) {
+               if (udc->board.pullup_pin <= 0) {
+                       DBG("no D+ pullup?\n");
+                       retval = -ENODEV;
+                       goto fail0;
+               }
+               retval = gpio_request(udc->board.pullup_pin, "udc_pullup");
+               if (retval) {
+                       DBG("D+ pullup is busy\n");
+                       goto fail0;
+               }
+               gpio_direction_output(udc->board.pullup_pin,
+                               udc->board.pullup_active_low);
+       }
+
        udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1);
        if (!udc->udp_baseaddr) {
-               release_mem_region(res->start, res->end - res->start + 1);
-               return -ENOMEM;
+               retval = -ENOMEM;
+               goto fail0a;
        }
 
        udc_reinit(udc);
@@ -1686,12 +1705,13 @@ static int __init at91udc_probe(struct platform_device *pdev)
        if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
                DBG("clocks missing\n");
                retval = -ENODEV;
-               goto fail0;
+               /* NOTE: we "know" here that refcounts on these are NOPs */
+               goto fail0b;
        }
 
        retval = device_register(&udc->gadget.dev);
        if (retval < 0)
-               goto fail0;
+               goto fail0b;
 
        /* don't do anything until we have both gadget driver and VBUS */
        clk_enable(udc->iclk);
@@ -1703,25 +1723,32 @@ static int __init at91udc_probe(struct platform_device *pdev)
 
        /* request UDC and maybe VBUS irqs */
        udc->udp_irq = platform_get_irq(pdev, 0);
-       if (request_irq(udc->udp_irq, at91_udc_irq,
-                       IRQF_DISABLED, driver_name, udc)) {
+       retval = request_irq(udc->udp_irq, at91_udc_irq,
+                       IRQF_DISABLED, driver_name, udc);
+       if (retval < 0) {
                DBG("request irq %d failed\n", udc->udp_irq);
-               retval = -EBUSY;
                goto fail1;
        }
        if (udc->board.vbus_pin > 0) {
+               retval = gpio_request(udc->board.vbus_pin, "udc_vbus");
+               if (retval < 0) {
+                       DBG("request vbus pin failed\n");
+                       goto fail2;
+               }
+               gpio_direction_input(udc->board.vbus_pin);
+
                /*
                 * Get the initial state of VBUS - we cannot expect
                 * a pending interrupt.
                 */
-               udc->vbus = at91_get_gpio_value(udc->board.vbus_pin);
+               udc->vbus = gpio_get_value(udc->board.vbus_pin);
                if (request_irq(udc->board.vbus_pin, at91_vbus_irq,
                                IRQF_DISABLED, driver_name, udc)) {
                        DBG("request vbus irq %d failed\n",
                                        udc->board.vbus_pin);
                        free_irq(udc->udp_irq, udc);
                        retval = -EBUSY;
-                       goto fail1;
+                       goto fail3;
                }
        } else {
                DBG("no VBUS detection, assuming always-on\n");
@@ -1734,8 +1761,18 @@ static int __init at91udc_probe(struct platform_device *pdev)
        INFO("%s version %s\n", driver_name, DRIVER_VERSION);
        return 0;
 
+fail3:
+       if (udc->board.vbus_pin > 0)
+               gpio_free(udc->board.vbus_pin);
+fail2:
+       free_irq(udc->udp_irq, udc);
 fail1:
        device_unregister(&udc->gadget.dev);
+fail0b:
+       iounmap(udc->udp_baseaddr);
+fail0a:
+       if (cpu_is_at91rm9200())
+               gpio_free(udc->board.pullup_pin);
 fail0:
        release_mem_region(res->start, res->end - res->start + 1);
        DBG("%s probe failed, %d\n", driver_name, retval);
@@ -1756,12 +1793,18 @@ static int __exit at91udc_remove(struct platform_device *pdev)
 
        device_init_wakeup(&pdev->dev, 0);
        remove_debug_file(udc);
-       if (udc->board.vbus_pin > 0)
+       if (udc->board.vbus_pin > 0) {
                free_irq(udc->board.vbus_pin, udc);
+               gpio_free(udc->board.vbus_pin);
+       }
        free_irq(udc->udp_irq, udc);
        device_unregister(&udc->gadget.dev);
 
        iounmap(udc->udp_baseaddr);
+
+       if (cpu_is_at91rm9200())
+               gpio_free(udc->board.pullup_pin);
+
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        release_mem_region(res->start, res->end - res->start + 1);
 
index 7e34e2f864f9d70efcfd41ed1c2e6719e91dcb30..a973f2a50fb959509472aa66db390817c78f1a7d 100644 (file)
@@ -53,7 +53,7 @@
 #define     AT91_UDP_RXRSM     (1 <<  9)       /* USB Resume Interrupt Status */
 #define     AT91_UDP_EXTRSM    (1 << 10)       /* External Resume Interrupt Status [AT91RM9200 only] */
 #define     AT91_UDP_SOFINT    (1 << 11)       /* Start of Frame Interrupt Status */
-#define     AT91_UDP_ENDBUSRES (1 << 12)       /* End of Bus Reset Interrpt Status */
+#define     AT91_UDP_ENDBUSRES (1 << 12)       /* End of Bus Reset Interrupt Status */
 #define     AT91_UDP_WAKEUP    (1 << 13)       /* USB Wakeup Interrupt Status [AT91RM9200 only] */
 
 #define AT91_UDP_ICR           0x20            /* Interrupt Clear Register */
@@ -158,13 +158,7 @@ struct at91_request {
 
 /*-------------------------------------------------------------------------*/
 
-#ifdef DEBUG
-#define DBG(stuff...)          printk(KERN_DEBUG "udc: " stuff)
-#else
-#define DBG(stuff...)          do{}while(0)
-#endif
-
-#ifdef VERBOSE
+#ifdef VERBOSE_DEBUG
 #    define VDBG               DBG
 #else
 #    define VDBG(stuff...)     do{}while(0)
@@ -176,9 +170,10 @@ struct at91_request {
 #    define PACKET(stuff...)   do{}while(0)
 #endif
 
-#define ERR(stuff...)          printk(KERN_ERR "udc: " stuff)
-#define WARN(stuff...)         printk(KERN_WARNING "udc: " stuff)
-#define INFO(stuff...)         printk(KERN_INFO "udc: " stuff)
+#define ERR(stuff...)          pr_err("udc: " stuff)
+#define WARN(stuff...)         pr_warning("udc: " stuff)
+#define INFO(stuff...)         pr_info("udc: " stuff)
+#define DBG(stuff...)          pr_debug("udc: " stuff)
 
 #endif
 
index 4fb5ff469574dd4c944f7a3a1d18713d955a100a..af8b2a3a2d4a3042c1b28783c2254114646a1533 100644 (file)
@@ -1384,8 +1384,7 @@ delegate:
        return retval;
 
 stall:
-       printk(KERN_ERR
-               "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
+       pr_err("udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
                "halting endpoint...\n",
                ep->ep.name, crq->bRequestType, crq->bRequest,
                le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex),
@@ -1456,8 +1455,7 @@ restart:
                                set_protocol_stall(udc, ep);
                        break;
                default:
-                       printk(KERN_ERR
-                               "udc: %s: TXCOMP: Invalid endpoint state %d, "
+                       pr_err("udc: %s: TXCOMP: Invalid endpoint state %d, "
                                "halting endpoint...\n",
                                ep->ep.name, ep->state);
                        set_protocol_stall(udc, ep);
@@ -1486,8 +1484,7 @@ restart:
                default:
                        usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
                        usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
-                       printk(KERN_ERR
-                               "udc: %s: RXRDY: Invalid endpoint state %d, "
+                       pr_err("udc: %s: RXRDY: Invalid endpoint state %d, "
                                "halting endpoint...\n",
                                ep->ep.name, ep->state);
                        set_protocol_stall(udc, ep);
@@ -1532,7 +1529,7 @@ restart:
                pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
                DBG(DBG_HW, "Packet length: %u\n", pkt_len);
                if (pkt_len != sizeof(crq)) {
-                       printk(KERN_WARNING "udc: Invalid packet length %u "
+                       pr_warning("udc: Invalid packet length %u "
                                "(expected %lu)\n", pkt_len, sizeof(crq));
                        set_protocol_stall(udc, ep);
                        return;
index a68304e31a684791d606e1590998b68142f5e948..08bf6f9aaf7ee32ed1cb167da98f42e13fa17c40 100644 (file)
 #define FIFO_IOMEM_ID  0
 #define CTRL_IOMEM_ID  1
 
-#ifdef DEBUG
 #define DBG_ERR                0x0001  /* report all error returns */
 #define DBG_HW         0x0002  /* debug hardware initialization */
 #define DBG_GADGET     0x0004  /* calls to/from gadget driver */
 #define DBG_NONE       0x0000
 
 #define DEBUG_LEVEL    (DBG_ERR)
+
 #define DBG(level, fmt, ...)                                   \
        do {                                                    \
                if ((level) & DEBUG_LEVEL)                      \
-                       printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \
+                       pr_debug("udc: " fmt, ## __VA_ARGS__);  \
        } while (0)
-#else
-#define DBG(level, fmt...)
-#endif
 
 enum usba_ctrl_state {
        WAIT_FOR_SETUP,
index 9db2482bdfa2c5c46618697ba09d8ecc901d1f45..cbe44535c0f0a4520af8b004ff84bad0264e1008 100644 (file)
@@ -61,6 +61,8 @@
 #define DRIVER_DESC    "USB Host+Gadget Emulator"
 #define DRIVER_VERSION "02 May 2005"
 
+#define POWER_BUDGET   500     /* in mA; use 8 for low-power port testing */
+
 static const char      driver_name [] = "dummy_hcd";
 static const char      driver_desc [] = "USB Host+Gadget Emulator";
 
@@ -772,18 +774,17 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
        list_del_init (&dum->ep [0].ep.ep_list);
        INIT_LIST_HEAD(&dum->fifo_req.queue);
 
+       driver->driver.bus = NULL;
        dum->driver = driver;
        dum->gadget.dev.driver = &driver->driver;
        dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
                        driver->driver.name);
-       if ((retval = driver->bind (&dum->gadget)) != 0)
-               goto err_bind_gadget;
-
-       driver->driver.bus = dum->gadget.dev.parent->bus;
-       if ((retval = driver_register (&driver->driver)) != 0)
-               goto err_register;
-       if ((retval = device_bind_driver (&dum->gadget.dev)) != 0)
-               goto err_bind_driver;
+       retval = driver->bind(&dum->gadget);
+       if (retval) {
+               dum->driver = NULL;
+               dum->gadget.dev.driver = NULL;
+               return retval;
+       }
 
        /* khubd will enumerate this in a while */
        spin_lock_irq (&dum->lock);
@@ -793,20 +794,6 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
 
        usb_hcd_poll_rh_status (dummy_to_hcd (dum));
        return 0;
-
-err_bind_driver:
-       driver_unregister (&driver->driver);
-err_register:
-       if (driver->unbind)
-               driver->unbind (&dum->gadget);
-       spin_lock_irq (&dum->lock);
-       dum->pullup = 0;
-       set_link_state (dum);
-       spin_unlock_irq (&dum->lock);
-err_bind_gadget:
-       dum->driver = NULL;
-       dum->gadget.dev.driver = NULL;
-       return retval;
 }
 EXPORT_SYMBOL (usb_gadget_register_driver);
 
@@ -830,11 +817,9 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
        spin_unlock_irqrestore (&dum->lock, flags);
 
        driver->unbind (&dum->gadget);
+       dum->gadget.dev.driver = NULL;
        dum->driver = NULL;
 
-       device_release_driver (&dum->gadget.dev);
-       driver_unregister (&driver->driver);
-
        spin_lock_irqsave (&dum->lock, flags);
        dum->pullup = 0;
        set_link_state (dum);
@@ -1827,8 +1812,7 @@ static int dummy_start (struct usb_hcd *hcd)
 
        INIT_LIST_HEAD (&dum->urbp_list);
 
-       /* only show a low-power port: just 8mA */
-       hcd->power_budget = 8;
+       hcd->power_budget = POWER_BUDGET;
        hcd->state = HC_STATE_RUNNING;
        hcd->uses_new_polling = 1;
 
index 9e732bff9df0608670dcf88b5db1f6d2f5b95ce2..a70e255402b86e60aed06c1e54194909d25b916a 100644 (file)
@@ -1067,19 +1067,19 @@ done:
 
        /* on error, disable any endpoints  */
        if (result < 0) {
-               if (!subset_active(dev))
+               if (!subset_active(dev) && dev->status_ep)
                        (void) usb_ep_disable (dev->status_ep);
                dev->status = NULL;
                (void) usb_ep_disable (dev->in_ep);
                (void) usb_ep_disable (dev->out_ep);
                dev->in = NULL;
                dev->out = NULL;
-       } else
+       }
 
        /* activate non-CDC configs right away
         * this isn't strictly according to the RNDIS spec
         */
-       if (!cdc_active (dev)) {
+       else if (!cdc_active (dev)) {
                netif_carrier_on (dev->net);
                if (netif_running (dev->net)) {
                        spin_unlock (&dev->lock);
index 1d174dcb3ac9e6a4ea5ce8133d6e4519d32d9783..3301167d4f2a9eba4827b818dbaaf67fbf1ddc90 100644 (file)
@@ -275,19 +275,15 @@ MODULE_LICENSE("Dual BSD/GPL");
 
 /*-------------------------------------------------------------------------*/
 
-#ifdef DEBUG
 #define LDBG(lun,fmt,args...) \
        dev_dbg(&(lun)->dev , fmt , ## args)
 #define MDBG(fmt,args...) \
-       printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args)
-#else
-#define LDBG(lun,fmt,args...) \
-       do { } while (0)
-#define MDBG(fmt,args...) \
-       do { } while (0)
+       pr_debug(DRIVER_NAME ": " fmt , ## args)
+
+#ifndef DEBUG
 #undef VERBOSE_DEBUG
 #undef DUMP_MSGS
-#endif /* DEBUG */
+#endif /* !DEBUG */
 
 #ifdef VERBOSE_DEBUG
 #define VLDBG  LDBG
@@ -304,7 +300,7 @@ MODULE_LICENSE("Dual BSD/GPL");
        dev_info(&(lun)->dev , fmt , ## args)
 
 #define MINFO(fmt,args...) \
-       printk(KERN_INFO DRIVER_NAME ": " fmt , ## args)
+       pr_info(DRIVER_NAME ": " fmt , ## args)
 
 #define DBG(d, fmt, args...) \
        dev_dbg(&(d)->gadget->dev , fmt , ## args)
index 038e7d7b4da1c13845ae944f07b5aaeabf27b0ec..63e8fa3a69e19bc55dbb5bc78d53ccc91871016f 100644 (file)
@@ -776,7 +776,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
                VDBG("%s, bad params\n", __FUNCTION__);
                return -EINVAL;
        }
-       if (!_ep || (!ep->desc && ep_index(ep))) {
+       if (unlikely(!_ep || !ep->desc)) {
                VDBG("%s, bad ep\n", __FUNCTION__);
                return -EINVAL;
        }
@@ -1896,7 +1896,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 
        spin_lock_irqsave(&udc->lock, flags);
 
-       /* ------basic driver infomation ---- */
+       /* ------basic driver information ---- */
        t = scnprintf(next, size,
                        DRIVER_DESC "\n"
                        "%s version: %s\n"
index 832ab82b4882c9ad1d4ae7b5eb0e2aaff921c233..9fb0b1ec85266322054422db511f337e53459efd 100644 (file)
@@ -551,9 +551,9 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
 #define VDBG(stuff...) do{}while(0)
 #endif
 
-#define ERR(stuff...)          printk(KERN_ERR "udc: " stuff)
-#define WARN(stuff...)         printk(KERN_WARNING "udc: " stuff)
-#define INFO(stuff...)         printk(KERN_INFO "udc: " stuff)
+#define ERR(stuff...)          pr_err("udc: " stuff)
+#define WARN(stuff...)         pr_warning("udc: " stuff)
+#define INFO(stuff...)         pr_info("udc: " stuff)
 
 /*-------------------------------------------------------------------------*/
 
index 7da7fcb05640b4fdd74597c2dd5cbc2fd5db51d6..5b42ccd0035fee4364d4d8021c0e72814015775a 100644 (file)
@@ -1158,7 +1158,7 @@ static int __devinit gmidi_bind(struct usb_gadget *gadget)
        /* support optional vendor/distro customization */
        if (idVendor) {
                if (!idProduct) {
-                       printk(KERN_ERR "idVendor needs idProduct!\n");
+                       pr_err("idVendor needs idProduct!\n");
                        return -ENODEV;
                }
                device_desc.idVendor = cpu_to_le16(idVendor);
@@ -1190,7 +1190,7 @@ static int __devinit gmidi_bind(struct usb_gadget *gadget)
        in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc);
        if (!in_ep) {
 autoconf_fail:
-               printk(KERN_ERR "%s: can't autoconfigure on %s\n",
+               pr_err("%s: can't autoconfigure on %s\n",
                        shortname, gadget->name);
                return -ENODEV;
        }
@@ -1212,7 +1212,7 @@ autoconf_fail:
                 * it SHOULD NOT have problems with bulk-capable hardware.
                 * so warn about unrecognized controllers, don't panic.
                 */
-               printk(KERN_WARNING "%s: controller '%s' not recognized\n",
+               pr_warning("%s: controller '%s' not recognized\n",
                        shortname, gadget->name);
                device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
        }
index 2ec9d196a8cfdc798232d2d51f1d4aad6686338f..d3e702576de6e23c7aca952bc40cc3288de1dd59 100644 (file)
@@ -1422,6 +1422,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        spin_unlock_irqrestore(&dev->lock, flags);
 
        driver->unbind(&dev->gadget);
+       dev->gadget.dev.driver = NULL;
 
        DBG(dev, "unregistered driver '%s'\n", driver->driver.name);
        return 0;
index 47ef8bd58a00c1f99f9ef8a937801bbd12e0095d..805602a687cbc7bfd2b225d5e247a6f4f8c19cc5 100644 (file)
@@ -1699,7 +1699,7 @@ gadgetfs_bind (struct usb_gadget *gadget)
        if (!dev)
                return -ESRCH;
        if (0 != strcmp (CHIP, gadget->name)) {
-               printk (KERN_ERR "%s expected %s controller not %s\n",
+               pr_err("%s expected %s controller not %s\n",
                        shortname, CHIP, gadget->name);
                return -ENODEV;
        }
index 367b75c0b25b3e8f9a4af753fa9c6cea8578d097..37243ef7104ef7d0f24ff1369c99cf33fcb947c6 100644 (file)
@@ -474,6 +474,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        spin_unlock_irqrestore(&dev->lock, flags);
 
        driver->unbind(&dev->gadget);
+       dev->gadget.dev.driver = NULL;
        device_del(&dev->gadget.dev);
 
        udc_disable(dev);
index ebc5536aa271d8ad78b76dcf701670ee76b1982c..835948f0715a9118f18e90a83fb2e2ff28161895 100644 (file)
@@ -36,9 +36,14 @@ MODULE_DESCRIPTION("M66592 USB gadget driver");
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Yoshihiro Shimoda");
 
-#define DRIVER_VERSION "29 May 2007"
+#define DRIVER_VERSION "18 Oct 2007"
 
 /* module parameters */
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+static unsigned short endian = M66592_LITTLE;
+module_param(endian, ushort, 0644);
+MODULE_PARM_DESC(endian, "data endian: big=0, little=0 (default=0)");
+#else
 static unsigned short clock = M66592_XTAL24;
 module_param(clock, ushort, 0644);
 MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
@@ -56,6 +61,7 @@ static unsigned short irq_sense = M66592_INTL;
 module_param(irq_sense, ushort, 0644);
 MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 "
                "(default=2)");
+#endif
 
 static const char udc_name[] = "m66592_udc";
 static const char *m66592_ep_name[] = {
@@ -141,7 +147,7 @@ static inline u16 control_reg_get_pid(struct m66592 *m66592, u16 pipenum)
                offset = get_pipectr_addr(pipenum);
                pid = m66592_read(m66592, offset) & M66592_PID;
        } else
-               printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum);
+               pr_err("unexpect pipe num (%d)\n", pipenum);
 
        return pid;
 }
@@ -157,7 +163,7 @@ static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum,
                offset = get_pipectr_addr(pipenum);
                m66592_mdfy(m66592, pid, M66592_PID, offset);
        } else
-               printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum);
+               pr_err("unexpect pipe num (%d)\n", pipenum);
 }
 
 static inline void pipe_start(struct m66592 *m66592, u16 pipenum)
@@ -186,7 +192,7 @@ static inline u16 control_reg_get(struct m66592 *m66592, u16 pipenum)
                offset = get_pipectr_addr(pipenum);
                ret = m66592_read(m66592, offset);
        } else
-               printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum);
+               pr_err("unexpect pipe num (%d)\n", pipenum);
 
        return ret;
 }
@@ -203,7 +209,7 @@ static inline void control_reg_sqclr(struct m66592 *m66592, u16 pipenum)
                offset = get_pipectr_addr(pipenum);
                m66592_bset(m66592, M66592_SQCLR, offset);
        } else
-               printk(KERN_ERR "unexpect pipe num(%d)\n", pipenum);
+               pr_err("unexpect pipe num(%d)\n", pipenum);
 }
 
 static inline int get_buffer_size(struct m66592 *m66592, u16 pipenum)
@@ -285,7 +291,7 @@ static int pipe_buffer_setting(struct m66592 *m66592,
                break;
        }
        if (m66592->bi_bufnum > M66592_MAX_BUFNUM) {
-               printk(KERN_ERR "m66592 pipe memory is insufficient(%d)\n",
+               pr_err("m66592 pipe memory is insufficient(%d)\n",
                                m66592->bi_bufnum);
                return -ENOMEM;
        }
@@ -326,7 +332,7 @@ static void pipe_buffer_release(struct m66592 *m66592,
                if (info->type == M66592_BULK)
                        m66592->bulk--;
        } else
-               printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n",
+               pr_err("ep_release: unexpect pipenum (%d)\n",
                                info->pipe);
 }
 
@@ -360,6 +366,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep,
                        ep->fifosel = M66592_D0FIFOSEL;
                        ep->fifoctr = M66592_D0FIFOCTR;
                        ep->fifotrn = M66592_D0FIFOTRN;
+#if !defined(CONFIG_SUPERH_BUILT_IN_M66592)
                } else if (m66592->num_dma == 1) {
                        m66592->num_dma++;
                        ep->use_dma = 1;
@@ -367,6 +374,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep,
                        ep->fifosel = M66592_D1FIFOSEL;
                        ep->fifoctr = M66592_D1FIFOCTR;
                        ep->fifotrn = M66592_D1FIFOTRN;
+#endif
                } else {
                        ep->use_dma = 0;
                        ep->fifoaddr = M66592_CFIFO;
@@ -422,7 +430,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
        case USB_ENDPOINT_XFER_BULK:
                if (m66592->bulk >= M66592_MAX_NUM_BULK) {
                        if (m66592->isochronous >= M66592_MAX_NUM_ISOC) {
-                               printk(KERN_ERR "bulk pipe is insufficient\n");
+                               pr_err("bulk pipe is insufficient\n");
                                return -ENODEV;
                        } else {
                                info.pipe = M66592_BASE_PIPENUM_ISOC
@@ -438,7 +446,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
                break;
        case USB_ENDPOINT_XFER_INT:
                if (m66592->interrupt >= M66592_MAX_NUM_INT) {
-                       printk(KERN_ERR "interrupt pipe is insufficient\n");
+                       pr_err("interrupt pipe is insufficient\n");
                        return -ENODEV;
                }
                info.pipe = M66592_BASE_PIPENUM_INT + m66592->interrupt;
@@ -447,7 +455,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
                break;
        case USB_ENDPOINT_XFER_ISOC:
                if (m66592->isochronous >= M66592_MAX_NUM_ISOC) {
-                       printk(KERN_ERR "isochronous pipe is insufficient\n");
+                       pr_err("isochronous pipe is insufficient\n");
                        return -ENODEV;
                }
                info.pipe = M66592_BASE_PIPENUM_ISOC + m66592->isochronous;
@@ -455,7 +463,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
                counter = &m66592->isochronous;
                break;
        default:
-               printk(KERN_ERR "unexpect xfer type\n");
+               pr_err("unexpect xfer type\n");
                return -EINVAL;
        }
        ep->type = info.type;
@@ -470,7 +478,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
 
        ret = pipe_buffer_setting(m66592, &info);
        if (ret < 0) {
-               printk(KERN_ERR "pipe_buffer_setting fail\n");
+               pr_err("pipe_buffer_setting fail\n");
                return ret;
        }
 
@@ -606,11 +614,33 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req)
                control_end(ep->m66592, 0);
                break;
        default:
-               printk(KERN_ERR "start_ep0: unexpect ctsq(%x)\n", ctsq);
+               pr_err("start_ep0: unexpect ctsq(%x)\n", ctsq);
                break;
        }
 }
 
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+static void init_controller(struct m66592 *m66592)
+{
+       usbf_start_clock();
+       m66592_bset(m66592, M66592_HSE, M66592_SYSCFG);         /* High spd */
+       m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG);
+       m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG);
+       m66592_bset(m66592, M66592_USBE, M66592_SYSCFG);
+
+       /* This is a workaound for SH7722 2nd cut */
+       m66592_bset(m66592, 0x8000, M66592_DVSTCTR);
+       m66592_bset(m66592, 0x1000, M66592_TESTMODE);
+       m66592_bclr(m66592, 0x8000, M66592_DVSTCTR);
+
+       m66592_bset(m66592, M66592_INTL, M66592_INTENB1);
+
+       m66592_write(m66592, 0, M66592_CFBCFG);
+       m66592_write(m66592, 0, M66592_D0FBCFG);
+       m66592_bset(m66592, endian, M66592_CFBCFG);
+       m66592_bset(m66592, endian, M66592_D0FBCFG);
+}
+#else  /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
 static void init_controller(struct m66592 *m66592)
 {
        m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND),
@@ -636,9 +666,13 @@ static void init_controller(struct m66592 *m66592)
        m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR,
                        M66592_DMA0CFG);
 }
+#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
 
 static void disable_controller(struct m66592 *m66592)
 {
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+       usbf_stop_clock();
+#else
        m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG);
        udelay(1);
        m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG);
@@ -646,15 +680,20 @@ static void disable_controller(struct m66592 *m66592)
        m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG);
        udelay(1);
        m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG);
+#endif
 }
 
 static void m66592_start_xclock(struct m66592 *m66592)
 {
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+       usbf_start_clock();
+#else
        u16 tmp;
 
        tmp = m66592_read(m66592, M66592_SYSCFG);
        if (!(tmp & M66592_XCKE))
                m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG);
+#endif
 }
 
 /*-------------------------------------------------------------------------*/
@@ -709,7 +748,7 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
        do {
                tmp = m66592_read(m66592, ep->fifoctr);
                if (i++ > 100000) {
-                       printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus"
+                       pr_err("pipe0 is busy. maybe cpu i/o bus "
                                "conflict. please power off this controller.");
                        return;
                }
@@ -759,7 +798,7 @@ static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req)
        if (unlikely((tmp & M66592_FRDY) == 0)) {
                pipe_stop(m66592, pipenum);
                pipe_irq_disable(m66592, pipenum);
-               printk(KERN_ERR "write fifo not ready. pipnum=%d\n", pipenum);
+               pr_err("write fifo not ready. pipnum=%d\n", pipenum);
                return;
        }
 
@@ -808,7 +847,7 @@ static void irq_packet_read(struct m66592_ep *ep, struct m66592_request *req)
                req->req.status = -EPIPE;
                pipe_stop(m66592, pipenum);
                pipe_irq_disable(m66592, pipenum);
-               printk(KERN_ERR "read fifo not ready");
+               pr_err("read fifo not ready");
                return;
        }
 
@@ -1063,7 +1102,7 @@ static void m66592_update_usb_speed(struct m66592 *m66592)
                break;
        default:
                m66592->gadget.speed = USB_SPEED_UNKNOWN;
-               printk(KERN_ERR "USB speed unknown\n");
+               pr_err("USB speed unknown\n");
        }
 }
 
@@ -1122,7 +1161,7 @@ __acquires(m66592->lock)
                control_end(m66592, 0);
                break;
        default:
-               printk(KERN_ERR "ctrl_stage: unexpect ctsq(%x)\n", ctsq);
+               pr_err("ctrl_stage: unexpect ctsq(%x)\n", ctsq);
                break;
        }
 }
@@ -1142,6 +1181,19 @@ static irqreturn_t m66592_irq(int irq, void *_m66592)
        intsts0 = m66592_read(m66592, M66592_INTSTS0);
        intenb0 = m66592_read(m66592, M66592_INTENB0);
 
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+       if (!intsts0 && !intenb0) {
+               /*
+                * When USB clock stops, it cannot read register. Even if a
+                * clock stops, the interrupt occurs. So this driver turn on
+                * a clock by this timing and do re-reading of register.
+                */
+               m66592_start_xclock(m66592);
+               intsts0 = m66592_read(m66592, M66592_INTSTS0);
+               intenb0 = m66592_read(m66592, M66592_INTENB0);
+       }
+#endif
+
        savepipe = m66592_read(m66592, M66592_CFIFOSEL);
 
        mask0 = intsts0 & intenb0;
@@ -1409,13 +1461,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 
        retval = device_add(&m66592->gadget.dev);
        if (retval) {
-               printk(KERN_ERR "device_add error (%d)\n", retval);
+               pr_err("device_add error (%d)\n", retval);
                goto error;
        }
 
        retval = driver->bind (&m66592->gadget);
        if (retval) {
-               printk(KERN_ERR "bind to driver error (%d)\n", retval);
+               pr_err("bind to driver error (%d)\n", retval);
                device_del(&m66592->gadget.dev);
                goto error;
        }
@@ -1456,6 +1508,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
 
        driver->unbind(&m66592->gadget);
+       m66592->gadget.dev.driver = NULL;
 
        init_controller(m66592);
        disable_controller(m66592);
@@ -1485,6 +1538,7 @@ static int __exit m66592_remove(struct platform_device *pdev)
        iounmap(m66592->reg);
        free_irq(platform_get_irq(pdev, 0), m66592);
        m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
+       usbf_stop_clock();
        kfree(m66592);
        return 0;
 }
@@ -1508,28 +1562,28 @@ static int __init m66592_probe(struct platform_device *pdev)
                        (char *)udc_name);
        if (!res) {
                ret = -ENODEV;
-               printk(KERN_ERR "platform_get_resource_byname error.\n");
+               pr_err("platform_get_resource_byname error.\n");
                goto clean_up;
        }
 
        irq = platform_get_irq(pdev, 0);
        if (irq < 0) {
                ret = -ENODEV;
-               printk(KERN_ERR "platform_get_irq error.\n");
+               pr_err("platform_get_irq error.\n");
                goto clean_up;
        }
 
        reg = ioremap(res->start, resource_len(res));
        if (reg == NULL) {
                ret = -ENOMEM;
-               printk(KERN_ERR "ioremap error.\n");
+               pr_err("ioremap error.\n");
                goto clean_up;
        }
 
        /* initialize ucd */
        m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL);
        if (m66592 == NULL) {
-               printk(KERN_ERR "kzalloc error\n");
+               pr_err("kzalloc error\n");
                goto clean_up;
        }
 
@@ -1555,7 +1609,7 @@ static int __init m66592_probe(struct platform_device *pdev)
        ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED,
                        udc_name, m66592);
        if (ret < 0) {
-               printk(KERN_ERR "request_irq error (%d)\n", ret);
+               pr_err("request_irq error (%d)\n", ret);
                goto clean_up;
        }
 
index bfa0c645f229b97752c5362c8503cf1e8f8e46f3..17b792b7f6bfc43d3879fc316b188f0a12ae36f4 100644 (file)
 #define   M66592_P_TST_J        0x0001         /* PERI TEST J */
 #define   M66592_P_TST_NORMAL   0x0000         /* PERI Normal Mode */
 
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+#define M66592_CFBCFG          0x0A
+#define M66592_D0FBCFG         0x0C
+#define M66592_LITTLE          0x0100  /* b8: Little endian mode */
+#else
 #define M66592_PINCFG          0x0A
 #define M66592_LDRV            0x8000  /* b15: Drive Current Adjust */
 #define M66592_BIGEND          0x0100  /* b8: Big endian mode */
@@ -91,6 +96,7 @@
 #define M66592_PKTM            0x0020  /* b5: Packet mode */
 #define M66592_DENDE           0x0010  /* b4: Dend enable */
 #define M66592_OBUS            0x0004  /* b2: OUTbus mode */
+#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
 
 #define M66592_CFIFO           0x10
 #define M66592_D0FIFO          0x14
 #define M66592_REW             0x4000  /* b14: Buffer rewind */
 #define M66592_DCLRM           0x2000  /* b13: DMA buffer clear mode */
 #define M66592_DREQE           0x1000  /* b12: DREQ output enable */
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+#define M66592_MBW             0x0800  /* b11: Maximum bit width for FIFO */
+#else
 #define M66592_MBW             0x0400  /* b10: Maximum bit width for FIFO */
 #define   M66592_MBW_8          0x0000   /*  8bit */
 #define   M66592_MBW_16                 0x0400   /* 16bit */
+#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
 #define M66592_TRENB           0x0200  /* b9: Transaction counter enable */
 #define M66592_TRCLR           0x0100  /* b8: Transaction counter clear */
 #define M66592_DEZPM           0x0080  /* b7: Zero-length packet mode */
@@ -530,8 +540,13 @@ static inline void m66592_read_fifo(struct m66592 *m66592,
 {
        unsigned long fifoaddr = (unsigned long)m66592->reg + offset;
 
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+       len = (len + 3) / 4;
+       insl(fifoaddr, buf, len);
+#else
        len = (len + 1) / 2;
        insw(fifoaddr, buf, len);
+#endif
 }
 
 static inline void m66592_write(struct m66592 *m66592, u16 val,
@@ -545,6 +560,24 @@ static inline void m66592_write_fifo(struct m66592 *m66592,
                void *buf, unsigned long len)
 {
        unsigned long fifoaddr = (unsigned long)m66592->reg + offset;
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+       unsigned long count;
+       unsigned char *pb;
+       int i;
+
+       count = len / 4;
+       outsl(fifoaddr, buf, count);
+
+       if (len & 0x00000003) {
+               pb = buf + count * 4;
+               for (i = 0; i < (len & 0x00000003); i++) {
+                       if (m66592_read(m66592, M66592_CFBCFG)) /* little */
+                               outb(pb[i], fifoaddr + (3 - i));
+                       else
+                               outb(pb[i], fifoaddr + i);
+               }
+       }
+#else
        unsigned long odd = len & 0x0001;
 
        len = len / 2;
@@ -553,6 +586,7 @@ static inline void m66592_write_fifo(struct m66592 *m66592,
                unsigned char *p = buf + len*2;
                outb(*p, fifoaddr);
        }
+#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
 }
 
 static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
@@ -570,6 +604,26 @@ static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
 #define m66592_bset(m66592, val, offset)       \
                        m66592_mdfy(m66592, val, 0, offset)
 
+#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
+#include <asm/io.h>
+#define MSTPCR2                0xA4150038      /* for SH7722 */
+#define MSTPCR2_USB    0x00000800
+
+static inline void usbf_start_clock(void)
+{
+       ctrl_outl(ctrl_inl(MSTPCR2) & ~MSTPCR2_USB, MSTPCR2);
+}
+
+static inline void usbf_stop_clock(void)
+{
+       ctrl_outl(ctrl_inl(MSTPCR2) | MSTPCR2_USB, MSTPCR2);
+}
+
+#else
+#define usbf_start_clock(x)
+#define usbf_stop_clock(x)
+#endif /* if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
+
 #endif /* ifndef __M66592_UDC_H__ */
 
 
index d5d473f8144b5332a550f07a9ece5df1ab4cc946..33469cf5aec35af86933b39d3781a409ffc9f97c 100644 (file)
@@ -2435,7 +2435,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
                        break;
                default:
 delegate:
-                       VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x"
+                       VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x "
                                "ep_cfg %08x\n",
                                u.r.bRequestType, u.r.bRequest,
                                w_value, w_index, w_length,
index d377154658b5abe624568eabecde914a107caff6..e6d68bda428a850d6d98ac05d06abf83aa604b18 100644 (file)
@@ -4,6 +4,8 @@
  * Copyright (C) 2004 Texas Instruments, Inc.
  * Copyright (C) 2004-2005 David Brownell
  *
+ * OMAP2 & DMA support by Kyungmin Park <kyungmin.park@samsung.com>
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
 /* bulk DMA seems to be behaving for both IN and OUT */
 #define        USE_DMA
 
-/* FIXME: OMAP2 currently has some problem in DMA mode */
-#ifdef CONFIG_ARCH_OMAP2
-#undef USE_DMA
-#endif
-
 /* ISO too */
 #define        USE_ISO
 
@@ -73,6 +70,8 @@
 
 #define        DMA_ADDR_INVALID        (~(dma_addr_t)0)
 
+#define OMAP2_DMA_CH(ch)       (((ch) - 1) << 1)
+#define OMAP24XX_DMA(name, ch) (OMAP24XX_DMA_##name + OMAP2_DMA_CH(ch))
 
 /*
  * The OMAP UDC needs _very_ early endpoint setup:  before enabling the
@@ -571,20 +570,25 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
        const int       sync_mode = cpu_is_omap15xx()
                                ? OMAP_DMA_SYNC_FRAME
                                : OMAP_DMA_SYNC_ELEMENT;
+       int             dma_trigger = 0;
+
+       if (cpu_is_omap24xx())
+               dma_trigger = OMAP24XX_DMA(USB_W2FC_TX0, ep->dma_channel);
 
        /* measure length in either bytes or packets */
        if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC)
+                       || (cpu_is_omap24xx() && length < ep->maxpacket)
                        || (cpu_is_omap15xx() && length < ep->maxpacket)) {
                txdma_ctrl = UDC_TXN_EOT | length;
                omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
-                               length, 1, sync_mode, 0, 0);
+                               length, 1, sync_mode, dma_trigger, 0);
        } else {
                length = min(length / ep->maxpacket,
                                (unsigned) UDC_TXN_TSC + 1);
                txdma_ctrl = length;
                omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
                                ep->ep.maxpacket >> 1, length, sync_mode,
-                               0, 0);
+                               dma_trigger, 0);
                length *= ep->maxpacket;
        }
        omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF,
@@ -622,20 +626,31 @@ static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
 
 static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
 {
-       unsigned packets;
+       unsigned packets = req->req.length - req->req.actual;
+       int dma_trigger = 0;
+
+       if (cpu_is_omap24xx())
+               dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel);
 
        /* NOTE:  we filtered out "short reads" before, so we know
         * the buffer has only whole numbers of packets.
+        * except MODE SELECT(6) sent the 24 bytes data in OMAP24XX DMA mode
         */
-
-       /* set up this DMA transfer, enable the fifo, start */
-       packets = (req->req.length - req->req.actual) / ep->ep.maxpacket;
-       packets = min(packets, (unsigned)UDC_RXN_TC + 1);
-       req->dma_bytes = packets * ep->ep.maxpacket;
-       omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
-                       ep->ep.maxpacket >> 1, packets,
-                       OMAP_DMA_SYNC_ELEMENT,
-                       0, 0);
+       if (cpu_is_omap24xx() && packets < ep->maxpacket) {
+               omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
+                               packets, 1, OMAP_DMA_SYNC_ELEMENT,
+                               dma_trigger, 0);
+               req->dma_bytes = packets;
+       } else {
+               /* set up this DMA transfer, enable the fifo, start */
+               packets /= ep->ep.maxpacket;
+               packets = min(packets, (unsigned)UDC_RXN_TC + 1);
+               req->dma_bytes = packets * ep->ep.maxpacket;
+               omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
+                               ep->ep.maxpacket >> 1, packets,
+                               OMAP_DMA_SYNC_ELEMENT,
+                               dma_trigger, 0);
+       }
        omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
                OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
                0, 0);
@@ -743,6 +758,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
 {
        u16     reg;
        int     status, restart, is_in;
+       int     dma_channel;
 
        is_in = ep->bEndpointAddress & USB_DIR_IN;
        if (is_in)
@@ -769,11 +785,15 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
        ep->dma_channel = channel;
 
        if (is_in) {
-               status = omap_request_dma(OMAP_DMA_USB_W2FC_TX0 - 1 + channel,
+               if (cpu_is_omap24xx())
+                       dma_channel = OMAP24XX_DMA(USB_W2FC_TX0, channel);
+               else
+                       dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel;
+               status = omap_request_dma(dma_channel,
                        ep->ep.name, dma_error, ep, &ep->lch);
                if (status == 0) {
                        UDC_TXDMA_CFG_REG = reg;
-                       /* EMIFF */
+                       /* EMIFF or SDRC */
                        omap_set_dma_src_burst_mode(ep->lch,
                                                OMAP_DMA_DATA_BURST_4);
                        omap_set_dma_src_data_pack(ep->lch, 1);
@@ -785,7 +805,12 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
                                0, 0);
                }
        } else {
-               status = omap_request_dma(OMAP_DMA_USB_W2FC_RX0 - 1 + channel,
+               if (cpu_is_omap24xx())
+                       dma_channel = OMAP24XX_DMA(USB_W2FC_RX0, channel);
+               else
+                       dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel;
+
+               status = omap_request_dma(dma_channel,
                        ep->ep.name, dma_error, ep, &ep->lch);
                if (status == 0) {
                        UDC_RXDMA_CFG_REG = reg;
@@ -795,7 +820,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
                                OMAP_DMA_AMODE_CONSTANT,
                                (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG),
                                0, 0);
-                       /* EMIFF */
+                       /* EMIFF or SDRC */
                        omap_set_dma_dest_burst_mode(ep->lch,
                                                OMAP_DMA_DATA_BURST_4);
                        omap_set_dma_dest_data_pack(ep->lch, 1);
@@ -808,7 +833,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
                omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ);
 
                /* channel type P: hw synch (fifo) */
-               if (!cpu_is_omap15xx())
+               if (cpu_class_is_omap1() && !cpu_is_omap15xx())
                        OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2;
        }
 
@@ -926,11 +951,13 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 
        /* this isn't bogus, but OMAP DMA isn't the only hardware to
         * have a hard time with partial packet reads...  reject it.
+        * Except OMAP2 can handle the small packets.
         */
        if (use_dma
                        && ep->has_dma
                        && ep->bEndpointAddress != 0
                        && (ep->bEndpointAddress & USB_DIR_IN) == 0
+                       && !cpu_class_is_omap2()
                        && (req->req.length % ep->ep.maxpacket) != 0) {
                DBG("%s, no partial packet OUT reads\n", __FUNCTION__);
                return -EMSGSIZE;
@@ -1001,7 +1028,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 
                                /* STATUS for zero length DATA stages is
                                 * always an IN ... even for IN transfers,
-                                * a wierd case which seem to stall OMAP.
+                                * a weird case which seem to stall OMAP.
                                 */
                                UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR);
                                UDC_CTRL_REG = UDC_CLR_EP;
index 1dc398bb9ab2ae408f0d77ee2c24d3d9c966c838..c6b9cbc7230a5bb121feb288dd9ce3228c9f984d 100644 (file)
@@ -182,21 +182,16 @@ struct omap_udc {
 
 /*-------------------------------------------------------------------------*/
 
-#ifdef DEBUG
-#define DBG(stuff...)          printk(KERN_DEBUG "udc: " stuff)
-#else
-#define DBG(stuff...)          do{}while(0)
-#endif
-
 #ifdef VERBOSE
 #    define VDBG               DBG
 #else
 #    define VDBG(stuff...)     do{}while(0)
 #endif
 
-#define ERR(stuff...)          printk(KERN_ERR "udc: " stuff)
-#define WARN(stuff...)         printk(KERN_WARNING "udc: " stuff)
-#define INFO(stuff...)         printk(KERN_INFO "udc: " stuff)
+#define ERR(stuff...)          pr_err("udc: " stuff)
+#define WARN(stuff...)         pr_warning("udc: " stuff)
+#define INFO(stuff...)         pr_info("udc: " stuff)
+#define DBG(stuff...)          pr_debug("udc: " stuff)
 
 /*-------------------------------------------------------------------------*/
 
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
new file mode 100644 (file)
index 0000000..9fdabc8
--- /dev/null
@@ -0,0 +1,1592 @@
+/*
+ * printer.c -- Printer gadget driver
+ *
+ * Copyright (C) 2003-2005 David Brownell
+ * Copyright (C) 2006 Craig W. Nadler
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/list.h>
+#include <linux/interrupt.h>
+#include <linux/utsname.h>
+#include <linux/device.h>
+#include <linux/moduleparam.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
+#include <linux/types.h>
+#include <linux/ctype.h>
+#include <linux/cdev.h>
+
+#include <asm/byteorder.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <asm/system.h>
+#include <linux/uaccess.h>
+#include <asm/unaligned.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/g_printer.h>
+
+#include "gadget_chips.h"
+
+#define DRIVER_DESC            "Printer Gadget"
+#define DRIVER_VERSION         "2007 OCT 06"
+
+static const char shortname [] = "printer";
+static const char driver_desc [] = DRIVER_DESC;
+
+static dev_t g_printer_devno;
+
+static struct class *usb_gadget_class;
+
+/*-------------------------------------------------------------------------*/
+
+struct printer_dev {
+       spinlock_t              lock;           /* lock this structure */
+       /* lock buffer lists during read/write calls */
+       spinlock_t              lock_printer_io;
+       struct usb_gadget       *gadget;
+       struct usb_request      *req;           /* for control responses */
+       u8                      config;
+       s8                      interface;
+       struct usb_ep           *in_ep, *out_ep;
+       const struct usb_endpoint_descriptor
+                               *in, *out;
+       struct list_head        rx_reqs;        /* List of free RX structs */
+       struct list_head        rx_reqs_active; /* List of Active RX xfers */
+       struct list_head        rx_buffers;     /* List of completed xfers */
+       /* wait until there is data to be read. */
+       wait_queue_head_t       rx_wait;
+       struct list_head        tx_reqs;        /* List of free TX structs */
+       struct list_head        tx_reqs_active; /* List of Active TX xfers */
+       /* Wait until there are write buffers available to use. */
+       wait_queue_head_t       tx_wait;
+       /* Wait until all write buffers have been sent. */
+       wait_queue_head_t       tx_flush_wait;
+       struct usb_request      *current_rx_req;
+       size_t                  current_rx_bytes;
+       u8                      *current_rx_buf;
+       u8                      printer_status;
+       u8                      reset_printer;
+       struct class_device     *printer_class_dev;
+       struct cdev             printer_cdev;
+       struct device           *pdev;
+       u8                      printer_cdev_open;
+       wait_queue_head_t       wait;
+};
+
+static struct printer_dev usb_printer_gadget;
+
+/*-------------------------------------------------------------------------*/
+
+/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!!  Ever!!
+ * Instead:  allocate your own, using normal USB-IF procedures.
+ */
+
+/* Thanks to NetChip Technologies for donating this product ID.
+ */
+#define PRINTER_VENDOR_NUM     0x0525          /* NetChip */
+#define PRINTER_PRODUCT_NUM    0xa4a8          /* Linux-USB Printer Gadget */
+
+/* Some systems will want different product identifers published in the
+ * device descriptor, either numbers or strings or both.  These string
+ * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
+ */
+
+static ushort __initdata idVendor;
+module_param(idVendor, ushort, S_IRUGO);
+MODULE_PARM_DESC(idVendor, "USB Vendor ID");
+
+static ushort __initdata idProduct;
+module_param(idProduct, ushort, S_IRUGO);
+MODULE_PARM_DESC(idProduct, "USB Product ID");
+
+static ushort __initdata bcdDevice;
+module_param(bcdDevice, ushort, S_IRUGO);
+MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
+
+static char *__initdata iManufacturer;
+module_param(iManufacturer, charp, S_IRUGO);
+MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
+
+static char *__initdata iProduct;
+module_param(iProduct, charp, S_IRUGO);
+MODULE_PARM_DESC(iProduct, "USB Product string");
+
+static char *__initdata iSerialNum;
+module_param(iSerialNum, charp, S_IRUGO);
+MODULE_PARM_DESC(iSerialNum, "1");
+
+static char *__initdata iPNPstring;
+module_param(iPNPstring, charp, S_IRUGO);
+MODULE_PARM_DESC(iPNPstring, "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;");
+
+/* Number of requests to allocate per endpoint, not used for ep0. */
+static unsigned qlen = 10;
+module_param(qlen, uint, S_IRUGO|S_IWUSR);
+
+#define QLEN   qlen
+
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+#define DEVSPEED       USB_SPEED_HIGH
+#else   /* full speed (low speed doesn't do bulk) */
+#define DEVSPEED        USB_SPEED_FULL
+#endif
+
+/*-------------------------------------------------------------------------*/
+
+#define xprintk(d, level, fmt, args...) \
+       printk(level "%s: " fmt, DRIVER_DESC, ## args)
+
+#ifdef DEBUG
+#define DBG(dev, fmt, args...) \
+       xprintk(dev, KERN_DEBUG, fmt, ## args)
+#else
+#define DBG(dev, fmt, args...) \
+       do { } while (0)
+#endif /* DEBUG */
+
+#ifdef VERBOSE
+#define VDBG(dev, fmt, args...) \
+       xprintk(dev, KERN_DEBUG, fmt, ## args)
+#else
+#define VDBG(dev, fmt, args...) \
+       do { } while (0)
+#endif /* VERBOSE */
+
+#define ERROR(dev, fmt, args...) \
+       xprintk(dev, KERN_ERR, fmt, ## args)
+#define WARN(dev, fmt, args...) \
+       xprintk(dev, KERN_WARNING, fmt, ## args)
+#define INFO(dev, fmt, args...) \
+       xprintk(dev, KERN_INFO, fmt, ## args)
+
+/*-------------------------------------------------------------------------*/
+
+/* USB DRIVER HOOKUP (to the hardware driver, below us), mostly
+ * ep0 implementation:  descriptors, config management, setup().
+ * also optional class-specific notification interrupt transfer.
+ */
+
+/*
+ * DESCRIPTORS ... most are static, but strings and (full) configuration
+ * descriptors are built on demand.
+ */
+
+#define STRING_MANUFACTURER            1
+#define STRING_PRODUCT                 2
+#define STRING_SERIALNUM               3
+
+/* holds our biggest descriptor */
+#define USB_DESC_BUFSIZE               256
+#define USB_BUFSIZE                    8192
+
+/* This device advertises one configuration. */
+#define DEV_CONFIG_VALUE               1
+#define        PRINTER_INTERFACE               0
+
+static struct usb_device_descriptor device_desc = {
+       .bLength =              sizeof device_desc,
+       .bDescriptorType =      USB_DT_DEVICE,
+       .bcdUSB =               __constant_cpu_to_le16(0x0200),
+       .bDeviceClass =         USB_CLASS_PER_INTERFACE,
+       .bDeviceSubClass =      0,
+       .bDeviceProtocol =      0,
+       .idVendor =             __constant_cpu_to_le16(PRINTER_VENDOR_NUM),
+       .idProduct =            __constant_cpu_to_le16(PRINTER_PRODUCT_NUM),
+       .iManufacturer =        STRING_MANUFACTURER,
+       .iProduct =             STRING_PRODUCT,
+       .iSerialNumber =        STRING_SERIALNUM,
+       .bNumConfigurations =   1
+};
+
+static struct usb_otg_descriptor otg_desc = {
+       .bLength =              sizeof otg_desc,
+       .bDescriptorType =      USB_DT_OTG,
+       .bmAttributes =         USB_OTG_SRP
+};
+
+static struct usb_config_descriptor config_desc = {
+       .bLength =              sizeof config_desc,
+       .bDescriptorType =      USB_DT_CONFIG,
+
+       /* compute wTotalLength on the fly */
+       .bNumInterfaces =       1,
+       .bConfigurationValue =  DEV_CONFIG_VALUE,
+       .iConfiguration =       0,
+       .bmAttributes =         USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
+       .bMaxPower =            1       /* Self-Powered */
+};
+
+static struct usb_interface_descriptor intf_desc = {
+       .bLength =              sizeof intf_desc,
+       .bDescriptorType =      USB_DT_INTERFACE,
+       .bInterfaceNumber =     PRINTER_INTERFACE,
+       .bNumEndpoints =        2,
+       .bInterfaceClass =      USB_CLASS_PRINTER,
+       .bInterfaceSubClass =   1,      /* Printer Sub-Class */
+       .bInterfaceProtocol =   2,      /* Bi-Directional */
+       .iInterface =           0
+};
+
+static struct usb_endpoint_descriptor fs_ep_in_desc = {
+       .bLength =              USB_DT_ENDPOINT_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bEndpointAddress =     USB_DIR_IN,
+       .bmAttributes =         USB_ENDPOINT_XFER_BULK
+};
+
+static struct usb_endpoint_descriptor fs_ep_out_desc = {
+       .bLength =              USB_DT_ENDPOINT_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bEndpointAddress =     USB_DIR_OUT,
+       .bmAttributes =         USB_ENDPOINT_XFER_BULK
+};
+
+static const struct usb_descriptor_header *fs_printer_function [11] = {
+       (struct usb_descriptor_header *) &otg_desc,
+       (struct usb_descriptor_header *) &intf_desc,
+       (struct usb_descriptor_header *) &fs_ep_in_desc,
+       (struct usb_descriptor_header *) &fs_ep_out_desc,
+       NULL
+};
+
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+
+/*
+ * usb 2.0 devices need to expose both high speed and full speed
+ * descriptors, unless they only run at full speed.
+ */
+
+static struct usb_endpoint_descriptor hs_ep_in_desc = {
+       .bLength =              USB_DT_ENDPOINT_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
+       .wMaxPacketSize =       __constant_cpu_to_le16(512)
+};
+
+static struct usb_endpoint_descriptor hs_ep_out_desc = {
+       .bLength =              USB_DT_ENDPOINT_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
+       .wMaxPacketSize =       __constant_cpu_to_le16(512)
+};
+
+static struct usb_qualifier_descriptor dev_qualifier = {
+       .bLength =              sizeof dev_qualifier,
+       .bDescriptorType =      USB_DT_DEVICE_QUALIFIER,
+       .bcdUSB =               __constant_cpu_to_le16(0x0200),
+       .bDeviceClass =         USB_CLASS_PRINTER,
+       .bNumConfigurations =   1
+};
+
+static const struct usb_descriptor_header *hs_printer_function [11] = {
+       (struct usb_descriptor_header *) &otg_desc,
+       (struct usb_descriptor_header *) &intf_desc,
+       (struct usb_descriptor_header *) &hs_ep_in_desc,
+       (struct usb_descriptor_header *) &hs_ep_out_desc,
+       NULL
+};
+
+/* maxpacket and other transfer characteristics vary by speed. */
+#define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs))
+
+#else
+
+/* if there's no high speed support, maxpacket doesn't change. */
+#define ep_desc(g, hs, fs) (((void)(g)), (fs))
+
+#endif /* !CONFIG_USB_GADGET_DUALSPEED */
+
+/*-------------------------------------------------------------------------*/
+
+/* descriptors that are built on-demand */
+
+static char                            manufacturer [50];
+static char                            product_desc [40] = DRIVER_DESC;
+static char                            serial_num [40] = "1";
+static char                            pnp_string [1024] =
+       "XXMFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;";
+
+/* static strings, in UTF-8 */
+static struct usb_string               strings [] = {
+       { STRING_MANUFACTURER,  manufacturer, },
+       { STRING_PRODUCT,       product_desc, },
+       { STRING_SERIALNUM,     serial_num, },
+       {  }            /* end of list */
+};
+
+static struct usb_gadget_strings       stringtab = {
+       .language       = 0x0409,       /* en-us */
+       .strings        = strings,
+};
+
+/*-------------------------------------------------------------------------*/
+
+static struct usb_request *
+printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags)
+{
+       struct usb_request      *req;
+
+       req = usb_ep_alloc_request(ep, gfp_flags);
+
+       if (req != NULL) {
+               req->length = len;
+               req->buf = kmalloc(len, gfp_flags);
+               if (req->buf == NULL) {
+                       usb_ep_free_request(ep, req);
+                       return NULL;
+               }
+       }
+
+       return req;
+}
+
+static void
+printer_req_free(struct usb_ep *ep, struct usb_request *req)
+{
+       if (ep != NULL && req != NULL) {
+               kfree(req->buf);
+               usb_ep_free_request(ep, req);
+       }
+}
+
+/*-------------------------------------------------------------------------*/
+
+static void rx_complete(struct usb_ep *ep, struct usb_request *req)
+{
+       struct printer_dev      *dev = ep->driver_data;
+       int                     status = req->status;
+       unsigned long           flags;
+
+       spin_lock_irqsave(&dev->lock, flags);
+
+       list_del_init(&req->list);      /* Remode from Active List */
+
+       switch (status) {
+
+       /* normal completion */
+       case 0:
+               list_add_tail(&req->list, &dev->rx_buffers);
+               wake_up_interruptible(&dev->rx_wait);
+               DBG(dev, "G_Printer : rx length %d\n", req->actual);
+               break;
+
+       /* software-driven interface shutdown */
+       case -ECONNRESET:               /* unlink */
+       case -ESHUTDOWN:                /* disconnect etc */
+               VDBG(dev, "rx shutdown, code %d\n", status);
+               list_add(&req->list, &dev->rx_reqs);
+               break;
+
+       /* for hardware automagic (such as pxa) */
+       case -ECONNABORTED:             /* endpoint reset */
+               DBG(dev, "rx %s reset\n", ep->name);
+               list_add(&req->list, &dev->rx_reqs);
+               break;
+
+       /* data overrun */
+       case -EOVERFLOW:
+               /* FALLTHROUGH */
+
+       default:
+               DBG(dev, "rx status %d\n", status);
+               list_add(&req->list, &dev->rx_reqs);
+               break;
+       }
+       spin_unlock_irqrestore(&dev->lock, flags);
+}
+
+static void tx_complete(struct usb_ep *ep, struct usb_request *req)
+{
+       struct printer_dev      *dev = ep->driver_data;
+
+       switch (req->status) {
+       default:
+               VDBG(dev, "tx err %d\n", req->status);
+               /* FALLTHROUGH */
+       case -ECONNRESET:               /* unlink */
+       case -ESHUTDOWN:                /* disconnect etc */
+               break;
+       case 0:
+               break;
+       }
+
+       spin_lock(&dev->lock);
+       /* Take the request struct off the active list and put it on the
+        * free list.
+        */
+       list_del_init(&req->list);
+       list_add(&req->list, &dev->tx_reqs);
+       wake_up_interruptible(&dev->tx_wait);
+       if (likely(list_empty(&dev->tx_reqs_active)))
+               wake_up_interruptible(&dev->tx_flush_wait);
+
+       spin_unlock(&dev->lock);
+}
+
+/*-------------------------------------------------------------------------*/
+
+static int
+printer_open(struct inode *inode, struct file *fd)
+{
+       struct printer_dev      *dev;
+       unsigned long           flags;
+       int                     ret = -EBUSY;
+
+       dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev);
+
+       spin_lock_irqsave(&dev->lock, flags);
+
+       if (!dev->printer_cdev_open) {
+               dev->printer_cdev_open = 1;
+               fd->private_data = dev;
+               ret = 0;
+               /* Change the printer status to show that it's on-line. */
+               dev->printer_status |= PRINTER_SELECTED;
+       }
+
+       spin_unlock_irqrestore(&dev->lock, flags);
+
+       DBG(dev, "printer_open returned %x\n", ret);
+
+       return ret;
+}
+
+static int
+printer_close(struct inode *inode, struct file *fd)
+{
+       struct printer_dev      *dev = fd->private_data;
+       unsigned long           flags;
+
+       spin_lock_irqsave(&dev->lock, flags);
+       dev->printer_cdev_open = 0;
+       fd->private_data = NULL;
+       /* Change printer status to show that the printer is off-line. */
+       dev->printer_status &= ~PRINTER_SELECTED;
+       spin_unlock_irqrestore(&dev->lock, flags);
+
+       DBG(dev, "printer_close\n");
+
+       return 0;
+}
+
+static ssize_t
+printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
+{
+       struct printer_dev              *dev = fd->private_data;
+       unsigned long                   flags;
+       size_t                          size;
+       size_t                          bytes_copied;
+       struct usb_request              *req;
+       /* This is a pointer to the current USB rx request. */
+       struct usb_request              *current_rx_req;
+       /* This is the number of bytes in the current rx buffer. */
+       size_t                          current_rx_bytes;
+       /* This is a pointer to the current rx buffer. */
+       u8                              *current_rx_buf;
+
+       if (len == 0)
+               return -EINVAL;
+
+       DBG(dev, "printer_read trying to read %d bytes\n", (int)len);
+
+       spin_lock(&dev->lock_printer_io);
+       spin_lock_irqsave(&dev->lock, flags);
+
+       /* We will use this flag later to check if a printer reset happened
+        * after we turn interrupts back on.
+        */
+       dev->reset_printer = 0;
+
+       while (likely(!list_empty(&dev->rx_reqs))) {
+               int error;
+
+               req = container_of(dev->rx_reqs.next,
+                               struct usb_request, list);
+               list_del_init(&req->list);
+
+               /* The USB Host sends us whatever amount of data it wants to
+                * so we always set the length field to the full USB_BUFSIZE.
+                * If the amount of data is more than the read() caller asked
+                * for it will be stored in the request buffer until it is
+                * asked for by read().
+                */
+               req->length = USB_BUFSIZE;
+               req->complete = rx_complete;
+
+               error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
+               if (error) {
+                       DBG(dev, "rx submit --> %d\n", error);
+                       list_add(&req->list, &dev->rx_reqs);
+                       break;
+               } else {
+                       list_add(&req->list, &dev->rx_reqs_active);
+               }
+       }
+
+       bytes_copied = 0;
+       current_rx_req = dev->current_rx_req;
+       current_rx_bytes = dev->current_rx_bytes;
+       current_rx_buf = dev->current_rx_buf;
+       dev->current_rx_req = NULL;
+       dev->current_rx_bytes = 0;
+       dev->current_rx_buf = NULL;
+
+       /* Check if there is any data in the read buffers. Please note that
+        * current_rx_bytes is the number of bytes in the current rx buffer.
+        * If it is zero then check if there are any other rx_buffers that
+        * are on the completed list. We are only out of data if all rx
+        * buffers are empty.
+        */
+       if ((current_rx_bytes == 0) &&
+                       (likely(list_empty(&dev->rx_buffers)))) {
+               /* Turn interrupts back on before sleeping. */
+               spin_unlock_irqrestore(&dev->lock, flags);
+
+               /*
+                * If no data is available check if this is a NON-Blocking
+                * call or not.
+                */
+               if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
+                       spin_unlock(&dev->lock_printer_io);
+                       return -EAGAIN;
+               }
+
+               /* Sleep until data is available */
+               wait_event_interruptible(dev->rx_wait,
+                               (likely(!list_empty(&dev->rx_buffers))));
+               spin_lock_irqsave(&dev->lock, flags);
+       }
+
+       /* We have data to return then copy it to the caller's buffer.*/
+       while ((current_rx_bytes || likely(!list_empty(&dev->rx_buffers)))
+                       && len) {
+               if (current_rx_bytes == 0) {
+                       req = container_of(dev->rx_buffers.next,
+                                       struct usb_request, list);
+                       list_del_init(&req->list);
+
+                       if (req->actual && req->buf) {
+                               current_rx_req = req;
+                               current_rx_bytes = req->actual;
+                               current_rx_buf = req->buf;
+                       } else {
+                               list_add(&req->list, &dev->rx_reqs);
+                               continue;
+                       }
+               }
+
+               /* Don't leave irqs off while doing memory copies */
+               spin_unlock_irqrestore(&dev->lock, flags);
+
+               if (len > current_rx_bytes)
+                       size = current_rx_bytes;
+               else
+                       size = len;
+
+               size -= copy_to_user(buf, current_rx_buf, size);
+               bytes_copied += size;
+               len -= size;
+               buf += size;
+
+               spin_lock_irqsave(&dev->lock, flags);
+
+               /* We've disconnected or reset free the req and buffer */
+               if (dev->reset_printer) {
+                       printer_req_free(dev->out_ep, current_rx_req);
+                       spin_unlock_irqrestore(&dev->lock, flags);
+                       spin_unlock(&dev->lock_printer_io);
+                       return -EAGAIN;
+               }
+
+               /* If we not returning all the data left in this RX request
+                * buffer then adjust the amount of data left in the buffer.
+                * Othewise if we are done with this RX request buffer then
+                * requeue it to get any incoming data from the USB host.
+                */
+               if (size < current_rx_bytes) {
+                       current_rx_bytes -= size;
+                       current_rx_buf += size;
+               } else {
+                       list_add(&current_rx_req->list, &dev->rx_reqs);
+                       current_rx_bytes = 0;
+                       current_rx_buf = NULL;
+                       current_rx_req = NULL;
+               }
+       }
+
+       dev->current_rx_req = current_rx_req;
+       dev->current_rx_bytes = current_rx_bytes;
+       dev->current_rx_buf = current_rx_buf;
+
+       spin_unlock_irqrestore(&dev->lock, flags);
+       spin_unlock(&dev->lock_printer_io);
+
+       DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied);
+
+       if (bytes_copied)
+               return bytes_copied;
+       else
+               return -EAGAIN;
+}
+
+static ssize_t
+printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
+{
+       struct printer_dev      *dev = fd->private_data;
+       unsigned long           flags;
+       size_t                  size;   /* Amount of data in a TX request. */
+       size_t                  bytes_copied = 0;
+       struct usb_request      *req;
+
+       DBG(dev, "printer_write trying to send %d bytes\n", (int)len);
+
+       if (len == 0)
+               return -EINVAL;
+
+       spin_lock(&dev->lock_printer_io);
+       spin_lock_irqsave(&dev->lock, flags);
+
+       /* Check if a printer reset happens while we have interrupts on */
+       dev->reset_printer = 0;
+
+       /* Check if there is any available write buffers */
+       if (likely(list_empty(&dev->tx_reqs))) {
+               /* Turn interrupts back on before sleeping. */
+               spin_unlock_irqrestore(&dev->lock, flags);
+
+               /*
+                * If write buffers are available check if this is
+                * a NON-Blocking call or not.
+                */
+               if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
+                       spin_unlock(&dev->lock_printer_io);
+                       return -EAGAIN;
+               }
+
+               /* Sleep until a write buffer is available */
+               wait_event_interruptible(dev->tx_wait,
+                               (likely(!list_empty(&dev->tx_reqs))));
+               spin_lock_irqsave(&dev->lock, flags);
+       }
+
+       while (likely(!list_empty(&dev->tx_reqs)) && len) {
+
+               if (len > USB_BUFSIZE)
+                       size = USB_BUFSIZE;
+               else
+                       size = len;
+
+               req = container_of(dev->tx_reqs.next, struct usb_request,
+                               list);
+               list_del_init(&req->list);
+
+               req->complete = tx_complete;
+               req->length = size;
+
+               /* Check if we need to send a zero length packet. */
+               if (len > size)
+                       /* They will be more TX requests so no yet. */
+                       req->zero = 0;
+               else
+                       /* If the data amount is not a multple of the
+                        * maxpacket size then send a zero length packet.
+                        */
+                       req->zero = ((len % dev->in_ep->maxpacket) == 0);
+
+               /* Don't leave irqs off while doing memory copies */
+               spin_unlock_irqrestore(&dev->lock, flags);
+
+               if (copy_from_user(req->buf, buf, size)) {
+                       list_add(&req->list, &dev->tx_reqs);
+                       spin_unlock(&dev->lock_printer_io);
+                       return bytes_copied;
+               }
+
+               bytes_copied += size;
+               len -= size;
+               buf += size;
+
+               spin_lock_irqsave(&dev->lock, flags);
+
+               /* We've disconnected or reset so free the req and buffer */
+               if (dev->reset_printer) {
+                       printer_req_free(dev->in_ep, req);
+                       spin_unlock_irqrestore(&dev->lock, flags);
+                       spin_unlock(&dev->lock_printer_io);
+                       return -EAGAIN;
+               }
+
+               if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) {
+                       list_add(&req->list, &dev->tx_reqs);
+                       spin_unlock_irqrestore(&dev->lock, flags);
+                       spin_unlock(&dev->lock_printer_io);
+                       return -EAGAIN;
+               }
+
+               list_add(&req->list, &dev->tx_reqs_active);
+
+       }
+
+       spin_unlock_irqrestore(&dev->lock, flags);
+       spin_unlock(&dev->lock_printer_io);
+
+       DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied);
+
+       if (bytes_copied) {
+               return bytes_copied;
+       } else {
+               return -EAGAIN;
+       }
+}
+
+static int
+printer_fsync(struct file *fd, struct dentry *dentry, int datasync)
+{
+       struct printer_dev      *dev = fd->private_data;
+       unsigned long           flags;
+       int                     tx_list_empty;
+
+       spin_lock_irqsave(&dev->lock, flags);
+       tx_list_empty = (likely(list_empty(&dev->tx_reqs)));
+       spin_unlock_irqrestore(&dev->lock, flags);
+
+       if (!tx_list_empty) {
+               /* Sleep until all data has been sent */
+               wait_event_interruptible(dev->tx_flush_wait,
+                               (likely(list_empty(&dev->tx_reqs_active))));
+       }
+
+       return 0;
+}
+
+static unsigned int
+printer_poll(struct file *fd, poll_table *wait)
+{
+       struct printer_dev      *dev = fd->private_data;
+       unsigned long           flags;
+       int                     status = 0;
+
+       poll_wait(fd, &dev->rx_wait, wait);
+       poll_wait(fd, &dev->tx_wait, wait);
+
+       spin_lock_irqsave(&dev->lock, flags);
+       if (likely(!list_empty(&dev->tx_reqs)))
+               status |= POLLOUT | POLLWRNORM;
+
+       if (likely(!list_empty(&dev->rx_buffers)))
+               status |= POLLIN | POLLRDNORM;
+
+       spin_unlock_irqrestore(&dev->lock, flags);
+
+       return status;
+}
+
+static int
+printer_ioctl(struct inode *inode, struct file *fd, unsigned int code,
+               unsigned long arg)
+{
+       struct printer_dev      *dev = fd->private_data;
+       unsigned long           flags;
+       int                     status = 0;
+
+       DBG(dev, "printer_ioctl: cmd=0x%4.4x, arg=%lu\n", code, arg);
+
+       /* handle ioctls */
+
+       spin_lock_irqsave(&dev->lock, flags);
+
+       switch (code) {
+       case GADGET_GET_PRINTER_STATUS:
+               status = (int)dev->printer_status;
+               break;
+       case GADGET_SET_PRINTER_STATUS:
+               dev->printer_status = (u8)arg;
+               break;
+       default:
+               /* could not handle ioctl */
+               DBG(dev, "printer_ioctl: ERROR cmd=0x%4.4xis not supported\n",
+                               code);
+               status = -ENOTTY;
+       }
+
+       spin_unlock_irqrestore(&dev->lock, flags);
+
+       return status;
+}
+
+/* used after endpoint configuration */
+static struct file_operations printer_io_operations = {
+       .owner =        THIS_MODULE,
+       .open =         printer_open,
+       .read =         printer_read,
+       .write =        printer_write,
+       .fsync =        printer_fsync,
+       .poll =         printer_poll,
+       .ioctl =        printer_ioctl,
+       .release =      printer_close
+};
+
+/*-------------------------------------------------------------------------*/
+
+static int
+set_printer_interface(struct printer_dev *dev)
+{
+       int                     result = 0;
+
+       dev->in = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc);
+       dev->in_ep->driver_data = dev;
+
+       dev->out = ep_desc(dev->gadget, &hs_ep_out_desc, &fs_ep_out_desc);
+       dev->out_ep->driver_data = dev;
+
+       result = usb_ep_enable(dev->in_ep, dev->in);
+       if (result != 0) {
+               DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
+               goto done;
+       }
+
+       result = usb_ep_enable(dev->out_ep, dev->out);
+       if (result != 0) {
+               DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
+               goto done;
+       }
+
+done:
+       /* on error, disable any endpoints  */
+       if (result != 0) {
+               (void) usb_ep_disable(dev->in_ep);
+               (void) usb_ep_disable(dev->out_ep);
+               dev->in = NULL;
+               dev->out = NULL;
+       }
+
+       /* caller is responsible for cleanup on error */
+       return result;
+}
+
+static void printer_reset_interface(struct printer_dev *dev)
+{
+       if (dev->interface < 0)
+               return;
+
+       DBG(dev, "%s\n", __FUNCTION__);
+
+       if (dev->in)
+               usb_ep_disable(dev->in_ep);
+
+       if (dev->out)
+               usb_ep_disable(dev->out_ep);
+
+       dev->interface = -1;
+}
+
+/* change our operational config.  must agree with the code
+ * that returns config descriptors, and altsetting code.
+ */
+static int
+printer_set_config(struct printer_dev *dev, unsigned number)
+{
+       int                     result = 0;
+       struct usb_gadget       *gadget = dev->gadget;
+
+       if (gadget_is_sa1100(gadget) && dev->config) {
+               /* tx fifo is full, but we can't clear it...*/
+               INFO(dev, "can't change configurations\n");
+               return -ESPIPE;
+       }
+
+       switch (number) {
+       case DEV_CONFIG_VALUE:
+               result = 0;
+               break;
+       default:
+               result = -EINVAL;
+               /* FALL THROUGH */
+       case 0:
+               break;
+       }
+
+       if (result) {
+               usb_gadget_vbus_draw(dev->gadget,
+                               dev->gadget->is_otg ? 8 : 100);
+       } else {
+               char *speed;
+               unsigned power;
+
+               power = 2 * config_desc.bMaxPower;
+               usb_gadget_vbus_draw(dev->gadget, power);
+
+               switch (gadget->speed) {
+               case USB_SPEED_FULL:    speed = "full"; break;
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+               case USB_SPEED_HIGH:    speed = "high"; break;
+#endif
+               default:                speed = "?"; break;
+               }
+
+               dev->config = number;
+               INFO(dev, "%s speed config #%d: %d mA, %s\n",
+                               speed, number, power, driver_desc);
+       }
+       return result;
+}
+
+static int
+config_buf(enum usb_device_speed speed, u8 *buf, u8 type, unsigned index,
+               int is_otg)
+{
+       int                                     len;
+       const struct usb_descriptor_header      **function;
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+       int                                     hs = (speed == USB_SPEED_HIGH);
+
+       if (type == USB_DT_OTHER_SPEED_CONFIG)
+               hs = !hs;
+
+       if (hs) {
+               function = hs_printer_function;
+       } else {
+               function = fs_printer_function;
+       }
+#else
+       function = fs_printer_function;
+#endif
+
+       if (index >= device_desc.bNumConfigurations)
+               return -EINVAL;
+
+       /* for now, don't advertise srp-only devices */
+       if (!is_otg)
+               function++;
+
+       len = usb_gadget_config_buf(&config_desc, buf, USB_DESC_BUFSIZE,
+                       function);
+       if (len < 0)
+               return len;
+       ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
+       return len;
+}
+
+/* Change our operational Interface. */
+static int
+set_interface(struct printer_dev *dev, unsigned number)
+{
+       int                     result = 0;
+
+       if (gadget_is_sa1100(dev->gadget) && dev->interface < 0) {
+               /* tx fifo is full, but we can't clear it...*/
+               INFO(dev, "can't change interfaces\n");
+               return -ESPIPE;
+       }
+
+       /* Free the current interface */
+       switch (dev->interface) {
+       case PRINTER_INTERFACE:
+               printer_reset_interface(dev);
+               break;
+       }
+
+       switch (number) {
+       case PRINTER_INTERFACE:
+               result = set_printer_interface(dev);
+               if (result) {
+                       printer_reset_interface(dev);
+               } else {
+                       dev->interface = PRINTER_INTERFACE;
+               }
+               break;
+       default:
+               result = -EINVAL;
+               /* FALL THROUGH */
+       }
+
+       if (!result)
+               INFO(dev, "Using interface %x\n", number);
+
+       return result;
+}
+
+static void printer_setup_complete(struct usb_ep *ep, struct usb_request *req)
+{
+       if (req->status || req->actual != req->length)
+               DBG((struct printer_dev *) ep->driver_data,
+                               "setup complete --> %d, %d/%d\n",
+                               req->status, req->actual, req->length);
+}
+
+static void printer_soft_reset(struct printer_dev *dev)
+{
+       struct usb_request      *req;
+
+       INFO(dev, "Received Printer Reset Request\n");
+
+       if (usb_ep_disable(dev->in_ep))
+               DBG(dev, "Failed to disable USB in_ep\n");
+       if (usb_ep_disable(dev->out_ep))
+               DBG(dev, "Failed to disable USB out_ep\n");
+
+       if (dev->current_rx_req != NULL) {
+               list_add(&dev->current_rx_req->list, &dev->rx_reqs);
+               dev->current_rx_req = NULL;
+       }
+       dev->current_rx_bytes = 0;
+       dev->current_rx_buf = NULL;
+       dev->reset_printer = 1;
+
+       while (likely(!(list_empty(&dev->rx_buffers)))) {
+               req = container_of(dev->rx_buffers.next, struct usb_request,
+                               list);
+               list_del_init(&req->list);
+               list_add(&req->list, &dev->rx_reqs);
+       }
+
+       while (likely(!(list_empty(&dev->rx_reqs_active)))) {
+               req = container_of(dev->rx_buffers.next, struct usb_request,
+                               list);
+               list_del_init(&req->list);
+               list_add(&req->list, &dev->rx_reqs);
+       }
+
+       while (likely(!(list_empty(&dev->tx_reqs_active)))) {
+               req = container_of(dev->tx_reqs_active.next,
+                               struct usb_request, list);
+               list_del_init(&req->list);
+               list_add(&req->list, &dev->tx_reqs);
+       }
+
+       if (usb_ep_enable(dev->in_ep, dev->in))
+               DBG(dev, "Failed to enable USB in_ep\n");
+       if (usb_ep_enable(dev->out_ep, dev->out))
+               DBG(dev, "Failed to enable USB out_ep\n");
+
+       wake_up_interruptible(&dev->tx_wait);
+       wake_up_interruptible(&dev->tx_flush_wait);
+}
+
+/*-------------------------------------------------------------------------*/
+
+/*
+ * The setup() callback implements all the ep0 functionality that's not
+ * handled lower down.
+ */
+static int
+printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
+{
+       struct printer_dev      *dev = get_gadget_data(gadget);
+       struct usb_request      *req = dev->req;
+       int                     value = -EOPNOTSUPP;
+       u16                     wIndex = le16_to_cpu(ctrl->wIndex);
+       u16                     wValue = le16_to_cpu(ctrl->wValue);
+       u16                     wLength = le16_to_cpu(ctrl->wLength);
+
+       DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n",
+               ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength);
+
+       req->complete = printer_setup_complete;
+
+       switch (ctrl->bRequestType&USB_TYPE_MASK) {
+
+       case USB_TYPE_STANDARD:
+               switch (ctrl->bRequest) {
+
+               case USB_REQ_GET_DESCRIPTOR:
+                       if (ctrl->bRequestType != USB_DIR_IN)
+                               break;
+                       switch (wValue >> 8) {
+
+                       case USB_DT_DEVICE:
+                               value = min(wLength, (u16) sizeof device_desc);
+                               memcpy(req->buf, &device_desc, value);
+                               break;
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+                       case USB_DT_DEVICE_QUALIFIER:
+                               if (!gadget->is_dualspeed)
+                                       break;
+                               value = min(wLength,
+                                               (u16) sizeof dev_qualifier);
+                               memcpy(req->buf, &dev_qualifier, value);
+                               break;
+
+                       case USB_DT_OTHER_SPEED_CONFIG:
+                               if (!gadget->is_dualspeed)
+                                       break;
+                               /* FALLTHROUGH */
+#endif /* CONFIG_USB_GADGET_DUALSPEED */
+                       case USB_DT_CONFIG:
+                               value = config_buf(gadget->speed, req->buf,
+                                               wValue >> 8,
+                                               wValue & 0xff,
+                                               gadget->is_otg);
+                               if (value >= 0)
+                                       value = min(wLength, (u16) value);
+                               break;
+
+                       case USB_DT_STRING:
+                               value = usb_gadget_get_string(&stringtab,
+                                               wValue & 0xff, req->buf);
+                               if (value >= 0)
+                                       value = min(wLength, (u16) value);
+                               break;
+                       }
+                       break;
+
+               case USB_REQ_SET_CONFIGURATION:
+                       if (ctrl->bRequestType != 0)
+                               break;
+                       if (gadget->a_hnp_support)
+                               DBG(dev, "HNP available\n");
+                       else if (gadget->a_alt_hnp_support)
+                               DBG(dev, "HNP needs a different root port\n");
+                       value = printer_set_config(dev, wValue);
+                       break;
+               case USB_REQ_GET_CONFIGURATION:
+                       if (ctrl->bRequestType != USB_DIR_IN)
+                               break;
+                       *(u8 *)req->buf = dev->config;
+                       value = min(wLength, (u16) 1);
+                       break;
+
+               case USB_REQ_SET_INTERFACE:
+                       if (ctrl->bRequestType != USB_RECIP_INTERFACE ||
+                                       !dev->config)
+                               break;
+
+                       value = set_interface(dev, PRINTER_INTERFACE);
+                       break;
+               case USB_REQ_GET_INTERFACE:
+                       if (ctrl->bRequestType !=
+                                       (USB_DIR_IN|USB_RECIP_INTERFACE)
+                                       || !dev->config)
+                               break;
+
+                       *(u8 *)req->buf = dev->interface;
+                       value = min(wLength, (u16) 1);
+                       break;
+
+               default:
+                       goto unknown;
+               }
+               break;
+
+       case USB_TYPE_CLASS:
+               switch (ctrl->bRequest) {
+               case 0: /* Get the IEEE-1284 PNP String */
+                       /* Only one printer interface is supported. */
+                       if ((wIndex>>8) != PRINTER_INTERFACE)
+                               break;
+
+                       value = (pnp_string[0]<<8)|pnp_string[1];
+                       memcpy(req->buf, pnp_string, value);
+                       DBG(dev, "1284 PNP String: %x %s\n", value,
+                                       &pnp_string[2]);
+                       break;
+
+               case 1: /* Get Port Status */
+                       /* Only one printer interface is supported. */
+                       if (wIndex != PRINTER_INTERFACE)
+                               break;
+
+                       *(u8 *)req->buf = dev->printer_status;
+                       value = min(wLength, (u16) 1);
+                       break;
+
+               case 2: /* Soft Reset */
+                       /* Only one printer interface is supported. */
+                       if (wIndex != PRINTER_INTERFACE)
+                               break;
+
+                       printer_soft_reset(dev);
+
+                       value = 0;
+                       break;
+
+               default:
+                       goto unknown;
+               }
+               break;
+
+       default:
+unknown:
+               VDBG(dev,
+                       "unknown ctrl req%02x.%02x v%04x i%04x l%d\n",
+                       ctrl->bRequestType, ctrl->bRequest,
+                       wValue, wIndex, wLength);
+               break;
+       }
+
+       /* respond with data transfer before status phase? */
+       if (value >= 0) {
+               req->length = value;
+               req->zero = value < wLength
+                               && (value % gadget->ep0->maxpacket) == 0;
+               value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
+               if (value < 0) {
+                       DBG(dev, "ep_queue --> %d\n", value);
+                       req->status = 0;
+                       printer_setup_complete(gadget->ep0, req);
+               }
+       }
+
+       /* host either stalls (value < 0) or reports success */
+       return value;
+}
+
+static void
+printer_disconnect(struct usb_gadget *gadget)
+{
+       struct printer_dev      *dev = get_gadget_data(gadget);
+       unsigned long           flags;
+
+       DBG(dev, "%s\n", __FUNCTION__);
+
+       spin_lock_irqsave(&dev->lock, flags);
+
+       printer_reset_interface(dev);
+
+       spin_unlock_irqrestore(&dev->lock, flags);
+}
+
+static void
+printer_unbind(struct usb_gadget *gadget)
+{
+       struct printer_dev      *dev = get_gadget_data(gadget);
+       struct usb_request      *req;
+
+
+       DBG(dev, "%s\n", __FUNCTION__);
+
+       /* Remove sysfs files */
+       device_destroy(usb_gadget_class, g_printer_devno);
+
+       /* Remove Character Device */
+       cdev_del(&dev->printer_cdev);
+
+       /* we must already have been disconnected ... no i/o may be active */
+       WARN_ON(!list_empty(&dev->tx_reqs_active));
+       WARN_ON(!list_empty(&dev->rx_reqs_active));
+
+       /* Free all memory for this driver. */
+       while (!list_empty(&dev->tx_reqs)) {
+               req = container_of(dev->tx_reqs.next, struct usb_request,
+                               list);
+               list_del(&req->list);
+               printer_req_free(dev->in_ep, req);
+       }
+
+       if (dev->current_rx_req != NULL);
+               printer_req_free(dev->out_ep, dev->current_rx_req);
+
+       while (!list_empty(&dev->rx_reqs)) {
+               req = container_of(dev->rx_reqs.next,
+                               struct usb_request, list);
+               list_del(&req->list);
+               printer_req_free(dev->out_ep, req);
+       }
+
+       while (!list_empty(&dev->rx_buffers)) {
+               req = container_of(dev->rx_buffers.next,
+                               struct usb_request, list);
+               list_del(&req->list);
+               printer_req_free(dev->out_ep, req);
+       }
+
+       if (dev->req) {
+               printer_req_free(gadget->ep0, dev->req);
+               dev->req = NULL;
+       }
+
+       set_gadget_data(gadget, NULL);
+}
+
+static int __init
+printer_bind(struct usb_gadget *gadget)
+{
+       struct printer_dev      *dev;
+       struct usb_ep           *in_ep, *out_ep;
+       int                     status = -ENOMEM;
+       int                     gcnum;
+       size_t                  len;
+       u32                     i;
+       struct usb_request      *req;
+
+       dev = &usb_printer_gadget;
+
+
+       /* Setup the sysfs files for the printer gadget. */
+       dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno,
+                       "g_printer");
+       if (IS_ERR(dev->pdev)) {
+               ERROR(dev, "Failed to create device: g_printer\n");
+               goto fail;
+       }
+
+       /*
+        * Register a character device as an interface to a user mode
+        * program that handles the printer specific functionality.
+        */
+       cdev_init(&dev->printer_cdev, &printer_io_operations);
+       dev->printer_cdev.owner = THIS_MODULE;
+       status = cdev_add(&dev->printer_cdev, g_printer_devno, 1);
+       if (status) {
+               ERROR(dev, "Failed to open char device\n");
+               goto fail;
+       }
+
+       if (gadget_is_sa1100(gadget)) {
+               /* hardware can't write zero length packets. */
+               ERROR(dev, "SA1100 controller is unsupport by this driver\n");
+               goto fail;
+       }
+
+       gcnum = usb_gadget_controller_number(gadget);
+       if (gcnum >= 0) {
+               device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
+       } else {
+               dev_warn(&gadget->dev, "controller '%s' not recognized\n",
+                       gadget->name);
+               /* unrecognized, but safe unless bulk is REALLY quirky */
+               device_desc.bcdDevice =
+                       __constant_cpu_to_le16(0xFFFF);
+       }
+       snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
+               init_utsname()->sysname, init_utsname()->release,
+               gadget->name);
+
+       device_desc.idVendor =
+               __constant_cpu_to_le16(PRINTER_VENDOR_NUM);
+       device_desc.idProduct =
+               __constant_cpu_to_le16(PRINTER_PRODUCT_NUM);
+
+       /* support optional vendor/distro customization */
+       if (idVendor) {
+               if (!idProduct) {
+                       dev_err(&gadget->dev, "idVendor needs idProduct!\n");
+                       return -ENODEV;
+               }
+               device_desc.idVendor = cpu_to_le16(idVendor);
+               device_desc.idProduct = cpu_to_le16(idProduct);
+               if (bcdDevice)
+                       device_desc.bcdDevice = cpu_to_le16(bcdDevice);
+       }
+
+       if (iManufacturer)
+               strlcpy(manufacturer, iManufacturer, sizeof manufacturer);
+
+       if (iProduct)
+               strlcpy(product_desc, iProduct, sizeof product_desc);
+
+       if (iSerialNum)
+               strlcpy(serial_num, iSerialNum, sizeof serial_num);
+
+       if (iPNPstring)
+               strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2);
+
+       len = strlen(pnp_string);
+       pnp_string[0] = (len >> 8) & 0xFF;
+       pnp_string[1] = len & 0xFF;
+
+       /* all we really need is bulk IN/OUT */
+       usb_ep_autoconfig_reset(gadget);
+       in_ep = usb_ep_autoconfig(gadget, &fs_ep_in_desc);
+       if (!in_ep) {
+autoconf_fail:
+               dev_err(&gadget->dev, "can't autoconfigure on %s\n",
+                       gadget->name);
+               return -ENODEV;
+       }
+       in_ep->driver_data = in_ep;     /* claim */
+
+       out_ep = usb_ep_autoconfig(gadget, &fs_ep_out_desc);
+       if (!out_ep)
+               goto autoconf_fail;
+       out_ep->driver_data = out_ep;   /* claim */
+
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+       /* assumes ep0 uses the same value for both speeds ... */
+       dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
+
+       /* and that all endpoints are dual-speed */
+       hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
+       hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
+#endif /* DUALSPEED */
+
+       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
+       usb_gadget_set_selfpowered(gadget);
+
+       if (gadget->is_otg) {
+               otg_desc.bmAttributes |= USB_OTG_HNP,
+               config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
+               config_desc.bMaxPower = 4;
+       }
+
+       spin_lock_init(&dev->lock);
+       spin_lock_init(&dev->lock_printer_io);
+       INIT_LIST_HEAD(&dev->tx_reqs);
+       INIT_LIST_HEAD(&dev->tx_reqs_active);
+       INIT_LIST_HEAD(&dev->rx_reqs);
+       INIT_LIST_HEAD(&dev->rx_reqs_active);
+       INIT_LIST_HEAD(&dev->rx_buffers);
+       init_waitqueue_head(&dev->rx_wait);
+       init_waitqueue_head(&dev->tx_wait);
+       init_waitqueue_head(&dev->tx_flush_wait);
+
+       dev->config = 0;
+       dev->interface = -1;
+       dev->printer_cdev_open = 0;
+       dev->printer_status = PRINTER_NOT_ERROR;
+       dev->current_rx_req = NULL;
+       dev->current_rx_bytes = 0;
+       dev->current_rx_buf = NULL;
+
+       dev->in_ep = in_ep;
+       dev->out_ep = out_ep;
+
+       /* preallocate control message data and buffer */
+       dev->req = printer_req_alloc(gadget->ep0, USB_DESC_BUFSIZE,
+                       GFP_KERNEL);
+       if (!dev->req) {
+               status = -ENOMEM;
+               goto fail;
+       }
+
+       for (i = 0; i < QLEN; i++) {
+               req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL);
+               if (!req) {
+                       while (!list_empty(&dev->tx_reqs)) {
+                               req = container_of(dev->tx_reqs.next,
+                                               struct usb_request, list);
+                               list_del(&req->list);
+                               printer_req_free(dev->in_ep, req);
+                       }
+                       return -ENOMEM;
+               }
+               list_add(&req->list, &dev->tx_reqs);
+       }
+
+       for (i = 0; i < QLEN; i++) {
+               req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL);
+               if (!req) {
+                       while (!list_empty(&dev->rx_reqs)) {
+                               req = container_of(dev->rx_reqs.next,
+                                               struct usb_request, list);
+                               list_del(&req->list);
+                               printer_req_free(dev->out_ep, req);
+                       }
+                       return -ENOMEM;
+               }
+               list_add(&req->list, &dev->rx_reqs);
+       }
+
+       dev->req->complete = printer_setup_complete;
+
+       /* finish hookup to lower layer ... */
+       dev->gadget = gadget;
+       set_gadget_data(gadget, dev);
+       gadget->ep0->driver_data = dev;
+
+       INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
+       INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name,
+                       in_ep->name);
+
+       return 0;
+
+fail:
+       printer_unbind(gadget);
+       return status;
+}
+
+/*-------------------------------------------------------------------------*/
+
+static struct usb_gadget_driver printer_driver = {
+       .speed          = DEVSPEED,
+
+       .function       = (char *) driver_desc,
+       .bind           = printer_bind,
+       .unbind         = printer_unbind,
+
+       .setup          = printer_setup,
+       .disconnect     = printer_disconnect,
+
+       .driver         = {
+               .name           = (char *) shortname,
+               .owner          = THIS_MODULE,
+       },
+};
+
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_AUTHOR("Craig Nadler");
+MODULE_LICENSE("GPL");
+
+static int __init
+init(void)
+{
+       int status;
+
+       usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget");
+       if (IS_ERR(usb_gadget_class)) {
+               status = PTR_ERR(usb_gadget_class);
+               ERROR(dev, "unable to create usb_gadget class %d\n", status);
+               return status;
+       }
+
+       status = alloc_chrdev_region(&g_printer_devno, 0, 1,
+                       "USB printer gadget");
+       if (status) {
+               ERROR(dev, "alloc_chrdev_region %d\n", status);
+               class_destroy(usb_gadget_class);
+               return status;
+       }
+
+       status = usb_gadget_register_driver(&printer_driver);
+       if (status) {
+               class_destroy(usb_gadget_class);
+               unregister_chrdev_region(g_printer_devno, 1);
+               DBG(dev, "usb_gadget_register_driver %x\n", status);
+       }
+
+       return status;
+}
+module_init(init);
+
+static void __exit
+cleanup(void)
+{
+       int status;
+
+       spin_lock(&usb_printer_gadget.lock_printer_io);
+       class_destroy(usb_gadget_class);
+       unregister_chrdev_region(g_printer_devno, 2);
+
+       status = usb_gadget_unregister_driver(&printer_driver);
+       if (status)
+               ERROR(dev, "usb_gadget_unregister_driver %x\n", status);
+
+       spin_unlock(&usb_printer_gadget.lock_printer_io);
+}
+module_exit(cleanup);
index 3173b39f0bfdf52d79034b6e5214cf260d33a637..4402d6f042d971bd42d6a1453bb3c0bef85172ee 100644 (file)
@@ -24,7 +24,7 @@
  *
  */
 
-// #define     VERBOSE DBG_VERBOSE
+/* #define VERBOSE_DEBUG */
 
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/timer.h>
 #include <linux/list.h>
 #include <linux/interrupt.h>
-#include <linux/proc_fs.h>
 #include <linux/mm.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/irq.h>
 #include <linux/clk.h>
 #include <linux/err.h>
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
 
 #include <asm/byteorder.h>
 #include <asm/dma.h>
@@ -127,8 +128,10 @@ static int is_vbus_present(void)
 {
        struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
 
-       if (mach->gpio_vbus)
-               return gpio_get_value(mach->gpio_vbus);
+       if (mach->gpio_vbus) {
+               int value = gpio_get_value(mach->gpio_vbus);
+               return mach->gpio_vbus_inverted ? !value : value;
+       }
        if (mach->udc_is_connected)
                return mach->udc_is_connected();
        return 1;
@@ -677,7 +680,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 
        /* kickstart this i/o queue? */
        if (list_empty(&ep->queue) && !ep->stopped) {
-               if (ep->desc == /* ep0 */) {
+               if (ep->desc == NULL/* ep0 */) {
                        unsigned        length = _req->length;
 
                        switch (dev->ep0state) {
@@ -731,7 +734,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
        }
 
        /* pio or dma irq handler advances the queue. */
-       if (likely (req != 0))
+       if (likely(req != NULL))
                list_add_tail(&req->queue, &ep->queue);
        local_irq_restore(flags);
 
@@ -991,45 +994,32 @@ static const struct usb_gadget_ops pxa2xx_udc_ops = {
 
 /*-------------------------------------------------------------------------*/
 
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-
-static const char proc_node_name [] = "driver/udc";
+#ifdef CONFIG_USB_GADGET_DEBUG_FS
 
 static int
-udc_proc_read(char *page, char **start, off_t off, int count,
-               int *eof, void *_dev)
+udc_seq_show(struct seq_file *m, void *d)
 {
-       char                    *buf = page;
-       struct pxa2xx_udc       *dev = _dev;
-       char                    *next = buf;
-       unsigned                size = count;
+       struct pxa2xx_udc       *dev = m->private;
        unsigned long           flags;
-       int                     i, t;
+       int                     i;
        u32                     tmp;
 
-       if (off != 0)
-               return 0;
-
        local_irq_save(flags);
 
        /* basic device status */
-       t = scnprintf(next, size, DRIVER_DESC "\n"
+       seq_printf(m, DRIVER_DESC "\n"
                "%s version: %s\nGadget driver: %s\nHost %s\n\n",
                driver_name, DRIVER_VERSION SIZE_STR "(pio)",
                dev->driver ? dev->driver->driver.name : "(none)",
                is_vbus_present() ? "full speed" : "disconnected");
-       size -= t;
-       next += t;
 
        /* registers for device and ep0 */
-       t = scnprintf(next, size,
+       seq_printf(m,
                "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
                UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
-       size -= t;
-       next += t;
 
        tmp = UDCCR;
-       t = scnprintf(next, size,
+       seq_printf(m,
                "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
                (tmp & UDCCR_REM) ? " rem" : "",
                (tmp & UDCCR_RSTIR) ? " rstir" : "",
@@ -1039,11 +1029,9 @@ udc_proc_read(char *page, char **start, off_t off, int count,
                (tmp & UDCCR_RSM) ? " rsm" : "",
                (tmp & UDCCR_UDA) ? " uda" : "",
                (tmp & UDCCR_UDE) ? " ude" : "");
-       size -= t;
-       next += t;
 
        tmp = UDCCS0;
-       t = scnprintf(next, size,
+       seq_printf(m,
                "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
                (tmp & UDCCS0_SA) ? " sa" : "",
                (tmp & UDCCS0_RNE) ? " rne" : "",
@@ -1053,28 +1041,22 @@ udc_proc_read(char *page, char **start, off_t off, int count,
                (tmp & UDCCS0_FTF) ? " ftf" : "",
                (tmp & UDCCS0_IPR) ? " ipr" : "",
                (tmp & UDCCS0_OPR) ? " opr" : "");
-       size -= t;
-       next += t;
 
        if (dev->has_cfr) {
                tmp = UDCCFR;
-               t = scnprintf(next, size,
+               seq_printf(m,
                        "udccfr %02X =%s%s\n", tmp,
                        (tmp & UDCCFR_AREN) ? " aren" : "",
                        (tmp & UDCCFR_ACM) ? " acm" : "");
-               size -= t;
-               next += t;
        }
 
        if (!is_vbus_present() || !dev->driver)
                goto done;
 
-       t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
+       seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
                dev->stats.write.bytes, dev->stats.write.ops,
                dev->stats.read.bytes, dev->stats.read.ops,
                dev->stats.irqs);
-       size -= t;
-       next += t;
 
        /* dump endpoint queues */
        for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
@@ -1082,61 +1064,68 @@ udc_proc_read(char *page, char **start, off_t off, int count,
                struct pxa2xx_request   *req;
 
                if (i != 0) {
-                       const struct usb_endpoint_descriptor    *d;
+                       const struct usb_endpoint_descriptor    *desc;
 
-                       d = ep->desc;
-                       if (!d)
+                       desc = ep->desc;
+                       if (!desc)
                                continue;
                        tmp = *dev->ep [i].reg_udccs;
-                       t = scnprintf(next, size,
+                       seq_printf(m,
                                "%s max %d %s udccs %02x irqs %lu\n",
-                               ep->ep.name, le16_to_cpu (d->wMaxPacketSize),
+                               ep->ep.name, le16_to_cpu(desc->wMaxPacketSize),
                                "pio", tmp, ep->pio_irqs);
                        /* TODO translate all five groups of udccs bits! */
 
                } else /* ep0 should only have one transfer queued */
-                       t = scnprintf(next, size, "ep0 max 16 pio irqs %lu\n",
+                       seq_printf(m, "ep0 max 16 pio irqs %lu\n",
                                ep->pio_irqs);
-               if (t <= 0 || t > size)
-                       goto done;
-               size -= t;
-               next += t;
 
                if (list_empty(&ep->queue)) {
-                       t = scnprintf(next, size, "\t(nothing queued)\n");
-                       if (t <= 0 || t > size)
-                               goto done;
-                       size -= t;
-                       next += t;
+                       seq_printf(m, "\t(nothing queued)\n");
                        continue;
                }
                list_for_each_entry(req, &ep->queue, queue) {
-                       t = scnprintf(next, size,
+                       seq_printf(m,
                                        "\treq %p len %d/%d buf %p\n",
                                        &req->req, req->req.actual,
                                        req->req.length, req->req.buf);
-                       if (t <= 0 || t > size)
-                               goto done;
-                       size -= t;
-                       next += t;
                }
        }
 
 done:
        local_irq_restore(flags);
-       *eof = 1;
-       return count - size;
+       return 0;
 }
 
-#define create_proc_files() \
-       create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev)
-#define remove_proc_files() \
-       remove_proc_entry(proc_node_name, NULL)
+static int
+udc_debugfs_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, udc_seq_show, inode->i_private);
+}
+
+static const struct file_operations debug_fops = {
+       .open           = udc_debugfs_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .owner          = THIS_MODULE,
+};
+
+#define create_debug_files(dev) \
+       do { \
+               dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
+                       S_IRUGO, NULL, dev, &debug_fops); \
+       } while (0)
+#define remove_debug_files(dev) \
+       do { \
+               if (dev->debugfs_udc) \
+                       debugfs_remove(dev->debugfs_udc); \
+       } while (0)
 
 #else  /* !CONFIG_USB_GADGET_DEBUG_FILES */
 
-#define create_proc_files() do {} while (0)
-#define remove_proc_files() do {} while (0)
+#define create_debug_files(dev) do {} while (0)
+#define remove_debug_files(dev) do {} while (0)
 
 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
 
@@ -1345,6 +1334,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        local_irq_enable();
 
        driver->unbind(&dev->gadget);
+       dev->gadget.dev.driver = NULL;
        dev->driver = NULL;
 
        device_del (&dev->gadget.dev);
@@ -1397,6 +1387,9 @@ static irqreturn_t udc_vbus_irq(int irq, void *_dev)
        struct pxa2xx_udc       *dev = _dev;
        int                     vbus = gpio_get_value(dev->mach->gpio_vbus);
 
+       if (dev->mach->gpio_vbus_inverted)
+               vbus = !vbus;
+
        pxa2xx_udc_vbus_session(&dev->gadget, vbus);
        return IRQ_HANDLED;
 }
@@ -2099,7 +2092,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
        /* insist on Intel/ARM/XScale */
        asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
        if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
-               printk(KERN_ERR "%s: not XScale!\n", driver_name);
+               pr_err("%s: not XScale!\n", driver_name);
                return -ENODEV;
        }
 
@@ -2128,7 +2121,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
                break;
 #endif
        default:
-               printk(KERN_ERR "%s: unrecognized processor: %08x\n",
+               pr_err("%s: unrecognized processor: %08x\n",
                        driver_name, chiprev);
                /* iop3xx, ixp4xx, ... */
                return -ENODEV;
@@ -2199,7 +2192,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
        retval = request_irq(irq, pxa2xx_udc_irq,
                        IRQF_DISABLED, driver_name, dev);
        if (retval != 0) {
-               printk(KERN_ERR "%s: can't get irq %d, err %d\n",
+               pr_err("%s: can't get irq %d, err %d\n",
                        driver_name, irq, retval);
                goto err_irq1;
        }
@@ -2212,7 +2205,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
                                IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
                                driver_name, dev);
                if (retval != 0) {
-                       printk(KERN_ERR "%s: can't get irq %i, err %d\n",
+                       pr_err("%s: can't get irq %i, err %d\n",
                                driver_name, LUBBOCK_USB_DISC_IRQ, retval);
 lubbock_fail0:
                        goto err_irq_lub;
@@ -2222,7 +2215,7 @@ lubbock_fail0:
                                IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
                                driver_name, dev);
                if (retval != 0) {
-                       printk(KERN_ERR "%s: can't get irq %i, err %d\n",
+                       pr_err("%s: can't get irq %i, err %d\n",
                                driver_name, LUBBOCK_USB_IRQ, retval);
                        free_irq(LUBBOCK_USB_DISC_IRQ, dev);
                        goto lubbock_fail0;
@@ -2235,12 +2228,12 @@ lubbock_fail0:
                                IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
                                driver_name, dev);
                if (retval != 0) {
-                       printk(KERN_ERR "%s: can't get irq %i, err %d\n",
+                       pr_err("%s: can't get irq %i, err %d\n",
                                driver_name, vbus_irq, retval);
                        goto err_vbus_irq;
                }
        }
-       create_proc_files();
+       create_debug_files(dev);
 
        return 0;
 
@@ -2277,7 +2270,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
                return -EBUSY;
 
        udc_disable(dev);
-       remove_proc_files();
+       remove_debug_files(dev);
 
        if (dev->got_irq) {
                free_irq(platform_get_irq(pdev, 0), dev);
@@ -2361,7 +2354,7 @@ static struct platform_driver udc_driver = {
 
 static int __init udc_init(void)
 {
-       printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
+       pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
        return platform_driver_probe(&udc_driver, pxa2xx_udc_probe);
 }
 module_init(udc_init);
index 1db46d705777a39881cca5f395700e8410e84feb..b67e3ff5e4eb5baf648b0fcceb457e7e3456af69 100644 (file)
@@ -129,6 +129,10 @@ struct pxa2xx_udc {
        struct pxa2xx_udc_mach_info             *mach;
        u64                                     dma_mask;
        struct pxa2xx_ep                        ep [PXA_UDC_NUM_ENDPOINTS];
+
+#ifdef CONFIG_USB_GADGET_DEBUG_FS
+       struct dentry                           *debugfs_udc;
+#endif
 };
 
 /*-------------------------------------------------------------------------*/
@@ -151,17 +155,19 @@ static struct pxa2xx_udc *the_controller;
 #define DBG_NOISY      3       /* ... even more: request level */
 #define DBG_VERY_NOISY 4       /* ... even more: packet level */
 
+#define DMSG(stuff...) pr_debug("udc: " stuff)
+
 #ifdef DEBUG
 
+static int is_vbus_present(void);
+
 static const char *state_name[] = {
        "EP0_IDLE",
        "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE",
        "EP0_END_XFER", "EP0_STALL"
 };
 
-#define DMSG(stuff...) printk(KERN_DEBUG "udc: " stuff)
-
-#ifdef VERBOSE
+#ifdef VERBOSE_DEBUG
 #    define UDC_DEBUG DBG_VERBOSE
 #else
 #    define UDC_DEBUG DBG_NORMAL
@@ -207,7 +213,7 @@ dump_state(struct pxa2xx_udc *dev)
        unsigned        i;
 
        DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
-               is_usb_connected() ? "host " : "disconnected",
+               is_vbus_present() ? "host " : "disconnected",
                state_name[dev->ep0state],
                UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
        dump_udccr("udccr");
@@ -224,7 +230,7 @@ dump_state(struct pxa2xx_udc *dev)
        } else
                DMSG("ep0 driver '%s'\n", dev->driver->driver.name);
 
-       if (!is_usb_connected())
+       if (!is_vbus_present())
                return;
 
        dump_udccs0 ("udccs0");
@@ -233,7 +239,7 @@ dump_state(struct pxa2xx_udc *dev)
                dev->stats.read.bytes, dev->stats.read.ops);
 
        for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
-               if (dev->ep [i].desc == 0)
+               if (dev->ep [i].desc == NULL)
                        continue;
                DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);
        }
@@ -241,8 +247,6 @@ dump_state(struct pxa2xx_udc *dev)
 
 #else
 
-#define DMSG(stuff...)         do{}while(0)
-
 #define        dump_udccr(x)   do{}while(0)
 #define        dump_udccs0(x)  do{}while(0)
 #define        dump_state(x)   do{}while(0)
@@ -253,8 +257,9 @@ dump_state(struct pxa2xx_udc *dev)
 
 #define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
 
-#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff)
-#define INFO(stuff...) printk(KERN_INFO "udc: " stuff)
+#define ERR(stuff...)          pr_err("udc: " stuff)
+#define WARN(stuff...)         pr_warning("udc: " stuff)
+#define INFO(stuff...)         pr_info("udc: " stuff)
 
 
 #endif /* __LINUX_USB_GADGET_PXA2XX_H */
index db1b2bfcee4e65eb91cc0c9070f55cea556a76bc..3d036647431fdbd8f409a30cf327d74acceb82c5 100644 (file)
  */
 
 #if 0
-#define DBG(str,args...) do { \
-       if (rndis_debug) \
-               printk(KERN_DEBUG str , ## args ); \
-       } while (0)
 static int rndis_debug = 0;
-
 module_param (rndis_debug, int, 0);
 MODULE_PARM_DESC (rndis_debug, "enable debugging");
-
 #else
-
 #define rndis_debug            0
-#define DBG(str,args...)       do{}while(0)
 #endif
 
+#define DBG(str,args...) do { \
+       if (rndis_debug) \
+               pr_debug(str , ## args); \
+       } while (0)
+
 #define RNDIS_MAX_CONFIGS      1
 
 
@@ -679,7 +676,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
 #endif
 
        default:
-               printk (KERN_WARNING "%s: query unknown OID 0x%08X\n",
+               pr_warning("%s: query unknown OID 0x%08X\n",
                         __FUNCTION__, OID);
        }
        if (retval < 0)
@@ -804,7 +801,7 @@ update_linkstate:
 #endif /* RNDIS_PM */
 
        default:
-               printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n",
+               pr_warning("%s: set unknown OID 0x%08X, size %d\n",
                         __FUNCTION__, OID, buf_len);
        }
 
@@ -1126,8 +1123,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
                 * In one case those messages seemed to relate to the host
                 * suspending itself.
                 */
-               printk (KERN_WARNING
-                       "%s: unknown RNDIS message 0x%08X len %d\n",
+               pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
                        __FUNCTION__ , MsgType, MsgLength);
                {
                        unsigned i;
index 4ce050c3d13fad9199d91697c4490ede73c70ae5..aadc4204d6f9435a32282e92bc28ee3eccf0e383 100644 (file)
@@ -893,7 +893,7 @@ static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
 /*
  *     s3c2410_udc_irq - interrupt handler
  */
-static irqreturn_t s3c2410_udc_irq(int irq, void *_dev)
+static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev)
 {
        struct s3c2410_udc *dev = _dev;
        int usb_status;
@@ -1016,7 +1016,7 @@ static irqreturn_t s3c2410_udc_irq(int irq, void *_dev)
                }
        }
 
-       dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", irq);
+       dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD);
 
        /* Restore old index */
        udc_write(idx, S3C2410_UDC_INDEX_REG);
index f5738eb8e76522ae43c12c3c9a8b56f3732a2fe3..f5c3896b1d959a5cbf66e705ba21038ef51553e5 100644 (file)
@@ -89,9 +89,9 @@ static int debug = 1;
 #endif
 
 #define gs_debug(format, arg...) \
-       do { if (debug) printk(KERN_DEBUG format, ## arg); } while(0)
+       do { if (debug) pr_debug(format, ## arg); } while (0)
 #define gs_debug_level(level, format, arg...) \
-       do { if (debug>=level) printk(KERN_DEBUG format, ## arg); } while(0)
+       do { if (debug >= level) pr_debug(format, ## arg); } while (0)
 
 
 /* Thanks to NetChip Technologies for donating this product ID.
@@ -553,7 +553,8 @@ static int __init gs_module_init(void)
 
        retval = usb_gadget_register_driver(&gs_gadget_driver);
        if (retval) {
-               printk(KERN_ERR "gs_module_init: cannot register gadget driver, ret=%d\n", retval);
+               pr_err("gs_module_init: cannot register gadget driver, "
+                       "ret=%d\n", retval);
                return retval;
        }
 
@@ -579,11 +580,13 @@ static int __init gs_module_init(void)
        if (retval) {
                usb_gadget_unregister_driver(&gs_gadget_driver);
                put_tty_driver(gs_tty_driver);
-               printk(KERN_ERR "gs_module_init: cannot register tty driver, ret=%d\n", retval);
+               pr_err("gs_module_init: cannot register tty driver, "
+                               "ret=%d\n", retval);
                return retval;
        }
 
-       printk(KERN_INFO "gs_module_init: %s %s loaded\n", GS_LONG_NAME, GS_VERSION_STR);
+       pr_info("gs_module_init: %s %s loaded\n",
+                       GS_LONG_NAME, GS_VERSION_STR);
        return 0;
 }
 
@@ -598,7 +601,8 @@ static void __exit gs_module_exit(void)
        put_tty_driver(gs_tty_driver);
        usb_gadget_unregister_driver(&gs_gadget_driver);
 
-       printk(KERN_INFO "gs_module_exit: %s %s unloaded\n", GS_LONG_NAME, GS_VERSION_STR);
+       pr_info("gs_module_exit: %s %s unloaded\n",
+                       GS_LONG_NAME, GS_VERSION_STR);
 }
 
 /* TTY Driver */
@@ -621,7 +625,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
        gs_debug("gs_open: (%d,%p,%p)\n", port_num, tty, file);
 
        if (port_num < 0 || port_num >= GS_NUM_PORTS) {
-               printk(KERN_ERR "gs_open: (%d,%p,%p) invalid port number\n",
+               pr_err("gs_open: (%d,%p,%p) invalid port number\n",
                        port_num, tty, file);
                return -ENODEV;
        }
@@ -629,15 +633,14 @@ static int gs_open(struct tty_struct *tty, struct file *file)
        dev = gs_device;
 
        if (dev == NULL) {
-               printk(KERN_ERR "gs_open: (%d,%p,%p) NULL device pointer\n",
+               pr_err("gs_open: (%d,%p,%p) NULL device pointer\n",
                        port_num, tty, file);
                return -ENODEV;
        }
 
        mtx = &gs_open_close_lock[port_num];
        if (mutex_lock_interruptible(mtx)) {
-               printk(KERN_ERR
-               "gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
+               pr_err("gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
                        port_num, tty, file);
                return -ERESTARTSYS;
        }
@@ -645,8 +648,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
        spin_lock_irqsave(&dev->dev_lock, flags);
 
        if (dev->dev_config == GS_NO_CONFIG_ID) {
-               printk(KERN_ERR
-                       "gs_open: (%d,%p,%p) device is not connected\n",
+               pr_err("gs_open: (%d,%p,%p) device is not connected\n",
                        port_num, tty, file);
                ret = -ENODEV;
                goto exit_unlock_dev;
@@ -655,7 +657,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
        port = dev->dev_port[port_num];
 
        if (port == NULL) {
-               printk(KERN_ERR "gs_open: (%d,%p,%p) NULL port pointer\n",
+               pr_err("gs_open: (%d,%p,%p) NULL port pointer\n",
                        port_num, tty, file);
                ret = -ENODEV;
                goto exit_unlock_dev;
@@ -665,7 +667,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
        spin_unlock(&dev->dev_lock);
 
        if (port->port_dev == NULL) {
-               printk(KERN_ERR "gs_open: (%d,%p,%p) port disconnected (1)\n",
+               pr_err("gs_open: (%d,%p,%p) port disconnected (1)\n",
                        port_num, tty, file);
                ret = -EIO;
                goto exit_unlock_port;
@@ -692,8 +694,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
 
                /* might have been disconnected while asleep, check */
                if (port->port_dev == NULL) {
-                       printk(KERN_ERR
-                               "gs_open: (%d,%p,%p) port disconnected (2)\n",
+                       pr_err("gs_open: (%d,%p,%p) port disconnected (2)\n",
                                port_num, tty, file);
                        port->port_in_use = 0;
                        ret = -EIO;
@@ -701,7 +702,8 @@ static int gs_open(struct tty_struct *tty, struct file *file)
                }
 
                if ((port->port_write_buf=buf) == NULL) {
-                       printk(KERN_ERR "gs_open: (%d,%p,%p) cannot allocate port write buffer\n",
+                       pr_err("gs_open: (%d,%p,%p) cannot allocate "
+                               "port write buffer\n",
                                port_num, tty, file);
                        port->port_in_use = 0;
                        ret = -ENOMEM;
@@ -714,7 +716,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
 
        /* might have been disconnected while asleep, check */
        if (port->port_dev == NULL) {
-               printk(KERN_ERR "gs_open: (%d,%p,%p) port disconnected (3)\n",
+               pr_err("gs_open: (%d,%p,%p) port disconnected (3)\n",
                        port_num, tty, file);
                port->port_in_use = 0;
                ret = -EIO;
@@ -762,7 +764,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
        struct mutex *mtx;
 
        if (port == NULL) {
-               printk(KERN_ERR "gs_close: NULL port pointer\n");
+               pr_err("gs_close: NULL port pointer\n");
                return;
        }
 
@@ -774,8 +776,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
        spin_lock_irq(&port->port_lock);
 
        if (port->port_open_count == 0) {
-               printk(KERN_ERR
-                       "gs_close: (%d,%p,%p) port is already closed\n",
+               pr_err("gs_close: (%d,%p,%p) port is already closed\n",
                        port->port_num, tty, file);
                goto exit;
        }
@@ -837,7 +838,7 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
        int ret;
 
        if (port == NULL) {
-               printk(KERN_ERR "gs_write: NULL port pointer\n");
+               pr_err("gs_write: NULL port pointer\n");
                return -EIO;
        }
 
@@ -850,14 +851,14 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
        spin_lock_irqsave(&port->port_lock, flags);
 
        if (port->port_dev == NULL) {
-               printk(KERN_ERR "gs_write: (%d,%p) port is not connected\n",
+               pr_err("gs_write: (%d,%p) port is not connected\n",
                        port->port_num, tty);
                ret = -EIO;
                goto exit;
        }
 
        if (port->port_open_count == 0) {
-               printk(KERN_ERR "gs_write: (%d,%p) port is closed\n",
+               pr_err("gs_write: (%d,%p) port is closed\n",
                        port->port_num, tty);
                ret = -EBADF;
                goto exit;
@@ -888,7 +889,7 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch)
        struct gs_port *port = tty->driver_data;
 
        if (port == NULL) {
-               printk(KERN_ERR "gs_put_char: NULL port pointer\n");
+               pr_err("gs_put_char: NULL port pointer\n");
                return;
        }
 
@@ -898,13 +899,13 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch)
        spin_lock_irqsave(&port->port_lock, flags);
 
        if (port->port_dev == NULL) {
-               printk(KERN_ERR "gs_put_char: (%d,%p) port is not connected\n",
+               pr_err("gs_put_char: (%d,%p) port is not connected\n",
                        port->port_num, tty);
                goto exit;
        }
 
        if (port->port_open_count == 0) {
-               printk(KERN_ERR "gs_put_char: (%d,%p) port is closed\n",
+               pr_err("gs_put_char: (%d,%p) port is closed\n",
                        port->port_num, tty);
                goto exit;
        }
@@ -924,7 +925,7 @@ static void gs_flush_chars(struct tty_struct *tty)
        struct gs_port *port = tty->driver_data;
 
        if (port == NULL) {
-               printk(KERN_ERR "gs_flush_chars: NULL port pointer\n");
+               pr_err("gs_flush_chars: NULL port pointer\n");
                return;
        }
 
@@ -933,14 +934,13 @@ static void gs_flush_chars(struct tty_struct *tty)
        spin_lock_irqsave(&port->port_lock, flags);
 
        if (port->port_dev == NULL) {
-               printk(KERN_ERR
-                       "gs_flush_chars: (%d,%p) port is not connected\n",
+               pr_err("gs_flush_chars: (%d,%p) port is not connected\n",
                        port->port_num, tty);
                goto exit;
        }
 
        if (port->port_open_count == 0) {
-               printk(KERN_ERR "gs_flush_chars: (%d,%p) port is closed\n",
+               pr_err("gs_flush_chars: (%d,%p) port is closed\n",
                        port->port_num, tty);
                goto exit;
        }
@@ -1038,7 +1038,7 @@ static int gs_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd,
        struct gs_port *port = tty->driver_data;
 
        if (port == NULL) {
-               printk(KERN_ERR "gs_ioctl: NULL port pointer\n");
+               pr_err("gs_ioctl: NULL port pointer\n");
                return -EIO;
        }
 
@@ -1076,7 +1076,7 @@ static int gs_send(struct gs_dev *dev)
        struct gs_req_entry *req_entry;
 
        if (dev == NULL) {
-               printk(KERN_ERR "gs_send: NULL device pointer\n");
+               pr_err("gs_send: NULL device pointer\n");
                return -ENODEV;
        }
 
@@ -1103,7 +1103,7 @@ static int gs_send(struct gs_dev *dev)
                        req->length = len;
                        spin_unlock_irqrestore(&dev->dev_lock, flags);
                        if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
-                               printk(KERN_ERR
+                               pr_err(
                                "gs_send: cannot queue read request, ret=%d\n",
                                        ret);
                                spin_lock_irqsave(&dev->dev_lock, flags);
@@ -1144,9 +1144,7 @@ static int gs_send_packet(struct gs_dev *dev, char *packet, unsigned int size)
        port = dev->dev_port[0];
 
        if (port == NULL) {
-               printk(KERN_ERR
-                       "gs_send_packet: port=%d, NULL port pointer\n",
-                       0);
+               pr_err("gs_send_packet: port=%d, NULL port pointer\n", 0);
                return -EIO;
        }
 
@@ -1193,7 +1191,7 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size)
        port = dev->dev_port[0];
 
        if (port == NULL) {
-               printk(KERN_ERR "gs_recv_packet: port=%d, NULL port pointer\n",
+               pr_err("gs_recv_packet: port=%d, NULL port pointer\n",
                        port->port_num);
                return -EIO;
        }
@@ -1201,7 +1199,7 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size)
        spin_lock(&port->port_lock);
 
        if (port->port_open_count == 0) {
-               printk(KERN_ERR "gs_recv_packet: port=%d, port is closed\n",
+               pr_err("gs_recv_packet: port=%d, port is closed\n",
                        port->port_num);
                ret = -EIO;
                goto exit;
@@ -1211,14 +1209,14 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size)
        tty = port->port_tty;
 
        if (tty == NULL) {
-               printk(KERN_ERR "gs_recv_packet: port=%d, NULL tty pointer\n",
+               pr_err("gs_recv_packet: port=%d, NULL tty pointer\n",
                        port->port_num);
                ret = -EIO;
                goto exit;
        }
 
        if (port->port_tty->magic != TTY_MAGIC) {
-               printk(KERN_ERR "gs_recv_packet: port=%d, bad tty magic\n",
+               pr_err("gs_recv_packet: port=%d, bad tty magic\n",
                        port->port_num);
                ret = -EIO;
                goto exit;
@@ -1245,7 +1243,7 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
        struct gs_dev *dev = ep->driver_data;
 
        if (dev == NULL) {
-               printk(KERN_ERR "gs_read_complete: NULL device pointer\n");
+               pr_err("gs_read_complete: NULL device pointer\n");
                return;
        }
 
@@ -1256,7 +1254,7 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
 requeue:
                req->length = ep->maxpacket;
                if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
-                       printk(KERN_ERR
+                       pr_err(
                        "gs_read_complete: cannot queue read request, ret=%d\n",
                                ret);
                }
@@ -1270,7 +1268,7 @@ requeue:
 
        default:
                /* unexpected */
-               printk(KERN_ERR
+               pr_err(
                "gs_read_complete: unexpected status error, status=%d\n",
                        req->status);
                goto requeue;
@@ -1287,7 +1285,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
        struct gs_req_entry *gs_req = req->context;
 
        if (dev == NULL) {
-               printk(KERN_ERR "gs_write_complete: NULL device pointer\n");
+               pr_err("gs_write_complete: NULL device pointer\n");
                return;
        }
 
@@ -1296,8 +1294,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
                /* normal completion */
 requeue:
                if (gs_req == NULL) {
-                       printk(KERN_ERR
-                               "gs_write_complete: NULL request pointer\n");
+                       pr_err("gs_write_complete: NULL request pointer\n");
                        return;
                }
 
@@ -1316,7 +1313,7 @@ requeue:
                break;
 
        default:
-               printk(KERN_ERR
+               pr_err(
                "gs_write_complete: unexpected status error, status=%d\n",
                        req->status);
                goto requeue;
@@ -1351,7 +1348,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
                gs_device_desc.bcdDevice =
                                cpu_to_le16(GS_VERSION_NUM | gcnum);
        else {
-               printk(KERN_WARNING "gs_bind: controller '%s' not recognized\n",
+               pr_warning("gs_bind: controller '%s' not recognized\n",
                        gadget->name);
                /* unrecognized, but safe unless bulk is REALLY quirky */
                gs_device_desc.bcdDevice =
@@ -1375,7 +1372,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
        if (use_acm) {
                ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc);
                if (!ep) {
-                       printk(KERN_ERR "gs_bind: cannot run ACM on %s\n", gadget->name);
+                       pr_err("gs_bind: cannot run ACM on %s\n", gadget->name);
                        goto autoconf_fail;
                }
                gs_device_desc.idProduct = __constant_cpu_to_le16(
@@ -1425,7 +1422,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
        set_gadget_data(gadget, dev);
 
        if ((ret=gs_alloc_ports(dev, GFP_KERNEL)) != 0) {
-               printk(KERN_ERR "gs_bind: cannot allocate ports\n");
+               pr_err("gs_bind: cannot allocate ports\n");
                gs_unbind(gadget);
                return ret;
        }
@@ -1441,13 +1438,13 @@ static int __init gs_bind(struct usb_gadget *gadget)
 
        gadget->ep0->driver_data = dev;
 
-       printk(KERN_INFO "gs_bind: %s %s bound\n",
+       pr_info("gs_bind: %s %s bound\n",
                GS_LONG_NAME, GS_VERSION_STR);
 
        return 0;
 
 autoconf_fail:
-       printk(KERN_ERR "gs_bind: cannot autoconfigure on %s\n", gadget->name);
+       pr_err("gs_bind: cannot autoconfigure on %s\n", gadget->name);
        return -ENODEV;
 }
 
@@ -1480,7 +1477,7 @@ static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget)
                set_gadget_data(gadget, NULL);
        }
 
-       printk(KERN_INFO "gs_unbind: %s %s unbound\n", GS_LONG_NAME,
+       pr_info("gs_unbind: %s %s unbound\n", GS_LONG_NAME,
                GS_VERSION_STR);
 }
 
@@ -1513,7 +1510,8 @@ static int gs_setup(struct usb_gadget *gadget,
                break;
 
        default:
-               printk(KERN_ERR "gs_setup: unknown request, type=%02x, request=%02x, value=%04x, index=%04x, length=%d\n",
+               pr_err("gs_setup: unknown request, type=%02x, request=%02x, "
+                       "value=%04x, index=%04x, length=%d\n",
                        ctrl->bRequestType, ctrl->bRequest,
                        wValue, wIndex, wLength);
                break;
@@ -1526,7 +1524,7 @@ static int gs_setup(struct usb_gadget *gadget,
                                && (ret % gadget->ep0->maxpacket) == 0;
                ret = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
                if (ret < 0) {
-                       printk(KERN_ERR "gs_setup: cannot queue response, ret=%d\n",
+                       pr_err("gs_setup: cannot queue response, ret=%d\n",
                                ret);
                        req->status = 0;
                        gs_setup_complete(gadget->ep0, req);
@@ -1656,7 +1654,8 @@ set_interface_done:
                break;
 
        default:
-               printk(KERN_ERR "gs_setup: unknown standard request, type=%02x, request=%02x, value=%04x, index=%04x, length=%d\n",
+               pr_err("gs_setup: unknown standard request, type=%02x, "
+                       "request=%02x, value=%04x, index=%04x, length=%d\n",
                        ctrl->bRequestType, ctrl->bRequest,
                        wValue, wIndex, wLength);
                break;
@@ -1682,7 +1681,7 @@ static int gs_setup_class(struct usb_gadget *gadget,
                 * handler copy that data to port->port_line_coding (iff
                 * it's valid) and maybe pass it on.  Until then, fail.
                 */
-               printk(KERN_WARNING "gs_setup: set_line_coding "
+               pr_warning("gs_setup: set_line_coding "
                                "unuspported\n");
                break;
 
@@ -1702,12 +1701,12 @@ static int gs_setup_class(struct usb_gadget *gadget,
                 * handler use that to set the state (iff it's valid) and
                 * maybe pass it on.  Until then, fail.
                 */
-               printk(KERN_WARNING "gs_setup: set_control_line_state "
+               pr_warning("gs_setup: set_control_line_state "
                                "unuspported\n");
                break;
 
        default:
-               printk(KERN_ERR "gs_setup: unknown class request, "
+               pr_err("gs_setup: unknown class request, "
                                "type=%02x, request=%02x, value=%04x, "
                                "index=%04x, length=%d\n",
                        ctrl->bRequestType, ctrl->bRequest,
@@ -1724,7 +1723,8 @@ static int gs_setup_class(struct usb_gadget *gadget,
 static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req)
 {
        if (req->status || req->actual != req->length) {
-               printk(KERN_ERR "gs_setup_complete: status error, status=%d, actual=%d, length=%d\n",
+               pr_err("gs_setup_complete: status error, status=%d, "
+                       "actual=%d, length=%d\n",
                        req->status, req->actual, req->length);
        }
 }
@@ -1751,11 +1751,11 @@ static void gs_disconnect(struct usb_gadget *gadget)
 
        /* re-allocate ports for the next connection */
        if (gs_alloc_ports(dev, GFP_ATOMIC) != 0)
-               printk(KERN_ERR "gs_disconnect: cannot re-allocate ports\n");
+               pr_err("gs_disconnect: cannot re-allocate ports\n");
 
        spin_unlock_irqrestore(&dev->dev_lock, flags);
 
-       printk(KERN_INFO "gs_disconnect: %s disconnected\n", GS_LONG_NAME);
+       pr_info("gs_disconnect: %s disconnected\n", GS_LONG_NAME);
 }
 
 /*
@@ -1778,7 +1778,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
        struct gs_req_entry *req_entry;
 
        if (dev == NULL) {
-               printk(KERN_ERR "gs_set_config: NULL device pointer\n");
+               pr_err("gs_set_config: NULL device pointer\n");
                return 0;
        }
 
@@ -1823,7 +1823,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
                                dev->dev_notify_ep = ep;
                                dev->dev_notify_ep_desc = ep_desc;
                        } else {
-                               printk(KERN_ERR "gs_set_config: cannot enable notify endpoint %s, ret=%d\n",
+                               pr_err("gs_set_config: cannot enable NOTIFY "
+                                       "endpoint %s, ret=%d\n",
                                        ep->name, ret);
                                goto exit_reset_config;
                        }
@@ -1839,7 +1840,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
                                dev->dev_in_ep = ep;
                                dev->dev_in_ep_desc = ep_desc;
                        } else {
-                               printk(KERN_ERR "gs_set_config: cannot enable in endpoint %s, ret=%d\n",
+                               pr_err("gs_set_config: cannot enable IN "
+                                       "endpoint %s, ret=%d\n",
                                        ep->name, ret);
                                goto exit_reset_config;
                        }
@@ -1855,7 +1857,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
                                dev->dev_out_ep = ep;
                                dev->dev_out_ep_desc = ep_desc;
                        } else {
-                               printk(KERN_ERR "gs_set_config: cannot enable out endpoint %s, ret=%d\n",
+                               pr_err("gs_set_config: cannot enable OUT "
+                                       "endpoint %s, ret=%d\n",
                                        ep->name, ret);
                                goto exit_reset_config;
                        }
@@ -1865,7 +1868,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
 
        if (dev->dev_in_ep == NULL || dev->dev_out_ep == NULL
        || (config != GS_BULK_CONFIG_ID && dev->dev_notify_ep == NULL)) {
-               printk(KERN_ERR "gs_set_config: cannot find endpoints\n");
+               pr_err("gs_set_config: cannot find endpoints\n");
                ret = -ENODEV;
                goto exit_reset_config;
        }
@@ -1876,11 +1879,12 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
                if ((req=gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC))) {
                        req->complete = gs_read_complete;
                        if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
-                               printk(KERN_ERR "gs_set_config: cannot queue read request, ret=%d\n",
-                                       ret);
+                               pr_err("gs_set_config: cannot queue read "
+                                       "request, ret=%d\n", ret);
                        }
                } else {
-                       printk(KERN_ERR "gs_set_config: cannot allocate read requests\n");
+                       pr_err("gs_set_config: cannot allocate "
+                                       "read requests\n");
                        ret = -ENOMEM;
                        goto exit_reset_config;
                }
@@ -1893,13 +1897,14 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
                        req_entry->re_req->complete = gs_write_complete;
                        list_add(&req_entry->re_entry, &dev->dev_req_list);
                } else {
-                       printk(KERN_ERR "gs_set_config: cannot allocate write requests\n");
+                       pr_err("gs_set_config: cannot allocate "
+                                       "write requests\n");
                        ret = -ENOMEM;
                        goto exit_reset_config;
                }
        }
 
-       printk(KERN_INFO "gs_set_config: %s configured, %s speed %s config\n",
+       pr_info("gs_set_config: %s configured, %s speed %s config\n",
                GS_LONG_NAME,
                gadget->speed == USB_SPEED_HIGH ? "high" : "full",
                config == GS_BULK_CONFIG_ID ? "BULK" : "CDC-ACM");
@@ -1926,7 +1931,7 @@ static void gs_reset_config(struct gs_dev *dev)
        struct gs_req_entry *req_entry;
 
        if (dev == NULL) {
-               printk(KERN_ERR "gs_reset_config: NULL device pointer\n");
+               pr_err("gs_reset_config: NULL device pointer\n");
                return;
        }
 
index fcde5d9c87df11eb6d867f7ff4a3bee075c96bc4..d3d4f4048e6c39f7f958e263cf1761d194c25d34 100644 (file)
@@ -1115,7 +1115,7 @@ zero_bind (struct usb_gadget *gadget)
        ep = usb_ep_autoconfig (gadget, &fs_source_desc);
        if (!ep) {
 autoconf_fail:
-               printk (KERN_ERR "%s: can't autoconfigure on %s\n",
+               pr_err("%s: can't autoconfigure on %s\n",
                        shortname, gadget->name);
                return -ENODEV;
        }
@@ -1139,7 +1139,7 @@ autoconf_fail:
                 * things like configuration and altsetting numbering
                 * can need hardware-specific attention though.
                 */
-               printk (KERN_WARNING "%s: controller '%s' not recognized\n",
+               pr_warning("%s: controller '%s' not recognized\n",
                        shortname, gadget->name);
                device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999);
        }
index 49a91c5ee51bc4574808302dbf52a1960f703c12..d97b16b52efa051f39c3d2fd1cf97a1b961a58d6 100644 (file)
@@ -29,15 +29,6 @@ config USB_EHCI_HCD
          To compile this driver as a module, choose M here: the
          module will be called ehci-hcd.
 
-config USB_EHCI_SPLIT_ISO
-       bool "Full speed ISO transactions (EXPERIMENTAL)"
-       depends on USB_EHCI_HCD && EXPERIMENTAL
-       default n
-       ---help---
-         This code is new and hasn't been used with many different
-         EHCI or USB 2.0 transaction translator implementations.
-         It should work for ISO-OUT transfers, like audio.
-
 config USB_EHCI_ROOT_HUB_TT
        bool "Root Hub Transaction Translators (EXPERIMENTAL)"
        depends on USB_EHCI_HCD && EXPERIMENTAL
@@ -69,21 +60,30 @@ config USB_EHCI_TT_NEWSCHED
 
 config USB_EHCI_BIG_ENDIAN_MMIO
        bool
-       depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX)
+       depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX)
        default y
 
 config USB_EHCI_BIG_ENDIAN_DESC
        bool
-       depends on USB_EHCI_HCD && 440EPX
+       depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX)
        default y
 
 config USB_EHCI_FSL
        bool
+       depends on USB_EHCI_HCD
        select USB_EHCI_ROOT_HUB_TT
        default y if MPC834x || PPC_MPC831x
        ---help---
          Variation of ARC USB block used in some Freescale chips.
 
+config USB_EHCI_HCD_PPC_OF
+       bool "EHCI support for PPC USB controller on OF platform bus"
+       depends on USB_EHCI_HCD && PPC_OF
+       default y
+       ---help---
+         Enables support for the USB controller present on the PowerPC
+         OpenFirmware platform bus.
+
 config USB_ISP116X_HCD
        tristate "ISP116X HCD support"
        depends on USB
index 766ef68a0b43a98d81168ec781a9b01623a337f1..da7532d38bf1622044ed654147d25116a46a9b26 100644 (file)
@@ -222,6 +222,7 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
        .hub_control = ehci_hub_control,
        .bus_suspend = ehci_bus_suspend,
        .bus_resume = ehci_bus_resume,
+       .relinquish_port = ehci_relinquish_port,
 };
 
 /*-------------------------------------------------------------------------*/
index c9cc4413198e15d977a5d1e8b4d671eb2d72188a..64ebfc5548a31c04735bcb428aa040a68e4a2598 100644 (file)
@@ -323,7 +323,43 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
 
 #else
 
-/* troubleshooting help: expose state in sysfs */
+/* troubleshooting help: expose state in debugfs */
+
+static int debug_async_open(struct inode *, struct file *);
+static int debug_periodic_open(struct inode *, struct file *);
+static int debug_registers_open(struct inode *, struct file *);
+static int debug_async_open(struct inode *, struct file *);
+static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
+static int debug_close(struct inode *, struct file *);
+
+static const struct file_operations debug_async_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_async_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+static const struct file_operations debug_periodic_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_periodic_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+static const struct file_operations debug_registers_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_registers_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+
+static struct dentry *ehci_debug_root;
+
+struct debug_buffer {
+       ssize_t (*fill_func)(struct debug_buffer *);    /* fill method */
+       struct usb_bus *bus;
+       struct mutex mutex;     /* protect filling of buffer */
+       size_t count;           /* number of characters filled into buffer */
+       char *page;
+};
 
 #define speed_char(info1) ({ char tmp; \
                switch (info1 & (3 << 12)) { \
@@ -441,10 +477,8 @@ done:
        *nextp = next;
 }
 
-static ssize_t
-show_async (struct class_device *class_dev, char *buf)
+static ssize_t fill_async_buffer(struct debug_buffer *buf)
 {
-       struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct ehci_hcd         *ehci;
        unsigned long           flags;
@@ -452,14 +486,13 @@ show_async (struct class_device *class_dev, char *buf)
        char                    *next;
        struct ehci_qh          *qh;
 
-       *buf = 0;
-
-       bus = class_get_devdata(class_dev);
-       hcd = bus_to_hcd(bus);
+       hcd = bus_to_hcd(buf->bus);
        ehci = hcd_to_ehci (hcd);
-       next = buf;
+       next = buf->page;
        size = PAGE_SIZE;
 
+       *next = 0;
+
        /* dumps a snapshot of the async schedule.
         * usually empty except for long-term bulk reads, or head.
         * one QH per line, and TDs we know about
@@ -477,16 +510,12 @@ show_async (struct class_device *class_dev, char *buf)
        }
        spin_unlock_irqrestore (&ehci->lock, flags);
 
-       return strlen (buf);
+       return strlen(buf->page);
 }
-static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
 
 #define DBG_SCHED_LIMIT 64
-
-static ssize_t
-show_periodic (struct class_device *class_dev, char *buf)
+static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
 {
-       struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct ehci_hcd         *ehci;
        unsigned long           flags;
@@ -500,10 +529,9 @@ show_periodic (struct class_device *class_dev, char *buf)
                return 0;
        seen_count = 0;
 
-       bus = class_get_devdata(class_dev);
-       hcd = bus_to_hcd(bus);
+       hcd = bus_to_hcd(buf->bus);
        ehci = hcd_to_ehci (hcd);
-       next = buf;
+       next = buf->page;
        size = PAGE_SIZE;
 
        temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
@@ -623,14 +651,10 @@ show_periodic (struct class_device *class_dev, char *buf)
 
        return PAGE_SIZE - size;
 }
-static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
-
 #undef DBG_SCHED_LIMIT
 
-static ssize_t
-show_registers (struct class_device *class_dev, char *buf)
+static ssize_t fill_registers_buffer(struct debug_buffer *buf)
 {
-       struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct ehci_hcd         *ehci;
        unsigned long           flags;
@@ -639,15 +663,14 @@ show_registers (struct class_device *class_dev, char *buf)
        static char             fmt [] = "%*s\n";
        static char             label [] = "";
 
-       bus = class_get_devdata(class_dev);
-       hcd = bus_to_hcd(bus);
+       hcd = bus_to_hcd(buf->bus);
        ehci = hcd_to_ehci (hcd);
-       next = buf;
+       next = buf->page;
        size = PAGE_SIZE;
 
        spin_lock_irqsave (&ehci->lock, flags);
 
-       if (bus->controller->power.power_state.event) {
+       if (buf->bus->controller->power.power_state.event) {
                size = scnprintf (next, size,
                        "bus %s, device %s (driver " DRIVER_VERSION ")\n"
                        "%s\n"
@@ -763,9 +786,7 @@ show_registers (struct class_device *class_dev, char *buf)
        }
 
        if (ehci->reclaim) {
-               temp = scnprintf (next, size, "reclaim qh %p%s\n",
-                               ehci->reclaim,
-                               ehci->reclaim_ready ? " ready" : "");
+               temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim);
                size -= temp;
                next += temp;
        }
@@ -789,26 +810,150 @@ done:
 
        return PAGE_SIZE - size;
 }
-static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
 
-static inline void create_debug_files (struct ehci_hcd *ehci)
+static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
+                               ssize_t (*fill_func)(struct debug_buffer *))
 {
-       struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
-       int retval;
+       struct debug_buffer *buf;
+
+       buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
 
-       retval = class_device_create_file(cldev, &class_device_attr_async);
-       retval = class_device_create_file(cldev, &class_device_attr_periodic);
-       retval = class_device_create_file(cldev, &class_device_attr_registers);
+       if (buf) {
+               buf->bus = bus;
+               buf->fill_func = fill_func;
+               mutex_init(&buf->mutex);
+       }
+
+       return buf;
 }
 
-static inline void remove_debug_files (struct ehci_hcd *ehci)
+static int fill_buffer(struct debug_buffer *buf)
 {
-       struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
+       int ret = 0;
+
+       if (!buf->page)
+               buf->page = (char *)get_zeroed_page(GFP_KERNEL);
+
+       if (!buf->page) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = buf->fill_func(buf);
 
-       class_device_remove_file(cldev, &class_device_attr_async);
-       class_device_remove_file(cldev, &class_device_attr_periodic);
-       class_device_remove_file(cldev, &class_device_attr_registers);
+       if (ret >= 0) {
+               buf->count = ret;
+               ret = 0;
+       }
+
+out:
+       return ret;
 }
 
-#endif /* STUB_DEBUG_FILES */
+static ssize_t debug_output(struct file *file, char __user *user_buf,
+                           size_t len, loff_t *offset)
+{
+       struct debug_buffer *buf = file->private_data;
+       int ret = 0;
+
+       mutex_lock(&buf->mutex);
+       if (buf->count == 0) {
+               ret = fill_buffer(buf);
+               if (ret != 0) {
+                       mutex_unlock(&buf->mutex);
+                       goto out;
+               }
+       }
+       mutex_unlock(&buf->mutex);
+
+       ret = simple_read_from_buffer(user_buf, len, offset,
+                                     buf->page, buf->count);
+
+out:
+       return ret;
+
+}
+
+static int debug_close(struct inode *inode, struct file *file)
+{
+       struct debug_buffer *buf = file->private_data;
 
+       if (buf) {
+               if (buf->page)
+                       free_page((unsigned long)buf->page);
+               kfree(buf);
+       }
+
+       return 0;
+}
+static int debug_async_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static int debug_periodic_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private,
+                                         fill_periodic_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static int debug_registers_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private,
+                                         fill_registers_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static inline void create_debug_files (struct ehci_hcd *ehci)
+{
+       struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
+
+       ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
+       if (!ehci->debug_dir)
+               goto dir_error;
+
+       ehci->debug_async = debugfs_create_file("async", S_IRUGO,
+                                               ehci->debug_dir, bus,
+                                               &debug_async_fops);
+       if (!ehci->debug_async)
+               goto async_error;
+
+       ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
+                                                  ehci->debug_dir, bus,
+                                                  &debug_periodic_fops);
+       if (!ehci->debug_periodic)
+               goto periodic_error;
+
+       ehci->debug_registers = debugfs_create_file("registers", S_IRUGO,
+                                                   ehci->debug_dir, bus,
+                                                   &debug_registers_fops);
+       if (!ehci->debug_registers)
+               goto registers_error;
+       return;
+
+registers_error:
+       debugfs_remove(ehci->debug_periodic);
+periodic_error:
+       debugfs_remove(ehci->debug_async);
+async_error:
+       debugfs_remove(ehci->debug_dir);
+dir_error:
+       ehci->debug_periodic = NULL;
+       ehci->debug_async = NULL;
+       ehci->debug_dir = NULL;
+}
+
+static inline void remove_debug_files (struct ehci_hcd *ehci)
+{
+       debugfs_remove(ehci->debug_registers);
+       debugfs_remove(ehci->debug_periodic);
+       debugfs_remove(ehci->debug_async);
+       debugfs_remove(ehci->debug_dir);
+}
+
+#endif /* STUB_DEBUG_FILES */
index 430821cb95c8f32dae781f26a44290ae9138a7e3..adb0defa1631f0de75baaf6d1777119c1ba0d434 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "ehci-fsl.h"
 
-/* FIXME: Power Managment is un-ported so temporarily disable it */
+/* FIXME: Power Management is un-ported so temporarily disable it */
 #undef CONFIG_PM
 
 /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
@@ -323,6 +323,7 @@ static const struct hc_driver ehci_fsl_hc_driver = {
        .hub_control = ehci_hub_control,
        .bus_suspend = ehci_bus_suspend,
        .bus_resume = ehci_bus_resume,
+       .relinquish_port = ehci_relinquish_port,
 };
 
 static int ehci_fsl_drv_probe(struct platform_device *pdev)
index 5f2d74ed5ad73a299480022938645551d5179b09..4caa6a8b9a3772246dcb140dde02e5765104374f 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/usb.h>
 #include <linux/moduleparam.h>
 #include <linux/dma-mapping.h>
+#include <linux/debugfs.h>
 
 #include "../core/hcd.h"
 
@@ -109,7 +110,7 @@ static const char   hcd_name [] = "ehci_hcd";
 #define        EHCI_TUNE_MULT_TT       1
 #define        EHCI_TUNE_FLS           2       /* (small) 256 frame schedule */
 
-#define EHCI_IAA_JIFFIES       (HZ/100)        /* arbitrary; ~10 msec */
+#define EHCI_IAA_MSECS         10              /* arbitrary */
 #define EHCI_IO_JIFFIES                (HZ/10)         /* io watchdog > irq_thresh */
 #define EHCI_ASYNC_JIFFIES     (HZ/20)         /* async idle timeout */
 #define EHCI_SHRINK_JIFFIES    (HZ/200)        /* async qh unlink delay */
@@ -266,6 +267,7 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
 
 /*-------------------------------------------------------------------------*/
 
+static void end_unlink_async(struct ehci_hcd *ehci);
 static void ehci_work(struct ehci_hcd *ehci);
 
 #include "ehci-hub.c"
@@ -275,25 +277,41 @@ static void ehci_work(struct ehci_hcd *ehci);
 
 /*-------------------------------------------------------------------------*/
 
-static void ehci_watchdog (unsigned long param)
+static void ehci_iaa_watchdog(unsigned long param)
 {
        struct ehci_hcd         *ehci = (struct ehci_hcd *) param;
        unsigned long           flags;
+       u32                     status, cmd;
 
        spin_lock_irqsave (&ehci->lock, flags);
+       WARN_ON(!ehci->reclaim);
 
-       /* lost IAA irqs wedge things badly; seen with a vt8235 */
+       status = ehci_readl(ehci, &ehci->regs->status);
+       cmd = ehci_readl(ehci, &ehci->regs->command);
+       ehci_dbg(ehci, "IAA watchdog: status %x cmd %x\n", status, cmd);
+
+       /* lost IAA irqs wedge things badly; seen first with a vt8235 */
        if (ehci->reclaim) {
-               u32             status = ehci_readl(ehci, &ehci->regs->status);
                if (status & STS_IAA) {
                        ehci_vdbg (ehci, "lost IAA\n");
                        COUNT (ehci->stats.lost_iaa);
                        ehci_writel(ehci, STS_IAA, &ehci->regs->status);
-                       ehci->reclaim_ready = 1;
                }
+               ehci_writel(ehci, cmd & ~CMD_IAAD, &ehci->regs->command);
+               end_unlink_async(ehci);
        }
 
-       /* stop async processing after it's idled a bit */
+       spin_unlock_irqrestore(&ehci->lock, flags);
+}
+
+static void ehci_watchdog(unsigned long param)
+{
+       struct ehci_hcd         *ehci = (struct ehci_hcd *) param;
+       unsigned long           flags;
+
+       spin_lock_irqsave(&ehci->lock, flags);
+
+       /* stop async processing after it's idled a bit */
        if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
                start_unlink_async (ehci, ehci->async);
 
@@ -363,8 +381,6 @@ static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
 static void ehci_work (struct ehci_hcd *ehci)
 {
        timer_action_done (ehci, TIMER_IO_WATCHDOG);
-       if (ehci->reclaim_ready)
-               end_unlink_async (ehci);
 
        /* another CPU may drop ehci->lock during a schedule scan while
         * it reports urb completions.  this flag guards against bogus
@@ -399,6 +415,7 @@ static void ehci_stop (struct usb_hcd *hcd)
 
        /* no more interrupts ... */
        del_timer_sync (&ehci->watchdog);
+       del_timer_sync(&ehci->iaa_watchdog);
 
        spin_lock_irq(&ehci->lock);
        if (HC_IS_RUNNING (hcd->state))
@@ -447,6 +464,10 @@ static int ehci_init(struct usb_hcd *hcd)
        ehci->watchdog.function = ehci_watchdog;
        ehci->watchdog.data = (unsigned long) ehci;
 
+       init_timer(&ehci->iaa_watchdog);
+       ehci->iaa_watchdog.function = ehci_iaa_watchdog;
+       ehci->iaa_watchdog.data = (unsigned long) ehci;
+
        /*
         * hw default: 1K periodic list heads, one per frame.
         * periodic_size can shrink by USBCMD update if hcc_params allows.
@@ -463,7 +484,6 @@ static int ehci_init(struct usb_hcd *hcd)
                ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
 
        ehci->reclaim = NULL;
-       ehci->reclaim_ready = 0;
        ehci->next_uframe = -1;
 
        /*
@@ -654,8 +674,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
        /* complete the unlinking of some qh [4.15.2.3] */
        if (status & STS_IAA) {
                COUNT (ehci->stats.reclaim);
-               ehci->reclaim_ready = 1;
-               bh = 1;
+               end_unlink_async(ehci);
        }
 
        /* remote wakeup [4.3.1] */
@@ -761,10 +780,16 @@ static int ehci_urb_enqueue (
 
 static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
 {
-       /* if we need to use IAA and it's busy, defer */
-       if (qh->qh_state == QH_STATE_LINKED
-                       && ehci->reclaim
-                       && HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) {
+       /* failfast */
+       if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state))
+               end_unlink_async(ehci);
+
+       /* if it's not linked then there's nothing to do */
+       if (qh->qh_state != QH_STATE_LINKED)
+               ;
+
+       /* defer till later if busy */
+       else if (ehci->reclaim) {
                struct ehci_qh          *last;
 
                for (last = ehci->reclaim;
@@ -774,12 +799,8 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
                qh->qh_state = QH_STATE_UNLINK_WAIT;
                last->reclaim = qh;
 
-       /* bypass IAA if the hc can't care */
-       } else if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && ehci->reclaim)
-               end_unlink_async (ehci);
-
-       /* something else might have unlinked the qh by now */
-       if (qh->qh_state == QH_STATE_LINKED)
+       /* start IAA cycle */
+       } else
                start_unlink_async (ehci, qh);
 }
 
@@ -806,7 +827,19 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
                qh = (struct ehci_qh *) urb->hcpriv;
                if (!qh)
                        break;
-               unlink_async (ehci, qh);
+               switch (qh->qh_state) {
+               case QH_STATE_LINKED:
+               case QH_STATE_COMPLETING:
+                       unlink_async(ehci, qh);
+                       break;
+               case QH_STATE_UNLINK:
+               case QH_STATE_UNLINK_WAIT:
+                       /* already started */
+                       break;
+               case QH_STATE_IDLE:
+                       WARN_ON(1);
+                       break;
+               }
                break;
 
        case PIPE_INTERRUPT:
@@ -829,16 +862,16 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
                /* reschedule QH iff another request is queued */
                if (!list_empty (&qh->qtd_list)
                                && HC_IS_RUNNING (hcd->state)) {
-                       int status;
+                       int schedule_status;
 
-                       status = qh_schedule (ehci, qh);
+                       schedule_status = qh_schedule (ehci, qh);
                        spin_unlock_irqrestore (&ehci->lock, flags);
 
-                       if (status != 0) {
+                       if (schedule_status != 0) {
                                // shouldn't happen often, but ...
                                // FIXME kill those tds' urbs
                                err ("can't reschedule qh %p, err %d",
-                                       qh, status);
+                                       qh, schedule_status);
                        }
                        return status;
                }
@@ -898,6 +931,7 @@ rescan:
                unlink_async (ehci, qh);
                /* FALL THROUGH */
        case QH_STATE_UNLINK:           /* wait for hw to finish? */
+       case QH_STATE_UNLINK_WAIT:
 idle_timeout:
                spin_unlock_irqrestore (&ehci->lock, flags);
                schedule_timeout_uninterruptible(1);
@@ -959,11 +993,26 @@ MODULE_LICENSE ("GPL");
 #define        PS3_SYSTEM_BUS_DRIVER   ps3_ehci_driver
 #endif
 
-#ifdef CONFIG_440EPX
+#if defined(CONFIG_440EPX) && !defined(CONFIG_PPC_MERGE)
 #include "ehci-ppc-soc.c"
 #define        PLATFORM_DRIVER         ehci_ppc_soc_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_HCD_PPC_OF
+#include "ehci-ppc-of.c"
+#define OF_PLATFORM_DRIVER     ehci_hcd_ppc_of_driver
+#endif
+
+#ifdef CONFIG_ARCH_ORION
+#include "ehci-orion.c"
+#define        PLATFORM_DRIVER         ehci_orion_driver
+#endif
+
+#ifdef CONFIG_ARCH_IXP4XX
+#include "ehci-ixp4xx.c"
+#define        PLATFORM_DRIVER         ixp4xx_ehci_driver
+#endif
+
 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
     !defined(PS3_SYSTEM_BUS_DRIVER)
 #error "missing bus glue for ehci-hcd"
@@ -978,41 +1027,66 @@ static int __init ehci_hcd_init(void)
                 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
                 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
 
+#ifdef DEBUG
+       ehci_debug_root = debugfs_create_dir("ehci", NULL);
+       if (!ehci_debug_root)
+               return -ENOENT;
+#endif
+
 #ifdef PLATFORM_DRIVER
        retval = platform_driver_register(&PLATFORM_DRIVER);
        if (retval < 0)
-               return retval;
+               goto clean0;
 #endif
 
 #ifdef PCI_DRIVER
        retval = pci_register_driver(&PCI_DRIVER);
-       if (retval < 0) {
-#ifdef PLATFORM_DRIVER
-               platform_driver_unregister(&PLATFORM_DRIVER);
-#endif
-               return retval;
-       }
+       if (retval < 0)
+               goto clean1;
 #endif
 
 #ifdef PS3_SYSTEM_BUS_DRIVER
        retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
-       if (retval < 0) {
-#ifdef PLATFORM_DRIVER
-               platform_driver_unregister(&PLATFORM_DRIVER);
+       if (retval < 0)
+               goto clean2;
+#endif
+
+#ifdef OF_PLATFORM_DRIVER
+       retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
+       if (retval < 0)
+               goto clean3;
+#endif
+       return retval;
+
+#ifdef OF_PLATFORM_DRIVER
+       /* of_unregister_platform_driver(&OF_PLATFORM_DRIVER); */
+clean3:
+#endif
+#ifdef PS3_SYSTEM_BUS_DRIVER
+       ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
+clean2:
 #endif
 #ifdef PCI_DRIVER
-               pci_unregister_driver(&PCI_DRIVER);
+       pci_unregister_driver(&PCI_DRIVER);
+clean1:
 #endif
-               return retval;
-       }
+#ifdef PLATFORM_DRIVER
+       platform_driver_unregister(&PLATFORM_DRIVER);
+clean0:
+#endif
+#ifdef DEBUG
+       debugfs_remove(ehci_debug_root);
+       ehci_debug_root = NULL;
 #endif
-
        return retval;
 }
 module_init(ehci_hcd_init);
 
 static void __exit ehci_hcd_cleanup(void)
 {
+#ifdef OF_PLATFORM_DRIVER
+       of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
+#endif
 #ifdef PLATFORM_DRIVER
        platform_driver_unregister(&PLATFORM_DRIVER);
 #endif
@@ -1022,6 +1096,9 @@ static void __exit ehci_hcd_cleanup(void)
 #ifdef PS3_SYSTEM_BUS_DRIVER
        ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
 #endif
+#ifdef DEBUG
+       debugfs_remove(ehci_debug_root);
+#endif
 }
 module_exit(ehci_hcd_cleanup);
 
index 735db4aec831cc2302a761801f51eccc25efdeb7..40e8240b7851f012e0e4fe9e71c37ab27d99d67a 100644 (file)
@@ -123,6 +123,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
 
        if (time_before (jiffies, ehci->next_statechange))
                msleep(5);
+       del_timer_sync(&ehci->watchdog);
+       del_timer_sync(&ehci->iaa_watchdog);
 
        port = HCS_N_PORTS (ehci->hcs_params);
        spin_lock_irq (&ehci->lock);
@@ -134,7 +136,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
        }
        ehci->command = ehci_readl(ehci, &ehci->regs->command);
        if (ehci->reclaim)
-               ehci->reclaim_ready = 1;
+               end_unlink_async(ehci);
        ehci_work(ehci);
 
        /* Unlike other USB host controller types, EHCI doesn't have
@@ -170,8 +172,11 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
                }
        }
 
+       /* Apparently some devices need a >= 1-uframe delay here */
+       if (ehci->bus_suspended)
+               udelay(150);
+
        /* turn off now-idle HC */
-       del_timer_sync (&ehci->watchdog);
        ehci_halt (ehci);
        hcd->state = HC_STATE_SUSPENDED;
 
@@ -291,14 +296,16 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
 /*-------------------------------------------------------------------------*/
 
 /* Display the ports dedicated to the companion controller */
-static ssize_t show_companion(struct class_device *class_dev, char *buf)
+static ssize_t show_companion(struct device *dev,
+                             struct device_attribute *attr,
+                             char *buf)
 {
        struct ehci_hcd         *ehci;
        int                     nports, index, n;
        int                     count = PAGE_SIZE;
        char                    *ptr = buf;
 
-       ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev)));
+       ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
        nports = HCS_N_PORTS(ehci->hcs_params);
 
        for (index = 0; index < nports; ++index) {
@@ -312,40 +319,21 @@ static ssize_t show_companion(struct class_device *class_dev, char *buf)
 }
 
 /*
- * Dedicate or undedicate a port to the companion controller.
- * Syntax is "[-]portnum", where a leading '-' sign means
- * return control of the port to the EHCI controller.
+ * Sets the owner of a port
  */
-static ssize_t store_companion(struct class_device *class_dev,
-               const char *buf, size_t count)
+static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
 {
-       struct ehci_hcd         *ehci;
-       int                     portnum, new_owner, try;
        u32 __iomem             *status_reg;
        u32                     port_status;
+       int                     try;
 
-       ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev)));
-       new_owner = PORT_OWNER;         /* Owned by companion */
-       if (sscanf(buf, "%d", &portnum) != 1)
-               return -EINVAL;
-       if (portnum < 0) {
-               portnum = - portnum;
-               new_owner = 0;          /* Owned by EHCI */
-       }
-       if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
-               return -ENOENT;
-       status_reg = &ehci->regs->port_status[--portnum];
-       if (new_owner)
-               set_bit(portnum, &ehci->companion_ports);
-       else
-               clear_bit(portnum, &ehci->companion_ports);
+       status_reg = &ehci->regs->port_status[portnum];
 
        /*
         * The controller won't set the OWNER bit if the port is
         * enabled, so this loop will sometimes require at least two
         * iterations: one to disable the port and one to set OWNER.
         */
-
        for (try = 4; try > 0; --try) {
                spin_lock_irq(&ehci->lock);
                port_status = ehci_readl(ehci, status_reg);
@@ -362,9 +350,39 @@ static ssize_t store_companion(struct class_device *class_dev,
                if (try > 1)
                        msleep(5);
        }
+}
+
+/*
+ * Dedicate or undedicate a port to the companion controller.
+ * Syntax is "[-]portnum", where a leading '-' sign means
+ * return control of the port to the EHCI controller.
+ */
+static ssize_t store_companion(struct device *dev,
+                              struct device_attribute *attr,
+                              const char *buf, size_t count)
+{
+       struct ehci_hcd         *ehci;
+       int                     portnum, new_owner;
+
+       ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
+       new_owner = PORT_OWNER;         /* Owned by companion */
+       if (sscanf(buf, "%d", &portnum) != 1)
+               return -EINVAL;
+       if (portnum < 0) {
+               portnum = - portnum;
+               new_owner = 0;          /* Owned by EHCI */
+       }
+       if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
+               return -ENOENT;
+       portnum--;
+       if (new_owner)
+               set_bit(portnum, &ehci->companion_ports);
+       else
+               clear_bit(portnum, &ehci->companion_ports);
+       set_owner(ehci, portnum, new_owner);
        return count;
 }
-static CLASS_DEVICE_ATTR(companion, 0644, show_companion, store_companion);
+static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
 
 static inline void create_companion_file(struct ehci_hcd *ehci)
 {
@@ -372,16 +390,16 @@ static inline void create_companion_file(struct ehci_hcd *ehci)
 
        /* with integrated TT there is no companion! */
        if (!ehci_is_TDI(ehci))
-               i = class_device_create_file(ehci_to_hcd(ehci)->self.class_dev,
-                               &class_device_attr_companion);
+               i = device_create_file(ehci_to_hcd(ehci)->self.dev,
+                                      &dev_attr_companion);
 }
 
 static inline void remove_companion_file(struct ehci_hcd *ehci)
 {
        /* with integrated TT there is no companion! */
        if (!ehci_is_TDI(ehci))
-               class_device_remove_file(ehci_to_hcd(ehci)->self.class_dev,
-                               &class_device_attr_companion);
+               device_remove_file(ehci_to_hcd(ehci)->self.dev,
+                                  &dev_attr_companion);
 }
 
 
@@ -393,10 +411,8 @@ static int check_reset_complete (
        u32 __iomem     *status_reg,
        int             port_status
 ) {
-       if (!(port_status & PORT_CONNECT)) {
-               ehci->reset_done [index] = 0;
+       if (!(port_status & PORT_CONNECT))
                return port_status;
-       }
 
        /* if reset finished and it's still not enabled -- handoff */
        if (!(port_status & PORT_PE)) {
@@ -475,8 +491,6 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
                 * controller by the user.
                 */
 
-               if (!(temp & PORT_CONNECT))
-                       ehci->reset_done [i] = 0;
                if ((temp & mask) != 0
                                || ((temp & PORT_RESUME) != 0
                                        && time_after_eq(jiffies,
@@ -864,3 +878,13 @@ error:
        spin_unlock_irqrestore (&ehci->lock, flags);
        return retval;
 }
+
+static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
+{
+       struct ehci_hcd         *ehci = hcd_to_ehci(hcd);
+
+       if (ehci_is_TDI(ehci))
+               return;
+       set_owner(ehci, --portnum, PORT_OWNER);
+}
+
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
new file mode 100644 (file)
index 0000000..3041d8f
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * IXP4XX EHCI Host Controller Driver
+ *
+ * Author: Vladimir Barinov <vbarinov@ru.mvista.com>
+ *
+ * Based on "ehci-fsl.c" by Randy Vinson <rvinson@mvista.com>
+ *
+ * 2007 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#include <linux/platform_device.h>
+
+static int ixp4xx_ehci_init(struct usb_hcd *hcd)
+{
+       struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+       int retval = 0;
+
+       ehci->big_endian_desc = 1;
+       ehci->big_endian_mmio = 1;
+
+       ehci->caps = hcd->regs + 0x100;
+       ehci->regs = hcd->regs + 0x100
+               + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
+       ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
+
+       ehci->is_tdi_rh_tt = 1;
+       ehci_reset(ehci);
+
+       retval = ehci_init(hcd);
+       if (retval)
+               return retval;
+
+       ehci_port_power(ehci, 0);
+
+       return retval;
+}
+
+static const struct hc_driver ixp4xx_ehci_hc_driver = {
+       .description            = hcd_name,
+       .product_desc           = "IXP4XX EHCI Host Controller",
+       .hcd_priv_size          = sizeof(struct ehci_hcd),
+       .irq                    = ehci_irq,
+       .flags                  = HCD_MEMORY | HCD_USB2,
+       .reset                  = ixp4xx_ehci_init,
+       .start                  = ehci_run,
+       .stop                   = ehci_stop,
+       .shutdown               = ehci_shutdown,
+       .urb_enqueue            = ehci_urb_enqueue,
+       .urb_dequeue            = ehci_urb_dequeue,
+       .endpoint_disable       = ehci_endpoint_disable,
+       .get_frame_number       = ehci_get_frame,
+       .hub_status_data        = ehci_hub_status_data,
+       .hub_control            = ehci_hub_control,
+#if defined(CONFIG_PM)
+       .bus_suspend            = ehci_bus_suspend,
+       .bus_resume             = ehci_bus_resume,
+#endif
+};
+
+static int ixp4xx_ehci_probe(struct platform_device *pdev)
+{
+       struct usb_hcd *hcd;
+       const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
+       struct resource *res;
+       int irq;
+       int retval;
+
+       if (usb_disabled())
+               return -ENODEV;
+
+       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+       if (!res) {
+               dev_err(&pdev->dev,
+                       "Found HC with no IRQ. Check %s setup!\n",
+                       pdev->dev.bus_id);
+               return -ENODEV;
+       }
+       irq = res->start;
+
+       hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
+       if (!hcd) {
+               retval = -ENOMEM;
+               goto fail_create_hcd;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(&pdev->dev,
+                       "Found HC with no register addr. Check %s setup!\n",
+                       pdev->dev.bus_id);
+               retval = -ENODEV;
+               goto fail_request_resource;
+       }
+       hcd->rsrc_start = res->start;
+       hcd->rsrc_len = res->end - res->start + 1;
+
+       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
+                               driver->description)) {
+               dev_dbg(&pdev->dev, "controller already in use\n");
+               retval = -EBUSY;
+               goto fail_request_resource;
+       }
+
+       hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
+       if (hcd->regs == NULL) {
+               dev_dbg(&pdev->dev, "error mapping memory\n");
+               retval = -EFAULT;
+               goto fail_ioremap;
+       }
+
+       retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
+       if (retval)
+               goto fail_add_hcd;
+
+       return retval;
+
+fail_add_hcd:
+       iounmap(hcd->regs);
+fail_ioremap:
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+fail_request_resource:
+       usb_put_hcd(hcd);
+fail_create_hcd:
+       dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval);
+       return retval;
+}
+
+static int ixp4xx_ehci_remove(struct platform_device *pdev)
+{
+       struct usb_hcd *hcd = platform_get_drvdata(pdev);
+
+       usb_remove_hcd(hcd);
+       iounmap(hcd->regs);
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+       usb_put_hcd(hcd);
+
+       return 0;
+}
+
+MODULE_ALIAS("ixp4xx-ehci");
+
+static struct platform_driver ixp4xx_ehci_driver = {
+       .probe = ixp4xx_ehci_probe,
+       .remove = ixp4xx_ehci_remove,
+       .driver = {
+               .name = "ixp4xx-ehci",
+               .bus = &platform_bus_type
+       },
+};
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
new file mode 100644 (file)
index 0000000..e129981
--- /dev/null
@@ -0,0 +1,272 @@
+/*
+ * drivers/usb/host/ehci-orion.c
+ *
+ * Tzachi Perelstein <tzachi@marvell.com>
+ *
+ * This file is licensed under  the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <asm/arch/orion.h>
+
+#define rdl(off)       __raw_readl(hcd->regs + (off))
+#define wrl(off, val)  __raw_writel((val), hcd->regs + (off))
+
+#define USB_CAUSE              0x310
+#define USB_MASK               0x314
+#define USB_CMD                        0x140
+#define USB_MODE               0x1a8
+#define USB_IPG                        0x360
+#define USB_PHY_PWR_CTRL       0x400
+#define USB_PHY_TX_CTRL                0x420
+#define USB_PHY_RX_CTRL                0x430
+#define USB_PHY_IVREF_CTRL     0x440
+#define USB_PHY_TST_GRP_CTRL   0x450
+
+/*
+ * Implement Orion USB controller specification guidelines
+ */
+static void orion_usb_setup(struct usb_hcd *hcd)
+{
+       /*
+        * Clear interrupt cause and mask
+        */
+       wrl(USB_CAUSE, 0);
+       wrl(USB_MASK, 0);
+
+       /*
+        * Reset controller
+        */
+       wrl(USB_CMD, rdl(USB_CMD) | 0x2);
+       while (rdl(USB_CMD) & 0x2);
+
+       /*
+        * GL# USB-10: Set IPG for non start of frame packets
+        * Bits[14:8]=0xc
+        */
+       wrl(USB_IPG, (rdl(USB_IPG) & ~0x7f00) | 0xc00);
+
+       /*
+        * GL# USB-9: USB 2.0 Power Control
+        * BG_VSEL[7:6]=0x1
+        */
+       wrl(USB_PHY_PWR_CTRL, (rdl(USB_PHY_PWR_CTRL) & ~0xc0)| 0x40);
+
+       /*
+        * GL# USB-1: USB PHY Tx Control - force calibration to '8'
+        * TXDATA_BLOCK_EN[21]=0x1, EXT_RCAL_EN[13]=0x1, IMP_CAL[6:3]=0x8
+        */
+       wrl(USB_PHY_TX_CTRL, (rdl(USB_PHY_TX_CTRL) & ~0x78) | 0x202040);
+
+       /*
+        * GL# USB-3 GL# USB-9: USB PHY Rx Control
+        * RXDATA_BLOCK_LENGHT[31:30]=0x3, EDGE_DET_SEL[27:26]=0,
+        * CDR_FASTLOCK_EN[21]=0, DISCON_THRESHOLD[9:8]=0, SQ_THRESH[7:4]=0x1
+        */
+       wrl(USB_PHY_RX_CTRL, (rdl(USB_PHY_RX_CTRL) & ~0xc2003f0) | 0xc0000010);
+
+       /*
+        * GL# USB-3 GL# USB-9: USB PHY IVREF Control
+        * PLLVDD12[1:0]=0x2, RXVDD[5:4]=0x3, Reserved[19]=0
+        */
+       wrl(USB_PHY_IVREF_CTRL, (rdl(USB_PHY_IVREF_CTRL) & ~0x80003 ) | 0x32);
+
+       /*
+        * GL# USB-3 GL# USB-9: USB PHY Test Group Control
+        * REG_FIFO_SQ_RST[15]=0
+        */
+       wrl(USB_PHY_TST_GRP_CTRL, rdl(USB_PHY_TST_GRP_CTRL) & ~0x8000);
+
+       /*
+        * Stop and reset controller
+        */
+       wrl(USB_CMD, rdl(USB_CMD) & ~0x1);
+       wrl(USB_CMD, rdl(USB_CMD) | 0x2);
+       while (rdl(USB_CMD) & 0x2);
+
+       /*
+        * GL# USB-5 Streaming disable REG_USB_MODE[4]=1
+        * TBD: This need to be done after each reset!
+        * GL# USB-4 Setup USB Host mode
+        */
+       wrl(USB_MODE, 0x13);
+}
+
+static int ehci_orion_setup(struct usb_hcd *hcd)
+{
+       struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+       int retval;
+
+       retval = ehci_halt(ehci);
+       if (retval)
+               return retval;
+
+       /*
+        * data structure init
+        */
+       retval = ehci_init(hcd);
+       if (retval)
+               return retval;
+
+       ehci_reset(ehci);
+       ehci_port_power(ehci, 0);
+
+       return retval;
+}
+
+static const struct hc_driver ehci_orion_hc_driver = {
+       .description = hcd_name,
+       .product_desc = "Marvell Orion EHCI",
+       .hcd_priv_size = sizeof(struct ehci_hcd),
+
+       /*
+        * generic hardware linkage
+        */
+       .irq = ehci_irq,
+       .flags = HCD_MEMORY | HCD_USB2,
+
+       /*
+        * basic lifecycle operations
+        */
+       .reset = ehci_orion_setup,
+       .start = ehci_run,
+#ifdef CONFIG_PM
+       .suspend = ehci_bus_suspend,
+       .resume = ehci_bus_resume,
+#endif
+       .stop = ehci_stop,
+       .shutdown = ehci_shutdown,
+
+       /*
+        * managing i/o requests and associated device resources
+        */
+       .urb_enqueue = ehci_urb_enqueue,
+       .urb_dequeue = ehci_urb_dequeue,
+       .endpoint_disable = ehci_endpoint_disable,
+
+       /*
+        * scheduling support
+        */
+       .get_frame_number = ehci_get_frame,
+
+       /*
+        * root hub support
+        */
+       .hub_status_data = ehci_hub_status_data,
+       .hub_control = ehci_hub_control,
+       .bus_suspend = ehci_bus_suspend,
+       .bus_resume = ehci_bus_resume,
+};
+
+static int __init ehci_orion_drv_probe(struct platform_device *pdev)
+{
+       struct resource *res;
+       struct usb_hcd *hcd;
+       struct ehci_hcd *ehci;
+       void __iomem *regs;
+       int irq, err;
+
+       if (usb_disabled())
+               return -ENODEV;
+
+       pr_debug("Initializing Orion-SoC USB Host Controller\n");
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq <= 0) {
+               dev_err(&pdev->dev,
+                       "Found HC with no IRQ. Check %s setup!\n",
+                       pdev->dev.bus_id);
+               err = -ENODEV;
+               goto err1;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(&pdev->dev,
+                       "Found HC with no register addr. Check %s setup!\n",
+                       pdev->dev.bus_id);
+               err = -ENODEV;
+               goto err1;
+       }
+
+       if (!request_mem_region(res->start, res->end - res->start + 1,
+                               ehci_orion_hc_driver.description)) {
+               dev_dbg(&pdev->dev, "controller already in use\n");
+               err = -EBUSY;
+               goto err1;
+       }
+
+       regs = ioremap(res->start, res->end - res->start + 1);
+       if (regs == NULL) {
+               dev_dbg(&pdev->dev, "error mapping memory\n");
+               err = -EFAULT;
+               goto err2;
+       }
+
+       hcd = usb_create_hcd(&ehci_orion_hc_driver,
+                       &pdev->dev, pdev->dev.bus_id);
+       if (!hcd) {
+               err = -ENOMEM;
+               goto err3;
+       }
+
+       hcd->rsrc_start = res->start;
+       hcd->rsrc_len = res->end - res->start + 1;
+       hcd->regs = regs;
+
+       ehci = hcd_to_ehci(hcd);
+       ehci->caps = hcd->regs + 0x100;
+       ehci->regs = hcd->regs + 0x100 +
+               HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
+       ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
+       ehci->is_tdi_rh_tt = 1;
+       ehci->sbrn = 0x20;
+
+       /*
+        * setup Orion USB controller
+        */
+       orion_usb_setup(hcd);
+
+       err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED);
+       if (err)
+               goto err4;
+
+       return 0;
+
+err4:
+       usb_put_hcd(hcd);
+err3:
+       iounmap(regs);
+err2:
+       release_mem_region(res->start, res->end - res->start + 1);
+err1:
+       dev_err(&pdev->dev, "init %s fail, %d\n",
+               pdev->dev.bus_id, err);
+
+       return err;
+}
+
+static int __exit ehci_orion_drv_remove(struct platform_device *pdev)
+{
+       struct usb_hcd *hcd = platform_get_drvdata(pdev);
+
+       usb_remove_hcd(hcd);
+       iounmap(hcd->regs);
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+       usb_put_hcd(hcd);
+
+       return 0;
+}
+
+MODULE_ALIAS("platform:orion-ehci");
+
+static struct platform_driver ehci_orion_driver = {
+       .probe          = ehci_orion_drv_probe,
+       .remove         = __exit_p(ehci_orion_drv_remove),
+       .shutdown       = usb_hcd_platform_shutdown,
+       .driver.name    = "orion-ehci",
+};
index ad0d4965f2fb5df834cc54d0f5b6eed29d1e5e3b..3ba01664f82154b00bef518eea7c3e809566f63b 100644 (file)
@@ -305,7 +305,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd)
        /* emptying the schedule aborts any urbs */
        spin_lock_irq(&ehci->lock);
        if (ehci->reclaim)
-               ehci->reclaim_ready = 1;
+               end_unlink_async(ehci);
        ehci_work(ehci);
        spin_unlock_irq(&ehci->lock);
 
@@ -364,6 +364,7 @@ static const struct hc_driver ehci_pci_hc_driver = {
        .hub_control =          ehci_hub_control,
        .bus_suspend =          ehci_bus_suspend,
        .bus_resume =           ehci_bus_resume,
+       .relinquish_port =      ehci_relinquish_port,
 };
 
 /*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
new file mode 100644 (file)
index 0000000..ee305b1
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * EHCI HCD (Host Controller Driver) for USB.
+ *
+ * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
+ * Tested on AMCC PPC 440EPx
+ *
+ * Valentine Barshak <vbarshak@ru.mvista.com>
+ *
+ * Based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
+ * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
+ *
+ * This file is licenced under the GPL.
+ */
+
+#include <linux/signal.h>
+
+#include <linux/of.h>
+#include <linux/of_platform.h>
+
+/* called during probe() after chip reset completes */
+static int ehci_ppc_of_setup(struct usb_hcd *hcd)
+{
+       struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+       int             retval;
+
+       retval = ehci_halt(ehci);
+       if (retval)
+               return retval;
+
+       retval = ehci_init(hcd);
+       if (retval)
+               return retval;
+
+       ehci->sbrn = 0x20;
+       return ehci_reset(ehci);
+}
+
+
+static const struct hc_driver ehci_ppc_of_hc_driver = {
+       .description            = hcd_name,
+       .product_desc           = "OF EHCI",
+       .hcd_priv_size          = sizeof(struct ehci_hcd),
+
+       /*
+        * generic hardware linkage
+        */
+       .irq                    = ehci_irq,
+       .flags                  = HCD_MEMORY | HCD_USB2,
+
+       /*
+        * basic lifecycle operations
+        */
+       .reset                  = ehci_ppc_of_setup,
+       .start                  = ehci_run,
+       .stop                   = ehci_stop,
+       .shutdown               = ehci_shutdown,
+
+       /*
+        * managing i/o requests and associated device resources
+        */
+       .urb_enqueue            = ehci_urb_enqueue,
+       .urb_dequeue            = ehci_urb_dequeue,
+       .endpoint_disable       = ehci_endpoint_disable,
+
+       /*
+        * scheduling support
+        */
+       .get_frame_number       = ehci_get_frame,
+
+       /*
+        * root hub support
+        */
+       .hub_status_data        = ehci_hub_status_data,
+       .hub_control            = ehci_hub_control,
+#ifdef CONFIG_PM
+       .bus_suspend            = ehci_bus_suspend,
+       .bus_resume             = ehci_bus_resume,
+#endif
+};
+
+
+/*
+ * 440EPx Errata USBH_3
+ * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
+ */
+#define PPC440EPX_EHCI0_INSREG_BMT     (0x1 << 0)
+static int __devinit
+ppc44x_enable_bmt(struct device_node *dn)
+{
+       __iomem u32 *insreg_virt;
+
+       insreg_virt = of_iomap(dn, 1);
+       if (!insreg_virt)
+               return  -EINVAL;
+
+       out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT);
+
+       iounmap(insreg_virt);
+       return 0;
+}
+
+
+static int __devinit
+ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
+{
+       struct device_node *dn = op->node;
+       struct usb_hcd *hcd;
+       struct ehci_hcd *ehci;
+       struct resource res;
+       int irq;
+       int rv;
+
+       if (usb_disabled())
+               return -ENODEV;
+
+       dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
+
+       rv = of_address_to_resource(dn, 0, &res);
+       if (rv)
+               return rv;
+
+       hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
+       if (!hcd)
+               return -ENOMEM;
+
+       hcd->rsrc_start = res.start;
+       hcd->rsrc_len = res.end - res.start + 1;
+
+       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
+               printk(KERN_ERR __FILE__ ": request_mem_region failed\n");
+               rv = -EBUSY;
+               goto err_rmr;
+       }
+
+       irq = irq_of_parse_and_map(dn, 0);
+       if (irq == NO_IRQ) {
+               printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n");
+               rv = -EBUSY;
+               goto err_irq;
+       }
+
+       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
+       if (!hcd->regs) {
+               printk(KERN_ERR __FILE__ ": ioremap failed\n");
+               rv = -ENOMEM;
+               goto err_ioremap;
+       }
+
+       ehci = hcd_to_ehci(hcd);
+
+       if (of_get_property(dn, "big-endian", NULL)) {
+               ehci->big_endian_mmio = 1;
+               ehci->big_endian_desc = 1;
+       }
+       if (of_get_property(dn, "big-endian-regs", NULL))
+               ehci->big_endian_mmio = 1;
+       if (of_get_property(dn, "big-endian-desc", NULL))
+               ehci->big_endian_desc = 1;
+
+       ehci->caps = hcd->regs;
+       ehci->regs = hcd->regs +
+                       HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
+
+       /* cache this readonly data; minimize chip reads */
+       ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
+
+       if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
+               rv = ppc44x_enable_bmt(dn);
+               ehci_dbg(ehci, "Break Memory Transfer (BMT) is %senabled!\n",
+                               rv ? "NOT ": "");
+       }
+
+       rv = usb_add_hcd(hcd, irq, 0);
+       if (rv == 0)
+               return 0;
+
+       iounmap(hcd->regs);
+err_ioremap:
+       irq_dispose_mapping(irq);
+err_irq:
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+err_rmr:
+       usb_put_hcd(hcd);
+
+       return rv;
+}
+
+
+static int ehci_hcd_ppc_of_remove(struct of_device *op)
+{
+       struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
+       dev_set_drvdata(&op->dev, NULL);
+
+       dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
+
+       usb_remove_hcd(hcd);
+
+       iounmap(hcd->regs);
+       irq_dispose_mapping(hcd->irq);
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+
+       usb_put_hcd(hcd);
+
+       return 0;
+}
+
+
+static int ehci_hcd_ppc_of_shutdown(struct of_device *op)
+{
+       struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
+
+       if (hcd->driver->shutdown)
+               hcd->driver->shutdown(hcd);
+
+       return 0;
+}
+
+
+static struct of_device_id ehci_hcd_ppc_of_match[] = {
+       {
+               .compatible = "usb-ehci",
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
+
+
+static struct of_platform_driver ehci_hcd_ppc_of_driver = {
+       .name           = "ppc-of-ehci",
+       .match_table    = ehci_hcd_ppc_of_match,
+       .probe          = ehci_hcd_ppc_of_probe,
+       .remove         = ehci_hcd_ppc_of_remove,
+       .shutdown       = ehci_hcd_ppc_of_shutdown,
+       .driver         = {
+               .name   = "ppc-of-ehci",
+               .owner  = THIS_MODULE,
+       },
+};
index 452d4b1bc85927e4d21c3bb91caea7e14dc16d8a..a3249078c8085af2d7aa28be8fb739c2e8fcb788 100644 (file)
@@ -162,6 +162,7 @@ static const struct hc_driver ehci_ppc_soc_hc_driver = {
        .hub_control = ehci_hub_control,
        .bus_suspend = ehci_bus_suspend,
        .bus_resume = ehci_bus_resume,
+       .relinquish_port = ehci_relinquish_port,
 };
 
 static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
index 03a6b2f4e6ed81e722d855ee3bc76bdf6242648e..bbda58eb881304052be475a0604c682cd87d6041 100644 (file)
@@ -72,6 +72,7 @@ static const struct hc_driver ps3_ehci_hc_driver = {
        .bus_suspend            = ehci_bus_suspend,
        .bus_resume             = ehci_bus_resume,
 #endif
+       .relinquish_port        = ehci_relinquish_port,
 };
 
 static int ps3_ehci_probe(struct ps3_system_bus_device *dev)
index b10f39c047e944848f3ac2aa4067e820d2f5df90..776a97f33914e05511bc85dcdced2b4febe6a89b 100644 (file)
@@ -198,7 +198,8 @@ static int qtd_copy_status (
 
                /* if async CSPLIT failed, try cleaning out the TT buffer */
                if (status != -EPIPE
-                               && urb->dev->tt && !usb_pipeint (urb->pipe)
+                               && urb->dev->tt
+                               && !usb_pipeint(urb->pipe)
                                && ((token & QTD_STS_MMF) != 0
                                        || QTD_CERR(token) == 0)
                                && (!ehci_is_TDI(ehci)
@@ -211,6 +212,9 @@ static int qtd_copy_status (
                                urb->dev->ttport, urb->dev->devnum,
                                usb_pipeendpoint (urb->pipe), token);
 #endif /* DEBUG */
+                       /* REVISIT ARC-derived cores don't clear the root
+                        * hub TT buffer in this way...
+                        */
                        usb_hub_tt_clear_buffer (urb->dev, urb->pipe);
                }
        }
@@ -638,6 +642,7 @@ qh_make (
        u32                     info1 = 0, info2 = 0;
        int                     is_input, type;
        int                     maxp = 0;
+       struct usb_tt           *tt = urb->dev->tt;
 
        if (!qh)
                return qh;
@@ -661,8 +666,9 @@ qh_make (
         * For control/bulk requests, the HC or TT handles these.
         */
        if (type == PIPE_INTERRUPT) {
-               qh->usecs = NS_TO_US (usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0,
-                               hb_mult (maxp) * max_packet (maxp)));
+               qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
+                               is_input, 0,
+                               hb_mult(maxp) * max_packet(maxp)));
                qh->start = NO_FRAME;
 
                if (urb->dev->speed == USB_SPEED_HIGH) {
@@ -680,7 +686,6 @@ qh_make (
                                goto done;
                        }
                } else {
-                       struct usb_tt   *tt = urb->dev->tt;
                        int             think_time;
 
                        /* gap is f(FS/LS transfer times) */
@@ -736,10 +741,8 @@ qh_make (
                /* set the address of the TT; for TDI's integrated
                 * root hub tt, leave it zeroed.
                 */
-               if (!ehci_is_TDI(ehci)
-                               || urb->dev->tt->hub !=
-                                       ehci_to_hcd(ehci)->self.root_hub)
-                       info2 |= urb->dev->tt->hub->devnum << 16;
+               if (tt && tt->hub != ehci_to_hcd(ehci)->self.root_hub)
+                       info2 |= tt->hub->devnum << 16;
 
                /* NOTE:  if (PIPE_INTERRUPT) { scheduler sets c-mask } */
 
@@ -973,7 +976,7 @@ static void end_unlink_async (struct ehci_hcd *ehci)
        struct ehci_qh          *qh = ehci->reclaim;
        struct ehci_qh          *next;
 
-       timer_action_done (ehci, TIMER_IAA_WATCHDOG);
+       iaa_watchdog_done(ehci);
 
        // qh->hw_next = cpu_to_hc32(qh->qh_dma);
        qh->qh_state = QH_STATE_IDLE;
@@ -983,7 +986,6 @@ static void end_unlink_async (struct ehci_hcd *ehci)
        /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */
        next = qh->reclaim;
        ehci->reclaim = next;
-       ehci->reclaim_ready = 0;
        qh->reclaim = NULL;
 
        qh_completions (ehci, qh);
@@ -1059,11 +1061,10 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
                return;
        }
 
-       ehci->reclaim_ready = 0;
        cmd |= CMD_IAAD;
        ehci_writel(ehci, cmd, &ehci->regs->command);
        (void)ehci_readl(ehci, &ehci->regs->command);
-       timer_action (ehci, TIMER_IAA_WATCHDOG);
+       iaa_watchdog_start(ehci);
 }
 
 /*-------------------------------------------------------------------------*/
index 80d99bce2b38fb3d5a6459cdff8eeb5642fa0b06..8a8e08a51ba33cd55b57c127d550d7c54e40a5ca 100644 (file)
@@ -119,7 +119,8 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe)
                        q = &q->fstn->fstn_next;
                        break;
                case Q_TYPE_ITD:
-                       usecs += q->itd->usecs [uframe];
+                       if (q->itd->hw_transaction[uframe])
+                               usecs += q->itd->stream->usecs;
                        hw_p = &q->itd->hw_next;
                        q = &q->itd->itd_next;
                        break;
@@ -211,7 +212,7 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
  * low/fullspeed transfer can "carry over" from one uframe to the next,
  * since the TT just performs downstream transfers in sequence.
  *
- * For example two seperate 100 usec transfers can start in the same uframe,
+ * For example two separate 100 usec transfers can start in the same uframe,
  * and the second one would "carry over" 75 usecs into the next uframe.
  */
 static void
@@ -1536,7 +1537,6 @@ itd_link_urb (
                uframe = next_uframe & 0x07;
                frame = next_uframe >> 3;
 
-               itd->usecs [uframe] = stream->usecs;
                itd_patch(ehci, itd, iso_sched, packet, uframe);
 
                next_uframe += stream->interval;
@@ -1565,6 +1565,16 @@ itd_link_urb (
 
 #define        ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR)
 
+/* Process and recycle a completed ITD.  Return true iff its urb completed,
+ * and hence its completion callback probably added things to the hardware
+ * schedule.
+ *
+ * Note that we carefully avoid recycling this descriptor until after any
+ * completion callback runs, so that it won't be reused quickly.  That is,
+ * assuming (a) no more than two urbs per frame on this endpoint, and also
+ * (b) only this endpoint's completions submit URBs.  It seems some silicon
+ * corrupts things if you reuse completed descriptors very quickly...
+ */
 static unsigned
 itd_complete (
        struct ehci_hcd *ehci,
@@ -1577,6 +1587,7 @@ itd_complete (
        int                                     urb_index = -1;
        struct ehci_iso_stream                  *stream = itd->stream;
        struct usb_device                       *dev;
+       unsigned                                retval = false;
 
        /* for each uframe with a packet */
        for (uframe = 0; uframe < 8; uframe++) {
@@ -1610,30 +1621,21 @@ itd_complete (
                }
        }
 
-       usb_put_urb (urb);
-       itd->urb = NULL;
-       itd->stream = NULL;
-       list_move (&itd->itd_list, &stream->free_list);
-       iso_stream_put (ehci, stream);
-
        /* handle completion now? */
        if (likely ((urb_index + 1) != urb->number_of_packets))
-               return 0;
+               goto done;
 
        /* ASSERT: it's really the last itd for this urb
        list_for_each_entry (itd, &stream->td_list, itd_list)
                BUG_ON (itd->urb == urb);
         */
 
-       /* give urb back to the driver ... can be out-of-order */
+       /* give urb back to the driver; completion often (re)submits */
        dev = urb->dev;
        ehci_urb_done(ehci, urb, 0);
+       retval = true;
        urb = NULL;
-
-       /* defer stopping schedule; completion can submit */
        ehci->periodic_sched--;
-       if (unlikely (!ehci->periodic_sched))
-               (void) disable_periodic (ehci);
        ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
 
        if (unlikely (list_empty (&stream->td_list))) {
@@ -1645,8 +1647,15 @@ itd_complete (
                        (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
        }
        iso_stream_put (ehci, stream);
+       /* OK to recycle this ITD now that its completion callback ran. */
+done:
+       usb_put_urb(urb);
+       itd->urb = NULL;
+       itd->stream = NULL;
+       list_move(&itd->itd_list, &stream->free_list);
+       iso_stream_put(ehci, stream);
 
-       return 1;
+       return retval;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -1712,8 +1721,6 @@ done:
        return status;
 }
 
-#ifdef CONFIG_USB_EHCI_SPLIT_ISO
-
 /*-------------------------------------------------------------------------*/
 
 /*
@@ -1950,6 +1957,16 @@ sitd_link_urb (
 #define        SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \
                                | SITD_STS_XACT | SITD_STS_MMF)
 
+/* Process and recycle a completed SITD.  Return true iff its urb completed,
+ * and hence its completion callback probably added things to the hardware
+ * schedule.
+ *
+ * Note that we carefully avoid recycling this descriptor until after any
+ * completion callback runs, so that it won't be reused quickly.  That is,
+ * assuming (a) no more than two urbs per frame on this endpoint, and also
+ * (b) only this endpoint's completions submit URBs.  It seems some silicon
+ * corrupts things if you reuse completed descriptors very quickly...
+ */
 static unsigned
 sitd_complete (
        struct ehci_hcd         *ehci,
@@ -1961,6 +1978,7 @@ sitd_complete (
        int                                     urb_index = -1;
        struct ehci_iso_stream                  *stream = sitd->stream;
        struct usb_device                       *dev;
+       unsigned                                retval = false;
 
        urb_index = sitd->index;
        desc = &urb->iso_frame_desc [urb_index];
@@ -1981,32 +1999,23 @@ sitd_complete (
                desc->status = 0;
                desc->actual_length = desc->length - SITD_LENGTH (t);
        }
-
-       usb_put_urb (urb);
-       sitd->urb = NULL;
-       sitd->stream = NULL;
-       list_move (&sitd->sitd_list, &stream->free_list);
        stream->depth -= stream->interval << 3;
-       iso_stream_put (ehci, stream);
 
        /* handle completion now? */
        if ((urb_index + 1) != urb->number_of_packets)
-               return 0;
+               goto done;
 
        /* ASSERT: it's really the last sitd for this urb
        list_for_each_entry (sitd, &stream->td_list, sitd_list)
                BUG_ON (sitd->urb == urb);
         */
 
-       /* give urb back to the driver */
+       /* give urb back to the driver; completion often (re)submits */
        dev = urb->dev;
        ehci_urb_done(ehci, urb, 0);
+       retval = true;
        urb = NULL;
-
-       /* defer stopping schedule; completion can submit */
        ehci->periodic_sched--;
-       if (!ehci->periodic_sched)
-               (void) disable_periodic (ehci);
        ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
 
        if (list_empty (&stream->td_list)) {
@@ -2018,8 +2027,15 @@ sitd_complete (
                        (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
        }
        iso_stream_put (ehci, stream);
+       /* OK to recycle this SITD now that its completion callback ran. */
+done:
+       usb_put_urb(urb);
+       sitd->urb = NULL;
+       sitd->stream = NULL;
+       list_move(&sitd->sitd_list, &stream->free_list);
+       iso_stream_put(ehci, stream);
 
-       return 1;
+       return retval;
 }
 
 
@@ -2082,26 +2098,6 @@ done:
        return status;
 }
 
-#else
-
-static inline int
-sitd_submit (struct ehci_hcd *ehci, struct urb *urb, gfp_t mem_flags)
-{
-       ehci_dbg (ehci, "split iso support is disabled\n");
-       return -ENOSYS;
-}
-
-static inline unsigned
-sitd_complete (
-       struct ehci_hcd         *ehci,
-       struct ehci_sitd        *sitd
-) {
-       ehci_err (ehci, "sitd_complete %p?\n", sitd);
-       return 0;
-}
-
-#endif /* USB_EHCI_SPLIT_ISO */
-
 /*-------------------------------------------------------------------------*/
 
 static void
@@ -2127,17 +2123,9 @@ scan_periodic (struct ehci_hcd *ehci)
        for (;;) {
                union ehci_shadow       q, *q_p;
                __hc32                  type, *hw_p;
-               unsigned                uframes;
+               unsigned                incomplete = false;
 
-               /* don't scan past the live uframe */
                frame = now_uframe >> 3;
-               if (frame == (clock >> 3))
-                       uframes = now_uframe & 0x07;
-               else {
-                       /* safe to scan the whole frame at once */
-                       now_uframe |= 0x07;
-                       uframes = 8;
-               }
 
 restart:
                /* scan each element in frame's queue for completions */
@@ -2175,12 +2163,15 @@ restart:
                                q = q.fstn->fstn_next;
                                break;
                        case Q_TYPE_ITD:
-                               /* skip itds for later in the frame */
+                               /* If this ITD is still active, leave it for
+                                * later processing ... check the next entry.
+                                */
                                rmb ();
-                               for (uf = live ? uframes : 8; uf < 8; uf++) {
+                               for (uf = 0; uf < 8 && live; uf++) {
                                        if (0 == (q.itd->hw_transaction [uf]
                                                        & ITD_ACTIVE(ehci)))
                                                continue;
+                                       incomplete = true;
                                        q_p = &q.itd->itd_next;
                                        hw_p = &q.itd->hw_next;
                                        type = Q_NEXT_TYPE(ehci,
@@ -2188,10 +2179,12 @@ restart:
                                        q = *q_p;
                                        break;
                                }
-                               if (uf != 8)
+                               if (uf < 8 && live)
                                        break;
 
-                               /* this one's ready ... HC won't cache the
+                               /* Take finished ITDs out of the schedule
+                                * and process them:  recycle, maybe report
+                                * URB completion.  HC won't cache the
                                 * pointer for much longer, if at all.
                                 */
                                *q_p = q.itd->itd_next;
@@ -2202,8 +2195,12 @@ restart:
                                q = *q_p;
                                break;
                        case Q_TYPE_SITD:
+                               /* If this SITD is still active, leave it for
+                                * later processing ... check the next entry.
+                                */
                                if ((q.sitd->hw_results & SITD_ACTIVE(ehci))
                                                && live) {
+                                       incomplete = true;
                                        q_p = &q.sitd->sitd_next;
                                        hw_p = &q.sitd->hw_next;
                                        type = Q_NEXT_TYPE(ehci,
@@ -2211,6 +2208,11 @@ restart:
                                        q = *q_p;
                                        break;
                                }
+
+                               /* Take finished SITDs out of the schedule
+                                * and process them:  recycle, maybe report
+                                * URB completion.
+                                */
                                *q_p = q.sitd->sitd_next;
                                *hw_p = q.sitd->hw_next;
                                type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
@@ -2226,11 +2228,24 @@ restart:
                        }
 
                        /* assume completion callbacks modify the queue */
-                       if (unlikely (modified))
-                               goto restart;
+                       if (unlikely (modified)) {
+                               if (likely(ehci->periodic_sched > 0))
+                                       goto restart;
+                               /* maybe we can short-circuit this scan! */
+                               disable_periodic(ehci);
+                               now_uframe = clock;
+                               break;
+                       }
                }
 
-               /* stop when we catch up to the HC */
+               /* If we can tell we caught up to the hardware, stop now.
+                * We can't advance our scan without collecting the ISO
+                * transfers that are still pending in this frame.
+                */
+               if (incomplete && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
+                       ehci->next_uframe = now_uframe;
+                       break;
+               }
 
                // FIXME:  this assumes we won't get lapped when
                // latencies climb; that should be rare, but...
@@ -2243,7 +2258,8 @@ restart:
                if (now_uframe == clock) {
                        unsigned        now;
 
-                       if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))
+                       if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)
+                                       || ehci->periodic_sched == 0)
                                break;
                        ehci->next_uframe = now_uframe;
                        now = ehci_readl(ehci, &ehci->regs->frame_index) % mod;
index 951d69fec513a2b12fa7c5f666844af4f0729128..bf92d209a1a9bad0091983ce0d35ff5ee0fc011e 100644 (file)
@@ -74,7 +74,6 @@ struct ehci_hcd {                     /* one per controller */
        /* async schedule support */
        struct ehci_qh          *async;
        struct ehci_qh          *reclaim;
-       unsigned                reclaim_ready : 1;
        unsigned                scanning : 1;
 
        /* periodic schedule support */
@@ -105,6 +104,7 @@ struct ehci_hcd {                   /* one per controller */
        struct dma_pool         *itd_pool;      /* itd per iso urb */
        struct dma_pool         *sitd_pool;     /* sitd per split iso urb */
 
+       struct timer_list       iaa_watchdog;
        struct timer_list       watchdog;
        unsigned long           actions;
        unsigned                stamp;
@@ -126,6 +126,14 @@ struct ehci_hcd {                  /* one per controller */
 #      define COUNT(x) do { (x)++; } while (0)
 #else
 #      define COUNT(x) do {} while (0)
+#endif
+
+       /* debug files */
+#ifdef DEBUG
+       struct dentry           *debug_dir;
+       struct dentry           *debug_async;
+       struct dentry           *debug_periodic;
+       struct dentry           *debug_registers;
 #endif
 };
 
@@ -140,9 +148,21 @@ static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
 }
 
 
+static inline void
+iaa_watchdog_start(struct ehci_hcd *ehci)
+{
+       WARN_ON(timer_pending(&ehci->iaa_watchdog));
+       mod_timer(&ehci->iaa_watchdog,
+                       jiffies + msecs_to_jiffies(EHCI_IAA_MSECS));
+}
+
+static inline void iaa_watchdog_done(struct ehci_hcd *ehci)
+{
+       del_timer(&ehci->iaa_watchdog);
+}
+
 enum ehci_timer_action {
        TIMER_IO_WATCHDOG,
-       TIMER_IAA_WATCHDOG,
        TIMER_ASYNC_SHRINK,
        TIMER_ASYNC_OFF,
 };
@@ -160,9 +180,6 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
                unsigned long t;
 
                switch (action) {
-               case TIMER_IAA_WATCHDOG:
-                       t = EHCI_IAA_JIFFIES;
-                       break;
                case TIMER_IO_WATCHDOG:
                        t = EHCI_IO_JIFFIES;
                        break;
@@ -179,8 +196,7 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
                // async queue SHRINK often precedes IAA.  while it's ready
                // to go OFF neither can matter, and afterwards the IO
                // watchdog stops unless there's still periodic traffic.
-               if (action != TIMER_IAA_WATCHDOG
-                               && t > ehci->watchdog.expires
+               if (time_before_eq(t, ehci->watchdog.expires)
                                && timer_pending (&ehci->watchdog))
                        return;
                mod_timer (&ehci->watchdog, t);
@@ -534,8 +550,8 @@ struct ehci_iso_stream {
         * trusting urb->interval == f(epdesc->bInterval) and
         * including the extra info for hw_bufp[0..2]
         */
-       u8                      interval;
        u8                      usecs, c_usecs;
+       u16                     interval;
        u16                     tt_usecs;
        u16                     maxp;
        u16                     raw_mask;
@@ -586,7 +602,6 @@ struct ehci_itd {
        unsigned                frame;          /* where scheduled */
        unsigned                pg;
        unsigned                index[8];       /* in urb->iso_frame_desc */
-       u8                      usecs[8];
 } __attribute__ ((aligned (32)));
 
 /*-------------------------------------------------------------------------*/
@@ -725,11 +740,16 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
  * definition below can die once the 4xx support is
  * finally ported over.
  */
-#if defined(CONFIG_PPC)
+#if defined(CONFIG_PPC) && !defined(CONFIG_PPC_MERGE)
 #define readl_be(addr)         in_be32((__force unsigned *)addr)
 #define writel_be(val, addr)   out_be32((__force unsigned *)addr, val)
 #endif
 
+#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX)
+#define readl_be(addr)         __raw_readl((__force unsigned *)addr)
+#define writel_be(val, addr)   __raw_writel(val, (__force unsigned *)addr)
+#endif
+
 static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
                __u32 __iomem * regs)
 {
index c27417f5b9d8635320a491bd5fbdad1c8f4b366c..0130fd8571e4018549db9a5003bd432b72645878 100644 (file)
@@ -918,7 +918,6 @@ static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
                              | RH_PS_OCIC | RH_PS_PRSC)) {
                        changed = 1;
                        buf[0] |= 1 << (i + 1);
-                       continue;
                }
        }
        spin_unlock_irqrestore(&isp116x->lock, flags);
index d849c809acbdca97394fa7b8dcd8225733a91f5a..126fcbdd6408a2fed44fec58a0b3c74798200d0e 100644 (file)
@@ -17,6 +17,8 @@
 
 #include <asm/mach-types.h>
 #include <asm/hardware.h>
+#include <asm/gpio.h>
+
 #include <asm/arch/board.h>
 #include <asm/arch/cpu.h>
 
@@ -271,12 +273,41 @@ static const struct hc_driver ohci_at91_hc_driver = {
 
 static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
 {
+       struct at91_usbh_data   *pdata = pdev->dev.platform_data;
+       int                     i;
+
+       if (pdata) {
+               /* REVISIT make the driver support per-port power switching,
+                * and also overcurrent detection.  Here we assume the ports
+                * are always powered while this driver is active, and use
+                * active-low power switches.
+                */
+               for (i = 0; i < pdata->ports; i++) {
+                       if (pdata->vbus_pin[i] <= 0)
+                               continue;
+                       gpio_request(pdata->vbus_pin[i], "ohci_vbus");
+                       gpio_direction_output(pdata->vbus_pin[i], 0);
+               }
+       }
+
        device_init_wakeup(&pdev->dev, 1);
        return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
 }
 
 static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
 {
+       struct at91_usbh_data   *pdata = pdev->dev.platform_data;
+       int                     i;
+
+       if (pdata) {
+               for (i = 0; i < pdata->ports; i++) {
+                       if (pdata->vbus_pin[i] <= 0)
+                               continue;
+                       gpio_direction_output(pdata->vbus_pin[i], 1);
+                       gpio_free(pdata->vbus_pin[i]);
+               }
+       }
+
        device_init_wakeup(&pdev->dev, 0);
        return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
 }
index ebab5ce8f5ce7d760b48e9fb5e1df650c7ffded5..a22c30aa745d69f1a15b3fa85d844a2d768f99ce 100644 (file)
@@ -401,6 +401,42 @@ static inline void remove_debug_files (struct ohci_hcd *bus) { }
 
 #else
 
+static int debug_async_open(struct inode *, struct file *);
+static int debug_periodic_open(struct inode *, struct file *);
+static int debug_registers_open(struct inode *, struct file *);
+static int debug_async_open(struct inode *, struct file *);
+static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
+static int debug_close(struct inode *, struct file *);
+
+static const struct file_operations debug_async_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_async_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+static const struct file_operations debug_periodic_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_periodic_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+static const struct file_operations debug_registers_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_registers_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+
+static struct dentry *ohci_debug_root;
+
+struct debug_buffer {
+       ssize_t (*fill_func)(struct debug_buffer *);    /* fill method */
+       struct device *dev;
+       struct mutex mutex;     /* protect filling of buffer */
+       size_t count;           /* number of characters filled into buffer */
+       char *page;
+};
+
 static ssize_t
 show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
 {
@@ -467,8 +503,7 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
        return count - size;
 }
 
-static ssize_t
-show_async (struct class_device *class_dev, char *buf)
+static ssize_t fill_async_buffer(struct debug_buffer *buf)
 {
        struct usb_bus          *bus;
        struct usb_hcd          *hcd;
@@ -476,25 +511,23 @@ show_async (struct class_device *class_dev, char *buf)
        size_t                  temp;
        unsigned long           flags;
 
-       bus = class_get_devdata(class_dev);
+       bus = dev_get_drvdata(buf->dev);
        hcd = bus_to_hcd(bus);
        ohci = hcd_to_ohci(hcd);
 
        /* display control and bulk lists together, for simplicity */
        spin_lock_irqsave (&ohci->lock, flags);
-       temp = show_list (ohci, buf, PAGE_SIZE, ohci->ed_controltail);
-       temp += show_list (ohci, buf + temp, PAGE_SIZE - temp, ohci->ed_bulktail);
+       temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail);
+       temp += show_list(ohci, buf->page + temp, buf->count - temp,
+                         ohci->ed_bulktail);
        spin_unlock_irqrestore (&ohci->lock, flags);
 
        return temp;
 }
-static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
-
 
 #define DBG_SCHED_LIMIT 64
 
-static ssize_t
-show_periodic (struct class_device *class_dev, char *buf)
+static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
 {
        struct usb_bus          *bus;
        struct usb_hcd          *hcd;
@@ -509,10 +542,10 @@ show_periodic (struct class_device *class_dev, char *buf)
                return 0;
        seen_count = 0;
 
-       bus = class_get_devdata(class_dev);
+       bus = (struct usb_bus *)dev_get_drvdata(buf->dev);
        hcd = bus_to_hcd(bus);
        ohci = hcd_to_ohci(hcd);
-       next = buf;
+       next = buf->page;
        size = PAGE_SIZE;
 
        temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
@@ -589,13 +622,9 @@ show_periodic (struct class_device *class_dev, char *buf)
 
        return PAGE_SIZE - size;
 }
-static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
-
-
 #undef DBG_SCHED_LIMIT
 
-static ssize_t
-show_registers (struct class_device *class_dev, char *buf)
+static ssize_t fill_registers_buffer(struct debug_buffer *buf)
 {
        struct usb_bus          *bus;
        struct usb_hcd          *hcd;
@@ -606,11 +635,11 @@ show_registers (struct class_device *class_dev, char *buf)
        char                    *next;
        u32                     rdata;
 
-       bus = class_get_devdata(class_dev);
+       bus = (struct usb_bus *)dev_get_drvdata(buf->dev);
        hcd = bus_to_hcd(bus);
        ohci = hcd_to_ohci(hcd);
        regs = ohci->regs;
-       next = buf;
+       next = buf->page;
        size = PAGE_SIZE;
 
        spin_lock_irqsave (&ohci->lock, flags);
@@ -677,29 +706,155 @@ show_registers (struct class_device *class_dev, char *buf)
 
 done:
        spin_unlock_irqrestore (&ohci->lock, flags);
+
        return PAGE_SIZE - size;
 }
-static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
 
+static struct debug_buffer *alloc_buffer(struct device *dev,
+                               ssize_t (*fill_func)(struct debug_buffer *))
+{
+       struct debug_buffer *buf;
+
+       buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
 
+       if (buf) {
+               buf->dev = dev;
+               buf->fill_func = fill_func;
+               mutex_init(&buf->mutex);
+       }
+
+       return buf;
+}
+
+static int fill_buffer(struct debug_buffer *buf)
+{
+       int ret = 0;
+
+       if (!buf->page)
+               buf->page = (char *)get_zeroed_page(GFP_KERNEL);
+
+       if (!buf->page) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = buf->fill_func(buf);
+
+       if (ret >= 0) {
+               buf->count = ret;
+               ret = 0;
+       }
+
+out:
+       return ret;
+}
+
+static ssize_t debug_output(struct file *file, char __user *user_buf,
+                       size_t len, loff_t *offset)
+{
+       struct debug_buffer *buf = file->private_data;
+       int ret = 0;
+
+       mutex_lock(&buf->mutex);
+       if (buf->count == 0) {
+               ret = fill_buffer(buf);
+               if (ret != 0) {
+                       mutex_unlock(&buf->mutex);
+                       goto out;
+               }
+       }
+       mutex_unlock(&buf->mutex);
+
+       ret = simple_read_from_buffer(user_buf, len, offset,
+                                     buf->page, buf->count);
+
+out:
+       return ret;
+
+}
+
+static int debug_close(struct inode *inode, struct file *file)
+{
+       struct debug_buffer *buf = file->private_data;
+
+       if (buf) {
+               if (buf->page)
+                       free_page((unsigned long)buf->page);
+               kfree(buf);
+       }
+
+       return 0;
+}
+static int debug_async_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static int debug_periodic_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private,
+                                         fill_periodic_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static int debug_registers_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private,
+                                         fill_registers_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
 static inline void create_debug_files (struct ohci_hcd *ohci)
 {
-       struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
-       int retval;
+       struct usb_bus *bus = &ohci_to_hcd(ohci)->self;
+       struct device *dev = bus->dev;
+
+       ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root);
+       if (!ohci->debug_dir)
+               goto dir_error;
+
+       ohci->debug_async = debugfs_create_file("async", S_IRUGO,
+                                               ohci->debug_dir, dev,
+                                               &debug_async_fops);
+       if (!ohci->debug_async)
+               goto async_error;
+
+       ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
+                                                  ohci->debug_dir, dev,
+                                                  &debug_periodic_fops);
+       if (!ohci->debug_periodic)
+               goto periodic_error;
+
+       ohci->debug_registers = debugfs_create_file("registers", S_IRUGO,
+                                                   ohci->debug_dir, dev,
+                                                   &debug_registers_fops);
+       if (!ohci->debug_registers)
+               goto registers_error;
 
-       retval = class_device_create_file(cldev, &class_device_attr_async);
-       retval = class_device_create_file(cldev, &class_device_attr_periodic);
-       retval = class_device_create_file(cldev, &class_device_attr_registers);
        ohci_dbg (ohci, "created debug files\n");
+       return;
+
+registers_error:
+       debugfs_remove(ohci->debug_periodic);
+periodic_error:
+       debugfs_remove(ohci->debug_async);
+async_error:
+       debugfs_remove(ohci->debug_dir);
+dir_error:
+       ohci->debug_periodic = NULL;
+       ohci->debug_async = NULL;
+       ohci->debug_dir = NULL;
 }
 
 static inline void remove_debug_files (struct ohci_hcd *ohci)
 {
-       struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
-
-       class_device_remove_file(cldev, &class_device_attr_async);
-       class_device_remove_file(cldev, &class_device_attr_periodic);
-       class_device_remove_file(cldev, &class_device_attr_registers);
+       debugfs_remove(ohci->debug_registers);
+       debugfs_remove(ohci->debug_periodic);
+       debugfs_remove(ohci->debug_async);
+       debugfs_remove(ohci->debug_dir);
 }
 
 #endif
index ddd4ee1f2413633bccd1ae9d9309a2a7a86b9e32..dd4798ee028edba1e9612bfaa8d77a34afa2e8b3 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/dmapool.h>
 #include <linux/reboot.h>
 #include <linux/workqueue.h>
+#include <linux/debugfs.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -809,13 +810,9 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
        }
 
        if (ints & OHCI_INTR_WDH) {
-               if (HC_IS_RUNNING(hcd->state))
-                       ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
                spin_lock (&ohci->lock);
                dl_done_list (ohci);
                spin_unlock (&ohci->lock);
-               if (HC_IS_RUNNING(hcd->state))
-                       ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
        }
 
        if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
@@ -1032,6 +1029,13 @@ MODULE_LICENSE ("GPL");
 #define PLATFORM_DRIVER                usb_hcd_pnx4008_driver
 #endif
 
+#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
+    defined(CONFIG_CPU_SUBTYPE_SH7721) || \
+    defined(CONFIG_CPU_SUBTYPE_SH7763)
+#include "ohci-sh.c"
+#define PLATFORM_DRIVER                ohci_hcd_sh_driver
+#endif
+
 
 #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
 #include "ohci-ppc-of.c"
@@ -1048,6 +1052,11 @@ MODULE_LICENSE ("GPL");
 #define SSB_OHCI_DRIVER                ssb_ohci_driver
 #endif
 
+#ifdef CONFIG_MFD_SM501
+#include "ohci-sm501.c"
+#define PLATFORM_DRIVER                ohci_hcd_sm501_driver
+#endif
+
 #if    !defined(PCI_DRIVER) &&         \
        !defined(PLATFORM_DRIVER) &&    \
        !defined(OF_PLATFORM_DRIVER) && \
@@ -1068,6 +1077,14 @@ static int __init ohci_hcd_mod_init(void)
        pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
                sizeof (struct ed), sizeof (struct td));
 
+#ifdef DEBUG
+       ohci_debug_root = debugfs_create_dir("ohci", NULL);
+       if (!ohci_debug_root) {
+               retval = -ENOENT;
+               goto error_debug;
+       }
+#endif
+
 #ifdef PS3_SYSTEM_BUS_DRIVER
        retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
        if (retval < 0)
@@ -1130,6 +1147,12 @@ static int __init ohci_hcd_mod_init(void)
        ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  error_ps3:
 #endif
+#ifdef DEBUG
+       debugfs_remove(ohci_debug_root);
+       ohci_debug_root = NULL;
+ error_debug:
+#endif
+
        return retval;
 }
 module_init(ohci_hcd_mod_init);
@@ -1154,6 +1177,9 @@ static void __exit ohci_hcd_mod_exit(void)
 #ifdef PS3_SYSTEM_BUS_DRIVER
        ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
 #endif
+#ifdef DEBUG
+       debugfs_remove(ohci_debug_root);
+#endif
 }
 module_exit(ohci_hcd_mod_exit);
 
diff --git a/drivers/usb/host/ohci-sh.c b/drivers/usb/host/ohci-sh.c
new file mode 100644 (file)
index 0000000..5309ac0
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * OHCI HCD (Host Controller Driver) for USB.
+ *
+ * Copyright (C) 2008 Renesas Solutions Corp.
+ *
+ * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <linux/platform_device.h>
+
+static int ohci_sh_start(struct usb_hcd *hcd)
+{
+       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+
+       ohci_hcd_init(ohci);
+       ohci_init(ohci);
+       ohci_run(ohci);
+       hcd->state = HC_STATE_RUNNING;
+       return 0;
+}
+
+static const struct hc_driver ohci_sh_hc_driver = {
+       .description =          hcd_name,
+       .product_desc =         "SuperH OHCI",
+       .hcd_priv_size =        sizeof(struct ohci_hcd),
+
+       /*
+        * generic hardware linkage
+        */
+       .irq =                  ohci_irq,
+       .flags =                HCD_USB11 | HCD_MEMORY,
+
+       /*
+        * basic lifecycle operations
+        */
+       .start =                ohci_sh_start,
+       .stop =                 ohci_stop,
+       .shutdown =             ohci_shutdown,
+
+       /*
+        * managing i/o requests and associated device resources
+        */
+       .urb_enqueue =          ohci_urb_enqueue,
+       .urb_dequeue =          ohci_urb_dequeue,
+       .endpoint_disable =     ohci_endpoint_disable,
+
+       /*
+        * scheduling support
+        */
+       .get_frame_number =     ohci_get_frame,
+
+       /*
+        * root hub support
+        */
+       .hub_status_data =      ohci_hub_status_data,
+       .hub_control =          ohci_hub_control,
+       .hub_irq_enable =       ohci_rhsc_enable,
+#ifdef CONFIG_PM
+       .bus_suspend =          ohci_bus_suspend,
+       .bus_resume =           ohci_bus_resume,
+#endif
+       .start_port_reset =     ohci_start_port_reset,
+};
+
+/*-------------------------------------------------------------------------*/
+
+#define resource_len(r) (((r)->end - (r)->start) + 1)
+static int ohci_hcd_sh_probe(struct platform_device *pdev)
+{
+       struct resource *res = NULL;
+       struct usb_hcd *hcd = NULL;
+       int irq = -1;
+       int ret;
+
+       if (usb_disabled())
+               return -ENODEV;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               err("platform_get_resource error.");
+               return -ENODEV;
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               err("platform_get_irq error.");
+               return -ENODEV;
+       }
+
+       /* initialize hcd */
+       hcd = usb_create_hcd(&ohci_sh_hc_driver, &pdev->dev, (char *)hcd_name);
+       if (!hcd) {
+               err("Failed to create hcd");
+               return -ENOMEM;
+       }
+
+       hcd->regs = (void __iomem *)res->start;
+       hcd->rsrc_start = res->start;
+       hcd->rsrc_len = resource_len(res);
+       ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
+       if (ret != 0) {
+               err("Failed to add hcd");
+               usb_put_hcd(hcd);
+               return ret;
+       }
+
+       return ret;
+}
+
+static int ohci_hcd_sh_remove(struct platform_device *pdev)
+{
+       struct usb_hcd *hcd = platform_get_drvdata(pdev);
+
+       usb_remove_hcd(hcd);
+       usb_put_hcd(hcd);
+
+       return 0;
+}
+
+static struct platform_driver ohci_hcd_sh_driver = {
+       .probe          = ohci_hcd_sh_probe,
+       .remove         = ohci_hcd_sh_remove,
+       .shutdown       = usb_hcd_platform_shutdown,
+       .driver         = {
+               .name   = "sh_ohci",
+               .owner  = THIS_MODULE,
+       },
+};
+
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
new file mode 100644 (file)
index 0000000..a970701
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+ * OHCI HCD (Host Controller Driver) for USB.
+ *
+ * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
+ * (C) Copyright 2000-2005 David Brownell
+ * (C) Copyright 2002 Hewlett-Packard Company
+ * (C) Copyright 2008 Magnus Damm
+ *
+ * SM501 Bus Glue - based on ohci-omap.c
+ *
+ * This file is licenced under the GPL.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/sm501.h>
+#include <linux/sm501-regs.h>
+
+static int ohci_sm501_init(struct usb_hcd *hcd)
+{
+       return ohci_init(hcd_to_ohci(hcd));
+}
+
+static int ohci_sm501_start(struct usb_hcd *hcd)
+{
+       struct device *dev = hcd->self.controller;
+       int ret;
+
+       ret = ohci_run(hcd_to_ohci(hcd));
+       if (ret < 0) {
+               dev_err(dev, "can't start %s", hcd->self.bus_name);
+               ohci_stop(hcd);
+       }
+
+       return ret;
+}
+
+/*-------------------------------------------------------------------------*/
+
+static const struct hc_driver ohci_sm501_hc_driver = {
+       .description =          hcd_name,
+       .product_desc =         "SM501 OHCI",
+       .hcd_priv_size =        sizeof(struct ohci_hcd),
+
+       /*
+        * generic hardware linkage
+        */
+       .irq =                  ohci_irq,
+       .flags =                HCD_USB11 | HCD_MEMORY | HCD_LOCAL_MEM,
+
+       /*
+        * basic lifecycle operations
+        */
+       .reset =                ohci_sm501_init,
+       .start =                ohci_sm501_start,
+       .stop =                 ohci_stop,
+       .shutdown =             ohci_shutdown,
+
+       /*
+        * managing i/o requests and associated device resources
+        */
+       .urb_enqueue =          ohci_urb_enqueue,
+       .urb_dequeue =          ohci_urb_dequeue,
+       .endpoint_disable =     ohci_endpoint_disable,
+
+       /*
+        * scheduling support
+        */
+       .get_frame_number =     ohci_get_frame,
+
+       /*
+        * root hub support
+        */
+       .hub_status_data =      ohci_hub_status_data,
+       .hub_control =          ohci_hub_control,
+       .hub_irq_enable =       ohci_rhsc_enable,
+#ifdef CONFIG_PM
+       .bus_suspend =          ohci_bus_suspend,
+       .bus_resume =           ohci_bus_resume,
+#endif
+       .start_port_reset =     ohci_start_port_reset,
+};
+
+/*-------------------------------------------------------------------------*/
+
+static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
+{
+       const struct hc_driver *driver = &ohci_sm501_hc_driver;
+       struct device *dev = &pdev->dev;
+       struct resource *res, *mem;
+       int retval, irq;
+       struct usb_hcd *hcd = 0;
+
+       irq = retval = platform_get_irq(pdev, 0);
+       if (retval < 0)
+               goto err0;
+
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+       if (mem == NULL) {
+               dev_err(dev, "no resource definition for memory\n");
+               retval = -ENOENT;
+               goto err0;
+       }
+
+       if (!request_mem_region(mem->start, mem->end - mem->start + 1,
+                               pdev->name)) {
+               dev_err(dev, "request_mem_region failed\n");
+               retval = -EBUSY;
+               goto err0;
+       }
+
+       /* The sm501 chip is equipped with local memory that may be used
+        * by on-chip devices such as the video controller and the usb host.
+        * This driver uses dma_declare_coherent_memory() to make sure
+        * usb allocations with dma_alloc_coherent() allocate from
+        * this local memory. The dma_handle returned by dma_alloc_coherent()
+        * will be an offset starting from 0 for the first local memory byte.
+        *
+        * So as long as data is allocated using dma_alloc_coherent() all is
+        * fine. This is however not always the case - buffers may be allocated
+        * using kmalloc() - so the usb core needs to be told that it must copy
+        * data into our local memory if the buffers happen to be placed in
+        * regular memory. The HCD_LOCAL_MEM flag does just that.
+        */
+
+       if (!dma_declare_coherent_memory(dev, mem->start,
+                                        mem->start - mem->parent->start,
+                                        (mem->end - mem->start) + 1,
+                                        DMA_MEMORY_MAP |
+                                        DMA_MEMORY_EXCLUSIVE)) {
+               dev_err(dev, "cannot declare coherent memory\n");
+               retval = -ENXIO;
+               goto err1;
+       }
+
+       /* allocate, reserve and remap resources for registers */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               dev_err(dev, "no resource definition for registers\n");
+               retval = -ENOENT;
+               goto err2;
+       }
+
+       hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
+       if (!hcd) {
+               retval = -ENOMEM;
+               goto err2;
+       }
+
+       hcd->rsrc_start = res->start;
+       hcd->rsrc_len = res->end - res->start + 1;
+
+       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, pdev->name)) {
+               dev_err(dev, "request_mem_region failed\n");
+               retval = -EBUSY;
+               goto err3;
+       }
+
+       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
+       if (hcd->regs == NULL) {
+               dev_err(dev, "cannot remap registers\n");
+               retval = -ENXIO;
+               goto err4;
+       }
+
+       ohci_hcd_init(hcd_to_ohci(hcd));
+
+       retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
+       if (retval)
+               goto err4;
+
+       /* enable power and unmask interrupts */
+
+       sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1);
+       sm501_modify_reg(dev->parent, SM501_IRQ_MASK, 1 << 6, 0);
+
+       return 0;
+err4:
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+err3:
+       usb_put_hcd(hcd);
+err2:
+       dma_release_declared_memory(dev);
+err1:
+       release_mem_region(mem->start, mem->end - mem->start + 1);
+err0:
+       return retval;
+}
+
+static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev)
+{
+       struct usb_hcd *hcd = platform_get_drvdata(pdev);
+       struct resource *mem;
+
+       usb_remove_hcd(hcd);
+       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+       usb_put_hcd(hcd);
+       dma_release_declared_memory(&pdev->dev);
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+       release_mem_region(mem->start, mem->end - mem->start + 1);
+
+       /* mask interrupts and disable power */
+
+       sm501_modify_reg(pdev->dev.parent, SM501_IRQ_MASK, 0, 1 << 6);
+       sm501_unit_power(pdev->dev.parent, SM501_GATE_USB_HOST, 0);
+
+       platform_set_drvdata(pdev, NULL);
+       return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+#ifdef CONFIG_PM
+static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg)
+{
+       struct device *dev = &pdev->dev;
+       struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev));
+
+       if (time_before(jiffies, ohci->next_statechange))
+               msleep(5);
+       ohci->next_statechange = jiffies;
+
+       sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0);
+       ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
+       dev->power.power_state = PMSG_SUSPEND;
+       return 0;
+}
+
+static int ohci_sm501_resume(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev));
+
+       if (time_before(jiffies, ohci->next_statechange))
+               msleep(5);
+       ohci->next_statechange = jiffies;
+
+       sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1);
+       dev->power.power_state = PMSG_ON;
+       usb_hcd_resume_root_hub(platform_get_drvdata(pdev));
+       return 0;
+}
+#endif
+
+/*-------------------------------------------------------------------------*/
+
+/*
+ * Driver definition to register with the SM501 bus
+ */
+static struct platform_driver ohci_hcd_sm501_driver = {
+       .probe          = ohci_hcd_sm501_drv_probe,
+       .remove         = ohci_hcd_sm501_drv_remove,
+       .shutdown       = usb_hcd_platform_shutdown,
+#ifdef CONFIG_PM
+       .suspend        = ohci_sm501_suspend,
+       .resume         = ohci_sm501_resume,
+#endif
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "sm501-usb",
+       },
+};
index 47c5c66a282c55fdc24f0f6b654c39fb7137f9ee..dc544ddc784962831637e749c4d50420ee24aa0b 100644 (file)
@@ -408,6 +408,13 @@ struct ohci_hcd {
        unsigned                eds_scheduled;
        struct ed               *ed_to_check;
        unsigned                zf_delay;
+
+#ifdef DEBUG
+       struct dentry           *debug_dir;
+       struct dentry           *debug_async;
+       struct dentry           *debug_periodic;
+       struct dentry           *debug_registers;
+#endif
 };
 
 #ifdef CONFIG_PCI
index c225159ca3d346759a33b73b49743d64914ba778..0ee694f043cc9b84d0a6aef45980a97212da1fdc 100644 (file)
@@ -190,9 +190,8 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
                        msleep(10);
                }
                if (wait_time <= 0)
-                       printk(KERN_WARNING "%s %s: BIOS handoff "
-                                       "failed (BIOS bug ?) %08x\n",
-                                       pdev->dev.bus_id, "OHCI",
+                       dev_warn(&pdev->dev, "OHCI: BIOS handoff failed"
+                                       " (BIOS bug?) %08x\n",
                                        readl(base + OHCI_CONTROL));
 
                /* reset controller, preserving RWC */
@@ -243,8 +242,7 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
                switch (cap & 0xff) {
                case 1:                 /* BIOS/SMM/... handoff support */
                        if ((cap & EHCI_USBLEGSUP_BIOS)) {
-                               pr_debug("%s %s: BIOS handoff\n",
-                                               pdev->dev.bus_id, "EHCI");
+                               dev_dbg(&pdev->dev, "EHCI: BIOS handoff\n");
 
 #if 0
 /* aleksey_gorelov@phoenix.com reports that some systems need SMI forced on,
@@ -285,9 +283,8 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
                                /* well, possibly buggy BIOS... try to shut
                                 * it down, and hope nothing goes too wrong
                                 */
-                               printk(KERN_WARNING "%s %s: BIOS handoff "
-                                               "failed (BIOS bug ?) %08x\n",
-                                       pdev->dev.bus_id, "EHCI", cap);
+                               dev_warn(&pdev->dev, "EHCI: BIOS handoff failed"
+                                               " (BIOS bug?) %08x\n", cap);
                                pci_write_config_byte(pdev, offset + 2, 0);
                        }
 
@@ -306,17 +303,14 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
                        cap = 0;
                        /* FALLTHROUGH */
                default:
-                       printk(KERN_WARNING "%s %s: unrecognized "
-                                       "capability %02x\n",
-                                       pdev->dev.bus_id, "EHCI",
-                                       cap & 0xff);
+                       dev_warn(&pdev->dev, "EHCI: unrecognized capability "
+                                       "%02x\n", cap & 0xff);
                        break;
                }
                offset = (cap >> 8) & 0xff;
        }
        if (!count)
-               printk(KERN_DEBUG "%s %s: capability loop?\n",
-                               pdev->dev.bus_id, "EHCI");
+               dev_printk(KERN_DEBUG, &pdev->dev, "EHCI: capability loop?\n");
 
        /*
         * halt EHCI & disable its interrupts in any case
index fe9ceb077d9bbddaf38f7dd6998ca73d1bea7b1a..57388252b693cb7ca6e79fa75c251b1abc64f708 100644 (file)
 
 struct r8a66597_pipe_info {
        u16 pipenum;
-       u16 address;    /* R8A66597 HCD usb addres */
+       u16 address;    /* R8A66597 HCD usb address */
        u16 epnum;
        u16 maxpacket;
        u16 type;
index d1131a87a5b13ad72e40e4f573a6a7ace8979445..0fb114ca1eba9d598da09483f7565451b351822a 100644 (file)
@@ -478,8 +478,6 @@ static int mdc800_usb_probe (struct usb_interface *intf,
                                {
                                        irq_interval=intf_desc->endpoint [j].desc.bInterval;
                                }
-
-                               continue;
                        }
                }
                if (mdc800->endpoint[i] == -1)
index d721380b242d69a9e4c4addcb21bfdb47d363ec9..937940404b7a316600aff66c83e1d36372b81405 100644 (file)
@@ -1,7 +1,7 @@
 /*
 * cypress_cy7c63.c
 *
-* Copyright (c) 2006 Oliver Bock (o.bock@fh-wolfenbuettel.de)
+* Copyright (c) 2006-2007 Oliver Bock (bock@tfh-berlin.de)
 *
 *      This driver is based on the Cypress USB Driver by Marcus Maul
 *      (cyport) and the 2.0 version of Greg Kroah-Hartman's
@@ -21,6 +21,9 @@
 *      Supported functions:    Read/Write Ports
 *
 *
+*      For up-to-date information please visit:
+*      http://www.obock.de/kernel/cypress
+*
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License as
 *      published by the Free Software Foundation, version 2.
@@ -31,7 +34,7 @@
 #include <linux/kernel.h>
 #include <linux/usb.h>
 
-#define DRIVER_AUTHOR          "Oliver Bock (o.bock@fh-wolfenbuettel.de)"
+#define DRIVER_AUTHOR          "Oliver Bock (bock@tfh-berlin.de)"
 #define DRIVER_DESC            "Cypress CY7C63xxx USB driver"
 
 #define CYPRESS_VENDOR_ID      0xa2c
index 764696ff1e8e27838255834b79f084f6358751f8..801070502cc1b14faa0bd3769247154f2935736f 100644 (file)
@@ -715,7 +715,7 @@ static unsigned iowarrior_poll(struct file *file, poll_table * wait)
  * would use "struct net_driver" instead, and a serial
  * device would use "struct tty_driver".
  */
-static struct file_operations iowarrior_fops = {
+static const struct file_operations iowarrior_fops = {
        .owner = THIS_MODULE,
        .write = iowarrior_write,
        .read = iowarrior_read,
index aab320085ebf007af652cfa797d93c5ac09de1ce..6664043f4645bc0d13fa0ac51a3c6f017356cbbb 100644 (file)
@@ -205,7 +205,7 @@ static DEFINE_MUTEX(open_disc_mutex);
 
 /* Structure to hold all of our device specific stuff */
 struct lego_usb_tower {
-       struct semaphore        sem;            /* locks this structure */
+       struct mutex            lock;           /* locks this structure */
        struct usb_device*      udev;           /* save off the usb device pointer */
        unsigned char           minor;          /* the starting minor number for this device */
 
@@ -361,7 +361,7 @@ static int tower_open (struct inode *inode, struct file *file)
        }
 
        /* lock this device */
-       if (down_interruptible (&dev->sem)) {
+       if (mutex_lock_interruptible(&dev->lock)) {
                mutex_unlock(&open_disc_mutex);
                retval = -ERESTARTSYS;
                goto exit;
@@ -421,7 +421,7 @@ static int tower_open (struct inode *inode, struct file *file)
        file->private_data = dev;
 
 unlock_exit:
-       up (&dev->sem);
+       mutex_unlock(&dev->lock);
 
 exit:
        dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval);
@@ -448,7 +448,7 @@ static int tower_release (struct inode *inode, struct file *file)
        }
 
        mutex_lock(&open_disc_mutex);
-       if (down_interruptible (&dev->sem)) {
+       if (mutex_lock_interruptible(&dev->lock)) {
                retval = -ERESTARTSYS;
                goto exit;
        }
@@ -460,7 +460,9 @@ static int tower_release (struct inode *inode, struct file *file)
        }
        if (dev->udev == NULL) {
                /* the device was unplugged before the file was released */
-               up (&dev->sem); /* unlock here as tower_delete frees dev */
+
+               /* unlock here as tower_delete frees dev */
+               mutex_unlock(&dev->lock);
                tower_delete (dev);
                goto exit;
        }
@@ -473,7 +475,7 @@ static int tower_release (struct inode *inode, struct file *file)
        dev->open_count = 0;
 
 unlock_exit:
-       up (&dev->sem);
+       mutex_unlock(&dev->lock);
 
 exit:
        mutex_unlock(&open_disc_mutex);
@@ -586,7 +588,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
        dev = (struct lego_usb_tower *)file->private_data;
 
        /* lock this object */
-       if (down_interruptible (&dev->sem)) {
+       if (mutex_lock_interruptible(&dev->lock)) {
                retval = -ERESTARTSYS;
                goto exit;
        }
@@ -653,7 +655,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
 
 unlock_exit:
        /* unlock the device */
-       up (&dev->sem);
+       mutex_unlock(&dev->lock);
 
 exit:
        dbg(2, "%s: leave, return value %d", __FUNCTION__, retval);
@@ -675,7 +677,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
        dev = (struct lego_usb_tower *)file->private_data;
 
        /* lock this object */
-       if (down_interruptible (&dev->sem)) {
+       if (mutex_lock_interruptible(&dev->lock)) {
                retval = -ERESTARTSYS;
                goto exit;
        }
@@ -737,7 +739,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
 
 unlock_exit:
        /* unlock the device */
-       up (&dev->sem);
+       mutex_unlock(&dev->lock);
 
 exit:
        dbg(2, "%s: leave, return value %d", __FUNCTION__, retval);
@@ -862,7 +864,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
                goto exit;
        }
 
-       init_MUTEX (&dev->sem);
+       mutex_init(&dev->lock);
 
        dev->udev = udev;
        dev->open_count = 0;
@@ -1007,16 +1009,16 @@ static void tower_disconnect (struct usb_interface *interface)
        /* give back our minor */
        usb_deregister_dev (interface, &tower_class);
 
-       down (&dev->sem);
+       mutex_lock(&dev->lock);
        mutex_unlock(&open_disc_mutex);
 
        /* if the device is not opened, then we clean up right now */
        if (!dev->open_count) {
-               up (&dev->sem);
+               mutex_unlock(&dev->lock);
                tower_delete (dev);
        } else {
                dev->udev = NULL;
-               up (&dev->sem);
+               mutex_unlock(&dev->lock);
        }
 
        info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE));
index 9244d067cec1d9e3232d3379bae6cf46fa998925..cb7fa0eaf3ae9e264bc4fea418a6e70afe979021 100644 (file)
@@ -323,7 +323,7 @@ sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data,
                        usb_kill_urb(urb);
                        retval = -ETIMEDOUT;
                } else {
-                       /* URB completed within timout */
+                       /* URB completed within timeout */
                        retval = urb->status;
                        readbytes = urb->actual_length;
                }
@@ -3195,20 +3195,6 @@ static int sisusb_probe(struct usb_interface *intf,
 
        sisusb->present = 1;
 
-#ifdef SISUSB_OLD_CONFIG_COMPAT
-       {
-       int ret;
-       /* Our ioctls are all "32/64bit compatible" */
-       ret =  register_ioctl32_conversion(SISUSB_GET_CONFIG_SIZE, NULL);
-       ret |= register_ioctl32_conversion(SISUSB_GET_CONFIG,      NULL);
-       ret |= register_ioctl32_conversion(SISUSB_COMMAND,         NULL);
-       if (ret)
-               dev_err(&sisusb->sisusb_dev->dev, "Error registering ioctl32 translations\n");
-       else
-               sisusb->ioctl32registered = 1;
-       }
-#endif
-
        if (dev->speed == USB_SPEED_HIGH) {
                int initscreen = 1;
 #ifdef INCL_SISUSB_CON
@@ -3271,19 +3257,6 @@ static void sisusb_disconnect(struct usb_interface *intf)
 
        usb_set_intfdata(intf, NULL);
 
-#ifdef SISUSB_OLD_CONFIG_COMPAT
-       if (sisusb->ioctl32registered) {
-               int ret;
-               sisusb->ioctl32registered = 0;
-               ret =  unregister_ioctl32_conversion(SISUSB_GET_CONFIG_SIZE);
-               ret |= unregister_ioctl32_conversion(SISUSB_GET_CONFIG);
-               ret |= unregister_ioctl32_conversion(SISUSB_COMMAND);
-               if (ret) {
-                       dev_err(&sisusb->sisusb_dev->dev, "Error unregistering ioctl32 translations\n");
-               }
-       }
-#endif
-
        sisusb->present = 0;
        sisusb->ready = 0;
 
index d2d7872cd0229622ba546f3fc3111b20bccc471e..cf0b4a5883f665f27f2f9d34d13e9854d080565f 100644 (file)
@@ -120,9 +120,6 @@ struct sisusb_usb_data {
        int isopen;             /* !=0 if open */
        int present;            /* !=0 if device is present on the bus */
        int ready;              /* !=0 if device is ready for userland */
-#ifdef SISUSB_OLD_CONFIG_COMPAT
-       int ioctl32registered;
-#endif
        int numobufs;           /* number of obufs = number of out urbs */
        char *obuf[NUMOBUFS], *ibuf;    /* transfer buffers */
        int obufsize, ibufsize;
index ea3162146481fa4791a4ec750b4c1f5a6b83bc77..da922dfc0dccfefa3c308d35301580fe1e39d82f 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/scatterlist.h>
+#include <linux/mutex.h>
 
 #include <linux/usb.h>
 
@@ -64,7 +65,7 @@ struct usbtest_dev {
        int                     in_iso_pipe;
        int                     out_iso_pipe;
        struct usb_endpoint_descriptor  *iso_in, *iso_out;
-       struct semaphore        sem;
+       struct mutex            lock;
 
 #define TBUF_SIZE      256
        u8                      *buf;
@@ -1151,6 +1152,7 @@ static int verify_halted (int ep, struct urb *urb)
                dbg ("ep %02x couldn't get halt status, %d", ep, retval);
                return retval;
        }
+       le16_to_cpus(&status);
        if (status != 1) {
                dbg ("ep %02x bogus status: %04x != 1", ep, status);
                return -EINVAL;
@@ -1310,7 +1312,7 @@ static int ctrl_out (struct usbtest_dev *dev,
                len += vary;
 
                /* [real world] the "zero bytes IN" case isn't really used.
-                * hardware can easily trip up in this wierd case, since its
+                * hardware can easily trip up in this weird case, since its
                 * status stage is IN, not OUT like other ep0in transfers.
                 */
                if (len > length)
@@ -1558,11 +1560,11 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                        || param->sglen < 0 || param->vary < 0)
                return -EINVAL;
 
-       if (down_interruptible (&dev->sem))
+       if (mutex_lock_interruptible(&dev->lock))
                return -ERESTARTSYS;
 
        if (intf->dev.power.power_state.event != PM_EVENT_ON) {
-               up (&dev->sem);
+               mutex_unlock(&dev->lock);
                return -EHOSTUNREACH;
        }
 
@@ -1574,7 +1576,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                int     res;
 
                if (intf->altsetting->desc.bInterfaceNumber) {
-                       up (&dev->sem);
+                       mutex_unlock(&dev->lock);
                        return -ENODEV;
                }
                res = set_altsetting (dev, dev->info->alt);
@@ -1582,7 +1584,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                        dev_err (&intf->dev,
                                        "set altsetting to %d failed, %d\n",
                                        dev->info->alt, res);
-                       up (&dev->sem);
+                       mutex_unlock(&dev->lock);
                        return res;
                }
        }
@@ -1855,7 +1857,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
                param->duration.tv_usec += 1000 * 1000;
                param->duration.tv_sec -= 1;
        }
-       up (&dev->sem);
+       mutex_unlock(&dev->lock);
        return retval;
 }
 
@@ -1905,7 +1907,7 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
                return -ENOMEM;
        info = (struct usbtest_info *) id->driver_info;
        dev->info = info;
-       init_MUTEX (&dev->sem);
+       mutex_init(&dev->lock);
 
        dev->intf = intf;
 
@@ -1990,8 +1992,6 @@ static void usbtest_disconnect (struct usb_interface *intf)
 {
        struct usbtest_dev      *dev = usb_get_intfdata (intf);
 
-       down (&dev->sem);
-
        usb_set_intfdata (intf, NULL);
        dev_dbg (&intf->dev, "disconnect\n");
        kfree (dev);
index f06e4e2b49d3bdac755d8136077dcae352bcb19d..1774ba5c4c3bf8944118d7b13c944f07370a1529 100644 (file)
@@ -1026,6 +1026,8 @@ mon_bin_poll(struct file *file, struct poll_table_struct *wait)
        return mask;
 }
 
+#if 0
+
 /*
  * open and close: just keep track of how many times the device is
  * mapped, to use the proper memory allocation function.
@@ -1045,33 +1047,31 @@ static void mon_bin_vma_close(struct vm_area_struct *vma)
 /*
  * Map ring pages to user space.
  */
-struct page *mon_bin_vma_nopage(struct vm_area_struct *vma,
-                                unsigned long address, int *type)
+static int mon_bin_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        struct mon_reader_bin *rp = vma->vm_private_data;
        unsigned long offset, chunk_idx;
        struct page *pageptr;
 
-       offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
+       offset = vmf->pgoff << PAGE_SHIFT;
        if (offset >= rp->b_size)
-               return NOPAGE_SIGBUS;
+               return VM_FAULT_SIGBUS;
        chunk_idx = offset / CHUNK_SIZE;
        pageptr = rp->b_vec[chunk_idx].pg;
        get_page(pageptr);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return pageptr;
+       vmf->page = pageptr;
+       return 0;
 }
 
 struct vm_operations_struct mon_bin_vm_ops = {
        .open =     mon_bin_vma_open,
        .close =    mon_bin_vma_close,
-       .nopage =   mon_bin_vma_nopage,
+       .fault =    mon_bin_vma_fault,
 };
 
 int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-       /* don't do anything here: "nopage" will set up page table entries */
+       /* don't do anything here: "fault" will set up page table entries */
        vma->vm_ops = &mon_bin_vm_ops;
        vma->vm_flags |= VM_RESERVED;
        vma->vm_private_data = filp->private_data;
@@ -1079,7 +1079,9 @@ int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
        return 0;
 }
 
-struct file_operations mon_fops_binary = {
+#endif  /*  0  */
+
+static const struct file_operations mon_fops_binary = {
        .owner =        THIS_MODULE,
        .open =         mon_bin_open,
        .llseek =       no_llseek,
index 4a86696e6c7dd20240aca1776139669c9ac4005c..c1e65dfd93538349f07b4d056bbdc2d25a0709a5 100644 (file)
@@ -2,10 +2,7 @@
 # USB Serial device configuration
 #
 
-menu "USB Serial Converter support"
-       depends on USB!=n
-
-config USB_SERIAL
+menuconfig USB_SERIAL
        tristate "USB Serial Converter support"
        depends on USB
        ---help---
@@ -20,6 +17,8 @@ config USB_SERIAL
          To compile this driver as a module, choose M here: the
          module will be called usbserial.
 
+if USB_SERIAL
+
 config USB_SERIAL_CONSOLE
        bool "USB Serial Console device support (EXPERIMENTAL)"
        depends on USB_SERIAL=y && EXPERIMENTAL
@@ -43,6 +42,12 @@ config USB_SERIAL_CONSOLE
 
          If unsure, say N.
 
+config USB_EZUSB
+       bool "Functions for loading firmware on EZUSB chips"
+       depends on USB_SERIAL
+       help
+           Say Y here if you need EZUSB device support.
+
 config USB_SERIAL_GENERIC
        bool "USB Generic Serial Driver"
        depends on USB_SERIAL
@@ -105,6 +110,7 @@ config USB_SERIAL_CH341
 config USB_SERIAL_WHITEHEAT
        tristate "USB ConnectTech WhiteHEAT Serial Driver"
        depends on USB_SERIAL
+       select USB_EZUSB
        help
          Say Y here if you want to use a ConnectTech WhiteHEAT 4 port
          USB to serial converter device.
@@ -282,9 +288,21 @@ config USB_SERIAL_IPW
          To compile this driver as a module, choose M here: the
          module will be called ipw.
 
+config USB_SERIAL_IUU
+       tristate "USB Infinity USB Unlimited Phoenix Driver (Experimental)"
+       depends on USB_SERIAL && EXPERIMENTAL
+       help
+         Say Y here if you want to use a IUU in phoenix mode and get
+         an extra ttyUSBx device. More information available on
+         http://eczema.ecze.com/iuu_phoenix.html
+
+         To compile this driver as a module, choose M here: the
+         module will be called iuu_phoenix.o
+
 config USB_SERIAL_KEYSPAN_PDA
        tristate "USB Keyspan PDA Single Port Serial Driver"
        depends on USB_SERIAL
+       select USB_EZUSB
        help
          Say Y here if you want to use a Keyspan PDA single port USB to
          serial converter device.  This driver makes use of firmware
@@ -296,6 +314,7 @@ config USB_SERIAL_KEYSPAN_PDA
 config USB_SERIAL_KEYSPAN
        tristate "USB Keyspan USA-xxx Serial Driver"
        depends on USB_SERIAL
+       select USB_EZUSB
        ---help---
          Say Y here if you want to use Keyspan USB to serial converter
          devices.  This driver makes use of Keyspan's official firmware
@@ -538,6 +557,7 @@ config USB_SERIAL_CYBERJACK
 config USB_SERIAL_XIRCOM
        tristate "USB Xircom / Entregra Single Port Serial Driver"
        depends on USB_SERIAL
+       select USB_EZUSB
        help
          Say Y here if you want to use a Xircom or Entregra single port USB to
          serial converter device.  This driver makes use of firmware
@@ -585,11 +605,4 @@ config USB_SERIAL_DEBUG
          To compile this driver as a module, choose M here: the
          module will be called usb-debug.
 
-config USB_EZUSB
-       bool
-       depends on USB_SERIAL_KEYSPAN_PDA || USB_SERIAL_XIRCOM || USB_SERIAL_KEYSPAN || USB_SERIAL_WHITEHEAT
-       default y
-
-
-endmenu
-
+endif # USB_SERIAL
index d6fb384e52b24ab1dca674e1ceaa9bfd515595e0..0db109a54d10b621242f1ca489f23362ed2a3528 100644 (file)
@@ -30,6 +30,7 @@ obj-$(CONFIG_USB_SERIAL_GARMIN)                       += garmin_gps.o
 obj-$(CONFIG_USB_SERIAL_HP4X)                  += hp4x.o
 obj-$(CONFIG_USB_SERIAL_IPAQ)                  += ipaq.o
 obj-$(CONFIG_USB_SERIAL_IPW)                   += ipw.o
+obj-$(CONFIG_USB_SERIAL_IUU)                   += iuu_phoenix.o
 obj-$(CONFIG_USB_SERIAL_IR)                    += ir-usb.o
 obj-$(CONFIG_USB_SERIAL_KEYSPAN)               += keyspan.o
 obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA)           += keyspan_pda.o
index 77bb893bf2e922c51bb51ef4e2ac69f6d2cd2a86..f156dba0300f77168f7774199e988074bd249e8a 100644 (file)
@@ -217,7 +217,10 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
        priv->rts_state = 0;
        priv->dtr_state = 0;
 
-       airprime_send_setup(port);
+       mutex_lock(&port->serial->disc_mutex);
+       if (!port->serial->disconnected)
+               airprime_send_setup(port);
+       mutex_lock(&port->serial->disc_mutex);
 
        for (i = 0; i < NUM_READ_URBS; ++i) {
                usb_kill_urb (priv->read_urbp[i]);
index ddfee918000dc5fd8b6b997d75a81625472821c4..fe2bfd67ba8e4717ef3b96657902663dbeedd22c 100644 (file)
@@ -151,8 +151,10 @@ static int ark3116_attach(struct usb_serial *serial)
        return 0;
 
 cleanup:
-       for (--i; i >= 0; --i)
+       for (--i; i >= 0; --i) {
+               kfree(usb_get_serial_port_data(serial->port[i]));
                usb_set_serial_port_data(serial->port[i], NULL);
+       }
        return -ENOMEM;
 }
 
index 86724e885704b01dcfb77d9291d3958690f32932..df0a2b3b02943e76d40a89f832c498eea0e964ca 100644 (file)
@@ -350,14 +350,12 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
        unsigned long control_state;
        int bad_flow_control;
        speed_t baud;
+       struct ktermios *termios = port->tty->termios;
        
-       if ((!port->tty) || (!port->tty->termios)) {
-               dbg ("%s - no tty or termios structure", __FUNCTION__);
-               return;
-       }
+       iflag = termios->c_iflag;
+       cflag = termios->c_cflag;
 
-       iflag = port->tty->termios->c_iflag;
-       cflag = port->tty->termios->c_cflag;
+       termios->c_cflag &= ~CMSPAR;
 
        /* get a local copy of the current port settings */
        spin_lock_irqsave(&priv->lock, flags);
@@ -369,33 +367,30 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
        old_cflag = old_termios->c_cflag;
 
        /* Set the baud rate */
-       if( (cflag&CBAUD) != (old_cflag&CBAUD) ) {
+       if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
                /* reassert DTR and (maybe) RTS on transition from B0 */
                if( (old_cflag&CBAUD) == B0 ) {
                        control_state |= (TIOCM_DTR|TIOCM_RTS);
                        if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0)
                                err("Set DTR error");
                        /* don't set RTS if using hardware flow control */
-                       if (!(old_cflag&CRTSCTS) )
+                       if (!(old_cflag & CRTSCTS))
                                if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0)
                                        err("Set RTS error");
                }
        }
 
        baud = tty_get_baud_rate(port->tty);
-       if (baud == 0) {
-               dbg("%s - tty_get_baud_rate says 0 baud", __FUNCTION__);
-               return;
-       }
-       urb_value = BELKIN_SA_BAUD(baud);
-       /* Clip to maximum speed */
-       if (urb_value == 0)
-               urb_value = 1;
-       /* Turn it back into a resulting real baud rate */
-       baud = BELKIN_SA_BAUD(urb_value);
-       /* FIXME: Once the tty updates are done then push this back to the tty */
-
-       if ((cflag & CBAUD) != B0 ) {
+       if (baud) {
+               urb_value = BELKIN_SA_BAUD(baud);
+               /* Clip to maximum speed */
+               if (urb_value == 0)
+                       urb_value = 1;
+               /* Turn it back into a resulting real baud rate */
+               baud = BELKIN_SA_BAUD(urb_value);
+
+               /* Report the actual baud rate back to the caller */
+               tty_encode_baud_rate(port->tty, baud, baud);
                if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0)
                        err("Set baudrate error");
        } else {
index 0362654d3b52e8aa53453c6cb499a8d247a9f8b2..66ce30c1b75bba3db5e91e61f8105f10ba2a30d2 100644 (file)
@@ -64,8 +64,8 @@ static int usb_console_setup(struct console *co, char *options)
        struct usb_serial *serial;
        struct usb_serial_port *port;
        int retval = 0;
-       struct tty_struct *tty;
-       struct ktermios *termios;
+       struct tty_struct *tty = NULL;
+       struct ktermios *termios = NULL, dummy;
 
        dbg ("%s", __FUNCTION__);
 
@@ -133,11 +133,14 @@ static int usb_console_setup(struct console *co, char *options)
        }
        co->cflag = cflag;
 
-       /* grab the first serial port that happens to be connected */
-       serial = usb_serial_get_by_index(0);
+       /*
+        * no need to check the index here: if the index is wrong, console
+        * code won't call us
+        */
+       serial = usb_serial_get_by_index(co->index);
        if (serial == NULL) {
                /* no device is connected yet, sorry :( */
-               err ("No USB device connected to ttyUSB0");
+               err ("No USB device connected to ttyUSB%i", co->index);
                return -ENODEV;
        }
 
@@ -148,49 +151,64 @@ static int usb_console_setup(struct console *co, char *options)
         
        ++port->open_count;
        if (port->open_count == 1) {
+               if (serial->type->set_termios) {
+                       /*
+                        * allocate a fake tty so the driver can initialize
+                        * the termios structure, then later call set_termios to
+                        * configure according to command line arguments
+                        */
+                       tty = kzalloc(sizeof(*tty), GFP_KERNEL);
+                       if (!tty) {
+                               retval = -ENOMEM;
+                               err("no more memory");
+                               goto reset_open_count;
+                       }
+                       termios = kzalloc(sizeof(*termios), GFP_KERNEL);
+                       if (!termios) {
+                               retval = -ENOMEM;
+                               err("no more memory");
+                               goto free_tty;
+                       }
+                       memset(&dummy, 0, sizeof(struct ktermios));
+                       tty->termios = termios;
+                       port->tty = tty;
+               }
+
                /* only call the device specific open if this 
                 * is the first time the port is opened */
                if (serial->type->open)
                        retval = serial->type->open(port, NULL);
                else
                        retval = usb_serial_generic_open(port, NULL);
-               if (retval)
-                       port->open_count = 0;
-       }
 
-       if (retval) {
-               err ("could not open USB console port");
-               return retval;
-       }
-
-       if (serial->type->set_termios) {
-               struct ktermios dummy;
-               /* build up a fake tty structure so that the open call has something
-                * to look at to get the cflag value */
-               tty = kzalloc(sizeof(*tty), GFP_KERNEL);
-               if (!tty) {
-                       err ("no more memory");
-                       return -ENOMEM;
+               if (retval) {
+                       err("could not open USB console port");
+                       goto free_termios;
                }
-               termios = kzalloc(sizeof(*termios), GFP_KERNEL);
-               if (!termios) {
-                       err ("no more memory");
-                       kfree (tty);
-                       return -ENOMEM;
-               }
-               memset(&dummy, 0, sizeof(struct ktermios));
-               termios->c_cflag = cflag;
-               tty->termios = termios;
-               port->tty = tty;
 
-               /* set up the initial termios settings */
-               serial->type->set_termios(port, &dummy);
-               port->tty = NULL;
-               kfree (termios);
-               kfree (tty);
+               if (serial->type->set_termios) {
+                       termios->c_cflag = cflag;
+                       serial->type->set_termios(port, &dummy);
+
+                       port->tty = NULL;
+                       kfree(termios);
+                       kfree(tty);
+               }
        }
 
+       port->console = 1;
+       retval = 0;
+
+out:
        return retval;
+free_termios:
+       kfree(termios);
+       port->tty = NULL;
+free_tty:
+       kfree(tty);
+reset_open_count:
+       port->open_count = 0;
+goto out;
 }
 
 static void usb_console_write(struct console *co, const char *buf, unsigned count)
index 22833589c4bedcc17ea2120552f6eaf9118a88b3..f3ca66017a031ba81db256216b905b4cf3989efa 100644 (file)
@@ -59,6 +59,7 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
        { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
        { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
+       { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */
        { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
        { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */
        { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */
@@ -76,8 +77,13 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
        { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
        { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
+       { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
+       { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */
+       { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
+       { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */
        { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
        { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
+       { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */
        { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
        { } /* Terminating Entry */
 };
@@ -342,7 +348,10 @@ static void cp2101_close (struct usb_serial_port *port, struct file * filp)
        usb_kill_urb(port->write_urb);
        usb_kill_urb(port->read_urb);
 
-       cp2101_set_config_single(port, CP2101_UART, UART_DISABLE);
+       mutex_lock(&port->serial->disc_mutex);
+       if (!port->serial->disconnected)
+               cp2101_set_config_single(port, CP2101_UART, UART_DISABLE);
+       mutex_unlock(&port->serial->disc_mutex);
 }
 
 /*
index 4353df92487f528256ca27bb8169d287d3f85b63..8d9b045aa7e84b1e90f8f5431d088320466079b7 100644 (file)
@@ -319,7 +319,6 @@ static void cyberjack_read_int_callback( struct urb *urb )
        /* React only to interrupts signaling a bulk_in transfer */
        if( (urb->actual_length==4) && (data[0]==0x01) ) {
                short old_rdtodo;
-               int result;
 
                /* This is a announcement of coming bulk_ins. */
                unsigned short size = ((unsigned short)data[3]<<8)+data[2]+3;
index 163386336a5daa76852eda408974ace308bf2176..08c65c1a377163ded8eaf7f861674250852bcc6c 100644 (file)
@@ -682,7 +682,6 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
 {
        struct cypress_private *priv = usb_get_serial_port_data(port);
        unsigned int c_cflag;
-       unsigned long flags;
        int bps;
        long timeout;
        wait_queue_t wait;
@@ -690,7 +689,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
        dbg("%s - port %d", __FUNCTION__, port->number);
 
        /* wait for data to drain from buffer */
-       spin_lock_irqsave(&priv->lock, flags);
+       spin_lock_irq(&priv->lock);
        timeout = CYPRESS_CLOSING_WAIT;
        init_waitqueue_entry(&wait, current);
        add_wait_queue(&port->tty->write_wait, &wait);
@@ -698,18 +697,25 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
                set_current_state(TASK_INTERRUPTIBLE);
                if (cypress_buf_data_avail(priv->buf) == 0
                || timeout == 0 || signal_pending(current)
-               || !usb_get_intfdata(port->serial->interface))
+               /* without mutex, allowed due to harmless failure mode */
+               || port->serial->disconnected)
                        break;
-               spin_unlock_irqrestore(&priv->lock, flags);
+               spin_unlock_irq(&priv->lock);
                timeout = schedule_timeout(timeout);
-               spin_lock_irqsave(&priv->lock, flags);
+               spin_lock_irq(&priv->lock);
        }
        set_current_state(TASK_RUNNING);
        remove_wait_queue(&port->tty->write_wait, &wait);
        /* clear out any remaining data in the buffer */
        cypress_buf_clear(priv->buf);
-       spin_unlock_irqrestore(&priv->lock, flags);
-       
+       spin_unlock_irq(&priv->lock);
+
+       /* writing is potentially harmful, lock must be taken */
+       mutex_lock(&port->serial->disc_mutex);
+       if (port->serial->disconnected) {
+               mutex_unlock(&port->serial->disc_mutex);
+               return;
+       }
        /* wait for characters to drain from device */
        bps = tty_get_baud_rate(port->tty);
        if (bps > 1200)
@@ -727,10 +733,10 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
                if (c_cflag & HUPCL) {
                        /* drop dtr and rts */
                        priv = usb_get_serial_port_data(port);
-                       spin_lock_irqsave(&priv->lock, flags);
+                       spin_lock_irq(&priv->lock);
                        priv->line_control = 0;
                        priv->cmd_ctrl = 1;
-                       spin_unlock_irqrestore(&priv->lock, flags);
+                       spin_unlock_irq(&priv->lock);
                        cypress_write(port, NULL, 0);
                }
        }
@@ -738,6 +744,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
        if (stats)
                dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
                          priv->bytes_in, priv->bytes_out, priv->cmd_count);
+       mutex_unlock(&port->serial->disc_mutex);
 } /* cypress_close */
 
 
index ae410c4678ea697abe9f62a435a5aca73f87490e..5f9c6e46bee5712effaed0346d7ae5a31e305d60 100644 (file)
@@ -1405,19 +1405,19 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
        unsigned char buf[32];
        struct tty_struct *tty = port->tty;
        struct digi_port *priv = usb_get_serial_port_data(port);
-       unsigned long flags = 0;
 
        dbg("digi_close: TOP: port=%d, open_count=%d",
                priv->dp_port_num, port->open_count);
 
+       mutex_lock(&port->serial->disc_mutex);
        /* if disconnected, just clear flags */
-       if (!usb_get_intfdata(port->serial->interface))
+       if (port->serial->disconnected)
                goto exit;
 
        /* do cleanup only after final close on this port */
-       spin_lock_irqsave(&priv->dp_port_lock, flags);
+       spin_lock_irq(&priv->dp_port_lock);
        priv->dp_in_close = 1;
-       spin_unlock_irqrestore(&priv->dp_port_lock, flags);
+       spin_unlock_irq(&priv->dp_port_lock);
 
        /* tell line discipline to process only XON/XOFF */
        tty->closing = 1;
@@ -1482,11 +1482,12 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
        }
        tty->closing = 0;
 exit:
-       spin_lock_irqsave(&priv->dp_port_lock, flags);
+       spin_lock_irq(&priv->dp_port_lock);
        priv->dp_write_urb_in_use = 0;
        priv->dp_in_close = 0;
        wake_up_interruptible(&priv->dp_close_wait);
-       spin_unlock_irqrestore(&priv->dp_port_lock, flags);
+       spin_unlock_irq(&priv->dp_port_lock);
+       mutex_unlock(&port->serial->disc_mutex);
        dbg("digi_close: done");
 }
 
index 97ee718b1da2a29bf08ed4f30e88cff14bb3beb9..3f698baa0abb69d1015c4d69fa7576d357f0b9c5 100644 (file)
@@ -53,6 +53,6 @@ int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit)
 }
 
 
-EXPORT_SYMBOL(ezusb_writememory);
-EXPORT_SYMBOL(ezusb_set_reset);
+EXPORT_SYMBOL_GPL(ezusb_writememory);
+EXPORT_SYMBOL_GPL(ezusb_set_reset);
 
index c40e77dccf8ea91224b94841e1f74efb9533613d..90dcc625f70deb008c45ca0c6c349ba0a6d6eb4e 100644 (file)
  * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
  *     and extra documentation
  *
- * (21/Jul/2004) Ian Abbott
- *      Incorporated Steven Turner's code to add support for the FT2232C chip.
- *      The prelimilary port to the 2.6 kernel was by Rus V. Brushkoff.  I have
- *      fixed a couple of things.
- *
- * (27/May/2004) Ian Abbott
- *      Improved throttling code, mostly stolen from the WhiteHEAT driver.
- *
- * (26/Mar/2004) Jan Capek
- *      Added PID's for ICD-U20/ICD-U40 - incircuit PIC debuggers from CCS Inc.
- *
- * (09/Feb/2004) Ian Abbott
- *      Changed full name of USB-UIRT device to avoid "/" character.
- *      Added FTDI's alternate PID (0x6006) for FT232/245 devices.
- *      Added PID for "ELV USB Module UO100" from Stefan Frings.
- *
- * (21/Oct/2003) Ian Abbott
- *      Renamed some VID/PID macros for Matrix Orbital and Perle Systems
- *      devices.  Removed Matrix Orbital and Perle Systems devices from the
- *      8U232AM device table, but left them in the FT232BM table, as they are
- *      known to use only FT232BM.
- *
- * (17/Oct/2003) Scott Allen
- *      Added vid/pid for Perle Systems UltraPort USB serial converters
- *
- * (21/Sep/2003) Ian Abbott
- *      Added VID/PID for Omnidirectional Control Technology US101 USB to
- *      RS-232 adapter (also rebadged as Dick Smith Electronics XH6381).
- *      VID/PID supplied by Donald Gordon.
- *
- * (19/Aug/2003) Ian Abbott
- *      Freed urb's transfer buffer in write bulk callback.
- *      Omitted some paranoid checks in write bulk callback that don't matter.
- *      Scheduled work in write bulk callback regardless of port's open count.
- *
- * (05/Aug/2003) Ian Abbott
- *      Added VID/PID for ID TECH IDT1221U USB to RS-232 adapter.
- *      VID/PID provided by Steve Briggs.
- *
- * (23/Jul/2003) Ian Abbott
- *      Added PIDs for CrystalFontz 547, 633, 631, 635, 640 and 640 from
- *      Wayne Wylupski.
- *
- * (10/Jul/2003) David Glance
- *      Added PID for DSS-20 SyncStation cradle for Sony-Ericsson P800.
- *
- * (27/Jun/2003) Ian Abbott
- *     Reworked the urb handling logic.  We have no more pool, but dynamically
- *     allocate the urb and the transfer buffer on the fly.  In testing this
- *     does not incure any measurable overhead.  This also relies on the fact
- *     that we have proper reference counting logic for urbs.  I nicked this
- *     from Greg KH's Visor driver.
- *
- * (23/Jun/2003) Ian Abbott
- *      Reduced flip buffer pushes and corrected a data length test in
- *      ftdi_read_bulk_callback.
- *      Defererence pointers after any paranoid checks, not before.
- *
- * (21/Jun/2003) Erik Nygren
- *      Added support for Home Electronics Tira-1 IR transceiver using FT232BM chip.
- *      See <http://www.home-electro.com/tira1.htm>.  Only operates properly
- *      at 100000 and RTS-CTS, so set custom divisor mode on startup.
- *      Also force the Tira-1 and USB-UIRT to only use their custom baud rates.
- *
- * (18/Jun/2003) Ian Abbott
- *      Added Device ID of the USB relais from Rudolf Gugler (backported from
- *      Philipp Gühring's patch for 2.5.x kernel).
- *      Moved read transfer buffer reallocation into startup function.
- *      Free existing write urb and transfer buffer in startup function.
- *      Only use urbs in write urb pool that were successfully allocated.
- *      Moved some constant macros out of functions.
- *      Minor whitespace and comment changes.
- *
- * (12/Jun/2003) David Norwood
- *      Added support for USB-UIRT IR transceiver using 8U232AM chip.
- *      See <http://home.earthlink.net/~jrhees/USBUIRT/index.htm>.  Only
- *      operates properly at 312500, so set custom divisor mode on startup.
- *
- * (12/Jun/2003) Ian Abbott
- *      Added Sealevel SeaLINK+ 210x, 220x, 240x, 280x vid/pids from Tuan Hoang
- *      - I've eliminated some that don't seem to exist!
- *      Added Home Electronics Tira-1 IR transceiver pid from Chris Horn
- *      Some whitespace/coding-style cleanups
- *
- * (11/Jun/2003) Ian Abbott
- *      Fixed unsafe spinlock usage in ftdi_write
- *
- * (24/Feb/2003) Richard Shooter
- *      Increase read buffer size to improve read speeds at higher baud rates
- *      (specifically tested with up to 1Mb/sec at 1.5M baud)
- *
- * (23/Feb/2003) John Wilkins
- *      Added Xon/xoff flow control (activating support in the ftdi device)
- *      Added vid/pid for Videonetworks/Homechoice (UK ISP)
- *
- * (23/Feb/2003) Bill Ryder
- *      Added matrix orb device vid/pids from Wayne Wylupski
- *
- * (19/Feb/2003) Ian Abbott
- *      For TIOCSSERIAL, set alt_speed to 0 when ASYNC_SPD_MASK value has
- *      changed to something other than ASYNC_SPD_HI, ASYNC_SPD_VHI,
- *      ASYNC_SPD_SHI or ASYNC_SPD_WARP.  Also, unless ASYNC_SPD_CUST is in
- *      force, don't bother changing baud rate when custom_divisor has changed.
- *
- * (18/Feb/2003) Ian Abbott
- *      Fixed TIOCMGET handling to include state of DTR and RTS, the state
- *      of which are now saved by set_dtr() and set_rts().
- *      Fixed improper storage class for buf in set_dtr() and set_rts().
- *      Added FT232BM chip type and support for its extra baud rates (compared
- *      to FT8U232AM).
- *      Took account of special case divisor values for highest baud rates of
- *      FT8U232AM and FT232BM.
- *      For TIOCSSERIAL, forced alt_speed to 0 when ASYNC_SPD_CUST kludge used,
- *      as previous alt_speed setting is now stale.
- *      Moved startup code common between the startup routines for the
- *      different chip types into a common subroutine.
- *
- * (17/Feb/2003) Bill Ryder
- *      Added write urb buffer pool on a per device basis
- *      Added more checking for open file on callbacks (fixed OOPS)
- *      Added CrystalFontz 632 and 634 PIDs
- *         (thanx to CrystalFontz for the sample devices - they flushed out
- *           some driver bugs)
- *      Minor debugging message changes
- *      Added throttle, unthrottle and chars_in_buffer functions
- *      Fixed FTDI_SIO (the original device) bug
- *      Fixed some shutdown handling
- *
- *
- *
- *
- * (07/Jun/2002) Kuba Ober
- *     Changed FTDI_SIO_BASE_BAUD_TO_DIVISOR macro into ftdi_baud_to_divisor
- *     function. It was getting too complex.
- *     Fix the divisor calculation logic which was setting divisor of 0.125
- *     instead of 0.5 for fractional parts of divisor equal to 5/8, 6/8, 7/8.
- *     Also make it bump up the divisor to next integer in case of 7/8 - it's
- *     a better approximation.
- *
- * (25/Jul/2002) Bill Ryder inserted Dmitri's TIOCMIWAIT patch
- *      Not tested by me but it doesn't break anything I use.
- *
- * (04/Jan/2002) Kuba Ober
- *     Implemented 38400 baudrate kludge, where it can be substituted with other
- *       values. That's the only way to set custom baudrates.
- *     Implemented TIOCSSERIAL, TIOCGSERIAL ioctl's so that setserial is happy.
- *     FIXME: both baudrate things should eventually go to usbserial.c as other
- *       devices may need that functionality too. Actually, it can probably be
- *       merged in serial.c somehow - too many drivers repeat this code over
- *       and over.
- *     Fixed baudrate forgetfulness - open() used to reset baudrate to 9600 every time.
- *     Divisors for baudrates are calculated by a macro.
- *     Small code cleanups. Ugly whitespace changes for Plato's sake only ;-].
- *
- * (04/Nov/2001) Bill Ryder
- *     Fixed bug in read_bulk_callback where incorrect urb buffer was used.
- *     Cleaned up write offset calculation
- *     Added write_room since default values can be incorrect for sio
- *     Changed write_bulk_callback to use same queue_task as other drivers
- *        (the previous version caused panics)
- *     Removed port iteration code since the device only has one I/O port and it
- *       was wrong anyway.
- *
- * (31/May/2001) gkh
- *     Switched from using spinlock to a semaphore, which fixes lots of problems.
- *
- * (23/May/2001)   Bill Ryder
- *     Added runtime debug patch (thanx Tyson D Sawyer).
- *     Cleaned up comments for 8U232
- *     Added parity, framing and overrun error handling
- *     Added receive break handling.
- *
- * (04/08/2001) gb
- *     Identify version on module load.
- *
- * (18/March/2001) Bill Ryder
- *     (Not released)
- *     Added send break handling. (requires kernel patch too)
- *     Fixed 8U232AM hardware RTS/CTS etc status reporting.
- *     Added flipbuf fix copied from generic device
- *
- * (12/3/2000) Bill Ryder
- *     Added support for 8U232AM device.
- *     Moved PID and VIDs into header file only.
- *     Turned on low-latency for the tty (device will do high baudrates)
- *     Added shutdown routine to close files when device removed.
- *     More debug and error message cleanups.
- *
- * (11/13/2000) Bill Ryder
- *     Added spinlock protected open code and close code.
- *     Multiple opens work (sort of - see webpage mentioned above).
- *     Cleaned up comments. Removed multiple PID/VID definitions.
- *     Factorised cts/dtr code
- *     Made use of __FUNCTION__ in dbg's
- *
- * (11/01/2000) Adam J. Richter
- *     usb_device_id table support
- *
- * (10/05/2000) gkh
- *     Fixed bug with urb->dev not being set properly, now that the usb
- *     core needs it.
- *
- * (09/11/2000) gkh
- *     Removed DEBUG #ifdefs with call to usb_serial_debug_data
- *
- * (07/19/2000) gkh
- *     Added module_init and module_exit functions to handle the fact that this
- *     driver is a loadable module now.
- *
- * (04/04/2000) Bill Ryder
- *     Fixed bugs in TCGET/TCSET ioctls (by removing them - they are
- *        handled elsewhere in the tty io driver chain).
- *
- * (03/30/2000) Bill Ryder
- *     Implemented lots of ioctls
- *     Fixed a race condition in write
- *     Changed some dbg's to errs
- *
- * (03/26/2000) gkh
- *     Split driver up into device specific pieces.
+ * Change entries from 2004 and earlier can be found in versions of this
+ * file in kernel versions prior to the 2.6.24 release.
  *
  */
 
@@ -309,12 +91,12 @@ struct ftdi_sio_quirk {
        void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */
 };
 
-static int   ftdi_olimex_probe         (struct usb_serial *serial);
+static int   ftdi_jtag_probe           (struct usb_serial *serial);
 static void  ftdi_USB_UIRT_setup       (struct ftdi_private *priv);
 static void  ftdi_HE_TIRA1_setup       (struct ftdi_private *priv);
 
-static struct ftdi_sio_quirk ftdi_olimex_quirk = {
-       .probe  = ftdi_olimex_probe,
+static struct ftdi_sio_quirk ftdi_jtag_quirk = {
+       .probe  = ftdi_jtag_probe,
 };
 
 static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
@@ -471,30 +253,28 @@ static struct usb_device_id id_table_combined [] = {
        { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) },
        { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) },
        /*
-        * These will probably use user-space drivers.  Uncomment them if
-        * you need them or use the user-specified vendor/product module
-        * parameters (see ftdi_sio.h for the numbers).  Make a fuss if
-        * you think the driver should recognize any of them by default.
+        * Due to many user requests for multiple ELV devices we enable
+        * them by default.
         */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) }, */
-       /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, */
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) },
        { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
        { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
        { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
@@ -545,6 +325,7 @@ static struct usb_device_id id_table_combined [] = {
        { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) },
        { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) },
        { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16IC_PID) },
        { USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) },
        { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) },
        { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) },
@@ -569,8 +350,13 @@ static struct usb_device_id id_table_combined [] = {
        { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
        { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) },
        { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
+       { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) },
        { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
-               .driver_info = (kernel_ulong_t)&ftdi_olimex_quirk },
+               .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
+       { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID),
+               .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
+       { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
+               .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
        { },                                    /* Optional parameter entry */
        { }                                     /* Terminating entry */
 };
@@ -1283,10 +1069,11 @@ static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv)
 } /* ftdi_HE_TIRA1_setup */
 
 /*
- * First port on Olimex arm-usb-ocd is reserved for JTAG interface
- * and can be accessed from userspace using openocd.
+ * First port on JTAG adaptors such as Olimex arm-usb-ocd or the FIC/OpenMoko
+ * Neo1973 Debug Board is reserved for JTAG interface and can be accessed from
+ * userspace using openocd.
  */
-static int ftdi_olimex_probe(struct usb_serial *serial)
+static int ftdi_jtag_probe(struct usb_serial *serial)
 {
        struct usb_device *udev = serial->dev;
        struct usb_interface *interface = serial->interface;
@@ -1294,7 +1081,7 @@ static int ftdi_olimex_probe(struct usb_serial *serial)
        dbg("%s",__FUNCTION__);
 
        if (interface == udev->actconfig->interface[0]) {
-               info("Ignoring reserved serial port on Olimex arm-usb-ocd\n");
+               info("Ignoring serial port reserved for JTAG");
                return -ENODEV;
        }
 
@@ -1411,7 +1198,8 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
 
        dbg("%s", __FUNCTION__);
 
-       if (c_cflag & HUPCL){
+       mutex_lock(&port->serial->disc_mutex);
+       if (c_cflag & HUPCL && !port->serial->disconnected){
                /* Disable flow control */
                if (usb_control_msg(port->serial->dev,
                                    usb_sndctrlpipe(port->serial->dev, 0),
@@ -1425,6 +1213,7 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
                /* drop RTS and DTR */
                clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
        } /* Note change no line if hupcl is off */
+       mutex_unlock(&port->serial->disc_mutex);
 
        /* cancel any scheduled reading */
        cancel_delayed_work(&priv->rx_work);
index b51cbb0eaa054491c8bcc2479788f28fa0a0afde..6eee2ab914eca092d1d3b53dc92b30ee294605d1 100644 (file)
 #define FTDI_MTXORB_5_PID      0xFA05  /* Matrix Orbital Product Id */
 #define FTDI_MTXORB_6_PID      0xFA06  /* Matrix Orbital Product Id */
 
+/* OOCDlink by Joern Kaipf <joernk@web.de>
+ * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */
+#define FTDI_OOCDLINK_PID      0xbaf8  /* Amontec JTAGkey */
+
 /* Interbiometrics USB I/O Board */
 /* Developed for Interbiometrics by Rudolf Gugler */
 #define INTERBIOMETRICS_VID              0x1209
 #define FTDI_ELV_WS300PC_PID   0xE0F6  /* PC-Wetterstation (WS 300 PC) */
 #define FTDI_ELV_FHZ1300PC_PID 0xE0E8  /* FHZ 1300 PC */
 #define FTDI_ELV_WS500_PID     0xE0E9  /* PC-Wetterstation (WS 500) */
+#define FTDI_ELV_EM1010PC_PID  0xE0EF  /* Engery monitor EM 1010 PC */
 
 /*
  * Definitions for ID TECH (www.idt-net.com) devices
 #define FTDI_ATIK_ATK16C_PID   0xDF32  /* ATIK ATK-16C Colour Camera */
 #define FTDI_ATIK_ATK16HR_PID  0xDF31  /* ATIK ATK-16HR Grayscale Camera */
 #define FTDI_ATIK_ATK16HRC_PID 0xDF33  /* ATIK ATK-16HRC Colour Camera */
+#define FTDI_ATIK_ATK16IC_PID   0xDF35  /* ATIK ATK-16IC Grayscale Camera */
 
 /*
  * Protego product ids
 #define OLIMEX_VID                     0x15BA
 #define OLIMEX_ARM_USB_OCD_PID         0x0003
 
+/* www.elsterelectricity.com Elster Unicom III Optical Probe */
+#define FTDI_ELSTER_UNICOM_PID         0xE700 /* Product Id */
 
 /*
  * The Mobility Lab (TML)
 #define FTDI_SIO_GET_LATENCY_TIMER     10 /* Get the latency timer */
 
 
+/*
+ * FIC / OpenMoko, Inc. http://wiki.openmoko.org/wiki/Neo1973_Debug_Board_v3
+ * Submitted by Harald Welte <laforge@openmoko.org>
+ */
+#define        FIC_VID                 0x1457
+#define        FIC_NEO1973_DEBUG_PID   0x5118
+
 /*
  *   BmRequestType:  1100 0000b
  *   bRequest:       FTDI_E2_READ
index f1c90cfe72515365236c9ddf61e1c41ee90fe82a..d74e43d69230b5ea1d7b75a4b599f9052f658004 100644 (file)
@@ -1020,19 +1020,26 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
        if (!serial)
                return;
 
-       garmin_clear(garmin_data_p);
+       mutex_lock(&port->serial->disc_mutex);
+       if (!port->serial->disconnected)
+               garmin_clear(garmin_data_p);
 
        /* shutdown our urbs */
        usb_kill_urb (port->read_urb);
        usb_kill_urb (port->write_urb);
 
-       if (noResponseFromAppLayer(garmin_data_p) ||
-           ((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) {
-               process_resetdev_request(port);
-               garmin_data_p->state = STATE_RESET;
+       if (!port->serial->disconnected) {
+               if (noResponseFromAppLayer(garmin_data_p) ||
+                   ((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) {
+                       process_resetdev_request(port);
+                       garmin_data_p->state = STATE_RESET;
+               } else {
+                       garmin_data_p->state = STATE_DISCONNECTED;
+               }
        } else {
                garmin_data_p->state = STATE_DISCONNECTED;
        }
+       mutex_unlock(&port->serial->disc_mutex);
 }
 
 
index d41531139c55e249ce14cd0ca86ada8cd5024409..97fa3c4284350ab24a32cc9d46d69bc4e4fe39e2 100644 (file)
@@ -175,6 +175,14 @@ int usb_serial_generic_resume(struct usb_serial *serial)
        struct usb_serial_port *port;
        int i, c = 0, r;
 
+#ifdef CONFIG_PM
+       /*
+        * If this is an autoresume, don't submit URBs.
+        * They will be submitted in the open function instead.
+        */
+       if (serial->dev->auto_pm)
+               return 0;
+#endif
        for (i = 0; i < serial->num_ports; i++) {
                port = serial->port[i];
                if (port->open_count && port->read_urb) {
index a5d2e115e1675e954c28ad67490646a4de27976e..3428ccc28da7ca0a96ee284e0a300ba2a0313632 100644 (file)
@@ -959,7 +959,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
  *
  *     This function will block the close until one of the following:
  *             1. Response to our Chase comes from Edgeport
- *             2. A timout of 10 seconds without activity has expired
+ *             2. A timeout of 10 seconds without activity has expired
  *                (1K of Edgeport data @ 2400 baud ==> 4 sec to empty)
  *
  ************************************************************************/
@@ -999,7 +999,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
                                return;
                        }
                } else {
-                       // Reset timout value back to 10 seconds
+                       // Reset timeout value back to 10 seconds
                        dbg("%s - Last %d, Current %d", __FUNCTION__, lastCredits, edge_port->txCredits);
                        loop = 10;
                }
@@ -1014,7 +1014,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
  *     This function will block the close until one of the following:
  *             1. TX count are 0
  *             2. The edgeport has stopped
- *             3. A timout of 3 seconds without activity has expired
+ *             3. A timeout of 3 seconds without activity has expired
  *
  ************************************************************************/
 static void block_until_tx_empty (struct edgeport_port *edge_port)
@@ -1050,7 +1050,7 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
                                return;
                        }
                } else {
-                       // Reset timout value back to seconds
+                       // Reset timeout value back to seconds
                        loop = 30;
                }
        }
index b8670905bc3ac858d4e30aa91c2191e4c883c88e..cd3405953f741a4b4e103d482a0009db59453550 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/tty_flip.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/serial.h>
 #include <linux/ioctl.h>
 #include <asm/uaccess.h>
@@ -133,7 +134,7 @@ struct edgeport_serial {
        struct product_info product_info;
        u8 TI_I2C_Type;                 // Type of I2C in UMP
        u8 TiReadI2C;                   // Set to TRUE if we have read the I2c in Boot Mode
-       struct semaphore es_sem;
+       struct mutex es_lock;
        int num_ports_open;
        struct usb_serial *serial;
 };
@@ -1978,7 +1979,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
        }
        
        /* set up the port settings */
-       edge_set_termios (port, NULL);
+       edge_set_termios (port, port->tty->termios);
 
        /* open up the port */
 
@@ -2044,7 +2045,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
        dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr);
 
        edge_serial = edge_port->edge_serial;
-       if (down_interruptible(&edge_serial->es_sem))
+       if (mutex_lock_interruptible(&edge_serial->es_lock))
                return -ERESTARTSYS;
        if (edge_serial->num_ports_open == 0) {
                /* we are the first port to be opened, let's post the interrupt urb */
@@ -2052,7 +2053,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
                if (!urb) {
                        dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__);
                        status = -EINVAL;
-                       goto up_es_sem;
+                       goto release_es_lock;
                }
                urb->complete = edge_interrupt_callback;
                urb->context = edge_serial;
@@ -2060,7 +2061,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
                status = usb_submit_urb (urb, GFP_KERNEL);
                if (status) {
                        dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
-                       goto up_es_sem;
+                       goto release_es_lock;
                }
        }
 
@@ -2092,13 +2093,13 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
 
        dbg("%s - exited", __FUNCTION__);
 
-       goto up_es_sem;
+       goto release_es_lock;
 
 unlink_int_urb:
        if (edge_port->edge_serial->num_ports_open == 0)
                usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
-up_es_sem:
-       up(&edge_serial->es_sem);
+release_es_lock:
+       mutex_unlock(&edge_serial->es_lock);
        return status;
 }
 
@@ -2137,14 +2138,14 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
                                     0,
                                     NULL,
                                     0);
-       down(&edge_serial->es_sem);
+       mutex_lock(&edge_serial->es_lock);
        --edge_port->edge_serial->num_ports_open;
        if (edge_port->edge_serial->num_ports_open <= 0) {
                /* last port is now closed, let's shut down our interrupt urb */
                usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
                edge_port->edge_serial->num_ports_open = 0;
        }
-       up(&edge_serial->es_sem);
+       mutex_unlock(&edge_serial->es_lock);
        edge_port->close_pending = 0;
 
        dbg("%s - exited", __FUNCTION__);
@@ -2393,11 +2394,6 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
        dbg("%s - port %d", __FUNCTION__, edge_port->port->number);
 
        tty = edge_port->port->tty;
-       if ((!tty) ||
-           (!tty->termios)) {
-               dbg("%s - no tty structures", __FUNCTION__);
-               return;
-       }
 
        config = kmalloc (sizeof (*config), GFP_KERNEL);
        if (!config) {
@@ -2492,15 +2488,21 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
                }
        }
 
+       tty->termios->c_cflag &= ~CMSPAR;
+
        /* Round the baud rate */
        baud = tty_get_baud_rate(tty);
        if (!baud) {
                /* pick a default, any default... */
                baud = 9600;
-       }
+       } else
+               tty_encode_baud_rate(tty, baud, baud);
+
        edge_port->baud_rate = baud;
        config->wBaudRate = (__u16)((461550L + baud/2) / baud);
 
+       /* FIXME: Recompute actual baud from divisor here */
+
        dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate);
 
        dbg ("wBaudRate:   %d", (int)(461550L / config->wBaudRate));
@@ -2538,19 +2540,12 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
        struct tty_struct *tty = port->tty;
        unsigned int cflag;
 
-       if (!port->tty || !port->tty->termios) {
-               dbg ("%s - no tty or termios", __FUNCTION__);
-               return;
-       }
-
        cflag = tty->termios->c_cflag;
 
        dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 
            tty->termios->c_cflag, tty->termios->c_iflag);
-       if (old_termios) {
-               dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
-                   old_termios->c_cflag, old_termios->c_iflag);
-       }
+       dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
+           old_termios->c_cflag, old_termios->c_iflag);
 
        dbg("%s - port %d", __FUNCTION__, port->number);
 
@@ -2743,7 +2738,7 @@ static int edge_startup (struct usb_serial *serial)
                dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
                return -ENOMEM;
        }
-       sema_init(&edge_serial->es_sem, 1);
+       mutex_init(&edge_serial->es_lock);
        edge_serial->serial = serial;
        usb_set_serial_data(serial, edge_serial);
 
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
new file mode 100644 (file)
index 0000000..fde188e
--- /dev/null
@@ -0,0 +1,1217 @@
+/*
+ * Infinity Unlimited USB Phoenix driver
+ *
+ * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com)
+ *
+ * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás)
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *  And tested with help of WB Electronics
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/serial.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/spinlock.h>
+#include <linux/uaccess.h>
+#include <linux/usb.h>
+#include <linux/usb/serial.h>
+#include "iuu_phoenix.h"
+#include <linux/random.h>
+
+
+#ifdef CONFIG_USB_SERIAL_DEBUG
+static int debug = 1;
+#else
+static int debug;
+#endif
+
+/*
+ * Version Information
+ */
+#define DRIVER_VERSION "v0.5"
+#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver"
+
+static struct usb_device_id id_table[] = {
+       {USB_DEVICE(IUU_USB_VENDOR_ID, IUU_USB_PRODUCT_ID)},
+       {}                      /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(usb, id_table);
+
+static struct usb_driver iuu_driver = {
+       .name = "iuu_phoenix",
+       .probe = usb_serial_probe,
+       .disconnect = usb_serial_disconnect,
+       .id_table = id_table,
+       .no_dynamic_id = 1,
+};
+
+/* turbo parameter */
+static int boost = 100;
+static int clockmode = 1;
+static int cdmode = 1;
+static int iuu_cardin;
+static int iuu_cardout;
+static int xmas;
+
+static void read_rxcmd_callback(struct urb *urb);
+
+struct iuu_private {
+       spinlock_t lock;        /* store irq state */
+       wait_queue_head_t delta_msr_wait;
+       u8 line_control;
+       u8 line_status;
+       u8 termios_initialized;
+       int tiostatus;          /* store IUART SIGNAL for tiocmget call */
+       u8 reset;               /* if 1 reset is needed */
+       int poll;               /* number of poll */
+       u8 *writebuf;           /* buffer for writing to device */
+       int writelen;           /* num of byte to write to device */
+       u8 *buf;                /* used for initialize speed */
+       u8 *dbgbuf;             /* debug buffer */
+       u8 len;
+};
+
+
+static void iuu_free_buf(struct iuu_private *priv)
+{
+       kfree(priv->buf);
+       kfree(priv->dbgbuf);
+       kfree(priv->writebuf);
+}
+
+static int iuu_alloc_buf(struct iuu_private *priv)
+{
+       priv->buf = kzalloc(256, GFP_KERNEL);
+       priv->dbgbuf = kzalloc(256, GFP_KERNEL);
+       priv->writebuf = kzalloc(256, GFP_KERNEL);
+       if (!priv->buf || !priv->dbgbuf || !priv->writebuf) {
+               iuu_free_buf(priv);
+               dbg("%s problem allocation buffer", __FUNCTION__);
+               return -ENOMEM;
+       }
+       dbg("%s - Privates buffers allocation success", __FUNCTION__);
+       return 0;
+}
+
+static int iuu_startup(struct usb_serial *serial)
+{
+       struct iuu_private *priv;
+       priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL);
+       dbg("%s- priv allocation success", __FUNCTION__);
+       if (!priv)
+               return -ENOMEM;
+       if (iuu_alloc_buf(priv)) {
+               kfree(priv);
+               return -ENOMEM;
+       }
+       spin_lock_init(&priv->lock);
+       init_waitqueue_head(&priv->delta_msr_wait);
+       usb_set_serial_port_data(serial->port[0], priv);
+       return 0;
+}
+
+/* Shutdown function */
+static void iuu_shutdown(struct usb_serial *serial)
+{
+       struct usb_serial_port *port = serial->port[0];
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       if (!port)
+               return;
+
+       dbg("%s", __FUNCTION__);
+
+       if (priv) {
+               iuu_free_buf(priv);
+               dbg("%s - I will free all", __FUNCTION__);
+               usb_set_serial_port_data(port, NULL);
+
+               dbg("%s - priv is not anymore in port structure", __FUNCTION__);
+               kfree(priv);
+
+               dbg("%s priv is now kfree", __FUNCTION__);
+       }
+}
+
+static int iuu_tiocmset(struct usb_serial_port *port, struct file *file,
+                       unsigned int set, unsigned int clear)
+{
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       struct tty_struct *tty;
+       tty = port->tty;
+
+       dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __FUNCTION__,
+           port->number, set, clear);
+       if (set & TIOCM_RTS)
+               priv->tiostatus = TIOCM_RTS;
+
+       if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) {
+               dbg("%s TIOCMSET RESET called !!!", __FUNCTION__);
+               priv->reset = 1;
+               return 0;
+       }
+
+       return 0;
+}
+
+/* This is used to provide a carrier detect mechanism
+ * When a card is present, the response is 0x00
+ * When no card , the reader respond with TIOCM_CD
+ * This is known as CD autodetect mechanism
+ */
+static int iuu_tiocmget(struct usb_serial_port *port, struct file *file)
+{
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       return priv->tiostatus;
+}
+
+static void iuu_rxcmd(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       int result;
+       dbg("%s - enter", __FUNCTION__);
+
+       if (urb->status) {
+               dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+               /* error stop all */
+               return;
+       }
+
+
+       memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1);
+       usb_fill_bulk_urb(port->write_urb, port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->write_urb->transfer_buffer, 1,
+                         read_rxcmd_callback, port);
+       result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
+}
+
+static int iuu_reset(struct usb_serial_port *port, u8 wt)
+{
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       int result;
+       char *buf_ptr = port->write_urb->transfer_buffer;
+       dbg("%s - enter", __FUNCTION__);
+
+       /* Prepare the reset sequence */
+
+       *buf_ptr++ = IUU_RST_SET;
+       *buf_ptr++ = IUU_DELAY_MS;
+       *buf_ptr++ = wt;
+       *buf_ptr = IUU_RST_CLEAR;
+
+       /* send the sequence */
+
+       usb_fill_bulk_urb(port->write_urb,
+                         port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->write_urb->transfer_buffer, 4, iuu_rxcmd, port);
+       result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
+       priv->reset = 0;
+       return result;
+}
+
+/* Status Function
+ * Return value is
+ * 0x00 = no card
+ * 0x01 = smartcard
+ * 0x02 = sim card
+ */
+static void iuu_update_status_callback(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       u8 *st;
+       dbg("%s - enter", __FUNCTION__);
+
+       if (urb->status) {
+               dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+               /* error stop all */
+               return;
+       }
+
+       st = urb->transfer_buffer;
+       dbg("%s - enter", __FUNCTION__);
+       if (urb->actual_length == 1) {
+               switch (st[0]) {
+               case 0x1:
+                       priv->tiostatus = iuu_cardout;
+                       break;
+               case 0x0:
+                       priv->tiostatus = iuu_cardin;
+                       break;
+               default:
+                       priv->tiostatus = iuu_cardin;
+               }
+       }
+       iuu_rxcmd(urb);
+}
+
+static void iuu_status_callback(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       int result;
+       dbg("%s - enter", __FUNCTION__);
+
+       dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+       usb_fill_bulk_urb(port->read_urb, port->serial->dev,
+                         usb_rcvbulkpipe(port->serial->dev,
+                                         port->bulk_in_endpointAddress),
+                         port->read_urb->transfer_buffer, 256,
+                         iuu_update_status_callback, port);
+       result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
+}
+
+static int iuu_status(struct usb_serial_port *port)
+{
+       int result;
+
+       dbg("%s - enter", __FUNCTION__);
+
+       memset(port->write_urb->transfer_buffer, IUU_GET_STATE_REGISTER, 1);
+       usb_fill_bulk_urb(port->write_urb, port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->write_urb->transfer_buffer, 1,
+                         iuu_status_callback, port);
+       result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
+       return result;
+
+}
+
+static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
+{
+       int status;
+       struct usb_serial *serial = port->serial;
+       int actual = 0;
+
+       dbg("%s - enter", __FUNCTION__);
+
+       /* send the data out the bulk port */
+
+       status =
+           usb_bulk_msg(serial->dev,
+                        usb_sndbulkpipe(serial->dev,
+                                        port->bulk_out_endpointAddress), buf,
+                        count, &actual, HZ * 1);
+
+       if (status != IUU_OPERATION_OK) {
+               dbg("%s - error = %2x", __FUNCTION__, status);
+       } else {
+               dbg("%s - write OK !", __FUNCTION__);
+       }
+       return status;
+}
+
+static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
+{
+       int status;
+       struct usb_serial *serial = port->serial;
+       int actual = 0;
+
+       dbg("%s - enter", __FUNCTION__);
+
+       /* send the data out the bulk port */
+
+       status =
+           usb_bulk_msg(serial->dev,
+                        usb_rcvbulkpipe(serial->dev,
+                                        port->bulk_in_endpointAddress), buf,
+                        count, &actual, HZ * 1);
+
+       if (status != IUU_OPERATION_OK) {
+               dbg("%s - error = %2x", __FUNCTION__, status);
+       } else {
+               dbg("%s - read OK !", __FUNCTION__);
+       }
+
+       return status;
+}
+
+static int iuu_led(struct usb_serial_port *port, unsigned int R,
+                  unsigned int G, unsigned int B, u8 f)
+{
+       int status;
+       u8 *buf;
+       buf = kmalloc(8, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       dbg("%s - enter", __FUNCTION__);
+
+       buf[0] = IUU_SET_LED;
+       buf[1] = R & 0xFF;
+       buf[2] = (R >> 8) & 0xFF;
+       buf[3] = G & 0xFF;
+       buf[4] = (G >> 8) & 0xFF;
+       buf[5] = B & 0xFF;
+       buf[6] = (B >> 8) & 0xFF;
+       buf[7] = f;
+       status = bulk_immediate(port, buf, 8);
+       kfree(buf);
+       if (status != IUU_OPERATION_OK)
+               dbg("%s - led error status = %2x", __FUNCTION__, status);
+       else
+               dbg("%s - led OK !", __FUNCTION__);
+       return IUU_OPERATION_OK;
+}
+
+static void iuu_rgbf_fill_buffer(u8 *buf, u8 r1, u8 r2, u8 g1, u8 g2, u8 b1,
+                                u8 b2, u8 freq)
+{
+       *buf++ = IUU_SET_LED;
+       *buf++ = r1;
+       *buf++ = r2;
+       *buf++ = g1;
+       *buf++ = g2;
+       *buf++ = b1;
+       *buf++ = b2;
+       *buf = freq;
+}
+
+static void iuu_led_activity_on(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       int result;
+       char *buf_ptr = port->write_urb->transfer_buffer;
+       *buf_ptr++ = IUU_SET_LED;
+       if (xmas == 1) {
+               get_random_bytes(buf_ptr, 6);
+               *(buf_ptr+7) = 1;
+       } else {
+               iuu_rgbf_fill_buffer(buf_ptr, 255, 255, 0, 0, 0, 0, 255);
+       }
+
+       usb_fill_bulk_urb(port->write_urb, port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->write_urb->transfer_buffer, 8 ,
+                         iuu_rxcmd, port);
+       result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
+}
+
+static void iuu_led_activity_off(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       int result;
+       char *buf_ptr = port->write_urb->transfer_buffer;
+       if (xmas == 1) {
+               iuu_rxcmd(urb);
+               return;
+       } else {
+               *buf_ptr++ = IUU_SET_LED;
+               iuu_rgbf_fill_buffer(buf_ptr, 0, 0, 255, 255, 0, 0, 255);
+       }
+       usb_fill_bulk_urb(port->write_urb, port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->write_urb->transfer_buffer, 8 ,
+                         iuu_rxcmd, port);
+       result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
+}
+
+
+
+static int iuu_clk(struct usb_serial_port *port, int dwFrq)
+{
+       int status;
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       int Count = 0;
+       u8 FrqGenAdr = 0x69;
+       u8 DIV = 0;             /* 8bit */
+       u8 XDRV = 0;            /* 8bit */
+       u8 PUMP = 0;            /* 3bit */
+       u8 PBmsb = 0;           /* 2bit */
+       u8 PBlsb = 0;           /* 8bit */
+       u8 PO = 0;              /* 1bit */
+       u8 Q = 0;               /* 7bit */
+       /* 24bit = 3bytes */
+       unsigned int P = 0;
+       unsigned int P2 = 0;
+       int frq = (int)dwFrq;
+
+       dbg("%s - enter", __FUNCTION__);
+
+       if (frq == 0) {
+               priv->buf[Count++] = IUU_UART_WRITE_I2C;
+               priv->buf[Count++] = FrqGenAdr << 1;
+               priv->buf[Count++] = 0x09;
+               priv->buf[Count++] = 0x00;
+
+               status = bulk_immediate(port, (u8 *) priv->buf, Count);
+               if (status != 0) {
+                       dbg("%s - write error ", __FUNCTION__);
+                       return status;
+               }
+       } else if (frq == 3579000) {
+               DIV = 100;
+               P = 1193;
+               Q = 40;
+               XDRV = 0;
+       } else if (frq == 3680000) {
+               DIV = 105;
+               P = 161;
+               Q = 5;
+               XDRV = 0;
+       } else if (frq == 6000000) {
+               DIV = 66;
+               P = 66;
+               Q = 2;
+               XDRV = 0x28;
+       } else {
+               unsigned int result = 0;
+               unsigned int tmp = 0;
+               unsigned int check;
+               unsigned int check2;
+               char found = 0x00;
+               unsigned int lQ = 2;
+               unsigned int lP = 2055;
+               unsigned int lDiv = 4;
+
+               for (lQ = 2; lQ <= 47 && !found; lQ++)
+                       for (lP = 2055; lP >= 8 && !found; lP--)
+                               for (lDiv = 4; lDiv <= 127 && !found; lDiv++) {
+                                       tmp = (12000000 / lDiv) * (lP / lQ);
+                                       if (abs((int)(tmp - frq)) <
+                                           abs((int)(frq - result))) {
+                                               check2 = (12000000 / lQ);
+                                               if (check2 < 250000)
+                                                       continue;
+                                               check = (12000000 / lQ) * lP;
+                                               if (check > 400000000)
+                                                       continue;
+                                               if (check < 100000000)
+                                                       continue;
+                                               if (lDiv < 4 || lDiv > 127)
+                                                       continue;
+                                               result = tmp;
+                                               P = lP;
+                                               DIV = lDiv;
+                                               Q = lQ;
+                                               if (result == frq)
+                                                       found = 0x01;
+                                       }
+                               }
+       }
+       P2 = ((P - PO) / 2) - 4;
+       DIV = DIV;
+       PUMP = 0x04;
+       PBmsb = (P2 >> 8 & 0x03);
+       PBlsb = P2 & 0xFF;
+       PO = (P >> 10) & 0x01;
+       Q = Q - 2;
+
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /* 0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x09;
+       priv->buf[Count++] = 0x20;      /* Adr = 0x09 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /* 0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x0C;
+       priv->buf[Count++] = DIV;       /* Adr = 0x0C */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /* 0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x12;
+       priv->buf[Count++] = XDRV;      /* Adr = 0x12 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x13;
+       priv->buf[Count++] = 0x6B;      /* Adr = 0x13 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x40;
+       priv->buf[Count++] = (0xC0 | ((PUMP & 0x07) << 2)) |
+                            (PBmsb & 0x03);    /* Adr = 0x40 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x41;
+       priv->buf[Count++] = PBlsb;     /* Adr = 0x41 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x42;
+       priv->buf[Count++] = Q | (((PO & 0x01) << 7));  /* Adr = 0x42 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x44;
+       priv->buf[Count++] = (char)0xFF;        /* Adr = 0x44 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x45;
+       priv->buf[Count++] = (char)0xFE;        /* Adr = 0x45 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x46;
+       priv->buf[Count++] = 0x7F;      /* Adr = 0x46 */
+       priv->buf[Count++] = IUU_UART_WRITE_I2C;        /*  0x4C */
+       priv->buf[Count++] = FrqGenAdr << 1;
+       priv->buf[Count++] = 0x47;
+       priv->buf[Count++] = (char)0x84;        /* Adr = 0x47 */
+
+       status = bulk_immediate(port, (u8 *) priv->buf, Count);
+       if (status != IUU_OPERATION_OK)
+               dbg("%s - write error ", __FUNCTION__);
+       return status;
+}
+
+static int iuu_uart_flush(struct usb_serial_port *port)
+{
+       int i;
+       int status;
+       u8 rxcmd = IUU_UART_RX;
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+
+       dbg("%s - enter", __FUNCTION__);
+
+       if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0)
+               return -EIO;
+
+       for (i = 0; i < 2; i++) {
+               status = bulk_immediate(port, &rxcmd, 1);
+               if (status != IUU_OPERATION_OK) {
+                       dbg("%s - uart_flush_write error", __FUNCTION__);
+                       return status;
+               }
+
+               status = read_immediate(port, &priv->len, 1);
+               if (status != IUU_OPERATION_OK) {
+                       dbg("%s - uart_flush_read error", __FUNCTION__);
+                       return status;
+               }
+
+               if (priv->len > 0) {
+                       dbg("%s - uart_flush datalen is : %i ", __FUNCTION__,
+                           priv->len);
+                       status = read_immediate(port, priv->buf, priv->len);
+                       if (status != IUU_OPERATION_OK) {
+                               dbg("%s - uart_flush_read error", __FUNCTION__);
+                               return status;
+                       }
+               }
+       }
+       dbg("%s - uart_flush_read OK!", __FUNCTION__);
+       iuu_led(port, 0, 0xF000, 0, 0xFF);
+       return status;
+}
+
+static void read_buf_callback(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       unsigned char *data = urb->transfer_buffer;
+       struct tty_struct *tty;
+       dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+
+       if (urb->status) {
+               dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+               if (urb->status == -EPROTO) {
+                       /* reschedule needed */
+               }
+               return;
+       }
+
+       dbg("%s - %i chars to write", __FUNCTION__, urb->actual_length);
+       tty = port->tty;
+       if (data == NULL)
+               dbg("%s - data is NULL !!!", __FUNCTION__);
+       if (tty && urb->actual_length && data) {
+               tty_insert_flip_string(tty, data, urb->actual_length);
+               tty_flip_buffer_push(tty);
+       }
+       iuu_led_activity_on(urb);
+}
+
+static int iuu_bulk_write(struct usb_serial_port *port)
+{
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       unsigned int flags;
+       int result;
+       int i;
+       char *buf_ptr = port->write_urb->transfer_buffer;
+       dbg("%s - enter", __FUNCTION__);
+
+       *buf_ptr++ = IUU_UART_ESC;
+       *buf_ptr++ = IUU_UART_TX;
+       *buf_ptr++ = priv->writelen;
+
+       memcpy(buf_ptr, priv->writebuf,
+              priv->writelen);
+       if (debug == 1) {
+               for (i = 0; i < priv->writelen; i++)
+                       sprintf(priv->dbgbuf + i*2 ,
+                               "%02X", priv->writebuf[i]);
+               priv->dbgbuf[priv->writelen+i*2] = 0;
+               dbg("%s - writing %i chars : %s", __FUNCTION__,
+                   priv->writelen, priv->dbgbuf);
+       }
+       usb_fill_bulk_urb(port->write_urb, port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->write_urb->transfer_buffer, priv->writelen + 3,
+                         iuu_rxcmd, port);
+       result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
+       spin_lock_irqsave(&priv->lock, flags);
+       priv->writelen = 0;
+       spin_unlock_irqrestore(&priv->lock, flags);
+       usb_serial_port_softint(port);
+       return result;
+}
+
+static int iuu_read_buf(struct usb_serial_port *port, int len)
+{
+       int result;
+       dbg("%s - enter", __FUNCTION__);
+
+       usb_fill_bulk_urb(port->read_urb, port->serial->dev,
+                         usb_rcvbulkpipe(port->serial->dev,
+                                         port->bulk_in_endpointAddress),
+                         port->read_urb->transfer_buffer, len,
+                         read_buf_callback, port);
+       result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
+       return result;
+}
+
+static void iuu_uart_read_callback(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       unsigned int flags;
+       int status;
+       int error = 0;
+       int len = 0;
+       unsigned char *data = urb->transfer_buffer;
+       priv->poll++;
+
+       dbg("%s - enter", __FUNCTION__);
+
+       if (urb->status) {
+               dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+               /* error stop all */
+               return;
+       }
+       if (data == NULL)
+               dbg("%s - data is NULL !!!", __FUNCTION__);
+
+       if (urb->actual_length == 1  && data != NULL)
+               len = (int) data[0];
+
+       if (urb->actual_length > 1) {
+               dbg("%s - urb->actual_length = %i", __FUNCTION__,
+                   urb->actual_length);
+               error = 1;
+               return;
+       }
+       /* if len > 0 call readbuf */
+
+       if (len > 0 && error == 0) {
+               dbg("%s - call read buf - len to read is %i ",
+                       __FUNCTION__, len);
+               status = iuu_read_buf(port, len);
+               return;
+       }
+       /* need to update status  ? */
+       if (priv->poll > 99) {
+               status = iuu_status(port);
+               priv->poll = 0;
+               return;
+       }
+
+       /* reset waiting ? */
+
+       if (priv->reset == 1) {
+               status = iuu_reset(port, 0xC);
+               return;
+       }
+       /* Writebuf is waiting */
+       spin_lock_irqsave(&priv->lock, flags);
+       if (priv->writelen > 0) {
+               spin_unlock_irqrestore(&priv->lock, flags);
+               status = iuu_bulk_write(port);
+               return;
+       }
+       spin_unlock_irqrestore(&priv->lock, flags);
+       /* if nothing to write call again rxcmd */
+       dbg("%s - rxcmd recall", __FUNCTION__);
+       iuu_led_activity_off(urb);
+       return;
+}
+
+static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf,
+                         int count)
+{
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       unsigned int flags;
+       dbg("%s - enter", __FUNCTION__);
+
+       if (count > 256)
+               return -ENOMEM;
+
+       spin_lock_irqsave(&priv->lock, flags);
+       if (priv->writelen > 0) {
+               /* buffer already filled but not commited */
+               spin_unlock_irqrestore(&priv->lock, flags);
+               return (0);
+       }
+       /* fill the buffer */
+       memcpy(priv->writebuf, buf, count);
+       priv->writelen = count;
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       return (count);
+}
+
+static void read_rxcmd_callback(struct urb *urb)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       int result;
+       dbg("%s - enter", __FUNCTION__);
+
+       dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+
+       if (urb->status) {
+               dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+               /* error stop all */
+               return;
+       }
+
+       usb_fill_bulk_urb(port->read_urb, port->serial->dev,
+                         usb_rcvbulkpipe(port->serial->dev,
+                                         port->bulk_in_endpointAddress),
+                         port->read_urb->transfer_buffer, 256,
+                         iuu_uart_read_callback, port);
+       result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
+       dbg("%s - submit result = %d", __FUNCTION__, result);
+       return;
+}
+
+static int iuu_uart_on(struct usb_serial_port *port)
+{
+       int status;
+       u8 *buf;
+
+       buf = kmalloc(sizeof(u8) * 4, GFP_KERNEL);
+
+       if (!buf)
+               return -ENOMEM;
+
+       buf[0] = IUU_UART_ENABLE;
+       buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF);
+       buf[2] = (u8) (0x00FF & IUU_BAUD_9600);
+       buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN);
+
+       status = bulk_immediate(port, buf, 4);
+       if (status != IUU_OPERATION_OK) {
+               dbg("%s - uart_on error", __FUNCTION__);
+               goto uart_enable_failed;
+       }
+       /*  iuu_reset() the card after iuu_uart_on() */
+       status = iuu_uart_flush(port);
+       if (status != IUU_OPERATION_OK)
+               dbg("%s - uart_flush error", __FUNCTION__);
+uart_enable_failed:
+       kfree(buf);
+       return status;
+}
+
+/*  Diables the IUU UART (a.k.a. the Phoenix voiderface) */
+static int iuu_uart_off(struct usb_serial_port *port)
+{
+       int status;
+       u8 *buf;
+       buf = kmalloc(1, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+       buf[0] = IUU_UART_DISABLE;
+
+       status = bulk_immediate(port, buf, 1);
+       if (status != IUU_OPERATION_OK)
+               dbg("%s - uart_off error", __FUNCTION__);
+
+       kfree(buf);
+       return status;
+}
+
+static int iuu_uart_baud(struct usb_serial_port *port, u32 baud,
+                        u32 *actual, u8 parity)
+{
+       int status;
+       u8 *dataout;
+       u8 DataCount = 0;
+       u8 T1Frekvens = 0;
+       u8 T1reload = 0;
+       unsigned int T1FrekvensHZ = 0;
+
+       dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL);
+
+       if (!dataout)
+               return -ENOMEM;
+
+       if (baud < 1200 || baud > 230400) {
+               kfree(dataout);
+               return IUU_INVALID_PARAMETER;
+       }
+       if (baud > 977) {
+               T1Frekvens = 3;
+               T1FrekvensHZ = 500000;
+       }
+
+       if (baud > 3906) {
+               T1Frekvens = 2;
+               T1FrekvensHZ = 2000000;
+       }
+
+       if (baud > 11718) {
+               T1Frekvens = 1;
+               T1FrekvensHZ = 6000000;
+       }
+
+       if (baud > 46875) {
+               T1Frekvens = 0;
+               T1FrekvensHZ = 24000000;
+       }
+
+       T1reload = 256 - (u8) (T1FrekvensHZ / (baud * 2));
+
+       /*  magic number here:  ENTER_FIRMWARE_UPDATE; */
+       dataout[DataCount++] = IUU_UART_ESC;
+       /*  magic number here:  CHANGE_BAUD; */
+       dataout[DataCount++] = IUU_UART_CHANGE;
+       dataout[DataCount++] = T1Frekvens;
+       dataout[DataCount++] = T1reload;
+
+       *actual = (T1FrekvensHZ / (256 - T1reload)) / 2;
+
+       switch (parity & 0x0F) {
+       case IUU_PARITY_NONE:
+               dataout[DataCount++] = 0x00;
+               break;
+       case IUU_PARITY_EVEN:
+               dataout[DataCount++] = 0x01;
+               break;
+       case IUU_PARITY_ODD:
+               dataout[DataCount++] = 0x02;
+               break;
+       case IUU_PARITY_MARK:
+               dataout[DataCount++] = 0x03;
+               break;
+       case IUU_PARITY_SPACE:
+               dataout[DataCount++] = 0x04;
+               break;
+       default:
+               kfree(dataout);
+               return IUU_INVALID_PARAMETER;
+               break;
+       }
+
+       switch (parity & 0xF0) {
+       case IUU_ONE_STOP_BIT:
+               dataout[DataCount - 1] |= IUU_ONE_STOP_BIT;
+               break;
+
+       case IUU_TWO_STOP_BITS:
+               dataout[DataCount - 1] |= IUU_TWO_STOP_BITS;
+               break;
+       default:
+               kfree(dataout);
+               return IUU_INVALID_PARAMETER;
+               break;
+       }
+
+       status = bulk_immediate(port, dataout, DataCount);
+       if (status != IUU_OPERATION_OK)
+               dbg("%s - uart_off error", __FUNCTION__);
+       kfree(dataout);
+       return status;
+}
+
+static int set_control_lines(struct usb_device *dev, u8 value)
+{
+       return 0;
+}
+
+static void iuu_close(struct usb_serial_port *port, struct file *filp)
+{
+       /* iuu_led (port,255,0,0,0); */
+       struct usb_serial *serial;
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+       unsigned long flags;
+       unsigned int c_cflag;
+
+       serial = port->serial;
+       if (!serial)
+               return;
+
+       dbg("%s - port %d", __FUNCTION__, port->number);
+
+       iuu_uart_off(port);
+       if (serial->dev) {
+               if (port->tty) {
+                       c_cflag = port->tty->termios->c_cflag;
+                       if (c_cflag & HUPCL) {
+                               /* drop DTR and RTS */
+                               priv = usb_get_serial_port_data(port);
+                               spin_lock_irqsave(&priv->lock, flags);
+                               priv->line_control = 0;
+                               spin_unlock_irqrestore(&priv->lock, flags);
+                               set_control_lines(port->serial->dev, 0);
+                       }
+               }
+               /* free writebuf */
+               /* shutdown our urbs */
+               dbg("%s - shutting down urbs", __FUNCTION__);
+               usb_kill_urb(port->write_urb);
+               usb_kill_urb(port->read_urb);
+               usb_kill_urb(port->interrupt_in_urb);
+               msleep(1000);
+               /* wait one second to free all buffers */
+               iuu_led(port, 0, 0, 0xF000, 0xFF);
+               msleep(1000);
+               usb_reset_device(port->serial->dev);
+       }
+}
+
+static int iuu_open(struct usb_serial_port *port, struct file *filp)
+{
+       struct usb_serial *serial = port->serial;
+       u8 *buf;
+       int result;
+       u32 actual;
+       unsigned long flags;
+       struct iuu_private *priv = usb_get_serial_port_data(port);
+
+       dbg("%s -  port %d", __FUNCTION__, port->number);
+       usb_clear_halt(serial->dev, port->write_urb->pipe);
+       usb_clear_halt(serial->dev, port->read_urb->pipe);
+
+       buf = kmalloc(10, GFP_KERNEL);
+       if (buf == NULL)
+               return -ENOMEM;
+
+       /* fixup the endpoint buffer size */
+       kfree(port->bulk_out_buffer);
+       port->bulk_out_buffer = kmalloc(512, GFP_KERNEL);
+       port->bulk_out_size = 512;
+       kfree(port->bulk_in_buffer);
+       port->bulk_in_buffer = kmalloc(512, GFP_KERNEL);
+       port->bulk_in_size = 512;
+
+       if (!port->bulk_out_buffer || !port->bulk_in_buffer) {
+               kfree(port->bulk_out_buffer);
+               kfree(port->bulk_in_buffer);
+               kfree(buf);
+               return -ENOMEM;
+       }
+
+       usb_fill_bulk_urb(port->write_urb, port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->bulk_out_buffer, 512,
+                         NULL, NULL);
+
+
+       usb_fill_bulk_urb(port->read_urb, port->serial->dev,
+                         usb_rcvbulkpipe(port->serial->dev,
+                                         port->bulk_in_endpointAddress),
+                         port->bulk_in_buffer, 512,
+                         NULL, NULL);
+
+       /* set the termios structure */
+       spin_lock_irqsave(&priv->lock, flags);
+       if (!priv->termios_initialized) {
+               *(port->tty->termios) = tty_std_termios;
+               port->tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
+                                               | TIOCM_CTS | CSTOPB | PARENB;
+               port->tty->termios->c_lflag = 0;
+               port->tty->termios->c_oflag = 0;
+               port->tty->termios->c_iflag = 0;
+               priv->termios_initialized = 1;
+               port->tty->low_latency = 1;
+               priv->poll = 0;
+        }
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       /* initialize writebuf */
+#define FISH(a, b, c, d) do { \
+       result = usb_control_msg(port->serial->dev,     \
+                               usb_rcvctrlpipe(port->serial->dev, 0),  \
+                               b, a, c, d, buf, 1, 1000); \
+       dbg("0x%x:0x%x:0x%x:0x%x  %d - %x", a, b, c, d, result, \
+                               buf[0]); } while (0);
+
+#define SOUP(a, b, c, d)  do { \
+       result = usb_control_msg(port->serial->dev,     \
+                               usb_sndctrlpipe(port->serial->dev, 0),  \
+                               b, a, c, d, NULL, 0, 1000); \
+       dbg("0x%x:0x%x:0x%x:0x%x  %d", a, b, c, d, result); } while (0)
+
+       /*  This is not UART related but IUU USB driver related or something */
+       /*  like that. Basically no IUU will accept any commands from the USB */
+       /*  host unless it has received the following message */
+       /* sprintf(buf ,"%c%c%c%c",0x03,0x02,0x02,0x0); */
+
+       SOUP(0x03, 0x02, 0x02, 0x0);
+       kfree(buf);
+       iuu_led(port, 0xF000, 0xF000, 0, 0xFF);
+       iuu_uart_on(port);
+       if (boost < 100)
+               boost = 100;
+       switch (clockmode) {
+       case 2:         /*  3.680 Mhz */
+               iuu_clk(port, IUU_CLK_3680000 * boost / 100);
+               result =
+                   iuu_uart_baud(port, 9600 * boost / 100, &actual,
+                                 IUU_PARITY_EVEN);
+               break;
+       case 3:         /*  6.00 Mhz */
+               iuu_clk(port, IUU_CLK_6000000 * boost / 100);
+               result =
+                   iuu_uart_baud(port, 16457 * boost / 100, &actual,
+                                 IUU_PARITY_EVEN);
+               break;
+       default:                /*  3.579 Mhz */
+               iuu_clk(port, IUU_CLK_3579000 * boost / 100);
+               result =
+                   iuu_uart_baud(port, 9600 * boost / 100, &actual,
+                                 IUU_PARITY_EVEN);
+       }
+
+       /* set the cardin cardout signals */
+       switch (cdmode) {
+       case 0:
+               iuu_cardin = 0;
+               iuu_cardout = 0;
+               break;
+       case 1:
+               iuu_cardin = TIOCM_CD;
+               iuu_cardout =  0;
+               break;
+       case 2:
+               iuu_cardin = 0;
+               iuu_cardout = TIOCM_CD;
+               break;
+       case 3:
+               iuu_cardin = TIOCM_DSR;
+               iuu_cardout = 0;
+               break;
+       case 4:
+               iuu_cardin = 0;
+               iuu_cardout = TIOCM_DSR;
+               break;
+       case 5:
+               iuu_cardin = TIOCM_CTS;
+               iuu_cardout = 0;
+               break;
+       case 6:
+               iuu_cardin = 0;
+               iuu_cardout = TIOCM_CTS;
+               break;
+       case 7:
+               iuu_cardin = TIOCM_RNG;
+               iuu_cardout = 0;
+               break;
+       case 8:
+               iuu_cardin = 0;
+               iuu_cardout = TIOCM_RNG;
+       }
+
+       iuu_uart_flush(port);
+
+       dbg("%s - initialization done", __FUNCTION__);
+
+       memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1);
+       usb_fill_bulk_urb(port->write_urb, port->serial->dev,
+                         usb_sndbulkpipe(port->serial->dev,
+                                         port->bulk_out_endpointAddress),
+                         port->write_urb->transfer_buffer, 1,
+                         read_rxcmd_callback, port);
+       result = usb_submit_urb(port->write_urb, GFP_KERNEL);
+
+       if (result) {
+               dev_err(&port->dev, "%s - failed submitting read urb,"
+                       " error %d\n", __FUNCTION__, result);
+               iuu_close(port, NULL);
+               return -EPROTO;
+       } else {
+               dbg("%s - rxcmd OK", __FUNCTION__);
+       }
+       return result;
+}
+
+static struct usb_serial_driver iuu_device = {
+       .driver = {
+                  .owner = THIS_MODULE,
+                  .name = "iuu_phoenix",
+                  },
+       .id_table = id_table,
+       .num_interrupt_in = NUM_DONT_CARE,
+       .num_bulk_in = 1,
+       .num_bulk_out = 1,
+       .num_ports = 1,
+       .open = iuu_open,
+       .close = iuu_close,
+       .write = iuu_uart_write,
+       .read_bulk_callback = iuu_uart_read_callback,
+       .tiocmget = iuu_tiocmget,
+       .tiocmset = iuu_tiocmset,
+       .attach = iuu_startup,
+       .shutdown = iuu_shutdown,
+};
+
+static int __init iuu_init(void)
+{
+       int retval;
+       retval = usb_serial_register(&iuu_device);
+       if (retval)
+               goto failed_usb_serial_register;
+       retval = usb_register(&iuu_driver);
+       if (retval)
+               goto failed_usb_register;
+       info(DRIVER_DESC " " DRIVER_VERSION);
+       return 0;
+failed_usb_register:
+       usb_serial_deregister(&iuu_device);
+failed_usb_serial_register:
+       return retval;
+}
+
+static void __exit iuu_exit(void)
+{
+       usb_deregister(&iuu_driver);
+       usb_serial_deregister(&iuu_device);
+}
+
+module_init(iuu_init);
+module_exit(iuu_exit);
+
+MODULE_AUTHOR("Alain Degreffe eczema@ecze.com");
+
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+
+MODULE_VERSION(DRIVER_VERSION);
+module_param(debug, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(debug, "Debug enabled or not");
+
+module_param(xmas, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(xmas, "xmas color enabled or not");
+
+module_param(boost, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(boost, "overclock boost percent 100 to 500");
+
+module_param(clockmode, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(clockmode, "1=3Mhz579,2=3Mhz680,3=6Mhz");
+
+module_param(cdmode, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(cdmode, "Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, "
+                "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING");
diff --git a/drivers/usb/serial/iuu_phoenix.h b/drivers/usb/serial/iuu_phoenix.h
new file mode 100644 (file)
index 0000000..b82630a
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Infinity Unlimited USB Phoenix driver
+ *
+ * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com)
+ *
+ *
+ * Original code taken from iuutool ( Copyright (C) 2006 Juan Carlos Borrás )
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *  And tested with help of WB Electronics
+ *
+ */
+
+#define   IUU_USB_VENDOR_ID  0x104f
+#define   IUU_USB_PRODUCT_ID  0x0004
+#define   IUU_USB_OP_TIMEOUT  0x0200
+
+/* Programmer commands */
+
+#define IUU_NO_OPERATION   0x00
+#define IUU_GET_FIRMWARE_VERSION   0x01
+#define IUU_GET_PRODUCT_NAME   0x02
+#define IUU_GET_STATE_REGISTER   0x03
+#define IUU_SET_LED   0x04
+#define IUU_WAIT_MUS   0x05
+#define IUU_WAIT_MS   0x06
+#define IUU_GET_LOADER_VERSION   0x50
+#define IUU_RST_SET   0x52
+#define IUU_RST_CLEAR   0x53
+#define IUU_SET_VCC   0x59
+#define IUU_UART_ENABLE   0x49
+#define IUU_UART_DISABLE   0x4A
+#define IUU_UART_WRITE_I2C   0x4C
+#define IUU_UART_ESC   0x5E
+#define IUU_UART_TRAP   0x54
+#define IUU_UART_TRAP_BREAK   0x5B
+#define IUU_UART_RX   0x56
+#define IUU_AVR_ON   0x21
+#define IUU_AVR_OFF   0x22
+#define IUU_AVR_1CLK   0x23
+#define IUU_AVR_RESET   0x24
+#define IUU_AVR_RESET_PC   0x25
+#define IUU_AVR_INC_PC   0x26
+#define IUU_AVR_INCN_PC   0x27
+#define IUU_AVR_PREAD   0x29
+#define IUU_AVR_PREADN   0x2A
+#define IUU_AVR_PWRITE   0x28
+#define IUU_AVR_DREAD   0x2C
+#define IUU_AVR_DREADN   0x2D
+#define IUU_AVR_DWRITE   0x2B
+#define IUU_AVR_PWRITEN   0x2E
+#define IUU_EEPROM_ON   0x37
+#define IUU_EEPROM_OFF   0x38
+#define IUU_EEPROM_WRITE   0x39
+#define IUU_EEPROM_WRITEX   0x3A
+#define IUU_EEPROM_WRITE8   0x3B
+#define IUU_EEPROM_WRITE16   0x3C
+#define IUU_EEPROM_WRITEX32   0x3D
+#define IUU_EEPROM_WRITEX64   0x3E
+#define IUU_EEPROM_READ   0x3F
+#define IUU_EEPROM_READX   0x40
+#define IUU_EEPROM_BREAD   0x41
+#define IUU_EEPROM_BREADX   0x42
+#define IUU_PIC_CMD   0x0A
+#define IUU_PIC_CMD_LOAD   0x0B
+#define IUU_PIC_CMD_READ   0x0C
+#define IUU_PIC_ON   0x0D
+#define IUU_PIC_OFF   0x0E
+#define IUU_PIC_RESET   0x16
+#define IUU_PIC_INC_PC   0x0F
+#define IUU_PIC_INCN_PC   0x10
+#define IUU_PIC_PWRITE   0x11
+#define IUU_PIC_PREAD   0x12
+#define IUU_PIC_PREADN   0x13
+#define IUU_PIC_DWRITE   0x14
+#define IUU_PIC_DREAD   0x15
+#define IUU_UART_NOP   0x00
+#define IUU_UART_CHANGE   0x02
+#define IUU_UART_TX   0x04
+#define IUU_DELAY_MS   0x06
+
+#define IUU_OPERATION_OK   0x00
+#define IUU_DEVICE_NOT_FOUND   0x01
+#define IUU_INVALID_HANDLE   0x02
+#define IUU_INVALID_PARAMETER   0x03
+#define IUU_INVALID_voidERFACE   0x04
+#define IUU_INVALID_REQUEST_LENGTH   0x05
+#define IUU_UART_NOT_ENABLED   0x06
+#define IUU_WRITE_ERROR   0x07
+#define IUU_READ_ERROR   0x08
+#define IUU_TX_ERROR   0x09
+#define IUU_RX_ERROR   0x0A
+
+#define IUU_PARITY_NONE   0x00
+#define IUU_PARITY_EVEN   0x01
+#define IUU_PARITY_ODD   0x02
+#define IUU_PARITY_MARK   0x03
+#define IUU_PARITY_SPACE   0x04
+#define IUU_SC_INSERTED   0x01
+#define IUU_VERIFY_ERROR   0x02
+#define IUU_SIM_INSERTED   0x04
+#define IUU_TWO_STOP_BITS   0x00
+#define IUU_ONE_STOP_BIT   0x20
+#define IUU_BAUD_2400   0x0398
+#define IUU_BAUD_9600   0x0298
+#define IUU_BAUD_19200   0x0164
+#define IUU_BAUD_28800   0x0198
+#define IUU_BAUD_38400   0x01B2
+#define IUU_BAUD_57600   0x0030
+#define IUU_BAUD_115200   0x0098
+#define IUU_CLK_3579000   3579000
+#define IUU_CLK_3680000   3680000
+#define IUU_CLK_6000000   6000000
+#define IUU_FULLCARD_IN   0x01
+#define IUU_DEV_ERROR   0x02
+#define IUU_MINICARD_IN   0x04
+#define IUU_VCC_5V   0x00
+#define IUU_VCC_3V   0x01
index 7c069a02c1dd40817d93b58dffed4217bd740ff2..ea7bba69f4da129397e111463a0ec13995d0ac5a 100644 (file)
@@ -838,7 +838,7 @@ static void usa49_indat_callback(struct urb *urb)
 
        port = (struct usb_serial_port *) urb->context;
        tty = port->tty;
-       if (urb->actual_length) {
+       if (tty && urb->actual_length) {
                /* 0x80 bit is error flag */
                if ((data[0] & 0x80) == 0) {
                        /* no error on any byte */
index be9ac20a8f10b3adeb456192f84246da79206419..b1fa5a376e96798fc6871b6a47e93c7bed2378a9 100644 (file)
@@ -303,7 +303,7 @@ static void keyspan_pda_rx_unthrottle (struct usb_serial_port *port)
 }
 
 
-static int keyspan_pda_setbaud (struct usb_serial *serial, int baud)
+static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud)
 {
        int rc;
        int bindex;
@@ -319,7 +319,9 @@ static int keyspan_pda_setbaud (struct usb_serial *serial, int baud)
                case 38400: bindex = 7; break;
                case 57600: bindex = 8; break;
                case 115200: bindex = 9; break;
-               default: return -EINVAL;
+               default:
+                       bindex = 5;     /* Default to 9600 */
+                       baud = 9600;
        }
 
        /* rather than figure out how to sleep while waiting for this
@@ -334,7 +336,9 @@ static int keyspan_pda_setbaud (struct usb_serial *serial, int baud)
                             NULL, /* &data */
                             0, /* size */
                             2000); /* timeout */
-       return(rc);
+       if (rc < 0)
+               return 0;
+       return baud;
 }
 
 
@@ -366,7 +370,7 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
                                     struct ktermios *old_termios)
 {
        struct usb_serial *serial = port->serial;
-       unsigned int cflag = port->tty->termios->c_cflag;
+       speed_t speed;
 
        /* cflag specifies lots of stuff: number of stop bits, parity, number
           of data bits, baud. What can the device actually handle?:
@@ -388,22 +392,18 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
 
           For now, just do baud. */
 
-       switch (cflag & CBAUD) {
-               /* we could support more values here, just need to calculate
-                  the necessary divisors in the firmware. <asm/termbits.h>
-                  has the Bnnn constants. */
-               case B110: keyspan_pda_setbaud(serial, 110); break;
-               case B300: keyspan_pda_setbaud(serial, 300); break;
-               case B1200: keyspan_pda_setbaud(serial, 1200); break;
-               case B2400: keyspan_pda_setbaud(serial, 2400); break;
-               case B4800: keyspan_pda_setbaud(serial, 4800); break;
-               case B9600: keyspan_pda_setbaud(serial, 9600); break;
-               case B19200: keyspan_pda_setbaud(serial, 19200); break;
-               case B38400: keyspan_pda_setbaud(serial, 38400); break;
-               case B57600: keyspan_pda_setbaud(serial, 57600); break;
-               case B115200: keyspan_pda_setbaud(serial, 115200); break;
-               default: dbg("can't handle requested baud rate"); break;
+       speed = tty_get_baud_rate(port->tty);
+       speed = keyspan_pda_setbaud(serial, speed);
+
+       if (speed == 0) {
+               dbg("can't handle requested baud rate");
+               /* It hasn't changed so.. */
+               speed = tty_termios_baud_rate(old_termios);
        }
+       /* Only speed can change so copy the old h/w parameters
+          then encode the new speed */
+       tty_termios_copy_hw(port->tty->termios, old_termios);
+       tty_encode_baud_rate(port->tty, speed, speed);
 }
 
 
index 90e3216abd1f006800f0d2ed018a83c12a9b5cc0..55736df7d2f4ed0232d2c33700d353a47336cafe 100644 (file)
@@ -461,17 +461,21 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
 
        dbg("%s port %d", __FUNCTION__, port->number);
 
-       /* send READ_OFF */
-       rc = usb_control_msg (port->serial->dev,
-                             usb_sndctrlpipe(port->serial->dev, 0),
-                             KL5KUSB105A_SIO_CONFIGURE,
-                             USB_TYPE_VENDOR | USB_DIR_OUT,
-                             KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
-                             0, /* index */
-                             NULL, 0,
-                             KLSI_TIMEOUT);
-       if (rc < 0)
-                   err("Disabling read failed (error = %d)", rc);
+       mutex_lock(&port->serial->disc_mutex);
+       if (!port->serial->disconnected) {
+               /* send READ_OFF */
+               rc = usb_control_msg (port->serial->dev,
+                                     usb_sndctrlpipe(port->serial->dev, 0),
+                                     KL5KUSB105A_SIO_CONFIGURE,
+                                     USB_TYPE_VENDOR | USB_DIR_OUT,
+                                     KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
+                                     0, /* index */
+                                     NULL, 0,
+                                     KLSI_TIMEOUT);
+               if (rc < 0)
+                       err("Disabling read failed (error = %d)", rc);
+       }
+       mutex_unlock(&port->serial->disc_mutex);
 
        /* shutdown our bulk reads and writes */
        usb_kill_urb(port->write_urb);
index aee450246bfd8b0befa879ca9613415ad649d577..17b3baead4adec5acf81f4e9955d1c97f3bc59f0 100644 (file)
@@ -114,6 +114,7 @@ static struct usb_serial_driver kobil_device = {
        .usb_driver =           &kobil_driver,
        .id_table =             id_table,
        .num_interrupt_in =     NUM_DONT_CARE,
+       .num_interrupt_out =    NUM_DONT_CARE,
        .num_bulk_in =          0,
        .num_bulk_out =         0,
        .num_ports =            1,
index 0dc99f75bb09d13ab67072e4703c81a80894eb21..fc1cea4aba13979ff48ea6fbdd371787fc1cea5e 100644 (file)
@@ -182,10 +182,11 @@ struct mct_u232_private {
 /*
  * Later day 2.6.0-test kernels have new baud rates like B230400 which
  * we do not know how to support. We ignore them for the moment.
- * XXX Rate-limit the error message, it's user triggerable.
  */
-static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value)
+static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result)
 {
+       *result = value;
+
        if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
          || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
                switch (value) {
@@ -200,11 +201,13 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
                case  57600: return 0x0b;
                case 115200: return 0x0c;
                default:
-                       err("MCT USB-RS232: unsupported baudrate request 0x%x,"
-                           " using default of B9600", value);
+                       *result = 9600;
                        return 0x08;
                }
        } else {
+               /* FIXME: Can we use any divider - should we do
+                  divider = 115200/value;
+                  real baud = 115200/divider */
                switch (value) {
                case 300: break;
                case 600: break;
@@ -217,9 +220,8 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
                case 57600: break;
                case 115200: break;
                default:
-                       err("MCT USB-RS232: unsupported baudrate request 0x%x,"
-                           " using default of B9600", value);
                        value = 9600;
+                       *result = 9600;
                }
                return 115200/value;
        }
@@ -232,16 +234,19 @@ static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_p
         int rc;
         unsigned char zero_byte = 0;
         unsigned char cts_enable_byte = 0;
+        speed_t speed;
 
-       divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value));
+       divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, &speed));
 
         rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
                              MCT_U232_SET_BAUD_RATE_REQUEST,
                             MCT_U232_SET_REQUEST_TYPE,
                              0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE,
                             WDR_TIMEOUT);
-       if (rc < 0)
+       if (rc < 0)     /*FIXME: What value speed results */
                err("Set BAUD RATE %d failed (error = %d)", value, rc);
+       else
+               tty_encode_baud_rate(port->tty, speed, speed);
        dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
 
        /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
@@ -482,21 +487,22 @@ error:
 static void mct_u232_close (struct usb_serial_port *port, struct file *filp)
 {
        unsigned int c_cflag;
-       unsigned long flags;
        unsigned int control_state;
        struct mct_u232_private *priv = usb_get_serial_port_data(port);
        dbg("%s port %d", __FUNCTION__, port->number);
 
        if (port->tty) {
                c_cflag = port->tty->termios->c_cflag;
-               if (c_cflag & HUPCL) {
-                  /* drop DTR and RTS */
-                  spin_lock_irqsave(&priv->lock, flags);
-                  priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
-                  control_state = priv->control_state;
-                  spin_unlock_irqrestore(&priv->lock, flags);
-                  mct_u232_set_modem_ctrl(port->serial, control_state);
+               mutex_lock(&port->serial->disc_mutex);
+               if (c_cflag & HUPCL && !port->serial->disconnected) {
+                       /* drop DTR and RTS */
+                       spin_lock_irq(&priv->lock);
+                       priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
+                       control_state = priv->control_state;
+                       spin_unlock_irq(&priv->lock);
+                       mct_u232_set_modem_ctrl(port->serial, control_state);
                }
+               mutex_unlock(&port->serial->disc_mutex);
        }
 
 
@@ -608,7 +614,8 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
 {
        struct usb_serial *serial = port->serial;
        struct mct_u232_private *priv = usb_get_serial_port_data(port);
-       unsigned int cflag = port->tty->termios->c_cflag;
+       struct ktermios *termios = port->tty->termios;
+       unsigned int cflag = termios->c_cflag;
        unsigned int old_cflag = old_termios->c_cflag;
        unsigned long flags;
        unsigned int control_state;
@@ -670,6 +677,8 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
                break;
        }
 
+       termios->c_cflag &= ~CMSPAR;
+
        /* set the number of stop bits */
        last_lcr |= (cflag & CSTOPB) ?
                MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
index aae10c8174d6bb0fd51abd7fb397999bce64f237..07b6bec31dc898a2e6f9fcccc5ff1ab654b328c6 100644 (file)
@@ -79,7 +79,7 @@
  * and "Intel solution". They are the regular MCT and "Sitecom" for us.
  * This is pointless to document in the header, see the code for the bits.
  */
-static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value);
+static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result);
 
 /*
  * Line Control Register (LCR)
index e02c198016b02204ee5ef92c43850356e99d9264..40f3a0188807d95c7e69a7a23001133678dbd9d1 100644 (file)
@@ -564,22 +564,25 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
        }
 
        /* While closing port, shutdown all bulk read, write  *
-        * and interrupt read if they exists                  */
-       if (serial->dev) {
-               dbg("Shutdown bulk write");
-               usb_kill_urb(port->write_urb);
-               dbg("Shutdown bulk read");
-               usb_kill_urb(port->read_urb);
+        * and interrupt read if they exists, otherwise nop   */
+       dbg("Shutdown bulk write");
+       usb_kill_urb(port->write_urb);
+       dbg("Shutdown bulk read");
+       usb_kill_urb(port->read_urb);
+
+       mutex_lock(&serial->disc_mutex);
+       /* these commands must not be issued if the device has
+        * been disconnected */
+       if (!serial->disconnected) {
+               data = 0x00;
+               send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
+                            0x04, &data);
+
+               data = 0x00;
+               send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
+                            0x01, &data);
        }
-
-       data = 0x00;
-       send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
-                    0x04, &data);
-
-       data = 0x00;
-       send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
-                    0x01, &data);
-
+       mutex_unlock(&serial->disc_mutex);
        mos7720_port->open = 0;
 
        dbg("Leaving %s", __FUNCTION__);
@@ -1040,11 +1043,6 @@ static void change_port_settings(struct moschip_port *mos7720_port,
 
        tty = mos7720_port->port->tty;
 
-       if ((!tty) || (!tty->termios)) {
-               dbg("%s - no tty structures", __FUNCTION__);
-               return;
-       }
-
        dbg("%s: Entering ..........", __FUNCTION__);
 
        lData = UART_LCR_WLEN8;
@@ -1175,7 +1173,10 @@ static void change_port_settings(struct moschip_port *mos7720_port,
 
        dbg("%s - baud rate = %d", __FUNCTION__, baud);
        status = send_cmd_write_baud_rate(mos7720_port, baud);
-
+       /* FIXME: needs to write actual resulting baud back not just
+          blindly do so */
+       if (cflag & CBAUD)
+               tty_encode_baud_rate(tty, baud, baud);
        /* Enable Interrupts */
        data = 0x0c;
        send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
@@ -1214,10 +1215,6 @@ static void mos7720_set_termios(struct usb_serial_port *port,
 
        tty = port->tty;
 
-       if (!port->tty || !port->tty->termios) {
-               dbg("%s - no tty or termios", __FUNCTION__);
-               return;
-       }
 
        if (!mos7720_port->open) {
                dbg("%s - port not opened", __FUNCTION__);
@@ -1228,19 +1225,13 @@ static void mos7720_set_termios(struct usb_serial_port *port,
 
        cflag = tty->termios->c_cflag;
 
-       if (!cflag) {
-               printk("%s %s\n",__FUNCTION__,"cflag is NULL");
-               return;
-       }
-
-       dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
+       dbg("%s - cflag %08x iflag %08x", __FUNCTION__,
            tty->termios->c_cflag,
            RELEVANT_IFLAG(tty->termios->c_iflag));
 
-       if (old_termios)
-               dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
-                   old_termios->c_cflag,
-                   RELEVANT_IFLAG(old_termios->c_iflag));
+       dbg("%s - old cflag %08x old iflag %08x", __FUNCTION__,
+           old_termios->c_cflag,
+           RELEVANT_IFLAG(old_termios->c_iflag));
 
        dbg("%s - port %d", __FUNCTION__, port->number);
 
index c29c91271133584bdc9369f40c3cfd1817ac154a..869ecd374cb49e8161b765d23791604c3aff6256 100644 (file)
@@ -1133,7 +1133,7 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
  *     This function will block the close until one of the following:
  *             1. TX count are 0
  *             2. The mos7840 has stopped
- *             3. A timout of 3 seconds without activity has expired
+ *             3. A timeout of 3 seconds without activity has expired
  *
  ************************************************************************/
 static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
@@ -1161,7 +1161,7 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
                        dbg("%s - TIMEOUT", __FUNCTION__);
                        return;
                } else {
-                       /* Reset timout value back to seconds */
+                       /* Reset timeout value back to seconds */
                        wait = 30;
                }
        }
@@ -1275,7 +1275,7 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
  *
  *     This function will block the close until one of the following:
  *             1. Response to our Chase comes from mos7840
- *             2. A timout of 10 seconds without activity has expired
+ *             2. A timeout of 10 seconds without activity has expired
  *                (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
  *
  ************************************************************************/
@@ -1304,7 +1304,7 @@ static void mos7840_block_until_chase_response(struct moschip_port
                        dbg("%s - TIMEOUT", __FUNCTION__);
                        return;
                } else {
-                       /* Reset timout value back to seconds */
+                       /* Reset timeout value back to seconds */
                        wait = 10;
                }
        }
index d1185f53447b3f0b915807376dc99867509e755c..5e8bf1bc1e50577fb6231e8088b63fdda307994c 100644 (file)
@@ -180,6 +180,7 @@ static struct usb_device_id option_ids[] = {
        { USB_DEVICE(DELL_VENDOR_ID, 0x8117) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO ExpressCard == Novatel Merlin XV620 CDMA/EV-DO */
        { USB_DEVICE(DELL_VENDOR_ID, 0x8118) }, /* Dell Wireless 5510 Mobile Broadband HSDPA ExpressCard == Novatel Merlin XU870 HSDPA/3G */
        { USB_DEVICE(DELL_VENDOR_ID, 0x8128) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO Mini-Card == Novatel Expedite E720 CDMA/EV-DO */
+       { USB_DEVICE(DELL_VENDOR_ID, 0x8136) }, /* Dell Wireless HSDPA 5520 == Novatel Expedite EU860D */
        { USB_DEVICE(DELL_VENDOR_ID, 0x8137) }, /* Dell Wireless HSDPA 5520 */
        { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_E100A) },
        { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_500A) },
@@ -640,7 +641,10 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
        portdata->dtr_state = 0;
 
        if (serial->dev) {
-               option_send_setup(port);
+               mutex_lock(&serial->disc_mutex);
+               if (!serial->disconnected)
+                       option_send_setup(port);
+               mutex_unlock(&serial->disc_mutex);
 
                /* Stop reading/writing urbs */
                for (i = 0; i < N_IN_URB; i++)
index eea226ae37bd15bacf66e4057ce54b8152256469..a3847d6c946eac309fe899b8698cdb34bbe29276 100644 (file)
@@ -79,7 +79,7 @@ static int debug;
 #define PL2303_BUF_SIZE                1024
 #define PL2303_TMP_BUF_SIZE    1024
 
-struct pl2303_buf {
+struct oti6858_buf {
        unsigned int    buf_size;
        char            *buf_buf;
        char            *buf_get;
@@ -161,14 +161,14 @@ static int oti6858_startup(struct usb_serial *serial);
 static void oti6858_shutdown(struct usb_serial *serial);
 
 /* functions operating on buffers */
-static struct pl2303_buf *pl2303_buf_alloc(unsigned int size);
-static void pl2303_buf_free(struct pl2303_buf *pb);
-static void pl2303_buf_clear(struct pl2303_buf *pb);
-static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb);
-static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb);
-static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
+static struct oti6858_buf *oti6858_buf_alloc(unsigned int size);
+static void oti6858_buf_free(struct oti6858_buf *pb);
+static void oti6858_buf_clear(struct oti6858_buf *pb);
+static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb);
+static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb);
+static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
                                        unsigned int count);
-static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
+static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
                                        unsigned int count);
 
 
@@ -203,7 +203,7 @@ static struct usb_serial_driver oti6858_device = {
 struct oti6858_private {
        spinlock_t lock;
 
-       struct pl2303_buf *buf;
+       struct oti6858_buf *buf;
        struct oti6858_control_pkt status;
 
        struct {
@@ -316,7 +316,7 @@ void send_data(struct work_struct *work)
        }
        priv->flags.write_urb_in_use = 1;
 
-       count = pl2303_buf_data_avail(priv->buf);
+       count = oti6858_buf_data_avail(priv->buf);
        spin_unlock_irqrestore(&priv->lock, flags);
        if (count > port->bulk_out_size)
                count = port->bulk_out_size;
@@ -345,7 +345,7 @@ void send_data(struct work_struct *work)
        }
 
        spin_lock_irqsave(&priv->lock, flags);
-       pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, count);
+       oti6858_buf_get(priv->buf, port->write_urb->transfer_buffer, count);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        port->write_urb->transfer_buffer_length = count;
@@ -370,7 +370,7 @@ static int oti6858_startup(struct usb_serial *serial)
                priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL);
                if (!priv)
                        break;
-               priv->buf = pl2303_buf_alloc(PL2303_BUF_SIZE);
+               priv->buf = oti6858_buf_alloc(PL2303_BUF_SIZE);
                if (priv->buf == NULL) {
                        kfree(priv);
                        break;
@@ -391,7 +391,7 @@ static int oti6858_startup(struct usb_serial *serial)
 
        for (--i; i >= 0; --i) {
                priv = usb_get_serial_port_data(serial->port[i]);
-               pl2303_buf_free(priv->buf);
+               oti6858_buf_free(priv->buf);
                kfree(priv);
                usb_set_serial_port_data(serial->port[i], NULL);
        }
@@ -410,7 +410,7 @@ static int oti6858_write(struct usb_serial_port *port,
                return count;
 
        spin_lock_irqsave(&priv->lock, flags);
-       count = pl2303_buf_put(priv->buf, buf, count);
+       count = oti6858_buf_put(priv->buf, buf, count);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return count;
@@ -425,7 +425,7 @@ static int oti6858_write_room(struct usb_serial_port *port)
        dbg("%s(port = %d)", __FUNCTION__, port->number);
 
        spin_lock_irqsave(&priv->lock, flags);
-       room = pl2303_buf_space_avail(priv->buf);
+       room = oti6858_buf_space_avail(priv->buf);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return room;
@@ -440,7 +440,7 @@ static int oti6858_chars_in_buffer(struct usb_serial_port *port)
        dbg("%s(port = %d)", __FUNCTION__, port->number);
 
        spin_lock_irqsave(&priv->lock, flags);
-       chars = pl2303_buf_data_avail(priv->buf);
+       chars = oti6858_buf_data_avail(priv->buf);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return chars;
@@ -458,7 +458,7 @@ static void oti6858_set_termios(struct usb_serial_port *port,
 
        dbg("%s(port = %d)", __FUNCTION__, port->number);
 
-       if ((!port->tty) || (!port->tty->termios)) {
+       if (!port->tty || !port->tty->termios) {
                dbg("%s(): no tty structures", __FUNCTION__);
                return;
        }
@@ -468,6 +468,8 @@ static void oti6858_set_termios(struct usb_serial_port *port,
                *(port->tty->termios) = tty_std_termios;
                port->tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL;
                priv->flags.termios_initialized = 1;
+               port->tty->termios->c_ispeed = 38400;
+               port->tty->termios->c_ospeed = 38400;
        }
        spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -504,19 +506,14 @@ static void oti6858_set_termios(struct usb_serial_port *port,
        br = tty_get_baud_rate(port->tty);
        if (br == 0) {
                divisor = 0;
-       } else if (br <= OTI6858_MAX_BAUD_RATE) {
+       } else {
                int real_br;
+               br = min(br, OTI6858_MAX_BAUD_RATE);
 
                divisor = (96000000 + 8 * br) / (16 * br);
                real_br = 96000000 / (16 * divisor);
-               if ((((real_br - br) * 100 + br - 1) / br) > 2) {
-                       dbg("%s(): baud rate %d is invalid", __FUNCTION__, br);
-                       return;
-               }
                divisor = cpu_to_le16(divisor);
-       } else {
-               dbg("%s(): baud rate %d is too high", __FUNCTION__, br);
-               return;
+               tty_encode_baud_rate(port->tty, real_br, real_br);
        }
 
        frame_fmt &= ~FMT_STOP_BITS_MASK;
@@ -650,9 +647,9 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
        dbg("%s(): entering wait loop", __FUNCTION__);
        for (;;) {
                set_current_state(TASK_INTERRUPTIBLE);
-               if (pl2303_buf_data_avail(priv->buf) == 0
+               if (oti6858_buf_data_avail(priv->buf) == 0
                || timeout == 0 || signal_pending(current)
-               || !usb_get_intfdata(port->serial->interface))  /* disconnect */
+               || port->serial->disconnected)
                        break;
                spin_unlock_irqrestore(&priv->lock, flags);
                timeout = schedule_timeout(timeout);
@@ -663,7 +660,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
        dbg("%s(): after wait loop", __FUNCTION__);
 
        /* clear out any remaining data in the buffer */
-       pl2303_buf_clear(priv->buf);
+       oti6858_buf_clear(priv->buf);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        /* wait for characters to drain from the device */
@@ -831,21 +828,6 @@ static int oti6858_ioctl(struct usb_serial_port *port, struct file *file,
                                return -EFAULT;
                        return oti6858_tiocmset(port, NULL, 0, x);
 
-               case TIOCGSERIAL:
-                       if (copy_to_user(user_arg, port->tty->termios,
-                                               sizeof(struct ktermios))) {
-                               return -EFAULT;
-                       }
-                        return 0;
-
-               case TIOCSSERIAL:
-                       if (copy_from_user(port->tty->termios, user_arg,
-                                               sizeof(struct ktermios))) {
-                               return -EFAULT;
-                       }
-                       oti6858_set_termios(port, NULL);
-                       return 0;
-
                case TIOCMIWAIT:
                        dbg("%s(): TIOCMIWAIT", __FUNCTION__);
                        return wait_modem_info(port, arg);
@@ -887,7 +869,7 @@ static void oti6858_shutdown(struct usb_serial *serial)
        for (i = 0; i < serial->num_ports; ++i) {
                priv = usb_get_serial_port_data(serial->port[i]);
                if (priv) {
-                       pl2303_buf_free(priv->buf);
+                       oti6858_buf_free(priv->buf);
                        kfree(priv);
                        usb_set_serial_port_data(serial->port[i], NULL);
                }
@@ -987,7 +969,7 @@ static void oti6858_read_int_callback(struct urb *urb)
 
                spin_lock_irqsave(&priv->lock, flags);
                if (priv->flags.write_urb_in_use == 0
-                               && pl2303_buf_data_avail(priv->buf) != 0) {
+                               && oti6858_buf_data_avail(priv->buf) != 0) {
                        schedule_delayed_work(&priv->delayed_write_work,0);
                        resubmit = 0;
                }
@@ -1015,9 +997,8 @@ static void oti6858_read_bulk_callback(struct urb *urb)
        struct tty_struct *tty;
        unsigned char *data = urb->transfer_buffer;
        unsigned long flags;
-       int i, result;
        int status = urb->status;
-       char tty_flag;
+       int result;
 
        dbg("%s(port = %d, status = %d)",
                                __FUNCTION__, port->number, status);
@@ -1045,27 +1026,9 @@ static void oti6858_read_bulk_callback(struct urb *urb)
                return;
        }
 
-       // get tty_flag from status
-       tty_flag = TTY_NORMAL;
-
-/* FIXME: probably, errors will be signalled using interrupt pipe! */
-/*
-       // break takes precedence over parity,
-       // which takes precedence over framing errors
-       if (status & UART_BREAK_ERROR )
-               tty_flag = TTY_BREAK;
-       else if (status & UART_PARITY_ERROR)
-               tty_flag = TTY_PARITY;
-       else if (status & UART_FRAME_ERROR)
-               tty_flag = TTY_FRAME;
-       dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag);
-*/
-
        tty = port->tty;
        if (tty != NULL && urb->actual_length > 0) {
-               tty_buffer_request_room(tty, urb->actual_length);
-               for (i = 0; i < urb->actual_length; ++i)
-                       tty_insert_flip_char(tty, data[i], tty_flag);
+               tty_insert_flip_string(tty, data, urb->actual_length);
                tty_flip_buffer_push(tty);
        }
 
@@ -1133,18 +1096,18 @@ static void oti6858_write_bulk_callback(struct urb *urb)
 
 
 /*
- * pl2303_buf_alloc
+ * oti6858_buf_alloc
  *
  * Allocate a circular buffer and all associated memory.
  */
-static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
+static struct oti6858_buf *oti6858_buf_alloc(unsigned int size)
 {
-       struct pl2303_buf *pb;
+       struct oti6858_buf *pb;
 
        if (size == 0)
                return NULL;
 
-       pb = kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
+       pb = kmalloc(sizeof(struct oti6858_buf), GFP_KERNEL);
        if (pb == NULL)
                return NULL;
 
@@ -1161,11 +1124,11 @@ static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
 }
 
 /*
- * pl2303_buf_free
+ * oti6858_buf_free
  *
  * Free the buffer and all associated memory.
  */
-static void pl2303_buf_free(struct pl2303_buf *pb)
+static void oti6858_buf_free(struct oti6858_buf *pb)
 {
        if (pb) {
                kfree(pb->buf_buf);
@@ -1174,11 +1137,11 @@ static void pl2303_buf_free(struct pl2303_buf *pb)
 }
 
 /*
- * pl2303_buf_clear
+ * oti6858_buf_clear
  *
  * Clear out all data in the circular buffer.
  */
-static void pl2303_buf_clear(struct pl2303_buf *pb)
+static void oti6858_buf_clear(struct oti6858_buf *pb)
 {
        if (pb != NULL) {
                /* equivalent to a get of all data available */
@@ -1187,12 +1150,12 @@ static void pl2303_buf_clear(struct pl2303_buf *pb)
 }
 
 /*
- * pl2303_buf_data_avail
+ * oti6858_buf_data_avail
  *
  * Return the number of bytes of data available in the circular
  * buffer.
  */
-static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
+static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb)
 {
        if (pb == NULL)
                return 0;
@@ -1200,12 +1163,12 @@ static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
 }
 
 /*
- * pl2303_buf_space_avail
+ * oti6858_buf_space_avail
  *
  * Return the number of bytes of space available in the circular
  * buffer.
  */
-static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
+static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb)
 {
        if (pb == NULL)
                return 0;
@@ -1213,14 +1176,14 @@ static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
 }
 
 /*
- * pl2303_buf_put
+ * oti6858_buf_put
  *
  * Copy data data from a user buffer and put it into the circular buffer.
  * Restrict to the amount of space available.
  *
  * Return the number of bytes copied.
  */
-static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
+static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
                                        unsigned int count)
 {
        unsigned int len;
@@ -1228,7 +1191,7 @@ static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
        if (pb == NULL)
                return 0;
 
-       len  = pl2303_buf_space_avail(pb);
+       len  = oti6858_buf_space_avail(pb);
        if (count > len)
                count = len;
 
@@ -1252,14 +1215,14 @@ static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
 }
 
 /*
- * pl2303_buf_get
+ * oti6858_buf_get
  *
  * Get data from the circular buffer and copy to the given buffer.
  * Restrict to the amount of data available.
  *
  * Return the number of bytes copied.
  */
-static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
+static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
                                        unsigned int count)
 {
        unsigned int len;
@@ -1267,7 +1230,7 @@ static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
        if (pb == NULL)
                return 0;
 
-       len = pl2303_buf_data_avail(pb);
+       len = oti6858_buf_data_avail(pb);
        if (count > len)
                count = len;
 
index 0da1df9c79bf044677e703c125212a0dd5f0f52f..ae3ec1a64008b65e2b10f4a95152ea74e6c23729 100644 (file)
@@ -65,6 +65,7 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID_2080) },
        { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) },
        { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) },
+       { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
        { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) },
        { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) },
        { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) },
@@ -84,9 +85,10 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) },
        { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
        { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
-       { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
        { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) },
        { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) },
+       { USB_DEVICE(HL340_VENDOR_ID, HL340_PRODUCT_ID) },
+       { USB_DEVICE(YCCABLE_VENDOR_ID, YCCABLE_PRODUCT_ID) },
        { }                                     /* Terminating entry */
 };
 
@@ -97,7 +99,10 @@ static struct usb_driver pl2303_driver = {
        .probe =        usb_serial_probe,
        .disconnect =   usb_serial_disconnect,
        .id_table =     id_table,
+       .suspend =      usb_serial_suspend,
+       .resume =       usb_serial_resume,
        .no_dynamic_id =        1,
+       .supports_autosuspend = 1,
 };
 
 #define SET_LINE_REQUEST_TYPE          0x21
@@ -310,12 +315,39 @@ static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
        return count;
 }
 
+static int pl2303_vendor_read(__u16 value, __u16 index,
+               struct usb_serial *serial, unsigned char *buf)
+{
+       int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
+                       VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE,
+                       value, index, buf, 1, 100);
+       dbg("0x%x:0x%x:0x%x:0x%x  %d - %x", VENDOR_READ_REQUEST_TYPE,
+                       VENDOR_READ_REQUEST, value, index, res, buf[0]);
+       return res;
+}
+
+static int pl2303_vendor_write(__u16 value, __u16 index,
+               struct usb_serial *serial)
+{
+       int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
+                       VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
+                       value, index, NULL, 0, 100);
+       dbg("0x%x:0x%x:0x%x:0x%x  %d", VENDOR_WRITE_REQUEST_TYPE,
+                       VENDOR_WRITE_REQUEST, value, index, res);
+       return res;
+}
+
 static int pl2303_startup(struct usb_serial *serial)
 {
        struct pl2303_private *priv;
        enum pl2303_type type = type_0;
+       unsigned char *buf;
        int i;
 
+       buf = kmalloc(10, GFP_KERNEL);
+       if (buf == NULL)
+               return -ENOMEM;
+
        if (serial->dev->descriptor.bDeviceClass == 0x02)
                type = type_0;
        else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
@@ -340,9 +372,27 @@ static int pl2303_startup(struct usb_serial *serial)
                priv->type = type;
                usb_set_serial_port_data(serial->port[i], priv);
        }
+
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_write(0x0404, 0, serial);
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_read(0x8383, 0, serial, buf);
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_write(0x0404, 1, serial);
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_read(0x8383, 0, serial, buf);
+       pl2303_vendor_write(0, 1, serial);
+       pl2303_vendor_write(1, 0, serial);
+       if (type == HX)
+               pl2303_vendor_write(2, 0x44, serial);
+       else
+               pl2303_vendor_write(2, 0x24, serial);
+
+       kfree(buf);
        return 0;
 
 cleanup:
+       kfree(buf);
        for (--i; i>=0; --i) {
                priv = usb_get_serial_port_data(serial->port[i]);
                pl2303_buf_free(priv->buf);
@@ -582,24 +632,12 @@ static void pl2303_set_termios(struct usb_serial_port *port,
             buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
 
        if (cflag & CRTSCTS) {
-               __u16 index;
                if (priv->type == HX)
-                       index = 0x61;
+                       pl2303_vendor_write(0x0, 0x61, serial);
                else
-                       index = 0x41;
-               i = usb_control_msg(serial->dev,
-                                   usb_sndctrlpipe(serial->dev, 0),
-                                   VENDOR_WRITE_REQUEST,
-                                   VENDOR_WRITE_REQUEST_TYPE,
-                                   0x0, index, NULL, 0, 100);
-               dbg("0x40:0x1:0x0:0x%x  %d", index, i);
+                       pl2303_vendor_write(0x0, 0x41, serial);
        } else {
-               i = usb_control_msg(serial->dev,
-                                   usb_sndctrlpipe(serial->dev, 0),
-                                   VENDOR_WRITE_REQUEST,
-                                   VENDOR_WRITE_REQUEST_TYPE,
-                                   0x0, 0x0, NULL, 0, 100);
-               dbg ("0x40:0x1:0x0:0x0  %d", i);
+               pl2303_vendor_write(0x0, 0x0, serial);
        }
 
        /* FIXME: Need to read back resulting baud rate */
@@ -629,7 +667,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
                set_current_state(TASK_INTERRUPTIBLE);
                if (pl2303_buf_data_avail(priv->buf) == 0 ||
                    timeout == 0 || signal_pending(current) ||
-                   !usb_get_intfdata(port->serial->interface)) /* disconnect */
+                   port->serial->disconnected)
                        break;
                spin_unlock_irqrestore(&priv->lock, flags);
                timeout = schedule_timeout(timeout);
@@ -678,7 +716,6 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
        struct ktermios tmp_termios;
        struct usb_serial *serial = port->serial;
        struct pl2303_private *priv = usb_get_serial_port_data(port);
-       unsigned char *buf;
        int result;
 
        dbg("%s -  port %d", __FUNCTION__, port->number);
@@ -686,45 +723,12 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
        if (priv->type != HX) {
                usb_clear_halt(serial->dev, port->write_urb->pipe);
                usb_clear_halt(serial->dev, port->read_urb->pipe);
-       }
-
-       buf = kmalloc(10, GFP_KERNEL);
-       if (buf==NULL)
-               return -ENOMEM;
-
-#define FISH(a,b,c,d)                                                          \
-       result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0),     \
-                              b, a, c, d, buf, 1, 100);                        \
-       dbg("0x%x:0x%x:0x%x:0x%x  %d - %x",a,b,c,d,result,buf[0]);
-
-#define SOUP(a,b,c,d)                                                          \
-       result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0),     \
-                              b, a, c, d, NULL, 0, 100);                       \
-       dbg("0x%x:0x%x:0x%x:0x%x  %d",a,b,c,d,result);
-
-       FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
-       SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0);
-       FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
-       FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
-       FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
-       SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1);
-       FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
-       FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
-       SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1);
-       SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0);
-
-       if (priv->type == HX) {
-               /* HX chip */
-               SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x44);
-               /* reset upstream data pipes */
-               SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 8, 0);
-               SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 9, 0);
        } else {
-               SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x24);
+               /* reset upstream data pipes */
+               pl2303_vendor_write(8, 0, serial);
+               pl2303_vendor_write(9, 0, serial);
        }
 
-       kfree(buf);
-
        /* Setup termios */
        if (port->tty) {
                pl2303_set_termios(port, &tmp_termios);
index d31f5d299989f2315b280c4ab3092edec912d002..237a41f6638ac239b9c3dc980230cf4c615537f5 100644 (file)
@@ -35,6 +35,7 @@
 
 #define RATOC_VENDOR_ID                0x0584
 #define RATOC_PRODUCT_ID       0xb000
+#define RATOC_PRODUCT_ID_USB60F        0xb020
 
 #define TRIPP_VENDOR_ID                0x2478
 #define TRIPP_PRODUCT_ID       0x2008
 #define ALCOR_VENDOR_ID                0x058F
 #define ALCOR_PRODUCT_ID       0x9720
 
-/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */
-#define HUAWEI_VENDOR_ID       0x12d1
-#define HUAWEI_PRODUCT_ID      0x1001
-
 /* Willcom WS002IN Data Driver (by NetIndex Inc.) */
 #define WS002IN_VENDOR_ID      0x11f6
 #define WS002IN_PRODUCT_ID     0x2001
 /* Corega CG-USBRS232R Serial Adapter */
 #define COREGA_VENDOR_ID       0x07aa
 #define COREGA_PRODUCT_ID      0x002a
+
+/* HL HL-340 (ID: 4348:5523) */
+#define HL340_VENDOR_ID                0x4348
+#define HL340_PRODUCT_ID       0x5523
+
+/* Y.C. Cable U.S.A., Inc - USB to RS-232 */
+#define YCCABLE_VENDOR_ID      0x05ad
+#define YCCABLE_PRODUCT_ID     0x0fba
index c295d0495f96f9a6a490494e504ee0510f9a40fb..4c925e3e8a6387663447f56cd07bc5532c931ddc 100644 (file)
@@ -1,7 +1,7 @@
 /*
   USB Driver for Sierra Wireless
 
-  Copyright (C) 2006, 2007  Kevin Lloyd <linux@sierrawireless.com>
+  Copyright (C) 2006, 2007, 2008  Kevin Lloyd <linux@sierrawireless.com>
 
   IMPORTANT DISCLAIMER: This driver is not commercially supported by
   Sierra Wireless. Use at your own risk.
@@ -14,7 +14,7 @@
   Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
 */
 
-#define DRIVER_VERSION "v.1.2.5b"
+#define DRIVER_VERSION "v.1.2.7"
 #define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>"
 #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
 
 #include <linux/module.h>
 #include <linux/usb.h>
 #include <linux/usb/serial.h>
+#include <linux/usb/ch9.h>
 
+#define SWIMS_USB_REQUEST_SetPower     0x00
+#define SWIMS_USB_REQUEST_SetNmea      0x07
 #define SWIMS_USB_REQUEST_SetMode      0x0B
-#define SWIMS_USB_REQUEST_TYPE_SetMode 0x40
-#define SWIMS_USB_INDEX_SetMode                0x0000
+#define SWIMS_USB_REQUEST_TYPE_VSC_SET 0x40
 #define SWIMS_SET_MODE_Modem           0x0001
 
 /* per port private data */
@@ -38,6 +40,8 @@
 #define IN_BUFLEN      4096
 
 static int debug;
+static int nmea;
+static int truinstall = 1;
 
 enum devicetype {
        DEVICE_3_PORT =         0,
@@ -50,48 +54,96 @@ static int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
        int result;
        dev_dbg(&udev->dev, "%s", "SET POWER STATE\n");
        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
-                       0x00,                   /* __u8 request      */
-                       0x40,                   /* __u8 request type */
-                       swiState,               /* __u16 value       */
-                       0,                      /* __u16 index       */
-                       NULL,                   /* void *data        */
-                       0,                      /* __u16 size        */
-                       USB_CTRL_SET_TIMEOUT);  /* int timeout       */
+                       SWIMS_USB_REQUEST_SetPower,     /* __u8 request      */
+                       SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */
+                       swiState,                       /* __u16 value       */
+                       0,                              /* __u16 index       */
+                       NULL,                           /* void *data        */
+                       0,                              /* __u16 size        */
+                       USB_CTRL_SET_TIMEOUT);          /* int timeout       */
        return result;
 }
 
-static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSocMode)
+static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSWocMode)
 {
        int result;
        dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n");
        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
                        SWIMS_USB_REQUEST_SetMode,      /* __u8 request      */
-                       SWIMS_USB_REQUEST_TYPE_SetMode, /* __u8 request type */
-                       eSocMode,                       /* __u16 value       */
-                       SWIMS_USB_INDEX_SetMode,        /* __u16 index       */
+                       SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */
+                       eSWocMode,                      /* __u16 value       */
+                       0x0000,                         /* __u16 index       */
                        NULL,                           /* void *data        */
                        0,                              /* __u16 size        */
                        USB_CTRL_SET_TIMEOUT);          /* int timeout       */
        return result;
 }
 
-static int sierra_probe(struct usb_interface *iface,
-                       const struct usb_device_id *id)
+static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable)
+{
+       int result;
+       dev_dbg(&udev->dev, "%s", "NMEA Enable sent\n");
+       result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                       SWIMS_USB_REQUEST_SetNmea,      /* __u8 request      */
+                       SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */
+                       enable,                         /* __u16 value       */
+                       0x0000,                         /* __u16 index       */
+                       NULL,                           /* void *data        */
+                       0,                              /* __u16 size        */
+                       USB_CTRL_SET_TIMEOUT);          /* int timeout       */
+       return result;
+}
+
+static int sierra_calc_num_ports(struct usb_serial *serial)
 {
        int result;
+       int *num_ports = usb_get_serial_data(serial);
+
+       result = *num_ports;
+
+       if (result) {
+               kfree(num_ports);
+               usb_set_serial_data(serial, NULL);
+       }
+
+       return result;
+}
+
+static int sierra_probe(struct usb_serial *serial,
+                       const struct usb_device_id *id)
+{
+       int result = 0;
        struct usb_device *udev;
+       int *num_ports;
+       u8 ifnum;
+
+       num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL);
+       if (!num_ports)
+               return -ENOMEM;
 
-       udev = usb_get_dev(interface_to_usbdev(iface));
+       ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
+       udev = serial->dev;
 
        /* Check if in installer mode */
-       if (id->driver_info == DEVICE_INSTALLER) {
-               dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n");
+       if (truinstall && id->driver_info == DEVICE_INSTALLER) {
+               dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE(SW)\n");
                result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem);
-               /*We do not want to bind to the device when in installer mode*/
+               /* Don't bind to the device when in installer mode */
+               kfree(num_ports);
                return -EIO;
-       }
+       } else if (id->driver_info == DEVICE_1_PORT)
+               *num_ports = 1;
+       else if (ifnum == 0x99)
+               *num_ports = 0;
+       else
+               *num_ports = 3;
+       /*
+        * save off our num_ports info so that we can use it in the
+        * calc_num_ports callback
+        */
+       usb_set_serial_data(serial, (void *)num_ports);
 
-       return usb_serial_probe(iface, id);
+       return result;
 }
 
 static struct usb_device_id id_table [] = {
@@ -104,6 +156,7 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
        { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
        { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
+       { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless AirCard */
 
        { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
        { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
@@ -117,56 +170,29 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
        { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
        { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
+       { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
+       { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
+
+       { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
+       { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
 
        { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */
        { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */
+       { USB_DEVICE(0x05C6, 0x6613), .driver_info = DEVICE_1_PORT }, /* Onda H600/ZTE MF330 */
 
        { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER},
        { }
 };
 MODULE_DEVICE_TABLE(usb, id_table);
 
-static struct usb_device_id id_table_1port [] = {
-       { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
-       { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
-       { }
-};
-
-static struct usb_device_id id_table_3port [] = {
-       { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
-       { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
-       { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
-       { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
-       { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
-       { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
-       { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
-       { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
-       { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/
-
-       { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
-       { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
-       { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
-       { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
-       { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
-       { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
-       { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
-       { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
-       { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
-       { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
-       { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */
-       { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */
-       { }
-};
-
 static struct usb_driver sierra_driver = {
        .name       = "sierra",
-       .probe      = sierra_probe,
+       .probe      = usb_serial_probe,
        .disconnect = usb_serial_disconnect,
        .id_table   = id_table,
        .no_dynamic_id =        1,
 };
 
-
 struct sierra_port_private {
        spinlock_t lock;        /* lock the structure */
        int outstanding_urbs;   /* number of out urbs in flight */
@@ -188,6 +214,7 @@ static int sierra_send_setup(struct usb_serial_port *port)
 {
        struct usb_serial *serial = port->serial;
        struct sierra_port_private *portdata;
+       __u16 interface = 0;
 
        dbg("%s", __FUNCTION__);
 
@@ -200,9 +227,18 @@ static int sierra_send_setup(struct usb_serial_port *port)
                if (portdata->rts_state)
                        val |= 0x02;
 
+               /* Determine which port is targeted */
+               if (port->bulk_out_endpointAddress == 2)
+                       interface = 0;
+               else if (port->bulk_out_endpointAddress == 4)
+                       interface = 1;
+               else if (port->bulk_out_endpointAddress == 5)
+                       interface = 2;
+
                return usb_control_msg(serial->dev,
                                usb_rcvctrlpipe(serial->dev, 0),
-                               0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
+                               0x22, 0x21, val, interface,
+                               NULL, 0, USB_CTRL_SET_TIMEOUT);
        }
 
        return 0;
@@ -561,7 +597,10 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
        portdata->dtr_state = 0;
 
        if (serial->dev) {
-               sierra_send_setup(port);
+               mutex_lock(&serial->disc_mutex);
+               if (!serial->disconnected)
+                       sierra_send_setup(port);
+               mutex_unlock(&serial->disc_mutex);
 
                /* Stop reading/writing urbs */
                for (i = 0; i < N_IN_URB; i++)
@@ -583,9 +622,13 @@ static int sierra_startup(struct usb_serial *serial)
 
        dbg("%s", __FUNCTION__);
 
-       /*Set Device mode to D0 */
+       /* Set Device mode to D0 */
        sierra_set_power_state(serial->dev, 0x0000);
 
+       /* Check NMEA and set */
+       if (nmea)
+               sierra_vsc_set_nmea(serial->dev, 1);
+
        /* Now setup per port private data */
        for (i = 0; i < serial->num_ports; i++) {
                port = serial->port[i];
@@ -646,47 +689,19 @@ static void sierra_shutdown(struct usb_serial *serial)
        }
 }
 
-static struct usb_serial_driver sierra_1port_device = {
+static struct usb_serial_driver sierra_device = {
        .driver = {
                .owner =        THIS_MODULE,
                .name =         "sierra1",
        },
-       .description       = "Sierra USB modem (1 port)",
-       .id_table          = id_table_1port,
-       .usb_driver        = &sierra_driver,
-       .num_interrupt_in  = NUM_DONT_CARE,
-       .num_bulk_in       = 1,
-       .num_bulk_out      = 1,
-       .num_ports         = 1,
-       .open              = sierra_open,
-       .close             = sierra_close,
-       .write             = sierra_write,
-       .write_room        = sierra_write_room,
-       .chars_in_buffer   = sierra_chars_in_buffer,
-       .throttle          = sierra_rx_throttle,
-       .unthrottle        = sierra_rx_unthrottle,
-       .ioctl             = sierra_ioctl,
-       .set_termios       = sierra_set_termios,
-       .break_ctl         = sierra_break_ctl,
-       .tiocmget          = sierra_tiocmget,
-       .tiocmset          = sierra_tiocmset,
-       .attach            = sierra_startup,
-       .shutdown          = sierra_shutdown,
-       .read_int_callback = sierra_instat_callback,
-};
-
-static struct usb_serial_driver sierra_3port_device = {
-       .driver = {
-               .owner =        THIS_MODULE,
-               .name =         "sierra3",
-       },
-       .description       = "Sierra USB modem (3 port)",
-       .id_table          = id_table_3port,
+       .description       = "Sierra USB modem",
+       .id_table          = id_table,
        .usb_driver        = &sierra_driver,
        .num_interrupt_in  = NUM_DONT_CARE,
-       .num_bulk_in       = 3,
-       .num_bulk_out      = 3,
-       .num_ports         = 3,
+       .num_bulk_in       = NUM_DONT_CARE,
+       .num_bulk_out      = NUM_DONT_CARE,
+       .calc_num_ports    = sierra_calc_num_ports,
+       .probe             = sierra_probe,
        .open              = sierra_open,
        .close             = sierra_close,
        .write             = sierra_write,
@@ -708,12 +723,9 @@ static struct usb_serial_driver sierra_3port_device = {
 static int __init sierra_init(void)
 {
        int retval;
-       retval = usb_serial_register(&sierra_1port_device);
-       if (retval)
-               goto failed_1port_device_register;
-       retval = usb_serial_register(&sierra_3port_device);
+       retval = usb_serial_register(&sierra_device);
        if (retval)
-               goto failed_3port_device_register;
+               goto failed_device_register;
 
 
        retval = usb_register(&sierra_driver);
@@ -725,18 +737,15 @@ static int __init sierra_init(void)
        return 0;
 
 failed_driver_register:
-       usb_serial_deregister(&sierra_3port_device);
-failed_3port_device_register:
-       usb_serial_deregister(&sierra_1port_device);
-failed_1port_device_register:
+       usb_serial_deregister(&sierra_device);
+failed_device_register:
        return retval;
 }
 
 static void __exit sierra_exit(void)
 {
        usb_deregister (&sierra_driver);
-       usb_serial_deregister(&sierra_1port_device);
-       usb_serial_deregister(&sierra_3port_device);
+       usb_serial_deregister(&sierra_device);
 }
 
 module_init(sierra_init);
@@ -747,6 +756,12 @@ MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_VERSION(DRIVER_VERSION);
 MODULE_LICENSE("GPL");
 
+module_param(truinstall, bool, 0);
+MODULE_PARM_DESC(truinstall, "TRU-Install support");
+
+module_param(nmea, bool, 0);
+MODULE_PARM_DESC(nmea, "NMEA streaming");
+
 #ifdef CONFIG_USB_DEBUG
 module_param(debug, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Debug messages");
index 1f0149495fb4f218067433a53a07abe8721ace57..b517f93352ec414d8ee52258b5965868ea2fb5f2 100644 (file)
@@ -80,6 +80,7 @@
 #include <linux/ioctl.h>
 #include <linux/serial.h>
 #include <linux/circ_buf.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 #include <linux/usb.h>
@@ -139,7 +140,7 @@ struct ti_port {
 };
 
 struct ti_device {
-       struct semaphore        td_open_close_sem;
+       struct mutex            td_open_close_lock;
        int                     td_open_port_count;
        struct usb_serial       *td_serial;
        int                     td_is_3410;
@@ -424,7 +425,7 @@ static int ti_startup(struct usb_serial *serial)
                dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__);
                return -ENOMEM;
        }
-       sema_init(&tdev->td_open_close_sem, 1);
+       mutex_init(&tdev->td_open_close_lock);
        tdev->td_serial = serial;
        usb_set_serial_data(serial, tdev);
 
@@ -547,7 +548,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
        tdev = tport->tp_tdev;
 
        /* only one open on any port on a device at a time */
-       if (down_interruptible(&tdev->td_open_close_sem))
+       if (mutex_lock_interruptible(&tdev->td_open_close_lock))
                return -ERESTARTSYS;
 
        if (port->tty)
@@ -568,7 +569,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
                if (!urb) {
                        dev_err(&port->dev, "%s - no interrupt urb\n", __FUNCTION__);
                        status = -EINVAL;
-                       goto up_sem;
+                       goto release_lock;
                }
                urb->complete = ti_interrupt_callback;
                urb->context = tdev;
@@ -576,11 +577,11 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
                status = usb_submit_urb(urb, GFP_KERNEL);
                if (status) {
                        dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __FUNCTION__, status);
-                       goto up_sem;
+                       goto release_lock;
                }
        }
 
-       ti_set_termios(port, NULL);
+       ti_set_termios(port, port->tty->termios);
 
        dbg("%s - sending TI_OPEN_PORT", __FUNCTION__);
        status = ti_command_out_sync(tdev, TI_OPEN_PORT,
@@ -617,7 +618,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
        usb_clear_halt(dev, port->write_urb->pipe);
        usb_clear_halt(dev, port->read_urb->pipe);
 
-       ti_set_termios(port, NULL);
+       ti_set_termios(port, port->tty->termios);
 
        dbg("%s - sending TI_OPEN_PORT (2)", __FUNCTION__);
        status = ti_command_out_sync(tdev, TI_OPEN_PORT,
@@ -656,13 +657,13 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
        tport->tp_is_open = 1;
        ++tdev->td_open_port_count;
 
-       goto up_sem;
+       goto release_lock;
 
 unlink_int_urb:
        if (tdev->td_open_port_count == 0)
                usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
-up_sem:
-       up(&tdev->td_open_close_sem);
+release_lock:
+       mutex_unlock(&tdev->td_open_close_lock);
        dbg("%s - exit %d", __FUNCTION__, status);
        return status;
 }
@@ -674,7 +675,7 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
        struct ti_port *tport;
        int port_number;
        int status;
-       int do_up;
+       int do_unlock;
 
        dbg("%s - port %d", __FUNCTION__, port->number);
                         
@@ -699,16 +700,16 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
        if (status)
                dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __FUNCTION__, status);
 
-       /* if down is interrupted, continue anyway */
-       do_up = !down_interruptible(&tdev->td_open_close_sem);
+       /* if mutex_lock is interrupted, continue anyway */
+       do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock);
        --tport->tp_tdev->td_open_port_count;
        if (tport->tp_tdev->td_open_port_count <= 0) {
                /* last port is closed, shut down interrupt urb */
                usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
                tport->tp_tdev->td_open_port_count = 0;
        }
-       if (do_up)
-               up(&tdev->td_open_close_sem);
+       if (do_unlock)
+               mutex_unlock(&tdev->td_open_close_lock);
 
        dbg("%s - exit", __FUNCTION__);
 }
@@ -896,24 +897,11 @@ static void ti_set_termios(struct usb_serial_port *port,
 
        dbg("%s - port %d", __FUNCTION__, port->number);
 
-       if (!tty || !tty->termios) {
-               dbg("%s - no tty or termios", __FUNCTION__);
-               return;
-       }
-
        cflag = tty->termios->c_cflag;
        iflag = tty->termios->c_iflag;
 
-       if (old_termios && cflag == old_termios->c_cflag
-       && iflag == old_termios->c_iflag) {
-               dbg("%s - nothing to change", __FUNCTION__);
-               return;
-       }
-
-       dbg("%s - clfag %08x, iflag %08x", __FUNCTION__, cflag, iflag);
-
-       if (old_termios)
-               dbg("%s - old clfag %08x, old iflag %08x", __FUNCTION__, old_termios->c_cflag, old_termios->c_iflag);
+       dbg("%s - cflag %08x, iflag %08x", __FUNCTION__, cflag, iflag);
+       dbg("%s - old clfag %08x, old iflag %08x", __FUNCTION__, old_termios->c_cflag, old_termios->c_iflag);
 
        if (tport == NULL)
                return;
@@ -947,6 +935,9 @@ static void ti_set_termios(struct usb_serial_port *port,
                            break;
        }
 
+       /* CMSPAR isn't supported by this driver */
+       tty->termios->c_cflag &= ~CMSPAR;
+
        if (cflag & PARENB) {
                if (cflag & PARODD) {
                        config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING;
@@ -989,12 +980,17 @@ static void ti_set_termios(struct usb_serial_port *port,
        }
 
        baud = tty_get_baud_rate(tty);
-       if (!baud) baud = 9600;
+       if (!baud)
+               baud = 9600;
        if (tport->tp_tdev->td_is_3410)
                config->wBaudRate = (__u16)((923077 + baud/2) / baud);
        else
                config->wBaudRate = (__u16)((461538 + baud/2) / baud);
 
+       /* FIXME: Should calculate resulting baud here and report it back */
+       if ((cflag & CBAUD) != B0)
+               tty_encode_baud_rate(tty, baud, baud);
+
        dbg("%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d",
        __FUNCTION__, baud, config->wBaudRate, config->wFlags, config->bDataBits, config->bParity, config->bStopBits, config->cXon, config->cXoff, config->bUartMode);
 
@@ -1497,11 +1493,10 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
        struct ti_device *tdev = tport->tp_tdev;
        struct usb_serial_port *port = tport->tp_port;
        wait_queue_t wait;
-       unsigned long flags;
 
        dbg("%s - port %d", __FUNCTION__, port->number);
 
-       spin_lock_irqsave(&tport->tp_lock, flags);
+       spin_lock_irq(&tport->tp_lock);
 
        /* wait for data to drain from the buffer */
        tdev->td_urb_error = 0;
@@ -1512,11 +1507,11 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
                if (ti_buf_data_avail(tport->tp_write_buf) == 0
                || timeout == 0 || signal_pending(current)
                || tdev->td_urb_error
-               || !usb_get_intfdata(port->serial->interface))  /* disconnect */
+               || port->serial->disconnected)  /* disconnect */
                        break;
-               spin_unlock_irqrestore(&tport->tp_lock, flags);
+               spin_unlock_irq(&tport->tp_lock);
                timeout = schedule_timeout(timeout);
-               spin_lock_irqsave(&tport->tp_lock, flags);
+               spin_lock_irq(&tport->tp_lock);
        }
        set_current_state(TASK_RUNNING);
        remove_wait_queue(&tport->tp_write_wait, &wait);
@@ -1525,19 +1520,23 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
        if (flush)
                ti_buf_clear(tport->tp_write_buf);
 
-       spin_unlock_irqrestore(&tport->tp_lock, flags);
+       spin_unlock_irq(&tport->tp_lock);
 
+       mutex_lock(&port->serial->disc_mutex);
        /* wait for data to drain from the device */
        /* wait for empty tx register, plus 20 ms */
        timeout += jiffies;
        tport->tp_lsr &= ~TI_LSR_TX_EMPTY;
        while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
        && !(tport->tp_lsr&TI_LSR_TX_EMPTY) && !tdev->td_urb_error
-       && usb_get_intfdata(port->serial->interface)) {  /* not disconnected */
+       && !port->serial->disconnected) {
                if (ti_get_lsr(tport))
                        break;
+               mutex_unlock(&port->serial->disc_mutex);
                msleep_interruptible(20);
+               mutex_lock(&port->serial->disc_mutex);
        }
+       mutex_unlock(&port->serial->disc_mutex);
 }
 
 
index 497e29a700ca8dccb20049e0aa0abf983dcbf40c..3ce98e8d7bce6103031af188dc56218693f8ac51 100644 (file)
@@ -225,16 +225,21 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
                        goto bailout_mutex_unlock;
                }
 
+               retval = usb_autopm_get_interface(serial->interface);
+               if (retval)
+                       goto bailout_module_put;
                /* only call the device specific open if this 
                 * is the first time the port is opened */
                retval = serial->type->open(port, filp);
                if (retval)
-                       goto bailout_module_put;
+                       goto bailout_interface_put;
        }
 
        mutex_unlock(&port->mutex);
        return 0;
 
+bailout_interface_put:
+       usb_autopm_put_interface(serial->interface);
 bailout_module_put:
        module_put(serial->type->driver.owner);
 bailout_mutex_unlock:
@@ -264,17 +269,21 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
        }
 
        --port->open_count;
-       if (port->open_count == 0) {
+       if (port->open_count == 0)
                /* only call the device specific close if this 
                 * port is being closed by the last owner */
                port->serial->type->close(port, filp);
 
+       if (port->open_count == (port->console? 1 : 0)) {
                if (port->tty) {
                        if (port->tty->driver_data)
                                port->tty->driver_data = NULL;
                        port->tty = NULL;
                }
+       }
 
+       if (port->open_count == 0) {
+               usb_autopm_put_interface(port->serial->interface);
                module_put(port->serial->type->driver.owner);
        }
 
@@ -625,6 +634,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
        serial->type = driver;
        serial->interface = interface;
        kref_init(&serial->kref);
+       mutex_init(&serial->disc_mutex);
 
        return serial;
 }
@@ -1080,20 +1090,22 @@ void usb_serial_disconnect(struct usb_interface *interface)
        usb_serial_console_disconnect(serial);
        dbg ("%s", __FUNCTION__);
 
+       mutex_lock(&serial->disc_mutex);
        usb_set_intfdata (interface, NULL);
-       if (serial) {
-               for (i = 0; i < serial->num_ports; ++i) {
-                       port = serial->port[i];
-                       if (port) {
-                               if (port->tty)
-                                       tty_hangup(port->tty);
-                               kill_traffic(port);
-                       }
+       /* must set a flag, to signal subdrivers */
+       serial->disconnected = 1;
+       for (i = 0; i < serial->num_ports; ++i) {
+               port = serial->port[i];
+               if (port) {
+                       if (port->tty)
+                               tty_hangup(port->tty);
+                       kill_traffic(port);
                }
-               /* let the last holder of this object 
-                * cause it to be cleaned up */
-               usb_serial_put(serial);
        }
+       /* let the last holder of this object
+        * cause it to be cleaned up */
+       mutex_unlock(&serial->disc_mutex);
+       usb_serial_put(serial);
        dev_info(dev, "device disconnected\n");
 }
 
@@ -1103,9 +1115,6 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
        struct usb_serial_port *port;
        int i, r = 0;
 
-       if (!serial) /* device has been disconnected */
-               return 0;
-
        for (i = 0; i < serial->num_ports; ++i) {
                port = serial->port[i];
                if (port)
@@ -1253,6 +1262,7 @@ static void fixup_generic(struct usb_serial_driver *device)
        set_to_generic_if_null(device, read_bulk_callback);
        set_to_generic_if_null(device, write_bulk_callback);
        set_to_generic_if_null(device, shutdown);
+       set_to_generic_if_null(device, resume);
 }
 
 int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */
index 7ee087fed913fbeed34678caebbe15dc8a96567c..22b3f78a388ce0d40486ede8c98f9af41051dc49 100644 (file)
@@ -349,16 +349,20 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
        usb_kill_urb(port->read_urb);
        usb_kill_urb(port->interrupt_in_urb);
 
-       /* Try to send shutdown message, if the device is gone, this will just fail. */
-       transfer_buffer =  kmalloc (0x12, GFP_KERNEL);
-       if (transfer_buffer) {
-               usb_control_msg (port->serial->dev,
-                                usb_rcvctrlpipe(port->serial->dev, 0),
-                                VISOR_CLOSE_NOTIFICATION, 0xc2,
-                                0x0000, 0x0000, 
-                                transfer_buffer, 0x12, 300);
-               kfree (transfer_buffer);
+       mutex_lock(&port->serial->disc_mutex);
+       if (!port->serial->disconnected) {
+               /* Try to send shutdown message, unless the device is gone */
+               transfer_buffer =  kmalloc (0x12, GFP_KERNEL);
+               if (transfer_buffer) {
+                       usb_control_msg (port->serial->dev,
+                                        usb_rcvctrlpipe(port->serial->dev, 0),
+                                        VISOR_CLOSE_NOTIFICATION, 0xc2,
+                                        0x0000, 0x0000,
+                                        transfer_buffer, 0x12, 300);
+                       kfree (transfer_buffer);
+               }
        }
+       mutex_unlock(&port->serial->disc_mutex);
 
        if (stats)
                dev_info(&port->dev, "Bytes In = %d  Bytes Out = %d\n",
index ee5dd8b5a7131b23846d153586686f1163fa7dec..38726ef3132b70d83121d8bdaa894b47990f0843 100644 (file)
@@ -610,8 +610,7 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
        if (retval)
                goto exit;
 
-       if (port->tty)
-               port->tty->low_latency = 1;
+       port->tty->low_latency = 1;
 
        /* send an open port command */
        retval = firm_open(port);
@@ -659,11 +658,14 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
        struct list_head *tmp2;
 
        dbg("%s - port %d", __FUNCTION__, port->number);
-       
+
+       mutex_lock(&port->serial->disc_mutex);
        /* filp is NULL when called from usb_serial_disconnect */
-       if (filp && (tty_hung_up_p(filp))) {
+       if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) {
+               mutex_unlock(&port->serial->disc_mutex);
                return;
        }
+       mutex_unlock(&port->serial->disc_mutex);
 
        port->tty->closing = 1;
 
index ee5b42aa53633b159b259d95bbf208e866a48492..187dd1e01093584c47d9da7f7c22f0f596a37c3c 100644 (file)
@@ -66,7 +66,8 @@ int usb_stor_ucr61s2b_init(struct us_data *us)
 {
        struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf;
        struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf;
-       int res, partial;
+       int res;
+       unsigned int partial;
        static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS";
 
        US_DEBUGP("Sending UCR-61S2B initialization packet...\n");
index 0db488624ab1c4983cf481ec637e29a9650bc586..2ae1e8673b195297aeea17e7f9333ba4fecd8c42 100644 (file)
@@ -48,7 +48,6 @@
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/hdreg.h>
-#include <linux/ide.h>
 #include <linux/scatterlist.h>
 
 #include <scsi/scsi.h>
 #define REG_STATUS             0x80
 #define REG_COMMAND            0x80
 
+/* ATA registers offset definitions */
+#define ATA_REG_ERROR_OFFSET           1
+#define ATA_REG_LCYL_OFFSET            4
+#define ATA_REG_HCYL_OFFSET            5
+#define ATA_REG_STATUS_OFFSET          7
+
 /* ATA error definitions not in <linux/hdreg.h> */
 #define ATA_ERROR_MEDIA_CHANGE         0x20
 
@@ -360,7 +365,7 @@ static void isd200_build_sense(struct us_data *us, struct scsi_cmnd *srb)
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0];
-       unsigned char error = info->ATARegs[IDE_ERROR_OFFSET];
+       unsigned char error = info->ATARegs[ATA_REG_ERROR_OFFSET];
 
        if(error & ATA_ERROR_MEDIA_CHANGE) {
                buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID;
@@ -549,8 +554,8 @@ static int isd200_read_regs( struct us_data *us )
                retStatus = ISD200_ERROR;
        } else {
                memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs));
-               US_DEBUGP("   Got ATA Register[IDE_ERROR_OFFSET] = 0x%x\n", 
-                         info->ATARegs[IDE_ERROR_OFFSET]);
+               US_DEBUGP("   Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n",
+                         info->ATARegs[ATA_REG_ERROR_OFFSET]);
        }
 
        return retStatus;
@@ -892,7 +897,7 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
                        break;
 
                if (!detect) {
-                       if (regs[IDE_STATUS_OFFSET] & BUSY_STAT ) {
+                       if (regs[ATA_REG_STATUS_OFFSET] & BUSY_STAT) {
                                US_DEBUGP("   %s status is still BSY, try again...\n",mstr);
                        } else {
                                US_DEBUGP("   %s status !BSY, continue with next operation\n",mstr);
@@ -902,12 +907,12 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
                /* check for BUSY_STAT and */
                /* WRERR_STAT (workaround ATA Zip drive) and */ 
                /* ERR_STAT (workaround for Archos CD-ROM) */
-               else if (regs[IDE_STATUS_OFFSET] & 
+               else if (regs[ATA_REG_STATUS_OFFSET] &
                         (BUSY_STAT | WRERR_STAT | ERR_STAT )) {
                        US_DEBUGP("   Status indicates it is not ready, try again...\n");
                }
                /* check for DRDY, ATA devices set DRDY after SRST */
-               else if (regs[IDE_STATUS_OFFSET] & READY_STAT) {
+               else if (regs[ATA_REG_STATUS_OFFSET] & READY_STAT) {
                        US_DEBUGP("   Identified ATA device\n");
                        info->DeviceFlags |= DF_ATA_DEVICE;
                        info->DeviceHead = master_slave;
@@ -916,8 +921,8 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
                /* check Cylinder High/Low to
                   determine if it is an ATAPI device
                */
-               else if ((regs[IDE_HCYL_OFFSET] == 0xEB) &&
-                        (regs[IDE_LCYL_OFFSET] == 0x14)) {
+               else if (regs[ATA_REG_HCYL_OFFSET] == 0xEB &&
+                        regs[ATA_REG_LCYL_OFFSET] == 0x14) {
                        /* It seems that the RICOH 
                           MP6200A CD/RW drive will 
                           report itself okay as a
@@ -1001,12 +1006,6 @@ static int isd200_manual_enum(struct us_data *us)
        return(retStatus);
 }
 
-/*
- *     We are the last non IDE user of the legacy IDE ident structures
- *     and we thus want to keep a private copy of this function so the
- *     driver can be used without the obsolete drivers/ide layer
- */
-
 static void isd200_fix_driveid (struct hd_driveid *id)
 {
 #ifndef __LITTLE_ENDIAN
index 6d6108b3993b3d33aea67adbaf6479a9e8deffa0..fe12737e0e2be566becbf4133d401a5ea4fba8dd 100644 (file)
@@ -86,6 +86,14 @@ UNUSUAL_DEV(  0x03f0, 0x0307, 0x0001, 0x0001,
                US_SC_8070, US_PR_USBAT, init_usbat_cd, 0),
 #endif
 
+/* Reported by Grant Grundler <grundler@parisc-linux.org>
+ * HP r707 camera in "Disk" mode with 2.00.23 or 2.00.24 firmware.
+ */
+UNUSUAL_DEV(  0x03f0, 0x4002, 0x0001, 0x0001,
+               "HP",
+               "PhotoSmart R707",
+               US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_CAPACITY),
+
 /* Reported by Sebastian Kapfer <sebastian_kapfer@gmx.net>
  * and Olaf Hering <olh@suse.de> (different bcd's, same vendor/product)
  * for USB floppies that need the SINGLE_LUN enforcement.
index f8e711147501079011887cc86f65365b04b1cf46..fc65c02306ddbd6c32c2be96b80fcd630be0258a 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/fb.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/backlight.h>
 
 #include <asm/arch/board.h>
 #include <asm/arch/cpu.h>
@@ -69,6 +70,107 @@ static void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
 }
 #endif
 
+static const u32 contrast_ctr = ATMEL_LCDC_PS_DIV8
+               | ATMEL_LCDC_POL_POSITIVE
+               | ATMEL_LCDC_ENA_PWMENABLE;
+
+#ifdef CONFIG_BACKLIGHT_ATMEL_LCDC
+
+/* some bl->props field just changed */
+static int atmel_bl_update_status(struct backlight_device *bl)
+{
+       struct atmel_lcdfb_info *sinfo = bl_get_data(bl);
+       int                     power = sinfo->bl_power;
+       int                     brightness = bl->props.brightness;
+
+       /* REVISIT there may be a meaningful difference between
+        * fb_blank and power ... there seem to be some cases
+        * this doesn't handle correctly.
+        */
+       if (bl->props.fb_blank != sinfo->bl_power)
+               power = bl->props.fb_blank;
+       else if (bl->props.power != sinfo->bl_power)
+               power = bl->props.power;
+
+       if (brightness < 0 && power == FB_BLANK_UNBLANK)
+               brightness = lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
+       else if (power != FB_BLANK_UNBLANK)
+               brightness = 0;
+
+       lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_VAL, brightness);
+       lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR,
+                       brightness ? contrast_ctr : 0);
+
+       bl->props.fb_blank = bl->props.power = sinfo->bl_power = power;
+
+       return 0;
+}
+
+static int atmel_bl_get_brightness(struct backlight_device *bl)
+{
+       struct atmel_lcdfb_info *sinfo = bl_get_data(bl);
+
+       return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
+}
+
+static struct backlight_ops atmel_lcdc_bl_ops = {
+       .update_status = atmel_bl_update_status,
+       .get_brightness = atmel_bl_get_brightness,
+};
+
+static void init_backlight(struct atmel_lcdfb_info *sinfo)
+{
+       struct backlight_device *bl;
+
+       sinfo->bl_power = FB_BLANK_UNBLANK;
+
+       if (sinfo->backlight)
+               return;
+
+       bl = backlight_device_register("backlight", &sinfo->pdev->dev,
+                       sinfo, &atmel_lcdc_bl_ops);
+       if (IS_ERR(sinfo->backlight)) {
+               dev_err(&sinfo->pdev->dev, "error %ld on backlight register\n",
+                               PTR_ERR(bl));
+               return;
+       }
+       sinfo->backlight = bl;
+
+       bl->props.power = FB_BLANK_UNBLANK;
+       bl->props.fb_blank = FB_BLANK_UNBLANK;
+       bl->props.max_brightness = 0xff;
+       bl->props.brightness = atmel_bl_get_brightness(bl);
+}
+
+static void exit_backlight(struct atmel_lcdfb_info *sinfo)
+{
+       if (sinfo->backlight)
+               backlight_device_unregister(sinfo->backlight);
+}
+
+#else
+
+static void init_backlight(struct atmel_lcdfb_info *sinfo)
+{
+       dev_warn(&sinfo->pdev->dev, "backlight control is not available\n");
+}
+
+static void exit_backlight(struct atmel_lcdfb_info *sinfo)
+{
+}
+
+#endif
+
+static void init_contrast(struct atmel_lcdfb_info *sinfo)
+{
+       /* have some default contrast/backlight settings */
+       lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, contrast_ctr);
+       lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_VAL, ATMEL_LCDC_CVAL_DEFAULT);
+
+       if (sinfo->lcdcon_is_backlight)
+               init_backlight(sinfo);
+}
+
 
 static struct fb_fix_screeninfo atmel_lcdfb_fix __initdata = {
        .type           = FB_TYPE_PACKED_PIXELS,
@@ -203,6 +305,26 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
        var->transp.offset = var->transp.length = 0;
        var->xoffset = var->yoffset = 0;
 
+       /* Saturate vertical and horizontal timings at maximum values */
+       var->vsync_len = min_t(u32, var->vsync_len,
+                       (ATMEL_LCDC_VPW >> ATMEL_LCDC_VPW_OFFSET) + 1);
+       var->upper_margin = min_t(u32, var->upper_margin,
+                       ATMEL_LCDC_VBP >> ATMEL_LCDC_VBP_OFFSET);
+       var->lower_margin = min_t(u32, var->lower_margin,
+                       ATMEL_LCDC_VFP);
+       var->right_margin = min_t(u32, var->right_margin,
+                       (ATMEL_LCDC_HFP >> ATMEL_LCDC_HFP_OFFSET) + 1);
+       var->hsync_len = min_t(u32, var->hsync_len,
+                       (ATMEL_LCDC_HPW >> ATMEL_LCDC_HPW_OFFSET) + 1);
+       var->left_margin = min_t(u32, var->left_margin,
+                       ATMEL_LCDC_HBP + 1);
+
+       /* Some parameters can't be zero */
+       var->vsync_len = max_t(u32, var->vsync_len, 1);
+       var->right_margin = max_t(u32, var->right_margin, 1);
+       var->hsync_len = max_t(u32, var->hsync_len, 1);
+       var->left_margin = max_t(u32, var->left_margin, 1);
+
        switch (var->bits_per_pixel) {
        case 1:
        case 2:
@@ -370,10 +492,6 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
        /* Disable all interrupts */
        lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL);
 
-       /* Set contrast */
-       value = ATMEL_LCDC_PS_DIV8 | ATMEL_LCDC_POL_POSITIVE | ATMEL_LCDC_ENA_PWMENABLE;
-       lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, value);
-       lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_VAL, ATMEL_LCDC_CVAL_DEFAULT);
        /* ...wait for DMA engine to become idle... */
        while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY)
                msleep(10);
@@ -577,6 +695,7 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
                sinfo->default_monspecs = pdata_sinfo->default_monspecs;
                sinfo->atmel_lcdfb_power_control = pdata_sinfo->atmel_lcdfb_power_control;
                sinfo->guard_time = pdata_sinfo->guard_time;
+               sinfo->lcdcon_is_backlight = pdata_sinfo->lcdcon_is_backlight;
        } else {
                dev_err(dev, "cannot get default configuration\n");
                goto free_info;
@@ -670,6 +789,9 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
                goto release_mem;
        }
 
+       /* Initialize PWM for contrast or backlight ("off") */
+       init_contrast(sinfo);
+
        /* interrupt */
        ret = request_irq(sinfo->irq_base, atmel_lcdfb_interrupt, 0, pdev->name, info);
        if (ret) {
@@ -721,6 +843,7 @@ free_cmap:
 unregister_irqs:
        free_irq(sinfo->irq_base, info);
 unmap_mmio:
+       exit_backlight(sinfo);
        iounmap(sinfo->mmio);
 release_mem:
        release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
@@ -755,6 +878,7 @@ static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
        if (!sinfo)
                return 0;
 
+       exit_backlight(sinfo);
        if (sinfo->atmel_lcdfb_power_control)
                sinfo->atmel_lcdfb_power_control(0);
        unregister_framebuffer(info);
@@ -781,6 +905,9 @@ static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
 
 static struct platform_driver atmel_lcdfb_driver = {
        .remove         = __exit_p(atmel_lcdfb_remove),
+
+// FIXME need suspend, resume
+
        .driver         = {
                .name   = "atmel_lcdfb",
                .owner  = THIS_MODULE,
index 83ee3e75386cf7a4d1676a60d30b3f621d580989..675abdafc2d8d047741ed3b8fdf2c0291343440c 100644 (file)
@@ -2561,7 +2561,7 @@ static void radeon_set_suspend(struct radeonfb_info *rinfo, int suspend)
                        pci_read_config_dword(rinfo->pdev, i * 4,
                                              &rinfo->cfg_save[i]);
 
-               /* Switch PCI power managment to D2. */
+               /* Switch PCI power management to D2. */
                pci_disable_device(rinfo->pdev);
                for (;;) {
                        pci_read_config_word(
index 9609a6c676bea96296a89cd479216dd7c6be38fd..924e2551044aee6b1f3e84b547c702ac30690412 100644 (file)
@@ -50,6 +50,19 @@ config BACKLIGHT_CLASS_DEVICE
          To have support for your specific LCD panel you will have to
          select the proper drivers which depend on this option.
 
+config BACKLIGHT_ATMEL_LCDC
+       bool "Atmel LCDC Contrast-as-Backlight control"
+       depends on BACKLIGHT_CLASS_DEVICE && FB_ATMEL
+       default y if MACH_SAM9261EK || MACH_SAM9263EK
+       help
+         This provides a backlight control internal to the Atmel LCDC
+         driver.  If the LCD "contrast control" on your board is wired
+         so it controls the backlight brightness, select this option to
+         export this as a PWM-based backlight control.
+
+         If in doubt, it's safe to enable this option; it doesn't kick
+         in unless the board's description says it's wired that way.
+
 config BACKLIGHT_CORGI
        tristate "Generic (aka Sharp Corgi) Backlight Driver"
        depends on BACKLIGHT_CLASS_DEVICE
index c8e7427a0bc8732a18122a16e966236ebff4895a..0ce791e6f79cee17b7c16072042d6b5d5b26206c 100644 (file)
@@ -498,8 +498,7 @@ static struct lcd_device *lcd_dev;
 
 static irqreturn_t bfin_bf54x_irq_error(int irq, void *dev_id)
 {
-
-       /*struct bfin_bf54xfb_info *info = (struct bfin_bf54xfb_info *)dev_id;*/
+       /*struct bfin_bf54xfb_info *info = dev_id;*/
 
        u16 status = bfin_read_EPPI0_STATUS();
 
index 308850df16fea8bafaa7c610cf954f87fc7cd866..69864b1b3f9ee149aa7f2adbf2676574d09c8d49 100644 (file)
@@ -63,7 +63,7 @@ static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,
        int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
        struct fb_fillrect region;
 
-       region.color = attr_bgcol_ec(bgshift, vc);
+       region.color = attr_bgcol_ec(bgshift, vc, info);
        region.dx = sx * vc->vc_font.width;
        region.dy = sy * vc->vc_font.height;
        region.width = width * vc->vc_font.width;
@@ -213,7 +213,7 @@ static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
        unsigned int bs = info->var.yres - bh;
        struct fb_fillrect region;
 
-       region.color = attr_bgcol_ec(bgshift, vc);
+       region.color = attr_bgcol_ec(bgshift, vc, info);
        region.rop = ROP_COPY;
 
        if (rw && !bottom_only) {
index 0f32f4a00b2df52844022b4bcdac074a1f48e98c..022282494d3fecee136f47d831e2dd4e534fe62d 100644 (file)
@@ -84,7 +84,7 @@
 #ifdef CONFIG_MAC
 #include <asm/macints.h>
 #endif
-#if defined(__mc68000__) || defined(CONFIG_APUS)
+#if defined(__mc68000__)
 #include <asm/machdep.h>
 #include <asm/setup.h>
 #endif
@@ -147,7 +147,7 @@ static char fontname[40];
 static int info_idx = -1;
 
 /* console rotation */
-static int rotate;
+static int initial_rotation;
 static int fbcon_has_sysfs;
 
 static const struct consw fb_con;
@@ -334,10 +334,7 @@ static inline int get_color(struct vc_data *vc, struct fb_info *info,
        switch (depth) {
        case 1:
        {
-               int col = ~(0xfff << (max(info->var.green.length,
-                                         max(info->var.red.length,
-                                             info->var.blue.length)))) & 0xff;
-
+               int col = mono_col(info);
                /* 0 or 1 */
                int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
                int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
@@ -537,9 +534,9 @@ static int __init fb_console_setup(char *this_opt)
                if (!strncmp(options, "rotate:", 7)) {
                        options += 7;
                        if (*options)
-                               rotate = simple_strtoul(options, &options, 0);
-                       if (rotate > 3)
-                               rotate = 0;
+                               initial_rotation = simple_strtoul(options, &options, 0);
+                       if (initial_rotation > 3)
+                               initial_rotation = 0;
                }
        }
        return 1;
@@ -989,7 +986,7 @@ static const char *fbcon_startup(void)
        ops->graphics = 1;
        ops->cur_rotate = -1;
        info->fbcon_par = ops;
-       p->con_rotate = rotate;
+       p->con_rotate = initial_rotation;
        set_blitting_type(vc, info);
 
        if (info->fix.type != FB_TYPE_TEXT) {
@@ -1176,7 +1173,7 @@ static void fbcon_init(struct vc_data *vc, int init)
                con_copy_unimap(vc, svc);
 
        ops = info->fbcon_par;
-       p->con_rotate = rotate;
+       p->con_rotate = initial_rotation;
        set_blitting_type(vc, info);
 
        cols = vc->vc_cols;
@@ -2795,7 +2792,7 @@ static int fbcon_scrolldelta(struct vc_data *vc, int lines)
 {
        struct fb_info *info = registered_fb[con2fb_map[fg_console]];
        struct fbcon_ops *ops = info->fbcon_par;
-       struct display *p = &fb_display[fg_console];
+       struct display *disp = &fb_display[fg_console];
        int offset, limit, scrollback_old;
 
        if (softback_top) {
@@ -2833,7 +2830,7 @@ static int fbcon_scrolldelta(struct vc_data *vc, int lines)
                        logo_shown = FBCON_LOGO_CANSHOW;
                }
                fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
-               fbcon_redraw_softback(vc, p, lines);
+               fbcon_redraw_softback(vc, disp, lines);
                fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
                return 0;
        }
@@ -2855,9 +2852,9 @@ static int fbcon_scrolldelta(struct vc_data *vc, int lines)
 
        fbcon_cursor(vc, CM_ERASE);
 
-       offset = p->yscroll - scrollback_current;
-       limit = p->vrows;
-       switch (p->scrollmode) {
+       offset = disp->yscroll - scrollback_current;
+       limit = disp->vrows;
+       switch (disp->scrollmode) {
        case SCROLL_WRAP_MOVE:
                info->var.vmode |= FB_VMODE_YWRAP;
                break;
index 8e6ef4bc7a5c75027ae59c8b35b4c5c5acdaead0..3706307e70ed271ddc84d70f1c02ef66c9ff604e 100644 (file)
@@ -93,10 +93,6 @@ struct fbcon_ops {
        (((s) >> (fgshift)) & 0x0f)
 #define attr_bgcol(bgshift,s)    \
        (((s) >> (bgshift)) & 0x0f)
-#define        attr_bgcol_ec(bgshift,vc) \
-       ((vc) ? (((vc)->vc_video_erase_char >> (bgshift)) & 0x0f) : 0)
-#define attr_fgcol_ec(fgshift,vc) \
-       ((vc) ? (((vc)->vc_video_erase_char >> (fgshift)) & 0x0f) : 0)
 
 /* Monochrome */
 #define attr_bold(s) \
@@ -108,6 +104,49 @@ struct fbcon_ops {
 #define attr_blink(s) \
        ((s) & 0x8000)
        
+#define mono_col(info)                                                 \
+       (~(0xfff << (max((info)->var.green.length,                      \
+                        max((info)->var.red.length,                    \
+                            (info)->var.blue.length)))) & 0xff)
+
+static inline int attr_col_ec(int shift, struct vc_data *vc,
+                             struct fb_info *info, int is_fg)
+{
+       int is_mono01;
+       int col;
+       int fg;
+       int bg;
+
+       if (!vc)
+               return 0;
+
+       if (vc->vc_can_do_color)
+               return is_fg ? attr_fgcol(shift,vc->vc_video_erase_char)
+                       : attr_bgcol(shift,vc->vc_video_erase_char);
+
+       if (!info)
+               return 0;
+
+       col = mono_col(info);
+       is_mono01 = info->fix.visual == FB_VISUAL_MONO01;
+
+       if (attr_reverse(vc->vc_video_erase_char)) {
+               fg = is_mono01 ? col : 0;
+               bg = is_mono01 ? 0 : col;
+       }
+       else {
+               fg = is_mono01 ? 0 : col;
+               bg = is_mono01 ? col : 0;
+       }
+
+       return is_fg ? fg : bg;
+}
+
+#define attr_bgcol_ec(bgshift,vc,info)         \
+       attr_col_ec(bgshift,vc,info,0);
+#define attr_fgcol_ec(fgshift,vc,info)         \
+       attr_col_ec(fgshift,vc,info,1);
+
 /* Font */
 #define REFCOUNT(fd)   (((int *)(fd))[-1])
 #define FNTSIZE(fd)    (((int *)(fd))[-2])
index 825e6d6972a72cbecb51a1194fcdaf16f0cf0a7e..bdf913ecf001de64916ede55b21c9b318743ee04 100644 (file)
@@ -84,7 +84,7 @@ static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy,
        int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
        u32 vyres = GETVYRES(ops->p->scrollmode, info);
 
-       region.color = attr_bgcol_ec(bgshift,vc);
+       region.color = attr_bgcol_ec(bgshift,vc,info);
        region.dx = sy * vc->vc_font.height;
        region.dy = vyres - ((sx + width) * vc->vc_font.width);
        region.height = width * vc->vc_font.width;
@@ -198,7 +198,7 @@ static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info,
        struct fb_fillrect region;
        int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
 
-       region.color = attr_bgcol_ec(bgshift,vc);
+       region.color = attr_bgcol_ec(bgshift,vc,info);
        region.rop = ROP_COPY;
 
        if (rw && !bottom_only) {
index c637e6318803796e6b735b2f860227543cd0107d..a6819b9d1770cccd2690e9ee4c95f52736c27d42 100644 (file)
@@ -70,7 +70,7 @@ static void cw_clear(struct vc_data *vc, struct fb_info *info, int sy,
        int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
        u32 vxres = GETVXRES(ops->p->scrollmode, info);
 
-       region.color = attr_bgcol_ec(bgshift,vc);
+       region.color = attr_bgcol_ec(bgshift,vc,info);
        region.dx = vxres - ((sy + height) * vc->vc_font.height);
        region.dy = sx *  vc->vc_font.width;
        region.height = width * vc->vc_font.width;
@@ -182,7 +182,7 @@ static void cw_clear_margins(struct vc_data *vc, struct fb_info *info,
        struct fb_fillrect region;
        int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
 
-       region.color = attr_bgcol_ec(bgshift,vc);
+       region.color = attr_bgcol_ec(bgshift,vc,info);
        region.rop = ROP_COPY;
 
        if (rw && !bottom_only) {
index 1473506df5d0654cba5d2bf6e5281ccc6b186870..d9b5d6eb68a73c4e9129a84679532dc191cf4693 100644 (file)
@@ -71,7 +71,7 @@ static void ud_clear(struct vc_data *vc, struct fb_info *info, int sy,
        u32 vyres = GETVYRES(ops->p->scrollmode, info);
        u32 vxres = GETVXRES(ops->p->scrollmode, info);
 
-       region.color = attr_bgcol_ec(bgshift,vc);
+       region.color = attr_bgcol_ec(bgshift,vc,info);
        region.dy = vyres - ((sy + height) * vc->vc_font.height);
        region.dx = vxres - ((sx + width) *  vc->vc_font.width);
        region.width = width * vc->vc_font.width;
@@ -228,7 +228,7 @@ static void ud_clear_margins(struct vc_data *vc, struct fb_info *info,
        struct fb_fillrect region;
        int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
 
-       region.color = attr_bgcol_ec(bgshift,vc);
+       region.color = attr_bgcol_ec(bgshift,vc,info);
        region.rop = ROP_COPY;
 
        if (rw && !bottom_only) {
index 96979c37751846f9143a218401d0eb6a5ec02182..d0c03fd7087141359d3d733791bbca2020de0de0 100644 (file)
@@ -15,7 +15,7 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/string.h>
-#if defined(__mc68000__) || defined(CONFIG_APUS)
+#if defined(__mc68000__)
 #include <asm/setup.h>
 #endif
 #include <linux/font.h>
@@ -120,7 +120,7 @@ const struct font_desc *get_default_font(int xres, int yres, u32 font_w,
     for(i=0; i<num_fonts; i++) {
        f = fonts[i];
        c = f->pref;
-#if defined(__mc68000__) || defined(CONFIG_APUS)
+#if defined(__mc68000__)
 #ifdef CONFIG_FONT_PEARL_8x8
        if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX)
            c = 100;
index d981fe4d86c6b18dc5396dc99a032b5f02ca455d..0056a41e5c35c2a3d323c69845a2db895a080108 100644 (file)
@@ -40,8 +40,8 @@ static void tile_clear(struct vc_data *vc, struct fb_info *info, int sy,
 
        rect.index = vc->vc_video_erase_char &
                ((vc->vc_hi_font_mask) ? 0x1ff : 0xff);
-       rect.fg = attr_fgcol_ec(fgshift, vc);
-       rect.bg = attr_bgcol_ec(bgshift, vc);
+       rect.fg = attr_fgcol_ec(fgshift, vc, info);
+       rect.bg = attr_bgcol_ec(bgshift, vc, info);
        rect.sx = sx;
        rect.sy = sy;
        rect.width = width;
index f65bcd314d54118b0b8d5fd69847fd060a352f69..6df29a62d7202552d63ced7bfc588ef8854d6c49 100644 (file)
@@ -1153,8 +1153,6 @@ static int vgacon_do_font_op(struct vgastate *state,char *arg,int set,int ch512)
 
        /* if 512 char mode is already enabled don't re-enable it. */
        if ((set) && (ch512 != vga_512_chars)) {
-               int i;  
-               
                /* attribute controller */
                for (i = 0; i < MAX_NR_CONSOLES; i++) {
                        struct vc_data *c = vc_cons[i].d;
index e23324d10be269cf60767e2a486de897e39edb37..9704b73135f54588e08c1c57075bf61491c67dd7 100644 (file)
@@ -1156,7 +1156,7 @@ static struct fb_ops cyblafb_ops __devinitdata = {
 // need altered timings to display correctly. So I decided that it is much
 // better to provide a limited optimized set of modes plus the option of
 // using the mode in effect at startup time (might be selected using the
-// vga=??? paramter). After that the user might use fbset to select any
+// vga=??? parameter). After that the user might use fbset to select any
 // mode he likes, check_var will not try to alter geometry parameters as
 // it would be necessary otherwise.
 //
index a0c5d9d90d741499e5cdb6087d138337c494b3e9..0f8cfb988c901a7f45314387149a759d8b252929 100644 (file)
@@ -25,8 +25,8 @@
 #include <linux/pagemap.h>
 
 /* this is to find and return the vmalloc-ed fb pages */
-static struct page* fb_deferred_io_nopage(struct vm_area_struct *vma,
-                                       unsigned long vaddr, int *type)
+static int fb_deferred_io_fault(struct vm_area_struct *vma,
+                               struct vm_fault *vmf)
 {
        unsigned long offset;
        struct page *page;
@@ -34,18 +34,17 @@ static struct page* fb_deferred_io_nopage(struct vm_area_struct *vma,
        /* info->screen_base is in System RAM */
        void *screen_base = (void __force *) info->screen_base;
 
-       offset = (vaddr - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
+       offset = vmf->pgoff << PAGE_SHIFT;
        if (offset >= info->fix.smem_len)
-               return NOPAGE_SIGBUS;
+               return VM_FAULT_SIGBUS;
 
        page = vmalloc_to_page(screen_base + offset);
        if (!page)
-               return NOPAGE_OOM;
+               return VM_FAULT_SIGBUS;
 
        get_page(page);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return page;
+       vmf->page = page;
+       return 0;
 }
 
 int fb_deferred_io_fsync(struct file *file, struct dentry *dentry, int datasync)
@@ -84,7 +83,7 @@ static int fb_deferred_io_mkwrite(struct vm_area_struct *vma,
 }
 
 static struct vm_operations_struct fb_deferred_io_vm_ops = {
-       .nopage         = fb_deferred_io_nopage,
+       .fault          = fb_deferred_io_fault,
        .page_mkwrite   = fb_deferred_io_mkwrite,
 };
 
index cdafbe14ef1fa511bf97f82efb3af88064ae9f55..a2a0618d86a54aa34ed7a45364e559bcc040636e 100644 (file)
@@ -91,6 +91,7 @@ static inline unsigned long fb_rev_pixels_in_long(unsigned long val,
                val = comp(val >> 2, val << 2, REV_PIXELS_MASK2);
        if (bswapmask & 3)
                val = comp(val >> 4, val << 4, REV_PIXELS_MASK4);
+       return val;
 }
 
 static inline u32 fb_shifted_pixels_mask_u32(u32 index, u32 bswapmask)
index 4ba9c08944161043fb1c9a13a3e4a0b5652dc5c7..052e180584987260a19a96a2e253b768af71f11e 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2002 James Simmons <jsimmons@users.sf.net>
  *
  * Credits:
- * 
+ *
  * The EDID Parser is a conglomeration from the following sources:
  *
  *   1. SciTech SNAP Graphics Architecture
  *
  *   2. XFree86 4.3.0, interpret_edid.c
  *      Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE>
- * 
- *   3. John Fremlin <vii@users.sourceforge.net> and 
+ *
+ *   3. John Fremlin <vii@users.sourceforge.net> and
  *      Ani Joshi <ajoshi@unixbox.com>
- *  
+ *
  * Generalized Timing Formula is derived from:
  *
- *      GTF Spreadsheet by Andy Morrish (1/5/97) 
+ *      GTF Spreadsheet by Andy Morrish (1/5/97)
  *      available at http://www.vesa.org
  *
  * This file is subject to the terms and conditions of the GNU General Public
@@ -36,7 +36,7 @@
 #endif
 #include "edid.h"
 
-/* 
+/*
  * EDID parser
  */
 
@@ -160,8 +160,8 @@ static int check_edid(unsigned char *edid)
        for (i = 0; i < ARRAY_SIZE(brokendb); i++) {
                if (!strncmp(manufacturer, brokendb[i].manufacturer, 4) &&
                        brokendb[i].model == model) {
-                       fix = brokendb[i].fix;
-                       break;
+                       fix = brokendb[i].fix;
+                       break;
                }
        }
 
@@ -323,7 +323,7 @@ static void get_dpms_capabilities(unsigned char flags,
               (flags & DPMS_SUSPEND)    ? "yes" : "no",
               (flags & DPMS_STANDBY)    ? "yes" : "no");
 }
-       
+
 static void get_chroma(unsigned char *block, struct fb_monspecs *specs)
 {
        int tmp;
@@ -365,7 +365,7 @@ static void get_chroma(unsigned char *block, struct fb_monspecs *specs)
        tmp += 512;
        specs->chroma.bluey = tmp/1024;
        DPRINTK("BlueY:    0.%03d\n", specs->chroma.bluey);
-       
+
        tmp = ((block[6] & (3 << 2)) >> 2) | (block[0xd] << 2);
        tmp *= 1000;
        tmp += 512;
@@ -383,7 +383,7 @@ static void calc_mode_timings(int xres, int yres, int refresh,
                              struct fb_videomode *mode)
 {
        struct fb_var_screeninfo *var;
-       
+
        var = kzalloc(sizeof(struct fb_var_screeninfo), GFP_KERNEL);
 
        if (var) {
@@ -451,11 +451,11 @@ static int get_est_timing(unsigned char *block, struct fb_videomode *mode)
 
        c = block[1];
        if (c&0x80) {
-               mode[num++] = vesa_modes[9];
+               mode[num++] = vesa_modes[9];
                DPRINTK("      800x600@72Hz\n");
        }
        if (c&0x40) {
-               mode[num++] = vesa_modes[10];
+               mode[num++] = vesa_modes[10];
                DPRINTK("      800x600@75Hz\n");
        }
        if (c&0x20) {
@@ -495,7 +495,7 @@ static int get_est_timing(unsigned char *block, struct fb_videomode *mode)
 static int get_std_timing(unsigned char *block, struct fb_videomode *mode)
 {
        int xres, yres = 0, refresh, ratio, i;
-       
+
        xres = (block[0] + 31) * 8;
        if (xres <= 256)
                return 0;
@@ -519,7 +519,7 @@ static int get_std_timing(unsigned char *block, struct fb_videomode *mode)
 
        DPRINTK("      %dx%d@%dHz\n", xres, yres, refresh);
        for (i = 0; i < VESA_MODEDB_SIZE; i++) {
-               if (vesa_modes[i].xres == xres && 
+               if (vesa_modes[i].xres == xres &&
                    vesa_modes[i].yres == yres &&
                    vesa_modes[i].refresh == refresh) {
                        *mode = vesa_modes[i];
@@ -536,13 +536,13 @@ static int get_dst_timing(unsigned char *block,
 {
        int j, num = 0;
 
-       for (j = 0; j < 6; j++, block+= STD_TIMING_DESCRIPTION_SIZE) 
+       for (j = 0; j < 6; j++, block += STD_TIMING_DESCRIPTION_SIZE)
                num += get_std_timing(block, &mode[num]);
 
        return num;
 }
 
-static void get_detailed_timing(unsigned char *block, 
+static void get_detailed_timing(unsigned char *block,
                                struct fb_videomode *mode)
 {
        mode->xres = H_ACTIVE;
@@ -553,7 +553,7 @@ static void get_detailed_timing(unsigned char *block,
        mode->right_margin = H_SYNC_OFFSET;
        mode->left_margin = (H_ACTIVE + H_BLANKING) -
                (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH);
-       mode->upper_margin = V_BLANKING - V_SYNC_OFFSET - 
+       mode->upper_margin = V_BLANKING - V_SYNC_OFFSET -
                V_SYNC_WIDTH;
        mode->lower_margin = V_SYNC_OFFSET;
        mode->hsync_len = H_SYNC_WIDTH;
@@ -597,7 +597,7 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
        if (mode == NULL)
                return NULL;
 
-       if (edid == NULL || !edid_checksum(edid) || 
+       if (edid == NULL || !edid_checksum(edid) ||
            !edid_check_header(edid)) {
                kfree(mode);
                return NULL;
@@ -632,7 +632,7 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
                if (block[0] == 0x00 && block[1] == 0x00 && block[3] == 0xfa)
                        num += get_dst_timing(block + 5, &mode[num]);
        }
-       
+
        /* Yikes, EDID data is totally useless */
        if (!num) {
                kfree(mode);
@@ -686,7 +686,7 @@ static int fb_get_monitor_limits(unsigned char *edid, struct fb_monspecs *specs)
        /* estimate monitor limits based on modes supported */
        if (retval) {
                struct fb_videomode *modes, *mode;
-               int num_modes, i, hz, hscan, pixclock;
+               int num_modes, hz, hscan, pixclock;
                int vtotal, htotal;
 
                modes = fb_create_modedb(edid, &num_modes);
@@ -713,7 +713,7 @@ static int fb_get_monitor_limits(unsigned char *edid, struct fb_monspecs *specs)
                        hscan = (pixclock + htotal / 2) / htotal;
                        hscan = (hscan + 500) / 1000 * 1000;
                        hz = (hscan + vtotal / 2) / vtotal;
-                       
+
                        if (specs->dclkmax == 0 || specs->dclkmax < pixclock)
                                specs->dclkmax = pixclock;
 
@@ -966,8 +966,8 @@ void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
        DPRINTK("========================================\n");
 }
 
-/* 
- * VESA Generalized Timing Formula (GTF) 
+/*
+ * VESA Generalized Timing Formula (GTF)
  */
 
 #define FLYBACK                     550
@@ -996,7 +996,7 @@ struct __fb_timings {
  * @hfreq: horizontal freq
  *
  * DESCRIPTION:
- * vblank = right_margin + vsync_len + left_margin 
+ * vblank = right_margin + vsync_len + left_margin
  *
  *    given: right_margin = 1 (V_FRONTPORCH)
  *           vsync_len    = 3
@@ -1010,12 +1010,12 @@ static u32 fb_get_vblank(u32 hfreq)
 {
        u32 vblank;
 
-       vblank = (hfreq * FLYBACK)/1000; 
+       vblank = (hfreq * FLYBACK)/1000;
        vblank = (vblank + 500)/1000;
        return (vblank + V_FRONTPORCH);
 }
 
-/** 
+/**
  * fb_get_hblank_by_freq - get horizontal blank time given hfreq
  * @hfreq: horizontal freq
  * @xres: horizontal resolution in pixels
@@ -1031,7 +1031,7 @@ static u32 fb_get_vblank(u32 hfreq)
  *
  * where: C = ((offset - scale factor) * blank_scale)
  *            -------------------------------------- + scale factor
- *                        256 
+ *                        256
  *        M = blank_scale * gradient
  *
  */
@@ -1039,7 +1039,7 @@ static u32 fb_get_hblank_by_hfreq(u32 hfreq, u32 xres)
 {
        u32 c_val, m_val, duty_cycle, hblank;
 
-       c_val = (((H_OFFSET - H_SCALEFACTOR) * H_BLANKSCALE)/256 + 
+       c_val = (((H_OFFSET - H_SCALEFACTOR) * H_BLANKSCALE)/256 +
                 H_SCALEFACTOR) * 1000;
        m_val = (H_BLANKSCALE * H_GRADIENT)/256;
        m_val = (m_val * 1000000)/hfreq;
@@ -1048,7 +1048,7 @@ static u32 fb_get_hblank_by_hfreq(u32 hfreq, u32 xres)
        return (hblank);
 }
 
-/** 
+/**
  * fb_get_hblank_by_dclk - get horizontal blank time given pixelclock
  * @dclk: pixelclock in Hz
  * @xres: horizontal resolution in pixels
@@ -1061,7 +1061,7 @@ static u32 fb_get_hblank_by_hfreq(u32 hfreq, u32 xres)
  *
  * duty cycle = percent of htotal assigned to inactive display
  * duty cycle = C - (M * h_period)
- * 
+ *
  * where: h_period = SQRT(100 - C + (0.4 * xres * M)/dclk) + C - 100
  *                   -----------------------------------------------
  *                                    2 * M
@@ -1077,11 +1077,11 @@ static u32 fb_get_hblank_by_dclk(u32 dclk, u32 xres)
        h_period = 100 - C_VAL;
        h_period *= h_period;
        h_period += (M_VAL * xres * 2 * 1000)/(5 * dclk);
-       h_period *=10000; 
+       h_period *= 10000;
 
        h_period = int_sqrt(h_period);
        h_period -= (100 - C_VAL) * 100;
-       h_period *= 1000; 
+       h_period *= 1000;
        h_period /= 2 * M_VAL;
 
        duty_cycle = C_VAL * 1000 - (M_VAL * h_period)/100;
@@ -1089,7 +1089,7 @@ static u32 fb_get_hblank_by_dclk(u32 dclk, u32 xres)
        hblank &= ~15;
        return (hblank);
 }
-       
+
 /**
  * fb_get_hfreq - estimate hsync
  * @vfreq: vertical refresh rate
@@ -1100,13 +1100,13 @@ static u32 fb_get_hblank_by_dclk(u32 dclk, u32 xres)
  *          (yres + front_port) * vfreq * 1000000
  * hfreq = -------------------------------------
  *          (1000000 - (vfreq * FLYBACK)
- * 
+ *
  */
 
 static u32 fb_get_hfreq(u32 vfreq, u32 yres)
 {
        u32 divisor, hfreq;
-       
+
        divisor = (1000000 - (vfreq * FLYBACK))/1000;
        hfreq = (yres + V_FRONTPORCH) * vfreq  * 1000;
        return (hfreq/divisor);
@@ -1117,7 +1117,7 @@ static void fb_timings_vfreq(struct __fb_timings *timings)
        timings->hfreq = fb_get_hfreq(timings->vfreq, timings->vactive);
        timings->vblank = fb_get_vblank(timings->hfreq);
        timings->vtotal = timings->vactive + timings->vblank;
-       timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq, 
+       timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq,
                                                 timings->hactive);
        timings->htotal = timings->hactive + timings->hblank;
        timings->dclk = timings->htotal * timings->hfreq;
@@ -1128,7 +1128,7 @@ static void fb_timings_hfreq(struct __fb_timings *timings)
        timings->vblank = fb_get_vblank(timings->hfreq);
        timings->vtotal = timings->vactive + timings->vblank;
        timings->vfreq = timings->hfreq/timings->vtotal;
-       timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq, 
+       timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq,
                                                 timings->hactive);
        timings->htotal = timings->hactive + timings->hblank;
        timings->dclk = timings->htotal * timings->hfreq;
@@ -1136,7 +1136,7 @@ static void fb_timings_hfreq(struct __fb_timings *timings)
 
 static void fb_timings_dclk(struct __fb_timings *timings)
 {
-       timings->hblank = fb_get_hblank_by_dclk(timings->dclk, 
+       timings->hblank = fb_get_hblank_by_dclk(timings->dclk,
                                                timings->hactive);
        timings->htotal = timings->hactive + timings->hblank;
        timings->hfreq = timings->dclk/timings->htotal;
@@ -1156,29 +1156,29 @@ static void fb_timings_dclk(struct __fb_timings *timings)
  * @info: pointer to fb_info
  *
  * DESCRIPTION:
- * Calculates video mode based on monitor specs using VESA GTF. 
- * The GTF is best for VESA GTF compliant monitors but is 
+ * Calculates video mode based on monitor specs using VESA GTF.
+ * The GTF is best for VESA GTF compliant monitors but is
  * specifically formulated to work for older monitors as well.
  *
- * If @flag==0, the function will attempt to maximize the 
+ * If @flag==0, the function will attempt to maximize the
  * refresh rate.  Otherwise, it will calculate timings based on
- * the flag and accompanying value.  
+ * the flag and accompanying value.
  *
- * If FB_IGNOREMON bit is set in @flags, monitor specs will be 
+ * If FB_IGNOREMON bit is set in @flags, monitor specs will be
  * ignored and @var will be filled with the calculated timings.
  *
  * All calculations are based on the VESA GTF Spreadsheet
  * available at VESA's public ftp (http://www.vesa.org).
- * 
+ *
  * NOTES:
  * The timings generated by the GTF will be different from VESA
  * DMT.  It might be a good idea to keep a table of standard
  * VESA modes as well.  The GTF may also not work for some displays,
  * such as, and especially, analog TV.
- *   
+ *
  * REQUIRES:
  * A valid info->monspecs, otherwise 'safe numbers' will be used.
- */ 
+ */
 int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_info *info)
 {
        struct __fb_timings *timings;
@@ -1191,7 +1191,7 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf
        if (!timings)
                return -ENOMEM;
 
-       /* 
+       /*
         * If monspecs are invalid, use values that are enough
         * for 640x480@60
         */
@@ -1214,7 +1214,7 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf
 
        timings->hactive = var->xres;
        timings->vactive = var->yres;
-       if (var->vmode & FB_VMODE_INTERLACED) { 
+       if (var->vmode & FB_VMODE_INTERLACED) {
                timings->vactive /= 2;
                interlace = 2;
        }
@@ -1250,9 +1250,9 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf
                break;
        default:
                err = -EINVAL;
-               
-       } 
-       
+
+       }
+
        if (err || (!(flags & FB_IGNOREMON) &&
            (timings->vfreq < vfmin || timings->vfreq > vfmax ||
             timings->hfreq < hfmin || timings->hfreq > hfmax ||
@@ -1269,7 +1269,7 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf
                var->upper_margin = (timings->vblank * interlace)/dscan -
                        (var->vsync_len + var->lower_margin);
        }
-       
+
        kfree(timings);
        return err;
 }
@@ -1291,7 +1291,7 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var,
        return -EINVAL;
 }
 #endif /* CONFIG_FB_MODE_HELPERS */
-       
+
 /*
  * fb_validate_mode - validates var against monitor capabilities
  * @var: pointer to fb_var_screeninfo
@@ -1309,7 +1309,7 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
        u32 hfreq, vfreq, htotal, vtotal, pixclock;
        u32 hfmin, hfmax, vfmin, vfmax, dclkmin, dclkmax;
 
-       /* 
+       /*
         * If monspecs are invalid, use values that are enough
         * for 640x480@60
         */
@@ -1333,10 +1333,10 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
        if (!var->pixclock)
                return -EINVAL;
        pixclock = PICOS2KHZ(var->pixclock) * 1000;
-          
-       htotal = var->xres + var->right_margin + var->hsync_len + 
+
+       htotal = var->xres + var->right_margin + var->hsync_len +
                var->left_margin;
-       vtotal = var->yres + var->lower_margin + var->vsync_len + 
+       vtotal = var->yres + var->lower_margin + var->vsync_len +
                var->upper_margin;
 
        if (var->vmode & FB_VMODE_INTERLACED)
@@ -1349,7 +1349,7 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
 
        vfreq = hfreq/vtotal;
 
-       return (vfreq < vfmin || vfreq > vfmax || 
+       return (vfreq < vfmin || vfreq > vfmax ||
                hfreq < hfmin || hfreq > hfmax ||
                pixclock < dclkmin || pixclock > dclkmax) ?
                -EINVAL : 0;
index 583185fd7c94b0d50241d6a9d0f49f53b72b59ec..eb6b881715387bbdbc4226ff801d4f5cc3f193ac 100644 (file)
@@ -34,7 +34,7 @@ static int fbsize;
  * we try to make it something sane - 640x480-60 is sane
  */
 
-const struct fb_videomode geode_modedb[] __initdata = {
+static const struct fb_videomode geode_modedb[] __initdata = {
        /* 640x480-60 */
        { NULL, 60, 640, 480, 39682, 48, 8, 25, 2, 88, 2,
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
index b18486ad8e17fc11fbea0d9c9e657602c10a13da..2eb4fb15908404e8926d6342b88faed3d64d180b 100644 (file)
@@ -207,7 +207,8 @@ static struct fb_ops hpfb_ops = {
 #define HPFB_FBOMSB    0x5d    /* Frame buffer offset          */
 #define HPFB_FBOLSB    0x5f
 
-static int __init hpfb_init_one(unsigned long phys_base, unsigned long virt_base)
+static int __devinit hpfb_init_one(unsigned long phys_base,
+                                  unsigned long virt_base)
 {
        unsigned long fboff, fb_width, fb_height, fb_start;
 
index 1a7d7789d8772f600c6bb3100b86b50b68a45dab..1d13dd099af81236af440329cf65727b9689b6d9 100644 (file)
@@ -1476,7 +1476,7 @@ static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
        struct i810fb_par *par = info->par;
        u8 __iomem *mmio = par->mmio_start_virtual;
 
-       if (!par->dev_flags & LOCKUP)
+       if (!(par->dev_flags & LOCKUP))
                return -ENXIO;
 
        if (cursor->image.width > 64 || cursor->image.height > 64)
index b87ea21d3d78480faeca4bdc5f06d71aea4fe2b6..3a81060137a22bd29176d885a2cec1facf3c599b 100644 (file)
@@ -400,6 +400,7 @@ int __init igafb_init(void)
         info = kzalloc(size, GFP_ATOMIC);
         if (!info) {
                 printk("igafb_init: can't alloc fb_info\n");
+                pci_dev_put(pdev);
                 return -ENOMEM;
         }
 
@@ -409,12 +410,14 @@ int __init igafb_init(void)
        if ((addr = pdev->resource[0].start) == 0) {
                 printk("igafb_init: no memory start\n");
                kfree(info);
+               pci_dev_put(pdev);
                return -ENXIO;
        }
 
        if ((info->screen_base = ioremap(addr, 1024*1024*2)) == 0) {
                 printk("igafb_init: can't remap %lx[2M]\n", addr);
                kfree(info);
+               pci_dev_put(pdev);
                return -ENXIO;
        }
 
@@ -449,6 +452,7 @@ int __init igafb_init(void)
                 printk("igafb_init: can't remap %lx[4K]\n", igafb_fix.mmio_start);
                iounmap((void *)info->screen_base);
                kfree(info);
+               pci_dev_put(pdev);
                return -ENXIO;
        }
 
@@ -466,6 +470,7 @@ int __init igafb_init(void)
                iounmap((void *)par->io_base);
                iounmap(info->screen_base);
                kfree(info);
+               pci_dev_put(pdev);
                return -ENOMEM;
        }
 
index 2fe3f7def5305ed5c422c0bed9db2a558bf591b4..8367961779420c275b0b5e2f0a693b2f702fa73c 100644 (file)
 
 #define FIXED_MODE(d) ((d)->fixed_mode)
 
-/*** Driver paramters ***/
+/*** Driver parameters ***/
 
 #define RINGBUFFER_SIZE                KB(64)
 #define HW_CURSOR_SIZE         KB(4)
index 5f6fb7d2c40898ab2dfaef590dc855876942b88e..fa1fff5535654e4f6bbce1c294efd9031d16d1a2 100644 (file)
@@ -1971,7 +1971,7 @@ void intelfbhw_cursor_reset(struct intelfb_info *dinfo)
 static irqreturn_t intelfbhw_irq(int irq, void *dev_id)
 {
        u16 tmp;
-       struct intelfb_info *dinfo = (struct intelfb_info *)dev_id;
+       struct intelfb_info *dinfo = dev_id;
 
        spin_lock(&dinfo->int_lock);
 
index 4b6a99b5be0d7ba5c720bf5f4e09d43da93897ac..5246b0402d76ce7bedd9504c460b34a36bcca9b2 100644 (file)
@@ -2066,40 +2066,49 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const st
 
        switch (info->fix.accel) {
        case FB_ACCEL_NEOMAGIC_NM2070:
-               sprintf(info->fix.id, "MagicGraph 128");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 128");
                break;
        case FB_ACCEL_NEOMAGIC_NM2090:
-               sprintf(info->fix.id, "MagicGraph 128V");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 128V");
                break;
        case FB_ACCEL_NEOMAGIC_NM2093:
-               sprintf(info->fix.id, "MagicGraph 128ZV");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 128ZV");
                break;
        case FB_ACCEL_NEOMAGIC_NM2097:
-               sprintf(info->fix.id, "MagicGraph 128ZV+");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 128ZV+");
                break;
        case FB_ACCEL_NEOMAGIC_NM2160:
-               sprintf(info->fix.id, "MagicGraph 128XD");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 128XD");
                break;
        case FB_ACCEL_NEOMAGIC_NM2200:
-               sprintf(info->fix.id, "MagicGraph 256AV");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 256AV");
                info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
                               FBINFO_HWACCEL_COPYAREA |
                               FBINFO_HWACCEL_FILLRECT;
                break;
        case FB_ACCEL_NEOMAGIC_NM2230:
-               sprintf(info->fix.id, "MagicGraph 256AV+");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 256AV+");
                info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
                               FBINFO_HWACCEL_COPYAREA |
                               FBINFO_HWACCEL_FILLRECT;
                break;
        case FB_ACCEL_NEOMAGIC_NM2360:
-               sprintf(info->fix.id, "MagicGraph 256ZX");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 256ZX");
                info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
                               FBINFO_HWACCEL_COPYAREA |
                               FBINFO_HWACCEL_FILLRECT;
                break;
        case FB_ACCEL_NEOMAGIC_NM2380:
-               sprintf(info->fix.id, "MagicGraph 256XL+");
+               snprintf(info->fix.id, sizeof(info->fix.id),
+                               "MagicGraph 256XL+");
                info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
                               FBINFO_HWACCEL_COPYAREA |
                               FBINFO_HWACCEL_FILLRECT;
index 30e14eb1f51e60e126166fa0c94d3a3cc08741f9..74517b1b26a6d2bfd8c7c79fa018b86df2b20dc3 100644 (file)
@@ -849,9 +849,27 @@ static int nvidiafb_check_var(struct fb_var_screeninfo *var,
        if (!mode_valid && info->monspecs.modedb_len)
                return -EINVAL;
 
+       /*
+        * If we're on a flat panel, check if the mode is outside of the
+        * panel dimensions. If so, cap it and try for the next best mode
+        * before bailing out.
+        */
        if (par->fpWidth && par->fpHeight && (par->fpWidth < var->xres ||
-                                             par->fpHeight < var->yres))
-               return -EINVAL;
+                                             par->fpHeight < var->yres)) {
+               const struct fb_videomode *mode;
+
+               var->xres = par->fpWidth;
+               var->yres = par->fpHeight;
+
+               mode = fb_find_best_mode(var, &info->modelist);
+               if (!mode) {
+                       printk(KERN_ERR PFX "mode out of range of flat "
+                              "panel dimensions\n");
+                       return -EINVAL;
+               }
+
+               fb_videomode_to_var(var, mode);
+       }
 
        if (var->yres_virtual < var->yres)
                var->yres_virtual = var->yres;
index 9085188d815e0bd1e301523351f71eed38bb25cb..fb19ed4992dbc670d9f89c017995bd8c8faa9d5d 100644 (file)
@@ -312,7 +312,7 @@ static irqreturn_t lcdc_irq_handler(int irq, void *dev_id)
 /*
  * Change to a new video mode. We defer this to a later time to avoid any
  * flicker and not to mess up the current LCD DMA context. For this we disable
- * the LCD controler, which will generate a DONE irq after the last frame has
+ * the LCD controller, which will generate a DONE irq after the last frame has
  * been transferred. Then it'll be safe to reconfigure both the LCD controller
  * as well as the LCD DMA.
  */
index 5591dfb22b18fe2710942d3647cb374a4c0dc526..30181b593829b1e94fe6d5229965d8894c4357cd 100644 (file)
@@ -1159,6 +1159,11 @@ static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image)
        u32 fgx, bgx;
        const u32 *src = (const u32 *)image->data;
        u32 xres = (info->var.xres + 31) & ~31;
+       int raster_mode = 1; /* invert bits */
+
+#ifdef __LITTLE_ENDIAN
+       raster_mode |= 3 << 7; /* reverse byte order */
+#endif
 
        if (info->state != FBINFO_STATE_RUNNING)
                return;
@@ -1208,9 +1213,8 @@ static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image)
                pm2_WR(par, PM2R_RENDER,
                        PM2F_RENDER_RECTANGLE |
                        PM2F_INCREASE_X | PM2F_INCREASE_Y);
-               /* BitMapPackEachScanline & invert bits and byte order*/
-               /* force background */
-               pm2_WR(par, PM2R_RASTERIZER_MODE,  (1 << 9) | 1 | (3 << 7));
+               /* BitMapPackEachScanline */
+               pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode | (1 << 9));
                pm2_WR(par, PM2R_CONSTANT_COLOR, fgx);
                pm2_WR(par, PM2R_RENDER,
                        PM2F_RENDER_RECTANGLE |
@@ -1224,8 +1228,7 @@ static void pm2fb_imageblit(struct fb_info *info, const struct fb_image *image)
                        PM2F_RENDER_RECTANGLE |
                        PM2F_RENDER_FASTFILL |
                        PM2F_INCREASE_X | PM2F_INCREASE_Y);
-               /* invert bits and byte order*/
-               pm2_WR(par, PM2R_RASTERIZER_MODE,  1 | (3 << 7));
+               pm2_WR(par, PM2R_RASTERIZER_MODE, raster_mode);
                pm2_WR(par, PM2R_FB_BLOCK_COLOR, fgx);
                pm2_WR(par, PM2R_RENDER,
                        PM2F_RENDER_RECTANGLE |
index 070659992c1841bd6fccac6f9d2abd56ec174011..5dba8cdd05173709c2365559c11d6b760a052adc 100644 (file)
@@ -1227,7 +1227,7 @@ static struct fb_ops pm3fb_ops = {
 
 /* mmio register are already mapped when this function is called */
 /* the pm3fb_fix.smem_start is also set */
-static unsigned long pm3fb_size_memory(struct pm3_par *par)
+static unsigned long __devinit pm3fb_size_memory(struct pm3_par *par)
 {
        unsigned long   memsize = 0;
        unsigned long   tempBypass, i, temp1, temp2;
index a864438b6008bcde0d9baba19821f13fff1b6435..6515ec11c16ba250f55f6cbe6a10b6a74f7effca 100644 (file)
@@ -150,7 +150,7 @@ static int aafbcon_set_font(struct display *disp, int width, int height)
 {
        struct aafb_info *info = (struct aafb_info *)disp->fb_info;
        struct aafb_cursor *c = &info->cursor;
-       u8 fgc = ~attr_bgcol_ec(disp, disp->conp);
+       u8 fgc = ~attr_bgcol_ec(disp, disp->conp, &info->info);
 
        if (width > 64 || height > 64 || width < 0 || height < 0)
                return -EINVAL;
index 044a423a72cbe406e0a5811796b246cb788f1ec3..dc3af1c78c56ce2fff1fa32a5f8961ae727a496a 100644 (file)
@@ -57,8 +57,6 @@
 #define GPU_ALIGN_UP(x)                                _ALIGN_UP((x), 64)
 #define GPU_MAX_LINE_LENGTH                    (65536 - 64)
 
-#define PS3FB_FULL_MODE_BIT                    0x80
-
 #define GPU_INTR_STATUS_VSYNC_0                        0       /* vsync on head A */
 #define GPU_INTR_STATUS_VSYNC_1                        1       /* vsync on head B */
 #define GPU_INTR_STATUS_FLIP_0                 3       /* flip head A */
@@ -118,8 +116,6 @@ struct ps3fb_priv {
        unsigned int irq_no;
 
        u64 context_handle, memory_handle;
-       void *xdr_ea;
-       size_t xdr_size;
        struct gpu_driver_info *dinfo;
 
        u64 vblank_count;       /* frame count */
@@ -136,42 +132,19 @@ static struct ps3fb_priv ps3fb;
 struct ps3fb_par {
        u32 pseudo_palette[16];
        int mode_id, new_mode_id;
-       int res_index;
        unsigned int num_frames;        /* num of frame buffers */
        unsigned int width;
        unsigned int height;
-       unsigned long full_offset;      /* start of fullscreen DDR fb */
-       unsigned long fb_offset;        /* start of actual DDR fb */
-       unsigned long pan_offset;
+       unsigned int ddr_line_length;
+       unsigned int ddr_frame_size;
+       unsigned int xdr_frame_size;
+       unsigned int full_offset;       /* start of fullscreen DDR fb */
+       unsigned int fb_offset;         /* start of actual DDR fb */
+       unsigned int pan_offset;
 };
 
-struct ps3fb_res_table {
-       u32 xres;
-       u32 yres;
-       u32 xoff;
-       u32 yoff;
-       u32 type;
-};
-#define PS3FB_RES_FULL 1
-static const struct ps3fb_res_table ps3fb_res[] = {
-       /* res_x,y   margin_x,y  full */
-       {  720,  480,  72,  48 , 0},
-       {  720,  576,  72,  58 , 0},
-       { 1280,  720,  78,  38 , 0},
-       { 1920, 1080, 116,  58 , 0},
-       /* full mode */
-       {  720,  480,   0,   0 , PS3FB_RES_FULL},
-       {  720,  576,   0,   0 , PS3FB_RES_FULL},
-       { 1280,  720,   0,   0 , PS3FB_RES_FULL},
-       { 1920, 1080,   0,   0 , PS3FB_RES_FULL},
-       /* vesa: normally full mode */
-       { 1280,  768,   0,   0 , 0},
-       { 1280, 1024,   0,   0 , 0},
-       { 1920, 1200,   0,   0 , 0},
-       {    0,    0,   0,   0 , 0} };
-
-/* default resolution */
-#define GPU_RES_INDEX  0               /* 720 x 480 */
+
+#define FIRST_NATIVE_MODE_INDEX        10
 
 static const struct fb_videomode ps3fb_modedb[] = {
     /* 60 Hz broadcast modes (modes "1" to "5") */
@@ -211,7 +184,7 @@ static const struct fb_videomode ps3fb_modedb[] = {
         "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
     },    {
-        /* 1080 */
+        /* 1080i */
         "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
         FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
     },    {
@@ -220,24 +193,7 @@ static const struct fb_videomode ps3fb_modedb[] = {
         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
     },
 
-    /* VESA modes (modes "11" to "13") */
-    {
-       /* WXGA */
-       "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
-       0, FB_VMODE_NONINTERLACED,
-       FB_MODE_IS_VESA
-    }, {
-       /* SXGA */
-       "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
-       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
-       FB_MODE_IS_VESA
-    }, {
-       /* WUXGA */
-       "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
-       FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
-       FB_MODE_IS_VESA
-    },
-
+    [FIRST_NATIVE_MODE_INDEX] =
     /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */
     {
        /* 480if */
@@ -276,12 +232,30 @@ static const struct fb_videomode ps3fb_modedb[] = {
        FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
     }, {
        /* 1080if */
-       "1080f", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
+       "1080if", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
        FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
     }, {
        /* 1080pf */
        "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
        FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
+    },
+
+    /* VESA modes (modes "11" to "13") */
+    {
+       /* WXGA */
+       "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
+       0, FB_VMODE_NONINTERLACED,
+       FB_MODE_IS_VESA
+    }, {
+       /* SXGA */
+       "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
+       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
+       FB_MODE_IS_VESA
+    }, {
+       /* WUXGA */
+       "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
+       FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
+       FB_MODE_IS_VESA
     }
 };
 
@@ -289,110 +263,188 @@ static const struct fb_videomode ps3fb_modedb[] = {
 #define HEAD_A
 #define HEAD_B
 
-#define X_OFF(i)       (ps3fb_res[i].xoff)     /* left/right margin (pixel) */
-#define Y_OFF(i)       (ps3fb_res[i].yoff)     /* top/bottom margin (pixel) */
-#define WIDTH(i)       (ps3fb_res[i].xres)     /* width of FB */
-#define HEIGHT(i)      (ps3fb_res[i].yres)     /* height of FB */
 #define BPP            4                       /* number of bytes per pixel */
 
-/* Start of the virtual frame buffer (relative to fullscreen ) */
-#define VP_OFF(i)      ((WIDTH(i) * Y_OFF(i) + X_OFF(i)) * BPP)
-
 
 static int ps3fb_mode;
 module_param(ps3fb_mode, int, 0);
 
 static char *mode_option __devinitdata;
 
-static int ps3fb_get_res_table(u32 xres, u32 yres, int mode)
+static int ps3fb_cmp_mode(const struct fb_videomode *vmode,
+                         const struct fb_var_screeninfo *var)
 {
-       int full_mode;
-       unsigned int i;
-       u32 x, y, f;
-
-       full_mode = (mode & PS3FB_FULL_MODE_BIT) ? PS3FB_RES_FULL : 0;
-       for (i = 0;; i++) {
-               x = ps3fb_res[i].xres;
-               y = ps3fb_res[i].yres;
-               f = ps3fb_res[i].type;
-
-               if (!x) {
-                       pr_debug("ERROR: ps3fb_get_res_table()\n");
-                       return -1;
-               }
+       long xres, yres, left_margin, right_margin, upper_margin, lower_margin;
+       long dx, dy;
+
+       /* maximum values */
+       if (var->xres > vmode->xres || var->yres > vmode->yres ||
+           var->pixclock > vmode->pixclock ||
+           var->hsync_len > vmode->hsync_len ||
+           var->vsync_len > vmode->vsync_len)
+               return -1;
 
-               if (full_mode == PS3FB_RES_FULL && f != PS3FB_RES_FULL)
-                       continue;
+       /* progressive/interlaced must match */
+       if ((var->vmode & FB_VMODE_MASK) != vmode->vmode)
+               return -1;
 
-               if (x == xres && (yres == 0 || y == yres))
-                       break;
+       /* minimum resolution */
+       xres = max(var->xres, 1U);
+       yres = max(var->yres, 1U);
+
+       /* minimum margins */
+       left_margin = max(var->left_margin, vmode->left_margin);
+       right_margin = max(var->right_margin, vmode->right_margin);
+       upper_margin = max(var->upper_margin, vmode->upper_margin);
+       lower_margin = max(var->lower_margin, vmode->lower_margin);
+
+       /* resolution + margins may not exceed native parameters */
+       dx = ((long)vmode->left_margin + (long)vmode->xres +
+             (long)vmode->right_margin) -
+            (left_margin + xres + right_margin);
+       if (dx < 0)
+               return -1;
 
-               x = x - 2 * ps3fb_res[i].xoff;
-               y = y - 2 * ps3fb_res[i].yoff;
-               if (x == xres && (yres == 0 || y == yres))
-                       break;
+       dy = ((long)vmode->upper_margin + (long)vmode->yres +
+             (long)vmode->lower_margin) -
+            (upper_margin + yres + lower_margin);
+       if (dy < 0)
+               return -1;
+
+       /* exact match */
+       if (!dx && !dy)
+               return 0;
+
+       /* resolution difference */
+       return (vmode->xres - xres) * (vmode->yres - yres);
+}
+
+static const struct fb_videomode *ps3fb_native_vmode(enum ps3av_mode_num id)
+{
+       return &ps3fb_modedb[FIRST_NATIVE_MODE_INDEX + id - 1];
+}
+
+static const struct fb_videomode *ps3fb_vmode(int id)
+{
+       u32 mode = id & PS3AV_MODE_MASK;
+
+       if (mode < PS3AV_MODE_480I || mode > PS3AV_MODE_WUXGA)
+               return NULL;
+
+       if (mode <= PS3AV_MODE_1080P50 && !(id & PS3AV_MODE_FULL)) {
+               /* Non-fullscreen broadcast mode */
+               return &ps3fb_modedb[mode - 1];
        }
-       return i;
+
+       return ps3fb_native_vmode(mode);
 }
 
-static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
+static unsigned int ps3fb_find_mode(struct fb_var_screeninfo *var,
                                    u32 *ddr_line_length, u32 *xdr_line_length)
 {
-       unsigned int i, mode;
-
-       for (i = 0; i < ARRAY_SIZE(ps3fb_modedb); i++)
-               if (var->xres == ps3fb_modedb[i].xres &&
-                   var->yres == ps3fb_modedb[i].yres &&
-                   var->pixclock == ps3fb_modedb[i].pixclock &&
-                   var->hsync_len == ps3fb_modedb[i].hsync_len &&
-                   var->vsync_len == ps3fb_modedb[i].vsync_len &&
-                   var->left_margin == ps3fb_modedb[i].left_margin &&
-                   var->right_margin == ps3fb_modedb[i].right_margin &&
-                   var->upper_margin == ps3fb_modedb[i].upper_margin &&
-                   var->lower_margin == ps3fb_modedb[i].lower_margin &&
-                   var->sync == ps3fb_modedb[i].sync &&
-                   (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode)
-                       goto found;
-
-       pr_debug("ps3fb_find_mode: mode not found\n");
-       return 0;
+       unsigned int id, best_id;
+       int diff, best_diff;
+       const struct fb_videomode *vmode;
+       long gap;
+
+       best_id = 0;
+       best_diff = INT_MAX;
+       pr_debug("%s: wanted %u [%u] %u x %u [%u] %u\n", __func__,
+                var->left_margin, var->xres, var->right_margin,
+                var->upper_margin, var->yres, var->lower_margin);
+       for (id = PS3AV_MODE_480I; id <= PS3AV_MODE_WUXGA; id++) {
+               vmode = ps3fb_native_vmode(id);
+               diff = ps3fb_cmp_mode(vmode, var);
+               pr_debug("%s: mode %u: %u [%u] %u x %u [%u] %u: diff = %d\n",
+                        __func__, id, vmode->left_margin, vmode->xres,
+                        vmode->right_margin, vmode->upper_margin,
+                        vmode->yres, vmode->lower_margin, diff);
+               if (diff < 0)
+                       continue;
+               if (diff < best_diff) {
+                       best_id = id;
+                       if (!diff)
+                               break;
+                       best_diff = diff;
+               }
+       }
 
-found:
-       /* Cropped broadcast modes use the full line length */
-       *ddr_line_length = ps3fb_modedb[i < 10 ? i + 13 : i].xres * BPP;
+       if (!best_id) {
+               pr_debug("%s: no suitable mode found\n", __func__);
+               return 0;
+       }
 
-       if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
-               *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
-                                                   var->xres_virtual) * BPP);
-               if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
-                       *xdr_line_length = GPU_MAX_LINE_LENGTH;
-       } else
-               *xdr_line_length = *ddr_line_length;
+       id = best_id;
+       vmode = ps3fb_native_vmode(id);
 
-       /* Full broadcast modes have the full mode bit set */
-       mode = i > 12 ? (i - 12) | PS3FB_FULL_MODE_BIT : i + 1;
+       *ddr_line_length = vmode->xres * BPP;
 
-       pr_debug("ps3fb_find_mode: mode %u\n", mode);
+       /* minimum resolution */
+       if (!var->xres)
+               var->xres = 1;
+       if (!var->yres)
+               var->yres = 1;
 
-       return mode;
-}
+       /* minimum virtual resolution */
+       if (var->xres_virtual < var->xres)
+               var->xres_virtual = var->xres;
+       if (var->yres_virtual < var->yres)
+               var->yres_virtual = var->yres;
 
-static const struct fb_videomode *ps3fb_default_mode(int id)
-{
-       u32 mode = id & PS3AV_MODE_MASK;
-       u32 flags;
+       /* minimum margins */
+       if (var->left_margin < vmode->left_margin)
+               var->left_margin = vmode->left_margin;
+       if (var->right_margin < vmode->right_margin)
+               var->right_margin = vmode->right_margin;
+       if (var->upper_margin < vmode->upper_margin)
+               var->upper_margin = vmode->upper_margin;
+       if (var->lower_margin < vmode->lower_margin)
+               var->lower_margin = vmode->lower_margin;
+
+       /* extra margins */
+       gap = ((long)vmode->left_margin + (long)vmode->xres +
+              (long)vmode->right_margin) -
+             ((long)var->left_margin + (long)var->xres +
+              (long)var->right_margin);
+       if (gap > 0) {
+               var->left_margin += gap/2;
+               var->right_margin += (gap+1)/2;
+               pr_debug("%s: rounded up H to %u [%u] %u\n", __func__,
+                        var->left_margin, var->xres, var->right_margin);
+       }
 
-       if (mode < 1 || mode > 13)
-               return NULL;
+       gap = ((long)vmode->upper_margin + (long)vmode->yres +
+              (long)vmode->lower_margin) -
+             ((long)var->upper_margin + (long)var->yres +
+              (long)var->lower_margin);
+       if (gap > 0) {
+               var->upper_margin += gap/2;
+               var->lower_margin += (gap+1)/2;
+               pr_debug("%s: rounded up V to %u [%u] %u\n", __func__,
+                        var->upper_margin, var->yres, var->lower_margin);
+       }
+
+       /* fixed fields */
+       var->pixclock = vmode->pixclock;
+       var->hsync_len = vmode->hsync_len;
+       var->vsync_len = vmode->vsync_len;
+       var->sync = vmode->sync;
 
-       flags = id & ~PS3AV_MODE_MASK;
+       if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
+               *xdr_line_length = GPU_ALIGN_UP(var->xres_virtual * BPP);
+               if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
+                       *xdr_line_length = GPU_MAX_LINE_LENGTH;
+       } else
+               *xdr_line_length = *ddr_line_length;
 
-       if (mode <= 10 && flags & PS3FB_FULL_MODE_BIT) {
-               /* Full broadcast mode */
-               return &ps3fb_modedb[mode + 12];
+       if (vmode->sync & FB_SYNC_BROADCAST) {
+               /* Full broadcast modes have the full mode bit set */
+               if (vmode->xres == var->xres && vmode->yres == var->yres)
+                       id |= PS3AV_MODE_FULL;
        }
 
-       return &ps3fb_modedb[mode - 1];
+       pr_debug("%s: mode %u\n", __func__, id);
+       return id;
 }
 
 static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
@@ -439,8 +491,7 @@ static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
 static int ps3fb_sync(struct fb_info *info, u32 frame)
 {
        struct ps3fb_par *par = info->par;
-       int i, error = 0;
-       u32 ddr_line_length, xdr_line_length;
+       int error = 0;
        u64 ddr_base, xdr_base;
 
        if (frame > par->num_frames - 1) {
@@ -450,16 +501,13 @@ static int ps3fb_sync(struct fb_info *info, u32 frame)
                goto out;
        }
 
-       i = par->res_index;
-       xdr_line_length = info->fix.line_length;
-       ddr_line_length = ps3fb_res[i].xres * BPP;
-       xdr_base = frame * info->var.yres_virtual * xdr_line_length;
-       ddr_base = frame * ps3fb_res[i].yres * ddr_line_length;
+       xdr_base = frame * par->xdr_frame_size;
+       ddr_base = frame * par->ddr_frame_size;
 
        ps3fb_sync_image(info->device, ddr_base + par->full_offset,
                         ddr_base + par->fb_offset, xdr_base + par->pan_offset,
-                        par->width, par->height, ddr_line_length,
-                        xdr_line_length);
+                        par->width, par->height, par->ddr_line_length,
+                        info->fix.line_length);
 
 out:
        return error;
@@ -498,22 +546,11 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        u32 xdr_line_length, ddr_line_length;
        int mode;
 
-       dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
-               info->var.xres);
-       dev_dbg(info->device, "var->yres:%u info->var.yres:%u\n", var->yres,
-               info->var.yres);
-
-       /* FIXME For now we do exact matches only */
        mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
        if (!mode)
                return -EINVAL;
 
        /* Virtual screen */
-       if (var->xres_virtual < var->xres)
-               var->xres_virtual = var->xres;
-       if (var->yres_virtual < var->yres)
-               var->yres_virtual = var->yres;
-
        if (var->xres_virtual > xdr_line_length / BPP) {
                dev_dbg(info->device,
                        "Horizontal virtual screen size too large\n");
@@ -559,7 +596,7 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        }
 
        /* Memory limit */
-       if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
+       if (var->yres_virtual * xdr_line_length > info->fix.smem_len) {
                dev_dbg(info->device, "Not enough memory\n");
                return -ENOMEM;
        }
@@ -578,39 +615,38 @@ static int ps3fb_set_par(struct fb_info *info)
 {
        struct ps3fb_par *par = info->par;
        unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
-       int i;
-       unsigned long offset;
+       unsigned int ddr_xoff, ddr_yoff, offset;
+       const struct fb_videomode *vmode;
        u64 dst;
 
-       dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
-               info->var.xres, info->var.xres_virtual,
-               info->var.yres, info->var.yres_virtual, info->var.pixclock);
-
        mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
        if (!mode)
                return -EINVAL;
 
-       i = ps3fb_get_res_table(info->var.xres, info->var.yres, mode);
-       par->res_index = i;
+       vmode = ps3fb_native_vmode(mode & PS3AV_MODE_MASK);
 
-       info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
-       info->fix.smem_len = ps3fb.xdr_size;
        info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
        info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
        info->fix.line_length = xdr_line_length;
 
-       info->screen_base = (char __iomem *)ps3fb.xdr_ea;
+       par->ddr_line_length = ddr_line_length;
+       par->ddr_frame_size = vmode->yres * ddr_line_length;
+       par->xdr_frame_size = info->var.yres_virtual * xdr_line_length;
 
-       par->num_frames = ps3fb.xdr_size /
-                         max(ps3fb_res[i].yres * ddr_line_length,
-                             info->var.yres_virtual * xdr_line_length);
+       par->num_frames = info->fix.smem_len /
+                         max(par->ddr_frame_size, par->xdr_frame_size);
 
        /* Keep the special bits we cannot set using fb_var_screeninfo */
        par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
 
        par->width = info->var.xres;
        par->height = info->var.yres;
-       offset = VP_OFF(i);
+
+       /* Start of the virtual frame buffer (relative to fullscreen) */
+       ddr_xoff = info->var.left_margin - vmode->left_margin;
+       ddr_yoff = info->var.upper_margin - vmode->upper_margin;
+       offset = ddr_yoff * ddr_line_length + ddr_xoff * BPP;
+
        par->fb_offset = GPU_ALIGN_UP(offset);
        par->full_offset = par->fb_offset - offset;
        par->pan_offset = info->var.yoffset * xdr_line_length +
@@ -625,16 +661,16 @@ static int ps3fb_set_par(struct fb_info *info)
        }
 
        /* Clear XDR frame buffer memory */
-       memset(ps3fb.xdr_ea, 0, ps3fb.xdr_size);
+       memset((void __force *)info->screen_base, 0, info->fix.smem_len);
 
        /* Clear DDR frame buffer memory */
-       lines = ps3fb_res[i].yres * par->num_frames;
+       lines = vmode->yres * par->num_frames;
        if (par->full_offset)
                lines++;
-       maxlines = ps3fb.xdr_size / ddr_line_length;
+       maxlines = info->fix.smem_len / ddr_line_length;
        for (dst = 0; lines; dst += maxlines * ddr_line_length) {
                unsigned int l = min(lines, maxlines);
-               ps3fb_sync_image(info->device, 0, dst, 0, ps3fb_res[i].xres, l,
+               ps3fb_sync_image(info->device, 0, dst, 0, vmode->xres, l,
                                 ddr_line_length, ddr_line_length);
                lines -= l;
        }
@@ -797,7 +833,7 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
        case PS3FB_IOCTL_SETMODE:
                {
                        struct ps3fb_par *par = info->par;
-                       const struct fb_videomode *mode;
+                       const struct fb_videomode *vmode;
                        struct fb_var_screeninfo var;
 
                        if (copy_from_user(&val, argp, sizeof(val)))
@@ -810,10 +846,10 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
                        }
                        dev_dbg(info->device, "PS3FB_IOCTL_SETMODE:%x\n", val);
                        retval = -EINVAL;
-                       mode = ps3fb_default_mode(val);
-                       if (mode) {
+                       vmode = ps3fb_vmode(val);
+                       if (vmode) {
                                var = info->var;
-                               fb_videomode_to_var(&var, mode);
+                               fb_videomode_to_var(&var, vmode);
                                acquire_console_sem();
                                info->flags |= FBINFO_MISC_USEREVENT;
                                /* Force, in case only special bits changed */
@@ -975,10 +1011,9 @@ static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
                        __func__, status);
                return -ENXIO;
        }
-       dev_dbg(dev,
-               "video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
-               ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
-               virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
+       dev_dbg(dev, "video:%p ioif:%lx lpar:%lx size:%lx\n",
+               ps3fb_videomemory.address, GPU_IOIF, xdr_lpar,
+               ps3fb_videomemory.size);
 
        status = lv1_gpu_context_attribute(ps3fb.context_handle,
                                           L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
@@ -1055,14 +1090,14 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        struct fb_info *info;
        struct ps3fb_par *par;
        int retval = -ENOMEM;
-       u32 xres, yres;
        u64 ddr_lpar = 0;
        u64 lpar_dma_control = 0;
        u64 lpar_driver_info = 0;
        u64 lpar_reports = 0;
        u64 lpar_reports_size = 0;
        u64 xdr_lpar;
-       int status, res_index;
+       void *fb_start;
+       int status;
        struct task_struct *task;
        unsigned long max_ps3fb_size;
 
@@ -1080,14 +1115,7 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
 
        if (!ps3fb_mode)
                ps3fb_mode = ps3av_get_mode();
-       dev_dbg(&dev->core, "ps3av_mode:%d\n", ps3fb_mode);
-
-       if (ps3fb_mode > 0 &&
-           !ps3av_video_mode2res(ps3fb_mode, &xres, &yres)) {
-               res_index = ps3fb_get_res_table(xres, yres, ps3fb_mode);
-               dev_dbg(&dev->core, "res_index:%d\n", res_index);
-       } else
-               res_index = GPU_RES_INDEX;
+       dev_dbg(&dev->core, "ps3fb_mode: %d\n", ps3fb_mode);
 
        atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
        atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
@@ -1124,7 +1152,7 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        }
 
        /* vsync interrupt */
-       ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
+       ps3fb.dinfo = (void __force *)ioremap(lpar_driver_info, 128 * 1024);
        if (!ps3fb.dinfo) {
                dev_err(&dev->core, "%s: ioremap failed\n", __func__);
                goto err_gpu_context_free;
@@ -1134,22 +1162,10 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        if (retval)
                goto err_iounmap_dinfo;
 
-       /* XDR frame buffer */
-       ps3fb.xdr_ea = ps3fb_videomemory.address;
-       xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
-
        /* Clear memory to prevent kernel info leakage into userspace */
-       memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
-
-       /*
-        * The GPU command buffer is at the start of video memory
-        * As we don't use the full command buffer, we can put the actual
-        * frame buffer at offset GPU_FB_START and save some precious XDR
-        * memory
-        */
-       ps3fb.xdr_ea += GPU_FB_START;
-       ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
+       memset(ps3fb_videomemory.address, 0, ps3fb_videomemory.size);
 
+       xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb_videomemory.address));
        retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
        if (retval)
                goto err_free_irq;
@@ -1161,15 +1177,22 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        par = info->par;
        par->mode_id = ~ps3fb_mode;     /* != ps3fb_mode, to trigger change */
        par->new_mode_id = ps3fb_mode;
-       par->res_index = res_index;
        par->num_frames = 1;
 
-       info->screen_base = (char __iomem *)ps3fb.xdr_ea;
        info->fbops = &ps3fb_ops;
-
        info->fix = ps3fb_fix;
-       info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
-       info->fix.smem_len = ps3fb.xdr_size;
+
+       /*
+        * The GPU command buffer is at the start of video memory
+        * As we don't use the full command buffer, we can put the actual
+        * frame buffer at offset GPU_FB_START and save some precious XDR
+        * memory
+        */
+       fb_start = ps3fb_videomemory.address + GPU_FB_START;
+       info->screen_base = (char __force __iomem *)fb_start;
+       info->fix.smem_start = virt_to_abs(fb_start);
+       info->fix.smem_len = ps3fb_videomemory.size - GPU_FB_START;
+
        info->pseudo_palette = par->pseudo_palette;
        info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
                      FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
@@ -1180,7 +1203,7 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
 
        if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
                          ARRAY_SIZE(ps3fb_modedb),
-                         ps3fb_default_mode(par->new_mode_id), 32)) {
+                         ps3fb_vmode(par->new_mode_id), 32)) {
                retval = -EINVAL;
                goto err_fb_dealloc;
        }
@@ -1194,9 +1217,9 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
 
        dev->core.driver_data = info;
 
-       dev_info(info->device, "%s %s, using %lu KiB of video memory\n",
+       dev_info(info->device, "%s %s, using %u KiB of video memory\n",
                 dev_driver_string(info->dev), info->dev->bus_id,
-                ps3fb.xdr_size >> 10);
+                info->fix.smem_len >> 10);
 
        task = kthread_run(ps3fbd, info, DEVICE_NAME);
        if (IS_ERR(task)) {
@@ -1219,7 +1242,7 @@ err_free_irq:
        free_irq(ps3fb.irq_no, &dev->core);
        ps3_irq_plug_destroy(ps3fb.irq_no);
 err_iounmap_dinfo:
-       iounmap((u8 __iomem *)ps3fb.dinfo);
+       iounmap((u8 __force __iomem *)ps3fb.dinfo);
 err_gpu_context_free:
        lv1_gpu_context_free(ps3fb.context_handle);
 err_gpu_memory_free:
@@ -1254,7 +1277,7 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
                framebuffer_release(info);
                info = dev->core.driver_data = NULL;
        }
-       iounmap((u8 __iomem *)ps3fb.dinfo);
+       iounmap((u8 __force __iomem *)ps3fb.dinfo);
 
        status = lv1_gpu_context_free(ps3fb.context_handle);
        if (status)
index b3c31d9dc591bc1c8e4780e9e086ec5254834a32..71fa6edb5c477d64cd255b9fd866ec9dbe070d28 100644 (file)
@@ -110,6 +110,11 @@ static int debug   = 0;
 
 /* useful functions */
 
+static int is_s3c2412(struct s3c2410fb_info *fbi)
+{
+       return (fbi->drv_type == DRV_S3C2412);
+}
+
 /* s3c2410fb_set_lcdaddr
  *
  * initialise lcd controller address pointers
@@ -501,7 +506,7 @@ static void schedule_palette_update(struct s3c2410fb_info *fbi,
 {
        unsigned long flags;
        unsigned long irqen;
-       void __iomem *regs = fbi->io;
+       void __iomem *irq_base = fbi->irq_base;
 
        local_irq_save(flags);
 
@@ -511,9 +516,9 @@ static void schedule_palette_update(struct s3c2410fb_info *fbi,
                fbi->palette_ready = 1;
 
                /* enable IRQ */
-               irqen = readl(regs + S3C2410_LCDINTMSK);
+               irqen = readl(irq_base + S3C24XX_LCDINTMSK);
                irqen &= ~S3C2410_LCDINT_FRSYNC;
-               writel(irqen, regs + S3C2410_LCDINTMSK);
+               writel(irqen, irq_base + S3C24XX_LCDINTMSK);
        }
 
        local_irq_restore(flags);
@@ -594,15 +599,17 @@ static int s3c2410fb_setcolreg(unsigned regno,
 static int s3c2410fb_blank(int blank_mode, struct fb_info *info)
 {
        struct s3c2410fb_info *fbi = info->par;
-       void __iomem *regs = fbi->io;
+       void __iomem *tpal_reg = fbi->io;
 
        dprintk("blank(mode=%d, info=%p)\n", blank_mode, info);
 
+       tpal_reg += is_s3c2412(fbi) ? S3C2412_TPAL : S3C2410_TPAL;
+
        if (blank_mode == FB_BLANK_UNBLANK)
-               writel(0x0, regs + S3C2410_TPAL);
+               writel(0x0, tpal_reg);
        else {
                dprintk("setting TPAL to output 0x000000\n");
-               writel(S3C2410_TPAL_EN, regs + S3C2410_TPAL);
+               writel(S3C2410_TPAL_EN, tpal_reg);
        }
 
        return 0;
@@ -663,7 +670,7 @@ static int __init s3c2410fb_map_video_memory(struct fb_info *info)
        dma_addr_t map_dma;
        unsigned map_size = PAGE_ALIGN(info->fix.smem_len);
 
-       dprintk("map_video_memory(fbi=%p)\n", fbi);
+       dprintk("map_video_memory(fbi=%p) map_size %u\n", fbi, map_size);
 
        info->screen_base = dma_alloc_writecombine(fbi->dev, map_size,
                                                   &map_dma, GFP_KERNEL);
@@ -672,7 +679,7 @@ static int __init s3c2410fb_map_video_memory(struct fb_info *info)
                /* prevent initial garbage on screen */
                dprintk("map_video_memory: clear %p:%08x\n",
                        info->screen_base, map_size);
-               memset(info->screen_base, 0xf0, map_size);
+               memset(info->screen_base, 0x00, map_size);
 
                info->fix.smem_start = map_dma;
 
@@ -709,6 +716,16 @@ static int s3c2410fb_init_registers(struct fb_info *info)
        struct s3c2410fb_mach_info *mach_info = fbi->dev->platform_data;
        unsigned long flags;
        void __iomem *regs = fbi->io;
+       void __iomem *tpal;
+       void __iomem *lpcsel;
+
+       if (is_s3c2412(fbi)) {
+               tpal = regs + S3C2412_TPAL;
+               lpcsel = regs + S3C2412_TCONSEL;
+       } else {
+               tpal = regs + S3C2410_TPAL;
+               lpcsel = regs + S3C2410_LPCSEL;
+       }
 
        /* Initialise LCD with values from haret */
 
@@ -724,12 +741,12 @@ static int s3c2410fb_init_registers(struct fb_info *info)
        local_irq_restore(flags);
 
        dprintk("LPCSEL    = 0x%08lx\n", mach_info->lpcsel);
-       writel(mach_info->lpcsel, regs + S3C2410_LPCSEL);
+       writel(mach_info->lpcsel, lpcsel);
 
-       dprintk("replacing TPAL %08x\n", readl(regs + S3C2410_TPAL));
+       dprintk("replacing TPAL %08x\n", readl(tpal));
 
        /* ensure temporary palette disabled */
-       writel(0x00, regs + S3C2410_TPAL);
+       writel(0x00, tpal);
 
        return 0;
 }
@@ -763,15 +780,15 @@ static void s3c2410fb_write_palette(struct s3c2410fb_info *fbi)
 static irqreturn_t s3c2410fb_irq(int irq, void *dev_id)
 {
        struct s3c2410fb_info *fbi = dev_id;
-       void __iomem *regs = fbi->io;
-       unsigned long lcdirq = readl(regs + S3C2410_LCDINTPND);
+       void __iomem *irq_base = fbi->irq_base;
+       unsigned long lcdirq = readl(irq_base + S3C24XX_LCDINTPND);
 
        if (lcdirq & S3C2410_LCDINT_FRSYNC) {
                if (fbi->palette_ready)
                        s3c2410fb_write_palette(fbi);
 
-               writel(S3C2410_LCDINT_FRSYNC, regs + S3C2410_LCDINTPND);
-               writel(S3C2410_LCDINT_FRSYNC, regs + S3C2410_LCDSRCPND);
+               writel(S3C2410_LCDINT_FRSYNC, irq_base + S3C24XX_LCDINTPND);
+               writel(S3C2410_LCDINT_FRSYNC, irq_base + S3C24XX_LCDSRCPND);
        }
 
        return IRQ_HANDLED;
@@ -779,7 +796,8 @@ static irqreturn_t s3c2410fb_irq(int irq, void *dev_id)
 
 static char driver_name[] = "s3c2410fb";
 
-static int __init s3c2410fb_probe(struct platform_device *pdev)
+static int __init s3c24xxfb_probe(struct platform_device *pdev,
+                                 enum s3c_drv_type drv_type)
 {
        struct s3c2410fb_info *info;
        struct s3c2410fb_display *display;
@@ -799,6 +817,12 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
+       if (mach_info->default_display >= mach_info->num_displays) {
+               dev_err(&pdev->dev, "default is %d but only %d displays\n",
+                       mach_info->default_display, mach_info->num_displays);
+               return -EINVAL;
+       }
+
        display = mach_info->displays + mach_info->default_display;
 
        irq = platform_get_irq(pdev, 0);
@@ -815,6 +839,7 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
 
        info = fbinfo->par;
        info->dev = &pdev->dev;
+       info->drv_type = drv_type;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (res == NULL) {
@@ -838,6 +863,8 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
                goto release_mem;
        }
 
+       info->irq_base = info->io + ((drv_type == DRV_S3C2412) ? S3C2412_LCDINTBASE : S3C2410_LCDINTBASE);
+
        dprintk("devinit\n");
 
        strcpy(fbinfo->fix.id, driver_name);
@@ -946,6 +973,16 @@ dealloc_fb:
        return ret;
 }
 
+static int __init s3c2410fb_probe(struct platform_device *pdev)
+{
+       return s3c24xxfb_probe(pdev, DRV_S3C2410);
+}
+
+static int __init s3c2412fb_probe(struct platform_device *pdev)
+{
+       return s3c24xxfb_probe(pdev, DRV_S3C2412);
+}
+
 /* s3c2410fb_stop_lcd
  *
  * shutdown the lcd controller
@@ -1047,14 +1084,31 @@ static struct platform_driver s3c2410fb_driver = {
        },
 };
 
+static struct platform_driver s3c2412fb_driver = {
+       .probe          = s3c2412fb_probe,
+       .remove         = s3c2410fb_remove,
+       .suspend        = s3c2410fb_suspend,
+       .resume         = s3c2410fb_resume,
+       .driver         = {
+               .name   = "s3c2412-lcd",
+               .owner  = THIS_MODULE,
+       },
+};
+
 int __init s3c2410fb_init(void)
 {
-       return platform_driver_register(&s3c2410fb_driver);
+       int ret = platform_driver_register(&s3c2410fb_driver);
+
+       if (ret == 0)
+               ret = platform_driver_register(&s3c2412fb_driver);;
+
+       return ret;
 }
 
 static void __exit s3c2410fb_cleanup(void)
 {
        platform_driver_unregister(&s3c2410fb_driver);
+       platform_driver_unregister(&s3c2412fb_driver);
 }
 
 module_init(s3c2410fb_init);
index 6ce5dc26c5f7c5c33eb08e452261c2db9d0273c6..dbb73b95e2efd24167c7446eaf1544ed6a297c60 100644 (file)
 #ifndef __S3C2410FB_H
 #define __S3C2410FB_H
 
+enum s3c_drv_type {
+       DRV_S3C2410,
+       DRV_S3C2412,
+};
+
 struct s3c2410fb_info {
        struct device           *dev;
        struct clk              *clk;
 
        struct resource         *mem;
        void __iomem            *io;
+       void __iomem            *irq_base;
 
+       enum s3c_drv_type       drv_type;
        struct s3c2410fb_hw     regs;
 
        unsigned int            palette_ready;
index d53bf6945f0c9b427df8a07dc0c3add81fe48d8d..9b05da6268f7e8cfc72e6f07afb4b3460416dcdd 100644 (file)
 #include <linux/spinlock.h>
 
 #ifdef CONFIG_COMPAT
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
-#include <linux/ioctl32.h>
-#define SIS_OLD_CONFIG_COMPAT
-#else
 #define SIS_NEW_CONFIG_COMPAT
-#endif
 #endif /* CONFIG_COMPAT */
 
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
@@ -607,9 +602,6 @@ struct sis_video_info {
        int             haveXGIROM;
        int             registered;
        int             warncount;
-#ifdef SIS_OLD_CONFIG_COMPAT
-       int             ioctl32registered;
-#endif
 
        int             sisvga_engine;
        int             hwcursor_size;
index 37bd24b8d83b2568d516a16cd58e196e4e2e59f7..73803624c1318cd4bb82f18a5084284d924673d3 100644 (file)
@@ -427,7 +427,7 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
 
        monitor->feature = buffer[0x18];
 
-       if(!buffer[0x14] & 0x80) {
+       if(!(buffer[0x14] & 0x80)) {
                if(!(buffer[0x14] & 0x08)) {
                        printk(KERN_INFO
                                "sisfb: WARNING: Monitor does not support separate syncs\n");
@@ -4621,9 +4621,9 @@ sisfb_find_host_bridge(struct sis_video_info *ivideo, struct pci_dev *mypdev,
 
        while((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST, pdev))) {
                temp = pdev->vendor;
-               pci_dev_put(pdev);
                if(temp == pcivendor) {
                        ret = 1;
+                       pci_dev_put(pdev);
                        break;
                }
        }
@@ -5805,9 +5805,6 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        ivideo->pcifunc = PCI_FUNC(pdev->devfn);
        ivideo->subsysvendor = pdev->subsystem_vendor;
        ivideo->subsysdevice = pdev->subsystem_device;
-#ifdef SIS_OLD_CONFIG_COMPAT
-       ivideo->ioctl32registered = 0;
-#endif
 
 #ifndef MODULE
        if(sisfb_mode_idx == -1) {
@@ -6420,30 +6417,6 @@ error_3: vfree(ivideo->bios_abase);
                ivideo->next = card_list;
                card_list = ivideo;
 
-#ifdef SIS_OLD_CONFIG_COMPAT
-               {
-               int ret;
-               /* Our ioctls are all "32/64bit compatible" */
-               ret =  register_ioctl32_conversion(FBIO_ALLOC,             NULL);
-               ret |= register_ioctl32_conversion(FBIO_FREE,              NULL);
-               ret |= register_ioctl32_conversion(FBIOGET_VBLANK,         NULL);
-               ret |= register_ioctl32_conversion(SISFB_GET_INFO_SIZE,    NULL);
-               ret |= register_ioctl32_conversion(SISFB_GET_INFO,         NULL);
-               ret |= register_ioctl32_conversion(SISFB_GET_TVPOSOFFSET,  NULL);
-               ret |= register_ioctl32_conversion(SISFB_SET_TVPOSOFFSET,  NULL);
-               ret |= register_ioctl32_conversion(SISFB_SET_LOCK,         NULL);
-               ret |= register_ioctl32_conversion(SISFB_GET_VBRSTATUS,    NULL);
-               ret |= register_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE, NULL);
-               ret |= register_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE, NULL);
-               ret |= register_ioctl32_conversion(SISFB_COMMAND,          NULL);
-               if(ret)
-                       printk(KERN_ERR
-                               "sisfb: Error registering ioctl32 translations\n");
-               else
-                       ivideo->ioctl32registered = 1;
-               }
-#endif
-
                printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n",
                        ivideo->sisfb_accel ? "enabled" : "disabled",
                        ivideo->sisfb_ypan  ?
@@ -6473,27 +6446,6 @@ static void __devexit sisfb_remove(struct pci_dev *pdev)
        int                     registered = ivideo->registered;
        int                     modechanged = ivideo->modechanged;
 
-#ifdef SIS_OLD_CONFIG_COMPAT
-       if(ivideo->ioctl32registered) {
-               int ret;
-               ret =  unregister_ioctl32_conversion(FBIO_ALLOC);
-               ret |= unregister_ioctl32_conversion(FBIO_FREE);
-               ret |= unregister_ioctl32_conversion(FBIOGET_VBLANK);
-               ret |= unregister_ioctl32_conversion(SISFB_GET_INFO_SIZE);
-               ret |= unregister_ioctl32_conversion(SISFB_GET_INFO);
-               ret |= unregister_ioctl32_conversion(SISFB_GET_TVPOSOFFSET);
-               ret |= unregister_ioctl32_conversion(SISFB_SET_TVPOSOFFSET);
-               ret |= unregister_ioctl32_conversion(SISFB_SET_LOCK);
-               ret |= unregister_ioctl32_conversion(SISFB_GET_VBRSTATUS);
-               ret |= unregister_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE);
-               ret |= unregister_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE);
-               ret |= unregister_ioctl32_conversion(SISFB_COMMAND);
-               if(ret)
-                       printk(KERN_ERR
-                            "sisfb: Error unregistering ioctl32 translations\n");
-       }
-#endif
-
        /* Unmap */
        iounmap(ivideo->mmio_vbase);
        iounmap(ivideo->video_vbase);
index 1be95a68d69678d4ba05400bedd506467826cb99..e83dfba7e6361af564390dcd553dcdd6a1790ee5 100644 (file)
@@ -48,7 +48,7 @@ enum sm501_controller {
        HEAD_PANEL      = 1,
 };
 
-/* SM501 memory adress */
+/* SM501 memory address */
 struct sm501_mem {
        unsigned long    size;
        unsigned long    sm_addr;
@@ -641,6 +641,7 @@ static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
 {
        unsigned long control;
        void __iomem *ctrl_reg = fbi->regs + SM501_DC_PANEL_CONTROL;
+       struct sm501_platdata_fbsub *pd = fbi->pdata->fb_pnl;
 
        control = readl(ctrl_reg);
 
@@ -657,26 +658,34 @@ static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
                sm501fb_sync_regs(fbi);
                mdelay(10);
 
-               control |= SM501_DC_PANEL_CONTROL_BIAS; /* VBIASEN */
-               writel(control, ctrl_reg);
-               sm501fb_sync_regs(fbi);
-               mdelay(10);
-
-               control |= SM501_DC_PANEL_CONTROL_FPEN;
-               writel(control, ctrl_reg);
+               if (pd->flags & SM501FB_FLAG_PANEL_USE_VBIASEN) {
+                       control |= SM501_DC_PANEL_CONTROL_BIAS; /* VBIASEN */
+                       writel(control, ctrl_reg);
+                       sm501fb_sync_regs(fbi);
+                       mdelay(10);
+               }
 
+               if (pd->flags & SM501FB_FLAG_PANEL_USE_FPEN) {
+                       control |= SM501_DC_PANEL_CONTROL_FPEN;
+                       writel(control, ctrl_reg);
+                       sm501fb_sync_regs(fbi);
+                       mdelay(10);
+               }
        } else if (!to && (control & SM501_DC_PANEL_CONTROL_VDD) != 0) {
                /* disable panel power */
+               if (pd->flags & SM501FB_FLAG_PANEL_USE_FPEN) {
+                       control &= ~SM501_DC_PANEL_CONTROL_FPEN;
+                       writel(control, ctrl_reg);
+                       sm501fb_sync_regs(fbi);
+                       mdelay(10);
+               }
 
-               control &= ~SM501_DC_PANEL_CONTROL_FPEN;
-               writel(control, ctrl_reg);
-               sm501fb_sync_regs(fbi);
-               mdelay(10);
-
-               control &= ~SM501_DC_PANEL_CONTROL_BIAS;
-               writel(control, ctrl_reg);
-               sm501fb_sync_regs(fbi);
-               mdelay(10);
+               if (pd->flags & SM501FB_FLAG_PANEL_USE_VBIASEN) {
+                       control &= ~SM501_DC_PANEL_CONTROL_BIAS;
+                       writel(control, ctrl_reg);
+                       sm501fb_sync_regs(fbi);
+                       mdelay(10);
+               }
 
                control &= ~SM501_DC_PANEL_CONTROL_DATA;
                writel(control, ctrl_reg);
@@ -1267,6 +1276,7 @@ static int sm501fb_start(struct sm501fb_info *info,
 {
        struct resource *res;
        struct device *dev;
+       int k;
        int ret;
 
        info->dev = dev = &pdev->dev;
@@ -1328,6 +1338,13 @@ static int sm501fb_start(struct sm501fb_info *info,
 
        info->fbmem_len = (res->end - res->start)+1;
 
+       /* clear framebuffer memory - avoids garbage data on unused fb */
+       memset(info->fbmem, 0, info->fbmem_len);
+
+       /* clear palette ram - undefined at power on */
+       for (k = 0; k < (256 * 3); k++)
+               writel(0, info->regs + SM501_DC_PANEL_PALETTE + (k * 4));
+
        /* enable display controller */
        sm501_unit_power(dev->parent, SM501_GATE_DISPLAY, 1);
 
@@ -1681,6 +1698,15 @@ static int sm501fb_suspend_fb(struct sm501fb_info *info,
        if (par->screen.size == 0)
                return 0;
 
+       /* blank the relevant interface to ensure unit power minimised */
+       (par->ops.fb_blank)(FB_BLANK_POWERDOWN, fbi);
+
+       /* tell console/fb driver we are suspending */
+
+       acquire_console_sem();
+       fb_set_suspend(fbi, 1);
+       release_console_sem();
+
        /* backup copies in case chip is powered down over suspend */
 
        par->store_fb = vmalloc(par->screen.size);
@@ -1700,12 +1726,6 @@ static int sm501fb_suspend_fb(struct sm501fb_info *info,
 
        memcpy_fromio(par->store_fb, par->screen.k_addr, par->screen.size);
        memcpy_fromio(par->store_cursor, par->cursor.k_addr, par->cursor.size);
-       /* blank the relevant interface to ensure unit power minimised */
-       (par->ops.fb_blank)(FB_BLANK_POWERDOWN, fbi);
-
-       acquire_console_sem();
-       fb_set_suspend(fbi, 1);
-       release_console_sem();
 
        return 0;
 
index 057bdd593800c9c9f3b22fc5066ed7ba6fd20def..71e179ea5f95db581df36b0e544169b2de947436 100644 (file)
@@ -1342,7 +1342,7 @@ out_err:
 }
 
 #ifndef MODULE
-static void tdfxfb_setup(char *options)
+static void __init tdfxfb_setup(char *options)
 {
        char *this_opt;
 
index a14ef894d5716e4413affaea26cd59725b752341..be27b9c1ed72aca6832d30f3e27b6d2d20878854 100644 (file)
@@ -2003,12 +2003,12 @@ static void __devexit uvesafb_exit(void)
 
 module_exit(uvesafb_exit);
 
-static inline int param_get_scroll(char *buffer, struct kernel_param *kp)
+static int param_get_scroll(char *buffer, struct kernel_param *kp)
 {
        return 0;
 }
 
-static inline int param_set_scroll(const char *val, struct kernel_param *kp)
+static int param_set_scroll(const char *val, struct kernel_param *kp)
 {
        ypan = 0;
 
@@ -2022,11 +2022,11 @@ static inline int param_set_scroll(const char *val, struct kernel_param *kp)
        return 0;
 }
 
-#define param_check_scroll(name, p) __param_check(name, p, void);
+#define param_check_scroll(name, p) __param_check(name, p, void)
 
 module_param_named(scroll, ypan, scroll, 0);
 MODULE_PARM_DESC(scroll,
-       "Scrolling mode, set to 'redraw', ''ypan' or 'ywrap'");
+       "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
 module_param_named(vgapal, pmi_setpal, invbool, 0);
 MODULE_PARM_DESC(vgapal, "Set palette using VGA registers");
 module_param_named(pmipal, pmi_setpal, bool, 0);
index 1c656667b937d5ba1d4ce1fbc6d6e6de6cd5a320..2aa71eb67c2bb048f5f80c29951cf24648dfb88c 100644 (file)
@@ -651,7 +651,7 @@ static int vmlfb_check_var_locked(struct fb_var_screeninfo *var,
                return -EINVAL;
        }
 
-       pitch = __ALIGN_MASK((var->xres * var->bits_per_pixel) >> 3, 0x3F);
+       pitch = ALIGN((var->xres * var->bits_per_pixel) >> 3, 0x40);
        mem = pitch * var->yres_virtual;
        if (mem > vinfo->vram_contig_size) {
                return -ENOMEM;
@@ -785,8 +785,7 @@ static int vmlfb_set_par_locked(struct vml_info *vinfo)
        int clock;
 
        vinfo->bytes_per_pixel = var->bits_per_pixel >> 3;
-       vinfo->stride =
-           __ALIGN_MASK(var->xres_virtual * vinfo->bytes_per_pixel, 0x3F);
+       vinfo->stride = ALIGN(var->xres_virtual * vinfo->bytes_per_pixel, 0x40);
        info->fix.line_length = vinfo->stride;
 
        if (!subsys)
index 9e33fc4da875010f11b95e1512f57ba69c593e01..3dd6294d10b64066b1660a33542ce2c726c2aa84 100644 (file)
@@ -1,8 +1,35 @@
 # Virtio always gets selected by whoever wants it.
 config VIRTIO
-       bool
+       tristate
 
 # Similarly the virtio ring implementation.
 config VIRTIO_RING
-       bool
+       tristate
        depends on VIRTIO
+
+config VIRTIO_PCI
+       tristate "PCI driver for virtio devices (EXPERIMENTAL)"
+       depends on PCI && EXPERIMENTAL
+       select VIRTIO
+       select VIRTIO_RING
+       ---help---
+         This drivers provides support for virtio based paravirtual device
+         drivers over PCI.  This requires that your VMM has appropriate PCI
+         virtio backends.  Most QEMU based VMMs should support these devices
+         (like KVM or Xen).
+
+         Currently, the ABI is not considered stable so there is no guarantee
+         that this version of the driver will work with your VMM.
+
+         If unsure, say M.
+
+config VIRTIO_BALLOON
+       tristate "Virtio balloon driver (EXPERIMENTAL)"
+       select VIRTIO
+       select VIRTIO_RING
+       ---help---
+        This driver supports increasing and decreasing the amount
+        of memory within a KVM guest.
+
+        If unsure, say M.
+
index f70e40971dd9bc93221aff170949f6d6674e1af2..6738c446c199e5af4ebfdb655166c1d7dc2fa065 100644 (file)
@@ -1,2 +1,4 @@
 obj-$(CONFIG_VIRTIO) += virtio.o
 obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o
+obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
+obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
index 69d7ea02cd489bac96c3e3051678b669547e0211..b535483bc556f5f153eb434583c8dc6593377164 100644 (file)
@@ -102,9 +102,13 @@ static int virtio_dev_remove(struct device *_d)
        struct virtio_driver *drv = container_of(dev->dev.driver,
                                                 struct virtio_driver, driver);
 
-       dev->config->set_status(dev, dev->config->get_status(dev)
-                               & ~VIRTIO_CONFIG_S_DRIVER);
        drv->remove(dev);
+
+       /* Driver should have reset device. */
+       BUG_ON(dev->config->get_status(dev));
+
+       /* Acknowledge the device's existence again. */
+       add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
        return 0;
 }
 
@@ -130,6 +134,10 @@ int register_virtio_device(struct virtio_device *dev)
        dev->dev.bus = &virtio_bus;
        sprintf(dev->dev.bus_id, "%u", dev->index);
 
+       /* We always start by resetting the device, in case a previous
+        * driver messed it up.  This also tests that code path a little. */
+       dev->config->reset(dev);
+
        /* Acknowledge that we've seen the device. */
        add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
 
@@ -148,55 +156,18 @@ void unregister_virtio_device(struct virtio_device *dev)
 }
 EXPORT_SYMBOL_GPL(unregister_virtio_device);
 
-int __virtio_config_val(struct virtio_device *vdev,
-                       u8 type, void *val, size_t size)
-{
-       void *token;
-       unsigned int len;
-
-       token = vdev->config->find(vdev, type, &len);
-       if (!token)
-               return -ENOENT;
-
-       if (len != size)
-               return -EIO;
-
-       vdev->config->get(vdev, token, val, size);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(__virtio_config_val);
-
-int virtio_use_bit(struct virtio_device *vdev,
-                  void *token, unsigned int len, unsigned int bitnum)
-{
-       unsigned long bits[16];
-
-       /* This makes it convenient to pass-through find() results. */
-       if (!token)
-               return 0;
-
-       /* bit not in range of this bitfield? */
-       if (bitnum * 8 >= len / 2)
-               return 0;
-
-       /* Giant feature bitfields are silly. */
-       BUG_ON(len > sizeof(bits));
-       vdev->config->get(vdev, token, bits, len);
-
-       if (!test_bit(bitnum, bits))
-               return 0;
-
-       /* Set acknowledge bit, and write it back. */
-       set_bit(bitnum + len * 8 / 2, bits);
-       vdev->config->set(vdev, token, bits, len);
-       return 1;
-}
-EXPORT_SYMBOL_GPL(virtio_use_bit);
-
 static int virtio_init(void)
 {
        if (bus_register(&virtio_bus) != 0)
                panic("virtio bus registration failed");
        return 0;
 }
+
+static void __exit virtio_exit(void)
+{
+       bus_unregister(&virtio_bus);
+}
 core_initcall(virtio_init);
+module_exit(virtio_exit);
+
+MODULE_LICENSE("GPL");
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
new file mode 100644 (file)
index 0000000..c8a4332
--- /dev/null
@@ -0,0 +1,285 @@
+/* Virtio balloon implementation, inspired by Dor Loar and Marcelo
+ * Tosatti's implementations.
+ *
+ *  Copyright 2008 Rusty Russell IBM Corporation
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+//#define DEBUG
+#include <linux/virtio.h>
+#include <linux/virtio_balloon.h>
+#include <linux/swap.h>
+#include <linux/kthread.h>
+#include <linux/freezer.h>
+#include <linux/delay.h>
+
+struct virtio_balloon
+{
+       struct virtio_device *vdev;
+       struct virtqueue *inflate_vq, *deflate_vq;
+
+       /* Where the ballooning thread waits for config to change. */
+       wait_queue_head_t config_change;
+
+       /* The thread servicing the balloon. */
+       struct task_struct *thread;
+
+       /* Waiting for host to ack the pages we released. */
+       struct completion acked;
+
+       /* Do we have to tell Host *before* we reuse pages? */
+       bool tell_host_first;
+
+       /* The pages we've told the Host we're not using. */
+       unsigned int num_pages;
+       struct list_head pages;
+
+       /* The array of pfns we tell the Host about. */
+       unsigned int num_pfns;
+       u32 pfns[256];
+};
+
+static struct virtio_device_id id_table[] = {
+       { VIRTIO_ID_BALLOON, VIRTIO_DEV_ANY_ID },
+       { 0 },
+};
+
+static void balloon_ack(struct virtqueue *vq)
+{
+       struct virtio_balloon *vb;
+       unsigned int len;
+
+       vb = vq->vq_ops->get_buf(vq, &len);
+       if (vb)
+               complete(&vb->acked);
+}
+
+static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
+{
+       struct scatterlist sg;
+
+       sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns);
+
+       init_completion(&vb->acked);
+
+       /* We should always be able to add one buffer to an empty queue. */
+       if (vq->vq_ops->add_buf(vq, &sg, 1, 0, vb) != 0)
+               BUG();
+       vq->vq_ops->kick(vq);
+
+       /* When host has read buffer, this completes via balloon_ack */
+       wait_for_completion(&vb->acked);
+}
+
+static void fill_balloon(struct virtio_balloon *vb, size_t num)
+{
+       /* We can only do one array worth at a time. */
+       num = min(num, ARRAY_SIZE(vb->pfns));
+
+       for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) {
+               struct page *page = alloc_page(GFP_HIGHUSER | __GFP_NORETRY);
+               if (!page) {
+                       if (printk_ratelimit())
+                               dev_printk(KERN_INFO, &vb->vdev->dev,
+                                          "Out of puff! Can't get %zu pages\n",
+                                          num);
+                       /* Sleep for at least 1/5 of a second before retry. */
+                       msleep(200);
+                       break;
+               }
+               vb->pfns[vb->num_pfns] = page_to_pfn(page);
+               totalram_pages--;
+               vb->num_pages++;
+               list_add(&page->lru, &vb->pages);
+       }
+
+       /* Didn't get any?  Oh well. */
+       if (vb->num_pfns == 0)
+               return;
+
+       tell_host(vb, vb->inflate_vq);
+}
+
+static void release_pages_by_pfn(const u32 pfns[], unsigned int num)
+{
+       unsigned int i;
+
+       for (i = 0; i < num; i++) {
+               __free_page(pfn_to_page(pfns[i]));
+               totalram_pages++;
+       }
+}
+
+static void leak_balloon(struct virtio_balloon *vb, size_t num)
+{
+       struct page *page;
+
+       /* We can only do one array worth at a time. */
+       num = min(num, ARRAY_SIZE(vb->pfns));
+
+       for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) {
+               page = list_first_entry(&vb->pages, struct page, lru);
+               list_del(&page->lru);
+               vb->pfns[vb->num_pfns] = page_to_pfn(page);
+               vb->num_pages--;
+       }
+
+       if (vb->tell_host_first) {
+               tell_host(vb, vb->deflate_vq);
+               release_pages_by_pfn(vb->pfns, vb->num_pfns);
+       } else {
+               release_pages_by_pfn(vb->pfns, vb->num_pfns);
+               tell_host(vb, vb->deflate_vq);
+       }
+}
+
+static void virtballoon_changed(struct virtio_device *vdev)
+{
+       struct virtio_balloon *vb = vdev->priv;
+
+       wake_up(&vb->config_change);
+}
+
+static inline int towards_target(struct virtio_balloon *vb)
+{
+       u32 v;
+       __virtio_config_val(vb->vdev,
+                           offsetof(struct virtio_balloon_config, num_pages),
+                           &v);
+       return v - vb->num_pages;
+}
+
+static void update_balloon_size(struct virtio_balloon *vb)
+{
+       __le32 actual = cpu_to_le32(vb->num_pages);
+
+       vb->vdev->config->set(vb->vdev,
+                             offsetof(struct virtio_balloon_config, actual),
+                             &actual, sizeof(actual));
+}
+
+static int balloon(void *_vballoon)
+{
+       struct virtio_balloon *vb = _vballoon;
+
+       set_freezable();
+       while (!kthread_should_stop()) {
+               int diff;
+
+               try_to_freeze();
+               wait_event_interruptible(vb->config_change,
+                                        (diff = towards_target(vb)) != 0
+                                        || kthread_should_stop());
+               if (diff > 0)
+                       fill_balloon(vb, diff);
+               else if (diff < 0)
+                       leak_balloon(vb, -diff);
+               update_balloon_size(vb);
+       }
+       return 0;
+}
+
+static int virtballoon_probe(struct virtio_device *vdev)
+{
+       struct virtio_balloon *vb;
+       int err;
+
+       vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL);
+       if (!vb) {
+               err = -ENOMEM;
+               goto out;
+       }
+
+       INIT_LIST_HEAD(&vb->pages);
+       vb->num_pages = 0;
+       init_waitqueue_head(&vb->config_change);
+       vb->vdev = vdev;
+
+       /* We expect two virtqueues. */
+       vb->inflate_vq = vdev->config->find_vq(vdev, 0, balloon_ack);
+       if (IS_ERR(vb->inflate_vq)) {
+               err = PTR_ERR(vb->inflate_vq);
+               goto out_free_vb;
+       }
+
+       vb->deflate_vq = vdev->config->find_vq(vdev, 1, balloon_ack);
+       if (IS_ERR(vb->deflate_vq)) {
+               err = PTR_ERR(vb->deflate_vq);
+               goto out_del_inflate_vq;
+       }
+
+       vb->thread = kthread_run(balloon, vb, "vballoon");
+       if (IS_ERR(vb->thread)) {
+               err = PTR_ERR(vb->thread);
+               goto out_del_deflate_vq;
+       }
+
+       vb->tell_host_first
+               = vdev->config->feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
+
+       return 0;
+
+out_del_deflate_vq:
+       vdev->config->del_vq(vb->deflate_vq);
+out_del_inflate_vq:
+       vdev->config->del_vq(vb->inflate_vq);
+out_free_vb:
+       kfree(vb);
+out:
+       return err;
+}
+
+static void virtballoon_remove(struct virtio_device *vdev)
+{
+       struct virtio_balloon *vb = vdev->priv;
+
+       kthread_stop(vb->thread);
+
+       /* There might be pages left in the balloon: free them. */
+       while (vb->num_pages)
+               leak_balloon(vb, vb->num_pages);
+
+       /* Now we reset the device so we can clean up the queues. */
+       vdev->config->reset(vdev);
+
+       vdev->config->del_vq(vb->deflate_vq);
+       vdev->config->del_vq(vb->inflate_vq);
+       kfree(vb);
+}
+
+static struct virtio_driver virtio_balloon = {
+       .driver.name =  KBUILD_MODNAME,
+       .driver.owner = THIS_MODULE,
+       .id_table =     id_table,
+       .probe =        virtballoon_probe,
+       .remove =       __devexit_p(virtballoon_remove),
+       .config_changed = virtballoon_changed,
+};
+
+static int __init init(void)
+{
+       return register_virtio_driver(&virtio_balloon);
+}
+
+static void __exit fini(void)
+{
+       unregister_virtio_driver(&virtio_balloon);
+}
+module_init(init);
+module_exit(fini);
+
+MODULE_DEVICE_TABLE(virtio, id_table);
+MODULE_DESCRIPTION("Virtio balloon driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
new file mode 100644 (file)
index 0000000..26f787d
--- /dev/null
@@ -0,0 +1,446 @@
+/*
+ * Virtio PCI driver
+ *
+ * This module allows virtio devices to be used over a virtual PCI device.
+ * This can be used with QEMU based VMMs like KVM or Xen.
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ *  Anthony Liguori  <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/pci.h>
+#include <linux/interrupt.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
+#include <linux/highmem.h>
+#include <linux/spinlock.h>
+
+MODULE_AUTHOR("Anthony Liguori <aliguori@us.ibm.com>");
+MODULE_DESCRIPTION("virtio-pci");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("1");
+
+/* Our device structure */
+struct virtio_pci_device
+{
+       struct virtio_device vdev;
+       struct pci_dev *pci_dev;
+
+       /* the IO mapping for the PCI config space */
+       void *ioaddr;
+
+       /* a list of queues so we can dispatch IRQs */
+       spinlock_t lock;
+       struct list_head virtqueues;
+};
+
+struct virtio_pci_vq_info
+{
+       /* the actual virtqueue */
+       struct virtqueue *vq;
+
+       /* the number of entries in the queue */
+       int num;
+
+       /* the index of the queue */
+       int queue_index;
+
+       /* the virtual address of the ring queue */
+       void *queue;
+
+       /* the list node for the virtqueues list */
+       struct list_head node;
+};
+
+/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */
+static struct pci_device_id virtio_pci_id_table[] = {
+       { 0x1af4, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
+       { 0 },
+};
+
+MODULE_DEVICE_TABLE(pci, virtio_pci_id_table);
+
+/* A PCI device has it's own struct device and so does a virtio device so
+ * we create a place for the virtio devices to show up in sysfs.  I think it
+ * would make more sense for virtio to not insist on having it's own device. */
+static struct device virtio_pci_root = {
+       .parent         = NULL,
+       .bus_id         = "virtio-pci",
+};
+
+/* Unique numbering for devices under the kvm root */
+static unsigned int dev_index;
+
+/* Convert a generic virtio device to our structure */
+static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev)
+{
+       return container_of(vdev, struct virtio_pci_device, vdev);
+}
+
+/* virtio config->feature() implementation */
+static bool vp_feature(struct virtio_device *vdev, unsigned bit)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+       u32 mask;
+
+       /* Since this function is supposed to have the side effect of
+        * enabling a queried feature, we simulate that by doing a read
+        * from the host feature bitmask and then writing to the guest
+        * feature bitmask */
+       mask = ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
+       if (mask & (1 << bit)) {
+               mask |= (1 << bit);
+               iowrite32(mask, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+       }
+
+       return !!(mask & (1 << bit));
+}
+
+/* virtio config->get() implementation */
+static void vp_get(struct virtio_device *vdev, unsigned offset,
+                  void *buf, unsigned len)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+       void *ioaddr = vp_dev->ioaddr + VIRTIO_PCI_CONFIG + offset;
+       u8 *ptr = buf;
+       int i;
+
+       for (i = 0; i < len; i++)
+               ptr[i] = ioread8(ioaddr + i);
+}
+
+/* the config->set() implementation.  it's symmetric to the config->get()
+ * implementation */
+static void vp_set(struct virtio_device *vdev, unsigned offset,
+                  const void *buf, unsigned len)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+       void *ioaddr = vp_dev->ioaddr + VIRTIO_PCI_CONFIG + offset;
+       const u8 *ptr = buf;
+       int i;
+
+       for (i = 0; i < len; i++)
+               iowrite8(ptr[i], ioaddr + i);
+}
+
+/* config->{get,set}_status() implementations */
+static u8 vp_get_status(struct virtio_device *vdev)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+       return ioread8(vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+}
+
+static void vp_set_status(struct virtio_device *vdev, u8 status)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+       /* We should never be setting status to 0. */
+       BUG_ON(status == 0);
+       return iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+}
+
+static void vp_reset(struct virtio_device *vdev)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+       /* 0 status means a reset. */
+       return iowrite8(0, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+}
+
+/* the notify function used when creating a virt queue */
+static void vp_notify(struct virtqueue *vq)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
+       struct virtio_pci_vq_info *info = vq->priv;
+
+       /* we write the queue's selector into the notification register to
+        * signal the other end */
+       iowrite16(info->queue_index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
+}
+
+/* A small wrapper to also acknowledge the interrupt when it's handled.
+ * I really need an EIO hook for the vring so I can ack the interrupt once we
+ * know that we'll be handling the IRQ but before we invoke the callback since
+ * the callback may notify the host which results in the host attempting to
+ * raise an interrupt that we would then mask once we acknowledged the
+ * interrupt. */
+static irqreturn_t vp_interrupt(int irq, void *opaque)
+{
+       struct virtio_pci_device *vp_dev = opaque;
+       struct virtio_pci_vq_info *info;
+       irqreturn_t ret = IRQ_NONE;
+       u8 isr;
+
+       /* reading the ISR has the effect of also clearing it so it's very
+        * important to save off the value. */
+       isr = ioread8(vp_dev->ioaddr + VIRTIO_PCI_ISR);
+
+       /* It's definitely not us if the ISR was not high */
+       if (!isr)
+               return IRQ_NONE;
+
+       /* Configuration change?  Tell driver if it wants to know. */
+       if (isr & VIRTIO_PCI_ISR_CONFIG) {
+               struct virtio_driver *drv;
+               drv = container_of(vp_dev->vdev.dev.driver,
+                                  struct virtio_driver, driver);
+
+               if (drv->config_changed)
+                       drv->config_changed(&vp_dev->vdev);
+       }
+
+       spin_lock(&vp_dev->lock);
+       list_for_each_entry(info, &vp_dev->virtqueues, node) {
+               if (vring_interrupt(irq, info->vq) == IRQ_HANDLED)
+                       ret = IRQ_HANDLED;
+       }
+       spin_unlock(&vp_dev->lock);
+
+       return ret;
+}
+
+/* the config->find_vq() implementation */
+static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index,
+                                   void (*callback)(struct virtqueue *vq))
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+       struct virtio_pci_vq_info *info;
+       struct virtqueue *vq;
+       u16 num;
+       int err;
+
+       /* Select the queue we're interested in */
+       iowrite16(index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+
+       /* Check if queue is either not available or already active. */
+       num = ioread16(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NUM);
+       if (!num || ioread32(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN))
+               return ERR_PTR(-ENOENT);
+
+       /* allocate and fill out our structure the represents an active
+        * queue */
+       info = kmalloc(sizeof(struct virtio_pci_vq_info), GFP_KERNEL);
+       if (!info)
+               return ERR_PTR(-ENOMEM);
+
+       info->queue_index = index;
+       info->num = num;
+
+       info->queue = kzalloc(PAGE_ALIGN(vring_size(num,PAGE_SIZE)), GFP_KERNEL);
+       if (info->queue == NULL) {
+               err = -ENOMEM;
+               goto out_info;
+       }
+
+       /* activate the queue */
+       iowrite32(virt_to_phys(info->queue) >> PAGE_SHIFT,
+                 vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+
+       /* create the vring */
+       vq = vring_new_virtqueue(info->num, vdev, info->queue,
+                                vp_notify, callback);
+       if (!vq) {
+               err = -ENOMEM;
+               goto out_activate_queue;
+       }
+
+       vq->priv = info;
+       info->vq = vq;
+
+       spin_lock(&vp_dev->lock);
+       list_add(&info->node, &vp_dev->virtqueues);
+       spin_unlock(&vp_dev->lock);
+
+       return vq;
+
+out_activate_queue:
+       iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+       kfree(info->queue);
+out_info:
+       kfree(info);
+       return ERR_PTR(err);
+}
+
+/* the config->del_vq() implementation */
+static void vp_del_vq(struct virtqueue *vq)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
+       struct virtio_pci_vq_info *info = vq->priv;
+
+       spin_lock(&vp_dev->lock);
+       list_del(&info->node);
+       spin_unlock(&vp_dev->lock);
+
+       vring_del_virtqueue(vq);
+
+       /* Select and deactivate the queue */
+       iowrite16(info->queue_index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+       iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+
+       kfree(info->queue);
+       kfree(info);
+}
+
+static struct virtio_config_ops virtio_pci_config_ops = {
+       .feature        = vp_feature,
+       .get            = vp_get,
+       .set            = vp_set,
+       .get_status     = vp_get_status,
+       .set_status     = vp_set_status,
+       .reset          = vp_reset,
+       .find_vq        = vp_find_vq,
+       .del_vq         = vp_del_vq,
+};
+
+/* the PCI probing function */
+static int __devinit virtio_pci_probe(struct pci_dev *pci_dev,
+                                     const struct pci_device_id *id)
+{
+       struct virtio_pci_device *vp_dev;
+       int err;
+
+       /* We only own devices >= 0x1000 and <= 0x103f: leave the rest. */
+       if (pci_dev->device < 0x1000 || pci_dev->device > 0x103f)
+               return -ENODEV;
+
+       if (pci_dev->revision != VIRTIO_PCI_ABI_VERSION) {
+               printk(KERN_ERR "virtio_pci: expected ABI version %d, got %d\n",
+                      VIRTIO_PCI_ABI_VERSION, pci_dev->revision);
+               return -ENODEV;
+       }
+
+       /* allocate our structure and fill it out */
+       vp_dev = kzalloc(sizeof(struct virtio_pci_device), GFP_KERNEL);
+       if (vp_dev == NULL)
+               return -ENOMEM;
+
+       snprintf(vp_dev->vdev.dev.bus_id, BUS_ID_SIZE, "virtio%d", dev_index);
+       vp_dev->vdev.index = dev_index;
+       dev_index++;
+
+       vp_dev->vdev.dev.parent = &virtio_pci_root;
+       vp_dev->vdev.config = &virtio_pci_config_ops;
+       vp_dev->pci_dev = pci_dev;
+       INIT_LIST_HEAD(&vp_dev->virtqueues);
+       spin_lock_init(&vp_dev->lock);
+
+       /* enable the device */
+       err = pci_enable_device(pci_dev);
+       if (err)
+               goto out;
+
+       err = pci_request_regions(pci_dev, "virtio-pci");
+       if (err)
+               goto out_enable_device;
+
+       vp_dev->ioaddr = pci_iomap(pci_dev, 0, 0);
+       if (vp_dev->ioaddr == NULL)
+               goto out_req_regions;
+
+       pci_set_drvdata(pci_dev, vp_dev);
+
+       /* we use the subsystem vendor/device id as the virtio vendor/device
+        * id.  this allows us to use the same PCI vendor/device id for all
+        * virtio devices and to identify the particular virtio driver by
+        * the subsytem ids */
+       vp_dev->vdev.id.vendor = pci_dev->subsystem_vendor;
+       vp_dev->vdev.id.device = pci_dev->subsystem_device;
+
+       /* register a handler for the queue with the PCI device's interrupt */
+       err = request_irq(vp_dev->pci_dev->irq, vp_interrupt, IRQF_SHARED,
+                         vp_dev->vdev.dev.bus_id, vp_dev);
+       if (err)
+               goto out_set_drvdata;
+
+       /* finally register the virtio device */
+       err = register_virtio_device(&vp_dev->vdev);
+       if (err)
+               goto out_req_irq;
+
+       return 0;
+
+out_req_irq:
+       free_irq(pci_dev->irq, vp_dev);
+out_set_drvdata:
+       pci_set_drvdata(pci_dev, NULL);
+       pci_iounmap(pci_dev, vp_dev->ioaddr);
+out_req_regions:
+       pci_release_regions(pci_dev);
+out_enable_device:
+       pci_disable_device(pci_dev);
+out:
+       kfree(vp_dev);
+       return err;
+}
+
+static void __devexit virtio_pci_remove(struct pci_dev *pci_dev)
+{
+       struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
+
+       free_irq(pci_dev->irq, vp_dev);
+       pci_set_drvdata(pci_dev, NULL);
+       pci_iounmap(pci_dev, vp_dev->ioaddr);
+       pci_release_regions(pci_dev);
+       pci_disable_device(pci_dev);
+       kfree(vp_dev);
+}
+
+#ifdef CONFIG_PM
+static int virtio_pci_suspend(struct pci_dev *pci_dev, pm_message_t state)
+{
+       pci_save_state(pci_dev);
+       pci_set_power_state(pci_dev, PCI_D3hot);
+       return 0;
+}
+
+static int virtio_pci_resume(struct pci_dev *pci_dev)
+{
+       pci_restore_state(pci_dev);
+       pci_set_power_state(pci_dev, PCI_D0);
+       return 0;
+}
+#endif
+
+static struct pci_driver virtio_pci_driver = {
+       .name           = "virtio-pci",
+       .id_table       = virtio_pci_id_table,
+       .probe          = virtio_pci_probe,
+       .remove         = virtio_pci_remove,
+#ifdef CONFIG_PM
+       .suspend        = virtio_pci_suspend,
+       .resume         = virtio_pci_resume,
+#endif
+};
+
+static int __init virtio_pci_init(void)
+{
+       int err;
+
+       err = device_register(&virtio_pci_root);
+       if (err)
+               return err;
+
+       err = pci_register_driver(&virtio_pci_driver);
+       if (err)
+               device_unregister(&virtio_pci_root);
+
+       return err;
+}
+
+module_init(virtio_pci_init);
+
+static void __exit virtio_pci_exit(void)
+{
+       device_unregister(&virtio_pci_root);
+       pci_unregister_driver(&virtio_pci_driver);
+}
+
+module_exit(virtio_pci_exit);
index 1dc04b6684e6a3ce03451923d09164480932eebd..3a28c1382131d04940035448d24aada5244e7589 100644 (file)
@@ -87,6 +87,8 @@ static int vring_add_buf(struct virtqueue *_vq,
        if (vq->num_free < out + in) {
                pr_debug("Can't add buf len %i - avail = %i\n",
                         out + in, vq->num_free);
+               /* We notify *even if* VRING_USED_F_NO_NOTIFY is set here. */
+               vq->notify(&vq->vq);
                END_USE(vq);
                return -ENOSPC;
        }
@@ -97,16 +99,14 @@ static int vring_add_buf(struct virtqueue *_vq,
        head = vq->free_head;
        for (i = vq->free_head; out; i = vq->vring.desc[i].next, out--) {
                vq->vring.desc[i].flags = VRING_DESC_F_NEXT;
-               vq->vring.desc[i].addr = (page_to_pfn(sg_page(sg))<<PAGE_SHIFT)
-                       + sg->offset;
+               vq->vring.desc[i].addr = sg_phys(sg);
                vq->vring.desc[i].len = sg->length;
                prev = i;
                sg++;
        }
        for (; in; i = vq->vring.desc[i].next, in--) {
                vq->vring.desc[i].flags = VRING_DESC_F_NEXT|VRING_DESC_F_WRITE;
-               vq->vring.desc[i].addr = (page_to_pfn(sg_page(sg))<<PAGE_SHIFT)
-                       + sg->offset;
+               vq->vring.desc[i].addr = sg_phys(sg);
                vq->vring.desc[i].len = sg->length;
                prev = i;
                sg++;
@@ -171,16 +171,6 @@ static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
        vq->num_free++;
 }
 
-/* FIXME: We need to tell other side about removal, to synchronize. */
-static void vring_shutdown(struct virtqueue *_vq)
-{
-       struct vring_virtqueue *vq = to_vvq(_vq);
-       unsigned int i;
-
-       for (i = 0; i < vq->vring.num; i++)
-               detach_buf(vq, i);
-}
-
 static inline bool more_used(const struct vring_virtqueue *vq)
 {
        return vq->last_used_idx != vq->vring.used->idx;
@@ -220,7 +210,17 @@ static void *vring_get_buf(struct virtqueue *_vq, unsigned int *len)
        return ret;
 }
 
-static bool vring_restart(struct virtqueue *_vq)
+static void vring_disable_cb(struct virtqueue *_vq)
+{
+       struct vring_virtqueue *vq = to_vvq(_vq);
+
+       START_USE(vq);
+       BUG_ON(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT);
+       vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
+       END_USE(vq);
+}
+
+static bool vring_enable_cb(struct virtqueue *_vq)
 {
        struct vring_virtqueue *vq = to_vvq(_vq);
 
@@ -253,26 +253,34 @@ irqreturn_t vring_interrupt(int irq, void *_vq)
        if (unlikely(vq->broken))
                return IRQ_HANDLED;
 
+       /* Other side may have missed us turning off the interrupt,
+        * but we should preserve disable semantic for virtio users. */
+       if (unlikely(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) {
+               pr_debug("virtqueue interrupt after disable for %p\n", vq);
+               return IRQ_HANDLED;
+       }
+
        pr_debug("virtqueue callback for %p (%p)\n", vq, vq->vq.callback);
-       if (vq->vq.callback && !vq->vq.callback(&vq->vq))
-               vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
+       if (vq->vq.callback)
+               vq->vq.callback(&vq->vq);
 
        return IRQ_HANDLED;
 }
+EXPORT_SYMBOL_GPL(vring_interrupt);
 
 static struct virtqueue_ops vring_vq_ops = {
        .add_buf = vring_add_buf,
        .get_buf = vring_get_buf,
        .kick = vring_kick,
-       .restart = vring_restart,
-       .shutdown = vring_shutdown,
+       .disable_cb = vring_disable_cb,
+       .enable_cb = vring_enable_cb,
 };
 
 struct virtqueue *vring_new_virtqueue(unsigned int num,
                                      struct virtio_device *vdev,
                                      void *pages,
                                      void (*notify)(struct virtqueue *),
-                                     bool (*callback)(struct virtqueue *))
+                                     void (*callback)(struct virtqueue *))
 {
        struct vring_virtqueue *vq;
        unsigned int i;
@@ -311,9 +319,12 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
 
        return &vq->vq;
 }
+EXPORT_SYMBOL_GPL(vring_new_virtqueue);
 
 void vring_del_virtqueue(struct virtqueue *vq)
 {
        kfree(to_vvq(vq));
 }
+EXPORT_SYMBOL_GPL(vring_del_virtqueue);
 
+MODULE_LICENSE("GPL");
index 8236d447adf5f90ecbf054bc5fa9f54a6ada8137..c4493091c655d109dd008983183048b02c2a304e 100644 (file)
@@ -42,5 +42,15 @@ config W1_MASTER_DS1WM
          in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like
          hx4700.
 
+config W1_MASTER_GPIO
+       tristate "GPIO 1-wire busmaster"
+       depends on GENERIC_GPIO
+       help
+         Say Y here if you want to communicate with your 1-wire devices using
+         GPIO pins. This driver uses the GPIO API to control the wire.
+
+         This support is also available as a module.  If so, the module
+         will be called w1-gpio.ko.
+
 endmenu
 
index 11551b328186fb23de8a9ddc71f1a13350d802dd..1420b5bbdda81f930379dfac9e776af216af7557 100644 (file)
@@ -6,3 +6,4 @@ obj-$(CONFIG_W1_MASTER_MATROX)          += matrox_w1.o
 obj-$(CONFIG_W1_MASTER_DS2490)         += ds2490.o
 obj-$(CONFIG_W1_MASTER_DS2482)         += ds2482.o
 obj-$(CONFIG_W1_MASTER_DS1WM)          += ds1wm.o
+obj-$(CONFIG_W1_MASTER_GPIO)           += w1-gpio.o
diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
new file mode 100644 (file)
index 0000000..9e1138a
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * w1-gpio - GPIO w1 bus master driver
+ *
+ * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/w1-gpio.h>
+
+#include "../w1.h"
+#include "../w1_int.h"
+
+#include <asm/gpio.h>
+
+static void w1_gpio_write_bit_dir(void *data, u8 bit)
+{
+       struct w1_gpio_platform_data *pdata = data;
+
+       if (bit)
+               gpio_direction_input(pdata->pin);
+       else
+               gpio_direction_output(pdata->pin, 0);
+}
+
+static void w1_gpio_write_bit_val(void *data, u8 bit)
+{
+       struct w1_gpio_platform_data *pdata = data;
+
+       gpio_set_value(pdata->pin, bit);
+}
+
+static u8 w1_gpio_read_bit(void *data)
+{
+       struct w1_gpio_platform_data *pdata = data;
+
+       return gpio_get_value(pdata->pin);
+}
+
+static int __init w1_gpio_probe(struct platform_device *pdev)
+{
+       struct w1_bus_master *master;
+       struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+       int err;
+
+       if (!pdata)
+               return -ENXIO;
+
+       master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
+       if (!master)
+               return -ENOMEM;
+
+       err = gpio_request(pdata->pin, "w1");
+       if (err)
+               goto free_master;
+
+       master->data = pdata;
+       master->read_bit = w1_gpio_read_bit;
+
+       if (pdata->is_open_drain) {
+               gpio_direction_output(pdata->pin, 1);
+               master->write_bit = w1_gpio_write_bit_val;
+       } else {
+               gpio_direction_input(pdata->pin);
+               master->write_bit = w1_gpio_write_bit_dir;
+       }
+
+       err = w1_add_master_device(master);
+       if (err)
+               goto free_gpio;
+
+       platform_set_drvdata(pdev, master);
+
+       return 0;
+
+ free_gpio:
+       gpio_free(pdata->pin);
+ free_master:
+       kfree(master);
+
+       return err;
+}
+
+static int __exit w1_gpio_remove(struct platform_device *pdev)
+{
+       struct w1_bus_master *master = platform_get_drvdata(pdev);
+       struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+
+       w1_remove_master_device(master);
+       gpio_free(pdata->pin);
+       kfree(master);
+
+       return 0;
+}
+
+static struct platform_driver w1_gpio_driver = {
+       .driver = {
+               .name   = "w1-gpio",
+               .owner  = THIS_MODULE,
+       },
+       .remove = __exit_p(w1_gpio_remove),
+};
+
+static int __init w1_gpio_init(void)
+{
+       return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe);
+}
+
+static void __exit w1_gpio_exit(void)
+{
+       platform_driver_unregister(&w1_gpio_driver);
+}
+
+module_init(w1_gpio_init);
+module_exit(w1_gpio_exit);
+
+MODULE_DESCRIPTION("GPIO w1 bus master driver");
+MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
+MODULE_LICENSE("GPL");
index 112f4ec59035424bc36b7251fcb6367c9bca7f77..fb28acaeed6c4ab01235f09b764b8d0b7e1b20b6 100644 (file)
@@ -92,6 +92,7 @@ struct w1_therm_family_converter
        int                     (*convert)(u8 rom[9]);
 };
 
+/* The return value is millidegrees Centigrade. */
 static inline int w1_DS18B20_convert_temp(u8 rom[9]);
 static inline int w1_DS18S20_convert_temp(u8 rom[9]);
 
@@ -113,7 +114,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {
 static inline int w1_DS18B20_convert_temp(u8 rom[9])
 {
        s16 t = (rom[1] << 8) | rom[0];
-       t /= 16;
+       t = t*1000/16;
        return t;
 }
 
index 33e50310e9e02418763188665457b127f4ae7520..7293c9b11f9160e2b80f89e8e9c63d6bdfd6553f 100644 (file)
@@ -675,7 +675,6 @@ static void w1_slave_found(void *data, u64 rn)
        struct w1_slave *sl;
        struct list_head *ent;
        struct w1_reg_num *tmp;
-       int family_found = 0;
        struct w1_master *dev;
        u64 rn_le = cpu_to_le64(rn);
 
@@ -698,9 +697,6 @@ static void w1_slave_found(void *data, u64 rn)
                    sl->reg_num.crc == tmp->crc) {
                        set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags);
                        break;
-               } else if (sl->reg_num.family == tmp->family) {
-                       family_found = 1;
-                       break;
                }
 
                slave_count++;
index cecbedd473a4392436ea150e1446b66c0a4c4601..61dde863bd40c2da42f04a6472a8407249fd961d 100644 (file)
@@ -52,7 +52,7 @@
  * overflow periods respectively.
  *
  * Also, since we can't really expect userspace to be responsive enough
- * before the overflow happens, we maintain two seperate timers .. One in
+ * before the overflow happens, we maintain two separate timers .. One in
  * the kernel for clearing out WOVF every 2ms or so (again, this depends on
  * HZ == 1000), and another for monitoring userspace writes to the WDT device.
  *
index b364da70ff28f048dabcb7029076019eec17dc8d..dfebdbe7440e6f31f627fdd41718cf55c459a55d 100644 (file)
@@ -175,7 +175,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
        if (!wnames)
                return ERR_PTR(-ENOMEM);
 
-       for (d = dentry, i = n; i >= 0; i--, d = d->d_parent)
+       for (d = dentry, i = (n-1); i >= 0; i--, d = d->d_parent)
                wnames[i] = (char *) d->d_name.name;
 
        clone = 1;
@@ -183,7 +183,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
        while (i < n) {
                l = min(n - i, P9_MAXWELEM);
                fid = p9_client_walk(fid, l, &wnames[i], clone);
-               if (!fid) {
+               if (IS_ERR(fid)) {
                        kfree(wnames);
                        return fid;
                }
index fbb12dadba8389a77f7cfece24fc452d86732640..9b0f0222e8bbed0947f19f0baebdef0f52aabe56 100644 (file)
@@ -3,7 +3,7 @@
  *
  *  This file contains functions assisting in mapping VFS to 9P2000
  *
- *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
+ *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,6 @@
 #include <linux/idr.h>
 #include <net/9p/9p.h>
 #include <net/9p/transport.h>
-#include <net/9p/conn.h>
 #include <net/9p/client.h>
 #include "v9fs.h"
 #include "v9fs_vfs.h"
 
 enum {
        /* Options that take integer arguments */
-       Opt_debug, Opt_msize, Opt_dfltuid, Opt_dfltgid, Opt_afid,
+       Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
        /* String options */
        Opt_uname, Opt_remotename, Opt_trans,
        /* Options that take no arguments */
-       Opt_legacy, Opt_nodevmap,
+       Opt_nodevmap,
        /* Cache options */
        Opt_cache_loose,
        /* Access options */
@@ -58,14 +57,11 @@ enum {
 
 static match_table_t tokens = {
        {Opt_debug, "debug=%x"},
-       {Opt_msize, "msize=%u"},
        {Opt_dfltuid, "dfltuid=%u"},
        {Opt_dfltgid, "dfltgid=%u"},
        {Opt_afid, "afid=%u"},
        {Opt_uname, "uname=%s"},
        {Opt_remotename, "aname=%s"},
-       {Opt_trans, "trans=%s"},
-       {Opt_legacy, "noextend"},
        {Opt_nodevmap, "nodevmap"},
        {Opt_cache_loose, "cache=loose"},
        {Opt_cache_loose, "loose"},
@@ -85,16 +81,14 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
        char *options;
        substring_t args[MAX_OPT_ARGS];
        char *p;
-       int option;
-       int ret;
+       int option = 0;
        char *s, *e;
+       int ret;
 
        /* setup defaults */
-       v9ses->maxdata = 8192;
        v9ses->afid = ~0;
        v9ses->debug = 0;
        v9ses->cache = 0;
-       v9ses->trans = v9fs_default_trans();
 
        if (!v9ses->options)
                return;
@@ -106,7 +100,8 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
                        continue;
                token = match_token(p, tokens, args);
                if (token < Opt_uname) {
-                       if ((ret = match_int(&args[0], &option)) < 0) {
+                       ret = match_int(&args[0], &option);
+                       if (ret < 0) {
                                P9_DPRINTK(P9_DEBUG_ERROR,
                                        "integer field, but no integer?\n");
                                continue;
@@ -119,9 +114,7 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
                        p9_debug_level = option;
 #endif
                        break;
-               case Opt_msize:
-                       v9ses->maxdata = option;
-                       break;
+
                case Opt_dfltuid:
                        v9ses->dfltuid = option;
                        break;
@@ -131,18 +124,12 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
                case Opt_afid:
                        v9ses->afid = option;
                        break;
-               case Opt_trans:
-                       v9ses->trans = v9fs_match_trans(&args[0]);
-                       break;
                case Opt_uname:
                        match_strcpy(v9ses->uname, &args[0]);
                        break;
                case Opt_remotename:
                        match_strcpy(v9ses->aname, &args[0]);
                        break;
-               case Opt_legacy:
-                       v9ses->flags &= ~V9FS_EXTENDED;
-                       break;
                case Opt_nodevmap:
                        v9ses->nodev = 1;
                        break;
@@ -185,7 +172,6 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
                  const char *dev_name, char *data)
 {
        int retval = -EINVAL;
-       struct p9_trans *trans = NULL;
        struct p9_fid *fid;
 
        v9ses->uname = __getname();
@@ -207,24 +193,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
        v9ses->options = kstrdup(data, GFP_KERNEL);
        v9fs_parse_options(v9ses);
 
-       if (v9ses->trans == NULL) {
-               retval = -EPROTONOSUPPORT;
-               P9_DPRINTK(P9_DEBUG_ERROR,
-                               "No transport defined or default transport\n");
-               goto error;
-       }
-
-       trans = v9ses->trans->create(dev_name, v9ses->options);
-       if (IS_ERR(trans)) {
-               retval = PTR_ERR(trans);
-               trans = NULL;
-               goto error;
-       }
-       if ((v9ses->maxdata+P9_IOHDRSZ) > v9ses->trans->maxsize)
-               v9ses->maxdata = v9ses->trans->maxsize-P9_IOHDRSZ;
-
-       v9ses->clnt = p9_client_create(trans, v9ses->maxdata+P9_IOHDRSZ,
-               v9fs_extended(v9ses));
+       v9ses->clnt = p9_client_create(dev_name, v9ses->options);
 
        if (IS_ERR(v9ses->clnt)) {
                retval = PTR_ERR(v9ses->clnt);
@@ -236,6 +205,8 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
        if (!v9ses->clnt->dotu)
                v9ses->flags &= ~V9FS_EXTENDED;
 
+       v9ses->maxdata = v9ses->clnt->msize;
+
        /* for legacy mode, fall back to V9FS_ACCESS_ANY */
        if (!v9fs_extended(v9ses) &&
                ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
index db4b4193f2e258ba77e9341f2e0fb04a72b00fcd..7d3a1018db5215ec9a410b2d789b1ea5d3e8aab5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * V9FS definitions.
  *
- *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
+ *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -28,7 +28,6 @@
 
 struct v9fs_session_info {
        /* options */
-       unsigned int maxdata;
        unsigned char flags;    /* session flags */
        unsigned char nodev;    /* set to 1 if no disable device mapping */
        unsigned short debug;   /* debug level */
@@ -38,10 +37,10 @@ struct v9fs_session_info {
        char *options;          /* copy of mount options */
        char *uname;            /* user name to mount as */
        char *aname;            /* name of remote hierarchy being mounted */
+       unsigned int maxdata;   /* max data for client interface */
        unsigned int dfltuid;   /* default uid/muid for legacy support */
        unsigned int dfltgid;   /* default gid for legacy support */
        u32 uid;                /* if ACCESS_SINGLE, the uid that has access */
-       struct p9_trans_module *trans; /* 9p transport */
        struct p9_client *clnt; /* 9p client */
        struct dentry *debugfs_dir;
 };
index ba4b1caa9c43a7491bcef73b8e4585057ea3c57f..a616fff8906d8e803c928981a8cb346f46db7d76 100644 (file)
@@ -184,7 +184,7 @@ static const struct file_operations v9fs_cached_file_operations = {
        .open = v9fs_file_open,
        .release = v9fs_dir_release,
        .lock = v9fs_file_lock,
-       .mmap = generic_file_mmap,
+       .mmap = generic_file_readonly_mmap,
 };
 
 const struct file_operations v9fs_file_operations = {
@@ -194,5 +194,5 @@ const struct file_operations v9fs_file_operations = {
        .open = v9fs_file_open,
        .release = v9fs_dir_release,
        .lock = v9fs_file_lock,
-       .mmap = generic_file_mmap,
+       .mmap = generic_file_readonly_mmap,
 };
index 23581bcb599b2f7d6031644de612742512e218e3..5c5137c11484d22f22c18412a3d26ad231e898cc 100644 (file)
@@ -77,6 +77,8 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
                        res |= P9_DMSETUID;
                if ((mode & S_ISGID) == S_ISGID)
                        res |= P9_DMSETGID;
+               if ((mode & S_ISVTX) == S_ISVTX)
+                       res |= P9_DMSETVTX;
                if ((mode & P9_DMLINK))
                        res |= P9_DMLINK;
        }
@@ -119,6 +121,9 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
 
                if ((mode & P9_DMSETGID) == P9_DMSETGID)
                        res |= S_ISGID;
+
+               if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
+                       res |= S_ISVTX;
        }
 
        return res;
index 219ec06a8c7e2cd057a28898c4827776a1abf0c3..ea5b359476234452070e5ba64f44eb404c4f2107 100644 (file)
@@ -1152,7 +1152,7 @@ config BEFS_DEBUG
        depends on BEFS_FS
        help
          If you say Y here, you can use the 'debug' mount option to enable
-         debugging output from the driver. 
+         debugging output from the driver.
 
 config BFS_FS
        tristate "BFS file system support (EXPERIMENTAL)"
@@ -1263,7 +1263,7 @@ config JFFS2_FS_XATTR
          Extended attributes are name:value pairs associated with inodes by
          the kernel or by users (see the attr(5) manual page, or visit
          <http://acl.bestbits.at/> for details).
-         
+
          If unsure, say N.
 
 config JFFS2_FS_POSIX_ACL
@@ -1274,10 +1274,10 @@ config JFFS2_FS_POSIX_ACL
        help
          Posix Access Control Lists (ACLs) support permissions for users and
          groups beyond the owner/group/world scheme.
-         
+
          To learn more about Access Control Lists, visit the Posix ACLs for
          Linux website <http://acl.bestbits.at/>.
-         
+
          If you don't know what Access Control Lists are, say N
 
 config JFFS2_FS_SECURITY
@@ -1289,7 +1289,7 @@ config JFFS2_FS_SECURITY
          implemented by security modules like SELinux.  This option
          enables an extended attribute handler for file security
          labels in the jffs2 filesystem.
-         
+
          If you are not using a security module that requires using
          extended attributes for file security labels, say N.
 
@@ -1674,6 +1674,8 @@ config NFSD
        select CRYPTO_MD5 if NFSD_V4
        select CRYPTO if NFSD_V4
        select FS_POSIX_ACL if NFSD_V4
+       select PROC_FS if NFSD_V4
+       select PROC_FS if SUNRPC_GSS
        help
          If you want your Linux box to act as an NFS *server*, so that other
          computers on your local network which support NFS can access certain
@@ -1833,7 +1835,7 @@ config RPCSEC_GSS_SPKM3
          If unsure, say N.
 
 config SMB_FS
-       tristate "SMB file system support (to mount Windows shares etc.)"
+       tristate "SMB file system support (OBSOLETE, please use CIFS)"
        depends on INET
        select NLS
        help
@@ -1856,8 +1858,8 @@ config SMB_FS
          General information about how to connect Linux, Windows machines and
          Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>.
 
-         To compile the SMB support as a module, choose M here: the module will
-         be called smbfs.  Most people say N, however.
+         To compile the SMB support as a module, choose M here:
+         the module will be called smbfs.  Most people say N, however.
 
 config SMB_NLS_DEFAULT
        bool "Use a default NLS"
@@ -1889,7 +1891,7 @@ config SMB_NLS_REMOTE
          smbmount from samba 2.2.0 or later supports this.
 
 config CIFS
-       tristate "CIFS support (advanced network filesystem for Samba, Window and other CIFS compliant servers)"
+       tristate "CIFS support (advanced network filesystem, SMBFS successor)"
        depends on INET
        select NLS
        help
@@ -1947,16 +1949,16 @@ config CIFS_WEAK_PW_HASH
          LANMAN based servers such as OS/2 and Windows 95, but such
          mounts may be less secure than mounts using NTLM or more recent
          security mechanisms if you are on a public network.  Unless you
-         have a need to access old SMB servers (and are on a private 
+         have a need to access old SMB servers (and are on a private
          network) you probably want to say N.  Even if this support
          is enabled in the kernel build, LANMAN authentication will not be
          used automatically. At runtime LANMAN mounts are disabled but
          can be set to required (or optional) either in
          /proc/fs/cifs (see fs/cifs/README for more detail) or via an
-         option on the mount command. This support is disabled by 
+         option on the mount command. This support is disabled by
          default in order to reduce the possibility of a downgrade
          attack.
+
          If unsure, say N.
 
 config CIFS_XATTR
@@ -1997,7 +1999,7 @@ config CIFS_DEBUG2
           messages in some error paths, slowing performance. This
           option can be turned off unless you are debugging
           cifs problems.  If unsure, say N.
-          
+
 config CIFS_EXPERIMENTAL
          bool "CIFS Experimental Features (EXPERIMENTAL)"
          depends on CIFS && EXPERIMENTAL
@@ -2088,7 +2090,7 @@ config CODA_FS_OLD_API
          However this new API is not backward compatible with older
          clients. If you really need to run the old Coda userspace
          cache manager then say Y.
-         
+
          For most cases you probably want to say N.
 
 config AFS_FS
index af5bb93276f855ab6a3bdc8ec9cf632be8b5e22c..4202db7496cb51eb07cf3dfd7322b40dcc16ad08 100644 (file)
@@ -232,7 +232,7 @@ befs_bt_read_node(struct super_block *sb, befs_data_stream * ds,
  * @key: Key string to lookup in btree
  * @value: Value stored with @key
  *
- * On sucess, returns BEFS_OK and sets *@value to the value stored
+ * On success, returns BEFS_OK and sets *@value to the value stored
  * with @key (usually the disk block number of an inode).
  *
  * On failure, returns BEFS_ERR or BEFS_BT_NOT_FOUND.
index aacb4da6298aefe41200fb587784e09ce7d842ae..e3287d0d1a58815020044ef9f47383eec92cddcb 100644 (file)
@@ -236,7 +236,7 @@ befs_count_blocks(struct super_block * sb, befs_data_stream * ds)
        as in the indirect region code).
        
        When/if blockno is found, if blockno is inside of a block 
-       run as stored on disk, we offset the start and lenght members 
+       run as stored on disk, we offset the start and length members
        of the block run, so that blockno is the start and len is
        still valid (the run ends in the same place).
        
index 18ed6dd906c150208a4beb9230676a5a95de06d6..111771d38e6e2d457aa939ba35dafaee5dd28db3 100644 (file)
@@ -117,7 +117,7 @@ static int padzero(unsigned long elf_bss)
        return 0;
 }
 
-/* Let's use some macros to make this stack manipulation a litle clearer */
+/* Let's use some macros to make this stack manipulation a little clearer */
 #ifdef CONFIG_STACK_GROWSUP
 #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) + (items))
 #define STACK_ROUND(sp, items) \
@@ -1077,7 +1077,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
        current->mm->start_stack = bprm->p;
 
 #ifdef arch_randomize_brk
-       if (current->flags & PF_RANDOMIZE)
+       if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1))
                current->mm->brk = current->mm->start_brk =
                        arch_randomize_brk(current->mm);
 #endif
index e48a630ae266331f2ca7e482e0b8eeeea9f65d6b..e63067d25cdb9b839bae496e2f1110177b234e97 100644 (file)
@@ -534,7 +534,6 @@ void __init bdev_cache_init(void)
        if (err)
                panic("Cannot register bdev pseudo-fs");
        bd_mnt = kern_mount(&bd_type);
-       err = PTR_ERR(bd_mnt);
        if (IS_ERR(bd_mnt))
                panic("Cannot create bdev pseudo-fs");
        blockdev_superblock = bd_mnt->mnt_sb;   /* For writeback */
index 456c9ab7705b0fce1f7299ee455c26614330fb34..826baf4f04bc738fdfea27f6652bc3c0bfe9969d 100644 (file)
@@ -1798,7 +1798,7 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to)
                                        start = max(from, block_start);
                                        size = min(to, block_end) - start;
 
-                                       zero_user_page(page, start, size, KM_USER0);
+                                       zero_user(page, start, size);
                                        set_buffer_uptodate(bh);
                                }
 
@@ -1861,19 +1861,10 @@ static int __block_prepare_write(struct inode *inode, struct page *page,
                                        mark_buffer_dirty(bh);
                                        continue;
                                }
-                               if (block_end > to || block_start < from) {
-                                       void *kaddr;
-
-                                       kaddr = kmap_atomic(page, KM_USER0);
-                                       if (block_end > to)
-                                               memset(kaddr+to, 0,
-                                                       block_end-to);
-                                       if (block_start < from)
-                                               memset(kaddr+block_start,
-                                                       0, from-block_start);
-                                       flush_dcache_page(page);
-                                       kunmap_atomic(kaddr, KM_USER0);
-                               }
+                               if (block_end > to || block_start < from)
+                                       zero_user_segments(page,
+                                               to, block_end,
+                                               block_start, from);
                                continue;
                        }
                }
@@ -2104,8 +2095,7 @@ int block_read_full_page(struct page *page, get_block_t *get_block)
                                        SetPageError(page);
                        }
                        if (!buffer_mapped(bh)) {
-                               zero_user_page(page, i * blocksize, blocksize,
-                                               KM_USER0);
+                               zero_user(page, i * blocksize, blocksize);
                                if (!err)
                                        set_buffer_uptodate(bh);
                                continue;
@@ -2218,7 +2208,7 @@ int cont_expand_zero(struct file *file, struct address_space *mapping,
                                                &page, &fsdata);
                if (err)
                        goto out;
-               zero_user_page(page, zerofrom, len, KM_USER0);
+               zero_user(page, zerofrom, len);
                err = pagecache_write_end(file, mapping, curpos, len, len,
                                                page, fsdata);
                if (err < 0)
@@ -2245,7 +2235,7 @@ int cont_expand_zero(struct file *file, struct address_space *mapping,
                                                &page, &fsdata);
                if (err)
                        goto out;
-               zero_user_page(page, zerofrom, len, KM_USER0);
+               zero_user(page, zerofrom, len);
                err = pagecache_write_end(file, mapping, curpos, len, len,
                                                page, fsdata);
                if (err < 0)
@@ -2422,7 +2412,6 @@ int nobh_write_begin(struct file *file, struct address_space *mapping,
        unsigned block_in_page;
        unsigned block_start, block_end;
        sector_t block_in_file;
-       char *kaddr;
        int nr_reads = 0;
        int ret = 0;
        int is_mapped_to_disk = 1;
@@ -2493,13 +2482,8 @@ int nobh_write_begin(struct file *file, struct address_space *mapping,
                        continue;
                }
                if (buffer_new(bh) || !buffer_mapped(bh)) {
-                       kaddr = kmap_atomic(page, KM_USER0);
-                       if (block_start < from)
-                               memset(kaddr+block_start, 0, from-block_start);
-                       if (block_end > to)
-                               memset(kaddr + to, 0, block_end - to);
-                       flush_dcache_page(page);
-                       kunmap_atomic(kaddr, KM_USER0);
+                       zero_user_segments(page, block_start, from,
+                                                       to, block_end);
                        continue;
                }
                if (buffer_uptodate(bh))
@@ -2636,7 +2620,7 @@ int nobh_writepage(struct page *page, get_block_t *get_block,
         * the  page size, the remaining memory is zeroed when mapped, and
         * writes to that region are not written out to the file."
         */
-       zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0);
+       zero_user_segment(page, offset, PAGE_CACHE_SIZE);
 out:
        ret = mpage_writepage(page, get_block, wbc);
        if (ret == -EAGAIN)
@@ -2709,7 +2693,7 @@ has_buffers:
                if (page_has_buffers(page))
                        goto has_buffers;
        }
-       zero_user_page(page, offset, length, KM_USER0);
+       zero_user(page, offset, length);
        set_page_dirty(page);
        err = 0;
 
@@ -2785,7 +2769,7 @@ int block_truncate_page(struct address_space *mapping,
                        goto unlock;
        }
 
-       zero_user_page(page, offset, length, KM_USER0);
+       zero_user(page, offset, length);
        mark_buffer_dirty(bh);
        err = 0;
 
@@ -2831,7 +2815,7 @@ int block_write_full_page(struct page *page, get_block_t *get_block,
         * the  page size, the remaining memory is zeroed when mapped, and
         * writes to that region are not written out to the file."
         */
-       zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0);
+       zero_user_segment(page, offset, PAGE_CACHE_SIZE);
        return __block_write_full_page(inode, page, get_block, wbc);
 }
 
@@ -3169,7 +3153,7 @@ static void recalc_bh_state(void)
        
 struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
 {
-       struct buffer_head *ret = kmem_cache_zalloc(bh_cachep,
+       struct buffer_head *ret = kmem_cache_alloc(bh_cachep,
                                set_migrateflags(gfp_flags, __GFP_RECLAIMABLE));
        if (ret) {
                INIT_LIST_HEAD(&ret->b_assoc_buffers);
@@ -3257,12 +3241,24 @@ int bh_submit_read(struct buffer_head *bh)
 }
 EXPORT_SYMBOL(bh_submit_read);
 
+static void
+init_buffer_head(struct kmem_cache *cachep, void *data)
+{
+       struct buffer_head *bh = data;
+
+       memset(bh, 0, sizeof(*bh));
+       INIT_LIST_HEAD(&bh->b_assoc_buffers);
+}
+
 void __init buffer_init(void)
 {
        int nrpages;
 
-       bh_cachep = KMEM_CACHE(buffer_head,
-                       SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
+       bh_cachep = kmem_cache_create("buffer_head",
+                       sizeof(struct buffer_head), 0,
+                               (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
+                               SLAB_MEM_SPREAD),
+                               init_buffer_head);
 
        /*
         * Limit the bh occupancy to 10% of ZONE_NORMAL
index d9567ba2960bea58e679bd294ea150a609d537d7..47f2621001e4e09069c2c390f77fb95a4d3dd15f 100644 (file)
@@ -1386,7 +1386,7 @@ static int cifs_truncate_page(struct address_space *mapping, loff_t from)
        if (!page)
                return -ENOMEM;
 
-       zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0);
+       zero_user_segment(page, offset, PAGE_CACHE_SIZE);
        unlock_page(page);
        page_cache_release(page);
        return rc;
index 5216c3fd751771ab4349753f68395b6daba74063..ee80ff341d37655d40cac120104a1cbd96f0fbcb 100644 (file)
@@ -2083,51 +2083,6 @@ long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2)
 
 #ifdef CONFIG_EPOLL
 
-#ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
-asmlinkage long compat_sys_epoll_ctl(int epfd, int op, int fd,
-                       struct compat_epoll_event __user *event)
-{
-       long err = 0;
-       struct compat_epoll_event user;
-       struct epoll_event __user *kernel = NULL;
-
-       if (event) {
-               if (copy_from_user(&user, event, sizeof(user)))
-                       return -EFAULT;
-               kernel = compat_alloc_user_space(sizeof(struct epoll_event));
-               err |= __put_user(user.events, &kernel->events);
-               err |= __put_user(user.data, &kernel->data);
-       }
-
-       return err ? err : sys_epoll_ctl(epfd, op, fd, kernel);
-}
-
-
-asmlinkage long compat_sys_epoll_wait(int epfd,
-                       struct compat_epoll_event __user *events,
-                       int maxevents, int timeout)
-{
-       long i, ret, err = 0;
-       struct epoll_event __user *kbuf;
-       struct epoll_event ev;
-
-       if ((maxevents <= 0) ||
-                       (maxevents > (INT_MAX / sizeof(struct epoll_event))))
-               return -EINVAL;
-       kbuf = compat_alloc_user_space(sizeof(struct epoll_event) * maxevents);
-       ret = sys_epoll_wait(epfd, kbuf, maxevents, timeout);
-       for (i = 0; i < ret; i++) {
-               err |= __get_user(ev.events, &kbuf[i].events);
-               err |= __get_user(ev.data, &kbuf[i].data);
-               err |= __put_user(ev.events, &events->events);
-               err |= __put_user_unaligned(ev.data, &events->data);
-               events++;
-       }
-
-       return err ? -EFAULT: ret;
-}
-#endif /* CONFIG_HAS_COMPAT_EPOLL_EVENT */
-
 #ifdef TIF_RESTORE_SIGMASK
 asmlinkage long compat_sys_epoll_pwait(int epfd,
                        struct compat_epoll_event __user *events,
@@ -2153,11 +2108,7 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
                sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
        }
 
-#ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
-       err = compat_sys_epoll_wait(epfd, events, maxevents, timeout);
-#else
        err = sys_epoll_wait(epfd, events, maxevents, timeout);
-#endif
 
        /*
         * If we changed the signal mask, we need to restore the original one.
@@ -2206,19 +2157,41 @@ asmlinkage long compat_sys_signalfd(int ufd,
 
 #ifdef CONFIG_TIMERFD
 
-asmlinkage long compat_sys_timerfd(int ufd, int clockid, int flags,
-                                  const struct compat_itimerspec __user *utmr)
+asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
+                                  const struct compat_itimerspec __user *utmr,
+                                  struct compat_itimerspec __user *otmr)
 {
+       int error;
        struct itimerspec t;
        struct itimerspec __user *ut;
 
        if (get_compat_itimerspec(&t, utmr))
                return -EFAULT;
-       ut = compat_alloc_user_space(sizeof(*ut));
-       if (copy_to_user(ut, &t, sizeof(t)))
+       ut = compat_alloc_user_space(2 * sizeof(struct itimerspec));
+       if (copy_to_user(&ut[0], &t, sizeof(t)))
                return -EFAULT;
+       error = sys_timerfd_settime(ufd, flags, &ut[0], &ut[1]);
+       if (!error && otmr)
+               error = (copy_from_user(&t, &ut[1], sizeof(struct itimerspec)) ||
+                        put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0;
+
+       return error;
+}
+
+asmlinkage long compat_sys_timerfd_gettime(int ufd,
+                                  struct compat_itimerspec __user *otmr)
+{
+       int error;
+       struct itimerspec t;
+       struct itimerspec __user *ut;
 
-       return sys_timerfd(ufd, clockid, flags, ut);
+       ut = compat_alloc_user_space(sizeof(struct itimerspec));
+       error = sys_timerfd_gettime(ufd, ut);
+       if (!error)
+               error = (copy_from_user(&t, ut, sizeof(struct itimerspec)) ||
+                        put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0;
+
+       return error;
 }
 
 #endif /* CONFIG_TIMERFD */
index d9ca1e5ceb92f02302fdeedb7bc1e2b6e5768f2e..44f6cf23b70e3baf4affccf31a68568aff7dd496 100644 (file)
@@ -89,7 +89,7 @@ static void d_free(struct dentry *dentry)
        if (dentry->d_op && dentry->d_op->d_release)
                dentry->d_op->d_release(dentry);
        /* if dentry was never inserted into hash, immediate free is OK */
-       if (dentry->d_hash.pprev == NULL)
+       if (hlist_unhashed(&dentry->d_hash))
                __d_free(dentry);
        else
                call_rcu(&dentry->d_u.d_rcu, d_callback);
@@ -1408,9 +1408,6 @@ void d_delete(struct dentry * dentry)
        if (atomic_read(&dentry->d_count) == 1) {
                dentry_iput(dentry);
                fsnotify_nameremove(dentry, isdir);
-
-               /* remove this and other inotify debug checks after 2.6.18 */
-               dentry->d_flags &= ~DCACHE_INOTIFY_PARENT_WATCHED;
                return;
        }
 
index acf0da1bd257158fa79b0ba9f9f34b58a7207562..9e81addbd6ea7293ad3d2578d20bfeaf92cf8354 100644 (file)
@@ -878,8 +878,8 @@ do_holes:
                                        page_cache_release(page);
                                        goto out;
                                }
-                               zero_user_page(page, block_in_page << blkbits,
-                                               1 << blkbits, KM_USER0);
+                               zero_user(page, block_in_page << blkbits,
+                                               1 << blkbits);
                                dio->block_in_file++;
                                block_in_page++;
                                goto next_block;
index cee7c6f428f0fa518e80bda281eb92421a5ac295..def4e969df77646192eb6ce96d223a1f78ec4544 100644 (file)
@@ -696,9 +696,8 @@ static int dqinit_needed(struct inode *inode, int type)
 /* This routine is guarded by dqonoff_mutex mutex */
 static void add_dquot_ref(struct super_block *sb, int type)
 {
-       struct inode *inode;
+       struct inode *inode, *old_inode = NULL;
 
-restart:
        spin_lock(&inode_lock);
        list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
                if (!atomic_read(&inode->i_writecount))
@@ -711,12 +710,18 @@ restart:
                __iget(inode);
                spin_unlock(&inode_lock);
 
+               iput(old_inode);
                sb->dq_op->initialize(inode, type);
-               iput(inode);
-               /* As we may have blocked we had better restart... */
-               goto restart;
+               /* We hold a reference to 'inode' so it couldn't have been
+                * removed from s_inodes list while we dropped the inode_lock.
+                * We cannot iput the inode now as we can be holding the last
+                * reference and we cannot iput it under inode_lock. So we
+                * keep the reference and iput it later. */
+               old_inode = inode;
+               spin_lock(&inode_lock);
        }
        spin_unlock(&inode_lock);
+       iput(old_inode);
 }
 
 /* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */
index f8ef0af919e70d27acdb9292acbd0d3d95669bd7..a066e109ad9c05a7cbc0670f92045a3475e9aac1 100644 (file)
@@ -355,8 +355,11 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat,
        }
        /* Consider doing this once, when the file is opened */
        mutex_lock(&crypt_stat->cs_tfm_mutex);
-       rc = crypto_blkcipher_setkey(crypt_stat->tfm, crypt_stat->key,
-                                    crypt_stat->key_size);
+       if (!(crypt_stat->flags & ECRYPTFS_KEY_SET)) {
+               rc = crypto_blkcipher_setkey(crypt_stat->tfm, crypt_stat->key,
+                                            crypt_stat->key_size);
+               crypt_stat->flags |= ECRYPTFS_KEY_SET;
+       }
        if (rc) {
                ecryptfs_printk(KERN_ERR, "Error setting key; rc = [%d]\n",
                                rc);
@@ -376,11 +379,10 @@ out:
  *
  * Convert an eCryptfs page index into a lower byte offset
  */
-void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num,
-                                     struct ecryptfs_crypt_stat *crypt_stat)
+static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num,
+                                            struct ecryptfs_crypt_stat *crypt_stat)
 {
-       (*offset) = ((crypt_stat->extent_size
-                     * crypt_stat->num_header_extents_at_front)
+       (*offset) = (crypt_stat->num_header_bytes_at_front
                     + (crypt_stat->extent_size * extent_num));
 }
 
@@ -842,15 +844,13 @@ void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat)
        set_extent_mask_and_shift(crypt_stat);
        crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES;
        if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
-               crypt_stat->num_header_extents_at_front = 0;
+               crypt_stat->num_header_bytes_at_front = 0;
        else {
                if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)
-                       crypt_stat->num_header_extents_at_front =
-                               (ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE
-                                / crypt_stat->extent_size);
+                       crypt_stat->num_header_bytes_at_front =
+                               ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
                else
-                       crypt_stat->num_header_extents_at_front =
-                               (PAGE_CACHE_SIZE / crypt_stat->extent_size);
+                       crypt_stat->num_header_bytes_at_front = PAGE_CACHE_SIZE;
        }
 }
 
@@ -1128,7 +1128,7 @@ write_ecryptfs_flags(char *page_virt, struct ecryptfs_crypt_stat *crypt_stat,
 
 struct ecryptfs_cipher_code_str_map_elem {
        char cipher_str[16];
-       u16 cipher_code;
+       u8 cipher_code;
 };
 
 /* Add support for additional ciphers by adding elements here. The
@@ -1152,10 +1152,10 @@ ecryptfs_cipher_code_str_map[] = {
  *
  * Returns zero on no match, or the cipher code on match
  */
-u16 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat)
+u8 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat)
 {
        int i;
-       u16 code = 0;
+       u8 code = 0;
        struct ecryptfs_cipher_code_str_map_elem *map =
                ecryptfs_cipher_code_str_map;
 
@@ -1187,7 +1187,7 @@ u16 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat)
  *
  * Returns zero on success
  */
-int ecryptfs_cipher_code_to_string(char *str, u16 cipher_code)
+int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code)
 {
        int rc = 0;
        int i;
@@ -1236,7 +1236,8 @@ ecryptfs_write_header_metadata(char *virt,
 
        header_extent_size = (u32)crypt_stat->extent_size;
        num_header_extents_at_front =
-               (u16)crypt_stat->num_header_extents_at_front;
+               (u16)(crypt_stat->num_header_bytes_at_front
+                     / crypt_stat->extent_size);
        header_extent_size = cpu_to_be32(header_extent_size);
        memcpy(virt, &header_extent_size, 4);
        virt += 4;
@@ -1311,40 +1312,16 @@ static int ecryptfs_write_headers_virt(char *page_virt, size_t *size,
 static int
 ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat,
                                    struct dentry *ecryptfs_dentry,
-                                   char *page_virt)
+                                   char *virt)
 {
-       int current_header_page;
-       int header_pages;
        int rc;
 
-       rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, page_virt,
-                                 0, PAGE_CACHE_SIZE);
-       if (rc) {
+       rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt,
+                                 0, crypt_stat->num_header_bytes_at_front);
+       if (rc)
                printk(KERN_ERR "%s: Error attempting to write header "
                       "information to lower file; rc = [%d]\n", __FUNCTION__,
                       rc);
-               goto out;
-       }
-       header_pages = ((crypt_stat->extent_size
-                        * crypt_stat->num_header_extents_at_front)
-                       / PAGE_CACHE_SIZE);
-       memset(page_virt, 0, PAGE_CACHE_SIZE);
-       current_header_page = 1;
-       while (current_header_page < header_pages) {
-               loff_t offset;
-
-               offset = (((loff_t)current_header_page) << PAGE_CACHE_SHIFT);
-               if ((rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode,
-                                              page_virt, offset,
-                                              PAGE_CACHE_SIZE))) {
-                       printk(KERN_ERR "%s: Error attempting to write header "
-                              "information to lower file; rc = [%d]\n",
-                              __FUNCTION__, rc);
-                       goto out;
-               }
-               current_header_page++;
-       }
-out:
        return rc;
 }
 
@@ -1370,15 +1347,13 @@ ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry,
  * retrieved via a prompt.  Exactly what happens at this point should
  * be policy-dependent.
  *
- * TODO: Support header information spanning multiple pages
- *
  * Returns zero on success; non-zero on error
  */
 int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry)
 {
        struct ecryptfs_crypt_stat *crypt_stat =
                &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat;
-       char *page_virt;
+       char *virt;
        size_t size = 0;
        int rc = 0;
 
@@ -1389,40 +1364,39 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry)
                        goto out;
                }
        } else {
+               printk(KERN_WARNING "%s: Encrypted flag not set\n",
+                      __FUNCTION__);
                rc = -EINVAL;
-               ecryptfs_printk(KERN_WARNING,
-                               "Called with crypt_stat->encrypted == 0\n");
                goto out;
        }
        /* Released in this function */
-       page_virt = kmem_cache_zalloc(ecryptfs_header_cache_0, GFP_USER);
-       if (!page_virt) {
-               ecryptfs_printk(KERN_ERR, "Out of memory\n");
+       virt = kzalloc(crypt_stat->num_header_bytes_at_front, GFP_KERNEL);
+       if (!virt) {
+               printk(KERN_ERR "%s: Out of memory\n", __FUNCTION__);
                rc = -ENOMEM;
                goto out;
        }
-       rc = ecryptfs_write_headers_virt(page_virt, &size, crypt_stat,
-                                        ecryptfs_dentry);
+       rc = ecryptfs_write_headers_virt(virt, &size, crypt_stat,
+                                        ecryptfs_dentry);
        if (unlikely(rc)) {
-               ecryptfs_printk(KERN_ERR, "Error whilst writing headers\n");
-               memset(page_virt, 0, PAGE_CACHE_SIZE);
+               printk(KERN_ERR "%s: Error whilst writing headers; rc = [%d]\n",
+                      __FUNCTION__, rc);
                goto out_free;
        }
        if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
                rc = ecryptfs_write_metadata_to_xattr(ecryptfs_dentry,
-                                                     crypt_stat, page_virt,
-                                                     size);
+                                                     crypt_stat, virt, size);
        else
                rc = ecryptfs_write_metadata_to_contents(crypt_stat,
-                                                        ecryptfs_dentry,
-                                                        page_virt);
+                                                        ecryptfs_dentry, virt);
        if (rc) {
-               printk(KERN_ERR "Error writing metadata out to lower file; "
-                      "rc = [%d]\n", rc);
+               printk(KERN_ERR "%s: Error writing metadata out to lower file; "
+                      "rc = [%d]\n", __FUNCTION__, rc);
                goto out_free;
        }
 out_free:
-       kmem_cache_free(ecryptfs_header_cache_0, page_virt);
+       memset(virt, 0, crypt_stat->num_header_bytes_at_front);
+       kfree(virt);
 out:
        return rc;
 }
@@ -1442,16 +1416,16 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat,
        virt += sizeof(u32);
        memcpy(&num_header_extents_at_front, virt, sizeof(u16));
        num_header_extents_at_front = be16_to_cpu(num_header_extents_at_front);
-       crypt_stat->num_header_extents_at_front =
-               (int)num_header_extents_at_front;
+       crypt_stat->num_header_bytes_at_front =
+               (((size_t)num_header_extents_at_front
+                 * (size_t)header_extent_size));
        (*bytes_read) = (sizeof(u32) + sizeof(u16));
        if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE)
-           && ((crypt_stat->extent_size
-                * crypt_stat->num_header_extents_at_front)
+           && (crypt_stat->num_header_bytes_at_front
                < ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) {
                rc = -EINVAL;
-               printk(KERN_WARNING "Invalid number of header extents: [%zd]\n",
-                      crypt_stat->num_header_extents_at_front);
+               printk(KERN_WARNING "Invalid header size: [%zd]\n",
+                      crypt_stat->num_header_bytes_at_front);
        }
        return rc;
 }
@@ -1466,7 +1440,8 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat,
  */
 static void set_default_header_data(struct ecryptfs_crypt_stat *crypt_stat)
 {
-       crypt_stat->num_header_extents_at_front = 2;
+       crypt_stat->num_header_bytes_at_front =
+               ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
 }
 
 /**
@@ -1552,9 +1527,10 @@ int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode)
        size = ecryptfs_getxattr_lower(lower_dentry, ECRYPTFS_XATTR_NAME,
                                       page_virt, ECRYPTFS_DEFAULT_EXTENT_SIZE);
        if (size < 0) {
-               printk(KERN_ERR "Error attempting to read the [%s] "
-                      "xattr from the lower file; return value = [%zd]\n",
-                      ECRYPTFS_XATTR_NAME, size);
+               if (unlikely(ecryptfs_verbosity > 0))
+                       printk(KERN_INFO "Error attempting to read the [%s] "
+                              "xattr from the lower file; return value = "
+                              "[%zd]\n", ECRYPTFS_XATTR_NAME, size);
                rc = -EINVAL;
                goto out;
        }
@@ -1802,7 +1778,7 @@ out:
 }
 
 struct kmem_cache *ecryptfs_key_tfm_cache;
-struct list_head key_tfm_list;
+static struct list_head key_tfm_list;
 struct mutex key_tfm_list_mutex;
 
 int ecryptfs_init_crypto(void)
@@ -1812,6 +1788,11 @@ int ecryptfs_init_crypto(void)
        return 0;
 }
 
+/**
+ * ecryptfs_destroy_crypto - free all cached key_tfms on key_tfm_list
+ *
+ * Called only at module unload time
+ */
 int ecryptfs_destroy_crypto(void)
 {
        struct ecryptfs_key_tfm *key_tfm, *key_tfm_tmp;
@@ -1835,6 +1816,8 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
        struct ecryptfs_key_tfm *tmp_tfm;
        int rc = 0;
 
+       BUG_ON(!mutex_is_locked(&key_tfm_list_mutex));
+
        tmp_tfm = kmem_cache_alloc(ecryptfs_key_tfm_cache, GFP_KERNEL);
        if (key_tfm != NULL)
                (*key_tfm) = tmp_tfm;
@@ -1861,13 +1844,50 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
                        (*key_tfm) = NULL;
                goto out;
        }
-       mutex_lock(&key_tfm_list_mutex);
        list_add(&tmp_tfm->key_tfm_list, &key_tfm_list);
-       mutex_unlock(&key_tfm_list_mutex);
 out:
        return rc;
 }
 
+/**
+ * ecryptfs_tfm_exists - Search for existing tfm for cipher_name.
+ * @cipher_name: the name of the cipher to search for
+ * @key_tfm: set to corresponding tfm if found
+ *
+ * Searches for cached key_tfm matching @cipher_name
+ * Must be called with &key_tfm_list_mutex held
+ * Returns 1 if found, with @key_tfm set
+ * Returns 0 if not found, with @key_tfm set to NULL
+ */
+int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm)
+{
+       struct ecryptfs_key_tfm *tmp_key_tfm;
+
+       BUG_ON(!mutex_is_locked(&key_tfm_list_mutex));
+
+       list_for_each_entry(tmp_key_tfm, &key_tfm_list, key_tfm_list) {
+               if (strcmp(tmp_key_tfm->cipher_name, cipher_name) == 0) {
+                       if (key_tfm)
+                               (*key_tfm) = tmp_key_tfm;
+                       return 1;
+               }
+       }
+       if (key_tfm)
+               (*key_tfm) = NULL;
+       return 0;
+}
+
+/**
+ * ecryptfs_get_tfm_and_mutex_for_cipher_name
+ *
+ * @tfm: set to cached tfm found, or new tfm created
+ * @tfm_mutex: set to mutex for cached tfm found, or new tfm created
+ * @cipher_name: the name of the cipher to search for and/or add
+ *
+ * Sets pointers to @tfm & @tfm_mutex matching @cipher_name.
+ * Searches for cached item first, and creates new if not found.
+ * Returns 0 on success, non-zero if adding new cipher failed
+ */
 int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm,
                                               struct mutex **tfm_mutex,
                                               char *cipher_name)
@@ -1877,22 +1897,17 @@ int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm,
 
        (*tfm) = NULL;
        (*tfm_mutex) = NULL;
+
        mutex_lock(&key_tfm_list_mutex);
-       list_for_each_entry(key_tfm, &key_tfm_list, key_tfm_list) {
-               if (strcmp(key_tfm->cipher_name, cipher_name) == 0) {
-                       (*tfm) = key_tfm->key_tfm;
-                       (*tfm_mutex) = &key_tfm->key_tfm_mutex;
-                       mutex_unlock(&key_tfm_list_mutex);
+       if (!ecryptfs_tfm_exists(cipher_name, &key_tfm)) {
+               rc = ecryptfs_add_new_key_tfm(&key_tfm, cipher_name, 0);
+               if (rc) {
+                       printk(KERN_ERR "Error adding new key_tfm to list; "
+                                       "rc = [%d]\n", rc);
                        goto out;
                }
        }
        mutex_unlock(&key_tfm_list_mutex);
-       rc = ecryptfs_add_new_key_tfm(&key_tfm, cipher_name, 0);
-       if (rc) {
-               printk(KERN_ERR "Error adding new key_tfm to list; rc = [%d]\n",
-                      rc);
-               goto out;
-       }
        (*tfm) = key_tfm->key_tfm;
        (*tfm_mutex) = &key_tfm->key_tfm_mutex;
 out:
index ce7a5d4aec36895014a60ee4771efadb94e40342..5007f788da01cec21fb39be75f714840ce6d29e9 100644 (file)
@@ -234,10 +234,11 @@ struct ecryptfs_crypt_stat {
 #define ECRYPTFS_KEY_VALID          0x00000080
 #define ECRYPTFS_METADATA_IN_XATTR  0x00000100
 #define ECRYPTFS_VIEW_AS_ENCRYPTED  0x00000200
+#define ECRYPTFS_KEY_SET            0x00000400
        u32 flags;
        unsigned int file_version;
        size_t iv_bytes;
-       size_t num_header_extents_at_front;
+       size_t num_header_bytes_at_front;
        size_t extent_size; /* Data extent size; default is 4096 */
        size_t key_size;
        size_t extent_shift;
@@ -322,7 +323,6 @@ struct ecryptfs_key_tfm {
        unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
 };
 
-extern struct list_head key_tfm_list;
 extern struct mutex key_tfm_list_mutex;
 
 /**
@@ -521,11 +521,9 @@ extern struct kmem_cache *ecryptfs_file_info_cache;
 extern struct kmem_cache *ecryptfs_dentry_info_cache;
 extern struct kmem_cache *ecryptfs_inode_info_cache;
 extern struct kmem_cache *ecryptfs_sb_info_cache;
-extern struct kmem_cache *ecryptfs_header_cache_0;
 extern struct kmem_cache *ecryptfs_header_cache_1;
 extern struct kmem_cache *ecryptfs_header_cache_2;
 extern struct kmem_cache *ecryptfs_xattr_cache;
-extern struct kmem_cache *ecryptfs_lower_page_cache;
 extern struct kmem_cache *ecryptfs_key_record_cache;
 extern struct kmem_cache *ecryptfs_key_sig_cache;
 extern struct kmem_cache *ecryptfs_global_auth_tok_cache;
@@ -562,8 +560,8 @@ int ecryptfs_read_and_validate_header_region(char *data,
                                             struct inode *ecryptfs_inode);
 int ecryptfs_read_and_validate_xattr_region(char *page_virt,
                                            struct dentry *ecryptfs_dentry);
-u16 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat);
-int ecryptfs_cipher_code_to_string(char *str, u16 cipher_code);
+u8 ecryptfs_code_for_cipher_string(struct ecryptfs_crypt_stat *crypt_stat);
+int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code);
 void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat);
 int ecryptfs_generate_key_packet_set(char *dest_base,
                                     struct ecryptfs_crypt_stat *crypt_stat,
@@ -576,8 +574,6 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
 int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode);
 int ecryptfs_inode_set(struct inode *inode, void *lower_inode);
 void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode);
-ssize_t ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
-                         size_t size);
 ssize_t
 ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
                        void *value, size_t size);
@@ -623,6 +619,7 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
                         size_t key_size);
 int ecryptfs_init_crypto(void);
 int ecryptfs_destroy_crypto(void);
+int ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm);
 int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm,
                                               struct mutex **tfm_mutex,
                                               char *cipher_name);
@@ -631,8 +628,6 @@ int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key,
                                      char *sig);
 int ecryptfs_write_zeros(struct file *file, pgoff_t index, int start,
                         int num_zeros);
-void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num,
-                                     struct ecryptfs_crypt_stat *crypt_stat);
 int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
                         loff_t offset, size_t size);
 int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
@@ -646,8 +641,6 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
                                     pgoff_t page_index,
                                     size_t offset_in_page, size_t size,
                                     struct inode *ecryptfs_inode);
-int ecryptfs_read(char *data, loff_t offset, size_t size,
-                 struct file *ecryptfs_file);
 struct page *ecryptfs_get_locked_page(struct file *file, loff_t index);
 
 #endif /* #ifndef ECRYPTFS_KERNEL_H */
index c98c4690a771c78ad69d3188be2a595be081fa66..2b8f5ed4adea534063ae77259d366c426f9d5725 100644 (file)
@@ -209,9 +209,10 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
                        if (!(mount_crypt_stat->flags
                              & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
                                rc = -EIO;
-                               printk(KERN_WARNING "Attempt to read file that "
+                               printk(KERN_WARNING "Either the lower file "
                                       "is not in a valid eCryptfs format, "
-                                      "and plaintext passthrough mode is not "
+                                      "or the key could not be retrieved. "
+                                      "Plaintext passthrough mode is not "
                                       "enabled; returning -EIO\n");
                                mutex_unlock(&crypt_stat->cs_mutex);
                                goto out_free;
index 5a719180983cb36ebf3e264dc45c1559ebc209c0..edd1e44e9d474bdb46a5b7820192cef29c95cf92 100644 (file)
@@ -365,8 +365,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
                dentry->d_sb)->mount_crypt_stat;
        if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) {
                if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
-                       file_size = ((crypt_stat->extent_size
-                                     * crypt_stat->num_header_extents_at_front)
+                       file_size = (crypt_stat->num_header_bytes_at_front
                                     + i_size_read(lower_dentry->d_inode));
                else
                        file_size = i_size_read(lower_dentry->d_inode);
@@ -685,7 +684,7 @@ ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
  * @crypt_stat: Crypt_stat associated with file
  * @upper_size: Size of the upper file
  *
- * Calculate the requried size of the lower file based on the
+ * Calculate the required size of the lower file based on the
  * specified size of the upper file. This calculation is based on the
  * number of headers in the underlying file and the extent size.
  *
@@ -697,8 +696,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
 {
        loff_t lower_size;
 
-       lower_size = (crypt_stat->extent_size
-                     * crypt_stat->num_header_extents_at_front);
+       lower_size = crypt_stat->num_header_bytes_at_front;
        if (upper_size != 0) {
                loff_t num_extents;
 
@@ -875,11 +873,11 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
                        if (!(mount_crypt_stat->flags
                              & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
                                rc = -EIO;
-                               printk(KERN_WARNING "Attempt to read file that "
+                               printk(KERN_WARNING "Either the lower file "
                                       "is not in a valid eCryptfs format, "
-                                      "and plaintext passthrough mode is not "
+                                      "or the key could not be retrieved. "
+                                      "Plaintext passthrough mode is not "
                                       "enabled; returning -EIO\n");
-
                                mutex_unlock(&crypt_stat->cs_mutex);
                                goto out;
                        }
@@ -954,7 +952,7 @@ out:
        return rc;
 }
 
-ssize_t
+static ssize_t
 ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
                  size_t size)
 {
index f458c1f355655fcee80e3b8d4346d611686f3bc9..682b1b2482c26a062cefeaf924787242f89612d1 100644 (file)
@@ -189,7 +189,7 @@ out:
 }
 
 static int
-parse_tag_65_packet(struct ecryptfs_session_key *session_key, u16 *cipher_code,
+parse_tag_65_packet(struct ecryptfs_session_key *session_key, u8 *cipher_code,
                    struct ecryptfs_message *msg)
 {
        size_t i = 0;
@@ -275,7 +275,7 @@ out:
 
 
 static int
-write_tag_66_packet(char *signature, size_t cipher_code,
+write_tag_66_packet(char *signature, u8 cipher_code,
                    struct ecryptfs_crypt_stat *crypt_stat, char **packet,
                    size_t *packet_len)
 {
@@ -428,7 +428,7 @@ static int
 decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
                                  struct ecryptfs_crypt_stat *crypt_stat)
 {
-       u16 cipher_code = 0;
+       u8 cipher_code = 0;
        struct ecryptfs_msg_ctx *msg_ctx;
        struct ecryptfs_message *msg = NULL;
        char *auth_tok_sig;
@@ -1537,7 +1537,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
        struct scatterlist dst_sg;
        struct scatterlist src_sg;
        struct mutex *tfm_mutex = NULL;
-       size_t cipher_code;
+       u8 cipher_code;
        size_t packet_size_length;
        size_t max_packet_size;
        struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
index 0249aa4ae181886cd2a26921a465feb5f8d27d41..778c420e4cac4c5d8bfda354c260e819106967c4 100644 (file)
@@ -117,7 +117,7 @@ void __ecryptfs_printk(const char *fmt, ...)
  *
  * Returns zero on success; non-zero otherwise
  */
-int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
+static int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
 {
        struct ecryptfs_inode_info *inode_info =
                ecryptfs_inode_to_private(ecryptfs_dentry->d_inode);
@@ -226,17 +226,15 @@ out:
        return rc;
 }
 
-enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, ecryptfs_opt_debug,
-       ecryptfs_opt_ecryptfs_debug, ecryptfs_opt_cipher,
-       ecryptfs_opt_ecryptfs_cipher, ecryptfs_opt_ecryptfs_key_bytes,
+enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
+       ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
+       ecryptfs_opt_ecryptfs_key_bytes,
        ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
        ecryptfs_opt_encrypted_view, ecryptfs_opt_err };
 
 static match_table_t tokens = {
        {ecryptfs_opt_sig, "sig=%s"},
        {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
-       {ecryptfs_opt_debug, "debug=%u"},
-       {ecryptfs_opt_ecryptfs_debug, "ecryptfs_debug=%u"},
        {ecryptfs_opt_cipher, "cipher=%s"},
        {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
        {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
@@ -313,7 +311,6 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options)
        substring_t args[MAX_OPT_ARGS];
        int token;
        char *sig_src;
-       char *debug_src;
        char *cipher_name_dst;
        char *cipher_name_src;
        char *cipher_key_bytes_src;
@@ -341,16 +338,6 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options)
                        }
                        sig_set = 1;
                        break;
-               case ecryptfs_opt_debug:
-               case ecryptfs_opt_ecryptfs_debug:
-                       debug_src = args[0].from;
-                       ecryptfs_verbosity =
-                               (int)simple_strtol(debug_src, &debug_src,
-                                                  0);
-                       ecryptfs_printk(KERN_DEBUG,
-                                       "Verbosity set to [%d]" "\n",
-                                       ecryptfs_verbosity);
-                       break;
                case ecryptfs_opt_cipher:
                case ecryptfs_opt_ecryptfs_cipher:
                        cipher_name_src = args[0].from;
@@ -423,9 +410,13 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options)
        if (!cipher_key_bytes_set) {
                mount_crypt_stat->global_default_cipher_key_size = 0;
        }
-       rc = ecryptfs_add_new_key_tfm(
-               NULL, mount_crypt_stat->global_default_cipher_name,
-               mount_crypt_stat->global_default_cipher_key_size);
+       mutex_lock(&key_tfm_list_mutex);
+       if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
+                                NULL))
+               rc = ecryptfs_add_new_key_tfm(
+                       NULL, mount_crypt_stat->global_default_cipher_name,
+                       mount_crypt_stat->global_default_cipher_key_size);
+       mutex_unlock(&key_tfm_list_mutex);
        if (rc) {
                printk(KERN_ERR "Error attempting to initialize cipher with "
                       "name = [%s] and key size = [%td]; rc = [%d]\n",
@@ -653,11 +644,6 @@ static struct ecryptfs_cache_info {
                .name = "ecryptfs_sb_cache",
                .size = sizeof(struct ecryptfs_sb_info),
        },
-       {
-               .cache = &ecryptfs_header_cache_0,
-               .name = "ecryptfs_headers_0",
-               .size = PAGE_CACHE_SIZE,
-       },
        {
                .cache = &ecryptfs_header_cache_1,
                .name = "ecryptfs_headers_1",
@@ -821,6 +807,10 @@ static int __init ecryptfs_init(void)
                       "rc = [%d]\n", rc);
                goto out_release_messaging;
        }
+       if (ecryptfs_verbosity > 0)
+               printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
+                       "will be written to the syslog!\n", ecryptfs_verbosity);
+
        goto out;
 out_release_messaging:
        ecryptfs_release_messaging(ecryptfs_transport);
index 32c5711d79a320593e9a536590f3b347905055bd..dc74b186145d74db8a56470d5ef2e63ea5c0a3c0 100644 (file)
@@ -34,8 +34,6 @@
 #include <linux/scatterlist.h>
 #include "ecryptfs_kernel.h"
 
-struct kmem_cache *ecryptfs_lower_page_cache;
-
 /**
  * ecryptfs_get_locked_page
  *
@@ -102,13 +100,14 @@ static void set_header_info(char *page_virt,
                            struct ecryptfs_crypt_stat *crypt_stat)
 {
        size_t written;
-       int save_num_header_extents_at_front =
-               crypt_stat->num_header_extents_at_front;
+       size_t save_num_header_bytes_at_front =
+               crypt_stat->num_header_bytes_at_front;
 
-       crypt_stat->num_header_extents_at_front = 1;
+       crypt_stat->num_header_bytes_at_front =
+               ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
        ecryptfs_write_header_metadata(page_virt + 20, crypt_stat, &written);
-       crypt_stat->num_header_extents_at_front =
-               save_num_header_extents_at_front;
+       crypt_stat->num_header_bytes_at_front =
+               save_num_header_bytes_at_front;
 }
 
 /**
@@ -134,8 +133,11 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
                loff_t view_extent_num = ((((loff_t)page->index)
                                           * num_extents_per_page)
                                          + extent_num_in_page);
+               size_t num_header_extents_at_front =
+                       (crypt_stat->num_header_bytes_at_front
+                        / crypt_stat->extent_size);
 
-               if (view_extent_num < crypt_stat->num_header_extents_at_front) {
+               if (view_extent_num < num_header_extents_at_front) {
                        /* This is a header extent */
                        char *page_virt;
 
@@ -157,9 +159,8 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
                } else {
                        /* This is an encrypted data extent */
                        loff_t lower_offset =
-                               ((view_extent_num -
-                                 crypt_stat->num_header_extents_at_front)
-                                * crypt_stat->extent_size);
+                               ((view_extent_num * crypt_stat->extent_size)
+                                - crypt_stat->num_header_bytes_at_front);
 
                        rc = ecryptfs_read_lower_page_segment(
                                page, (lower_offset >> PAGE_CACHE_SHIFT),
@@ -257,8 +258,7 @@ static int fill_zeros_to_end_of_page(struct page *page, unsigned int to)
        end_byte_in_page = i_size_read(inode) % PAGE_CACHE_SIZE;
        if (to > end_byte_in_page)
                end_byte_in_page = to;
-       zero_user_page(page, end_byte_in_page,
-               PAGE_CACHE_SIZE - end_byte_in_page, KM_USER0);
+       zero_user_segment(page, end_byte_in_page, PAGE_CACHE_SIZE);
 out:
        return 0;
 }
@@ -307,7 +307,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
         */
        if ((i_size_read(page->mapping->host) == prev_page_end_size) &&
            (from != 0)) {
-               zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
+               zero_user(page, 0, PAGE_CACHE_SIZE);
        }
 out:
        return rc;
index 948f57624c05dd2bb1750ff05628f7931f44f2b7..0c4928623bbc414f7f0a4861e4dc727bfcdf132f 100644 (file)
@@ -293,6 +293,7 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
        return rc;
 }
 
+#if 0
 /**
  * ecryptfs_read
  * @data: The virtual address into which to write the data read (and
@@ -371,3 +372,4 @@ int ecryptfs_read(char *data, loff_t offset, size_t size,
 out:
        return rc;
 }
+#endif  /*  0  */
index 4859c4eecd654c8b7493f51fec4fee228a9f3d8f..c27ac2b358a12d7334003980b4b7d5fc8066cffa 100644 (file)
@@ -156,32 +156,38 @@ static void ecryptfs_clear_inode(struct inode *inode)
 /**
  * ecryptfs_show_options
  *
- * Prints the directory we are currently mounted over.
- * Returns zero on success; non-zero otherwise
+ * Prints the mount options for a given superblock.
+ * Returns zero; does not fail.
  */
 static int ecryptfs_show_options(struct seq_file *m, struct vfsmount *mnt)
 {
        struct super_block *sb = mnt->mnt_sb;
-       struct dentry *lower_root_dentry = ecryptfs_dentry_to_lower(sb->s_root);
-       struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(sb->s_root);
-       char *tmp_page;
-       char *path;
-       int rc = 0;
-
-       tmp_page = (char *)__get_free_page(GFP_KERNEL);
-       if (!tmp_page) {
-               rc = -ENOMEM;
-               goto out;
-       }
-       path = d_path(lower_root_dentry, lower_mnt, tmp_page, PAGE_SIZE);
-       if (IS_ERR(path)) {
-               rc = PTR_ERR(path);
-               goto out;
+       struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
+               &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
+       struct ecryptfs_global_auth_tok *walker;
+
+       mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex);
+       list_for_each_entry(walker,
+                           &mount_crypt_stat->global_auth_tok_list,
+                           mount_crypt_stat_list) {
+               seq_printf(m, ",ecryptfs_sig=%s", walker->sig);
        }
-       seq_printf(m, ",dir=%s", path);
-       free_page((unsigned long)tmp_page);
-out:
-       return rc;
+       mutex_unlock(&mount_crypt_stat->global_auth_tok_list_mutex);
+
+       seq_printf(m, ",ecryptfs_cipher=%s",
+               mount_crypt_stat->global_default_cipher_name);
+
+       if (mount_crypt_stat->global_default_cipher_key_size)
+               seq_printf(m, ",ecryptfs_key_bytes=%zd",
+                          mount_crypt_stat->global_default_cipher_key_size);
+       if (mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)
+               seq_printf(m, ",ecryptfs_passthrough");
+       if (mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED)
+               seq_printf(m, ",ecryptfs_xattr_metadata");
+       if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
+               seq_printf(m, ",ecryptfs_encrypted_view");
+
+       return 0;
 }
 
 const struct super_operations ecryptfs_sops = {
index 2ce19c000d2adb40afc17205edcb937cbb84d730..a9f130cd50ac2be6009ed2091fce0ec21d134fdd 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/spinlock.h>
 #include <linux/anon_inodes.h>
 #include <linux/eventfd.h>
+#include <linux/syscalls.h>
 
 struct eventfd_ctx {
        wait_queue_head_t wqh;
index 81c04abfb1aaf2e6d3a19df7f67f31132ca2556e..a415f42d32cf66aba720da4e05b2a0ccfdd55663 100644 (file)
@@ -353,7 +353,7 @@ static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq)
        spin_unlock_irqrestore(&psw->lock, flags);
 
        /* Do really wake up now */
-       wake_up(wq);
+       wake_up_nested(wq, 1 + wake_nests);
 
        /* Remove the current task from the list */
        spin_lock_irqsave(&psw->lock, flags);
index 282240afe99e5e223b1732c4c1b58245d90618d8..be923e4bc38972954325aee09363cb38bff60884 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -760,7 +760,7 @@ static int de_thread(struct task_struct *tsk)
         */
        read_lock(&tasklist_lock);
        spin_lock_irq(lock);
-       if (sig->flags & SIGNAL_GROUP_EXIT) {
+       if (signal_group_exit(sig)) {
                /*
                 * Another group action in progress, just
                 * return so that the signal is processed.
@@ -778,6 +778,7 @@ static int de_thread(struct task_struct *tsk)
        if (unlikely(tsk->group_leader == task_child_reaper(tsk)))
                task_active_pid_ns(tsk)->child_reaper = tsk;
 
+       sig->group_exit_task = tsk;
        zap_other_threads(tsk);
        read_unlock(&tasklist_lock);
 
@@ -802,7 +803,6 @@ static int de_thread(struct task_struct *tsk)
        }
 
        sig->notify_count = count;
-       sig->group_exit_task = tsk;
        while (atomic_read(&sig->count) > count) {
                __set_current_state(TASK_UNINTERRUPTIBLE);
                spin_unlock_irq(lock);
@@ -871,15 +871,10 @@ static int de_thread(struct task_struct *tsk)
                leader->exit_state = EXIT_DEAD;
 
                write_unlock_irq(&tasklist_lock);
-        }
+       }
 
        sig->group_exit_task = NULL;
        sig->notify_count = 0;
-       /*
-        * There may be one thread left which is just exiting,
-        * but it's safe to stop telling the group to kill themselves.
-        */
-       sig->flags = 0;
 
 no_thread_group:
        exit_itimers(sig);
@@ -947,12 +942,13 @@ static void flush_old_files(struct files_struct * files)
        spin_unlock(&files->file_lock);
 }
 
-void get_task_comm(char *buf, struct task_struct *tsk)
+char *get_task_comm(char *buf, struct task_struct *tsk)
 {
        /* buf must be at least sizeof(tsk->comm) in size */
        task_lock(tsk);
        strncpy(buf, tsk->comm, sizeof(tsk->comm));
        task_unlock(tsk);
+       return buf;
 }
 
 void set_task_comm(struct task_struct *tsk, char *buf)
@@ -1548,7 +1544,7 @@ static inline int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
        int err = -EAGAIN;
 
        spin_lock_irq(&tsk->sighand->siglock);
-       if (!(tsk->signal->flags & SIGNAL_GROUP_EXIT)) {
+       if (!signal_group_exit(tsk->signal)) {
                tsk->signal->group_exit_code = exit_code;
                zap_process(tsk);
                err = 0;
index 377ad172d74b1c5e8110393d875d5499f9bfe199..e7b2bafa1dd91cd69f8caf4597654a6355c3a666 100644 (file)
@@ -69,9 +69,53 @@ struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
        return desc + offset;
 }
 
+static int ext2_valid_block_bitmap(struct super_block *sb,
+                                       struct ext2_group_desc *desc,
+                                       unsigned int block_group,
+                                       struct buffer_head *bh)
+{
+       ext2_grpblk_t offset;
+       ext2_grpblk_t next_zero_bit;
+       ext2_fsblk_t bitmap_blk;
+       ext2_fsblk_t group_first_block;
+
+       group_first_block = ext2_group_first_block_no(sb, block_group);
+
+       /* check whether block bitmap block number is set */
+       bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
+       offset = bitmap_blk - group_first_block;
+       if (!ext2_test_bit(offset, bh->b_data))
+               /* bad block bitmap */
+               goto err_out;
+
+       /* check whether the inode bitmap block number is set */
+       bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
+       offset = bitmap_blk - group_first_block;
+       if (!ext2_test_bit(offset, bh->b_data))
+               /* bad block bitmap */
+               goto err_out;
+
+       /* check whether the inode table block number is set */
+       bitmap_blk = le32_to_cpu(desc->bg_inode_table);
+       offset = bitmap_blk - group_first_block;
+       next_zero_bit = ext2_find_next_zero_bit(bh->b_data,
+                               offset + EXT2_SB(sb)->s_itb_per_group,
+                               offset);
+       if (next_zero_bit >= offset + EXT2_SB(sb)->s_itb_per_group)
+               /* good bitmap for inode tables */
+               return 1;
+
+err_out:
+       ext2_error(sb, __FUNCTION__,
+                       "Invalid block bitmap - "
+                       "block_group = %d, block = %lu",
+                       block_group, bitmap_blk);
+       return 0;
+}
+
 /*
- * Read the bitmap for a given block_group, reading into the specified 
- * slot in the superblock's bitmap cache.
+ * Read the bitmap for a given block_group,and validate the
+ * bits for block/inode/inode tables are set in the bitmaps
  *
  * Return buffer_head on success or NULL in case of failure.
  */
@@ -80,17 +124,36 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
 {
        struct ext2_group_desc * desc;
        struct buffer_head * bh = NULL;
-       
-       desc = ext2_get_group_desc (sb, block_group, NULL);
+       ext2_fsblk_t bitmap_blk;
+
+       desc = ext2_get_group_desc(sb, block_group, NULL);
        if (!desc)
-               goto error_out;
-       bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
-       if (!bh)
-               ext2_error (sb, "read_block_bitmap",
+               return NULL;
+       bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
+       bh = sb_getblk(sb, bitmap_blk);
+       if (unlikely(!bh)) {
+               ext2_error(sb, __FUNCTION__,
+                           "Cannot read block bitmap - "
+                           "block_group = %d, block_bitmap = %u",
+                           block_group, le32_to_cpu(desc->bg_block_bitmap));
+               return NULL;
+       }
+       if (likely(bh_uptodate_or_lock(bh)))
+               return bh;
+
+       if (bh_submit_read(bh) < 0) {
+               brelse(bh);
+               ext2_error(sb, __FUNCTION__,
                            "Cannot read block bitmap - "
                            "block_group = %d, block_bitmap = %u",
                            block_group, le32_to_cpu(desc->bg_block_bitmap));
-error_out:
+               return NULL;
+       }
+       if (!ext2_valid_block_bitmap(sb, desc, block_group, bh)) {
+               brelse(bh);
+               return NULL;
+       }
+
        return bh;
 }
 
@@ -474,11 +537,13 @@ do_more:
            in_range (block, le32_to_cpu(desc->bg_inode_table),
                      sbi->s_itb_per_group) ||
            in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
-                     sbi->s_itb_per_group))
+                     sbi->s_itb_per_group)) {
                ext2_error (sb, "ext2_free_blocks",
                            "Freeing blocks in system zones - "
                            "Block = %lu, count = %lu",
                            block, count);
+               goto error_return;
+       }
 
        for (i = 0, group_freed = 0; i < count; i++) {
                if (!ext2_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
@@ -1250,8 +1315,8 @@ retry_alloc:
        smp_rmb();
 
        /*
-        * Now search the rest of the groups.  We assume that 
-        * i and gdp correctly point to the last group visited.
+        * Now search the rest of the groups.  We assume that
+        * group_no and gdp correctly point to the last group visited.
         */
        for (bgi = 0; bgi < ngroups; bgi++) {
                group_no++;
@@ -1311,11 +1376,13 @@ allocated:
            in_range(ret_block, le32_to_cpu(gdp->bg_inode_table),
                      EXT2_SB(sb)->s_itb_per_group) ||
            in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
-                     EXT2_SB(sb)->s_itb_per_group))
+                     EXT2_SB(sb)->s_itb_per_group)) {
                ext2_error(sb, "ext2_new_blocks",
                            "Allocating block in system zone - "
                            "blocks from "E2FSBLK", length %lu",
                            ret_block, num);
+               goto out;
+       }
 
        performed_allocation = 1;
 
@@ -1466,9 +1533,6 @@ int ext2_bg_has_super(struct super_block *sb, int group)
  */
 unsigned long ext2_bg_num_gdb(struct super_block *sb, int group)
 {
-       if (EXT2_HAS_RO_COMPAT_FEATURE(sb,EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
-           !ext2_group_sparse(group))
-               return 0;
-       return EXT2_SB(sb)->s_gdb_count;
+       return ext2_bg_has_super(sb, group) ? EXT2_SB(sb)->s_gdb_count : 0;
 }
 
index d868e26c15eba90e48c5c1324c9f207ef109d1e6..8dededd80fe2fa6747699c70b81d211b77d49ff0 100644 (file)
@@ -703,7 +703,7 @@ const struct file_operations ext2_dir_operations = {
        .llseek         = generic_file_llseek,
        .read           = generic_read_dir,
        .readdir        = ext2_readdir,
-       .ioctl          = ext2_ioctl,
+       .unlocked_ioctl = ext2_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = ext2_compat_ioctl,
 #endif
index c87ae29c19cb346d86de36513d43a654ff3362e8..bb9948cdd50f8499d5cfc689f00288dad6fd2495 100644 (file)
@@ -139,8 +139,7 @@ int __ext2_write_begin(struct file *file, struct address_space *mapping,
                struct page **pagep, void **fsdata);
 
 /* ioctl.c */
-extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
-                      unsigned long);
+extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
 extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
 
 /* namei.c */
index c051798459a1c9faf33fa9b1c89508145c646c00..5f2fa9c36293d835722ec1371b820b07d5c5d9b5 100644 (file)
@@ -48,7 +48,7 @@ const struct file_operations ext2_file_operations = {
        .write          = do_sync_write,
        .aio_read       = generic_file_aio_read,
        .aio_write      = generic_file_aio_write,
-       .ioctl          = ext2_ioctl,
+       .unlocked_ioctl = ext2_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = ext2_compat_ioctl,
 #endif
@@ -65,7 +65,7 @@ const struct file_operations ext2_xip_file_operations = {
        .llseek         = generic_file_llseek,
        .read           = xip_file_read,
        .write          = xip_file_write,
-       .ioctl          = ext2_ioctl,
+       .unlocked_ioctl = ext2_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = ext2_compat_ioctl,
 #endif
index b1ab32ab5a779381b1b46d29c61bd5fe2eddac44..03978ec2a91c5c547138e9313d276f08cad6e02d 100644 (file)
@@ -286,15 +286,12 @@ static unsigned long ext2_find_near(struct inode *inode, Indirect *ind)
  *     ext2_find_goal - find a prefered place for allocation.
  *     @inode: owner
  *     @block:  block we want
- *     @chain:  chain of indirect blocks
  *     @partial: pointer to the last triple within a chain
  *
  *     Returns preferred place for a block (the goal).
  */
 
-static inline int ext2_find_goal(struct inode *inode,
-                                long block,
-                                Indirect chain[4],
+static inline int ext2_find_goal(struct inode *inode, long block,
                                 Indirect *partial)
 {
        struct ext2_block_alloc_info *block_i;
@@ -569,7 +566,6 @@ static void ext2_splice_branch(struct inode *inode,
  *
  * `handle' can be NULL if create == 0.
  *
- * The BKL may not be held on entry here.  Be sure to take it early.
  * return > 0, # of blocks mapped or allocated.
  * return = 0, if plain lookup failed.
  * return < 0, error case.
@@ -639,7 +635,7 @@ reread:
        if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
                ext2_init_block_alloc_info(inode);
 
-       goal = ext2_find_goal(inode, iblock, chain, partial);
+       goal = ext2_find_goal(inode, iblock, partial);
 
        /* the number of blocks need to allocate for [d,t]indirect blocks */
        indirect_blks = (chain + depth) - partial - 1;
index 320b2cb3d4d22eddf610d7a27d043eeef0437d5e..b8ea11fee5c6fc36e059f9dc873564e82a464ab0 100644 (file)
@@ -17,9 +17,9 @@
 #include <asm/uaccess.h>
 
 
-int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
-               unsigned long arg)
+long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
+       struct inode *inode = filp->f_dentry->d_inode;
        struct ext2_inode_info *ei = EXT2_I(inode);
        unsigned int flags;
        unsigned short rsv_window_size;
@@ -141,9 +141,6 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
 #ifdef CONFIG_COMPAT
 long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
-       struct inode *inode = file->f_path.dentry->d_inode;
-       int ret;
-
        /* These are just misnamed, they actually get/put from/to user an int */
        switch (cmd) {
        case EXT2_IOC32_GETFLAGS:
@@ -161,9 +158,6 @@ long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        default:
                return -ENOIOCTLCMD;
        }
-       lock_kernel();
-       ret = ext2_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
-       unlock_kernel();
-       return ret;
+       return ext2_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
 }
 #endif
index 6abaf75163f0b17b1cbfb9b8b6e7ad563930bfdc..1ba18b72d43ae06234e6fe2a2f5aebcdc006af97 100644 (file)
@@ -234,16 +234,16 @@ static int ext2_show_options(struct seq_file *seq, struct vfsmount *vfs)
            le16_to_cpu(es->s_def_resgid) != EXT2_DEF_RESGID) {
                seq_printf(seq, ",resgid=%u", sbi->s_resgid);
        }
-       if (test_opt(sb, ERRORS_CONT)) {
+       if (test_opt(sb, ERRORS_RO)) {
                int def_errors = le16_to_cpu(es->s_errors);
 
                if (def_errors == EXT2_ERRORS_PANIC ||
-                   def_errors == EXT2_ERRORS_RO) {
-                       seq_puts(seq, ",errors=continue");
+                   def_errors == EXT2_ERRORS_CONTINUE) {
+                       seq_puts(seq, ",errors=remount-ro");
                }
        }
-       if (test_opt(sb, ERRORS_RO))
-               seq_puts(seq, ",errors=remount-ro");
+       if (test_opt(sb, ERRORS_CONT))
+               seq_puts(seq, ",errors=continue");
        if (test_opt(sb, ERRORS_PANIC))
                seq_puts(seq, ",errors=panic");
        if (test_opt(sb, NO_UID32))
@@ -617,27 +617,24 @@ static int ext2_setup_super (struct super_block * sb,
        return res;
 }
 
-static int ext2_check_descriptors (struct super_block * sb)
+static int ext2_check_descriptors(struct super_block *sb)
 {
        int i;
-       int desc_block = 0;
        struct ext2_sb_info *sbi = EXT2_SB(sb);
        unsigned long first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
        unsigned long last_block;
-       struct ext2_group_desc * gdp = NULL;
 
        ext2_debug ("Checking group descriptors");
 
-       for (i = 0; i < sbi->s_groups_count; i++)
-       {
+       for (i = 0; i < sbi->s_groups_count; i++) {
+               struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL);
+
                if (i == sbi->s_groups_count - 1)
                        last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
                else
                        last_block = first_block +
                                (EXT2_BLOCKS_PER_GROUP(sb) - 1);
 
-               if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
-                       gdp = (struct ext2_group_desc *) sbi->s_group_desc[desc_block++]->b_data;
                if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
                    le32_to_cpu(gdp->bg_block_bitmap) > last_block)
                {
@@ -667,7 +664,6 @@ static int ext2_check_descriptors (struct super_block * sb)
                        return 0;
                }
                first_block += EXT2_BLOCKS_PER_GROUP(sb);
-               gdp++;
        }
        return 1;
 }
@@ -820,10 +816,10 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
        
        if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
                set_opt(sbi->s_mount_opt, ERRORS_PANIC);
-       else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_RO)
-               set_opt(sbi->s_mount_opt, ERRORS_RO);
-       else
+       else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE)
                set_opt(sbi->s_mount_opt, ERRORS_CONT);
+       else
+               set_opt(sbi->s_mount_opt, ERRORS_RO);
 
        sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
        sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
@@ -868,8 +864,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 
        blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
 
-       if ((ext2_use_xip(sb)) && ((blocksize != PAGE_SIZE) ||
-                                 (sb->s_blocksize != blocksize))) {
+       if (ext2_use_xip(sb) && blocksize != PAGE_SIZE) {
                if (!silent)
                        printk("XIP: Unsupported blocksize\n");
                goto failed_mount;
index a8ba7e831278a0f53518edc101cd5517734af33e..a75713031105159ab82472301be86abef9ccc0af 100644 (file)
@@ -80,13 +80,57 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
        return desc + offset;
 }
 
+static int ext3_valid_block_bitmap(struct super_block *sb,
+                                       struct ext3_group_desc *desc,
+                                       unsigned int block_group,
+                                       struct buffer_head *bh)
+{
+       ext3_grpblk_t offset;
+       ext3_grpblk_t next_zero_bit;
+       ext3_fsblk_t bitmap_blk;
+       ext3_fsblk_t group_first_block;
+
+       group_first_block = ext3_group_first_block_no(sb, block_group);
+
+       /* check whether block bitmap block number is set */
+       bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
+       offset = bitmap_blk - group_first_block;
+       if (!ext3_test_bit(offset, bh->b_data))
+               /* bad block bitmap */
+               goto err_out;
+
+       /* check whether the inode bitmap block number is set */
+       bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
+       offset = bitmap_blk - group_first_block;
+       if (!ext3_test_bit(offset, bh->b_data))
+               /* bad block bitmap */
+               goto err_out;
+
+       /* check whether the inode table block number is set */
+       bitmap_blk = le32_to_cpu(desc->bg_inode_table);
+       offset = bitmap_blk - group_first_block;
+       next_zero_bit = ext3_find_next_zero_bit(bh->b_data,
+                               offset + EXT3_SB(sb)->s_itb_per_group,
+                               offset);
+       if (next_zero_bit >= offset + EXT3_SB(sb)->s_itb_per_group)
+               /* good bitmap for inode tables */
+               return 1;
+
+err_out:
+       ext3_error(sb, __FUNCTION__,
+                       "Invalid block bitmap - "
+                       "block_group = %d, block = %lu",
+                       block_group, bitmap_blk);
+       return 0;
+}
+
 /**
  * read_block_bitmap()
  * @sb:                        super block
  * @block_group:       given block group
  *
- * Read the bitmap for a given block_group, reading into the specified
- * slot in the superblock's bitmap cache.
+ * Read the bitmap for a given block_group,and validate the
+ * bits for block/inode/inode tables are set in the bitmaps
  *
  * Return buffer_head on success or NULL in case of failure.
  */
@@ -95,17 +139,35 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
 {
        struct ext3_group_desc * desc;
        struct buffer_head * bh = NULL;
+       ext3_fsblk_t bitmap_blk;
 
-       desc = ext3_get_group_desc (sb, block_group, NULL);
+       desc = ext3_get_group_desc(sb, block_group, NULL);
        if (!desc)
-               goto error_out;
-       bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
-       if (!bh)
-               ext3_error (sb, "read_block_bitmap",
+               return NULL;
+       bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
+       bh = sb_getblk(sb, bitmap_blk);
+       if (unlikely(!bh)) {
+               ext3_error(sb, __FUNCTION__,
                            "Cannot read block bitmap - "
                            "block_group = %d, block_bitmap = %u",
                            block_group, le32_to_cpu(desc->bg_block_bitmap));
-error_out:
+               return NULL;
+       }
+       if (likely(bh_uptodate_or_lock(bh)))
+               return bh;
+
+       if (bh_submit_read(bh) < 0) {
+               brelse(bh);
+               ext3_error(sb, __FUNCTION__,
+                           "Cannot read block bitmap - "
+                           "block_group = %d, block_bitmap = %u",
+                           block_group, le32_to_cpu(desc->bg_block_bitmap));
+               return NULL;
+       }
+       if (!ext3_valid_block_bitmap(sb, desc, block_group, bh)) {
+               brelse(bh);
+               return NULL;
+       }
        return bh;
 }
 /*
@@ -468,11 +530,13 @@ do_more:
            in_range (block, le32_to_cpu(desc->bg_inode_table),
                      sbi->s_itb_per_group) ||
            in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
-                     sbi->s_itb_per_group))
+                     sbi->s_itb_per_group)) {
                ext3_error (sb, "ext3_free_blocks",
                            "Freeing blocks in system zones - "
                            "Block = "E3FSBLK", count = %lu",
                            block, count);
+               goto error_return;
+       }
 
        /*
         * We are about to start releasing blocks in the bitmap,
@@ -1508,7 +1572,7 @@ retry_alloc:
 
        /*
         * Now search the rest of the groups.  We assume that
-        * i and gdp correctly point to the last group visited.
+        * group_no and gdp correctly point to the last group visited.
         */
        for (bgi = 0; bgi < ngroups; bgi++) {
                group_no++;
@@ -1575,11 +1639,13 @@ allocated:
            in_range(ret_block, le32_to_cpu(gdp->bg_inode_table),
                      EXT3_SB(sb)->s_itb_per_group) ||
            in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
-                     EXT3_SB(sb)->s_itb_per_group))
+                     EXT3_SB(sb)->s_itb_per_group)) {
                ext3_error(sb, "ext3_new_block",
                            "Allocating block in system zone - "
                            "blocks from "E3FSBLK", length %lu",
                             ret_block, num);
+               goto out;
+       }
 
        performed_allocation = 1;
 
@@ -1782,11 +1848,7 @@ static unsigned long ext3_bg_num_gdb_meta(struct super_block *sb, int group)
 
 static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group)
 {
-       if (EXT3_HAS_RO_COMPAT_FEATURE(sb,
-                               EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
-                       !ext3_group_sparse(group))
-               return 0;
-       return EXT3_SB(sb)->s_gdb_count;
+       return ext3_bg_has_super(sb, group) ? EXT3_SB(sb)->s_gdb_count : 0;
 }
 
 /**
index 9b162cd6c16c170ce7c35c3fc2f993ccc648cbc3..8a9ce2d09bde9e7bd418b4cf1294185645d77f49 100644 (file)
@@ -439,16 +439,14 @@ static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind)
  *     ext3_find_goal - find a prefered place for allocation.
  *     @inode: owner
  *     @block:  block we want
- *     @chain:  chain of indirect blocks
  *     @partial: pointer to the last triple within a chain
- *     @goal:  place to store the result.
  *
  *     Normally this function find the prefered place for block allocation,
- *     stores it in *@goal and returns zero.
+ *     returns it.
  */
 
 static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block,
-               Indirect chain[4], Indirect *partial)
+                                  Indirect *partial)
 {
        struct ext3_block_alloc_info *block_i;
 
@@ -884,7 +882,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
        if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
                ext3_init_block_alloc_info(inode);
 
-       goal = ext3_find_goal(inode, iblock, chain, partial);
+       goal = ext3_find_goal(inode, iblock, partial);
 
        /* the number of blocks need to allocate for [d,t]indirect blocks */
        indirect_blks = (chain + depth) - partial - 1;
@@ -941,55 +939,45 @@ out:
        return err;
 }
 
-#define DIO_CREDITS (EXT3_RESERVE_TRANS_BLOCKS + 32)
+/* Maximum number of blocks we map for direct IO at once. */
+#define DIO_MAX_BLOCKS 4096
+/*
+ * Number of credits we need for writing DIO_MAX_BLOCKS:
+ * We need sb + group descriptor + bitmap + inode -> 4
+ * For B blocks with A block pointers per block we need:
+ * 1 (triple ind.) + (B/A/A + 2) (doubly ind.) + (B/A + 2) (indirect).
+ * If we plug in 4096 for B and 256 for A (for 1KB block size), we get 25.
+ */
+#define DIO_CREDITS 25
 
 static int ext3_get_block(struct inode *inode, sector_t iblock,
                        struct buffer_head *bh_result, int create)
 {
        handle_t *handle = ext3_journal_current_handle();
-       int ret = 0;
+       int ret = 0, started = 0;
        unsigned max_blocks = bh_result->b_size >> inode->i_blkbits;
 
-       if (!create)
-               goto get_block;         /* A read */
-
-       if (max_blocks == 1)
-               goto get_block;         /* A single block get */
-
-       if (handle->h_transaction->t_state == T_LOCKED) {
-               /*
-                * Huge direct-io writes can hold off commits for long
-                * periods of time.  Let this commit run.
-                */
-               ext3_journal_stop(handle);
-               handle = ext3_journal_start(inode, DIO_CREDITS);
-               if (IS_ERR(handle))
+       if (create && !handle) {        /* Direct IO write... */
+               if (max_blocks > DIO_MAX_BLOCKS)
+                       max_blocks = DIO_MAX_BLOCKS;
+               handle = ext3_journal_start(inode, DIO_CREDITS +
+                               2 * EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb));
+               if (IS_ERR(handle)) {
                        ret = PTR_ERR(handle);
-               goto get_block;
-       }
-
-       if (handle->h_buffer_credits <= EXT3_RESERVE_TRANS_BLOCKS) {
-               /*
-                * Getting low on buffer credits...
-                */
-               ret = ext3_journal_extend(handle, DIO_CREDITS);
-               if (ret > 0) {
-                       /*
-                        * Couldn't extend the transaction.  Start a new one.
-                        */
-                       ret = ext3_journal_restart(handle, DIO_CREDITS);
+                       goto out;
                }
+               started = 1;
        }
 
-get_block:
-       if (ret == 0) {
-               ret = ext3_get_blocks_handle(handle, inode, iblock,
+       ret = ext3_get_blocks_handle(handle, inode, iblock,
                                        max_blocks, bh_result, create, 0);
-               if (ret > 0) {
-                       bh_result->b_size = (ret << inode->i_blkbits);
-                       ret = 0;
-               }
+       if (ret > 0) {
+               bh_result->b_size = (ret << inode->i_blkbits);
+               ret = 0;
        }
+       if (started)
+               ext3_journal_stop(handle);
+out:
        return ret;
 }
 
@@ -1680,7 +1668,8 @@ static int ext3_releasepage(struct page *page, gfp_t wait)
  * if the machine crashes during the write.
  *
  * If the O_DIRECT write is intantiating holes inside i_size and the machine
- * crashes then stale disk data _may_ be exposed inside the file.
+ * crashes then stale disk data _may_ be exposed inside the file. But current
+ * VFS code falls back into buffered path in that case so we are safe.
  */
 static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
                        const struct iovec *iov, loff_t offset,
@@ -1689,7 +1678,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
        struct file *file = iocb->ki_filp;
        struct inode *inode = file->f_mapping->host;
        struct ext3_inode_info *ei = EXT3_I(inode);
-       handle_t *handle = NULL;
+       handle_t *handle;
        ssize_t ret;
        int orphan = 0;
        size_t count = iov_length(iov, nr_segs);
@@ -1697,17 +1686,21 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
        if (rw == WRITE) {
                loff_t final_size = offset + count;
 
-               handle = ext3_journal_start(inode, DIO_CREDITS);
-               if (IS_ERR(handle)) {
-                       ret = PTR_ERR(handle);
-                       goto out;
-               }
                if (final_size > inode->i_size) {
+                       /* Credits for sb + inode write */
+                       handle = ext3_journal_start(inode, 2);
+                       if (IS_ERR(handle)) {
+                               ret = PTR_ERR(handle);
+                               goto out;
+                       }
                        ret = ext3_orphan_add(handle, inode);
-                       if (ret)
-                               goto out_stop;
+                       if (ret) {
+                               ext3_journal_stop(handle);
+                               goto out;
+                       }
                        orphan = 1;
                        ei->i_disksize = inode->i_size;
+                       ext3_journal_stop(handle);
                }
        }
 
@@ -1715,18 +1708,21 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
                                 offset, nr_segs,
                                 ext3_get_block, NULL);
 
-       /*
-        * Reacquire the handle: ext3_get_block() can restart the transaction
-        */
-       handle = ext3_journal_current_handle();
-
-out_stop:
-       if (handle) {
+       if (orphan) {
                int err;
 
-               if (orphan && inode->i_nlink)
+               /* Credits for sb + inode write */
+               handle = ext3_journal_start(inode, 2);
+               if (IS_ERR(handle)) {
+                       /* This is really bad luck. We've written the data
+                        * but cannot extend i_size. Bail out and pretend
+                        * the write failed... */
+                       ret = PTR_ERR(handle);
+                       goto out;
+               }
+               if (inode->i_nlink)
                        ext3_orphan_del(handle, inode);
-               if (orphan && ret > 0) {
+               if (ret > 0) {
                        loff_t end = offset + ret;
                        if (end > inode->i_size) {
                                ei->i_disksize = end;
@@ -1845,7 +1841,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
         */
        if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
             ext3_should_writeback_data(inode) && PageUptodate(page)) {
-               zero_user_page(page, offset, length, KM_USER0);
+               zero_user(page, offset, length);
                set_page_dirty(page);
                goto unlock;
        }
@@ -1898,7 +1894,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
                        goto unlock;
        }
 
-       zero_user_page(page, offset, length, KM_USER0);
+       zero_user(page, offset, length);
        BUFFER_TRACE(bh, "zeroed end of block");
 
        err = 0;
index 4ab6f76e63d0cda8e125672153571038f48b16c6..92b83b004dd8b09c5b8a981750af3521bc424b81 100644 (file)
@@ -860,14 +860,10 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
        int nblocks, i, err;
        struct inode *dir = dentry->d_parent->d_inode;
        int namelen;
-       const u8 *name;
-       unsigned blocksize;
 
        *res_dir = NULL;
        sb = dir->i_sb;
-       blocksize = sb->s_blocksize;
        namelen = dentry->d_name.len;
-       name = dentry->d_name.name;
        if (namelen > EXT3_NAME_LEN)
                return NULL;
        if (is_dx(dir)) {
index f3675cc630e97a7c5ab42251193050872957c5c1..343677e8c3500164b09d12513772d00f7d2d7a91 100644 (file)
@@ -575,16 +575,16 @@ static int ext3_show_options(struct seq_file *seq, struct vfsmount *vfs)
            le16_to_cpu(es->s_def_resgid) != EXT3_DEF_RESGID) {
                seq_printf(seq, ",resgid=%u", sbi->s_resgid);
        }
-       if (test_opt(sb, ERRORS_CONT)) {
+       if (test_opt(sb, ERRORS_RO)) {
                int def_errors = le16_to_cpu(es->s_errors);
 
                if (def_errors == EXT3_ERRORS_PANIC ||
-                   def_errors == EXT3_ERRORS_RO) {
-                       seq_puts(seq, ",errors=continue");
+                   def_errors == EXT3_ERRORS_CONTINUE) {
+                       seq_puts(seq, ",errors=remount-ro");
                }
        }
-       if (test_opt(sb, ERRORS_RO))
-               seq_puts(seq, ",errors=remount-ro");
+       if (test_opt(sb, ERRORS_CONT))
+               seq_puts(seq, ",errors=continue");
        if (test_opt(sb, ERRORS_PANIC))
                seq_puts(seq, ",errors=panic");
        if (test_opt(sb, NO_UID32))
@@ -1252,28 +1252,24 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
 }
 
 /* Called at mount-time, super-block is locked */
-static int ext3_check_descriptors (struct super_block * sb)
+static int ext3_check_descriptors(struct super_block *sb)
 {
        struct ext3_sb_info *sbi = EXT3_SB(sb);
        ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
        ext3_fsblk_t last_block;
-       struct ext3_group_desc * gdp = NULL;
-       int desc_block = 0;
        int i;
 
        ext3_debug ("Checking group descriptors");
 
-       for (i = 0; i < sbi->s_groups_count; i++)
-       {
+       for (i = 0; i < sbi->s_groups_count; i++) {
+               struct ext3_group_desc *gdp = ext3_get_group_desc(sb, i, NULL);
+
                if (i == sbi->s_groups_count - 1)
                        last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
                else
                        last_block = first_block +
                                (EXT3_BLOCKS_PER_GROUP(sb) - 1);
 
-               if ((i % EXT3_DESC_PER_BLOCK(sb)) == 0)
-                       gdp = (struct ext3_group_desc *)
-                                       sbi->s_group_desc[desc_block++]->b_data;
                if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
                    le32_to_cpu(gdp->bg_block_bitmap) > last_block)
                {
@@ -1306,7 +1302,6 @@ static int ext3_check_descriptors (struct super_block * sb)
                        return 0;
                }
                first_block += EXT3_BLOCKS_PER_GROUP(sb);
-               gdp++;
        }
 
        sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb));
@@ -1583,10 +1578,10 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
 
        if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC)
                set_opt(sbi->s_mount_opt, ERRORS_PANIC);
-       else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_RO)
-               set_opt(sbi->s_mount_opt, ERRORS_RO);
-       else
+       else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_CONTINUE)
                set_opt(sbi->s_mount_opt, ERRORS_CONT);
+       else
+               set_opt(sbi->s_mount_opt, ERRORS_RO);
 
        sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
        sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
index ac75ea953d83fbfe3d3919783f85c963d905c264..0737e05ba3dd22842429f287356ca1c500265943 100644 (file)
@@ -1700,7 +1700,7 @@ retry_alloc:
 
        /*
         * Now search the rest of the groups.  We assume that
-        * i and gdp correctly point to the last group visited.
+        * group_no and gdp correctly point to the last group visited.
         */
        for (bgi = 0; bgi < ngroups; bgi++) {
                group_no++;
@@ -2011,11 +2011,7 @@ static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb,
 static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
                                        ext4_group_t group)
 {
-       if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
-                               EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
-                       !ext4_group_sparse(group))
-               return 0;
-       return EXT4_SB(sb)->s_gdb_count;
+       return ext4_bg_has_super(sb, group) ? EXT4_SB(sb)->s_gdb_count : 0;
 }
 
 /**
index bb717cbb749c822265bccdd8159de7af456ad745..0e9055cf700e606f1aacb5432b8744a810242e11 100644 (file)
@@ -429,16 +429,13 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
  *     ext4_find_goal - find a prefered place for allocation.
  *     @inode: owner
  *     @block:  block we want
- *     @chain:  chain of indirect blocks
  *     @partial: pointer to the last triple within a chain
- *     @goal:  place to store the result.
  *
  *     Normally this function find the prefered place for block allocation,
- *     stores it in *@goal and returns zero.
+ *     returns it.
  */
-
 static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block,
-               Indirect chain[4], Indirect *partial)
+               Indirect *partial)
 {
        struct ext4_block_alloc_info *block_i;
 
@@ -839,7 +836,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
        if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
                ext4_init_block_alloc_info(inode);
 
-       goal = ext4_find_goal(inode, iblock, chain, partial);
+       goal = ext4_find_goal(inode, iblock, partial);
 
        /* the number of blocks need to allocate for [d,t]indirect blocks */
        indirect_blks = (chain + depth) - partial - 1;
@@ -1840,7 +1837,7 @@ int ext4_block_truncate_page(handle_t *handle, struct page *page,
         */
        if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
             ext4_should_writeback_data(inode) && PageUptodate(page)) {
-               zero_user_page(page, offset, length, KM_USER0);
+               zero_user(page, offset, length);
                set_page_dirty(page);
                goto unlock;
        }
@@ -1893,7 +1890,7 @@ int ext4_block_truncate_page(handle_t *handle, struct page *page,
                        goto unlock;
        }
 
-       zero_user_page(page, offset, length, KM_USER0);
+       zero_user(page, offset, length);
 
        BUFFER_TRACE(bh, "zeroed end of block");
 
index 055a0cd0168e5029ee87bb3ce8c55153fae3b171..c89bb8797765b9edd1a8a74a8404216d35b8e969 100644 (file)
@@ -1458,7 +1458,7 @@ int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group,
 }
 
 /* Called at mount-time, super-block is locked */
-static int ext4_check_descriptors (struct super_block * sb)
+static int ext4_check_descriptors(struct super_block *sb)
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
        ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
@@ -1466,8 +1466,6 @@ static int ext4_check_descriptors (struct super_block * sb)
        ext4_fsblk_t block_bitmap;
        ext4_fsblk_t inode_bitmap;
        ext4_fsblk_t inode_table;
-       struct ext4_group_desc * gdp = NULL;
-       int desc_block = 0;
        int flexbg_flag = 0;
        ext4_group_t i;
 
@@ -1476,17 +1474,15 @@ static int ext4_check_descriptors (struct super_block * sb)
 
        ext4_debug ("Checking group descriptors");
 
-       for (i = 0; i < sbi->s_groups_count; i++)
-       {
+       for (i = 0; i < sbi->s_groups_count; i++) {
+               struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
+
                if (i == sbi->s_groups_count - 1 || flexbg_flag)
                        last_block = ext4_blocks_count(sbi->s_es) - 1;
                else
                        last_block = first_block +
                                (EXT4_BLOCKS_PER_GROUP(sb) - 1);
 
-               if ((i % EXT4_DESC_PER_BLOCK(sb)) == 0)
-                       gdp = (struct ext4_group_desc *)
-                                       sbi->s_group_desc[desc_block++]->b_data;
                block_bitmap = ext4_block_bitmap(sb, gdp);
                if (block_bitmap < first_block || block_bitmap > last_block)
                {
@@ -1524,8 +1520,6 @@ static int ext4_check_descriptors (struct super_block * sb)
                }
                if (!flexbg_flag)
                        first_block += EXT4_BLOCKS_PER_GROUP(sb);
-               gdp = (struct ext4_group_desc *)
-                       ((__u8 *)gdp + EXT4_DESC_SIZE(sb));
        }
 
        ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
index 69a83b59dce80bdc84f1d4507e1ad74195c38690..c614175876e09316ea0a36566dc072fe6819169c 100644 (file)
@@ -155,6 +155,42 @@ out:
        return err;
 }
 
+static int check_mode(const struct msdos_sb_info *sbi, mode_t mode)
+{
+       mode_t req = mode & ~S_IFMT;
+
+       /*
+        * Of the r and x bits, all (subject to umask) must be present. Of the
+        * w bits, either all (subject to umask) or none must be present.
+        */
+
+       if (S_ISREG(mode)) {
+               req &= ~sbi->options.fs_fmask;
+
+               if ((req & (S_IRUGO | S_IXUGO)) !=
+                   ((S_IRUGO | S_IXUGO) & ~sbi->options.fs_fmask))
+                       return -EPERM;
+
+               if ((req & S_IWUGO) != 0 &&
+                   (req & S_IWUGO) != (S_IWUGO & ~sbi->options.fs_fmask))
+                       return -EPERM;
+       } else if (S_ISDIR(mode)) {
+               req &= ~sbi->options.fs_dmask;
+
+               if ((req & (S_IRUGO | S_IXUGO)) !=
+                   ((S_IRUGO | S_IXUGO) & ~sbi->options.fs_dmask))
+                       return -EPERM;
+
+               if ((req & S_IWUGO) != 0 &&
+                   (req & S_IWUGO) != (S_IWUGO & ~sbi->options.fs_dmask))
+                       return -EPERM;
+       } else {
+               return -EPERM;
+       }
+
+       return 0;
+}
+
 int fat_notify_change(struct dentry *dentry, struct iattr *attr)
 {
        struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
@@ -186,9 +222,7 @@ int fat_notify_change(struct dentry *dentry, struct iattr *attr)
        if (((attr->ia_valid & ATTR_UID) &&
             (attr->ia_uid != sbi->options.fs_uid)) ||
            ((attr->ia_valid & ATTR_GID) &&
-            (attr->ia_gid != sbi->options.fs_gid)) ||
-           ((attr->ia_valid & ATTR_MODE) &&
-            (attr->ia_mode & ~MSDOS_VALID_MODE)))
+            (attr->ia_gid != sbi->options.fs_gid)))
                error = -EPERM;
 
        if (error) {
@@ -196,6 +230,13 @@ int fat_notify_change(struct dentry *dentry, struct iattr *attr)
                        error = 0;
                goto out;
        }
+
+       if (attr->ia_valid & ATTR_MODE) {
+               error = check_mode(sbi, attr->ia_mode);
+               if (error != 0 && !sbi->options.quiet)
+                       goto out;
+       }
+
        error = inode_setattr(inode, attr);
        if (error)
                goto out;
index 920a576e1c25e26240c8ed583cbdfce7e4452e4e..24c0aaa5ae80d6de0cb876f554da57f2cca864b7 100644 (file)
@@ -1295,10 +1295,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
 
                fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data;
                if (!IS_FSINFO(fsinfo)) {
-                       printk(KERN_WARNING
-                              "FAT: Did not find valid FSINFO signature.\n"
-                              "     Found signature1 0x%08x signature2 0x%08x"
-                              " (sector = %lu)\n",
+                       printk(KERN_WARNING "FAT: Invalid FSINFO signature: "
+                              "0x%08x, 0x%08x (sector = %lu)\n",
                               le32_to_cpu(fsinfo->signature1),
                               le32_to_cpu(fsinfo->signature2),
                               sbi->fsinfo_sector);
index 308f2b6b50264da37c24843a1943d1e5ad22bc4e..61f23511eacf41ec34649a84f1cc7e601ff61a68 100644 (file)
@@ -55,9 +55,8 @@ void fat_clusters_flush(struct super_block *sb)
        fsinfo = (struct fat_boot_fsinfo *)bh->b_data;
        /* Sanity check */
        if (!IS_FSINFO(fsinfo)) {
-               printk(KERN_ERR "FAT: Did not find valid FSINFO signature.\n"
-                      "     Found signature1 0x%08x signature2 0x%08x"
-                      " (sector = %lu)\n",
+               printk(KERN_ERR "FAT: Invalid FSINFO signature: "
+                      "0x%08x, 0x%08x (sector = %lu)\n",
                       le32_to_cpu(fsinfo->signature1),
                       le32_to_cpu(fsinfo->signature2),
                       sbi->fsinfo_sector);
index c5575de01113eb24aa182c77b35d46d0f0fced48..5110acb1c9ef59bb046a69f79fa601a07218b61a 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -24,6 +24,8 @@ struct fdtable_defer {
        struct fdtable *next;
 };
 
+int sysctl_nr_open __read_mostly = 1024*1024;
+
 /*
  * We use this list to defer free fdtables that have vmalloced
  * sets/arrays. By keeping a per-cpu list, we avoid having to embed
@@ -147,8 +149,8 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
        nr /= (1024 / sizeof(struct file *));
        nr = roundup_pow_of_two(nr + 1);
        nr *= (1024 / sizeof(struct file *));
-       if (nr > NR_OPEN)
-               nr = NR_OPEN;
+       if (nr > sysctl_nr_open)
+               nr = sysctl_nr_open;
 
        fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL);
        if (!fdt)
@@ -233,7 +235,7 @@ int expand_files(struct files_struct *files, int nr)
        if (nr < fdt->max_fds)
                return 0;
        /* Can we expand? */
-       if (nr >= NR_OPEN)
+       if (nr >= sysctl_nr_open)
                return -EMFILE;
 
        /* All good, so we try */
index 3c96d6e6397868e28550c986a35ee6f4df5beefc..aaf1fb098639553fc6ad7a8d6c9e0ccd7162a9ce 100644 (file)
@@ -41,7 +41,7 @@
  * VxFS directory block header.
  *
  * This entry is the head of every filesystem block in a directory.
- * It is used for free space managment and additionally includes
+ * It is used for free space management and additionally includes
  * a hash for speeding up directory search (lookup).
  *
  * The hash may be empty and in fact we do not use it all in the
index 24b5a775ff960493a60df4d6c1cb36bdf54010be..8a5959a61ba9dbff4b9b713efa1f5d42da003e1f 100644 (file)
@@ -54,7 +54,7 @@ const struct inode_operations vxfs_immed_symlink_iops = {
 };
 
 /*
- * Adress space operations for immed files and directories.
+ * Address space operations for immed files and directories.
  */
 const struct address_space_operations vxfs_immed_aops = {
        .readpage =             vxfs_immed_readpage,
index 300324bd563c924ae87c10db7d5171726f8bffc1..db80ce9eb1d07896fb3ddd5f545ed8876dc8b2fa 100644 (file)
@@ -284,7 +284,17 @@ __sync_single_inode(struct inode *inode, struct writeback_control *wbc)
                                 * soon as the queue becomes uncongested.
                                 */
                                inode->i_state |= I_DIRTY_PAGES;
-                               requeue_io(inode);
+                               if (wbc->nr_to_write <= 0) {
+                                       /*
+                                        * slice used up: queue for next turn
+                                        */
+                                       requeue_io(inode);
+                               } else {
+                                       /*
+                                        * somehow blocked: retry later
+                                        */
+                                       redirty_tail(inode);
+                               }
                        } else {
                                /*
                                 * Otherwise fully redirty the inode so that
@@ -334,9 +344,6 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
                WARN_ON(inode->i_state & I_WILL_FREE);
 
        if ((wbc->sync_mode != WB_SYNC_ALL) && (inode->i_state & I_SYNC)) {
-               struct address_space *mapping = inode->i_mapping;
-               int ret;
-
                /*
                 * We're skipping this inode because it's locked, and we're not
                 * doing writeback-for-data-integrity.  Move it to s_more_io so
@@ -345,15 +352,7 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
                 * completed a full scan of s_io.
                 */
                requeue_io(inode);
-
-               /*
-                * Even if we don't actually write the inode itself here,
-                * we can at least start some of the data writeout..
-                */
-               spin_unlock(&inode_lock);
-               ret = do_writepages(mapping, wbc);
-               spin_lock(&inode_lock);
-               return ret;
+               return 0;
        }
 
        /*
@@ -479,8 +478,12 @@ sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc)
                iput(inode);
                cond_resched();
                spin_lock(&inode_lock);
-               if (wbc->nr_to_write <= 0)
+               if (wbc->nr_to_write <= 0) {
+                       wbc->more_io = 1;
                        break;
+               }
+               if (!list_empty(&sb->s_more_io))
+                       wbc->more_io = 1;
        }
        return;         /* Leave any unwritten inodes on s_io */
 }
@@ -512,8 +515,7 @@ writeback_inodes(struct writeback_control *wbc)
        might_sleep();
        spin_lock(&sb_lock);
 restart:
-       sb = sb_entry(super_blocks.prev);
-       for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
+       list_for_each_entry_reverse(sb, &super_blocks, s_list) {
                if (sb_has_dirty_inodes(sb)) {
                        /* we're making our own get_super here */
                        sb->s_count++;
@@ -578,10 +580,8 @@ static void set_sb_syncing(int val)
 {
        struct super_block *sb;
        spin_lock(&sb_lock);
-       sb = sb_entry(super_blocks.prev);
-       for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
+       list_for_each_entry_reverse(sb, &super_blocks, s_list)
                sb->s_syncing = val;
-       }
        spin_unlock(&sb_lock);
 }
 
index db534bcde45f6ff52a7cbfb44fcb8b49ea9bbb9d..af639807524e63164397b32f8589bf75131a5112 100644 (file)
@@ -201,6 +201,55 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
        }
 }
 
+static unsigned len_args(unsigned numargs, struct fuse_arg *args)
+{
+       unsigned nbytes = 0;
+       unsigned i;
+
+       for (i = 0; i < numargs; i++)
+               nbytes += args[i].size;
+
+       return nbytes;
+}
+
+static u64 fuse_get_unique(struct fuse_conn *fc)
+{
+       fc->reqctr++;
+       /* zero is special */
+       if (fc->reqctr == 0)
+               fc->reqctr = 1;
+
+       return fc->reqctr;
+}
+
+static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
+{
+       req->in.h.unique = fuse_get_unique(fc);
+       req->in.h.len = sizeof(struct fuse_in_header) +
+               len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
+       list_add_tail(&req->list, &fc->pending);
+       req->state = FUSE_REQ_PENDING;
+       if (!req->waiting) {
+               req->waiting = 1;
+               atomic_inc(&fc->num_waiting);
+       }
+       wake_up(&fc->waitq);
+       kill_fasync(&fc->fasync, SIGIO, POLL_IN);
+}
+
+static void flush_bg_queue(struct fuse_conn *fc)
+{
+       while (fc->active_background < FUSE_MAX_BACKGROUND &&
+              !list_empty(&fc->bg_queue)) {
+               struct fuse_req *req;
+
+               req = list_entry(fc->bg_queue.next, struct fuse_req, list);
+               list_del(&req->list);
+               fc->active_background++;
+               queue_request(fc, req);
+       }
+}
+
 /*
  * This function is called when a request is finished.  Either a reply
  * has arrived or it was aborted (and not yet sent) or some error
@@ -229,6 +278,8 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
                        clear_bdi_congested(&fc->bdi, WRITE);
                }
                fc->num_background--;
+               fc->active_background--;
+               flush_bg_queue(fc);
        }
        spin_unlock(&fc->lock);
        wake_up(&req->waitq);
@@ -320,42 +371,6 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
        }
 }
 
-static unsigned len_args(unsigned numargs, struct fuse_arg *args)
-{
-       unsigned nbytes = 0;
-       unsigned i;
-
-       for (i = 0; i < numargs; i++)
-               nbytes += args[i].size;
-
-       return nbytes;
-}
-
-static u64 fuse_get_unique(struct fuse_conn *fc)
- {
-       fc->reqctr++;
-       /* zero is special */
-       if (fc->reqctr == 0)
-               fc->reqctr = 1;
-
-       return fc->reqctr;
-}
-
-static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
-{
-       req->in.h.unique = fuse_get_unique(fc);
-       req->in.h.len = sizeof(struct fuse_in_header) +
-               len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
-       list_add_tail(&req->list, &fc->pending);
-       req->state = FUSE_REQ_PENDING;
-       if (!req->waiting) {
-               req->waiting = 1;
-               atomic_inc(&fc->num_waiting);
-       }
-       wake_up(&fc->waitq);
-       kill_fasync(&fc->fasync, SIGIO, POLL_IN);
-}
-
 void request_send(struct fuse_conn *fc, struct fuse_req *req)
 {
        req->isreply = 1;
@@ -375,20 +390,26 @@ void request_send(struct fuse_conn *fc, struct fuse_req *req)
        spin_unlock(&fc->lock);
 }
 
+static void request_send_nowait_locked(struct fuse_conn *fc,
+                                      struct fuse_req *req)
+{
+       req->background = 1;
+       fc->num_background++;
+       if (fc->num_background == FUSE_MAX_BACKGROUND)
+               fc->blocked = 1;
+       if (fc->num_background == FUSE_CONGESTION_THRESHOLD) {
+               set_bdi_congested(&fc->bdi, READ);
+               set_bdi_congested(&fc->bdi, WRITE);
+       }
+       list_add_tail(&req->list, &fc->bg_queue);
+       flush_bg_queue(fc);
+}
+
 static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
 {
        spin_lock(&fc->lock);
        if (fc->connected) {
-               req->background = 1;
-               fc->num_background++;
-               if (fc->num_background == FUSE_MAX_BACKGROUND)
-                       fc->blocked = 1;
-               if (fc->num_background == FUSE_CONGESTION_THRESHOLD) {
-                       set_bdi_congested(&fc->bdi, READ);
-                       set_bdi_congested(&fc->bdi, WRITE);
-               }
-
-               queue_request(fc, req);
+               request_send_nowait_locked(fc, req);
                spin_unlock(&fc->lock);
        } else {
                req->out.h.error = -ENOTCONN;
index 80d2f5292cf91f490532e903c0e37795e705de15..f56f91bd38bea8b978bb26c38d8e3e3bb993e00a 100644 (file)
@@ -416,6 +416,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
        fuse_put_request(fc, forget_req);
        d_instantiate(entry, inode);
        fuse_change_entry_timeout(entry, &outentry);
+       fuse_invalidate_attr(dir);
        file = lookup_instantiate_filp(nd, entry, generic_file_open);
        if (IS_ERR(file)) {
                ff->fh = outopen.fh;
index bb05d227cf30bb074da715a08d438e295fbc8892..676b0bc8a86dba3e3c048a1a35320d3931a65f20 100644 (file)
@@ -77,8 +77,8 @@ static struct fuse_file *fuse_file_get(struct fuse_file *ff)
 
 static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req)
 {
-       dput(req->dentry);
-       mntput(req->vfsmount);
+       dput(req->misc.release.dentry);
+       mntput(req->misc.release.vfsmount);
        fuse_put_request(fc, req);
 }
 
@@ -86,7 +86,8 @@ static void fuse_file_put(struct fuse_file *ff)
 {
        if (atomic_dec_and_test(&ff->count)) {
                struct fuse_req *req = ff->reserved_req;
-               struct fuse_conn *fc = get_fuse_conn(req->dentry->d_inode);
+               struct inode *inode = req->misc.release.dentry->d_inode;
+               struct fuse_conn *fc = get_fuse_conn(inode);
                req->end = fuse_release_end;
                request_send_background(fc, req);
                kfree(ff);
@@ -137,7 +138,7 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir)
 void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode)
 {
        struct fuse_req *req = ff->reserved_req;
-       struct fuse_release_in *inarg = &req->misc.release_in;
+       struct fuse_release_in *inarg = &req->misc.release.in;
 
        inarg->fh = ff->fh;
        inarg->flags = flags;
@@ -153,13 +154,14 @@ int fuse_release_common(struct inode *inode, struct file *file, int isdir)
        struct fuse_file *ff = file->private_data;
        if (ff) {
                struct fuse_conn *fc = get_fuse_conn(inode);
+               struct fuse_req *req = ff->reserved_req;
 
                fuse_release_fill(ff, get_node_id(inode), file->f_flags,
                                  isdir ? FUSE_RELEASEDIR : FUSE_RELEASE);
 
                /* Hold vfsmount and dentry until release is finished */
-               ff->reserved_req->vfsmount = mntget(file->f_path.mnt);
-               ff->reserved_req->dentry = dget(file->f_path.dentry);
+               req->misc.release.vfsmount = mntget(file->f_path.mnt);
+               req->misc.release.dentry = dget(file->f_path.dentry);
 
                spin_lock(&fc->lock);
                list_del(&ff->write_entry);
index 3ab8a3048e8b8fa185028cdeab329463ed6b1245..67aaf6ee38eaaeb1fedd9c313a160f623d58b8c3 100644 (file)
@@ -215,7 +215,11 @@ struct fuse_req {
        /** Data for asynchronous requests */
        union {
                struct fuse_forget_in forget_in;
-               struct fuse_release_in release_in;
+               struct {
+                       struct fuse_release_in in;
+                       struct vfsmount *vfsmount;
+                       struct dentry *dentry;
+               } release;
                struct fuse_init_in init_in;
                struct fuse_init_out init_out;
                struct fuse_read_in read_in;
@@ -238,12 +242,6 @@ struct fuse_req {
        /** File used in the request (or NULL) */
        struct fuse_file *ff;
 
-       /** vfsmount used in release */
-       struct vfsmount *vfsmount;
-
-       /** dentry used in release */
-       struct dentry *dentry;
-
        /** Request completion callback */
        void (*end)(struct fuse_conn *, struct fuse_req *);
 
@@ -298,6 +296,12 @@ struct fuse_conn {
        /** Number of requests currently in the background */
        unsigned num_background;
 
+       /** Number of background requests currently queued for userspace */
+       unsigned active_background;
+
+       /** The list of background requests set aside for later queuing */
+       struct list_head bg_queue;
+
        /** Pending interrupts */
        struct list_head interrupts;
 
index e5e80d1a46870dda75135efca29c793860164b15..c90f633d0b578766103a52d8d277e1500d168f6d 100644 (file)
@@ -465,6 +465,7 @@ static struct fuse_conn *new_conn(void)
                INIT_LIST_HEAD(&fc->processing);
                INIT_LIST_HEAD(&fc->io);
                INIT_LIST_HEAD(&fc->interrupts);
+               INIT_LIST_HEAD(&fc->bg_queue);
                atomic_set(&fc->num_waiting, 0);
                fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
                fc->bdi.unplug_io_fn = default_unplug_io_fn;
index e4effc47abfc865f82f71b6855f06521253c25b5..e9456ebd3bb619c0dc269331ec793d54e3eee319 100644 (file)
@@ -932,7 +932,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
        if (!gfs2_is_writeback(ip))
                gfs2_trans_add_bh(ip->i_gl, bh, 0);
 
-       zero_user_page(page, offset, length, KM_USER0);
+       zero_user(page, offset, length);
 
 unlock:
        unlock_page(page);
index 38dbe99a30ede1ac388596278ef02ca9e9590bae..ac772b6d9dbbfa6cde57fb366fdd54e11dd68d5a 100644 (file)
@@ -446,7 +446,7 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
         * so we need to supply one here. It doesn't happen often.
         */
        if (unlikely(page->index)) {
-               zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
+               zero_user(page, 0, PAGE_CACHE_SIZE);
                return 0;
        }
 
index b249e294a95bfa76cde2699716a3e96f817d6e03..6fb07d67ca8a41bef05b1940a6831fb2b2764139 100644 (file)
@@ -450,7 +450,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
                fs_info(sdp, "jid=%u: Trying to acquire journal lock...\n",
                        jd->jd_jid);
 
-               /* Aquire the journal lock so we can do recovery */
+               /* Acquire the journal lock so we can do recovery */
 
                error = gfs2_glock_nq_num(sdp, jd->jd_jid, &gfs2_journal_glops,
                                          LM_ST_EXCLUSIVE,
index f8452a0eab562085ddd50e3f3e52352bebcc4cb2..4129cdb3f0d8fbf80c4b161d877d9e922666f9ea 100644 (file)
@@ -52,9 +52,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
                rec = (e + b) / 2;
                len = hfs_brec_lenoff(bnode, rec, &off);
                keylen = hfs_brec_keylen(bnode, rec);
-               if (keylen == HFS_BAD_KEYLEN) {
+               if (keylen == 0) {
                        res = -EINVAL;
-                       goto done;
+                       goto fail;
                }
                hfs_bnode_read(bnode, fd->key, off, keylen);
                cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
@@ -71,9 +71,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
        if (rec != e && e >= 0) {
                len = hfs_brec_lenoff(bnode, e, &off);
                keylen = hfs_brec_keylen(bnode, e);
-               if (keylen == HFS_BAD_KEYLEN) {
+               if (keylen == 0) {
                        res = -EINVAL;
-                       goto done;
+                       goto fail;
                }
                hfs_bnode_read(bnode, fd->key, off, keylen);
        }
@@ -83,6 +83,7 @@ done:
        fd->keylength = keylen;
        fd->entryoffset = off + keylen;
        fd->entrylength = len - keylen;
+fail:
        return res;
 }
 
@@ -206,7 +207,7 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt)
 
        len = hfs_brec_lenoff(bnode, fd->record, &off);
        keylen = hfs_brec_keylen(bnode, fd->record);
-       if (keylen == HFS_BAD_KEYLEN) {
+       if (keylen == 0) {
                res = -EINVAL;
                goto out;
        }
index 8626ee375ea811d3a4e794a5f72a05d96b09bea0..878bf25dbc6a8c60d8ffc9736c0d6bf5c20ed699 100644 (file)
@@ -49,14 +49,14 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
                        if (retval > node->tree->max_key_len + 2) {
                                printk(KERN_ERR "hfs: keylen %d too large\n",
                                        retval);
-                               retval = HFS_BAD_KEYLEN;
+                               retval = 0;
                        }
                } else {
                        retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1;
                        if (retval > node->tree->max_key_len + 1) {
                                printk(KERN_ERR "hfs: keylen %d too large\n",
                                        retval);
-                               retval = HFS_BAD_KEYLEN;
+                               retval = 0;
                        }
                }
        }
index 110dd3515dc89b27e226a9a65867f338df18de69..24cf6fc4302122366ed444c7f5f3344b7cae7382 100644 (file)
@@ -81,15 +81,23 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
                goto fail_page;
        if (!tree->node_count)
                goto fail_page;
-       if ((id == HFS_EXT_CNID) && (tree->max_key_len != HFS_MAX_EXT_KEYLEN)) {
-               printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
-                       tree->max_key_len);
-               goto fail_page;
-       }
-       if ((id == HFS_CAT_CNID) && (tree->max_key_len != HFS_MAX_CAT_KEYLEN)) {
-               printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
-                       tree->max_key_len);
-               goto fail_page;
+       switch (id) {
+       case HFS_EXT_CNID:
+               if (tree->max_key_len != HFS_MAX_EXT_KEYLEN) {
+                       printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
+                               tree->max_key_len);
+                       goto fail_page;
+               }
+               break;
+       case HFS_CAT_CNID:
+               if (tree->max_key_len != HFS_MAX_CAT_KEYLEN) {
+                       printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
+                               tree->max_key_len);
+                       goto fail_page;
+               }
+               break;
+       default:
+               BUG();
        }
 
        tree->node_size_shift = ffs(size) - 1;
index c6aae61adfe6f098f9c0fc260b1090b1331d29d9..6f194d0768b6fd72b76e617ffc7711b0edd25982 100644 (file)
@@ -28,8 +28,6 @@
 #define HFS_MAX_NAMELEN                128
 #define HFS_MAX_VALENCE                32767U
 
-#define HFS_BAD_KEYLEN         0xFF
-
 /* Meanings of the drAtrb field of the MDB,
  * Reference: _Inside Macintosh: Files_ p. 2-61
  */
index 16cbd902f8b9569a6874710832d7ab1316010063..32de44ed002196c5b3fd327662dc123f9899f8ac 100644 (file)
@@ -6,7 +6,7 @@
  * This file may be distributed under the terms of the GNU General Public License.
  *
  * This file contains hfs_read_super(), some of the super_ops and
- * init_module() and cleanup_module(). The remaining super_ops are in
+ * init_hfs_fs() and exit_hfs_fs().  The remaining super_ops are in
  * inode.c since they deal with inodes.
  *
  * Based on the minix file system code, (C) 1991, 1992 by Linus Torvalds
index 35c1a9f33f47895958cb68aff7e449c06ce08f3a..53fd0a67c11abf148a76cea7820a1a3c782adc26 100644 (file)
@@ -285,17 +285,17 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
                        return err;
 
                times[0].tv_sec = atime_ts.tv_sec;
-               times[0].tv_usec = atime_ts.tv_nsec * 1000;
+               times[0].tv_usec = atime_ts.tv_nsec / 1000;
                times[1].tv_sec = mtime_ts.tv_sec;
-               times[1].tv_usec = mtime_ts.tv_nsec * 1000;
+               times[1].tv_usec = mtime_ts.tv_nsec / 1000;
 
                if (attrs->ia_valid & HOSTFS_ATTR_ATIME_SET) {
                        times[0].tv_sec = attrs->ia_atime.tv_sec;
-                       times[0].tv_usec = attrs->ia_atime.tv_nsec * 1000;
+                       times[0].tv_usec = attrs->ia_atime.tv_nsec / 1000;
                }
                if (attrs->ia_valid & HOSTFS_ATTR_MTIME_SET) {
                        times[1].tv_sec = attrs->ia_mtime.tv_sec;
-                       times[1].tv_usec = attrs->ia_mtime.tv_nsec * 1000;
+                       times[1].tv_usec = attrs->ia_mtime.tv_nsec / 1000;
                }
 
                if (fd >= 0) {
index 09ee07f026630501869eb0bd53131e46b7f8d82d..3b3cc28cdefcaf5929be2a3d13be24bf4791fd6c 100644 (file)
@@ -768,7 +768,7 @@ hugetlbfs_parse_options(char *options, struct hugetlbfs_config *pconfig)
                case Opt_mode:
                        if (match_octal(&args[0], &option))
                                goto bad_val;
-                       pconfig->mode = option & 0777U;
+                       pconfig->mode = option & 01777U;
                        break;
 
                case Opt_size: {
index 2c5b921528760b9da6d8abcc3f90668a8e9381d7..690e72595e6e6048addba645cf179cb418208f50 100644 (file)
@@ -168,20 +168,14 @@ static void set_dentry_child_flags(struct inode *inode, int watched)
                struct dentry *child;
 
                list_for_each_entry(child, &alias->d_subdirs, d_u.d_child) {
-                       if (!child->d_inode) {
-                               WARN_ON(child->d_flags & DCACHE_INOTIFY_PARENT_WATCHED);
+                       if (!child->d_inode)
                                continue;
-                       }
+
                        spin_lock(&child->d_lock);
-                       if (watched) {
-                               WARN_ON(child->d_flags &
-                                               DCACHE_INOTIFY_PARENT_WATCHED);
+                       if (watched)
                                child->d_flags |= DCACHE_INOTIFY_PARENT_WATCHED;
-                       } else {
-                               WARN_ON(!(child->d_flags &
-                                       DCACHE_INOTIFY_PARENT_WATCHED));
-                               child->d_flags&=~DCACHE_INOTIFY_PARENT_WATCHED;
-                       }
+                       else
+                               child->d_flags &=~DCACHE_INOTIFY_PARENT_WATCHED;
                        spin_unlock(&child->d_lock);
                }
        }
@@ -253,7 +247,6 @@ void inotify_d_instantiate(struct dentry *entry, struct inode *inode)
        if (!inode)
                return;
 
-       WARN_ON(entry->d_flags & DCACHE_INOTIFY_PARENT_WATCHED);
        spin_lock(&entry->d_lock);
        parent = entry->d_parent;
        if (parent->d_inode && inotify_inode_watched(parent->d_inode))
@@ -627,6 +620,7 @@ s32 inotify_add_watch(struct inotify_handle *ih, struct inotify_watch *watch,
                      struct inode *inode, u32 mask)
 {
        int ret = 0;
+       int newly_watched;
 
        /* don't allow invalid bits: we don't want flags set */
        mask &= IN_ALL_EVENTS | IN_ONESHOT;
@@ -653,12 +647,18 @@ s32 inotify_add_watch(struct inotify_handle *ih, struct inotify_watch *watch,
         */
        watch->inode = igrab(inode);
 
-       if (!inotify_inode_watched(inode))
-               set_dentry_child_flags(inode, 1);
-
        /* Add the watch to the handle's and the inode's list */
+       newly_watched = !inotify_inode_watched(inode);
        list_add(&watch->h_list, &ih->watches);
        list_add(&watch->i_list, &inode->inotify_watches);
+       /*
+        * Set child flags _after_ adding the watch, so there is no race
+        * windows where newly instantiated children could miss their parent's
+        * watched flag.
+        */
+       if (newly_watched)
+               set_dentry_child_flags(inode, 1);
+
 out:
        mutex_unlock(&ih->mutex);
        mutex_unlock(&inode->inotify_mutex);
index 5e009331c01ff5fbe1a453f735e906e54645368f..a336c9709f3cc477ed15236642b743f0a3ca493e 100644 (file)
@@ -79,6 +79,7 @@ struct inotify_device {
        atomic_t                count;          /* reference count */
        struct user_struct      *user;          /* user who opened this dev */
        struct inotify_handle   *ih;            /* inotify handle */
+       struct fasync_struct    *fa;            /* async notification */
        unsigned int            queue_size;     /* size of the queue (bytes) */
        unsigned int            event_count;    /* number of pending events */
        unsigned int            max_events;     /* maximum number of events */
@@ -247,6 +248,19 @@ inotify_dev_get_event(struct inotify_device *dev)
        return list_entry(dev->events.next, struct inotify_kernel_event, list);
 }
 
+/*
+ * inotify_dev_get_last_event - return the last event in the given dev's queue
+ *
+ * Caller must hold dev->ev_mutex.
+ */
+static inline struct inotify_kernel_event *
+inotify_dev_get_last_event(struct inotify_device *dev)
+{
+       if (list_empty(&dev->events))
+               return NULL;
+       return list_entry(dev->events.prev, struct inotify_kernel_event, list);
+}
+
 /*
  * inotify_dev_queue_event - event handler registered with core inotify, adds
  * a new event to the given device
@@ -273,7 +287,7 @@ static void inotify_dev_queue_event(struct inotify_watch *w, u32 wd, u32 mask,
                put_inotify_watch(w); /* final put */
 
        /* coalescing: drop this event if it is a dupe of the previous */
-       last = inotify_dev_get_event(dev);
+       last = inotify_dev_get_last_event(dev);
        if (last && last->event.mask == mask && last->event.wd == wd &&
                        last->event.cookie == cookie) {
                const char *lastname = last->name;
@@ -302,6 +316,7 @@ static void inotify_dev_queue_event(struct inotify_watch *w, u32 wd, u32 mask,
        dev->queue_size += sizeof(struct inotify_event) + kevent->event.len;
        list_add_tail(&kevent->list, &dev->events);
        wake_up_interruptible(&dev->wq);
+       kill_fasync(&dev->fa, SIGIO, POLL_IN);
 
 out:
        mutex_unlock(&dev->ev_mutex);
@@ -490,6 +505,13 @@ static ssize_t inotify_read(struct file *file, char __user *buf,
        return ret;
 }
 
+static int inotify_fasync(int fd, struct file *file, int on)
+{
+       struct inotify_device *dev = file->private_data;
+
+       return fasync_helper(fd, file, on, &dev->fa) >= 0 ? 0 : -EIO;
+}
+
 static int inotify_release(struct inode *ignored, struct file *file)
 {
        struct inotify_device *dev = file->private_data;
@@ -502,6 +524,9 @@ static int inotify_release(struct inode *ignored, struct file *file)
                inotify_dev_event_dequeue(dev);
        mutex_unlock(&dev->ev_mutex);
 
+       if (file->f_flags & FASYNC)
+               inotify_fasync(-1, file, 0);
+
        /* free this device: the put matching the get in inotify_init() */
        put_inotify_dev(dev);
 
@@ -530,6 +555,7 @@ static long inotify_ioctl(struct file *file, unsigned int cmd,
 static const struct file_operations inotify_fops = {
        .poll           = inotify_poll,
        .read           = inotify_read,
+       .fasync         = inotify_fasync,
        .release        = inotify_release,
        .unlocked_ioctl = inotify_ioctl,
        .compat_ioctl   = inotify_ioctl,
@@ -577,6 +603,7 @@ asmlinkage long sys_inotify_init(void)
                goto out_free_dev;
        }
        dev->ih = ih;
+       dev->fa = NULL;
 
        filp->f_op = &inotify_fops;
        filp->f_path.mnt = mntget(inotify_mnt);
index 5d14243499d47d117fa662620f34da9d3bd76ed8..3943a8905eb2595e4f43594e778f0e0f7c69f94a 100644 (file)
@@ -1457,7 +1457,7 @@ static const char *journal_dev_name(journal_t *journal, char *buffer)
  * Aborts hard --- we mark the abort as occurred, but do _nothing_ else,
  * and don't attempt to make any other journal updates.
  */
-void __journal_abort_hard(journal_t *journal)
+static void __journal_abort_hard(journal_t *journal)
 {
        transaction_t *transaction;
        char b[BDEVNAME_SIZE];
index c5d9694b6a2ff2df7f9311942674321c05147c88..2b8edf4d6eaa6462c59f055f81017954d92b0e39 100644 (file)
@@ -354,7 +354,7 @@ static int do_one_pass(journal_t *journal,
                struct buffer_head *    obh;
                struct buffer_head *    nbh;
 
-               cond_resched();         /* We're under lock_kernel() */
+               cond_resched();
 
                /* If we already know where to stop the log traversal,
                 * check right now that we haven't gone past the end of
index 921680663fa2771319837ad1ff24d4c8f9d8c55e..d36356f7d222c94f63f5c64d16137a2692c09841 100644 (file)
@@ -397,7 +397,7 @@ static int do_one_pass(journal_t *journal,
                struct buffer_head *    obh;
                struct buffer_head *    nbh;
 
-               cond_resched();         /* We're under lock_kernel() */
+               cond_resched();
 
                /* If we already know where to stop the log traversal,
                 * check right now that we haven't gone past the end of
index 2eae5d2dbebed3707bf9805675822527a922045e..6c1ba3566f58b4c498c1cfa7a3a627db9e089eeb 100644 (file)
@@ -741,7 +741,7 @@ static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
                         * are not obsolete.
                         *
                         * Of course, this optimization only makes sense in case
-                        * of NAND flashes (or other flashes whith
+                        * of NAND flashes (or other flashes with
                         * !jffs2_can_mark_obsolete()), since on NOR flashes
                         * nodes are marked obsolete physically.
                         *
index 1543906a2e0dd29ac7008ac1204c490b765ba14b..a000aaa75136d68f9b064197af05388b2acf93cf 100644 (file)
@@ -3965,7 +3965,7 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
  *     xtTruncate_pmap()
  *
  * function:
- *     Perform truncate to zero lenghth for deleted file, leaving the
+ *     Perform truncate to zero length for deleted file, leaving the
  *     the xtree and working map untouched.  This allows the file to
  *     be accessed via open file handles, while the delete of the file
  *     is committed to disk.
index 6e68b700958d331e7e0c2446d54b7d9d06b8f3c2..5523bde963879d6060c9a9d19396e8a8615b40a2 100644 (file)
@@ -341,13 +341,10 @@ int simple_prepare_write(struct file *file, struct page *page,
                        unsigned from, unsigned to)
 {
        if (!PageUptodate(page)) {
-               if (to - from != PAGE_CACHE_SIZE) {
-                       void *kaddr = kmap_atomic(page, KM_USER0);
-                       memset(kaddr, 0, from);
-                       memset(kaddr + to, 0, PAGE_CACHE_SIZE - to);
-                       flush_dcache_page(page);
-                       kunmap_atomic(kaddr, KM_USER0);
-               }
+               if (to - from != PAGE_CACHE_SIZE)
+                       zero_user_segments(page,
+                               0, from,
+                               to, PAGE_CACHE_SIZE);
        }
        return 0;
 }
index 572601e98dcdec6d6d88da33ec0b757bd8b7d3f4..ca6b16fc3101a3df88d60350060eae56d6528535 100644 (file)
@@ -34,10 +34,10 @@ static DEFINE_MUTEX(nlm_host_mutex);
 
 static void                    nlm_gc_hosts(void);
 static struct nsm_handle *     __nsm_find(const struct sockaddr_in *,
-                                       const char *, int, int);
+                                       const char *, unsigned int, int);
 static struct nsm_handle *     nsm_find(const struct sockaddr_in *sin,
                                         const char *hostname,
-                                        int hostname_len);
+                                        unsigned int hostname_len);
 
 /*
  * Common host lookup routine for server & client
@@ -45,7 +45,8 @@ static struct nsm_handle *    nsm_find(const struct sockaddr_in *sin,
 static struct nlm_host *
 nlm_lookup_host(int server, const struct sockaddr_in *sin,
                int proto, int version, const char *hostname,
-               int hostname_len, const struct sockaddr_in *ssin)
+               unsigned int hostname_len,
+               const struct sockaddr_in *ssin)
 {
        struct hlist_head *chain;
        struct hlist_node *pos;
@@ -176,7 +177,7 @@ nlm_destroy_host(struct nlm_host *host)
  */
 struct nlm_host *
 nlmclnt_lookup_host(const struct sockaddr_in *sin, int proto, int version,
-                       const char *hostname, int hostname_len)
+                       const char *hostname, unsigned int hostname_len)
 {
        struct sockaddr_in ssin = {0};
 
@@ -189,7 +190,7 @@ nlmclnt_lookup_host(const struct sockaddr_in *sin, int proto, int version,
  */
 struct nlm_host *
 nlmsvc_lookup_host(struct svc_rqst *rqstp,
-                       const char *hostname, int hostname_len)
+                       const char *hostname, unsigned int hostname_len)
 {
        struct sockaddr_in ssin = {0};
 
@@ -307,7 +308,8 @@ void nlm_release_host(struct nlm_host *host)
  * Release all resources held by that peer.
  */
 void nlm_host_rebooted(const struct sockaddr_in *sin,
-                               const char *hostname, int hostname_len,
+                               const char *hostname,
+                               unsigned int hostname_len,
                                u32 new_state)
 {
        struct hlist_head *chain;
@@ -377,8 +379,13 @@ nlm_shutdown_hosts(void)
        /* First, make all hosts eligible for gc */
        dprintk("lockd: nuking all hosts...\n");
        for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
-               hlist_for_each_entry(host, pos, chain, h_hash)
+               hlist_for_each_entry(host, pos, chain, h_hash) {
                        host->h_expires = jiffies - 1;
+                       if (host->h_rpcclnt) {
+                               rpc_shutdown_client(host->h_rpcclnt);
+                               host->h_rpcclnt = NULL;
+                       }
+               }
        }
 
        /* Then, perform a garbage collection pass */
@@ -449,7 +456,7 @@ static DEFINE_MUTEX(nsm_mutex);
 
 static struct nsm_handle *
 __nsm_find(const struct sockaddr_in *sin,
-               const char *hostname, int hostname_len,
+               const char *hostname, unsigned int hostname_len,
                int create)
 {
        struct nsm_handle *nsm = NULL;
@@ -503,7 +510,8 @@ out:
 }
 
 static struct nsm_handle *
-nsm_find(const struct sockaddr_in *sin, const char *hostname, int hostname_len)
+nsm_find(const struct sockaddr_in *sin, const char *hostname,
+        unsigned int hostname_len)
 {
        return __nsm_find(sin, hostname, hostname_len, 1);
 }
index 82e2192a0d5c873a72b867702c511b0c8872f6a7..08226464e5638f1c9ec0636124800609ffb09b84 100644 (file)
@@ -219,19 +219,6 @@ lockd(struct svc_rqst *rqstp)
        module_put_and_exit(0);
 }
 
-
-static int find_socket(struct svc_serv *serv, int proto)
-{
-       struct svc_sock *svsk;
-       int found = 0;
-       list_for_each_entry(svsk, &serv->sv_permsocks, sk_list)
-               if (svsk->sk_sk->sk_protocol == proto) {
-                       found = 1;
-                       break;
-               }
-       return found;
-}
-
 /*
  * Make any sockets that are needed but not present.
  * If nlm_udpport or nlm_tcpport were set as module
@@ -240,17 +227,25 @@ static int find_socket(struct svc_serv *serv, int proto)
 static int make_socks(struct svc_serv *serv, int proto)
 {
        static int warned;
+       struct svc_xprt *xprt;
        int err = 0;
 
-       if (proto == IPPROTO_UDP || nlm_udpport)
-               if (!find_socket(serv, IPPROTO_UDP))
-                       err = svc_makesock(serv, IPPROTO_UDP, nlm_udpport,
-                                               SVC_SOCK_DEFAULTS);
-       if (err >= 0 && (proto == IPPROTO_TCP || nlm_tcpport))
-               if (!find_socket(serv, IPPROTO_TCP))
-                       err = svc_makesock(serv, IPPROTO_TCP, nlm_tcpport,
-                                               SVC_SOCK_DEFAULTS);
-
+       if (proto == IPPROTO_UDP || nlm_udpport) {
+               xprt = svc_find_xprt(serv, "udp", 0, 0);
+               if (!xprt)
+                       err = svc_create_xprt(serv, "udp", nlm_udpport,
+                                             SVC_SOCK_DEFAULTS);
+               else
+                       svc_xprt_put(xprt);
+       }
+       if (err >= 0 && (proto == IPPROTO_TCP || nlm_tcpport)) {
+               xprt = svc_find_xprt(serv, "tcp", 0, 0);
+               if (!xprt)
+                       err = svc_create_xprt(serv, "tcp", nlm_tcpport,
+                                             SVC_SOCK_DEFAULTS);
+               else
+                       svc_xprt_put(xprt);
+       }
        if (err >= 0) {
                warned = 0;
                err = 0;
index bf27b6c6cb6b6219f0518d856d77796ed9694828..385437e3387de895fde1540f58c7d3269a842373 100644 (file)
@@ -84,6 +84,7 @@ nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
 {
        struct nlm_host *host;
        struct nlm_file *file;
+       int rc = rpc_success;
 
        dprintk("lockd: TEST4        called\n");
        resp->cookie = argp->cookie;
@@ -91,7 +92,7 @@ nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
        /* Don't accept test requests during grace period */
        if (nlmsvc_grace_period) {
                resp->status = nlm_lck_denied_grace_period;
-               return rpc_success;
+               return rc;
        }
 
        /* Obtain client and file */
@@ -101,12 +102,13 @@ nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
        /* Now check for conflicting locks */
        resp->status = nlmsvc_testlock(rqstp, file, &argp->lock, &resp->lock, &resp->cookie);
        if (resp->status == nlm_drop_reply)
-               return rpc_drop_reply;
+               rc = rpc_drop_reply;
+       else
+               dprintk("lockd: TEST4        status %d\n", ntohl(resp->status));
 
-       dprintk("lockd: TEST4          status %d\n", ntohl(resp->status));
        nlm_release_host(host);
        nlm_release_file(file);
-       return rpc_success;
+       return rc;
 }
 
 static __be32
@@ -115,6 +117,7 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
 {
        struct nlm_host *host;
        struct nlm_file *file;
+       int rc = rpc_success;
 
        dprintk("lockd: LOCK          called\n");
 
@@ -123,7 +126,7 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
        /* Don't accept new lock requests during grace period */
        if (nlmsvc_grace_period && !argp->reclaim) {
                resp->status = nlm_lck_denied_grace_period;
-               return rpc_success;
+               return rc;
        }
 
        /* Obtain client and file */
@@ -146,12 +149,13 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->status = nlmsvc_lock(rqstp, file, &argp->lock,
                                        argp->block, &argp->cookie);
        if (resp->status == nlm_drop_reply)
-               return rpc_drop_reply;
+               rc = rpc_drop_reply;
+       else
+               dprintk("lockd: LOCK         status %d\n", ntohl(resp->status));
 
-       dprintk("lockd: LOCK          status %d\n", ntohl(resp->status));
        nlm_release_host(host);
        nlm_release_file(file);
-       return rpc_success;
+       return rc;
 }
 
 static __be32
index d120ec39bcb0ea5c472fc7c1f3ba277b9308709d..2f4d8fa666892b9fa8b41266a627608c55c1e8a0 100644 (file)
@@ -501,25 +501,29 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
                        block, block->b_flags, block->b_fl);
                if (block->b_flags & B_TIMED_OUT) {
                        nlmsvc_unlink_block(block);
-                       return nlm_lck_denied;
+                       ret = nlm_lck_denied;
+                       goto out;
                }
                if (block->b_flags & B_GOT_CALLBACK) {
+                       nlmsvc_unlink_block(block);
                        if (block->b_fl != NULL
                                        && block->b_fl->fl_type != F_UNLCK) {
                                lock->fl = *block->b_fl;
                                goto conf_lock;
-                       }
-                       else {
-                               nlmsvc_unlink_block(block);
-                               return nlm_granted;
+                       } else {
+                               ret = nlm_granted;
+                               goto out;
                        }
                }
-               return nlm_drop_reply;
+               ret = nlm_drop_reply;
+               goto out;
        }
 
        error = vfs_test_lock(file->f_file, &lock->fl);
-       if (error == -EINPROGRESS)
-               return nlmsvc_defer_lock_rqst(rqstp, block);
+       if (error == -EINPROGRESS) {
+               ret = nlmsvc_defer_lock_rqst(rqstp, block);
+               goto out;
+       }
        if (error) {
                ret = nlm_lck_denied_nolocks;
                goto out;
index 9cd5c8b37593f099d3c64da583085b733175c038..88379cc6e0b1c0ee196c8686c3f0e7c46cabef9a 100644 (file)
@@ -113,6 +113,7 @@ nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
 {
        struct nlm_host *host;
        struct nlm_file *file;
+       int rc = rpc_success;
 
        dprintk("lockd: TEST          called\n");
        resp->cookie = argp->cookie;
@@ -120,7 +121,7 @@ nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
        /* Don't accept test requests during grace period */
        if (nlmsvc_grace_period) {
                resp->status = nlm_lck_denied_grace_period;
-               return rpc_success;
+               return rc;
        }
 
        /* Obtain client and file */
@@ -130,13 +131,14 @@ nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
        /* Now check for conflicting locks */
        resp->status = cast_status(nlmsvc_testlock(rqstp, file, &argp->lock, &resp->lock, &resp->cookie));
        if (resp->status == nlm_drop_reply)
-               return rpc_drop_reply;
+               rc = rpc_drop_reply;
+       else
+               dprintk("lockd: TEST          status %d vers %d\n",
+                       ntohl(resp->status), rqstp->rq_vers);
 
-       dprintk("lockd: TEST          status %d vers %d\n",
-               ntohl(resp->status), rqstp->rq_vers);
        nlm_release_host(host);
        nlm_release_file(file);
-       return rpc_success;
+       return rc;
 }
 
 static __be32
@@ -145,6 +147,7 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
 {
        struct nlm_host *host;
        struct nlm_file *file;
+       int rc = rpc_success;
 
        dprintk("lockd: LOCK          called\n");
 
@@ -153,7 +156,7 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
        /* Don't accept new lock requests during grace period */
        if (nlmsvc_grace_period && !argp->reclaim) {
                resp->status = nlm_lck_denied_grace_period;
-               return rpc_success;
+               return rc;
        }
 
        /* Obtain client and file */
@@ -176,12 +179,13 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->status = cast_status(nlmsvc_lock(rqstp, file, &argp->lock,
                                               argp->block, &argp->cookie));
        if (resp->status == nlm_drop_reply)
-               return rpc_drop_reply;
+               rc = rpc_drop_reply;
+       else
+               dprintk("lockd: LOCK         status %d\n", ntohl(resp->status));
 
-       dprintk("lockd: LOCK          status %d\n", ntohl(resp->status));
        nlm_release_host(host);
        nlm_release_file(file);
-       return rpc_success;
+       return rc;
 }
 
 static __be32
index 84ebba33b98d0ae2567cb79c45adbae5f9d751fb..dbbefbcd671255935c61783e5cf73d4122346cd7 100644 (file)
@@ -87,7 +87,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,
        unsigned int    hash;
        __be32          nfserr;
 
-       nlm_debug_print_fh("nlm_file_lookup", f);
+       nlm_debug_print_fh("nlm_lookup_file", f);
 
        hash = file_hash(f);
 
index 8b8388eca05e88bde827d97bc71193247c190e86..49354b9c7dc1234779a7c21114e0c976d12e7e1d 100644 (file)
 #include <linux/syscalls.h>
 #include <linux/time.h>
 #include <linux/rcupdate.h>
+#include <linux/pid_namespace.h>
 
 #include <asm/semaphore.h>
 #include <asm/uaccess.h>
@@ -185,6 +186,7 @@ void locks_init_lock(struct file_lock *fl)
        fl->fl_fasync = NULL;
        fl->fl_owner = NULL;
        fl->fl_pid = 0;
+       fl->fl_nspid = NULL;
        fl->fl_file = NULL;
        fl->fl_flags = 0;
        fl->fl_type = 0;
@@ -553,6 +555,8 @@ static void locks_insert_lock(struct file_lock **pos, struct file_lock *fl)
 {
        list_add(&fl->fl_link, &file_lock_list);
 
+       fl->fl_nspid = get_pid(task_tgid(current));
+
        /* insert into file's list */
        fl->fl_next = *pos;
        *pos = fl;
@@ -584,6 +588,11 @@ static void locks_delete_lock(struct file_lock **thisfl_p)
        if (fl->fl_ops && fl->fl_ops->fl_remove)
                fl->fl_ops->fl_remove(fl);
 
+       if (fl->fl_nspid) {
+               put_pid(fl->fl_nspid);
+               fl->fl_nspid = NULL;
+       }
+
        locks_wake_up_blocks(fl);
        locks_free_lock(fl);
 }
@@ -634,33 +643,6 @@ static int flock_locks_conflict(struct file_lock *caller_fl, struct file_lock *s
        return (locks_conflict(caller_fl, sys_fl));
 }
 
-static int interruptible_sleep_on_locked(wait_queue_head_t *fl_wait, int timeout)
-{
-       int result = 0;
-       DECLARE_WAITQUEUE(wait, current);
-
-       __set_current_state(TASK_INTERRUPTIBLE);
-       add_wait_queue(fl_wait, &wait);
-       if (timeout == 0)
-               schedule();
-       else
-               result = schedule_timeout(timeout);
-       if (signal_pending(current))
-               result = -ERESTARTSYS;
-       remove_wait_queue(fl_wait, &wait);
-       __set_current_state(TASK_RUNNING);
-       return result;
-}
-
-static int locks_block_on_timeout(struct file_lock *blocker, struct file_lock *waiter, int time)
-{
-       int result;
-       locks_insert_block(blocker, waiter);
-       result = interruptible_sleep_on_locked(&waiter->fl_wait, time);
-       __locks_delete_block(waiter);
-       return result;
-}
-
 void
 posix_test_lock(struct file *filp, struct file_lock *fl)
 {
@@ -673,55 +655,67 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
                if (posix_locks_conflict(fl, cfl))
                        break;
        }
-       if (cfl)
+       if (cfl) {
                __locks_copy_lock(fl, cfl);
-       else
+               if (cfl->fl_nspid)
+                       fl->fl_pid = pid_nr_ns(cfl->fl_nspid,
+                                               task_active_pid_ns(current));
+       } else
                fl->fl_type = F_UNLCK;
        unlock_kernel();
        return;
 }
-
 EXPORT_SYMBOL(posix_test_lock);
 
-/* This function tests for deadlock condition before putting a process to
- * sleep. The detection scheme is no longer recursive. Recursive was neat,
- * but dangerous - we risked stack corruption if the lock data was bad, or
- * if the recursion was too deep for any other reason.
+/*
+ * Deadlock detection:
+ *
+ * We attempt to detect deadlocks that are due purely to posix file
+ * locks.
  *
- * We rely on the fact that a task can only be on one lock's wait queue
- * at a time. When we find blocked_task on a wait queue we can re-search
- * with blocked_task equal to that queue's owner, until either blocked_task
- * isn't found, or blocked_task is found on a queue owned by my_task.
+ * We assume that a task can be waiting for at most one lock at a time.
+ * So for any acquired lock, the process holding that lock may be
+ * waiting on at most one other lock.  That lock in turns may be held by
+ * someone waiting for at most one other lock.  Given a requested lock
+ * caller_fl which is about to wait for a conflicting lock block_fl, we
+ * follow this chain of waiters to ensure we are not about to create a
+ * cycle.
  *
- * Note: the above assumption may not be true when handling lock requests
- * from a broken NFS client. But broken NFS clients have a lot more to
- * worry about than proper deadlock detection anyway... --okir
+ * Since we do this before we ever put a process to sleep on a lock, we
+ * are ensured that there is never a cycle; that is what guarantees that
+ * the while() loop in posix_locks_deadlock() eventually completes.
  *
- * However, the failure of this assumption (also possible in the case of
- * multiple tasks sharing the same open file table) also means there's no
- * guarantee that the loop below will terminate.  As a hack, we give up
- * after a few iterations.
+ * Note: the above assumption may not be true when handling lock
+ * requests from a broken NFS client. It may also fail in the presence
+ * of tasks (such as posix threads) sharing the same open file table.
+ *
+ * To handle those cases, we just bail out after a few iterations.
  */
 
 #define MAX_DEADLK_ITERATIONS 10
 
+/* Find a lock that the owner of the given block_fl is blocking on. */
+static struct file_lock *what_owner_is_waiting_for(struct file_lock *block_fl)
+{
+       struct file_lock *fl;
+
+       list_for_each_entry(fl, &blocked_list, fl_link) {
+               if (posix_same_owner(fl, block_fl))
+                       return fl->fl_next;
+       }
+       return NULL;
+}
+
 static int posix_locks_deadlock(struct file_lock *caller_fl,
                                struct file_lock *block_fl)
 {
-       struct file_lock *fl;
        int i = 0;
 
-next_task:
-       if (posix_same_owner(caller_fl, block_fl))
-               return 1;
-       list_for_each_entry(fl, &blocked_list, fl_link) {
-               if (posix_same_owner(fl, block_fl)) {
-                       if (i++ > MAX_DEADLK_ITERATIONS)
-                               return 0;
-                       fl = fl->fl_next;
-                       block_fl = fl;
-                       goto next_task;
-               }
+       while ((block_fl = what_owner_is_waiting_for(block_fl))) {
+               if (i++ > MAX_DEADLK_ITERATIONS)
+                       return 0;
+               if (posix_same_owner(caller_fl, block_fl))
+                       return 1;
        }
        return 0;
 }
@@ -1256,7 +1250,10 @@ restart:
                if (break_time == 0)
                        break_time++;
        }
-       error = locks_block_on_timeout(flock, new_fl, break_time);
+       locks_insert_block(flock, new_fl);
+       error = wait_event_interruptible_timeout(new_fl->fl_wait,
+                                               !new_fl->fl_next, break_time);
+       __locks_delete_block(new_fl);
        if (error >= 0) {
                if (error == 0)
                        time_out_leases(inode);
@@ -2084,6 +2081,12 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
                                                        int id, char *pfx)
 {
        struct inode *inode = NULL;
+       unsigned int fl_pid;
+
+       if (fl->fl_nspid)
+               fl_pid = pid_nr_ns(fl->fl_nspid, task_active_pid_ns(current));
+       else
+               fl_pid = fl->fl_pid;
 
        if (fl->fl_file != NULL)
                inode = fl->fl_file->f_path.dentry->d_inode;
@@ -2124,16 +2127,16 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
        }
        if (inode) {
 #ifdef WE_CAN_BREAK_LSLK_NOW
-               seq_printf(f, "%d %s:%ld ", fl->fl_pid,
+               seq_printf(f, "%d %s:%ld ", fl_pid,
                                inode->i_sb->s_id, inode->i_ino);
 #else
                /* userspace relies on this representation of dev_t ;-( */
-               seq_printf(f, "%d %02x:%02x:%ld ", fl->fl_pid,
+               seq_printf(f, "%d %02x:%02x:%ld ", fl_pid,
                                MAJOR(inode->i_sb->s_dev),
                                MINOR(inode->i_sb->s_dev), inode->i_ino);
 #endif
        } else {
-               seq_printf(f, "%d <none>:0 ", fl->fl_pid);
+               seq_printf(f, "%d <none>:0 ", fl_pid);
        }
        if (IS_POSIX(fl)) {
                if (fl->fl_end == OFFSET_MAX)
index d54f8f8972242a62e437bc904059773d2c697e6d..5df564366f36b5ea287245b3b5fd060ab1012f31 100644 (file)
@@ -276,9 +276,7 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
        }
 
        if (first_hole != blocks_per_page) {
-               zero_user_page(page, first_hole << blkbits,
-                               PAGE_CACHE_SIZE - (first_hole << blkbits),
-                               KM_USER0);
+               zero_user_segment(page, first_hole << blkbits, PAGE_CACHE_SIZE);
                if (first_hole == 0) {
                        SetPageUptodate(page);
                        unlock_page(page);
@@ -571,8 +569,7 @@ page_is_mapped:
 
                if (page->index > end_index || !offset)
                        goto confused;
-               zero_user_page(page, offset, PAGE_CACHE_SIZE - offset,
-                               KM_USER0);
+               zero_user_segment(page, offset, PAGE_CACHE_SIZE);
        }
 
        /*
index 73e2e665817a100c9f05c33a12756f639d9c5ae7..241cff423653692ec067afa71ccf9c8ca4e86b05 100644 (file)
@@ -2188,6 +2188,7 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry)
 
        /* We don't d_delete() NFS sillyrenamed files--they still exist. */
        if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
+               fsnotify_link_count(dentry->d_inode);
                d_delete(dentry);
        }
 
@@ -2360,7 +2361,7 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
        error = dir->i_op->link(old_dentry, dir, new_dentry);
        mutex_unlock(&old_dentry->d_inode->i_mutex);
        if (!error)
-               fsnotify_create(dir, new_dentry);
+               fsnotify_link(dir, old_dentry->d_inode, new_dentry);
        return error;
 }
 
index 61bf376e29e85bfda2456cb929c0a0eeb38af1b3..e9c10cd01e1325cff95869cbb0f23aa8d14c10ce 100644 (file)
 #include <linux/security.h>
 #include <linux/mount.h>
 #include <linux/ramfs.h>
+#include <linux/log2.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 #include "pnode.h"
 #include "internal.h"
 
+#define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head))
+#define HASH_SIZE (1UL << HASH_SHIFT)
+
 /* spinlock for vfsmount related operations, inplace of dcache_lock */
 __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
 
 static int event;
 
 static struct list_head *mount_hashtable __read_mostly;
-static int hash_mask __read_mostly, hash_bits __read_mostly;
 static struct kmem_cache *mnt_cache __read_mostly;
 static struct rw_semaphore namespace_sem;
 
@@ -48,8 +51,8 @@ static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
 {
        unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
        tmp += ((unsigned long)dentry / L1_CACHE_BYTES);
-       tmp = tmp + (tmp >> hash_bits);
-       return tmp & hash_mask;
+       tmp = tmp + (tmp >> HASH_SHIFT);
+       return tmp & (HASH_SIZE - 1);
 }
 
 struct vfsmount *alloc_vfsmnt(const char *name)
@@ -1813,9 +1816,7 @@ static void __init init_mount_tree(void)
 
 void __init mnt_init(void)
 {
-       struct list_head *d;
-       unsigned int nr_hash;
-       int i;
+       unsigned u;
        int err;
 
        init_rwsem(&namespace_sem);
@@ -1828,35 +1829,11 @@ void __init mnt_init(void)
        if (!mount_hashtable)
                panic("Failed to allocate mount hash table\n");
 
-       /*
-        * Find the power-of-two list-heads that can fit into the allocation..
-        * We don't guarantee that "sizeof(struct list_head)" is necessarily
-        * a power-of-two.
-        */
-       nr_hash = PAGE_SIZE / sizeof(struct list_head);
-       hash_bits = 0;
-       do {
-               hash_bits++;
-       } while ((nr_hash >> hash_bits) != 0);
-       hash_bits--;
+       printk("Mount-cache hash table entries: %lu\n", HASH_SIZE);
+
+       for (u = 0; u < HASH_SIZE; u++)
+               INIT_LIST_HEAD(&mount_hashtable[u]);
 
-       /*
-        * Re-calculate the actual number of entries and the mask
-        * from the number of bits we can fit.
-        */
-       nr_hash = 1UL << hash_bits;
-       hash_mask = nr_hash - 1;
-
-       printk("Mount-cache hash table entries: %d\n", nr_hash);
-
-       /* And initialize the newly allocated array */
-       d = mount_hashtable;
-       i = nr_hash;
-       do {
-               INIT_LIST_HEAD(d);
-               d++;
-               i--;
-       } while (i);
        err = sysfs_init();
        if (err)
                printk(KERN_WARNING "%s: sysfs_init error: %d\n",
index e1cb70c643f8f81f599ad1da0c76cc9080aba332..eff1f18d034f1b2510aa6ef54c71427bda284ba1 100644 (file)
@@ -987,7 +987,7 @@ static struct file_system_type ncp_fs_type = {
 static int __init init_ncp_fs(void)
 {
        int err;
-       DPRINTK("ncpfs: init_module called\n");
+       DPRINTK("ncpfs: init_ncp_fs called\n");
 
        err = init_inodecache();
        if (err)
@@ -1004,7 +1004,7 @@ out1:
 
 static void __exit exit_ncp_fs(void)
 {
-       DPRINTK("ncpfs: cleanup_module called\n");
+       DPRINTK("ncpfs: exit_ncp_fs called\n");
        unregister_filesystem(&ncp_fs_type);
        destroy_inodecache();
 }
index a94473d3072c606784f86cb058f5371e8b183ff1..5d8dcb9ee326ffcbb3b747666a9f44f1431f7bb8 100644 (file)
@@ -50,10 +50,6 @@ static int ncp_file_mmap_fault(struct vm_area_struct *area,
        pos = vmf->pgoff << PAGE_SHIFT;
 
        count = PAGE_SIZE;
-       if ((unsigned long)vmf->virtual_address + PAGE_SIZE > area->vm_end) {
-               WARN_ON(1); /* shouldn't happen? */
-               count = area->vm_end - (unsigned long)vmf->virtual_address;
-       }
        /* what we can read in one go */
        bufsize = NCP_SERVER(inode)->buffer_size;
 
index 9b6bbf1b978795b8ba29668db9313f1e86bb0d36..bd185a572a23aeb0d015b701d0786dab359f260a 100644 (file)
@@ -119,8 +119,8 @@ int nfs_callback_up(void)
        if (!serv)
                goto out_err;
 
-       ret = svc_makesock(serv, IPPROTO_TCP, nfs_callback_set_tcpport,
-                                                       SVC_SOCK_ANONYMOUS);
+       ret = svc_create_xprt(serv, "tcp", nfs_callback_set_tcpport,
+                             SVC_SOCK_ANONYMOUS);
        if (ret <= 0)
                goto out_destroy;
        nfs_callback_tcpport = ret;
index 8fd6dfbe1bc3b8c248595a85fc5d3f3b86779ee3..3d7d9631e1254f7ad898863e66519740af1e34e9 100644 (file)
@@ -79,7 +79,7 @@ void nfs_readdata_release(void *data)
 static
 int nfs_return_empty_page(struct page *page)
 {
-       zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
+       zero_user(page, 0, PAGE_CACHE_SIZE);
        SetPageUptodate(page);
        unlock_page(page);
        return 0;
@@ -103,10 +103,10 @@ static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data)
        pglen = PAGE_CACHE_SIZE - base;
        for (;;) {
                if (remainder <= pglen) {
-                       zero_user_page(*pages, base, remainder, KM_USER0);
+                       zero_user(*pages, base, remainder);
                        break;
                }
-               zero_user_page(*pages, base, pglen, KM_USER0);
+               zero_user(*pages, base, pglen);
                pages++;
                remainder -= pglen;
                pglen = PAGE_CACHE_SIZE;
@@ -130,7 +130,7 @@ static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
                return PTR_ERR(new);
        }
        if (len < PAGE_CACHE_SIZE)
-               zero_user_page(page, len, PAGE_CACHE_SIZE - len, KM_USER0);
+               zero_user_segment(page, len, PAGE_CACHE_SIZE);
 
        nfs_list_add_request(new, &one_request);
        if (NFS_SERVER(inode)->rsize < PAGE_CACHE_SIZE)
@@ -532,7 +532,7 @@ readpage_async_filler(void *data, struct page *page)
                goto out_error;
 
        if (len < PAGE_CACHE_SIZE)
-               zero_user_page(page, len, PAGE_CACHE_SIZE - len, KM_USER0);
+               zero_user_segment(page, len, PAGE_CACHE_SIZE);
        nfs_pageio_add_request(desc->pgio, new);
        return 0;
 out_error:
index 522efff3e2c51b67befab23c1b4d6c2673d54aeb..b144b1957dd99f7e011e7f635454f4d9215e4757 100644 (file)
@@ -665,9 +665,7 @@ zero_page:
         * then we need to zero any uninitalised data. */
        if (req->wb_pgbase == 0 && req->wb_bytes != PAGE_CACHE_SIZE
                        && !PageUptodate(req->wb_page))
-               zero_user_page(req->wb_page, req->wb_bytes,
-                               PAGE_CACHE_SIZE - req->wb_bytes,
-                               KM_USER0);
+               zero_user_segment(req->wb_page, req->wb_bytes, PAGE_CACHE_SIZE);
        return req;
 }
 
index 21928056e35ecad1c8aa5cb656d9d495df6a3022..d13403e33622eaade5d483d4453f7d58ff4b9a8f 100644 (file)
@@ -11,8 +11,6 @@
 #include <linux/nfsd/nfsd.h>
 #include <linux/nfsd/export.h>
 
-#define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
-
 int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
 {
        struct exp_flavor_info *f;
@@ -69,10 +67,12 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
        ret = set_current_groups(cred.cr_group_info);
        put_group_info(cred.cr_group_info);
        if ((cred.cr_uid)) {
-               cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
+               current->cap_effective =
+                       cap_drop_nfsd_set(current->cap_effective);
        } else {
-               cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
-                                                 current->cap_permitted);
+               current->cap_effective =
+                       cap_raise_nfsd_set(current->cap_effective,
+                                          current->cap_permitted);
        }
        return ret;
 }
similarity index 87%
rename from include/linux/nfsd/auth.h
rename to fs/nfsd/auth.h
index 0fb9f7212195383e47c5354b33e7399ee29a75c0..78b3c0e9382279a5205cbb3e90dc86811a85a10c 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * include/linux/nfsd/auth.h
- *
  * nfsd-specific authentication stuff.
  * uid/gid mapping not yet implemented.
  *
@@ -10,8 +8,6 @@
 #ifndef LINUX_NFSD_AUTH_H
 #define LINUX_NFSD_AUTH_H
 
-#ifdef __KERNEL__
-
 #define nfsd_luid(rq, uid)     ((u32)(uid))
 #define nfsd_lgid(rq, gid)     ((u32)(gid))
 #define nfsd_ruid(rq, uid)     ((u32)(uid))
@@ -23,5 +19,4 @@
  */
 int nfsd_setuser(struct svc_rqst *, struct svc_export *);
 
-#endif /* __KERNEL__ */
 #endif /* LINUX_NFSD_AUTH_H */
index 66d0aeb32a47e5f4385e68c1947a8d8c1ab3a7e5..79b4bf8129602b9ebbbec979960d614e90b7185b 100644 (file)
@@ -1357,8 +1357,6 @@ exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
        mk_fsid(FSID_NUM, fsidv, 0, 0, 0, NULL);
 
        exp = rqst_exp_find(rqstp, FSID_NUM, fsidv);
-       if (PTR_ERR(exp) == -ENOENT)
-               return nfserr_perm;
        if (IS_ERR(exp))
                return nfserrno(PTR_ERR(exp));
        rv = fh_compose(fhp, exp, exp->ex_dentry, NULL);
@@ -1637,13 +1635,19 @@ exp_verify_string(char *cp, int max)
 /*
  * Initialize the exports module.
  */
-void
+int
 nfsd_export_init(void)
 {
+       int rv;
        dprintk("nfsd: initializing export module.\n");
 
-       cache_register(&svc_export_cache);
-       cache_register(&svc_expkey_cache);
+       rv = cache_register(&svc_export_cache);
+       if (rv)
+               return rv;
+       rv = cache_register(&svc_expkey_cache);
+       if (rv)
+               cache_unregister(&svc_export_cache);
+       return rv;
 
 }
 
@@ -1670,10 +1674,8 @@ nfsd_export_shutdown(void)
 
        exp_writelock();
 
-       if (cache_unregister(&svc_expkey_cache))
-               printk(KERN_ERR "nfsd: failed to unregister expkey cache\n");
-       if (cache_unregister(&svc_export_cache))
-               printk(KERN_ERR "nfsd: failed to unregister export cache\n");
+       cache_unregister(&svc_expkey_cache);
+       cache_unregister(&svc_export_cache);
        svcauth_unix_purge();
 
        exp_writeunlock();
index 0e5fa11e6b44c4fa114e5e48ef0408a4227a5c07..1c3b7654e966d9f02cd46d8284ee636e670dd882 100644 (file)
@@ -221,12 +221,17 @@ static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
                struct nfsd3_getaclres *resp)
 {
        struct dentry *dentry = resp->fh.fh_dentry;
-       struct inode *inode = dentry->d_inode;
+       struct inode *inode;
        struct kvec *head = rqstp->rq_res.head;
        unsigned int base;
        int n;
        int w;
 
+       /*
+        * Since this is version 2, the check for nfserr in
+        * nfsd_dispatch actually ensures the following cannot happen.
+        * However, it seems fragile to depend on that.
+        */
        if (dentry == NULL || dentry->d_inode == NULL)
                return 0;
        inode = dentry->d_inode;
index f917fd25858af81a4edaf712fffa3480ee3a8e6b..d7647f70e02b0b2cf219577a67ebdff68ce73116 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/sunrpc/svc.h>
 #include <linux/nfsd/nfsd.h>
 #include <linux/nfsd/xdr3.h>
+#include "auth.h"
 
 #define NFSDDBG_FACILITY               NFSDDBG_XDR
 
@@ -88,10 +89,10 @@ encode_fh(__be32 *p, struct svc_fh *fhp)
  * no slashes or null bytes.
  */
 static __be32 *
-decode_filename(__be32 *p, char **namp, int *lenp)
+decode_filename(__be32 *p, char **namp, unsigned int *lenp)
 {
        char            *name;
-       int             i;
+       unsigned int    i;
 
        if ((p = xdr_decode_string_inplace(p, namp, lenp, NFS3_MAXNAMLEN)) != NULL) {
                for (i = 0, name = *namp; i < *lenp; i++, name++) {
@@ -452,8 +453,7 @@ int
 nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p,
                                        struct nfsd3_symlinkargs *args)
 {
-       unsigned int len;
-       int avail;
+       unsigned int len, avail;
        char *old, *new;
        struct kvec *vec;
 
@@ -486,7 +486,8 @@ nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p,
        /* now copy next page if there is one */
        if (len && !avail && rqstp->rq_arg.page_len) {
                avail = rqstp->rq_arg.page_len;
-               if (avail > PAGE_SIZE) avail = PAGE_SIZE;
+               if (avail > PAGE_SIZE)
+                       avail = PAGE_SIZE;
                old = page_address(rqstp->rq_arg.pages[0]);
        }
        while (len && avail && *old) {
@@ -816,11 +817,11 @@ static __be32 *
 encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p,
                struct svc_fh *fhp)
 {
-               p = encode_post_op_attr(cd->rqstp, p, fhp);
-               *p++ = xdr_one;                 /* yes, a file handle follows */
-               p = encode_fh(p, fhp);
-               fh_put(fhp);
-               return p;
+       p = encode_post_op_attr(cd->rqstp, p, fhp);
+       *p++ = xdr_one;                 /* yes, a file handle follows */
+       p = encode_fh(p, fhp);
+       fh_put(fhp);
+       return p;
 }
 
 static int
index 9d536a8cb3795651551af7b228407a09d890f7b7..aae2b29ae2c9e6d4b645f91bf68b50046030accc 100644 (file)
@@ -350,30 +350,6 @@ static struct rpc_version *        nfs_cb_version[] = {
 static int do_probe_callback(void *data)
 {
        struct nfs4_client *clp = data;
-       struct nfs4_callback *cb = &clp->cl_callback;
-       struct rpc_message msg = {
-               .rpc_proc       = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL],
-               .rpc_argp       = clp,
-       };
-       int status;
-
-       status = rpc_call_sync(cb->cb_client, &msg, RPC_TASK_SOFT);
-
-       if (status) {
-               rpc_shutdown_client(cb->cb_client);
-               cb->cb_client = NULL;
-       } else
-               atomic_set(&cb->cb_set, 1);
-       put_nfs4_client(clp);
-       return 0;
-}
-
-/*
- * Set up the callback client and put a NFSPROC4_CB_NULL on the wire...
- */
-void
-nfsd4_probe_callback(struct nfs4_client *clp)
-{
        struct sockaddr_in      addr;
        struct nfs4_callback    *cb = &clp->cl_callback;
        struct rpc_timeout      timeparms = {
@@ -390,13 +366,15 @@ nfsd4_probe_callback(struct nfs4_client *clp)
                .timeout        = &timeparms,
                .program        = program,
                .version        = nfs_cb_version[1]->number,
-               .authflavor     = RPC_AUTH_UNIX,        /* XXX: need AUTH_GSS... */
+               .authflavor     = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */
                .flags          = (RPC_CLNT_CREATE_NOPING),
        };
-       struct task_struct *t;
-
-       if (atomic_read(&cb->cb_set))
-               return;
+       struct rpc_message msg = {
+               .rpc_proc       = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL],
+               .rpc_argp       = clp,
+       };
+       struct rpc_clnt *client;
+       int status;
 
        /* Initialize address */
        memset(&addr, 0, sizeof(addr));
@@ -416,29 +394,50 @@ nfsd4_probe_callback(struct nfs4_client *clp)
        program->stats->program = program;
 
        /* Create RPC client */
-       cb->cb_client = rpc_create(&args);
-       if (IS_ERR(cb->cb_client)) {
+       client = rpc_create(&args);
+       if (IS_ERR(client)) {
                dprintk("NFSD: couldn't create callback client\n");
+               status = PTR_ERR(client);
                goto out_err;
        }
 
+       status = rpc_call_sync(client, &msg, RPC_TASK_SOFT);
+
+       if (status)
+               goto out_release_client;
+
+       cb->cb_client = client;
+       atomic_set(&cb->cb_set, 1);
+       put_nfs4_client(clp);
+       return 0;
+out_release_client:
+       rpc_shutdown_client(client);
+out_err:
+       put_nfs4_client(clp);
+       dprintk("NFSD: warning: no callback path to client %.*s\n",
+               (int)clp->cl_name.len, clp->cl_name.data);
+       return status;
+}
+
+/*
+ * Set up the callback client and put a NFSPROC4_CB_NULL on the wire...
+ */
+void
+nfsd4_probe_callback(struct nfs4_client *clp)
+{
+       struct task_struct *t;
+
+       BUG_ON(atomic_read(&clp->cl_callback.cb_set));
+
        /* the task holds a reference to the nfs4_client struct */
        atomic_inc(&clp->cl_count);
 
        t = kthread_run(do_probe_callback, clp, "nfs4_cb_probe");
 
        if (IS_ERR(t))
-               goto out_release_clp;
+               atomic_dec(&clp->cl_count);
 
        return;
-
-out_release_clp:
-       atomic_dec(&clp->cl_count);
-       rpc_shutdown_client(cb->cb_client);
-out_err:
-       cb->cb_client = NULL;
-       dprintk("NFSD: warning: no callback path to client %.*s\n",
-               (int)clp->cl_name.len, clp->cl_name.data);
 }
 
 /*
@@ -458,9 +457,6 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)
        int retries = 1;
        int status = 0;
 
-       if ((!atomic_read(&clp->cl_callback.cb_set)) || !clnt)
-               return;
-
        cbr->cbr_trunc = 0; /* XXX need to implement truncate optimization */
        cbr->cbr_dp = dp;
 
@@ -469,6 +465,7 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)
                switch (status) {
                        case -EIO:
                                /* Network partition? */
+                               atomic_set(&clp->cl_callback.cb_set, 0);
                        case -EBADHANDLE:
                        case -NFS4ERR_BAD_STATEID:
                                /* Race: client probably got cb_recall
@@ -481,11 +478,10 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)
                status = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT);
        }
 out_put_cred:
-       if (status == -EIO)
-               atomic_set(&clp->cl_callback.cb_set, 0);
-       /* Success or failure, now we're either waiting for lease expiration
-        * or deleg_return. */
-       dprintk("NFSD: nfs4_cb_recall: dp %p dl_flock %p dl_count %d\n",dp, dp->dl_flock, atomic_read(&dp->dl_count));
+       /*
+        * Success or failure, now we're either waiting for lease expiration
+        * or deleg_return.
+        */
        put_nfs4_client(clp);
        nfs4_put_delegation(dp);
        return;
index 4c0c683ce07a8be9852f06370dfad35d3591a45a..996bd88b75ba4d4e094129d6e856c561f6843b57 100644 (file)
@@ -255,13 +255,10 @@ idtoname_parse(struct cache_detail *cd, char *buf, int buflen)
                goto out;
        if (len == 0)
                set_bit(CACHE_NEGATIVE, &ent.h.flags);
-       else {
-               if (error >= IDMAP_NAMESZ) {
-                       error = -EINVAL;
-                       goto out;
-               }
+       else if (len >= IDMAP_NAMESZ)
+               goto out;
+       else
                memcpy(ent.name, buf1, sizeof(ent.name));
-       }
        error = -ENOMEM;
        res = idtoname_update(&ent, res);
        if (res == NULL)
@@ -467,20 +464,25 @@ nametoid_update(struct ent *new, struct ent *old)
  * Exported API
  */
 
-void
+int
 nfsd_idmap_init(void)
 {
-       cache_register(&idtoname_cache);
-       cache_register(&nametoid_cache);
+       int rv;
+
+       rv = cache_register(&idtoname_cache);
+       if (rv)
+               return rv;
+       rv = cache_register(&nametoid_cache);
+       if (rv)
+               cache_unregister(&idtoname_cache);
+       return rv;
 }
 
 void
 nfsd_idmap_shutdown(void)
 {
-       if (cache_unregister(&idtoname_cache))
-               printk(KERN_ERR "nfsd: failed to unregister idtoname cache\n");
-       if (cache_unregister(&nametoid_cache))
-               printk(KERN_ERR "nfsd: failed to unregister nametoid cache\n");
+       cache_unregister(&idtoname_cache);
+       cache_unregister(&nametoid_cache);
 }
 
 /*
index 18ead1790bb388461b08d42e3e5fcc5c1d1807cd..c593db047d8bbd51babb22bbacc765f65636ff68 100644 (file)
@@ -750,7 +750,7 @@ _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                                    cstate->current_fh.fh_export,
                                    cstate->current_fh.fh_dentry, buf,
                                    &count, verify->ve_bmval,
-                                   rqstp);
+                                   rqstp, 0);
 
        /* this means that nfsd4_encode_fattr() ran out of space */
        if (status == nfserr_resource && count == 0)
index 31673cd251c3c2936b99e566a34773f5a0dce0c1..f6744bc03dae28e5249132ccc719a47e25ffeb63 100644 (file)
@@ -61,7 +61,6 @@ static time_t lease_time = 90;     /* default lease time */
 static time_t user_lease_time = 90;
 static time_t boot_time;
 static int in_grace = 1;
-static u32 current_clientid = 1;
 static u32 current_ownerid = 1;
 static u32 current_fileid = 1;
 static u32 current_delegid = 1;
@@ -340,21 +339,20 @@ STALE_CLIENTID(clientid_t *clid)
  * This type of memory management is somewhat inefficient, but we use it
  * anyway since SETCLIENTID is not a common operation.
  */
-static inline struct nfs4_client *
-alloc_client(struct xdr_netobj name)
+static struct nfs4_client *alloc_client(struct xdr_netobj name)
 {
        struct nfs4_client *clp;
 
-       if ((clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL))!= NULL) {
-               if ((clp->cl_name.data = kmalloc(name.len, GFP_KERNEL)) != NULL) {
-                       memcpy(clp->cl_name.data, name.data, name.len);
-                       clp->cl_name.len = name.len;
-               }
-               else {
-                       kfree(clp);
-                       clp = NULL;
-               }
+       clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL);
+       if (clp == NULL)
+               return NULL;
+       clp->cl_name.data = kmalloc(name.len, GFP_KERNEL);
+       if (clp->cl_name.data == NULL) {
+               kfree(clp);
+               return NULL;
        }
+       memcpy(clp->cl_name.data, name.data, name.len);
+       clp->cl_name.len = name.len;
        return clp;
 }
 
@@ -363,8 +361,11 @@ shutdown_callback_client(struct nfs4_client *clp)
 {
        struct rpc_clnt *clnt = clp->cl_callback.cb_client;
 
-       /* shutdown rpc client, ending any outstanding recall rpcs */
        if (clnt) {
+               /*
+                * Callback threads take a reference on the client, so there
+                * should be no outstanding callbacks at this point.
+                */
                clp->cl_callback.cb_client = NULL;
                rpc_shutdown_client(clnt);
        }
@@ -422,12 +423,13 @@ expire_client(struct nfs4_client *clp)
        put_nfs4_client(clp);
 }
 
-static struct nfs4_client *
-create_client(struct xdr_netobj name, char *recdir) {
+static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir)
+{
        struct nfs4_client *clp;
 
-       if (!(clp = alloc_client(name)))
-               goto out;
+       clp = alloc_client(name);
+       if (clp == NULL)
+               return NULL;
        memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
        atomic_set(&clp->cl_count, 1);
        atomic_set(&clp->cl_callback.cb_set, 0);
@@ -436,32 +438,30 @@ create_client(struct xdr_netobj name, char *recdir) {
        INIT_LIST_HEAD(&clp->cl_openowners);
        INIT_LIST_HEAD(&clp->cl_delegations);
        INIT_LIST_HEAD(&clp->cl_lru);
-out:
        return clp;
 }
 
-static void
-copy_verf(struct nfs4_client *target, nfs4_verifier *source) {
-       memcpy(target->cl_verifier.data, source->data, sizeof(target->cl_verifier.data));
+static void copy_verf(struct nfs4_client *target, nfs4_verifier *source)
+{
+       memcpy(target->cl_verifier.data, source->data,
+                       sizeof(target->cl_verifier.data));
 }
 
-static void
-copy_clid(struct nfs4_client *target, struct nfs4_client *source) {
+static void copy_clid(struct nfs4_client *target, struct nfs4_client *source)
+{
        target->cl_clientid.cl_boot = source->cl_clientid.cl_boot; 
        target->cl_clientid.cl_id = source->cl_clientid.cl_id; 
 }
 
-static void
-copy_cred(struct svc_cred *target, struct svc_cred *source) {
-
+static void copy_cred(struct svc_cred *target, struct svc_cred *source)
+{
        target->cr_uid = source->cr_uid;
        target->cr_gid = source->cr_gid;
        target->cr_group_info = source->cr_group_info;
        get_group_info(target->cr_group_info);
 }
 
-static inline int
-same_name(const char *n1, const char *n2)
+static int same_name(const char *n1, const char *n2)
 {
        return 0 == memcmp(n1, n2, HEXDIR_LEN);
 }
@@ -485,26 +485,26 @@ same_creds(struct svc_cred *cr1, struct svc_cred *cr2)
        return cr1->cr_uid == cr2->cr_uid;
 }
 
-static void
-gen_clid(struct nfs4_client *clp) {
+static void gen_clid(struct nfs4_client *clp)
+{
+       static u32 current_clientid = 1;
+
        clp->cl_clientid.cl_boot = boot_time;
        clp->cl_clientid.cl_id = current_clientid++; 
 }
 
-static void
-gen_confirm(struct nfs4_client *clp) {
-       struct timespec         tv;
-       u32 *                   p;
+static void gen_confirm(struct nfs4_client *clp)
+{
+       static u32 i;
+       u32 *p;
 
-       tv = CURRENT_TIME;
        p = (u32 *)clp->cl_confirm.data;
-       *p++ = tv.tv_sec;
-       *p++ = tv.tv_nsec;
+       *p++ = get_seconds();
+       *p++ = i++;
 }
 
-static int
-check_name(struct xdr_netobj name) {
-
+static int check_name(struct xdr_netobj name)
+{
        if (name.len == 0) 
                return 0;
        if (name.len > NFS4_OPAQUE_LIMIT) {
@@ -683,39 +683,6 @@ out_err:
        return;
 }
 
-/*
- * RFC 3010 has a complex implmentation description of processing a 
- * SETCLIENTID request consisting of 5 bullets, labeled as 
- * CASE0 - CASE4 below.
- *
- * NOTES:
- *     callback information will be processed in a future patch
- *
- *     an unconfirmed record is added when:
- *      NORMAL (part of CASE 4): there is no confirmed nor unconfirmed record.
- *     CASE 1: confirmed record found with matching name, principal,
- *             verifier, and clientid.
- *     CASE 2: confirmed record found with matching name, principal,
- *             and there is no unconfirmed record with matching
- *             name and principal
- *
- *      an unconfirmed record is replaced when:
- *     CASE 3: confirmed record found with matching name, principal,
- *             and an unconfirmed record is found with matching 
- *             name, principal, and with clientid and
- *             confirm that does not match the confirmed record.
- *     CASE 4: there is no confirmed record with matching name and 
- *             principal. there is an unconfirmed record with 
- *             matching name, principal.
- *
- *     an unconfirmed record is deleted when:
- *     CASE 1: an unconfirmed record that matches input name, verifier,
- *             and confirmed clientid.
- *     CASE 4: any unconfirmed records with matching name and principal
- *             that exist after an unconfirmed record has been replaced
- *             as described above.
- *
- */
 __be32
 nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                  struct nfsd4_setclientid *setclid)
@@ -748,11 +715,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        nfs4_lock_state();
        conf = find_confirmed_client_by_str(dname, strhashval);
        if (conf) {
-               /* 
-                * CASE 0:
-                * clname match, confirmed, different principal
-                * or different ip_address
-                */
+               /* RFC 3530 14.2.33 CASE 0: */
                status = nfserr_clid_inuse;
                if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)
                                || conf->cl_addr != sin->sin_addr.s_addr) {
@@ -761,12 +724,17 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                        goto out;
                }
        }
+       /*
+        * section 14.2.33 of RFC 3530 (under the heading "IMPLEMENTATION")
+        * has a description of SETCLIENTID request processing consisting
+        * of 5 bullet points, labeled as CASE0 - CASE4 below.
+        */
        unconf = find_unconfirmed_client_by_str(dname, strhashval);
        status = nfserr_resource;
        if (!conf) {
-               /* 
-                * CASE 4:
-                * placed first, because it is the normal case.
+               /*
+                * RFC 3530 14.2.33 CASE 4:
+                * placed first, because it is the normal case
                 */
                if (unconf)
                        expire_client(unconf);
@@ -776,17 +744,8 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                gen_clid(new);
        } else if (same_verf(&conf->cl_verifier, &clverifier)) {
                /*
-                * CASE 1:
-                * cl_name match, confirmed, principal match
-                * verifier match: probable callback update
-                *
-                * remove any unconfirmed nfs4_client with 
-                * matching cl_name, cl_verifier, and cl_clientid
-                *
-                * create and insert an unconfirmed nfs4_client with same 
-                * cl_name, cl_verifier, and cl_clientid as existing 
-                * nfs4_client,  but with the new callback info and a 
-                * new cl_confirm
+                * RFC 3530 14.2.33 CASE 1:
+                * probable callback update
                 */
                if (unconf) {
                        /* Note this is removing unconfirmed {*x***},
@@ -802,43 +761,25 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                copy_clid(new, conf);
        } else if (!unconf) {
                /*
-                * CASE 2:
-                * clname match, confirmed, principal match
-                * verfier does not match
-                * no unconfirmed. create a new unconfirmed nfs4_client
-                * using input clverifier, clname, and callback info
-                * and generate a new cl_clientid and cl_confirm.
+                * RFC 3530 14.2.33 CASE 2:
+                * probable client reboot; state will be removed if
+                * confirmed.
                 */
                new = create_client(clname, dname);
                if (new == NULL)
                        goto out;
                gen_clid(new);
-       } else if (!same_verf(&conf->cl_confirm, &unconf->cl_confirm)) {
-               /*      
-                * CASE3:
-                * confirmed found (name, principal match)
-                * confirmed verifier does not match input clverifier
-                *
-                * unconfirmed found (name match)
-                * confirmed->cl_confirm != unconfirmed->cl_confirm
-                *
-                * remove unconfirmed.
-                *
-                * create an unconfirmed nfs4_client 
-                * with same cl_name as existing confirmed nfs4_client, 
-                * but with new callback info, new cl_clientid,
-                * new cl_verifier and a new cl_confirm
+       } else {
+               /*
+                * RFC 3530 14.2.33 CASE 3:
+                * probable client reboot; state will be removed if
+                * confirmed.
                 */
                expire_client(unconf);
                new = create_client(clname, dname);
                if (new == NULL)
                        goto out;
                gen_clid(new);
-       } else {
-               /* No cases hit !!! */
-               status = nfserr_inval;
-               goto out;
-
        }
        copy_verf(new, &clverifier);
        new->cl_addr = sin->sin_addr.s_addr;
@@ -857,11 +798,9 @@ out:
 
 
 /*
- * RFC 3010 has a complex implmentation description of processing a 
- * SETCLIENTID_CONFIRM request consisting of 4 bullets describing
- * processing on a DRC miss, labeled as CASE1 - CASE4 below.
- *
- * NOTE: callback information will be processed here in a future patch
+ * Section 14.2.34 of RFC 3530 (under the heading "IMPLEMENTATION") has
+ * a description of SETCLIENTID_CONFIRM request processing consisting of 4
+ * bullets, labeled as CASE1 - CASE4 below.
  */
 __be32
 nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
@@ -892,16 +831,16 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
        if (unconf && unconf->cl_addr != sin->sin_addr.s_addr)
                goto out;
 
-       if ((conf && unconf) && 
-           (same_verf(&unconf->cl_confirm, &confirm)) &&
-           (same_verf(&conf->cl_verifier, &unconf->cl_verifier)) &&
-           (same_name(conf->cl_recdir,unconf->cl_recdir))  &&
-           (!same_verf(&conf->cl_confirm, &unconf->cl_confirm))) {
-               /* CASE 1:
-               * unconf record that matches input clientid and input confirm.
-               * conf record that matches input clientid.
-               * conf and unconf records match names, verifiers
-               */
+       /*
+        * section 14.2.34 of RFC 3530 has a description of
+        * SETCLIENTID_CONFIRM request processing consisting
+        * of 4 bullet points, labeled as CASE1 - CASE4 below.
+        */
+       if (conf && unconf && same_verf(&confirm, &unconf->cl_confirm)) {
+               /*
+                * RFC 3530 14.2.34 CASE 1:
+                * callback update
+                */
                if (!same_creds(&conf->cl_cred, &unconf->cl_cred))
                        status = nfserr_clid_inuse;
                else {
@@ -914,15 +853,11 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
                        status = nfs_ok;
 
                }
-       } else if ((conf && !unconf) ||
-           ((conf && unconf) && 
-            (!same_verf(&conf->cl_verifier, &unconf->cl_verifier) ||
-             !same_name(conf->cl_recdir, unconf->cl_recdir)))) {
-               /* CASE 2:
-                * conf record that matches input clientid.
-                * if unconf record matches input clientid, then
-                * unconf->cl_name or unconf->cl_verifier don't match the
-                * conf record.
+       } else if (conf && !unconf) {
+               /*
+                * RFC 3530 14.2.34 CASE 2:
+                * probable retransmitted request; play it safe and
+                * do nothing.
                 */
                if (!same_creds(&conf->cl_cred, &rqstp->rq_cred))
                        status = nfserr_clid_inuse;
@@ -930,10 +865,9 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
                        status = nfs_ok;
        } else if (!conf && unconf
                        && same_verf(&unconf->cl_confirm, &confirm)) {
-               /* CASE 3:
-                * conf record not found.
-                * unconf record found.
-                * unconf->cl_confirm matches input confirm
+               /*
+                * RFC 3530 14.2.34 CASE 3:
+                * Normal case; new or rebooted client:
                 */
                if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred)) {
                        status = nfserr_clid_inuse;
@@ -948,16 +882,15 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
                        }
                        move_to_confirmed(unconf);
                        conf = unconf;
+                       nfsd4_probe_callback(conf);
                        status = nfs_ok;
                }
        } else if ((!conf || (conf && !same_verf(&conf->cl_confirm, &confirm)))
            && (!unconf || (unconf && !same_verf(&unconf->cl_confirm,
                                                                &confirm)))) {
-               /* CASE 4:
-                * conf record not found, or if conf, conf->cl_confirm does not
-                * match input confirm.
-                * unconf record not found, or if unconf, unconf->cl_confirm
-                * does not match input confirm.
+               /*
+                * RFC 3530 14.2.34 CASE 4:
+                * Client probably hasn't noticed that we rebooted yet.
                 */
                status = nfserr_stale_clientid;
        } else {
@@ -965,8 +898,6 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
                status = nfserr_clid_inuse;
        }
 out:
-       if (!status)
-               nfsd4_probe_callback(conf);
        nfs4_unlock_state();
        return status;
 }
@@ -1226,14 +1157,19 @@ find_file(struct inode *ino)
        return NULL;
 }
 
-static int access_valid(u32 x)
+static inline int access_valid(u32 x)
 {
-       return (x > 0 && x < 4);
+       if (x < NFS4_SHARE_ACCESS_READ)
+               return 0;
+       if (x > NFS4_SHARE_ACCESS_BOTH)
+               return 0;
+       return 1;
 }
 
-static int deny_valid(u32 x)
+static inline int deny_valid(u32 x)
 {
-       return (x >= 0 && x < 5);
+       /* Note: unlike access bits, deny bits may be zero. */
+       return x <= NFS4_SHARE_DENY_BOTH;
 }
 
 static void
@@ -2162,8 +2098,10 @@ nfs4_preprocess_seqid_op(struct svc_fh *current_fh, u32 seqid, stateid_t *statei
                goto check_replay;
        }
 
+       *stpp = stp;
+       *sopp = sop = stp->st_stateowner;
+
        if (lock) {
-               struct nfs4_stateowner *sop = stp->st_stateowner;
                clientid_t *lockclid = &lock->v.new.clientid;
                struct nfs4_client *clp = sop->so_client;
                int lkflg = 0;
@@ -2193,9 +2131,6 @@ nfs4_preprocess_seqid_op(struct svc_fh *current_fh, u32 seqid, stateid_t *statei
                return nfserr_bad_stateid;
        }
 
-       *stpp = stp;
-       *sopp = sop = stp->st_stateowner;
-
        /*
        *  We now validate the seqid and stateid generation numbers.
        *  For the moment, we ignore the possibility of 
index 57333944af7fe5c63937472088c29b4725f006d2..b0592e7c378dbdf29878528bdfd8e3def4c744ad 100644 (file)
@@ -148,12 +148,12 @@ xdr_error:                                        \
        }                                       \
 } while (0)
 
-static __be32 *read_buf(struct nfsd4_compoundargs *argp, int nbytes)
+static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
 {
        /* We want more bytes than seem to be available.
         * Maybe we need a new page, maybe we have just run out
         */
-       int avail = (char*)argp->end - (char*)argp->p;
+       unsigned int avail = (char *)argp->end - (char *)argp->p;
        __be32 *p;
        if (avail + argp->pagelen < nbytes)
                return NULL;
@@ -169,6 +169,11 @@ static __be32 *read_buf(struct nfsd4_compoundargs *argp, int nbytes)
                        return NULL;
                
        }
+       /*
+        * The following memcpy is safe because read_buf is always
+        * called with nbytes > avail, and the two cases above both
+        * guarantee p points to at least nbytes bytes.
+        */
        memcpy(p, argp->p, avail);
        /* step to next page */
        argp->p = page_address(argp->pagelist[0]);
@@ -1448,7 +1453,7 @@ static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
 __be32
 nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
                struct dentry *dentry, __be32 *buffer, int *countp, u32 *bmval,
-               struct svc_rqst *rqstp)
+               struct svc_rqst *rqstp, int ignore_crossmnt)
 {
        u32 bmval0 = bmval[0];
        u32 bmval1 = bmval[1];
@@ -1828,7 +1833,12 @@ out_acl:
        if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
                if ((buflen -= 8) < 0)
                        goto out_resource;
-               if (exp->ex_mnt->mnt_root->d_inode == dentry->d_inode) {
+               /*
+                * Get parent's attributes if not ignoring crossmount
+                * and this is the root of a cross-mounted filesystem.
+                */
+               if (ignore_crossmnt == 0 &&
+                   exp->ex_mnt->mnt_root->d_inode == dentry->d_inode) {
                        err = vfs_getattr(exp->ex_mnt->mnt_parent,
                                exp->ex_mnt->mnt_mountpoint, &stat);
                        if (err)
@@ -1864,13 +1874,25 @@ nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
        struct svc_export *exp = cd->rd_fhp->fh_export;
        struct dentry *dentry;
        __be32 nfserr;
+       int ignore_crossmnt = 0;
 
        dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
        if (IS_ERR(dentry))
                return nfserrno(PTR_ERR(dentry));
 
        exp_get(exp);
-       if (d_mountpoint(dentry)) {
+       /*
+        * In the case of a mountpoint, the client may be asking for
+        * attributes that are only properties of the underlying filesystem
+        * as opposed to the cross-mounted file system. In such a case,
+        * we will not follow the cross mount and will fill the attribtutes
+        * directly from the mountpoint dentry.
+        */
+       if (d_mountpoint(dentry) &&
+           (cd->rd_bmval[0] & ~FATTR4_WORD0_RDATTR_ERROR) == 0 &&
+           (cd->rd_bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) == 0)
+               ignore_crossmnt = 1;
+       else if (d_mountpoint(dentry)) {
                int err;
 
                /*
@@ -1889,7 +1911,7 @@ nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
 
        }
        nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
-                                       cd->rd_rqstp);
+                                       cd->rd_rqstp, ignore_crossmnt);
 out_put:
        dput(dentry);
        exp_put(exp);
@@ -2043,7 +2065,7 @@ nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
        buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
        nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
                                    resp->p, &buflen, getattr->ga_bmval,
-                                   resp->rqstp);
+                                   resp->rqstp, 0);
        if (!nfserr)
                resp->p += buflen;
        return nfserr;
index 578f2c9d56bec09899d4dc1c0ca135320e7c6bf9..5bfc2ac60d543a07a8d70d71057cf880d1bb995e 100644 (file)
@@ -44,17 +44,17 @@ static int  nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
  */
 static DEFINE_SPINLOCK(cache_lock);
 
-void
-nfsd_cache_init(void)
+int nfsd_reply_cache_init(void)
 {
        struct svc_cacherep     *rp;
        int                     i;
 
        INIT_LIST_HEAD(&lru_head);
        i = CACHESIZE;
-       while(i) {
+       while (i) {
                rp = kmalloc(sizeof(*rp), GFP_KERNEL);
-               if (!rp) break;
+               if (!rp)
+                       goto out_nomem;
                list_add(&rp->c_lru, &lru_head);
                rp->c_state = RC_UNUSED;
                rp->c_type = RC_NOCACHE;
@@ -62,23 +62,19 @@ nfsd_cache_init(void)
                i--;
        }
 
-       if (i)
-               printk (KERN_ERR "nfsd: cannot allocate all %d cache entries, only got %d\n",
-                       CACHESIZE, CACHESIZE-i);
-
        hash_list = kcalloc (HASHSIZE, sizeof(struct hlist_head), GFP_KERNEL);
-       if (!hash_list) {
-               nfsd_cache_shutdown();
-               printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n",
-                       HASHSIZE * sizeof(struct hlist_head));
-               return;
-       }
+       if (!hash_list)
+               goto out_nomem;
 
        cache_disabled = 0;
+       return 0;
+out_nomem:
+       printk(KERN_ERR "nfsd: failed to allocate reply cache\n");
+       nfsd_reply_cache_shutdown();
+       return -ENOMEM;
 }
 
-void
-nfsd_cache_shutdown(void)
+void nfsd_reply_cache_shutdown(void)
 {
        struct svc_cacherep     *rp;
 
index 77dc9893b7bab462b65ebd751d9cc0c01273891f..8516137cdbb055ac87d1673c482126d2e670f488 100644 (file)
@@ -304,6 +304,9 @@ static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
        struct auth_domain *dom;
        struct knfsd_fh fh;
 
+       if (size == 0)
+               return -EINVAL;
+
        if (buf[size-1] != '\n')
                return -EINVAL;
        buf[size-1] = 0;
@@ -503,7 +506,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)
                int len = 0;
                lock_kernel();
                if (nfsd_serv)
-                       len = svc_sock_names(buf, nfsd_serv, NULL);
+                       len = svc_xprt_names(nfsd_serv, buf, 0);
                unlock_kernel();
                return len;
        }
@@ -540,7 +543,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)
                }
                return err < 0 ? err : 0;
        }
-       if (buf[0] == '-') {
+       if (buf[0] == '-' && isdigit(buf[1])) {
                char *toclose = kstrdup(buf+1, GFP_KERNEL);
                int len = 0;
                if (!toclose)
@@ -554,6 +557,53 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)
                kfree(toclose);
                return len;
        }
+       /*
+        * Add a transport listener by writing it's transport name
+        */
+       if (isalpha(buf[0])) {
+               int err;
+               char transport[16];
+               int port;
+               if (sscanf(buf, "%15s %4d", transport, &port) == 2) {
+                       err = nfsd_create_serv();
+                       if (!err) {
+                               err = svc_create_xprt(nfsd_serv,
+                                                     transport, port,
+                                                     SVC_SOCK_ANONYMOUS);
+                               if (err == -ENOENT)
+                                       /* Give a reasonable perror msg for
+                                        * bad transport string */
+                                       err = -EPROTONOSUPPORT;
+                       }
+                       return err < 0 ? err : 0;
+               }
+       }
+       /*
+        * Remove a transport by writing it's transport name and port number
+        */
+       if (buf[0] == '-' && isalpha(buf[1])) {
+               struct svc_xprt *xprt;
+               int err = -EINVAL;
+               char transport[16];
+               int port;
+               if (sscanf(&buf[1], "%15s %4d", transport, &port) == 2) {
+                       if (port == 0)
+                               return -EINVAL;
+                       lock_kernel();
+                       if (nfsd_serv) {
+                               xprt = svc_find_xprt(nfsd_serv, transport,
+                                                    AF_UNSPEC, port);
+                               if (xprt) {
+                                       svc_close_xprt(xprt);
+                                       svc_xprt_put(xprt);
+                                       err = 0;
+                               } else
+                                       err = -ENOTCONN;
+                       }
+                       unlock_kernel();
+                       return err < 0 ? err : 0;
+               }
+       }
        return -EINVAL;
 }
 
@@ -616,7 +666,7 @@ static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
        char *recdir;
        int len, status;
 
-       if (size > PATH_MAX || buf[size-1] != '\n')
+       if (size == 0 || size > PATH_MAX || buf[size-1] != '\n')
                return -EINVAL;
        buf[size-1] = 0;
 
@@ -674,6 +724,27 @@ static struct file_system_type nfsd_fs_type = {
        .kill_sb        = kill_litter_super,
 };
 
+#ifdef CONFIG_PROC_FS
+static int create_proc_exports_entry(void)
+{
+       struct proc_dir_entry *entry;
+
+       entry = proc_mkdir("fs/nfs", NULL);
+       if (!entry)
+               return -ENOMEM;
+       entry = create_proc_entry("fs/nfs/exports", 0, NULL);
+       if (!entry)
+               return -ENOMEM;
+       entry->proc_fops =  &exports_operations;
+       return 0;
+}
+#else /* CONFIG_PROC_FS */
+static int create_proc_exports_entry(void)
+{
+       return 0;
+}
+#endif
+
 static int __init init_nfsd(void)
 {
        int retval;
@@ -683,32 +754,43 @@ static int __init init_nfsd(void)
        if (retval)
                return retval;
        nfsd_stat_init();       /* Statistics */
-       nfsd_cache_init();      /* RPC reply cache */
-       nfsd_export_init();     /* Exports table */
+       retval = nfsd_reply_cache_init();
+       if (retval)
+               goto out_free_stat;
+       retval = nfsd_export_init();
+       if (retval)
+               goto out_free_cache;
        nfsd_lockd_init();      /* lockd->nfsd callbacks */
-       nfsd_idmap_init();      /* Name to ID mapping */
-       if (proc_mkdir("fs/nfs", NULL)) {
-               struct proc_dir_entry *entry;
-               entry = create_proc_entry("fs/nfs/exports", 0, NULL);
-               if (entry)
-                       entry->proc_fops =  &exports_operations;
-       }
+       retval = nfsd_idmap_init();
+       if (retval)
+               goto out_free_lockd;
+       retval = create_proc_exports_entry();
+       if (retval)
+               goto out_free_idmap;
        retval = register_filesystem(&nfsd_fs_type);
-       if (retval) {
-               nfsd_export_shutdown();
-               nfsd_cache_shutdown();
-               remove_proc_entry("fs/nfs/exports", NULL);
-               remove_proc_entry("fs/nfs", NULL);
-               nfsd_stat_shutdown();
-               nfsd_lockd_shutdown();
-       }
+       if (retval)
+               goto out_free_all;
+       return 0;
+out_free_all:
+       remove_proc_entry("fs/nfs/exports", NULL);
+       remove_proc_entry("fs/nfs", NULL);
+out_free_idmap:
+       nfsd_idmap_shutdown();
+out_free_lockd:
+       nfsd_lockd_shutdown();
+       nfsd_export_shutdown();
+out_free_cache:
+       nfsd_reply_cache_shutdown();
+out_free_stat:
+       nfsd_stat_shutdown();
+       nfsd4_free_slabs();
        return retval;
 }
 
 static void __exit exit_nfsd(void)
 {
        nfsd_export_shutdown();
-       nfsd_cache_shutdown();
+       nfsd_reply_cache_shutdown();
        remove_proc_entry("fs/nfs/exports", NULL);
        remove_proc_entry("fs/nfs", NULL);
        nfsd_stat_shutdown();
index 468f17a784416e96e11081d90230a8e6df4eec90..8fbd2dc08a92159a853ef748db561522ec0a0480 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/sunrpc/svc.h>
 #include <linux/sunrpc/svcauth_gss.h>
 #include <linux/nfsd/nfsd.h>
+#include "auth.h"
 
 #define NFSDDBG_FACILITY               NFSDDBG_FH
 
index 1190aeaa92be2e4563c759d04fe96bbc46a0b393..9647b0f7bc0c0d52610bf1419c9bafcd466b57dc 100644 (file)
@@ -155,8 +155,8 @@ static int killsig; /* signal that was used to kill last nfsd */
 static void nfsd_last_thread(struct svc_serv *serv)
 {
        /* When last nfsd thread exits we need to do some clean-up */
-       struct svc_sock *svsk;
-       list_for_each_entry(svsk, &serv->sv_permsocks, sk_list)
+       struct svc_xprt *xprt;
+       list_for_each_entry(xprt, &serv->sv_permsocks, xpt_list)
                lockd_down();
        nfsd_serv = NULL;
        nfsd_racache_shutdown();
@@ -236,7 +236,7 @@ static int nfsd_init_socks(int port)
 
        error = lockd_up(IPPROTO_UDP);
        if (error >= 0) {
-               error = svc_makesock(nfsd_serv, IPPROTO_UDP, port,
+               error = svc_create_xprt(nfsd_serv, "udp", port,
                                        SVC_SOCK_DEFAULTS);
                if (error < 0)
                        lockd_down();
@@ -247,7 +247,7 @@ static int nfsd_init_socks(int port)
 #ifdef CONFIG_NFSD_TCP
        error = lockd_up(IPPROTO_TCP);
        if (error >= 0) {
-               error = svc_makesock(nfsd_serv, IPPROTO_TCP, port,
+               error = svc_create_xprt(nfsd_serv, "tcp", port,
                                        SVC_SOCK_DEFAULTS);
                if (error < 0)
                        lockd_down();
index b86e3658a0af10ebce825e260ee1fc5fd879f367..61ad61743d9403524242e564523b4f3945aa25e3 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/nfsd/nfsd.h>
 #include <linux/nfsd/xdr.h>
 #include <linux/mm.h>
+#include "auth.h"
 
 #define NFSDDBG_FACILITY               NFSDDBG_XDR
 
@@ -62,10 +63,10 @@ encode_fh(__be32 *p, struct svc_fh *fhp)
  * no slashes or null bytes.
  */
 static __be32 *
-decode_filename(__be32 *p, char **namp, int *lenp)
+decode_filename(__be32 *p, char **namp, unsigned int *lenp)
 {
        char            *name;
-       int             i;
+       unsigned int    i;
 
        if ((p = xdr_decode_string_inplace(p, namp, lenp, NFS_MAXNAMLEN)) != NULL) {
                for (i = 0, name = *namp; i < *lenp; i++, name++) {
@@ -78,10 +79,10 @@ decode_filename(__be32 *p, char **namp, int *lenp)
 }
 
 static __be32 *
-decode_pathname(__be32 *p, char **namp, int *lenp)
+decode_pathname(__be32 *p, char **namp, unsigned int *lenp)
 {
        char            *name;
-       int             i;
+       unsigned int    i;
 
        if ((p = xdr_decode_string_inplace(p, namp, lenp, NFS_MAXPATHLEN)) != NULL) {
                for (i = 0, name = *namp; i < *lenp; i++, name++) {
index d0199189924cee7d5ea49aafd52dcc81fab21df2..cc75e4fcd02baf2a989573ac5aac2e16dad8df17 100644 (file)
@@ -132,7 +132,7 @@ out:
 
 __be32
 nfsd_lookup_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp,
-                  const char *name, int len,
+                  const char *name, unsigned int len,
                   struct svc_export **exp_ret, struct dentry **dentry_ret)
 {
        struct svc_export       *exp;
@@ -226,7 +226,7 @@ out_nfserr:
  */
 __be32
 nfsd_lookup(struct svc_rqst *rqstp, struct svc_fh *fhp, const char *name,
-                                       int len, struct svc_fh *resfh)
+                               unsigned int len, struct svc_fh *resfh)
 {
        struct svc_export       *exp;
        struct dentry           *dentry;
@@ -1151,6 +1151,26 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
 }
 #endif /* CONFIG_NFSD_V3 */
 
+__be32
+nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *resfhp,
+                       struct iattr *iap)
+{
+       /*
+        * Mode has already been set earlier in create:
+        */
+       iap->ia_valid &= ~ATTR_MODE;
+       /*
+        * Setting uid/gid works only for root.  Irix appears to
+        * send along the gid on create when it tries to implement
+        * setgid directories via NFS:
+        */
+       if (current->fsuid != 0)
+               iap->ia_valid &= ~(ATTR_UID|ATTR_GID);
+       if (iap->ia_valid)
+               return nfsd_setattr(rqstp, resfhp, iap, 0, (time_t)0);
+       return 0;
+}
+
 /*
  * Create a file (regular, directory, device, fifo); UNIX sockets 
  * not yet implemented.
@@ -1167,6 +1187,7 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
        struct dentry   *dentry, *dchild = NULL;
        struct inode    *dirp;
        __be32          err;
+       __be32          err2;
        int             host_err;
 
        err = nfserr_perm;
@@ -1257,16 +1278,9 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
        }
 
 
-       /* Set file attributes. Mode has already been set and
-        * setting uid/gid works only for root. Irix appears to
-        * send along the gid when it tries to implement setgid
-        * directories via NFS.
-        */
-       if ((iap->ia_valid &= ~(ATTR_UID|ATTR_GID|ATTR_MODE)) != 0) {
-               __be32 err2 = nfsd_setattr(rqstp, resfhp, iap, 0, (time_t)0);
-               if (err2)
-                       err = err2;
-       }
+       err2 = nfsd_create_setattr(rqstp, resfhp, iap);
+       if (err2)
+               err = err2;
        /*
         * Update the file handle to get the new inode info.
         */
@@ -1295,6 +1309,7 @@ nfsd_create_v3(struct svc_rqst *rqstp, struct svc_fh *fhp,
        struct dentry   *dentry, *dchild = NULL;
        struct inode    *dirp;
        __be32          err;
+       __be32          err2;
        int             host_err;
        __u32           v_mtime=0, v_atime=0;
 
@@ -1399,16 +1414,10 @@ nfsd_create_v3(struct svc_rqst *rqstp, struct svc_fh *fhp,
                iap->ia_atime.tv_nsec = 0;
        }
 
-       /* Set file attributes.
-        * Irix appears to send along the gid when it tries to
-        * implement setgid directories via NFS. Clear out all that cruft.
-        */
  set_attr:
-       if ((iap->ia_valid &= ~(ATTR_UID|ATTR_GID|ATTR_MODE)) != 0) {
-               __be32 err2 = nfsd_setattr(rqstp, resfhp, iap, 0, (time_t)0);
-               if (err2)
-                       err = err2;
-       }
+       err2 = nfsd_create_setattr(rqstp, resfhp, iap);
+       if (err2)
+               err = err2;
 
        /*
         * Update the filehandle to get the new inode info.
index ad87cb01299b6d8febb7ae670fddb36ce33cc666..00e9ccde8e42b787724bee44aedc432df37e7875 100644 (file)
@@ -87,13 +87,17 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
                /* Check for the current buffer head overflowing. */
                if (unlikely(file_ofs + bh->b_size > init_size)) {
                        int ofs;
+                       void *kaddr;
 
                        ofs = 0;
                        if (file_ofs < init_size)
                                ofs = init_size - file_ofs;
                        local_irq_save(flags);
-                       zero_user_page(page, bh_offset(bh) + ofs,
-                                        bh->b_size - ofs, KM_BIO_SRC_IRQ);
+                       kaddr = kmap_atomic(page, KM_BIO_SRC_IRQ);
+                       memset(kaddr + bh_offset(bh) + ofs, 0,
+                                       bh->b_size - ofs);
+                       flush_dcache_page(page);
+                       kunmap_atomic(kaddr, KM_BIO_SRC_IRQ);
                        local_irq_restore(flags);
                }
        } else {
@@ -334,7 +338,7 @@ handle_hole:
                bh->b_blocknr = -1UL;
                clear_buffer_mapped(bh);
 handle_zblock:
-               zero_user_page(page, i * blocksize, blocksize, KM_USER0);
+               zero_user(page, i * blocksize, blocksize);
                if (likely(!err))
                        set_buffer_uptodate(bh);
        } while (i++, iblock++, (bh = bh->b_this_page) != head);
@@ -410,7 +414,7 @@ retry_readpage:
        /* Is the page fully outside i_size? (truncate in progress) */
        if (unlikely(page->index >= (i_size + PAGE_CACHE_SIZE - 1) >>
                        PAGE_CACHE_SHIFT)) {
-               zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
+               zero_user(page, 0, PAGE_CACHE_SIZE);
                ntfs_debug("Read outside i_size - truncated?");
                goto done;
        }
@@ -459,7 +463,7 @@ retry_readpage:
         * ok to ignore the compressed flag here.
         */
        if (unlikely(page->index > 0)) {
-               zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
+               zero_user(page, 0, PAGE_CACHE_SIZE);
                goto done;
        }
        if (!NInoAttr(ni))
@@ -788,8 +792,7 @@ lock_retry_remap:
                if (err == -ENOENT || lcn == LCN_ENOENT) {
                        bh->b_blocknr = -1;
                        clear_buffer_dirty(bh);
-                       zero_user_page(page, bh_offset(bh), blocksize,
-                                       KM_USER0);
+                       zero_user(page, bh_offset(bh), blocksize);
                        set_buffer_uptodate(bh);
                        err = 0;
                        continue;
@@ -1414,8 +1417,7 @@ retry_writepage:
                if (page->index >= (i_size >> PAGE_CACHE_SHIFT)) {
                        /* The page straddles i_size. */
                        unsigned int ofs = i_size & ~PAGE_CACHE_MASK;
-                       zero_user_page(page, ofs, PAGE_CACHE_SIZE - ofs,
-                                       KM_USER0);
+                       zero_user_segment(page, ofs, PAGE_CACHE_SIZE);
                }
                /* Handle mst protected attributes. */
                if (NInoMstProtected(ni))
index d1619d05eb23bce83bea2d9f005e663625fa1f2e..33ff314cc5073cf9f88a3623db7129fd4ad4e772 100644 (file)
@@ -565,7 +565,7 @@ int ntfs_read_compressed_block(struct page *page)
        if (xpage >= max_page) {
                kfree(bhs);
                kfree(pages);
-               zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
+               zero_user(page, 0, PAGE_CACHE_SIZE);
                ntfs_debug("Compressed read outside i_size - truncated?");
                SetPageUptodate(page);
                unlock_page(page);
index 6cd08dfdc2ed17afcacb1985e2c444910f18e4dd..3c5550cd11d67b53a5d3ef6ff49dd6d4312f9d4c 100644 (file)
@@ -607,8 +607,8 @@ do_next_page:
                                        ntfs_submit_bh_for_read(bh);
                                        *wait_bh++ = bh;
                                } else {
-                                       zero_user_page(page, bh_offset(bh),
-                                                       blocksize, KM_USER0);
+                                       zero_user(page, bh_offset(bh),
+                                                       blocksize);
                                        set_buffer_uptodate(bh);
                                }
                        }
@@ -683,9 +683,8 @@ map_buffer_cached:
                                                ntfs_submit_bh_for_read(bh);
                                                *wait_bh++ = bh;
                                        } else {
-                                               zero_user_page(page,
-                                                       bh_offset(bh),
-                                                       blocksize, KM_USER0);
+                                               zero_user(page, bh_offset(bh),
+                                                               blocksize);
                                                set_buffer_uptodate(bh);
                                        }
                                }
@@ -703,8 +702,8 @@ map_buffer_cached:
                         */
                        if (bh_end <= pos || bh_pos >= end) {
                                if (!buffer_uptodate(bh)) {
-                                       zero_user_page(page, bh_offset(bh),
-                                                       blocksize, KM_USER0);
+                                       zero_user(page, bh_offset(bh),
+                                                       blocksize);
                                        set_buffer_uptodate(bh);
                                }
                                mark_buffer_dirty(bh);
@@ -743,8 +742,7 @@ map_buffer_cached:
                                if (!buffer_uptodate(bh))
                                        set_buffer_uptodate(bh);
                        } else if (!buffer_uptodate(bh)) {
-                               zero_user_page(page, bh_offset(bh), blocksize,
-                                               KM_USER0);
+                               zero_user(page, bh_offset(bh), blocksize);
                                set_buffer_uptodate(bh);
                        }
                        continue;
@@ -868,8 +866,8 @@ rl_not_mapped_enoent:
                                        if (!buffer_uptodate(bh))
                                                set_buffer_uptodate(bh);
                                } else if (!buffer_uptodate(bh)) {
-                                       zero_user_page(page, bh_offset(bh),
-                                                       blocksize, KM_USER0);
+                                       zero_user(page, bh_offset(bh),
+                                               blocksize);
                                        set_buffer_uptodate(bh);
                                }
                                continue;
@@ -1128,8 +1126,8 @@ rl_not_mapped_enoent:
 
                                if (likely(bh_pos < initialized_size))
                                        ofs = initialized_size - bh_pos;
-                               zero_user_page(page, bh_offset(bh) + ofs,
-                                               blocksize - ofs, KM_USER0);
+                               zero_user_segment(page, bh_offset(bh) + ofs,
+                                               blocksize);
                        }
                } else /* if (unlikely(!buffer_uptodate(bh))) */
                        err = -EIO;
@@ -1269,8 +1267,8 @@ rl_not_mapped_enoent:
                                if (PageUptodate(page))
                                        set_buffer_uptodate(bh);
                                else {
-                                       zero_user_page(page, bh_offset(bh),
-                                                       blocksize, KM_USER0);
+                                       zero_user(page, bh_offset(bh),
+                                                       blocksize);
                                        set_buffer_uptodate(bh);
                                }
                        }
@@ -1330,7 +1328,7 @@ err_out:
                len = PAGE_CACHE_SIZE;
                if (len > bytes)
                        len = bytes;
-               zero_user_page(*pages, 0, len, KM_USER0);
+               zero_user(*pages, 0, len);
        }
        goto out;
 }
@@ -1451,7 +1449,7 @@ err_out:
                len = PAGE_CACHE_SIZE;
                if (len > bytes)
                        len = bytes;
-               zero_user_page(*pages, 0, len, KM_USER0);
+               zero_user(*pages, 0, len);
        }
        goto out;
 }
index e38e402e410351c6a70ff9ae148f10133ee28177..cd0be3f5c3cd34a5d5209adafcf6ad518ff7da0b 100644 (file)
@@ -85,8 +85,7 @@ static inline void *ntfs_malloc_nofs_nofail(unsigned long size)
 
 static inline void ntfs_free(void *addr)
 {
-       if (likely(((unsigned long)addr < VMALLOC_START) ||
-                       ((unsigned long)addr >= VMALLOC_END ))) {
+       if (!is_vmalloc_addr(addr)) {
                kfree(addr);
                /* free_page((unsigned long)addr); */
                return;
index e6df06ac64059bb495a742f892530e1dd3212f3b..447206eb5c2e85fe1c0a4e1542f3a3083cac0982 100644 (file)
@@ -3338,7 +3338,7 @@ static int ocfs2_insert_path(struct inode *inode,
        if (insert->ins_split != SPLIT_NONE) {
                /*
                 * We could call ocfs2_insert_at_leaf() for some types
-                * of splits, but it's easier to just let one seperate
+                * of splits, but it's easier to just let one separate
                 * function sort it all out.
                 */
                ocfs2_split_record(inode, left_path, right_path,
@@ -5670,7 +5670,7 @@ static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle,
                mlog_errno(ret);
 
        if (zero)
-               zero_user_page(page, from, to - from, KM_USER0);
+               zero_user_segment(page, from, to);
 
        /*
         * Need to set the buffers we zero'd into uptodate
index bc7b4cbbe8eca6f418761b64d0ff8f24141242b0..82243127eebf6b81d80acd239609bdc1fd26ae43 100644 (file)
@@ -307,7 +307,7 @@ static int ocfs2_readpage(struct file *file, struct page *page)
         * XXX sys_readahead() seems to get that wrong?
         */
        if (start >= i_size_read(inode)) {
-               zero_user_page(page, 0, PAGE_SIZE, KM_USER0);
+               zero_user(page, 0, PAGE_SIZE);
                SetPageUptodate(page);
                ret = 0;
                goto out_alloc;
@@ -869,7 +869,7 @@ int ocfs2_map_page_blocks(struct page *page, u64 *p_blkno,
                if (block_start >= to)
                        break;
 
-               zero_user_page(page, block_start, bh->b_size, KM_USER0);
+               zero_user(page, block_start, bh->b_size);
                set_buffer_uptodate(bh);
                mark_buffer_dirty(bh);
 
@@ -1034,7 +1034,7 @@ static void ocfs2_zero_new_buffers(struct page *page, unsigned from, unsigned to
                                        start = max(from, block_start);
                                        end = min(to, block_end);
 
-                                       zero_user_page(page, start, end - start, KM_USER0);
+                                       zero_user_segment(page, start, end);
                                        set_buffer_uptodate(bh);
                                }
 
index 6b0107f21344734f583ea103b56cc10bee7d6b74..e280833ceb9aa76bd8404ded84b6047948b0ca9d 100644 (file)
@@ -1215,7 +1215,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
        down_write(&oi->ip_alloc_sem);
 
        /*
-        * Prepare for worst case allocation scenario of two seperate
+        * Prepare for worst case allocation scenario of two separate
         * extents.
         */
        if (alloc == 2)
index 0b499bccec5ae5be5771ddf22d10461a252bfc47..dfb313bda5dd618b95e431568bc818dcc34a1c3f 100644 (file)
@@ -77,7 +77,7 @@ struct ocfs1_disk_lock
 {
 /*00*/ __u32 curr_master;
        __u8 file_lock;
-       __u8 compat_pad[3];  /* Not in orignal definition.  Used to
+       __u8 compat_pad[3];  /* Not in original definition.  Used to
                                make the already existing alignment
                                explicit */
        __u64 last_write_time;
index 7e397e2c25dd219fd55e3f16c363488fb57223e6..72c198a004df46744c1c025e253763727ce635bb 100644 (file)
@@ -646,7 +646,7 @@ bail:
  * sync-data inodes."
  *
  * Note: OCFS2 already does this differently for metadata vs data
- * allocations, as those bitmaps are seperate and undo access is never
+ * allocations, as those bitmaps are separate and undo access is never
  * called on a metadata group descriptor.
  */
 static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
index a99acd8de3539ec56ecc9761a2bb37b66fcb7a93..cb5f0a3f1b035887acfafa9a0a5e4789dd9d8a33 100644 (file)
@@ -198,7 +198,7 @@ config LDM_DEBUG
 
 config SGI_PARTITION
        bool "SGI partition support" if PARTITION_ADVANCED
-       default y if (SGI_IP22 || SGI_IP27 || ((MACH_JAZZ || SNI_RM) && !CPU_LITTLE_ENDIAN))
+       default y if DEFAULT_SGI_PARTITION
        help
          Say Y here if you would like to be able to read the hard disk
          partition table format used by SGI machines.
index 89940f243fc235d2f2f8d9abf27e5b0f6862cd52..05ba692bc540ade3b63c5f5af72e1987556bd9fe 100644 (file)
@@ -83,6 +83,8 @@ void change_mnt_propagation(struct vfsmount *mnt, int type)
                mnt->mnt_master = NULL;
                if (type == MS_UNBINDABLE)
                        mnt->mnt_flags |= MNT_UNBINDABLE;
+               else
+                       mnt->mnt_flags &= ~MNT_UNBINDABLE;
        }
 }
 
index b380313092bd5e42173af45654e99b5a41aee908..6ba2746e451706fc59beee9319cb896187958f05 100644 (file)
@@ -281,14 +281,23 @@ static inline char *task_sig(struct task_struct *p, char *buffer)
        return buffer;
 }
 
+static char *render_cap_t(const char *header, kernel_cap_t *a, char *buffer)
+{
+       unsigned __capi;
+
+       buffer += sprintf(buffer, "%s", header);
+       CAP_FOR_EACH_U32(__capi) {
+               buffer += sprintf(buffer, "%08x",
+                                 a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
+       }
+       return buffer + sprintf(buffer, "\n");
+}
+
 static inline char *task_cap(struct task_struct *p, char *buffer)
 {
-    return buffer + sprintf(buffer, "CapInh:\t%016x\n"
-                           "CapPrm:\t%016x\n"
-                           "CapEff:\t%016x\n",
-                           cap_t(p->cap_inheritable),
-                           cap_t(p->cap_permitted),
-                           cap_t(p->cap_effective));
+       buffer = render_cap_t("CapInh:\t", &p->cap_inheritable, buffer);
+       buffer = render_cap_t("CapPrm:\t", &p->cap_permitted, buffer);
+       return render_cap_t("CapEff:\t", &p->cap_effective, buffer);
 }
 
 static inline char *task_context_switch_counts(struct task_struct *p,
index 33537487f5abe4dadb7c90068dfb961528bdaaaf..c59852b38787382a9399de7c69ae787ce22d9bf4 100644 (file)
  *     in /proc for a task before it execs a suid executable.
  */
 
-
-/* Worst case buffer size needed for holding an integer. */
-#define PROC_NUMBUF 13
-
 struct pid_entry {
        char *name;
        int len;
@@ -787,7 +783,7 @@ out_no_task:
 }
 #endif
 
-static loff_t mem_lseek(struct file * file, loff_t offset, int orig)
+loff_t mem_lseek(struct file *file, loff_t offset, int orig)
 {
        switch (orig) {
        case 0:
@@ -935,42 +931,6 @@ static const struct file_operations proc_oom_adjust_operations = {
        .write          = oom_adjust_write,
 };
 
-#ifdef CONFIG_MMU
-static ssize_t clear_refs_write(struct file *file, const char __user *buf,
-                               size_t count, loff_t *ppos)
-{
-       struct task_struct *task;
-       char buffer[PROC_NUMBUF], *end;
-       struct mm_struct *mm;
-
-       memset(buffer, 0, sizeof(buffer));
-       if (count > sizeof(buffer) - 1)
-               count = sizeof(buffer) - 1;
-       if (copy_from_user(buffer, buf, count))
-               return -EFAULT;
-       if (!simple_strtol(buffer, &end, 0))
-               return -EINVAL;
-       if (*end == '\n')
-               end++;
-       task = get_proc_task(file->f_path.dentry->d_inode);
-       if (!task)
-               return -ESRCH;
-       mm = get_task_mm(task);
-       if (mm) {
-               clear_refs_smap(mm);
-               mmput(mm);
-       }
-       put_task_struct(task);
-       if (end - buffer == 0)
-               return -EIO;
-       return end - buffer;
-}
-
-static struct file_operations proc_clear_refs_operations = {
-       .write          = clear_refs_write,
-};
-#endif
-
 #ifdef CONFIG_AUDITSYSCALL
 #define TMPBUFLEN 21
 static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
@@ -2289,9 +2249,10 @@ static const struct pid_entry tgid_base_stuff[] = {
        LNK("exe",        exe),
        REG("mounts",     S_IRUGO, mounts),
        REG("mountstats", S_IRUSR, mountstats),
-#ifdef CONFIG_MMU
+#ifdef CONFIG_PROC_PAGE_MONITOR
        REG("clear_refs", S_IWUSR, clear_refs),
        REG("smaps",      S_IRUGO, smaps),
+       REG("pagemap",    S_IRUSR, pagemap),
 #endif
 #ifdef CONFIG_SECURITY
        DIR("attr",       S_IRUGO|S_IXUGO, attr_dir),
@@ -2360,7 +2321,8 @@ static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid)
        name.len = snprintf(buf, sizeof(buf), "%d", pid);
        dentry = d_hash_and_lookup(mnt->mnt_root, &name);
        if (dentry) {
-               shrink_dcache_parent(dentry);
+               if (!(current->flags & PF_EXITING))
+                       shrink_dcache_parent(dentry);
                d_drop(dentry);
                dput(dentry);
        }
@@ -2617,9 +2579,10 @@ static const struct pid_entry tid_base_stuff[] = {
        LNK("root",      root),
        LNK("exe",       exe),
        REG("mounts",    S_IRUGO, mounts),
-#ifdef CONFIG_MMU
+#ifdef CONFIG_PROC_PAGE_MONITOR
        REG("clear_refs", S_IWUSR, clear_refs),
        REG("smaps",     S_IRUGO, smaps),
+       REG("pagemap",    S_IRUSR, pagemap),
 #endif
 #ifdef CONFIG_SECURITY
        DIR("attr",      S_IRUGO|S_IXUGO, attr_dir),
index 05b3e9006262c49145f640e482062bbd0b6d14ad..7d57e80699241fade80e341cd47ca057444a6f69 100644 (file)
@@ -52,15 +52,13 @@ extern int proc_tid_stat(struct task_struct *,  char *);
 extern int proc_tgid_stat(struct task_struct *, char *);
 extern int proc_pid_status(struct task_struct *, char *);
 extern int proc_pid_statm(struct task_struct *, char *);
+extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
 
 extern const struct file_operations proc_maps_operations;
 extern const struct file_operations proc_numa_maps_operations;
 extern const struct file_operations proc_smaps_operations;
-
-extern const struct file_operations proc_maps_operations;
-extern const struct file_operations proc_numa_maps_operations;
-extern const struct file_operations proc_smaps_operations;
-
+extern const struct file_operations proc_clear_refs_operations;
+extern const struct file_operations proc_pagemap_operations;
 
 void free_proc_entry(struct proc_dir_entry *de);
 
index 1be73082edd388bd443f0be5c559cdf756eccbbb..7dd26e18cbfd6f4941f9744d47381ada5c4bfcfe 100644 (file)
@@ -325,7 +325,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
                if (m == NULL) {
                        if (clear_user(buffer, tsz))
                                return -EFAULT;
-               } else if ((start >= VMALLOC_START) && (start < VMALLOC_END)) {
+               } else if (is_vmalloc_addr((void *)start)) {
                        char * elf_buf;
                        struct vm_struct *m;
                        unsigned long curstart = start;
index 3462bfde89f68224a4ec48629e26c81feee0e44b..2686592dbcb2b01b29108da7587361afce9fa6c3 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/mm.h>
 #include <linux/mmzone.h>
 #include <linux/pagemap.h>
+#include <linux/interrupt.h>
 #include <linux/swap.h>
 #include <linux/slab.h>
 #include <linux/smp.h>
@@ -46,6 +47,7 @@
 #include <linux/vmalloc.h>
 #include <linux/crash_dump.h>
 #include <linux/pid_namespace.h>
+#include <linux/bootmem.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 #include <asm/io.h>
@@ -63,7 +65,6 @@
  */
 extern int get_hardware_list(char *);
 extern int get_stram_list(char *);
-extern int get_filesystem_list(char *);
 extern int get_exec_domain_list(char *);
 extern int get_dma_list(char *);
 
@@ -83,10 +84,15 @@ static int loadavg_read_proc(char *page, char **start, off_t off,
 {
        int a, b, c;
        int len;
+       unsigned long seq;
+
+       do {
+               seq = read_seqbegin(&xtime_lock);
+               a = avenrun[0] + (FIXED_1/200);
+               b = avenrun[1] + (FIXED_1/200);
+               c = avenrun[2] + (FIXED_1/200);
+       } while (read_seqretry(&xtime_lock, seq));
 
-       a = avenrun[0] + (FIXED_1/200);
-       b = avenrun[1] + (FIXED_1/200);
-       c = avenrun[2] + (FIXED_1/200);
        len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
                LOAD_INT(a), LOAD_FRAC(a),
                LOAD_INT(b), LOAD_FRAC(b),
@@ -598,7 +604,6 @@ static void int_seq_stop(struct seq_file *f, void *v)
 }
 
 
-extern int show_interrupts(struct seq_file *f, void *v); /* In arch code */
 static struct seq_operations int_seq_ops = {
        .start = int_seq_start,
        .next  = int_seq_next,
@@ -675,6 +680,137 @@ static const struct file_operations proc_sysrq_trigger_operations = {
 };
 #endif
 
+#ifdef CONFIG_PROC_PAGE_MONITOR
+#define KPMSIZE sizeof(u64)
+#define KPMMASK (KPMSIZE - 1)
+/* /proc/kpagecount - an array exposing page counts
+ *
+ * Each entry is a u64 representing the corresponding
+ * physical page count.
+ */
+static ssize_t kpagecount_read(struct file *file, char __user *buf,
+                            size_t count, loff_t *ppos)
+{
+       u64 __user *out = (u64 __user *)buf;
+       struct page *ppage;
+       unsigned long src = *ppos;
+       unsigned long pfn;
+       ssize_t ret = 0;
+       u64 pcount;
+
+       pfn = src / KPMSIZE;
+       count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
+       if (src & KPMMASK || count & KPMMASK)
+               return -EIO;
+
+       while (count > 0) {
+               ppage = NULL;
+               if (pfn_valid(pfn))
+                       ppage = pfn_to_page(pfn);
+               pfn++;
+               if (!ppage)
+                       pcount = 0;
+               else
+                       pcount = atomic_read(&ppage->_count);
+
+               if (put_user(pcount, out++)) {
+                       ret = -EFAULT;
+                       break;
+               }
+
+               count -= KPMSIZE;
+       }
+
+       *ppos += (char __user *)out - buf;
+       if (!ret)
+               ret = (char __user *)out - buf;
+       return ret;
+}
+
+static struct file_operations proc_kpagecount_operations = {
+       .llseek = mem_lseek,
+       .read = kpagecount_read,
+};
+
+/* /proc/kpageflags - an array exposing page flags
+ *
+ * Each entry is a u64 representing the corresponding
+ * physical page flags.
+ */
+
+/* These macros are used to decouple internal flags from exported ones */
+
+#define KPF_LOCKED     0
+#define KPF_ERROR      1
+#define KPF_REFERENCED 2
+#define KPF_UPTODATE   3
+#define KPF_DIRTY      4
+#define KPF_LRU        5
+#define KPF_ACTIVE     6
+#define KPF_SLAB       7
+#define KPF_WRITEBACK  8
+#define KPF_RECLAIM    9
+#define KPF_BUDDY     10
+
+#define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
+
+static ssize_t kpageflags_read(struct file *file, char __user *buf,
+                            size_t count, loff_t *ppos)
+{
+       u64 __user *out = (u64 __user *)buf;
+       struct page *ppage;
+       unsigned long src = *ppos;
+       unsigned long pfn;
+       ssize_t ret = 0;
+       u64 kflags, uflags;
+
+       pfn = src / KPMSIZE;
+       count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
+       if (src & KPMMASK || count & KPMMASK)
+               return -EIO;
+
+       while (count > 0) {
+               ppage = NULL;
+               if (pfn_valid(pfn))
+                       ppage = pfn_to_page(pfn);
+               pfn++;
+               if (!ppage)
+                       kflags = 0;
+               else
+                       kflags = ppage->flags;
+
+               uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
+                       kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
+                       kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
+                       kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
+                       kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
+                       kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
+                       kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
+                       kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
+                       kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
+                       kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
+                       kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
+
+               if (put_user(uflags, out++)) {
+                       ret = -EFAULT;
+                       break;
+               }
+
+               count -= KPMSIZE;
+       }
+
+       *ppos += (char __user *)out - buf;
+       if (!ret)
+               ret = (char __user *)out - buf;
+       return ret;
+}
+
+static struct file_operations proc_kpageflags_operations = {
+       .llseek = mem_lseek,
+       .read = kpageflags_read,
+};
+#endif /* CONFIG_PROC_PAGE_MONITOR */
+
 struct proc_dir_entry *proc_root_kcore;
 
 void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
@@ -755,6 +891,10 @@ void __init proc_misc_init(void)
                                (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
        }
 #endif
+#ifdef CONFIG_PROC_PAGE_MONITOR
+       create_seq_entry("kpagecount", S_IRUSR, &proc_kpagecount_operations);
+       create_seq_entry("kpageflags", S_IRUSR, &proc_kpageflags_operations);
+#endif
 #ifdef CONFIG_PROC_VMCORE
        proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
        if (proc_vmcore)
index 8043a3eab52ce49f14f0b23f863b8fb77c6916ba..38338ed98cc6df167febbe2fc962f55a700bfb19 100644 (file)
@@ -5,7 +5,10 @@
 #include <linux/highmem.h>
 #include <linux/ptrace.h>
 #include <linux/pagemap.h>
+#include <linux/ptrace.h>
 #include <linux/mempolicy.h>
+#include <linux/swap.h>
+#include <linux/swapops.h>
 
 #include <asm/elf.h>
 #include <asm/uaccess.h>
@@ -114,24 +117,124 @@ static void pad_len_spaces(struct seq_file *m, int len)
        seq_printf(m, "%*c", len, ' ');
 }
 
-struct mem_size_stats
+static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
 {
-       unsigned long resident;
-       unsigned long shared_clean;
-       unsigned long shared_dirty;
-       unsigned long private_clean;
-       unsigned long private_dirty;
-       unsigned long referenced;
-};
+       if (vma && vma != priv->tail_vma) {
+               struct mm_struct *mm = vma->vm_mm;
+               up_read(&mm->mmap_sem);
+               mmput(mm);
+       }
+}
 
-struct pmd_walker {
-       struct vm_area_struct *vma;
-       void *private;
-       void (*action)(struct vm_area_struct *, pmd_t *, unsigned long,
-                      unsigned long, void *);
-};
+static void *m_start(struct seq_file *m, loff_t *pos)
+{
+       struct proc_maps_private *priv = m->private;
+       unsigned long last_addr = m->version;
+       struct mm_struct *mm;
+       struct vm_area_struct *vma, *tail_vma = NULL;
+       loff_t l = *pos;
+
+       /* Clear the per syscall fields in priv */
+       priv->task = NULL;
+       priv->tail_vma = NULL;
+
+       /*
+        * We remember last_addr rather than next_addr to hit with
+        * mmap_cache most of the time. We have zero last_addr at
+        * the beginning and also after lseek. We will have -1 last_addr
+        * after the end of the vmas.
+        */
+
+       if (last_addr == -1UL)
+               return NULL;
+
+       priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
+       if (!priv->task)
+               return NULL;
+
+       mm = mm_for_maps(priv->task);
+       if (!mm)
+               return NULL;
+
+       tail_vma = get_gate_vma(priv->task);
+       priv->tail_vma = tail_vma;
+
+       /* Start with last addr hint */
+       vma = find_vma(mm, last_addr);
+       if (last_addr && vma) {
+               vma = vma->vm_next;
+               goto out;
+       }
+
+       /*
+        * Check the vma index is within the range and do
+        * sequential scan until m_index.
+        */
+       vma = NULL;
+       if ((unsigned long)l < mm->map_count) {
+               vma = mm->mmap;
+               while (l-- && vma)
+                       vma = vma->vm_next;
+               goto out;
+       }
+
+       if (l != mm->map_count)
+               tail_vma = NULL; /* After gate vma */
+
+out:
+       if (vma)
+               return vma;
+
+       /* End of vmas has been reached */
+       m->version = (tail_vma != NULL)? 0: -1UL;
+       up_read(&mm->mmap_sem);
+       mmput(mm);
+       return tail_vma;
+}
 
-static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats *mss)
+static void *m_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       struct proc_maps_private *priv = m->private;
+       struct vm_area_struct *vma = v;
+       struct vm_area_struct *tail_vma = priv->tail_vma;
+
+       (*pos)++;
+       if (vma && (vma != tail_vma) && vma->vm_next)
+               return vma->vm_next;
+       vma_stop(priv, vma);
+       return (vma != tail_vma)? tail_vma: NULL;
+}
+
+static void m_stop(struct seq_file *m, void *v)
+{
+       struct proc_maps_private *priv = m->private;
+       struct vm_area_struct *vma = v;
+
+       vma_stop(priv, vma);
+       if (priv->task)
+               put_task_struct(priv->task);
+}
+
+static int do_maps_open(struct inode *inode, struct file *file,
+                       struct seq_operations *ops)
+{
+       struct proc_maps_private *priv;
+       int ret = -ENOMEM;
+       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+       if (priv) {
+               priv->pid = proc_pid(inode);
+               ret = seq_open(file, ops);
+               if (!ret) {
+                       struct seq_file *m = file->private_data;
+                       m->private = priv;
+               } else {
+                       kfree(priv);
+               }
+       }
+       return ret;
+}
+
+static int show_map(struct seq_file *m, void *v)
 {
        struct proc_maps_private *priv = m->private;
        struct task_struct *task = priv->task;
@@ -191,41 +294,71 @@ static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats
        }
        seq_putc(m, '\n');
 
-       if (mss)
-               seq_printf(m,
-                          "Size:           %8lu kB\n"
-                          "Rss:            %8lu kB\n"
-                          "Shared_Clean:   %8lu kB\n"
-                          "Shared_Dirty:   %8lu kB\n"
-                          "Private_Clean:  %8lu kB\n"
-                          "Private_Dirty:  %8lu kB\n"
-                          "Referenced:     %8lu kB\n",
-                          (vma->vm_end - vma->vm_start) >> 10,
-                          mss->resident >> 10,
-                          mss->shared_clean  >> 10,
-                          mss->shared_dirty  >> 10,
-                          mss->private_clean >> 10,
-                          mss->private_dirty >> 10,
-                          mss->referenced >> 10);
-
        if (m->count < m->size)  /* vma is copied successfully */
                m->version = (vma != get_gate_vma(task))? vma->vm_start: 0;
        return 0;
 }
 
-static int show_map(struct seq_file *m, void *v)
+static struct seq_operations proc_pid_maps_op = {
+       .start  = m_start,
+       .next   = m_next,
+       .stop   = m_stop,
+       .show   = show_map
+};
+
+static int maps_open(struct inode *inode, struct file *file)
 {
-       return show_map_internal(m, v, NULL);
+       return do_maps_open(inode, file, &proc_pid_maps_op);
 }
 
-static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
-                           unsigned long addr, unsigned long end,
-                           void *private)
+const struct file_operations proc_maps_operations = {
+       .open           = maps_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release_private,
+};
+
+/*
+ * Proportional Set Size(PSS): my share of RSS.
+ *
+ * PSS of a process is the count of pages it has in memory, where each
+ * page is divided by the number of processes sharing it.  So if a
+ * process has 1000 pages all to itself, and 1000 shared with one other
+ * process, its PSS will be 1500.
+ *
+ * To keep (accumulated) division errors low, we adopt a 64bit
+ * fixed-point pss counter to minimize division errors. So (pss >>
+ * PSS_SHIFT) would be the real byte count.
+ *
+ * A shift of 12 before division means (assuming 4K page size):
+ *     - 1M 3-user-pages add up to 8KB errors;
+ *     - supports mapcount up to 2^24, or 16M;
+ *     - supports PSS up to 2^52 bytes, or 4PB.
+ */
+#define PSS_SHIFT 12
+
+#ifdef CONFIG_PROC_PAGE_MONITOR
+struct mem_size_stats
+{
+       struct vm_area_struct *vma;
+       unsigned long resident;
+       unsigned long shared_clean;
+       unsigned long shared_dirty;
+       unsigned long private_clean;
+       unsigned long private_dirty;
+       unsigned long referenced;
+       u64 pss;
+};
+
+static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
+                          void *private)
 {
        struct mem_size_stats *mss = private;
+       struct vm_area_struct *vma = mss->vma;
        pte_t *pte, ptent;
        spinlock_t *ptl;
        struct page *page;
+       int mapcount;
 
        pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
        for (; addr != end; pte++, addr += PAGE_SIZE) {
@@ -242,26 +375,88 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
                /* Accumulate the size in pages that have been accessed. */
                if (pte_young(ptent) || PageReferenced(page))
                        mss->referenced += PAGE_SIZE;
-               if (page_mapcount(page) >= 2) {
+               mapcount = page_mapcount(page);
+               if (mapcount >= 2) {
                        if (pte_dirty(ptent))
                                mss->shared_dirty += PAGE_SIZE;
                        else
                                mss->shared_clean += PAGE_SIZE;
+                       mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
                } else {
                        if (pte_dirty(ptent))
                                mss->private_dirty += PAGE_SIZE;
                        else
                                mss->private_clean += PAGE_SIZE;
+                       mss->pss += (PAGE_SIZE << PSS_SHIFT);
                }
        }
        pte_unmap_unlock(pte - 1, ptl);
        cond_resched();
+       return 0;
 }
 
-static void clear_refs_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
-                                unsigned long addr, unsigned long end,
-                                void *private)
+static struct mm_walk smaps_walk = { .pmd_entry = smaps_pte_range };
+
+static int show_smap(struct seq_file *m, void *v)
 {
+       struct vm_area_struct *vma = v;
+       struct mem_size_stats mss;
+       int ret;
+
+       memset(&mss, 0, sizeof mss);
+       mss.vma = vma;
+       if (vma->vm_mm && !is_vm_hugetlb_page(vma))
+               walk_page_range(vma->vm_mm, vma->vm_start, vma->vm_end,
+                               &smaps_walk, &mss);
+
+       ret = show_map(m, v);
+       if (ret)
+               return ret;
+
+       seq_printf(m,
+                  "Size:           %8lu kB\n"
+                  "Rss:            %8lu kB\n"
+                  "Pss:            %8lu kB\n"
+                  "Shared_Clean:   %8lu kB\n"
+                  "Shared_Dirty:   %8lu kB\n"
+                  "Private_Clean:  %8lu kB\n"
+                  "Private_Dirty:  %8lu kB\n"
+                  "Referenced:     %8lu kB\n",
+                  (vma->vm_end - vma->vm_start) >> 10,
+                  mss.resident >> 10,
+                  (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
+                  mss.shared_clean  >> 10,
+                  mss.shared_dirty  >> 10,
+                  mss.private_clean >> 10,
+                  mss.private_dirty >> 10,
+                  mss.referenced >> 10);
+
+       return ret;
+}
+
+static struct seq_operations proc_pid_smaps_op = {
+       .start  = m_start,
+       .next   = m_next,
+       .stop   = m_stop,
+       .show   = show_smap
+};
+
+static int smaps_open(struct inode *inode, struct file *file)
+{
+       return do_maps_open(inode, file, &proc_pid_smaps_op);
+}
+
+const struct file_operations proc_smaps_operations = {
+       .open           = smaps_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release_private,
+};
+
+static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
+                               unsigned long end, void *private)
+{
+       struct vm_area_struct *vma = private;
        pte_t *pte, ptent;
        spinlock_t *ptl;
        struct page *page;
@@ -282,235 +477,248 @@ static void clear_refs_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
        }
        pte_unmap_unlock(pte - 1, ptl);
        cond_resched();
+       return 0;
 }
 
-static inline void walk_pmd_range(struct pmd_walker *walker, pud_t *pud,
-                                 unsigned long addr, unsigned long end)
+static struct mm_walk clear_refs_walk = { .pmd_entry = clear_refs_pte_range };
+
+static ssize_t clear_refs_write(struct file *file, const char __user *buf,
+                               size_t count, loff_t *ppos)
 {
-       pmd_t *pmd;
-       unsigned long next;
+       struct task_struct *task;
+       char buffer[PROC_NUMBUF], *end;
+       struct mm_struct *mm;
+       struct vm_area_struct *vma;
 
-       for (pmd = pmd_offset(pud, addr); addr != end;
-            pmd++, addr = next) {
-               next = pmd_addr_end(addr, end);
-               if (pmd_none_or_clear_bad(pmd))
-                       continue;
-               walker->action(walker->vma, pmd, addr, next, walker->private);
+       memset(buffer, 0, sizeof(buffer));
+       if (count > sizeof(buffer) - 1)
+               count = sizeof(buffer) - 1;
+       if (copy_from_user(buffer, buf, count))
+               return -EFAULT;
+       if (!simple_strtol(buffer, &end, 0))
+               return -EINVAL;
+       if (*end == '\n')
+               end++;
+       task = get_proc_task(file->f_path.dentry->d_inode);
+       if (!task)
+               return -ESRCH;
+       mm = get_task_mm(task);
+       if (mm) {
+               down_read(&mm->mmap_sem);
+               for (vma = mm->mmap; vma; vma = vma->vm_next)
+                       if (!is_vm_hugetlb_page(vma))
+                               walk_page_range(mm, vma->vm_start, vma->vm_end,
+                                               &clear_refs_walk, vma);
+               flush_tlb_mm(mm);
+               up_read(&mm->mmap_sem);
+               mmput(mm);
        }
+       put_task_struct(task);
+       if (end - buffer == 0)
+               return -EIO;
+       return end - buffer;
 }
 
-static inline void walk_pud_range(struct pmd_walker *walker, pgd_t *pgd,
-                                 unsigned long addr, unsigned long end)
-{
-       pud_t *pud;
-       unsigned long next;
+const struct file_operations proc_clear_refs_operations = {
+       .write          = clear_refs_write,
+};
 
-       for (pud = pud_offset(pgd, addr); addr != end;
-            pud++, addr = next) {
-               next = pud_addr_end(addr, end);
-               if (pud_none_or_clear_bad(pud))
-                       continue;
-               walk_pmd_range(walker, pud, addr, next);
+struct pagemapread {
+       char __user *out, *end;
+};
+
+#define PM_ENTRY_BYTES sizeof(u64)
+#define PM_RESERVED_BITS    3
+#define PM_RESERVED_OFFSET  (64 - PM_RESERVED_BITS)
+#define PM_RESERVED_MASK    (((1LL<<PM_RESERVED_BITS)-1) << PM_RESERVED_OFFSET)
+#define PM_SPECIAL(nr)      (((nr) << PM_RESERVED_OFFSET) | PM_RESERVED_MASK)
+#define PM_NOT_PRESENT      PM_SPECIAL(1LL)
+#define PM_SWAP             PM_SPECIAL(2LL)
+#define PM_END_OF_BUFFER    1
+
+static int add_to_pagemap(unsigned long addr, u64 pfn,
+                         struct pagemapread *pm)
+{
+       /*
+        * Make sure there's room in the buffer for an
+        * entire entry.  Otherwise, only copy part of
+        * the pfn.
+        */
+       if (pm->out + PM_ENTRY_BYTES >= pm->end) {
+               if (copy_to_user(pm->out, &pfn, pm->end - pm->out))
+                       return -EFAULT;
+               pm->out = pm->end;
+               return PM_END_OF_BUFFER;
        }
+
+       if (put_user(pfn, pm->out))
+               return -EFAULT;
+       pm->out += PM_ENTRY_BYTES;
+       return 0;
 }
 
-/*
- * walk_page_range - walk the page tables of a VMA with a callback
- * @vma - VMA to walk
- * @action - callback invoked for every bottom-level (PTE) page table
- * @private - private data passed to the callback function
- *
- * Recursively walk the page table for the memory area in a VMA, calling
- * a callback for every bottom-level (PTE) page table.
- */
-static inline void walk_page_range(struct vm_area_struct *vma,
-                                  void (*action)(struct vm_area_struct *,
-                                                 pmd_t *, unsigned long,
-                                                 unsigned long, void *),
-                                  void *private)
+static int pagemap_pte_hole(unsigned long start, unsigned long end,
+                               void *private)
 {
-       unsigned long addr = vma->vm_start;
-       unsigned long end = vma->vm_end;
-       struct pmd_walker walker = {
-               .vma            = vma,
-               .private        = private,
-               .action         = action,
-       };
-       pgd_t *pgd;
-       unsigned long next;
-
-       for (pgd = pgd_offset(vma->vm_mm, addr); addr != end;
-            pgd++, addr = next) {
-               next = pgd_addr_end(addr, end);
-               if (pgd_none_or_clear_bad(pgd))
-                       continue;
-               walk_pud_range(&walker, pgd, addr, next);
+       struct pagemapread *pm = private;
+       unsigned long addr;
+       int err = 0;
+       for (addr = start; addr < end; addr += PAGE_SIZE) {
+               err = add_to_pagemap(addr, PM_NOT_PRESENT, pm);
+               if (err)
+                       break;
        }
+       return err;
 }
 
-static int show_smap(struct seq_file *m, void *v)
+u64 swap_pte_to_pagemap_entry(pte_t pte)
 {
-       struct vm_area_struct *vma = v;
-       struct mem_size_stats mss;
-
-       memset(&mss, 0, sizeof mss);
-       if (vma->vm_mm && !is_vm_hugetlb_page(vma))
-               walk_page_range(vma, smaps_pte_range, &mss);
-       return show_map_internal(m, v, &mss);
+       swp_entry_t e = pte_to_swp_entry(pte);
+       return PM_SWAP | swp_type(e) | (swp_offset(e) << MAX_SWAPFILES_SHIFT);
 }
 
-void clear_refs_smap(struct mm_struct *mm)
+static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
+                            void *private)
 {
-       struct vm_area_struct *vma;
+       struct pagemapread *pm = private;
+       pte_t *pte;
+       int err = 0;
+
+       for (; addr != end; addr += PAGE_SIZE) {
+               u64 pfn = PM_NOT_PRESENT;
+               pte = pte_offset_map(pmd, addr);
+               if (is_swap_pte(*pte))
+                       pfn = swap_pte_to_pagemap_entry(*pte);
+               else if (pte_present(*pte))
+                       pfn = pte_pfn(*pte);
+               /* unmap so we're not in atomic when we copy to userspace */
+               pte_unmap(pte);
+               err = add_to_pagemap(addr, pfn, pm);
+               if (err)
+                       return err;
+       }
 
-       down_read(&mm->mmap_sem);
-       for (vma = mm->mmap; vma; vma = vma->vm_next)
-               if (vma->vm_mm && !is_vm_hugetlb_page(vma))
-                       walk_page_range(vma, clear_refs_pte_range, NULL);
-       flush_tlb_mm(mm);
-       up_read(&mm->mmap_sem);
+       cond_resched();
+
+       return err;
 }
 
-static void *m_start(struct seq_file *m, loff_t *pos)
+static struct mm_walk pagemap_walk = {
+       .pmd_entry = pagemap_pte_range,
+       .pte_hole = pagemap_pte_hole
+};
+
+/*
+ * /proc/pid/pagemap - an array mapping virtual pages to pfns
+ *
+ * For each page in the address space, this file contains one 64-bit
+ * entry representing the corresponding physical page frame number
+ * (PFN) if the page is present. If there is a swap entry for the
+ * physical page, then an encoding of the swap file number and the
+ * page's offset into the swap file are returned. If no page is
+ * present at all, PM_NOT_PRESENT is returned. This allows determining
+ * precisely which pages are mapped (or in swap) and comparing mapped
+ * pages between processes.
+ *
+ * Efficient users of this interface will use /proc/pid/maps to
+ * determine which areas of memory are actually mapped and llseek to
+ * skip over unmapped regions.
+ */
+static ssize_t pagemap_read(struct file *file, char __user *buf,
+                           size_t count, loff_t *ppos)
 {
-       struct proc_maps_private *priv = m->private;
-       unsigned long last_addr = m->version;
+       struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
+       struct page **pages, *page;
+       unsigned long uaddr, uend;
        struct mm_struct *mm;
-       struct vm_area_struct *vma, *tail_vma = NULL;
-       loff_t l = *pos;
-
-       /* Clear the per syscall fields in priv */
-       priv->task = NULL;
-       priv->tail_vma = NULL;
+       struct pagemapread pm;
+       int pagecount;
+       int ret = -ESRCH;
 
-       /*
-        * We remember last_addr rather than next_addr to hit with
-        * mmap_cache most of the time. We have zero last_addr at
-        * the beginning and also after lseek. We will have -1 last_addr
-        * after the end of the vmas.
-        */
+       if (!task)
+               goto out;
 
-       if (last_addr == -1UL)
-               return NULL;
+       ret = -EACCES;
+       if (!ptrace_may_attach(task))
+               goto out;
 
-       priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
-       if (!priv->task)
-               return NULL;
+       ret = -EINVAL;
+       /* file position must be aligned */
+       if (*ppos % PM_ENTRY_BYTES)
+               goto out;
 
-       mm = mm_for_maps(priv->task);
+       ret = 0;
+       mm = get_task_mm(task);
        if (!mm)
-               return NULL;
-
-       priv->tail_vma = tail_vma = get_gate_vma(priv->task);
-
-       /* Start with last addr hint */
-       if (last_addr && (vma = find_vma(mm, last_addr))) {
-               vma = vma->vm_next;
                goto out;
-       }
 
-       /*
-        * Check the vma index is within the range and do
-        * sequential scan until m_index.
-        */
-       vma = NULL;
-       if ((unsigned long)l < mm->map_count) {
-               vma = mm->mmap;
-               while (l-- && vma)
-                       vma = vma->vm_next;
-               goto out;
-       }
+       ret = -ENOMEM;
+       uaddr = (unsigned long)buf & PAGE_MASK;
+       uend = (unsigned long)(buf + count);
+       pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
+       pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
+       if (!pages)
+               goto out_task;
 
-       if (l != mm->map_count)
-               tail_vma = NULL; /* After gate vma */
+       down_read(&current->mm->mmap_sem);
+       ret = get_user_pages(current, current->mm, uaddr, pagecount,
+                            1, 0, pages, NULL);
+       up_read(&current->mm->mmap_sem);
 
-out:
-       if (vma)
-               return vma;
+       if (ret < 0)
+               goto out_free;
 
-       /* End of vmas has been reached */
-       m->version = (tail_vma != NULL)? 0: -1UL;
-       up_read(&mm->mmap_sem);
-       mmput(mm);
-       return tail_vma;
-}
+       pm.out = buf;
+       pm.end = buf + count;
 
-static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
-{
-       if (vma && vma != priv->tail_vma) {
-               struct mm_struct *mm = vma->vm_mm;
-               up_read(&mm->mmap_sem);
-               mmput(mm);
+       if (!ptrace_may_attach(task)) {
+               ret = -EIO;
+       } else {
+               unsigned long src = *ppos;
+               unsigned long svpfn = src / PM_ENTRY_BYTES;
+               unsigned long start_vaddr = svpfn << PAGE_SHIFT;
+               unsigned long end_vaddr = TASK_SIZE_OF(task);
+
+               /* watch out for wraparound */
+               if (svpfn > TASK_SIZE_OF(task) >> PAGE_SHIFT)
+                       start_vaddr = end_vaddr;
+
+               /*
+                * The odds are that this will stop walking way
+                * before end_vaddr, because the length of the
+                * user buffer is tracked in "pm", and the walk
+                * will stop when we hit the end of the buffer.
+                */
+               ret = walk_page_range(mm, start_vaddr, end_vaddr,
+                                       &pagemap_walk, &pm);
+               if (ret == PM_END_OF_BUFFER)
+                       ret = 0;
+               /* don't need mmap_sem for these, but this looks cleaner */
+               *ppos += pm.out - buf;
+               if (!ret)
+                       ret = pm.out - buf;
        }
-}
-
-static void *m_next(struct seq_file *m, void *v, loff_t *pos)
-{
-       struct proc_maps_private *priv = m->private;
-       struct vm_area_struct *vma = v;
-       struct vm_area_struct *tail_vma = priv->tail_vma;
-
-       (*pos)++;
-       if (vma && (vma != tail_vma) && vma->vm_next)
-               return vma->vm_next;
-       vma_stop(priv, vma);
-       return (vma != tail_vma)? tail_vma: NULL;
-}
-
-static void m_stop(struct seq_file *m, void *v)
-{
-       struct proc_maps_private *priv = m->private;
-       struct vm_area_struct *vma = v;
 
-       vma_stop(priv, vma);
-       if (priv->task)
-               put_task_struct(priv->task);
-}
-
-static struct seq_operations proc_pid_maps_op = {
-       .start  = m_start,
-       .next   = m_next,
-       .stop   = m_stop,
-       .show   = show_map
-};
-
-static struct seq_operations proc_pid_smaps_op = {
-       .start  = m_start,
-       .next   = m_next,
-       .stop   = m_stop,
-       .show   = show_smap
-};
-
-static int do_maps_open(struct inode *inode, struct file *file,
-                       struct seq_operations *ops)
-{
-       struct proc_maps_private *priv;
-       int ret = -ENOMEM;
-       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-       if (priv) {
-               priv->pid = proc_pid(inode);
-               ret = seq_open(file, ops);
-               if (!ret) {
-                       struct seq_file *m = file->private_data;
-                       m->private = priv;
-               } else {
-                       kfree(priv);
-               }
+       for (; pagecount; pagecount--) {
+               page = pages[pagecount-1];
+               if (!PageReserved(page))
+                       SetPageDirty(page);
+               page_cache_release(page);
        }
+       mmput(mm);
+out_free:
+       kfree(pages);
+out_task:
+       put_task_struct(task);
+out:
        return ret;
 }
 
-static int maps_open(struct inode *inode, struct file *file)
-{
-       return do_maps_open(inode, file, &proc_pid_maps_op);
-}
-
-const struct file_operations proc_maps_operations = {
-       .open           = maps_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = seq_release_private,
+const struct file_operations proc_pagemap_operations = {
+       .llseek         = mem_lseek, /* borrow this */
+       .read           = pagemap_read,
 };
+#endif /* CONFIG_PROC_PAGE_MONITOR */
 
 #ifdef CONFIG_NUMA
 extern int show_numa_map(struct seq_file *m, void *v);
@@ -545,15 +753,3 @@ const struct file_operations proc_numa_maps_operations = {
        .release        = seq_release_private,
 };
 #endif
-
-static int smaps_open(struct inode *inode, struct file *file)
-{
-       return do_maps_open(inode, file, &proc_pid_smaps_op);
-}
-
-const struct file_operations proc_smaps_operations = {
-       .open           = smaps_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = seq_release_private,
-};
index 16b331dd9913a93f6575d8ec38dd9b63dcf05251..f491ceb5af02d9a8c089066e8a3ca908c641acaa 100644 (file)
@@ -272,7 +272,7 @@ static inline int block_group_used(struct super_block *s, u32 id)
 
        /* If we don't have cached information on this bitmap block, we're
         * going to have to load it later anyway. Loading it here allows us
-        * to make a better decision. This favors long-term performace gain
+        * to make a better decision. This favors long-term performance gain
         * with a better on-disk layout vs. a short term gain of skipping the
         * read and potentially having a bad placement. */
        if (info->free_count == UINT_MAX) {
@@ -663,7 +663,7 @@ static inline void new_hashed_relocation(reiserfs_blocknr_hint_t * hint)
 
 /*
  * Relocation based on dirid, hashing them into a given bitmap block
- * files. Formatted nodes are unaffected, a seperate policy covers them
+ * files. Formatted nodes are unaffected, a separate policy covers them
  */
 static void dirid_groups(reiserfs_blocknr_hint_t * hint)
 {
@@ -688,7 +688,7 @@ static void dirid_groups(reiserfs_blocknr_hint_t * hint)
 
 /*
  * Relocation based on oid, hashing them into a given bitmap block
- * files. Formatted nodes are unaffected, a seperate policy covers them
+ * files. Formatted nodes are unaffected, a separate policy covers them
  */
 static void oid_groups(reiserfs_blocknr_hint_t * hint)
 {
index 231fd5ccadc52040775842b7a8867c18656314b8..195309857e6323048e20b2286952e56b754b5301 100644 (file)
@@ -2143,7 +2143,7 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
                /* if we are not on a block boundary */
                if (length) {
                        length = blocksize - length;
-                       zero_user_page(page, offset, length, KM_USER0);
+                       zero_user(page, offset, length);
                        if (buffer_mapped(bh) && bh->b_blocknr != 0) {
                                mark_buffer_dirty(bh);
                        }
@@ -2367,7 +2367,7 @@ static int reiserfs_write_full_page(struct page *page,
                        unlock_page(page);
                        return 0;
                }
-               zero_user_page(page, last_offset, PAGE_CACHE_SIZE - last_offset, KM_USER0);
+               zero_user_segment(page, last_offset, PAGE_CACHE_SIZE);
        }
        bh = head;
        block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits);
index 5e7388b32d020f17b6b22fb515bbe04a8a3ee67c..740bb8c0c1ae8e455caafadd37351a6d14b2815e 100644 (file)
@@ -575,6 +575,8 @@ void print_block(struct buffer_head *bh, ...)       //int print_mode, int first, int l
                                        printk
                                            ("Block %llu contains unformatted data\n",
                                             (unsigned long long)bh->b_blocknr);
+
+       va_end(args);
 }
 
 static char print_tb_buf[2048];
index 1597f6b649e040a5aad306e5cde5330f2e953f73..a5bd23ce0e46fde64420455c7097338954da0f76 100644 (file)
@@ -1084,7 +1084,7 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
 }
 
 /* This is the implementation for the xattr plugin infrastructure */
-static struct list_head xattr_handlers = LIST_HEAD_INIT(xattr_handlers);
+static LIST_HEAD(xattr_handlers);
 static DEFINE_RWLOCK(handler_lock);
 
 static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
index 47f47925aea2bead2a4491d672476a7a63e9be1b..5633fe98078179b472a878c444594c4628dbde28 100644 (file)
@@ -739,7 +739,7 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
                        timeout_jiffies = -1;
                else
 #endif
-                       timeout_jiffies = msecs_to_jiffies(timeout_msecs);
+                       timeout_jiffies = msecs_to_jiffies(timeout_msecs) + 1;
        } else {
                /* Infinite (< 0) or no (0) timeout */
                timeout_jiffies = timeout_msecs;
index fb7f7e8034df512db10978276d7c2cf8f9cc0a75..cb2b63ae0bf40adc55ccde41d753e04097e1ddab 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/anon_inodes.h>
 #include <linux/signalfd.h>
+#include <linux/syscalls.h>
 
 struct signalfd_ctx {
        sigset_t sigmask;
@@ -66,7 +67,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
        BUILD_BUG_ON(sizeof(struct signalfd_siginfo) != 128);
 
        /*
-        * Unused memebers should be zero ...
+        * Unused members should be zero ...
         */
        err = __clear_user(uinfo, sizeof(*uinfo));
 
index 9416ead0c7aae67ef1c2bd8b9d3ce12e79cdd9c8..4e5c22ca802e86f77380f51fdb402bcd7add26c9 100644 (file)
@@ -500,6 +500,13 @@ static int smb_fill_super(struct super_block *sb, void *raw_data, int silent)
        struct smb_fattr root;
        int ver;
        void *mem;
+       static int warn_count;
+
+       if (warn_count < 5) {
+               warn_count++;
+               printk(KERN_EMERG "smbfs is deprecated and will be removed"
+                       "from the 2.6.27 kernel.  Please migrate to cifs\n");
+       }
 
        if (!raw_data)
                goto out_no_data;
index e48bd8235a8e39fd81231cb091ee570569d37b09..e37fe4deebd0ebe5050e1fbab7c9ef7cbc2ad4db 100644 (file)
@@ -329,9 +329,8 @@ smb_receive(struct smb_sb_info *server, struct smb_request *req)
        msg.msg_control = NULL;
 
        /* Dont repeat bytes and count available bufferspace */
-       rlen = smb_move_iov(&p, &num, iov, req->rq_bytes_recvd);
-       if (req->rq_rlen < rlen)
-               rlen = req->rq_rlen;
+       rlen = min_t(int, smb_move_iov(&p, &num, iov, req->rq_bytes_recvd),
+                       (req->rq_rlen - req->rq_bytes_recvd));
 
        result = kernel_recvmsg(sock, &msg, p, num, rlen, flags);
 
index 61983f3b107c5ee5d12521d3f38255a77bc6f781..10c80b59ec4bb7e542b8864f369ec10da7dc34f5 100644 (file)
@@ -25,13 +25,15 @@ struct timerfd_ctx {
        struct hrtimer tmr;
        ktime_t tintv;
        wait_queue_head_t wqh;
+       u64 ticks;
        int expired;
+       int clockid;
 };
 
 /*
  * This gets called when the timer event triggers. We set the "expired"
  * flag, but we do not re-arm the timer (in case it's necessary,
- * tintv.tv64 != 0) until the timer is read.
+ * tintv.tv64 != 0) until the timer is accessed.
  */
 static enum hrtimer_restart timerfd_tmrproc(struct hrtimer *htmr)
 {
@@ -40,13 +42,24 @@ static enum hrtimer_restart timerfd_tmrproc(struct hrtimer *htmr)
 
        spin_lock_irqsave(&ctx->wqh.lock, flags);
        ctx->expired = 1;
+       ctx->ticks++;
        wake_up_locked(&ctx->wqh);
        spin_unlock_irqrestore(&ctx->wqh.lock, flags);
 
        return HRTIMER_NORESTART;
 }
 
-static void timerfd_setup(struct timerfd_ctx *ctx, int clockid, int flags,
+static ktime_t timerfd_get_remaining(struct timerfd_ctx *ctx)
+{
+       ktime_t now, remaining;
+
+       now = ctx->tmr.base->get_time();
+       remaining = ktime_sub(ctx->tmr.expires, now);
+
+       return remaining.tv64 < 0 ? ktime_set(0, 0): remaining;
+}
+
+static void timerfd_setup(struct timerfd_ctx *ctx, int flags,
                          const struct itimerspec *ktmr)
 {
        enum hrtimer_mode htmode;
@@ -57,8 +70,9 @@ static void timerfd_setup(struct timerfd_ctx *ctx, int clockid, int flags,
 
        texp = timespec_to_ktime(ktmr->it_value);
        ctx->expired = 0;
+       ctx->ticks = 0;
        ctx->tintv = timespec_to_ktime(ktmr->it_interval);
-       hrtimer_init(&ctx->tmr, clockid, htmode);
+       hrtimer_init(&ctx->tmr, ctx->clockid, htmode);
        ctx->tmr.expires = texp;
        ctx->tmr.function = timerfd_tmrproc;
        if (texp.tv64 != 0)
@@ -83,7 +97,7 @@ static unsigned int timerfd_poll(struct file *file, poll_table *wait)
        poll_wait(file, &ctx->wqh, wait);
 
        spin_lock_irqsave(&ctx->wqh.lock, flags);
-       if (ctx->expired)
+       if (ctx->ticks)
                events |= POLLIN;
        spin_unlock_irqrestore(&ctx->wqh.lock, flags);
 
@@ -102,11 +116,11 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
                return -EINVAL;
        spin_lock_irq(&ctx->wqh.lock);
        res = -EAGAIN;
-       if (!ctx->expired && !(file->f_flags & O_NONBLOCK)) {
+       if (!ctx->ticks && !(file->f_flags & O_NONBLOCK)) {
                __add_wait_queue(&ctx->wqh, &wait);
                for (res = 0;;) {
                        set_current_state(TASK_INTERRUPTIBLE);
-                       if (ctx->expired) {
+                       if (ctx->ticks) {
                                res = 0;
                                break;
                        }
@@ -121,22 +135,21 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
                __remove_wait_queue(&ctx->wqh, &wait);
                __set_current_state(TASK_RUNNING);
        }
-       if (ctx->expired) {
-               ctx->expired = 0;
-               if (ctx->tintv.tv64 != 0) {
+       if (ctx->ticks) {
+               ticks = ctx->ticks;
+               if (ctx->expired && ctx->tintv.tv64) {
                        /*
                         * If tintv.tv64 != 0, this is a periodic timer that
                         * needs to be re-armed. We avoid doing it in the timer
                         * callback to avoid DoS attacks specifying a very
                         * short timer period.
                         */
-                       ticks = (u64)
-                               hrtimer_forward(&ctx->tmr,
-                                               hrtimer_cb_get_time(&ctx->tmr),
-                                               ctx->tintv);
+                       ticks += hrtimer_forward_now(&ctx->tmr,
+                                                    ctx->tintv) - 1;
                        hrtimer_restart(&ctx->tmr);
-               } else
-                       ticks = 1;
+               }
+               ctx->expired = 0;
+               ctx->ticks = 0;
        }
        spin_unlock_irq(&ctx->wqh.lock);
        if (ticks)
@@ -150,76 +163,132 @@ static const struct file_operations timerfd_fops = {
        .read           = timerfd_read,
 };
 
-asmlinkage long sys_timerfd(int ufd, int clockid, int flags,
-                           const struct itimerspec __user *utmr)
+static struct file *timerfd_fget(int fd)
+{
+       struct file *file;
+
+       file = fget(fd);
+       if (!file)
+               return ERR_PTR(-EBADF);
+       if (file->f_op != &timerfd_fops) {
+               fput(file);
+               return ERR_PTR(-EINVAL);
+       }
+
+       return file;
+}
+
+asmlinkage long sys_timerfd_create(int clockid, int flags)
 {
-       int error;
+       int error, ufd;
        struct timerfd_ctx *ctx;
        struct file *file;
        struct inode *inode;
-       struct itimerspec ktmr;
-
-       if (copy_from_user(&ktmr, utmr, sizeof(ktmr)))
-               return -EFAULT;
 
+       if (flags)
+               return -EINVAL;
        if (clockid != CLOCK_MONOTONIC &&
            clockid != CLOCK_REALTIME)
                return -EINVAL;
+
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+
+       init_waitqueue_head(&ctx->wqh);
+       ctx->clockid = clockid;
+       hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS);
+
+       error = anon_inode_getfd(&ufd, &inode, &file, "[timerfd]",
+                                &timerfd_fops, ctx);
+       if (error) {
+               kfree(ctx);
+               return error;
+       }
+
+       return ufd;
+}
+
+asmlinkage long sys_timerfd_settime(int ufd, int flags,
+                                   const struct itimerspec __user *utmr,
+                                   struct itimerspec __user *otmr)
+{
+       struct file *file;
+       struct timerfd_ctx *ctx;
+       struct itimerspec ktmr, kotmr;
+
+       if (copy_from_user(&ktmr, utmr, sizeof(ktmr)))
+               return -EFAULT;
+
        if (!timespec_valid(&ktmr.it_value) ||
            !timespec_valid(&ktmr.it_interval))
                return -EINVAL;
 
-       if (ufd == -1) {
-               ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
-               if (!ctx)
-                       return -ENOMEM;
-
-               init_waitqueue_head(&ctx->wqh);
-
-               timerfd_setup(ctx, clockid, flags, &ktmr);
-
-               /*
-                * When we call this, the initialization must be complete, since
-                * anon_inode_getfd() will install the fd.
-                */
-               error = anon_inode_getfd(&ufd, &inode, &file, "[timerfd]",
-                                        &timerfd_fops, ctx);
-               if (error)
-                       goto err_tmrcancel;
-       } else {
-               file = fget(ufd);
-               if (!file)
-                       return -EBADF;
-               ctx = file->private_data;
-               if (file->f_op != &timerfd_fops) {
-                       fput(file);
-                       return -EINVAL;
-               }
-               /*
-                * We need to stop the existing timer before reprogramming
-                * it to the new values.
-                */
-               for (;;) {
-                       spin_lock_irq(&ctx->wqh.lock);
-                       if (hrtimer_try_to_cancel(&ctx->tmr) >= 0)
-                               break;
-                       spin_unlock_irq(&ctx->wqh.lock);
-                       cpu_relax();
-               }
-               /*
-                * Re-program the timer to the new value ...
-                */
-               timerfd_setup(ctx, clockid, flags, &ktmr);
+       file = timerfd_fget(ufd);
+       if (IS_ERR(file))
+               return PTR_ERR(file);
+       ctx = file->private_data;
 
+       /*
+        * We need to stop the existing timer before reprogramming
+        * it to the new values.
+        */
+       for (;;) {
+               spin_lock_irq(&ctx->wqh.lock);
+               if (hrtimer_try_to_cancel(&ctx->tmr) >= 0)
+                       break;
                spin_unlock_irq(&ctx->wqh.lock);
-               fput(file);
+               cpu_relax();
        }
 
-       return ufd;
+       /*
+        * If the timer is expired and it's periodic, we need to advance it
+        * because the caller may want to know the previous expiration time.
+        * We do not update "ticks" and "expired" since the timer will be
+        * re-programmed again in the following timerfd_setup() call.
+        */
+       if (ctx->expired && ctx->tintv.tv64)
+               hrtimer_forward_now(&ctx->tmr, ctx->tintv);
 
-err_tmrcancel:
-       hrtimer_cancel(&ctx->tmr);
-       kfree(ctx);
-       return error;
+       kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
+       kotmr.it_interval = ktime_to_timespec(ctx->tintv);
+
+       /*
+        * Re-program the timer to the new value ...
+        */
+       timerfd_setup(ctx, flags, &ktmr);
+
+       spin_unlock_irq(&ctx->wqh.lock);
+       fput(file);
+       if (otmr && copy_to_user(otmr, &kotmr, sizeof(kotmr)))
+               return -EFAULT;
+
+       return 0;
+}
+
+asmlinkage long sys_timerfd_gettime(int ufd, struct itimerspec __user *otmr)
+{
+       struct file *file;
+       struct timerfd_ctx *ctx;
+       struct itimerspec kotmr;
+
+       file = timerfd_fget(ufd);
+       if (IS_ERR(file))
+               return PTR_ERR(file);
+       ctx = file->private_data;
+
+       spin_lock_irq(&ctx->wqh.lock);
+       if (ctx->expired && ctx->tintv.tv64) {
+               ctx->expired = 0;
+               ctx->ticks +=
+                       hrtimer_forward_now(&ctx->tmr, ctx->tintv) - 1;
+               hrtimer_restart(&ctx->tmr);
+       }
+       kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
+       kotmr.it_interval = ktime_to_timespec(ctx->tintv);
+       spin_unlock_irq(&ctx->wqh.lock);
+       fput(file);
+
+       return copy_to_user(otmr, &kotmr, sizeof(kotmr)) ? -EFAULT: 0;
 }
 
index b9912ecbee241231ca0b776d9131af1e2643d80a..e5588cd8530e1b7b751bb2a459ac51fdcd3498aa 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/sched.h>
 #include <linux/stat.h>
 #include <linux/utime.h>
+#include <linux/syscalls.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 
index 6645b7313b3372a0a490bdc9b382f81fc8ace71c..f7c8f87bb39065c1ed6fa3011bbb653fcc029e5c 100644 (file)
@@ -104,6 +104,33 @@ out:
 }
 EXPORT_SYMBOL_GPL(vfs_setxattr);
 
+ssize_t
+xattr_getsecurity(struct inode *inode, const char *name, void *value,
+                       size_t size)
+{
+       void *buffer = NULL;
+       ssize_t len;
+
+       if (!value || !size) {
+               len = security_inode_getsecurity(inode, name, &buffer, false);
+               goto out_noalloc;
+       }
+
+       len = security_inode_getsecurity(inode, name, &buffer, true);
+       if (len < 0)
+               return len;
+       if (size < len) {
+               len = -ERANGE;
+               goto out;
+       }
+       memcpy(value, buffer, len);
+out:
+       security_release_secctx(buffer, len);
+out_noalloc:
+       return len;
+}
+EXPORT_SYMBOL_GPL(xattr_getsecurity);
+
 ssize_t
 vfs_getxattr(struct dentry *dentry, char *name, void *value, size_t size)
 {
@@ -118,23 +145,23 @@ vfs_getxattr(struct dentry *dentry, char *name, void *value, size_t size)
        if (error)
                return error;
 
-       if (inode->i_op->getxattr)
-               error = inode->i_op->getxattr(dentry, name, value, size);
-       else
-               error = -EOPNOTSUPP;
-
        if (!strncmp(name, XATTR_SECURITY_PREFIX,
                                XATTR_SECURITY_PREFIX_LEN)) {
                const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
-               int ret = security_inode_getsecurity(inode, suffix, value,
-                                                    size, error);
+               int ret = xattr_getsecurity(inode, suffix, value, size);
                /*
                 * Only overwrite the return value if a security module
                 * is actually active.
                 */
-               if (ret != -EOPNOTSUPP)
-                       error = ret;
+               if (ret == -EOPNOTSUPP)
+                       goto nolsm;
+               return ret;
        }
+nolsm:
+       if (inode->i_op->getxattr)
+               error = inode->i_op->getxattr(dentry, name, value, size);
+       else
+               error = -EOPNOTSUPP;
 
        return error;
 }
index ed2b16dff91434f2bd0b90d35dec3921c447cb27..e040f1ce1b6a71885c6453c620bcf3642ddd45c1 100644 (file)
@@ -92,8 +92,7 @@ kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize,
 void
 kmem_free(void *ptr, size_t size)
 {
-       if (((unsigned long)ptr < VMALLOC_START) ||
-           ((unsigned long)ptr >= VMALLOC_END)) {
+       if (!is_vmalloc_addr(ptr)) {
                kfree(ptr);
        } else {
                vfree(ptr);
index a49dd8d4b06974c9a9b8b20ca19bc0663dfe0471..0382c19d6523708792675b9215aebd4867801aa3 100644 (file)
@@ -709,8 +709,7 @@ static inline struct page *
 mem_to_page(
        void                    *addr)
 {
-       if (((unsigned long)addr < VMALLOC_START) ||
-           ((unsigned long)addr >= VMALLOC_END)) {
+       if ((!is_vmalloc_addr(addr))) {
                return virt_to_page(addr);
        } else {
                return vmalloc_to_page(addr);
index d6a8dddb2268bab8a341499d0debadba041f3928..6f614f35f65015140d2078a92484328d275e94c1 100644 (file)
@@ -155,7 +155,7 @@ xfs_iozero(
                if (status)
                        break;
 
-               zero_user_page(page, offset, bytes, KM_USER0);
+               zero_user(page, offset, bytes);
 
                status = pagecache_write_end(NULL, mapping, pos, bytes, bytes,
                                        page, fsdata);
index 9512f0456ad1f241df8ba36e64f1d0cb060fef6a..d970f7f99549639183b73d8324043c2805020dd5 100644 (file)
@@ -85,7 +85,7 @@ acpi_install_initialization_handler(acpi_init_handler handler, u32 function);
 #endif
 
 /*
- * ACPI Memory managment
+ * ACPI Memory management
  */
 void *acpi_allocate(u32 size);
 
@@ -335,6 +335,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state);
 
 acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void);
 
+acpi_status acpi_leave_sleep_state_prep(u8 sleep_state);
+
 acpi_status acpi_leave_sleep_state(u8 sleep_state);
 
 #endif                         /* __ACXFACE_H__ */
index 76411b1fc4fd4778e2e35cda00da46ead7b7dd5e..6e253b5b0f3bc33ba5d7c622bb0d689ee4df2c12 100644 (file)
@@ -182,7 +182,7 @@ struct acpi_processor_throttling {
 /* Limit Interface */
 
 struct acpi_processor_lx {
-       int px;                 /* performace state */
+       int px;                 /* performance state */
        int tx;                 /* throttle level */
 };
 
index f5cb7b878af25ba2dd69abb0343327db8c183dd4..ca88e54dec93774770f3eb93629d908db69e499e 100644 (file)
@@ -100,7 +100,7 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
 /*
  * Same as above, but return the result value
  */
-static __inline__ long atomic_add_return(int i, atomic_t * v)
+static inline int atomic_add_return(int i, atomic_t *v)
 {
        long temp, result;
        smp_mb();
index 30ee7669b19f9622703478bd77c45aab598c628e..d5b10ef643642b292c7baad6098d06175520f8e9 100644 (file)
@@ -4,6 +4,7 @@
 #ifdef __KERNEL__
 
 #include <linux/spinlock.h>
+#include <linux/dma-mapping.h>
 #include <asm/scatterlist.h>
 #include <asm/machvec.h>
 
index 471864e8d4c370d17d3ff5a672c95cc71444087a..fdbedacc7375158990236e13b546a7fa1c92a8a6 100644 (file)
@@ -31,7 +31,7 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
 extern pgd_t *pgd_alloc(struct mm_struct *mm);
 
 static inline void
-pgd_free(pgd_t *pgd)
+pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_page((unsigned long)pgd);
 }
@@ -44,7 +44,7 @@ pmd_alloc_one(struct mm_struct *mm, unsigned long address)
 }
 
 static inline void
-pmd_free(pmd_t *pmd)
+pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        free_page((unsigned long)pmd);
 }
@@ -52,7 +52,7 @@ pmd_free(pmd_t *pmd)
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr);
 
 static inline void
-pte_free_kernel(pte_t *pte)
+pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
@@ -67,7 +67,7 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
 }
 
 static inline void
-pte_free(struct page *page)
+pte_free(struct mm_struct *mm, struct page *page)
 {
        __free_page(page);
 }
index aa91335533e0443b87a6b5863943716ff17e1d8b..c13636575fbab4fb14c17b75d53058b0f9181e1c 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <asm-generic/tlb.h>
 
-#define __pte_free_tlb(tlb,pte)                        pte_free(pte)
-#define __pmd_free_tlb(tlb,pmd)                        pmd_free(pmd)
+#define __pte_free_tlb(tlb, pte)                       pte_free((tlb)->mm, pte)
+#define __pmd_free_tlb(tlb, pmd)                       pmd_free((tlb)->mm, pmd)
  
 #endif
index b9e9147226f770ba3bc09149375984b525f066c7..9d87aaa08c0df1cf093bbb90227a2f8470adb70e 100644 (file)
@@ -142,6 +142,10 @@ extern void flush_tlb_range(struct vm_area_struct *, unsigned long,
 
 #endif /* CONFIG_SMP */
 
-#define flush_tlb_kernel_range(start, end) flush_tlb_all()
+static inline void flush_tlb_kernel_range(unsigned long start,
+                                       unsigned long end)
+{
+       flush_tlb_all();
+}
 
 #endif /* _ALPHA_TLBFLUSH_H */
index 29bf2fdc91c0eefe194b5123774e88eb29c4f8b6..5b5c174859428edda511595e263a4540ce7d9354 100644 (file)
 #define __ARCH_WANT_OLD_READDIR
 #define __ARCH_WANT_STAT64
 #define __ARCH_WANT_SYS_GETHOSTNAME
-#define __ARCH_WANT_SYS_SOCKETCALL
 #define __ARCH_WANT_SYS_FADVISE64
 #define __ARCH_WANT_SYS_GETPGRP
 #define __ARCH_WANT_SYS_OLD_GETRLIMIT
index c2e11cc374ba6a28a1b33bf94f13a523bc73df90..1551fc24eb43b6bdaa14e590ae1a9ed175513c64 100644 (file)
@@ -89,7 +89,7 @@
 #define                AT91_MCI_ENDRX          (1 <<  6)       /* End of RX Buffer */
 #define                AT91_MCI_ENDTX          (1 <<  7)       /* End fo TX Buffer */
 #define                AT91_MCI_SDIOIRQA       (1 <<  8)       /* SDIO Interrupt for Slot A */
-#define                At91_MCI_SDIOIRQB       (1 <<  9)       /* SDIO Interrupt for Slot B [AT91RM9200 only] */
+#define                AT91_MCI_SDIOIRQB       (1 <<  9)       /* SDIO Interrupt for Slot B */
 #define                AT91_MCI_RXBUFF         (1 << 14)       /* RX Buffer Full */
 #define                AT91_MCI_TXBUFE         (1 << 15)       /* TX Buffer Empty */
 #define                AT91_MCI_RINDE          (1 << 16)       /* Response Index Error */
index 802891a9cd81d76089c980ae1ea02df5fa969e3f..e8fc0b1c33f4423647a60db76fac50f85b7f49d2 100644 (file)
 #define AT91_RTC       (0xfffffe00 - AT91_BASE_SYS)    /* Real-Time Clock */
 #define AT91_MC                (0xffffff00 - AT91_BASE_SYS)    /* Memory Controllers */
 
+#define AT91_USART0    AT91RM9200_BASE_US0
+#define AT91_USART1    AT91RM9200_BASE_US1
+#define AT91_USART2    AT91RM9200_BASE_US2
+#define AT91_USART3    AT91RM9200_BASE_US3
+
 #define AT91_MATRIX    0       /* not supported */
 
 /*
index 0427f8698c07a8e8f43ec675929b1fd907ebb033..c8934fe34dc512ff43b30518f8fe7ba480e86be0 100644 (file)
 #define AT91_WDT       (0xfffffd40 - AT91_BASE_SYS)
 #define AT91_GPBR      (0xfffffd50 - AT91_BASE_SYS)
 
+#define AT91_USART0    AT91SAM9260_BASE_US0
+#define AT91_USART1    AT91SAM9260_BASE_US1
+#define AT91_USART2    AT91SAM9260_BASE_US2
+#define AT91_USART3    AT91SAM9260_BASE_US3
+#define AT91_USART4    AT91SAM9260_BASE_US4
+#define AT91_USART5    AT91SAM9260_BASE_US5
+
 
 /*
  * Internal Memory.
index 9eb4595703307832b8cc2224fcab032f1a45ee08..c7c4778dac49bed468e44eab6a23a32dd468789a 100644 (file)
 #define AT91_WDT       (0xfffffd40 - AT91_BASE_SYS)
 #define AT91_GPBR      (0xfffffd50 - AT91_BASE_SYS)
 
+#define AT91_USART0    AT91SAM9261_BASE_US0
+#define AT91_USART1    AT91SAM9261_BASE_US1
+#define AT91_USART2    AT91SAM9261_BASE_US2
+
 
 /*
  * Internal Memory.
index 115c47ac7ebb0b22b75d00e1ddcfeaf1dee25a21..018a647311da97590a21677931ea21a8899301ea 100644 (file)
 #define AT91_RTT1      (0xfffffd50 - AT91_BASE_SYS)
 #define AT91_GPBR      (0xfffffd60 - AT91_BASE_SYS)
 
+#define AT91_USART0    AT91SAM9263_BASE_US0
+#define AT91_USART1    AT91SAM9263_BASE_US1
+#define AT91_USART2    AT91SAM9263_BASE_US2
+
 #define AT91_SMC       AT91_SMC0
 
 /*
index 8a9708a370c63fddc87b550d628eda108460dc49..16d2832f6c0abf04b2f8091f92d87af2af2cf2e9 100644 (file)
 #define AT91_GPBR      (0xfffffd60 - AT91_BASE_SYS)
 #define AT91_RTC       (0xfffffe00 - AT91_BASE_SYS)
 
+#define AT91_USART0    AT91SAM9RL_BASE_US0
+#define AT91_USART1    AT91SAM9RL_BASE_US1
+#define AT91_USART2    AT91SAM9RL_BASE_US2
+#define AT91_USART3    AT91SAM9RL_BASE_US3
+
 
 /*
  * Internal Memory.
index 55b07bd5316ccf446f6eb902776f53068e0222f6..dc189f01c5b3c969071057484e75b4d72df236db 100644 (file)
@@ -40,7 +40,8 @@
  /* USB Device */
 struct at91_udc_data {
        u8      vbus_pin;               /* high == host powering us */
-       u8      pullup_pin;             /* high == D+ pulled up */
+       u8      pullup_pin;             /* active == D+ pulled up */
+       u8      pullup_active_low;      /* true == pullup_pin is active low */
 };
 extern void __init at91_add_device_udc(struct at91_udc_data *data);
 
index 272a7e0dc6cf928c11a4328741a03e5302441c8e..f5636a8f6132989de20acf64b6e04fdcbbf3245d 100644 (file)
 #define __ASM_ARCH_UNCOMPRESS_H
 
 #include <asm/io.h>
-#include <asm/arch/at91_dbgu.h>
+#include <linux/atmel_serial.h>
+
+#if defined(CONFIG_AT91_EARLY_DBGU)
+#define UART_OFFSET (AT91_DBGU + AT91_BASE_SYS)
+#elif defined(CONFIG_AT91_EARLY_USART0)
+#define UART_OFFSET AT91_USART0
+#elif defined(CONFIG_AT91_EARLY_USART1)
+#define UART_OFFSET AT91_USART1
+#elif defined(CONFIG_AT91_EARLY_USART2)
+#define UART_OFFSET AT91_USART2
+#elif defined(CONFIG_AT91_EARLY_USART3)
+#define UART_OFFSET AT91_USART3
+#elif defined(CONFIG_AT91_EARLY_USART4)
+#define UART_OFFSET AT91_USART4
+#elif defined(CONFIG_AT91_EARLY_USART5)
+#define UART_OFFSET AT91_USART5
+#endif
 
 /*
  * The following code assumes the serial port has already been
  */
 static void putc(int c)
 {
-#ifdef AT91_DBGU
-       void __iomem *sys = (void __iomem *) AT91_BASE_SYS;     /* physical address */
+#ifdef UART_OFFSET
+       void __iomem *sys = (void __iomem *) UART_OFFSET;       /* physical address */
 
-       while (!(__raw_readl(sys + AT91_DBGU_SR) & AT91_DBGU_TXRDY))
+       while (!(__raw_readl(sys + ATMEL_US_CSR) & ATMEL_US_TXRDY))
                barrier();
-       __raw_writel(c, sys + AT91_DBGU_THR);
+       __raw_writel(c, sys + ATMEL_US_THR);
 #endif
 }
 
 static inline void flush(void)
 {
-#ifdef AT91_DBGU
-       void __iomem *sys = (void __iomem *) AT91_BASE_SYS;     /* physical address */
+#ifdef UART_OFFSET
+       void __iomem *sys = (void __iomem *) UART_OFFSET;       /* physical address */
 
        /* wait for transmission to complete */
-       while (!(__raw_readl(sys + AT91_DBGU_SR) & AT91_DBGU_TXEMPTY))
+       while (!(__raw_readl(sys + ATMEL_US_CSR) & ATMEL_US_TXEMPTY))
                barrier();
 #endif
 }
index 04006c1c5fd76bb75387b3136fc1e62619617b1c..efd9a5eb10081275859eb5605e78611f149572da 100644 (file)
@@ -247,7 +247,7 @@ static inline u32 iop_desc_get_src_count(struct iop_adma_desc_slot *desc,
 }
 
 static inline void
-iop_desc_init_memcpy(struct iop_adma_desc_slot *desc, int int_en)
+iop_desc_init_memcpy(struct iop_adma_desc_slot *desc, unsigned long flags)
 {
        struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
        union {
@@ -257,13 +257,13 @@ iop_desc_init_memcpy(struct iop_adma_desc_slot *desc, int int_en)
 
        u_desc_ctrl.value = 0;
        u_desc_ctrl.field.xfer_dir = 3; /* local to internal bus */
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
        hw_desc->crc_addr = 0;
 }
 
 static inline void
-iop_desc_init_memset(struct iop_adma_desc_slot *desc, int int_en)
+iop_desc_init_memset(struct iop_adma_desc_slot *desc, unsigned long flags)
 {
        struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
        union {
@@ -274,14 +274,15 @@ iop_desc_init_memset(struct iop_adma_desc_slot *desc, int int_en)
        u_desc_ctrl.value = 0;
        u_desc_ctrl.field.xfer_dir = 3; /* local to internal bus */
        u_desc_ctrl.field.block_fill_en = 1;
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
        hw_desc->crc_addr = 0;
 }
 
 /* to do: support buffers larger than ADMA_MAX_BYTE_COUNT */
 static inline void
-iop_desc_init_xor(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
+iop_desc_init_xor(struct iop_adma_desc_slot *desc, int src_cnt,
+                 unsigned long flags)
 {
        struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
        union {
@@ -292,7 +293,7 @@ iop_desc_init_xor(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
        u_desc_ctrl.value = 0;
        u_desc_ctrl.field.src_select = src_cnt - 1;
        u_desc_ctrl.field.xfer_dir = 3; /* local to internal bus */
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
        hw_desc->crc_addr = 0;
 
@@ -301,7 +302,8 @@ iop_desc_init_xor(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
 
 /* to do: support buffers larger than ADMA_MAX_BYTE_COUNT */
 static inline int
-iop_desc_init_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
+iop_desc_init_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt,
+                      unsigned long flags)
 {
        struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
        union {
@@ -314,7 +316,7 @@ iop_desc_init_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
        u_desc_ctrl.field.xfer_dir = 3; /* local to internal bus */
        u_desc_ctrl.field.zero_result = 1;
        u_desc_ctrl.field.status_write_back_en = 1;
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
        hw_desc->crc_addr = 0;
 
index d2523b326c6c2d1595dd1980fa7c4e9db09fc135..2fa3d6b8dbb8de9074b642e4593c7ee479b21fab 100644 (file)
@@ -28,4 +28,19 @@ extern unsigned int processor_id;
 #define cpu_is_ixp46x()        ((processor_id & IXP4XX_PROCESSOR_ID_MASK) == \
                          IXP465_PROCESSOR_ID_VALUE)
 
+static inline u32 ixp4xx_read_feature_bits(void)
+{
+       unsigned int val = ~*IXP4XX_EXP_CFG2;
+       val &= ~IXP4XX_FEATURE_RESERVED;
+       if (!cpu_is_ixp46x())
+               val &= ~IXP4XX_FEATURE_IXP46X_ONLY;
+
+       return val;
+}
+
+static inline void ixp4xx_write_feature_bits(u32 value)
+{
+       *IXP4XX_EXP_CFG2 = ~value;
+}
+
 #endif  /* _ASM_ARCH_CPU_H */
index a19605ad240da758f96d9acd59c6c49ed4d25dd3..b7673e171abe0c111bd9521e92d4fd45d02fe197 100644 (file)
 /* Buttons */
 
 #define DSMG600_PB_GPIO                15      /* power button */
-#define DSMG600_PB_BM          (1L << DSMG600_PB_GPIO)
-
 #define DSMG600_RB_GPIO                3       /* reset button */
 
-#define DSMG600_RB_IRQ         IRQ_IXP4XX_GPIO3
+/* Power control */
 
 #define DSMG600_PO_GPIO                2       /* power off */
 
 /* LEDs */
 
 #define DSMG600_LED_PWR_GPIO   0
-#define DSMG600_LED_PWR_BM     (1L << DSMG600_LED_PWR_GPIO)
-
 #define DSMG600_LED_WLAN_GPIO  14
-#define DSMG600_LED_WLAN_BM    (1L << DSMG600_LED_WLAN_GPIO)
index 297ceda08b61375fef91233b953c50374853f221..73e8dc36f6a4f11882dfde8aba7ecfa53cc15b7d 100644 (file)
 
 #define pcibios_assign_all_busses()    1
 
+/* Register locations and bits */
+#include "ixp4xx-regs.h"
+
 #ifndef __ASSEMBLER__
 #include <asm/arch/cpu.h>
 #endif
 
-/* Register locations and bits */
-#include "ixp4xx-regs.h"
-
 /* Platform helper functions and definitions */
 #include "platform.h"
 
index 9c5d2357aff3ac4689ae36747022f76cb2d6081a..de181ce958db86d23f4749e23ea2b0a8d4b43fb4 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef __ASM_ARM_ARCH_IO_H
 #define __ASM_ARM_ARCH_IO_H
 
+#include <linux/bitops.h>
+
 #include <asm/hardware.h>
 
 #define IO_SPACE_LIMIT 0xffff0000
index 5d949d763a918810571f46f5b163cb61a740ca2a..68aca8554f5ad5556ddae23be4143563bb8e4d33 100644 (file)
  *
  */
 
-#ifndef __ASM_ARCH_HARDWARE_H__
-#error "Do not include this directly, instead #include <asm/hardware.h>"
-#endif
-
 #ifndef _ASM_ARM_IXP4XX_H_
 #define _ASM_ARM_IXP4XX_H_
 
 #define UICR1_IM14     (1 << 6)        /* Interrupt mask ep 14 */
 #define UICR1_IM15     (1 << 7)        /* Interrupt mask ep 15 */
 
-#define USIR0_IR0      (1 << 0)        /* Interrup request ep 0 */
-#define USIR0_IR1      (1 << 1)        /* Interrup request ep 1 */
-#define USIR0_IR2      (1 << 2)        /* Interrup request ep 2 */
-#define USIR0_IR3      (1 << 3)        /* Interrup request ep 3 */
-#define USIR0_IR4      (1 << 4)        /* Interrup request ep 4 */
-#define USIR0_IR5      (1 << 5)        /* Interrup request ep 5 */
-#define USIR0_IR6      (1 << 6)        /* Interrup request ep 6 */
-#define USIR0_IR7      (1 << 7)        /* Interrup request ep 7 */
-
-#define USIR1_IR8      (1 << 0)        /* Interrup request ep 8 */
-#define USIR1_IR9      (1 << 1)        /* Interrup request ep 9 */
-#define USIR1_IR10     (1 << 2)        /* Interrup request ep 10 */
-#define USIR1_IR11     (1 << 3)        /* Interrup request ep 11 */
-#define USIR1_IR12     (1 << 4)        /* Interrup request ep 12 */
-#define USIR1_IR13     (1 << 5)        /* Interrup request ep 13 */
-#define USIR1_IR14     (1 << 6)        /* Interrup request ep 14 */
-#define USIR1_IR15     (1 << 7)        /* Interrup request ep 15 */
+#define USIR0_IR0      (1 << 0)        /* Interrupt request ep 0 */
+#define USIR0_IR1      (1 << 1)        /* Interrupt request ep 1 */
+#define USIR0_IR2      (1 << 2)        /* Interrupt request ep 2 */
+#define USIR0_IR3      (1 << 3)        /* Interrupt request ep 3 */
+#define USIR0_IR4      (1 << 4)        /* Interrupt request ep 4 */
+#define USIR0_IR5      (1 << 5)        /* Interrupt request ep 5 */
+#define USIR0_IR6      (1 << 6)        /* Interrupt request ep 6 */
+#define USIR0_IR7      (1 << 7)        /* Interrupt request ep 7 */
+
+#define USIR1_IR8      (1 << 0)        /* Interrupt request ep 8 */
+#define USIR1_IR9      (1 << 1)        /* Interrupt request ep 9 */
+#define USIR1_IR10     (1 << 2)        /* Interrupt request ep 10 */
+#define USIR1_IR11     (1 << 3)        /* Interrupt request ep 11 */
+#define USIR1_IR12     (1 << 4)        /* Interrupt request ep 12 */
+#define USIR1_IR13     (1 << 5)        /* Interrupt request ep 13 */
+#define USIR1_IR14     (1 << 6)        /* Interrupt request ep 14 */
+#define USIR1_IR15     (1 << 7)        /* Interrupt request ep 15 */
 
 #define DCMD_LENGTH    0x01fff         /* length mask (max = 8K - 1) */
 
+/* "fuse" bits of IXP_EXP_CFG2 */
+#define IXP4XX_FEATURE_RCOMP           (1 << 0)
+#define IXP4XX_FEATURE_USB_DEVICE      (1 << 1)
+#define IXP4XX_FEATURE_HASH            (1 << 2)
+#define IXP4XX_FEATURE_AES             (1 << 3)
+#define IXP4XX_FEATURE_DES             (1 << 4)
+#define IXP4XX_FEATURE_HDLC            (1 << 5)
+#define IXP4XX_FEATURE_AAL             (1 << 6)
+#define IXP4XX_FEATURE_HSS             (1 << 7)
+#define IXP4XX_FEATURE_UTOPIA          (1 << 8)
+#define IXP4XX_FEATURE_NPEB_ETH0       (1 << 9)
+#define IXP4XX_FEATURE_NPEC_ETH                (1 << 10)
+#define IXP4XX_FEATURE_RESET_NPEA      (1 << 11)
+#define IXP4XX_FEATURE_RESET_NPEB      (1 << 12)
+#define IXP4XX_FEATURE_RESET_NPEC      (1 << 13)
+#define IXP4XX_FEATURE_PCI             (1 << 14)
+#define IXP4XX_FEATURE_ECC_TIMESYNC    (1 << 15)
+#define IXP4XX_FEATURE_UTOPIA_PHY_LIMIT        (3 << 16)
+#define IXP4XX_FEATURE_USB_HOST                (1 << 18)
+#define IXP4XX_FEATURE_NPEA_ETH                (1 << 19)
+#define IXP4XX_FEATURE_NPEB_ETH_1_TO_3 (1 << 20)
+#define IXP4XX_FEATURE_RSA             (1 << 21)
+#define IXP4XX_FEATURE_XSCALE_MAX_FREQ (3 << 22)
+#define IXP4XX_FEATURE_RESERVED                (0xFF << 24)
+
+#define IXP4XX_FEATURE_IXP46X_ONLY (IXP4XX_FEATURE_ECC_TIMESYNC |      \
+                                   IXP4XX_FEATURE_USB_HOST |           \
+                                   IXP4XX_FEATURE_NPEA_ETH |           \
+                                   IXP4XX_FEATURE_NPEB_ETH_1_TO_3 |    \
+                                   IXP4XX_FEATURE_RSA |                \
+                                   IXP4XX_FEATURE_XSCALE_MAX_FREQ)
+
 #endif
index 131e0a1d0df395f3d7740167e54b0b9419e5ad4d..98d937897bceba13b3489db3323b8fd750d6544b 100644 (file)
 
 /* Buttons */
 
-#define NAS100D_PB_GPIO         14
-#define NAS100D_RB_GPIO         4
+#define NAS100D_PB_GPIO         14   /* power button */
+#define NAS100D_RB_GPIO         4    /* reset button */
+
+/* Power control */
+
 #define NAS100D_PO_GPIO         12   /* power off */
 
-#define NAS100D_PB_IRQ          IRQ_IXP4XX_GPIO14
-#define NAS100D_RB_IRQ          IRQ_IXP4XX_GPIO4
+/* LEDs */
 
-/*
-#define NAS100D_PB_BM           (1L << NAS100D_PB_GPIO)
-#define NAS100D_PO_BM           (1L << NAS100D_PO_GPIO)
-#define NAS100D_RB_BM           (1L << NAS100D_RB_GPIO)
-*/
+#define NAS100D_LED_WLAN_GPIO  0
+#define NAS100D_LED_DISK_GPIO  3
+#define NAS100D_LED_PWR_GPIO   15
diff --git a/include/asm-arm/arch-ixp4xx/npe.h b/include/asm-arm/arch-ixp4xx/npe.h
new file mode 100644 (file)
index 0000000..37d0511
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __IXP4XX_NPE_H
+#define __IXP4XX_NPE_H
+
+#include <linux/kernel.h>
+
+extern const char *npe_names[];
+
+struct npe_regs {
+       u32 exec_addr, exec_data, exec_status_cmd, exec_count;
+       u32 action_points[4];
+       u32 watchpoint_fifo, watch_count;
+       u32 profile_count;
+       u32 messaging_status, messaging_control;
+       u32 mailbox_status, /*messaging_*/ in_out_fifo;
+};
+
+struct npe {
+       struct resource *mem_res;
+       struct npe_regs __iomem *regs;
+       u32 regs_phys;
+       int id;
+       int valid;
+};
+
+
+static inline const char *npe_name(struct npe *npe)
+{
+       return npe_names[npe->id];
+}
+
+int npe_running(struct npe *npe);
+int npe_send_message(struct npe *npe, const void *msg, const char *what);
+int npe_recv_message(struct npe *npe, void *msg, const char *what);
+int npe_send_recv_message(struct npe *npe, void *msg, const char *what);
+int npe_load_firmware(struct npe *npe, const char *name, struct device *dev);
+struct npe *npe_request(int id);
+void npe_release(struct npe *npe);
+
+#endif /* __IXP4XX_NPE_H */
index 850fdc5b45da21eda6f6a3ad9d03a7a06b9d738a..714bbc65126af1c26a3303ab79c659dfd65f8bc3 100644 (file)
 
 /* Buttons */
 
-#define NSLU2_PB_GPIO          5
+#define NSLU2_PB_GPIO          5       /* power button */
 #define NSLU2_PO_GPIO          8       /* power off */
-#define NSLU2_RB_GPIO          12
-
-#define NSLU2_PB_IRQ           IRQ_IXP4XX_GPIO5
-#define NSLU2_RB_IRQ           IRQ_IXP4XX_GPIO12
-
-#define NSLU2_PB_BM            (1L << NSLU2_PB_GPIO)
-#define NSLU2_PO_BM            (1L << NSLU2_PO_GPIO)
-#define NSLU2_RB_BM            (1L << NSLU2_RB_GPIO)
+#define NSLU2_RB_GPIO          12      /* reset button */
 
 /* Buzzer */
 
 #define NSLU2_GPIO_BUZZ                4
-#define NSLU2_BZ_BM            (1L << NSLU2_GPIO_BUZZ)
 
 /* LEDs */
 
 #define NSLU2_LED_RED_GPIO     0
 #define NSLU2_LED_GRN_GPIO     1
-
-#define NSLU2_LED_RED_BM       (1L << NSLU2_LED_RED_GPIO)
-#define NSLU2_LED_GRN_BM       (1L << NSLU2_LED_GRN_GPIO)
-
 #define NSLU2_LED_DISK1_GPIO   3
 #define NSLU2_LED_DISK2_GPIO   2
-
-#define NSLU2_LED_DISK1_BM     (1L << NSLU2_LED_DISK1_GPIO)
-#define NSLU2_LED_DISK2_BM     (1L << NSLU2_LED_DISK2_GPIO)
-
-
index 2ce28e3fd325ba3898e23c26ed18ac6dad0554e9..a1f2b5404db1f95e6496676555e48629091c605a 100644 (file)
@@ -91,6 +91,27 @@ struct ixp4xx_pata_data {
 
 struct sys_timer;
 
+#define IXP4XX_ETH_NPEA                0x00
+#define IXP4XX_ETH_NPEB                0x10
+#define IXP4XX_ETH_NPEC                0x20
+
+/* Information about built-in Ethernet MAC interfaces */
+struct eth_plat_info {
+       u8 phy;         /* MII PHY ID, 0 - 31 */
+       u8 rxq;         /* configurable, currently 0 - 31 only */
+       u8 txreadyq;
+       u8 hwaddr[6];
+};
+
+/* Information about built-in HSS (synchronous serial) interfaces */
+struct hss_plat_info {
+       int (*set_clock)(int port, unsigned int clock_type);
+       int (*open)(int port, void *pdev,
+                   void (*set_carrier_cb)(void *pdev, int carrier));
+       void (*close)(int port, void *pdev);
+       u8 txreadyq;
+};
+
 /*
  * Frequency of clock used for primary clocksource
  */
diff --git a/include/asm-arm/arch-ixp4xx/qmgr.h b/include/asm-arm/arch-ixp4xx/qmgr.h
new file mode 100644 (file)
index 0000000..1e52b95
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+#ifndef IXP4XX_QMGR_H
+#define IXP4XX_QMGR_H
+
+#include <linux/io.h>
+#include <linux/kernel.h>
+
+#define HALF_QUEUES    32
+#define QUEUES         64      /* only 32 lower queues currently supported */
+#define MAX_QUEUE_LENGTH 4     /* in dwords */
+
+#define QUEUE_STAT1_EMPTY              1 /* queue status bits */
+#define QUEUE_STAT1_NEARLY_EMPTY       2
+#define QUEUE_STAT1_NEARLY_FULL                4
+#define QUEUE_STAT1_FULL               8
+#define QUEUE_STAT2_UNDERFLOW          1
+#define QUEUE_STAT2_OVERFLOW           2
+
+#define QUEUE_WATERMARK_0_ENTRIES      0
+#define QUEUE_WATERMARK_1_ENTRY                1
+#define QUEUE_WATERMARK_2_ENTRIES      2
+#define QUEUE_WATERMARK_4_ENTRIES      3
+#define QUEUE_WATERMARK_8_ENTRIES      4
+#define QUEUE_WATERMARK_16_ENTRIES     5
+#define QUEUE_WATERMARK_32_ENTRIES     6
+#define QUEUE_WATERMARK_64_ENTRIES     7
+
+/* queue interrupt request conditions */
+#define QUEUE_IRQ_SRC_EMPTY            0
+#define QUEUE_IRQ_SRC_NEARLY_EMPTY     1
+#define QUEUE_IRQ_SRC_NEARLY_FULL      2
+#define QUEUE_IRQ_SRC_FULL             3
+#define QUEUE_IRQ_SRC_NOT_EMPTY                4
+#define QUEUE_IRQ_SRC_NOT_NEARLY_EMPTY 5
+#define QUEUE_IRQ_SRC_NOT_NEARLY_FULL  6
+#define QUEUE_IRQ_SRC_NOT_FULL         7
+
+struct qmgr_regs {
+       u32 acc[QUEUES][MAX_QUEUE_LENGTH]; /* 0x000 - 0x3FF */
+       u32 stat1[4];           /* 0x400 - 0x40F */
+       u32 stat2[2];           /* 0x410 - 0x417 */
+       u32 statne_h;           /* 0x418 - queue nearly empty */
+       u32 statf_h;            /* 0x41C - queue full */
+       u32 irqsrc[4];          /* 0x420 - 0x42F IRC source */
+       u32 irqen[2];           /* 0x430 - 0x437 IRQ enabled */
+       u32 irqstat[2];         /* 0x438 - 0x43F - IRQ access only */
+       u32 reserved[1776];
+       u32 sram[2048];         /* 0x2000 - 0x3FFF - config and buffer */
+};
+
+void qmgr_set_irq(unsigned int queue, int src,
+                 void (*handler)(void *pdev), void *pdev);
+void qmgr_enable_irq(unsigned int queue);
+void qmgr_disable_irq(unsigned int queue);
+
+/* request_ and release_queue() must be called from non-IRQ context */
+int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
+                      unsigned int nearly_empty_watermark,
+                      unsigned int nearly_full_watermark);
+void qmgr_release_queue(unsigned int queue);
+
+
+static inline void qmgr_put_entry(unsigned int queue, u32 val)
+{
+       extern struct qmgr_regs __iomem *qmgr_regs;
+       __raw_writel(val, &qmgr_regs->acc[queue][0]);
+}
+
+static inline u32 qmgr_get_entry(unsigned int queue)
+{
+       extern struct qmgr_regs __iomem *qmgr_regs;
+       return __raw_readl(&qmgr_regs->acc[queue][0]);
+}
+
+static inline int qmgr_get_stat1(unsigned int queue)
+{
+       extern struct qmgr_regs __iomem *qmgr_regs;
+       return (__raw_readl(&qmgr_regs->stat1[queue >> 3])
+               >> ((queue & 7) << 2)) & 0xF;
+}
+
+static inline int qmgr_get_stat2(unsigned int queue)
+{
+       extern struct qmgr_regs __iomem *qmgr_regs;
+       return (__raw_readl(&qmgr_regs->stat2[queue >> 4])
+               >> ((queue & 0xF) << 1)) & 0x3;
+}
+
+static inline int qmgr_stat_empty(unsigned int queue)
+{
+       return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_EMPTY);
+}
+
+static inline int qmgr_stat_nearly_empty(unsigned int queue)
+{
+       return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_EMPTY);
+}
+
+static inline int qmgr_stat_nearly_full(unsigned int queue)
+{
+       return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_FULL);
+}
+
+static inline int qmgr_stat_full(unsigned int queue)
+{
+       return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_FULL);
+}
+
+static inline int qmgr_stat_underflow(unsigned int queue)
+{
+       return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_UNDERFLOW);
+}
+
+static inline int qmgr_stat_overflow(unsigned int queue)
+{
+       return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_OVERFLOW);
+}
+
+#endif
index f7a35b78823ff0227c44c6e4d9cc4d6052408ddd..34ef48fe327eff50b05329a9a053a61a758f724b 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef _ARCH_UNCOMPRESS_H_
 #define _ARCH_UNCOMPRESS_H_
 
-#include <asm/hardware.h>
+#include "ixp4xx-regs.h"
 #include <asm/mach-types.h>
 #include <linux/serial_reg.h>
 
index 9dbc2dc794f777dfd18b4ad014dc5501b77075ed..bdbf5f9ffdd5df5694deb4ffd664f9e0d5ac9d29 100644 (file)
 #include <asm/irq.h>
 #include <asm/hardware.h>
 
-static inline int gpio_request(unsigned gpio, const char *label)
-{
-       return 0;
-}
+#include <asm-generic/gpio.h>
 
-static inline void gpio_free(unsigned gpio)
-{
-       return;
-}
 
-extern int gpio_direction_input(unsigned gpio);
-extern int gpio_direction_output(unsigned gpio, int value);
+/* NOTE: some PXAs have fewer on-chip GPIOs (like PXA255, with 85).
+ * Those cases currently cause holes in the GPIO number space.
+ */
+#define NR_BUILTIN_GPIO 128
 
-static inline int __gpio_get_value(unsigned gpio)
+static inline int gpio_get_value(unsigned gpio)
 {
-       return GPLR(gpio) & GPIO_bit(gpio);
+       if (__builtin_constant_p(gpio) && (gpio < NR_BUILTIN_GPIO))
+               return GPLR(gpio) & GPIO_bit(gpio);
+       else
+               return __gpio_get_value(gpio);
 }
 
-#define gpio_get_value(gpio)                   \
-       (__builtin_constant_p(gpio) ?           \
-        __gpio_get_value(gpio) :               \
-        pxa_gpio_get_value(gpio))
-
-static inline void __gpio_set_value(unsigned gpio, int value)
+static inline void gpio_set_value(unsigned gpio, int value)
 {
-       if (value)
-               GPSR(gpio) = GPIO_bit(gpio);
-       else
-               GPCR(gpio) = GPIO_bit(gpio);
+       if (__builtin_constant_p(gpio) && (gpio < NR_BUILTIN_GPIO)) {
+               if (value)
+                       GPSR(gpio) = GPIO_bit(gpio);
+               else
+                       GPCR(gpio) = GPIO_bit(gpio);
+       } else {
+               __gpio_set_value(gpio, value);
+       }
 }
 
-#define gpio_set_value(gpio,value)             \
-       (__builtin_constant_p(gpio) ?           \
-        __gpio_set_value(gpio, value) :        \
-        pxa_gpio_set_value(gpio, value))
-
-#include <asm-generic/gpio.h>                  /* cansleep wrappers */
+#define gpio_cansleep __gpio_cansleep
 
 #define gpio_to_irq(gpio)      IRQ_GPIO(gpio)
 #define irq_to_gpio(irq)       IRQ_TO_GPIO(irq)
index 442494d71f12d38ff4dfefb8b5e9246447b73201..ac175b4d10cbfa859880be062163be2526eaab4c 100644 (file)
 
 #define USIR0          __REG(0x40600058)  /* UDC Status Interrupt Register 0 */
 
-#define USIR0_IR0      (1 << 0)        /* Interrup request ep 0 */
-#define USIR0_IR1      (1 << 1)        /* Interrup request ep 1 */
-#define USIR0_IR2      (1 << 2)        /* Interrup request ep 2 */
-#define USIR0_IR3      (1 << 3)        /* Interrup request ep 3 */
-#define USIR0_IR4      (1 << 4)        /* Interrup request ep 4 */
-#define USIR0_IR5      (1 << 5)        /* Interrup request ep 5 */
-#define USIR0_IR6      (1 << 6)        /* Interrup request ep 6 */
-#define USIR0_IR7      (1 << 7)        /* Interrup request ep 7 */
+#define USIR0_IR0      (1 << 0)        /* Interrupt request ep 0 */
+#define USIR0_IR1      (1 << 1)        /* Interrupt request ep 1 */
+#define USIR0_IR2      (1 << 2)        /* Interrupt request ep 2 */
+#define USIR0_IR3      (1 << 3)        /* Interrupt request ep 3 */
+#define USIR0_IR4      (1 << 4)        /* Interrupt request ep 4 */
+#define USIR0_IR5      (1 << 5)        /* Interrupt request ep 5 */
+#define USIR0_IR6      (1 << 6)        /* Interrupt request ep 6 */
+#define USIR0_IR7      (1 << 7)        /* Interrupt request ep 7 */
 
 #define USIR1          __REG(0x4060005C)  /* UDC Status Interrupt Register 1 */
 
-#define USIR1_IR8      (1 << 0)        /* Interrup request ep 8 */
-#define USIR1_IR9      (1 << 1)        /* Interrup request ep 9 */
-#define USIR1_IR10     (1 << 2)        /* Interrup request ep 10 */
-#define USIR1_IR11     (1 << 3)        /* Interrup request ep 11 */
-#define USIR1_IR12     (1 << 4)        /* Interrup request ep 12 */
-#define USIR1_IR13     (1 << 5)        /* Interrup request ep 13 */
-#define USIR1_IR14     (1 << 6)        /* Interrup request ep 14 */
-#define USIR1_IR15     (1 << 7)        /* Interrup request ep 15 */
+#define USIR1_IR8      (1 << 0)        /* Interrupt request ep 8 */
+#define USIR1_IR9      (1 << 1)        /* Interrupt request ep 9 */
+#define USIR1_IR10     (1 << 2)        /* Interrupt request ep 10 */
+#define USIR1_IR11     (1 << 3)        /* Interrupt request ep 11 */
+#define USIR1_IR12     (1 << 4)        /* Interrupt request ep 12 */
+#define USIR1_IR13     (1 << 5)        /* Interrupt request ep 13 */
+#define USIR1_IR14     (1 << 6)        /* Interrupt request ep 14 */
+#define USIR1_IR15     (1 << 7)        /* Interrupt request ep 15 */
 
 #elif defined(CONFIG_PXA27x)
 
 #define ICSR0          __REG(0x40800014)  /* ICP Status Register 0 */
 #define ICSR1          __REG(0x40800018)  /* ICP Status Register 1 */
 
-#define ICCR0_AME      (1 << 7)        /* Adress match enable */
+#define ICCR0_AME      (1 << 7)        /* Address match enable */
 #define ICCR0_TIE      (1 << 6)        /* Transmit FIFO interrupt enable */
 #define ICCR0_RIE      (1 << 5)        /* Recieve FIFO interrupt enable */
 #define ICCR0_RXE      (1 << 4)        /* Receive enable */
  * General Purpose I/O
  */
 
+#define GPIO0_BASE     ((void __iomem *)io_p2v(0x40E00000))
+#define GPIO1_BASE     ((void __iomem *)io_p2v(0x40E00004))
+#define GPIO2_BASE     ((void __iomem *)io_p2v(0x40E00008))
+#define GPIO3_BASE     ((void __iomem *)io_p2v(0x40E00100))
+
+#define GPLR_OFFSET    0x00
+#define GPDR_OFFSET    0x0C
+#define GPSR_OFFSET    0x18
+#define GPCR_OFFSET    0x24
+#define GRER_OFFSET    0x30
+#define GFER_OFFSET    0x3C
+#define GEDR_OFFSET    0x48
+
 #define GPLR0          __REG(0x40E00000)  /* GPIO Pin-Level Register GPIO<31:0> */
 #define GPLR1          __REG(0x40E00004)  /* GPIO Pin-Level Register GPIO<63:32> */
 #define GPLR2          __REG(0x40E00008)  /* GPIO Pin-Level Register GPIO<80:64> */
index 66d54119757cb665a9a3af08b5afb1c8028d4d73..8e1b3ead827fc017fa35c7e09ad3e2681845c544 100644 (file)
 
 #ifndef __ASM_ARCH_PXA3XX_REGS_H
 #define __ASM_ARCH_PXA3XX_REGS_H
+/*
+ * Service Power Management Unit (MPMU)
+ */
+#define PMCR           __REG(0x40F50000)       /* Power Manager Control Register */
+#define PSR            __REG(0x40F50004)       /* Power Manager S2 Status Register */
+#define PSPR           __REG(0x40F50008)       /* Power Manager Scratch Pad Register */
+#define PCFR           __REG(0x40F5000C)       /* Power Manager General Configuration Register */
+#define PWER           __REG(0x40F50010)       /* Power Manager Wake-up Enable Register */
+#define PWSR           __REG(0x40F50014)       /* Power Manager Wake-up Status Register */
+#define PECR           __REG(0x40F50018)       /* Power Manager EXT_WAKEUP[1:0] Control Register */
+#define DCDCSR         __REG(0x40F50080)       /* DC-DC Controller Status Register */
+#define PVCR           __REG(0x40F50100)       /* Power Manager Voltage Change Control Register */
+#define PCMD(x)                __REG(0x40F50110 + ((x) << 2))
 
 /*
  * Slave Power Managment Unit
diff --git a/include/asm-arm/arch-realview/board-eb.h b/include/asm-arm/arch-realview/board-eb.h
new file mode 100644 (file)
index 0000000..3e437b7
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * include/asm-arm/arch-realview/board-eb.h
+ *
+ * Copyright (C) 2007 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef __ASM_ARCH_BOARD_EB_H
+#define __ASM_ARCH_BOARD_EB_H
+
+#include <asm/arch/platform.h>
+
+/*
+ * RealView EB + ARM11MPCore peripheral addresses
+ */
+#ifdef CONFIG_REALVIEW_EB_ARM11MP_REVB
+#define REALVIEW_EB11MP_SCU_BASE       0x10100000      /* SCU registers */
+#define REALVIEW_EB11MP_GIC_CPU_BASE   0x10100100      /* Generic interrupt controller CPU interface */
+#define REALVIEW_EB11MP_TWD_BASE       0x10100700
+#define REALVIEW_EB11MP_TWD_SIZE       0x00000100
+#define REALVIEW_EB11MP_GIC_DIST_BASE  0x10101000      /* Generic interrupt controller distributor */
+#define REALVIEW_EB11MP_L220_BASE      0x10102000      /* L220 registers */
+#define REALVIEW_EB11MP_SYS_PLD_CTRL1  0xD8            /* Register offset for MPCore sysctl */
+#else
+#define REALVIEW_EB11MP_SCU_BASE       0x1F000000      /* SCU registers */
+#define REALVIEW_EB11MP_GIC_CPU_BASE   0x1F000100      /* Generic interrupt controller CPU interface */
+#define REALVIEW_EB11MP_TWD_BASE       0x1F000700
+#define REALVIEW_EB11MP_TWD_SIZE       0x00000100
+#define REALVIEW_EB11MP_GIC_DIST_BASE  0x1F001000      /* Generic interrupt controller distributor */
+#define REALVIEW_EB11MP_L220_BASE      0x1F002000      /* L220 registers */
+#define REALVIEW_EB11MP_SYS_PLD_CTRL1  0x74            /* Register offset for MPCore sysctl */
+#endif
+
+#define IRQ_EB_GIC_START       32
+
+/*
+ * RealView EB interrupt sources
+ */
+#define IRQ_EB_WDOG            (IRQ_EB_GIC_START + 0)          /* Watchdog timer */
+#define IRQ_EB_SOFT            (IRQ_EB_GIC_START + 1)          /* Software interrupt */
+#define IRQ_EB_COMMRx          (IRQ_EB_GIC_START + 2)          /* Debug Comm Rx interrupt */
+#define IRQ_EB_COMMTx          (IRQ_EB_GIC_START + 3)          /* Debug Comm Tx interrupt */
+#define IRQ_EB_TIMER0_1                (IRQ_EB_GIC_START + 4)          /* Timer 0 and 1 */
+#define IRQ_EB_TIMER2_3                (IRQ_EB_GIC_START + 5)          /* Timer 2 and 3 */
+#define IRQ_EB_GPIO0           (IRQ_EB_GIC_START + 6)          /* GPIO 0 */
+#define IRQ_EB_GPIO1           (IRQ_EB_GIC_START + 7)          /* GPIO 1 */
+#define IRQ_EB_GPIO2           (IRQ_EB_GIC_START + 8)          /* GPIO 2 */
+                                                               /* 9 reserved */
+#define IRQ_EB_RTC             (IRQ_EB_GIC_START + 10)         /* Real Time Clock */
+#define IRQ_EB_SSP             (IRQ_EB_GIC_START + 11)         /* Synchronous Serial Port */
+#define IRQ_EB_UART0           (IRQ_EB_GIC_START + 12)         /* UART 0 on development chip */
+#define IRQ_EB_UART1           (IRQ_EB_GIC_START + 13)         /* UART 1 on development chip */
+#define IRQ_EB_UART2           (IRQ_EB_GIC_START + 14)         /* UART 2 on development chip */
+#define IRQ_EB_UART3           (IRQ_EB_GIC_START + 15)         /* UART 3 on development chip */
+#define IRQ_EB_SCI             (IRQ_EB_GIC_START + 16)         /* Smart Card Interface */
+#define IRQ_EB_MMCI0A          (IRQ_EB_GIC_START + 17)         /* Multimedia Card 0A */
+#define IRQ_EB_MMCI0B          (IRQ_EB_GIC_START + 18)         /* Multimedia Card 0B */
+#define IRQ_EB_AACI            (IRQ_EB_GIC_START + 19)         /* Audio Codec */
+#define IRQ_EB_KMI0            (IRQ_EB_GIC_START + 20)         /* Keyboard/Mouse port 0 */
+#define IRQ_EB_KMI1            (IRQ_EB_GIC_START + 21)         /* Keyboard/Mouse port 1 */
+#define IRQ_EB_CHARLCD         (IRQ_EB_GIC_START + 22)         /* Character LCD */
+#define IRQ_EB_CLCD            (IRQ_EB_GIC_START + 23)         /* CLCD controller */
+#define IRQ_EB_DMA             (IRQ_EB_GIC_START + 24)         /* DMA controller */
+#define IRQ_EB_PWRFAIL         (IRQ_EB_GIC_START + 25)         /* Power failure */
+#define IRQ_EB_PISMO           (IRQ_EB_GIC_START + 26)         /* PISMO interface */
+#define IRQ_EB_DoC             (IRQ_EB_GIC_START + 27)         /* Disk on Chip memory controller */
+#define IRQ_EB_ETH             (IRQ_EB_GIC_START + 28)         /* Ethernet controller */
+#define IRQ_EB_USB             (IRQ_EB_GIC_START + 29)         /* USB controller */
+#define IRQ_EB_TSPEN           (IRQ_EB_GIC_START + 30)         /* Touchscreen pen */
+#define IRQ_EB_TSKPAD          (IRQ_EB_GIC_START + 31)         /* Touchscreen keypad */
+
+/*
+ * RealView EB + ARM11MPCore interrupt sources (primary GIC on the core tile)
+ */
+#define IRQ_EB11MP_AACI                (IRQ_EB_GIC_START + 0)
+#define IRQ_EB11MP_TIMER0_1    (IRQ_EB_GIC_START + 1)
+#define IRQ_EB11MP_TIMER2_3    (IRQ_EB_GIC_START + 2)
+#define IRQ_EB11MP_USB         (IRQ_EB_GIC_START + 3)
+#define IRQ_EB11MP_UART0       (IRQ_EB_GIC_START + 4)
+#define IRQ_EB11MP_UART1       (IRQ_EB_GIC_START + 5)
+#define IRQ_EB11MP_RTC         (IRQ_EB_GIC_START + 6)
+#define IRQ_EB11MP_KMI0                (IRQ_EB_GIC_START + 7)
+#define IRQ_EB11MP_KMI1                (IRQ_EB_GIC_START + 8)
+#define IRQ_EB11MP_ETH         (IRQ_EB_GIC_START + 9)
+#define IRQ_EB11MP_EB_IRQ1     (IRQ_EB_GIC_START + 10)         /* main GIC */
+#define IRQ_EB11MP_EB_IRQ2     (IRQ_EB_GIC_START + 11)         /* tile GIC */
+#define IRQ_EB11MP_EB_FIQ1     (IRQ_EB_GIC_START + 12)         /* main GIC */
+#define IRQ_EB11MP_EB_FIQ2     (IRQ_EB_GIC_START + 13)         /* tile GIC */
+#define IRQ_EB11MP_MMCI0A      (IRQ_EB_GIC_START + 14)
+#define IRQ_EB11MP_MMCI0B      (IRQ_EB_GIC_START + 15)
+
+#define IRQ_EB11MP_PMU_CPU0    (IRQ_EB_GIC_START + 17)
+#define IRQ_EB11MP_PMU_CPU1    (IRQ_EB_GIC_START + 18)
+#define IRQ_EB11MP_PMU_CPU2    (IRQ_EB_GIC_START + 19)
+#define IRQ_EB11MP_PMU_CPU3    (IRQ_EB_GIC_START + 20)
+#define IRQ_EB11MP_PMU_SCU0    (IRQ_EB_GIC_START + 21)
+#define IRQ_EB11MP_PMU_SCU1    (IRQ_EB_GIC_START + 22)
+#define IRQ_EB11MP_PMU_SCU2    (IRQ_EB_GIC_START + 23)
+#define IRQ_EB11MP_PMU_SCU3    (IRQ_EB_GIC_START + 24)
+#define IRQ_EB11MP_PMU_SCU4    (IRQ_EB_GIC_START + 25)
+#define IRQ_EB11MP_PMU_SCU5    (IRQ_EB_GIC_START + 26)
+#define IRQ_EB11MP_PMU_SCU6    (IRQ_EB_GIC_START + 27)
+#define IRQ_EB11MP_PMU_SCU7    (IRQ_EB_GIC_START + 28)
+
+#define IRQ_EB11MP_L220_EVENT  (IRQ_EB_GIC_START + 29)
+#define IRQ_EB11MP_L220_SLAVE  (IRQ_EB_GIC_START + 30)
+#define IRQ_EB11MP_L220_DECODE (IRQ_EB_GIC_START + 31)
+
+#define IRQ_EB11MP_UART2       -1
+#define IRQ_EB11MP_UART3       -1
+#define IRQ_EB11MP_CLCD                -1
+#define IRQ_EB11MP_DMA         -1
+#define IRQ_EB11MP_WDOG                -1
+#define IRQ_EB11MP_GPIO0       -1
+#define IRQ_EB11MP_GPIO1       -1
+#define IRQ_EB11MP_GPIO2       -1
+#define IRQ_EB11MP_SCI         -1
+#define IRQ_EB11MP_SSP         -1
+
+#define NR_GIC_EB11MP          2
+
+/*
+ * Only define NR_IRQS if less than NR_IRQS_EB
+ */
+#define NR_IRQS_EB             (IRQ_EB_GIC_START + 96)
+
+#if defined(CONFIG_MACH_REALVIEW_EB) \
+       && (!defined(NR_IRQS) || (NR_IRQS < NR_IRQS_EB))
+#undef NR_IRQS
+#define NR_IRQS                        NR_IRQS_EB
+#endif
+
+#if defined(CONFIG_REALVIEW_EB_ARM11MP) \
+       && (!defined(MAX_GIC_NR) || (MAX_GIC_NR < NR_GIC_EB11MP))
+#undef MAX_GIC_NR
+#define MAX_GIC_NR             NR_GIC_EB11MP
+#endif
+
+/*
+ * Core tile identification (REALVIEW_SYS_PROCID)
+ */
+#define REALVIEW_EB_PROC_MASK          0xFF000000
+#define REALVIEW_EB_PROC_ARM7TDMI      0x00000000
+#define REALVIEW_EB_PROC_ARM9          0x02000000
+#define REALVIEW_EB_PROC_ARM11         0x04000000
+#define REALVIEW_EB_PROC_ARM11MP       0x06000000
+
+#define check_eb_proc(proc_type)                                               \
+       ((readl(__io_address(REALVIEW_SYS_PROCID)) & REALVIEW_EB_PROC_MASK)     \
+        == proc_type)
+
+#ifdef CONFIG_REALVIEW_EB_ARM11MP
+#define core_tile_eb11mp()     check_eb_proc(REALVIEW_EB_PROC_ARM11MP)
+#else
+#define core_tile_eb11mp()     0
+#endif
+
+#endif /* __ASM_ARCH_BOARD_EB_H */
index 3b4e2076603a5e23eb97f68f20c307ffd2d7384e..cd26306d8e57f8d2ecff1361ece23315485473d8 100644 (file)
@@ -14,7 +14,8 @@
                .endm
 
                .macro  get_irqnr_preamble, base, tmp
-               ldr     \base, =IO_ADDRESS(REALVIEW_GIC_CPU_BASE)
+               ldr     \base, =gic_cpu_base_addr
+               ldr     \base, [\base]
                .endm
 
                .macro  arch_ret_to_user, tmp1, tmp2
index aa78fe087ab2a39cf9ed841aac5e97f42e318ab1..bad8d7ce9bfe480e30b69c15dbfc75dfaf489cd0 100644 (file)
@@ -23,7 +23,6 @@
 #define __ASM_ARCH_HARDWARE_H
 
 #include <asm/sizes.h>
-#include <asm/arch/platform.h>
 
 /* macro to get at IO space when running virtually */
 #define IO_ADDRESS(x)          ((((x) & 0x0effffff) | (((x) >> 4) & 0x0f000000)) + 0xf0000000)
index 5a5db56f86b8cd9a712dc31fc8b630c4cf075e4f..ad0c911002fc29ddcfd0449c14cfa38ab9a49e36 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <asm/arch/platform.h>
+#ifndef __ASM_ARCH_IRQS_H
+#define __ASM_ARCH_IRQS_H
 
-#define IRQ_LOCALTIMER                 29
-#define IRQ_LOCALWDOG                  30
+#include <asm/arch/board-eb.h>
 
-/* 
- *  IRQ interrupts definitions are the same the INT definitions
- *  held within platform.h
- */
-#define IRQ_GIC_START          32
-#define IRQ_WDOGINT            (IRQ_GIC_START + INT_WDOGINT)
-#define IRQ_SOFTINT            (IRQ_GIC_START + INT_SOFTINT)
-#define IRQ_COMMRx             (IRQ_GIC_START + INT_COMMRx)
-#define IRQ_COMMTx             (IRQ_GIC_START + INT_COMMTx)
-#define IRQ_TIMERINT0_1                (IRQ_GIC_START + INT_TIMERINT0_1)
-#define IRQ_TIMERINT2_3                (IRQ_GIC_START + INT_TIMERINT2_3)
-#define IRQ_GPIOINT0           (IRQ_GIC_START + INT_GPIOINT0)
-#define IRQ_GPIOINT1           (IRQ_GIC_START + INT_GPIOINT1)
-#define IRQ_GPIOINT2           (IRQ_GIC_START + INT_GPIOINT2)
-#define IRQ_GPIOINT3           (IRQ_GIC_START + INT_GPIOINT3)
-#define IRQ_RTCINT             (IRQ_GIC_START + INT_RTCINT)
-#define IRQ_SSPINT             (IRQ_GIC_START + INT_SSPINT)
-#define IRQ_UARTINT0           (IRQ_GIC_START + INT_UARTINT0)
-#define IRQ_UARTINT1           (IRQ_GIC_START + INT_UARTINT1)
-#define IRQ_UARTINT2           (IRQ_GIC_START + INT_UARTINT2)
-#define IRQ_UART3              (IRQ_GIC_START + INT_UARTINT3)
-#define IRQ_SCIINT             (IRQ_GIC_START + INT_SCIINT)
-#define IRQ_CLCDINT            (IRQ_GIC_START + INT_CLCDINT)
-#define IRQ_DMAINT             (IRQ_GIC_START + INT_DMAINT)
-#define IRQ_PWRFAILINT                 (IRQ_GIC_START + INT_PWRFAILINT)
-#define IRQ_MBXINT             (IRQ_GIC_START + INT_MBXINT)
-#define IRQ_GNDINT             (IRQ_GIC_START + INT_GNDINT)
-#define IRQ_MMCI0B             (IRQ_GIC_START + INT_MMCI0B)
-#define IRQ_MMCI1B             (IRQ_GIC_START + INT_MMCI1B)
-#define IRQ_KMI0               (IRQ_GIC_START + INT_KMI0)
-#define IRQ_KMI1               (IRQ_GIC_START + INT_KMI1)
-#define IRQ_SCI3               (IRQ_GIC_START + INT_SCI3)
-#define IRQ_CLCD               (IRQ_GIC_START + INT_CLCD)
-#define IRQ_TOUCH              (IRQ_GIC_START + INT_TOUCH)
-#define IRQ_KEYPAD             (IRQ_GIC_START + INT_KEYPAD)
-#define IRQ_DoC                        (IRQ_GIC_START + INT_DoC)
-#define IRQ_MMCI0A             (IRQ_GIC_START + INT_MMCI0A)
-#define IRQ_MMCI1A             (IRQ_GIC_START + INT_MMCI1A)
-#define IRQ_AACI               (IRQ_GIC_START + INT_AACI)
-#define IRQ_ETH                        (IRQ_GIC_START + INT_ETH)
-#define IRQ_USB                        (IRQ_GIC_START + INT_USB)
-#define IRQ_PMU_CPU0           (IRQ_GIC_START + INT_PMU_CPU0)
-#define IRQ_PMU_CPU1           (IRQ_GIC_START + INT_PMU_CPU1)
-#define IRQ_PMU_CPU2           (IRQ_GIC_START + INT_PMU_CPU2)
-#define IRQ_PMU_CPU3           (IRQ_GIC_START + INT_PMU_CPU3)
-#define IRQ_PMU_SCU0           (IRQ_GIC_START + INT_PMU_SCU0)
-#define IRQ_PMU_SCU1           (IRQ_GIC_START + INT_PMU_SCU1)
-#define IRQ_PMU_SCU2           (IRQ_GIC_START + INT_PMU_SCU2)
-#define IRQ_PMU_SCU3           (IRQ_GIC_START + INT_PMU_SCU3)
-#define IRQ_PMU_SCU4           (IRQ_GIC_START + INT_PMU_SCU4)
-#define IRQ_PMU_SCU5           (IRQ_GIC_START + INT_PMU_SCU5)
-#define IRQ_PMU_SCU6           (IRQ_GIC_START + INT_PMU_SCU6)
-#define IRQ_PMU_SCU7           (IRQ_GIC_START + INT_PMU_SCU7)
+#define IRQ_LOCALTIMER         29
+#define IRQ_LOCALWDOG          30
 
-#define IRQ_EB_IRQ1            (IRQ_GIC_START + INT_EB_IRQ1)
-#define IRQ_EB_IRQ2            (IRQ_GIC_START + INT_EB_IRQ2)
+#define IRQ_GIC_START          32
 
-#define IRQMASK_WDOGINT                INTMASK_WDOGINT
-#define IRQMASK_SOFTINT                INTMASK_SOFTINT
-#define IRQMASK_COMMRx                 INTMASK_COMMRx
-#define IRQMASK_COMMTx                 INTMASK_COMMTx
-#define IRQMASK_TIMERINT0_1    INTMASK_TIMERINT0_1
-#define IRQMASK_TIMERINT2_3    INTMASK_TIMERINT2_3
-#define IRQMASK_GPIOINT0       INTMASK_GPIOINT0
-#define IRQMASK_GPIOINT1       INTMASK_GPIOINT1
-#define IRQMASK_GPIOINT2       INTMASK_GPIOINT2
-#define IRQMASK_GPIOINT3       INTMASK_GPIOINT3
-#define IRQMASK_RTCINT                 INTMASK_RTCINT
-#define IRQMASK_SSPINT                 INTMASK_SSPINT
-#define IRQMASK_UARTINT0       INTMASK_UARTINT0
-#define IRQMASK_UARTINT1       INTMASK_UARTINT1
-#define IRQMASK_UARTINT2       INTMASK_UARTINT2
-#define IRQMASK_SCIINT                 INTMASK_SCIINT
-#define IRQMASK_CLCDINT                INTMASK_CLCDINT
-#define IRQMASK_DMAINT                 INTMASK_DMAINT
-#define IRQMASK_PWRFAILINT     INTMASK_PWRFAILINT
-#define IRQMASK_MBXINT                 INTMASK_MBXINT
-#define IRQMASK_GNDINT                 INTMASK_GNDINT
-#define IRQMASK_MMCI0B         INTMASK_MMCI0B
-#define IRQMASK_MMCI1B         INTMASK_MMCI1B
-#define IRQMASK_KMI0           INTMASK_KMI0
-#define IRQMASK_KMI1           INTMASK_KMI1
-#define IRQMASK_SCI3           INTMASK_SCI3
-#define IRQMASK_UART3          INTMASK_UART3
-#define IRQMASK_CLCD           INTMASK_CLCD
-#define IRQMASK_TOUCH          INTMASK_TOUCH
-#define IRQMASK_KEYPAD         INTMASK_KEYPAD
-#define IRQMASK_DoC            INTMASK_DoC
-#define IRQMASK_MMCI0A         INTMASK_MMCI0A
-#define IRQMASK_MMCI1A         INTMASK_MMCI1A
-#define IRQMASK_AACI           INTMASK_AACI
-#define IRQMASK_ETH            INTMASK_ETH
-#define IRQMASK_USB            INTMASK_USB
+#ifndef NR_IRQS
+#error "NR_IRQS not defined by the board-specific files"
+#endif
 
-#define NR_IRQS                        (IRQ_GIC_START + 96)
+#endif
index 6e0eab95a3a2ed3b8de1a0ae9044e5bc78c193c9..4fd351b5e4a2172a325e0edb45be7de43e68c0cb 100644 (file)
@@ -18,8 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef __address_h
-#define __address_h                     1
+#ifndef __ASM_ARCH_PLATFORM_H
+#define __ASM_ARCH_PLATFORM_H
 
 /*
  * Memory definitions
 #define REALVIEW_SYS_24MHz_OFFSET            0x5C
 #define REALVIEW_SYS_MISC_OFFSET             0x60
 #define REALVIEW_SYS_IOSEL_OFFSET            0x70
-#define REALVIEW_SYS_TEST_OSC0_OFFSET        0x80
-#define REALVIEW_SYS_TEST_OSC1_OFFSET        0x84
-#define REALVIEW_SYS_TEST_OSC2_OFFSET        0x88
-#define REALVIEW_SYS_TEST_OSC3_OFFSET        0x8C
-#define REALVIEW_SYS_TEST_OSC4_OFFSET        0x90
+#define REALVIEW_SYS_PROCID_OFFSET           0x84
+#define REALVIEW_SYS_TEST_OSC0_OFFSET        0xC0
+#define REALVIEW_SYS_TEST_OSC1_OFFSET        0xC4
+#define REALVIEW_SYS_TEST_OSC2_OFFSET        0xC8
+#define REALVIEW_SYS_TEST_OSC3_OFFSET        0xCC
+#define REALVIEW_SYS_TEST_OSC4_OFFSET        0xD0
 
 #define REALVIEW_SYS_BASE                    0x10000000
 #define REALVIEW_SYS_ID                      (REALVIEW_SYS_BASE + REALVIEW_SYS_ID_OFFSET)
 #define REALVIEW_SYS_24MHz                   (REALVIEW_SYS_BASE + REALVIEW_SYS_24MHz_OFFSET)
 #define REALVIEW_SYS_MISC                    (REALVIEW_SYS_BASE + REALVIEW_SYS_MISC_OFFSET)
 #define REALVIEW_SYS_IOSEL                   (REALVIEW_SYS_BASE + REALVIEW_SYS_IOSEL_OFFSET)
+#define REALVIEW_SYS_PROCID                  (REALVIEW_SYS_BASE + REALVIEW_SYS_PROCID_OFFSET)
 #define REALVIEW_SYS_TEST_OSC0               (REALVIEW_SYS_BASE + REALVIEW_SYS_TEST_OSC0_OFFSET)
 #define REALVIEW_SYS_TEST_OSC1               (REALVIEW_SYS_BASE + REALVIEW_SYS_TEST_OSC1_OFFSET)
 #define REALVIEW_SYS_TEST_OSC2               (REALVIEW_SYS_BASE + REALVIEW_SYS_TEST_OSC2_OFFSET)
        /* Reserved 0x1001A000 - 0x1001FFFF */
 #define REALVIEW_CLCD_BASE            0x10020000       /* CLCD */
 #define REALVIEW_DMAC_BASE            0x10030000       /* DMA controller */
-#ifndef CONFIG_REALVIEW_MPCORE
 #define REALVIEW_GIC_CPU_BASE         0x10040000       /* Generic interrupt controller CPU interface */
 #define REALVIEW_GIC_DIST_BASE        0x10041000       /* Generic interrupt controller distributor */
-#else
-#ifdef CONFIG_REALVIEW_MPCORE_REVB
-#define REALVIEW_MPCORE_SCU_BASE       0x10100000      /*  SCU registers */
-#define REALVIEW_GIC_CPU_BASE          0x10100100      /* Generic interrupt controller CPU interface */
-#define REALVIEW_TWD_BASE              0x10100700
-#define REALVIEW_TWD_SIZE              0x00000100
-#define REALVIEW_GIC_DIST_BASE         0x10101000      /* Generic interrupt controller distributor */
-#define REALVIEW_MPCORE_L220_BASE      0x10102000      /* L220 registers */
-#define REALVIEW_MPCORE_SYS_PLD_CTRL1 0xD8             /*  Register offset for MPCore sysctl */
-#else
-#define REALVIEW_MPCORE_SCU_BASE      0x1F000000       /*  SCU registers */
-#define REALVIEW_GIC_CPU_BASE         0x1F000100       /* Generic interrupt controller CPU interface */
-#define REALVIEW_TWD_BASE             0x1F000700
-#define REALVIEW_TWD_SIZE             0x00000100
-#define REALVIEW_GIC_DIST_BASE        0x1F001000       /* Generic interrupt controller distributor */
-#define REALVIEW_MPCORE_L220_BASE     0x1F002000       /* L220 registers */
-#define REALVIEW_MPCORE_SYS_PLD_CTRL1 0x74             /*  Register offset for MPCore sysctl */
-#endif
-#define REALVIEW_GIC1_CPU_BASE        0x10040000       /* Generic interrupt controller CPU interface */
-#define REALVIEW_GIC1_DIST_BASE       0x10041000       /* Generic interrupt controller distributor */
-#endif
 #define REALVIEW_SMC_BASE             0x10080000       /* SMC */
        /* Reserved 0x10090000 - 0x100EFFFF */
 
 #define REALVIEW_INTREG_OFFSET         0x8     /* Interrupt control */
 #define REALVIEW_DECODE_OFFSET         0xC     /* Fitted logic modules */
 
-/* ------------------------------------------------------------------------
- *  Interrupts - bit assignment (primary)
- * ------------------------------------------------------------------------
- */
-#ifndef CONFIG_REALVIEW_MPCORE
-#define INT_WDOGINT                    0       /* Watchdog timer */
-#define INT_SOFTINT                    1       /* Software interrupt */
-#define INT_COMMRx                     2       /* Debug Comm Rx interrupt */
-#define INT_COMMTx                     3       /* Debug Comm Tx interrupt */
-#define INT_TIMERINT0_1                        4       /* Timer 0 and 1 */
-#define INT_TIMERINT2_3                        5       /* Timer 2 and 3 */
-#define INT_GPIOINT0                   6       /* GPIO 0 */
-#define INT_GPIOINT1                   7       /* GPIO 1 */
-#define INT_GPIOINT2                   8       /* GPIO 2 */
-/* 9 reserved */
-#define INT_RTCINT                     10      /* Real Time Clock */
-#define INT_SSPINT                     11      /* Synchronous Serial Port */
-#define INT_UARTINT0                   12      /* UART 0 on development chip */
-#define INT_UARTINT1                   13      /* UART 1 on development chip */
-#define INT_UARTINT2                   14      /* UART 2 on development chip */
-#define INT_UARTINT3                   15      /* UART 3 on development chip */
-#define INT_SCIINT                     16      /* Smart Card Interface */
-#define INT_MMCI0A                     17      /* Multimedia Card 0A */
-#define INT_MMCI0B                     18      /* Multimedia Card 0B */
-#define INT_AACI                       19      /* Audio Codec */
-#define INT_KMI0                       20      /* Keyboard/Mouse port 0 */
-#define INT_KMI1                       21      /* Keyboard/Mouse port 1 */
-#define INT_CHARLCD                    22      /* Character LCD */
-#define INT_CLCDINT                    23      /* CLCD controller */
-#define INT_DMAINT                     24      /* DMA controller */
-#define INT_PWRFAILINT                 25      /* Power failure */
-#define INT_PISMO                      26
-#define INT_DoC                                27      /* Disk on Chip memory controller */
-#define INT_ETH                                28      /* Ethernet controller */
-#define INT_USB                                29      /* USB controller */
-#define INT_TSPENINT                   30      /* Touchscreen pen */
-#define INT_TSKPADINT                  31      /* Touchscreen keypad */
-
-#else
-
-#define MAX_GIC_NR                     2
-
-#define INT_AACI                       0
-#define INT_TIMERINT0_1                        1
-#define INT_TIMERINT2_3                        2
-#define INT_USB                                3
-#define INT_UARTINT0                   4
-#define INT_UARTINT1                   5
-#define INT_RTCINT                     6
-#define INT_KMI0                       7
-#define INT_KMI1                       8
-#define INT_ETH                                9
-#define INT_EB_IRQ1                    10      /* main GIC */
-#define INT_EB_IRQ2                    11      /* tile GIC */
-#define INT_EB_FIQ1                    12      /* main GIC */
-#define INT_EB_FIQ2                    13      /* tile GIC */
-#define INT_MMCI0A                     14
-#define INT_MMCI0B                     15
-
-#define INT_PMU_CPU0                   17
-#define INT_PMU_CPU1                   18
-#define INT_PMU_CPU2                   19
-#define INT_PMU_CPU3                   20
-#define INT_PMU_SCU0                   21
-#define INT_PMU_SCU1                   22
-#define INT_PMU_SCU2                   23
-#define INT_PMU_SCU3                   24
-#define INT_PMU_SCU4                   25
-#define INT_PMU_SCU5                   26
-#define INT_PMU_SCU6                   27
-#define INT_PMU_SCU7                   28
-
-#define INT_L220_EVENT                 29
-#define INT_L220_SLAVE                 30
-#define INT_L220_DECODE                        31
-
-#define INT_UARTINT2                   -1
-#define INT_UARTINT3                   -1
-#define INT_CLCDINT                    -1
-#define INT_DMAINT                     -1
-#define INT_WDOGINT                    -1
-#define INT_GPIOINT0                   -1
-#define INT_GPIOINT1                   -1
-#define INT_GPIOINT2                   -1
-#define INT_SCIINT                     -1
-#define INT_SSPINT                     -1
-#endif
-
-/* 
- *  Interrupt bit positions
- * 
- */
-#define INTMASK_WDOGINT                        (1 << INT_WDOGINT)
-#define INTMASK_SOFTINT                        (1 << INT_SOFTINT)
-#define INTMASK_COMMRx                 (1 << INT_COMMRx)
-#define INTMASK_COMMTx                 (1 << INT_COMMTx)
-#define INTMASK_TIMERINT0_1            (1 << INT_TIMERINT0_1)
-#define INTMASK_TIMERINT2_3            (1 << INT_TIMERINT2_3)
-#define INTMASK_GPIOINT0               (1 << INT_GPIOINT0)
-#define INTMASK_GPIOINT1               (1 << INT_GPIOINT1)
-#define INTMASK_GPIOINT2               (1 << INT_GPIOINT2)
-#define INTMASK_RTCINT                 (1 << INT_RTCINT)
-#define INTMASK_SSPINT                 (1 << INT_SSPINT)
-#define INTMASK_UARTINT0               (1 << INT_UARTINT0)
-#define INTMASK_UARTINT1               (1 << INT_UARTINT1)
-#define INTMASK_UARTINT2               (1 << INT_UARTINT2)
-#define INTMASK_UARTINT3               (1 << INT_UARTINT3)
-#define INTMASK_SCIINT                 (1 << INT_SCIINT)
-#define INTMASK_MMCI0A                 (1 << INT_MMCI0A)
-#define INTMASK_MMCI0B                 (1 << INT_MMCI0B)
-#define INTMASK_AACI                   (1 << INT_AACI)
-#define INTMASK_KMI0                   (1 << INT_KMI0)
-#define INTMASK_KMI1                   (1 << INT_KMI1)
-#define INTMASK_CHARLCD                        (1 << INT_CHARLCD)
-#define INTMASK_CLCDINT                        (1 << INT_CLCDINT)
-#define INTMASK_DMAINT                 (1 << INT_DMAINT)
-#define INTMASK_PWRFAILINT             (1 << INT_PWRFAILINT)
-#define INTMASK_PISMO                  (1 << INT_PISMO)
-#define INTMASK_DoC                    (1 << INT_DoC)
-#define INTMASK_ETH                    (1 << INT_ETH)
-#define INTMASK_USB                    (1 << INT_USB)
-#define INTMASK_TSPENINT               (1 << INT_TSPENINT)
-#define INTMASK_TSKPADINT              (1 << INT_TSKPADINT)
-
-#define MAXIRQNUM                       31
-#define MAXFIQNUM                       31
-#define MAXSWINUM                       31
-
 /* 
  *  Application Flash
  * 
 #define REALVIEW_CSR_BASE             0x10000000
 #define REALVIEW_CSR_SIZE             0x10000000
 
-#endif
-
-/*     END */
+#endif /* __ASM_ARCH_PLATFORM_H */
index cc293640178ed02b56673ef183305374f8fbf080..08b3db883c361fb1ad20484d650589b88b146c87 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef __ASMARM_ARCH_SCU_H
 #define __ASMARM_ARCH_SCU_H
 
-#include <asm/arch/platform.h>
+#include <asm/arch/board-eb.h>
 
-#define SCU_BASE       REALVIEW_MPCORE_SCU_BASE
+#define SCU_BASE       REALVIEW_EB11MP_SCU_BASE
 
 #endif
index f05631d767435f2f086c3ead981a95790b19ce08..3d5c2db07a2688c5b564a2ea046dda2e719d8a65 100644 (file)
@@ -19,6 +19,8 @@
  */
 #include <asm/hardware.h>
 
+#include <asm/arch/platform.h>
+
 #define AMBA_UART_DR   (*(volatile unsigned char *) (REALVIEW_UART0_BASE + 0x00))
 #define AMBA_UART_LCRH (*(volatile unsigned char *) (REALVIEW_UART0_BASE + 0x2c))
 #define AMBA_UART_CR   (*(volatile unsigned char *) (REALVIEW_UART0_BASE + 0x30))
index 76fe5f6934267f702341b80ebba58ac7c3857c34..bd854845697f314c11af21af0ae537cf43b0b661 100644 (file)
 
 #define S3C2412_FRCPAT(x)      S3C2410_LCDREG(0xB4 + ((x)*4))
 
-#endif /* ___ASM_ARCH_REGS_LCD_H */
+/* general registers */
+
+/* base of the LCD registers, where INTPND, INTSRC and then INTMSK
+ * are available. */
 
+#define S3C2410_LCDINTBASE     S3C2410_LCDREG(0x54)
+#define S3C2412_LCDINTBASE     S3C2410_LCDREG(0x24)
 
+#define S3C24XX_LCDINTPND      (0x00)
+#define S3C24XX_LCDSRCPND      (0x04)
+#define S3C24XX_LCDINTMSK      (0x08)
 
+#endif /* ___ASM_ARCH_REGS_LCD_H */
index ba1dca88d48069dcb59040001b796c4b6c24399e..73803731142a6928bc44127d506210a61ff79db4 100644 (file)
@@ -13,9 +13,6 @@
 #ifndef __ASM_ARCH_SPIGPIO_H
 #define __ASM_ARCH_SPIGPIO_H __FILE__
 
-struct s3c2410_spigpio_info;
-struct spi_board_info;
-
 struct s3c2410_spigpio_info {
        unsigned long            pin_clk;
        unsigned long            pin_mosi;
@@ -23,9 +20,6 @@ struct s3c2410_spigpio_info {
 
        int                      bus_num;
 
-       unsigned long            board_size;
-       struct spi_board_info   *board_info;
-
        void (*chip_select)(struct s3c2410_spigpio_info *spi, int cs);
 };
 
index 4029a1a1ab406fcaf661f94c8243f15d0269f8c0..7ca0ed97a6d0fd7e457c8b9549ba98c98dbf28b4 100644 (file)
 #ifndef __ASM_ARCH_SPI_H
 #define __ASM_ARCH_SPI_H __FILE__
 
-struct s3c2410_spi_info;
-struct spi_board_info;
-
 struct s3c2410_spi_info {
        unsigned long            pin_cs;        /* simple gpio cs */
 
-       unsigned long            board_size;
-       struct spi_board_info   *board_info;
-
        void (*set_cs)(struct s3c2410_spi_info *spi, int cs, int pol);
 };
 
index 745aa841b31ae8824739edc5678a8b4141650db2..f7263b99403b9b8cfc5cd014300b882a81fd6c28 100644 (file)
@@ -22,7 +22,7 @@
 #include <asm/arch/platform.h>
 
 /* 
- *  IRQ interrupts definitions are the same the INT definitions
+ *  IRQ interrupts definitions are the same as the INT definitions
  *  held within platform.h
  */
 #define IRQ_VIC_START          0
@@ -94,7 +94,7 @@
 #define IRQMASK_VICSOURCE31    INTMASK_VICSOURCE31
 
 /* 
- *  FIQ interrupts definitions are the same the INT definitions.
+ *  FIQ interrupts definitions are the same as the INT definitions.
  */
 #define FIQ_WDOGINT            INT_WDOGINT
 #define FIQ_SOFTINT            INT_SOFTINT
index 131d5b40e072934e2b3cd6a0477f5f6fdfe121da..e521b70713c8cff2f14cd90c00e1b39287291183 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __ASM_HARDWARE_TWD_H
 #define __ASM_HARDWARE_TWD_H
 
-#define TWD_TIMER_LOAD                 0x00
+#define TWD_TIMER_LOAD                         0x00
 #define TWD_TIMER_COUNTER              0x04
 #define TWD_TIMER_CONTROL              0x08
 #define TWD_TIMER_INTSTAT              0x0C
@@ -13,4 +13,9 @@
 #define TWD_WDOG_RESETSTAT             0x30
 #define TWD_WDOG_DISABLE               0x34
 
+#define TWD_TIMER_CONTROL_ENABLE       (1 << 0)
+#define TWD_TIMER_CONTROL_ONESHOT      (0 << 1)
+#define TWD_TIMER_CONTROL_PERIODIC     (1 << 1)
+#define TWD_TIMER_CONTROL_IT_ENABLE    (1 << 2)
+
 #endif
index 10834b54f6816c49431ab5de7b952e7bd2114e08..5c529e6a5e3b6a7c0336ca0b6a205887fb443f55 100644 (file)
@@ -414,7 +414,7 @@ static inline void iop3xx_aau_desc_set_src_addr(struct iop3xx_desc_aau *hw_desc,
 }
 
 static inline void
-iop_desc_init_memcpy(struct iop_adma_desc_slot *desc, int int_en)
+iop_desc_init_memcpy(struct iop_adma_desc_slot *desc, unsigned long flags)
 {
        struct iop3xx_desc_dma *hw_desc = desc->hw_desc;
        union {
@@ -425,14 +425,14 @@ iop_desc_init_memcpy(struct iop_adma_desc_slot *desc, int int_en)
        u_desc_ctrl.value = 0;
        u_desc_ctrl.field.mem_to_mem_en = 1;
        u_desc_ctrl.field.pci_transaction = 0xe; /* memory read block */
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
        hw_desc->upper_pci_src_addr = 0;
        hw_desc->crc_addr = 0;
 }
 
 static inline void
-iop_desc_init_memset(struct iop_adma_desc_slot *desc, int int_en)
+iop_desc_init_memset(struct iop_adma_desc_slot *desc, unsigned long flags)
 {
        struct iop3xx_desc_aau *hw_desc = desc->hw_desc;
        union {
@@ -443,12 +443,13 @@ iop_desc_init_memset(struct iop_adma_desc_slot *desc, int int_en)
        u_desc_ctrl.value = 0;
        u_desc_ctrl.field.blk1_cmd_ctrl = 0x2; /* memory block fill */
        u_desc_ctrl.field.dest_write_en = 1;
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
 }
 
 static inline u32
-iop3xx_desc_init_xor(struct iop3xx_desc_aau *hw_desc, int src_cnt, int int_en)
+iop3xx_desc_init_xor(struct iop3xx_desc_aau *hw_desc, int src_cnt,
+                    unsigned long flags)
 {
        int i, shift;
        u32 edcr;
@@ -509,21 +510,23 @@ iop3xx_desc_init_xor(struct iop3xx_desc_aau *hw_desc, int src_cnt, int int_en)
 
        u_desc_ctrl.field.dest_write_en = 1;
        u_desc_ctrl.field.blk1_cmd_ctrl = 0x7; /* direct fill */
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
 
        return u_desc_ctrl.value;
 }
 
 static inline void
-iop_desc_init_xor(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
+iop_desc_init_xor(struct iop_adma_desc_slot *desc, int src_cnt,
+                 unsigned long flags)
 {
-       iop3xx_desc_init_xor(desc->hw_desc, src_cnt, int_en);
+       iop3xx_desc_init_xor(desc->hw_desc, src_cnt, flags);
 }
 
 /* return the number of operations */
 static inline int
-iop_desc_init_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
+iop_desc_init_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt,
+                      unsigned long flags)
 {
        int slot_cnt = desc->slot_cnt, slots_per_op = desc->slots_per_op;
        struct iop3xx_desc_aau *hw_desc, *prev_hw_desc, *iter;
@@ -538,10 +541,10 @@ iop_desc_init_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
        for (i = 0, j = 0; (slot_cnt -= slots_per_op) >= 0;
                i += slots_per_op, j++) {
                iter = iop_hw_desc_slot_idx(hw_desc, i);
-               u_desc_ctrl.value = iop3xx_desc_init_xor(iter, src_cnt, int_en);
+               u_desc_ctrl.value = iop3xx_desc_init_xor(iter, src_cnt, flags);
                u_desc_ctrl.field.dest_write_en = 0;
                u_desc_ctrl.field.zero_result_en = 1;
-               u_desc_ctrl.field.int_en = int_en;
+               u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
                iter->desc_ctrl = u_desc_ctrl.value;
 
                /* for the subsequent descriptors preserve the store queue
@@ -559,7 +562,8 @@ iop_desc_init_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
 }
 
 static inline void
-iop_desc_init_null_xor(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
+iop_desc_init_null_xor(struct iop_adma_desc_slot *desc, int src_cnt,
+                      unsigned long flags)
 {
        struct iop3xx_desc_aau *hw_desc = desc->hw_desc;
        union {
@@ -591,7 +595,7 @@ iop_desc_init_null_xor(struct iop_adma_desc_slot *desc, int src_cnt, int int_en)
        }
 
        u_desc_ctrl.field.dest_write_en = 0;
-       u_desc_ctrl.field.int_en = int_en;
+       u_desc_ctrl.field.int_en = flags & DMA_PREP_INTERRUPT;
        hw_desc->desc_ctrl = u_desc_ctrl.value;
 }
 
index aaebb61aca4872cb7147a25653072db98c436e5b..74b5fff7f57575f3f67e3f085d6befb51a682d48 100644 (file)
@@ -42,7 +42,7 @@ extern unsigned long it8152_base_address;
 #define IT8152_GPIO_GPDR               __REG_IT8152(0x3f00500)
 
 /*
-  Interrup contoler per register summary:
+  Interrupt controller per register summary:
   ---------------------------------------
   LCDNIRR:
   IT8152_LD_IRQ(8) PCICLK stop
index 46dcc4d0b9bd9cbc520378521b5e9084259ad9aa..1ee17b6951d02f9057867594dbb5f3d268c4e038 100644 (file)
@@ -16,6 +16,9 @@
 
 #define KEXEC_BOOT_PARAMS_SIZE 1536
 
+#define KEXEC_ARM_ATAGS_OFFSET  0x1000
+#define KEXEC_ARM_ZIMAGE_OFFSET 0x8000
+
 #ifndef __ASSEMBLY__
 
 struct kimage;
index ff0a95715a07befda0621fcfca85d829b0ab53ed..f9f3606986c27fedea03382b9de34ba1a7667e89 100644 (file)
@@ -16,10 +16,12 @@ struct pxa2xx_udc_mach_info {
 #define        PXA2XX_UDC_CMD_DISCONNECT       1       /* so host won't see us */
 
        /* Boards following the design guidelines in the developer's manual,
-        * with on-chip GPIOs not Lubbock's wierd hardware, can have a sane
+        * with on-chip GPIOs not Lubbock's weird hardware, can have a sane
         * VBUS IRQ and omit the methods above.  Store the GPIO number
         * here; for GPIO 0, also mask in one of the pxa_gpio_mode() bits.
+        * Note that sometimes the signals go through inverters...
         */
+       bool    gpio_vbus_inverted;
        u16     gpio_vbus;                      /* high == vbus present */
        u16     gpio_pullup;                    /* high == pullup activated */
 };
index 4d43945529118a8ea7e92241771a6f3253a1e93a..fb6c6e3222bddc19131fc59408e12ffbfb824a22 100644 (file)
  * Since we have only two-level page tables, these are trivial
  */
 #define pmd_alloc_one(mm,addr)         ({ BUG(); ((pmd_t *)2); })
-#define pmd_free(pmd)                  do { } while (0)
+#define pmd_free(mm, pmd)              do { } while (0)
 #define pgd_populate(mm,pmd,pte)       BUG()
 
 extern pgd_t *get_pgd_slow(struct mm_struct *mm);
-extern void free_pgd_slow(pgd_t *pgd);
+extern void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd);
 
 #define pgd_alloc(mm)                  get_pgd_slow(mm)
-#define pgd_free(pgd)                  free_pgd_slow(pgd)
+#define pgd_free(mm, pgd)              free_pgd_slow(mm, pgd)
 
 /*
  * Allocate one PTE table.
@@ -83,7 +83,7 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
 /*
  * Free one PTE table.
  */
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        if (pte) {
                pte -= PTRS_PER_PTE;
@@ -91,7 +91,7 @@ static inline void pte_free_kernel(pte_t *pte)
        }
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 }
index f67acce387e7fc1bc0dd18326c5633e4fd2314c2..af99636db400e7e8cfbe81956faa1d84f11ebdf2 100644 (file)
@@ -60,6 +60,11 @@ extern void smp_cross_call(cpumask_t callmap);
  */
 extern void smp_send_timer(void);
 
+/*
+ * Broadcast a clock event to other CPUs.
+ */
+extern void smp_timer_broadcast(cpumask_t mask);
+
 /*
  * Boot a secondary CPU, and assign it the specified idle task.
  * This also gives us the initial stack to use for this CPU.
@@ -96,11 +101,12 @@ extern void platform_cpu_die(unsigned int cpu);
 extern int platform_cpu_kill(unsigned int cpu);
 extern void platform_cpu_enable(unsigned int cpu);
 
-#ifdef CONFIG_LOCAL_TIMERS
 /*
- * Setup a local timer interrupt for a CPU.
+ * Local timer interrupt handling function (can be IPI'ed).
  */
-extern void local_timer_setup(unsigned int cpu);
+extern void local_timer_interrupt(void);
+
+#ifdef CONFIG_LOCAL_TIMERS
 
 /*
  * Stop a local timer interrupt.
@@ -114,16 +120,17 @@ extern int local_timer_ack(void);
 
 #else
 
-static inline void local_timer_setup(unsigned int cpu)
-{
-}
-
 static inline void local_timer_stop(unsigned int cpu)
 {
 }
 
 #endif
 
+/*
+ * Setup a local timer interrupt for a CPU.
+ */
+extern void local_timer_setup(unsigned int cpu);
+
 /*
  * show local interrupt info
  */
index cb740025d4131382de81ac3925ffd7b4359bf94f..36bd402a21cb12ad52ffd610e740fc83b265efde 100644 (file)
@@ -85,8 +85,8 @@ tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
 }
 
 #define tlb_remove_page(tlb,page)      free_page_and_swap_cache(page)
-#define pte_free_tlb(tlb,ptep)         pte_free(ptep)
-#define pmd_free_tlb(tlb,pmdp)         pmd_free(pmdp)
+#define pte_free_tlb(tlb, ptep)                pte_free((tlb)->mm, ptep)
+#define pmd_free_tlb(tlb, pmdp)                pmd_free((tlb)->mm, pmdp)
 
 #define tlb_migrate_finish(mm)         do { } while (0)
 
index 99684d6f39677fbb29a1a4481be58bc226d31204..31e48b0e732414aff872d901dd4c0f33a5f5b54d 100644 (file)
@@ -13,8 +13,6 @@
 #define GPIO_PERIPH_A  0
 #define GPIO_PERIPH_B  1
 
-#define NR_GPIO_CONTROLLERS    4
-
 /*
  * Pin numbers identifying specific GPIO pins on the chip. They can
  * also be converted to IRQ numbers by passing them through
index af7f9535bab32bcaf29a1d253756cfb3f7526142..0180f584ef03d81cc432197e4a23f29eecc2f873 100644 (file)
@@ -5,20 +5,36 @@
 #include <asm/irq.h>
 
 
-/* Arch-neutral GPIO API */
-int __must_check gpio_request(unsigned int gpio, const char *label);
-void gpio_free(unsigned int gpio);
+/* Some GPIO chips can manage IRQs; some can't.  The exact numbers can
+ * be changed if needed, but for the moment they're not configurable.
+ */
+#define ARCH_NR_GPIOS  (NR_GPIO_IRQS + 2 * 32)
 
-int gpio_direction_input(unsigned int gpio);
-int gpio_direction_output(unsigned int gpio, int value);
-int gpio_get_value(unsigned int gpio);
-void gpio_set_value(unsigned int gpio, int value);
 
-#include <asm-generic/gpio.h>          /* cansleep wrappers */
+/* Arch-neutral GPIO API, supporting both "native" and external GPIOs. */
+#include <asm-generic/gpio.h>
+
+static inline int gpio_get_value(unsigned int gpio)
+{
+       return __gpio_get_value(gpio);
+}
+
+static inline void gpio_set_value(unsigned int gpio, int value)
+{
+       __gpio_set_value(gpio, value);
+}
+
+static inline int gpio_cansleep(unsigned int gpio)
+{
+       return __gpio_cansleep(gpio);
+}
+
 
 static inline int gpio_to_irq(unsigned int gpio)
 {
-       return gpio + GPIO_IRQ_BASE;
+       if (gpio < NR_GPIO_IRQS)
+               return gpio + GPIO_IRQ_BASE;
+       return -EINVAL;
 }
 
 static inline int irq_to_gpio(unsigned int irq)
index 5adffab9a577948bd3ed0d74b3a953838d118df9..608e350368c7c7ea58c74dcb2a924c46f9bb8834 100644 (file)
@@ -3,11 +3,11 @@
 
 #define EIM_IRQ_BASE   NR_INTERNAL_IRQS
 #define NR_EIM_IRQS    32
-
 #define AT32_EXTINT(n) (EIM_IRQ_BASE + (n))
 
 #define GPIO_IRQ_BASE  (EIM_IRQ_BASE + NR_EIM_IRQS)
-#define NR_GPIO_IRQS   (5 * 32)
+#define NR_GPIO_CTLR   (5 /*internal*/ + 1 /*external*/)
+#define NR_GPIO_IRQS   (NR_GPIO_CTLR * 32)
 
 #define NR_IRQS                (GPIO_IRQ_BASE + NR_GPIO_IRQS)
 
index cc3b2e3343b35d3e16321086005a9c9fd7cc4078..a0ed9a9839a54f2982468da7e0ade766d5176343 100644 (file)
@@ -12,7 +12,7 @@ extern void __bad_ndelay(void);
 
 extern void __udelay(unsigned long usecs);
 extern void __ndelay(unsigned long nsecs);
-extern void __const_udelay(unsigned long usecs);
+extern void __const_udelay(unsigned long xloops);
 extern void __delay(unsigned long loops);
 
 #define udelay(n) (__builtin_constant_p(n) ? \
index 0e680f47209fbc87ca98f90683f8cc57510d10e8..b77e364b4c444a164c9741d2d6ab94df1dfc2e35 100644 (file)
@@ -30,7 +30,7 @@ static __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
        return kcalloc(USER_PTRS_PER_PGD, sizeof(pgd_t), GFP_KERNEL);
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        kfree(pgd);
 }
@@ -55,12 +55,12 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        return pte;
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 }
index 5e44ecb3ce0cf63cc97a348227464a05312f66b8..187dcf38b2104e911b39014a458b575e1f6719fe 100644 (file)
@@ -34,7 +34,6 @@ static inline cycles_t get_cycles (void)
        return 0;
 }
 
-extern int read_current_timer(unsigned long *timer_value);
-#define ARCH_HAS_READ_CURRENT_TIMER    1
+#define ARCH_HAS_READ_CURRENT_TIMER
 
 #endif /* __ASM_AVR32_TIMEX_H */
index de09009593f84eb12d3e8fa38c0450df96777b7d..89861a27543ec58554f9ad957b84801a80885595 100644 (file)
 
 #define __NR_utimensat         278
 #define __NR_signalfd          279
-#define __NR_timerfd           280
+/* 280 was __NR_timerfd */
 #define __NR_eventfd           281
 
 #ifdef __KERNEL__
index 1601d62f39a57785a925d6e2ca3a260a5bd9cabe..574fe56989d1d68c82e90ef6d1d365720a7ce162 100644 (file)
@@ -188,8 +188,6 @@ extern void blkfin_inv_cache_all(void);
 #define page_to_phys(page)      ((page - mem_map) << PAGE_SHIFT)
 #define page_to_bus(page)       ((page - mem_map) << PAGE_SHIFT)
 
-#define mm_ptov(vaddr)         ((void *) (vaddr))
-#define mm_vtop(vaddr)         ((unsigned long) (vaddr))
 #define phys_to_virt(vaddr)    ((void *) (vaddr))
 #define virt_to_phys(vaddr)    ((unsigned long) (vaddr))
 
index e2f49c27ed297ab40dc7187de1639809fa1c9640..75ea6e0964839de32831162c7338218db9072435 100644 (file)
 #include <asm/atomic.h>
 #include <linux/compiler.h>
 
-/*
- * Some hacks to defeat gcc over-optimizations..
- */
-struct __dummy { unsigned long a[100]; };
-#define ADDR (*(struct __dummy *) addr)
-#define CONST_ADDR (*(const struct __dummy *) addr)
-
 /*
  * set_bit - Atomically set a bit in memory
  * @nr: the bit to set
index deaddfe79bbcd6527f968bc6bc3c4c1087e11440..8ddd66f8177346aeba8c6dd42bf1d313e2355b0a 100644 (file)
@@ -16,7 +16,7 @@ static inline pgd_t *pgd_alloc (struct mm_struct *mm)
        return (pgd_t *)get_zeroed_page(GFP_KERNEL);
 }
 
-static inline void pgd_free (pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_page((unsigned long)pgd);
 }
@@ -34,12 +34,12 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long add
        return pte;
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 }
index d425d8d0ad7758c73d40000a9a792f740ff78a5d..6ec494a5bc5ad91ccbbc7d40749a8b92e9fba913 100644 (file)
@@ -1,7 +1,7 @@
 /* atomic.h: atomic operation emulation for FR-V
  *
  * For an explanation of how atomic ops work in this arch, see:
- *   Documentation/fujitsu/frv/atomic-ops.txt
+ *   Documentation/frv/atomic-ops.txt
  *
  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  * Written by David Howells (dhowells@redhat.com)
index e29de7131b79dcca7250aad73b3d603fb1f53458..5f86b876b298b1382a6167e119cc29ea33d26aa2 100644 (file)
@@ -1,7 +1,7 @@
 /* bitops.h: bit operations for the Fujitsu FR-V CPUs
  *
  * For an explanation of how atomic ops work in this arch, see:
- *   Documentation/fujitsu/frv/atomic-ops.txt
+ *   Documentation/frv/atomic-ops.txt
  *
  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  * Written by David Howells (dhowells@redhat.com)
index 02500405a6fb26317ad2def7ea098ed3e93a3e0f..432a69e7f3d491488631a270b1cff0e8f2ac6daa 100644 (file)
@@ -29,7 +29,7 @@
 #define flush_dcache_mmap_unlock(mapping)      do {} while(0)
 
 /*
- * physically-indexed cache managment
+ * physically-indexed cache management
  * - see arch/frv/lib/cache.S
  */
 extern void frv_dcache_writeback(unsigned long start, unsigned long size);
index bcb2df68496e684d582f71d6a119f5398ee31c2f..2e8966ca030d46cd4b7514a3a0c4589aeba667b7 100644 (file)
@@ -16,16 +16,6 @@ extern unsigned long __nongprelbss dma_coherent_mem_end;
 void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp);
 void dma_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle);
 
-/*
- * These macros should be used after a pci_map_sg call has been done
- * to get bus addresses of each of the SG entries and their lengths.
- * You should only work with the number of sg entries pci_map_sg
- * returns, or alternatively stop on the first sg_dma_len(sg) which
- * is 0.
- */
-#define sg_dma_address(sg)     ((sg)->dma_address)
-#define sg_dma_len(sg)         ((sg)->length)
-
 /*
  * Map a single buffer of the indicated size for DMA in streaming mode.
  * The 32-bit bus address to use is returned.
index ff4d6cdeb1522811bd4131da61d68575ff55502b..26cefcde5cee9abba5df2dc5627d4f38b4016f05 100644 (file)
@@ -4,7 +4,7 @@
  * Written by David Howells (dhowells@redhat.com)
  * - Derived from include/asm-i386/highmem.h
  *
- * See Documentation/fujitsu/frv/mmu-layout.txt for more information.
+ * See Documentation/frv/mmu-layout.txt for more information.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
index aaf2a773d9d3d42070f221ca3443b24821a372cc..83532252b8be17f401d380ed78a0d5df5bbf7b42 100644 (file)
@@ -39,7 +39,7 @@
 
 #ifdef CONFIG_MMU
 
-/* see Documentation/fujitsu/frv/mmu-layout.txt */
+/* see Documentation/frv/mmu-layout.txt */
 #define KERNEL_LOWMEM_START            __UL(0xc0000000)
 #define KERNEL_LOWMEM_END              __UL(0xd0000000)
 #define VMALLOC_START                  __UL(0xd0000000)
index 213d92fd652aa24175ddd673c52cabb932d876be..bd9bd2d9cc7894294c737fa9fe4a2871050030a8 100644 (file)
@@ -76,10 +76,6 @@ extern unsigned long max_pfn;
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_CONTIGUOUS_PAGE_ALLOC
-#define WANT_PAGE_VIRTUAL      1
-#endif
-
 #include <asm-generic/memory_model.h>
 #include <asm-generic/page.h>
 
index ce982a6c610f0081a97c836d6edbc17e52e98f5c..e89620ef08cab876e315ec845d6c96d0d6e1cc97 100644 (file)
@@ -31,18 +31,18 @@ do {                                                                                \
  */
 
 extern pgd_t *pgd_alloc(struct mm_struct *);
-extern void pgd_free(pgd_t *);
+extern void pgd_free(struct mm_struct *mm, pgd_t *);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
 
 extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 }
@@ -55,7 +55,7 @@ static inline void pte_free(struct page *pte)
  * (In the PAE case we free the pmds as part of the pgd.)
  */
 #define pmd_alloc_one(mm, addr)                ({ BUG(); ((pmd_t *) 2); })
-#define pmd_free(x)                    do { } while (0)
+#define pmd_free(mm, x)                        do { } while (0)
 #define __pmd_free_tlb(tlb,x)          do { } while (0)
 
 #endif /* CONFIG_MMU */
index 147e995bec24e0b058c4a0911f92e8d1706c8763..6c0682ed5fc93db05ec12a27e9dabb6fee665cfc 100644 (file)
@@ -93,7 +93,7 @@ extern unsigned long empty_zero_page;
 
 /*
  * we use 2-level page tables, folding the PMD (mid-level table) into the PGE (top-level entry)
- * [see Documentation/fujitsu/frv/mmu-layout.txt]
+ * [see Documentation/frv/mmu-layout.txt]
  *
  * Page Directory:
  *  - Size: 16KB
@@ -226,7 +226,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
  * inside the pgd, so has no extra memory associated with it.
  */
 #define pud_alloc_one(mm, address)             NULL
-#define pud_free(x)                            do { } while (0)
+#define pud_free(mm, x)                                do { } while (0)
 #define __pud_free_tlb(tlb, x)                 do { } while (0)
 
 /*
index 2e7143b5a7ad2921109e4bbf1ec3a4ec2d8d1e76..4bca8a28546c2474e6300d041e117186175dc0ea 100644 (file)
@@ -31,6 +31,16 @@ struct scatterlist {
        unsigned int    length;
 };
 
+/*
+ * These macros should be used after a pci_map_sg call has been done
+ * to get bus addresses of each of the SG entries and their lengths.
+ * You should only work with the number of sg entries pci_map_sg
+ * returns, or alternatively stop on the first sg_dma_len(sg) which
+ * is 0.
+ */
+#define sg_dma_address(sg)     ((sg)->dma_address)
+#define sg_dma_len(sg)         ((sg)->length)
+
 #define ISA_DMA_THRESHOLD (0xffffffffUL)
 
 #endif /* !_ASM_SCATTERLIST_H */
index cd84f1771e34b306397b99c1dfad730d2de63d22..e8c9866675321b1d0c601f500efccf1343a41230 100644 (file)
 #define __NR_epoll_pwait       319
 #define __NR_utimensat         320
 #define __NR_signalfd          321
-#define __NR_timerfd           322
+/* #define __NR_timerfd                322 removed */
 #define __NR_eventfd           323
 #define __NR_fallocate         324
 
index 7b88d3931e3426f96bd88f93b7934bc4023ec79a..9d40e879f99ea968e18e07f142519c5839392003 100644 (file)
@@ -28,7 +28,7 @@
 
 #undef pud_free_tlb
 #define pud_free_tlb(tlb, x)            do { } while (0)
-#define pud_free(x)                    do { } while (0)
+#define pud_free(mm, x)                        do { } while (0)
 #define __pud_free_tlb(tlb, x)         do { } while (0)
 
 #undef  pud_addr_end
index 09204e40d66312edb7ba12e58261fd4760a89939..1c1fa422d18ab0dea14dbd7fc1e2d3b4731d7d76 100644 (file)
@@ -18,6 +18,7 @@ typedef unsigned long cputime_t;
 #define cputime_lt(__a, __b)           ((__a) <  (__b))
 #define cputime_le(__a, __b)           ((__a) <= (__b))
 #define cputime_to_jiffies(__ct)       (__ct)
+#define cputime_to_scaled(__ct)                (__ct)
 #define jiffies_to_cputime(__hz)       (__hz)
 
 typedef u64 cputime64_t;
index 2d0aab1d8611b756ec02e8f31378c7b6f3f5e828..f29a502f4a6c3d1a656ae5142f52b98fe6421408 100644 (file)
@@ -1,6 +1,102 @@
 #ifndef _ASM_GENERIC_GPIO_H
 #define _ASM_GENERIC_GPIO_H
 
+#ifdef CONFIG_HAVE_GPIO_LIB
+
+/* Platforms may implement their GPIO interface with library code,
+ * at a small performance cost for non-inlined operations and some
+ * extra memory (for code and for per-GPIO table entries).
+ *
+ * While the GPIO programming interface defines valid GPIO numbers
+ * to be in the range 0..MAX_INT, this library restricts them to the
+ * smaller range 0..ARCH_NR_GPIOS.
+ */
+
+#ifndef ARCH_NR_GPIOS
+#define ARCH_NR_GPIOS          256
+#endif
+
+struct seq_file;
+
+/**
+ * struct gpio_chip - abstract a GPIO controller
+ * @label: for diagnostics
+ * @direction_input: configures signal "offset" as input, or returns error
+ * @get: returns value for signal "offset"; for output signals this
+ *     returns either the value actually sensed, or zero
+ * @direction_output: configures signal "offset" as output, or returns error
+ * @set: assigns output value for signal "offset"
+ * @dbg_show: optional routine to show contents in debugfs; default code
+ *     will be used when this is omitted, but custom code can show extra
+ *     state (such as pullup/pulldown configuration).
+ * @base: identifies the first GPIO number handled by this chip; or, if
+ *     negative during registration, requests dynamic ID allocation.
+ * @ngpio: the number of GPIOs handled by this controller; the last GPIO
+ *     handled is (base + ngpio - 1).
+ * @can_sleep: flag must be set iff get()/set() methods sleep, as they
+ *     must while accessing GPIO expander chips over I2C or SPI
+ *
+ * A gpio_chip can help platforms abstract various sources of GPIOs so
+ * they can all be accessed through a common programing interface.
+ * Example sources would be SOC controllers, FPGAs, multifunction
+ * chips, dedicated GPIO expanders, and so on.
+ *
+ * Each chip controls a number of signals, identified in method calls
+ * by "offset" values in the range 0..(@ngpio - 1).  When those signals
+ * are referenced through calls like gpio_get_value(gpio), the offset
+ * is calculated by subtracting @base from the gpio number.
+ */
+struct gpio_chip {
+       char                    *label;
+
+       int                     (*direction_input)(struct gpio_chip *chip,
+                                               unsigned offset);
+       int                     (*get)(struct gpio_chip *chip,
+                                               unsigned offset);
+       int                     (*direction_output)(struct gpio_chip *chip,
+                                               unsigned offset, int value);
+       void                    (*set)(struct gpio_chip *chip,
+                                               unsigned offset, int value);
+       void                    (*dbg_show)(struct seq_file *s,
+                                               struct gpio_chip *chip);
+       int                     base;
+       u16                     ngpio;
+       unsigned                can_sleep:1;
+};
+
+extern const char *gpiochip_is_requested(struct gpio_chip *chip,
+                       unsigned offset);
+
+/* add/remove chips */
+extern int gpiochip_add(struct gpio_chip *chip);
+extern int __must_check gpiochip_remove(struct gpio_chip *chip);
+
+
+/* Always use the library code for GPIO management calls,
+ * or when sleeping may be involved.
+ */
+extern int gpio_request(unsigned gpio, const char *label);
+extern void gpio_free(unsigned gpio);
+
+extern int gpio_direction_input(unsigned gpio);
+extern int gpio_direction_output(unsigned gpio, int value);
+
+extern int gpio_get_value_cansleep(unsigned gpio);
+extern void gpio_set_value_cansleep(unsigned gpio, int value);
+
+
+/* A platform's <asm/gpio.h> code may want to inline the I/O calls when
+ * the GPIO is constant and refers to some always-present controller,
+ * giving direct access to chip registers and tight bitbanging loops.
+ */
+extern int __gpio_get_value(unsigned gpio);
+extern void __gpio_set_value(unsigned gpio, int value);
+
+extern int __gpio_cansleep(unsigned gpio);
+
+
+#else
+
 /* platforms that don't directly support access to GPIOs through I2C, SPI,
  * or other blocking infrastructure can use these wrappers.
  */
@@ -22,4 +118,6 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
        gpio_set_value(gpio, value);
 }
 
+#endif
+
 #endif /* _ASM_GENERIC_GPIO_H */
index 29ff5d84d8c32d2156201ae0eeceb00a4b5ad776..087325ede76cf31e4a9798664d36913928f058b3 100644 (file)
@@ -54,7 +54,7 @@ static inline pmd_t * pmd_offset(pud_t * pud, unsigned long address)
  * inside the pud, so has no extra memory associated with it.
  */
 #define pmd_alloc_one(mm, address)             NULL
-#define pmd_free(x)                            do { } while (0)
+#define pmd_free(mm, x)                                do { } while (0)
 #define __pmd_free_tlb(tlb, x)                 do { } while (0)
 
 #undef  pmd_addr_end
index 566464500558f19e2ec7a72f5985ce184ce81ae9..87cf449a6df380e6be3a11fd24648ef3aefe588b 100644 (file)
@@ -51,7 +51,7 @@ static inline pud_t * pud_offset(pgd_t * pgd, unsigned long address)
  * inside the pgd, so has no extra memory associated with it.
  */
 #define pud_alloc_one(mm, address)             NULL
-#define pud_free(x)                            do { } while (0)
+#define pud_free(mm, x)                                do { } while (0)
 #define __pud_free_tlb(tlb, x)                 do { } while (0)
 
 #undef  pud_addr_end
index d3238f1f70a684c109df2f4b976e2bc89eff22f2..dd1bed860e6487a3c325c2dfd66570efe8616066 100644 (file)
 static inline unsigned char rtc_is_updating(void)
 {
        unsigned char uip;
+       unsigned long flags;
 
-       spin_lock_irq(&rtc_lock);
+       spin_lock_irqsave(&rtc_lock, flags);
        uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP);
-       spin_unlock_irq(&rtc_lock);
+       spin_unlock_irqrestore(&rtc_lock, flags);
        return uip;
 }
 
@@ -46,6 +47,8 @@ static inline unsigned int get_rtc_time(struct rtc_time *time)
 {
        unsigned long uip_watchdog = jiffies;
        unsigned char ctrl;
+       unsigned long flags;
+
 #ifdef CONFIG_MACH_DECSTATION
        unsigned int real_year;
 #endif
@@ -72,7 +75,7 @@ static inline unsigned int get_rtc_time(struct rtc_time *time)
         * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
         * by the RTC when initially set to a non-zero value.
         */
-       spin_lock_irq(&rtc_lock);
+       spin_lock_irqsave(&rtc_lock, flags);
        time->tm_sec = CMOS_READ(RTC_SECONDS);
        time->tm_min = CMOS_READ(RTC_MINUTES);
        time->tm_hour = CMOS_READ(RTC_HOURS);
@@ -83,7 +86,7 @@ static inline unsigned int get_rtc_time(struct rtc_time *time)
        real_year = CMOS_READ(RTC_DEC_YEAR);
 #endif
        ctrl = CMOS_READ(RTC_CONTROL);
-       spin_unlock_irq(&rtc_lock);
+       spin_unlock_irqrestore(&rtc_lock, flags);
 
        if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
        {
index 962cad7cfbbda0849cc68380b43c2da97643f23c..8feeae1f2369b64cdf1be263880200503c5c3a41 100644 (file)
@@ -8,8 +8,6 @@ extern char _data[], _sdata[], _edata[];
 extern char __bss_start[], __bss_stop[];
 extern char __init_begin[], __init_end[];
 extern char _sinittext[], _einittext[];
-extern char _sextratext[] __attribute__((weak));
-extern char _eextratext[] __attribute__((weak));
 extern char _end[];
 extern char __per_cpu_start[], __per_cpu_end[];
 extern char __kprobes_text_start[], __kprobes_text_end[];
index 75f2bfab614f40639090702a2a6268f34864df75..f490e43a90b90a09e1cfe78a9f1215b66d3df74e 100644 (file)
@@ -14,7 +14,6 @@
 #define _ASM_GENERIC__TLB_H
 
 #include <linux/swap.h>
-#include <linux/quicklist.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 
index 7543a57b4ea13dce3ba67355eb161f8b14ce305f..26dc6ccd9441a2237ada1f7168131f07402949a9 100644 (file)
@@ -302,8 +302,6 @@ static __inline__ void ctrl_outl(unsigned long b, unsigned long addr)
 /*
  * Macros used for converting between virtual and physical mappings.
  */
-#define mm_ptov(vaddr)         ((void *) (vaddr))
-#define mm_vtop(vaddr)         ((unsigned long) (vaddr))
 #define phys_to_virt(vaddr)    ((void *) (vaddr))
 #define virt_to_phys(vaddr)    ((unsigned long) (vaddr))
 
index ee7d5ea10065dc3ba28a7d9d9f8c5ca0724b8993..19cfd62b11c30ac1206a0f9b4fc61f21fc1efdb5 100644 (file)
@@ -10,8 +10,6 @@
 #include <asm/setup.h>
 #include <asm/page.h>
 
-#define mm_ptov(vaddr)         ((void *) (vaddr))
-#define mm_vtop(vaddr)         ((unsigned long) (vaddr))
 #define phys_to_virt(vaddr)    ((void *) (vaddr))
 #define virt_to_phys(vaddr)    ((unsigned long) (vaddr))
 
index a1b9719f5fbb7ba11071a92ddcd611e6945e2c2e..953d3df9dd22670f16fec92440a9dc18f5431593 100644 (file)
@@ -122,38 +122,40 @@ clear_bit_unlock (int nr, volatile void *addr)
 }
 
 /**
- * __clear_bit_unlock - Non-atomically clear a bit with release
+ * __clear_bit_unlock - Non-atomically clears a bit in memory with release
+ * @nr: Bit to clear
+ * @addr: Address to start counting from
  *
- * This is like clear_bit_unlock, but the implementation uses a store
+ * Similarly to clear_bit_unlock, the implementation uses a store
  * with release semantics. See also __raw_spin_unlock().
  */
 static __inline__ void
-__clear_bit_unlock(int nr, volatile void *addr)
+__clear_bit_unlock(int nr, void *addr)
 {
-       __u32 mask, new;
-       volatile __u32 *m;
+       __u32 * const m = (__u32 *) addr + (nr >> 5);
+       __u32 const new = *m & ~(1 << (nr & 31));
 
-       m = (volatile __u32 *)addr + (nr >> 5);
-       mask = ~(1 << (nr & 31));
-       new = *m & mask;
-       barrier();
        ia64_st4_rel_nta(m, new);
 }
 
 /**
  * __clear_bit - Clears a bit in memory (non-atomic version)
+ * @nr: the bit to clear
+ * @addr: the address to start counting from
+ *
+ * Unlike clear_bit(), this function is non-atomic and may be reordered.
+ * If it's called on the same region of memory simultaneously, the effect
+ * may be that only one operation succeeds.
  */
 static __inline__ void
 __clear_bit (int nr, volatile void *addr)
 {
-       volatile __u32 *p = (__u32 *) addr + (nr >> 5);
-       __u32 m = 1 << (nr & 31);
-       *p &= ~m;
+       *((__u32 *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
 }
 
 /**
  * change_bit - Toggle a bit in memory
- * @nr: Bit to clear
+ * @nr: Bit to toggle
  * @addr: Address to start counting from
  *
  * change_bit() is atomic and may not be reordered.
@@ -178,7 +180,7 @@ change_bit (int nr, volatile void *addr)
 
 /**
  * __change_bit - Toggle a bit in memory
- * @nr: the bit to set
+ * @nr: the bit to toggle
  * @addr: the address to start counting from
  *
  * Unlike change_bit(), this function is non-atomic and may be reordered.
@@ -197,7 +199,7 @@ __change_bit (int nr, volatile void *addr)
  * @addr: Address to count from
  *
  * This operation is atomic and cannot be reordered.  
- * It also implies a memory barrier.
+ * It also implies the acquisition side of the memory barrier.
  */
 static __inline__ int
 test_and_set_bit (int nr, volatile void *addr)
@@ -247,11 +249,11 @@ __test_and_set_bit (int nr, volatile void *addr)
 
 /**
  * test_and_clear_bit - Clear a bit and return its old value
- * @nr: Bit to set
+ * @nr: Bit to clear
  * @addr: Address to count from
  *
  * This operation is atomic and cannot be reordered.  
- * It also implies a memory barrier.
+ * It also implies the acquisition side of the memory barrier.
  */
 static __inline__ int
 test_and_clear_bit (int nr, volatile void *addr)
@@ -272,7 +274,7 @@ test_and_clear_bit (int nr, volatile void *addr)
 
 /**
  * __test_and_clear_bit - Clear a bit and return its old value
- * @nr: Bit to set
+ * @nr: Bit to clear
  * @addr: Address to count from
  *
  * This operation is non-atomic and can be reordered.  
@@ -292,11 +294,11 @@ __test_and_clear_bit(int nr, volatile void * addr)
 
 /**
  * test_and_change_bit - Change a bit and return its old value
- * @nr: Bit to set
+ * @nr: Bit to change
  * @addr: Address to count from
  *
  * This operation is atomic and cannot be reordered.  
- * It also implies a memory barrier.
+ * It also implies the acquisition side of the memory barrier.
  */
 static __inline__ int
 test_and_change_bit (int nr, volatile void *addr)
@@ -315,8 +317,12 @@ test_and_change_bit (int nr, volatile void *addr)
        return (old & bit) != 0;
 }
 
-/*
- * WARNING: non atomic version.
+/**
+ * __test_and_change_bit - Change a bit and return its old value
+ * @nr: Bit to change
+ * @addr: Address to count from
+ *
+ * This operation is non-atomic and can be reordered.
  */
 static __inline__ int
 __test_and_change_bit (int nr, void *addr)
index 0f6e5264ab8fcccefa2da67faa794fec3d79d206..dfcf75b8426d8bde81dd8b7fda51ad5f12df137c 100644 (file)
@@ -181,7 +181,7 @@ struct compat_shmid64_ds {
 /*
  * A pointer passed in from user mode. This should not be used for syscall parameters,
  * just declare them as pointers because the syscall entry code will have appropriately
- * comverted them already.
+ * converted them already.
  */
 typedef        u32             compat_uptr_t;
 
index 5b6665c754c914213f4e6fa8fb76bc497e5bbf1c..de2ed2cbdd845d9404c4036de78cba661f7a6ea5 100644 (file)
@@ -24,7 +24,9 @@
 extern void ia64_bad_param_for_setreg (void);
 extern void ia64_bad_param_for_getreg (void);
 
+#ifdef __KERNEL__
 register unsigned long ia64_r13 asm ("r13") __used;
+#endif
 
 #define ia64_setreg(regnum, val)                                               \
 ({                                                                             \
index 823553bf12e6681861297cbcbcf746a1c0a1a460..f1663aa94a52422dd9c882ad5f3c2d543402ad21 100644 (file)
@@ -3,9 +3,9 @@
  * Purpose:    Machine check handling specific defines
  *
  * Copyright (C) 1999, 2004 Silicon Graphics, Inc.
- * Copyright (C) Vijay Chander (vijay@engr.sgi.com)
- * Copyright (C) Srinivasa Thirumalachar (sprasad@engr.sgi.com)
- * Copyright (C) Russ Anderson (rja@sgi.com)
+ * Copyright (C) Vijay Chander <vijay@engr.sgi.com>
+ * Copyright (C) Srinivasa Thirumalachar <sprasad@engr.sgi.com>
+ * Copyright (C) Russ Anderson <rja@sgi.com>
  */
 
 #ifndef _ASM_IA64_MCA_H
index 76203f9a8718d6706216a961684205f6beffbdaa..dd2a5b134390682b571be17cf5b2689bd2f7bfdc 100644 (file)
@@ -1,8 +1,9 @@
 /*
  * File:       mca_asm.h
+ * Purpose:    Machine check handling specific defines
  *
  * Copyright (C) 1999 Silicon Graphics, Inc.
- * Copyright (C) Vijay Chander (vijay@engr.sgi.com)
+ * Copyright (C) Vijay Chander <vijay@engr.sgi.com>
  * Copyright (C) Srinivasa Thirumalachar <sprasad@engr.sgi.com>
  * Copyright (C) 2000 Hewlett-Packard Co.
  * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
index 67552cad517339dea7791ce825ca00109d6602f3..556d988123ac1cd5ba351396caf39479401450b0 100644 (file)
@@ -27,7 +27,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline void pgd_free(pgd_t * pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        quicklist_free(0, NULL, pgd);
 }
@@ -44,11 +44,11 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline void pud_free(pud_t * pud)
+static inline void pud_free(struct mm_struct *mm, pud_t *pud)
 {
        quicklist_free(0, NULL, pud);
 }
-#define __pud_free_tlb(tlb, pud)       pud_free(pud)
+#define __pud_free_tlb(tlb, pud)       pud_free((tlb)->mm, pud)
 #endif /* CONFIG_PGTABLE_4 */
 
 static inline void
@@ -62,12 +62,12 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline void pmd_free(pmd_t * pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        quicklist_free(0, NULL, pmd);
 }
 
-#define __pmd_free_tlb(tlb, pmd)       pmd_free(pmd)
+#define __pmd_free_tlb(tlb, pmd)       pmd_free((tlb)->mm, pmd)
 
 static inline void
 pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte)
@@ -94,12 +94,12 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        quicklist_free_page(0, NULL, pte);
 }
 
-static inline void pte_free_kernel(pte_t * pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        quicklist_free(0, NULL, pte);
 }
@@ -109,6 +109,6 @@ static inline void check_pgt_cache(void)
        quicklist_trim(0, NULL, 25, 16);
 }
 
-#define __pte_free_tlb(tlb, pte)       pte_free(pte)
+#define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, pte)
 
 #endif                         /* _ASM_IA64_PGALLOC_H */
index be3b0ae43270f81800945752f65843b849ef2460..741f7ecb986a90fb28ed9c0a8020da5b67654f46 100644 (file)
@@ -31,7 +31,8 @@
  * each (assuming 8KB page size), for a total of 8TB of user virtual
  * address space.
  */
-#define TASK_SIZE              (current->thread.task_size)
+#define TASK_SIZE_OF(tsk)      ((tsk)->thread.task_size)
+#define TASK_SIZE              TASK_SIZE_OF(current)
 
 /*
  * This decides where the kernel will search for a free chunk of vm
@@ -472,7 +473,7 @@ ia64_set_psr (__u64 psr)
 {
        ia64_stop();
        ia64_setreg(_IA64_REG_PSR_L, psr);
-       ia64_srlz_d();
+       ia64_srlz_i();
 }
 
 /*
index 1f5412d6f9bb67c97ca25ff51937dfc2e0a34ec4..2251118894ae0005f193a2befa8c5a11b963f4e0 100644 (file)
@@ -649,17 +649,6 @@ typedef struct err_rec {
  * Now define a couple of inline functions for improved type checking
  * and convenience.
  */
-static inline long
-ia64_sal_freq_base (unsigned long which, unsigned long *ticks_per_second,
-                   unsigned long *drift_info)
-{
-       struct ia64_sal_retval isrv;
-
-       SAL_CALL(isrv, SAL_FREQ_BASE, which, 0, 0, 0, 0, 0, 0);
-       *ticks_per_second = isrv.v0;
-       *drift_info = isrv.v1;
-       return isrv.status;
-}
 
 extern s64 ia64_sal_cache_flush (u64 cache_type);
 extern void __init check_sal_cache_flush (void);
@@ -841,6 +830,9 @@ extern int ia64_sal_oemcall_nolock(struct ia64_sal_retval *, u64, u64, u64,
                                   u64, u64, u64, u64, u64);
 extern int ia64_sal_oemcall_reentrant(struct ia64_sal_retval *, u64, u64, u64,
                                      u64, u64, u64, u64, u64);
+extern long
+ia64_sal_freq_base (unsigned long which, unsigned long *ticks_per_second,
+                   unsigned long *drift_info);
 #ifdef CONFIG_HOTPLUG_CPU
 /*
  * System Abstraction Layer Specification
index 164448d23850ec312843ba722d7962822f05444d..9dd9e999ea69cdd0a20b7c9e15e6b5788b03f6d5 100644 (file)
@@ -12,7 +12,7 @@ extern void __bad_ndelay(void);
 
 extern void __udelay(unsigned long usecs);
 extern void __ndelay(unsigned long nsecs);
-extern void __const_udelay(unsigned long usecs);
+extern void __const_udelay(unsigned long xloops);
 extern void __delay(unsigned long loops);
 
 #define udelay(n) (__builtin_constant_p(n) ? \
index 2f93f4743add897ce75a9700c9a4abfa58d8442b..242028b4d86a1dc858a8df7b606bf80a97e8066d 100644 (file)
@@ -3,7 +3,7 @@
 #define _ASM_M32R_IRQ_H
 
 
-#if defined(CONFIG_PLAT_M32700UT_Alpha) || defined(CONFIG_PLAT_USRV)
+#if defined(CONFIG_PLAT_USRV)
 /*
  * IRQ definitions for M32700UT
  *  M32700 Chip: 64 interrupts
index d39121279a1a411ce4862268bca40e5daf42c574..57623beb44cb6a62a0b14d9cbb7769174b4e75b1 100644 (file)
@@ -13,9 +13,7 @@
  * this archive for more details.
  */
 
-#if defined(CONFIG_PLAT_M32700UT_Alpha)
-#define PLD_PLAT_BASE          0x08c00000
-#elif defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV)
+#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV)
 #define PLD_PLAT_BASE          0x04c00000
 #else
 #error "no platform configuration"
index 943ba63c1ebcf7bb365f541b75b05828429c6e54..e5921adfad1b6ae2490fb89aa61689f9eaf20b5e 100644 (file)
@@ -24,7 +24,7 @@ static __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
        return pgd;
 }
 
-static __inline__ void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_page((unsigned long)pgd);
 }
@@ -46,17 +46,17 @@ static __inline__ struct page *pte_alloc_one(struct mm_struct *mm,
        return pte;
 }
 
-static __inline__ void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static __inline__ void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 }
 
-#define __pte_free_tlb(tlb, pte)       pte_free((pte))
+#define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, (pte))
 
 /*
  * allocating and freeing a pmd is trivial: the 1-entry pmd is
@@ -65,7 +65,7 @@ static __inline__ void pte_free(struct page *pte)
  */
 
 #define pmd_alloc_one(mm, addr)                ({ BUG(); ((pmd_t *)2); })
-#define pmd_free(x)                    do { } while (0)
+#define pmd_free(mm, x)                        do { } while (0)
 #define __pmd_free_tlb(tlb, x)         do { } while (0)
 #define pgd_populate(mm, pmd, pte)     BUG()
 
index f467eac9ba70cf3e77402bbc1fc0140a774ce032..cf701c93324937aa4f6803279baa6df0bcc1a4cb 100644 (file)
 #define __NR_epoll_pwait       319
 #define __NR_utimensat         320
 #define __NR_signalfd          321
-#define __NR_timerfd           322
+/* #define __NR_timerfd                322 removed */
 #define __NR_eventfd           323
 #define __NR_fallocate         324
 
index 27d11da2b47961a04ad930d04183dcf6e7b1f874..28b0f49ee5217c184eacbb9746101571ef85ff97 100644 (file)
@@ -14,8 +14,6 @@ extern void mac_init_IRQ(void);
 extern int mac_irq_pending(unsigned int);
 extern void mac_identify(void);
 extern void mac_report_hardware(void);
-extern void mac_debugging_penguin(int);
-extern void mac_boom(int);
 
 /*
  *     Floppy driver magic hook - probably shouldnt be here
index 5158412cd54dd4f8a8ca827c57b6441897850101..500ec9b8b1892aebb41ec8833fa982abf5acaf9f 100644 (file)
@@ -22,7 +22,7 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long ad
        return pte;
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        cache_page(pte);
        free_page((unsigned long) pte);
@@ -47,7 +47,7 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long add
        return page;
 }
 
-static inline void pte_free(struct page *page)
+static inline void pte_free(struct mm_struct *mm, struct page *page)
 {
        cache_page(kmap(page));
        kunmap(page);
@@ -67,7 +67,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
        return get_pointer_table();
 }
 
-static inline int pmd_free(pmd_t *pmd)
+static inline int pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        return free_pointer_table(pmd);
 }
@@ -78,9 +78,9 @@ static inline int __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
 }
 
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
-       pmd_free((pmd_t *)pgd);
+       pmd_free(mm, (pmd_t *)pgd);
 }
 
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
index 778a4c538eb2ed03da163506d93573622bb1a4ab..0b604f0f192d5916b74aee3026c70a7351834671 100644 (file)
@@ -107,8 +107,6 @@ extern void *empty_zero_page;
 /* 64-bit machines, beware!  SRB. */
 #define SIZEOF_PTR_LOG2                               2
 
-#define mm_end_of_chunk(addr, len)     0
-
 extern void kernel_set_cachemode(void *addr, unsigned long size, int cmode);
 
 /*
index fd8241117649e978e320b4731cdc257c54c7f49c..a5a91e72714b0b9e715bba4ee0a008a777187057 100644 (file)
@@ -21,12 +21,12 @@ extern const char bad_pmd_string[];
 #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); })
 
 
-static inline void pte_free_kernel(pte_t * pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
         free_page((unsigned long) pte);
 }
 
-static inline void pte_free(struct page *page)
+static inline void pte_free(struct mm_struct *mm, struct page *page)
 {
         __free_page(page);
 }
@@ -72,10 +72,10 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *p
  * allocating and freeing a pmd is trivial: the 1-entry pmd is
  * inside the pgd, so has no extra memory associated with it.
  */
-#define pmd_free(x)                    do { } while (0)
+#define pmd_free(mm, x)                        do { } while (0)
 #define __pmd_free_tlb(tlb, x)         do { } while (0)
 
-static inline void pgd_free(pgd_t * pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
         free_page((unsigned long) pgd);
 }
index f43afe1fc3b33940dc1c46178045830f4bf01b44..c142fbf2f376b0abc4767f5c6c048130d5fcd8f2 100644 (file)
@@ -262,7 +262,7 @@ static __inline__ unsigned long ext2_find_next_zero_bit(void *addr, unsigned lon
                 * tmp = __swab32(*(p++));
                 * tmp |= ~0UL >> (32-offset);
                 *
-                * but this would decrease preformance, so we change the
+                * but this would decrease performance, so we change the
                 * shift:
                 */
                tmp = *(p++);
index 0161ebb5d883f903e9bef07371ba2dbd5b79331f..36e870b468ef0fa1546890f5b8b05516eab60398 100644 (file)
@@ -715,7 +715,7 @@ extern void cpm_install_handler(int vec, void (*handler)(void *), void *dev_id);
 #define        CICR_SCC_SCC3           ((uint)0x00200000)      /* SCC3 @ SCCc */
 #define        CICR_SCB_SCC2           ((uint)0x00040000)      /* SCC2 @ SCCb */
 #define        CICR_SCA_SCC1           ((uint)0x00000000)      /* SCC1 @ SCCa */
-#define CICR_IRL_MASK          ((uint)0x0000e000)      /* Core interrrupt */
+#define CICR_IRL_MASK          ((uint)0x0000e000)      /* Core interrupt */
 #define CICR_HP_MASK           ((uint)0x00001f00)      /* Hi-pri int. */
 #define CICR_IEN               ((uint)0x00000080)      /* Int. enable */
 #define CICR_SPS               ((uint)0x00000001)      /* SCC Spread */
index 04a20fd051cfa5685ad7a144d027d449a9fce771..55cbd6294ab68508492d3143fa49c2d6a306611c 100644 (file)
@@ -68,7 +68,7 @@ static inline void _udelay(unsigned long usecs)
 /*
  *     Moved the udelay() function into library code, no longer inlined.
  *     I had to change the algorithm because we are overflowing now on
- *     the faster ColdFire parts. The code is a little biger, so it makes
+ *     the faster ColdFire parts. The code is a little bigger, so it makes
  *     sense to library it.
  */
 extern void udelay(unsigned long usecs);
index 653d9b2d7ddfe5be3799ba95ca715d6898f3c56b..6adef1ee2082c72c4a740d19b091c2c5f19faeb1 100644 (file)
@@ -172,8 +172,6 @@ extern void iounmap(void *addr);
 /*
  * Macros used for converting between virtual and physical mappings.
  */
-#define mm_ptov(vaddr)         ((void *) (vaddr))
-#define mm_vtop(vaddr)         ((unsigned long) (vaddr))
 #define phys_to_virt(vaddr)    ((void *) (vaddr))
 #define virt_to_phys(vaddr)    ((unsigned long) (vaddr))
 
index 399814f0b219fee7468f84321064aa58f2ac9020..366eb8602d2fb124aee5eab7b59341e49b41cf41 100644 (file)
 #define MCFSIM_CSAR1           0x8c            /* CS 1 Address reg (r/w) */
 #define MCFSIM_CSMR1           0x90            /* CS 1 Mask reg (r/w) */
 #define MCFSIM_CSCR1           0x96            /* CS 1 Control reg (r/w) */
-#define MCFSIM_CSAR2           0x98            /* CS 2 Adress reg (r/w) */
+#define MCFSIM_CSAR2           0x98            /* CS 2 Address reg (r/w) */
 #define MCFSIM_CSMR2           0x9c            /* CS 2 Mask reg (r/w) */
 #define MCFSIM_CSCR2           0xa2            /* CS 2 Control reg (r/w) */
-#define MCFSIM_CSAR3           0xa4            /* CS 3 Adress reg (r/w) */
+#define MCFSIM_CSAR3           0xa4            /* CS 3 Address reg (r/w) */
 #define MCFSIM_CSMR3           0xa8            /* CS 3 Mask reg (r/w) */
 #define MCFSIM_CSCR3           0xae            /* CS 3 Control reg (r/w) */
 
index d3ce550f6ef4b078d50c2d14b38fdb318405c723..5886728409c07894522da014d95dd022958840e1 100644 (file)
 #define MCFSIM_CSMR7           0xda            /* CS 7 Mask reg (r/w) */
 #define MCFSIM_CSCR7           0xde            /* CS 7 Control reg (r/w) */
 #else
-#define MCFSIM_CSAR2           0x98            /* CS 2 Adress reg (r/w) */
+#define MCFSIM_CSAR2           0x98            /* CS 2 Address reg (r/w) */
 #define MCFSIM_CSMR2           0x9c            /* CS 2 Mask reg (r/w) */
 #define MCFSIM_CSCR2           0xa2            /* CS 2 Control reg (r/w) */
-#define MCFSIM_CSAR3           0xa4            /* CS 3 Adress reg (r/w) */
+#define MCFSIM_CSAR3           0xa4            /* CS 3 Address reg (r/w) */
 #define MCFSIM_CSMR3           0xa8            /* CS 3 Mask reg (r/w) */
 #define MCFSIM_CSCR3           0xae            /* CS 3 Control reg (r/w) */
-#define MCFSIM_CSAR4           0xb0            /* CS 4 Adress reg (r/w) */
+#define MCFSIM_CSAR4           0xb0            /* CS 4 Address reg (r/w) */
 #define MCFSIM_CSMR4           0xb4            /* CS 4 Mask reg (r/w) */
 #define MCFSIM_CSCR4           0xba            /* CS 4 Control reg (r/w) */
-#define MCFSIM_CSAR5           0xbc            /* CS 5 Adress reg (r/w) */
+#define MCFSIM_CSAR5           0xbc            /* CS 5 Address reg (r/w) */
 #define MCFSIM_CSMR5           0xc0            /* CS 5 Mask reg (r/w) */
 #define MCFSIM_CSCR5           0xc6            /* CS 5 Control reg (r/w) */
-#define MCFSIM_CSAR6           0xc8            /* CS 6 Adress reg (r/w) */
+#define MCFSIM_CSAR6           0xc8            /* CS 6 Address reg (r/w) */
 #define MCFSIM_CSMR6           0xcc            /* CS 6 Mask reg (r/w) */
 #define MCFSIM_CSCR6           0xd2            /* CS 6 Control reg (r/w) */
-#define MCFSIM_CSAR7           0xd4            /* CS 7 Adress reg (r/w) */
+#define MCFSIM_CSAR7           0xd4            /* CS 7 Address reg (r/w) */
 #define MCFSIM_CSMR7           0xd8            /* CS 7 Mask reg (r/w) */
 #define MCFSIM_CSCR7           0xde            /* CS 7 Control reg (r/w) */
 #endif /* CONFIG_OLDMASK */
index 75dcdacdb2980d90ca27398cee610c997b6bc74d..cc22c4a53005cc9a9e714889fd2869f3919a84e9 100644 (file)
 #define MCFSIM_CSMR1           0x90            /* CS 1 Mask reg (r/w) */
 #define MCFSIM_CSCR1           0x96            /* CS 1 Control reg (r/w) */
 
-#define MCFSIM_CSAR2           0x98            /* CS 2 Adress reg (r/w) */
+#define MCFSIM_CSAR2           0x98            /* CS 2 Address reg (r/w) */
 #define MCFSIM_CSMR2           0x9c            /* CS 2 Mask reg (r/w) */
 #define MCFSIM_CSCR2           0xa2            /* CS 2 Control reg (r/w) */
-#define MCFSIM_CSAR3           0xa4            /* CS 3 Adress reg (r/w) */
+#define MCFSIM_CSAR3           0xa4            /* CS 3 Address reg (r/w) */
 #define MCFSIM_CSMR3           0xa8            /* CS 3 Mask reg (r/w) */
 #define MCFSIM_CSCR3           0xae            /* CS 3 Control reg (r/w) */
-#define MCFSIM_CSAR4           0xb0            /* CS 4 Adress reg (r/w) */
+#define MCFSIM_CSAR4           0xb0            /* CS 4 Address reg (r/w) */
 #define MCFSIM_CSMR4           0xb4            /* CS 4 Mask reg (r/w) */
 #define MCFSIM_CSCR4           0xba            /* CS 4 Control reg (r/w) */
-#define MCFSIM_CSAR5           0xbc            /* CS 5 Adress reg (r/w) */
+#define MCFSIM_CSAR5           0xbc            /* CS 5 Address reg (r/w) */
 #define MCFSIM_CSMR5           0xc0            /* CS 5 Mask reg (r/w) */
 #define MCFSIM_CSCR5           0xc6            /* CS 5 Control reg (r/w) */
-#define MCFSIM_CSAR6           0xc8            /* CS 6 Adress reg (r/w) */
+#define MCFSIM_CSAR6           0xc8            /* CS 6 Address reg (r/w) */
 #define MCFSIM_CSMR6           0xcc            /* CS 6 Mask reg (r/w) */
 #define MCFSIM_CSCR6           0xd2            /* CS 6 Control reg (r/w) */
-#define MCFSIM_CSAR7           0xd4            /* CS 7 Adress reg (r/w) */
+#define MCFSIM_CSAR7           0xd4            /* CS 7 Address reg (r/w) */
 #define MCFSIM_CSMR7           0xd8            /* CS 7 Mask reg (r/w) */
 #define MCFSIM_CSCR7           0xde            /* CS 7 Control reg (r/w) */
 
index a3f8cc8a4a8403f79ce381945e05dad7f8bd2480..d57217ca4f27fe15c1dbe96d926ba3cd0989121c 100644 (file)
 #define CICR_SCC_SCC3           ((uint)0x00200000)      /* SCC3 @ SCCc */
 #define CICR_SCD_SCC4           ((uint)0x00c00000)      /* SCC4 @ SCCd */
 
-#define CICR_IRL_MASK           ((uint)0x0000e000)      /* Core interrrupt */
+#define CICR_IRL_MASK           ((uint)0x0000e000)      /* Core interrupt */
 #define CICR_HP_MASK            ((uint)0x00001f00)      /* Hi-pri int. */
 #define CICR_VBA_MASK           ((uint)0x000000e0)      /* Vector Base Address */
 #define CICR_SPS                ((uint)0x00000001)      /* SCC Spread */
index c920ccdb61fef26c82188658de184a5ced0dac3c..431f63aadd0ea3fbec75748cdce78c65326ffb89 100644 (file)
 #define        NE2000_BYTE             volatile unsigned char
 #endif
 
-#if defined(CONFIG_CFV240)
-#define NE2000_ADDR             0x40010000
-#define NE2000_ADDR1            0x40010001
-#define NE2000_ODDOFFSET        0x00000000
-#define NE2000_IRQ              1
-#define NE2000_IRQ_VECTOR       0x19
-#define NE2000_IRQ_PRIORITY     2
-#define NE2000_IRQ_LEVEL        1
-#define        NE2000_BYTE             volatile unsigned char
-#endif
-
 #if defined(CONFIG_M5307C3)
 #define NE2000_ADDR            0x40000300
 #define NE2000_ODDOFFSET       0x00010000
@@ -173,13 +162,8 @@ void ne2000_outsw(unsigned int addr, void *vbuf, unsigned long len);
  *     On most NE2000 implementations on ColdFire boards the chip is
  *     mapped in kinda funny, due to its ISA heritage.
  */
-#ifdef CONFIG_CFV240
-#define NE2000_PTR(addr)       (NE2000_ADDR + ((addr & 0x3f) << 1) + 1)
-#define NE2000_DATA_PTR(addr)  (NE2000_ADDR + ((addr & 0x3f) << 1))
-#else
 #define        NE2000_PTR(addr)        ((addr&0x1)?(NE2000_ODDOFFSET+addr-1):(addr))
 #define        NE2000_DATA_PTR(addr)   (addr)
-#endif
 
 
 void ne2000_outb(unsigned int val, unsigned int addr)
@@ -285,17 +269,6 @@ void ne2000_irqsetup(int irq)
 }
 #endif
 
-#if defined(CONFIG_CFV240)
-void ne2000_irqsetup(int irq)
-{
-       volatile unsigned char  *icrp;
-
-       icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_ICR1);
-       *icrp = MCFSIM_ICR_LEVEL1 | MCFSIM_ICR_PRI2 | MCFSIM_ICR_AUTOVEC;
-       mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_EINT1);
-}
-#endif
-
 #if defined(CONFIG_M5206e) && defined(CONFIG_NETtel)
 void ne2000_irqsetup(int irq)
 {
index 1074ae717f74bf73f67d8710abfcb7b62bea6dfc..da3f2ceff3a4bd1b5abf5bfd0568d4cad91022b5 100644 (file)
@@ -17,9 +17,7 @@
  *     Include 5204, 5206/e, 5235, 5249, 5270/5271, 5272, 5280/5282,
  *     5307 or 5407 specific addresses.
  */
-#if defined(CONFIG_M5204)
-#include <asm/m5204sim.h>
-#elif defined(CONFIG_M5206) || defined(CONFIG_M5206e)
+#if defined(CONFIG_M5206) || defined(CONFIG_M5206e)
 #include <asm/m5206sim.h>
 #elif defined(CONFIG_M520x)
 #include <asm/m520xsim.h>
index 6f4d796e03db057f20cc3434be121439711cf381..0f90f6d2227a7993acefba1a3caaff4c626e9257 100644 (file)
@@ -16,7 +16,7 @@
 /*
  *     Get address specific defines for this ColdFire member.
  */
-#if defined(CONFIG_M5204) || defined(CONFIG_M5206) || defined(CONFIG_M5206e)
+#if defined(CONFIG_M5206) || defined(CONFIG_M5206e)
 #define        MCFTIMER_BASE1          0x100           /* Base address of TIMER1 */
 #define        MCFTIMER_BASE2          0x120           /* Base address of TIMER2 */
 #elif defined(CONFIG_M5272)
index 1319a81814b15cb840f61987fc37842145b58668..ef2293873612c6985814be4786420573d00869f6 100644 (file)
@@ -19,7 +19,7 @@
 #if defined(CONFIG_M5272)
 #define        MCFUART_BASE1           0x100           /* Base address of UART1 */
 #define        MCFUART_BASE2           0x140           /* Base address of UART2 */
-#elif defined(CONFIG_M5204) || defined(CONFIG_M5206) || defined(CONFIG_M5206e)
+#elif defined(CONFIG_M5206) || defined(CONFIG_M5206e)
 #if defined(CONFIG_NETtel)
 #define        MCFUART_BASE1           0x180           /* Base address of UART1 */
 #define        MCFUART_BASE2           0x140           /* Base address of UART2 */
@@ -71,7 +71,7 @@ struct mcf_platform_uart {
 #define        MCFUART_UTB             0x0c            /* Transmit Buffer (w) */
 #define        MCFUART_UIPCR           0x10            /* Input Port Change (r) */
 #define        MCFUART_UACR            0x10            /* Auxiliary Control (w) */
-#define        MCFUART_UISR            0x14            /* Interrup Status (r) */
+#define        MCFUART_UISR            0x14            /* Interrupt Status (r) */
 #define        MCFUART_UIMR            0x14            /* Interrupt Mask (w) */
 #define        MCFUART_UBG1            0x18            /* Baud Rate MSB (r/w) */
 #define        MCFUART_UBG2            0x1c            /* Baud Rate LSB (r/w) */
index 15b4c7d45c94a643865b511040cff2e5dcd0e04a..ee2dc07bae0e3ef232d8a23b38bcaf3029a1d5d2 100644 (file)
@@ -207,23 +207,6 @@ cmpxchg(volatile int *p, int old, int new)
 }
 
 
-#ifdef CONFIG_M68332
-#define HARD_RESET_NOW() ({            \
-        local_irq_disable();           \
-        asm("                          \
-       movew   #0x0000, 0xfffa6a;      \
-        reset;                         \
-        /*movew #0x1557, 0xfffa44;*/   \
-        /*movew #0x0155, 0xfffa46;*/   \
-        moveal #0, %a0;                        \
-        movec %a0, %vbr;               \
-        moveal 0, %sp;                 \
-        moveal 4, %a0;                 \
-        jmp (%a0);                     \
-        ");                            \
-})
-#endif
-
 #if defined( CONFIG_M68328 ) || defined( CONFIG_M68EZ328 ) || \
        defined (CONFIG_M68360) || defined( CONFIG_M68VZ328 )
 #define HARD_RESET_NOW() ({            \
index 568c76cdd9000aed94b2d7970bbfdb2f446d6973..ac5d541368e934a30ca17ac03e58bd990b9eb7ca 100644 (file)
@@ -128,7 +128,7 @@ typedef u32         compat_sigset_word;
  * A pointer passed in from user mode. This should not
  * be used for syscall parameters, just declare them
  * as pointers because the syscall entry code will have
- * appropriately comverted them already.
+ * appropriately converted them already.
  */
 typedef u32            compat_uptr_t;
 
index 38fcda703a0b197234fbb09577f1fb83b8285c00..0a1ef69bece76c54c356537506021da904c4611a 100644 (file)
@@ -3,7 +3,7 @@
 
 
 /**
- * Adress alignment of the individual FPGA bytes.
+ * Address alignment of the individual FPGA bytes.
  * The address arrangement of the individual bytes of the FPGA is two
  * byte aligned at the embedded MK2 platform.
  */
index 00d8bf6164a950f1664b3f81fa8d1cc607e5fe61..83746b84a5ec53c3c2d36a84e3780050fcff7ad2 100644 (file)
@@ -45,7 +45,7 @@
 #define GT_PCI_IO_SIZE 0x02000000UL
 
 /*
- * PCI interrupts will come in on either the INTA or INTD interrups lines,
+ * PCI interrupts will come in on either the INTA or INTD interrupt lines,
  * which are mapped to the #2 and #5 interrupt pins of the MIPS.  On our
  * boards, they all either come in on IntD or they all come in on IntA, they
  * aren't mixed. There can be numerous PCI interrupts, so we keep a list of the
index 81b72122207ad47a8dc09118c1dae1f0d9bebf65..c4efeced8396da58d0bad7b56fc4f2da50d2f753 100644 (file)
@@ -58,7 +58,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
        return ret;
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_pages((unsigned long)pgd, PGD_ORDER);
 }
@@ -85,12 +85,12 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        return pte;
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_pages((unsigned long)pte, PTE_ORDER);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_pages(pte, PTE_ORDER);
 }
@@ -103,7 +103,7 @@ static inline void pte_free(struct page *pte)
  * allocating and freeing a pmd is trivial: the 1-entry pmd is
  * inside the pgd, so has no extra memory associated with it.
  */
-#define pmd_free(x)                    do { } while (0)
+#define pmd_free(mm, x)                        do { } while (0)
 #define __pmd_free_tlb(tlb, x)         do { } while (0)
 
 #endif
@@ -120,12 +120,12 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
        return pmd;
 }
 
-static inline void pmd_free(pmd_t *pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        free_pages((unsigned long)pmd, PMD_ORDER);
 }
 
-#define __pmd_free_tlb(tlb, x) pmd_free(x)
+#define __pmd_free_tlb(tlb, x) pmd_free((tlb)->mm, x)
 
 #endif
 
index 83bc94534084a429735e9d6620fdb1a02c2d9f80..36f42de594094b73f5b60ffc2dc0f09ebdf20b1c 100644 (file)
@@ -65,6 +65,8 @@ extern unsigned int vced_count, vcei_count;
 #define TASK_UNMAPPED_BASE                                             \
        (test_thread_flag(TIF_32BIT_ADDR) ?                             \
                PAGE_ALIGN(TASK_SIZE32 / 3) : PAGE_ALIGN(TASK_SIZE / 3))
+#define TASK_SIZE_OF(tsk)                                              \
+       (test_tsk_thread_flag(tsk, TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
 #endif
 
 #define NUM_FPU_REGS   32
index f4981c4f16bbfa999f49039dc76afa4a1a796973..c0501f91719b93a6a82db3fa082243eb500b9ffe 100644 (file)
@@ -15,7 +15,7 @@
 /*
  * These are the virtual IRQ numbers, we divide all IRQ's into
  * 'spaces', the 'space' determines where and how to enable/disable
- * that particular IRQ on an SGI machine. HPC DMA and MC DMA interrups
+ * that particular IRQ on an SGI machine. HPC DMA and MC DMA interrupts
  * are not supported this way. Driver is supposed to allocate HPC/MC
  * interrupt as shareable and then look to proper status bit (see
  * HAL2 driver). This will prevent many complications, trust me ;-)
index ef91b3363554ca8e1736112f3ab4a017b117e2cd..0187895e556c0f4a42bb4a83c544b16687551536 100644 (file)
@@ -338,7 +338,7 @@ typedef union io_perf_cnt {
 #define IIO_IFDR       0x400398        /* IOQ FIFO Depth */
 #define IIO_IIAP       0x4003a0        /* IIQ Arbitration Parameters */
 #define IIO_IMMR       IIO_IIAP
-#define IIO_ICMR       0x4003a8        /* CRB Managment Register */
+#define IIO_ICMR       0x4003a8        /* CRB Management Register */
 #define IIO_ICCR       0x4003b0        /* CRB Control Register */
 #define IIO_ICTO       0x4003b8        /* CRB Time Out Register */
 #define IIO_ICTP       0x4003c0        /* CRB Time Out Prescalar */
index 5a85d1b025c810de6e881931ce0ae3a38574216c..7f32611a7a5ebc1fe64e36716db7748df21c5070 100644 (file)
@@ -132,7 +132,7 @@ typedef u32         compat_sigset_word;
  * A pointer passed in from user mode. This should not
  * be used for syscall parameters, just declare them
  * as pointers because the syscall entry code will have
- * appropriately comverted them already.
+ * appropriately converted them already.
  */
 typedef        u32             compat_uptr_t;
 
index f628ac7de83dca17868b3737732b00c61354f62a..8e7946a141def9d1dfcd74ad6ffb5a73bd135554 100644 (file)
@@ -28,7 +28,7 @@
 #define EFA_PARISC_1_1             0x0210 /* PA-RISC 1.1 big-endian.  */
 #define EFA_PARISC_2_0             0x0214 /* PA-RISC 2.0 big-endian.  */
 
-/* Additional section indeces.  */
+/* Additional section indices.  */
 
 #define SHN_PARISC_ANSI_COMMON 0xff00     /* Section for tenatively declared
                                              symbols in ANSI C.  */
index ad8cd0d069eabd1a69fd6b802028950067b2e05e..0b19a7242d0c1237a1f0f9a079043149b0b8b7df 100644 (file)
@@ -8,7 +8,7 @@
 
 /*
  * In parisc assembly a semicolon marks a comment while a
- * exclamation mark is used to seperate independent lines.
+ * exclamation mark is used to separate independent lines.
  */
 #ifdef __ASSEMBLY__
 
index 1af1a41e07233fa52e6d5da67afceecaf1d69301..aab66f1bea14d67c3381d39ba6bd0d15550467b7 100644 (file)
@@ -43,7 +43,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
        return actual_pgd;
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
 #ifdef CONFIG_64BIT
        pgd -= PTRS_PER_PGD;
@@ -70,7 +70,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
        return pmd;
 }
 
-static inline void pmd_free(pmd_t *pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
 #ifdef CONFIG_64BIT
        if(pmd_flag(*pmd) & PxD_FLAG_ATTACHED)
@@ -91,7 +91,7 @@ static inline void pmd_free(pmd_t *pmd)
  */
 
 #define pmd_alloc_one(mm, addr)                ({ BUG(); ((pmd_t *)2); })
-#define pmd_free(x)                    do { } while (0)
+#define pmd_free(mm, x)                        do { } while (0)
 #define pgd_populate(mm, pmd, pte)     BUG()
 
 #endif
@@ -130,12 +130,12 @@ pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
        return pte;
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-#define pte_free(page) pte_free_kernel(page_address(page))
+#define pte_free(mm, page) pte_free_kernel(page_address(page))
 
 #define check_pgt_cache()      do { } while (0)
 
index 6b294fb07a23d6aa9018599f46c80731abb4bb58..3bb06e898fdef5f0ad27d66a7144ed2e945c6d06 100644 (file)
@@ -32,7 +32,8 @@
 #endif
 #define current_text_addr() ({ void *pc; current_ia(pc); pc; })
 
-#define TASK_SIZE               (current->thread.task_size)
+#define TASK_SIZE_OF(tsk)       ((tsk)->thread.task_size)
+#define TASK_SIZE              TASK_SIZE_OF(current)
 #define TASK_UNMAPPED_BASE      (current->thread.map_base)
 
 #define DEFAULT_TASK_SIZE32    (0xFFF00000UL)
index 33107a248e1f76b991129adeaa30d69bcd4d4f1d..383b1db310ee71e18789112587f9ba3e818bdd25 100644 (file)
@@ -21,7 +21,7 @@ do {  if (!(tlb)->fullmm)     \
 
 #include <asm-generic/tlb.h>
 
-#define __pmd_free_tlb(tlb, pmd)       pmd_free(pmd)
-#define __pte_free_tlb(tlb, pte)       pte_free(pte)
+#define __pmd_free_tlb(tlb, pmd)       pmd_free((tlb)->mm, pmd)
+#define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, pte)
 
 #endif
index 154a84c843a749b459e05151079c2d431acda324..171399a88ca6aa175778c7bb3d727fd5c8cc7147 100644 (file)
@@ -3,4 +3,4 @@
 
 /* nothing */
 
-#endif __ASM_PARISC_VGA_H__
+#endif /* __ASM_PARISC_VGA_H__ */
index 64ab1ddbdf85c5d2cba8ca73750b873b43040a4d..d811a8cd7b58c9397200be83cf0ee333c313e037 100644 (file)
@@ -119,7 +119,7 @@ typedef u32         compat_sigset_word;
  * A pointer passed in from user mode. This should not
  * be used for syscall parameters, just declare them
  * as pointers because the syscall entry code will have
- * appropriately comverted them already.
+ * appropriately converted them already.
  */
 typedef        u32             compat_uptr_t;
 
index 310804485208d49b8f0a5438c33e04186dd2c70d..f42e623030eece0edb4a8f30c37db795c44f2395 100644 (file)
@@ -52,12 +52,26 @@ typedef u64 cputime64_t;
  * Convert cputime <-> jiffies
  */
 extern u64 __cputime_jiffies_factor;
+DECLARE_PER_CPU(unsigned long, cputime_last_delta);
+DECLARE_PER_CPU(unsigned long, cputime_scaled_last_delta);
 
 static inline unsigned long cputime_to_jiffies(const cputime_t ct)
 {
        return mulhdu(ct, __cputime_jiffies_factor);
 }
 
+/* Estimate the scaled cputime by scaling the real cputime based on
+ * the last scaled to real ratio */
+static inline cputime_t cputime_to_scaled(const cputime_t ct)
+{
+       if (cpu_has_feature(CPU_FTR_SPURR) &&
+           per_cpu(cputime_last_delta, smp_processor_id()))
+               return ct *
+                       per_cpu(cputime_scaled_last_delta, smp_processor_id())/
+                       per_cpu(cputime_last_delta, smp_processor_id());
+       return ct;
+}
+
 static inline cputime_t jiffies_to_cputime(const unsigned long jif)
 {
        cputime_t ct;
index 7a4374bdbef48fa482e55682e92e3e8cc74fdfa0..a7e06e25c7083b6648109f66a4e04f551672cf86 100644 (file)
  *
  */
 
-/* see prep_setup_arch() for detailed informations */
-#if defined(CONFIG_SOUND_CS4232) && defined(CONFIG_PPC_PREP)
-extern long ppc_cs4232_dma, ppc_cs4232_dma2;
-#define SND_DMA1 ppc_cs4232_dma
-#define SND_DMA2 ppc_cs4232_dma2
-#else
-#define SND_DMA1 -1
-#define SND_DMA2 -1
-#endif
-
 /* 8237 DMA controllers */
 #define IO_DMA1_BASE   0x00    /* 8 bit slave DMA, channels 0..3 */
 #define IO_DMA2_BASE   0xC0    /* 16 bit master DMA, ch 4(=slave input)..7 */
@@ -269,24 +259,15 @@ static __inline__ void set_dma_page(unsigned int dmanr, int pagenr)
                dma_outb(pagenr >> 8, DMA_HI_PAGE_3);
                break;
        case 5:
-               if (SND_DMA1 == 5 || SND_DMA2 == 5)
-                       dma_outb(pagenr, DMA_LO_PAGE_5);
-               else
-                       dma_outb(pagenr & 0xfe, DMA_LO_PAGE_5);
+               dma_outb(pagenr & 0xfe, DMA_LO_PAGE_5);
                dma_outb(pagenr >> 8, DMA_HI_PAGE_5);
                break;
        case 6:
-               if (SND_DMA1 == 6 || SND_DMA2 == 6)
-                       dma_outb(pagenr, DMA_LO_PAGE_6);
-               else
-                       dma_outb(pagenr & 0xfe, DMA_LO_PAGE_6);
+               dma_outb(pagenr & 0xfe, DMA_LO_PAGE_6);
                dma_outb(pagenr >> 8, DMA_HI_PAGE_6);
                break;
        case 7:
-               if (SND_DMA1 == 7 || SND_DMA2 == 7)
-                       dma_outb(pagenr, DMA_LO_PAGE_7);
-               else
-                       dma_outb(pagenr & 0xfe, DMA_LO_PAGE_7);
+               dma_outb(pagenr & 0xfe, DMA_LO_PAGE_7);
                dma_outb(pagenr >> 8, DMA_HI_PAGE_7);
                break;
        }
@@ -302,12 +283,6 @@ static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int phys)
                         ((dmanr & 3) << 1) + IO_DMA1_BASE);
                dma_outb((phys >> 8) & 0xff,
                         ((dmanr & 3) << 1) + IO_DMA1_BASE);
-       } else if (dmanr == SND_DMA1 || dmanr == SND_DMA2) {
-               dma_outb(phys & 0xff,
-                        ((dmanr & 3) << 2) + IO_DMA2_BASE);
-               dma_outb((phys >> 8) & 0xff,
-                        ((dmanr & 3) << 2) + IO_DMA2_BASE);
-               dma_outb((dmanr & 3), DMA2_EXT_REG);
        } else {
                dma_outb((phys >> 1) & 0xff,
                         ((dmanr & 3) << 2) + IO_DMA2_BASE);
@@ -334,11 +309,6 @@ static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
                         ((dmanr & 3) << 1) + 1 + IO_DMA1_BASE);
                dma_outb((count >> 8) & 0xff,
                         ((dmanr & 3) << 1) + 1 + IO_DMA1_BASE);
-       } else if (dmanr == SND_DMA1 || dmanr == SND_DMA2) {
-               dma_outb(count & 0xff,
-                        ((dmanr & 3) << 2) + 2 + IO_DMA2_BASE);
-               dma_outb((count >> 8) & 0xff,
-                        ((dmanr & 3) << 2) + 2 + IO_DMA2_BASE);
        } else {
                dma_outb((count >> 1) & 0xff,
                         ((dmanr & 3) << 2) + 2 + IO_DMA2_BASE);
@@ -368,8 +338,7 @@ static __inline__ int get_dma_residue(unsigned int dmanr)
        count = 1 + dma_inb(io_port);
        count += dma_inb(io_port) << 8;
 
-       return (dmanr <= 3 || dmanr == SND_DMA1 || dmanr == SND_DMA2)
-           ? count : (count << 1);
+       return (dmanr <= 3) ? count : (count << 1);
 }
 
 /* These are in kernel/dma.c: */
index 7a3cef785abdee2aa52b2cdc6716bdf04348b291..852e15f51a1e85f68260f31c2ad737d0b8eb35ad 100644 (file)
@@ -79,19 +79,19 @@ extern void iommu_free_table(struct iommu_table *tbl, const char *node_name);
 extern struct iommu_table *iommu_init_table(struct iommu_table * tbl,
                                            int nid);
 
-extern int iommu_map_sg(struct iommu_table *tbl, struct scatterlist *sglist,
+extern int iommu_map_sg(struct device *dev, struct scatterlist *sglist,
                        int nelems, unsigned long mask,
                        enum dma_data_direction direction);
 extern void iommu_unmap_sg(struct iommu_table *tbl, struct scatterlist *sglist,
                           int nelems, enum dma_data_direction direction);
 
-extern void *iommu_alloc_coherent(struct iommu_table *tbl, size_t size,
-                                 dma_addr_t *dma_handle, unsigned long mask,
-                                 gfp_t flag, int node);
+extern void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
+                                 size_t size, dma_addr_t *dma_handle,
+                                 unsigned long mask, gfp_t flag, int node);
 extern void iommu_free_coherent(struct iommu_table *tbl, size_t size,
                                void *vaddr, dma_addr_t dma_handle);
-extern dma_addr_t iommu_map_single(struct iommu_table *tbl, void *vaddr,
-                                  size_t size, unsigned long mask,
+extern dma_addr_t iommu_map_single(struct device *dev, struct iommu_table *tbl,
+                                  void *vaddr, size_t size, unsigned long mask,
                                   enum dma_data_direction direction);
 extern void iommu_unmap_single(struct iommu_table *tbl, dma_addr_t dma_handle,
                               size_t size, enum dma_data_direction direction);
index 9daa3252d7b6a42dd5fbbb22f6ba80c89ae76d03..de83fe196309143d4cab3a7e42c9a06b034613ad 100644 (file)
 #define MB_NO          7       /* media bay contains nothing */
 
 int check_media_bay(struct device_node *which_bay, int what);
-int check_media_bay_by_base(unsigned long base, int what);
 
 /* Number of bays in the machine or 0 */
 extern int media_bay_count;
 
-/* called by pmac-ide.c to register IDE controller for media bay */
-extern int media_bay_set_ide_infos(struct device_node* which_bay,
-                       unsigned long base, int irq, int index);
+int check_media_bay_by_base(unsigned long base, int what);
+/* called by IDE PMAC host driver to register IDE controller for media bay */
+int media_bay_set_ide_infos(struct device_node *which_bay, unsigned long base,
+                           int irq, int index);
 
 #endif /* __KERNEL__ */
 #endif /* _PPC_MEDIABAY_H */
index 4e7059cc6113f054fbaf8de634c2a9c05f785062..efde5ac82f7b915df030d42cae81c38fc63803fe 100644 (file)
@@ -58,6 +58,9 @@ struct nvram_header {
 };
 
 #ifdef __KERNEL__
+
+#include <linux/list.h>
+
 struct nvram_partition {
        struct list_head partition;
        struct nvram_header header;
index f6dfce025adfe4d117587321782b607028142bbf..748b35ab37b5aa7fdf02291149777d3117803467 100644 (file)
@@ -115,8 +115,6 @@ struct paca_struct {
        u64 system_time;                /* accumulated system TB ticks */
        u64 startpurr;                  /* PURR/TB value snapshot */
        u64 startspurr;                 /* SPURR value snapshot */
-       u64 purrdelta;                  /* FIXME: document */
-       u64 spurrdelta;                 /* FIXME: document */
 };
 
 extern struct paca_struct paca[];
index e1307432163c4cd1444e924b18f29fd02b0a8f91..c162a4c37b39ce5df12573c209dfd3a1edbdd59b 100644 (file)
@@ -6,14 +6,14 @@
 extern void __bad_pte(pmd_t *pmd);
 
 extern pgd_t *pgd_alloc(struct mm_struct *mm);
-extern void pgd_free(pgd_t *pgd);
+extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
 
 /*
  * We don't have any real pmd's, and this code never triggers because
  * the pgd will always be present..
  */
 /* #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); }) */
-#define pmd_free(x)                     do { } while (0)
+#define pmd_free(mm, x)                do { } while (0)
 #define __pmd_free_tlb(tlb,x)          do { } while (0)
 /* #define pgd_populate(mm, pmd, pte)      BUG() */
 
@@ -31,10 +31,10 @@ extern void pgd_free(pgd_t *pgd);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr);
 extern struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr);
-extern void pte_free_kernel(pte_t *pte);
-extern void pte_free(struct page *pte);
+extern void pte_free_kernel(struct mm_struct *mm, pte_t *pte);
+extern void pte_free(struct mm_struct *mm, struct page *pte);
 
-#define __pte_free_tlb(tlb, pte)       pte_free((pte))
+#define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, (pte))
 
 #define check_pgt_cache()      do { } while (0)
 
index 43214c8085b7f36cdf44a205e8c5fac8a3aad7b1..5afae8593931e5cf4966688307488adfc856a38b 100644 (file)
@@ -29,7 +29,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
        return kmem_cache_alloc(pgtable_cache[PGD_CACHE_NUM], GFP_KERNEL);
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        subpage_prot_free(pgd);
        kmem_cache_free(pgtable_cache[PGD_CACHE_NUM], pgd);
@@ -45,7 +45,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
                                GFP_KERNEL|__GFP_REPEAT);
 }
 
-static inline void pud_free(pud_t *pud)
+static inline void pud_free(struct mm_struct *mm, pud_t *pud)
 {
        kmem_cache_free(pgtable_cache[PUD_CACHE_NUM], pud);
 }
@@ -81,7 +81,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
                                GFP_KERNEL|__GFP_REPEAT);
 }
 
-static inline void pmd_free(pmd_t *pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        kmem_cache_free(pgtable_cache[PMD_CACHE_NUM], pmd);
 }
@@ -99,12 +99,12 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        return pte ? virt_to_page(pte) : NULL;
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct page *ptepage)
+static inline void pte_free(struct mm_struct *mm, struct page *ptepage)
 {
        __free_page(ptepage);
 }
index dba7c948189db065a0862bcfa8c438f236a15ada..1f4765d6546fe0313b6bbc150ff38b509d6811ba 100644 (file)
@@ -99,8 +99,9 @@ extern struct task_struct *last_task_used_spe;
  */
 #define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))
 
-#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
+#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
                TASK_SIZE_USER32 : TASK_SIZE_USER64)
+#define TASK_SIZE        TASK_SIZE_OF(current)
 
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
index 967930b82ed3591e566ad8755713c507c70511dc..fda98715cd356a4b74a18e66c860c81ed62ee50a 100644 (file)
 #define PS3AV_MONITOR_TYPE_HDMI                        1       /* HDMI */
 #define PS3AV_MONITOR_TYPE_DVI                 2       /* DVI */
 
-#define PS3AV_DEFAULT_HDMI_MODE_ID_REG_60      2       /* 480p */
-#define PS3AV_DEFAULT_AVMULTI_MODE_ID_REG_60   1       /* 480i */
-#define PS3AV_DEFAULT_HDMI_MODE_ID_REG_50      7       /* 576p */
-#define PS3AV_DEFAULT_AVMULTI_MODE_ID_REG_50   6       /* 576i */
-
-#define PS3AV_REGION_60                                0x01
-#define PS3AV_REGION_50                                0x02
-#define PS3AV_REGION_RGB                       0x10
-
-#define get_status(buf)                                (((__u32 *)buf)[2])
-#define PS3AV_HDR_SIZE                         4       /* version + size */
 
 /* for video mode */
+enum ps3av_mode_num {
+       PS3AV_MODE_AUTO                         = 0,
+       PS3AV_MODE_480I                         = 1,
+       PS3AV_MODE_480P                         = 2,
+       PS3AV_MODE_720P60                       = 3,
+       PS3AV_MODE_1080I60                      = 4,
+       PS3AV_MODE_1080P60                      = 5,
+       PS3AV_MODE_576I                         = 6,
+       PS3AV_MODE_576P                         = 7,
+       PS3AV_MODE_720P50                       = 8,
+       PS3AV_MODE_1080I50                      = 9,
+       PS3AV_MODE_1080P50                      = 10,
+       PS3AV_MODE_WXGA                         = 11,
+       PS3AV_MODE_SXGA                         = 12,
+       PS3AV_MODE_WUXGA                        = 13,
+};
+
 #define PS3AV_MODE_MASK                                0x000F
 #define PS3AV_MODE_HDCP_OFF                    0x1000  /* Retail PS3 product doesn't support this */
 #define PS3AV_MODE_DITHER                      0x0800
 #define PS3AV_MODE_RGB                         0x0020
 
 
+#define PS3AV_DEFAULT_HDMI_MODE_ID_REG_60      PS3AV_MODE_480P
+#define PS3AV_DEFAULT_AVMULTI_MODE_ID_REG_60   PS3AV_MODE_480I
+#define PS3AV_DEFAULT_HDMI_MODE_ID_REG_50      PS3AV_MODE_576P
+#define PS3AV_DEFAULT_AVMULTI_MODE_ID_REG_50   PS3AV_MODE_576I
+
+#define PS3AV_REGION_60                                0x01
+#define PS3AV_REGION_50                                0x02
+#define PS3AV_REGION_RGB                       0x10
+
+#define get_status(buf)                                (((__u32 *)buf)[2])
+#define PS3AV_HDR_SIZE                         4       /* version + size */
+
+
 /** command packet structure **/
 struct ps3av_send_hdr {
        u16 version;
@@ -713,8 +732,6 @@ extern int ps3av_set_video_mode(u32);
 extern int ps3av_set_audio_mode(u32, u32, u32, u32, u32);
 extern int ps3av_get_auto_mode(void);
 extern int ps3av_get_mode(void);
-extern int ps3av_get_scanmode(int);
-extern int ps3av_get_refresh_rate(int);
 extern int ps3av_video_mode2res(u32, u32 *, u32 *);
 extern int ps3av_video_mute(int);
 extern int ps3av_audio_mute(int);
index 0c8b0d6791399aa45605e0b3024f97f0511d649c..e996521fb3a686d09f128db627e2bd1d370428b9 100644 (file)
@@ -309,7 +309,7 @@ SYSCALL_SPU(getcpu)
 COMPAT_SYS(epoll_pwait)
 COMPAT_SYS_SPU(utimensat)
 COMPAT_SYS_SPU(signalfd)
-COMPAT_SYS_SPU(timerfd)
+SYSCALL(ni_syscall)
 SYSCALL_SPU(eventfd)
 COMPAT_SYS_SPU(sync_file_range2)
 COMPAT_SYS(fallocate)
index 44d88a98e87ca8a57d0f6a90cae48bd93c193822..7c39a95829c7263932cf445fe94200c050991df4 100644 (file)
@@ -7,14 +7,14 @@
 extern void __bad_pte(pmd_t *pmd);
 
 extern pgd_t *pgd_alloc(struct mm_struct *mm);
-extern void pgd_free(pgd_t *pgd);
+extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
 
 /*
  * We don't have any real pmd's, and this code never triggers because
  * the pgd will always be present..
  */
 #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); })
-#define pmd_free(x)                     do { } while (0)
+#define pmd_free(mm, x)                do { } while (0)
 #define __pmd_free_tlb(tlb,x)          do { } while (0)
 #define pgd_populate(mm, pmd, pte)      BUG()
 
@@ -32,10 +32,10 @@ extern void pgd_free(pgd_t *pgd);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr);
 extern struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr);
-extern void pte_free_kernel(pte_t *pte);
-extern void pte_free(struct page *pte);
+extern void pte_free_kernel(struct mm_struct *mm, pte_t *pte);
+extern void pte_free(struct mm_struct *mm, struct page *pte);
 
-#define __pte_free_tlb(tlb, pte)       pte_free((pte))
+#define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, (pte))
 
 #define check_pgt_cache()      do { } while (0)
 
index dba6fecad0be25353c535ddc1ac3feb64341dbcd..882db054110cbe9f8c7487e6dfe89cdc0647776e 100644 (file)
@@ -440,242 +440,256 @@ __constant_test_bit(unsigned long nr, const volatile unsigned long *addr) {
  __test_bit((nr),(addr)) )
 
 /*
- * ffz = Find First Zero in word. Undefined if no zero exists,
- * so code should check against ~0UL first..
+ * Optimized find bit helper functions.
  */
-static inline unsigned long ffz(unsigned long word)
+
+/**
+ * __ffz_word_loop - find byte offset of first long != -1UL
+ * @addr: pointer to array of unsigned long
+ * @size: size of the array in bits
+ */
+static inline unsigned long __ffz_word_loop(const unsigned long *addr,
+                                           unsigned long size)
 {
-        unsigned long bit = 0;
+       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
+       unsigned long bytes = 0;
 
+       asm volatile(
+#ifndef __s390x__
+               "       ahi     %1,31\n"
+               "       srl     %1,5\n"
+               "0:     c       %2,0(%0,%3)\n"
+               "       jne     1f\n"
+               "       la      %0,4(%0)\n"
+               "       brct    %1,0b\n"
+               "1:\n"
+#else
+               "       aghi    %1,63\n"
+               "       srlg    %1,%1,6\n"
+               "0:     cg      %2,0(%0,%3)\n"
+               "       jne     1f\n"
+               "       la      %0,8(%0)\n"
+               "       brct    %1,0b\n"
+               "1:\n"
+#endif
+               : "+a" (bytes), "+d" (size)
+               : "d" (-1UL), "a" (addr), "m" (*(addrtype *) addr)
+               : "cc" );
+       return bytes;
+}
+
+/**
+ * __ffs_word_loop - find byte offset of first long != 0UL
+ * @addr: pointer to array of unsigned long
+ * @size: size of the array in bits
+ */
+static inline unsigned long __ffs_word_loop(const unsigned long *addr,
+                                           unsigned long size)
+{
+       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
+       unsigned long bytes = 0;
+
+       asm volatile(
+#ifndef __s390x__
+               "       ahi     %1,31\n"
+               "       srl     %1,5\n"
+               "0:     c       %2,0(%0,%3)\n"
+               "       jne     1f\n"
+               "       la      %0,4(%0)\n"
+               "       brct    %1,0b\n"
+               "1:\n"
+#else
+               "       aghi    %1,63\n"
+               "       srlg    %1,%1,6\n"
+               "0:     cg      %2,0(%0,%3)\n"
+               "       jne     1f\n"
+               "       la      %0,8(%0)\n"
+               "       brct    %1,0b\n"
+               "1:\n"
+#endif
+               : "+a" (bytes), "+a" (size)
+               : "d" (0UL), "a" (addr), "m" (*(addrtype *) addr)
+               : "cc" );
+       return bytes;
+}
+
+/**
+ * __ffz_word - add number of the first unset bit
+ * @nr: base value the bit number is added to
+ * @word: the word that is searched for unset bits
+ */
+static inline unsigned long __ffz_word(unsigned long nr, unsigned long word)
+{
 #ifdef __s390x__
        if (likely((word & 0xffffffff) == 0xffffffff)) {
                word >>= 32;
-               bit += 32;
+               nr += 32;
        }
 #endif
        if (likely((word & 0xffff) == 0xffff)) {
                word >>= 16;
-               bit += 16;
+               nr += 16;
        }
        if (likely((word & 0xff) == 0xff)) {
                word >>= 8;
-               bit += 8;
+               nr += 8;
        }
-       return bit + _zb_findmap[word & 0xff];
+       return nr + _zb_findmap[(unsigned char) word];
 }
 
-/*
- * __ffs = find first bit in word. Undefined if no bit exists,
- * so code should check against 0UL first..
+/**
+ * __ffs_word - add number of the first set bit
+ * @nr: base value the bit number is added to
+ * @word: the word that is searched for set bits
  */
-static inline unsigned long __ffs (unsigned long word)
+static inline unsigned long __ffs_word(unsigned long nr, unsigned long word)
 {
-       unsigned long bit = 0;
-
 #ifdef __s390x__
        if (likely((word & 0xffffffff) == 0)) {
                word >>= 32;
-               bit += 32;
+               nr += 32;
        }
 #endif
        if (likely((word & 0xffff) == 0)) {
                word >>= 16;
-               bit += 16;
+               nr += 16;
        }
        if (likely((word & 0xff) == 0)) {
                word >>= 8;
-               bit += 8;
+               nr += 8;
        }
-       return bit + _sb_findmap[word & 0xff];
+       return nr + _sb_findmap[(unsigned char) word];
 }
 
-/*
- * Find-bit routines..
- */
 
-#ifndef __s390x__
+/**
+ * __load_ulong_be - load big endian unsigned long
+ * @p: pointer to array of unsigned long
+ * @offset: byte offset of source value in the array
+ */
+static inline unsigned long __load_ulong_be(const unsigned long *p,
+                                           unsigned long offset)
+{
+       p = (unsigned long *)((unsigned long) p + offset);
+       return *p;
+}
 
-static inline int
-find_first_zero_bit(const unsigned long * addr, unsigned long size)
+/**
+ * __load_ulong_le - load little endian unsigned long
+ * @p: pointer to array of unsigned long
+ * @offset: byte offset of source value in the array
+ */
+static inline unsigned long __load_ulong_le(const unsigned long *p,
+                                           unsigned long offset)
 {
-       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
-       unsigned long cmp, count;
-        unsigned int res;
+       unsigned long word;
 
-        if (!size)
-                return 0;
+       p = (unsigned long *)((unsigned long) p + offset);
+#ifndef __s390x__
        asm volatile(
-               "       lhi     %1,-1\n"
-               "       lr      %2,%3\n"
-               "       slr     %0,%0\n"
-               "       ahi     %2,31\n"
-               "       srl     %2,5\n"
-               "0:     c       %1,0(%0,%4)\n"
-               "       jne     1f\n"
-               "       la      %0,4(%0)\n"
-               "       brct    %2,0b\n"
-               "       lr      %0,%3\n"
-               "       j       4f\n"
-               "1:     l       %2,0(%0,%4)\n"
-               "       sll     %0,3\n"
-               "       lhi     %1,0xff\n"
-               "       tml     %2,0xffff\n"
-               "       jno     2f\n"
-               "       ahi     %0,16\n"
-               "       srl     %2,16\n"
-               "2:     tml     %2,0x00ff\n"
-               "       jno     3f\n"
-               "       ahi     %0,8\n"
-               "       srl     %2,8\n"
-               "3:     nr      %2,%1\n"
-               "       ic      %2,0(%2,%5)\n"
-               "       alr     %0,%2\n"
-               "4:"
-               : "=&a" (res), "=&d" (cmp), "=&a" (count)
-               : "a" (size), "a" (addr), "a" (&_zb_findmap),
-                 "m" (*(addrtype *) addr) : "cc");
-        return (res < size) ? res : size;
+               "       ic      %0,0(%1)\n"
+               "       icm     %0,2,1(%1)\n"
+               "       icm     %0,4,2(%1)\n"
+               "       icm     %0,8,3(%1)"
+               : "=&d" (word) : "a" (p), "m" (*p) : "cc");
+#else
+       asm volatile(
+               "       lrvg    %0,%1"
+               : "=d" (word) : "m" (*p) );
+#endif
+       return word;
 }
 
-static inline int
-find_first_bit(const unsigned long * addr, unsigned long size)
+/*
+ * The various find bit functions.
+ */
+
+/*
+ * ffz - find first zero in word.
+ * @word: The word to search
+ *
+ * Undefined if no zero exists, so code should check against ~0UL first.
+ */
+static inline unsigned long ffz(unsigned long word)
 {
-       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
-       unsigned long cmp, count;
-        unsigned int res;
+       return __ffz_word(0, word);
+}
 
-        if (!size)
-                return 0;
-       asm volatile(
-               "       slr     %1,%1\n"
-               "       lr      %2,%3\n"
-               "       slr     %0,%0\n"
-               "       ahi     %2,31\n"
-               "       srl     %2,5\n"
-               "0:     c       %1,0(%0,%4)\n"
-               "       jne     1f\n"
-               "       la      %0,4(%0)\n"
-               "       brct    %2,0b\n"
-               "       lr      %0,%3\n"
-               "       j       4f\n"
-               "1:     l       %2,0(%0,%4)\n"
-               "       sll     %0,3\n"
-               "       lhi     %1,0xff\n"
-               "       tml     %2,0xffff\n"
-               "       jnz     2f\n"
-               "       ahi     %0,16\n"
-               "       srl     %2,16\n"
-               "2:     tml     %2,0x00ff\n"
-               "       jnz     3f\n"
-               "       ahi     %0,8\n"
-               "       srl     %2,8\n"
-               "3:     nr      %2,%1\n"
-               "       ic      %2,0(%2,%5)\n"
-               "       alr     %0,%2\n"
-               "4:"
-               : "=&a" (res), "=&d" (cmp), "=&a" (count)
-               : "a" (size), "a" (addr), "a" (&_sb_findmap),
-                 "m" (*(addrtype *) addr) : "cc");
-        return (res < size) ? res : size;
+/**
+ * __ffs - find first bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static inline unsigned long __ffs (unsigned long word)
+{
+       return __ffs_word(0, word);
 }
 
-#else /* __s390x__ */
+/**
+ * ffs - find first bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as
+ * the libc and compiler builtin ffs routines, therefore
+ * differs in spirit from the above ffz (man ffs).
+ */
+static inline int ffs(int x)
+{
+       if (!x)
+               return 0;
+       return __ffs_word(1, x);
+}
 
-static inline unsigned long
-find_first_zero_bit(const unsigned long * addr, unsigned long size)
+/**
+ * find_first_zero_bit - find the first zero bit in a memory region
+ * @addr: The address to start the search at
+ * @size: The maximum size to search
+ *
+ * Returns the bit-number of the first zero bit, not the number of the byte
+ * containing a bit.
+ */
+static inline unsigned long find_first_zero_bit(const unsigned long *addr,
+                                               unsigned long size)
 {
-       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
-        unsigned long res, cmp, count;
+       unsigned long bytes, bits;
 
         if (!size)
                 return 0;
-       asm volatile(
-               "       lghi    %1,-1\n"
-               "       lgr     %2,%3\n"
-               "       slgr    %0,%0\n"
-               "       aghi    %2,63\n"
-               "       srlg    %2,%2,6\n"
-               "0:     cg      %1,0(%0,%4)\n"
-               "       jne     1f\n"
-               "       la      %0,8(%0)\n"
-               "       brct    %2,0b\n"
-               "       lgr     %0,%3\n"
-               "       j       5f\n"
-               "1:     lg      %2,0(%0,%4)\n"
-               "       sllg    %0,%0,3\n"
-               "       clr     %2,%1\n"
-               "       jne     2f\n"
-               "       aghi    %0,32\n"
-               "       srlg    %2,%2,32\n"
-               "2:     lghi    %1,0xff\n"
-               "       tmll    %2,0xffff\n"
-               "       jno     3f\n"
-               "       aghi    %0,16\n"
-               "       srl     %2,16\n"
-               "3:     tmll    %2,0x00ff\n"
-               "       jno     4f\n"
-               "       aghi    %0,8\n"
-               "       srl     %2,8\n"
-               "4:     ngr     %2,%1\n"
-               "       ic      %2,0(%2,%5)\n"
-               "       algr    %0,%2\n"
-               "5:"
-               : "=&a" (res), "=&d" (cmp), "=&a" (count)
-               : "a" (size), "a" (addr), "a" (&_zb_findmap),
-                 "m" (*(addrtype *) addr) : "cc");
-        return (res < size) ? res : size;
-}
-
-static inline unsigned long
-find_first_bit(const unsigned long * addr, unsigned long size)
+       bytes = __ffz_word_loop(addr, size);
+       bits = __ffz_word(bytes*8, __load_ulong_be(addr, bytes));
+       return (bits < size) ? bits : size;
+}
+
+/**
+ * find_first_bit - find the first set bit in a memory region
+ * @addr: The address to start the search at
+ * @size: The maximum size to search
+ *
+ * Returns the bit-number of the first set bit, not the number of the byte
+ * containing a bit.
+ */
+static inline unsigned long find_first_bit(const unsigned long * addr,
+                                          unsigned long size)
 {
-       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
-        unsigned long res, cmp, count;
+       unsigned long bytes, bits;
 
         if (!size)
                 return 0;
-       asm volatile(
-               "       slgr    %1,%1\n"
-               "       lgr     %2,%3\n"
-               "       slgr    %0,%0\n"
-               "       aghi    %2,63\n"
-               "       srlg    %2,%2,6\n"
-               "0:     cg      %1,0(%0,%4)\n"
-               "       jne     1f\n"
-               "       aghi    %0,8\n"
-               "       brct    %2,0b\n"
-               "       lgr     %0,%3\n"
-               "       j       5f\n"
-               "1:     lg      %2,0(%0,%4)\n"
-               "       sllg    %0,%0,3\n"
-               "       clr     %2,%1\n"
-               "       jne     2f\n"
-               "       aghi    %0,32\n"
-               "       srlg    %2,%2,32\n"
-               "2:     lghi    %1,0xff\n"
-               "       tmll    %2,0xffff\n"
-               "       jnz     3f\n"
-               "       aghi    %0,16\n"
-               "       srl     %2,16\n"
-               "3:     tmll    %2,0x00ff\n"
-               "       jnz     4f\n"
-               "       aghi    %0,8\n"
-               "       srl     %2,8\n"
-               "4:     ngr     %2,%1\n"
-               "       ic      %2,0(%2,%5)\n"
-               "       algr    %0,%2\n"
-               "5:"
-               : "=&a" (res), "=&d" (cmp), "=&a" (count)
-               : "a" (size), "a" (addr), "a" (&_sb_findmap),
-                 "m" (*(addrtype *) addr) : "cc");
-        return (res < size) ? res : size;
+       bytes = __ffs_word_loop(addr, size);
+       bits = __ffs_word(bytes*8, __load_ulong_be(addr, bytes));
+       return (bits < size) ? bits : size;
 }
 
-#endif /* __s390x__ */
-
-static inline int
-find_next_zero_bit (const unsigned long * addr, unsigned long size,
-                   unsigned long offset)
+/**
+ * find_next_zero_bit - find the first zero bit in a memory region
+ * @addr: The address to base the search on
+ * @offset: The bitnumber to start searching at
+ * @size: The maximum size to search
+ */
+static inline int find_next_zero_bit (const unsigned long * addr,
+                                     unsigned long size,
+                                     unsigned long offset)
 {
         const unsigned long *p;
        unsigned long bit, set;
@@ -688,10 +702,10 @@ find_next_zero_bit (const unsigned long * addr, unsigned long size,
        p = addr + offset / __BITOPS_WORDSIZE;
        if (bit) {
                /*
-                * s390 version of ffz returns __BITOPS_WORDSIZE
+                * __ffz_word returns __BITOPS_WORDSIZE
                 * if no zero bit is present in the word.
                 */
-               set = ffz(*p >> bit) + bit;
+               set = __ffz_word(0, *p >> bit) + bit;
                if (set >= size)
                        return size + offset;
                if (set < __BITOPS_WORDSIZE)
@@ -703,9 +717,15 @@ find_next_zero_bit (const unsigned long * addr, unsigned long size,
        return offset + find_first_zero_bit(p, size);
 }
 
-static inline int
-find_next_bit (const unsigned long * addr, unsigned long size,
-              unsigned long offset)
+/**
+ * find_next_bit - find the first set bit in a memory region
+ * @addr: The address to base the search on
+ * @offset: The bitnumber to start searching at
+ * @size: The maximum size to search
+ */
+static inline int find_next_bit (const unsigned long * addr,
+                                unsigned long size,
+                                unsigned long offset)
 {
         const unsigned long *p;
        unsigned long bit, set;
@@ -718,10 +738,10 @@ find_next_bit (const unsigned long * addr, unsigned long size,
        p = addr + offset / __BITOPS_WORDSIZE;
        if (bit) {
                /*
-                * s390 version of __ffs returns __BITOPS_WORDSIZE
+                * __ffs_word returns __BITOPS_WORDSIZE
                 * if no one bit is present in the word.
                 */
-               set = __ffs(*p & (~0UL << bit));
+               set = __ffs_word(0, *p & (~0UL << bit));
                if (set >= size)
                        return size + offset;
                if (set < __BITOPS_WORDSIZE)
@@ -744,8 +764,6 @@ static inline int sched_find_first_bit(unsigned long *b)
        return find_first_bit(b, 140);
 }
 
-#include <asm-generic/bitops/ffs.h>
-
 #include <asm-generic/bitops/fls.h>
 #include <asm-generic/bitops/fls64.h>
 
@@ -772,108 +790,23 @@ static inline int sched_find_first_bit(unsigned long *b)
        test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
 #define ext2_test_bit(nr, addr)      \
        test_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
-#define ext2_find_next_bit(addr, size, off) \
-       generic_find_next_le_bit((unsigned long *)(addr), (size), (off))
 
-#ifndef __s390x__
-
-static inline int 
-ext2_find_first_zero_bit(void *vaddr, unsigned int size)
+static inline int ext2_find_first_zero_bit(void *vaddr, unsigned int size)
 {
-       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
-       unsigned long cmp, count;
-        unsigned int res;
+       unsigned long bytes, bits;
 
         if (!size)
                 return 0;
-       asm volatile(
-               "       lhi     %1,-1\n"
-               "       lr      %2,%3\n"
-               "       ahi     %2,31\n"
-               "       srl     %2,5\n"
-               "       slr     %0,%0\n"
-               "0:     cl      %1,0(%0,%4)\n"
-               "       jne     1f\n"
-               "       ahi     %0,4\n"
-               "       brct    %2,0b\n"
-               "       lr      %0,%3\n"
-               "       j       4f\n"
-               "1:     l       %2,0(%0,%4)\n"
-               "       sll     %0,3\n"
-               "       ahi     %0,24\n"
-               "       lhi     %1,0xff\n"
-               "       tmh     %2,0xffff\n"
-               "       jo      2f\n"
-               "       ahi     %0,-16\n"
-               "       srl     %2,16\n"
-               "2:     tml     %2,0xff00\n"
-               "       jo      3f\n"
-               "       ahi     %0,-8\n"
-               "       srl     %2,8\n"
-               "3:     nr      %2,%1\n"
-               "       ic      %2,0(%2,%5)\n"
-               "       alr     %0,%2\n"
-               "4:"
-               : "=&a" (res), "=&d" (cmp), "=&a" (count)
-               : "a" (size), "a" (vaddr), "a" (&_zb_findmap),
-                 "m" (*(addrtype *) vaddr) : "cc");
-        return (res < size) ? res : size;
+       bytes = __ffz_word_loop(vaddr, size);
+       bits = __ffz_word(bytes*8, __load_ulong_le(vaddr, bytes));
+       return (bits < size) ? bits : size;
 }
 
-#else /* __s390x__ */
-
-static inline unsigned long
-ext2_find_first_zero_bit(void *vaddr, unsigned long size)
-{
-       typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
-        unsigned long res, cmp, count;
-
-        if (!size)
-                return 0;
-       asm volatile(
-               "       lghi    %1,-1\n"
-               "       lgr     %2,%3\n"
-               "       aghi    %2,63\n"
-               "       srlg    %2,%2,6\n"
-               "       slgr    %0,%0\n"
-               "0:     clg     %1,0(%0,%4)\n"
-               "       jne     1f\n"
-               "       aghi    %0,8\n"
-               "       brct    %2,0b\n"
-               "       lgr     %0,%3\n"
-               "       j       5f\n"
-               "1:     cl      %1,0(%0,%4)\n"
-               "       jne     2f\n"
-               "       aghi    %0,4\n"
-               "2:     l       %2,0(%0,%4)\n"
-               "       sllg    %0,%0,3\n"
-               "       aghi    %0,24\n"
-               "       lghi    %1,0xff\n"
-               "       tmlh    %2,0xffff\n"
-               "       jo      3f\n"
-               "       aghi    %0,-16\n"
-               "       srl     %2,16\n"
-               "3:     tmll    %2,0xff00\n"
-               "       jo      4f\n"
-               "       aghi    %0,-8\n"
-               "       srl     %2,8\n"
-               "4:     ngr     %2,%1\n"
-               "       ic      %2,0(%2,%5)\n"
-               "       algr    %0,%2\n"
-               "5:"
-               : "=&a" (res), "=&d" (cmp), "=&a" (count)
-               : "a" (size), "a" (vaddr), "a" (&_zb_findmap),
-                 "m" (*(addrtype *) vaddr) : "cc");
-        return (res < size) ? res : size;
-}
-
-#endif /* __s390x__ */
-
-static inline int
-ext2_find_next_zero_bit(void *vaddr, unsigned long size, unsigned long offset)
+static inline int ext2_find_next_zero_bit(void *vaddr, unsigned long size,
+                                         unsigned long offset)
 {
         unsigned long *addr = vaddr, *p;
-       unsigned long word, bit, set;
+       unsigned long bit, set;
 
         if (offset >= size)
                 return size;
@@ -882,23 +815,11 @@ ext2_find_next_zero_bit(void *vaddr, unsigned long size, unsigned long offset)
        size -= offset;
        p = addr + offset / __BITOPS_WORDSIZE;
         if (bit) {
-#ifndef __s390x__
-               asm volatile(
-                       "       ic      %0,0(%1)\n"
-                       "       icm     %0,2,1(%1)\n"
-                       "       icm     %0,4,2(%1)\n"
-                       "       icm     %0,8,3(%1)"
-                       : "=&a" (word) : "a" (p), "m" (*p) : "cc");
-#else
-               asm volatile(
-                       "       lrvg    %0,%1"
-                       : "=a" (word) : "m" (*p) );
-#endif
                /*
                 * s390 version of ffz returns __BITOPS_WORDSIZE
                 * if no zero bit is present in the word.
                 */
-               set = ffz(word >> bit) + bit;
+               set = ffz(__load_ulong_le(p, 0) >> bit) + bit;
                if (set >= size)
                        return size + offset;
                if (set < __BITOPS_WORDSIZE)
@@ -910,6 +831,47 @@ ext2_find_next_zero_bit(void *vaddr, unsigned long size, unsigned long offset)
        return offset + ext2_find_first_zero_bit(p, size);
 }
 
+static inline unsigned long ext2_find_first_bit(void *vaddr,
+                                               unsigned long size)
+{
+       unsigned long bytes, bits;
+
+       if (!size)
+               return 0;
+       bytes = __ffs_word_loop(vaddr, size);
+       bits = __ffs_word(bytes*8, __load_ulong_le(vaddr, bytes));
+       return (bits < size) ? bits : size;
+}
+
+static inline int ext2_find_next_bit(void *vaddr, unsigned long size,
+                                    unsigned long offset)
+{
+       unsigned long *addr = vaddr, *p;
+       unsigned long bit, set;
+
+       if (offset >= size)
+               return size;
+       bit = offset & (__BITOPS_WORDSIZE - 1);
+       offset -= bit;
+       size -= offset;
+       p = addr + offset / __BITOPS_WORDSIZE;
+       if (bit) {
+               /*
+                * s390 version of ffz returns __BITOPS_WORDSIZE
+                * if no zero bit is present in the word.
+                */
+               set = ffs(__load_ulong_le(p, 0) >> bit) + bit;
+               if (set >= size)
+                       return size + offset;
+               if (set < __BITOPS_WORDSIZE)
+                       return set + offset;
+               offset += __BITOPS_WORDSIZE;
+               size -= __BITOPS_WORDSIZE;
+               p++;
+       }
+       return offset + ext2_find_first_bit(p, size);
+}
+
 #include <asm-generic/bitops/minix.h>
 
 #endif /* __KERNEL__ */
index f7cade8083f3378e8297493f984f3749b2552b9e..49d5af916d014a9e22300464d11110b1d2855baf 100644 (file)
@@ -24,4 +24,8 @@
 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
        memcpy(dst, src, len)
 
+#ifdef CONFIG_DEBUG_PAGEALLOC
+void kernel_map_pages(struct page *page, int numpages, int enable);
+#endif
+
 #endif /* _S390_CACHEFLUSH_H */
index 7109c7cab87ecfe4d57941f24c0d83c46604e719..289053ef5e601628403e57279cc681cdfef36282 100644 (file)
@@ -37,6 +37,7 @@ struct ccwgroup_device {
  * @remove: function called on remove
  * @set_online: function called when device is set online
  * @set_offline: function called when device is set offline
+ * @shutdown: function called when device is shut down
  * @driver: embedded driver structure
  */
 struct ccwgroup_driver {
@@ -49,6 +50,7 @@ struct ccwgroup_driver {
        void (*remove) (struct ccwgroup_device *);
        int (*set_online) (struct ccwgroup_device *);
        int (*set_offline) (struct ccwgroup_device *);
+       void (*shutdown)(struct ccwgroup_device *);
 
        struct device_driver driver;
 };
index 7f4ad623f7d5d93a2f423cd76898c1df52883a51..de065b32381a36867eb7bf6bc58f2b0ba8ddeec2 100644 (file)
@@ -149,7 +149,7 @@ typedef u32         compat_sigset_word;
  * A pointer passed in from user mode. This should not
  * be used for syscall parameters, just declare them
  * as pointers because the syscall entry code will have
- * appropriately comverted them already.
+ * appropriately converted them already.
  */
 typedef        u32             compat_uptr_t;
 
index 4b3ef7cad11583bf580a6539340e85c4f8e2c5d9..133ce054fc8945dbe4d18a7fe8fd031908410c3b 100644 (file)
@@ -54,6 +54,7 @@ __div(unsigned long long n, unsigned int base)
 #define cputime_lt(__a, __b)           ((__a) <  (__b))
 #define cputime_le(__a, __b)           ((__a) <= (__b))
 #define cputime_to_jiffies(__ct)       (__div((__ct), 1000000 / HZ))
+#define cputime_to_scaled(__ct)                (__ct)
 #define jiffies_to_cputime(__hz)       ((cputime_t)(__hz) * (1000000 / HZ))
 
 #define cputime64_zero                 (0ULL)
index 709dd1740956b48407b8c3a58f8e762b9a52a543..6f6619ba898062c6af642c83dd574eda02c0e6c6 100644 (file)
@@ -57,10 +57,10 @@ static inline unsigned long pgd_entry_type(struct mm_struct *mm)
 }
 
 #define pud_alloc_one(mm,address)              ({ BUG(); ((pud_t *)2); })
-#define pud_free(x)                            do { } while (0)
+#define pud_free(mm, x)                                do { } while (0)
 
 #define pmd_alloc_one(mm,address)              ({ BUG(); ((pmd_t *)2); })
-#define pmd_free(x)                            do { } while (0)
+#define pmd_free(mm, x)                                do { } while (0)
 
 #define pgd_populate(mm, pgd, pud)             BUG()
 #define pgd_populate_kernel(mm, pgd, pud)      BUG()
@@ -76,7 +76,7 @@ static inline unsigned long pgd_entry_type(struct mm_struct *mm)
 }
 
 #define pud_alloc_one(mm,address)              ({ BUG(); ((pud_t *)2); })
-#define pud_free(x)                            do { } while (0)
+#define pud_free(mm, x)                                do { } while (0)
 
 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
 {
@@ -85,7 +85,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
                crst_table_init(crst, _SEGMENT_ENTRY_EMPTY);
        return (pmd_t *) crst;
 }
-#define pmd_free(pmd) crst_table_free((unsigned long *) pmd)
+#define pmd_free(mm, pmd) crst_table_free((unsigned long *)pmd)
 
 #define pgd_populate(mm, pgd, pud)             BUG()
 #define pgd_populate_kernel(mm, pgd, pud)      BUG()
@@ -115,7 +115,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
                crst_table_init(crst, pgd_entry_type(mm));
        return (pgd_t *) crst;
 }
-#define pgd_free(pgd) crst_table_free((unsigned long *) pgd)
+#define pgd_free(mm, pgd) crst_table_free((unsigned long *) pgd)
 
 static inline void 
 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
@@ -151,9 +151,9 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
 #define pte_alloc_one(mm, vmaddr) \
        virt_to_page(page_table_alloc(s390_noexec))
 
-#define pte_free_kernel(pte) \
+#define pte_free_kernel(mm, pte) \
        page_table_free((unsigned long *) pte)
-#define pte_free(pte) \
+#define pte_free(mm, pte) \
        page_table_free((unsigned long *) page_to_phys((struct page *) pte))
 
 #endif /* _S390_PGALLOC_H */
index 79b9eab1a0c71bc25ffbee10582c1267e2aecb3e..3f520754e71c4472db5d2570cb42cd8a795ab7d1 100644 (file)
@@ -115,15 +115,21 @@ extern char empty_zero_page[PAGE_SIZE];
 #ifndef __s390x__
 #define VMALLOC_START  0x78000000UL
 #define VMALLOC_END    0x7e000000UL
-#define VMEM_MAP_MAX   0x80000000UL
+#define VMEM_MAP_END   0x80000000UL
 #else /* __s390x__ */
 #define VMALLOC_START  0x3e000000000UL
 #define VMALLOC_END    0x3e040000000UL
-#define VMEM_MAP_MAX   0x40000000000UL
+#define VMEM_MAP_END   0x40000000000UL
 #endif /* __s390x__ */
 
+/*
+ * VMEM_MAX_PHYS is the highest physical address that can be added to the 1:1
+ * mapping. This needs to be calculated at compile time since the size of the
+ * VMEM_MAP is static but the size of struct page can change.
+ */
+#define VMEM_MAX_PHYS  min(VMALLOC_START, ((VMEM_MAP_END - VMALLOC_END) / \
+                         sizeof(struct page) * PAGE_SIZE) & ~((16 << 20) - 1))
 #define VMEM_MAP       ((struct page *) VMALLOC_END)
-#define VMEM_MAP_SIZE  ((VMALLOC_START / PAGE_SIZE) * sizeof(struct page))
 
 /*
  * A 31 bit pagetable entry of S390 has following format:
index c86b982aef5a6bb9ebce57a008617443555084f8..4f744609cd11b35aed60e95e33125553809b1692 100644 (file)
@@ -70,8 +70,9 @@ extern int get_cpu_capability(unsigned int *);
 
 #else /* __s390x__ */
 
-# define TASK_SIZE             (test_thread_flag(TIF_31BIT) ? \
+# define TASK_SIZE_OF(tsk)     (test_tsk_thread_flag(tsk, TIF_31BIT) ? \
                                        (0x80000000UL) : (0x40000000000UL))
+# define TASK_SIZE             TASK_SIZE_OF(current)
 # define TASK_UNMAPPED_BASE    (TASK_SIZE / 2)
 # define DEFAULT_TASK_SIZE     (0x40000000000UL)
 
index 618693cfc10f2047b710378210c4842d671f2678..985de2b88279c99a563d85635af1ccec07fc0a6c 100644 (file)
@@ -65,9 +65,9 @@ static inline void tlb_flush_mmu(struct mmu_gather *tlb,
        if (!tlb->fullmm && (tlb->nr_ptes > 0 || tlb->nr_pmds < TLB_NR_PTRS))
                __tlb_flush_mm(tlb->mm);
        while (tlb->nr_ptes > 0)
-               pte_free(tlb->array[--tlb->nr_ptes]);
+               pte_free(tlb->mm, tlb->array[--tlb->nr_ptes]);
        while (tlb->nr_pmds < TLB_NR_PTRS)
-               pmd_free((pmd_t *) tlb->array[tlb->nr_pmds++]);
+               pmd_free(tlb->mm, (pmd_t *) tlb->array[tlb->nr_pmds++]);
 }
 
 static inline void tlb_finish_mmu(struct mmu_gather *tlb,
@@ -102,7 +102,7 @@ static inline void pte_free_tlb(struct mmu_gather *tlb, struct page *page)
                if (tlb->nr_ptes >= tlb->nr_pmds)
                        tlb_flush_mmu(tlb, 0, 0);
        } else
-               pte_free(page);
+               pte_free(tlb->mm, page);
 }
 
 /*
@@ -117,7 +117,7 @@ static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
                if (tlb->nr_ptes >= tlb->nr_pmds)
                        tlb_flush_mmu(tlb, 0, 0);
        } else
-               pmd_free(pmd);
+               pmd_free(tlb->mm, pmd);
 #endif
 }
 
index 031db84f2aa150255348ae123778fe84776519bf..d5d464041003bb68104895c2e54ca5d32a46f195 100644 (file)
@@ -12,7 +12,7 @@ extern void __bad_ndelay(void);
 
 extern void __udelay(unsigned long usecs);
 extern void __ndelay(unsigned long nsecs);
-extern void __const_udelay(unsigned long usecs);
+extern void __const_udelay(unsigned long xloops);
 extern void __delay(unsigned long loops);
 
 #ifdef CONFIG_SUPERH32
index 18b613c57cf5118a8ea6fc452d0a0230ff4d50bf..59ca16d77a1d79b20775362e8d76d7d9cc2d3594 100644 (file)
@@ -36,7 +36,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
        return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        quicklist_free(QUICK_PGD, NULL, pgd);
 }
@@ -54,12 +54,12 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        return pg ? virt_to_page(pg) : NULL;
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        quicklist_free(QUICK_PT, NULL, pte);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        quicklist_free_page(QUICK_PT, NULL, pte);
 }
@@ -71,7 +71,7 @@ static inline void pte_free(struct page *pte)
  * inside the pgd, so has no extra memory associated with it.
  */
 
-#define pmd_free(x)                    do { } while (0)
+#define pmd_free(mm, x)                        do { } while (0)
 #define __pmd_free_tlb(tlb,x)          do { } while (0)
 
 static inline void check_pgt_cache(void)
index b182b1cb05fd24369aa0d1381f553c3135c7e57f..433fd1b48fa2663a93ee3942333281e61532a713 100644 (file)
 #define __NR_epoll_pwait       319
 #define __NR_utimensat         320
 #define __NR_signalfd          321
-#define __NR_timerfd           322
+/* #define __NR_timerfd                322 removed */
 #define __NR_eventfd           323
 #define __NR_fallocate         324
 
index 944511882cac4a7db0c06897f3bcf6321083b102..108d2ba897fe8e8ac4321475b7f23fc92d03aa65 100644 (file)
 #define __NR_epoll_pwait       347
 #define __NR_utimensat         348
 #define __NR_signalfd          349
-#define __NR_timerfd           350
+/* #define __NR_timerfd                350 removed */
 #define __NR_eventfd           351
 #define __NR_fallocate         352
 
index a449cd4912d1f711889c9991dcd8f155c5545a38..b5fbdd36447fbf2b69f384957b76962731553645 100644 (file)
@@ -32,7 +32,7 @@ BTFIXUPDEF_CALL(pgd_t *, get_pgd_fast, void)
 BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
 #define free_pgd_fast(pgd)     BTFIXUP_CALL(free_pgd_fast)(pgd)
 
-#define pgd_free(pgd)  free_pgd_fast(pgd)
+#define pgd_free(mm, pgd)      free_pgd_fast(pgd)
 #define pgd_alloc(mm)  get_pgd_fast()
 
 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
@@ -45,8 +45,8 @@ BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
 BTFIXUPDEF_CALL(void, free_pmd_fast, pmd_t *)
 #define free_pmd_fast(pmd)     BTFIXUP_CALL(free_pmd_fast)(pmd)
 
-#define pmd_free(pmd)           free_pmd_fast(pmd)
-#define __pmd_free_tlb(tlb, pmd) pmd_free(pmd)
+#define pmd_free(mm, pmd)      free_pmd_fast(pmd)
+#define __pmd_free_tlb(tlb, pmd) pmd_free((tlb)->mm, pmd)
 
 BTFIXUPDEF_CALL(void, pmd_populate, pmd_t *, struct page *)
 #define pmd_populate(MM, PMD, PTE)        BTFIXUP_CALL(pmd_populate)(PMD, PTE)
@@ -59,10 +59,10 @@ BTFIXUPDEF_CALL(pte_t *, pte_alloc_one_kernel, struct mm_struct *, unsigned long
 #define pte_alloc_one_kernel(mm, addr) BTFIXUP_CALL(pte_alloc_one_kernel)(mm, addr)
 
 BTFIXUPDEF_CALL(void, free_pte_fast, pte_t *)
-#define pte_free_kernel(pte)   BTFIXUP_CALL(free_pte_fast)(pte)
+#define pte_free_kernel(mm, pte)       BTFIXUP_CALL(free_pte_fast)(pte)
 
 BTFIXUPDEF_CALL(void, pte_free, struct page *)
-#define pte_free(pte)          BTFIXUP_CALL(pte_free)(pte)
-#define __pte_free_tlb(tlb, pte)       pte_free(pte)
+#define pte_free(mm, pte)      BTFIXUP_CALL(pte_free)(pte)
+#define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, pte)
 
 #endif /* _SPARC_PGALLOC_H */
index 0decdf76371640a45b5fcf43cdb39c862da8f93a..2338a027637705052632b6c535170bc05ca5e312 100644 (file)
 #define __NR_epoll_pwait       309
 #define __NR_utimensat         310
 #define __NR_signalfd          311
-#define __NR_timerfd           312
+#define __NR_timerfd_create    312
 #define __NR_eventfd           313
 #define __NR_fallocate         314
+#define __NR_timerfd_settime   315
+#define __NR_timerfd_gettime   316
 
-#define NR_SYSCALLS            315
+#define NR_SYSCALLS            317
 
 /* Sparc 32-bit only has the "setresuid32", "getresuid32" variants,
  * it never had the plain ones and there is no value to adding those
index 01fe6682b4054237ee55d8d4418310aaf68947cd..f260b58f5ce9d34ac224d2781bf4e0ac277849d4 100644 (file)
@@ -152,7 +152,7 @@ typedef u32         compat_sigset_word;
  * A pointer passed in from user mode. This should not
  * be used for syscall parameters, just declare them
  * as pointers because the syscall entry code will have
- * appropriately comverted them already.
+ * appropriately converted them already.
  */
 typedef        u32             compat_uptr_t;
 
index c299b853b5babae9520be2238620319cf490c149..b6ece223562de86719dc403595eca551140be570 100644 (file)
@@ -16,7 +16,7 @@
 /* BIO layer definitions. */
 extern unsigned long kern_base, kern_size;
 #define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
-#define BIO_VMERGE_BOUNDARY    8192
+#define BIO_VMERGE_BOUNDARY    0
 
 static inline u8 _inb(unsigned long addr)
 {
index 5d66b858a965bdb42d4ccf30565d5c36cfd68fda..b48f73c2274ef7ee682204deffa9bcd09dad962f 100644 (file)
@@ -20,7 +20,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        quicklist_free(0, NULL, pgd);
 }
@@ -32,7 +32,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline void pmd_free(pmd_t *pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        quicklist_free(0, NULL, pmd);
 }
@@ -50,12 +50,12 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        return pg ? virt_to_page(pg) : NULL;
 }
                
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        quicklist_free(0, NULL, pte);
 }
 
-static inline void pte_free(struct page *ptepage)
+static inline void pte_free(struct mm_struct *mm, struct page *ptepage)
 {
        quicklist_free_page(0, NULL, ptepage);
 }
index 2a5e4ebaad805bc89b313a17c38937f9273a2198..c622535c45600bd6c9faab97b40255e71685214d 100644 (file)
 typedef unsigned long cycles_t;
 #define get_cycles()   tick_ops->get_tick()
 
-#define ARCH_HAS_READ_CURRENT_TIMER    1
-#define read_current_timer(timer_val_p)        \
-({     *timer_val_p = tick_ops->get_tick();    \
-       0;                                      \
-})
+#define ARCH_HAS_READ_CURRENT_TIMER
 
 #endif
index 349d1d3e9c27135c84f833b60032f6b0907efbfc..ec81cdedef2c8a94aaea03263371b19c832edf60 100644 (file)
@@ -100,8 +100,8 @@ static inline void tlb_remove_page(struct mmu_gather *mp, struct page *page)
 }
 
 #define tlb_remove_tlb_entry(mp,ptep,addr) do { } while (0)
-#define pte_free_tlb(mp,ptepage) pte_free(ptepage)
-#define pmd_free_tlb(mp,pmdp) pmd_free(pmdp)
+#define pte_free_tlb(mp, ptepage) pte_free((mp)->mm, ptepage)
+#define pmd_free_tlb(mp, pmdp) pmd_free((mp)->mm, pmdp)
 #define pud_free_tlb(tlb,pudp) __pud_free_tlb(tlb,pudp)
 
 #define tlb_migrate_finish(mm) do { } while (0)
index cb751b4d0f564aab760af0f6faff8faeb34748e1..77559da0ea3fa92aee70ed7059df904c8bd8656f 100644 (file)
 #define __NR_epoll_pwait       309
 #define __NR_utimensat         310
 #define __NR_signalfd          311
-#define __NR_timerfd           312
+#define __NR_timerfd_create    312
 #define __NR_eventfd           313
 #define __NR_fallocate         314
+#define __NR_timerfd_settime   315
+#define __NR_timerfd_gettime   316
 
-#define NR_SYSCALLS            315
+#define NR_SYSCALLS            317
 
 #ifdef __KERNEL__
 /* sysconf options, for SunOS compatibility */
index 9281dd8eb3345960e58a9248e7027b0ff4c30059..f42ff14577fac4875228242f26128ae6659e92f0 100644 (file)
 
 extern unsigned long stacksizelim;
 
-extern unsigned long host_task_size;
-
 #define STACK_ROOM (stacksizelim)
 
-#define STACK_TOP task_size
+#define STACK_TOP (TASK_SIZE - 2 * PAGE_SIZE)
 
 #define STACK_TOP_MAX STACK_TOP
 
index 8fd72f69ce65d263da723de56bec53137e7a7f60..c2191d9aa03d872158ac7359e5e764dd615341f8 100644 (file)
@@ -1,32 +1,13 @@
-/* 
- * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
 #ifndef __UM_CURRENT_H
 #define __UM_CURRENT_H
 
-#ifndef __ASSEMBLY__
-
-#include "asm/page.h"
 #include "linux/thread_info.h"
 
 #define current (current_thread_info()->task)
 
-/*Backward compatibility - it's used inside arch/um.*/
-#define current_thread current_thread_info()
-
-#endif /* __ASSEMBLY__ */
-
 #endif
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index ca94a136dfe8ed0e75231d3a415cbbc9577ae62f..23d6893e8617d6ccfa0deb9819587d6f3d1452f6 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 #ifndef __UM_ELF_I386_H
 #define __UM_ELF_I386_H
 
-#include <linux/sched.h>
+#include <asm/user.h>
 #include "skas.h"
 
 #define R_386_NONE     0
@@ -46,7 +46,7 @@ typedef struct user_i387_struct elf_fpregset_t;
        PT_REGS_EDI(regs) = 0; \
        PT_REGS_EBP(regs) = 0; \
        PT_REGS_EAX(regs) = 0; \
-} while(0)
+} while (0)
 
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 4096
@@ -74,14 +74,9 @@ typedef struct user_i387_struct elf_fpregset_t;
        pr_reg[14] = PT_REGS_EFLAGS(regs);      \
        pr_reg[15] = PT_REGS_SP(regs);          \
        pr_reg[16] = PT_REGS_SS(regs);          \
-} while(0);
+} while (0);
 
-static inline int elf_core_copy_fpregs(struct task_struct *t,
-                                      elf_fpregset_t *fpu)
-{
-       int cpu = ((struct thread_info *) t->stack)->cpu;
-       return save_fp_registers(userspace_pid[cpu], (unsigned long *) fpu);
-}
+extern int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu);
 
 #define ELF_CORE_COPY_FPREGS(t, fpu) elf_core_copy_fpregs(t, fpu)
 
@@ -91,7 +86,7 @@ extern long elf_aux_hwcap;
 extern char * elf_aux_platform;
 #define ELF_PLATFORM (elf_aux_platform)
 
-#define SET_PERSONALITY(ex, ibcs2) do ; while(0)
+#define SET_PERSONALITY(ex, ibcs2) do { } while (0)
 
 extern unsigned long vsyscall_ehdr;
 extern unsigned long vsyscall_end;
@@ -166,14 +161,3 @@ if ( vsyscall_ehdr ) {                                                           \
 }
 
 #endif
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index 3c9d543eb61e4d797c9452950629ffa5662c58bd..3b2d5224a7e166947be5ce2baa9ae720e696a7e3 100644 (file)
@@ -7,7 +7,6 @@
 #ifndef __UM_ELF_X86_64_H
 #define __UM_ELF_X86_64_H
 
-#include <linux/sched.h>
 #include <asm/user.h>
 #include "skas.h"
 
@@ -96,12 +95,7 @@ typedef struct user_i387_struct elf_fpregset_t;
        (pr_reg)[25] = 0;                                       \
        (pr_reg)[26] = 0;
 
-static inline int elf_core_copy_fpregs(struct task_struct *t,
-                                      elf_fpregset_t *fpu)
-{
-       int cpu = current_thread->cpu;
-       return save_fp_registers(userspace_pid[cpu], (unsigned long *) fpu);
-}
+extern int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu);
 
 #define ELF_CORE_COPY_FPREGS(t, fpu) elf_core_copy_fpregs(t, fpu)
 
index d352a35cfafb3c1a0aff2eeab1f630d8646f220a..89a87c18b927f75d6b1ee486b83996deba4f754b 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef __UM_FIXMAP_H
 #define __UM_FIXMAP_H
 
+#include <asm/system.h>
 #include <asm/kmap_types.h>
 #include <asm/archparam.h>
-#include <asm/elf.h>
+#include <asm/page.h>
 
 /*
  * Here we define all the compile-time 'special' virtual
@@ -55,9 +56,8 @@ extern void __set_fixmap (enum fixed_addresses idx,
  * the start of the fixmap, and leave one page empty
  * at the top of mem..
  */
-extern unsigned long get_kmem_end(void);
 
-#define FIXADDR_TOP    (get_kmem_end() - 0x2000)
+#define FIXADDR_TOP    (CONFIG_TOP_ADDR - 2 * PAGE_SIZE)
 #define FIXADDR_SIZE   (__end_of_fixed_addresses << PAGE_SHIFT)
 #define FIXADDR_START  (FIXADDR_TOP - FIXADDR_SIZE)
 
index b2553f3e87ebfcd3294fe94ecf85a1b975b7f0eb..52af512f5e7dcf272a73de968b709f900218e98d 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef __ASM_LDT_H
 #define __ASM_LDT_H
 
-#include "asm/semaphore.h"
+#include <linux/mutex.h>
 #include "asm/host_ldt.h"
 
 extern void ldt_host_info(void);
@@ -27,7 +27,7 @@ struct ldt_entry {
 
 typedef struct uml_ldt {
        int entry_count;
-       struct semaphore semaphore;
+       struct mutex lock;
        union {
                struct ldt_entry * pages[LDT_PAGES_MAX];
                struct ldt_entry entries[LDT_DIRECT_ENTRIES];
index cdb3024a699a6d83df5f49ccd8e63a3e3adb362b..7dfce37adc8be83424c4463e50a635acfa72650a 100644 (file)
@@ -3,10 +3,4 @@
 
 #include "asm/arch/linkage.h"
 
-
-/* <linux/linkage.h> will pick sane defaults */
-#ifdef CONFIG_GPROF
-#undef fastcall
-#endif
-
 #endif
index 5f3b863aef9aeeafb40c8ee168addf2d6309ecd1..6686fc524ca1aff467688ad52d8976f073a29ea5 100644 (file)
@@ -6,11 +6,12 @@
 #ifndef __UM_MMU_CONTEXT_H
 #define __UM_MMU_CONTEXT_H
 
-#include <asm-generic/mm_hooks.h>
-
 #include "linux/sched.h"
 #include "um_mmu.h"
 
+extern void arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm);
+extern void arch_exit_mmap(struct mm_struct *mm);
+
 #define get_mmu_context(task) do ; while(0)
 #define activate_context(tsk) do ; while(0)
 
@@ -30,6 +31,8 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
         */
        if (old != new && (current->flags & PF_BORROWED_MM))
                __switch_mm(&new->context.id);
+
+       arch_dup_mmap(old, new);
 }
 
 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 
index 4b424c75fca54384a9e96c02dc840a848989cf7f..fe2374d705d15af36114379cfa5e4192a1125aca 100644 (file)
@@ -30,7 +30,7 @@ struct page;
 #if defined(CONFIG_3_LEVEL_PGTABLES) && !defined(CONFIG_64BIT)
 
 typedef struct { unsigned long pte_low, pte_high; } pte_t;
-typedef struct { unsigned long long pmd; } pmd_t;
+typedef struct { unsigned long pmd; } pmd_t;
 typedef struct { unsigned long pgd; } pgd_t;
 #define pte_val(x) ((x).pte_low | ((unsigned long long) (x).pte_high << 32))
 
@@ -106,8 +106,8 @@ extern unsigned long uml_physmem;
 #define __pa(virt) to_phys((void *) (unsigned long) (virt))
 #define __va(phys) to_virt((unsigned long) (phys))
 
-#define phys_to_pfn(p) ((p) >> PAGE_SHIFT)
-#define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
+#define phys_to_pfn(p) ((pfn_t) ((p) >> PAGE_SHIFT))
+#define pfn_to_phys(pfn) ((phys_t) ((pfn) << PAGE_SHIFT))
 
 #define pfn_valid(pfn) ((pfn) < max_mapnr)
 #define virt_addr_valid(v) pfn_valid(phys_to_pfn(__pa(v)))
index f914e7d67b01b8839c7fe185055566131b7d9d33..4cd4a226f8c125d07668b15fbf239370baa58ebe 100644 (file)
@@ -10,7 +10,7 @@
 #define MAXHOSTNAMELEN  64      /* max length of hostname */
 
 #ifdef __KERNEL__
-#define HZ 100
+#define HZ CONFIG_HZ
 #define USER_HZ        100        /* .. some user interfaces are in "ticks" */
 #define CLOCKS_PER_SEC (USER_HZ)  /* frequency at which times() counts */
 #endif
index 14904876e8fbd8deaf8b8ccc7e819af60f098514..4f3e62b02861f0a743a3ffe45f280e127b0c7f01 100644 (file)
  * Allocate and free page tables.
  */
 extern pgd_t *pgd_alloc(struct mm_struct *);
-extern void pgd_free(pgd_t *pgd);
+extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
 extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long) pte);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 }
@@ -42,7 +42,7 @@ static inline void pte_free(struct page *pte)
 
 #ifdef CONFIG_3_LEVEL_PGTABLES
 
-static inline void pmd_free(pmd_t *pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        free_page((unsigned long)pmd);
 }
index 172a75fde51285c49803a3843dbe74d743c62a03..f534b73e753e74c7515dc5bb96e68ce444546be7 100644 (file)
@@ -41,9 +41,6 @@ static inline void pgd_mkuptodate(pgd_t pgd)  { }
 #define pfn_pte(pfn, prot) __pte(pfn_to_phys(pfn) | pgprot_val(prot))
 #define pfn_pmd(pfn, prot) __pmd(pfn_to_phys(pfn) | pgprot_val(prot))
 
-#define pmd_page_vaddr(pmd) \
-       ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
-
 /*
  * Bits 0 through 4 are taken
  */
index 3ebafbaacb24196d82eb5521f4c17292c0a850e7..0446f456b428687b07ba689899cbefe4151d3fe7 100644 (file)
 
 /* PGDIR_SHIFT determines what a third-level page table entry can map */
 
+#ifdef CONFIG_64BIT
 #define PGDIR_SHIFT    30
+#else
+#define PGDIR_SHIFT    31
+#endif
 #define PGDIR_SIZE     (1UL << PGDIR_SHIFT)
 #define PGDIR_MASK     (~(PGDIR_SIZE-1))
 
  */
 
 #define PTRS_PER_PTE 512
+#ifdef CONFIG_64BIT
 #define PTRS_PER_PMD 512
-#define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
 #define PTRS_PER_PGD 512
+#else
+#define PTRS_PER_PMD 1024
+#define PTRS_PER_PGD 1024
+#endif
+
+#define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
 #define FIRST_USER_ADDRESS     0
 
 #define pte_ERROR(e) \
 #define pud_populate(mm, pud, pmd) \
        set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
 
+#ifdef CONFIG_64BIT
 #define set_pud(pudptr, pudval) set_64bit((phys_t *) (pudptr), pud_val(pudval))
+#else
+#define set_pud(pudptr, pudval) (*(pudptr) = (pudval))
+#endif
+
 static inline int pgd_newpage(pgd_t pgd)
 {
        return(pgd_val(pgd) & _PAGE_NEWPAGE);
@@ -57,17 +72,14 @@ static inline int pgd_newpage(pgd_t pgd)
 
 static inline void pgd_mkuptodate(pgd_t pgd) { pgd_val(pgd) &= ~_PAGE_NEWPAGE; }
 
+#ifdef CONFIG_64BIT
 #define set_pmd(pmdptr, pmdval) set_64bit((phys_t *) (pmdptr), pmd_val(pmdval))
+#else
+#define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
+#endif
 
-static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
-{
-        pmd_t *pmd = (pmd_t *) __get_free_page(GFP_KERNEL);
-
-        if(pmd)
-                memset(pmd, 0, PAGE_SIZE);
-
-        return pmd;
-}
+struct mm_struct;
+extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address);
 
 static inline void pud_clear (pud_t *pud)
 {
@@ -75,8 +87,7 @@ static inline void pud_clear (pud_t *pud)
 }
 
 #define pud_page(pud) phys_to_page(pud_val(pud) & PAGE_MASK)
-#define pud_page_vaddr(pud) \
-       ((struct page *) __va(pud_val(pud) & PAGE_MASK))
+#define pud_page_vaddr(pud) ((unsigned long) __va(pud_val(pud) & PAGE_MASK))
 
 /* Find an entry in the second-level page table.. */
 #define pmd_offset(pud, address) ((pmd_t *) pud_page_vaddr(*(pud)) + \
index 830fc6e5d49d0f41c87ab3e555ecea3a9fa3287f..4102b443e9259566346ca3974b881cc8ac465957 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Copyright 2003 PathScale, Inc.
  * Derived from include/asm-i386/pgtable.h
  * Licensed under the GPL
@@ -8,11 +8,7 @@
 #ifndef __UM_PGTABLE_H
 #define __UM_PGTABLE_H
 
-#include "linux/sched.h"
-#include "linux/linkage.h"
-#include "asm/processor.h"
-#include "asm/page.h"
-#include "asm/fixmap.h"
+#include <asm/fixmap.h>
 
 #define _PAGE_PRESENT  0x001
 #define _PAGE_NEWPAGE  0x002
 
 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 
-extern void *um_virt_to_phys(struct task_struct *task, unsigned long virt,
-                            pte_t *pte_out);
-
 /* zero page used for uninitialized stuff */
 extern unsigned long *empty_zero_page;
 
 #define pgtable_cache_init() do ; while (0)
 
-/*
- * pgd entries used up by user/kernel:
- */
-
-#define USER_PGD_PTRS (TASK_SIZE >> PGDIR_SHIFT)
-#define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
-
-#ifndef __ASSEMBLY__
 /* Just any arbitrary offset to the start of the vmalloc VM area: the
  * current 8MB value just means that there will be a 8MB "hole" after the
  * physical memory until the kernel virtual memory starts.  That means that
@@ -62,16 +47,12 @@ extern unsigned long end_iomem;
 
 #define VMALLOC_OFFSET (__va_space)
 #define VMALLOC_START ((end_iomem + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
-
 #ifdef CONFIG_HIGHMEM
 # define VMALLOC_END   (PKMAP_BASE-2*PAGE_SIZE)
 #else
 # define VMALLOC_END   (FIXADDR_START-2*PAGE_SIZE)
 #endif
 
-#define REGION_SHIFT   (sizeof(pte_t) * 8 - 4)
-#define REGION_MASK    (((unsigned long) 0xf) << REGION_SHIFT)
-
 #define _PAGE_TABLE    (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
 #define _KERNPG_TABLE  (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
 #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
@@ -81,11 +62,12 @@ extern unsigned long end_iomem;
 #define PAGE_COPY      __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
 #define PAGE_READONLY  __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
 #define PAGE_KERNEL    __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
-#define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED)
 
 /*
- * The i386 can't do page protection for execute, and considers that the same are read.
- * Also, write permissions imply read permissions. This is the closest we can get..
+ * The i386 can't do page protection for execute, and considers that the same
+ * are read.
+ * Also, write permissions imply read permissions. This is the closest we can
+ * get..
  */
 #define __P000 PAGE_NONE
 #define __P001 PAGE_READONLY
@@ -105,41 +87,17 @@ extern unsigned long end_iomem;
 #define __S110 PAGE_SHARED
 #define __S111 PAGE_SHARED
 
-/*
- * Define this if things work differently on an i386 and an i486:
- * it will (on an i486) warn about kernel memory accesses that are
- * done without a 'access_ok(VERIFY_WRITE,..)'
- */
-#undef TEST_VERIFY_AREA
-
-/* page table for 0-4MB for everybody */
-extern unsigned long pg0[1024];
-
 /*
  * ZERO_PAGE is a global shared page that is always zero: used
  * for zero-mapped memory areas etc..
  */
-
 #define ZERO_PAGE(vaddr) virt_to_page(empty_zero_page)
 
-/* number of bits that fit into a memory pointer */
-#define BITS_PER_PTR                   (8*sizeof(unsigned long))
-
-/* to align the pointer to a pointer address */
-#define PTR_MASK                       (~(sizeof(void*)-1))
-
-/* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
-/* 64-bit machines, beware!  SRB. */
-#define SIZEOF_PTR_LOG2                        3
-
-/* to find an entry in a page-table */
-#define PAGE_PTR(address) \
-((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
-
 #define pte_clear(mm,addr,xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEWPAGE))
 
 #define pmd_none(x)    (!((unsigned long)pmd_val(x) & ~_PAGE_NEWPAGE))
 #define        pmd_bad(x)      ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
+
 #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
 #define pmd_clear(xp)  do { pmd_val(*(xp)) = _PAGE_NEWPAGE; } while (0)
 
@@ -149,14 +107,9 @@ extern unsigned long pg0[1024];
 #define pud_newpage(x)  (pud_val(x) & _PAGE_NEWPAGE)
 #define pud_mkuptodate(x) (pud_val(x) &= ~_PAGE_NEWPAGE)
 
-#define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
-
 #define pmd_page(pmd) phys_to_page(pmd_val(pmd) & PAGE_MASK)
 
 #define pte_page(x) pfn_to_page(pte_pfn(x))
-#define pte_address(x) (__va(pte_val(x) & PAGE_MASK))
-#define mk_phys(a, r) ((a) + (((unsigned long) r) << REGION_SHIFT))
-#define phys_addr(p) ((p) & ~REGION_MASK)
 
 #define pte_present(x) pte_get_bits(x, (_PAGE_PRESENT | _PAGE_PROTNONE))
 
@@ -309,7 +262,8 @@ static inline void set_pte(pte_t *pteptr, pte_t pteval)
 
 #define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
 #define __virt_to_page(virt) phys_to_page(__pa(virt))
-#define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
+#define page_to_phys(page) pfn_to_phys((pfn_t) page_to_pfn(page))
+#define virt_to_page(addr) __virt_to_page((const unsigned long) addr)
 
 #define mk_pte(page, pgprot) \
        ({ pte_t pte;                                   \
@@ -325,8 +279,6 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
        return pte; 
 }
 
-#define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
-
 /*
  * the pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
  *
@@ -335,8 +287,6 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  */
 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
 
-#define pgd_index_k(addr) pgd_index(addr)
-
 /*
  * pgd_offset() returns a (pgd_t *)
  * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
@@ -355,8 +305,12 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  * this macro returns the index of the entry in the pmd page which would
  * control the given virtual address
  */
+#define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
 #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
 
+#define pmd_page_vaddr(pmd) \
+       ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
+
 /*
  * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
  *
@@ -372,6 +326,9 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 #define pte_unmap(pte) do { } while (0)
 #define pte_unmap_nested(pte) do { } while (0)
 
+struct mm_struct;
+extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
+
 #define update_mmu_cache(vma,address,pte) do ; while (0)
 
 /* Encode and de-code a swap entry */
@@ -388,29 +345,4 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 
 #include <asm-generic/pgtable.h>
 
-#include <asm-generic/pgtable-nopud.h>
-
-#ifdef CONFIG_HIGHMEM
-/* Clear a kernel PTE and flush it from the TLB */
-#define kpte_clear_flush(ptep, vaddr)                                  \
-do {                                                                   \
-       pte_clear(&init_mm, vaddr, ptep);                               \
-       __flush_tlb_one(vaddr);                                         \
-} while (0)
 #endif
-
-#endif
-#endif
-
-#define virt_to_page(addr) __virt_to_page((const unsigned long) addr)
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index 78c0599cc80c4da8e21d8c897a801560edbcb5e1..b7d9a16a74511d74194515042f703ecf940e5f24 100644 (file)
@@ -11,6 +11,7 @@ struct pt_regs;
 struct task_struct;
 
 #include "asm/ptrace.h"
+#include "asm/pgtable.h"
 #include "registers.h"
 #include "sysdep/archsetjmp.h"
 
@@ -26,7 +27,6 @@ struct thread_struct {
         * as of 2.6.11).
         */
        int forking;
-       int nsyscalls;
        struct pt_regs regs;
        int singlestep_syscall;
        void *fault_addr;
@@ -58,7 +58,6 @@ struct thread_struct {
 #define INIT_THREAD \
 { \
        .forking                = 0, \
-       .nsyscalls              = 0, \
        .regs                   = EMPTY_REGS,   \
        .fault_addr             = NULL, \
        .prev_sched             = NULL, \
@@ -68,10 +67,6 @@ struct thread_struct {
        .request                = { 0 } \
 }
 
-typedef struct {
-       unsigned long seg;
-} mm_segment_t;
-
 extern struct task_struct *alloc_task_struct(void);
 
 static inline void release_thread(struct task_struct *task)
@@ -97,9 +92,7 @@ static inline void mm_copy_segments(struct mm_struct *from_mm,
 /*
  * User space process size: 3GB (default).
  */
-extern unsigned long task_size;
-
-#define TASK_SIZE      (task_size)
+#define TASK_SIZE (CONFIG_TOP_ADDR & PGDIR_MASK)
 
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
@@ -128,6 +121,6 @@ extern struct cpuinfo_um cpu_data[];
 
 
 #define KSTK_REG(tsk, reg) get_thread_reg(reg, &tsk->thread.switch_buf)
-#define get_wchan(p) (0)
+extern unsigned long get_wchan(struct task_struct *p);
 
 #endif
index 595f1c3e1e400607c0b318d5bd7590a124731808..a2b7fe13fe1e48179b1fd5f0eeff8315dcb15b0d 100644 (file)
@@ -10,7 +10,6 @@
 #include "asm/host_ldt.h"
 #include "asm/segment.h"
 
-extern int host_has_xmm;
 extern int host_has_cmov;
 
 /* include faultinfo structure */
index 6e5fd5c892d069439ed56191d837df54dd94dd58..356b83e2c22edf07c357e91c46469ad762968fb2 100644 (file)
@@ -1,5 +1,5 @@
-/* 
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -8,8 +8,9 @@
 
 #ifndef __ASSEMBLY__
 
-#include <asm/processor.h>
 #include <asm/types.h>
+#include <asm/page.h>
+#include <asm/uaccess.h>
 
 struct thread_info {
        struct task_struct      *task;          /* main task structure */
@@ -75,8 +76,8 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_SYSCALL_TRACE      0       /* syscall trace active */
 #define TIF_SIGPENDING         1       /* signal pending */
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
-#define TIF_POLLING_NRFLAG      3       /* true if poll_idle() is polling 
-                                        * TIF_NEED_RESCHED 
+#define TIF_POLLING_NRFLAG      3       /* true if poll_idle() is polling
+                                        * TIF_NEED_RESCHED
                                         */
 #define TIF_RESTART_BLOCK      4
 #define TIF_MEMDIE             5
index c640033bc1fd1e6e0750422aa1afd8f0428aebc6..39fc475df6c93ca135453f0ba6d44c8853f42d0c 100644 (file)
@@ -1,6 +1,126 @@
 #ifndef __UM_TLB_H
 #define __UM_TLB_H
 
-#include <asm/arch/tlb.h>
+#include <linux/swap.h>
+#include <asm/percpu.h>
+#include <asm/pgalloc.h>
+#include <asm/tlbflush.h>
+
+#define tlb_start_vma(tlb, vma) do { } while (0)
+#define tlb_end_vma(tlb, vma) do { } while (0)
+#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
+
+/* struct mmu_gather is an opaque type used by the mm code for passing around
+ * any data needed by arch specific code for tlb_remove_page.
+ */
+struct mmu_gather {
+       struct mm_struct        *mm;
+       unsigned int            need_flush; /* Really unmapped some ptes? */
+       unsigned long           start;
+       unsigned long           end;
+       unsigned int            fullmm; /* non-zero means full mm flush */
+};
+
+/* Users of the generic TLB shootdown code must declare this storage space. */
+DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
+
+static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep,
+                                         unsigned long address)
+{
+       if (tlb->start > address)
+               tlb->start = address;
+       if (tlb->end < address + PAGE_SIZE)
+               tlb->end = address + PAGE_SIZE;
+}
+
+static inline void init_tlb_gather(struct mmu_gather *tlb)
+{
+       tlb->need_flush = 0;
+
+       tlb->start = TASK_SIZE;
+       tlb->end = 0;
+
+       if (tlb->fullmm) {
+               tlb->start = 0;
+               tlb->end = TASK_SIZE;
+       }
+}
+
+/* tlb_gather_mmu
+ *     Return a pointer to an initialized struct mmu_gather.
+ */
+static inline struct mmu_gather *
+tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
+{
+       struct mmu_gather *tlb = &get_cpu_var(mmu_gathers);
+
+       tlb->mm = mm;
+       tlb->fullmm = full_mm_flush;
+
+       init_tlb_gather(tlb);
+
+       return tlb;
+}
+
+extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
+                              unsigned long end);
+
+static inline void
+tlb_flush_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
+{
+       if (!tlb->need_flush)
+               return;
+
+       flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end);
+       init_tlb_gather(tlb);
+}
+
+/* tlb_finish_mmu
+ *     Called at the end of the shootdown operation to free up any resources
+ *     that were required.
+ */
+static inline void
+tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
+{
+       tlb_flush_mmu(tlb, start, end);
+
+       /* keep the page table cache within bounds */
+       check_pgt_cache();
+
+       put_cpu_var(mmu_gathers);
+}
+
+/* tlb_remove_page
+ *     Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)),
+ *     while handling the additional races in SMP caused by other CPUs
+ *     caching valid mappings in their TLBs.
+ */
+static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
+{
+       tlb->need_flush = 1;
+       free_page_and_swap_cache(page);
+       return;
+}
+
+/**
+ * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
+ *
+ * Record the fact that pte's were really umapped in ->need_flush, so we can
+ * later optimise away the tlb invalidate.   This helps when userspace is
+ * unmapping already-unmapped pages, which happens quite a lot.
+ */
+#define tlb_remove_tlb_entry(tlb, ptep, address)               \
+       do {                                                    \
+               tlb->need_flush = 1;                            \
+               __tlb_remove_tlb_entry(tlb, ptep, address);     \
+       } while (0)
+
+#define pte_free_tlb(tlb, ptep) __pte_free_tlb(tlb, ptep)
+
+#define pud_free_tlb(tlb, pudp) __pud_free_tlb(tlb, pudp)
+
+#define pmd_free_tlb(tlb, pmdp) __pmd_free_tlb(tlb, pmdp)
+
+#define tlb_migrate_finish(mm) do {} while (0)
 
 #endif
index 077032d4fc47f13c167ea67463646d6519700b62..b9a895d6fa1df7cf0447573e58983f5b095e36d2 100644 (file)
@@ -6,7 +6,15 @@
 #ifndef __UM_UACCESS_H
 #define __UM_UACCESS_H
 
-#include "linux/sched.h"
+#include <asm/errno.h>
+#include <asm/processor.h>
+
+/* thread_info has a mm_segment_t in it, so put the definition up here */
+typedef struct {
+       unsigned long seg;
+} mm_segment_t;
+
+#include "linux/thread_info.h"
 
 #define VERIFY_READ 0
 #define VERIFY_WRITE 1
index cc364fcbec101aacadd8641c74c5fc9ac7553985..cdad251fba9ff1802d7f311c660f08b0d9fa0d71 100644 (file)
@@ -122,8 +122,6 @@ outsl (unsigned long port, const void *src, unsigned long count)
 #endif
 
 /* Conversion between virtual and physical mappings.  */
-#define mm_ptov(addr)          ((void *)__phys_to_virt (addr))
-#define mm_vtop(addr)          ((unsigned long)__virt_to_phys (addr))
 #define phys_to_virt(addr)     ((void *)__phys_to_virt (addr))
 #define virt_to_phys(addr)     ((unsigned long)__virt_to_phys (addr))
 
index 1a6980a60fc6ef0717ed432480f06b7534e5328a..90dec0c236469455821607eca77a5a86684af6d2 100644 (file)
 
 #endif /* CONFIG_X86_32 */
 
+/* Exception table entry */
+# define _ASM_EXTABLE(from,to) \
+       " .section __ex_table,\"a\"\n" \
+       _ASM_ALIGN "\n" \
+       _ASM_PTR #from "," #to "\n" \
+       " .previous\n"
+
 #endif /* _ASM_X86_ASM_H */
index 48adbf56ca60c9f2d7da5954e3245188d6f8a2ea..aaf15194d536fc9dc2acd9e925db0bc999a9634b 100644 (file)
@@ -37,12 +37,6 @@ static inline long __scanbit(unsigned long val, unsigned long max)
   ((off)+(__scanbit(~(((*(unsigned long *)addr)) >> (off)),(size)-(off)))) : \
        find_next_zero_bit(addr,size,off)))
 
-/* 
- * Find string of zero bits in a bitmap. -1 when not found.
- */ 
-extern unsigned long 
-find_next_zero_string(unsigned long *bitmap, long start, long nbits, int len);
-
 static inline void set_bit_string(unsigned long *bitmap, unsigned long i, 
                                  int len) 
 { 
@@ -53,16 +47,6 @@ static inline void set_bit_string(unsigned long *bitmap, unsigned long i,
        }
 } 
 
-static inline void __clear_bit_string(unsigned long *bitmap, unsigned long i, 
-                                   int len) 
-{ 
-       unsigned long end = i + len; 
-       while (i < end) {
-               __clear_bit(i, bitmap); 
-               i++;
-       }
-} 
-
 /**
  * ffz - find first zero in word.
  * @word: The word to search
index 3fcc30dc07314ce0fc7460dfb956d260bf602829..021cbdd5f258a7739c2433d62f00a37a51070a4b 100644 (file)
@@ -2,6 +2,6 @@
 #define _ASM_X86_BUGS_H
 
 extern void check_bugs(void);
-extern int ppro_with_ram_bug(void);
+int ppro_with_ram_bug(void);
 
 #endif /* _ASM_X86_BUGS_H */
index b270ee04959ea7ce3fa73cf4935f39d9b7e0aa8b..d3e8f3e87ee8a876c413611fd2ae21fb0b6dbc63 100644 (file)
@@ -190,7 +190,7 @@ typedef struct user_regs_struct32 compat_elf_gregset_t;
  * A pointer passed in from user mode. This should not
  * be used for syscall parameters, just declare them
  * as pointers because the syscall entry code will have
- * appropriately comverted them already.
+ * appropriately converted them already.
  */
 typedef        u32             compat_uptr_t;
 
index 3fb7dfa7fc915b66f827c722ec31efc70cd63810..065e92966c7ccf966753ae03158eab9a8c3171e1 100644 (file)
@@ -4,9 +4,6 @@
 #ifndef _ASM_X86_CPUFEATURE_H
 #define _ASM_X86_CPUFEATURE_H
 
-#ifndef __ASSEMBLY__
-#include <linux/bitops.h>
-#endif
 #include <asm/required-features.h>
 
 #define NCAPINTS       8       /* N 32-bit words worth of info */
@@ -49,6 +46,7 @@
 #define X86_FEATURE_MP         (1*32+19) /* MP Capable. */
 #define X86_FEATURE_NX         (1*32+20) /* Execute Disable */
 #define X86_FEATURE_MMXEXT     (1*32+22) /* AMD MMX extensions */
+#define X86_FEATURE_GBPAGES    (1*32+26) /* GB pages */
 #define X86_FEATURE_RDTSCP     (1*32+27) /* RDTSCP */
 #define X86_FEATURE_LM         (1*32+29) /* Long Mode (x86-64) */
 #define X86_FEATURE_3DNOWEXT   (1*32+30) /* AMD 3DNow! extensions */
  */
 #define X86_FEATURE_IDA                (7*32+ 0) /* Intel Dynamic Acceleration */
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
+
+#include <linux/bitops.h>
+
+extern const char * const x86_cap_flags[NCAPINTS*32];
+extern const char * const x86_power_flags[32];
+
 #define cpu_has(c, bit)                                                        \
        (__builtin_constant_p(bit) &&                                   \
         ( (((bit)>>5)==0 && (1UL<<((bit)&31) & REQUIRED_MASK0)) ||     \
 #define cpu_has_pebs           boot_cpu_has(X86_FEATURE_PEBS)
 #define cpu_has_clflush                boot_cpu_has(X86_FEATURE_CLFLSH)
 #define cpu_has_bts            boot_cpu_has(X86_FEATURE_BTS)
+#define cpu_has_gbpages                boot_cpu_has(X86_FEATURE_GBPAGES)
 
 #if defined(CONFIG_X86_INVLPG) || defined(CONFIG_X86_64)
 # define cpu_has_invlpg                1
 
 #endif /* CONFIG_X86_64 */
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */
+
 #endif /* _ASM_X86_CPUFEATURE_H */
index d11d47fc1a0e8dc44177aa86f62ca2e1090d70d5..409a649204aa7308c8936d6cc08d4479222d6885 100644 (file)
@@ -13,7 +13,7 @@ extern void __bad_ndelay(void);
 
 extern void __udelay(unsigned long usecs);
 extern void __ndelay(unsigned long nsecs);
-extern void __const_udelay(unsigned long usecs);
+extern void __const_udelay(unsigned long xloops);
 extern void __delay(unsigned long loops);
 
 /* 0x10c7 is 2**32 / 1000000 (rounded up) */
index 9c68a1f098d8cb12af04bacd1564909b179aca61..ea9734b74aca235b33e98a33fbe54a99feeb9fbd 100644 (file)
@@ -33,7 +33,7 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...);
 #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6)      \
        efi_call_virt(f, a1, a2, a3, a4, a5, a6)
 
-#define efi_ioremap(addr, size)                        ioremap(addr, size)
+#define efi_ioremap(addr, size)                        ioremap_cache(addr, size)
 
 #else /* !CONFIG_X86_32 */
 
@@ -86,7 +86,7 @@ extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,
        efi_call6((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \
                  (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6))
 
-extern void *efi_ioremap(unsigned long offset, unsigned long size);
+extern void *efi_ioremap(unsigned long addr, unsigned long size);
 
 #endif /* CONFIG_X86_32 */
 
index 9d919264923a0b12db0bd804abed465c5ce82c55..cd9f894dd2d7c778fe4d85fdeb0f83168a16804d 100644 (file)
 "2:    .section .fixup,\"ax\"\n                                \
 3:     mov     %3, %1\n                                        \
        jmp     2b\n                                            \
-       .previous\n                                             \
-       .section __ex_table,\"a\"\n                             \
-       .align  8\n"                                            \
-       _ASM_PTR "1b,3b\n                                       \
-       .previous"                                              \
+       .previous\n"                                            \
+       _ASM_EXTABLE(1b,3b)                                     \
        : "=r" (oldval), "=r" (ret), "+m" (*uaddr)              \
        : "i" (-EFAULT), "0" (oparg), "1" (0))
 
 3:     .section .fixup,\"ax\"\n                                \
 4:     mov     %5, %1\n                                        \
        jmp     3b\n                                            \
-       .previous\n                                             \
-       .section __ex_table,\"a\"\n                             \
-       .align  8\n"                                            \
-       _ASM_PTR "1b,4b,2b,4b\n                                 \
-       .previous"                                              \
+       .previous\n"                                            \
+       _ASM_EXTABLE(1b,4b)                                     \
+       _ASM_EXTABLE(2b,4b)                                     \
        : "=&a" (oldval), "=&r" (ret), "+m" (*uaddr),           \
          "=&r" (tem)                                           \
        : "r" (oparg), "i" (-EFAULT), "1" (0))
@@ -111,18 +106,12 @@ futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
                return -EFAULT;
 
        __asm__ __volatile__(
-
                "1:     lock; cmpxchgl %3, %1                   \n"
                "2:     .section .fixup, \"ax\"                 \n"
                "3:     mov     %2, %0                          \n"
                "       jmp     2b                              \n"
                "       .previous                               \n"
-
-               "       .section __ex_table, \"a\"              \n"
-               "       .align  8                               \n"
-                       _ASM_PTR " 1b,3b                        \n"
-               "       .previous                               \n"
-
+               _ASM_EXTABLE(1b,3b)
                : "=a" (oldval), "+m" (*uaddr)
                : "i" (-EFAULT), "r" (newval), "0" (oldval)
                : "memory"
index 13cdcd66fff213dd6515ee0eb1eda411eb71eb73..479767c9195fcd36ced65ec1c8e5e66872b3e56c 100644 (file)
@@ -38,11 +38,6 @@ extern pte_t *pkmap_page_table;
  * easily, subsequent pte tables have to be allocated in one physical
  * chunk of RAM.
  */
-#ifdef CONFIG_X86_PAE
-#define LAST_PKMAP 512
-#else
-#define LAST_PKMAP 1024
-#endif
 /*
  * Ordering is:
  *
@@ -58,13 +53,12 @@ extern pte_t *pkmap_page_table;
  * VMALLOC_START
  * high_memory
  */
-#define PKMAP_BASE ( (FIXADDR_BOOT_START - PAGE_SIZE*(LAST_PKMAP + 1)) & PMD_MASK )
 #define LAST_PKMAP_MASK (LAST_PKMAP-1)
 #define PKMAP_NR(virt)  ((virt-PKMAP_BASE) >> PAGE_SHIFT)
 #define PKMAP_ADDR(nr)  (PKMAP_BASE + ((nr) << PAGE_SHIFT))
 
-extern void * FASTCALL(kmap_high(struct page *page));
-extern void FASTCALL(kunmap_high(struct page *page));
+extern void *kmap_high(struct page *page);
+extern void kunmap_high(struct page *page);
 
 void *kmap(struct page *page);
 void kunmap(struct page *page);
index 6d65fbb6358b0d91692da95313fd09c5ee3c8690..ea88054e03f373a3a909c1c697c6e4d5fa61d9de 100644 (file)
@@ -47,7 +47,7 @@ void enable_8259A_irq(unsigned int irq);
 int i8259A_irq_pending(unsigned int irq);
 void make_8259A_irq(unsigned int irq);
 void init_8259A(int aeoi);
-void FASTCALL(send_IPI_self(int vector));
+void send_IPI_self(int vector);
 void init_VISWS_APIC_irqs(void);
 void setup_IO_APIC(void);
 void disable_IO_APIC(void);
index ba8105ca822b99840f6bcf91b23e9d7f0c34902f..6b1895ccd6b78854bd3dc9f7f710ea1bc24ff9bb 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/sched.h>
 #include <linux/kernel_stat.h>
 #include <linux/regset.h>
+#include <asm/asm.h>
 #include <asm/processor.h>
 #include <asm/sigcontext.h>
 #include <asm/user.h>
@@ -41,10 +42,7 @@ static inline void tolerant_fwait(void)
 {
        asm volatile("1: fwait\n"
                     "2:\n"
-                    "   .section __ex_table,\"a\"\n"
-                    "  .align 8\n"
-                    "  .quad 1b,2b\n"
-                    "  .previous\n");
+                    _ASM_EXTABLE(1b,2b));
 }
 
 static inline int restore_fpu_checking(struct i387_fxsave_struct *fx)
@@ -57,10 +55,7 @@ static inline int restore_fpu_checking(struct i387_fxsave_struct *fx)
                     "3:  movl $-1,%[err]\n"
                     "    jmp  2b\n"
                     ".previous\n"
-                    ".section __ex_table,\"a\"\n"
-                    "   .align 8\n"
-                    "   .quad  1b,3b\n"
-                    ".previous"
+                    _ASM_EXTABLE(1b,3b)
                     : [err] "=r" (err)
 #if 0 /* See comment in __save_init_fpu() below. */
                     : [fx] "r" (fx), "m" (*fx), "0" (0));
@@ -99,10 +94,7 @@ static inline int save_i387_checking(struct i387_fxsave_struct __user *fx)
                     "3:  movl $-1,%[err]\n"
                     "    jmp  2b\n"
                     ".previous\n"
-                    ".section __ex_table,\"a\"\n"
-                    "   .align 8\n"
-                    "   .quad  1b,3b\n"
-                    ".previous"
+                    _ASM_EXTABLE(1b,3b)
                     : [err] "=r" (err), "=m" (*fx)
 #if 0 /* See comment in __fxsave_clear() below. */
                     : [fx] "r" (fx), "0" (0));
index 586d7aa54cebcaa2f629c112bbc88a4d077e9c21..58d2c45cd0b1bf0e2ddfacfc176f01a91c691045 100644 (file)
@@ -275,29 +275,6 @@ static inline void slow_down_io(void) {
 
 #endif
 
-#ifdef CONFIG_X86_NUMAQ
-extern void *xquad_portio;    /* Where the IO area was mapped */
-#define XQUAD_PORT_ADDR(port, quad) (xquad_portio + (XQUAD_PORTIO_QUAD*quad) + port)
-#define __BUILDIO(bwl,bw,type) \
-static inline void out##bwl##_quad(unsigned type value, int port, int quad) { \
-       if (xquad_portio) \
-               write##bwl(value, XQUAD_PORT_ADDR(port, quad)); \
-       else \
-               out##bwl##_local(value, port); \
-} \
-static inline void out##bwl(unsigned type value, int port) { \
-       out##bwl##_quad(value, port, 0); \
-} \
-static inline unsigned type in##bwl##_quad(int port, int quad) { \
-       if (xquad_portio) \
-               return read##bwl(XQUAD_PORT_ADDR(port, quad)); \
-       else \
-               return in##bwl##_local(port); \
-} \
-static inline unsigned type in##bwl(int port) { \
-       return in##bwl##_quad(port, 0); \
-}
-#else
 #define __BUILDIO(bwl,bw,type) \
 static inline void out##bwl(unsigned type value, int port) { \
        out##bwl##_local(value, port); \
@@ -305,8 +282,6 @@ static inline void out##bwl(unsigned type value, int port) { \
 static inline unsigned type in##bwl(int port) { \
        return in##bwl##_local(port); \
 }
-#endif
-
 
 #define BUILDIO(bwl,bw,type) \
 static inline void out##bwl##_local(unsigned type value, int port) { \
index 17e183bd39c1395d044489f58f17a09bbefe0e89..3b637fac890b8da769ab398cbe02d6dfe1a54d55 100644 (file)
@@ -109,6 +109,8 @@ static inline int mpc_apic_id(struct mpc_config_processor *m,
        return logical_apicid;
 }
 
+extern void *xquad_portio;
+
 static inline void setup_portio_remap(void)
 {
        int num_quads = num_online_nodes();
index bc2b5892630859f8c42441204d2beec90a2151dd..9e5a459fd15b2f13e5e1e266999a08ef49a3026e 100644 (file)
@@ -6,7 +6,6 @@
 
 /**
  * do_timer_interrupt_hook - hook into timer tick
- * @regs:     standard registers from interrupt
  *
  * Call the pit clock event handler. see asm/i8253.h
  **/
index 204a8a30fecf8e9669aae32b6f6db83852cb694b..3ca29ebebbb18dd8f7547eab749a94f0ce157874 100644 (file)
@@ -57,10 +57,7 @@ static inline unsigned long long native_read_msr_safe(unsigned int msr,
                     ".section .fixup,\"ax\"\n\t"
                     "3:  mov %3,%0 ; jmp 1b\n\t"
                     ".previous\n\t"
-                    ".section __ex_table,\"a\"\n"
-                    _ASM_ALIGN "\n\t"
-                    _ASM_PTR " 2b,3b\n\t"
-                    ".previous"
+                    _ASM_EXTABLE(2b,3b)
                     : "=r" (*err), EAX_EDX_RET(val, low, high)
                     : "c" (msr), "i" (-EFAULT));
        return EAX_EDX_VAL(val, low, high);
@@ -81,10 +78,7 @@ static inline int native_write_msr_safe(unsigned int msr,
                     ".section .fixup,\"ax\"\n\t"
                     "3:  mov %4,%0 ; jmp 1b\n\t"
                     ".previous\n\t"
-                    ".section __ex_table,\"a\"\n"
-                    _ASM_ALIGN "\n\t"
-                    _ASM_PTR " 2b,3b\n\t"
-                    ".previous"
+                    _ASM_EXTABLE(2b,3b)
                     : "=a" (err)
                     : "c" (msr), "0" (low), "d" (high),
                       "i" (-EFAULT));
index c8b30efeed85c6354d229a18d1d14bae2c206a87..1cb7c51bc2966fd1986684b9c87da245610f5d6b 100644 (file)
@@ -13,8 +13,8 @@
 #define PHYSICAL_PAGE_MASK     (PAGE_MASK & __PHYSICAL_MASK)
 #define PTE_MASK               (_AT(long, PHYSICAL_PAGE_MASK))
 
-#define LARGE_PAGE_SIZE                (_AC(1,UL) << PMD_SHIFT)
-#define LARGE_PAGE_MASK                (~(LARGE_PAGE_SIZE-1))
+#define PMD_PAGE_SIZE          (_AC(1, UL) << PMD_SHIFT)
+#define PMD_PAGE_MASK          (~(PMD_PAGE_SIZE-1))
 
 #define HPAGE_SHIFT            PMD_SHIFT
 #define HPAGE_SIZE             (_AC(1,UL) << HPAGE_SHIFT)
index c1ac42d8707f34fe374c6063cc37503b7e4647f4..dcf0c0746075ba07f4527f2018bb846f8ebf8424 100644 (file)
@@ -23,6 +23,9 @@
 #define MCE_STACK 5
 #define N_EXCEPTION_STACKS 5  /* hw limit: 7 */
 
+#define PUD_PAGE_SIZE          (_AC(1, UL) << PUD_SHIFT)
+#define PUD_PAGE_MASK          (~(PUD_PAGE_SIZE-1))
+
 #define __PAGE_OFFSET           _AC(0xffff810000000000, UL)
 
 #define __PHYSICAL_START       CONFIG_PHYSICAL_START
index 7641e7b5d931a8fe304eeb4c99f11596f5381216..bab12718a913fa446f25c8c9e6e2b2d380e3761a 100644 (file)
@@ -36,17 +36,17 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *p
  * Allocate and free page tables.
  */
 extern pgd_t *pgd_alloc(struct mm_struct *);
-extern void pgd_free(pgd_t *pgd);
+extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
 extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 }
@@ -63,7 +63,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
        return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
 }
 
-static inline void pmd_free(pmd_t *pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
        free_page((unsigned long)pmd);
@@ -80,8 +80,10 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
        set_pud(pudp, __pud(__pa(pmd) | _PAGE_PRESENT));
 
        /*
-        * Pentium-II erratum A13: in PAE mode we explicitly have to flush
-        * the TLB via cr3 if the top-level pgd is changed...
+        * According to Intel App note "TLBs, Paging-Structure Caches,
+        * and Their Invalidation", April 2007, document 317080-001,
+        * section 8.1: in PAE mode we explicitly have to flush the
+        * TLB via cr3 if the top-level pgd is changed...
         */
        if (mm == current->active_mm)
                write_cr3(read_cr3());
index 8bb5646878602f3731e345b46a80486f593e1640..4f6220db22b110bbf1606d75316a36e1b458fa1a 100644 (file)
@@ -17,7 +17,7 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *p
        set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
 }
 
-static inline void pmd_free(pmd_t *pmd)
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 {
        BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
        free_page((unsigned long)pmd);
@@ -33,7 +33,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
        return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
 }
 
-static inline void pud_free (pud_t *pud)
+static inline void pud_free(struct mm_struct *mm, pud_t *pud)
 {
        BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
        free_page((unsigned long)pud);
@@ -42,19 +42,21 @@ static inline void pud_free (pud_t *pud)
 static inline void pgd_list_add(pgd_t *pgd)
 {
        struct page *page = virt_to_page(pgd);
+       unsigned long flags;
 
-       spin_lock(&pgd_lock);
+       spin_lock_irqsave(&pgd_lock, flags);
        list_add(&page->lru, &pgd_list);
-       spin_unlock(&pgd_lock);
+       spin_unlock_irqrestore(&pgd_lock, flags);
 }
 
 static inline void pgd_list_del(pgd_t *pgd)
 {
        struct page *page = virt_to_page(pgd);
+       unsigned long flags;
 
-       spin_lock(&pgd_lock);
+       spin_lock_irqsave(&pgd_lock, flags);
        list_del(&page->lru);
-       spin_unlock(&pgd_lock);
+       spin_unlock_irqrestore(&pgd_lock, flags);
 }
 
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
@@ -77,7 +79,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
        return pgd;
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
        pgd_list_del(pgd);
@@ -100,13 +102,13 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long add
 /* Should really implement gc for free page table pages. This could be
    done with a reference count in struct page. */
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
        free_page((unsigned long)pte); 
 }
 
-static inline void pte_free(struct page *pte)
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
 {
        __free_page(pte);
 } 
index a195c3e757b9ef95931d4c7341fdd2ab02d44464..1d763eec740ff882c329889db1a9ae7006ac8817 100644 (file)
@@ -93,26 +93,22 @@ static inline void native_pmd_clear(pmd_t *pmd)
 
 static inline void pud_clear(pud_t *pudp)
 {
+       unsigned long pgd;
+
        set_pud(pudp, __pud(0));
 
        /*
-        * In principle we need to do a cr3 reload here to make sure
-        * the processor recognizes the changed pgd.  In practice, all
-        * the places where pud_clear() gets called are followed by
-        * full tlb flushes anyway, so we can defer the cost here.
-        *
-        * Specifically:
-        *
-        * mm/memory.c:free_pmd_range() - immediately after the
-        * pud_clear() it does a pmd_free_tlb().  We change the
-        * mmu_gather structure to do a full tlb flush (which has the
-        * effect of reloading cr3) when the pagetable free is
-        * complete.
+        * According to Intel App note "TLBs, Paging-Structure Caches,
+        * and Their Invalidation", April 2007, document 317080-001,
+        * section 8.1: in PAE mode we explicitly have to flush the
+        * TLB via cr3 if the top-level pgd is changed...
         *
-        * arch/x86/mm/hugetlbpage.c:huge_pmd_unshare() - the call to
-        * this is followed by a flush_tlb_range, which on x86 does a
-        * full tlb flush.
+        * Make sure the pud entry we're updating is within the
+        * current pgd to avoid unnecessary TLB flushes.
         */
+       pgd = read_cr3();
+       if (__pa(pudp) >= pgd && __pa(pudp) < (pgd + sizeof(pgd_t)*PTRS_PER_PGD))
+               write_cr3(pgd);
 }
 
 #define pud_page(pud) \
index cd2524f074525968a01917d9495711948e0c487d..44c0a4f1b1eb64d10bd1e33013b7e52a3dcc55f1 100644 (file)
 #define _PAGE_BIT_DIRTY                6
 #define _PAGE_BIT_FILE         6
 #define _PAGE_BIT_PSE          7       /* 4 MB (or 2MB) page */
+#define _PAGE_BIT_PAT          7       /* on 4KB pages */
 #define _PAGE_BIT_GLOBAL       8       /* Global TLB entry PPro+ */
 #define _PAGE_BIT_UNUSED1      9       /* available for programmer */
 #define _PAGE_BIT_UNUSED2      10
 #define _PAGE_BIT_UNUSED3      11
+#define _PAGE_BIT_PAT_LARGE    12      /* On 2MB or 1GB pages */
 #define _PAGE_BIT_NX           63       /* No execute: only valid after cpuid check */
 
 /*
@@ -36,6 +38,8 @@
 #define _PAGE_UNUSED1  (_AC(1, L)<<_PAGE_BIT_UNUSED1)
 #define _PAGE_UNUSED2  (_AC(1, L)<<_PAGE_BIT_UNUSED2)
 #define _PAGE_UNUSED3  (_AC(1, L)<<_PAGE_BIT_UNUSED3)
+#define _PAGE_PAT      (_AC(1, L)<<_PAGE_BIT_PAT)
+#define _PAGE_PAT_LARGE (_AC(1, L)<<_PAGE_BIT_PAT_LARGE)
 
 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
 #define _PAGE_NX       (_AC(1, ULL) << _PAGE_BIT_NX)
index 21e70fbf1dae55cae5ab87cd19c4cbaba3dc57b7..80dd438642f69b293e5aa090d9fb222d5f3c2db1 100644 (file)
@@ -66,6 +66,14 @@ void paging_init(void);
 #define VMALLOC_OFFSET (8*1024*1024)
 #define VMALLOC_START  (((unsigned long) high_memory + \
                        2*VMALLOC_OFFSET-1) & ~(VMALLOC_OFFSET-1))
+#ifdef CONFIG_X86_PAE
+#define LAST_PKMAP 512
+#else
+#define LAST_PKMAP 1024
+#endif
+
+#define PKMAP_BASE ((FIXADDR_BOOT_START - PAGE_SIZE*(LAST_PKMAP + 1)) & PMD_MASK)
+
 #ifdef CONFIG_HIGHMEM
 # define VMALLOC_END   (PKMAP_BASE-2*PAGE_SIZE)
 #else
@@ -148,6 +156,8 @@ static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
  */
 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
 
+static inline int pud_large(pud_t pud) { return 0; }
+
 /*
  * the pmd page can be thought of an array like this: pmd_t[PTRS_PER_PMD]
  *
index 6e615a103c2ff485fdd59b18b081243325baf114..bd4740a60f29b5c288eebd6f8e379c9259099aba 100644 (file)
@@ -21,7 +21,6 @@ extern pgd_t init_level4_pgt[];
 #define swapper_pg_dir init_level4_pgt
 
 extern void paging_init(void);
-extern void clear_kernel_mapping(unsigned long addr, unsigned long size);
 
 #endif /* !__ASSEMBLY__ */
 
@@ -199,6 +198,12 @@ static inline unsigned long pmd_bad(pmd_t pmd)
 #define pud_offset(pgd, address) ((pud_t *) pgd_page_vaddr(*(pgd)) + pud_index(address))
 #define pud_present(pud) (pud_val(pud) & _PAGE_PRESENT)
 
+static inline int pud_large(pud_t pte)
+{
+       return (pud_val(pte) & (_PAGE_PSE|_PAGE_PRESENT)) ==
+               (_PAGE_PSE|_PAGE_PRESENT);
+}
+
 /* PMD  - Level 2 access */
 #define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val(pmd) & PTE_MASK))
 #define pmd_page(pmd)          (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
index 55bfa308f900c831733f91018a0f68111aa35e6e..c5d13a86dea7faa61c8cf75deede797b22c4e640 100644 (file)
@@ -213,14 +213,14 @@ static __always_inline void * __constant_c_and_count_memset(void * s, unsigned l
                case 0:
                        return s;
                case 1:
-                       *(unsigned char *)s = pattern;
+                       *(unsigned char *)s = pattern & 0xff;
                        return s;
                case 2:
-                       *(unsigned short *)s = pattern;
+                       *(unsigned short *)s = pattern & 0xffff;
                        return s;
                case 3:
-                       *(unsigned short *)s = pattern;
-                       *(2+(unsigned char *)s) = pattern;
+                       *(unsigned short *)s = pattern & 0xffff;
+                       *(2+(unsigned char *)s) = pattern & 0xff;
                        return s;
                case 4:
                        *(unsigned long *)s = pattern;
index ee32ef9367f4f25b1c87bf435d2c80ed8586c9c9..9cff02ffe6c2d261e6c905fe6f0d9958ccaf2fbb 100644 (file)
@@ -20,8 +20,8 @@
 #ifdef CONFIG_X86_32
 
 struct task_struct; /* one of the stranger aspects of C forward declarations */
-extern struct task_struct *FASTCALL(__switch_to(struct task_struct *prev,
-                                               struct task_struct *next));
+struct task_struct *__switch_to(struct task_struct *prev,
+                               struct task_struct *next);
 
 /*
  * Saving eflags is important. It switches not only IOPL between tasks,
@@ -130,10 +130,7 @@ extern void load_gs_index(unsigned);
                "movl %k1, %%" #seg "\n\t"      \
                "jmp 2b\n"                      \
                ".previous\n"                   \
-               ".section __ex_table,\"a\"\n\t" \
-               _ASM_ALIGN "\n\t"               \
-               _ASM_PTR " 1b,3b\n"             \
-               ".previous"                     \
+               _ASM_EXTABLE(1b,3b)             \
                : :"r" (value), "r" (0))
 
 
@@ -214,12 +211,10 @@ static inline unsigned long native_read_cr4_safe(void)
        /* This could fault if %cr4 does not exist. In x86_64, a cr4 always
         * exists, so it will never fail. */
 #ifdef CONFIG_X86_32
-       asm volatile("1: mov %%cr4, %0          \n"
-               "2:                             \n"
-               ".section __ex_table,\"a\"      \n"
-               ".long 1b,2b                    \n"
-               ".previous                      \n"
-               : "=r" (val), "=m" (__force_order) : "0" (0));
+       asm volatile("1: mov %%cr4, %0\n"
+                    "2:\n"
+                    _ASM_EXTABLE(1b,2b)
+                    : "=r" (val), "=m" (__force_order) : "0" (0));
 #else
        val = native_read_cr4();
 #endif
@@ -276,9 +271,9 @@ static inline void native_wbinvd(void)
 
 #endif /* __KERNEL__ */
 
-static inline void clflush(void *__p)
+static inline void clflush(volatile void *__p)
 {
-       asm volatile("clflush %0" : "+m" (*(char __force *)__p));
+       asm volatile("clflush %0" : "+m" (*(volatile char __force *)__p));
 }
 
 #define nop() __asm__ __volatile__ ("nop")
index 27cfd6c599bad2ab649806c3aecefc69cb602947..43e5a78500c57905fa8c24f5397f37a86a13fd7a 100644 (file)
@@ -14,7 +14,6 @@
 #endif
 #define CLOCK_TICK_RATE        PIT_TICK_RATE
 
-extern int read_current_timer(unsigned long *timer_value);
-#define ARCH_HAS_READ_CURRENT_TIMER    1
+#define ARCH_HAS_READ_CURRENT_TIMER
 
 #endif
index d2a4f7be9c2c5ee3a1516b0b5bf636addc2cefac..fcc570ec4feed9107f4910da8e6a4939df3d2824 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/thread_info.h>
 #include <linux/prefetch.h>
 #include <linux/string.h>
+#include <asm/asm.h>
 #include <asm/page.h>
 
 #define VERIFY_READ 0
@@ -287,11 +288,8 @@ extern void __put_user_8(void);
                "4:     movl %3,%0\n"                           \
                "       jmp 3b\n"                               \
                ".previous\n"                                   \
-               ".section __ex_table,\"a\"\n"                   \
-               "       .align 4\n"                             \
-               "       .long 1b,4b\n"                          \
-               "       .long 2b,4b\n"                          \
-               ".previous"                                     \
+               _ASM_EXTABLE(1b,4b)                             \
+               _ASM_EXTABLE(2b,4b)                             \
                : "=r"(err)                                     \
                : "A" (x), "r" (addr), "i"(-EFAULT), "0"(err))
 
@@ -338,10 +336,7 @@ struct __large_struct { unsigned long buf[100]; };
                "3:     movl %3,%0\n"                                   \
                "       jmp 2b\n"                                       \
                ".previous\n"                                           \
-               ".section __ex_table,\"a\"\n"                           \
-               "       .align 4\n"                                     \
-               "       .long 1b,3b\n"                                  \
-               ".previous"                                             \
+               _ASM_EXTABLE(1b,3b)                                     \
                : "=r"(err)                                             \
                : ltype (x), "m"(__m(addr)), "i"(errret), "0"(err))
 
@@ -378,10 +373,7 @@ do {                                                                       \
                "       xor"itype" %"rtype"1,%"rtype"1\n"               \
                "       jmp 2b\n"                                       \
                ".previous\n"                                           \
-               ".section __ex_table,\"a\"\n"                           \
-               "       .align 4\n"                                     \
-               "       .long 1b,3b\n"                                  \
-               ".previous"                                             \
+               _ASM_EXTABLE(1b,3b)                                     \
                : "=r"(err), ltype (x)                                  \
                : "m"(__m(addr)), "i"(errret), "0"(err))
 
index 31d79470271942af7e4f8449294761b0d383b619..b87eb4ba8f9d6e20ff345eda0fcc78e88a807df5 100644 (file)
@@ -181,10 +181,7 @@ struct __large_struct { unsigned long buf[100]; };
                "3:     mov %3,%0\n"                            \
                "       jmp 2b\n"                               \
                ".previous\n"                                   \
-               ".section __ex_table,\"a\"\n"                   \
-               "       .align 8\n"                             \
-               "       .quad 1b,3b\n"                          \
-               ".previous"                                     \
+               _ASM_EXTABLE(1b,3b)                             \
                : "=r"(err)                                     \
                : ltype (x), "m"(__m(addr)), "i"(errno), "0"(err))
 
@@ -226,10 +223,7 @@ do {                                                                       \
                "       xor"itype" %"rtype"1,%"rtype"1\n"       \
                "       jmp 2b\n"                               \
                ".previous\n"                                   \
-               ".section __ex_table,\"a\"\n"                   \
-               "       .align 8\n"                             \
-               "       .quad 1b,3b\n"                          \
-               ".previous"                                     \
+               _ASM_EXTABLE(1b,3b)                             \
                : "=r"(err), ltype (x)                          \
                : "m"(__m(addr)), "i"(errno), "0"(err))
 
index 8d8f9b5adbb971a740ccf73476df86c280dd5d89..984123a68f7cc164ec78c540241546c469dbf295 100644 (file)
 #define __NR_epoll_pwait       319
 #define __NR_utimensat         320
 #define __NR_signalfd          321
-#define __NR_timerfd           322
+#define __NR_timerfd_create    322
 #define __NR_eventfd           323
 #define __NR_fallocate         324
+#define __NR_timerfd_settime   325
+#define __NR_timerfd_gettime   326
 
 #ifdef __KERNEL__
 
index 5ff4d3e24c348814e04a329ee5dc71c96a696784..3883ceb54ef5c144f1de6035ba670d5628a3e1cb 100644 (file)
@@ -629,12 +629,17 @@ __SYSCALL(__NR_utimensat, sys_utimensat)
 __SYSCALL(__NR_epoll_pwait, sys_epoll_pwait)
 #define __NR_signalfd                          282
 __SYSCALL(__NR_signalfd, sys_signalfd)
-#define __NR_timerfd                           283
-__SYSCALL(__NR_timerfd, sys_timerfd)
+#define __NR_timerfd_create                    283
+__SYSCALL(__NR_timerfd_create, sys_timerfd_create)
 #define __NR_eventfd                           284
 __SYSCALL(__NR_eventfd, sys_eventfd)
 #define __NR_fallocate                         285
 __SYSCALL(__NR_fallocate, sys_fallocate)
+#define __NR_timerfd_settime                   286
+__SYSCALL(__NR_timerfd_settime, sys_timerfd_settime)
+#define __NR_timerfd_gettime                   287
+__SYSCALL(__NR_timerfd_gettime, sys_timerfd_gettime)
+
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
index a5edf517b992d51a3689cb1539a7dd12f1368c13..c92fe4af52e891a42b6c7907d78e0338eafa5918 100644 (file)
@@ -195,6 +195,7 @@ struct kernel_vm86_struct {
 
 void handle_vm86_fault(struct kernel_vm86_regs *, long);
 int handle_vm86_trap(struct kernel_vm86_regs *, long, int);
+struct pt_regs *save_v86_state(struct kernel_vm86_regs *);
 
 struct task_struct;
 void release_vm86_irqs(struct task_struct *);
index 3e5b5652510239b081db16e3f54102289bee6cdd..1d51ba5463f9f2f215015c598b5ef51bb7ff06f2 100644 (file)
@@ -31,7 +31,7 @@ pgd_alloc(struct mm_struct *mm)
        return (pgd_t*) __get_free_pages(GFP_KERNEL | __GFP_ZERO, PGD_ORDER);
 }
 
-static inline void pgd_free(pgd_t *pgd)
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        free_page((unsigned long)pgd);
 }
@@ -52,12 +52,12 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        return virt_to_page(pte_alloc_one_kernel(mm, addr));
 }
 
-static inline void pte_free_kernel(pte_t *pte)
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        kmem_cache_free(pgtable_cache, pte);
 }
 
-static inline void pte_free(struct page *page)
+static inline void pte_free(struct mm_struct *mm, struct page *page)
 {
        kmem_cache_free(pgtable_cache, page_address(page));
 }
index 4830232017aff0766c99b83a7cc185acf473f919..31c220faca02ac9cbb3695f735e0221bdc32104a 100644 (file)
@@ -42,6 +42,6 @@
 
 #include <asm-generic/tlb.h>
 
-#define __pte_free_tlb(tlb,pte)                        pte_free(pte)
+#define __pte_free_tlb(tlb, pte)               pte_free((tlb)->mm, pte)
 
 #endif /* _XTENSA_TLB_H */
index 85b2482cc736c782307c99afd26a7b1f834f38d9..93631229fd5c89e70c378f26d30b72c72d112e02 100644 (file)
@@ -143,6 +143,7 @@ header-y += snmp.h
 header-y += sockios.h
 header-y += som.h
 header-y += sound.h
+header-y += suspend_ioctls.h
 header-y += taskstats.h
 header-y += telephony.h
 header-y += termios.h
@@ -218,6 +219,7 @@ unifdef-y += i2c-dev.h
 unifdef-y += icmp.h
 unifdef-y += icmpv6.h
 unifdef-y += if_addr.h
+unifdef-y += if_addrlabel.h
 unifdef-y += if_arp.h
 unifdef-y += if_bridge.h
 unifdef-y += if_ec.h
index 22eb9367235aee14f2e2da4863f450d842287e2b..0260c3e79fddc90ec5ab08694fdfc72d9969860f 100644 (file)
@@ -326,11 +326,7 @@ struct ac97_ops
 #define AC97_DEFAULT_POWER_OFF 4 /* Needs warm reset to power up */
 };
 
-extern int ac97_read_proc (char *page_out, char **start, off_t off,
-                          int count, int *eof, void *data);
 extern int ac97_probe_codec(struct ac97_codec *);
-extern unsigned int ac97_set_adc_rate(struct ac97_codec *codec, unsigned int rate);
-extern unsigned int ac97_set_dac_rate(struct ac97_codec *codec, unsigned int rate);
 
 extern struct ac97_codec *ac97_alloc_codec(void);
 extern void ac97_release_codec(struct ac97_codec *codec);
@@ -363,7 +359,4 @@ struct ac97_quirk {
        int type;               /* quirk type above */
 };
 
-struct pci_dev;
-extern int ac97_tune_hardware(struct pci_dev *pdev, struct ac97_quirk *quirk, int override);
-
 #endif /* _AC97_CODEC_H_ */
index 302eb727ecb85dc7dec0db126c9a5d5240d8194b..e8cae54e8d88b9116d4813771978f2acecc58bf2 100644 (file)
@@ -173,7 +173,11 @@ typedef struct acct acct_t;
 static inline u32 jiffies_to_AHZ(unsigned long x)
 {
 #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
+# if HZ < AHZ
+       return x * (AHZ / HZ);
+# else
        return x / (HZ / AHZ);
+# endif
 #else
         u64 tmp = (u64)x * TICK_NSEC;
         do_div(tmp, (NSEC_PER_SEC / AHZ));
index abc521cfb08464a7e5a9c3cf11ca60d80f0529af..03e34547d489132632b6a15b2286c7dc2ac8ffa5 100644 (file)
@@ -109,6 +109,7 @@ extern int agp_unbind_memory(struct agp_memory *);
 extern void agp_enable(struct agp_bridge_data *, u32);
 extern struct agp_bridge_data *agp_backend_acquire(struct pci_dev *);
 extern void agp_backend_release(struct agp_bridge_data *);
+extern void agp_flush_chipset(struct agp_bridge_data *);
 
 #endif                         /* __KERNEL__ */
 #endif                         /* _AGP_BACKEND_H */
index 09fbf7e5a6cbbbba0b3fe6991f4aefa494e937a4..62aef589eb940936d6adb53889165b4e1f17dba2 100644 (file)
@@ -38,6 +38,7 @@
 #define AGPIOC_DEALLOCATE _IOW (AGPIOC_BASE, 7, int)
 #define AGPIOC_BIND       _IOW (AGPIOC_BASE, 8, struct agp_bind*)
 #define AGPIOC_UNBIND     _IOW (AGPIOC_BASE, 9, struct agp_unbind*)
+#define AGPIOC_CHIPSET_FLUSH _IO (AGPIOC_BASE, 10)
 
 #define AGP_DEVICE      "/dev/agpgart"
 
index bdca3f1b3213ffb4871ed3cc028ae5a1f9257220..eb640f0acfacd629ee179c4b10e639d56a04b93a 100644 (file)
@@ -47,7 +47,6 @@ struct dma_chan_ref {
  * address is an implied source, whereas the asynchronous case it must be listed
  * as a source.  The destination address must be the first address in the source
  * array.
- * @ASYNC_TX_ASSUME_COHERENT: skip cache maintenance operations
  * @ASYNC_TX_ACK: immediately ack the descriptor, precludes setting up a
  * dependency chain
  * @ASYNC_TX_DEP_ACK: ack the dependency descriptor.  Useful for chaining.
@@ -55,7 +54,6 @@ struct dma_chan_ref {
 enum async_tx_flags {
        ASYNC_TX_XOR_ZERO_DST    = (1 << 0),
        ASYNC_TX_XOR_DROP_DST    = (1 << 1),
-       ASYNC_TX_ASSUME_COHERENT = (1 << 2),
        ASYNC_TX_ACK             = (1 << 3),
        ASYNC_TX_DEP_ACK         = (1 << 4),
 };
@@ -64,9 +62,15 @@ enum async_tx_flags {
 void async_tx_issue_pending_all(void);
 enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
 void async_tx_run_dependencies(struct dma_async_tx_descriptor *tx);
+#ifdef CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL
+#include <asm/async_tx.h>
+#else
+#define async_tx_find_channel(dep, type, dst, dst_count, src, src_count, len) \
+        __async_tx_find_channel(dep, type)
 struct dma_chan *
-async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
+__async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
        enum dma_transaction_type tx_type);
+#endif /* CONFIG_ARCH_HAS_ASYNC_TX_FIND_CHANNEL */
 #else
 static inline void async_tx_issue_pending_all(void)
 {
@@ -88,7 +92,8 @@ async_tx_run_dependencies(struct dma_async_tx_descriptor *tx,
 
 static inline struct dma_chan *
 async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
-       enum dma_transaction_type tx_type)
+       enum dma_transaction_type tx_type, struct page **dst, int dst_count,
+       struct page **src, int src_count, size_t len)
 {
        return NULL;
 }
similarity index 75%
rename from include/linux/pata_platform.h
rename to include/linux/ata_platform.h
index 6a7a92db294c03d92fb1174cff79a6fcdd65b0c3..b856a2a590d96c8b376b3c2ebcdb3f0fbc6be022 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef __LINUX_PATA_PLATFORM_H
-#define __LINUX_PATA_PLATFORM_H
+#ifndef __LINUX_ATA_PLATFORM_H
+#define __LINUX_ATA_PLATFORM_H
 
 struct pata_platform_info {
        /*
@@ -24,4 +24,11 @@ extern int __devinit __pata_platform_probe(struct device *dev,
 
 extern int __devexit __pata_platform_remove(struct device *dev);
 
-#endif /* __LINUX_PATA_PLATFORM_H */
+/*
+ * Marvell SATA private data
+ */
+struct mv_sata_platform_data {
+       int     n_ports; /* number of sata ports */
+};
+
+#endif /* __LINUX_ATA_PLATFORM_H */
similarity index 99%
rename from drivers/serial/atmel_serial.h
rename to include/linux/atmel_serial.h
index e0141776517c4fec9714d0077a8dac21d5f0c851..fd6833764d72b3bf77788741c6e85309b5aa6a72 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * drivers/serial/atmel_serial.h
+ * include/linux/atmel_serial.h
  *
  * Copyright (C) 2005 Ivan Kokshaysky
  * Copyright (C) SAN People
index bb017edffd56816099064f7367f925c15277aa09..7d50ff6d269fc6eb75d298e36140dfc012a8daf5 100644 (file)
@@ -14,7 +14,6 @@
 #define _LINUX_CAPABILITY_H
 
 #include <linux/types.h>
-#include <linux/compiler.h>
 
 struct task_struct;
 
@@ -23,13 +22,20 @@ struct task_struct;
    kernel might be somewhat backwards compatible, but don't bet on
    it. */
 
-/* XXX - Note, cap_t, is defined by POSIX to be an "opaque" pointer to
+/* Note, cap_t, is defined by POSIX (draft) to be an "opaque" pointer to
    a set of three capability sets.  The transposition of 3*the
    following structure to such a composite is better handled in a user
    library since the draft standard requires the use of malloc/free
    etc.. */
 
-#define _LINUX_CAPABILITY_VERSION  0x19980330
+#define _LINUX_CAPABILITY_VERSION_1  0x19980330
+#define _LINUX_CAPABILITY_U32S_1     1
+
+#define _LINUX_CAPABILITY_VERSION_2  0x20071026
+#define _LINUX_CAPABILITY_U32S_2     2
+
+#define _LINUX_CAPABILITY_VERSION    _LINUX_CAPABILITY_VERSION_2
+#define _LINUX_CAPABILITY_U32S       _LINUX_CAPABILITY_U32S_2
 
 typedef struct __user_cap_header_struct {
        __u32 version;
@@ -42,41 +48,42 @@ typedef struct __user_cap_data_struct {
         __u32 inheritable;
 } __user *cap_user_data_t;
 
+
 #define XATTR_CAPS_SUFFIX "capability"
 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
 
-#define XATTR_CAPS_SZ (3*sizeof(__le32))
 #define VFS_CAP_REVISION_MASK  0xFF000000
+#define VFS_CAP_FLAGS_MASK     ~VFS_CAP_REVISION_MASK
+#define VFS_CAP_FLAGS_EFFECTIVE        0x000001
+
 #define VFS_CAP_REVISION_1     0x01000000
+#define VFS_CAP_U32_1           1
+#define XATTR_CAPS_SZ_1         (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1))
 
-#define VFS_CAP_REVISION       VFS_CAP_REVISION_1
+#define VFS_CAP_REVISION_2     0x02000000
+#define VFS_CAP_U32_2           2
+#define XATTR_CAPS_SZ_2         (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2))
+
+#define XATTR_CAPS_SZ           XATTR_CAPS_SZ_2
+#define VFS_CAP_U32             VFS_CAP_U32_2
+#define VFS_CAP_REVISION       VFS_CAP_REVISION_2
 
-#define VFS_CAP_FLAGS_MASK     ~VFS_CAP_REVISION_MASK
-#define VFS_CAP_FLAGS_EFFECTIVE        0x000001
 
 struct vfs_cap_data {
-       __u32 magic_etc;  /* Little endian */
-       __u32 permitted;    /* Little endian */
-       __u32 inheritable;  /* Little endian */
+       __le32 magic_etc;            /* Little endian */
+       struct {
+               __le32 permitted;    /* Little endian */
+               __le32 inheritable;  /* Little endian */
+       } data[VFS_CAP_U32];
 };
 
 #ifdef __KERNEL__
 
-/* #define STRICT_CAP_T_TYPECHECKS */
-
-#ifdef STRICT_CAP_T_TYPECHECKS
-
 typedef struct kernel_cap_struct {
-       __u32 cap;
+       __u32 cap[_LINUX_CAPABILITY_U32S];
 } kernel_cap_t;
 
-#else
-
-typedef __u32 kernel_cap_t;
-
-#endif
-
-#define _USER_CAP_HEADER_SIZE  (2*sizeof(__u32))
+#define _USER_CAP_HEADER_SIZE  (sizeof(struct __user_cap_header_struct))
 #define _KERNEL_CAP_T_SIZE     (sizeof(kernel_cap_t))
 
 #endif
@@ -119,10 +126,6 @@ typedef __u32 kernel_cap_t;
 
 #define CAP_FSETID           4
 
-/* Used to decide between falling back on the old suser() or fsuser(). */
-
-#define CAP_FS_MASK          0x1f
-
 /* Overrides the restriction that the real or effective user ID of a
    process sending a signal must match the real or effective user ID
    of the process receiving the signal. */
@@ -145,8 +148,14 @@ typedef __u32 kernel_cap_t;
  ** Linux-specific capabilities
  **/
 
-/* Transfer any capability in your permitted set to any pid,
-   remove any capability in your permitted set from any pid */
+/* Without VFS support for capabilities:
+ *   Transfer any capability in your permitted set to any pid,
+ *   remove any capability in your permitted set from any pid
+ * With VFS support for capabilities (neither of above, but)
+ *   Add any capability from current's capability bounding set
+ *       to the current process' inheritable set
+ *   Allow taking bits out of capability bounding set
+ */
 
 #define CAP_SETPCAP          8
 
@@ -195,7 +204,6 @@ typedef __u32 kernel_cap_t;
 #define CAP_IPC_OWNER        15
 
 /* Insert and remove kernel modules - modify kernel without limit */
-/* Modify cap_bset */
 #define CAP_SYS_MODULE       16
 
 /* Allow ioperm/iopl access */
@@ -307,74 +315,183 @@ typedef __u32 kernel_cap_t;
 
 #define CAP_SETFCAP         31
 
+/* Override MAC access.
+   The base kernel enforces no MAC policy.
+   An LSM may enforce a MAC policy, and if it does and it chooses
+   to implement capability based overrides of that policy, this is
+   the capability it should use to do so. */
+
+#define CAP_MAC_OVERRIDE     32
+
+/* Allow MAC configuration or state changes.
+   The base kernel requires no MAC configuration.
+   An LSM may enforce a MAC policy, and if it does and it chooses
+   to implement capability based checks on modifications to that
+   policy or the data required to maintain it, this is the
+   capability it should use to do so. */
+
+#define CAP_MAC_ADMIN        33
+
+#define CAP_LAST_CAP         CAP_MAC_ADMIN
+
+#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
+
+/*
+ * Bit location of each capability (used by user-space library and kernel)
+ */
+
+#define CAP_TO_INDEX(x)     ((x) >> 5)        /* 1 << 5 == bits in __u32 */
+#define CAP_TO_MASK(x)      (1 << ((x) & 31)) /* mask for indexed __u32 */
+
 #ifdef __KERNEL__
 
 /*
  * Internal kernel functions only
  */
 
-#ifdef STRICT_CAP_T_TYPECHECKS
+#define CAP_FOR_EACH_U32(__capi)  \
+       for (__capi = 0; __capi < _LINUX_CAPABILITY_U32S; ++__capi)
+
+# define CAP_FS_MASK_B0     (CAP_TO_MASK(CAP_CHOWN)            \
+                           | CAP_TO_MASK(CAP_DAC_OVERRIDE)     \
+                           | CAP_TO_MASK(CAP_DAC_READ_SEARCH)  \
+                           | CAP_TO_MASK(CAP_FOWNER)           \
+                           | CAP_TO_MASK(CAP_FSETID))
+
+# define CAP_FS_MASK_B1     (CAP_TO_MASK(CAP_MAC_OVERRIDE))
+
+#if _LINUX_CAPABILITY_U32S != 2
+# error Fix up hand-coded capability macro initializers
+#else /* HAND-CODED capability initializers */
+
+# define CAP_EMPTY_SET    {{ 0, 0 }}
+# define CAP_FULL_SET     {{ ~0, ~0 }}
+# define CAP_INIT_EFF_SET {{ ~CAP_TO_MASK(CAP_SETPCAP), ~0 }}
+# define CAP_FS_SET       {{ CAP_FS_MASK_B0, CAP_FS_MASK_B1 } }
+# define CAP_NFSD_SET     {{ CAP_FS_MASK_B0|CAP_TO_MASK(CAP_SYS_RESOURCE), \
+                            CAP_FS_MASK_B1 } }
+
+#endif /* _LINUX_CAPABILITY_U32S != 2 */
+
+#define CAP_INIT_INH_SET    CAP_EMPTY_SET
+
+# define cap_clear(c)         do { (c) = __cap_empty_set; } while (0)
+# define cap_set_full(c)      do { (c) = __cap_full_set; } while (0)
+# define cap_set_init_eff(c)  do { (c) = __cap_init_eff_set; } while (0)
+
+#define cap_raise(c, flag)  ((c).cap[CAP_TO_INDEX(flag)] |= CAP_TO_MASK(flag))
+#define cap_lower(c, flag)  ((c).cap[CAP_TO_INDEX(flag)] &= ~CAP_TO_MASK(flag))
+#define cap_raised(c, flag) ((c).cap[CAP_TO_INDEX(flag)] & CAP_TO_MASK(flag))
+
+#define CAP_BOP_ALL(c, a, b, OP)                                    \
+do {                                                                \
+       unsigned __capi;                                            \
+       CAP_FOR_EACH_U32(__capi) {                                  \
+               c.cap[__capi] = a.cap[__capi] OP b.cap[__capi];     \
+       }                                                           \
+} while (0)
+
+#define CAP_UOP_ALL(c, a, OP)                                       \
+do {                                                                \
+       unsigned __capi;                                            \
+       CAP_FOR_EACH_U32(__capi) {                                  \
+               c.cap[__capi] = OP a.cap[__capi];                   \
+       }                                                           \
+} while (0)
+
+static inline kernel_cap_t cap_combine(const kernel_cap_t a,
+                                      const kernel_cap_t b)
+{
+       kernel_cap_t dest;
+       CAP_BOP_ALL(dest, a, b, |);
+       return dest;
+}
 
-#define to_cap_t(x) { x }
-#define cap_t(x) (x).cap
+static inline kernel_cap_t cap_intersect(const kernel_cap_t a,
+                                        const kernel_cap_t b)
+{
+       kernel_cap_t dest;
+       CAP_BOP_ALL(dest, a, b, &);
+       return dest;
+}
 
-#else
+static inline kernel_cap_t cap_drop(const kernel_cap_t a,
+                                   const kernel_cap_t drop)
+{
+       kernel_cap_t dest;
+       CAP_BOP_ALL(dest, a, drop, &~);
+       return dest;
+}
 
-#define to_cap_t(x) (x)
-#define cap_t(x) (x)
+static inline kernel_cap_t cap_invert(const kernel_cap_t c)
+{
+       kernel_cap_t dest;
+       CAP_UOP_ALL(dest, c, ~);
+       return dest;
+}
 
-#endif
+static inline int cap_isclear(const kernel_cap_t a)
+{
+       unsigned __capi;
+       CAP_FOR_EACH_U32(__capi) {
+               if (a.cap[__capi] != 0)
+                       return 0;
+       }
+       return 1;
+}
 
-#define CAP_EMPTY_SET       to_cap_t(0)
-#define CAP_FULL_SET        to_cap_t(~0)
-#define CAP_INIT_EFF_SET    to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
-#define CAP_INIT_INH_SET    to_cap_t(0)
+static inline int cap_issubset(const kernel_cap_t a, const kernel_cap_t set)
+{
+       kernel_cap_t dest;
+       dest = cap_drop(a, set);
+       return cap_isclear(dest);
+}
 
-#define CAP_TO_MASK(x) (1 << (x))
-#define cap_raise(c, flag)   (cap_t(c) |=  CAP_TO_MASK(flag))
-#define cap_lower(c, flag)   (cap_t(c) &= ~CAP_TO_MASK(flag))
-#define cap_raised(c, flag)  (cap_t(c) & CAP_TO_MASK(flag))
+/* Used to decide between falling back on the old suser() or fsuser(). */
 
-static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
+static inline int cap_is_fs_cap(int cap)
 {
-     kernel_cap_t dest;
-     cap_t(dest) = cap_t(a) | cap_t(b);
-     return dest;
+       const kernel_cap_t __cap_fs_set = CAP_FS_SET;
+       return !!(CAP_TO_MASK(cap) & __cap_fs_set.cap[CAP_TO_INDEX(cap)]);
 }
 
-static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b)
+static inline kernel_cap_t cap_drop_fs_set(const kernel_cap_t a)
 {
-     kernel_cap_t dest;
-     cap_t(dest) = cap_t(a) & cap_t(b);
-     return dest;
+       const kernel_cap_t __cap_fs_set = CAP_FS_SET;
+       return cap_drop(a, __cap_fs_set);
 }
 
-static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop)
+static inline kernel_cap_t cap_raise_fs_set(const kernel_cap_t a,
+                                           const kernel_cap_t permitted)
 {
-     kernel_cap_t dest;
-     cap_t(dest) = cap_t(a) & ~cap_t(drop);
-     return dest;
+       const kernel_cap_t __cap_fs_set = CAP_FS_SET;
+       return cap_combine(a,
+                          cap_intersect(permitted, __cap_fs_set));
 }
 
-static inline kernel_cap_t cap_invert(kernel_cap_t c)
+static inline kernel_cap_t cap_drop_nfsd_set(const kernel_cap_t a)
 {
-     kernel_cap_t dest;
-     cap_t(dest) = ~cap_t(c);
-     return dest;
+       const kernel_cap_t __cap_fs_set = CAP_NFSD_SET;
+       return cap_drop(a, __cap_fs_set);
 }
 
-#define cap_isclear(c)       (!cap_t(c))
-#define cap_issubset(a,set)  (!(cap_t(a) & ~cap_t(set)))
-
-#define cap_clear(c)         do { cap_t(c) =  0; } while(0)
-#define cap_set_full(c)      do { cap_t(c) = ~0; } while(0)
-#define cap_mask(c,mask)     do { cap_t(c) &= cap_t(mask); } while(0)
+static inline kernel_cap_t cap_raise_nfsd_set(const kernel_cap_t a,
+                                             const kernel_cap_t permitted)
+{
+       const kernel_cap_t __cap_nfsd_set = CAP_NFSD_SET;
+       return cap_combine(a,
+                          cap_intersect(permitted, __cap_nfsd_set));
+}
 
-#define cap_is_fs_cap(c)     (CAP_TO_MASK(c) & CAP_FS_MASK)
+extern const kernel_cap_t __cap_empty_set;
+extern const kernel_cap_t __cap_full_set;
+extern const kernel_cap_t __cap_init_eff_set;
 
 int capable(int cap);
 int __capable(struct task_struct *t, int cap);
 
+extern long cap_prctl_drop(unsigned long cap);
+
 #endif /* __KERNEL__ */
 
 #endif /* !_LINUX_CAPABILITY_H */
index a404c111c937a2da3dcddba17f7aba0a63e82cb4..519248d8b2b6529f3ec8833d09d0bf97710a5fac 100644 (file)
@@ -108,7 +108,7 @@ struct changer_element_status {
 
 /*
  * CHIOGELEM
- *    get more detailed status informtion for a single element
+ *    get more detailed status information for a single element
  */
 struct changer_get_element {
        int     cge_type;        /* type/unit */
index d38655f2be7088e3bce8d63476ec525fdf347511..a671dbff7a1fa229ab45851286ade5eed9b8fef1 100644 (file)
@@ -257,16 +257,8 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
 /*
  * epoll (fs/eventpoll.c) compat bits follow ...
  */
-#ifndef CONFIG_HAS_COMPAT_EPOLL_EVENT
 struct epoll_event;
 #define compat_epoll_event     epoll_event
-#else
-asmlinkage long compat_sys_epoll_ctl(int epfd, int op, int fd,
-                       struct compat_epoll_event __user *event);
-asmlinkage long compat_sys_epoll_wait(int epfd,
-                       struct compat_epoll_event __user *events,
-                       int maxevents, int timeout);
-#endif
 asmlinkage long compat_sys_epoll_pwait(int epfd,
                        struct compat_epoll_event __user *events,
                        int maxevents, int timeout,
@@ -279,8 +271,11 @@ asmlinkage long compat_sys_utimensat(unsigned int dfd, char __user *filename,
 asmlinkage long compat_sys_signalfd(int ufd,
                                const compat_sigset_t __user *sigmask,
                                 compat_size_t sigsetsize);
-asmlinkage long compat_sys_timerfd(int ufd, int clockid, int flags,
-                               const struct compat_itimerspec __user *utmr);
+asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
+                                  const struct compat_itimerspec __user *utmr,
+                                  struct compat_itimerspec __user *otmr);
+asmlinkage long compat_sys_timerfd_gettime(int ufd,
+                                  struct compat_itimerspec __user *otmr);
 
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */
index c4e00161a247975aca754484ecb5f232d1ff4f08..b0fd85ab9efb07efc8c39ef6e3857e29caa93dfb 100644 (file)
@@ -79,7 +79,7 @@ struct cpuidle_state_kobj {
 };
 
 struct cpuidle_device {
-       int                     enabled:1;
+       unsigned int            enabled:1;
        unsigned int            cpu;
 
        int                     last_residency;
index 8f3dcd30828fbb149ef7ee30c788ebf2e312e6e6..504cb2c3fa9a68fb77a0a4b3afb94a933c095f9c 100644 (file)
@@ -177,7 +177,7 @@ struct      CUSTOM_REG {
        __u32   fpga_version;           /* FPGA Version Number Register */
        __u32   cpu_start;              /* CPU start Register (write) */
        __u32   cpu_stop;               /* CPU stop Register (write) */
-       __u32   misc_reg;               /* Miscelaneous Register */
+       __u32   misc_reg;               /* Miscellaneous Register */
        __u32   idt_mode;               /* IDT mode Register */
        __u32   uart_irq_status;        /* UART IRQ status Register */
        __u32   clear_timer0_irq;       /* Clear timer interrupt Register */
index f7a9065834636c5824677d274beee1fc2d5f192d..362bf19d6cf194a8ae40f84632debc34aac218f0 100644 (file)
@@ -81,7 +81,7 @@ struct cycx_x25_cmd {
  *     @n2win - level 2 window (values: 1 thru 7)
  *     @n3win - level 3 window (values: 1 thru 7)
  *     @nvc - # of logical channels (values: 1 thru 64)
- *     @pktlen - level 3 packet lenght - log base 2 of size
+ *     @pktlen - level 3 packet length - log base 2 of size
  *     @locaddr - my address
  *     @remaddr - remote address
  *     @t1 - time, in seconds
index 484e45c7c89a832dd986c7fe927e545168e2ec77..aa0737019e37da6e759ea95e026088cbbfc6518d 100644 (file)
@@ -525,6 +525,7 @@ struct dccp_sock {
        __u64                           dccps_gsr;
        __u64                           dccps_gar;
        __be32                          dccps_service;
+       __u32                           dccps_mss_cache;
        struct dccp_service_list        *dccps_service_list;
        __u32                           dccps_timestamp_echo;
        __u32                           dccps_timestamp_time;
@@ -533,7 +534,6 @@ struct dccp_sock {
        __u16                           dccps_pcslen;
        __u16                           dccps_pcrlen;
        unsigned long                   dccps_ndp_count;
-       __u32                           dccps_mss_cache;
        unsigned long                   dccps_rate_last;
        struct dccp_minisock            dccps_minisock;
        struct dccp_ackvec              *dccps_hc_rx_ackvec;
index db375be333c708a2e556c5424c95a0aa91802836..2258d89bf5236fed75a7ce231c50fb25c088fb26 100644 (file)
@@ -410,6 +410,15 @@ extern int devres_release_group(struct device *dev, void *id);
 extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
 extern void devm_kfree(struct device *dev, void *p);
 
+struct device_dma_parameters {
+       /*
+        * a low level driver may set these to teach IOMMU code about
+        * sg limitations.
+        */
+       unsigned int max_segment_size;
+       unsigned long segment_boundary_mask;
+};
+
 struct device {
        struct klist            klist_children;
        struct klist_node       knode_parent;   /* node in sibling list */
@@ -445,6 +454,8 @@ struct device {
                                             64 bit addresses for consistent
                                             allocations such descriptors. */
 
+       struct device_dma_parameters *dma_parms;
+
        struct list_head        dma_pools;      /* dma pools (if dma'ble) */
 
        struct dma_coherent_mem *dma_mem; /* internal for coherent mem
@@ -534,11 +545,17 @@ extern struct device *device_create(struct class *cls, struct device *parent,
 extern void device_destroy(struct class *cls, dev_t devt);
 #ifdef CONFIG_PM_SLEEP
 extern void destroy_suspended_device(struct class *cls, dev_t devt);
+extern void device_pm_schedule_removal(struct device *);
 #else /* !CONFIG_PM_SLEEP */
 static inline void destroy_suspended_device(struct class *cls, dev_t devt)
 {
        device_destroy(cls, devt);
 }
+
+static inline void device_pm_schedule_removal(struct device *dev)
+{
+       device_unregister(dev);
+}
 #endif /* !CONFIG_PM_SLEEP */
 
 /*
index 101a2d4636befbd1248b7642c38a87ff77243f07..3320307096237a61495d785d751e897bc54a0102 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _ASM_LINUX_DMA_MAPPING_H
-#define _ASM_LINUX_DMA_MAPPING_H
+#ifndef _LINUX_DMA_MAPPING_H
+#define _LINUX_DMA_MAPPING_H
 
 #include <linux/device.h>
 #include <linux/err.h>
@@ -60,6 +60,36 @@ static inline int is_device_dma_capable(struct device *dev)
 
 extern u64 dma_get_required_mask(struct device *dev);
 
+static inline unsigned int dma_get_max_seg_size(struct device *dev)
+{
+       return dev->dma_parms ? dev->dma_parms->max_segment_size : 65536;
+}
+
+static inline unsigned int dma_set_max_seg_size(struct device *dev,
+                                               unsigned int size)
+{
+       if (dev->dma_parms) {
+               dev->dma_parms->max_segment_size = size;
+               return 0;
+       } else
+               return -EIO;
+}
+
+static inline unsigned long dma_get_seg_boundary(struct device *dev)
+{
+       return dev->dma_parms ?
+               dev->dma_parms->segment_boundary_mask : 0xffffffff;
+}
+
+static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
+{
+       if (dev->dma_parms) {
+               dev->dma_parms->segment_boundary_mask = mask;
+               return 0;
+       } else
+               return -EIO;
+}
+
 /* flags for the coherent memory api */
 #define        DMA_MEMORY_MAP                  0x01
 #define DMA_MEMORY_IO                  0x02
index 55c9a6952f447c6284a5b75b88ac9696ddc89214..acbb364674ff1f8516f50747d0d48375f15df49a 100644 (file)
@@ -29,7 +29,7 @@
 #include <linux/dma-mapping.h>
 
 /**
- * enum dma_state - resource PNP/power managment state
+ * enum dma_state - resource PNP/power management state
  * @DMA_RESOURCE_SUSPEND: DMA device going into low power state
  * @DMA_RESOURCE_RESUME: DMA device returning to full power
  * @DMA_RESOURCE_AVAILABLE: DMA device available to the system
@@ -94,6 +94,15 @@ enum dma_transaction_type {
 /* last transaction type for creation of the capabilities mask */
 #define DMA_TX_TYPE_END (DMA_INTERRUPT + 1)
 
+/**
+ * enum dma_prep_flags - DMA flags to augment operation preparation
+ * @DMA_PREP_INTERRUPT - trigger an interrupt (callback) upon completion of
+ *     this transaction
+ */
+enum dma_prep_flags {
+       DMA_PREP_INTERRUPT = (1 << 0),
+};
+
 /**
  * dma_cap_mask_t - capabilities bitmap modeled after cpumask_t.
  * See linux/cpumask.h
@@ -209,8 +218,6 @@ typedef void (*dma_async_tx_callback)(void *dma_async_param);
  *     descriptors
  * @chan: target channel for this operation
  * @tx_submit: set the prepared descriptor(s) to be executed by the engine
- * @tx_set_dest: set a destination address in a hardware descriptor
- * @tx_set_src: set a source address in a hardware descriptor
  * @callback: routine to call after this operation is complete
  * @callback_param: general parameter to pass to the callback routine
  * ---async_tx api specific fields---
@@ -227,10 +234,6 @@ struct dma_async_tx_descriptor {
        struct list_head tx_list;
        struct dma_chan *chan;
        dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx);
-       void (*tx_set_dest)(dma_addr_t addr,
-               struct dma_async_tx_descriptor *tx, int index);
-       void (*tx_set_src)(dma_addr_t addr,
-               struct dma_async_tx_descriptor *tx, int index);
        dma_async_tx_callback callback;
        void *callback_param;
        struct list_head depend_list;
@@ -279,15 +282,17 @@ struct dma_device {
        void (*device_free_chan_resources)(struct dma_chan *chan);
 
        struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)(
-               struct dma_chan *chan, size_t len, int int_en);
+               struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
+               size_t len, unsigned long flags);
        struct dma_async_tx_descriptor *(*device_prep_dma_xor)(
-               struct dma_chan *chan, unsigned int src_cnt, size_t len,
-               int int_en);
+               struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
+               unsigned int src_cnt, size_t len, unsigned long flags);
        struct dma_async_tx_descriptor *(*device_prep_dma_zero_sum)(
-               struct dma_chan *chan, unsigned int src_cnt, size_t len,
-               u32 *result, int int_en);
+               struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt,
+               size_t len, u32 *result, unsigned long flags);
        struct dma_async_tx_descriptor *(*device_prep_dma_memset)(
-               struct dma_chan *chan, int value, size_t len, int int_en);
+               struct dma_chan *chan, dma_addr_t dest, int value, size_t len,
+               unsigned long flags);
        struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)(
                struct dma_chan *chan);
 
index 71d4ada6f31549342d75dbc50dd10045c43e3e17..fcbe8b640ffba57f04a35c986728bf850717bb6c 100644 (file)
@@ -309,7 +309,7 @@ int ethtool_op_set_flags(struct net_device *dev, u32 data);
  * get_ringparam: Report ring sizes
  * set_ringparam: Set ring sizes
  * get_pauseparam: Report pause parameters
- * set_pauseparam: Set pause paramters
+ * set_pauseparam: Set pause parameters
  * get_rx_csum: Report whether receive checksums are turned on or off
  * set_rx_csum: Turn receive checksum on or off
  * get_tx_csum: Report whether transmit checksums are turned on or off
index a516b6716870d01f2238929a463e83e698a396ac..109734bf6377cb3e8392a51ae597df12025cb8be 100644 (file)
@@ -21,7 +21,7 @@
 
 /* Fixed constants first: */
 #undef NR_OPEN
-#define NR_OPEN (1024*1024)    /* Absolute upper limit on fd num */
+extern int sysctl_nr_open;
 #define INR_OPEN 1024          /* Initial setting for nfile rlimits */
 
 #define BLOCK_SIZE_BITS 10
@@ -872,6 +872,7 @@ struct file_lock {
        struct list_head fl_block;      /* circular list of blocked processes */
        fl_owner_t fl_owner;
        unsigned int fl_pid;
+       struct pid *fl_nspid;
        wait_queue_head_t fl_wait;
        struct file *fl_file;
        unsigned char fl_flags;
@@ -976,7 +977,6 @@ extern int send_sigurg(struct fown_struct *fown);
 extern struct list_head super_blocks;
 extern spinlock_t sb_lock;
 
-#define sb_entry(list) list_entry((list), struct super_block, s_list)
 #define S_BIAS (1<<30)
 struct super_block {
        struct list_head        s_list;         /* Keep this first */
@@ -1278,8 +1278,10 @@ struct super_operations {
  *
  * Two bits are used for locking and completion notification, I_LOCK and I_SYNC.
  *
- * I_DIRTY_SYNC                Inode itself is dirty.
- * I_DIRTY_DATASYNC    Data-related inode changes pending
+ * I_DIRTY_SYNC                Inode is dirty, but doesn't have to be written on
+ *                     fdatasync().  i_atime is the usual cause.
+ * I_DIRTY_DATASYNC    Inode is dirty and must be written on fdatasync(), f.e.
+ *                     because i_size changed.
  * I_DIRTY_PAGES       Inode has dirty pages.  Inode itself may be clean.
  * I_NEW               get_new_inode() sets i_state to I_LOCK|I_NEW.  Both
  *                     are cleared by unlock_new_inode(), called from iget().
@@ -1307,12 +1309,10 @@ struct super_operations {
  *                     being set.  find_inode() uses this to prevent returning
  *                     nearly-dead inodes.
  * I_SYNC              Similar to I_LOCK, but limited in scope to writeback
- *                     of inode dirty data.  Having a seperate lock for this
+ *                     of inode dirty data.  Having a separate lock for this
  *                     purpose reduces latency and prevents some filesystem-
  *                     specific deadlocks.
  *
- * Q: Why does I_DIRTY_DATASYNC exist?  It appears as if it could be replaced
- *    by (I_DIRTY_SYNC|I_DIRTY_PAGES).
  * Q: What is the difference between I_WILL_FREE and I_FREEING?
  * Q: igrab() only checks on (I_FREEING|I_WILL_FREE).  Should it also check on
  *    I_CLEAR?  If not, why?
@@ -2112,6 +2112,7 @@ struct ctl_table;
 int proc_nr_files(struct ctl_table *table, int write, struct file *filp,
                  void __user *buffer, size_t *lenp, loff_t *ppos);
 
+int get_filesystem_list(char * buf);
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_FS_H */
index 2bd31fa623b6a7b12c3aa8ac9369cc698b0746d2..d4b7c4ac72e6dd70e9bbda61158b36847e83bb2a 100644 (file)
@@ -91,6 +91,14 @@ static inline void fsnotify_inoderemove(struct inode *inode)
        inotify_inode_is_dead(inode);
 }
 
+/*
+ * fsnotify_link_count - inode's link count changed
+ */
+static inline void fsnotify_link_count(struct inode *inode)
+{
+       inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
+}
+
 /*
  * fsnotify_create - 'name' was linked in
  */
@@ -102,6 +110,20 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
        audit_inode_child(dentry->d_name.name, dentry, inode);
 }
 
+/*
+ * fsnotify_link - new hardlink in 'inode' directory
+ * Note: We have to pass also the linked inode ptr as some filesystems leave
+ *   new_dentry->d_inode NULL and instantiate inode pointer later
+ */
+static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
+{
+       inode_dir_notify(dir, DN_CREATE);
+       inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name,
+                                 inode);
+       fsnotify_link_count(inode);
+       audit_inode_child(new_dentry->d_name.name, new_dentry, dir);
+}
+
 /*
  * fsnotify_mkdir - directory 'name' was created
  */
index 7e93a9ae7064c3a59b0223763964181500f6d3cf..0c6ce515185d24f32476a1b4ebec353be36419bd 100644 (file)
@@ -228,5 +228,7 @@ extern void FASTCALL(free_cold_page(struct page *page));
 
 void page_alloc_init(void);
 void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp);
+void drain_all_pages(void);
+void drain_local_pages(void *dummy);
 
 #endif /* __LINUX_GFP_H */
index acf17bb8e7f963b1ea5400a17d24819f319a8062..06d25c189cc5679d0933747efa4a00b9758a4dca 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef _LINUX_HASH_H
 #define _LINUX_HASH_H
-/* Fast hashing routine for a long.
+/* Fast hashing routine for ints,  longs and pointers.
    (C) 2002 William Lee Irwin III, IBM */
 
 /*
  * them can use shifts and additions instead of multiplications for
  * machines where multiplications are slow.
  */
-#if BITS_PER_LONG == 32
+
+#include <asm/types.h>
+
 /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
-#define GOLDEN_RATIO_PRIME 0x9e370001UL
-#elif BITS_PER_LONG == 64
+#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
 /*  2^63 + 2^61 - 2^57 + 2^54 - 2^51 - 2^18 + 1 */
-#define GOLDEN_RATIO_PRIME 0x9e37fffffffc0001UL
+#define GOLDEN_RATIO_PRIME_64 0x9e37fffffffc0001UL
+
+#if BITS_PER_LONG == 32
+#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_PRIME_32
+#define hash_long(val, bits) hash_32(val, bits)
+#elif BITS_PER_LONG == 64
+#define hash_long(val, bits) hash_64(val, bits)
+#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_PRIME_64
 #else
-#error Define GOLDEN_RATIO_PRIME for your wordsize.
+#error Wordsize not 32 or 64
 #endif
 
-static inline unsigned long hash_long(unsigned long val, unsigned int bits)
+static inline u64 hash_64(u64 val, unsigned int bits)
 {
-       unsigned long hash = val;
+       u64 hash = val;
 
-#if BITS_PER_LONG == 64
        /*  Sigh, gcc can't optimise this alone like it does for 32 bits. */
-       unsigned long n = hash;
+       u64 n = hash;
        n <<= 18;
        hash -= n;
        n <<= 33;
@@ -42,15 +49,20 @@ static inline unsigned long hash_long(unsigned long val, unsigned int bits)
        hash += n;
        n <<= 2;
        hash += n;
-#else
+
+       /* High bits are more random, so use them. */
+       return hash >> (64 - bits);
+}
+
+static inline u32 hash_32(u32 val, unsigned int bits)
+{
        /* On some cpus multiply is faster, on others gcc will do shifts */
-       hash *= GOLDEN_RATIO_PRIME;
-#endif
+       u32 hash = val * GOLDEN_RATIO_PRIME_32;
 
        /* High bits are more random, so use them. */
-       return hash >> (BITS_PER_LONG - bits);
+       return hash >> (32 - bits);
 }
-       
+
 static inline unsigned long hash_ptr(void *ptr, unsigned int bits)
 {
        return hash_long((unsigned long)ptr, bits);
index db390c511ada863ce1173b267c066b99509a39a5..6115545a5b9cd307819c85c1475e99687097bd84 100644 (file)
 #include <linux/netdevice.h>
 #include <linux/hdlc/ioctl.h>
 
-
-/* Used by all network devices here, pointed to by netdev_priv(dev) */
-struct hdlc_device_desc {
-       int (*netif_rx)(struct sk_buff *skb);
-       struct net_device_stats stats;
-};
-
 /* This structure is a private property of HDLC protocols.
    Hardware drivers have no interest here */
 
@@ -44,12 +37,15 @@ struct hdlc_proto {
        void (*detach)(struct net_device *dev);
        int (*ioctl)(struct net_device *dev, struct ifreq *ifr);
        __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
+       int (*netif_rx)(struct sk_buff *skb);
        struct module *module;
        struct hdlc_proto *next; /* next protocol in the list */
 };
 
 
+/* Pointed to by dev->priv */
 typedef struct hdlc_device {
+       struct net_device_stats stats;
        /* used by HDLC layer to take control over HDLC device from hw driver*/
        int (*attach)(struct net_device *dev,
                      unsigned short encoding, unsigned short parity);
@@ -83,18 +79,11 @@ void unregister_hdlc_protocol(struct hdlc_proto *proto);
 
 struct net_device *alloc_hdlcdev(void *priv);
 
-
-static __inline__ struct hdlc_device_desc* dev_to_desc(struct net_device *dev)
-{
-       return netdev_priv(dev);
-}
-
-static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev)
+static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
 {
-       return netdev_priv(dev) + sizeof(struct hdlc_device_desc);
+       return dev->priv;
 }
 
-
 static __inline__ void debug_frame(const struct sk_buff *skb)
 {
        int i;
@@ -116,13 +105,13 @@ int hdlc_open(struct net_device *dev);
 void hdlc_close(struct net_device *dev);
 
 int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
-                        int (*rx)(struct sk_buff *skb), size_t size);
+                        size_t size);
 /* May be used by hardware driver to gain control over HDLC device */
 void detach_hdlc_protocol(struct net_device *dev);
 
 static __inline__ struct net_device_stats *hdlc_stats(struct net_device *dev)
 {
-       return &dev_to_desc(dev)->stats;
+       return &dev_to_hdlc(dev)->stats;
 }
 
 
index ff43f8d6b5b330379ef301dc8276088a1d59de20..e38e75967e74d765b518c4098cf61ee38e890d22 100644 (file)
@@ -364,7 +364,7 @@ typedef struct hd_drive_hob_hdr {
 #define SETFEATURES_EN_RLA     0xAA    /* Enable read look-ahead feature */
 #define SETFEATURES_PREFETCH   0xAB    /* Sets drive prefetch value */
 #define SETFEATURES_EN_REST    0xAC    /* ATA-1 */
-#define SETFEATURES_4B_RW_LONG 0xBB    /* Set Lenght of 4 bytes */
+#define SETFEATURES_4B_RW_LONG 0xBB    /* Set Length of 4 bytes */
 #define SETFEATURES_DIS_AAM    0xC2    /* Disable Automatic Acoustic Management */
 #define SETFEATURES_EN_RPOD    0xCC    /* Enable reverting to power on defaults */
 #define SETFEATURES_DIS_RI     0xDD    /* Disable release interrupt ATAPI */
@@ -706,8 +706,10 @@ struct hd_driveid {
  */
 #define IDE_NICE_DSC_OVERLAP   (0)     /* per the DSC overlap protocol */
 #define IDE_NICE_ATAPI_OVERLAP (1)     /* not supported yet */
-#define IDE_NICE_0             (2)     /* when sure that it won't affect us */
 #define IDE_NICE_1             (3)     /* when probably won't affect us much */
+#ifndef __KERNEL__
+#define IDE_NICE_0             (2)     /* when sure that it won't affect us */
 #define IDE_NICE_2             (4)     /* when we know it's on our expense */
+#endif
 
 #endif /* _LINUX_HDREG_H */
index 1fcb0033179ec4e68442a5cc389c8f93a6bcd528..7dcbc82f3b7bf4a19969d0cf19824cf373a2a91b 100644 (file)
@@ -68,8 +68,6 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
        void *addr = kmap_atomic(page, KM_USER0);
        clear_user_page(addr, vaddr, page);
        kunmap_atomic(addr, KM_USER0);
-       /* Make sure this page is cleared on other CPU's too before using it */
-       smp_wmb();
 }
 
 #ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
@@ -124,28 +122,40 @@ static inline void clear_highpage(struct page *page)
        kunmap_atomic(kaddr, KM_USER0);
 }
 
-/*
- * Same but also flushes aliased cache contents to RAM.
- *
- * This must be a macro because KM_USER0 and friends aren't defined if
- * !CONFIG_HIGHMEM
- */
-#define zero_user_page(page, offset, size, km_type)            \
-       do {                                                    \
-               void *kaddr;                                    \
-                                                               \
-               BUG_ON((offset) + (size) > PAGE_SIZE);          \
-                                                               \
-               kaddr = kmap_atomic(page, km_type);             \
-               memset((char *)kaddr + (offset), 0, (size));    \
-               flush_dcache_page(page);                        \
-               kunmap_atomic(kaddr, (km_type));                \
-       } while (0)
+static inline void zero_user_segments(struct page *page,
+       unsigned start1, unsigned end1,
+       unsigned start2, unsigned end2)
+{
+       void *kaddr = kmap_atomic(page, KM_USER0);
+
+       BUG_ON(end1 > PAGE_SIZE || end2 > PAGE_SIZE);
+
+       if (end1 > start1)
+               memset(kaddr + start1, 0, end1 - start1);
+
+       if (end2 > start2)
+               memset(kaddr + start2, 0, end2 - start2);
+
+       kunmap_atomic(kaddr, KM_USER0);
+       flush_dcache_page(page);
+}
+
+static inline void zero_user_segment(struct page *page,
+       unsigned start, unsigned end)
+{
+       zero_user_segments(page, start, end, 0, 0);
+}
+
+static inline void zero_user(struct page *page,
+       unsigned start, unsigned size)
+{
+       zero_user_segments(page, start, start + size, 0, 0);
+}
 
 static inline void __deprecated memclear_highpage_flush(struct page *page,
                        unsigned int offset, unsigned int size)
 {
-       zero_user_page(page, offset, size, KM_USER0);
+       zero_user(page, offset, size);
 }
 
 #ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE
@@ -160,8 +170,6 @@ static inline void copy_user_highpage(struct page *to, struct page *from,
        copy_user_page(vto, vfrom, vaddr, to);
        kunmap_atomic(vfrom, KM_USER0);
        kunmap_atomic(vto, KM_USER1);
-       /* Make sure this page is cleared on other CPU's too before using it */
-       smp_wmb();
 }
 
 #endif
index 49067f14fac190ea7bb492fceb1befdcf46aadce..8371b664b41f44314dbc5a6a2fae4e2d0953414c 100644 (file)
@@ -147,7 +147,6 @@ struct hrtimer_sleeper {
  * @get_time:          function to retrieve the current time of the clock
  * @get_softirq_time:  function to retrieve the current time from the softirq
  * @softirq_time:      the time when running the hrtimer queue in the softirq
- * @cb_pending:                list of timers where the callback is pending
  * @offset:            offset of this clock to the monotonic base
  * @reprogram:         function to reprogram the timer event
  */
@@ -302,9 +301,16 @@ static inline int hrtimer_is_queued(struct hrtimer *timer)
 }
 
 /* Forward a hrtimer so it expires after now: */
-extern unsigned long
+extern u64
 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
 
+/* Forward a hrtimer so it expires after the hrtimer's current now */
+static inline u64 hrtimer_forward_now(struct hrtimer *timer,
+                                     ktime_t interval)
+{
+       return hrtimer_forward(timer, timer->base->get_time(), interval);
+}
+
 /* Precise sleep: */
 extern long hrtimer_nanosleep(struct timespec *rqtp,
                              struct timespec *rmtp,
@@ -323,9 +329,9 @@ extern void hrtimer_run_pending(void);
 extern void __init hrtimers_init(void);
 
 #if BITS_PER_LONG < 64
-extern unsigned long ktime_divns(const ktime_t kt, s64 div);
+extern u64 ktime_divns(const ktime_t kt, s64 div);
 #else /* BITS_PER_LONG < 64 */
-# define ktime_divns(kt, div)          (unsigned long)((kt).tv64 / (div))
+# define ktime_divns(kt, div)          (u64)((kt).tv64 / (div))
 #endif
 
 /* Show pending timers: */
index 85d11916e9ea48a878f54eb3aff5045a8ec2b2c7..42131820bb892e368aafa15fa557b71274e593f4 100644 (file)
@@ -44,7 +44,15 @@ struct hwrng {
 /** Register a new Hardware Random Number Generator driver. */
 extern int hwrng_register(struct hwrng *rng);
 /** Unregister a Hardware Random Number Generator driver. */
-extern void hwrng_unregister(struct hwrng *rng);
+extern void __hwrng_unregister(struct hwrng *rng, bool suspended);
+static inline void hwrng_unregister(struct hwrng *rng)
+{
+       __hwrng_unregister(rng, false);
+}
+static inline void hwrng_unregister_suspended(struct hwrng *rng)
+{
+       __hwrng_unregister(rng, true);
+}
 
 #endif /* __KERNEL__ */
 #endif /* LINUX_HWRANDOM_H_ */
diff --git a/include/linux/i2c/pca953x.h b/include/linux/i2c/pca953x.h
new file mode 100644 (file)
index 0000000..3c73612
--- /dev/null
@@ -0,0 +1,18 @@
+/* platform data for the PCA9539 16-bit I/O expander driver */
+
+struct pca953x_platform_data {
+       /* number of the first GPIO */
+       unsigned        gpio_base;
+
+       /* initial polarity inversion setting */
+       uint16_t        invert;
+
+       void            *context;       /* param to setup/teardown */
+
+       int             (*setup)(struct i2c_client *client,
+                               unsigned gpio, unsigned ngpio,
+                               void *context);
+       int             (*teardown)(struct i2c_client *client,
+                               unsigned gpio, unsigned ngpio,
+                               void *context);
+};
diff --git a/include/linux/i2c/pcf857x.h b/include/linux/i2c/pcf857x.h
new file mode 100644 (file)
index 0000000..ba8ea6e
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef __LINUX_PCF857X_H
+#define __LINUX_PCF857X_H
+
+/**
+ * struct pcf857x_platform_data - data to set up pcf857x driver
+ * @gpio_base: number of the chip's first GPIO
+ * @n_latch: optional bit-inverse of initial register value; if
+ *     you leave this initialized to zero the driver will act
+ *     like the chip was just reset
+ * @setup: optional callback issued once the GPIOs are valid
+ * @teardown: optional callback issued before the GPIOs are invalidated
+ * @context: optional parameter passed to setup() and teardown()
+ *
+ * In addition to the I2C_BOARD_INFO() state appropriate to each chip,
+ * the i2c_board_info used with the pcf875x driver must provide the
+ * chip "type" ("pcf8574", "pcf8574a", "pcf8575", "pcf8575c") and its
+ * platform_data (pointer to one of these structures) with at least
+ * the gpio_base value initialized.
+ *
+ * The @setup callback may be used with the kind of board-specific glue
+ * which hands the (now-valid) GPIOs to other drivers, or which puts
+ * devices in their initial states using these GPIOs.
+ *
+ * These GPIO chips are only "quasi-bidirectional"; read the chip specs
+ * to understand the behavior.  They don't have separate registers to
+ * record which pins are used for input or output, record which output
+ * values are driven, or provide access to input values.  That must be
+ * inferred by reading the chip's value and knowing the last value written
+ * to it.  If you leave n_latch initialized to zero, that last written
+ * value is presumed to be all ones (as if the chip were just reset).
+ */
+struct pcf857x_platform_data {
+       unsigned        gpio_base;
+       unsigned        n_latch;
+
+       int             (*setup)(struct i2c_client *client,
+                                       int gpio, unsigned ngpio,
+                                       void *context);
+       int             (*teardown)(struct i2c_client *client,
+                                       int gpio, unsigned ngpio,
+                                       void *context);
+       void            *context;
+};
+
+#endif /* __LINUX_PCF857X_H */
index ec10b2a3bb6ec15e43dae0989062a27838278e0f..acec99da832dc475a44aa1e18696f84e1dae1f53 100644 (file)
@@ -112,18 +112,8 @@ typedef unsigned char      byte;   /* used everywhere */
 #define SATA_NR_PORTS          (3)     /* 16 possible ?? */
 
 #define SATA_STATUS_OFFSET     (0)
-#define SATA_STATUS_REG                (HWIF(drive)->sata_scr[SATA_STATUS_OFFSET])
 #define SATA_ERROR_OFFSET      (1)
-#define SATA_ERROR_REG         (HWIF(drive)->sata_scr[SATA_ERROR_OFFSET])
 #define SATA_CONTROL_OFFSET    (2)
-#define SATA_CONTROL_REG       (HWIF(drive)->sata_scr[SATA_CONTROL_OFFSET])
-
-#define SATA_MISC_OFFSET       (0)
-#define SATA_MISC_REG          (HWIF(drive)->sata_misc[SATA_MISC_OFFSET])
-#define SATA_PHY_OFFSET                (1)
-#define SATA_PHY_REG           (HWIF(drive)->sata_misc[SATA_PHY_OFFSET])
-#define SATA_IEN_OFFSET                (2)
-#define SATA_IEN_REG           (HWIF(drive)->sata_misc[SATA_IEN_OFFSET])
 
 /*
  * Our Physical Region Descriptor (PRD) table should be large enough
@@ -179,7 +169,7 @@ enum {              ide_unknown,    ide_generic,    ide_pci,
                ide_rz1000,     ide_trm290,
                ide_cmd646,     ide_cy82c693,   ide_4drives,
                ide_pmac,       ide_etrax100,   ide_acorn,
-               ide_au1xxx, ide_forced
+               ide_au1xxx,     ide_palm3710,   ide_forced
 };
 
 typedef u8 hwif_chipset_t;
@@ -196,6 +186,7 @@ typedef struct hw_regs_s {
 } hw_regs_t;
 
 struct hwif_s * ide_find_port(unsigned long);
+struct hwif_s *ide_deprecated_find_port(unsigned long);
 void ide_init_port_data(struct hwif_s *, unsigned int);
 void ide_init_port_hw(struct hwif_s *, hw_regs_t *);
 
@@ -203,17 +194,6 @@ struct ide_drive_s;
 int ide_register_hw(hw_regs_t *, void (*)(struct ide_drive_s *),
                    struct hwif_s **);
 
-void ide_setup_ports(  hw_regs_t *hw,
-                       unsigned long base,
-                       int *offsets,
-                       unsigned long ctrl,
-                       unsigned long intr,
-                       ide_ack_intr_t *ack_intr,
-#if 0
-                       ide_io_ops_t *iops,
-#endif
-                       int irq);
-
 static inline void ide_std_init_ports(hw_regs_t *hw,
                                      unsigned long io_addr,
                                      unsigned long ctl_addr)
@@ -406,8 +386,6 @@ typedef struct ide_drive_s {
        unsigned no_unmask      : 1;    /* disallow setting unmask bit */
        unsigned no_io_32bit    : 1;    /* disallow enabling 32bit I/O */
        unsigned atapi_overlap  : 1;    /* ATAPI overlap (not supported) */
-       unsigned nice0          : 1;    /* give obvious excess bandwidth */
-       unsigned nice2          : 1;    /* give a share in our own bandwidth */
        unsigned doorlocking    : 1;    /* for removable only: door lock/unlock works */
        unsigned nodma          : 1;    /* disallow DMA */
        unsigned autotune       : 2;    /* 0=default, 1=autotune, 2=noautotune */
@@ -480,14 +458,12 @@ typedef struct hwif_s {
                /* task file registers for pata and sata */
        unsigned long   io_ports[IDE_NR_PORTS];
        unsigned long   sata_scr[SATA_NR_PORTS];
-       unsigned long   sata_misc[SATA_NR_PORTS];
 
        ide_drive_t     drives[MAX_DRIVES];     /* drive info */
 
        u8 major;       /* our major number */
        u8 index;       /* 0 for ide0; 1 for ide1; ... */
        u8 channel;     /* for dual-port chips: 0=primary, 1=secondary */
-       u8 straight8;   /* Alan's straight 8 check */
        u8 bus_state;   /* power state of the IDE bus */
 
        u32 host_flags;
@@ -513,6 +489,8 @@ typedef struct hwif_s {
 #if 0
        ide_hwif_ops_t  *hwifops;
 #else
+       /* host specific initialization of devices on a port */
+       void    (*port_init_devs)(struct hwif_s *);
        /* routine to program host for PIO mode */
        void    (*set_pio_mode)(ide_drive_t *, const u8);
        /* routine to program host for DMA mode */
@@ -535,6 +513,8 @@ typedef struct hwif_s {
        u8 (*mdma_filter)(ide_drive_t *);
        u8 (*udma_filter)(ide_drive_t *);
 
+       u8 (*cable_detect)(struct hwif_s *);
+
        void (*ata_input_data)(ide_drive_t *, void *, u32);
        void (*ata_output_data)(ide_drive_t *, void *, u32);
 
@@ -602,10 +582,9 @@ typedef struct hwif_s {
        unsigned        serialized : 1; /* serialized all channel operation */
        unsigned        sharing_irq: 1; /* 1 = sharing irq with another hwif */
        unsigned        reset      : 1; /* reset after probe */
-       unsigned        auto_poll  : 1; /* supports nop auto-poll */
        unsigned        sg_mapped  : 1; /* sg_table and sg_nents are ready */
-       unsigned        no_io_32bit : 1; /* 1 = can not do 32-bit IO ops */
        unsigned        mmio       : 1; /* host uses MMIO */
+       unsigned        straight8  : 1; /* Alan's straight 8 check */
 
        struct device   gendev;
        struct completion gendev_rel_comp; /* To deal with device release() */
@@ -625,6 +604,9 @@ typedef struct hwif_s {
 typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
 typedef int (ide_expiry_t)(ide_drive_t *);
 
+/* used by ide-cd, ide-floppy, etc. */
+typedef void (xfer_func_t)(ide_drive_t *, void *, u32);
+
 typedef struct hwgroup_s {
                /* irq handler, if active */
        ide_startstop_t (*handler)(ide_drive_t *);
@@ -708,6 +690,7 @@ typedef struct {
 void proc_ide_create(void);
 void proc_ide_destroy(void);
 void ide_proc_register_port(ide_hwif_t *);
+void ide_proc_port_register_devices(ide_hwif_t *);
 void ide_proc_unregister_port(ide_hwif_t *);
 void ide_proc_register_driver(ide_drive_t *, ide_driver_t *);
 void ide_proc_unregister_driver(ide_drive_t *, ide_driver_t *);
@@ -740,6 +723,7 @@ void ide_pci_create_host_proc(const char *, get_info_t *);
 static inline void proc_ide_create(void) { ; }
 static inline void proc_ide_destroy(void) { ; }
 static inline void ide_proc_register_port(ide_hwif_t *hwif) { ; }
+static inline void ide_proc_port_register_devices(ide_hwif_t *hwif) { ; }
 static inline void ide_proc_unregister_port(ide_hwif_t *hwif) { ; }
 static inline void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver) { ; }
 static inline void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver) { ; }
@@ -988,10 +972,8 @@ int ide_task_ioctl(ide_drive_t *, unsigned int, unsigned long);
 extern int system_bus_clock(void);
 
 extern int ide_driveid_update(ide_drive_t *);
-extern int ide_ata66_check(ide_drive_t *, ide_task_t *);
 extern int ide_config_drive_speed(ide_drive_t *, u8);
 extern u8 eighty_ninty_three (ide_drive_t *);
-extern int set_transfer(ide_drive_t *, ide_task_t *);
 extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *);
 
 extern int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout);
@@ -1016,6 +998,14 @@ extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *o
 void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *, int, u8 *);
 void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *);
 
+/* FIXME: palm_bk3710 uses BLK_DEV_IDEDMA_PCI without BLK_DEV_IDEPCI! */
+#if defined(CONFIG_BLK_DEV_IDEPCI) && defined(CONFIG_BLK_DEV_IDEDMA_PCI)
+void ide_hwif_setup_dma(ide_hwif_t *, const struct ide_port_info *);
+#else
+static inline void ide_hwif_setup_dma(ide_hwif_t *hwif,
+                                     const struct ide_port_info *d) { }
+#endif
+
 extern void default_hwif_iops(ide_hwif_t *);
 extern void default_hwif_mmiops(ide_hwif_t *);
 extern void default_hwif_transport(ide_hwif_t *);
@@ -1052,7 +1042,7 @@ enum {
        IDE_HFLAG_NO_SET_MODE           = (1 << 9),
        /* trust BIOS for programming chipset/device for DMA */
        IDE_HFLAG_TRUST_BIOS_FOR_DMA    = (1 << 10),
-       /* host uses VDMA */
+       /* host uses VDMA (tied with IDE_HFLAG_CS5520 for now) */
        IDE_HFLAG_VDMA                  = (1 << 11),
        /* ATAPI DMA is unsupported */
        IDE_HFLAG_NO_ATAPI_DMA          = (1 << 12),
@@ -1062,8 +1052,10 @@ enum {
        IDE_HFLAG_NO_DMA                = (1 << 14),
        /* check if host is PCI IDE device before allowing DMA */
        IDE_HFLAG_NO_AUTODMA            = (1 << 15),
+       /* don't autotune PIO */
+       IDE_HFLAG_NO_AUTOTUNE           = (1 << 16),
        /* host is CS5510/CS5520 */
-       IDE_HFLAG_CS5520                = (1 << 16),
+       IDE_HFLAG_CS5520                = IDE_HFLAG_VDMA,
        /* no LBA48 */
        IDE_HFLAG_NO_LBA48              = (1 << 17),
        /* no LBA48 DMA */
@@ -1089,6 +1081,10 @@ enum {
        IDE_HFLAG_CLEAR_SIMPLEX         = (1 << 28),
        /* DSC overlap is unsupported */
        IDE_HFLAG_NO_DSC                = (1 << 29),
+       /* never use 32-bit I/O ops */
+       IDE_HFLAG_NO_IO_32BIT           = (1 << 30),
+       /* never unmask IRQs */
+       IDE_HFLAG_NO_UNMASK_IRQS        = (1 << 31),
 };
 
 #ifdef CONFIG_BLK_DEV_OFFBOARD
@@ -1144,6 +1140,7 @@ void ide_dma_off_quietly(ide_drive_t *);
 void ide_dma_off(ide_drive_t *);
 void ide_dma_on(ide_drive_t *);
 int ide_set_dma(ide_drive_t *);
+void ide_check_dma_crc(ide_drive_t *);
 ide_startstop_t ide_dma_intr(ide_drive_t *);
 
 int ide_build_sglist(ide_drive_t *, struct request *);
@@ -1171,6 +1168,7 @@ static inline void ide_dma_off(ide_drive_t *drive) { ; }
 static inline void ide_dma_on(ide_drive_t *drive) { ; }
 static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
 static inline int ide_set_dma(ide_drive_t *drive) { return 1; }
+static inline void ide_check_dma_crc(ide_drive_t *drive) { ; }
 #endif /* CONFIG_BLK_DEV_IDEDMA */
 
 #ifndef CONFIG_BLK_DEV_IDEDMA_PCI
@@ -1182,27 +1180,29 @@ extern int ide_acpi_exec_tfs(ide_drive_t *drive);
 extern void ide_acpi_get_timing(ide_hwif_t *hwif);
 extern void ide_acpi_push_timing(ide_hwif_t *hwif);
 extern void ide_acpi_init(ide_hwif_t *hwif);
+void ide_acpi_port_init_devices(ide_hwif_t *);
 extern void ide_acpi_set_state(ide_hwif_t *hwif, int on);
 #else
 static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; }
 static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; }
 static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; }
 static inline void ide_acpi_init(ide_hwif_t *hwif) { ; }
+static inline void ide_acpi_port_init_devices(ide_hwif_t *hwif) { ; }
 static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {}
 #endif
 
 void ide_remove_port_from_hwgroup(ide_hwif_t *);
 extern int ide_hwif_request_regions(ide_hwif_t *hwif);
 extern void ide_hwif_release_regions(ide_hwif_t* hwif);
-extern void ide_unregister (unsigned int index);
+void ide_unregister(unsigned int, int, int);
 
 void ide_register_region(struct gendisk *);
 void ide_unregister_region(struct gendisk *);
 
 void ide_undecoded_slave(ide_drive_t *);
 
-int ide_device_add_all(u8 *idx);
-int ide_device_add(u8 idx[4]);
+int ide_device_add_all(u8 *idx, const struct ide_port_info *);
+int ide_device_add(u8 idx[4], const struct ide_port_info *);
 
 static inline void *ide_get_hwifdata (ide_hwif_t * hwif)
 {
@@ -1309,4 +1309,25 @@ static inline void ide_set_irq(ide_drive_t *drive, int on)
        drive->hwif->OUTB(drive->ctl | (on ? 0 : 2), IDE_CONTROL_REG);
 }
 
+static inline u8 ide_read_status(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+
+       return hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
+}
+
+static inline u8 ide_read_altstatus(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+
+       return hwif->INB(hwif->io_ports[IDE_CONTROL_OFFSET]);
+}
+
+static inline u8 ide_read_error(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+
+       return hwif->INB(hwif->io_ports[IDE_ERROR_OFFSET]);
+}
+
 #endif /* _IDE_H */
index 5de6d911cdf7be1d8f7edf1b228fa70495e553e5..f577c8f1c66d999bda0a1338b2170058ed7c0956 100644 (file)
@@ -287,6 +287,12 @@ struct ieee80211_ht_addt_info {
 #define IEEE80211_HT_IE_NON_GF_STA_PRSNT       0x0004
 #define IEEE80211_HT_IE_NON_HT_STA_PRSNT       0x0010
 
+/* MIMO Power Save Modes */
+#define WLAN_HT_CAP_MIMO_PS_STATIC         0
+#define WLAN_HT_CAP_MIMO_PS_DYNAMIC        1
+#define WLAN_HT_CAP_MIMO_PS_INVALID        2
+#define WLAN_HT_CAP_MIMO_PS_DISABLED       3
+
 /* Authentication algorithms */
 #define WLAN_AUTH_OPEN 0
 #define WLAN_AUTH_SHARED_KEY 1
index 34f40efc7607d1801a0cb5d02407c0db9783a542..79504b22a932fc81df03f75990097bb27b8e5ad7 100644 (file)
@@ -327,7 +327,7 @@ static inline struct sk_buff *vlan_put_tag(struct sk_buff *skb, unsigned short t
  * 
  * Returns error if the skb is not of VLAN type
  */
-static inline int __vlan_get_tag(struct sk_buff *skb, unsigned short *tag)
+static inline int __vlan_get_tag(const struct sk_buff *skb, unsigned short *tag)
 {
        struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data;
 
@@ -347,7 +347,8 @@ static inline int __vlan_get_tag(struct sk_buff *skb, unsigned short *tag)
  * 
  * Returns error if @skb->cb[] is not set correctly
  */
-static inline int __vlan_hwaccel_get_tag(struct sk_buff *skb, unsigned short *tag)
+static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb,
+                                        unsigned short *tag)
 {
        struct vlan_skb_tx_cookie *cookie;
 
@@ -370,7 +371,7 @@ static inline int __vlan_hwaccel_get_tag(struct sk_buff *skb, unsigned short *ta
  * 
  * Returns error if the skb is not VLAN tagged
  */
-static inline int vlan_get_tag(struct sk_buff *skb, unsigned short *tag)
+static inline int vlan_get_tag(const struct sk_buff *skb, unsigned short *tag)
 {
        if (skb->dev->features & NETIF_F_HW_VLAN_TX) {
                return __vlan_hwaccel_get_tag(skb, tag);
index 2efbda01674186d166671dbf2455063970c52bfa..a404a0055dd7400489f5cc2ecff32c45d87f61ce 100644 (file)
 #define __FINIT                .previous
 
 #define __INITDATA     .section        ".init.data","aw"
+#define __FINITDATA    .previous
 
 #define __DEVINIT        .section      ".devinit.text", "ax"
 #define __DEVINITDATA    .section      ".devinit.data", "aw"
 #define __REF            .section       ".ref.text", "ax"
 #define __REFDATA        .section       ".ref.data", "aw"
 #define __REFCONST       .section       ".ref.rodata", "aw"
-/* backward compatibility */
-#define __INIT_REFOK     .section      __REF
-#define __INITDATA_REFOK .section      __REFDATA
 
 #ifndef __ASSEMBLY__
 /*
index f42663eaf655b697a452ed944847c505a1ad0607..1f74e1d7415fe9042e2e71467b40e4a56184ffa8 100644 (file)
@@ -121,6 +121,18 @@ extern struct group_info init_groups;
 #else
 #define INIT_IDS
 #endif
+
+#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
+/*
+ * Because of the reduced scope of CAP_SETPCAP when filesystem
+ * capabilities are in effect, it is safe to allow CAP_SETPCAP to
+ * be available in the default configuration.
+ */
+# define CAP_INIT_BSET  CAP_FULL_SET
+#else
+# define CAP_INIT_BSET  CAP_INIT_EFF_SET
+#endif
+
 /*
  *  INIT_TASK is used to set up the first task table, touch at
  * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -156,6 +168,7 @@ extern struct group_info init_groups;
        .cap_effective  = CAP_INIT_EFF_SET,                             \
        .cap_inheritable = CAP_INIT_INH_SET,                            \
        .cap_permitted  = CAP_FULL_SET,                                 \
+       .cap_bset       = CAP_INIT_BSET,                                \
        .keep_capabilities = 0,                                         \
        .user           = INIT_USER,                                    \
        .comm           = "swapper",                                    \
index c3db4a00f1fab50cbabe3002d8b7041179471ee2..dea7598aeff43c641d72ac18aa506a8fcac9ea57 100644 (file)
@@ -444,4 +444,6 @@ static inline void init_irq_proc(void)
 }
 #endif
 
+int show_interrupts(struct seq_file *p, void *v);
+
 #endif
diff --git a/include/linux/iommu-helper.h b/include/linux/iommu-helper.h
new file mode 100644 (file)
index 0000000..4dd4c04
--- /dev/null
@@ -0,0 +1,7 @@
+extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
+                                     unsigned long start, unsigned int nr,
+                                     unsigned long shift,
+                                     unsigned long boundary_size,
+                                     unsigned long align_mask);
+extern void iommu_area_free(unsigned long *map, unsigned long start,
+                           unsigned int nr);
index d0ecc8eebfbfd8d80b959407d366c6b8650c64c2..9cb2855bb170d34cd4e0b1c6b812312befb3c035 100644 (file)
@@ -507,7 +507,6 @@ typedef struct modem_info {
   struct ktermios      normal_termios;  /* For saving termios structs     */
   struct ktermios      callout_termios;
   wait_queue_head_t    open_wait, close_wait;
-  struct semaphore      write_sem;
   spinlock_t           readlock;
 } modem_info;
 
index d9ecd13393b0859ffa98034ec9cb77a3bd8f1912..b18fd3b9b8358c0fe4b6ace4b565176f0163734c 100644 (file)
@@ -33,7 +33,6 @@
 #include <linux/lockdep.h>
 
 #include <asm/semaphore.h>
-#endif
 
 #define journal_oom_retry 1
 
@@ -84,7 +83,6 @@ static inline void jbd_free(void *ptr, size_t size)
 
 #define JFS_MIN_JOURNAL_BLOCKS 1024
 
-#ifdef __KERNEL__
 
 /**
  * typedef handle_t - The handle_t type represents a single atomic update being performed by some process.
@@ -924,7 +922,6 @@ extern int     journal_recover    (journal_t *journal);
 extern int        journal_wipe       (journal_t *, int);
 extern int        journal_skip_recovery        (journal_t *);
 extern void       journal_update_superblock    (journal_t *, int);
-extern void       __journal_abort_hard (journal_t *);
 extern void       journal_abort      (journal_t *, int);
 extern int        journal_errno      (journal_t *);
 extern void       journal_ack_err    (journal_t *);
index ff356b2ee478d3dd006e67a76427a467525df7ae..18222f267bc4043f0a0ff0be1201d58938f1063a 100644 (file)
@@ -35,7 +35,7 @@ extern const char linux_proc_banner[];
 #define ALIGN(x,a)             __ALIGN_MASK(x,(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)   (((x)+(mask))&~(mask))
 #define PTR_ALIGN(p, a)                ((typeof(p))ALIGN((unsigned long)(p), (a)))
-#define IS_ALIGNED(x,a)                (((x) % ((typeof(x))(a))) == 0)
+#define IS_ALIGNED(x, a)               (((x) & ((typeof(x))(a) - 1)) == 0)
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 
index 6168c0a441724f198f1999e0f35ce88012750d59..4a6ce82ba03971f832a8f325eb150907090213bc 100644 (file)
@@ -152,8 +152,10 @@ static inline int arch_trampoline_kprobe(struct kprobe *p)
 struct kretprobe {
        struct kprobe kp;
        kretprobe_handler_t handler;
+       kretprobe_handler_t entry_handler;
        int maxactive;
        int nmissed;
+       size_t data_size;
        struct hlist_head free_instances;
        struct hlist_head used_instances;
 };
@@ -164,6 +166,7 @@ struct kretprobe_instance {
        struct kretprobe *rp;
        kprobe_opcode_t *ret_addr;
        struct task_struct *task;
+       char data[0];
 };
 
 struct kretprobe_blackpoint {
diff --git a/include/linux/latency.h b/include/linux/latency.h
deleted file mode 100644 (file)
index c08b52b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * latency.h: Explicit system-wide latency-expectation infrastructure
- *
- * (C) Copyright 2006 Intel Corporation
- * Author: Arjan van de Ven <arjan@linux.intel.com>
- *
- */
-
-#ifndef _INCLUDE_GUARD_LATENCY_H_
-#define _INCLUDE_GUARD_LATENCY_H_
-
-#include <linux/notifier.h>
-
-void set_acceptable_latency(char *identifier, int usecs);
-void modify_acceptable_latency(char *identifier, int usecs);
-void remove_acceptable_latency(char *identifier);
-void synchronize_acceptable_latency(void);
-int system_latency_constraint(void);
-
-int register_latency_notifier(struct notifier_block * nb);
-int unregister_latency_notifier(struct notifier_block * nb);
-
-#define INFINITE_LATENCY 1000000
-
-#endif
index b4130ff58d0c1be1543c21281e7189a7383834a5..00f89fd6c52a21f83d26a7b94e351e3c782854bf 100644 (file)
@@ -54,7 +54,15 @@ struct led_classdev {
 
 extern int led_classdev_register(struct device *parent,
                                 struct led_classdev *led_cdev);
-extern void led_classdev_unregister(struct led_classdev *led_cdev);
+extern void __led_classdev_unregister(struct led_classdev *led_cdev, bool sus);
+static inline void led_classdev_unregister(struct led_classdev *lcd)
+{
+       __led_classdev_unregister(lcd, false);
+}
+static inline void led_classdev_unregister_suspended(struct led_classdev *lcd)
+{
+       __led_classdev_unregister(lcd, true);
+}
 extern void led_classdev_suspend(struct led_classdev *led_cdev);
 extern void led_classdev_resume(struct led_classdev *led_cdev);
 
index 697104da91f11e159851c0698ff45dd0a1f5b618..589be3e1f3ac5a7859587ff4b662e0f6c3167314 100644 (file)
 struct lguest_device_desc {
        /* The device type: console, network, disk etc.  Type 0 terminates. */
        __u8 type;
-       /* The number of bytes of the config array. */
+       /* The number of virtqueues (first in config array) */
+       __u8 num_vq;
+       /* The number of bytes of feature bits.  Multiply by 2: one for host
+        * features and one for guest acknowledgements. */
+       __u8 feature_len;
+       /* The number of bytes of the config array after virtqueues. */
        __u8 config_len;
        /* A status byte, written by the Guest. */
        __u8 status;
@@ -31,7 +36,7 @@ struct lguest_device_desc {
 };
 
 /*D:135 This is how we expect the device configuration field for a virtqueue
- * (type VIRTIO_CONFIG_F_VIRTQUEUE) to be laid out: */
+ * to be laid out in config space. */
 struct lguest_vqconfig {
        /* The number of entries in the virtio_ring */
        __u16 num;
index 4374c427778081d0a4e13fbfd3449dd488a7c0ed..bc5a8d0c70902803fe63d4d6b3104e75bfa9c34e 100644 (file)
@@ -457,7 +457,6 @@ struct ata_queued_cmd {
        unsigned long           flags;          /* ATA_QCFLAG_xxx */
        unsigned int            tag;
        unsigned int            n_elem;
-       unsigned int            n_iter;
        unsigned int            mapped_n_elem;
 
        int                     dma_dir;
@@ -1367,7 +1366,6 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
        qc->nbytes = qc->raw_nbytes = qc->curbytes = 0;
        qc->n_elem = 0;
        qc->mapped_n_elem = 0;
-       qc->n_iter = 0;
        qc->err_mask = 0;
        qc->pad_len = 0;
        qc->last_sg = NULL;
index 09f2e6d0e9ebdb491d8a31223acd8fcfdd49e512..7733585603f12894b95120b91bd7d9178919f1a7 100644 (file)
@@ -49,9 +49,9 @@ enum llc_sockopts {
 
 /* LLC SAP types. */
 #define LLC_SAP_NULL   0x00            /* NULL SAP.                    */
-#define LLC_SAP_LLC    0x02            /* LLC Sublayer Managment.      */
+#define LLC_SAP_LLC    0x02            /* LLC Sublayer Management.     */
 #define LLC_SAP_SNA    0x04            /* SNA Path Control.            */
-#define LLC_SAP_PNM    0x0E            /* Proway Network Managment.    */      
+#define LLC_SAP_PNM    0x0E            /* Proway Network Management.   */      
 #define LLC_SAP_IP     0x06            /* TCP/IP.                      */
 #define LLC_SAP_BSPAN  0x42            /* Bridge Spanning Tree Proto   */
 #define LLC_SAP_MMS    0x4E            /* Manufacturing Message Srv.   */
index e2d1ce36b36728084d0d77538dd00b7101d1a528..4babb2a129ac946decc0478dc6690a6818e3b0e4 100644 (file)
@@ -173,14 +173,17 @@ void                nlmclnt_next_cookie(struct nlm_cookie *);
 /*
  * Host cache
  */
-struct nlm_host * nlmclnt_lookup_host(const struct sockaddr_in *, int, int, const char *, int);
-struct nlm_host * nlmsvc_lookup_host(struct svc_rqst *, const char *, int);
+struct nlm_host  *nlmclnt_lookup_host(const struct sockaddr_in *, int, int,
+                                       const char *, unsigned int);
+struct nlm_host  *nlmsvc_lookup_host(struct svc_rqst *, const char *,
+                                       unsigned int);
 struct rpc_clnt * nlm_bind_host(struct nlm_host *);
 void             nlm_rebind_host(struct nlm_host *);
 struct nlm_host * nlm_get_host(struct nlm_host *);
 void             nlm_release_host(struct nlm_host *);
 void             nlm_shutdown_hosts(void);
-extern void      nlm_host_rebooted(const struct sockaddr_in *, const char *, int, u32);
+extern void      nlm_host_rebooted(const struct sockaddr_in *, const char *,
+                                       unsigned int, u32);
 void             nsm_release(struct nsm_handle *);
 
 
index 83a1f9f6237b5f539f52cda2b6b09eeb013dd97c..df18fa053bcd7d0a1e1f9665e57efa8929dafb87 100644 (file)
@@ -29,7 +29,7 @@ struct svc_rqst;
 /* Lock info passed via NLM */
 struct nlm_lock {
        char *                  caller;
-       int                     len;    /* length of "caller" */
+       unsigned int            len;    /* length of "caller" */
        struct nfs_fh           fh;
        struct xdr_netobj       oh;
        u32                     svid;
@@ -78,7 +78,7 @@ struct nlm_res {
  */
 struct nlm_reboot {
        char *          mon;
-       int             len;
+       unsigned int    len;
        u32             state;
        __be32          addr;
        __be32          vers;
index c8cf5e8ef1717d40cde2768fd0608f29924b1545..25b808631cd92c50d10cf6a31b2d9b9942b62ac9 100644 (file)
@@ -190,4 +190,20 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
        __rounddown_pow_of_two(n)               \
  )
 
+/**
+ * order_base_2 - calculate the (rounded up) base 2 order of the argument
+ * @n: parameter
+ *
+ * The first few values calculated by this routine:
+ *  ob2(0) = 0
+ *  ob2(1) = 0
+ *  ob2(2) = 1
+ *  ob2(3) = 2
+ *  ob2(4) = 2
+ *  ob2(5) = 3
+ *  ... and so on.
+ */
+
+#define order_base_2(n) ilog2(roundup_pow_of_two(n))
+
 #endif /* _LINUX_LOG2_H */
index 26a0a103898f15bd755a7df696e3b9c52ec717cb..46169a7b559b9ebacd3e53c777a692008e4cb37f 100644 (file)
@@ -76,6 +76,7 @@ struct loop_device {
 enum {
        LO_FLAGS_READ_ONLY      = 1,
        LO_FLAGS_USE_AOPS       = 2,
+       LO_FLAGS_AUTOCLEAR      = 4,
 };
 
 #include <asm/posix_types.h>   /* for __kernel_old_dev_t */
index 7059b6b9878a196d0619ab8f200285767752a897..0df024bfd6f0c672a755b2f701711040691f95ae 100644 (file)
@@ -99,7 +99,7 @@
 #ifdef __KERNEL__
 
 #include <linux/wait.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 
 /* Magic numbers for defining port-device mappings */
 #define LP_PARPORT_UNSPEC -4
@@ -145,7 +145,7 @@ struct lp_struct {
 #endif
        wait_queue_head_t waitq;
        unsigned int last_error;
-       struct semaphore port_mutex;
+       struct mutex port_mutex;
        wait_queue_head_t dataq;
        long timeout;
        unsigned int best_mode;
index dff9ea32606a56e986fd6a2cc62375675eec61db..24b30b9b4f8a807f0b154f959ad871dd06735be5 100644 (file)
@@ -43,7 +43,15 @@ struct miscdevice  {
 };
 
 extern int misc_register(struct miscdevice * misc);
-extern int misc_deregister(struct miscdevice * misc);
+extern int __misc_deregister(struct miscdevice *misc, bool suspended);
+static inline int misc_deregister(struct miscdevice *misc)
+{
+       return __misc_deregister(misc, false);
+}
+static inline int misc_deregister_suspended(struct miscdevice *misc)
+{
+       return __misc_deregister(misc, true);
+}
 
 #define MODULE_ALIAS_MISCDEV(minor)                            \
        MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR)      \
index 1bba6789a50a39cd1139a7b0556df38fcd78624e..89d7c691b93a6a660ee5468ac333a805b049a6f7 100644 (file)
@@ -227,10 +227,22 @@ static inline int put_page_testzero(struct page *page)
  */
 static inline int get_page_unless_zero(struct page *page)
 {
-       VM_BUG_ON(PageCompound(page));
+       VM_BUG_ON(PageTail(page));
        return atomic_inc_not_zero(&page->_count);
 }
 
+/* Support for virtually mapped pages */
+struct page *vmalloc_to_page(const void *addr);
+unsigned long vmalloc_to_pfn(const void *addr);
+
+/* Determine if an address is within the vmalloc range */
+static inline int is_vmalloc_addr(const void *x)
+{
+       unsigned long addr = (unsigned long)x;
+
+       return addr >= VMALLOC_START && addr < VMALLOC_END;
+}
+
 static inline struct page *compound_head(struct page *page)
 {
        if (unlikely(PageTail(page)))
@@ -706,6 +718,28 @@ unsigned long unmap_vmas(struct mmu_gather **tlb,
                struct vm_area_struct *start_vma, unsigned long start_addr,
                unsigned long end_addr, unsigned long *nr_accounted,
                struct zap_details *);
+
+/**
+ * mm_walk - callbacks for walk_page_range
+ * @pgd_entry: if set, called for each non-empty PGD (top-level) entry
+ * @pud_entry: if set, called for each non-empty PUD (2nd-level) entry
+ * @pmd_entry: if set, called for each non-empty PMD (3rd-level) entry
+ * @pte_entry: if set, called for each non-empty PTE (4th-level) entry
+ * @pte_hole: if set, called for each hole at all levels
+ *
+ * (see walk_page_range for more details)
+ */
+struct mm_walk {
+       int (*pgd_entry)(pgd_t *, unsigned long, unsigned long, void *);
+       int (*pud_entry)(pud_t *, unsigned long, unsigned long, void *);
+       int (*pmd_entry)(pmd_t *, unsigned long, unsigned long, void *);
+       int (*pte_entry)(pte_t *, unsigned long, unsigned long, void *);
+       int (*pte_hole)(unsigned long, unsigned long, void *);
+};
+
+int walk_page_range(const struct mm_struct *, unsigned long addr,
+                   unsigned long end, const struct mm_walk *walk,
+                   void *private);
 void free_pgd_range(struct mmu_gather **tlb, unsigned long addr,
                unsigned long end, unsigned long floor, unsigned long ceiling);
 void free_pgtables(struct mmu_gather **tlb, struct vm_area_struct *start_vma,
@@ -1089,8 +1123,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
 
 pgprot_t vm_get_page_prot(unsigned long vm_flags);
 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
-struct page *vmalloc_to_page(void *addr);
-unsigned long vmalloc_to_pfn(void *addr);
 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
                        unsigned long pfn, unsigned long size, pgprot_t);
 int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
index 4c4522a51a3bfa6667a60d0c593efcf970781e52..8d8d1977736e01c05e48c7c0d3172c30a29bf427 100644 (file)
@@ -113,7 +113,7 @@ struct per_cpu_pages {
 };
 
 struct per_cpu_pageset {
-       struct per_cpu_pages pcp[2];    /* 0: hot.  1: cold */
+       struct per_cpu_pages pcp;
 #ifdef CONFIG_NUMA
        s8 expire;
 #endif
index e9fddb42f26cdee8199d8d4f1d1fc31ce61a6a95..139d49d2f078d5573f166475c99873916a041515 100644 (file)
@@ -343,7 +343,8 @@ struct sdio_device_id {
        __u8    class;                  /* Standard interface or SDIO_ANY_ID */
        __u16   vendor;                 /* Vendor or SDIO_ANY_ID */
        __u16   device;                 /* Device ID or SDIO_ANY_ID */
-       kernel_ulong_t driver_data;     /* Data private to the driver */
+       kernel_ulong_t driver_data      /* Data private to the driver */
+               __attribute__((aligned(sizeof(kernel_ulong_t))));
 };
 
 /* SSB core, see drivers/ssb/ */
index d9c5455808e590cd72057b18d22d239dc47e4b0a..e726fc3a4375f5948d395e6756e10bca0673d9b6 100644 (file)
@@ -4,4 +4,3 @@ unifdef-y += stats.h
 unifdef-y += syscall.h
 unifdef-y += nfsfh.h
 unifdef-y += debug.h
-unifdef-y += auth.h
index 007480cd6a601fbec62c5d5ac41ed50e2a2d882d..7b5d784cc8587cd80c8bd31125f56a793ebae253 100644 (file)
@@ -72,8 +72,8 @@ enum {
  */
 #define RC_DELAY               (HZ/5)
 
-void   nfsd_cache_init(void);
-void   nfsd_cache_shutdown(void);
+int    nfsd_reply_cache_init(void);
+void   nfsd_reply_cache_shutdown(void);
 int    nfsd_cache_lookup(struct svc_rqst *, int);
 void   nfsd_cache_update(struct svc_rqst *, int, __be32 *);
 
index bcb7abafbca9d041478122ecfeb26d8236a1f46d..3a1687251367bd83b18711303f1ae3a712dbdff0 100644 (file)
@@ -122,7 +122,7 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
 /*
  * Function declarations
  */
-void                   nfsd_export_init(void);
+int                    nfsd_export_init(void);
 void                   nfsd_export_shutdown(void);
 void                   nfsd_export_flush(void);
 void                   exp_readlock(void);
index 604a0d786bc6a2699f3968eed506c6ec001ebc0a..8caf4c4f64e68df30c686a396d60252e63915319 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/nfsd/debug.h>
 #include <linux/nfsd/nfsfh.h>
 #include <linux/nfsd/export.h>
-#include <linux/nfsd/auth.h>
 #include <linux/nfsd/stats.h>
 /*
  * nfsd version
@@ -70,9 +69,9 @@ void          nfsd_racache_shutdown(void);
 int            nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
                                struct svc_export **expp);
 __be32         nfsd_lookup(struct svc_rqst *, struct svc_fh *,
-                               const char *, int, struct svc_fh *);
+                               const char *, unsigned int, struct svc_fh *);
 __be32          nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *,
-                               const char *, int,
+                               const char *, unsigned int,
                                struct svc_export **, struct dentry **);
 __be32         nfsd_setattr(struct svc_rqst *, struct svc_fh *,
                                struct iattr *, int, time_t);
index 8bcddccb6c427e81a7a7b960d1f25afaa1bb9b6f..4e439765b705e3a01dd3be9559b57d38a70ea445 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/nfsd/const.h>
 #include <linux/nfsd/export.h>
 #include <linux/nfsd/nfsfh.h>
-#include <linux/nfsd/auth.h>
 
 /*
  * Version of the syscall interface
index 67885d5e6e50d2024b5d036f31a1fd5c3e5ab6ee..a0132ef58f2128c9fe25f1412f9959355db92d58 100644 (file)
@@ -23,7 +23,7 @@ struct nfsd_sattrargs {
 struct nfsd_diropargs {
        struct svc_fh           fh;
        char *                  name;
-       int                     len;
+       unsigned int            len;
 };
 
 struct nfsd_readargs {
@@ -43,17 +43,17 @@ struct nfsd_writeargs {
 struct nfsd_createargs {
        struct svc_fh           fh;
        char *                  name;
-       int                     len;
+       unsigned int            len;
        struct iattr            attrs;
 };
 
 struct nfsd_renameargs {
        struct svc_fh           ffh;
        char *                  fname;
-       int                     flen;
+       unsigned int            flen;
        struct svc_fh           tfh;
        char *                  tname;
-       int                     tlen;
+       unsigned int            tlen;
 };
 
 struct nfsd_readlinkargs {
@@ -65,15 +65,15 @@ struct nfsd_linkargs {
        struct svc_fh           ffh;
        struct svc_fh           tfh;
        char *                  tname;
-       int                     tlen;
+       unsigned int            tlen;
 };
 
 struct nfsd_symlinkargs {
        struct svc_fh           ffh;
        char *                  fname;
-       int                     flen;
+       unsigned int            flen;
        char *                  tname;
-       int                     tlen;
+       unsigned int            tlen;
        struct iattr            attrs;
 };
 
index 89d9d6061a62b5b8179380d4f38d346700490da8..421eddd65a25a7968b8abe94d4f041e4f9aa0319 100644 (file)
@@ -21,7 +21,7 @@ struct nfsd3_sattrargs {
 struct nfsd3_diropargs {
        struct svc_fh           fh;
        char *                  name;
-       int                     len;
+       unsigned int            len;
 };
 
 struct nfsd3_accessargs {
@@ -48,7 +48,7 @@ struct nfsd3_writeargs {
 struct nfsd3_createargs {
        struct svc_fh           fh;
        char *                  name;
-       int                     len;
+       unsigned int            len;
        int                     createmode;
        struct iattr            attrs;
        __be32 *                verf;
@@ -57,7 +57,7 @@ struct nfsd3_createargs {
 struct nfsd3_mknodargs {
        struct svc_fh           fh;
        char *                  name;
-       int                     len;
+       unsigned int            len;
        __u32                   ftype;
        __u32                   major, minor;
        struct iattr            attrs;
@@ -66,10 +66,10 @@ struct nfsd3_mknodargs {
 struct nfsd3_renameargs {
        struct svc_fh           ffh;
        char *                  fname;
-       int                     flen;
+       unsigned int            flen;
        struct svc_fh           tfh;
        char *                  tname;
-       int                     tlen;
+       unsigned int            tlen;
 };
 
 struct nfsd3_readlinkargs {
@@ -81,15 +81,15 @@ struct nfsd3_linkargs {
        struct svc_fh           ffh;
        struct svc_fh           tfh;
        char *                  tname;
-       int                     tlen;
+       unsigned int            tlen;
 };
 
 struct nfsd3_symlinkargs {
        struct svc_fh           ffh;
        char *                  fname;
-       int                     flen;
+       unsigned int            flen;
        char *                  tname;
-       int                     tlen;
+       unsigned int            tlen;
        struct iattr            attrs;
 };
 
index b0ddfb41c790754034a9cb5cfe650c6c00602339..27bd3e38ec5ad86b290a0f73feb73e973b917749 100644 (file)
@@ -441,7 +441,7 @@ void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *);
 void nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op);
 __be32 nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
                       struct dentry *dentry, __be32 *buffer, int *countp,
-                      u32 *bmval, struct svc_rqst *);
+                      u32 *bmval, struct svc_rqst *, int ignore_crossmnt);
 extern __be32 nfsd4_setclientid(struct svc_rqst *rqstp,
                struct nfsd4_compound_state *,
                struct nfsd4_setclientid *setclid);
index e82746fcad14551ab7aaf46157e3aba04c27e6b1..d4a2ac18bd4cfba2a6713aa6a492660264b94782 100644 (file)
 #define IDMAP_NAMESZ 128
 
 #ifdef CONFIG_NFSD_V4
-void nfsd_idmap_init(void);
+int nfsd_idmap_init(void);
 void nfsd_idmap_shutdown(void);
 #else
-static inline void nfsd_idmap_init(void) {};
-static inline void nfsd_idmap_shutdown(void) {};
+static inline int nfsd_idmap_init(void)
+{
+       return 0;
+}
+static inline void nfsd_idmap_shutdown(void)
+{
+}
 #endif
 
 int nfsd_map_name_to_uid(struct svc_rqst *, const char *, size_t, __u32 *);
index 5dfbc684ce7daab792ca9ddf40e842fe5a5cc1c7..f4df40038f0c4cb54d2596cbe051dfd9bd241f0e 100644 (file)
@@ -228,6 +228,8 @@ static inline int notifier_to_errno(int ret)
 #define PM_POST_HIBERNATION    0x0002 /* Hibernation finished */
 #define PM_SUSPEND_PREPARE     0x0003 /* Going to suspend the system */
 #define PM_POST_SUSPEND                0x0004 /* Suspend finished */
+#define PM_RESTORE_PREPARE     0x0005 /* Going to restore a saved image */
+#define PM_POST_RESTORE                0x0006 /* Restore failed */
 
 /* Console keyboard events.
  * Note: KBD_KEYCODE is always sent before KBD_UNBOUND_KEYCODE, KBD_UNICODE and
index cdb3e9b8db54b1d5a677fd55adfbbc4cf938bd03..c4355076d1a5e58183336134a51244b878fbce62 100644 (file)
@@ -132,10 +132,12 @@ enum nubus_drhw {
        NUBUS_DRHW_RDIUS_DCGX     = 0x027C, /* Radius DirectColor/GX */
        NUBUS_DRHW_RDIUS_PC8      = 0x0291, /* Radius PrecisionColor 8 */
        NUBUS_DRHW_LAPIS_PCS8     = 0x0292, /* Lapis ProColorServer 8 */
-       NUBUS_DRHW_RASTER_24LXI   = 0x02A0, /* RasterOps 8/24 XLi */
+       NUBUS_DRHW_RASTER_24XLI   = 0x02A0, /* RasterOps 8/24 XLi */
        NUBUS_DRHW_RASTER_PBPGT   = 0x02A5, /* RasterOps PaintBoard Prism GT */
        NUBUS_DRHW_EMACH_FSX      = 0x02AE, /* E-Machines Futura SX */
+       NUBUS_DRHW_RASTER_24XLTV  = 0x02B7, /* RasterOps 24XLTV */
        NUBUS_DRHW_SMAC_THUND24   = 0x02CB, /* SuperMac Thunder/24 */
+       NUBUS_DRHW_SMAC_THUNDLGHT = 0x03D9, /* SuperMac ThunderLight */
        NUBUS_DRHW_RDIUS_PC24XP   = 0x0406, /* Radius PrecisionColor 24Xp */
        NUBUS_DRHW_RDIUS_PC24X    = 0x040A, /* Radius PrecisionColor 24X */
        NUBUS_DRHW_RDIUS_PC8XJ    = 0x040B, /* Radius PrecisionColor 8XJ */
index 209d3a47f50f24b5ccbf29c6b3dd965ebb79d2d8..bbad43fb8181001b43ef1c8de406173138d118e0 100644 (file)
 #define ClearPageReferenced(page)      clear_bit(PG_referenced, &(page)->flags)
 #define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags)
 
-#define PageUptodate(page)     test_bit(PG_uptodate, &(page)->flags)
+static inline int PageUptodate(struct page *page)
+{
+       int ret = test_bit(PG_uptodate, &(page)->flags);
+
+       /*
+        * Must ensure that the data we read out of the page is loaded
+        * _after_ we've loaded page->flags to check for PageUptodate.
+        * We can skip the barrier if the page is not uptodate, because
+        * we wouldn't be reading anything from it.
+        *
+        * See SetPageUptodate() for the other side of the story.
+        */
+       if (ret)
+               smp_rmb();
+
+       return ret;
+}
+
+static inline void __SetPageUptodate(struct page *page)
+{
+       smp_wmb();
+       __set_bit(PG_uptodate, &(page)->flags);
 #ifdef CONFIG_S390
+       page_clear_dirty(page);
+#endif
+}
+
 static inline void SetPageUptodate(struct page *page)
 {
+#ifdef CONFIG_S390
        if (!test_and_set_bit(PG_uptodate, &page->flags))
                page_clear_dirty(page);
-}
 #else
-#define SetPageUptodate(page)  set_bit(PG_uptodate, &(page)->flags)
+       /*
+        * Memory barrier must be issued before setting the PG_uptodate bit,
+        * so that all previous stores issued in order to bring the page
+        * uptodate are actually visible before PageUptodate becomes true.
+        *
+        * s390 doesn't need an explicit smp_wmb here because the test and
+        * set bit already provides full barriers.
+        */
+       smp_wmb();
+       set_bit(PG_uptodate, &(page)->flags);
 #endif
+}
+
 #define ClearPageUptodate(page)        clear_bit(PG_uptodate, &(page)->flags)
 
 #define PageDirty(page)                test_bit(PG_dirty, &(page)->flags)
index 936ef82ed76a6f21cf07b0132da3a12efc748cb9..3ba25065fa96b0f3907447f20fda02a8ea7e840c 100644 (file)
 
 #ifdef CONFIG_ACPI
 extern acpi_status pci_osc_control_set(acpi_handle handle, u32 flags);
-extern acpi_status pci_osc_support_set(u32 flags);
+extern acpi_status __pci_osc_support_set(u32 flags, const char *hid);
+static inline acpi_status pci_osc_support_set(u32 flags)
+{
+       return __pci_osc_support_set(flags, PCI_ROOT_HID_STRING);
+}
+static inline acpi_status pcie_osc_support_set(u32 flags)
+{
+       return __pci_osc_support_set(flags, PCI_EXPRESS_ROOT_HID_STRING);
+}
 #else
 #if !defined(AE_ERROR)
 typedef u32            acpi_status;
@@ -57,6 +65,7 @@ typedef u32           acpi_status;
 static inline acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
 {return AE_ERROR;}
 static inline acpi_status pci_osc_support_set(u32 flags) {return AE_ERROR;} 
+static inline acpi_status pcie_osc_support_set(u32 flags) {return AE_ERROR;}
 #endif
 
 #endif /* _PCI_ACPI_H_ */
index ae1006322f808d90b233188108efac1f59f23359..7215d3b1f4af05d8731e6dc4989763be0aea6eb0 100644 (file)
@@ -28,7 +28,7 @@
  *     7:3 = slot
  *     2:0 = function
  */
-#define PCI_DEVFN(slot,func)   ((((slot) & 0x1f) << 3) | ((func) & 0x07))
+#define PCI_DEVFN(slot, func)  ((((slot) & 0x1f) << 3) | ((func) & 0x07))
 #define PCI_SLOT(devfn)                (((devfn) >> 3) & 0x1f)
 #define PCI_FUNC(devfn)                ((devfn) & 0x07)
 
@@ -66,7 +66,6 @@ enum pci_mmap_state {
 #define PCI_DMA_FROMDEVICE     2
 #define PCI_DMA_NONE           3
 
-#define DEVICE_COUNT_COMPATIBLE        4
 #define DEVICE_COUNT_RESOURCE  12
 
 typedef int __bitwise pci_power_t;
@@ -160,6 +159,8 @@ struct pci_dev {
                                           this if your device has broken DMA
                                           or supports 64-bit transfers.  */
 
+       struct device_dma_parameters dma_parms;
+
        pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
                                           this is D0-D3, D0 being fully functional,
                                           and D3 being off. */
@@ -167,10 +168,6 @@ struct pci_dev {
        pci_channel_state_t error_state;        /* current connectivity state */
        struct  device  dev;            /* Generic device interface */
 
-       /* device is compatible with these IDs */
-       unsigned short vendor_compatible[DEVICE_COUNT_COMPATIBLE];
-       unsigned short device_compatible[DEVICE_COUNT_COMPATIBLE];
-
        int             cfg_size;       /* Size of configuration space */
 
        /*
@@ -219,7 +216,7 @@ static inline int pci_channel_offline(struct pci_dev *pdev)
 }
 
 static inline struct pci_cap_saved_state *pci_find_saved_cap(
-       struct pci_dev *pci_dev,char cap)
+       struct pci_dev *pci_dev, char cap)
 {
        struct pci_cap_saved_state *tmp;
        struct hlist_node *pos;
@@ -278,13 +275,13 @@ struct pci_bus {
        unsigned short  bridge_ctl;     /* manage NO_ISA/FBB/et al behaviors */
        pci_bus_flags_t bus_flags;      /* Inherited by child busses */
        struct device           *bridge;
-       struct class_device     class_dev;
+       struct device           dev;
        struct bin_attribute    *legacy_io; /* legacy I/O for this bus */
        struct bin_attribute    *legacy_mem; /* legacy mem */
 };
 
 #define pci_bus_b(n)   list_entry(n, struct pci_bus, node)
-#define to_pci_bus(n)  container_of(n, struct pci_bus, class_dev)
+#define to_pci_bus(n)  container_of(n, struct pci_bus, dev)
 
 /*
  * Error values that may be returned by PCI functions.
@@ -314,8 +311,8 @@ struct pci_raw_ops {
 extern struct pci_raw_ops *raw_pci_ops;
 
 struct pci_bus_region {
-       unsigned long start;
-       unsigned long end;
+       resource_size_t start;
+       resource_size_t end;
 };
 
 struct pci_dynids {
@@ -351,11 +348,10 @@ enum pci_ers_result {
 };
 
 /* PCI bus error event callbacks */
-struct pci_error_handlers
-{
+struct pci_error_handlers {
        /* PCI bus error detected on this device */
        pci_ers_result_t (*error_detected)(struct pci_dev *dev,
-                             enum pci_channel_state error);
+                                          enum pci_channel_state error);
 
        /* MMIO has been re-enabled, but not DMA */
        pci_ers_result_t (*mmio_enabled)(struct pci_dev *dev);
@@ -390,7 +386,7 @@ struct pci_driver {
        struct pci_dynids dynids;
 };
 
-#define        to_pci_driver(drv) container_of(drv,struct pci_driver, driver)
+#define        to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
 
 /**
  * PCI_DEVICE - macro used to describe a specific pci device
@@ -448,7 +444,7 @@ extern int no_pci_devices(void);
 
 void pcibios_fixup_bus(struct pci_bus *);
 int __must_check pcibios_enable_device(struct pci_dev *, int mask);
-char *pcibios_setup (char *str);
+char *pcibios_setup(char *str);
 
 /* Used only when drivers/pci/setup.c is used */
 void pcibios_align_resource(void *, struct resource *, resource_size_t,
@@ -459,8 +455,10 @@ void pcibios_update_irq(struct pci_dev *, int irq);
 
 extern struct pci_bus *pci_find_bus(int domain, int busnr);
 void pci_bus_add_devices(struct pci_bus *bus);
-struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata);
-static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata)
+struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
+                                     struct pci_ops *ops, void *sysdata);
+static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops,
+                                          void *sysdata)
 {
        struct pci_bus *root_bus;
        root_bus = pci_scan_bus_parented(NULL, bus, ops, sysdata);
@@ -468,15 +466,18 @@ static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *s
                pci_bus_add_devices(root_bus);
        return root_bus;
 }
-struct pci_bus *pci_create_bus(struct device *parent, int bus, struct pci_ops *ops, void *sysdata);
-struct pci_bus * pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr);
+struct pci_bus *pci_create_bus(struct device *parent, int bus,
+                              struct pci_ops *ops, void *sysdata);
+struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
+                               int busnr);
 int pci_scan_slot(struct pci_bus *bus, int devfn);
-struct pci_dev * pci_scan_single_device(struct pci_bus *bus, int devfn);
+struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn);
 void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
 unsigned int pci_scan_child_bus(struct pci_bus *bus);
 int __must_check pci_bus_add_device(struct pci_dev *dev);
 void pci_read_bridge_bases(struct pci_bus *child);
-struct resource *pci_find_parent_resource(const struct pci_dev *dev, struct resource *res);
+struct resource *pci_find_parent_resource(const struct pci_dev *dev,
+                                         struct resource *res);
 int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
 extern struct pci_dev *pci_dev_get(struct pci_dev *dev);
 extern void pci_dev_put(struct pci_dev *dev);
@@ -489,15 +490,19 @@ extern void pci_sort_breadthfirst(void);
 /* Generic PCI functions exported to card drivers */
 
 #ifdef CONFIG_PCI_LEGACY
-struct pci_dev __deprecated *pci_find_device (unsigned int vendor, unsigned int device, const struct pci_dev *from);
-struct pci_dev __deprecated *pci_find_slot (unsigned int bus, unsigned int devfn);
+struct pci_dev __deprecated *pci_find_device(unsigned int vendor,
+                                            unsigned int device,
+                                            const struct pci_dev *from);
+struct pci_dev __deprecated *pci_find_slot(unsigned int bus,
+                                          unsigned int devfn);
 #endif /* CONFIG_PCI_LEGACY */
 
-int pci_find_capability (struct pci_dev *dev, int cap);
-int pci_find_next_capability (struct pci_dev *dev, u8 pos, int cap);
-int pci_find_ext_capability (struct pci_dev *dev, int cap);
-int pci_find_ht_capability (struct pci_dev *dev, int ht_cap);
-int pci_find_next_ht_capability (struct pci_dev *dev, int pos, int ht_cap);
+int pci_find_capability(struct pci_dev *dev, int cap);
+int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
+int pci_find_ext_capability(struct pci_dev *dev, int cap);
+int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
+int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
+void pcie_wait_pending_transaction(struct pci_dev *dev);
 struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
 
 struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
@@ -505,49 +510,58 @@ struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
 struct pci_dev *pci_get_device_reverse(unsigned int vendor, unsigned int device,
                                struct pci_dev *from);
 
-struct pci_dev *pci_get_subsys (unsigned int vendor, unsigned int device,
+struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
                                unsigned int ss_vendor, unsigned int ss_device,
                                struct pci_dev *from);
-struct pci_dev *pci_get_slot (struct pci_bus *bus, unsigned int devfn);
-struct pci_dev *pci_get_bus_and_slot (unsigned int bus, unsigned int devfn);
-struct pci_dev *pci_get_class (unsigned int class, struct pci_dev *from);
+struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn);
+struct pci_dev *pci_get_bus_and_slot(unsigned int bus, unsigned int devfn);
+struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
 int pci_dev_present(const struct pci_device_id *ids);
 const struct pci_device_id *pci_find_present(const struct pci_device_id *ids);
 
-int pci_bus_read_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u8 *val);
-int pci_bus_read_config_word (struct pci_bus *bus, unsigned int devfn, int where, u16 *val);
-int pci_bus_read_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u32 *val);
-int pci_bus_write_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u8 val);
-int pci_bus_write_config_word (struct pci_bus *bus, unsigned int devfn, int where, u16 val);
-int pci_bus_write_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u32 val);
+int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
+                            int where, u8 *val);
+int pci_bus_read_config_word(struct pci_bus *bus, unsigned int devfn,
+                            int where, u16 *val);
+int pci_bus_read_config_dword(struct pci_bus *bus, unsigned int devfn,
+                             int where, u32 *val);
+int pci_bus_write_config_byte(struct pci_bus *bus, unsigned int devfn,
+                             int where, u8 val);
+int pci_bus_write_config_word(struct pci_bus *bus, unsigned int devfn,
+                             int where, u16 val);
+int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
+                              int where, u32 val);
 
 static inline int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
 {
-       return pci_bus_read_config_byte (dev->bus, dev->devfn, where, val);
+       return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val);
 }
 static inline int pci_read_config_word(struct pci_dev *dev, int where, u16 *val)
 {
-       return pci_bus_read_config_word (dev->bus, dev->devfn, where, val);
+       return pci_bus_read_config_word(dev->bus, dev->devfn, where, val);
 }
-static inline int pci_read_config_dword(struct pci_dev *dev, int where, u32 *val)
+static inline int pci_read_config_dword(struct pci_dev *dev, int where,
+                                       u32 *val)
 {
-       return pci_bus_read_config_dword (dev->bus, dev->devfn, where, val);
+       return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val);
 }
 static inline int pci_write_config_byte(struct pci_dev *dev, int where, u8 val)
 {
-       return pci_bus_write_config_byte (dev->bus, dev->devfn, where, val);
+       return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val);
 }
 static inline int pci_write_config_word(struct pci_dev *dev, int where, u16 val)
 {
-       return pci_bus_write_config_word (dev->bus, dev->devfn, where, val);
+       return pci_bus_write_config_word(dev->bus, dev->devfn, where, val);
 }
-static inline int pci_write_config_dword(struct pci_dev *dev, int where, u32 val)
+static inline int pci_write_config_dword(struct pci_dev *dev, int where,
+                                        u32 val)
 {
-       return pci_bus_write_config_dword (dev->bus, dev->devfn, where, val);
+       return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
 }
 
 int __must_check pci_enable_device(struct pci_dev *dev);
-int __must_check pci_enable_device_bars(struct pci_dev *dev, int mask);
+int __must_check pci_enable_device_io(struct pci_dev *dev);
+int __must_check pci_enable_device_mem(struct pci_dev *dev);
 int __must_check pci_reenable_device(struct pci_dev *);
 int __must_check pcim_enable_device(struct pci_dev *pdev);
 void pcim_pin_device(struct pci_dev *pdev);
@@ -568,6 +582,8 @@ void pci_intx(struct pci_dev *dev, int enable);
 void pci_msi_off(struct pci_dev *dev);
 int pci_set_dma_mask(struct pci_dev *dev, u64 mask);
 int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask);
+int pci_set_dma_max_seg_size(struct pci_dev *dev, unsigned int size);
+int pci_set_dma_seg_boundary(struct pci_dev *dev, unsigned long mask);
 int pcix_get_max_mmrbc(struct pci_dev *dev);
 int pcix_get_mmrbc(struct pci_dev *dev);
 int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc);
@@ -576,14 +592,11 @@ int pcie_set_readrq(struct pci_dev *dev, int rq);
 void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno);
 int __must_check pci_assign_resource(struct pci_dev *dev, int i);
 int __must_check pci_assign_resource_fixed(struct pci_dev *dev, int i);
-void pci_restore_bars(struct pci_dev *dev);
 int pci_select_bars(struct pci_dev *dev, unsigned long flags);
 
 /* ROM control related routines */
 void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
-void __iomem __must_check *pci_map_rom_copy(struct pci_dev *pdev, size_t *size);
 void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
-void pci_remove_rom(struct pci_dev *pdev);
 size_t pci_get_rom_size(void __iomem *rom, size_t size);
 
 /* Power management related routines */
@@ -594,7 +607,7 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state);
 int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
 
 /* Functions for PCI Hotplug drivers to use */
-int pci_bus_find_capability (struct pci_bus *bus, unsigned int devfn, int cap);
+int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
 
 /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
 void pci_bus_assign_resources(struct pci_bus *bus);
@@ -631,16 +644,18 @@ static inline int __must_check pci_register_driver(struct pci_driver *driver)
        return __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME);
 }
 
-void pci_unregister_driver(struct pci_driver *);
-void pci_remove_behind_bridge(struct pci_dev *);
-struct pci_driver *pci_dev_driver(const struct pci_dev *);
-const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, struct pci_dev *dev);
-int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass);
+void pci_unregister_driver(struct pci_driver *dev);
+void pci_remove_behind_bridge(struct pci_dev *dev);
+struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
+const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
+                                        struct pci_dev *dev);
+int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
+                   int pass);
 
 void pci_walk_bus(struct pci_bus *top, void (*cb)(struct pci_dev *, void *),
                  void *userdata);
 int pci_cfg_space_size(struct pci_dev *dev);
-unsigned char pci_bus_max_busnr(struct pci_busbus);
+unsigned char pci_bus_max_busnr(struct pci_bus *bus);
 
 /* kmem_cache style wrapper around pci_alloc_consistent() */
 
@@ -669,19 +684,36 @@ struct msix_entry {
 
 
 #ifndef CONFIG_PCI_MSI
-static inline int pci_enable_msi(struct pci_dev *dev) {return -1;}
-static inline void pci_disable_msi(struct pci_dev *dev) {}
-static inline int pci_enable_msix(struct pci_dev* dev,
-       struct msix_entry *entries, int nvec) {return -1;}
-static inline void pci_disable_msix(struct pci_dev *dev) {}
-static inline void msi_remove_pci_irq_vectors(struct pci_dev *dev) {}
+static inline int pci_enable_msi(struct pci_dev *dev)
+{
+       return -1;
+}
+
+static inline void pci_disable_msi(struct pci_dev *dev)
+{ }
+
+static inline int pci_enable_msix(struct pci_dev *dev,
+                                 struct msix_entry *entries, int nvec)
+{
+       return -1;
+}
+
+static inline void pci_disable_msix(struct pci_dev *dev)
+{ }
+
+static inline void msi_remove_pci_irq_vectors(struct pci_dev *dev)
+{ }
+
+static inline void pci_restore_msi_state(struct pci_dev *dev)
+{ }
 #else
 extern int pci_enable_msi(struct pci_dev *dev);
 extern void pci_disable_msi(struct pci_dev *dev);
-extern int pci_enable_msix(struct pci_devdev,
+extern int pci_enable_msix(struct pci_dev *dev,
        struct msix_entry *entries, int nvec);
 extern void pci_disable_msix(struct pci_dev *dev);
 extern void msi_remove_pci_irq_vectors(struct pci_dev *dev);
+extern void pci_restore_msi_state(struct pci_dev *dev);
 #endif
 
 #ifdef CONFIG_HT_IRQ
@@ -702,7 +734,11 @@ extern void pci_unblock_user_cfg_access(struct pci_dev *dev);
 extern int pci_domains_supported;
 #else
 enum { pci_domains_supported = 0 };
-static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
+static inline int pci_domain_nr(struct pci_bus *bus)
+{
+       return 0;
+}
+
 static inline int pci_proc_domain(struct pci_bus *bus)
 {
        return 0;
@@ -716,67 +752,173 @@ static inline int pci_proc_domain(struct pci_bus *bus)
  *  these as simple inline functions to avoid hair in drivers.
  */
 
-#define _PCI_NOP(o,s,t) \
-       static inline int pci_##o##_config_##s (struct pci_dev *dev, int where, t val) \
+#define _PCI_NOP(o, s, t) \
+       static inline int pci_##o##_config_##s(struct pci_dev *dev, \
+                                               int where, t val) \
                { return PCIBIOS_FUNC_NOT_SUPPORTED; }
-#define _PCI_NOP_ALL(o,x)      _PCI_NOP(o,byte,u8 x) \
-                               _PCI_NOP(o,word,u16 x) \
-                               _PCI_NOP(o,dword,u32 x)
+
+#define _PCI_NOP_ALL(o, x)     _PCI_NOP(o, byte, u8 x) \
+                               _PCI_NOP(o, word, u16 x) \
+                               _PCI_NOP(o, dword, u32 x)
 _PCI_NOP_ALL(read, *)
 _PCI_NOP_ALL(write,)
 
-static inline struct pci_dev *pci_find_device(unsigned int vendor, unsigned int device, const struct pci_dev *from)
-{ return NULL; }
+static inline struct pci_dev *pci_find_device(unsigned int vendor,
+                                             unsigned int device,
+                                             const struct pci_dev *from)
+{
+       return NULL;
+}
 
-static inline struct pci_dev *pci_find_slot(unsigned int bus, unsigned int devfn)
-{ return NULL; }
+static inline struct pci_dev *pci_find_slot(unsigned int bus,
+                                           unsigned int devfn)
+{
+       return NULL;
+}
 
 static inline struct pci_dev *pci_get_device(unsigned int vendor,
-                               unsigned int device, struct pci_dev *from)
-{ return NULL; }
+                                            unsigned int device,
+                                            struct pci_dev *from)
+{
+       return NULL;
+}
 
 static inline struct pci_dev *pci_get_device_reverse(unsigned int vendor,
-                               unsigned int device, struct pci_dev *from)
-{ return NULL; }
+                                                    unsigned int device,
+                                                    struct pci_dev *from)
+{
+       return NULL;
+}
 
-static inline struct pci_dev *pci_get_subsys (unsigned int vendor, unsigned int device,
-unsigned int ss_vendor, unsigned int ss_device, struct pci_dev *from)
-{ return NULL; }
+static inline struct pci_dev *pci_get_subsys(unsigned int vendor,
+                                            unsigned int device,
+                                            unsigned int ss_vendor,
+                                            unsigned int ss_device,
+                                            struct pci_dev *from)
+{
+       return NULL;
+}
 
-static inline struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
-{ return NULL; }
+static inline struct pci_dev *pci_get_class(unsigned int class,
+                                           struct pci_dev *from)
+{
+       return NULL;
+}
 
 #define pci_dev_present(ids)   (0)
 #define no_pci_devices()       (1)
 #define pci_find_present(ids)  (NULL)
 #define pci_dev_put(dev)       do { } while (0)
 
-static inline void pci_set_master(struct pci_dev *dev) { }
-static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
-static inline void pci_disable_device(struct pci_dev *dev) { }
-static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask) { return -EIO; }
-static inline int pci_assign_resource(struct pci_dev *dev, int i) { return -EBUSY;}
-static inline int __pci_register_driver(struct pci_driver *drv, struct module *owner) { return 0;}
-static inline int pci_register_driver(struct pci_driver *drv) { return 0;}
-static inline void pci_unregister_driver(struct pci_driver *drv) { }
-static inline int pci_find_capability (struct pci_dev *dev, int cap) {return 0; }
-static inline int pci_find_next_capability (struct pci_dev *dev, u8 post, int cap) { return 0; }
-static inline int pci_find_ext_capability (struct pci_dev *dev, int cap) {return 0; }
+static inline void pci_set_master(struct pci_dev *dev)
+{ }
+
+static inline int pci_enable_device(struct pci_dev *dev)
+{
+       return -EIO;
+}
+
+static inline void pci_disable_device(struct pci_dev *dev)
+{ }
+
+static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
+{
+       return -EIO;
+}
+
+static inline int pci_set_dma_max_seg_size(struct pci_dev *dev,
+                                       unsigned int size)
+{
+       return -EIO;
+}
+
+static inline int pci_set_dma_seg_boundary(struct pci_dev *dev,
+                                       unsigned long mask)
+{
+       return -EIO;
+}
+
+static inline int pci_assign_resource(struct pci_dev *dev, int i)
+{
+       return -EBUSY;
+}
+
+static inline int __pci_register_driver(struct pci_driver *drv,
+                                       struct module *owner)
+{
+       return 0;
+}
+
+static inline int pci_register_driver(struct pci_driver *drv)
+{
+       return 0;
+}
+
+static inline void pci_unregister_driver(struct pci_driver *drv)
+{ }
+
+static inline int pci_find_capability(struct pci_dev *dev, int cap)
+{
+       return 0;
+}
+
+static inline int pci_find_next_capability(struct pci_dev *dev, u8 post,
+                                          int cap)
+{
+       return 0;
+}
+
+static inline int pci_find_ext_capability(struct pci_dev *dev, int cap)
+{
+       return 0;
+}
+
+static inline void pcie_wait_pending_transaction(struct pci_dev *dev)
+{ }
 
 /* Power management related routines */
-static inline int pci_save_state(struct pci_dev *dev) { return 0; }
-static inline int pci_restore_state(struct pci_dev *dev) { return 0; }
-static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { return 0; }
-static inline pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) { return PCI_D0; }
-static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) { return 0; }
+static inline int pci_save_state(struct pci_dev *dev)
+{
+       return 0;
+}
 
-static inline int pci_request_regions(struct pci_dev *dev, const char *res_name) { return -EIO; }
-static inline void pci_release_regions(struct pci_dev *dev) { }
+static inline int pci_restore_state(struct pci_dev *dev)
+{
+       return 0;
+}
+
+static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
+{
+       return 0;
+}
+
+static inline pci_power_t pci_choose_state(struct pci_dev *dev,
+                                          pm_message_t state)
+{
+       return PCI_D0;
+}
+
+static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
+                                 int enable)
+{
+       return 0;
+}
+
+static inline int pci_request_regions(struct pci_dev *dev, const char *res_name)
+{
+       return -EIO;
+}
+
+static inline void pci_release_regions(struct pci_dev *dev)
+{ }
 
 #define pci_dma_burst_advice(pdev, strat, strategy_parameter) do { } while (0)
 
-static inline void pci_block_user_cfg_access(struct pci_dev *dev) { }
-static inline void pci_unblock_user_cfg_access(struct pci_dev *dev) { }
+static inline void pci_block_user_cfg_access(struct pci_dev *dev)
+{ }
+
+static inline void pci_unblock_user_cfg_access(struct pci_dev *dev)
+{ }
 
 static inline struct pci_bus *pci_find_next_bus(const struct pci_bus *from)
 { return NULL; }
@@ -797,27 +939,27 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
 
 /* these helpers provide future and backwards compatibility
  * for accessing popular PCI BAR info */
-#define pci_resource_start(dev,bar)   ((dev)->resource[(bar)].start)
-#define pci_resource_end(dev,bar)     ((dev)->resource[(bar)].end)
-#define pci_resource_flags(dev,bar)   ((dev)->resource[(bar)].flags)
+#define pci_resource_start(dev, bar)   ((dev)->resource[(bar)].start)
+#define pci_resource_end(dev, bar)     ((dev)->resource[(bar)].end)
+#define pci_resource_flags(dev, bar)   ((dev)->resource[(bar)].flags)
 #define pci_resource_len(dev,bar) \
-       ((pci_resource_start((dev),(bar)) == 0 &&       \
-         pci_resource_end((dev),(bar)) ==              \
-         pci_resource_start((dev),(bar))) ? 0 :        \
-                                                       \
-        (pci_resource_end((dev),(bar)) -               \
-         pci_resource_start((dev),(bar)) + 1))
+       ((pci_resource_start((dev), (bar)) == 0 &&      \
+         pci_resource_end((dev), (bar)) ==             \
+         pci_resource_start((dev), (bar))) ? 0 :       \
+                                                       \
+        (pci_resource_end((dev), (bar)) -              \
+         pci_resource_start((dev), (bar)) + 1))
 
 /* Similar to the helpers above, these manipulate per-pci_dev
  * driver-specific data.  They are really just a wrapper around
  * the generic device structure functions of these calls.
  */
-static inline void *pci_get_drvdata (struct pci_dev *pdev)
+static inline void *pci_get_drvdata(struct pci_dev *pdev)
 {
        return dev_get_drvdata(&pdev->dev);
 }
 
-static inline void pci_set_drvdata (struct pci_dev *pdev, void *data)
+static inline void pci_set_drvdata(struct pci_dev *pdev, void *data)
 {
        dev_set_drvdata(&pdev->dev, data);
 }
@@ -836,7 +978,7 @@ static inline char *pci_name(struct pci_dev *pdev)
  */
 #ifndef HAVE_ARCH_PCI_RESOURCE_TO_USER
 static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
-                const struct resource *rsrc, resource_size_t *start,
+               const struct resource *rsrc, resource_size_t *start,
                resource_size_t *end)
 {
        *start = rsrc->start;
@@ -888,9 +1030,9 @@ enum pci_fixup_pass {
 
 void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
 
-void __iomem * pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
+void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
 void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
-void __iomem * const * pcim_iomap_table(struct pci_dev *pdev);
+void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
 int pcim_iomap_regions(struct pci_dev *pdev, u16 mask, const char *name);
 void pcim_iounmap_regions(struct pci_dev *pdev, u16 mask);
 
index 41f6f28690f63be67aa43a2a162a1d349dc347e3..df6dd79a0d3b8cc377c772f2fe1410ef39b873ce 100644 (file)
 #define PCI_DEVICE_ID_QUATECH_DSC100   0x0020
 #define PCI_DEVICE_ID_QUATECH_ESC100D  0x0050
 #define PCI_DEVICE_ID_QUATECH_ESC100M  0x0060
+#define PCI_DEVICE_ID_QUATECH_SPPXP_100 0x0278
 
 #define PCI_VENDOR_ID_SEALEVEL         0x135e
 #define PCI_DEVICE_ID_SEALEVEL_U530    0x7101
 #define PCI_VENDOR_ID_QUICKNET         0x15e2
 #define PCI_DEVICE_ID_QUICKNET_XJ      0x0500
 
+/*
+ * ADDI-DATA GmbH communication cards <info@addi-data.com>
+ */
+#define PCI_VENDOR_ID_ADDIDATA_OLD             0x10E8
+#define PCI_VENDOR_ID_ADDIDATA                 0x15B8
+#define PCI_DEVICE_ID_ADDIDATA_APCI7500        0x7000
+#define PCI_DEVICE_ID_ADDIDATA_APCI7420        0x7001
+#define PCI_DEVICE_ID_ADDIDATA_APCI7300        0x7002
+#define PCI_DEVICE_ID_ADDIDATA_APCI7800        0x818E
+#define PCI_DEVICE_ID_ADDIDATA_APCI7500_2      0x7009
+#define PCI_DEVICE_ID_ADDIDATA_APCI7420_2      0x700A
+#define PCI_DEVICE_ID_ADDIDATA_APCI7300_2      0x700B
+#define PCI_DEVICE_ID_ADDIDATA_APCI7500_3      0x700C
+#define PCI_DEVICE_ID_ADDIDATA_APCI7420_3      0x700D
+#define PCI_DEVICE_ID_ADDIDATA_APCI7300_3      0x700E
+#define PCI_DEVICE_ID_ADDIDATA_APCI7800_3      0x700F
+
 #define PCI_VENDOR_ID_PDC              0x15e9
 
 #define PCI_VENDOR_ID_FARSITE           0x1619
index 1375f15797e7d919970735796a6d7093df0cfec7..225beb136807dd4650288464c2b4f4ffb8de2e59 100644 (file)
@@ -26,6 +26,7 @@ struct pda_power_pdata {
 
        unsigned int wait_for_status; /* msecs, default is 500 */
        unsigned int wait_for_charger; /* msecs, default is 500 */
+       unsigned int polling_interval; /* msecs, default is 2000 */
 };
 
 #endif /* __PDA_POWER_H__ */
index 50faa0ea28e4a7a392f617863e0ab82d4d9c330c..1ac969724bb2fff929c397be1cbdcdf007a61953 100644 (file)
@@ -54,7 +54,7 @@
 #ifdef CONFIG_SMP
 
 struct percpu_data {
-       void *ptrs[NR_CPUS];
+       void *ptrs[1];
 };
 
 #define __percpu_disguise(pdata) (struct percpu_data *)~(unsigned long)(pdata)
index 554836edd915ef027011a9127b81b7188f3388ad..5e43ae7514122af688dc4679c04dd927856cb58b 100644 (file)
@@ -88,7 +88,7 @@ struct mii_bus {
 
        /* A lock to ensure that only one thing can read/write
         * the MDIO bus at a time */
-       spinlock_t mdio_lock;
+       struct mutex mdio_lock;
 
        struct device *dev;
 
@@ -284,10 +284,11 @@ struct phy_device {
 
        /* Interrupt and Polling infrastructure */
        struct work_struct phy_queue;
+       struct work_struct state_queue;
        struct timer_list phy_timer;
        atomic_t irq_disable;
 
-       spinlock_t lock;
+       struct mutex lock;
 
        struct net_device *attached_dev;
 
index 1c1dba9ea5fba9f0f2916b26e51da13ed14286a9..28dfc61cf79e590d18c6ba62cbb8ee66b8101d89 100644 (file)
@@ -348,6 +348,7 @@ enum
        FLOW_KEY_RTCLASSID,
        FLOW_KEY_SKUID,
        FLOW_KEY_SKGID,
+       FLOW_KEY_VLAN_TAG,
        __FLOW_KEY_MAX,
 };
 
@@ -459,7 +460,8 @@ enum
 #define        TCF_EM_U32              3
 #define        TCF_EM_META             4
 #define        TCF_EM_TEXT             5
-#define        TCF_EM_MAX              5
+#define        TCF_EM_VLAN             6
+#define        TCF_EM_MAX              6
 
 enum
 {
index b78e0295adf4342732b42d8ffd588a48771e2b79..eccf59ea2a77ba107359fd74288aa6043ff4140a 100644 (file)
@@ -95,7 +95,7 @@ struct pm_dev
 };
 
 /* Functions above this comment are list-based old-style power
- * managment. Please avoid using them.  */
+ * management. Please avoid using them.  */
 
 /*
  * Callbacks for platform drivers to implement.
diff --git a/include/linux/pm_qos_params.h b/include/linux/pm_qos_params.h
new file mode 100644 (file)
index 0000000..2e4e97b
--- /dev/null
@@ -0,0 +1,25 @@
+/* interface for the pm_qos_power infrastructure of the linux kernel.
+ *
+ * Mark Gross
+ */
+#include <linux/list.h>
+#include <linux/notifier.h>
+#include <linux/miscdevice.h>
+
+#define PM_QOS_RESERVED 0
+#define PM_QOS_CPU_DMA_LATENCY 1
+#define PM_QOS_NETWORK_LATENCY 2
+#define PM_QOS_NETWORK_THROUGHPUT 3
+
+#define PM_QOS_NUM_CLASSES 4
+#define PM_QOS_DEFAULT_VALUE -1
+
+int pm_qos_add_requirement(int qos, char *name, s32 value);
+int pm_qos_update_requirement(int qos, char *name, s32 new_value);
+void pm_qos_remove_requirement(int qos, char *name);
+
+int pm_qos_requirement(int qos);
+
+int pm_qos_add_notifier(int qos, struct notifier_block *notifier);
+int pm_qos_remove_notifier(int qos, struct notifier_block *notifier);
+
index 2a6d62c7d2d1a5d8f58baad15d82e9a198eb4993..cd6332b88829e1fdf7d1f8e25356993905953ea4 100644 (file)
@@ -126,7 +126,7 @@ struct pnp_resource_table {
 };
 
 /*
- * Device Managemnt
+ * Device Management
  */
 
 struct pnp_card {
@@ -258,6 +258,7 @@ extern struct pnp_protocol isapnp_protocol;
 #else
 #define pnp_device_is_isapnp(dev) 0
 #endif
+extern struct mutex pnp_res_mutex;
 
 #ifdef CONFIG_PNPBIOS
 extern struct pnp_protocol pnpbios_protocol;
index 606c0957997f8b59d87c61611b1dddd96d7e206f..68ed19ccf1f702c1978c8fb5e18ed557f316484c 100644 (file)
@@ -54,15 +54,7 @@ enum {
        POWER_SUPPLY_TECHNOLOGY_LIPO,
        POWER_SUPPLY_TECHNOLOGY_LiFe,
        POWER_SUPPLY_TECHNOLOGY_NiCd,
-};
-
-enum {
-       POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
-       POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
-       POWER_SUPPLY_CAPACITY_LEVEL_LOW,
-       POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
-       POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
-       POWER_SUPPLY_CAPACITY_LEVEL_FULL,
+       POWER_SUPPLY_TECHNOLOGY_LiMn,
 };
 
 enum power_supply_property {
@@ -72,6 +64,8 @@ enum power_supply_property {
        POWER_SUPPLY_PROP_PRESENT,
        POWER_SUPPLY_PROP_ONLINE,
        POWER_SUPPLY_PROP_TECHNOLOGY,
+       POWER_SUPPLY_PROP_VOLTAGE_MAX,
+       POWER_SUPPLY_PROP_VOLTAGE_MIN,
        POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
        POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
        POWER_SUPPLY_PROP_VOLTAGE_NOW,
@@ -91,7 +85,6 @@ enum power_supply_property {
        POWER_SUPPLY_PROP_ENERGY_NOW,
        POWER_SUPPLY_PROP_ENERGY_AVG,
        POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
-       POWER_SUPPLY_PROP_CAPACITY_LEVEL,
        POWER_SUPPLY_PROP_TEMP,
        POWER_SUPPLY_PROP_TEMP_AMBIENT,
        POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
@@ -101,6 +94,7 @@ enum power_supply_property {
        /* Properties of type `const char *' */
        POWER_SUPPLY_PROP_MODEL_NAME,
        POWER_SUPPLY_PROP_MANUFACTURER,
+       POWER_SUPPLY_PROP_SERIAL_NUMBER,
 };
 
 enum power_supply_type {
index e2eff9079fe9ff9f02f7e9704479571c02cdd9aa..3800639775aee4706734b1aa9bb3e55104fe4f3b 100644 (file)
@@ -63,4 +63,8 @@
 #define PR_GET_SECCOMP 21
 #define PR_SET_SECCOMP 22
 
+/* Get/set the capability bounding set */
+#define PR_CAPBSET_READ 23
+#define PR_CAPBSET_DROP 24
+
 #endif /* _LINUX_PRCTL_H */
index 8f92546b403d205633bb51e417913a1ec420a41d..e43551516831c53d2fd2ba021de863a54b02e709 100644 (file)
@@ -19,6 +19,8 @@ struct completion;
  */
 #define FIRST_PROCESS_ENTRY 256
 
+/* Worst case buffer size needed for holding an integer. */
+#define PROC_NUMBUF 13
 
 /*
  * We always define these enumerators
@@ -117,7 +119,6 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
 unsigned long task_vsize(struct mm_struct *);
 int task_statm(struct mm_struct *, int *, int *, int *, int *);
 char *task_mem(struct mm_struct *, char *);
-void clear_refs_smap(struct mm_struct *mm);
 
 struct proc_dir_entry *de_get(struct proc_dir_entry *de);
 void de_put(struct proc_dir_entry *de);
index 515bff053de8a55900e223019452950d178d81b9..6ab80714a9169c67ae116b5e4b0ae9aaceb4620e 100644 (file)
@@ -204,6 +204,41 @@ static inline void user_enable_block_step(struct task_struct *task)
 }
 #endif /* arch_has_block_step */
 
+#ifndef arch_ptrace_stop_needed
+/**
+ * arch_ptrace_stop_needed - Decide whether arch_ptrace_stop() should be called
+ * @code:      current->exit_code value ptrace will stop with
+ * @info:      siginfo_t pointer (or %NULL) for signal ptrace will stop with
+ *
+ * This is called with the siglock held, to decide whether or not it's
+ * necessary to release the siglock and call arch_ptrace_stop() with the
+ * same @code and @info arguments.  It can be defined to a constant if
+ * arch_ptrace_stop() is never required, or always is.  On machines where
+ * this makes sense, it should be defined to a quick test to optimize out
+ * calling arch_ptrace_stop() when it would be superfluous.  For example,
+ * if the thread has not been back to user mode since the last stop, the
+ * thread state might indicate that nothing needs to be done.
+ */
+#define arch_ptrace_stop_needed(code, info)    (0)
+#endif
+
+#ifndef arch_ptrace_stop
+/**
+ * arch_ptrace_stop - Do machine-specific work before stopping for ptrace
+ * @code:      current->exit_code value ptrace will stop with
+ * @info:      siginfo_t pointer (or %NULL) for signal ptrace will stop with
+ *
+ * This is called with no locks held when arch_ptrace_stop_needed() has
+ * just returned nonzero.  It is allowed to block, e.g. for user memory
+ * access.  The arch can have machine-specific work to be done before
+ * ptrace stops.  On ia64, register backing store gets written back to user
+ * memory here.  Since this can be costly (requires dropping the siglock),
+ * we only do it when the arch requires it for this particular stop, as
+ * indicated by arch_ptrace_stop_needed().
+ */
+#define arch_ptrace_stop(code, info)           do { } while (0)
+#endif
+
 #endif
 
 #endif
index b6116b4445c760f01f0f133ad9530af71b6f09d0..b8ce2b444bb51b3f74130a0ad11acbf3d729069e 100644 (file)
@@ -91,7 +91,7 @@ do {                                                                  \
  *
  * For API usage, in general,
  * - any function _modifying_ the tree or tags (inserting or deleting
- *   items, setting or clearing tags must exclude other modifications, and
+ *   items, setting or clearing tags) must exclude other modifications, and
  *   exclude any functions reading the tree.
  * - any function _reading_ the tree or tags (looking up items or tags,
  *   gang lookups) must exclude modifications to the tree, but may occur
index 306a1d1a5af070fc5823c4d0f6e6a3f3192650c7..e51b531cd0b2d970631bc6097019869b74c55830 100644 (file)
@@ -244,6 +244,8 @@ struct bitmap {
         */
        unsigned long daemon_lastrun; /* jiffies of last run */
        unsigned long daemon_sleep; /* how many seconds between updates? */
+       unsigned long last_end_sync; /* when we lasted called end_sync to
+                                     * update bitmap with resync progress */
 
        atomic_t pending_writes; /* pending writes to the bitmap file */
        wait_queue_head_t write_wait;
@@ -275,6 +277,7 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
 int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int degraded);
 void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted);
 void bitmap_close_sync(struct bitmap *bitmap);
+void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector);
 
 void bitmap_unplug(struct bitmap *bitmap);
 void bitmap_daemon_work(struct bitmap *bitmap);
index dcb729244f47e193cf71a192c920a9f674e2a99f..85a068bab625a85d9a62e34859eed5e580a31b16 100644 (file)
@@ -81,6 +81,8 @@ struct mdk_rdev_s
 #define        In_sync         2               /* device is in_sync with rest of array */
 #define        WriteMostly     4               /* Avoid reading if at all possible */
 #define        BarriersNotsupp 5               /* BIO_RW_BARRIER is not supported */
+#define        AllReserved     6               /* If whole device is reserved for
+                                        * one array */
 
        int desc_nr;                    /* descriptor index in the superblock */
        int raid_disk;                  /* role of device in array */
@@ -130,6 +132,9 @@ struct mddev_s
                                        minor_version,
                                        patch_version;
        int                             persistent;
+       int                             external;       /* metadata is
+                                                        * managed externally */
+       char                            metadata_type[17]; /* externally set*/
        int                             chunk_size;
        time_t                          ctime, utime;
        int                             level, layout;
@@ -216,6 +221,8 @@ struct mddev_s
        atomic_t                        recovery_active; /* blocks scheduled, but not written */
        wait_queue_head_t               recovery_wait;
        sector_t                        recovery_cp;
+       sector_t                        resync_max;     /* resync should pause
+                                                        * when it gets here */
 
        spinlock_t                      write_lock;
        wait_queue_head_t               sb_wait;        /* for waiting on superblock updates */
@@ -306,23 +313,17 @@ static inline char * mdname (mddev_t * mddev)
  * iterates through some rdev ringlist. It's safe to remove the
  * current 'rdev'. Dont touch 'tmp' though.
  */
-#define ITERATE_RDEV_GENERIC(head,rdev,tmp)                            \
+#define rdev_for_each_list(rdev, tmp, list)                            \
                                                                        \
-       for ((tmp) = (head).next;                                       \
+       for ((tmp) = (list).next;                                       \
                (rdev) = (list_entry((tmp), mdk_rdev_t, same_set)),     \
-                       (tmp) = (tmp)->next, (tmp)->prev != &(head)     \
+                       (tmp) = (tmp)->next, (tmp)->prev != &(list)     \
                ; )
 /*
  * iterates through the 'same array disks' ringlist
  */
-#define ITERATE_RDEV(mddev,rdev,tmp)                                   \
-       ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp)
-
-/*
- * Iterates through 'pending RAID disks'
- */
-#define ITERATE_RDEV_PENDING(rdev,tmp)                                 \
-       ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp)
+#define rdev_for_each(rdev, tmp, mddev)                                \
+       rdev_for_each_list(rdev, tmp, (mddev)->disks)
 
 typedef struct mdk_thread_s {
        void                    (*run) (mddev_t *mddev);
index d32c14de270ea28a1490c3241fe71057a1b0f582..37a642c54871f24166bec8e9b23b73e3369848bb 100644 (file)
@@ -174,10 +174,13 @@ struct rcu_head {
  * code.
  */
 
-#define rcu_assign_pointer(p, v)       ({ \
-                                               smp_wmb(); \
-                                               (p) = (v); \
-                                       })
+#define rcu_assign_pointer(p, v) \
+       ({ \
+               if (!__builtin_constant_p(v) || \
+                   ((v) != NULL)) \
+                       smp_wmb(); \
+               (p) = (v); \
+       })
 
 /**
  * synchronize_sched - block until all CPUs have exited any non-preemptive
index 85ea63f462af39fe0b589ac236baae4ee2831b39..b93b541cf111d08701c40939b9f201429a213e56 100644 (file)
@@ -59,8 +59,6 @@ extern void machine_crash_shutdown(struct pt_regs *);
  * Architecture independent implemenations of sys_reboot commands.
  */
 
-extern void kernel_shutdown_prepare(enum system_states state);
-
 extern void kernel_restart(char *cmd);
 extern void kernel_halt(void);
 extern void kernel_power_off(void);
index 10fa0c832018c870a7bac82b428cdb976cb34449..db5ef9b83c3ff366be21465ffe2a86a5602032f4 100644 (file)
@@ -185,7 +185,7 @@ struct reiserfs_journal {
        unsigned long j_trans_id;
        unsigned long j_mount_id;
        unsigned long j_start;  /* start of current waiting commit (index into j_ap_blocks) */
-       unsigned long j_len;    /* lenght of current waiting commit */
+       unsigned long j_len;    /* length of current waiting commit */
        unsigned long j_len_alloc;      /* number of buffers requested by journal_begin() */
        atomic_t j_wcount;      /* count of writers for current commit */
        unsigned long j_bcount; /* batch count. allows turning X transactions into 1 */
index b014f6b7fe2918784d1095c6cd8c25f3668862a9..b9e174079002300dee538600e8e6e5585757aed8 100644 (file)
@@ -602,24 +602,12 @@ struct tcamsg
 
 #include <linux/mutex.h>
 
-extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size);
 static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
 {
        int len = strlen(str) + 1;
        return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
 }
 
-extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
-extern int __rtattr_parse_nested_compat(struct rtattr *tb[], int maxattr,
-                                       struct rtattr *rta, int len);
-
-#define rtattr_parse_nested(tb, max, rta) \
-       rtattr_parse((tb), (max), RTA_DATA((rta)), RTA_PAYLOAD((rta)))
-
-#define rtattr_parse_nested_compat(tb, max, rta, data, len) \
-({     data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
-       __rtattr_parse_nested_compat(tb, max, rta, len); })
-
 extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo);
 extern int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid);
 extern int rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
index af6947e69b40cb2c9cce3ba291bca296ccb5edd7..7c8ca05c3cae4368a85da8a56b58050d5bd74944 100644 (file)
@@ -555,6 +555,13 @@ struct signal_struct {
 #define SIGNAL_STOP_CONTINUED  0x00000004 /* SIGCONT since WCONTINUED reap */
 #define SIGNAL_GROUP_EXIT      0x00000008 /* group exit in progress */
 
+/* If true, all threads except ->group_exit_task have pending SIGKILL */
+static inline int signal_group_exit(const struct signal_struct *sig)
+{
+       return  (sig->flags & SIGNAL_GROUP_EXIT) ||
+               (sig->group_exit_task != NULL);
+}
+
 /*
  * Some day this will be a full-fledged user tracking system..
  */
@@ -803,7 +810,7 @@ static inline int above_background_load(void)
 
 struct io_context;                     /* See blkdev.h */
 #define NGROUPS_SMALL          32
-#define NGROUPS_PER_BLOCK      ((int)(PAGE_SIZE / sizeof(gid_t)))
+#define NGROUPS_PER_BLOCK      ((unsigned int)(PAGE_SIZE / sizeof(gid_t)))
 struct group_info {
        int ngroups;
        atomic_t usage;
@@ -1091,7 +1098,7 @@ struct task_struct {
        uid_t uid,euid,suid,fsuid;
        gid_t gid,egid,sgid,fsgid;
        struct group_info *group_info;
-       kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;
+       kernel_cap_t   cap_effective, cap_inheritable, cap_permitted, cap_bset;
        unsigned keep_capabilities:1;
        struct user_struct *user;
 #ifdef CONFIG_KEYS
@@ -1770,7 +1777,7 @@ extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned lon
 struct task_struct *fork_idle(int);
 
 extern void set_task_comm(struct task_struct *tsk, char *from);
-extern void get_task_comm(char *to, struct task_struct *tsk);
+extern char *get_task_comm(char *to, struct task_struct *tsk);
 
 #ifdef CONFIG_SMP
 extern void wait_task_inactive(struct task_struct * p);
@@ -2080,6 +2087,10 @@ static inline void migration_init(void)
 }
 #endif
 
+#ifndef TASK_SIZE_OF
+#define TASK_SIZE_OF(tsk)      TASK_SIZE
+#endif
+
 #endif /* __KERNEL__ */
 
 #endif
index d24974262dc62a9376e6c6ffd1a4e7f42ca0196a..fe52cdeab0a67ba5cd1220383b9bd0872efd78e1 100644 (file)
 #define ROOTCONTEXT_MNT                0x04
 #define DEFCONTEXT_MNT         0x08
 
-/*
- * Bounding set
- */
-extern kernel_cap_t cap_bset;
-
 extern unsigned securebits;
 
 struct ctl_table;
@@ -423,15 +418,12 @@ struct request_sock;
  *     identified by @name for @dentry.
  *     Return 0 if permission is granted.
  * @inode_getsecurity:
- *     Copy the extended attribute representation of the security label 
- *     associated with @name for @inode into @buffer.  @buffer may be
- *     NULL to request the size of the buffer required.  @size indicates
- *     the size of @buffer in bytes.  Note that @name is the remainder
- *     of the attribute name after the security. prefix has been removed.
- *     @err is the return value from the preceding fs getxattr call,
- *     and can be used by the security module to determine whether it
- *     should try and canonicalize the attribute value.
- *     Return number of bytes used/required on success.
+ *     Retrieve a copy of the extended attribute representation of the
+ *     security label associated with @name for @inode via @buffer.  Note that
+ *     @name is the remainder of the attribute name after the security prefix
+ *     has been removed. @alloc is used to specify of the call should return a
+ *     value via the buffer or just the value length Return size of buffer on
+ *     success.
  * @inode_setsecurity:
  *     Set the security label associated with @name for @inode from the
  *     extended attribute value @value.  @size indicates the size of the
@@ -1304,7 +1296,7 @@ struct security_operations {
        int (*inode_removexattr) (struct dentry *dentry, char *name);
        int (*inode_need_killpriv) (struct dentry *dentry);
        int (*inode_killpriv) (struct dentry *dentry);
-       int (*inode_getsecurity)(const struct inode *inode, const char *name, void *buffer, size_t size, int err);
+       int (*inode_getsecurity)(const struct inode *inode, const char *name, void **buffer, bool alloc);
        int (*inode_setsecurity)(struct inode *inode, const char *name, const void *value, size_t size, int flags);
        int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size);
 
@@ -1565,7 +1557,7 @@ int security_inode_listxattr(struct dentry *dentry);
 int security_inode_removexattr(struct dentry *dentry, char *name);
 int security_inode_need_killpriv(struct dentry *dentry);
 int security_inode_killpriv(struct dentry *dentry);
-int security_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err);
+int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
 int security_file_permission(struct file *file, int mask);
@@ -1967,7 +1959,7 @@ static inline int security_inode_killpriv(struct dentry *dentry)
        return cap_inode_killpriv(dentry);
 }
 
-static inline int security_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err)
+static inline int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
 {
        return -EOPNOTSUPP;
 }
index afe0f6d9b9bcbfdbc39d726f5a202307d3ddbc81..00b65c0a82ca0a1c00d1ea862e098c88f9689684 100644 (file)
@@ -23,6 +23,7 @@ struct plat_serial8250_port {
        resource_size_t mapbase;        /* resource base */
        unsigned int    irq;            /* interrupt number */
        unsigned int    uartclk;        /* UART clock rate */
+       void            *private_data;
        unsigned char   regshift;       /* register shift */
        unsigned char   iotype;         /* UPIO_* */
        unsigned char   hub6;
index 0ae338866240dee807f7f35a5f8280ebe1aa15b2..7e095147656cfac8320faab052f5574e79cd6f13 100644 (file)
@@ -371,6 +371,8 @@ int unhandled_signal(struct task_struct *tsk, int sig);
        (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
         (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
 
+void signals_init(void);
+
 #endif /* __KERNEL__ */
 
 #endif /* _LINUX_SIGNAL_H */
index 86f9b1ef0e0934c9a354b44a67ab396be61ccbe4..ea037f28df91372d208a2e4301b24e21369596ca 100644 (file)
@@ -29,7 +29,7 @@ struct signalfd_siginfo {
 
        /*
         * Pad strcture to 128 bytes. Remember to update the
-        * pad size when you add new memebers. We use a fixed
+        * pad size when you add new members. We use a fixed
         * size structure to avoid compatibility problems with
         * future versions, and we leave extra space for additional
         * members. We use fixed size members because this strcture
index dfe975a9967ef16767be9040283ab8c34bb39e93..412672a79e8a9f237bd4dff87eb85df62fcf428c 100644 (file)
@@ -1810,5 +1810,6 @@ static inline void skb_forward_csum(struct sk_buff *skb)
                skb->ip_summed = CHECKSUM_NONE;
 }
 
+bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off);
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SKBUFF_H */
index 40801e754afb48430e3af7c59497b5726e298250..ddb1a706b144036dd1805eac5baa66784adbbc29 100644 (file)
 #include <linux/kobject.h>
 
 struct kmem_cache_cpu {
-       void **freelist;
-       struct page *page;
-       int node;
-       unsigned int offset;
-       unsigned int objsize;
+       void **freelist;        /* Pointer to first free per cpu object */
+       struct page *page;      /* The slab from which we are allocating */
+       int node;               /* The node of the page (or -1 for debug) */
+       unsigned int offset;    /* Freepointer offset (in word units) */
+       unsigned int objsize;   /* Size of an object (from kmem_cache) */
 };
 
 struct kmem_cache_node {
@@ -59,7 +59,10 @@ struct kmem_cache {
 #endif
 
 #ifdef CONFIG_NUMA
-       int defrag_ratio;
+       /*
+        * Defragmentation by allocating from a remote node.
+        */
+       int remote_node_defrag_ratio;
        struct kmem_cache_node *node[MAX_NUMNODES];
 #endif
 #ifdef CONFIG_SMP
index df7620dd8f3181133e6818a062cd85347c5e084d..64236b73c724e2bb4a8b357d8f8c50539377a9ca 100644 (file)
 /* USB slave/gadget data port base */
 #define SM501_USB_GADGET_DATA          (0x070000)
 
-/* Display contoller/video engine base */
+/* Display controller/video engine base */
 #define SM501_DC                       (0x080000)
 
 /* common defines for the SM501 address registers */
index 9e3aaad6fe4dd894f5baa6d70730dde5cd385dc5..932a9efee8a5c7c9508b6c6a4f1caf565069825e 100644 (file)
@@ -70,6 +70,8 @@ extern unsigned long sm501_gpio_get(struct device *dev,
 #define SM501FB_FLAG_DISABLE_AT_EXIT   (1<<1)
 #define SM501FB_FLAG_USE_HWCURSOR      (1<<2)
 #define SM501FB_FLAG_USE_HWACCEL       (1<<3)
+#define SM501FB_FLAG_PANEL_USE_FPEN    (1<<4)
+#define SM501FB_FLAG_PANEL_USE_VBIASEN (1<<5)
 
 struct sm501_platdata_fbsub {
        struct fb_videomode     *def_mode;
index 40c7b5d993b932f83864f04255e1853acd099dc5..f41ffd7c2dd9f611d0cc7e15d4f245f63b461116 100644 (file)
 #define SONYPI_EVENT_FNKEY_RELEASED            59
 #define SONYPI_EVENT_WIRELESS_ON               60
 #define SONYPI_EVENT_WIRELESS_OFF              61
+#define SONYPI_EVENT_ZOOM_IN_PRESSED           62
+#define SONYPI_EVENT_ZOOM_OUT_PRESSED          63
 
 /* get/set brightness */
 #define SONYPI_IOCGBRT         _IOR('v', 0, __u8)
diff --git a/include/linux/spi/mcp23s08.h b/include/linux/spi/mcp23s08.h
new file mode 100644 (file)
index 0000000..835ddf4
--- /dev/null
@@ -0,0 +1,24 @@
+
+/* FIXME driver should be able to handle all four slaves that
+ * can be hooked up to each chipselect, as well as IRQs...
+ */
+
+struct mcp23s08_platform_data {
+       /* four slaves can share one SPI chipselect */
+       u8              slave;
+
+       /* number assigned to the first GPIO */
+       unsigned        base;
+
+       /* pins with pullups */
+       u8              pullups;
+
+       void            *context;       /* param to setup/teardown */
+
+       int             (*setup)(struct spi_device *spi,
+                                       int gpio, unsigned ngpio,
+                                       void *context);
+       int             (*teardown)(struct spi_device *spi,
+                                       int gpio, unsigned ngpio,
+                                       void *context);
+};
index 67faa044c5f5574042e72c28fa18f7f38e1fe51f..04e1d3164576eac1a5137b0620da7c1aa1959d89 100644 (file)
@@ -21,7 +21,7 @@
 /*
  * In the UP-nondebug case there's no real locking going on, so the
  * only thing we have to do is to keep the preempt counts and irq
- * flags straight, to supress compiler warnings of unused lock
+ * flags straight, to suppress compiler warnings of unused lock
  * variables, and to add the proper checker annotations:
  */
 #define __LOCK(lock) \
index e18f5c23b9301eddd5e37dc9fce527ac63c47335..9d5da8b2ccf94f7e7211ccbff59edff11626bce0 100644 (file)
@@ -373,6 +373,15 @@ void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
        if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
                pci_set_power_state(sdev->bus->host_pci, state);
 }
+#else
+static inline void ssb_pcihost_unregister(struct pci_driver *driver)
+{
+}
+
+static inline
+void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
+{
+}
 #endif /* CONFIG_SSB_PCIHOST */
 
 
index bd7a6b0a87af654e080093037915238b6fc4fd74..03547d6abee50be5c73373dd14b6811700655b59 100644 (file)
@@ -169,8 +169,8 @@ extern int cache_check(struct cache_detail *detail,
 extern void cache_flush(void);
 extern void cache_purge(struct cache_detail *detail);
 #define NEVER (0x7FFFFFFF)
-extern void cache_register(struct cache_detail *cd);
-extern int cache_unregister(struct cache_detail *cd);
+extern int cache_register(struct cache_detail *cd);
+extern void cache_unregister(struct cache_detail *cd);
 
 extern void qword_add(char **bpp, int *lp, char *str);
 extern void qword_addhex(char **bpp, int *lp, char *buf, int blen);
index 3912cf16361ee98aa9334399fe6d8289e3270364..10709cbe96fdb88419a87b15bf32fc81fef7c06a 100644 (file)
@@ -20,7 +20,7 @@
 #define RPCDBG_BIND            0x0020
 #define RPCDBG_SCHED           0x0040
 #define RPCDBG_TRANS           0x0080
-#define RPCDBG_SVCSOCK         0x0100
+#define RPCDBG_SVCXPRT         0x0100
 #define RPCDBG_SVCDSP          0x0200
 #define RPCDBG_MISC            0x0400
 #define RPCDBG_CACHE           0x0800
index 8531a70da73d2526d7e110c92baa6fddb9152212..64c771056187a3957c70ce3c212e0db82db49ff9 100644 (file)
@@ -204,7 +204,7 @@ union svc_addr_u {
 struct svc_rqst {
        struct list_head        rq_list;        /* idle list */
        struct list_head        rq_all;         /* all threads list */
-       struct svc_sock *       rq_sock;        /* socket */
+       struct svc_xprt *       rq_xprt;        /* transport ptr */
        struct sockaddr_storage rq_addr;        /* peer address */
        size_t                  rq_addrlen;
 
@@ -214,9 +214,10 @@ struct svc_rqst {
        struct auth_ops *       rq_authop;      /* authentication flavour */
        u32                     rq_flavor;      /* pseudoflavor */
        struct svc_cred         rq_cred;        /* auth info */
-       struct sk_buff *        rq_skbuff;      /* fast recv inet buffer */
+       void *                  rq_xprt_ctxt;   /* transport specific context ptr */
        struct svc_deferred_req*rq_deferred;    /* deferred request we are replaying */
 
+       size_t                  rq_xprt_hlen;   /* xprt header len */
        struct xdr_buf          rq_arg;
        struct xdr_buf          rq_res;
        struct page *           rq_pages[RPCSVC_MAXPAGES];
@@ -317,11 +318,12 @@ static inline void svc_free_res_pages(struct svc_rqst *rqstp)
 
 struct svc_deferred_req {
        u32                     prot;   /* protocol (UDP or TCP) */
-       struct svc_sock         *svsk;
+       struct svc_xprt         *xprt;
        struct sockaddr_storage addr;   /* where reply must go */
        size_t                  addrlen;
        union svc_addr_u        daddr;  /* where reply must come from */
        struct cache_deferred_req handle;
+       size_t                  xprt_hlen;
        int                     argslen;
        __be32                  args[0];
 };
@@ -382,6 +384,8 @@ struct svc_procedure {
  */
 struct svc_serv *  svc_create(struct svc_program *, unsigned int,
                              void (*shutdown)(struct svc_serv*));
+struct svc_rqst *svc_prepare_thread(struct svc_serv *serv,
+                                       struct svc_pool *pool);
 int               svc_create_thread(svc_thread_fn, struct svc_serv *);
 void              svc_exit_thread(struct svc_rqst *);
 struct svc_serv *  svc_create_pooled(struct svc_program *, unsigned int,
diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
new file mode 100644 (file)
index 0000000..c11bbcc
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the BSD-type
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *      Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ *      Neither the name of the Network Appliance, Inc. nor the names of
+ *      its contributors may be used to endorse or promote products
+ *      derived from this software without specific prior written
+ *      permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Tom Tucker <tom@opengridcomputing.com>
+ */
+
+#ifndef SVC_RDMA_H
+#define SVC_RDMA_H
+#include <linux/sunrpc/xdr.h>
+#include <linux/sunrpc/svcsock.h>
+#include <linux/sunrpc/rpc_rdma.h>
+#include <rdma/ib_verbs.h>
+#include <rdma/rdma_cm.h>
+#define SVCRDMA_DEBUG
+
+/* RPC/RDMA parameters and stats */
+extern unsigned int svcrdma_ord;
+extern unsigned int svcrdma_max_requests;
+extern unsigned int svcrdma_max_req_size;
+
+extern atomic_t rdma_stat_recv;
+extern atomic_t rdma_stat_read;
+extern atomic_t rdma_stat_write;
+extern atomic_t rdma_stat_sq_starve;
+extern atomic_t rdma_stat_rq_starve;
+extern atomic_t rdma_stat_rq_poll;
+extern atomic_t rdma_stat_rq_prod;
+extern atomic_t rdma_stat_sq_poll;
+extern atomic_t rdma_stat_sq_prod;
+
+#define RPCRDMA_VERSION 1
+
+/*
+ * Contexts are built when an RDMA request is created and are a
+ * record of the resources that can be recovered when the request
+ * completes.
+ */
+struct svc_rdma_op_ctxt {
+       struct svc_rdma_op_ctxt *next;
+       struct xdr_buf arg;
+       struct list_head dto_q;
+       enum ib_wr_opcode wr_op;
+       enum ib_wc_status wc_status;
+       u32 byte_len;
+       struct svcxprt_rdma *xprt;
+       unsigned long flags;
+       enum dma_data_direction direction;
+       int count;
+       struct ib_sge sge[RPCSVC_MAXPAGES];
+       struct page *pages[RPCSVC_MAXPAGES];
+};
+
+#define RDMACTXT_F_READ_DONE   1
+#define RDMACTXT_F_LAST_CTXT   2
+
+struct svcxprt_rdma {
+       struct svc_xprt      sc_xprt;           /* SVC transport structure */
+       struct rdma_cm_id    *sc_cm_id;         /* RDMA connection id */
+       struct list_head     sc_accept_q;       /* Conn. waiting accept */
+       int                  sc_ord;            /* RDMA read limit */
+       wait_queue_head_t    sc_read_wait;
+       int                  sc_max_sge;
+
+       int                  sc_sq_depth;       /* Depth of SQ */
+       atomic_t             sc_sq_count;       /* Number of SQ WR on queue */
+
+       int                  sc_max_requests;   /* Depth of RQ */
+       int                  sc_max_req_size;   /* Size of each RQ WR buf */
+
+       struct ib_pd         *sc_pd;
+
+       struct svc_rdma_op_ctxt  *sc_ctxt_head;
+       int                  sc_ctxt_cnt;
+       int                  sc_ctxt_bump;
+       int                  sc_ctxt_max;
+       spinlock_t           sc_ctxt_lock;
+       struct list_head     sc_rq_dto_q;
+       spinlock_t           sc_rq_dto_lock;
+       struct ib_qp         *sc_qp;
+       struct ib_cq         *sc_rq_cq;
+       struct ib_cq         *sc_sq_cq;
+       struct ib_mr         *sc_phys_mr;       /* MR for server memory */
+
+       spinlock_t           sc_lock;           /* transport lock */
+
+       wait_queue_head_t    sc_send_wait;      /* SQ exhaustion waitlist */
+       unsigned long        sc_flags;
+       struct list_head     sc_dto_q;          /* DTO tasklet I/O pending Q */
+       struct list_head     sc_read_complete_q;
+       spinlock_t           sc_read_complete_lock;
+};
+/* sc_flags */
+#define RDMAXPRT_RQ_PENDING    1
+#define RDMAXPRT_SQ_PENDING    2
+#define RDMAXPRT_CONN_PENDING  3
+
+#define RPCRDMA_LISTEN_BACKLOG  10
+/* The default ORD value is based on two outstanding full-size writes with a
+ * page size of 4k, or 32k * 2 ops / 4k = 16 outstanding RDMA_READ.  */
+#define RPCRDMA_ORD             (64/4)
+#define RPCRDMA_SQ_DEPTH_MULT   8
+#define RPCRDMA_MAX_THREADS     16
+#define RPCRDMA_MAX_REQUESTS    16
+#define RPCRDMA_MAX_REQ_SIZE    4096
+
+/* svc_rdma_marshal.c */
+extern void svc_rdma_rcl_chunk_counts(struct rpcrdma_read_chunk *,
+                                     int *, int *);
+extern int svc_rdma_xdr_decode_req(struct rpcrdma_msg **, struct svc_rqst *);
+extern int svc_rdma_xdr_decode_deferred_req(struct svc_rqst *);
+extern int svc_rdma_xdr_encode_error(struct svcxprt_rdma *,
+                                    struct rpcrdma_msg *,
+                                    enum rpcrdma_errcode, u32 *);
+extern void svc_rdma_xdr_encode_write_list(struct rpcrdma_msg *, int);
+extern void svc_rdma_xdr_encode_reply_array(struct rpcrdma_write_array *, int);
+extern void svc_rdma_xdr_encode_array_chunk(struct rpcrdma_write_array *, int,
+                                           u32, u64, u32);
+extern void svc_rdma_xdr_encode_reply_header(struct svcxprt_rdma *,
+                                            struct rpcrdma_msg *,
+                                            struct rpcrdma_msg *,
+                                            enum rpcrdma_proc);
+extern int svc_rdma_xdr_get_reply_hdr_len(struct rpcrdma_msg *);
+
+/* svc_rdma_recvfrom.c */
+extern int svc_rdma_recvfrom(struct svc_rqst *);
+
+/* svc_rdma_sendto.c */
+extern int svc_rdma_sendto(struct svc_rqst *);
+
+/* svc_rdma_transport.c */
+extern int svc_rdma_send(struct svcxprt_rdma *, struct ib_send_wr *);
+extern int svc_rdma_send_error(struct svcxprt_rdma *, struct rpcrdma_msg *,
+                              enum rpcrdma_errcode);
+struct page *svc_rdma_get_page(void);
+extern int svc_rdma_post_recv(struct svcxprt_rdma *);
+extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *);
+extern struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *);
+extern void svc_rdma_put_context(struct svc_rdma_op_ctxt *, int);
+extern void svc_sq_reap(struct svcxprt_rdma *);
+extern void svc_rq_reap(struct svcxprt_rdma *);
+extern struct svc_xprt_class svc_rdma_class;
+extern void svc_rdma_prep_reply_hdr(struct svc_rqst *);
+
+/* svc_rdma.c */
+extern int svc_rdma_init(void);
+extern void svc_rdma_cleanup(void);
+
+/*
+ * Returns the address of the first read chunk or <nul> if no read chunk is
+ * present
+ */
+static inline struct rpcrdma_read_chunk *
+svc_rdma_get_read_chunk(struct rpcrdma_msg *rmsgp)
+{
+       struct rpcrdma_read_chunk *ch =
+               (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0];
+
+       if (ch->rc_discrim == 0)
+               return NULL;
+
+       return ch;
+}
+
+/*
+ * Returns the address of the first read write array element or <nul> if no
+ * write array list is present
+ */
+static inline struct rpcrdma_write_array *
+svc_rdma_get_write_array(struct rpcrdma_msg *rmsgp)
+{
+       if (rmsgp->rm_body.rm_chunks[0] != 0
+           || rmsgp->rm_body.rm_chunks[1] == 0)
+               return NULL;
+
+       return (struct rpcrdma_write_array *)&rmsgp->rm_body.rm_chunks[1];
+}
+
+/*
+ * Returns the address of the first reply array element or <nul> if no
+ * reply array is present
+ */
+static inline struct rpcrdma_write_array *
+svc_rdma_get_reply_array(struct rpcrdma_msg *rmsgp)
+{
+       struct rpcrdma_read_chunk *rch;
+       struct rpcrdma_write_array *wr_ary;
+       struct rpcrdma_write_array *rp_ary;
+
+       /* XXX: Need to fix when reply list may occur with read-list and/or
+        * write list */
+       if (rmsgp->rm_body.rm_chunks[0] != 0 ||
+           rmsgp->rm_body.rm_chunks[1] != 0)
+               return NULL;
+
+       rch = svc_rdma_get_read_chunk(rmsgp);
+       if (rch) {
+               while (rch->rc_discrim)
+                       rch++;
+
+               /* The reply list follows an empty write array located
+                * at 'rc_position' here. The reply array is at rc_target.
+                */
+               rp_ary = (struct rpcrdma_write_array *)&rch->rc_target;
+
+               goto found_it;
+       }
+
+       wr_ary = svc_rdma_get_write_array(rmsgp);
+       if (wr_ary) {
+               rp_ary = (struct rpcrdma_write_array *)
+                       &wr_ary->
+                       wc_array[wr_ary->wc_nchunks].wc_target.rs_length;
+
+               goto found_it;
+       }
+
+       /* No read list, no write list */
+       rp_ary = (struct rpcrdma_write_array *)
+               &rmsgp->rm_body.rm_chunks[2];
+
+ found_it:
+       if (rp_ary->wc_discrim == 0)
+               return NULL;
+
+       return rp_ary;
+}
+#endif
diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
new file mode 100644 (file)
index 0000000..6fd7b01
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * linux/include/linux/sunrpc/svc_xprt.h
+ *
+ * RPC server transport I/O
+ */
+
+#ifndef SUNRPC_SVC_XPRT_H
+#define SUNRPC_SVC_XPRT_H
+
+#include <linux/sunrpc/svc.h>
+#include <linux/module.h>
+
+struct svc_xprt_ops {
+       struct svc_xprt *(*xpo_create)(struct svc_serv *,
+                                      struct sockaddr *, int,
+                                      int);
+       struct svc_xprt *(*xpo_accept)(struct svc_xprt *);
+       int             (*xpo_has_wspace)(struct svc_xprt *);
+       int             (*xpo_recvfrom)(struct svc_rqst *);
+       void            (*xpo_prep_reply_hdr)(struct svc_rqst *);
+       int             (*xpo_sendto)(struct svc_rqst *);
+       void            (*xpo_release_rqst)(struct svc_rqst *);
+       void            (*xpo_detach)(struct svc_xprt *);
+       void            (*xpo_free)(struct svc_xprt *);
+};
+
+struct svc_xprt_class {
+       const char              *xcl_name;
+       struct module           *xcl_owner;
+       struct svc_xprt_ops     *xcl_ops;
+       struct list_head        xcl_list;
+       u32                     xcl_max_payload;
+};
+
+struct svc_xprt {
+       struct svc_xprt_class   *xpt_class;
+       struct svc_xprt_ops     *xpt_ops;
+       struct kref             xpt_ref;
+       struct list_head        xpt_list;
+       struct list_head        xpt_ready;
+       unsigned long           xpt_flags;
+#define        XPT_BUSY        0               /* enqueued/receiving */
+#define        XPT_CONN        1               /* conn pending */
+#define        XPT_CLOSE       2               /* dead or dying */
+#define        XPT_DATA        3               /* data pending */
+#define        XPT_TEMP        4               /* connected transport */
+#define        XPT_DEAD        6               /* transport closed */
+#define        XPT_CHNGBUF     7               /* need to change snd/rcv buf sizes */
+#define        XPT_DEFERRED    8               /* deferred request pending */
+#define        XPT_OLD         9               /* used for xprt aging mark+sweep */
+#define        XPT_DETACHED    10              /* detached from tempsocks list */
+#define XPT_LISTENER   11              /* listening endpoint */
+#define XPT_CACHE_AUTH 12              /* cache auth info */
+
+       struct svc_pool         *xpt_pool;      /* current pool iff queued */
+       struct svc_serv         *xpt_server;    /* service for transport */
+       atomic_t                xpt_reserved;   /* space on outq that is rsvd */
+       struct mutex            xpt_mutex;      /* to serialize sending data */
+       spinlock_t              xpt_lock;       /* protects sk_deferred
+                                                * and xpt_auth_cache */
+       void                    *xpt_auth_cache;/* auth cache */
+       struct list_head        xpt_deferred;   /* deferred requests that need
+                                                * to be revisted */
+       struct sockaddr_storage xpt_local;      /* local address */
+       size_t                  xpt_locallen;   /* length of address */
+       struct sockaddr_storage xpt_remote;     /* remote peer's address */
+       size_t                  xpt_remotelen;  /* length of address */
+};
+
+int    svc_reg_xprt_class(struct svc_xprt_class *);
+void   svc_unreg_xprt_class(struct svc_xprt_class *);
+void   svc_xprt_init(struct svc_xprt_class *, struct svc_xprt *,
+                     struct svc_serv *);
+int    svc_create_xprt(struct svc_serv *, char *, unsigned short, int);
+void   svc_xprt_enqueue(struct svc_xprt *xprt);
+void   svc_xprt_received(struct svc_xprt *);
+void   svc_xprt_put(struct svc_xprt *xprt);
+void   svc_xprt_copy_addrs(struct svc_rqst *rqstp, struct svc_xprt *xprt);
+void   svc_close_xprt(struct svc_xprt *xprt);
+void   svc_delete_xprt(struct svc_xprt *xprt);
+int    svc_port_is_privileged(struct sockaddr *sin);
+int    svc_print_xprts(char *buf, int maxlen);
+struct svc_xprt *svc_find_xprt(struct svc_serv *, char *, int, int);
+int    svc_xprt_names(struct svc_serv *serv, char *buf, int buflen);
+
+static inline void svc_xprt_get(struct svc_xprt *xprt)
+{
+       kref_get(&xprt->xpt_ref);
+}
+static inline void svc_xprt_set_local(struct svc_xprt *xprt,
+                                     struct sockaddr *sa, int salen)
+{
+       memcpy(&xprt->xpt_local, sa, salen);
+       xprt->xpt_locallen = salen;
+}
+static inline void svc_xprt_set_remote(struct svc_xprt *xprt,
+                                      struct sockaddr *sa, int salen)
+{
+       memcpy(&xprt->xpt_remote, sa, salen);
+       xprt->xpt_remotelen = salen;
+}
+static inline unsigned short svc_addr_port(struct sockaddr *sa)
+{
+       unsigned short ret = 0;
+       switch (sa->sa_family) {
+       case AF_INET:
+               ret = ntohs(((struct sockaddr_in *)sa)->sin_port);
+               break;
+       case AF_INET6:
+               ret = ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
+               break;
+       }
+       return ret;
+}
+
+static inline size_t svc_addr_len(struct sockaddr *sa)
+{
+       switch (sa->sa_family) {
+       case AF_INET:
+               return sizeof(struct sockaddr_in);
+       case AF_INET6:
+               return sizeof(struct sockaddr_in6);
+       }
+       return -EAFNOSUPPORT;
+}
+
+static inline unsigned short svc_xprt_local_port(struct svc_xprt *xprt)
+{
+       return svc_addr_port((struct sockaddr *)&xprt->xpt_local);
+}
+
+static inline unsigned short svc_xprt_remote_port(struct svc_xprt *xprt)
+{
+       return svc_addr_port((struct sockaddr *)&xprt->xpt_remote);
+}
+
+static inline char *__svc_print_addr(struct sockaddr *addr,
+                                    char *buf, size_t len)
+{
+       switch (addr->sa_family) {
+       case AF_INET:
+               snprintf(buf, len, "%u.%u.%u.%u, port=%u",
+                       NIPQUAD(((struct sockaddr_in *) addr)->sin_addr),
+                       ntohs(((struct sockaddr_in *) addr)->sin_port));
+               break;
+
+       case AF_INET6:
+               snprintf(buf, len, "%x:%x:%x:%x:%x:%x:%x:%x, port=%u",
+                       NIP6(((struct sockaddr_in6 *) addr)->sin6_addr),
+                       ntohs(((struct sockaddr_in6 *) addr)->sin6_port));
+               break;
+
+       default:
+               snprintf(buf, len, "unknown address type: %d", addr->sa_family);
+               break;
+       }
+       return buf;
+}
+#endif /* SUNRPC_SVC_XPRT_H */
index a53e0fa855d2e26f9b2827f616a7f0f9964b00eb..206f092ad4c7dbd09a120352f538141ad9e58977 100644 (file)
 #define SUNRPC_SVCSOCK_H
 
 #include <linux/sunrpc/svc.h>
+#include <linux/sunrpc/svc_xprt.h>
 
 /*
  * RPC server socket.
  */
 struct svc_sock {
-       struct list_head        sk_ready;       /* list of ready sockets */
-       struct list_head        sk_list;        /* list of all sockets */
+       struct svc_xprt         sk_xprt;
        struct socket *         sk_sock;        /* berkeley socket layer */
        struct sock *           sk_sk;          /* INET layer */
 
-       struct svc_pool *       sk_pool;        /* current pool iff queued */
-       struct svc_serv *       sk_server;      /* service for this socket */
-       atomic_t                sk_inuse;       /* use count */
-       unsigned long           sk_flags;
-#define        SK_BUSY         0                       /* enqueued/receiving */
-#define        SK_CONN         1                       /* conn pending */
-#define        SK_CLOSE        2                       /* dead or dying */
-#define        SK_DATA         3                       /* data pending */
-#define        SK_TEMP         4                       /* temp (TCP) socket */
-#define        SK_DEAD         6                       /* socket closed */
-#define        SK_CHNGBUF      7                       /* need to change snd/rcv buffer sizes */
-#define        SK_DEFERRED     8                       /* request on sk_deferred */
-#define        SK_OLD          9                       /* used for temp socket aging mark+sweep */
-#define        SK_DETACHED     10                      /* detached from tempsocks list */
-
-       atomic_t                sk_reserved;    /* space on outq that is reserved */
-
-       spinlock_t              sk_lock;        /* protects sk_deferred and
-                                                * sk_info_authunix */
-       struct list_head        sk_deferred;    /* deferred requests that need to
-                                                * be revisted */
-       struct mutex            sk_mutex;       /* to serialize sending data */
-
-       int                     (*sk_recvfrom)(struct svc_rqst *rqstp);
-       int                     (*sk_sendto)(struct svc_rqst *rqstp);
-
        /* We keep the old state_change and data_ready CB's here */
        void                    (*sk_ostate)(struct sock *);
        void                    (*sk_odata)(struct sock *, int bytes);
@@ -54,21 +28,12 @@ struct svc_sock {
        /* private TCP part */
        int                     sk_reclen;      /* length of record */
        int                     sk_tcplen;      /* current read length */
-       time_t                  sk_lastrecv;    /* time of last received request */
-
-       /* cache of various info for TCP sockets */
-       void                    *sk_info_authunix;
-
-       struct sockaddr_storage sk_local;       /* local address */
-       struct sockaddr_storage sk_remote;      /* remote peer's address */
-       int                     sk_remotelen;   /* length of address */
 };
 
 /*
  * Function prototypes.
  */
-int            svc_makesock(struct svc_serv *, int, unsigned short, int flags);
-void           svc_force_close_socket(struct svc_sock *);
+void           svc_close_all(struct list_head *);
 int            svc_recv(struct svc_rqst *, long);
 int            svc_send(struct svc_rqst *);
 void           svc_drop(struct svc_rqst *);
@@ -78,6 +43,8 @@ int           svc_addsock(struct svc_serv *serv,
                            int fd,
                            char *name_return,
                            int *proto);
+void           svc_init_xprt_sock(void);
+void           svc_cleanup_xprt_sock(void);
 
 /*
  * svc_makesock socket characteristics
index 0751c9464d0f84ff7291c7ca332c65dbde383cee..e4057d729f036c8a3b80e3100a704e03ef0c6d4a 100644 (file)
@@ -112,7 +112,8 @@ struct xdr_buf {
 __be32 *xdr_encode_opaque_fixed(__be32 *p, const void *ptr, unsigned int len);
 __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int len);
 __be32 *xdr_encode_string(__be32 *p, const char *s);
-__be32 *xdr_decode_string_inplace(__be32 *p, char **sp, int *lenp, int maxlen);
+__be32 *xdr_decode_string_inplace(__be32 *p, char **sp, unsigned int *lenp,
+                       unsigned int maxlen);
 __be32 *xdr_encode_netobj(__be32 *p, const struct xdr_netobj *);
 __be32 *xdr_decode_netobj(__be32 *p, struct xdr_netobj *);
 
index 40280df2a3dbc5d91d61291f8793f3d98b989cbc..1d7d4c5797ee93c37ab2d7f035f26fa114649a3f 100644 (file)
@@ -38,18 +38,16 @@ typedef int __bitwise suspend_state_t;
  *     There is the %suspend_valid_only_mem function available that can be
  *     assigned to this if the platform only supports mem sleep.
  *
- * @set_target: Tell the platform which system sleep state is going to be
- *     entered.
- *     @set_target() is executed right prior to suspending devices.  The
- *     information conveyed to the platform code by @set_target() should be
- *     disregarded by the platform as soon as @finish() is executed and if
- *     @prepare() fails.  If @set_target() fails (ie. returns nonzero),
+ * @begin: Initialise a transition to given system sleep state.
+ *     @begin() is executed right prior to suspending devices.  The information
+ *     conveyed to the platform code by @begin() should be disregarded by it as
+ *     soon as @end() is executed.  If @begin() fails (ie. returns nonzero),
  *     @prepare(), @enter() and @finish() will not be called by the PM core.
  *     This callback is optional.  However, if it is implemented, the argument
- *     passed to @enter() is meaningless and should be ignored.
+ *     passed to @enter() is redundant and should be ignored.
  *
  * @prepare: Prepare the platform for entering the system sleep state indicated
- *     by @set_target().
+ *     by @begin().
  *     @prepare() is called right after devices have been suspended (ie. the
  *     appropriate .suspend() method has been executed for each device) and
  *     before the nonboot CPUs are disabled (it is executed with IRQs enabled).
@@ -57,8 +55,8 @@ typedef int __bitwise suspend_state_t;
  *     error code otherwise, in which case the system cannot enter the desired
  *     sleep state (@enter() and @finish() will not be called in that case).
  *
- * @enter: Enter the system sleep state indicated by @set_target() or
- *     represented by the argument if @set_target() is not implemented.
+ * @enter: Enter the system sleep state indicated by @begin() or represented by
+ *     the argument if @begin() is not implemented.
  *     This callback is mandatory.  It returns 0 on success or a negative
  *     error code otherwise, in which case the system cannot enter the desired
  *     sleep state.
@@ -69,13 +67,22 @@ typedef int __bitwise suspend_state_t;
  *     This callback is optional, but should be implemented by the platforms
  *     that implement @prepare().  If implemented, it is always called after
  *     @enter() (even if @enter() fails).
+ *
+ * @end: Called by the PM core right after resuming devices, to indicate to
+ *     the platform that the system has returned to the working state or
+ *     the transition to the sleep state has been aborted.
+ *     This callback is optional, but should be implemented by the platforms
+ *     that implement @begin(), but platforms implementing @begin() should
+ *     also provide a @end() which cleans up transitions aborted before
+ *     @enter().
  */
 struct platform_suspend_ops {
        int (*valid)(suspend_state_t state);
-       int (*set_target)(suspend_state_t state);
+       int (*begin)(suspend_state_t state);
        int (*prepare)(void);
        int (*enter)(suspend_state_t state);
        void (*finish)(void);
+       void (*end)(void);
 };
 
 #ifdef CONFIG_SUSPEND
@@ -123,20 +130,22 @@ struct pbe {
 };
 
 /* mm/page_alloc.c */
-extern void drain_local_pages(void);
 extern void mark_free_pages(struct zone *zone);
 
 /**
  * struct platform_hibernation_ops - hibernation platform support
  *
- * The methods in this structure allow a platform to override the default
- * mechanism of shutting down the machine during a hibernation transition.
+ * The methods in this structure allow a platform to carry out special
+ * operations required by it during a hibernation transition.
  *
- * All three methods must be assigned.
+ * All the methods below must be implemented.
  *
- * @start: Tell the platform driver that we're starting hibernation.
+ * @begin: Tell the platform driver that we're starting hibernation.
  *     Called right after shrinking memory and before freezing devices.
  *
+ * @end: Called by the PM core right after resuming devices, to indicate to
+ *     the platform that the system has returned to the working state.
+ *
  * @pre_snapshot: Prepare the platform for creating the hibernation image.
  *     Called right after devices have been frozen and before the nonboot
  *     CPUs are disabled (runs with IRQs on).
@@ -171,7 +180,8 @@ extern void mark_free_pages(struct zone *zone);
  *     thawing devices (runs with IRQs on).
  */
 struct platform_hibernation_ops {
-       int (*start)(void);
+       int (*begin)(void);
+       void (*end)(void);
        int (*pre_snapshot)(void);
        void (*finish)(void);
        int (*prepare)(void);
@@ -213,17 +223,8 @@ void save_processor_state(void);
 void restore_processor_state(void);
 
 /* kernel/power/main.c */
-extern struct blocking_notifier_head pm_chain_head;
-
-static inline int register_pm_notifier(struct notifier_block *nb)
-{
-       return blocking_notifier_chain_register(&pm_chain_head, nb);
-}
-
-static inline int unregister_pm_notifier(struct notifier_block *nb)
-{
-       return blocking_notifier_chain_unregister(&pm_chain_head, nb);
-}
+extern int register_pm_notifier(struct notifier_block *nb);
+extern int unregister_pm_notifier(struct notifier_block *nb);
 
 #define pm_notifier(fn, pri) {                         \
        static struct notifier_block fn##_nb =                  \
diff --git a/include/linux/suspend_ioctls.h b/include/linux/suspend_ioctls.h
new file mode 100644 (file)
index 0000000..2c6faec
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef _LINUX_SUSPEND_IOCTLS_H
+#define _LINUX_SUSPEND_IOCTLS_H
+
+/*
+ * This structure is used to pass the values needed for the identification
+ * of the resume swap area from a user space to the kernel via the
+ * SNAPSHOT_SET_SWAP_AREA ioctl
+ */
+struct resume_swap_area {
+       loff_t offset;
+       u_int32_t dev;
+} __attribute__((packed));
+
+#define SNAPSHOT_IOC_MAGIC     '3'
+#define SNAPSHOT_FREEZE                        _IO(SNAPSHOT_IOC_MAGIC, 1)
+#define SNAPSHOT_UNFREEZE              _IO(SNAPSHOT_IOC_MAGIC, 2)
+#define SNAPSHOT_ATOMIC_RESTORE                _IO(SNAPSHOT_IOC_MAGIC, 4)
+#define SNAPSHOT_FREE                  _IO(SNAPSHOT_IOC_MAGIC, 5)
+#define SNAPSHOT_FREE_SWAP_PAGES       _IO(SNAPSHOT_IOC_MAGIC, 9)
+#define SNAPSHOT_S2RAM                 _IO(SNAPSHOT_IOC_MAGIC, 11)
+#define SNAPSHOT_SET_SWAP_AREA         _IOW(SNAPSHOT_IOC_MAGIC, 13, \
+                                                       struct resume_swap_area)
+#define SNAPSHOT_GET_IMAGE_SIZE                _IOR(SNAPSHOT_IOC_MAGIC, 14, loff_t)
+#define SNAPSHOT_PLATFORM_SUPPORT      _IO(SNAPSHOT_IOC_MAGIC, 15)
+#define SNAPSHOT_POWER_OFF             _IO(SNAPSHOT_IOC_MAGIC, 16)
+#define SNAPSHOT_CREATE_IMAGE          _IOW(SNAPSHOT_IOC_MAGIC, 17, int)
+#define SNAPSHOT_PREF_IMAGE_SIZE       _IO(SNAPSHOT_IOC_MAGIC, 18)
+#define SNAPSHOT_AVAIL_SWAP_SIZE       _IOR(SNAPSHOT_IOC_MAGIC, 19, loff_t)
+#define SNAPSHOT_ALLOC_SWAP_PAGE       _IOR(SNAPSHOT_IOC_MAGIC, 20, loff_t)
+#define SNAPSHOT_IOC_MAXNR     20
+
+#endif /* _LINUX_SUSPEND_IOCTLS_H */
index 4f3838adbb30626ec0e4df84a145e95f091b2aa6..353153ea0bd5cc88ba03ab48959cc0a281a95e8b 100644 (file)
@@ -158,9 +158,6 @@ struct swap_list_t {
 /* Swap 50% full? Release swapcache more aggressively.. */
 #define vm_swap_full() (nr_swap_pages*2 < total_swap_pages)
 
-/* linux/mm/memory.c */
-extern void swapin_readahead(swp_entry_t, unsigned long, struct vm_area_struct *);
-
 /* linux/mm/page_alloc.c */
 extern unsigned long totalram_pages;
 extern unsigned long totalreserve_pages;
@@ -223,16 +220,17 @@ extern struct address_space swapper_space;
 #define total_swapcache_pages  swapper_space.nrpages
 extern void show_swap_cache_info(void);
 extern int add_to_swap(struct page *, gfp_t);
+extern int add_to_swap_cache(struct page *, swp_entry_t, gfp_t);
 extern void __delete_from_swap_cache(struct page *);
 extern void delete_from_swap_cache(struct page *);
-extern int move_to_swap_cache(struct page *, swp_entry_t);
-extern int move_from_swap_cache(struct page *, unsigned long,
-               struct address_space *);
 extern void free_page_and_swap_cache(struct page *);
 extern void free_pages_and_swap_cache(struct page **, int);
-extern struct page * lookup_swap_cache(swp_entry_t);
-extern struct page * read_swap_cache_async(swp_entry_t, struct vm_area_struct *vma,
-                                          unsigned long addr);
+extern struct page *lookup_swap_cache(swp_entry_t);
+extern struct page *read_swap_cache_async(swp_entry_t, gfp_t,
+                       struct vm_area_struct *vma, unsigned long addr);
+extern struct page *swapin_readahead(swp_entry_t, gfp_t,
+                       struct vm_area_struct *vma, unsigned long addr);
+
 /* linux/mm/swapfile.c */
 extern long total_swap_pages;
 extern unsigned int nr_swapfiles;
@@ -306,7 +304,7 @@ static inline void swap_free(swp_entry_t swp)
 {
 }
 
-static inline struct page *read_swap_cache_async(swp_entry_t swp,
+static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
                        struct vm_area_struct *vma, unsigned long addr)
 {
        return NULL;
@@ -317,22 +315,12 @@ static inline struct page *lookup_swap_cache(swp_entry_t swp)
        return NULL;
 }
 
-static inline int valid_swaphandles(swp_entry_t entry, unsigned long *offset)
-{
-       return 0;
-}
-
 #define can_share_swap_page(p)                 (page_mapcount(p) == 1)
 
-static inline int move_to_swap_cache(struct page *page, swp_entry_t entry)
-{
-       return 1;
-}
-
-static inline int move_from_swap_cache(struct page *page, unsigned long index,
-                                       struct address_space *mapping)
+static inline int add_to_swap_cache(struct page *page, swp_entry_t entry,
+                                                       gfp_t gfp_mask)
 {
-       return 1;
+       return -1;
 }
 
 static inline void __delete_from_swap_cache(struct page *page)
index ceb6cc5ceebbee56b69107daad587c512987794f..7bf2d149d209615be247da2dadc4385f37636be5 100644 (file)
@@ -42,6 +42,12 @@ static inline pgoff_t swp_offset(swp_entry_t entry)
        return entry.val & SWP_OFFSET_MASK(entry);
 }
 
+/* check whether a pte points to a swap entry */
+static inline int is_swap_pte(pte_t pte)
+{
+       return !pte_none(pte) && !pte_present(pte) && !pte_file(pte);
+}
+
 /*
  * Convert the arch-dependent pte representation of a swp_entry_t into an
  * arch-independent swp_entry_t.
index 61def7c8fbb3c750677458d1d4e8a4f347e5beac..4c2577bd1c859c332821b2be75a378010d258c46 100644 (file)
@@ -607,8 +607,11 @@ asmlinkage long sys_set_robust_list(struct robust_list_head __user *head,
                                    size_t len);
 asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct getcpu_cache __user *cache);
 asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask);
-asmlinkage long sys_timerfd(int ufd, int clockid, int flags,
-                           const struct itimerspec __user *utmr);
+asmlinkage long sys_timerfd_create(int clockid, int flags);
+asmlinkage long sys_timerfd_settime(int ufd, int flags,
+                                   const struct itimerspec __user *utmr,
+                                   struct itimerspec __user *otmr);
+asmlinkage long sys_timerfd_gettime(int ufd, struct itimerspec __user *otmr);
 asmlinkage long sys_eventfd(unsigned int count);
 asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
 
index bf4ae4e138f747d79c2903b7a09771f5145112c4..571f01d20a86373454000db25760f7a7aa2572da 100644 (file)
@@ -102,7 +102,6 @@ enum
        KERN_NODENAME=7,
        KERN_DOMAINNAME=8,
 
-       KERN_CAP_BSET=14,       /* int: capability bounding set */
        KERN_PANIC=15,          /* int: panic timeout */
        KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
 
@@ -965,8 +964,6 @@ extern int proc_dostring(struct ctl_table *, int, struct file *,
                         void __user *, size_t *, loff_t *);
 extern int proc_dointvec(struct ctl_table *, int, struct file *,
                         void __user *, size_t *, loff_t *);
-extern int proc_dointvec_bset(struct ctl_table *, int, struct file *,
-                             void __user *, size_t *, loff_t *);
 extern int proc_dointvec_minmax(struct ctl_table *, int, struct file *,
                                void __user *, size_t *, loff_t *);
 extern int proc_dointvec_jiffies(struct ctl_table *, int, struct file *,
index e21937cf91d0e4510659566215260b13a9c9b6b8..c50d2ba5caf004ea9b8a33a12d27fa859a4e4864 100644 (file)
@@ -81,6 +81,7 @@ enum
        TCF_META_ID_SK_SNDTIMEO,
        TCF_META_ID_SK_SENDMSG_OFF,
        TCF_META_ID_SK_WRITE_PENDING,
+       TCF_META_ID_VLAN_TAG,
        __TCF_META_ID_MAX
 };
 #define TCF_META_ID_MAX (__TCF_META_ID_MAX - 1)
index 24c6a2b59511edbe9ba01d22ba265a202645bed7..8ea3e71ba7fa8ff17d8de5587f482450c349ef36 100644 (file)
@@ -244,6 +244,8 @@ extern int do_adjtimex(struct timex *);
 /* Don't use! Compatibility define for existing users. */
 #define tickadj        (500/HZ ? : 1)
 
+int read_current_timer(unsigned long *timer_val);
+
 #endif /* KERNEL */
 
 #endif /* LINUX_TIMEX_H */
index 402de892b3edcdd0ae3bbf16892100e5c5570915..5824a9777ad7d39cc13a67910936cafbb2cce178 100644 (file)
@@ -74,7 +74,6 @@ struct tty_buffer {
 
 struct tty_bufhead {
        struct delayed_work work;
-       struct semaphore pty_sem;
        spinlock_t lock;
        struct tty_buffer *head;        /* Queue head */
        struct tty_buffer *tail;        /* Active buffer */
index 5fc8ff73b7bbcd445ff7425f0cf459d94f08802e..2372e2e6b5271addb820c2c30f0f2549fe340134 100644 (file)
@@ -162,19 +162,19 @@ struct usb_interface {
        unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */
 
        struct device dev;              /* interface specific device info */
-       struct device *usb_dev;         /* pointer to the usb class's device, if any */
+       struct device *usb_dev;
        int pm_usage_cnt;               /* usage counter for autosuspend */
 };
 #define        to_usb_interface(d) container_of(d, struct usb_interface, dev)
 #define        interface_to_usbdev(intf) \
        container_of(intf->dev.parent, struct usb_device, dev)
 
-static inline void *usb_get_intfdata (struct usb_interface *intf)
+static inline void *usb_get_intfdata(struct usb_interface *intf)
 {
-       return dev_get_drvdata (&intf->dev);
+       return dev_get_drvdata(&intf->dev);
 }
 
-static inline void usb_set_intfdata (struct usb_interface *intf, void *data)
+static inline void usb_set_intfdata(struct usb_interface *intf, void *data)
 {
        dev_set_drvdata(&intf->dev, data);
 }
@@ -275,9 +275,10 @@ struct usb_host_config {
 
 int __usb_get_extra_descriptor(char *buffer, unsigned size,
        unsigned char type, void **ptr);
-#define usb_get_extra_descriptor(ifpoint,type,ptr)\
-       __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,\
-               type,(void**)ptr)
+#define usb_get_extra_descriptor(ifpoint, type, ptr) \
+                               __usb_get_extra_descriptor((ifpoint)->extra, \
+                               (ifpoint)->extralen, \
+                               type, (void **)ptr)
 
 /* ----------------------------------------------------------------------- */
 
@@ -318,7 +319,7 @@ struct usb_bus {
 #ifdef CONFIG_USB_DEVICEFS
        struct dentry *usbfs_dentry;    /* usbfs dentry entry for the bus */
 #endif
-       struct class_device *class_dev; /* class device for this bus */
+       struct device *dev;             /* device for this bus */
 
 #if defined(CONFIG_USB_MON)
        struct mon_bus *mon_bus;        /* non-null when associated */
@@ -388,7 +389,7 @@ struct usb_device {
        unsigned can_submit:1;          /* URBs may be submitted */
        unsigned discon_suspended:1;    /* Disconnected while suspended */
        unsigned have_langid:1;         /* whether string_langid is valid */
-       unsigned authorized:1;          /* Policy has determined we can use it */
+       unsigned authorized:1;          /* Policy has said we can use it */
        unsigned wusb:1;                /* Device is Wireless USB */
        int string_langid;              /* language ID for strings */
 
@@ -417,7 +418,10 @@ struct usb_device {
 
        int pm_usage_cnt;               /* usage counter for autosuspend */
        u32 quirks;                     /* quirks of the whole device */
-       atomic_t urbnum;                /* number of URBs submitted for the whole device */
+       atomic_t urbnum;                /* number of URBs submitted for
+                                          the whole device */
+
+       unsigned long active_duration;  /* total time device is not suspended */
 
 #ifdef CONFIG_PM
        struct delayed_work autosuspend; /* for delayed autosuspends */
@@ -425,6 +429,7 @@ struct usb_device {
 
        unsigned long last_busy;        /* time of last use */
        int autosuspend_delay;          /* in jiffies */
+       unsigned long connect_time;     /* time device was first connected */
 
        unsigned auto_pm:1;             /* autosuspend/resume in progress */
        unsigned do_remote_wakeup:1;    /* remote wakeup should be enabled */
@@ -498,11 +503,11 @@ static inline void usb_mark_last_busy(struct usb_device *udev)
 /*-------------------------------------------------------------------------*/
 
 /* for drivers using iso endpoints */
-extern int usb_get_current_frame_number (struct usb_device *usb_dev);
+extern int usb_get_current_frame_number(struct usb_device *usb_dev);
 
 /* used these for multi-interface device registration */
 extern int usb_driver_claim_interface(struct usb_driver *driver,
-                       struct usb_interface *iface, voidpriv);
+                       struct usb_interface *iface, void *priv);
 
 /**
  * usb_interface_claimed - returns true iff an interface is claimed
@@ -514,7 +519,8 @@ extern int usb_driver_claim_interface(struct usb_driver *driver,
  * may need to explicitly claim that lock.
  *
  */
-static inline int usb_interface_claimed(struct usb_interface *iface) {
+static inline int usb_interface_claimed(struct usb_interface *iface)
+{
        return (iface->dev.driver != NULL);
 }
 
@@ -557,12 +563,11 @@ extern struct usb_host_interface *usb_altnum_to_altsetting(
  * USB 2.0 root hubs (EHCI host controllers) will get one path ID if they are
  * high speed, and a different one if they are full or low speed.
  */
-static inline int usb_make_path (struct usb_device *dev, char *buf,
-               size_t size)
+static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size)
 {
        int actual;
-       actual = snprintf (buf, size, "usb-%s-%s", dev->bus->bus_name,
-                       dev->devpath);
+       actual = snprintf(buf, size, "usb-%s-%s", dev->bus->bus_name,
+                         dev->devpath);
        return (actual >= (int)size) ? -1 : actual;
 }
 
@@ -608,7 +613,8 @@ static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
  *
  * Returns true if the endpoint is of type OUT, otherwise it returns false.
  */
-static inline int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_dir_out(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
 }
@@ -619,7 +625,8 @@ static inline int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd
  *
  * Returns true if the endpoint is of type bulk, otherwise it returns false.
  */
-static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_xfer_bulk(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
                USB_ENDPOINT_XFER_BULK);
@@ -631,7 +638,8 @@ static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *e
  *
  * Returns true if the endpoint is of type control, otherwise it returns false.
  */
-static inline int usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_xfer_control(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
                USB_ENDPOINT_XFER_CONTROL);
@@ -644,7 +652,8 @@ static inline int usb_endpoint_xfer_control(const struct usb_endpoint_descriptor
  * Returns true if the endpoint is of type interrupt, otherwise it returns
  * false.
  */
-static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_xfer_int(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
                USB_ENDPOINT_XFER_INT);
@@ -657,7 +666,8 @@ static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *ep
  * Returns true if the endpoint is of type isochronous, otherwise it returns
  * false.
  */
-static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_xfer_isoc(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
                USB_ENDPOINT_XFER_ISOC);
@@ -670,7 +680,8 @@ static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *e
  * Returns true if the endpoint has bulk transfer type and IN direction,
  * otherwise it returns false.
  */
-static inline int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_is_bulk_in(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
 }
@@ -682,7 +693,8 @@ static inline int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *
  * Returns true if the endpoint has bulk transfer type and OUT direction,
  * otherwise it returns false.
  */
-static inline int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_is_bulk_out(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
 }
@@ -694,7 +706,8 @@ static inline int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor
  * Returns true if the endpoint has interrupt transfer type and IN direction,
  * otherwise it returns false.
  */
-static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_is_int_in(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
 }
@@ -706,7 +719,8 @@ static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *e
  * Returns true if the endpoint has interrupt transfer type and OUT direction,
  * otherwise it returns false.
  */
-static inline int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_is_int_out(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
 }
@@ -718,7 +732,8 @@ static inline int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *
  * Returns true if the endpoint has isochronous transfer type and IN direction,
  * otherwise it returns false.
  */
-static inline int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_is_isoc_in(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
 }
@@ -730,7 +745,8 @@ static inline int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *
  * Returns true if the endpoint has isochronous transfer type and OUT direction,
  * otherwise it returns false.
  */
-static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd)
+static inline int usb_endpoint_is_isoc_out(
+                               const struct usb_endpoint_descriptor *epd)
 {
        return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
 }
@@ -761,8 +777,9 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor
  * specific device.
  */
 #define USB_DEVICE(vend,prod) \
-       .match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = (vend), \
-                       .idProduct = (prod)
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
+       .idVendor = (vend), \
+       .idProduct = (prod)
 /**
  * USB_DEVICE_VER - macro used to describe a specific usb device with a
  *             version range
@@ -774,10 +791,12 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor
  * This macro is used to create a struct usb_device_id that matches a
  * specific device, with a version range.
  */
-#define USB_DEVICE_VER(vend,prod,lo,hi) \
+#define USB_DEVICE_VER(vend, prod, lo, hi) \
        .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \
-       .idVendor = (vend), .idProduct = (prod), \
-       .bcdDevice_lo = (lo), .bcdDevice_hi = (hi)
+       .idVendor = (vend), \
+       .idProduct = (prod), \
+       .bcdDevice_lo = (lo), \
+       .bcdDevice_hi = (hi)
 
 /**
  * USB_DEVICE_INTERFACE_PROTOCOL - macro used to describe a usb
@@ -789,8 +808,9 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor
  * This macro is used to create a struct usb_device_id that matches a
  * specific interface protocol of devices.
  */
-#define USB_DEVICE_INTERFACE_PROTOCOL(vend,prod,pr) \
-       .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
+#define USB_DEVICE_INTERFACE_PROTOCOL(vend, prod, pr) \
+       .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+                      USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
        .idVendor = (vend), \
        .idProduct = (prod), \
        .bInterfaceProtocol = (pr)
@@ -804,12 +824,14 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor
  * This macro is used to create a struct usb_device_id that matches a
  * specific class of devices.
  */
-#define USB_DEVICE_INFO(cl,sc,pr) \
-       .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, .bDeviceClass = (cl), \
-       .bDeviceSubClass = (sc), .bDeviceProtocol = (pr)
+#define USB_DEVICE_INFO(cl, sc, pr) \
+       .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, \
+       .bDeviceClass = (cl), \
+       .bDeviceSubClass = (sc), \
+       .bDeviceProtocol = (pr)
 
 /**
- * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces 
+ * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces
  * @cl: bInterfaceClass value
  * @sc: bInterfaceSubClass value
  * @pr: bInterfaceProtocol value
@@ -817,9 +839,11 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor
  * This macro is used to create a struct usb_device_id that matches a
  * specific class of interfaces.
  */
-#define USB_INTERFACE_INFO(cl,sc,pr) \
-       .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, .bInterfaceClass = (cl), \
-       .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr)
+#define USB_INTERFACE_INFO(cl, sc, pr) \
+       .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \
+       .bInterfaceClass = (cl), \
+       .bInterfaceSubClass = (sc), \
+       .bInterfaceProtocol = (pr)
 
 /**
  * USB_DEVICE_AND_INTERFACE_INFO - macro used to describe a specific usb device
@@ -836,12 +860,14 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor
  * This is especially useful when explicitly matching devices that have
  * vendor specific bDeviceClass values, but standards-compliant interfaces.
  */
-#define USB_DEVICE_AND_INTERFACE_INFO(vend,prod,cl,sc,pr) \
+#define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \
        .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
                | USB_DEVICE_ID_MATCH_DEVICE, \
-       .idVendor = (vend), .idProduct = (prod), \
+       .idVendor = (vend), \
+       .idProduct = (prod), \
        .bInterfaceClass = (cl), \
-       .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr)
+       .bInterfaceSubClass = (sc), \
+       .bInterfaceProtocol = (pr)
 
 /* ----------------------------------------------------------------------- */
 
@@ -1119,7 +1145,7 @@ typedef void (*usb_complete_t)(struct urb *);
  *     transferred.  It will normally be the same as requested, unless
  *     either an error was reported or a short read was performed.
  *     The URB_SHORT_NOT_OK transfer flag may be used to make such
- *     short reads be reported as errors. 
+ *     short reads be reported as errors.
  * @setup_packet: Only used for control transfers, this points to eight bytes
  *     of setup data.  Control transfers always start by sending this data
  *     to the device.  Then transfer_buffer is read or written, if needed.
@@ -1138,7 +1164,7 @@ typedef void (*usb_complete_t)(struct urb *);
  * @complete: Completion handler. This URB is passed as the parameter to the
  *     completion function.  The completion function may then do what
  *     it likes with the URB, including resubmitting or freeing it.
- * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to 
+ * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to
  *     collect the transfer status for each buffer.
  *
  * This structure identifies USB transfer requests.  URBs must be allocated by
@@ -1242,8 +1268,7 @@ typedef void (*usb_complete_t)(struct urb *);
  * when the urb is owned by the hcd, that is, since the call to
  * usb_submit_urb() till the entry into the completion routine.
  */
-struct urb
-{
+struct urb {
        /* private: usb core and host controller only fields in the urb */
        struct kref kref;               /* reference count of the URB */
        void *hcpriv;                   /* private data for host controller */
@@ -1254,10 +1279,10 @@ struct urb
        /* public: documented fields in the urb that can be used by drivers */
        struct list_head urb_list;      /* list head for use by the urb's
                                         * current owner */
-       struct list_head anchor_list;   /* the URB may be anchored by the driver */
+       struct list_head anchor_list;   /* the URB may be anchored */
        struct usb_anchor *anchor;
        struct usb_device *dev;         /* (in) pointer to associated device */
-       struct usb_host_endpoint *ep;   /* (internal) pointer to endpoint struct */
+       struct usb_host_endpoint *ep;   /* (internal) pointer to endpoint */
        unsigned int pipe;              /* (in) pipe information */
        int status;                     /* (return) non-ISO status */
        unsigned int transfer_flags;    /* (in) URB_SHORT_NOT_OK | ...*/
@@ -1294,14 +1319,14 @@ struct urb
  * Initializes a control urb with the proper information needed to submit
  * it to a device.
  */
-static inline void usb_fill_control_urb (struct urb *urb,
-                                        struct usb_device *dev,
-                                        unsigned int pipe,
-                                        unsigned char *setup_packet,
-                                        void *transfer_buffer,
-                                        int buffer_length,
-                                        usb_complete_t complete_fn,
-                                        void *context)
+static inline void usb_fill_control_urb(struct urb *urb,
+                                       struct usb_device *dev,
+                                       unsigned int pipe,
+                                       unsigned char *setup_packet,
+                                       void *transfer_buffer,
+                                       int buffer_length,
+                                       usb_complete_t complete_fn,
+                                       void *context)
 {
        urb->dev = dev;
        urb->pipe = pipe;
@@ -1325,13 +1350,13 @@ static inline void usb_fill_control_urb (struct urb *urb,
  * Initializes a bulk urb with the proper information needed to submit it
  * to a device.
  */
-static inline void usb_fill_bulk_urb (struct urb *urb,
-                                     struct usb_device *dev,
-                                     unsigned int pipe,
-                                     void *transfer_buffer,
-                                     int buffer_length,
-                                     usb_complete_t complete_fn,
-                                     void *context)
+static inline void usb_fill_bulk_urb(struct urb *urb,
+                                    struct usb_device *dev,
+                                    unsigned int pipe,
+                                    void *transfer_buffer,
+                                    int buffer_length,
+                                    usb_complete_t complete_fn,
+                                    void *context)
 {
        urb->dev = dev;
        urb->pipe = pipe;
@@ -1359,14 +1384,14 @@ static inline void usb_fill_bulk_urb (struct urb *urb,
  * the endpoint interval, and express polling intervals in microframes
  * (eight per millisecond) rather than in frames (one per millisecond).
  */
-static inline void usb_fill_int_urb (struct urb *urb,
-                                    struct usb_device *dev,
-                                    unsigned int pipe,
-                                    void *transfer_buffer,
-                                    int buffer_length,
-                                    usb_complete_t complete_fn,
-                                    void *context,
-                                    int interval)
+static inline void usb_fill_int_urb(struct urb *urb,
+                                   struct usb_device *dev,
+                                   unsigned int pipe,
+                                   void *transfer_buffer,
+                                   int buffer_length,
+                                   usb_complete_t complete_fn,
+                                   void *context,
+                                   int interval)
 {
        urb->dev = dev;
        urb->pipe = pipe;
@@ -1419,15 +1444,15 @@ static inline int usb_urb_dir_out(struct urb *urb)
        return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT;
 }
 
-void *usb_buffer_alloc (struct usb_device *dev, size_t size,
+void *usb_buffer_alloc(struct usb_device *dev, size_t size,
        gfp_t mem_flags, dma_addr_t *dma);
-void usb_buffer_free (struct usb_device *dev, size_t size,
+void usb_buffer_free(struct usb_device *dev, size_t size,
        void *addr, dma_addr_t dma);
 
 #if 0
-struct urb *usb_buffer_map (struct urb *urb);
-void usb_buffer_dmasync (struct urb *urb);
-void usb_buffer_unmap (struct urb *urb);
+struct urb *usb_buffer_map(struct urb *urb);
+void usb_buffer_dmasync(struct urb *urb);
+void usb_buffer_unmap(struct urb *urb);
 #endif
 
 struct scatterlist;
@@ -1499,7 +1524,7 @@ struct usb_sg_request {
        int                     status;
        size_t                  bytes;
 
-       /* 
+       /*
         * members below are private: to usbcore,
         * and are not provided for driver access!
         */
@@ -1517,18 +1542,18 @@ struct usb_sg_request {
        struct completion       complete;
 };
 
-int usb_sg_init (
+int usb_sg_init(
        struct usb_sg_request   *io,
        struct usb_device       *dev,
-       unsigned                pipe, 
+       unsigned                pipe,
        unsigned                period,
        struct scatterlist      *sg,
        int                     nents,
        size_t                  length,
        gfp_t                   mem_flags
 );
-void usb_sg_cancel (struct usb_sg_request *io);
-void usb_sg_wait (struct usb_sg_request *io);
+void usb_sg_cancel(struct usb_sg_request *io);
+void usb_sg_wait(struct usb_sg_request *io);
 
 
 /* ----------------------------------------------------------------------- */
@@ -1585,21 +1610,21 @@ static inline unsigned int __create_pipe(struct usb_device *dev,
 
 /* Create various pipes... */
 #define usb_sndctrlpipe(dev,endpoint)  \
-       ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
+       ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint))
 #define usb_rcvctrlpipe(dev,endpoint)  \
-       ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
+       ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
 #define usb_sndisocpipe(dev,endpoint)  \
-       ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
+       ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint))
 #define usb_rcvisocpipe(dev,endpoint)  \
-       ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
+       ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
 #define usb_sndbulkpipe(dev,endpoint)  \
-       ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
+       ((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
 #define usb_rcvbulkpipe(dev,endpoint)  \
-       ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
+       ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
 #define usb_sndintpipe(dev,endpoint)   \
-       ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
+       ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint))
 #define usb_rcvintpipe(dev,endpoint)   \
-       ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
+       ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
 
 /*-------------------------------------------------------------------------*/
 
index 6ce42bf9f743960a97fe95317542d042046dc059..b8cba1dcb2c63008a60f17926c40b3a5b728cc9c 100644 (file)
@@ -1,6 +1,7 @@
-unifdef-y += audio.h
-unifdef-y += cdc.h
-unifdef-y += ch9.h
-unifdef-y += gadgetfs.h
-unifdef-y += midi.h
+header-y += audio.h
+header-y += cdc.h
+header-y += ch9.h
+header-y += gadgetfs.h
+header-y += midi.h
+unifdef-y += g_printer.h
 
index 6bd235994dc2f7d25d12f78da6dfc95feea95eeb..2dfeef16b221d4605f2090de430e4f196c9d8712 100644 (file)
 
 /* 4.3.2  Class-Specific AC Interface Descriptor */
 struct usb_ac_header_descriptor {
-       __u8  bLength;                  // 8+n
-       __u8  bDescriptorType;          // USB_DT_CS_INTERFACE
-       __u8  bDescriptorSubtype;       // USB_MS_HEADER
-       __le16 bcdADC;                  // 0x0100
-       __le16 wTotalLength;            // includes Unit and Terminal desc.
-       __u8  bInCollection;            // n
-       __u8  baInterfaceNr[];          // [n]
+       __u8  bLength;                  /* 8+n */
+       __u8  bDescriptorType;          /* USB_DT_CS_INTERFACE */
+       __u8  bDescriptorSubtype;       /* USB_MS_HEADER */
+       __le16 bcdADC;                  /* 0x0100 */
+       __le16 wTotalLength;            /* includes Unit and Terminal desc. */
+       __u8  bInCollection;            /* n */
+       __u8  baInterfaceNr[];          /* [n] */
 } __attribute__ ((packed));
 
 #define USB_DT_AC_HEADER_SIZE(n)       (8+(n))
index 2204ae22c3812e1d4382acf5fc75673e825402fb..94ee4ecf0564972750e2fba836cd70990d01101a 100644 (file)
  * Class-Specific descriptors ... there are a couple dozen of them
  */
 
-#define USB_CDC_HEADER_TYPE            0x00            /* header_desc */
-#define USB_CDC_CALL_MANAGEMENT_TYPE   0x01            /* call_mgmt_descriptor */
-#define USB_CDC_ACM_TYPE               0x02            /* acm_descriptor */
-#define USB_CDC_UNION_TYPE             0x06            /* union_desc */
+#define USB_CDC_HEADER_TYPE            0x00    /* header_desc */
+#define USB_CDC_CALL_MANAGEMENT_TYPE   0x01    /* call_mgmt_descriptor */
+#define USB_CDC_ACM_TYPE               0x02    /* acm_descriptor */
+#define USB_CDC_UNION_TYPE             0x06    /* union_desc */
 #define USB_CDC_COUNTRY_TYPE           0x07
-#define USB_CDC_NETWORK_TERMINAL_TYPE  0x0a            /* network_terminal_desc */
-#define USB_CDC_ETHERNET_TYPE          0x0f            /* ether_desc */
+#define USB_CDC_NETWORK_TERMINAL_TYPE  0x0a    /* network_terminal_desc */
+#define USB_CDC_ETHERNET_TYPE          0x0f    /* ether_desc */
 #define USB_CDC_WHCM_TYPE              0x11
-#define USB_CDC_MDLM_TYPE              0x12            /* mdlm_desc */
-#define USB_CDC_MDLM_DETAIL_TYPE       0x13            /* mdlm_detail_desc */
+#define USB_CDC_MDLM_TYPE              0x12    /* mdlm_desc */
+#define USB_CDC_MDLM_DETAIL_TYPE       0x13    /* mdlm_detail_desc */
 #define USB_CDC_DMM_TYPE               0x14
 #define USB_CDC_OBEX_TYPE              0x15
 
diff --git a/include/linux/usb/g_printer.h b/include/linux/usb/g_printer.h
new file mode 100644 (file)
index 0000000..0c5ea1e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * g_printer.h -- Header file for USB Printer gadget driver
+ *
+ * Copyright (C) 2007 Craig W. Nadler
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#define PRINTER_NOT_ERROR      0x08
+#define PRINTER_SELECTED       0x10
+#define PRINTER_PAPER_EMPTY    0x20
+
+/* The 'g' code is also used by gadgetfs ioctl requests.
+ * Don't add any colliding codes to either driver, and keep
+ * them in unique ranges (size 0x20 for now).
+ */
+#define GADGET_GET_PRINTER_STATUS      _IOR('g', 0x21, unsigned char)
+#define GADGET_SET_PRINTER_STATUS      _IOWR('g', 0x22, unsigned char)
index c1527c2ef3cb1a8a8da5e79d7ca81acf867c9c79..aa3047ff00d13076e8ce29bd805b6a214b931945 100644 (file)
@@ -70,9 +70,10 @@ struct usb_ep;
  *
  * Bulk endpoints can use any size buffers, and can also be used for interrupt
  * transfers. interrupt-only endpoints can be much less functional.
+ *
+ * NOTE:  this is analagous to 'struct urb' on the host side, except that
+ * it's thinner and promotes more pre-allocation.
  */
-       // NOTE this is analagous to 'struct urb' on the host side,
-       // except that it's thinner and promotes more pre-allocation.
 
 struct usb_request {
        void                    *buf;
@@ -168,10 +169,10 @@ struct usb_ep {
  *
  * returns zero, or a negative error code.
  */
-static inline int
-usb_ep_enable (struct usb_ep *ep, const struct usb_endpoint_descriptor *desc)
+static inline int usb_ep_enable(struct usb_ep *ep,
+                               const struct usb_endpoint_descriptor *desc)
 {
-       return ep->ops->enable (ep, desc);
+       return ep->ops->enable(ep, desc);
 }
 
 /**
@@ -186,10 +187,9 @@ usb_ep_enable (struct usb_ep *ep, const struct usb_endpoint_descriptor *desc)
  *
  * returns zero, or a negative error code.
  */
-static inline int
-usb_ep_disable (struct usb_ep *ep)
+static inline int usb_ep_disable(struct usb_ep *ep)
 {
-       return ep->ops->disable (ep);
+       return ep->ops->disable(ep);
 }
 
 /**
@@ -206,10 +206,10 @@ usb_ep_disable (struct usb_ep *ep)
  *
  * Returns the request, or null if one could not be allocated.
  */
-static inline struct usb_request *
-usb_ep_alloc_request (struct usb_ep *ep, gfp_t gfp_flags)
+static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep,
+                                                      gfp_t gfp_flags)
 {
-       return ep->ops->alloc_request (ep, gfp_flags);
+       return ep->ops->alloc_request(ep, gfp_flags);
 }
 
 /**
@@ -221,10 +221,10 @@ usb_ep_alloc_request (struct usb_ep *ep, gfp_t gfp_flags)
  * Caller guarantees the request is not queued, and that it will
  * no longer be requeued (or otherwise used).
  */
-static inline void
-usb_ep_free_request (struct usb_ep *ep, struct usb_request *req)
+static inline void usb_ep_free_request(struct usb_ep *ep,
+                                      struct usb_request *req)
 {
-       ep->ops->free_request (ep, req);
+       ep->ops->free_request(ep, req);
 }
 
 /**
@@ -281,10 +281,10 @@ usb_ep_free_request (struct usb_ep *ep, struct usb_request *req)
  * report errors; errors will also be
  * reported when the usb peripheral is disconnected.
  */
-static inline int
-usb_ep_queue (struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags)
+static inline int usb_ep_queue(struct usb_ep *ep,
+                              struct usb_request *req, gfp_t gfp_flags)
 {
-       return ep->ops->queue (ep, req, gfp_flags);
+       return ep->ops->queue(ep, req, gfp_flags);
 }
 
 /**
@@ -301,9 +301,9 @@ usb_ep_queue (struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags)
  * restrictions prevent drivers from supporting configuration changes,
  * even to configuration zero (a "chapter 9" requirement).
  */
-static inline int usb_ep_dequeue (struct usb_ep *ep, struct usb_request *req)
+static inline int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
 {
-       return ep->ops->dequeue (ep, req);
+       return ep->ops->dequeue(ep, req);
 }
 
 /**
@@ -327,10 +327,9 @@ static inline int usb_ep_dequeue (struct usb_ep *ep, struct usb_request *req)
  * transfer requests are still queued, or if the controller hardware
  * (usually a FIFO) still holds bytes that the host hasn't collected.
  */
-static inline int
-usb_ep_set_halt (struct usb_ep *ep)
+static inline int usb_ep_set_halt(struct usb_ep *ep)
 {
-       return ep->ops->set_halt (ep, 1);
+       return ep->ops->set_halt(ep, 1);
 }
 
 /**
@@ -346,10 +345,9 @@ usb_ep_set_halt (struct usb_ep *ep)
  * Note that some hardware can't support this request (like pxa2xx_udc),
  * and accordingly can't correctly implement interface altsettings.
  */
-static inline int
-usb_ep_clear_halt (struct usb_ep *ep)
+static inline int usb_ep_clear_halt(struct usb_ep *ep)
 {
-       return ep->ops->set_halt (ep, 0);
+       return ep->ops->set_halt(ep, 0);
 }
 
 /**
@@ -367,11 +365,10 @@ usb_ep_clear_halt (struct usb_ep *ep)
  * errno if the endpoint doesn't use a FIFO or doesn't support such
  * precise handling.
  */
-static inline int
-usb_ep_fifo_status (struct usb_ep *ep)
+static inline int usb_ep_fifo_status(struct usb_ep *ep)
 {
        if (ep->ops->fifo_status)
-               return ep->ops->fifo_status (ep);
+               return ep->ops->fifo_status(ep);
        else
                return -EOPNOTSUPP;
 }
@@ -385,11 +382,10 @@ usb_ep_fifo_status (struct usb_ep *ep)
  * must never be used except when endpoint is not being used for any
  * protocol translation.
  */
-static inline void
-usb_ep_fifo_flush (struct usb_ep *ep)
+static inline void usb_ep_fifo_flush(struct usb_ep *ep)
 {
        if (ep->ops->fifo_flush)
-               ep->ops->fifo_flush (ep);
+               ep->ops->fifo_flush(ep);
 }
 
 
@@ -469,10 +465,10 @@ struct usb_gadget {
        struct device                   dev;
 };
 
-static inline void set_gadget_data (struct usb_gadget *gadget, void *data)
-       { dev_set_drvdata (&gadget->dev, data); }
-static inline void *get_gadget_data (struct usb_gadget *gadget)
-       { return dev_get_drvdata (&gadget->dev); }
+static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
+       { dev_set_drvdata(&gadget->dev, data); }
+static inline void *get_gadget_data(struct usb_gadget *gadget)
+       { return dev_get_drvdata(&gadget->dev); }
 
 /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */
 #define gadget_for_each_ep(tmp,gadget) \
@@ -511,7 +507,6 @@ static inline int gadget_is_otg(struct usb_gadget *g)
 #endif
 }
 
-
 /**
  * usb_gadget_frame_number - returns the current frame number
  * @gadget: controller that reports the frame number
@@ -519,9 +514,9 @@ static inline int gadget_is_otg(struct usb_gadget *g)
  * Returns the usb frame number, normally eleven bits from a SOF packet,
  * or negative errno if this device doesn't support this capability.
  */
-static inline int usb_gadget_frame_number (struct usb_gadget *gadget)
+static inline int usb_gadget_frame_number(struct usb_gadget *gadget)
 {
-       return gadget->ops->get_frame (gadget);
+       return gadget->ops->get_frame(gadget);
 }
 
 /**
@@ -537,11 +532,11 @@ static inline int usb_gadget_frame_number (struct usb_gadget *gadget)
  * even if OTG isn't otherwise in use.  OTG devices may also start
  * remote wakeup even when hosts don't explicitly enable it.
  */
-static inline int usb_gadget_wakeup (struct usb_gadget *gadget)
+static inline int usb_gadget_wakeup(struct usb_gadget *gadget)
 {
        if (!gadget->ops->wakeup)
                return -EOPNOTSUPP;
-       return gadget->ops->wakeup (gadget);
+       return gadget->ops->wakeup(gadget);
 }
 
 /**
@@ -553,12 +548,11 @@ static inline int usb_gadget_wakeup (struct usb_gadget *gadget)
  *
  * returns zero on success, else negative errno.
  */
-static inline int
-usb_gadget_set_selfpowered (struct usb_gadget *gadget)
+static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget)
 {
        if (!gadget->ops->set_selfpowered)
                return -EOPNOTSUPP;
-       return gadget->ops->set_selfpowered (gadget, 1);
+       return gadget->ops->set_selfpowered(gadget, 1);
 }
 
 /**
@@ -571,12 +565,11 @@ usb_gadget_set_selfpowered (struct usb_gadget *gadget)
  *
  * returns zero on success, else negative errno.
  */
-static inline int
-usb_gadget_clear_selfpowered (struct usb_gadget *gadget)
+static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget)
 {
        if (!gadget->ops->set_selfpowered)
                return -EOPNOTSUPP;
-       return gadget->ops->set_selfpowered (gadget, 0);
+       return gadget->ops->set_selfpowered(gadget, 0);
 }
 
 /**
@@ -591,12 +584,11 @@ usb_gadget_clear_selfpowered (struct usb_gadget *gadget)
  *
  * Returns zero on success, else negative errno.
  */
-static inline int
-usb_gadget_vbus_connect(struct usb_gadget *gadget)
+static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget)
 {
        if (!gadget->ops->vbus_session)
                return -EOPNOTSUPP;
-       return gadget->ops->vbus_session (gadget, 1);
+       return gadget->ops->vbus_session(gadget, 1);
 }
 
 /**
@@ -611,12 +603,11 @@ usb_gadget_vbus_connect(struct usb_gadget *gadget)
  *
  * Returns zero on success, else negative errno.
  */
-static inline int
-usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
+static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
        if (!gadget->ops->vbus_draw)
                return -EOPNOTSUPP;
-       return gadget->ops->vbus_draw (gadget, mA);
+       return gadget->ops->vbus_draw(gadget, mA);
 }
 
 /**
@@ -629,12 +620,11 @@ usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
  *
  * Returns zero on success, else negative errno.
  */
-static inline int
-usb_gadget_vbus_disconnect(struct usb_gadget *gadget)
+static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)
 {
        if (!gadget->ops->vbus_session)
                return -EOPNOTSUPP;
-       return gadget->ops->vbus_session (gadget, 0);
+       return gadget->ops->vbus_session(gadget, 0);
 }
 
 /**
@@ -648,12 +638,11 @@ usb_gadget_vbus_disconnect(struct usb_gadget *gadget)
  *
  * Returns zero on success, else negative errno.
  */
-static inline int
-usb_gadget_connect (struct usb_gadget *gadget)
+static inline int usb_gadget_connect(struct usb_gadget *gadget)
 {
        if (!gadget->ops->pullup)
                return -EOPNOTSUPP;
-       return gadget->ops->pullup (gadget, 1);
+       return gadget->ops->pullup(gadget, 1);
 }
 
 /**
@@ -671,16 +660,14 @@ usb_gadget_connect (struct usb_gadget *gadget)
  *
  * Returns zero on success, else negative errno.
  */
-static inline int
-usb_gadget_disconnect (struct usb_gadget *gadget)
+static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
 {
        if (!gadget->ops->pullup)
                return -EOPNOTSUPP;
-       return gadget->ops->pullup (gadget, 0);
+       return gadget->ops->pullup(gadget, 0);
 }
 
 
-
 /*-------------------------------------------------------------------------*/
 
 /**
@@ -764,7 +751,7 @@ struct usb_gadget_driver {
        void                    (*suspend)(struct usb_gadget *);
        void                    (*resume)(struct usb_gadget *);
 
-       // FIXME support safe rmmod
+       /* FIXME support safe rmmod */
        struct device_driver    driver;
 };
 
@@ -790,7 +777,7 @@ struct usb_gadget_driver {
  * the bind() functions will be in init sections.
  * This function must be called in a context that can sleep.
  */
-int usb_gadget_register_driver (struct usb_gadget_driver *driver);
+int usb_gadget_register_driver(struct usb_gadget_driver *driver);
 
 /**
  * usb_gadget_unregister_driver - unregister a gadget driver
@@ -805,7 +792,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver);
  * will in in exit sections, so may not be linked in some kernels.
  * This function must be called in a context that can sleep.
  */
-int usb_gadget_unregister_driver (struct usb_gadget_driver *driver);
+int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
 
 /*-------------------------------------------------------------------------*/
 
@@ -838,7 +825,7 @@ struct usb_gadget_strings {
 };
 
 /* put descriptor for string with that id into buf (buflen >= 256) */
-int usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf);
+int usb_gadget_get_string(struct usb_gadget_strings *table, int id, u8 *buf);
 
 /*-------------------------------------------------------------------------*/
 
@@ -856,10 +843,10 @@ int usb_gadget_config_buf(const struct usb_config_descriptor *config,
 
 /* utility wrapping a simple endpoint selection policy */
 
-extern struct usb_ep *usb_ep_autoconfig (struct usb_gadget *,
+extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
                        struct usb_endpoint_descriptor *) __devinit;
 
-extern void usb_ep_autoconfig_reset (struct usb_gadget *) __devinit;
+extern void usb_ep_autoconfig_reset(struct usb_gadget *) __devinit;
 
 #endif  /* __KERNEL__ */
 
index e8654c338729438de4b6d887b53c7dec725b3600..c291ab1af747a37953f7866fe6479dcef16a7877 100644 (file)
@@ -36,7 +36,7 @@ enum usb_gadgetfs_event_type {
        GADGETFS_DISCONNECT,
        GADGETFS_SETUP,
        GADGETFS_SUSPEND,
-       // and likely more !
+       /* and likely more ! */
 };
 
 /* NOTE:  this structure must stay the same size and layout on
@@ -44,21 +44,28 @@ enum usb_gadgetfs_event_type {
  */
 struct usb_gadgetfs_event {
        union {
-               // NOP, DISCONNECT, SUSPEND: nothing
-               // ... some hardware can't report disconnection
+               /* NOP, DISCONNECT, SUSPEND: nothing
+                * ... some hardware can't report disconnection
+                */
 
-               // CONNECT: just the speed
+               /* CONNECT: just the speed */
                enum usb_device_speed   speed;
 
-               // SETUP: packet; DATA phase i/o precedes next event
-               // (setup.bmRequestType & USB_DIR_IN) flags direction
-               // ... includes SET_CONFIGURATION, SET_INTERFACE
+               /* SETUP: packet; DATA phase i/o precedes next event
+                *(setup.bmRequestType & USB_DIR_IN) flags direction
+                * ... includes SET_CONFIGURATION, SET_INTERFACE
+                */
                struct usb_ctrlrequest  setup;
        } u;
        enum usb_gadgetfs_event_type    type;
 };
 
 
+/* The 'g' code is also used by printer gadget ioctl requests.
+ * Don't add any colliding codes to either driver, and keep
+ * them in unique ranges (size 0x20 for now).
+ */
+
 /* endpoint ioctls */
 
 /* IN transfers may be reported to the gadget driver as complete
@@ -68,14 +75,14 @@ struct usb_gadgetfs_event {
  * THIS returns how many bytes are "unclaimed" in the endpoint fifo
  * (needed for precise fault handling, when the hardware allows it)
  */
-#define        GADGETFS_FIFO_STATUS    _IO('g',1)
+#define        GADGETFS_FIFO_STATUS    _IO('g', 1)
 
 /* discards any unclaimed data in the fifo. */
-#define        GADGETFS_FIFO_FLUSH     _IO('g',2)
+#define        GADGETFS_FIFO_FLUSH     _IO('g', 2)
 
 /* resets endpoint halt+toggle; used to implement set_interface.
  * some hardware (like pxa2xx) can't support this.
  */
-#define        GADGETFS_CLEAR_HALT     _IO('g',3)
+#define        GADGETFS_CLEAR_HALT     _IO('g', 3)
 
 #endif /* __LINUX_USB_GADGETFS_H */
index cbbe020a4f5c493bd7481177f98cd53417c01bf4..de6f380e17a2bfac42059c40b41c69d3102222f9 100644 (file)
    this information.
 */
 struct iowarrior_info {
-       __u32 vendor;           /* vendor id : supposed to be USB_VENDOR_ID_CODEMERCS in all cases */
-       __u32 product;          /* product id : depends on type of chip (USB_DEVICE_ID_CODEMERCS_XXXXX) */
-       __u8 serial[9];         /* the serial number of our chip (if a serial-number is not available this is empty string) */
-       __u32 revision;         /* revision number of the chip */
-       __u32 speed;            /* USB-speed of the device (0=UNKNOWN, 1=LOW, 2=FULL 3=HIGH) */
-       __u32 power;            /* power consumption of the device in mA */
-       __u32 if_num;           /* the number of the endpoint */
-       __u32 report_size;      /* size of the data-packets on this interface */
+       /* vendor id : supposed to be USB_VENDOR_ID_CODEMERCS in all cases */
+       __u32 vendor;
+       /* product id : depends on type of chip (USB_DEVICE_ID_CODEMERCS_X) */
+       __u32 product;
+       /* the serial number of our chip (if a serial-number is not available
+        * this is empty string) */
+       __u8 serial[9];
+       /* revision number of the chip */
+       __u32 revision;
+       /* USB-speed of the device (0=UNKNOWN, 1=LOW, 2=FULL 3=HIGH) */
+       __u32 speed;
+       /* power consumption of the device in mA */
+       __u32 power;
+       /* the number of the endpoint */
+       __u32 if_num;
+       /* size of the data-packets on this interface */
+       __u32 report_size;
 };
 
 /*
index 436dd8a2b64ac67bea6d8d183be800a97c9ddc57..67d2826f34fe7795cc8bb37bf3ea4fa6ab7c1307 100644 (file)
@@ -25,5 +25,5 @@ struct isp116x_platform_data {
           300ns delay between access to ADDR_REG and DATA_REG
           OE, WE MUST NOT be changed during these intervals
         */
-       void (*delay) (struct device * dev, int delay);
+       void (*delay) (struct device *dev, int delay);
 };
index 11a97d5ffd34f3f68270339c808afcb8975552bb..80624c562921e0fe2dc620ccbaad6e16f70eb7cb 100644 (file)
@@ -47,9 +47,9 @@ struct usb_ms_header_descriptor {
 /* 6.1.2.2  MIDI IN Jack Descriptor */
 struct usb_midi_in_jack_descriptor {
        __u8  bLength;
-       __u8  bDescriptorType;          // USB_DT_CS_INTERFACE
-       __u8  bDescriptorSubtype;       // USB_MS_MIDI_IN_JACK
-       __u8  bJackType;                // USB_MS_EMBEDDED/EXTERNAL
+       __u8  bDescriptorType;          /* USB_DT_CS_INTERFACE */
+       __u8  bDescriptorSubtype;       /* USB_MS_MIDI_IN_JACK */
+       __u8  bJackType;                /* USB_MS_EMBEDDED/EXTERNAL */
        __u8  bJackID;
        __u8  iJack;
 } __attribute__ ((packed));
@@ -64,12 +64,12 @@ struct usb_midi_source_pin {
 /* 6.1.2.3  MIDI OUT Jack Descriptor */
 struct usb_midi_out_jack_descriptor {
        __u8  bLength;
-       __u8  bDescriptorType;          // USB_DT_CS_INTERFACE
-       __u8  bDescriptorSubtype;       // USB_MS_MIDI_OUT_JACK
-       __u8  bJackType;                // USB_MS_EMBEDDED/EXTERNAL
+       __u8  bDescriptorType;          /* USB_DT_CS_INTERFACE */
+       __u8  bDescriptorSubtype;       /* USB_MS_MIDI_OUT_JACK */
+       __u8  bJackType;                /* USB_MS_EMBEDDED/EXTERNAL */
        __u8  bJackID;
-       __u8  bNrInputPins;             // p
-       struct usb_midi_source_pin pins[]; // [p]
+       __u8  bNrInputPins;             /* p */
+       struct usb_midi_source_pin pins[]; /* [p] */
        /*__u8  iJack;  -- ommitted due to variable-sized pins[] */
 } __attribute__ ((packed));
 
@@ -90,11 +90,11 @@ struct usb_midi_out_jack_descriptor_##p {                   \
 
 /* 6.2.2  Class-Specific MS Bulk Data Endpoint Descriptor */
 struct usb_ms_endpoint_descriptor {
-       __u8  bLength;                  // 4+n
-       __u8  bDescriptorType;          // USB_DT_CS_ENDPOINT
-       __u8  bDescriptorSubtype;       // USB_MS_GENERAL
-       __u8  bNumEmbMIDIJack;          // n
-       __u8  baAssocJackID[];          // [n]
+       __u8  bLength;                  /* 4+n */
+       __u8  bDescriptorType;          /* USB_DT_CS_ENDPOINT */
+       __u8  bDescriptorSubtype;       /* USB_MS_GENERAL */
+       __u8  bNumEmbMIDIJack;          /* n */
+       __u8  baAssocJackID[];          /* [n] */
 } __attribute__ ((packed));
 
 #define USB_DT_MS_ENDPOINT_SIZE(n)     (4 + (n))
index c602f884f182ee91c7ce2a71fe77ab4071fb0edd..ec897cb844ab5cd9a8dbda9be1b66a37cf8235c2 100644 (file)
@@ -37,7 +37,7 @@
 
 /* main registers, BAR0 + 0x0000 */
 struct net2280_regs {
-       // offset 0x0000
+       /* offset 0x0000 */
        u32             devinit;
 #define     LOCAL_CLOCK_FREQUENCY                               8
 #define     FORCE_PCI_RESET                                     7
@@ -61,7 +61,7 @@ struct net2280_regs {
 #define     EEPROM_WRITE_DATA                                   0
        u32             eeclkfreq;
        u32             _unused0;
-       // offset 0x0010
+       /* offset 0x0010 */
 
        u32             pciirqenb0;             /* interrupt PCI master ... */
 #define     SETUP_PACKET_INTERRUPT_ENABLE                       7
@@ -131,7 +131,7 @@ struct net2280_regs {
 #define     RESUME_INTERRUPT_ENABLE                             1
 #define     SOF_INTERRUPT_ENABLE                                0
 
-       // offset 0x0020
+       /* offset 0x0020 */
        u32             _unused1;
        u32             usbirqenb1;
 #define     USB_INTERRUPT_ENABLE                                31
@@ -195,7 +195,7 @@ struct net2280_regs {
 #define     SUSPEND_REQUEST_CHANGE_INTERRUPT                    2
 #define     RESUME_INTERRUPT                                    1
 #define     SOF_INTERRUPT                                       0
-       // offset 0x0030
+       /* offset 0x0030 */
        u32             idxaddr;
        u32             idxdata;
        u32             fifoctl;
@@ -204,7 +204,7 @@ struct net2280_regs {
 #define     PCI_BASE2_SELECT                                    2
 #define     FIFO_CONFIGURATION_SELECT                           0
        u32             _unused2;
-       // offset 0x0040
+       /* offset 0x0040 */
        u32             memaddr;
 #define     START                                               28
 #define     DIRECTION                                           27
@@ -213,7 +213,7 @@ struct net2280_regs {
        u32             memdata0;
        u32             memdata1;
        u32             _unused3;
-       // offset 0x0050
+       /* offset 0x0050 */
        u32             gpioctl;
 #define     GPIO3_LED_SELECT                                    12
 #define     GPIO3_INTERRUPT_ENABLE                              11
@@ -237,7 +237,7 @@ struct net2280_regs {
 
 /* usb control, BAR0 + 0x0080 */
 struct net2280_usb_regs {
-       // offset 0x0080
+       /* offset 0x0080 */
        u32             stdrsp;
 #define     STALL_UNSUPPORTED_REQUESTS                          31
 #define     SET_TEST_MODE                                       16
@@ -275,7 +275,7 @@ struct net2280_usb_regs {
 #define     PME_WAKEUP_ENABLE                                   2
 #define     DEVICE_REMOTE_WAKEUP_ENABLE                         1
 #define     SELF_POWERED_STATUS                                 0
-       // offset 0x0090
+       /* offset 0x0090 */
        u32             usbstat;
 #define     HIGH_SPEED                                          7
 #define     FULL_SPEED                                          6
@@ -291,7 +291,7 @@ struct net2280_usb_regs {
 #define     TERMINATION_SELECT                                  0
        u32             setup0123;
        u32             setup4567;
-       // offset 0x0090
+       /* offset 0x0090 */
        u32             _unused0;
        u32             ouraddr;
 #define     FORCE_IMMEDIATE                                     7
@@ -301,7 +301,7 @@ struct net2280_usb_regs {
 
 /* pci control, BAR0 + 0x0100 */
 struct net2280_pci_regs {
-       // offset 0x0100
+       /* offset 0x0100 */
        u32              pcimstctl;
 #define     PCI_ARBITER_PARK_SELECT                             13
 #define     PCI_MULTI LEVEL_ARBITER                             12
@@ -331,7 +331,7 @@ struct net2280_pci_regs {
  * that can be loaded into some of these registers.
  */
 struct net2280_dma_regs {      /* [11.7] */
-       // offset 0x0180, 0x01a0, 0x01c0, 0x01e0,
+       /* offset 0x0180, 0x01a0, 0x01c0, 0x01e0, */
        u32             dmactl;
 #define     DMA_SCATTER_GATHER_DONE_INTERRUPT_ENABLE            25
 #define     DMA_CLEAR_COUNT_ENABLE                              21
@@ -355,7 +355,7 @@ struct net2280_dma_regs {   /* [11.7] */
 #define     DMA_ABORT                                           1
 #define     DMA_START                                           0
        u32             _unused0 [2];
-       // offset 0x0190, 0x01b0, 0x01d0, 0x01f0,
+       /* offset 0x0190, 0x01b0, 0x01d0, 0x01f0, */
        u32             dmacount;
 #define     VALID_BIT                                           31
 #define     DMA_DIRECTION                                       30
@@ -371,9 +371,9 @@ struct net2280_dma_regs {   /* [11.7] */
 /* dedicated endpoint registers, BAR0 + 0x0200 */
 
 struct net2280_dep_regs {      /* [11.8] */
-       // offset 0x0200, 0x0210, 0x220, 0x230, 0x240
+       /* offset 0x0200, 0x0210, 0x220, 0x230, 0x240 */
        u32             dep_cfg;
-       // offset 0x0204, 0x0214, 0x224, 0x234, 0x244
+       /* offset 0x0204, 0x0214, 0x224, 0x234, 0x244 */
        u32             dep_rsp;
        u32             _unused [2];
 } __attribute__ ((packed));
@@ -383,7 +383,7 @@ struct net2280_dep_regs {   /* [11.8] */
  * ep0 reserved for control; E and F have only 64 bytes of fifo
  */
 struct net2280_ep_regs {       /* [11.9] */
-       // offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0
+       /* offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0 */
        u32             ep_cfg;
 #define     ENDPOINT_BYTE_COUNT                                 16
 #define     ENDPOINT_ENABLE                                     10
@@ -435,7 +435,7 @@ struct net2280_ep_regs {    /* [11.9] */
 #define     DATA_PACKET_TRANSMITTED_INTERRUPT                   2
 #define     DATA_OUT_PING_TOKEN_INTERRUPT                       1
 #define     DATA_IN_TOKEN_INTERRUPT                             0
-       // offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0
+       /* offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0 */
        u32             ep_avail;
        u32             ep_data;
        u32             _unused0 [2];
index 9897f7a818c561fb6a6a04e2004874ee8ca4d967..e007074ebe41f6b9648f62177cfa588b7bc13fcb 100644 (file)
@@ -1,4 +1,4 @@
-// include/linux/usb/otg.h
+/* USB OTG (On The Go) defines */
 
 /*
  * These APIs may be used between USB controllers.  USB device drivers
index 488ce128885ceb1232bac30c2e3ec897edb50e5d..21b4a1c6f5851f9c92998694afd0171602af880b 100644 (file)
@@ -20,7 +20,8 @@
 #define SERIAL_TTY_MAJOR       188     /* Nice legal number now */
 #define SERIAL_TTY_MINORS      255     /* loads of devices :) */
 
-#define MAX_NUM_PORTS          8       /* The maximum number of ports one device can grab at once */
+/* The maximum number of ports one device can grab at once */
+#define MAX_NUM_PORTS          8
 
 /* parity check flag */
 #define RELEVANT_IFLAG(iflag)  (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  * ports of a device.
  */
 struct usb_serial_port {
-       struct usb_serial *     serial;
-       struct tty_struct *     tty;
+       struct usb_serial       *serial;
+       struct tty_struct       *tty;
        spinlock_t              lock;
        struct mutex            mutex;
        unsigned char           number;
 
-       unsigned char *         interrupt_in_buffer;
-       struct urb *            interrupt_in_urb;
+       unsigned char           *interrupt_in_buffer;
+       struct urb              *interrupt_in_urb;
        __u8                    interrupt_in_endpointAddress;
 
-       unsigned char *         interrupt_out_buffer;
+       unsigned char           *interrupt_out_buffer;
        int                     interrupt_out_size;
-       struct urb *            interrupt_out_urb;
+       struct urb              *interrupt_out_urb;
        __u8                    interrupt_out_endpointAddress;
 
-       unsigned char *         bulk_in_buffer;
+       unsigned char           *bulk_in_buffer;
        int                     bulk_in_size;
-       struct urb *            read_urb;
+       struct urb              *read_urb;
        __u8                    bulk_in_endpointAddress;
 
-       unsigned char *         bulk_out_buffer;
+       unsigned char           *bulk_out_buffer;
        int                     bulk_out_size;
-       struct urb *            write_urb;
+       struct urb              *write_urb;
        int                     write_urb_busy;
        __u8                    bulk_out_endpointAddress;
 
@@ -92,17 +93,19 @@ struct usb_serial_port {
        int                     open_count;
        char                    throttled;
        char                    throttle_req;
+       char                    console;
        struct device           dev;
 };
 #define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev)
 
 /* get and set the port private data pointer helper functions */
-static inline void *usb_get_serial_port_data (struct usb_serial_port *port)
+static inline void *usb_get_serial_port_data(struct usb_serial_port *port)
 {
        return dev_get_drvdata(&port->dev);
 }
 
-static inline void usb_set_serial_port_data (struct usb_serial_port *port, void *data)
+static inline void usb_set_serial_port_data(struct usb_serial_port *port,
+                                           void *data)
 {
        dev_set_drvdata(&port->dev, data);
 }
@@ -125,9 +128,10 @@ static inline void usb_set_serial_port_data (struct usb_serial_port *port, void
  *     usb_set_serial_data() to access this.
  */
 struct usb_serial {
-       struct usb_device *             dev;
-       struct usb_serial_driver *      type;
-       struct usb_interface *          interface;
+       struct usb_device               *dev;
+       struct usb_serial_driver        *type;
+       struct usb_interface            *interface;
+       unsigned char                   disconnected;
        unsigned char                   minor;
        unsigned char                   num_ports;
        unsigned char                   num_port_pointers;
@@ -135,29 +139,30 @@ struct usb_serial {
        char                            num_interrupt_out;
        char                            num_bulk_in;
        char                            num_bulk_out;
-       struct usb_serial_port *        port[MAX_NUM_PORTS];
+       struct usb_serial_port          *port[MAX_NUM_PORTS];
        struct kref                     kref;
-       void *                          private;
+       struct mutex                    disc_mutex;
+       void                            *private;
 };
 #define to_usb_serial(d) container_of(d, struct usb_serial, kref)
 
 #define NUM_DONT_CARE  99
 
 /* get and set the serial private data pointer helper functions */
-static inline void *usb_get_serial_data (struct usb_serial *serial)
+static inline void *usb_get_serial_data(struct usb_serial *serial)
 {
        return serial->private;
 }
 
-static inline void usb_set_serial_data (struct usb_serial *serial, void *data)
+static inline void usb_set_serial_data(struct usb_serial *serial, void *data)
 {
        serial->private = data;
 }
 
 /**
  * usb_serial_driver - describes a usb serial driver
- * @description: pointer to a string that describes this driver.  This string used
- *     in the syslog messages when a device is inserted or removed.
+ * @description: pointer to a string that describes this driver.  This string
+ *     used in the syslog messages when a device is inserted or removed.
  * @id_table: pointer to a list of usb_device_id structures that define all
  *     of the devices this structure can support.
  * @num_interrupt_in: If a device doesn't have this many interrupt-in
@@ -218,82 +223,91 @@ struct usb_serial_driver {
        struct usb_driver       *usb_driver;
        struct usb_dynids       dynids;
 
-       int (*probe) (struct usb_serial *serial, const struct usb_device_id *id);
-       int (*attach) (struct usb_serial *serial);
+       int (*probe)(struct usb_serial *serial, const struct usb_device_id *id);
+       int (*attach)(struct usb_serial *serial);
        int (*calc_num_ports) (struct usb_serial *serial);
 
-       void (*shutdown) (struct usb_serial *serial);
+       void (*shutdown)(struct usb_serial *serial);
 
-       int (*port_probe) (struct usb_serial_port *port);
-       int (*port_remove) (struct usb_serial_port *port);
+       int (*port_probe)(struct usb_serial_port *port);
+       int (*port_remove)(struct usb_serial_port *port);
 
-       int (*suspend) (struct usb_serial *serial, pm_message_t message);
-       int (*resume) (struct usb_serial *serial);
+       int (*suspend)(struct usb_serial *serial, pm_message_t message);
+       int (*resume)(struct usb_serial *serial);
 
        /* serial function calls */
-       int  (*open)            (struct usb_serial_port *port, struct file * filp);
-       void (*close)           (struct usb_serial_port *port, struct file * filp);
-       int  (*write)           (struct usb_serial_port *port, const unsigned char *buf, int count);
-       int  (*write_room)      (struct usb_serial_port *port);
-       int  (*ioctl)           (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
-       void (*set_termios)     (struct usb_serial_port *port, struct ktermios * old);
-       void (*break_ctl)       (struct usb_serial_port *port, int break_state);
-       int  (*chars_in_buffer) (struct usb_serial_port *port);
-       void (*throttle)        (struct usb_serial_port *port);
-       void (*unthrottle)      (struct usb_serial_port *port);
-       int  (*tiocmget)        (struct usb_serial_port *port, struct file *file);
-       int  (*tiocmset)        (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
+       int  (*open)(struct usb_serial_port *port, struct file *filp);
+       void (*close)(struct usb_serial_port *port, struct file *filp);
+       int  (*write)(struct usb_serial_port *port, const unsigned char *buf,
+                     int count);
+       int  (*write_room)(struct usb_serial_port *port);
+       int  (*ioctl)(struct usb_serial_port *port, struct file *file,
+                     unsigned int cmd, unsigned long arg);
+       void (*set_termios)(struct usb_serial_port *port, struct ktermios *old);
+       void (*break_ctl)(struct usb_serial_port *port, int break_state);
+       int  (*chars_in_buffer)(struct usb_serial_port *port);
+       void (*throttle)(struct usb_serial_port *port);
+       void (*unthrottle)(struct usb_serial_port *port);
+       int  (*tiocmget)(struct usb_serial_port *port, struct file *file);
+       int  (*tiocmset)(struct usb_serial_port *port, struct file *file,
+                        unsigned int set, unsigned int clear);
 
        void (*read_int_callback)(struct urb *urb);
        void (*write_int_callback)(struct urb *urb);
        void (*read_bulk_callback)(struct urb *urb);
        void (*write_bulk_callback)(struct urb *urb);
 };
-#define to_usb_serial_driver(d) container_of(d, struct usb_serial_driver, driver)
+#define to_usb_serial_driver(d) \
+       container_of(d, struct usb_serial_driver, driver)
 
 extern int  usb_serial_register(struct usb_serial_driver *driver);
 extern void usb_serial_deregister(struct usb_serial_driver *driver);
 extern void usb_serial_port_softint(struct usb_serial_port *port);
 
-extern int usb_serial_probe(struct usb_interface *iface, const struct usb_device_id *id);
+extern int usb_serial_probe(struct usb_interface *iface,
+                           const struct usb_device_id *id);
 extern void usb_serial_disconnect(struct usb_interface *iface);
 
 extern int usb_serial_suspend(struct usb_interface *intf, pm_message_t message);
 extern int usb_serial_resume(struct usb_interface *intf);
 
-extern int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest);
-extern int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit);
+extern int ezusb_writememory(struct usb_serial *serial, int address,
+                            unsigned char *data, int length, __u8 bRequest);
+extern int ezusb_set_reset(struct usb_serial *serial, unsigned char reset_bit);
 
 /* USB Serial console functions */
 #ifdef CONFIG_USB_SERIAL_CONSOLE
-extern void usb_serial_console_init (int debug, int minor);
-extern void usb_serial_console_exit (void);
+extern void usb_serial_console_init(int debug, int minor);
+extern void usb_serial_console_exit(void);
 extern void usb_serial_console_disconnect(struct usb_serial *serial);
 #else
-static inline void usb_serial_console_init (int debug, int minor) { }
-static inline void usb_serial_console_exit (void) { }
+static inline void usb_serial_console_init(int debug, int minor) { }
+static inline void usb_serial_console_exit(void) { }
 static inline void usb_serial_console_disconnect(struct usb_serial *serial) {}
 #endif
 
 /* Functions needed by other parts of the usbserial core */
-extern struct usb_serial *usb_serial_get_by_index (unsigned int minor);
+extern struct usb_serial *usb_serial_get_by_index(unsigned int minor);
 extern void usb_serial_put(struct usb_serial *serial);
-extern int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp);
-extern int usb_serial_generic_write (struct usb_serial_port *port, const unsigned char *buf, int count);
-extern void usb_serial_generic_close (struct usb_serial_port *port, struct file *filp);
-extern int usb_serial_generic_resume (struct usb_serial *serial);
-extern int usb_serial_generic_write_room (struct usb_serial_port *port);
-extern int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port);
-extern void usb_serial_generic_read_bulk_callback (struct urb *urb);
-extern void usb_serial_generic_write_bulk_callback (struct urb *urb);
-extern void usb_serial_generic_throttle (struct usb_serial_port *port);
-extern void usb_serial_generic_unthrottle (struct usb_serial_port *port);
-extern void usb_serial_generic_shutdown (struct usb_serial *serial);
-extern int usb_serial_generic_register (int debug);
-extern void usb_serial_generic_deregister (void);
-
-extern int usb_serial_bus_register (struct usb_serial_driver *device);
-extern void usb_serial_bus_deregister (struct usb_serial_driver *device);
+extern int usb_serial_generic_open(struct usb_serial_port *port,
+                                  struct file *filp);
+extern int usb_serial_generic_write(struct usb_serial_port *port,
+                                   const unsigned char *buf, int count);
+extern void usb_serial_generic_close(struct usb_serial_port *port,
+                                    struct file *filp);
+extern int usb_serial_generic_resume(struct usb_serial *serial);
+extern int usb_serial_generic_write_room(struct usb_serial_port *port);
+extern int usb_serial_generic_chars_in_buffer(struct usb_serial_port *port);
+extern void usb_serial_generic_read_bulk_callback(struct urb *urb);
+extern void usb_serial_generic_write_bulk_callback(struct urb *urb);
+extern void usb_serial_generic_throttle(struct usb_serial_port *port);
+extern void usb_serial_generic_unthrottle(struct usb_serial_port *port);
+extern void usb_serial_generic_shutdown(struct usb_serial *serial);
+extern int usb_serial_generic_register(int debug);
+extern void usb_serial_generic_deregister(void);
+
+extern int usb_serial_bus_register(struct usb_serial_driver *device);
+extern void usb_serial_bus_deregister(struct usb_serial_driver *device);
 
 extern struct usb_serial_driver usb_serial_generic_device;
 extern struct bus_type usb_serial_bus_type;
@@ -307,16 +321,22 @@ static inline void usb_serial_debug_data(int debug,
        int i;
 
        if (debug) {
-               dev_printk(KERN_DEBUG, dev, "%s - length = %d, data = ", function, size);
+               dev_printk(KERN_DEBUG, dev, "%s - length = %d, data = ",
+                          function, size);
                for (i = 0; i < size; ++i)
-                       printk ("%.2x ", data[i]);
-               printk ("\n");
+                       printk("%.2x ", data[i]);
+               printk("\n");
        }
 }
 
 /* Use our own dbg macro */
 #undef dbg
-#define dbg(format, arg...) do { if (debug) printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , ## arg); } while (0)
+#define dbg(format, arg...) \
+       do { \
+               if (debug) \
+                       printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , \
+                               ## arg); \
+       } while (0)
 
 
 
index 397ee3b3d7f357ff5d2d665491c12a28f478d909..877373da410dcd0520cae0babe731188351fc637 100644 (file)
@@ -19,8 +19,8 @@ struct sl811_platform_data {
        /* pulse sl811 nRST (probably with a GPIO) */
        void            (*reset)(struct device *dev);
 
-       // some boards need something like these:
-       // int          (*check_overcurrent)(struct device *dev);
-       // void         (*clock_enable)(struct device *dev, int is_on);
+       /* some boards need something like these: */
+       /* int          (*check_overcurrent)(struct device *dev); */
+       /* void         (*clock_enable)(struct device *dev, int is_on); */
 };
 
index a417b09b8b3db53875a1bd93936448aaf52be018..cee0623b3c7be52b17b2a47b5208b3528f13cf18 100644 (file)
@@ -80,10 +80,9 @@ enum { US_DO_ALL_FLAGS };
 #define US_SC_UFI      0x04            /* Floppy */
 #define US_SC_8070     0x05            /* Removable media */
 #define US_SC_SCSI     0x06            /* Transparent */
-#define US_SC_ISD200    0x07           /* ISD200 ATA */
-#define US_SC_MIN      US_SC_RBC
-#define US_SC_MAX      US_SC_ISD200
+#define US_SC_LOCKABLE 0x07            /* Password-protected */
 
+#define US_SC_ISD200    0xf0           /* ISD200 ATA */
 #define US_SC_DEVICE   0xff            /* Use device's value */
 
 /* Protocols */
index 8ca5a7fbc9ecaf38d8baefa7da3618aadd628828..17cb108b7db038558ef4e49337503c1217d8592a 100644 (file)
@@ -104,7 +104,7 @@ struct usbdevfs_urb {
        int error_count;
        unsigned int signr;     /* signal to be sent on completion,
                                  or 0 if none should be sent. */
-       void *usercontext;
+       void __user *usercontext;
        struct usbdevfs_iso_packet_desc iso_frame_desc[0];
 };
 
index 14e1379876d334f9bb99d04d43750c571c967528..260d1fcf29a4222c011ab39176b1e2e4d46a98a3 100644 (file)
 /**
  * virtqueue - a queue to register buffers for sending or receiving.
  * @callback: the function to call when buffers are consumed (can be NULL).
- *    If this returns false, callbacks are suppressed until vq_ops->restart
- *    is called.
  * @vdev: the virtio device this queue was created for.
  * @vq_ops: the operations for this virtqueue (see below).
  * @priv: a pointer for the virtqueue implementation to use.
  */
 struct virtqueue
 {
-       bool (*callback)(struct virtqueue *vq);
+       void (*callback)(struct virtqueue *vq);
        struct virtio_device *vdev;
        struct virtqueue_ops *vq_ops;
        void *priv;
@@ -41,13 +39,12 @@ struct virtqueue
  *     vq: the struct virtqueue we're talking about.
  *     len: the length written into the buffer
  *     Returns NULL or the "data" token handed to add_buf.
- * @restart: restart callbacks after callback returned false.
+ * @disable_cb: disable callbacks
+ *     vq: the struct virtqueue we're talking about.
+ * @enable_cb: restart callbacks after disable_cb.
  *     vq: the struct virtqueue we're talking about.
  *     This returns "false" (and doesn't re-enable) if there are pending
  *     buffers in the queue, to avoid a race.
- * @shutdown: "unadd" all buffers.
- *     vq: the struct virtqueue we're talking about.
- *     Remove everything from the queue.
  *
  * Locking rules are straightforward: the driver is responsible for
  * locking.  No two operations may be invoked simultaneously.
@@ -65,9 +62,8 @@ struct virtqueue_ops {
 
        void *(*get_buf)(struct virtqueue *vq, unsigned int *len);
 
-       bool (*restart)(struct virtqueue *vq);
-
-       void (*shutdown)(struct virtqueue *vq);
+       void (*disable_cb)(struct virtqueue *vq);
+       bool (*enable_cb)(struct virtqueue *vq);
 };
 
 /**
@@ -97,12 +93,15 @@ void unregister_virtio_device(struct virtio_device *dev);
  * @probe: the function to call when a device is found.  Returns a token for
  *    remove, or PTR_ERR().
  * @remove: the function when a device is removed.
+ * @config_changed: optional function to call when the device configuration
+ *    changes; may be called in interrupt context.
  */
 struct virtio_driver {
        struct device_driver driver;
        const struct virtio_device_id *id_table;
        int (*probe)(struct virtio_device *dev);
        void (*remove)(struct virtio_device *dev);
+       void (*config_changed)(struct virtio_device *dev);
 };
 
 int register_virtio_driver(struct virtio_driver *drv);
diff --git a/include/linux/virtio_balloon.h b/include/linux/virtio_balloon.h
new file mode 100644 (file)
index 0000000..979524e
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _LINUX_VIRTIO_BALLOON_H
+#define _LINUX_VIRTIO_BALLOON_H
+#include <linux/virtio_config.h>
+
+/* The ID for virtio_balloon */
+#define VIRTIO_ID_BALLOON      5
+
+/* The feature bitmap for virtio balloon */
+#define VIRTIO_BALLOON_F_MUST_TELL_HOST        0 /* Tell before reclaiming pages */
+
+struct virtio_balloon_config
+{
+       /* Number of pages host wants Guest to give up. */
+       __le32 num_pages;
+       /* Number of pages we've actually got in balloon. */
+       __le32 actual;
+};
+#endif /* _LINUX_VIRTIO_BALLOON_H */
index 7bd2bce0cfd964f2c4c5fe5bffa72977bc37fd2b..bca0b10d79470056cc6456101ef45454f813149f 100644 (file)
@@ -6,15 +6,19 @@
 #define VIRTIO_ID_BLOCK        2
 
 /* Feature bits */
-#define VIRTIO_CONFIG_BLK_F    0x40
-#define VIRTIO_BLK_F_BARRIER   1       /* Does host support barriers? */
+#define VIRTIO_BLK_F_BARRIER   0       /* Does host support barriers? */
+#define VIRTIO_BLK_F_SIZE_MAX  1       /* Indicates maximum segment size */
+#define VIRTIO_BLK_F_SEG_MAX   2       /* Indicates maximum # of segments */
 
-/* The capacity (in 512-byte sectors). */
-#define VIRTIO_CONFIG_BLK_F_CAPACITY   0x41
-/* The maximum segment size. */
-#define VIRTIO_CONFIG_BLK_F_SIZE_MAX   0x42
-/* The maximum number of segments. */
-#define VIRTIO_CONFIG_BLK_F_SEG_MAX    0x43
+struct virtio_blk_config
+{
+       /* The capacity (in 512-byte sectors). */
+       __le64 capacity;
+       /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
+       __le32 size_max;
+       /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
+       __le32 seg_max;
+} __attribute__((packed));
 
 /* These two define direction. */
 #define VIRTIO_BLK_T_IN                0
@@ -35,8 +39,6 @@ struct virtio_blk_outhdr
        __u32 ioprio;
        /* Sector (ie. 512 byte offset) */
        __u64 sector;
-       /* Where to put reply. */
-       __u64 id;
 };
 
 #define VIRTIO_BLK_S_OK                0
index bcc01888df78d52e19592a92bd8861b0f1f5f9c9..d581b2914b342cbbe83744bc15762fb8718a81a3 100644 (file)
@@ -5,7 +5,7 @@
  * store and access that space differently. */
 #include <linux/types.h>
 
-/* Status byte for guest to report progress, and synchronize config. */
+/* Status byte for guest to report progress, and synchronize features. */
 /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
 #define VIRTIO_CONFIG_S_ACKNOWLEDGE    1
 /* We have found a driver for the device. */
 /* We've given up on this device. */
 #define VIRTIO_CONFIG_S_FAILED         0x80
 
-/* Feature byte (actually 7 bits availabe): */
-/* Requirements/features of the virtio implementation. */
-#define VIRTIO_CONFIG_F_VIRTIO 1
-/* Requirements/features of the virtqueue (may have more than one). */
-#define VIRTIO_CONFIG_F_VIRTQUEUE 2
-
 #ifdef __KERNEL__
 struct virtio_device;
 
 /**
  * virtio_config_ops - operations for configuring a virtio device
- * @find: search for the next configuration field of the given type.
+ * @feature: search for a feature in this config
  *     vdev: the virtio_device
- *     type: the feature type
- *     len: the (returned) length of the field if found.
- *     Returns a token if found, or NULL.  Never returnes the same field twice
- *     (ie. it's used up).
- * @get: read the value of a configuration field after find().
+ *     bit: the feature bit
+ *     Returns true if the feature is supported.  Acknowledges the feature
+ *     so the host can see it.
+ * @get: read the value of a configuration field
  *     vdev: the virtio_device
- *     token: the token returned from find().
+ *     offset: the offset of the configuration field
  *     buf: the buffer to write the field value into.
- *     len: the length of the buffer (given by find()).
+ *     len: the length of the buffer
  *     Note that contents are conventionally little-endian.
- * @set: write the value of a configuration field after find().
+ * @set: write the value of a configuration field
  *     vdev: the virtio_device
- *     token: the token returned from find().
+ *     offset: the offset of the configuration field
  *     buf: the buffer to read the field value from.
- *     len: the length of the buffer (given by find()).
+ *     len: the length of the buffer
  *     Note that contents are conventionally little-endian.
  * @get_status: read the status byte
  *     vdev: the virtio_device
@@ -50,62 +43,67 @@ struct virtio_device;
  * @set_status: write the status byte
  *     vdev: the virtio_device
  *     status: the new status byte
- * @find_vq: find the first VIRTIO_CONFIG_F_VIRTQUEUE and create a virtqueue.
+ * @reset: reset the device
+ *     vdev: the virtio device
+ *     After this, status and feature negotiation must be done again
+ * @find_vq: find a virtqueue and instantiate it.
  *     vdev: the virtio_device
+ *     index: the 0-based virtqueue number in case there's more than one.
  *     callback: the virqtueue callback
- *     Returns the new virtqueue or ERR_PTR().
+ *     Returns the new virtqueue or ERR_PTR() (eg. -ENOENT).
  * @del_vq: free a virtqueue found by find_vq().
  */
 struct virtio_config_ops
 {
-       void *(*find)(struct virtio_device *vdev, u8 type, unsigned *len);
-       void (*get)(struct virtio_device *vdev, void *token,
+       bool (*feature)(struct virtio_device *vdev, unsigned bit);
+       void (*get)(struct virtio_device *vdev, unsigned offset,
                    void *buf, unsigned len);
-       void (*set)(struct virtio_device *vdev, void *token,
+       void (*set)(struct virtio_device *vdev, unsigned offset,
                    const void *buf, unsigned len);
        u8 (*get_status)(struct virtio_device *vdev);
        void (*set_status)(struct virtio_device *vdev, u8 status);
+       void (*reset)(struct virtio_device *vdev);
        struct virtqueue *(*find_vq)(struct virtio_device *vdev,
-                                    bool (*callback)(struct virtqueue *));
+                                    unsigned index,
+                                    void (*callback)(struct virtqueue *));
        void (*del_vq)(struct virtqueue *vq);
 };
 
 /**
- * virtio_config_val - get a single virtio config and mark it used.
- * @config: the virtio config space
- * @type: the type to search for.
+ * virtio_config_val - look for a feature and get a single virtio config.
+ * @vdev: the virtio device
+ * @fbit: the feature bit
+ * @offset: the type to search for.
  * @val: a pointer to the value to fill in.
  *
- * Once used, the config type is marked with VIRTIO_CONFIG_F_USED so it can't
- * be found again.  This version does endian conversion. */
-#define virtio_config_val(vdev, type, v) ({                            \
-       int _err = __virtio_config_val((vdev),(type),(v),sizeof(*(v))); \
-                                                                       \
-       BUILD_BUG_ON(sizeof(*(v)) != 1 && sizeof(*(v)) != 2             \
-                    && sizeof(*(v)) != 4 && sizeof(*(v)) != 8);        \
-       if (!_err) {                                                    \
-               switch (sizeof(*(v))) {                                 \
-               case 2: le16_to_cpus((__u16 *) v); break;               \
-               case 4: le32_to_cpus((__u32 *) v); break;               \
-               case 8: le64_to_cpus((__u64 *) v); break;               \
-               }                                                       \
-       }                                                               \
+ * The return value is -ENOENT if the feature doesn't exist.  Otherwise
+ * the value is endian-corrected and returned in v. */
+#define virtio_config_val(vdev, fbit, offset, v) ({                    \
+       int _err;                                                       \
+       if ((vdev)->config->feature((vdev), (fbit))) {                  \
+               __virtio_config_val((vdev), (offset), (v));             \
+               _err = 0;                                               \
+       } else                                                          \
+               _err = -ENOENT;                                         \
        _err;                                                           \
 })
 
-int __virtio_config_val(struct virtio_device *dev,
-                       u8 type, void *val, size_t size);
-
 /**
- * virtio_use_bit - helper to use a feature bit in a bitfield value.
- * @dev: the virtio device
- * @token: the token as returned from vdev->config->find().
- * @len: the length of the field.
- * @bitnum: the bit to test.
+ * __virtio_config_val - get a single virtio config without feature check.
+ * @vdev: the virtio device
+ * @offset: the type to search for.
+ * @val: a pointer to the value to fill in.
  *
- * If handed a NULL token, it returns false, otherwise returns bit status.
- * If it's one, it sets the mirroring acknowledgement bit. */
-int virtio_use_bit(struct virtio_device *vdev,
-                  void *token, unsigned int len, unsigned int bitnum);
+ * The value is endian-corrected and returned in v. */
+#define __virtio_config_val(vdev, offset, v) do {                      \
+       BUILD_BUG_ON(sizeof(*(v)) != 1 && sizeof(*(v)) != 2             \
+                    && sizeof(*(v)) != 4 && sizeof(*(v)) != 8);        \
+       (vdev)->config->get((vdev), (offset), (v), sizeof(*(v)));       \
+       switch (sizeof(*(v))) {                                         \
+       case 2: le16_to_cpus((__u16 *) v); break;                       \
+       case 4: le32_to_cpus((__u32 *) v); break;                       \
+       case 8: le64_to_cpus((__u64 *) v); break;                       \
+       }                                                               \
+} while(0)
 #endif /* __KERNEL__ */
 #endif /* _LINUX_VIRTIO_CONFIG_H */
index ae469ae55d3662fe80c198fea895e68c6890e204..1ea3351df609474d097b67e4f0df31131257a34f 100644 (file)
@@ -5,32 +5,32 @@
 /* The ID for virtio_net */
 #define VIRTIO_ID_NET  1
 
-/* The bitmap of config for virtio net */
-#define VIRTIO_CONFIG_NET_F    0x40
-#define VIRTIO_NET_F_NO_CSUM   0
-#define VIRTIO_NET_F_TSO4      1
-#define VIRTIO_NET_F_UFO       2
-#define VIRTIO_NET_F_TSO4_ECN  3
-#define VIRTIO_NET_F_TSO6      4
+/* The feature bitmap for virtio net */
+#define VIRTIO_NET_F_CSUM      0       /* Can handle pkts w/ partial csum */
+#define VIRTIO_NET_F_MAC       5       /* Host has given MAC address. */
+#define VIRTIO_NET_F_GSO       6       /* Can handle pkts w/ any GSO type */
 
-/* The config defining mac address. */
-#define VIRTIO_CONFIG_NET_MAC_F        0x41
+struct virtio_net_config
+{
+       /* The config defining mac address (if VIRTIO_NET_F_MAC) */
+       __u8 mac[6];
+} __attribute__((packed));
 
 /* This is the first element of the scatter-gather list.  If you don't
  * specify GSO or CSUM features, you can simply ignore the header. */
 struct virtio_net_hdr
 {
 #define VIRTIO_NET_HDR_F_NEEDS_CSUM    1       // Use csum_start, csum_offset
-      __u8 flags;
+       __u8 flags;
 #define VIRTIO_NET_HDR_GSO_NONE                0       // Not a GSO frame
 #define VIRTIO_NET_HDR_GSO_TCPV4       1       // GSO frame, IPv4 TCP (TSO)
-/* FIXME: Do we need this?  If they said they can handle ECN, do they care? */
-#define VIRTIO_NET_HDR_GSO_TCPV4_ECN   2       // GSO frame, IPv4 TCP w/ ECN
 #define VIRTIO_NET_HDR_GSO_UDP         3       // GSO frame, IPv4 UDP (UFO)
 #define VIRTIO_NET_HDR_GSO_TCPV6       4       // GSO frame, IPv6 TCP
-      __u8 gso_type;
-      __u16 gso_size;
-      __u16 csum_start;
-      __u16 csum_offset;
+#define VIRTIO_NET_HDR_GSO_ECN         0x80    // TCP has ECN set
+       __u8 gso_type;
+       __u16 hdr_len;          /* Ethernet + IP + tcp/udp hdrs */
+       __u16 gso_size;         /* Bytes to append to gso_hdr_len per frame */
+       __u16 csum_start;       /* Position to start checksumming from */
+       __u16 csum_offset;      /* Offset after that to place checksum */
 };
 #endif /* _LINUX_VIRTIO_NET_H */
diff --git a/include/linux/virtio_pci.h b/include/linux/virtio_pci.h
new file mode 100644 (file)
index 0000000..b315165
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Virtio PCI driver
+ *
+ * This module allows virtio devices to be used over a virtual PCI device.
+ * This can be used with QEMU based VMMs like KVM or Xen.
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ *  Anthony Liguori  <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef _LINUX_VIRTIO_PCI_H
+#define _LINUX_VIRTIO_PCI_H
+
+#include <linux/virtio_config.h>
+
+/* A 32-bit r/o bitmask of the features supported by the host */
+#define VIRTIO_PCI_HOST_FEATURES       0
+
+/* A 32-bit r/w bitmask of features activated by the guest */
+#define VIRTIO_PCI_GUEST_FEATURES      4
+
+/* A 32-bit r/w PFN for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_PFN           8
+
+/* A 16-bit r/o queue size for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_NUM           12
+
+/* A 16-bit r/w queue selector */
+#define VIRTIO_PCI_QUEUE_SEL           14
+
+/* A 16-bit r/w queue notifier */
+#define VIRTIO_PCI_QUEUE_NOTIFY                16
+
+/* An 8-bit device status register.  */
+#define VIRTIO_PCI_STATUS              18
+
+/* An 8-bit r/o interrupt status register.  Reading the value will return the
+ * current contents of the ISR and will also clear it.  This is effectively
+ * a read-and-acknowledge. */
+#define VIRTIO_PCI_ISR                 19
+
+/* The bit of the ISR which indicates a device configuration change. */
+#define VIRTIO_PCI_ISR_CONFIG          0x2
+
+/* The remaining space is defined by each driver as the per-driver
+ * configuration space */
+#define VIRTIO_PCI_CONFIG              20
+
+/* Virtio ABI version, this must match exactly */
+#define VIRTIO_PCI_ABI_VERSION         0
+#endif
index 1a4ed49f64780cc553a1ac3f6dcca0f2065972ff..abe481ed990e328bd6f5ec1f5212deeed07b9fea 100644 (file)
 /* This marks a buffer as write-only (otherwise read-only). */
 #define VRING_DESC_F_WRITE     2
 
-/* This means don't notify other side when buffer added. */
+/* The Host uses this in used->flags to advise the Guest: don't kick me when
+ * you add a buffer.  It's unreliable, so it's simply an optimization.  Guest
+ * will still kick if it's out of buffers. */
 #define VRING_USED_F_NO_NOTIFY 1
-/* This means don't interrupt guest when buffer consumed. */
+/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
+ * when you consume a buffer.  It's unreliable, so it's simply an
+ * optimization.  */
 #define VRING_AVAIL_F_NO_INTERRUPT     1
 
 /* Virtio ring descriptors: 16 bytes.  These can chain together via "next". */
@@ -89,7 +93,7 @@ struct vring {
  * };
  */
 static inline void vring_init(struct vring *vr, unsigned int num, void *p,
-                             unsigned int pagesize)
+                             unsigned long pagesize)
 {
        vr->num = num;
        vr->desc = p;
@@ -98,7 +102,7 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
                            & ~(pagesize - 1));
 }
 
-static inline unsigned vring_size(unsigned int num, unsigned int pagesize)
+static inline unsigned vring_size(unsigned int num, unsigned long pagesize)
 {
        return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num)
                 + pagesize - 1) & ~(pagesize - 1))
@@ -114,7 +118,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
                                      struct virtio_device *vdev,
                                      void *pages,
                                      void (*notify)(struct virtqueue *vq),
-                                     bool (*callback)(struct virtqueue *vq));
+                                     void (*callback)(struct virtqueue *vq));
 void vring_del_virtqueue(struct virtqueue *vq);
 
 irqreturn_t vring_interrupt(int irq, void *_vq);
index 89338b468d0de9c90d857e7e6154ecebcd3bc598..ce8e7da05807b7e69f0967b6c78620a4c202d6b7 100644 (file)
@@ -45,11 +45,11 @@ extern void *vmalloc_32_user(unsigned long size);
 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
 extern void *__vmalloc_area(struct vm_struct *area, gfp_t gfp_mask,
                                pgprot_t prot);
-extern void vfree(void *addr);
+extern void vfree(const void *addr);
 
 extern void *vmap(struct page **pages, unsigned int count,
                        unsigned long flags, pgprot_t prot);
-extern void vunmap(void *addr);
+extern void vunmap(const void *addr);
 
 extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
                                                        unsigned long pgoff);
@@ -71,7 +71,7 @@ extern struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
 extern struct vm_struct *get_vm_area_node(unsigned long size,
                                          unsigned long flags, int node,
                                          gfp_t gfp_mask);
-extern struct vm_struct *remove_vm_area(void *addr);
+extern struct vm_struct *remove_vm_area(const void *addr);
 
 extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
                        struct page ***pages);
index feb5e99a1079c97c0854669fcf46fcca595ab5f3..9448ffbdcbf62937047a69f1281116f133d5c079 100644 (file)
@@ -77,6 +77,7 @@ void change_console(struct vc_data *new_vc);
 void reset_vc(struct vc_data *vc);
 extern int unbind_con_driver(const struct consw *csw, int first, int last,
                             int deflt);
+int vty_init(void);
 
 /*
  * vc_screen.c shares this temporary buffer with the console write code so that
diff --git a/include/linux/w1-gpio.h b/include/linux/w1-gpio.h
new file mode 100644 (file)
index 0000000..9797fec
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * w1-gpio interface to platform code
+ *
+ * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ */
+#ifndef _LINUX_W1_GPIO_H
+#define _LINUX_W1_GPIO_H
+
+/**
+ * struct w1_gpio_platform_data - Platform-dependent data for w1-gpio
+ * @pin: GPIO pin to use
+ * @is_open_drain: GPIO pin is configured as open drain
+ */
+struct w1_gpio_platform_data {
+       unsigned int pin;
+       unsigned int is_open_drain:1;
+};
+
+#endif /* _LINUX_W1_GPIO_H */
index 1f4fb0a81ecdba3c29717458bbd0e772df0ffb95..33a2aa9e02f2ba93f9bad51a351dd30919251a7a 100644 (file)
@@ -162,6 +162,22 @@ wait_queue_head_t *FASTCALL(bit_waitqueue(void *, int));
 #define wake_up_interruptible_all(x)   __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
 #define wake_up_interruptible_sync(x)  __wake_up_sync((x), TASK_INTERRUPTIBLE, 1)
 
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+/*
+ * macro to avoid include hell
+ */
+#define wake_up_nested(x, s)                                           \
+do {                                                                   \
+       unsigned long flags;                                            \
+                                                                       \
+       spin_lock_irqsave_nested(&(x)->lock, flags, (s));               \
+       wake_up_locked(x);                                              \
+       spin_unlock_irqrestore(&(x)->lock, flags);                      \
+} while (0)
+#else
+#define wake_up_nested(x, s)           wake_up(x)
+#endif
+
 #define __wait_event(wq, condition)                                    \
 do {                                                                   \
        DEFINE_WAIT(__wait);                                            \
index 74e84caa1e208ba529729597bf8a66612d40061b..3160dfed73caf30a48cbfe64dd85a26315f446f9 100644 (file)
@@ -1079,7 +1079,7 @@ struct    iw_priv_args
  */
 struct iw_event
 {
-       __u16           len;                    /* Real lenght of this stuff */
+       __u16           len;                    /* Real length of this stuff */
        __u16           cmd;                    /* Wireless IOCTL */
        union iwreq_data        u;              /* IOCTL fixed payload */
 };
index c6148bbf1250a37ec4d29ba49732ff87a2019506..b7b3362f7717823768d0ae30f539019048ec9571 100644 (file)
@@ -62,6 +62,7 @@ struct writeback_control {
        unsigned for_reclaim:1;         /* Invoked from the page allocator */
        unsigned for_writepages:1;      /* This is a writepages() call */
        unsigned range_cyclic:1;        /* range_start is cyclic */
+       unsigned more_io:1;             /* more io to be dispatched */
 };
 
 /*
@@ -100,6 +101,7 @@ extern int dirty_background_ratio;
 extern int vm_dirty_ratio;
 extern int dirty_writeback_interval;
 extern int dirty_expire_interval;
+extern int vm_highmem_is_dirtyable;
 extern int block_dump;
 extern int laptop_mode;
 
index def131a5ac70085f685b527c6de0f23fccae4d0e..df6b95d2218e26930ef95d0bee2e05187f487659 100644 (file)
@@ -46,6 +46,7 @@ struct xattr_handler {
                   size_t size, int flags);
 };
 
+ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
 ssize_t vfs_getxattr(struct dentry *, char *, void *, size_t);
 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
 int vfs_setxattr(struct dentry *, char *, void *, size_t, int);
index 951c1ae0be7436b606274a63276407f8f8e60a00..a89426667618a42046a592b2f76e9c8262a1a19f 100644 (file)
@@ -4,7 +4,7 @@
     saa6588.c and every driver (e.g. bttv-driver.c) that wants
     to use the saa6588 module.
 
-    Instead of having a seperate rds.h, I'd prefer to include
+    Instead of having a separate rds.h, I'd prefer to include
     this stuff in one of the already existing files like tuner.h
 
     (c) 2005 by Hans J. Koch
index 625346c47ee2e276dd6eb413a96672bbb75014fb..585eb4496990d7a6c32951e301aaf192b09ca244 100644 (file)
@@ -124,6 +124,7 @@ enum {
        P9_DMSOCKET = 0x00100000,
        P9_DMSETUID = 0x00080000,
        P9_DMSETGID = 0x00040000,
+       P9_DMSETVTX = 0x00010000,
 };
 
 /* qid.types */
index 9b9221a213920a8d18504b82559d050cb732742d..e52f93d9ac5fca1dccdbe66a256b2d1b241f1e75 100644 (file)
@@ -3,6 +3,7 @@
  *
  * 9P Client Definitions
  *
+ *  Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com>
  *  Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -29,6 +30,7 @@ struct p9_client {
        spinlock_t lock; /* protect client structure */
        int msize;
        unsigned char dotu;
+       struct p9_trans_module *trans_mod;
        struct p9_trans *trans;
        struct p9_conn *conn;
 
@@ -52,8 +54,7 @@ struct p9_fid {
        struct list_head dlist; /* list of all fids attached to a dentry */
 };
 
-struct p9_client *p9_client_create(struct p9_trans *trans, int msize,
-                                                               int dotu);
+struct p9_client *p9_client_create(const char *dev_name, char *options);
 void p9_client_destroy(struct p9_client *clnt);
 void p9_client_disconnect(struct p9_client *clnt);
 struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
diff --git a/include/net/9p/conn.h b/include/net/9p/conn.h
deleted file mode 100644 (file)
index 756d878..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * include/net/9p/conn.h
- *
- * Connection Definitions
- *
- *  Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
- *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2
- *  as published by the Free Software Foundation.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to:
- *  Free Software Foundation
- *  51 Franklin Street, Fifth Floor
- *  Boston, MA  02111-1301  USA
- *
- */
-
-#ifndef NET_9P_CONN_H
-#define NET_9P_CONN_H
-
-#undef P9_NONBLOCK
-
-struct p9_conn;
-struct p9_req;
-
-/**
- * p9_mux_req_callback - callback function that is called when the
- * response of a request is received. The callback is called from
- * a workqueue and shouldn't block.
- *
- * @req - request
- * @a - the pointer that was specified when the request was send to be
- *      passed to the callback
- */
-typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a);
-
-struct p9_conn *p9_conn_create(struct p9_trans *trans, int msize,
-                                                       unsigned char *dotu);
-void p9_conn_destroy(struct p9_conn *);
-int p9_conn_rpc(struct p9_conn *m, struct p9_fcall *tc, struct p9_fcall **rc);
-
-#ifdef P9_NONBLOCK
-int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc,
-       p9_conn_req_callback cb, void *a);
-#endif /* P9_NONBLOCK */
-
-void p9_conn_cancel(struct p9_conn *m, int err);
-
-#endif /* NET_9P_CONN_H */
index 9dd4a05619a886c7bd7fa79fff3aa53315fcb4cd..d2209ae9d18b1a94a61e14ff00c4d6e0d2f1c638 100644 (file)
@@ -4,7 +4,7 @@
  * Transport Definition
  *
  *  Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
- *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
+ *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
@@ -34,11 +34,12 @@ enum p9_trans_status {
 
 struct p9_trans {
        enum p9_trans_status status;
+       int msize;
+       unsigned char extended;
        void *priv;
-       int (*write) (struct p9_trans *, void *, int);
-       int (*read) (struct p9_trans *, void *, int);
        void (*close) (struct p9_trans *);
-       unsigned int (*poll)(struct p9_trans *, struct poll_table_struct *);
+       int (*rpc) (struct p9_trans *t, struct p9_fcall *tc,
+                                                       struct p9_fcall **rc);
 };
 
 struct p9_trans_module {
@@ -46,7 +47,7 @@ struct p9_trans_module {
        char *name;             /* name of transport */
        int maxsize;            /* max message size of transport */
        int def;                /* this transport should be default */
-       struct p9_trans * (*create)(const char *devname, char *options);
+       struct p9_trans * (*create)(const char *, char *, int, unsigned char);
 };
 
 void v9fs_register_trans(struct p9_trans_module *m);
index b24508abb8505bff87d1ba1f139f25db0f4a10e6..b2cfc4927257cd2307ed31b96ecd0dd5759f0618 100644 (file)
@@ -112,13 +112,13 @@ struct ifmcaddr6
        struct ip6_sf_list      *mca_sources;
        struct ip6_sf_list      *mca_tomb;
        unsigned int            mca_sfmode;
+       unsigned char           mca_crcount;
        unsigned long           mca_sfcount[2];
        struct timer_list       mca_timer;
        unsigned                mca_flags;
        int                     mca_users;
        atomic_t                mca_refcnt;
        spinlock_t              mca_lock;
-       unsigned char           mca_crcount;
        unsigned long           mca_cstamp;
        unsigned long           mca_tstamp;
 };
@@ -166,11 +166,11 @@ struct inet6_dev
        struct ifmcaddr6        *mc_list;
        struct ifmcaddr6        *mc_tomb;
        rwlock_t                mc_lock;
-       unsigned long           mc_v1_seen;
-       unsigned long           mc_maxdelay;
        unsigned char           mc_qrv;
        unsigned char           mc_gq_running;
        unsigned char           mc_ifc_count;
+       unsigned long           mc_v1_seen;
+       unsigned long           mc_maxdelay;
        struct timer_list       mc_gq_timer;    /* general query timer */
        struct timer_list       mc_ifc_timer;   /* interface change timer */
 
index fdff630708ce864470a3f422cd9a1f0deea3fabe..62a5b691858e0369df0e43ae749ef0aeafcf4871 100644 (file)
@@ -49,7 +49,7 @@ static inline int inet6_sk_ehashfn(const struct sock *sk)
        return inet6_ehashfn(laddr, lport, faddr, fport);
 }
 
-extern void __inet6_hash(struct inet_hashinfo *hashinfo, struct sock *sk);
+extern void __inet6_hash(struct sock *sk);
 
 /*
  * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
index 133cf30d2d7928047bb9eed5669bce71c45513ed..f00f0573627b0b36544e50af781ad64b03c67cdc 100644 (file)
@@ -29,7 +29,6 @@
 #undef INET_CSK_CLEAR_TIMERS
 
 struct inet_bind_bucket;
-struct inet_hashinfo;
 struct tcp_congestion_ops;
 
 /*
@@ -59,6 +58,8 @@ struct inet_connection_sock_af_ops {
                                int level, int optname,
                                char __user *optval, int __user *optlen);
        void        (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
+       int         (*bind_conflict)(const struct sock *sk,
+                                    const struct inet_bind_bucket *tb);
 };
 
 /** inet_connection_sock - INET connection oriented sock
@@ -244,10 +245,7 @@ extern struct request_sock *inet_csk_search_req(const struct sock *sk,
                                                const __be32 laddr);
 extern int inet_csk_bind_conflict(const struct sock *sk,
                                  const struct inet_bind_bucket *tb);
-extern int inet_csk_get_port(struct inet_hashinfo *hashinfo,
-                            struct sock *sk, unsigned short snum,
-                            int (*bind_conflict)(const struct sock *sk,
-                                                 const struct inet_bind_bucket *tb));
+extern int inet_csk_get_port(struct sock *sk, unsigned short snum);
 
 extern struct dst_entry* inet_csk_route_req(struct sock *sk,
                                            const struct request_sock *req);
index c23c4ed30724f37e985aa65eb627bd841c5cd962..97dc35ad09bef3c8618445f44d5e97976b0aa2a9 100644 (file)
@@ -221,9 +221,9 @@ static inline int inet_sk_listen_hashfn(const struct sock *sk)
 }
 
 /* Caller must disable local BH processing. */
-static inline void __inet_inherit_port(struct inet_hashinfo *table,
-                                      struct sock *sk, struct sock *child)
+static inline void __inet_inherit_port(struct sock *sk, struct sock *child)
 {
+       struct inet_hashinfo *table = sk->sk_prot->hashinfo;
        const int bhash = inet_bhashfn(inet_sk(child)->num, table->bhash_size);
        struct inet_bind_hashbucket *head = &table->bhash[bhash];
        struct inet_bind_bucket *tb;
@@ -235,15 +235,14 @@ static inline void __inet_inherit_port(struct inet_hashinfo *table,
        spin_unlock(&head->lock);
 }
 
-static inline void inet_inherit_port(struct inet_hashinfo *table,
-                                    struct sock *sk, struct sock *child)
+static inline void inet_inherit_port(struct sock *sk, struct sock *child)
 {
        local_bh_disable();
-       __inet_inherit_port(table, sk, child);
+       __inet_inherit_port(sk, child);
        local_bh_enable();
 }
 
-extern void inet_put_port(struct inet_hashinfo *table, struct sock *sk);
+extern void inet_put_port(struct sock *sk);
 
 extern void inet_listen_wlock(struct inet_hashinfo *hashinfo);
 
@@ -266,41 +265,9 @@ static inline void inet_listen_unlock(struct inet_hashinfo *hashinfo)
                wake_up(&hashinfo->lhash_wait);
 }
 
-extern void __inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk);
-extern void __inet_hash_nolisten(struct inet_hashinfo *hinfo, struct sock *sk);
-
-static inline void inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk)
-{
-       if (sk->sk_state != TCP_CLOSE) {
-               local_bh_disable();
-               __inet_hash(hashinfo, sk);
-               local_bh_enable();
-       }
-}
-
-static inline void inet_unhash(struct inet_hashinfo *hashinfo, struct sock *sk)
-{
-       rwlock_t *lock;
-
-       if (sk_unhashed(sk))
-               goto out;
-
-       if (sk->sk_state == TCP_LISTEN) {
-               local_bh_disable();
-               inet_listen_wlock(hashinfo);
-               lock = &hashinfo->lhash_lock;
-       } else {
-               lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
-               write_lock_bh(lock);
-       }
-
-       if (__sk_del_node_init(sk))
-               sock_prot_inuse_add(sk->sk_prot, -1);
-       write_unlock_bh(lock);
-out:
-       if (sk->sk_state == TCP_LISTEN)
-               wake_up(&hashinfo->lhash_wait);
-}
+extern void __inet_hash_nolisten(struct sock *sk);
+extern void inet_hash(struct sock *sk);
+extern void inet_unhash(struct sock *sk);
 
 extern struct sock *__inet_lookup_listener(struct net *net,
                                           struct inet_hashinfo *hashinfo,
@@ -422,10 +389,10 @@ static inline struct sock *inet_lookup(struct net *net,
 }
 
 extern int __inet_hash_connect(struct inet_timewait_death_row *death_row,
-               struct sock *sk,
+               struct sock *sk, u32 port_offset,
                int (*check_established)(struct inet_timewait_death_row *,
                        struct sock *, __u16, struct inet_timewait_sock **),
-               void (*hash)(struct inet_hashinfo *, struct sock *));
+                              void (*hash)(struct sock *sk));
 extern int inet_hash_connect(struct inet_timewait_death_row *death_row,
                             struct sock *sk);
 #endif /* _INET_HASHTABLES_H */
index 67e925065aaeee1245c8088a6ccead3a128f4fc2..296547bfb0b726610141c511504d358e518e4d94 100644 (file)
@@ -116,6 +116,7 @@ struct inet_timewait_sock {
 #define tw_hash                        __tw_common.skc_hash
 #define tw_prot                        __tw_common.skc_prot
 #define tw_net                 __tw_common.skc_net
+       int                     tw_timeout;
        volatile unsigned char  tw_substate;
        /* 3 bits hole, try to pack */
        unsigned char           tw_rcv_wscale;
@@ -130,7 +131,6 @@ struct inet_timewait_sock {
        __u8                    tw_ipv6only:1;
        /* 15 bits hole, try to pack */
        __u16                   tw_ipv6_offset;
-       int                     tw_timeout;
        unsigned long           tw_ttd;
        struct inet_bind_bucket *tw_tb;
        struct hlist_node       tw_death_node;
index 90d1175f63dec46938ef08b5b6a9fdfc0cd297c5..8b12667f7a2bccad312fc0e63e679dfd02ec3509 100644 (file)
@@ -266,6 +266,14 @@ static inline void fib_res_put(struct fib_result *res)
 #ifdef CONFIG_PROC_FS
 extern int __net_init  fib_proc_init(struct net *net);
 extern void __net_exit fib_proc_exit(struct net *net);
+#else
+static inline int fib_proc_init(struct net *net)
+{
+       return 0;
+}
+static inline void fib_proc_exit(struct net *net)
+{
+}
 #endif
 
 #endif  /* _NET_FIB_H */
index fa80ea48639dd30002bfeaac4200eaef4bce7faf..c0c019f72ba95a1896cdf7c77c1312491318210b 100644 (file)
@@ -110,7 +110,6 @@ struct frag_hdr {
 
 /* sysctls */
 extern int sysctl_mld_max_msf;
-
 extern struct ctl_path net_ipv6_ctl_path[];
 
 #define _DEVINC(statname, modifier, idev, field)                       \
@@ -586,9 +585,6 @@ extern int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
                         int __user *optlen);
 
 #ifdef CONFIG_PROC_FS
-extern struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
-extern struct ctl_table *ipv6_route_sysctl_init(struct net *net);
-
 extern int  ac6_proc_init(void);
 extern void ac6_proc_exit(void);
 extern int  raw6_proc_init(void);
@@ -621,6 +617,8 @@ static inline int snmp6_unregister_dev(struct inet6_dev *idev)
 extern ctl_table ipv6_route_table_template[];
 extern ctl_table ipv6_icmp_table_template[];
 
+extern struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
+extern struct ctl_table *ipv6_route_sysctl_init(struct net *net);
 extern int ipv6_sysctl_register(void);
 extern void ipv6_sysctl_unregister(void);
 #endif
index b3213c7c53096d97b45b5e51ca842ba01284fefc..0ca67d73c7ad81b177dea9a08c4ea0e65e262ab8 100644 (file)
@@ -36,6 +36,8 @@
 #include <net/netlink.h>
 #include <asm/atomic.h>
 
+struct cipso_v4_doi;
+
 /*
  * NetLabel - A management interface for maintaining network packet label
  *            mapping tables for explicit packet labling protocols.
@@ -103,12 +105,6 @@ struct netlbl_audit {
        uid_t loginuid;
 };
 
-/* Domain mapping definition struct */
-struct netlbl_dom_map;
-
-/* Domain mapping operations */
-int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info);
-
 /*
  * LSM security attributes
  */
@@ -343,6 +339,19 @@ static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr)
 }
 
 #ifdef CONFIG_NETLABEL
+/*
+ * LSM configuration operations
+ */
+int netlbl_cfg_map_del(const char *domain, struct netlbl_audit *audit_info);
+int netlbl_cfg_unlbl_add_map(const char *domain,
+                            struct netlbl_audit *audit_info);
+int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def,
+                          struct netlbl_audit *audit_info);
+int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def,
+                              const char *domain,
+                              struct netlbl_audit *audit_info);
+int netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info);
+
 /*
  * LSM security attribute operations
  */
@@ -378,6 +387,32 @@ void netlbl_cache_invalidate(void);
 int netlbl_cache_add(const struct sk_buff *skb,
                     const struct netlbl_lsm_secattr *secattr);
 #else
+static inline int netlbl_cfg_map_del(const char *domain,
+                                    struct netlbl_audit *audit_info)
+{
+       return -ENOSYS;
+}
+static inline int netlbl_cfg_unlbl_add_map(const char *domain,
+                                          struct netlbl_audit *audit_info)
+{
+       return -ENOSYS;
+}
+static inline int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def,
+                                        struct netlbl_audit *audit_info)
+{
+       return -ENOSYS;
+}
+static inline int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def,
+                                            const char *domain,
+                                            struct netlbl_audit *audit_info)
+{
+       return -ENOSYS;
+}
+static inline int netlbl_cfg_cipsov4_del(u32 doi,
+                                        struct netlbl_audit *audit_info)
+{
+       return -ENOSYS;
+}
 static inline int netlbl_secattr_catmap_walk(
                                      struct netlbl_lsm_secattr_catmap *catmap,
                                      u32 offset)
index e3fb4c047f4c99b1bdb73471010916243e733bbf..8a7889b35810ce9e6ee4c4799af4d79c7315c0a6 100644 (file)
@@ -496,6 +496,7 @@ extern int sk_wait_data(struct sock *sk, long *timeo);
 
 struct request_sock_ops;
 struct timewait_sock_ops;
+struct inet_hashinfo;
 
 /* Networking protocol blocks we attach to sockets.
  * socket layer -> transport layer interface
@@ -578,6 +579,8 @@ struct proto {
        struct request_sock_ops *rsk_prot;
        struct timewait_sock_ops *twsk_prot;
 
+       struct inet_hashinfo    *hashinfo;
+
        struct module           *owner;
 
        char                    name[32];
index d5838c30d20f716cf69c7adc7183b6f580a30640..87a260e3699efd3dd138216e84038ed916064060 100644 (file)
@@ -147,11 +147,11 @@ typedef struct config_req_t {
 
 /* For RequestIO and ReleaseIO */
 typedef struct io_req_t {
-    ioaddr_t   BasePort1;
-    ioaddr_t   NumPorts1;
+    u_int      BasePort1;
+    u_int      NumPorts1;
     u_int      Attributes1;
-    ioaddr_t   BasePort2;
-    ioaddr_t   NumPorts2;
+    u_int      BasePort2;
+    u_int      NumPorts2;
     u_int      Attributes2;
     u_int      IOAddrLines;
 } io_req_t;
index 5f388035687de5004d11d42fbb436abb08fb325b..9a6bcc4952f0653fbc8dafad010b3c87b9be11bf 100644 (file)
@@ -27,7 +27,6 @@ typedef u_int   ioaddr_t;
 #else
 typedef u_short        ioaddr_t;
 #endif
-typedef unsigned long kio_addr_t;
 
 typedef u_short        socket_t;
 typedef u_int  event_t;
index 6e84258b94de2475cd48afc6c69d2f46999a76ca..f95dca077c1c2fdc8cc5c59562185fadc2c65ddd 100644 (file)
@@ -92,7 +92,7 @@ typedef struct pccard_io_map {
     u_char     map;
     u_char     flags;
     u_short    speed;
-    kio_addr_t start, stop;
+    u_int      start, stop;
 } pccard_io_map;
 
 typedef struct pccard_mem_map {
@@ -155,7 +155,7 @@ extern struct pccard_resource_ops pccard_iodyn_ops;
 struct pcmcia_socket;
 
 typedef struct io_window_t {
-       kio_addr_t              InUse, Config;
+       u_int                   InUse, Config;
        struct resource         *res;
 } io_window_t;
 
@@ -208,7 +208,7 @@ struct pcmcia_socket {
        u_int                           features;
        u_int                           irq_mask;
        u_int                           map_size;
-       kio_addr_t                      io_offset;
+       u_int                           io_offset;
        u_char                          pci_irq;
        struct pci_dev *                cb_dev;
 
index e466d886e19283621c2e6af4f6087ce7eafa2d1e..4769efd4db24ec745cd4f5baff15fcfa76e12e5c 100644 (file)
@@ -176,7 +176,7 @@ struct class_device_attribute class_device_attr_vport_##_name =     \
  * ports has a unique presense on the SAN, and may be instantiated via
  * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a
  * unique presense, each vport has it's own view of the fabric,
- * authentication priviledge, and priorities.
+ * authentication privilege, and priorities.
  *
  * A virtual port may support 1 or more FC4 roles. Typically it is a
  * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC
index 4eea63761a3f481fa8f6dd9ed5259056fee71668..336c20db87f817f2d6667e02b5a05b1592fb3148 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef __ATMEL_LCDC_H__
 #define __ATMEL_LCDC_H__
 
- /* LCD Controller info data structure */
+ /* LCD Controller info data structure, stored in device platform_data */
 struct atmel_lcdfb_info {
        spinlock_t              lock;
        struct fb_info          *info;
@@ -33,7 +33,14 @@ struct atmel_lcdfb_info {
        struct platform_device  *pdev;
        struct clk              *bus_clk;
        struct clk              *lcdc_clk;
-       unsigned int            default_bpp;
+
+#ifdef CONFIG_BACKLIGHT_ATMEL_LCDC
+       struct backlight_device *backlight;
+       u8                      bl_power;
+#endif
+       bool                    lcdcon_is_backlight;
+
+       u8                      default_bpp;
        unsigned int            default_lcdcon2;
        unsigned int            default_dmacon;
        void (*atmel_lcdfb_power_control)(int on);
@@ -115,20 +122,20 @@ struct atmel_lcdfb_info {
 #define                ATMEL_LCDC_MEMOR_LITTLE         (1 << 31)
 
 #define ATMEL_LCDC_TIM1                0x0808
-#define        ATMEL_LCDC_VFP          (0xff <<  0)
+#define        ATMEL_LCDC_VFP          (0xffU <<  0)
 #define        ATMEL_LCDC_VBP_OFFSET           8
-#define        ATMEL_LCDC_VBP          (0xff <<  ATMEL_LCDC_VBP_OFFSET)
+#define        ATMEL_LCDC_VBP          (0xffU <<  ATMEL_LCDC_VBP_OFFSET)
 #define        ATMEL_LCDC_VPW_OFFSET           16
-#define        ATMEL_LCDC_VPW          (0x3f << ATMEL_LCDC_VPW_OFFSET)
+#define        ATMEL_LCDC_VPW          (0x3fU << ATMEL_LCDC_VPW_OFFSET)
 #define        ATMEL_LCDC_VHDLY_OFFSET         24
-#define        ATMEL_LCDC_VHDLY        (0xf  << ATMEL_LCDC_VHDLY_OFFSET)
+#define        ATMEL_LCDC_VHDLY        (0xfU  << ATMEL_LCDC_VHDLY_OFFSET)
 
 #define ATMEL_LCDC_TIM2                0x080c
-#define        ATMEL_LCDC_HBP          (0xff  <<  0)
+#define        ATMEL_LCDC_HBP          (0xffU  <<  0)
 #define        ATMEL_LCDC_HPW_OFFSET           8
-#define        ATMEL_LCDC_HPW          (0x3f  <<  ATMEL_LCDC_HPW_OFFSET)
+#define        ATMEL_LCDC_HPW          (0x3fU  <<  ATMEL_LCDC_HPW_OFFSET)
 #define        ATMEL_LCDC_HFP_OFFSET           21
-#define        ATMEL_LCDC_HFP          (0x7ff << ATMEL_LCDC_HFP_OFFSET)
+#define        ATMEL_LCDC_HFP          (0x7ffU << ATMEL_LCDC_HFP_OFFSET)
 
 #define ATMEL_LCDC_LCDFRMCFG   0x0810
 #define        ATMEL_LCDC_LINEVAL      (0x7ff <<  0)
index dcc96a8c8c697451412d811a759b0a3683c265f8..92b23e256614ccdb11b94523043551d45fb15036 100644 (file)
@@ -541,6 +541,18 @@ config ELF_CORE
        help
          Enable support for generating core dumps. Disabling saves about 4k.
 
+config COMPAT_BRK
+       bool "Disable heap randomization"
+       default y
+       help
+         Randomizing heap placement makes heap exploits harder, but it
+         also breaks ancient binaries (including anything libc5 based).
+         This option changes the bootup default to heap randomization
+         disabled, and can be overriden runtime by setting
+         /proc/sys/kernel/randomize_va_space to 2.
+
+         On non-ancient distros (post-2000 ones) Y is usually a safe choice.
+
 config BASE_FULL
        default y
        bool "Enable full-sized data structures for core" if EMBEDDED
@@ -582,7 +594,6 @@ config SIGNALFD
 config TIMERFD
        bool "Enable timerfd() system call" if EMBEDDED
        select ANON_INODES
-       depends on BROKEN
        default y
        help
          Enable the timerfd() system call that allows to receive timer
@@ -657,14 +668,36 @@ config SLOB
        depends on EMBEDDED
        bool "SLOB (Simple Allocator)"
        help
-          SLOB replaces the SLAB allocator with a drastically simpler
-          allocator.  SLOB is more space efficient than SLAB but does not
-          scale well (single lock for all operations) and is also highly
-          susceptible to fragmentation. SLUB can accomplish a higher object
-          density. It is usually better to use SLUB instead of SLOB.
+          SLOB replaces the stock allocator with a drastically simpler
+          allocator. SLOB is generally more space efficient but
+          does not perform as well on large systems.
 
 endchoice
 
+config PROFILING
+       bool "Profiling support (EXPERIMENTAL)"
+       help
+         Say Y here to enable the extended profiling support mechanisms used
+         by profilers such as OProfile.
+
+config MARKERS
+       bool "Activate markers"
+       help
+         Place an empty function call at each marker site. Can be
+         dynamically changed for a probe function.
+
+source "arch/Kconfig"
+
+config PROC_PAGE_MONITOR
+       default y
+       depends on PROC_FS && MMU
+       bool "Enable /proc page monitoring" if EMBEDDED
+       help
+         Various /proc files exist to monitor process memory utilization:
+         /proc/pid/smaps, /proc/pid/clear_refs, /proc/pid/pagemap,
+         /proc/kpagecount, and /proc/kpageflags. Disabling these
+          interfaces will reduce the size of the kernel by approximately 4kb.
+
 endmenu                # General setup
 
 config SLABINFO
index 2d3d73bd4ce13b18dcbe6d9ebd63efe1cd70c073..ecb3822d4f70ed177c45318c31aeaf8f58b1273a 100644 (file)
@@ -7,8 +7,7 @@
 #include <linux/jiffies.h>
 #include <linux/delay.h>
 #include <linux/init.h>
-
-#include <asm/timex.h>
+#include <linux/timex.h>
 
 unsigned long preset_lpj;
 static int __init lpj_setup(char *str)
@@ -29,7 +28,7 @@ __setup("lpj=", lpj_setup);
 #define DELAY_CALIBRATION_TICKS                        ((HZ < 100) ? 1 : (HZ/100))
 #define MAX_DIRECT_CALIBRATION_RETRIES         5
 
-static unsigned long __devinit calibrate_delay_direct(void)
+static unsigned long __cpuinit calibrate_delay_direct(void)
 {
        unsigned long pre_start, start, post_start;
        unsigned long pre_end, end, post_end;
@@ -102,7 +101,7 @@ static unsigned long __devinit calibrate_delay_direct(void)
        return 0;
 }
 #else
-static unsigned long __devinit calibrate_delay_direct(void) {return 0;}
+static unsigned long __cpuinit calibrate_delay_direct(void) {return 0;}
 #endif
 
 /*
@@ -112,7 +111,7 @@ static unsigned long __devinit calibrate_delay_direct(void) {return 0;}
  */
 #define LPS_PREC 8
 
-void __devinit calibrate_delay(void)
+void __cpuinit calibrate_delay(void)
 {
        unsigned long ticks, loopbit;
        int lps_precision = LPS_PREC;
index 1161dfd7b0d3d23a4f9968c973a5f578b42c341d..f86573126f83fe76c3b87d85342786cb5a158204 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/mount.h>
 #include <linux/device.h>
 #include <linux/init.h>
+#include <linux/fs.h>
 
 #include <linux/nfs_fs.h>
 #include <linux/nfs_fs_sb.h>
@@ -18,8 +19,6 @@
 
 #include "do_mounts.h"
 
-extern int get_filesystem_list(char * buf);
-
 int __initdata rd_doload;      /* 1 = load RAM disk, 0 = don't load */
 
 int root_mountflags = MS_RDONLY | MS_SILENT;
index 1db02a0025db2a5f805ed78d7f88a8cf30a230df..d53fee8d8604a5514889bfcd93acee4dd882fae0 100644 (file)
@@ -503,7 +503,6 @@ static int __init retain_initrd_param(char *str)
 __setup("retain_initrd", retain_initrd_param);
 
 extern char __initramfs_start[], __initramfs_end[];
-#ifdef CONFIG_BLK_DEV_INITRD
 #include <linux/initrd.h>
 #include <linux/kexec.h>
 
@@ -539,15 +538,12 @@ skip:
        initrd_end = 0;
 }
 
-#endif
-
 static int __init populate_rootfs(void)
 {
        char *err = unpack_to_rootfs(__initramfs_start,
                         __initramfs_end - __initramfs_start, 0);
        if (err)
                panic(err);
-#ifdef CONFIG_BLK_DEV_INITRD
        if (initrd_start) {
 #ifdef CONFIG_BLK_DEV_RAM
                int fd;
@@ -579,7 +575,6 @@ static int __init populate_rootfs(void)
                free_initrd();
 #endif
        }
-#endif
        return 0;
 }
 rootfs_initcall(populate_rootfs);
index cb81ed116f62b3cadbde986e508081295c0446d9..c691f5f7fc27b40ea6b2df39e2fef9ac52b4cd0a 100644 (file)
@@ -57,6 +57,7 @@
 #include <linux/device.h>
 #include <linux/kthread.h>
 #include <linux/sched.h>
+#include <linux/signal.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -83,7 +84,6 @@ extern void init_IRQ(void);
 extern void fork_init(unsigned long);
 extern void mca_init(void);
 extern void sbus_init(void);
-extern void signals_init(void);
 extern void pidhash_init(void);
 extern void pidmap_init(void);
 extern void prio_tree_init(void);
index fdf3db5731ce8df2cfd038f40c69710243d85338..ec0c724054b95ce733eee1510d044df7d95bea20 100644 (file)
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -105,6 +105,7 @@ int msg_init_ns(struct ipc_namespace *ns)
 void msg_exit_ns(struct ipc_namespace *ns)
 {
        struct msg_queue *msq;
+       struct kern_ipc_perm *perm;
        int next_id;
        int total, in_use;
 
@@ -113,10 +114,11 @@ void msg_exit_ns(struct ipc_namespace *ns)
        in_use = msg_ids(ns).in_use;
 
        for (total = 0, next_id = 0; total < in_use; next_id++) {
-               msq = idr_find(&msg_ids(ns).ipcs_idr, next_id);
-               if (msq == NULL)
+               perm = idr_find(&msg_ids(ns).ipcs_idr, next_id);
+               if (perm == NULL)
                        continue;
-               ipc_lock_by_ptr(&msq->q_perm);
+               ipc_lock_by_ptr(perm);
+               msq = container_of(perm, struct msg_queue, q_perm);
                freeque(ns, msq);
                total++;
        }
@@ -144,6 +146,9 @@ static inline struct msg_queue *msg_lock_check_down(struct ipc_namespace *ns,
 {
        struct kern_ipc_perm *ipcp = ipc_lock_check_down(&msg_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct msg_queue *)ipcp;
+
        return container_of(ipcp, struct msg_queue, q_perm);
 }
 
@@ -155,6 +160,9 @@ static inline struct msg_queue *msg_lock(struct ipc_namespace *ns, int id)
 {
        struct kern_ipc_perm *ipcp = ipc_lock(&msg_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct msg_queue *)ipcp;
+
        return container_of(ipcp, struct msg_queue, q_perm);
 }
 
@@ -163,6 +171,9 @@ static inline struct msg_queue *msg_lock_check(struct ipc_namespace *ns,
 {
        struct kern_ipc_perm *ipcp = ipc_lock_check(&msg_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct msg_queue *)ipcp;
+
        return container_of(ipcp, struct msg_queue, q_perm);
 }
 
index 35952c0bae4629cac017c4c62623c91a022ebee5..d65e285b7e309de03d68cbef348929d0b23f961f 100644 (file)
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -143,6 +143,7 @@ int sem_init_ns(struct ipc_namespace *ns)
 void sem_exit_ns(struct ipc_namespace *ns)
 {
        struct sem_array *sma;
+       struct kern_ipc_perm *perm;
        int next_id;
        int total, in_use;
 
@@ -151,10 +152,11 @@ void sem_exit_ns(struct ipc_namespace *ns)
        in_use = sem_ids(ns).in_use;
 
        for (total = 0, next_id = 0; total < in_use; next_id++) {
-               sma = idr_find(&sem_ids(ns).ipcs_idr, next_id);
-               if (sma == NULL)
+               perm = idr_find(&sem_ids(ns).ipcs_idr, next_id);
+               if (perm == NULL)
                        continue;
-               ipc_lock_by_ptr(&sma->sem_perm);
+               ipc_lock_by_ptr(perm);
+               sma = container_of(perm, struct sem_array, sem_perm);
                freeary(ns, sma);
                total++;
        }
@@ -181,6 +183,9 @@ static inline struct sem_array *sem_lock_check_down(struct ipc_namespace *ns,
 {
        struct kern_ipc_perm *ipcp = ipc_lock_check_down(&sem_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct sem_array *)ipcp;
+
        return container_of(ipcp, struct sem_array, sem_perm);
 }
 
@@ -192,6 +197,9 @@ static inline struct sem_array *sem_lock(struct ipc_namespace *ns, int id)
 {
        struct kern_ipc_perm *ipcp = ipc_lock(&sem_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct sem_array *)ipcp;
+
        return container_of(ipcp, struct sem_array, sem_perm);
 }
 
@@ -200,6 +208,9 @@ static inline struct sem_array *sem_lock_check(struct ipc_namespace *ns,
 {
        struct kern_ipc_perm *ipcp = ipc_lock_check(&sem_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct sem_array *)ipcp;
+
        return container_of(ipcp, struct sem_array, sem_perm);
 }
 
index 3818fae625c5252363380fa9c7a521e8b5c1a7d1..65c3a294aba5cf265823f3d6f369b7b206643d22 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -111,6 +111,7 @@ int shm_init_ns(struct ipc_namespace *ns)
 void shm_exit_ns(struct ipc_namespace *ns)
 {
        struct shmid_kernel *shp;
+       struct kern_ipc_perm *perm;
        int next_id;
        int total, in_use;
 
@@ -119,10 +120,11 @@ void shm_exit_ns(struct ipc_namespace *ns)
        in_use = shm_ids(ns).in_use;
 
        for (total = 0, next_id = 0; total < in_use; next_id++) {
-               shp = idr_find(&shm_ids(ns).ipcs_idr, next_id);
-               if (shp == NULL)
+               perm = idr_find(&shm_ids(ns).ipcs_idr, next_id);
+               if (perm == NULL)
                        continue;
-               ipc_lock_by_ptr(&shp->shm_perm);
+               ipc_lock_by_ptr(perm);
+               shp = container_of(perm, struct shmid_kernel, shm_perm);
                do_shm_rmid(ns, shp);
                total++;
        }
@@ -149,6 +151,9 @@ static inline struct shmid_kernel *shm_lock_down(struct ipc_namespace *ns,
 {
        struct kern_ipc_perm *ipcp = ipc_lock_down(&shm_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct shmid_kernel *)ipcp;
+
        return container_of(ipcp, struct shmid_kernel, shm_perm);
 }
 
@@ -158,6 +163,9 @@ static inline struct shmid_kernel *shm_lock_check_down(
 {
        struct kern_ipc_perm *ipcp = ipc_lock_check_down(&shm_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct shmid_kernel *)ipcp;
+
        return container_of(ipcp, struct shmid_kernel, shm_perm);
 }
 
@@ -169,6 +177,9 @@ static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id)
 {
        struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct shmid_kernel *)ipcp;
+
        return container_of(ipcp, struct shmid_kernel, shm_perm);
 }
 
@@ -177,6 +188,9 @@ static inline struct shmid_kernel *shm_lock_check(struct ipc_namespace *ns,
 {
        struct kern_ipc_perm *ipcp = ipc_lock_check(&shm_ids(ns), id);
 
+       if (IS_ERR(ipcp))
+               return (struct shmid_kernel *)ipcp;
+
        return container_of(ipcp, struct shmid_kernel, shm_perm);
 }
 
index 1aa0ebf71bac7e5c30559eb0f60a89bdc6688efb..76c1f3461e22603496652242299af80d0e17d860 100644 (file)
@@ -802,8 +802,8 @@ struct ipc_proc_iter {
 /*
  * This routine locks the ipc structure found at least at position pos.
  */
-struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
-                                       loff_t *new_pos)
+static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
+                                             loff_t *new_pos)
 {
        struct kern_ipc_perm *ipc;
        int total, id;
diff --git a/kernel/Kconfig.instrumentation b/kernel/Kconfig.instrumentation
deleted file mode 100644 (file)
index 468f47a..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-menuconfig INSTRUMENTATION
-       bool "Instrumentation Support"
-       default y
-       ---help---
-         Say Y here to get to see options related to performance measurement,
-         system-wide debugging, and testing. This option alone does not add any
-         kernel code.
-
-         If you say N, all options in this submenu will be skipped and
-         disabled. If you're trying to debug the kernel itself, go see the
-         Kernel Hacking menu.
-
-if INSTRUMENTATION
-
-config PROFILING
-       bool "Profiling support (EXPERIMENTAL)"
-       help
-         Say Y here to enable the extended profiling support mechanisms used
-         by profilers such as OProfile.
-
-config OPROFILE
-       tristate "OProfile system profiling (EXPERIMENTAL)"
-       depends on PROFILING && !UML
-       depends on ARCH_SUPPORTS_OPROFILE || ALPHA || ARM || BLACKFIN || IA64 || M32R || PARISC || PPC || S390 || SUPERH || SPARC
-       help
-         OProfile is a profiling system capable of profiling the
-         whole system, include the kernel, kernel modules, libraries,
-         and applications.
-
-         If unsure, say N.
-
-config KPROBES
-       bool "Kprobes"
-       depends on KALLSYMS && MODULES && !UML
-       depends on X86_32 || IA64 || PPC || S390 || SPARC64 || X86_64 || AVR32
-       help
-         Kprobes allows you to trap at almost any kernel address and
-         execute a callback function.  register_kprobe() establishes
-         a probepoint and specifies the callback.  Kprobes is useful
-         for kernel debugging, non-intrusive instrumentation and testing.
-         If in doubt, say "N".
-
-config MARKERS
-       bool "Activate markers"
-       help
-         Place an empty function call at each marker site. Can be
-         dynamically changed for a probe function.
-
-endif # INSTRUMENTATION
index 8885627ea02138d58901d6c7d5d1cbda07883ccb..135a1b943446eafe72a1da7f272386749b9b0f35 100644 (file)
@@ -8,8 +8,8 @@ obj-y     = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
            signal.o sys.o kmod.o workqueue.o pid.o \
            rcupdate.o extable.o params.o posix-timers.o \
            kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
-           hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \
-           utsname.o notifier.o
+           hrtimer.o rwsem.o nsproxy.o srcu.o \
+           utsname.o notifier.o ksysfs.o pm_qos_params.o
 
 obj-$(CONFIG_SYSCTL) += sysctl_check.o
 obj-$(CONFIG_STACKTRACE) += stacktrace.o
@@ -49,7 +49,6 @@ obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
 obj-$(CONFIG_KPROBES) += kprobes.o
-obj-$(CONFIG_SYSFS) += ksysfs.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
index efbd9cdce1322d8a6e0c93ada872d68aadacf38e..39e8193b41ea658f1d67fca1d91edb38e698edea 100644 (file)
  */
 static DEFINE_SPINLOCK(task_capability_lock);
 
+/*
+ * Leveraged for setting/resetting capabilities
+ */
+
+const kernel_cap_t __cap_empty_set = CAP_EMPTY_SET;
+const kernel_cap_t __cap_full_set = CAP_FULL_SET;
+const kernel_cap_t __cap_init_eff_set = CAP_INIT_EFF_SET;
+
+EXPORT_SYMBOL(__cap_empty_set);
+EXPORT_SYMBOL(__cap_full_set);
+EXPORT_SYMBOL(__cap_init_eff_set);
+
+/*
+ * More recent versions of libcap are available from:
+ *
+ *   http://www.kernel.org/pub/linux/libs/security/linux-privs/
+ */
+
+static void warn_legacy_capability_use(void)
+{
+       static int warned;
+       if (!warned) {
+               char name[sizeof(current->comm)];
+
+               printk(KERN_INFO "warning: `%s' uses 32-bit capabilities"
+                      " (legacy support in use)\n",
+                      get_task_comm(name, current));
+               warned = 1;
+       }
+}
+
 /*
  * For sys_getproccap() and sys_setproccap(), any of the three
  * capability set pointers may be NULL -- indicating that that set is
@@ -42,12 +73,21 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr)
        pid_t pid;
        __u32 version;
        struct task_struct *target;
-       struct __user_cap_data_struct data;
+       unsigned tocopy;
+       kernel_cap_t pE, pI, pP;
 
        if (get_user(version, &header->version))
                return -EFAULT;
 
-       if (version != _LINUX_CAPABILITY_VERSION) {
+       switch (version) {
+       case _LINUX_CAPABILITY_VERSION_1:
+               warn_legacy_capability_use();
+               tocopy = _LINUX_CAPABILITY_U32S_1;
+               break;
+       case _LINUX_CAPABILITY_VERSION_2:
+               tocopy = _LINUX_CAPABILITY_U32S_2;
+               break;
+       default:
                if (put_user(_LINUX_CAPABILITY_VERSION, &header->version))
                        return -EFAULT;
                return -EINVAL;
@@ -71,14 +111,47 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr)
        } else
                target = current;
 
-       ret = security_capget(target, &data.effective, &data.inheritable, &data.permitted);
+       ret = security_capget(target, &pE, &pI, &pP);
 
 out:
        read_unlock(&tasklist_lock);
        spin_unlock(&task_capability_lock);
 
-       if (!ret && copy_to_user(dataptr, &data, sizeof data))
-               return -EFAULT;
+       if (!ret) {
+               struct __user_cap_data_struct kdata[_LINUX_CAPABILITY_U32S];
+               unsigned i;
+
+               for (i = 0; i < tocopy; i++) {
+                       kdata[i].effective = pE.cap[i];
+                       kdata[i].permitted = pP.cap[i];
+                       kdata[i].inheritable = pI.cap[i];
+               }
+
+               /*
+                * Note, in the case, tocopy < _LINUX_CAPABILITY_U32S,
+                * we silently drop the upper capabilities here. This
+                * has the effect of making older libcap
+                * implementations implicitly drop upper capability
+                * bits when they perform a: capget/modify/capset
+                * sequence.
+                *
+                * This behavior is considered fail-safe
+                * behavior. Upgrading the application to a newer
+                * version of libcap will enable access to the newer
+                * capabilities.
+                *
+                * An alternative would be to return an error here
+                * (-ERANGE), but that causes legacy applications to
+                * unexpectidly fail; the capget/modify/capset aborts
+                * before modification is attempted and the application
+                * fails.
+                */
+
+               if (copy_to_user(dataptr, kdata, tocopy
+                                * sizeof(struct __user_cap_data_struct))) {
+                       return -EFAULT;
+               }
+       }
 
        return ret;
 }
@@ -167,6 +240,8 @@ static inline int cap_set_all(kernel_cap_t *effective,
  */
 asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
 {
+       struct __user_cap_data_struct kdata[_LINUX_CAPABILITY_U32S];
+       unsigned i, tocopy;
        kernel_cap_t inheritable, permitted, effective;
        __u32 version;
        struct task_struct *target;
@@ -176,7 +251,15 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
        if (get_user(version, &header->version))
                return -EFAULT;
 
-       if (version != _LINUX_CAPABILITY_VERSION) {
+       switch (version) {
+       case _LINUX_CAPABILITY_VERSION_1:
+               warn_legacy_capability_use();
+               tocopy = _LINUX_CAPABILITY_U32S_1;
+               break;
+       case _LINUX_CAPABILITY_VERSION_2:
+               tocopy = _LINUX_CAPABILITY_U32S_2;
+               break;
+       default:
                if (put_user(_LINUX_CAPABILITY_VERSION, &header->version))
                        return -EFAULT;
                return -EINVAL;
@@ -188,10 +271,22 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
        if (pid && pid != task_pid_vnr(current) && !capable(CAP_SETPCAP))
                return -EPERM;
 
-       if (copy_from_user(&effective, &data->effective, sizeof(effective)) ||
-           copy_from_user(&inheritable, &data->inheritable, sizeof(inheritable)) ||
-           copy_from_user(&permitted, &data->permitted, sizeof(permitted)))
+       if (copy_from_user(&kdata, data, tocopy
+                          * sizeof(struct __user_cap_data_struct))) {
                return -EFAULT;
+       }
+
+       for (i = 0; i < tocopy; i++) {
+               effective.cap[i] = kdata[i].effective;
+               permitted.cap[i] = kdata[i].permitted;
+               inheritable.cap[i] = kdata[i].inheritable;
+       }
+       while (i < _LINUX_CAPABILITY_U32S) {
+               effective.cap[i] = 0;
+               permitted.cap[i] = 0;
+               inheritable.cap[i] = 0;
+               i++;
+       }
 
        spin_lock(&task_capability_lock);
        read_lock(&tasklist_lock);
index bfb1c0e940e814f7e64a3c707c65a6f5608c0388..eb9934a82fc1a900f29eb751e520603b82f2492f 100644 (file)
@@ -50,8 +50,6 @@
 #include <asm/pgtable.h>
 #include <asm/mmu_context.h>
 
-extern void sem_exit (void);
-
 static void exit_mm(struct task_struct * tsk);
 
 static void __unhash_process(struct task_struct *p)
@@ -1085,11 +1083,12 @@ do_group_exit(int exit_code)
                struct signal_struct *const sig = current->signal;
                struct sighand_struct *const sighand = current->sighand;
                spin_lock_irq(&sighand->siglock);
-               if (sig->flags & SIGNAL_GROUP_EXIT)
+               if (signal_group_exit(sig))
                        /* Another thread got here before we took the lock.  */
                        exit_code = sig->group_exit_code;
                else {
                        sig->group_exit_code = exit_code;
+                       sig->flags = SIGNAL_GROUP_EXIT;
                        zap_other_threads(current);
                }
                spin_unlock_irq(&sighand->siglock);
@@ -1591,8 +1590,6 @@ repeat:
                                        goto repeat;
                                if (retval != 0) /* He released the lock.  */
                                        goto end;
-                       } else if (p->exit_state == EXIT_DEAD) {
-                               continue;
                        } else if (p->exit_state == EXIT_ZOMBIE) {
                                /*
                                 * Eligible but we cannot release it yet:
@@ -1607,7 +1604,7 @@ repeat:
                                /* He released the lock.  */
                                if (retval != 0)
                                        goto end;
-                       } else {
+                       } else if (p->exit_state != EXIT_DEAD) {
 check_continued:
                                /*
                                 * It's running now, so it might later
index 05e0b6f4365bfc5fca5ef1cabd400c3894c013e3..3995297567a9f0a28467f71475e84880199f79ce 100644 (file)
@@ -325,7 +325,7 @@ static inline int mm_alloc_pgd(struct mm_struct * mm)
 
 static inline void mm_free_pgd(struct mm_struct * mm)
 {
-       pgd_free(mm->pgd);
+       pgd_free(mm, mm->pgd);
 }
 #else
 #define dup_mmap(mm, oldmm)    (0)
@@ -1118,6 +1118,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 #ifdef CONFIG_SECURITY
        p->security = NULL;
 #endif
+       p->cap_bset = current->cap_bset;
        p->io_context = NULL;
        p->audit_context = NULL;
        cgroup_fork(p);
@@ -1398,7 +1399,7 @@ fork_out:
        return ERR_PTR(retval);
 }
 
-noinline struct pt_regs * __devinit __attribute__((weak)) idle_regs(struct pt_regs *regs)
+noinline struct pt_regs * __cpuinit __attribute__((weak)) idle_regs(struct pt_regs *regs)
 {
        memset(regs, 0, sizeof(struct pt_regs));
        return regs;
@@ -1450,6 +1451,23 @@ long do_fork(unsigned long clone_flags,
        int trace = 0;
        long nr;
 
+       /*
+        * We hope to recycle these flags after 2.6.26
+        */
+       if (unlikely(clone_flags & CLONE_STOPPED)) {
+               static int __read_mostly count = 100;
+
+               if (count > 0 && printk_ratelimit()) {
+                       char comm[TASK_COMM_LEN];
+
+                       count--;
+                       printk(KERN_INFO "fork(): process `%s' used deprecated "
+                                       "clone flags 0x%lx\n",
+                               get_task_comm(comm, current),
+                               clone_flags & CLONE_STOPPED);
+               }
+       }
+
        if (unlikely(current->ptrace)) {
                trace = fork_traceflag (clone_flags);
                if (trace)
@@ -1492,7 +1510,7 @@ long do_fork(unsigned long clone_flags,
                if (!(clone_flags & CLONE_STOPPED))
                        wake_up_new_task(p, clone_flags);
                else
-                       p->state = TASK_STOPPED;
+                       __set_task_state(p, TASK_STOPPED);
 
                if (unlikely (trace)) {
                        current->ptrace_message = nr;
index 1069998fe25fdcce1af97f7be831852d85b6d20b..668f3967eb394e37fcecc65e47e6dce75173b5dc 100644 (file)
@@ -306,7 +306,7 @@ EXPORT_SYMBOL_GPL(ktime_sub_ns);
 /*
  * Divide a ktime value by a nanosecond value
  */
-unsigned long ktime_divns(const ktime_t kt, s64 div)
+u64 ktime_divns(const ktime_t kt, s64 div)
 {
        u64 dclc, inc, dns;
        int sft = 0;
@@ -321,7 +321,7 @@ unsigned long ktime_divns(const ktime_t kt, s64 div)
        dclc >>= sft;
        do_div(dclc, (unsigned long) div);
 
-       return (unsigned long) dclc;
+       return dclc;
 }
 #endif /* BITS_PER_LONG >= 64 */
 
@@ -656,10 +656,9 @@ void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
  * Forward the timer expiry so it will expire in the future.
  * Returns the number of overruns.
  */
-unsigned long
-hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
+u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
 {
-       unsigned long orun = 1;
+       u64 orun = 1;
        ktime_t delta;
 
        delta = ktime_sub(now, timer->expires);
index 7dadc71ce5162926529172e5a9ff71b86590a4a4..f091d13def0083b8d25107993affa1065cb8aabc 100644 (file)
@@ -53,14 +53,6 @@ static inline int is_kernel_inittext(unsigned long addr)
        return 0;
 }
 
-static inline int is_kernel_extratext(unsigned long addr)
-{
-       if (addr >= (unsigned long)_sextratext
-           && addr <= (unsigned long)_eextratext)
-               return 1;
-       return 0;
-}
-
 static inline int is_kernel_text(unsigned long addr)
 {
        if (addr >= (unsigned long)_stext && addr <= (unsigned long)_etext)
@@ -80,8 +72,7 @@ static int is_ksym_addr(unsigned long addr)
        if (all_var)
                return is_kernel(addr);
 
-       return is_kernel_text(addr) || is_kernel_inittext(addr) ||
-               is_kernel_extratext(addr);
+       return is_kernel_text(addr) || is_kernel_inittext(addr);
 }
 
 /* expand a compressed symbol data into the resulting uncompressed string,
index d0493eafea3ec5d86ece12d8861421b6bea13ec7..7a86e64323385785bda6e838f01c9637e192844a 100644 (file)
@@ -699,6 +699,12 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p,
                                 struct kretprobe_instance, uflist);
                ri->rp = rp;
                ri->task = current;
+
+               if (rp->entry_handler && rp->entry_handler(ri, regs)) {
+                       spin_unlock_irqrestore(&kretprobe_lock, flags);
+                       return 0;
+               }
+
                arch_prepare_kretprobe(ri, regs);
 
                /* XXX(hch): why is there no hlist_move_head? */
@@ -745,7 +751,8 @@ int __kprobes register_kretprobe(struct kretprobe *rp)
        INIT_HLIST_HEAD(&rp->used_instances);
        INIT_HLIST_HEAD(&rp->free_instances);
        for (i = 0; i < rp->maxactive; i++) {
-               inst = kmalloc(sizeof(struct kretprobe_instance), GFP_KERNEL);
+               inst = kmalloc(sizeof(struct kretprobe_instance) +
+                              rp->data_size, GFP_KERNEL);
                if (inst == NULL) {
                        free_rp_inst(rp);
                        return -ENOMEM;
diff --git a/kernel/latency.c b/kernel/latency.c
deleted file mode 100644 (file)
index e63fcac..0000000
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * latency.c: Explicit system-wide latency-expectation infrastructure
- *
- * The purpose of this infrastructure is to allow device drivers to set
- * latency constraint they have and to collect and summarize these
- * expectations globally. The cummulated result can then be used by
- * power management and similar users to make decisions that have
- * tradoffs with a latency component.
- *
- * An example user of this are the x86 C-states; each higher C state saves
- * more power, but has a higher exit latency. For the idle loop power
- * code to make a good decision which C-state to use, information about
- * acceptable latencies is required.
- *
- * An example announcer of latency is an audio driver that knowns it
- * will get an interrupt when the hardware has 200 usec of samples
- * left in the DMA buffer; in that case the driver can set a latency
- * constraint of, say, 150 usec.
- *
- * Multiple drivers can each announce their maximum accepted latency,
- * to keep these appart, a string based identifier is used.
- *
- *
- * (C) Copyright 2006 Intel Corporation
- * Author: Arjan van de Ven <arjan@linux.intel.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- */
-
-#include <linux/latency.h>
-#include <linux/list.h>
-#include <linux/spinlock.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/notifier.h>
-#include <linux/jiffies.h>
-#include <asm/atomic.h>
-
-struct latency_info {
-       struct list_head list;
-       int usecs;
-       char *identifier;
-};
-
-/*
- * locking rule: all modifications to current_max_latency and
- * latency_list need to be done while holding the latency_lock.
- * latency_lock needs to be taken _irqsave.
- */
-static atomic_t current_max_latency;
-static DEFINE_SPINLOCK(latency_lock);
-
-static LIST_HEAD(latency_list);
-static BLOCKING_NOTIFIER_HEAD(latency_notifier);
-
-/*
- * This function returns the maximum latency allowed, which
- * happens to be the minimum of all maximum latencies on the
- * list.
- */
-static int __find_max_latency(void)
-{
-       int min = INFINITE_LATENCY;
-       struct latency_info *info;
-
-       list_for_each_entry(info, &latency_list, list) {
-               if (info->usecs < min)
-                       min = info->usecs;
-       }
-       return min;
-}
-
-/**
- * set_acceptable_latency - sets the maximum latency acceptable
- * @identifier: string that identifies this driver
- * @usecs: maximum acceptable latency for this driver
- *
- * This function informs the kernel that this device(driver)
- * can accept at most usecs latency. This setting is used for
- * power management and similar tradeoffs.
- *
- * This function sleeps and can only be called from process
- * context.
- * Calling this function with an existing identifier is valid
- * and will cause the existing latency setting to be changed.
- */
-void set_acceptable_latency(char *identifier, int usecs)
-{
-       struct latency_info *info, *iter;
-       unsigned long flags;
-       int found_old = 0;
-
-       info = kzalloc(sizeof(struct latency_info), GFP_KERNEL);
-       if (!info)
-               return;
-       info->usecs = usecs;
-       info->identifier = kstrdup(identifier, GFP_KERNEL);
-       if (!info->identifier)
-               goto free_info;
-
-       spin_lock_irqsave(&latency_lock, flags);
-       list_for_each_entry(iter, &latency_list, list) {
-               if (strcmp(iter->identifier, identifier)==0) {
-                       found_old = 1;
-                       iter->usecs = usecs;
-                       break;
-               }
-       }
-       if (!found_old)
-               list_add(&info->list, &latency_list);
-
-       if (usecs < atomic_read(&current_max_latency))
-               atomic_set(&current_max_latency, usecs);
-
-       spin_unlock_irqrestore(&latency_lock, flags);
-
-       blocking_notifier_call_chain(&latency_notifier,
-               atomic_read(&current_max_latency), NULL);
-
-       /*
-        * if we inserted the new one, we're done; otherwise there was
-        * an existing one so we need to free the redundant data
-        */
-       if (!found_old)
-               return;
-
-       kfree(info->identifier);
-free_info:
-       kfree(info);
-}
-EXPORT_SYMBOL_GPL(set_acceptable_latency);
-
-/**
- * modify_acceptable_latency - changes the maximum latency acceptable
- * @identifier: string that identifies this driver
- * @usecs: maximum acceptable latency for this driver
- *
- * This function informs the kernel that this device(driver)
- * can accept at most usecs latency. This setting is used for
- * power management and similar tradeoffs.
- *
- * This function does not sleep and can be called in any context.
- * Trying to use a non-existing identifier silently gets ignored.
- *
- * Due to the atomic nature of this function, the modified latency
- * value will only be used for future decisions; past decisions
- * can still lead to longer latencies in the near future.
- */
-void modify_acceptable_latency(char *identifier, int usecs)
-{
-       struct latency_info *iter;
-       unsigned long flags;
-
-       spin_lock_irqsave(&latency_lock, flags);
-       list_for_each_entry(iter, &latency_list, list) {
-               if (strcmp(iter->identifier, identifier) == 0) {
-                       iter->usecs = usecs;
-                       break;
-               }
-       }
-       if (usecs < atomic_read(&current_max_latency))
-               atomic_set(&current_max_latency, usecs);
-       spin_unlock_irqrestore(&latency_lock, flags);
-}
-EXPORT_SYMBOL_GPL(modify_acceptable_latency);
-
-/**
- * remove_acceptable_latency - removes the maximum latency acceptable
- * @identifier: string that identifies this driver
- *
- * This function removes a previously set maximum latency setting
- * for the driver and frees up any resources associated with the
- * bookkeeping needed for this.
- *
- * This function does not sleep and can be called in any context.
- * Trying to use a non-existing identifier silently gets ignored.
- */
-void remove_acceptable_latency(char *identifier)
-{
-       unsigned long flags;
-       int newmax = 0;
-       struct latency_info *iter, *temp;
-
-       spin_lock_irqsave(&latency_lock, flags);
-
-       list_for_each_entry_safe(iter,  temp, &latency_list, list) {
-               if (strcmp(iter->identifier, identifier) == 0) {
-                       list_del(&iter->list);
-                       newmax = iter->usecs;
-                       kfree(iter->identifier);
-                       kfree(iter);
-                       break;
-               }
-       }
-
-       /* If we just deleted the system wide value, we need to
-        * recalculate with a full search
-        */
-       if (newmax == atomic_read(&current_max_latency)) {
-               newmax = __find_max_latency();
-               atomic_set(&current_max_latency, newmax);
-       }
-       spin_unlock_irqrestore(&latency_lock, flags);
-}
-EXPORT_SYMBOL_GPL(remove_acceptable_latency);
-
-/**
- * system_latency_constraint - queries the system wide latency maximum
- *
- * This function returns the system wide maximum latency in
- * microseconds.
- *
- * This function does not sleep and can be called in any context.
- */
-int system_latency_constraint(void)
-{
-       return atomic_read(&current_max_latency);
-}
-EXPORT_SYMBOL_GPL(system_latency_constraint);
-
-/**
- * synchronize_acceptable_latency - recalculates all latency decisions
- *
- * This function will cause a callback to various kernel pieces that
- * will make those pieces rethink their latency decisions. This implies
- * that if there are overlong latencies in hardware state already, those
- * latencies get taken right now. When this call completes no overlong
- * latency decisions should be active anymore.
- *
- * Typical usecase of this is after a modify_acceptable_latency() call,
- * which in itself is non-blocking and non-synchronizing.
- *
- * This function blocks and should not be called with locks held.
- */
-
-void synchronize_acceptable_latency(void)
-{
-       blocking_notifier_call_chain(&latency_notifier,
-               atomic_read(&current_max_latency), NULL);
-}
-EXPORT_SYMBOL_GPL(synchronize_acceptable_latency);
-
-/*
- * Latency notifier: this notifier gets called when a non-atomic new
- * latency value gets set. The expectation nof the caller of the
- * non-atomic set is that when the call returns, future latencies
- * are within bounds, so the functions on the notifier list are
- * expected to take the overlong latencies immediately, inside the
- * callback, and not make a overlong latency decision anymore.
- *
- * The callback gets called when the new latency value is made
- * active so system_latency_constraint() returns the new latency.
- */
-int register_latency_notifier(struct notifier_block * nb)
-{
-       return blocking_notifier_chain_register(&latency_notifier, nb);
-}
-EXPORT_SYMBOL_GPL(register_latency_notifier);
-
-int unregister_latency_notifier(struct notifier_block * nb)
-{
-       return blocking_notifier_chain_unregister(&latency_notifier, nb);
-}
-EXPORT_SYMBOL_GPL(unregister_latency_notifier);
-
-static __init int latency_init(void)
-{
-       atomic_set(&current_max_latency, INFINITE_LATENCY);
-       /*
-        * we don't want by default to have longer latencies than 2 ticks,
-        * since that would cause lost ticks
-        */
-       set_acceptable_latency("kernel", 2*1000000/HZ);
-       return 0;
-}
-
-module_init(latency_init);
index 4253f472f0606cc419eacf952cc9b801a0441ef9..643360d1bb144fda223301b348059cd5381eb35e 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/notifier.h>
 #include <linux/rcupdate.h>
 #include <linux/vmalloc.h>
+#include <linux/reboot.h>
 
 /*
  *     Notifier list for kernel code which wants to be called
index 42fe5e6126c0948e5b6859f5fcc75ebb71e2b039..e28c70628bb7d1cd723c84b26cbfeb1a6104c2a4 100644 (file)
@@ -272,7 +272,7 @@ static int param_array(const char *name,
                       unsigned int min, unsigned int max,
                       void *elem, int elemsize,
                       int (*set)(const char *, struct kernel_param *kp),
-                      int *num)
+                      unsigned int *num)
 {
        int ret;
        struct kernel_param kp;
diff --git a/kernel/pm_qos_params.c b/kernel/pm_qos_params.c
new file mode 100644 (file)
index 0000000..0afe32b
--- /dev/null
@@ -0,0 +1,425 @@
+/*
+ * This module exposes the interface to kernel space for specifying
+ * QoS dependencies.  It provides infrastructure for registration of:
+ *
+ * Dependents on a QoS value : register requirements
+ * Watchers of QoS value : get notified when target QoS value changes
+ *
+ * This QoS design is best effort based.  Dependents register their QoS needs.
+ * Watchers register to keep track of the current QoS needs of the system.
+ *
+ * There are 3 basic classes of QoS parameter: latency, timeout, throughput
+ * each have defined units:
+ * latency: usec
+ * timeout: usec <-- currently not used.
+ * throughput: kbs (kilo byte / sec)
+ *
+ * There are lists of pm_qos_objects each one wrapping requirements, notifiers
+ *
+ * User mode requirements on a QOS parameter register themselves to the
+ * subsystem by opening the device node /dev/... and writing there request to
+ * the node.  As long as the process holds a file handle open to the node the
+ * client continues to be accounted for.  Upon file release the usermode
+ * requirement is removed and a new qos target is computed.  This way when the
+ * requirement that the application has is cleaned up when closes the file
+ * pointer or exits the pm_qos_object will get an opportunity to clean up.
+ *
+ * mark gross mgross@linux.intel.com
+ */
+
+#include <linux/pm_qos_params.h>
+#include <linux/sched.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+#include <linux/time.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+
+#include <linux/uaccess.h>
+
+/*
+ * locking rule: all changes to target_value or requirements or notifiers lists
+ * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock
+ * held, taken with _irqsave.  One lock to rule them all
+ */
+struct requirement_list {
+       struct list_head list;
+       union {
+               s32 value;
+               s32 usec;
+               s32 kbps;
+       };
+       char *name;
+};
+
+static s32 max_compare(s32 v1, s32 v2);
+static s32 min_compare(s32 v1, s32 v2);
+
+struct pm_qos_object {
+       struct requirement_list requirements;
+       struct blocking_notifier_head *notifiers;
+       struct miscdevice pm_qos_power_miscdev;
+       char *name;
+       s32 default_value;
+       s32 target_value;
+       s32 (*comparitor)(s32, s32);
+};
+
+static struct pm_qos_object null_pm_qos;
+static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier);
+static struct pm_qos_object cpu_dma_pm_qos = {
+       .requirements = {LIST_HEAD_INIT(cpu_dma_pm_qos.requirements.list)},
+       .notifiers = &cpu_dma_lat_notifier,
+       .name = "cpu_dma_latency",
+       .default_value = 2000 * USEC_PER_SEC,
+       .target_value = 2000 * USEC_PER_SEC,
+       .comparitor = min_compare
+};
+
+static BLOCKING_NOTIFIER_HEAD(network_lat_notifier);
+static struct pm_qos_object network_lat_pm_qos = {
+       .requirements = {LIST_HEAD_INIT(network_lat_pm_qos.requirements.list)},
+       .notifiers = &network_lat_notifier,
+       .name = "network_latency",
+       .default_value = 2000 * USEC_PER_SEC,
+       .target_value = 2000 * USEC_PER_SEC,
+       .comparitor = min_compare
+};
+
+
+static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier);
+static struct pm_qos_object network_throughput_pm_qos = {
+       .requirements =
+               {LIST_HEAD_INIT(network_throughput_pm_qos.requirements.list)},
+       .notifiers = &network_throughput_notifier,
+       .name = "network_throughput",
+       .default_value = 0,
+       .target_value = 0,
+       .comparitor = max_compare
+};
+
+
+static struct pm_qos_object *pm_qos_array[] = {
+       &null_pm_qos,
+       &cpu_dma_pm_qos,
+       &network_lat_pm_qos,
+       &network_throughput_pm_qos
+};
+
+static DEFINE_SPINLOCK(pm_qos_lock);
+
+static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
+               size_t count, loff_t *f_pos);
+static int pm_qos_power_open(struct inode *inode, struct file *filp);
+static int pm_qos_power_release(struct inode *inode, struct file *filp);
+
+static const struct file_operations pm_qos_power_fops = {
+       .write = pm_qos_power_write,
+       .open = pm_qos_power_open,
+       .release = pm_qos_power_release,
+};
+
+/* static helper functions */
+static s32 max_compare(s32 v1, s32 v2)
+{
+       return max(v1, v2);
+}
+
+static s32 min_compare(s32 v1, s32 v2)
+{
+       return min(v1, v2);
+}
+
+
+static void update_target(int target)
+{
+       s32 extreme_value;
+       struct requirement_list *node;
+       unsigned long flags;
+       int call_notifier = 0;
+
+       spin_lock_irqsave(&pm_qos_lock, flags);
+       extreme_value = pm_qos_array[target]->default_value;
+       list_for_each_entry(node,
+                       &pm_qos_array[target]->requirements.list, list) {
+               extreme_value = pm_qos_array[target]->comparitor(
+                               extreme_value, node->value);
+       }
+       if (pm_qos_array[target]->target_value != extreme_value) {
+               call_notifier = 1;
+               pm_qos_array[target]->target_value = extreme_value;
+               pr_debug(KERN_ERR "new target for qos %d is %d\n", target,
+                       pm_qos_array[target]->target_value);
+       }
+       spin_unlock_irqrestore(&pm_qos_lock, flags);
+
+       if (call_notifier)
+               blocking_notifier_call_chain(pm_qos_array[target]->notifiers,
+                       (unsigned long) extreme_value, NULL);
+}
+
+static int register_pm_qos_misc(struct pm_qos_object *qos)
+{
+       qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR;
+       qos->pm_qos_power_miscdev.name = qos->name;
+       qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops;
+
+       return misc_register(&qos->pm_qos_power_miscdev);
+}
+
+static int find_pm_qos_object_by_minor(int minor)
+{
+       int pm_qos_class;
+
+       for (pm_qos_class = 0;
+               pm_qos_class < PM_QOS_NUM_CLASSES; pm_qos_class++) {
+               if (minor ==
+                       pm_qos_array[pm_qos_class]->pm_qos_power_miscdev.minor)
+                       return pm_qos_class;
+       }
+       return -1;
+}
+
+/**
+ * pm_qos_requirement - returns current system wide qos expectation
+ * @pm_qos_class: identification of which qos value is requested
+ *
+ * This function returns the current target value in an atomic manner.
+ */
+int pm_qos_requirement(int pm_qos_class)
+{
+       int ret_val;
+       unsigned long flags;
+
+       spin_lock_irqsave(&pm_qos_lock, flags);
+       ret_val = pm_qos_array[pm_qos_class]->target_value;
+       spin_unlock_irqrestore(&pm_qos_lock, flags);
+
+       return ret_val;
+}
+EXPORT_SYMBOL_GPL(pm_qos_requirement);
+
+/**
+ * pm_qos_add_requirement - inserts new qos request into the list
+ * @pm_qos_class: identifies which list of qos request to us
+ * @name: identifies the request
+ * @value: defines the qos request
+ *
+ * This function inserts a new entry in the pm_qos_class list of requested qos
+ * performance charactoistics.  It recomputes the agregate QoS expectations for
+ * the pm_qos_class of parrameters.
+ */
+int pm_qos_add_requirement(int pm_qos_class, char *name, s32 value)
+{
+       struct requirement_list *dep;
+       unsigned long flags;
+
+       dep = kzalloc(sizeof(struct requirement_list), GFP_KERNEL);
+       if (dep) {
+               if (value == PM_QOS_DEFAULT_VALUE)
+                       dep->value = pm_qos_array[pm_qos_class]->default_value;
+               else
+                       dep->value = value;
+               dep->name = kstrdup(name, GFP_KERNEL);
+               if (!dep->name)
+                       goto cleanup;
+
+               spin_lock_irqsave(&pm_qos_lock, flags);
+               list_add(&dep->list,
+                       &pm_qos_array[pm_qos_class]->requirements.list);
+               spin_unlock_irqrestore(&pm_qos_lock, flags);
+               update_target(pm_qos_class);
+
+               return 0;
+       }
+
+cleanup:
+       kfree(dep);
+       return -ENOMEM;
+}
+EXPORT_SYMBOL_GPL(pm_qos_add_requirement);
+
+/**
+ * pm_qos_update_requirement - modifies an existing qos request
+ * @pm_qos_class: identifies which list of qos request to us
+ * @name: identifies the request
+ * @value: defines the qos request
+ *
+ * Updates an existing qos requierement for the pm_qos_class of parameters along
+ * with updating the target pm_qos_class value.
+ *
+ * If the named request isn't in the lest then no change is made.
+ */
+int pm_qos_update_requirement(int pm_qos_class, char *name, s32 new_value)
+{
+       unsigned long flags;
+       struct requirement_list *node;
+       int pending_update = 0;
+
+       spin_lock_irqsave(&pm_qos_lock, flags);
+       list_for_each_entry(node,
+               &pm_qos_array[pm_qos_class]->requirements.list, list) {
+               if (strcmp(node->name, name) == 0) {
+                       if (new_value == PM_QOS_DEFAULT_VALUE)
+                               node->value =
+                               pm_qos_array[pm_qos_class]->default_value;
+                       else
+                               node->value = new_value;
+                       pending_update = 1;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&pm_qos_lock, flags);
+       if (pending_update)
+               update_target(pm_qos_class);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pm_qos_update_requirement);
+
+/**
+ * pm_qos_remove_requirement - modifies an existing qos request
+ * @pm_qos_class: identifies which list of qos request to us
+ * @name: identifies the request
+ *
+ * Will remove named qos request from pm_qos_class list of parrameters and
+ * recompute the current target value for the pm_qos_class.
+ */
+void pm_qos_remove_requirement(int pm_qos_class, char *name)
+{
+       unsigned long flags;
+       struct requirement_list *node;
+       int pending_update = 0;
+
+       spin_lock_irqsave(&pm_qos_lock, flags);
+       list_for_each_entry(node,
+               &pm_qos_array[pm_qos_class]->requirements.list, list) {
+               if (strcmp(node->name, name) == 0) {
+                       kfree(node->name);
+                       list_del(&node->list);
+                       kfree(node);
+                       pending_update = 1;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&pm_qos_lock, flags);
+       if (pending_update)
+               update_target(pm_qos_class);
+}
+EXPORT_SYMBOL_GPL(pm_qos_remove_requirement);
+
+/**
+ * pm_qos_add_notifier - sets notification entry for changes to target value
+ * @pm_qos_class: identifies which qos target changes should be notified.
+ * @notifier: notifier block managed by caller.
+ *
+ * will register the notifier into a notification chain that gets called
+ * uppon changes to the pm_qos_class target value.
+ */
+ int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier)
+{
+       int retval;
+
+       retval = blocking_notifier_chain_register(
+                       pm_qos_array[pm_qos_class]->notifiers, notifier);
+
+       return retval;
+}
+EXPORT_SYMBOL_GPL(pm_qos_add_notifier);
+
+/**
+ * pm_qos_remove_notifier - deletes notification entry from chain.
+ * @pm_qos_class: identifies which qos target changes are notified.
+ * @notifier: notifier block to be removed.
+ *
+ * will remove the notifier from the notification chain that gets called
+ * uppon changes to the pm_qos_class target value.
+ */
+int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier)
+{
+       int retval;
+
+       retval = blocking_notifier_chain_unregister(
+                       pm_qos_array[pm_qos_class]->notifiers, notifier);
+
+       return retval;
+}
+EXPORT_SYMBOL_GPL(pm_qos_remove_notifier);
+
+#define PID_NAME_LEN sizeof("process_1234567890")
+static char name[PID_NAME_LEN];
+
+static int pm_qos_power_open(struct inode *inode, struct file *filp)
+{
+       int ret;
+       long pm_qos_class;
+
+       pm_qos_class = find_pm_qos_object_by_minor(iminor(inode));
+       if (pm_qos_class >= 0) {
+               filp->private_data = (void *)pm_qos_class;
+               sprintf(name, "process_%d", current->pid);
+               ret = pm_qos_add_requirement(pm_qos_class, name,
+                                       PM_QOS_DEFAULT_VALUE);
+               if (ret >= 0)
+                       return 0;
+       }
+
+       return -EPERM;
+}
+
+static int pm_qos_power_release(struct inode *inode, struct file *filp)
+{
+       int pm_qos_class;
+
+       pm_qos_class = (long)filp->private_data;
+       sprintf(name, "process_%d", current->pid);
+       pm_qos_remove_requirement(pm_qos_class, name);
+
+       return 0;
+}
+
+static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
+               size_t count, loff_t *f_pos)
+{
+       s32 value;
+       int pm_qos_class;
+
+       pm_qos_class = (long)filp->private_data;
+       if (count != sizeof(s32))
+               return -EINVAL;
+       if (copy_from_user(&value, buf, sizeof(s32)))
+               return -EFAULT;
+       sprintf(name, "process_%d", current->pid);
+       pm_qos_update_requirement(pm_qos_class, name, value);
+
+       return  sizeof(s32);
+}
+
+
+static int __init pm_qos_power_init(void)
+{
+       int ret = 0;
+
+       ret = register_pm_qos_misc(&cpu_dma_pm_qos);
+       if (ret < 0) {
+               printk(KERN_ERR "pm_qos_param: cpu_dma_latency setup failed\n");
+               return ret;
+       }
+       ret = register_pm_qos_misc(&network_lat_pm_qos);
+       if (ret < 0) {
+               printk(KERN_ERR "pm_qos_param: network_latency setup failed\n");
+               return ret;
+       }
+       ret = register_pm_qos_misc(&network_throughput_pm_qos);
+       if (ret < 0)
+               printk(KERN_ERR
+                       "pm_qos_param: network_throughput setup failed\n");
+
+       return ret;
+}
+
+late_initcall(pm_qos_power_init);
index 35b4bbfc78ff6ee7d3f389baf0430231ed09af7b..122d5c787fe2fc7300deeb153fec9a1d3835cd34 100644 (file)
@@ -256,8 +256,9 @@ static void schedule_next_timer(struct k_itimer *timr)
        if (timr->it.real.interval.tv64 == 0)
                return;
 
-       timr->it_overrun += hrtimer_forward(timer, timer->base->get_time(),
-                                           timr->it.real.interval);
+       timr->it_overrun += (unsigned int) hrtimer_forward(timer,
+                                               timer->base->get_time(),
+                                               timr->it.real.interval);
 
        timr->it_overrun_last = timr->it_overrun;
        timr->it_overrun = -1;
@@ -386,7 +387,7 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
                                        now = ktime_add(now, kj);
                        }
 #endif
-                       timr->it_overrun +=
+                       timr->it_overrun += (unsigned int)
                                hrtimer_forward(timer, now,
                                                timr->it.real.interval);
                        ret = HRTIMER_RESTART;
@@ -493,7 +494,7 @@ sys_timer_create(const clockid_t which_clock,
                goto retry;
        else if (error) {
                /*
-                * Wierd looking, but we return EAGAIN if the IDR is
+                * Weird looking, but we return EAGAIN if the IDR is
                 * full (proper POSIX return value for this)
                 */
                error = -EAGAIN;
@@ -662,7 +663,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
         */
        if (iv.tv64 && (timr->it_requeue_pending & REQUEUE_PENDING ||
            (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE))
-               timr->it_overrun += hrtimer_forward(timer, now, iv);
+               timr->it_overrun += (unsigned int) hrtimer_forward(timer, now, iv);
 
        remaining = ktime_sub(timer->expires, now);
        /* Return 0 only, when the timer is expired and not pending */
index 8e186c678149e23581969a7acfca814a00295b95..ef9b802738a522851d7e95672164f83a997d8df6 100644 (file)
@@ -44,9 +44,30 @@ config PM_VERBOSE
        ---help---
        This option enables verbose messages from the Power Management code.
 
+config CAN_PM_TRACE
+       def_bool y
+       depends on PM_DEBUG && PM_SLEEP && EXPERIMENTAL
+
 config PM_TRACE
+       bool
+       help
+         This enables code to save the last PM event point across
+         reboot. The architecture needs to support this, x86 for
+         example does by saving things in the RTC, see below.
+
+         The architecture specific code must provide the extern
+         functions from <linux/resume-trace.h> as well as the
+         <asm/resume-trace.h> header with a TRACE_RESUME() macro.
+
+         The way the information is presented is architecture-
+         dependent, x86 will print the information during a
+         late_initcall.
+
+config PM_TRACE_RTC
        bool "Suspend/resume event tracing"
-       depends on PM_DEBUG && X86 && PM_SLEEP && EXPERIMENTAL
+       depends on CAN_PM_TRACE
+       depends on X86
+       select PM_TRACE
        default n
        ---help---
        This enables some cheesy code to save the last PM event point in the
@@ -63,7 +84,8 @@ config PM_TRACE
 
 config PM_SLEEP_SMP
        bool
-       depends on SUSPEND_SMP_POSSIBLE || HIBERNATION_SMP_POSSIBLE
+       depends on SMP
+       depends on ARCH_SUSPEND_POSSIBLE || ARCH_HIBERNATION_POSSIBLE
        depends on PM_SLEEP
        select HOTPLUG_CPU
        default y
@@ -73,46 +95,29 @@ config PM_SLEEP
        depends on SUSPEND || HIBERNATION
        default y
 
-config SUSPEND_UP_POSSIBLE
-       bool
-       depends on (X86 && !X86_VOYAGER) || PPC || ARM || BLACKFIN || MIPS \
-                  || SUPERH || FRV
-       depends on !SMP
-       default y
-
-config SUSPEND_SMP_POSSIBLE
-       bool
-       depends on (X86 && !X86_VOYAGER) \
-                  || (PPC && (PPC_PSERIES || PPC_PMAC)) || ARM
-       depends on SMP
-       default y
-
 config SUSPEND
        bool "Suspend to RAM and standby"
-       depends on PM
-       depends on SUSPEND_UP_POSSIBLE || SUSPEND_SMP_POSSIBLE
+       depends on PM && ARCH_SUSPEND_POSSIBLE
        default y
        ---help---
          Allow the system to enter sleep states in which main memory is
          powered and thus its contents are preserved, such as the
-         suspend-to-RAM state (i.e. the ACPI S3 state).
+         suspend-to-RAM state (e.g. the ACPI S3 state).
 
-config HIBERNATION_UP_POSSIBLE
-       bool
-       depends on X86 || PPC64_SWSUSP || PPC32
-       depends on !SMP
+config SUSPEND_FREEZER
+       bool "Enable freezer for suspend to RAM/standby" \
+               if ARCH_WANTS_FREEZER_CONTROL || BROKEN
+       depends on SUSPEND
        default y
+       help
+         This allows you to turn off the freezer for suspend. If this is
+         done, no tasks are frozen for suspend to RAM/standby.
 
-config HIBERNATION_SMP_POSSIBLE
-       bool
-       depends on (X86 && !X86_VOYAGER) || PPC64_SWSUSP
-       depends on SMP
-       default y
+         Turning OFF this setting is NOT recommended! If in doubt, say Y.
 
 config HIBERNATION
        bool "Hibernation (aka 'suspend to disk')"
-       depends on PM && SWAP
-       depends on HIBERNATION_UP_POSSIBLE || HIBERNATION_SMP_POSSIBLE
+       depends on PM && SWAP && ARCH_HIBERNATION_POSSIBLE
        ---help---
          Enable the suspend to disk (STD) functionality, which is usually
          called "hibernation" in user interfaces.  STD checkpoints the
index b138b431e27135aa7b2716335288069ea00beeee..859a8e59773a3a1822bf68700aac39600ff9a60f 100644 (file)
@@ -26,7 +26,7 @@
 
 
 static int noresume = 0;
-char resume_file[256] = CONFIG_PM_STD_PARTITION;
+static char resume_file[256] = CONFIG_PM_STD_PARTITION;
 dev_t swsusp_resume_device;
 sector_t swsusp_resume_block;
 
@@ -54,8 +54,8 @@ static struct platform_hibernation_ops *hibernation_ops;
 
 void hibernation_set_ops(struct platform_hibernation_ops *ops)
 {
-       if (ops && !(ops->start && ops->pre_snapshot && ops->finish
-           && ops->prepare && ops->enter && ops->pre_restore
+       if (ops && !(ops->begin && ops->end &&  ops->pre_snapshot
+           && ops->prepare && ops->finish && ops->enter && ops->pre_restore
            && ops->restore_cleanup)) {
                WARN_ON(1);
                return;
@@ -70,15 +70,55 @@ void hibernation_set_ops(struct platform_hibernation_ops *ops)
        mutex_unlock(&pm_mutex);
 }
 
+#ifdef CONFIG_PM_DEBUG
+static void hibernation_debug_sleep(void)
+{
+       printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n");
+       mdelay(5000);
+}
+
+static int hibernation_testmode(int mode)
+{
+       if (hibernation_mode == mode) {
+               hibernation_debug_sleep();
+               return 1;
+       }
+       return 0;
+}
+
+static int hibernation_test(int level)
+{
+       if (pm_test_level == level) {
+               hibernation_debug_sleep();
+               return 1;
+       }
+       return 0;
+}
+#else /* !CONFIG_PM_DEBUG */
+static int hibernation_testmode(int mode) { return 0; }
+static int hibernation_test(int level) { return 0; }
+#endif /* !CONFIG_PM_DEBUG */
+
 /**
- *     platform_start - tell the platform driver that we're starting
+ *     platform_begin - tell the platform driver that we're starting
  *     hibernation
  */
 
-static int platform_start(int platform_mode)
+static int platform_begin(int platform_mode)
 {
        return (platform_mode && hibernation_ops) ?
-               hibernation_ops->start() : 0;
+               hibernation_ops->begin() : 0;
+}
+
+/**
+ *     platform_end - tell the platform driver that we've entered the
+ *     working state
+ */
+
+static void platform_end(int platform_mode)
+{
+       if (platform_mode && hibernation_ops)
+               hibernation_ops->end();
 }
 
 /**
@@ -145,7 +185,7 @@ static void platform_restore_cleanup(int platform_mode)
  *     reappears in this routine after a restore.
  */
 
-int create_image(int platform_mode)
+static int create_image(int platform_mode)
 {
        int error;
 
@@ -162,19 +202,25 @@ int create_image(int platform_mode)
         */
        error = device_power_down(PMSG_FREEZE);
        if (error) {
-               printk(KERN_ERR "Some devices failed to power down, "
-                       KERN_ERR "aborting suspend\n");
+               printk(KERN_ERR "PM: Some devices failed to power down, "
+                       "aborting hibernation\n");
                goto Enable_irqs;
        }
 
+       if (hibernation_test(TEST_CORE))
+               goto Power_up;
+
+       in_suspend = 1;
        save_processor_state();
        error = swsusp_arch_suspend();
        if (error)
-               printk(KERN_ERR "Error %d while creating the image\n", error);
+               printk(KERN_ERR "PM: Error %d creating hibernation image\n",
+                       error);
        /* Restore control flow magically appears here */
        restore_processor_state();
        if (!in_suspend)
                platform_leave(platform_mode);
+ Power_up:
        /* NOTE:  device_power_up() is just a resume() for devices
         * that suspended with irqs off ... no overall powerup.
         */
@@ -202,36 +248,90 @@ int hibernation_snapshot(int platform_mode)
        if (error)
                return error;
 
-       error = platform_start(platform_mode);
+       error = platform_begin(platform_mode);
        if (error)
-               return error;
+               goto Close;
 
        suspend_console();
        error = device_suspend(PMSG_FREEZE);
        if (error)
                goto Resume_console;
 
-       error = platform_pre_snapshot(platform_mode);
-       if (error)
+       if (hibernation_test(TEST_DEVICES))
                goto Resume_devices;
 
+       error = platform_pre_snapshot(platform_mode);
+       if (error || hibernation_test(TEST_PLATFORM))
+               goto Finish;
+
        error = disable_nonboot_cpus();
        if (!error) {
-               if (hibernation_mode != HIBERNATION_TEST) {
-                       in_suspend = 1;
-                       error = create_image(platform_mode);
-                       /* Control returns here after successful restore */
-               } else {
-                       printk("swsusp debug: Waiting for 5 seconds.\n");
-                       mdelay(5000);
-               }
+               if (hibernation_test(TEST_CPUS))
+                       goto Enable_cpus;
+
+               if (hibernation_testmode(HIBERNATION_TEST))
+                       goto Enable_cpus;
+
+               error = create_image(platform_mode);
+               /* Control returns here after successful restore */
        }
+ Enable_cpus:
        enable_nonboot_cpus();
Resume_devices:
Finish:
        platform_finish(platform_mode);
+ Resume_devices:
        device_resume();
  Resume_console:
        resume_console();
+ Close:
+       platform_end(platform_mode);
+       return error;
+}
+
+/**
+ *     resume_target_kernel - prepare devices that need to be suspended with
+ *     interrupts off, restore the contents of highmem that have not been
+ *     restored yet from the image and run the low level code that will restore
+ *     the remaining contents of memory and switch to the just restored target
+ *     kernel.
+ */
+
+static int resume_target_kernel(void)
+{
+       int error;
+
+       local_irq_disable();
+       error = device_power_down(PMSG_PRETHAW);
+       if (error) {
+               printk(KERN_ERR "PM: Some devices failed to power down, "
+                       "aborting resume\n");
+               goto Enable_irqs;
+       }
+       /* We'll ignore saved state, but this gets preempt count (etc) right */
+       save_processor_state();
+       error = restore_highmem();
+       if (!error) {
+               error = swsusp_arch_resume();
+               /*
+                * The code below is only ever reached in case of a failure.
+                * Otherwise execution continues at place where
+                * swsusp_arch_suspend() was called
+                */
+               BUG_ON(!error);
+               /* This call to restore_highmem() undos the previous one */
+               restore_highmem();
+       }
+       /*
+        * The only reason why swsusp_arch_resume() can fail is memory being
+        * very tight, so we have to free it as soon as we can to avoid
+        * subsequent failures
+        */
+       swsusp_free();
+       restore_processor_state();
+       touch_softlockup_watchdog();
+       device_power_up();
+ Enable_irqs:
+       local_irq_enable();
        return error;
 }
 
@@ -258,7 +358,7 @@ int hibernation_restore(int platform_mode)
        if (!error) {
                error = disable_nonboot_cpus();
                if (!error)
-                       error = swsusp_resume();
+                       error = resume_target_kernel();
                enable_nonboot_cpus();
        }
        platform_restore_cleanup(platform_mode);
@@ -286,9 +386,9 @@ int hibernation_platform_enter(void)
         * hibernation_ops->finish() before saving the image, so we should let
         * the firmware know that we're going to enter the sleep state after all
         */
-       error = hibernation_ops->start();
+       error = hibernation_ops->begin();
        if (error)
-               return error;
+               goto Close;
 
        suspend_console();
        error = device_suspend(PMSG_SUSPEND);
@@ -322,6 +422,8 @@ int hibernation_platform_enter(void)
        device_resume();
  Resume_console:
        resume_console();
+ Close:
+       hibernation_ops->end();
        return error;
 }
 
@@ -352,24 +454,17 @@ static void power_down(void)
         * Valid image is on the disk, if we continue we risk serious data
         * corruption after resume.
         */
-       printk(KERN_CRIT "Please power me down manually\n");
+       printk(KERN_CRIT "PM: Please power down manually\n");
        while(1);
 }
 
-static void unprepare_processes(void)
-{
-       thaw_processes();
-       pm_restore_console();
-}
-
 static int prepare_processes(void)
 {
        int error = 0;
 
-       pm_prepare_console();
        if (freeze_processes()) {
                error = -EBUSY;
-               unprepare_processes();
+               thaw_processes();
        }
        return error;
 }
@@ -389,6 +484,7 @@ int hibernate(void)
                goto Unlock;
        }
 
+       pm_prepare_console();
        error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
        if (error)
                goto Exit;
@@ -398,7 +494,7 @@ int hibernate(void)
        if (error)
                goto Exit;
 
-       printk("Syncing filesystems ... ");
+       printk(KERN_INFO "PM: Syncing filesystems ... ");
        sys_sync();
        printk("done.\n");
 
@@ -406,11 +502,12 @@ int hibernate(void)
        if (error)
                goto Finish;
 
-       if (hibernation_mode == HIBERNATION_TESTPROC) {
-               printk("swsusp debug: Waiting for 5 seconds.\n");
-               mdelay(5000);
+       if (hibernation_test(TEST_FREEZER))
                goto Thaw;
-       }
+
+       if (hibernation_testmode(HIBERNATION_TESTPROC))
+               goto Thaw;
+
        error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
        if (in_suspend && !error) {
                unsigned int flags = 0;
@@ -427,11 +524,12 @@ int hibernate(void)
                swsusp_free();
        }
  Thaw:
-       unprepare_processes();
+       thaw_processes();
  Finish:
        free_basic_memory_bitmaps();
  Exit:
        pm_notifier_call_chain(PM_POST_HIBERNATION);
+       pm_restore_console();
        atomic_inc(&snapshot_device_available);
  Unlock:
        mutex_unlock(&pm_mutex);
@@ -473,22 +571,23 @@ static int software_resume(void)
                        return -ENOENT;
                }
                swsusp_resume_device = name_to_dev_t(resume_file);
-               pr_debug("swsusp: Resume From Partition %s\n", resume_file);
+               pr_debug("PM: Resume from partition %s\n", resume_file);
        } else {
-               pr_debug("swsusp: Resume From Partition %d:%d\n",
-                        MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
+               pr_debug("PM: Resume from partition %d:%d\n",
+                               MAJOR(swsusp_resume_device),
+                               MINOR(swsusp_resume_device));
        }
 
        if (noresume) {
                /**
-                * FIXME: If noresume is specified, we need to find the partition
-                * and reset it back to normal swap space.
+                * FIXME: If noresume is specified, we need to find the
+                * partition and reset it back to normal swap space.
                 */
                mutex_unlock(&pm_mutex);
                return 0;
        }
 
-       pr_debug("PM: Checking swsusp image.\n");
+       pr_debug("PM: Checking hibernation image.\n");
        error = swsusp_check();
        if (error)
                goto Unlock;
@@ -499,6 +598,11 @@ static int software_resume(void)
                goto Unlock;
        }
 
+       pm_prepare_console();
+       error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
+       if (error)
+               goto Finish;
+
        error = create_basic_memory_bitmaps();
        if (error)
                goto Finish;
@@ -510,7 +614,7 @@ static int software_resume(void)
                goto Done;
        }
 
-       pr_debug("PM: Reading swsusp image.\n");
+       pr_debug("PM: Reading hibernation image.\n");
 
        error = swsusp_read(&flags);
        if (!error)
@@ -518,10 +622,12 @@ static int software_resume(void)
 
        printk(KERN_ERR "PM: Restore failed, recovering.\n");
        swsusp_free();
-       unprepare_processes();
+       thaw_processes();
  Done:
        free_basic_memory_bitmaps();
  Finish:
+       pm_notifier_call_chain(PM_POST_RESTORE);
+       pm_restore_console();
        atomic_inc(&snapshot_device_available);
        /* For success case, the suspend path will release the lock */
  Unlock:
@@ -636,7 +742,7 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
                error = -EINVAL;
 
        if (!error)
-               pr_debug("PM: suspend-to-disk mode set to '%s'\n",
+               pr_debug("PM: Hibernation mode set to '%s'\n",
                         hibernation_modes[mode]);
        mutex_unlock(&pm_mutex);
        return error ? error : n;
@@ -668,7 +774,7 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
        mutex_lock(&pm_mutex);
        swsusp_resume_device = res;
        mutex_unlock(&pm_mutex);
-       printk("Attempting manual resume\n");
+       printk(KERN_INFO "PM: Starting manual resume from disk\n");
        noresume = 0;
        software_resume();
        ret = n;
index efc08360e627199374837ed95ea31ebcd0f94a80..6a6d5eb3524e7d2f219aeaa894e70981b3a706fb 100644 (file)
 
 #include "power.h"
 
-BLOCKING_NOTIFIER_HEAD(pm_chain_head);
-
 DEFINE_MUTEX(pm_mutex);
 
 unsigned int pm_flags;
 EXPORT_SYMBOL(pm_flags);
 
+#ifdef CONFIG_PM_SLEEP
+
+/* Routines for PM-transition notifications */
+
+static BLOCKING_NOTIFIER_HEAD(pm_chain_head);
+
+int register_pm_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_register(&pm_chain_head, nb);
+}
+EXPORT_SYMBOL_GPL(register_pm_notifier);
+
+int unregister_pm_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_unregister(&pm_chain_head, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_pm_notifier);
+
+int pm_notifier_call_chain(unsigned long val)
+{
+       return (blocking_notifier_call_chain(&pm_chain_head, val, NULL)
+                       == NOTIFY_BAD) ? -EINVAL : 0;
+}
+
+#ifdef CONFIG_PM_DEBUG
+int pm_test_level = TEST_NONE;
+
+static int suspend_test(int level)
+{
+       if (pm_test_level == level) {
+               printk(KERN_INFO "suspend debug: Waiting for 5 seconds.\n");
+               mdelay(5000);
+               return 1;
+       }
+       return 0;
+}
+
+static const char * const pm_tests[__TEST_AFTER_LAST] = {
+       [TEST_NONE] = "none",
+       [TEST_CORE] = "core",
+       [TEST_CPUS] = "processors",
+       [TEST_PLATFORM] = "platform",
+       [TEST_DEVICES] = "devices",
+       [TEST_FREEZER] = "freezer",
+};
+
+static ssize_t pm_test_show(struct kobject *kobj, struct kobj_attribute *attr,
+                               char *buf)
+{
+       char *s = buf;
+       int level;
+
+       for (level = TEST_FIRST; level <= TEST_MAX; level++)
+               if (pm_tests[level]) {
+                       if (level == pm_test_level)
+                               s += sprintf(s, "[%s] ", pm_tests[level]);
+                       else
+                               s += sprintf(s, "%s ", pm_tests[level]);
+               }
+
+       if (s != buf)
+               /* convert the last space to a newline */
+               *(s-1) = '\n';
+
+       return (s - buf);
+}
+
+static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
+                               const char *buf, size_t n)
+{
+       const char * const *s;
+       int level;
+       char *p;
+       int len;
+       int error = -EINVAL;
+
+       p = memchr(buf, '\n', n);
+       len = p ? p - buf : n;
+
+       mutex_lock(&pm_mutex);
+
+       level = TEST_FIRST;
+       for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++)
+               if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
+                       pm_test_level = level;
+                       error = 0;
+                       break;
+               }
+
+       mutex_unlock(&pm_mutex);
+
+       return error ? error : n;
+}
+
+power_attr(pm_test);
+#else /* !CONFIG_PM_DEBUG */
+static inline int suspend_test(int level) { return 0; }
+#endif /* !CONFIG_PM_DEBUG */
+
+#endif /* CONFIG_PM_SLEEP */
+
 #ifdef CONFIG_SUSPEND
 
 /* This is just an arbitrary number */
@@ -76,13 +175,13 @@ static int suspend_prepare(void)
        if (!suspend_ops || !suspend_ops->enter)
                return -EPERM;
 
+       pm_prepare_console();
+
        error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
        if (error)
                goto Finish;
 
-       pm_prepare_console();
-
-       if (freeze_processes()) {
+       if (suspend_freeze_processes()) {
                error = -EAGAIN;
                goto Thaw;
        }
@@ -100,10 +199,10 @@ static int suspend_prepare(void)
                return 0;
 
  Thaw:
-       thaw_processes();
-       pm_restore_console();
+       suspend_thaw_processes();
  Finish:
        pm_notifier_call_chain(PM_POST_SUSPEND);
+       pm_restore_console();
        return error;
 }
 
@@ -133,10 +232,13 @@ static int suspend_enter(suspend_state_t state)
        BUG_ON(!irqs_disabled());
 
        if ((error = device_power_down(PMSG_SUSPEND))) {
-               printk(KERN_ERR "Some devices failed to power down\n");
+               printk(KERN_ERR "PM: Some devices failed to power down\n");
                goto Done;
        }
-       error = suspend_ops->enter(state);
+
+       if (!suspend_test(TEST_CORE))
+               error = suspend_ops->enter(state);
+
        device_power_up();
  Done:
        arch_suspend_enable_irqs();
@@ -145,8 +247,8 @@ static int suspend_enter(suspend_state_t state)
 }
 
 /**
- *     suspend_devices_and_enter - suspend devices and enter the desired system sleep
- *                       state.
+ *     suspend_devices_and_enter - suspend devices and enter the desired system
+ *                                 sleep state.
  *     @state:           state to enter
  */
 int suspend_devices_and_enter(suspend_state_t state)
@@ -156,33 +258,45 @@ int suspend_devices_and_enter(suspend_state_t state)
        if (!suspend_ops)
                return -ENOSYS;
 
-       if (suspend_ops->set_target) {
-               error = suspend_ops->set_target(state);
+       if (suspend_ops->begin) {
+               error = suspend_ops->begin(state);
                if (error)
-                       return error;
+                       goto Close;
        }
        suspend_console();
        error = device_suspend(PMSG_SUSPEND);
        if (error) {
-               printk(KERN_ERR "Some devices failed to suspend\n");
+               printk(KERN_ERR "PM: Some devices failed to suspend\n");
                goto Resume_console;
        }
+
+       if (suspend_test(TEST_DEVICES))
+               goto Resume_devices;
+
        if (suspend_ops->prepare) {
                error = suspend_ops->prepare();
                if (error)
                        goto Resume_devices;
        }
+
+       if (suspend_test(TEST_PLATFORM))
+               goto Finish;
+
        error = disable_nonboot_cpus();
-       if (!error)
+       if (!error && !suspend_test(TEST_CPUS))
                suspend_enter(state);
 
        enable_nonboot_cpus();
+ Finish:
        if (suspend_ops->finish)
                suspend_ops->finish();
  Resume_devices:
        device_resume();
  Resume_console:
        resume_console();
+ Close:
+       if (suspend_ops->end)
+               suspend_ops->end();
        return error;
 }
 
@@ -194,9 +308,9 @@ int suspend_devices_and_enter(suspend_state_t state)
  */
 static void suspend_finish(void)
 {
-       thaw_processes();
-       pm_restore_console();
+       suspend_thaw_processes();
        pm_notifier_call_chain(PM_POST_SUSPEND);
+       pm_restore_console();
 }
 
 
@@ -238,17 +352,22 @@ static int enter_state(suspend_state_t state)
        if (!mutex_trylock(&pm_mutex))
                return -EBUSY;
 
-       printk("Syncing filesystems ... ");
+       printk(KERN_INFO "PM: Syncing filesystems ... ");
        sys_sync();
        printk("done.\n");
 
        pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
-       if ((error = suspend_prepare()))
+       error = suspend_prepare();
+       if (error)
                goto Unlock;
 
+       if (suspend_test(TEST_FREEZER))
+               goto Finish;
+
        pr_debug("PM: Entering %s sleep\n", pm_states[state]);
        error = suspend_devices_and_enter(state);
 
+ Finish:
        pr_debug("PM: Finishing wakeup.\n");
        suspend_finish();
  Unlock:
@@ -369,18 +488,18 @@ pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
 }
 
 power_attr(pm_trace);
+#endif /* CONFIG_PM_TRACE */
 
 static struct attribute * g[] = {
        &state_attr.attr,
+#ifdef CONFIG_PM_TRACE
        &pm_trace_attr.attr,
+#endif
+#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PM_DEBUG)
+       &pm_test_attr.attr,
+#endif
        NULL,
 };
-#else
-static struct attribute * g[] = {
-       &state_attr.attr,
-       NULL,
-};
-#endif /* CONFIG_PM_TRACE */
 
 static struct attribute_group attr_group = {
        .attrs = g,
index 2093c3a9a994d8a7a3bd82487200b925ee16ac61..700f44ec84067860cb86a79ff8201934c3c59e66 100644 (file)
@@ -1,5 +1,7 @@
 #include <linux/suspend.h>
+#include <linux/suspend_ioctls.h>
 #include <linux/utsname.h>
+#include <linux/freezer.h>
 
 struct swsusp_info {
        struct new_utsname      uts;
@@ -128,42 +130,12 @@ struct snapshot_handle {
 #define data_of(handle)        ((handle).buffer + (handle).buf_offset)
 
 extern unsigned int snapshot_additional_pages(struct zone *zone);
+extern unsigned long snapshot_get_image_size(void);
 extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
 extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
 extern void snapshot_write_finalize(struct snapshot_handle *handle);
 extern int snapshot_image_loaded(struct snapshot_handle *handle);
 
-/*
- * This structure is used to pass the values needed for the identification
- * of the resume swap area from a user space to the kernel via the
- * SNAPSHOT_SET_SWAP_AREA ioctl
- */
-struct resume_swap_area {
-       loff_t offset;
-       u_int32_t dev;
-} __attribute__((packed));
-
-#define SNAPSHOT_IOC_MAGIC     '3'
-#define SNAPSHOT_FREEZE                        _IO(SNAPSHOT_IOC_MAGIC, 1)
-#define SNAPSHOT_UNFREEZE              _IO(SNAPSHOT_IOC_MAGIC, 2)
-#define SNAPSHOT_ATOMIC_SNAPSHOT       _IOW(SNAPSHOT_IOC_MAGIC, 3, void *)
-#define SNAPSHOT_ATOMIC_RESTORE                _IO(SNAPSHOT_IOC_MAGIC, 4)
-#define SNAPSHOT_FREE                  _IO(SNAPSHOT_IOC_MAGIC, 5)
-#define SNAPSHOT_SET_IMAGE_SIZE                _IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long)
-#define SNAPSHOT_AVAIL_SWAP            _IOR(SNAPSHOT_IOC_MAGIC, 7, void *)
-#define SNAPSHOT_GET_SWAP_PAGE         _IOR(SNAPSHOT_IOC_MAGIC, 8, void *)
-#define SNAPSHOT_FREE_SWAP_PAGES       _IO(SNAPSHOT_IOC_MAGIC, 9)
-#define SNAPSHOT_SET_SWAP_FILE         _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
-#define SNAPSHOT_S2RAM                 _IO(SNAPSHOT_IOC_MAGIC, 11)
-#define SNAPSHOT_PMOPS                 _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
-#define SNAPSHOT_SET_SWAP_AREA         _IOW(SNAPSHOT_IOC_MAGIC, 13, \
-                                                       struct resume_swap_area)
-#define SNAPSHOT_IOC_MAXNR     13
-
-#define PMOPS_PREPARE  1
-#define PMOPS_ENTER    2
-#define PMOPS_FINISH   3
-
 /* If unset, the snapshot device cannot be open. */
 extern atomic_t snapshot_device_available;
 
@@ -181,7 +153,6 @@ extern int swsusp_swap_in_use(void);
 extern int swsusp_check(void);
 extern int swsusp_shrink_memory(void);
 extern void swsusp_free(void);
-extern int swsusp_resume(void);
 extern int swsusp_read(unsigned int *flags_p);
 extern int swsusp_write(unsigned int flags);
 extern void swsusp_close(void);
@@ -201,11 +172,56 @@ static inline int suspend_devices_and_enter(suspend_state_t state)
 }
 #endif /* !CONFIG_SUSPEND */
 
-/* kernel/power/common.c */
-extern struct blocking_notifier_head pm_chain_head;
+#ifdef CONFIG_PM_SLEEP
+/* kernel/power/main.c */
+extern int pm_notifier_call_chain(unsigned long val);
+#endif
+
+#ifdef CONFIG_HIGHMEM
+unsigned int count_highmem_pages(void);
+int restore_highmem(void);
+#else
+static inline unsigned int count_highmem_pages(void) { return 0; }
+static inline int restore_highmem(void) { return 0; }
+#endif
+
+/*
+ * Suspend test levels
+ */
+enum {
+       /* keep first */
+       TEST_NONE,
+       TEST_CORE,
+       TEST_CPUS,
+       TEST_PLATFORM,
+       TEST_DEVICES,
+       TEST_FREEZER,
+       /* keep last */
+       __TEST_AFTER_LAST
+};
+
+#define TEST_FIRST     TEST_NONE
+#define TEST_MAX       (__TEST_AFTER_LAST - 1)
+
+extern int pm_test_level;
+
+#ifdef CONFIG_SUSPEND_FREEZER
+static inline int suspend_freeze_processes(void)
+{
+       return freeze_processes();
+}
 
-static inline int pm_notifier_call_chain(unsigned long val)
+static inline void suspend_thaw_processes(void)
 {
-       return (blocking_notifier_call_chain(&pm_chain_head, val, NULL)
-                       == NOTIFY_BAD) ? -EINVAL : 0;
+       thaw_processes();
 }
+#else
+static inline int suspend_freeze_processes(void)
+{
+       return 0;
+}
+
+static inline void suspend_thaw_processes(void)
+{
+}
+#endif
index 78039b477d2bd7bbae3ab893763111475ea932a6..95250d7c8d91db36593fc3707b10c99a8370dc62 100644 (file)
@@ -635,7 +635,7 @@ __register_nosave_region(unsigned long start_pfn, unsigned long end_pfn,
        region->end_pfn = end_pfn;
        list_add_tail(&region->list, &nosave_regions);
  Report:
-       printk("swsusp: Registered nosave memory region: %016lx - %016lx\n",
+       printk(KERN_INFO "PM: Registered nosave memory: %016lx - %016lx\n",
                start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT);
 }
 
@@ -704,7 +704,7 @@ static void mark_nosave_pages(struct memory_bitmap *bm)
        list_for_each_entry(region, &nosave_regions, list) {
                unsigned long pfn;
 
-               printk("swsusp: Marking nosave pages: %016lx - %016lx\n",
+               pr_debug("PM: Marking nosave pages: %016lx - %016lx\n",
                                region->start_pfn << PAGE_SHIFT,
                                region->end_pfn << PAGE_SHIFT);
 
@@ -749,7 +749,7 @@ int create_basic_memory_bitmaps(void)
        free_pages_map = bm2;
        mark_nosave_pages(forbidden_pages_map);
 
-       printk("swsusp: Basic memory bitmaps created\n");
+       pr_debug("PM: Basic memory bitmaps created\n");
 
        return 0;
 
@@ -784,7 +784,7 @@ void free_basic_memory_bitmaps(void)
        memory_bm_free(bm2, PG_UNSAFE_CLEAR);
        kfree(bm2);
 
-       printk("swsusp: Basic memory bitmaps freed\n");
+       pr_debug("PM: Basic memory bitmaps freed\n");
 }
 
 /**
@@ -872,7 +872,6 @@ unsigned int count_highmem_pages(void)
 }
 #else
 static inline void *saveable_highmem_page(unsigned long pfn) { return NULL; }
-static inline unsigned int count_highmem_pages(void) { return 0; }
 #endif /* CONFIG_HIGHMEM */
 
 /**
@@ -1089,7 +1088,7 @@ static int enough_free_mem(unsigned int nr_pages, unsigned int nr_highmem)
        }
 
        nr_pages += count_pages_for_highmem(nr_highmem);
-       pr_debug("swsusp: Normal pages needed: %u + %u + %u, available pages: %u\n",
+       pr_debug("PM: Normal pages needed: %u + %u + %u, available pages: %u\n",
                nr_pages, PAGES_FOR_IO, meta, free);
 
        return free > nr_pages + PAGES_FOR_IO + meta;
@@ -1202,27 +1201,27 @@ asmlinkage int swsusp_save(void)
 {
        unsigned int nr_pages, nr_highmem;
 
-       printk("swsusp: critical section: \n");
+       printk(KERN_INFO "PM: Creating hibernation image: \n");
 
-       drain_local_pages();
+       drain_local_pages(NULL);
        nr_pages = count_data_pages();
        nr_highmem = count_highmem_pages();
-       printk("swsusp: Need to copy %u pages\n", nr_pages + nr_highmem);
+       printk(KERN_INFO "PM: Need to copy %u pages\n", nr_pages + nr_highmem);
 
        if (!enough_free_mem(nr_pages, nr_highmem)) {
-               printk(KERN_ERR "swsusp: Not enough free memory\n");
+               printk(KERN_ERR "PM: Not enough free memory\n");
                return -ENOMEM;
        }
 
        if (swsusp_alloc(&orig_bm, &copy_bm, nr_pages, nr_highmem)) {
-               printk(KERN_ERR "swsusp: Memory allocation failed\n");
+               printk(KERN_ERR "PM: Memory allocation failed\n");
                return -ENOMEM;
        }
 
        /* During allocating of suspend pagedir, new cold pages may appear.
         * Kill them.
         */
-       drain_local_pages();
+       drain_local_pages(NULL);
        copy_data_pages(&copy_bm, &orig_bm);
 
        /*
@@ -1235,7 +1234,8 @@ asmlinkage int swsusp_save(void)
        nr_copy_pages = nr_pages;
        nr_meta_pages = DIV_ROUND_UP(nr_pages * sizeof(long), PAGE_SIZE);
 
-       printk("swsusp: critical section: done (%d pages copied)\n", nr_pages);
+       printk(KERN_INFO "PM: Hibernation image created (%d pages copied)\n",
+               nr_pages);
 
        return 0;
 }
@@ -1264,12 +1264,17 @@ static char *check_image_kernel(struct swsusp_info *info)
 }
 #endif /* CONFIG_ARCH_HIBERNATION_HEADER */
 
+unsigned long snapshot_get_image_size(void)
+{
+       return nr_copy_pages + nr_meta_pages + 1;
+}
+
 static int init_header(struct swsusp_info *info)
 {
        memset(info, 0, sizeof(struct swsusp_info));
        info->num_physpages = num_physpages;
        info->image_pages = nr_copy_pages;
-       info->pages = nr_copy_pages + nr_meta_pages + 1;
+       info->pages = snapshot_get_image_size();
        info->size = info->pages;
        info->size <<= PAGE_SHIFT;
        return init_header_complete(info);
@@ -1429,7 +1434,7 @@ static int check_header(struct swsusp_info *info)
        if (!reason && info->num_physpages != num_physpages)
                reason = "memory size";
        if (reason) {
-               printk(KERN_ERR "swsusp: Resume mismatch: %s\n", reason);
+               printk(KERN_ERR "PM: Image mismatch: %s\n", reason);
                return -EPERM;
        }
        return 0;
index 917aba100575a45125ee3d98a1cee93553d22d58..a0abf9a463f95bc9948f3ccd10fecddf75401eb8 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "power.h"
 
-extern char resume_file[];
-
 #define SWSUSP_SIG     "S1SUSPEND"
 
 struct swsusp_header {
@@ -73,7 +71,8 @@ static int submit(int rw, pgoff_t page_off, struct page *page,
        bio->bi_end_io = end_swap_bio_read;
 
        if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
-               printk("swsusp: ERROR: adding page to bio at %ld\n", page_off);
+               printk(KERN_ERR "PM: Adding page to bio failed at %ld\n",
+                       page_off);
                bio_put(bio);
                return -EFAULT;
        }
@@ -153,7 +152,7 @@ static int mark_swapfiles(sector_t start, unsigned int flags)
                error = bio_write_page(swsusp_resume_block,
                                        swsusp_header, NULL);
        } else {
-               printk(KERN_ERR "swsusp: Swap header not found!\n");
+               printk(KERN_ERR "PM: Swap header not found!\n");
                error = -ENODEV;
        }
        return error;
@@ -325,7 +324,8 @@ static int save_image(struct swap_map_handle *handle,
        struct timeval start;
        struct timeval stop;
 
-       printk("Saving image data pages (%u pages) ...     ", nr_to_write);
+       printk(KERN_INFO "PM: Saving image data pages (%u pages) ...     ",
+               nr_to_write);
        m = nr_to_write / 100;
        if (!m)
                m = 1;
@@ -365,7 +365,7 @@ static int enough_swap(unsigned int nr_pages)
 {
        unsigned int free_swap = count_swap_pages(root_swap, 1);
 
-       pr_debug("swsusp: free swap pages: %u\n", free_swap);
+       pr_debug("PM: Free swap pages: %u\n", free_swap);
        return free_swap > nr_pages + PAGES_FOR_IO;
 }
 
@@ -388,7 +388,7 @@ int swsusp_write(unsigned int flags)
 
        error = swsusp_swap_check();
        if (error) {
-               printk(KERN_ERR "swsusp: Cannot find swap device, try "
+               printk(KERN_ERR "PM: Cannot find swap device, try "
                                "swapon -a.\n");
                return error;
        }
@@ -402,7 +402,7 @@ int swsusp_write(unsigned int flags)
        }
        header = (struct swsusp_info *)data_of(snapshot);
        if (!enough_swap(header->pages)) {
-               printk(KERN_ERR "swsusp: Not enough free swap\n");
+               printk(KERN_ERR "PM: Not enough free swap\n");
                error = -ENOSPC;
                goto out;
        }
@@ -417,7 +417,7 @@ int swsusp_write(unsigned int flags)
 
                if (!error) {
                        flush_swap_writer(&handle);
-                       printk("S");
+                       printk(KERN_INFO "PM: S");
                        error = mark_swapfiles(start, flags);
                        printk("|\n");
                }
@@ -507,7 +507,8 @@ static int load_image(struct swap_map_handle *handle,
        int err2;
        unsigned nr_pages;
 
-       printk("Loading image data pages (%u pages) ...     ", nr_to_read);
+       printk(KERN_INFO "PM: Loading image data pages (%u pages) ...     ",
+               nr_to_read);
        m = nr_to_read / 100;
        if (!m)
                m = 1;
@@ -558,7 +559,7 @@ int swsusp_read(unsigned int *flags_p)
 
        *flags_p = swsusp_header->flags;
        if (IS_ERR(resume_bdev)) {
-               pr_debug("swsusp: block device not initialised\n");
+               pr_debug("PM: Image device not initialised\n");
                return PTR_ERR(resume_bdev);
        }
 
@@ -577,9 +578,9 @@ int swsusp_read(unsigned int *flags_p)
        blkdev_put(resume_bdev);
 
        if (!error)
-               pr_debug("swsusp: Reading resume file was successful\n");
+               pr_debug("PM: Image successfully loaded\n");
        else
-               pr_debug("swsusp: Error %d resuming\n", error);
+               pr_debug("PM: Error %d resuming\n", error);
        return error;
 }
 
@@ -611,13 +612,13 @@ int swsusp_check(void)
                if (error)
                        blkdev_put(resume_bdev);
                else
-                       pr_debug("swsusp: Signature found, resuming\n");
+                       pr_debug("PM: Signature found, resuming\n");
        } else {
                error = PTR_ERR(resume_bdev);
        }
 
        if (error)
-               pr_debug("swsusp: Error %d check for resume file\n", error);
+               pr_debug("PM: Error %d checking image file\n", error);
 
        return error;
 }
@@ -629,7 +630,7 @@ int swsusp_check(void)
 void swsusp_close(void)
 {
        if (IS_ERR(resume_bdev)) {
-               pr_debug("swsusp: block device not initialised\n");
+               pr_debug("PM: Image device not initialised\n");
                return;
        }
 
index e1722d3155f17057284ab6374b3a00b9a31ed1d2..023ff2a31d899159e61ffb72e9e4eeea65d93b25 100644 (file)
@@ -64,14 +64,6 @@ unsigned long image_size = 500 * 1024 * 1024;
 
 int in_suspend __nosavedata = 0;
 
-#ifdef CONFIG_HIGHMEM
-unsigned int count_highmem_pages(void);
-int restore_highmem(void);
-#else
-static inline int restore_highmem(void) { return 0; }
-static inline unsigned int count_highmem_pages(void) { return 0; }
-#endif
-
 /**
  *     The following functions are used for tracing the allocated
  *     swap pages, so that they can be freed in case of an error.
@@ -196,7 +188,8 @@ void swsusp_show_speed(struct timeval *start, struct timeval *stop,
                centisecs = 1;  /* avoid div-by-zero */
        k = nr_pages * (PAGE_SIZE / 1024);
        kps = (k * 100) / centisecs;
-       printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k,
+       printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
+                       msg, k,
                        centisecs / 100, centisecs % 100,
                        kps / 1000, (kps % 1000) / 10);
 }
@@ -227,7 +220,7 @@ int swsusp_shrink_memory(void)
        char *p = "-\\|/";
        struct timeval start, stop;
 
-       printk("Shrinking memory...  ");
+       printk(KERN_INFO "PM: Shrinking memory...  ");
        do_gettimeofday(&start);
        do {
                long size, highmem_size;
@@ -269,38 +262,3 @@ int swsusp_shrink_memory(void)
 
        return 0;
 }
-
-int swsusp_resume(void)
-{
-       int error;
-
-       local_irq_disable();
-       /* NOTE:  device_power_down() is just a suspend() with irqs off;
-        * it has no special "power things down" semantics
-        */
-       if (device_power_down(PMSG_PRETHAW))
-               printk(KERN_ERR "Some devices failed to power down, very bad\n");
-       /* We'll ignore saved state, but this gets preempt count (etc) right */
-       save_processor_state();
-       error = restore_highmem();
-       if (!error) {
-               error = swsusp_arch_resume();
-               /* The code below is only ever reached in case of a failure.
-                * Otherwise execution continues at place where
-                * swsusp_arch_suspend() was called
-                */
-               BUG_ON(!error);
-               /* This call to restore_highmem() undos the previous one */
-               restore_highmem();
-       }
-       /* The only reason why swsusp_arch_resume() can fail is memory being
-        * very tight, so we have to free it as soon as we can to avoid
-        * subsequent failures
-        */
-       swsusp_free();
-       restore_processor_state();
-       touch_softlockup_watchdog();
-       device_power_up();
-       local_irq_enable();
-       return error;
-}
index 5bd321bcbb75f06031d6ede749cad599c251373c..f5512cb3aa86f61e98caec04c82a01a0dc9f6dcf 100644 (file)
 
 #include "power.h"
 
+/*
+ * NOTE: The SNAPSHOT_SET_SWAP_FILE and SNAPSHOT_PMOPS ioctls are obsolete and
+ * will be removed in the future.  They are only preserved here for
+ * compatibility with existing userland utilities.
+ */
+#define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
+#define SNAPSHOT_PMOPS         _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
+
+#define PMOPS_PREPARE  1
+#define PMOPS_ENTER    2
+#define PMOPS_FINISH   3
+
+/*
+ * NOTE: The following ioctl definitions are wrong and have been replaced with
+ * correct ones.  They are only preserved here for compatibility with existing
+ * userland utilities and will be removed in the future.
+ */
+#define SNAPSHOT_ATOMIC_SNAPSHOT       _IOW(SNAPSHOT_IOC_MAGIC, 3, void *)
+#define SNAPSHOT_SET_IMAGE_SIZE                _IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long)
+#define SNAPSHOT_AVAIL_SWAP            _IOR(SNAPSHOT_IOC_MAGIC, 7, void *)
+#define SNAPSHOT_GET_SWAP_PAGE         _IOR(SNAPSHOT_IOC_MAGIC, 8, void *)
+
+
 #define SNAPSHOT_MINOR 231
 
 static struct snapshot_data {
@@ -36,7 +59,7 @@ static struct snapshot_data {
        int mode;
        char frozen;
        char ready;
-       char platform_suspend;
+       char platform_support;
 } snapshot_state;
 
 atomic_t snapshot_device_available = ATOMIC_INIT(1);
@@ -44,6 +67,7 @@ atomic_t snapshot_device_available = ATOMIC_INIT(1);
 static int snapshot_open(struct inode *inode, struct file *filp)
 {
        struct snapshot_data *data;
+       int error;
 
        if (!atomic_add_unless(&snapshot_device_available, -1, 0))
                return -EBUSY;
@@ -64,13 +88,23 @@ static int snapshot_open(struct inode *inode, struct file *filp)
                data->swap = swsusp_resume_device ?
                        swap_type_of(swsusp_resume_device, 0, NULL) : -1;
                data->mode = O_RDONLY;
+               error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
+               if (error)
+                       pm_notifier_call_chain(PM_POST_RESTORE);
        } else {
                data->swap = -1;
                data->mode = O_WRONLY;
+               error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
+               if (error)
+                       pm_notifier_call_chain(PM_POST_HIBERNATION);
+       }
+       if (error) {
+               atomic_inc(&snapshot_device_available);
+               return error;
        }
        data->frozen = 0;
        data->ready = 0;
-       data->platform_suspend = 0;
+       data->platform_support = 0;
 
        return 0;
 }
@@ -88,6 +122,8 @@ static int snapshot_release(struct inode *inode, struct file *filp)
                thaw_processes();
                mutex_unlock(&pm_mutex);
        }
+       pm_notifier_call_chain(data->mode == O_WRONLY ?
+                       PM_POST_HIBERNATION : PM_POST_RESTORE);
        atomic_inc(&snapshot_device_available);
        return 0;
 }
@@ -133,7 +169,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
 {
        int error = 0;
        struct snapshot_data *data;
-       loff_t avail;
+       loff_t size;
        sector_t offset;
 
        if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC)
@@ -151,18 +187,13 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                if (data->frozen)
                        break;
                mutex_lock(&pm_mutex);
-               error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
-               if (!error) {
-                       printk("Syncing filesystems ... ");
-                       sys_sync();
-                       printk("done.\n");
-
-                       error = freeze_processes();
-                       if (error)
-                               thaw_processes();
-               }
+               printk("Syncing filesystems ... ");
+               sys_sync();
+               printk("done.\n");
+
+               error = freeze_processes();
                if (error)
-                       pm_notifier_call_chain(PM_POST_HIBERNATION);
+                       thaw_processes();
                mutex_unlock(&pm_mutex);
                if (!error)
                        data->frozen = 1;
@@ -173,19 +204,19 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                        break;
                mutex_lock(&pm_mutex);
                thaw_processes();
-               pm_notifier_call_chain(PM_POST_HIBERNATION);
                mutex_unlock(&pm_mutex);
                data->frozen = 0;
                break;
 
+       case SNAPSHOT_CREATE_IMAGE:
        case SNAPSHOT_ATOMIC_SNAPSHOT:
                if (data->mode != O_RDONLY || !data->frozen  || data->ready) {
                        error = -EPERM;
                        break;
                }
-               error = hibernation_snapshot(data->platform_suspend);
+               error = hibernation_snapshot(data->platform_support);
                if (!error)
-                       error = put_user(in_suspend, (unsigned int __user *)arg);
+                       error = put_user(in_suspend, (int __user *)arg);
                if (!error)
                        data->ready = 1;
                break;
@@ -197,7 +228,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                        error = -EPERM;
                        break;
                }
-               error = hibernation_restore(data->platform_suspend);
+               error = hibernation_restore(data->platform_support);
                break;
 
        case SNAPSHOT_FREE:
@@ -206,16 +237,29 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                data->ready = 0;
                break;
 
+       case SNAPSHOT_PREF_IMAGE_SIZE:
        case SNAPSHOT_SET_IMAGE_SIZE:
                image_size = arg;
                break;
 
+       case SNAPSHOT_GET_IMAGE_SIZE:
+               if (!data->ready) {
+                       error = -ENODATA;
+                       break;
+               }
+               size = snapshot_get_image_size();
+               size <<= PAGE_SHIFT;
+               error = put_user(size, (loff_t __user *)arg);
+               break;
+
+       case SNAPSHOT_AVAIL_SWAP_SIZE:
        case SNAPSHOT_AVAIL_SWAP:
-               avail = count_swap_pages(data->swap, 1);
-               avail <<= PAGE_SHIFT;
-               error = put_user(avail, (loff_t __user *)arg);
+               size = count_swap_pages(data->swap, 1);
+               size <<= PAGE_SHIFT;
+               error = put_user(size, (loff_t __user *)arg);
                break;
 
+       case SNAPSHOT_ALLOC_SWAP_PAGE:
        case SNAPSHOT_GET_SWAP_PAGE:
                if (data->swap < 0 || data->swap >= MAX_SWAPFILES) {
                        error = -ENODEV;
@@ -224,7 +268,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                offset = alloc_swapdev_block(data->swap);
                if (offset) {
                        offset <<= PAGE_SHIFT;
-                       error = put_user(offset, (sector_t __user *)arg);
+                       error = put_user(offset, (loff_t __user *)arg);
                } else {
                        error = -ENOSPC;
                }
@@ -238,7 +282,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                free_all_swap_pages(data->swap);
                break;
 
-       case SNAPSHOT_SET_SWAP_FILE:
+       case SNAPSHOT_SET_SWAP_FILE: /* This ioctl is deprecated */
                if (!swsusp_swap_in_use()) {
                        /*
                         * User space encodes device types as two-byte values,
@@ -275,26 +319,33 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                mutex_unlock(&pm_mutex);
                break;
 
-       case SNAPSHOT_PMOPS:
+       case SNAPSHOT_PLATFORM_SUPPORT:
+               data->platform_support = !!arg;
+               break;
+
+       case SNAPSHOT_POWER_OFF:
+               if (data->platform_support)
+                       error = hibernation_platform_enter();
+               break;
+
+       case SNAPSHOT_PMOPS: /* This ioctl is deprecated */
                error = -EINVAL;
 
                switch (arg) {
 
                case PMOPS_PREPARE:
-                       data->platform_suspend = 1;
+                       data->platform_support = 1;
                        error = 0;
                        break;
 
                case PMOPS_ENTER:
-                       if (data->platform_suspend)
+                       if (data->platform_support)
                                error = hibernation_platform_enter();
-
                        break;
 
                case PMOPS_FINISH:
-                       if (data->platform_suspend)
+                       if (data->platform_support)
                                error = 0;
-
                        break;
 
                default:
index 29ae1e99cde08b247aa106a2939496abf3b3c871..4a090621f3793fe705352565a41a022441e617b6 100644 (file)
@@ -93,16 +93,16 @@ static int console_locked, console_suspended;
  */
 static DEFINE_SPINLOCK(logbuf_lock);
 
-#define LOG_BUF_MASK   (log_buf_len-1)
+#define LOG_BUF_MASK (log_buf_len-1)
 #define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
 
 /*
  * The indices into log_buf are not constrained to log_buf_len - they
  * must be masked before subscripting
  */
-static unsigned long log_start;        /* Index into log_buf: next char to be read by syslog() */
-static unsigned long con_start;        /* Index into log_buf: next char to be sent to consoles */
-static unsigned long log_end;  /* Index into log_buf: most-recently-written-char + 1 */
+static unsigned log_start;     /* Index into log_buf: next char to be read by syslog() */
+static unsigned con_start;     /* Index into log_buf: next char to be sent to consoles */
+static unsigned log_end;       /* Index into log_buf: most-recently-written-char + 1 */
 
 /*
  *     Array of consoles built from command line options (console=)
@@ -128,17 +128,17 @@ static int console_may_schedule;
 static char __log_buf[__LOG_BUF_LEN];
 static char *log_buf = __log_buf;
 static int log_buf_len = __LOG_BUF_LEN;
-static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */
+static unsigned logged_chars; /* Number of chars produced since last read+clear operation */
 
 static int __init log_buf_len_setup(char *str)
 {
-       unsigned long size = memparse(str, &str);
+       unsigned size = memparse(str, &str);
        unsigned long flags;
 
        if (size)
                size = roundup_pow_of_two(size);
        if (size > log_buf_len) {
-               unsigned long start, dest_idx, offset;
+               unsigned start, dest_idx, offset;
                char *new_log_buf;
 
                new_log_buf = alloc_bootmem(size);
@@ -295,7 +295,7 @@ int log_buf_read(int idx)
  */
 int do_syslog(int type, char __user *buf, int len)
 {
-       unsigned long i, j, limit, count;
+       unsigned i, j, limit, count;
        int do_clear = 0;
        char c;
        int error = 0;
@@ -436,7 +436,7 @@ asmlinkage long sys_syslog(int type, char __user *buf, int len)
 /*
  * Call the console drivers on a range of log_buf
  */
-static void __call_console_drivers(unsigned long start, unsigned long end)
+static void __call_console_drivers(unsigned start, unsigned end)
 {
        struct console *con;
 
@@ -463,8 +463,8 @@ early_param("ignore_loglevel", ignore_loglevel_setup);
 /*
  * Write out chars from start to end - 1 inclusive
  */
-static void _call_console_drivers(unsigned long start,
-                               unsigned long end, int msg_log_level)
+static void _call_console_drivers(unsigned start,
+                               unsigned end, int msg_log_level)
 {
        if ((msg_log_level < console_loglevel || ignore_loglevel) &&
                        console_drivers && start != end) {
@@ -484,12 +484,12 @@ static void _call_console_drivers(unsigned long start,
  * log_buf[start] to log_buf[end - 1].
  * The console_sem must be held.
  */
-static void call_console_drivers(unsigned long start, unsigned long end)
+static void call_console_drivers(unsigned start, unsigned end)
 {
-       unsigned long cur_index, start_print;
+       unsigned cur_index, start_print;
        static int msg_level = -1;
 
-       BUG_ON(((long)(start - end)) > 0);
+       BUG_ON(((int)(start - end)) > 0);
 
        cur_index = start;
        start_print = start;
@@ -790,7 +790,7 @@ asmlinkage long sys_syslog(int type, char __user *buf, int len)
        return -ENOSYS;
 }
 
-static void call_console_drivers(unsigned long start, unsigned long end)
+static void call_console_drivers(unsigned start, unsigned end)
 {
 }
 
@@ -983,8 +983,8 @@ void wake_up_klogd(void)
 void release_console_sem(void)
 {
        unsigned long flags;
-       unsigned long _con_start, _log_end;
-       unsigned long wake_klogd = 0;
+       unsigned _con_start, _log_end;
+       unsigned wake_klogd = 0;
 
        if (console_suspended) {
                up(&secondary_console_sem);
@@ -1275,7 +1275,7 @@ void tty_write_message(struct tty_struct *tty, char *msg)
 int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst)
 {
        static DEFINE_SPINLOCK(ratelimit_lock);
-       static unsigned long toks = 10 * 5 * HZ;
+       static unsigned toks = 10 * 5 * HZ;
        static unsigned long last_msg;
        static int missed;
        unsigned long flags;
index b0d4ab4dfd3d27ee60e3a044f9e0bc3bba665d88..628b03ab88a579c52f9c802440e768c4752ab957 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/signal.h>
 #include <linux/audit.h>
 #include <linux/pid_namespace.h>
+#include <linux/syscalls.h>
 
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
@@ -53,7 +54,7 @@ void ptrace_untrace(struct task_struct *child)
        spin_lock(&child->sighand->siglock);
        if (task_is_traced(child)) {
                if (child->signal->flags & SIGNAL_STOP_STOPPED) {
-                       child->state = TASK_STOPPED;
+                       __set_task_state(child, TASK_STOPPED);
                } else {
                        signal_wake_up(child, 1);
                }
@@ -103,18 +104,16 @@ int ptrace_check_attach(struct task_struct *child, int kill)
            && child->signal != NULL) {
                ret = 0;
                spin_lock_irq(&child->sighand->siglock);
-               if (task_is_stopped(child)) {
+               if (task_is_stopped(child))
                        child->state = TASK_TRACED;
-               } else if (!task_is_traced(child) && !kill) {
+               else if (!task_is_traced(child) && !kill)
                        ret = -ESRCH;
-               }
                spin_unlock_irq(&child->sighand->siglock);
        }
        read_unlock(&tasklist_lock);
 
-       if (!ret && !kill) {
+       if (!ret && !kill)
                wait_task_inactive(child);
-       }
 
        /* All systems go.. */
        return ret;
index 61134eb7a0c8a9b2d2e0557b33ff4fbd7ff96f31..d080b9d161a75eee95bbf6d7aed235354bda9e9c 100644 (file)
@@ -37,37 +37,31 @@ static void relay_file_mmap_close(struct vm_area_struct *vma)
 }
 
 /*
- * nopage() vm_op implementation for relay file mapping.
+ * fault() vm_op implementation for relay file mapping.
  */
-static struct page *relay_buf_nopage(struct vm_area_struct *vma,
-                                    unsigned long address,
-                                    int *type)
+static int relay_buf_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        struct page *page;
        struct rchan_buf *buf = vma->vm_private_data;
-       unsigned long offset = address - vma->vm_start;
+       pgoff_t pgoff = vmf->pgoff;
 
-       if (address > vma->vm_end)
-               return NOPAGE_SIGBUS; /* Disallow mremap */
        if (!buf)
-               return NOPAGE_OOM;
+               return VM_FAULT_OOM;
 
-       page = vmalloc_to_page(buf->start + offset);
+       page = vmalloc_to_page(buf->start + (pgoff << PAGE_SHIFT));
        if (!page)
-               return NOPAGE_OOM;
+               return VM_FAULT_SIGBUS;
        get_page(page);
+       vmf->page = page;
 
-       if (type)
-               *type = VM_FAULT_MINOR;
-
-       return page;
+       return 0;
 }
 
 /*
  * vm_ops for relay file mappings.
  */
 static struct vm_operations_struct relay_file_mmap_ops = {
-       .nopage = relay_buf_nopage,
+       .fault = relay_buf_fault,
        .close = relay_file_mmap_close,
 };
 
@@ -92,6 +86,7 @@ static int relay_mmap_buf(struct rchan_buf *buf, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_ops = &relay_file_mmap_ops;
+       vma->vm_flags |= VM_DONTEXPAND;
        vma->vm_private_data = buf;
        buf->chan->cb->buf_mapped(buf, filp);
 
index 4333b6dbb424f9e0bb7f07148077254106386a50..5d30ff5618475273c60e6aeb59e7cf092603b9a4 100644 (file)
@@ -911,27 +911,6 @@ __group_complete_signal(int sig, struct task_struct *p)
                        } while_each_thread(p, t);
                        return;
                }
-
-               /*
-                * There will be a core dump.  We make all threads other
-                * than the chosen one go into a group stop so that nothing
-                * happens until it gets scheduled, takes the signal off
-                * the shared queue, and does the core dump.  This is a
-                * little more complicated than strictly necessary, but it
-                * keeps the signal state that winds up in the core dump
-                * unchanged from the death state, e.g. which thread had
-                * the core-dump signal unblocked.
-                */
-               rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
-               rm_from_queue(SIG_KERNEL_STOP_MASK, &p->signal->shared_pending);
-               p->signal->group_stop_count = 0;
-               p->signal->group_exit_task = t;
-               p = t;
-               do {
-                       p->signal->group_stop_count++;
-                       signal_wake_up(t, t == p);
-               } while_each_thread(p, t);
-               return;
        }
 
        /*
@@ -978,7 +957,6 @@ void zap_other_threads(struct task_struct *p)
 {
        struct task_struct *t;
 
-       p->signal->flags = SIGNAL_GROUP_EXIT;
        p->signal->group_stop_count = 0;
 
        for (t = next_thread(p); t != p; t = next_thread(t)) {
@@ -1599,6 +1577,17 @@ static inline int may_ptrace_stop(void)
        return 1;
 }
 
+/*
+ * Return nonzero if there is a SIGKILL that should be waking us up.
+ * Called with the siglock held.
+ */
+static int sigkill_pending(struct task_struct *tsk)
+{
+       return ((sigismember(&tsk->pending.signal, SIGKILL) ||
+                sigismember(&tsk->signal->shared_pending.signal, SIGKILL)) &&
+               !unlikely(sigismember(&tsk->blocked, SIGKILL)));
+}
+
 /*
  * This must be called with current->sighand->siglock held.
  *
@@ -1612,6 +1601,26 @@ static inline int may_ptrace_stop(void)
  */
 static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
 {
+       int killed = 0;
+
+       if (arch_ptrace_stop_needed(exit_code, info)) {
+               /*
+                * The arch code has something special to do before a
+                * ptrace stop.  This is allowed to block, e.g. for faults
+                * on user stack pages.  We can't keep the siglock while
+                * calling arch_ptrace_stop, so we must release it now.
+                * To preserve proper semantics, we must do this before
+                * any signal bookkeeping like checking group_stop_count.
+                * Meanwhile, a SIGKILL could come in before we retake the
+                * siglock.  That must prevent us from sleeping in TASK_TRACED.
+                * So after regaining the lock, we must check for SIGKILL.
+                */
+               spin_unlock_irq(&current->sighand->siglock);
+               arch_ptrace_stop(exit_code, info);
+               spin_lock_irq(&current->sighand->siglock);
+               killed = sigkill_pending(current);
+       }
+
        /*
         * If there is a group stop in progress,
         * we must participate in the bookkeeping.
@@ -1623,11 +1632,11 @@ static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
        current->exit_code = exit_code;
 
        /* Let the debugger run.  */
-       set_current_state(TASK_TRACED);
+       __set_current_state(TASK_TRACED);
        spin_unlock_irq(&current->sighand->siglock);
        try_to_freeze();
        read_lock(&tasklist_lock);
-       if (may_ptrace_stop()) {
+       if (!unlikely(killed) && may_ptrace_stop()) {
                do_notify_parent_cldstop(current, CLD_TRAPPED);
                read_unlock(&tasklist_lock);
                schedule();
@@ -1709,9 +1718,6 @@ static int do_signal_stop(int signr)
        struct signal_struct *sig = current->signal;
        int stop_count;
 
-       if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED))
-               return 0;
-
        if (sig->group_stop_count > 0) {
                /*
                 * There is a group stop in progress.  We don't need to
@@ -1719,12 +1725,15 @@ static int do_signal_stop(int signr)
                 */
                stop_count = --sig->group_stop_count;
        } else {
+               struct task_struct *t;
+
+               if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) ||
+                   unlikely(sig->group_exit_task))
+                       return 0;
                /*
                 * There is no group stop already in progress.
                 * We must initiate one now.
                 */
-               struct task_struct *t;
-
                sig->group_exit_code = signr;
 
                stop_count = 0;
@@ -1752,47 +1761,6 @@ static int do_signal_stop(int signr)
        return 1;
 }
 
-/*
- * Do appropriate magic when group_stop_count > 0.
- * We return nonzero if we stopped, after releasing the siglock.
- * We return zero if we still hold the siglock and should look
- * for another signal without checking group_stop_count again.
- */
-static int handle_group_stop(void)
-{
-       int stop_count;
-
-       if (current->signal->group_exit_task == current) {
-               /*
-                * Group stop is so we can do a core dump,
-                * We are the initiating thread, so get on with it.
-                */
-               current->signal->group_exit_task = NULL;
-               return 0;
-       }
-
-       if (current->signal->flags & SIGNAL_GROUP_EXIT)
-               /*
-                * Group stop is so another thread can do a core dump,
-                * or else we are racing against a death signal.
-                * Just punt the stop so we can get the next signal.
-                */
-               return 0;
-
-       /*
-        * There is a group stop in progress.  We stop
-        * without any associated signal being in our queue.
-        */
-       stop_count = --current->signal->group_stop_count;
-       if (stop_count == 0)
-               current->signal->flags = SIGNAL_STOP_STOPPED;
-       current->exit_code = current->signal->group_exit_code;
-       set_current_state(TASK_STOPPED);
-       spin_unlock_irq(&current->sighand->siglock);
-       finish_stop(stop_count);
-       return 1;
-}
-
 int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
                          struct pt_regs *regs, void *cookie)
 {
@@ -1807,7 +1775,7 @@ relock:
                struct k_sigaction *ka;
 
                if (unlikely(current->signal->group_stop_count > 0) &&
-                   handle_group_stop())
+                   do_signal_stop(0))
                        goto relock;
 
                signr = dequeue_signal(current, mask, info);
index c1d76552446e592bc132d8de37073ecb589a1629..7c2da88db4eddf6539673357b01d94b543aac52c 100644 (file)
@@ -101,6 +101,10 @@ void softlockup_tick(void)
 
        now = get_timestamp(this_cpu);
 
+       /* Wake up the high-prio watchdog task every second: */
+       if (now > (touch_timestamp + 1))
+               wake_up_process(per_cpu(watchdog_task, this_cpu));
+
        /* Warn about unreasonable delays: */
        if (now <= (touch_timestamp + softlockup_thresh))
                return;
@@ -191,11 +195,11 @@ static void check_hung_uninterruptible_tasks(int this_cpu)
        read_lock(&tasklist_lock);
        do_each_thread(g, t) {
                if (!--max_count)
-                       break;
+                       goto unlock;
                if (t->state & TASK_UNINTERRUPTIBLE)
                        check_hung_task(t, now);
        } while_each_thread(g, t);
-
+ unlock:
        read_unlock(&tasklist_lock);
 }
 
@@ -218,14 +222,19 @@ static int watchdog(void *__bind_cpu)
         * debug-printout triggers in softlockup_tick().
         */
        while (!kthread_should_stop()) {
+               set_current_state(TASK_INTERRUPTIBLE);
                touch_softlockup_watchdog();
-               msleep_interruptible(10000);
+               schedule();
+
+               if (kthread_should_stop())
+                       break;
 
                if (this_cpu != check_cpu)
                        continue;
 
                if (sysctl_hung_task_timeout_secs)
                        check_hung_uninterruptible_tasks(this_cpu);
+
        }
 
        return 0;
@@ -259,13 +268,6 @@ cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
                wake_up_process(per_cpu(watchdog_task, hotcpu));
                break;
 #ifdef CONFIG_HOTPLUG_CPU
-       case CPU_UP_CANCELED:
-       case CPU_UP_CANCELED_FROZEN:
-               if (!per_cpu(watchdog_task, hotcpu))
-                       break;
-               /* Unbind so it can run.  Fall thru. */
-               kthread_bind(per_cpu(watchdog_task, hotcpu),
-                            any_online_cpu(cpu_online_map));
        case CPU_DOWN_PREPARE:
        case CPU_DOWN_PREPARE_FROZEN:
                if (hotcpu == check_cpu) {
@@ -275,6 +277,14 @@ cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
                        check_cpu = any_online_cpu(temp_cpu_online_map);
                }
                break;
+
+       case CPU_UP_CANCELED:
+       case CPU_UP_CANCELED_FROZEN:
+               if (!per_cpu(watchdog_task, hotcpu))
+                       break;
+               /* Unbind so it can run.  Fall thru. */
+               kthread_bind(per_cpu(watchdog_task, hotcpu),
+                            any_online_cpu(cpu_online_map));
        case CPU_DEAD:
        case CPU_DEAD_FROZEN:
                p = per_cpu(watchdog_task, hotcpu);
index 3507cabe963bd453857b68f6bf56b59103d0781d..b0aeeaf22ce49c8c76098aac5224b1f4c44d4c4d 100644 (file)
@@ -74,7 +74,7 @@ static int srcu_readers_active_idx(struct srcu_struct *sp, int idx)
  * severe errors when invoked on an active srcu_struct.  That said, it
  * can be useful as an error check at cleanup time.
  */
-int srcu_readers_active(struct srcu_struct *sp)
+static int srcu_readers_active(struct srcu_struct *sp)
 {
        return srcu_readers_active_idx(sp, 0) + srcu_readers_active_idx(sp, 1);
 }
@@ -255,4 +255,3 @@ EXPORT_SYMBOL_GPL(srcu_read_lock);
 EXPORT_SYMBOL_GPL(srcu_read_unlock);
 EXPORT_SYMBOL_GPL(synchronize_srcu);
 EXPORT_SYMBOL_GPL(srcu_batches_completed);
-EXPORT_SYMBOL_GPL(srcu_readers_active);
index 51b5ee53571a63558cef49075de15c4dc25396a6..6f4e0e13f70c337c531be43b0d3cc5296c972c71 100644 (file)
@@ -29,7 +29,6 @@ enum stopmachine_state {
 static enum stopmachine_state stopmachine_state;
 static unsigned int stopmachine_num_threads;
 static atomic_t stopmachine_thread_ack;
-static DECLARE_MUTEX(stopmachine_mutex);
 
 static int stopmachine(void *cpu)
 {
@@ -170,6 +169,7 @@ static int do_stop(void *_smdata)
 struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
                                       unsigned int cpu)
 {
+       static DEFINE_MUTEX(stopmachine_mutex);
        struct stop_machine_data smdata;
        struct task_struct *p;
 
@@ -177,7 +177,7 @@ struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
        smdata.data = data;
        init_completion(&smdata.done);
 
-       down(&stopmachine_mutex);
+       mutex_lock(&stopmachine_mutex);
 
        /* If they don't care which CPU fn runs on, bind to any online one. */
        if (cpu == NR_CPUS)
@@ -193,7 +193,7 @@ struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
                wake_up_process(p);
                wait_for_completion(&smdata.done);
        }
-       up(&stopmachine_mutex);
+       mutex_unlock(&stopmachine_mutex);
        return p;
 }
 
index d1fe71eb45469bc99f23cfe9aee83a8cbecc81b1..e3c08d4324deed268673c23ff8efd01817874d68 100644 (file)
@@ -315,7 +315,7 @@ static void kernel_kexec(void)
 #endif
 }
 
-void kernel_shutdown_prepare(enum system_states state)
+static void kernel_shutdown_prepare(enum system_states state)
 {
        blocking_notifier_call_chain(&reboot_notifier_list,
                (state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
@@ -1145,16 +1145,16 @@ static int groups_to_user(gid_t __user *grouplist,
     struct group_info *group_info)
 {
        int i;
-       int count = group_info->ngroups;
+       unsigned int count = group_info->ngroups;
 
        for (i = 0; i < group_info->nblocks; i++) {
-               int cp_count = min(NGROUPS_PER_BLOCK, count);
-               int off = i * NGROUPS_PER_BLOCK;
-               int len = cp_count * sizeof(*grouplist);
+               unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);
+               unsigned int len = cp_count * sizeof(*grouplist);
 
-               if (copy_to_user(grouplist+off, group_info->blocks[i], len))
+               if (copy_to_user(grouplist, group_info->blocks[i], len))
                        return -EFAULT;
 
+               grouplist += NGROUPS_PER_BLOCK;
                count -= cp_count;
        }
        return 0;
@@ -1165,16 +1165,16 @@ static int groups_from_user(struct group_info *group_info,
     gid_t __user *grouplist)
 {
        int i;
-       int count = group_info->ngroups;
+       unsigned int count = group_info->ngroups;
 
        for (i = 0; i < group_info->nblocks; i++) {
-               int cp_count = min(NGROUPS_PER_BLOCK, count);
-               int off = i * NGROUPS_PER_BLOCK;
-               int len = cp_count * sizeof(*grouplist);
+               unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);
+               unsigned int len = cp_count * sizeof(*grouplist);
 
-               if (copy_from_user(group_info->blocks[i], grouplist+off, len))
+               if (copy_from_user(group_info->blocks[i], grouplist, len))
                        return -EFAULT;
 
+               grouplist += NGROUPS_PER_BLOCK;
                count -= cp_count;
        }
        return 0;
@@ -1472,7 +1472,7 @@ asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
        if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
            !capable(CAP_SYS_RESOURCE))
                return -EPERM;
-       if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
+       if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
                return -EPERM;
 
        retval = security_task_setrlimit(resource, &new_rlim);
@@ -1637,7 +1637,7 @@ asmlinkage long sys_umask(int mask)
        mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
        return mask;
 }
-    
+
 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                          unsigned long arg4, unsigned long arg5)
 {
@@ -1742,6 +1742,17 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                        error = prctl_set_seccomp(arg2);
                        break;
 
+               case PR_CAPBSET_READ:
+                       if (!cap_valid(arg2))
+                               return -EINVAL;
+                       return !!cap_raised(current->cap_bset, arg2);
+               case PR_CAPBSET_DROP:
+#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
+                       return cap_prctl_drop(arg2);
+#else
+                       return -EINVAL;
+#endif
+
                default:
                        error = -EINVAL;
                        break;
index beee5b3b68a284a2e2b3fd2c2a3d9578d0e03bb7..5b9b467de070e2b50e0e2da7b09aaacfd6cc417e 100644 (file)
@@ -154,7 +154,10 @@ cond_syscall(sys_ioprio_get);
 
 /* New file descriptors */
 cond_syscall(sys_signalfd);
-cond_syscall(sys_timerfd);
 cond_syscall(compat_sys_signalfd);
-cond_syscall(compat_sys_timerfd);
+cond_syscall(sys_timerfd_create);
+cond_syscall(sys_timerfd_settime);
+cond_syscall(sys_timerfd_gettime);
+cond_syscall(compat_sys_timerfd_settime);
+cond_syscall(compat_sys_timerfd_gettime);
 cond_syscall(sys_eventfd);
index 7cb1ac3e6fff9583c0d880788190d14da6e2ced1..86daaa26d1200c359f8f7c150e1ad5d7ddc1f70d 100644 (file)
@@ -84,8 +84,11 @@ extern int sysctl_stat_interval;
 extern int latencytop_enabled;
 
 /* Constants used for minimum and  maximum */
-#ifdef CONFIG_DETECT_SOFTLOCKUP
+#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
 static int one = 1;
+#endif
+
+#ifdef CONFIG_DETECT_SOFTLOCKUP
 static int sixty = 60;
 #endif
 
@@ -416,15 +419,6 @@ static struct ctl_table kern_table[] = {
                .proc_handler   = &proc_dointvec,
        },
 #endif
-#ifdef CONFIG_SECURITY_CAPABILITIES
-       {
-               .procname       = "cap-bound",
-               .data           = &cap_bset,
-               .maxlen         = sizeof(kernel_cap_t),
-               .mode           = 0600,
-               .proc_handler   = &proc_dointvec_bset,
-       },
-#endif /* def CONFIG_SECURITY_CAPABILITIES */
 #ifdef CONFIG_BLK_DEV_INITRD
        {
                .ctl_name       = KERN_REALROOTDEV,
@@ -1150,6 +1144,19 @@ static struct ctl_table vm_table[] = {
                .extra1         = &zero,
        },
 #endif
+#ifdef CONFIG_HIGHMEM
+       {
+               .ctl_name       = CTL_UNNUMBERED,
+               .procname       = "highmem_is_dirtyable",
+               .data           = &vm_highmem_is_dirtyable,
+               .maxlen         = sizeof(vm_highmem_is_dirtyable),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec_minmax,
+               .strategy       = &sysctl_intvec,
+               .extra1         = &zero,
+               .extra2         = &one,
+       },
+#endif
 /*
  * NOTE: do not add new entries to this table unless you have read
  * Documentation/sysctl/ctl_unnumbered.txt
@@ -1195,6 +1202,14 @@ static struct ctl_table fs_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dointvec,
        },
+       {
+               .ctl_name       = CTL_UNNUMBERED,
+               .procname       = "nr_open",
+               .data           = &sysctl_nr_open,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec,
+       },
        {
                .ctl_name       = FS_DENTRY,
                .procname       = "dentry-state",
@@ -2080,26 +2095,6 @@ static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
        return 0;
 }
 
-#ifdef CONFIG_SECURITY_CAPABILITIES
-/*
- *     init may raise the set.
- */
-
-int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
-                       void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-       int op;
-
-       if (write && !capable(CAP_SYS_MODULE)) {
-               return -EPERM;
-       }
-
-       op = is_global_init(current) ? OP_SET : OP_AND;
-       return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
-                               do_proc_dointvec_bset_conv,&op);
-}
-#endif /* def CONFIG_SECURITY_CAPABILITIES */
-
 /*
  *     Taint values can only be increased
  */
@@ -2513,12 +2508,6 @@ int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
        return -ENOSYS;
 }
 
-int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
-                       void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-       return -ENOSYS;
-}
-
 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
                    void __user *buffer, size_t *lenp, loff_t *ppos)
 {
index c3206fa50048b8333be64be54a3a52acf8d39bcb..006365b69eafdfcebbaa47ba1370a87d58813e94 100644 (file)
@@ -37,10 +37,6 @@ static struct trans_ctl_table trans_kern_table[] = {
        { KERN_NODENAME,                "hostname" },
        { KERN_DOMAINNAME,              "domainname" },
 
-#ifdef CONFIG_SECURITY_CAPABILITIES
-       { KERN_CAP_BSET,                "cap-bound" },
-#endif /* def CONFIG_SECURITY_CAPABILITIES */
-
        { KERN_PANIC,                   "panic" },
        { KERN_REALROOTDEV,             "real-root-dev" },
 
@@ -1498,9 +1494,6 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
                            (table->strategy == sysctl_ms_jiffies) ||
                            (table->proc_handler == proc_dostring) ||
                            (table->proc_handler == proc_dointvec) ||
-#ifdef CONFIG_SECURITY_CAPABILITIES
-                           (table->proc_handler == proc_dointvec_bset) ||
-#endif /* def CONFIG_SECURITY_CAPABILITIES */
                            (table->proc_handler == proc_dointvec_minmax) ||
                            (table->proc_handler == proc_dointvec_jiffies) ||
                            (table->proc_handler == proc_dointvec_userhz_jiffies) ||
index 88cdb109e13cbf605049ef3955054fd5774660ee..06b6395b45b25dcde1a2dd3e1075bce406742ba4 100644 (file)
@@ -135,6 +135,12 @@ static int test_jprobe(void)
 #ifdef CONFIG_KRETPROBES
 static u32 krph_val;
 
+static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       krph_val = (rand1 / div_factor);
+       return 0;
+}
+
 static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
 {
        unsigned long ret = regs_return_value(regs);
@@ -144,13 +150,19 @@ static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
                printk(KERN_ERR "Kprobe smoke test failed: "
                                "incorrect value in kretprobe handler\n");
        }
+       if (krph_val == 0) {
+               handler_errors++;
+               printk(KERN_ERR "Kprobe smoke test failed: "
+                               "call to kretprobe entry handler failed\n");
+       }
 
-       krph_val = (rand1 / div_factor);
+       krph_val = rand1;
        return 0;
 }
 
 static struct kretprobe rp = {
        .handler        = return_handler,
+       .entry_handler  = entry_handler,
        .kp.symbol_name = "kprobe_target"
 };
 
@@ -167,7 +179,7 @@ static int test_kretprobe(void)
 
        ret = kprobe_target(rand1);
        unregister_kretprobe(&rp);
-       if (krph_val == 0) {
+       if (krph_val != rand1) {
                printk(KERN_ERR "Kprobe smoke test failed: "
                                "kretprobe handler not called\n");
                handler_errors++;
index 4064c0566e77db73c9cd3b5534884975dc4394e0..33af3e55570dfc5d8fe74aba067d2e26591c1a91 100644 (file)
@@ -566,7 +566,11 @@ EXPORT_SYMBOL(jiffies_to_timeval);
 clock_t jiffies_to_clock_t(long x)
 {
 #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
+# if HZ < USER_HZ
+       return x * (USER_HZ / HZ);
+# else
        return x / (HZ / USER_HZ);
+# endif
 #else
        u64 tmp = (u64)x * TICK_NSEC;
        do_div(tmp, (NSEC_PER_SEC / USER_HZ));
@@ -599,7 +603,14 @@ EXPORT_SYMBOL(clock_t_to_jiffies);
 u64 jiffies_64_to_clock_t(u64 x)
 {
 #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
+# if HZ < USER_HZ
+       x *= USER_HZ;
+       do_div(x, HZ);
+# elif HZ > USER_HZ
        do_div(x, HZ / USER_HZ);
+# else
+       /* Nothing to do */
+# endif
 #else
        /*
         * There are better ways that don't overflow early,
@@ -611,7 +622,6 @@ u64 jiffies_64_to_clock_t(u64 x)
 #endif
        return x;
 }
-
 EXPORT_SYMBOL(jiffies_64_to_clock_t);
 
 u64 nsec_to_clock_t(u64 x)
@@ -646,7 +656,6 @@ u64 get_jiffies_64(void)
        } while (read_seqretry(&xtime_lock, seq));
        return ret;
 }
-
 EXPORT_SYMBOL(get_jiffies_64);
 #endif
 
index 6e9259a5d5010ac7e869f4f567fd3c0618002943..81afb3927eccca2a8f684eb41508740779ed102a 100644 (file)
@@ -363,15 +363,13 @@ void clocksource_unregister(struct clocksource *cs)
 static ssize_t
 sysfs_show_current_clocksources(struct sys_device *dev, char *buf)
 {
-       char *curr = buf;
+       ssize_t count = 0;
 
        spin_lock_irq(&clocksource_lock);
-       curr += sprintf(curr, "%s ", curr_clocksource->name);
+       count = snprintf(buf, PAGE_SIZE, "%s\n", curr_clocksource->name);
        spin_unlock_irq(&clocksource_lock);
 
-       curr += sprintf(curr, "\n");
-
-       return curr - buf;
+       return count;
 }
 
 /**
@@ -439,17 +437,20 @@ static ssize_t
 sysfs_show_available_clocksources(struct sys_device *dev, char *buf)
 {
        struct clocksource *src;
-       char *curr = buf;
+       ssize_t count = 0;
 
        spin_lock_irq(&clocksource_lock);
        list_for_each_entry(src, &clocksource_list, list) {
-               curr += sprintf(curr, "%s ", src->name);
+               count += snprintf(buf + count,
+                                 max((ssize_t)PAGE_SIZE - count, (ssize_t)0),
+                                 "%s ", src->name);
        }
        spin_unlock_irq(&clocksource_lock);
 
-       curr += sprintf(curr, "\n");
+       count += snprintf(buf + count,
+                         max((ssize_t)PAGE_SIZE - count, (ssize_t)0), "\n");
 
-       return curr - buf;
+       return count;
 }
 
 /*
index 9fbb472b8cf0a4e3016480fb205c42eda38dabf8..70b29b59343f6e5a0a0e2cd8cf636748ed16925d 100644 (file)
@@ -818,12 +818,14 @@ unsigned long next_timer_interrupt(void)
 #ifndef CONFIG_VIRT_CPU_ACCOUNTING
 void account_process_tick(struct task_struct *p, int user_tick)
 {
+       cputime_t one_jiffy = jiffies_to_cputime(1);
+
        if (user_tick) {
-               account_user_time(p, jiffies_to_cputime(1));
-               account_user_time_scaled(p, jiffies_to_cputime(1));
+               account_user_time(p, one_jiffy);
+               account_user_time_scaled(p, cputime_to_scaled(one_jiffy));
        } else {
-               account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1));
-               account_system_time_scaled(p, jiffies_to_cputime(1));
+               account_system_time(p, HARDIRQ_OFFSET, one_jiffy);
+               account_system_time_scaled(p, cputime_to_scaled(one_jiffy));
        }
 }
 #endif
index 0d8a5a4a789d868100762420d0647f50f27c72fc..0d385be682db021dccc6482f385d8bb6f30fa75e 100644 (file)
@@ -81,7 +81,7 @@ config HEADERS_CHECK
 
 config DEBUG_SECTION_MISMATCH
        bool "Enable full Section mismatch analysis"
-       default n
+       depends on UNDEFINED
        help
          The section mismatch analysis checks if there are illegal
          references from one section to another section.
@@ -90,19 +90,19 @@ config DEBUG_SECTION_MISMATCH
          most likely result in an oops.
          In the code functions and variables are annotated with
          __init, __devinit etc. (see full list in include/linux/init.h)
-         which result in the code/data being placed in specific sections.
-         The section mismatch anaylsis are always done after a full
-         kernel build but enabling this options will in addition
+         which results in the code/data being placed in specific sections.
+         The section mismatch analysis is always done after a full
+         kernel build but enabling this option will in addition
          do the following:
          - Add the option -fno-inline-functions-called-once to gcc
            When inlining a function annotated __init in a non-init
-           function we would loose the section information and thus
+           function we would lose the section information and thus
            the analysis would not catch the illegal reference.
-           This options tell gcc to inline less but will also
+           This option tells gcc to inline less but will also
            result in a larger kernel.
          - Run the section mismatch analysis for each module/built-in.o
            When we run the section mismatch analysis on vmlinux.o we
-           looses valueable information about where the mismatch was
+           lose valueble information about where the mismatch was
            introduced.
            Running the analysis for each module/built-in.o file
            will tell where the mismatch happens much closer to the
index 543f2502b60a416f2bb97575e2e8f0254c7a9199..a18062e4633f810463feae8efbe349a085604335 100644 (file)
@@ -65,6 +65,7 @@ obj-$(CONFIG_SMP) += pcounter.o
 obj-$(CONFIG_AUDIT_GENERIC) += audit.o
 
 obj-$(CONFIG_SWIOTLB) += swiotlb.o
+obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
 obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
 
 lib-$(CONFIG_GENERIC_BUG) += bug.o
index d2c2f257bedd348a0f81316fc02ef90226ecc0ac..49d1c9e3ce3820ccb8dd3d01cec5e11ac39cd7cc 100644 (file)
@@ -348,7 +348,7 @@ EXPORT_SYMBOL(crc32_be);
  * but again the multiple of the polynomial to subtract depends only on
  * the high bits, the high 8 bits in this case.  
  *
- * The multile we need in that case is the low 32 bits of a 40-bit
+ * The multiple we need in that case is the low 32 bits of a 40-bit
  * value whose high 8 bits are given, and which is a multiple of the
  * generator polynomial.  This is simply the CRC-32 of the given
  * one-byte message.
index 463f4560f16da1e6d03394b46d8e0763948501f7..179c0874559569bf2626cbfc70bfcfef09474097 100644 (file)
@@ -57,10 +57,10 @@ search_extable(const struct exception_table_entry *first,
        while (first <= last) {
                const struct exception_table_entry *mid;
 
-               mid = (last - first) / 2 + first;
+               mid = ((last - first) >> 1) + first;
                /*
-                * careful, the distance between entries can be
-                * larger than 2GB:
+                * careful, the distance between value and insn
+                * can be larger than MAX_LONG:
                 */
                if (mid->insn < value)
                        first = mid + 1;
diff --git a/lib/iommu-helper.c b/lib/iommu-helper.c
new file mode 100644 (file)
index 0000000..495575a
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * IOMMU helper functions for the free area management
+ */
+
+#include <linux/module.h>
+#include <linux/bitops.h>
+
+static unsigned long find_next_zero_area(unsigned long *map,
+                                        unsigned long size,
+                                        unsigned long start,
+                                        unsigned int nr,
+                                        unsigned long align_mask)
+{
+       unsigned long index, end, i;
+again:
+       index = find_next_zero_bit(map, size, start);
+
+       /* Align allocation */
+       index = (index + align_mask) & ~align_mask;
+
+       end = index + nr;
+       if (end >= size)
+               return -1;
+       for (i = index; i < end; i++) {
+               if (test_bit(i, map)) {
+                       start = i+1;
+                       goto again;
+               }
+       }
+       return index;
+}
+
+static inline void set_bit_area(unsigned long *map, unsigned long i,
+                               int len)
+{
+       unsigned long end = i + len;
+       while (i < end) {
+               __set_bit(i, map);
+               i++;
+       }
+}
+
+static inline int is_span_boundary(unsigned int index, unsigned int nr,
+                                  unsigned long shift,
+                                  unsigned long boundary_size)
+{
+       shift = (shift + index) & (boundary_size - 1);
+       return shift + nr > boundary_size;
+}
+
+unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
+                              unsigned long start, unsigned int nr,
+                              unsigned long shift, unsigned long boundary_size,
+                              unsigned long align_mask)
+{
+       unsigned long index;
+again:
+       index = find_next_zero_area(map, size, start, nr, align_mask);
+       if (index != -1) {
+               if (is_span_boundary(index, nr, shift, boundary_size)) {
+                       /* we could do more effectively */
+                       start = index + 1;
+                       goto again;
+               }
+               set_bit_area(map, index, nr);
+       }
+       return index;
+}
+EXPORT_SYMBOL(iommu_area_alloc);
+
+void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
+{
+       unsigned long end = start + nr;
+
+       while (start < end) {
+               __clear_bit(start, map);
+               start++;
+       }
+}
+EXPORT_SYMBOL(iommu_area_free);
index 1d63ead1815e4f5cb8aae5ea2d86a1541eed23a2..d784daeb8571692e0fed288f17df60651a04366c 100644 (file)
@@ -637,7 +637,7 @@ struct kobject *kobject_create(void)
  * @name: the name for the kset
  * @parent: the parent kobject of this kobject, if any.
  *
- * This function creates a kset structure dynamically and registers it
+ * This function creates a kobject structure dynamically and registers it
  * with sysfs.  When you are finished with this structure, call
  * kobject_put() and the structure will be dynamically freed when
  * it is no longer being used.
index 48c250fe2233d82c6d8fd563e83c234cdf1109ee..65f0e758ec3819d57f1799e5563a9f90dc0e41eb 100644 (file)
@@ -95,14 +95,17 @@ static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
 static struct radix_tree_node *
 radix_tree_node_alloc(struct radix_tree_root *root)
 {
-       struct radix_tree_node *ret;
+       struct radix_tree_node *ret = NULL;
        gfp_t gfp_mask = root_gfp_mask(root);
 
-       ret = kmem_cache_alloc(radix_tree_node_cachep,
-                               set_migrateflags(gfp_mask, __GFP_RECLAIMABLE));
-       if (ret == NULL && !(gfp_mask & __GFP_WAIT)) {
+       if (!(gfp_mask & __GFP_WAIT)) {
                struct radix_tree_preload *rtp;
 
+               /*
+                * Provided the caller has preloaded here, we will always
+                * succeed in getting a node here (and never reach
+                * kmem_cache_alloc)
+                */
                rtp = &__get_cpu_var(radix_tree_preloads);
                if (rtp->nr) {
                        ret = rtp->nodes[rtp->nr - 1];
@@ -110,6 +113,10 @@ radix_tree_node_alloc(struct radix_tree_root *root)
                        rtp->nr--;
                }
        }
+       if (ret == NULL)
+               ret = kmem_cache_alloc(radix_tree_node_cachep,
+                               set_migrateflags(gfp_mask, __GFP_RECLAIMABLE));
+
        BUG_ON(radix_tree_is_indirect_ptr(ret));
        return ret;
 }
index eddc9b3d38762ed17b06da35f26450f34c9ffd1a..6c90fb90e19c2ec25571947b7b98f88262e23ba4 100644 (file)
@@ -42,7 +42,9 @@ unsigned int debug_smp_processor_id(void)
        if (!printk_ratelimit())
                goto out_enable;
 
-       printk(KERN_ERR "BUG: using smp_processor_id() in preemptible [%08x] code: %s/%d\n", preempt_count(), current->comm, current->pid);
+       printk(KERN_ERR "BUG: using smp_processor_id() in preemptible [%08x] "
+                       "code: %s/%d\n",
+                       preempt_count() - 1, current->comm, current->pid);
        print_symbol("caller is %s\n", (long)__builtin_return_address(0));
        dump_stack();
 
index 1a8050ade86159877fd6eb4486954c7719bfc28d..4bb5a11e18a289e6bcf3a89ca41b0a13fb0b40cc 100644 (file)
@@ -282,6 +282,15 @@ address_needs_mapping(struct device *hwdev, dma_addr_t addr)
        return (addr & ~mask) != 0;
 }
 
+static inline unsigned int is_span_boundary(unsigned int index,
+                                           unsigned int nslots,
+                                           unsigned long offset_slots,
+                                           unsigned long max_slots)
+{
+       unsigned long offset = (offset_slots + index) & (max_slots - 1);
+       return offset + nslots > max_slots;
+}
+
 /*
  * Allocates bounce buffer and returns its kernel virtual address.
  */
@@ -292,6 +301,16 @@ map_single(struct device *hwdev, char *buffer, size_t size, int dir)
        char *dma_addr;
        unsigned int nslots, stride, index, wrap;
        int i;
+       unsigned long start_dma_addr;
+       unsigned long mask;
+       unsigned long offset_slots;
+       unsigned long max_slots;
+
+       mask = dma_get_seg_boundary(hwdev);
+       start_dma_addr = virt_to_bus(io_tlb_start) & mask;
+
+       offset_slots = ALIGN(start_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
+       max_slots = ALIGN(mask + 1, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
 
        /*
         * For mappings greater than a page, we limit the stride (and
@@ -311,10 +330,17 @@ map_single(struct device *hwdev, char *buffer, size_t size, int dir)
         */
        spin_lock_irqsave(&io_tlb_lock, flags);
        {
-               wrap = index = ALIGN(io_tlb_index, stride);
-
+               index = ALIGN(io_tlb_index, stride);
                if (index >= io_tlb_nslabs)
-                       wrap = index = 0;
+                       index = 0;
+
+               while (is_span_boundary(index, nslots, offset_slots,
+                                       max_slots)) {
+                       index += stride;
+                       if (index >= io_tlb_nslabs)
+                               index = 0;
+               }
+               wrap = index;
 
                do {
                        /*
@@ -341,9 +367,12 @@ map_single(struct device *hwdev, char *buffer, size_t size, int dir)
 
                                goto found;
                        }
-                       index += stride;
-                       if (index >= io_tlb_nslabs)
-                               index = 0;
+                       do {
+                               index += stride;
+                               if (index >= io_tlb_nslabs)
+                                       index = 0;
+                       } while (is_span_boundary(index, nslots, offset_slots,
+                                                 max_slots));
                } while (index != wrap);
 
                spin_unlock_irqrestore(&io_tlb_lock, flags);
index d9feaf638608a6de4d148f6fdce19e5a1fc59284..6b15a909ca3f0cfc163b4cdcd8a1613884643784 100644 (file)
@@ -164,7 +164,7 @@ typedef struct deflate_state {
     int nice_match; /* Stop searching when current match exceeds this */
 
                 /* used by trees.c: */
-    /* Didn't use ct_data typedef below to supress compiler warning */
+    /* Didn't use ct_data typedef below to suppress compiler warning */
     struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
     struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
     struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
index 5c0b0ea7572d8b04aa62ec2bbe2bd566eadef165..4af5dff372779949a28244208c26253e3356f60a 100644 (file)
@@ -13,8 +13,10 @@ obj-y                        := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
                           prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
                           page_isolation.o $(mmu-y)
 
+obj-$(CONFIG_PROC_PAGE_MONITOR) += pagewalk.o
 obj-$(CONFIG_BOUNCE)   += bounce.o
 obj-$(CONFIG_SWAP)     += page_io.o swap_state.o swapfile.o thrash.o
+obj-$(CONFIG_HAS_DMA)  += dmapool.o
 obj-$(CONFIG_HUGETLBFS)        += hugetlb.o
 obj-$(CONFIG_NUMA)     += mempolicy.o
 obj-$(CONFIG_SPARSEMEM)        += sparse.o
index 00b02623f008e924856329770c68ad0d3c3d7917..7e58322b7134ff1d04e40269e030bdd53e1c87f6 100644 (file)
@@ -98,7 +98,7 @@ EXPORT_SYMBOL_GPL(__percpu_populate_mask);
  */
 void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask)
 {
-       void *pdata = kzalloc(sizeof(struct percpu_data), gfp);
+       void *pdata = kzalloc(nr_cpu_ids * sizeof(void *), gfp);
        void *__pdata = __percpu_disguise(pdata);
 
        if (unlikely(!pdata))
diff --git a/mm/dmapool.c b/mm/dmapool.c
new file mode 100644 (file)
index 0000000..34aaac4
--- /dev/null
@@ -0,0 +1,500 @@
+/*
+ * DMA Pool allocator
+ *
+ * Copyright 2001 David Brownell
+ * Copyright 2007 Intel Corporation
+ *   Author: Matthew Wilcox <willy@linux.intel.com>
+ *
+ * This software may be redistributed and/or modified under the terms of
+ * the GNU General Public License ("GPL") version 2 as published by the
+ * Free Software Foundation.
+ *
+ * This allocator returns small blocks of a given size which are DMA-able by
+ * the given device.  It uses the dma_alloc_coherent page allocator to get
+ * new pages, then splits them up into blocks of the required size.
+ * Many older drivers still have their own code to do this.
+ *
+ * The current design of this allocator is fairly simple.  The pool is
+ * represented by the 'struct dma_pool' which keeps a doubly-linked list of
+ * allocated pages.  Each page in the page_list is split into blocks of at
+ * least 'size' bytes.  Free blocks are tracked in an unsorted singly-linked
+ * list of free blocks within the page.  Used blocks aren't tracked, but we
+ * keep a count of how many are currently allocated from each page.
+ */
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/poison.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/wait.h>
+
+struct dma_pool {              /* the pool */
+       struct list_head page_list;
+       spinlock_t lock;
+       size_t size;
+       struct device *dev;
+       size_t allocation;
+       size_t boundary;
+       char name[32];
+       wait_queue_head_t waitq;
+       struct list_head pools;
+};
+
+struct dma_page {              /* cacheable header for 'allocation' bytes */
+       struct list_head page_list;
+       void *vaddr;
+       dma_addr_t dma;
+       unsigned int in_use;
+       unsigned int offset;
+};
+
+#define        POOL_TIMEOUT_JIFFIES    ((100 /* msec */ * HZ) / 1000)
+
+static DEFINE_MUTEX(pools_lock);
+
+static ssize_t
+show_pools(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       unsigned temp;
+       unsigned size;
+       char *next;
+       struct dma_page *page;
+       struct dma_pool *pool;
+
+       next = buf;
+       size = PAGE_SIZE;
+
+       temp = scnprintf(next, size, "poolinfo - 0.1\n");
+       size -= temp;
+       next += temp;
+
+       mutex_lock(&pools_lock);
+       list_for_each_entry(pool, &dev->dma_pools, pools) {
+               unsigned pages = 0;
+               unsigned blocks = 0;
+
+               list_for_each_entry(page, &pool->page_list, page_list) {
+                       pages++;
+                       blocks += page->in_use;
+               }
+
+               /* per-pool info, no real statistics yet */
+               temp = scnprintf(next, size, "%-16s %4u %4Zu %4Zu %2u\n",
+                                pool->name, blocks,
+                                pages * (pool->allocation / pool->size),
+                                pool->size, pages);
+               size -= temp;
+               next += temp;
+       }
+       mutex_unlock(&pools_lock);
+
+       return PAGE_SIZE - size;
+}
+
+static DEVICE_ATTR(pools, S_IRUGO, show_pools, NULL);
+
+/**
+ * dma_pool_create - Creates a pool of consistent memory blocks, for dma.
+ * @name: name of pool, for diagnostics
+ * @dev: device that will be doing the DMA
+ * @size: size of the blocks in this pool.
+ * @align: alignment requirement for blocks; must be a power of two
+ * @boundary: returned blocks won't cross this power of two boundary
+ * Context: !in_interrupt()
+ *
+ * Returns a dma allocation pool with the requested characteristics, or
+ * null if one can't be created.  Given one of these pools, dma_pool_alloc()
+ * may be used to allocate memory.  Such memory will all have "consistent"
+ * DMA mappings, accessible by the device and its driver without using
+ * cache flushing primitives.  The actual size of blocks allocated may be
+ * larger than requested because of alignment.
+ *
+ * If @boundary is nonzero, objects returned from dma_pool_alloc() won't
+ * cross that size boundary.  This is useful for devices which have
+ * addressing restrictions on individual DMA transfers, such as not crossing
+ * boundaries of 4KBytes.
+ */
+struct dma_pool *dma_pool_create(const char *name, struct device *dev,
+                                size_t size, size_t align, size_t boundary)
+{
+       struct dma_pool *retval;
+       size_t allocation;
+
+       if (align == 0) {
+               align = 1;
+       } else if (align & (align - 1)) {
+               return NULL;
+       }
+
+       if (size == 0) {
+               return NULL;
+       } else if (size < 4) {
+               size = 4;
+       }
+
+       if ((size % align) != 0)
+               size = ALIGN(size, align);
+
+       allocation = max_t(size_t, size, PAGE_SIZE);
+
+       if (!boundary) {
+               boundary = allocation;
+       } else if ((boundary < size) || (boundary & (boundary - 1))) {
+               return NULL;
+       }
+
+       retval = kmalloc_node(sizeof(*retval), GFP_KERNEL, dev_to_node(dev));
+       if (!retval)
+               return retval;
+
+       strlcpy(retval->name, name, sizeof(retval->name));
+
+       retval->dev = dev;
+
+       INIT_LIST_HEAD(&retval->page_list);
+       spin_lock_init(&retval->lock);
+       retval->size = size;
+       retval->boundary = boundary;
+       retval->allocation = allocation;
+       init_waitqueue_head(&retval->waitq);
+
+       if (dev) {
+               int ret;
+
+               mutex_lock(&pools_lock);
+               if (list_empty(&dev->dma_pools))
+                       ret = device_create_file(dev, &dev_attr_pools);
+               else
+                       ret = 0;
+               /* note:  not currently insisting "name" be unique */
+               if (!ret)
+                       list_add(&retval->pools, &dev->dma_pools);
+               else {
+                       kfree(retval);
+                       retval = NULL;
+               }
+               mutex_unlock(&pools_lock);
+       } else
+               INIT_LIST_HEAD(&retval->pools);
+
+       return retval;
+}
+EXPORT_SYMBOL(dma_pool_create);
+
+static void pool_initialise_page(struct dma_pool *pool, struct dma_page *page)
+{
+       unsigned int offset = 0;
+       unsigned int next_boundary = pool->boundary;
+
+       do {
+               unsigned int next = offset + pool->size;
+               if (unlikely((next + pool->size) >= next_boundary)) {
+                       next = next_boundary;
+                       next_boundary += pool->boundary;
+               }
+               *(int *)(page->vaddr + offset) = next;
+               offset = next;
+       } while (offset < pool->allocation);
+}
+
+static struct dma_page *pool_alloc_page(struct dma_pool *pool, gfp_t mem_flags)
+{
+       struct dma_page *page;
+
+       page = kmalloc(sizeof(*page), mem_flags);
+       if (!page)
+               return NULL;
+       page->vaddr = dma_alloc_coherent(pool->dev, pool->allocation,
+                                        &page->dma, mem_flags);
+       if (page->vaddr) {
+#ifdef CONFIG_DEBUG_SLAB
+               memset(page->vaddr, POOL_POISON_FREED, pool->allocation);
+#endif
+               pool_initialise_page(pool, page);
+               list_add(&page->page_list, &pool->page_list);
+               page->in_use = 0;
+               page->offset = 0;
+       } else {
+               kfree(page);
+               page = NULL;
+       }
+       return page;
+}
+
+static inline int is_page_busy(struct dma_page *page)
+{
+       return page->in_use != 0;
+}
+
+static void pool_free_page(struct dma_pool *pool, struct dma_page *page)
+{
+       dma_addr_t dma = page->dma;
+
+#ifdef CONFIG_DEBUG_SLAB
+       memset(page->vaddr, POOL_POISON_FREED, pool->allocation);
+#endif
+       dma_free_coherent(pool->dev, pool->allocation, page->vaddr, dma);
+       list_del(&page->page_list);
+       kfree(page);
+}
+
+/**
+ * dma_pool_destroy - destroys a pool of dma memory blocks.
+ * @pool: dma pool that will be destroyed
+ * Context: !in_interrupt()
+ *
+ * Caller guarantees that no more memory from the pool is in use,
+ * and that nothing will try to use the pool after this call.
+ */
+void dma_pool_destroy(struct dma_pool *pool)
+{
+       mutex_lock(&pools_lock);
+       list_del(&pool->pools);
+       if (pool->dev && list_empty(&pool->dev->dma_pools))
+               device_remove_file(pool->dev, &dev_attr_pools);
+       mutex_unlock(&pools_lock);
+
+       while (!list_empty(&pool->page_list)) {
+               struct dma_page *page;
+               page = list_entry(pool->page_list.next,
+                                 struct dma_page, page_list);
+               if (is_page_busy(page)) {
+                       if (pool->dev)
+                               dev_err(pool->dev,
+                                       "dma_pool_destroy %s, %p busy\n",
+                                       pool->name, page->vaddr);
+                       else
+                               printk(KERN_ERR
+                                      "dma_pool_destroy %s, %p busy\n",
+                                      pool->name, page->vaddr);
+                       /* leak the still-in-use consistent memory */
+                       list_del(&page->page_list);
+                       kfree(page);
+               } else
+                       pool_free_page(pool, page);
+       }
+
+       kfree(pool);
+}
+EXPORT_SYMBOL(dma_pool_destroy);
+
+/**
+ * dma_pool_alloc - get a block of consistent memory
+ * @pool: dma pool that will produce the block
+ * @mem_flags: GFP_* bitmask
+ * @handle: pointer to dma address of block
+ *
+ * This returns the kernel virtual address of a currently unused block,
+ * and reports its dma address through the handle.
+ * If such a memory block can't be allocated, %NULL is returned.
+ */
+void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
+                    dma_addr_t *handle)
+{
+       unsigned long flags;
+       struct dma_page *page;
+       size_t offset;
+       void *retval;
+
+       spin_lock_irqsave(&pool->lock, flags);
+ restart:
+       list_for_each_entry(page, &pool->page_list, page_list) {
+               if (page->offset < pool->allocation)
+                       goto ready;
+       }
+       page = pool_alloc_page(pool, GFP_ATOMIC);
+       if (!page) {
+               if (mem_flags & __GFP_WAIT) {
+                       DECLARE_WAITQUEUE(wait, current);
+
+                       __set_current_state(TASK_INTERRUPTIBLE);
+                       __add_wait_queue(&pool->waitq, &wait);
+                       spin_unlock_irqrestore(&pool->lock, flags);
+
+                       schedule_timeout(POOL_TIMEOUT_JIFFIES);
+
+                       spin_lock_irqsave(&pool->lock, flags);
+                       __remove_wait_queue(&pool->waitq, &wait);
+                       goto restart;
+               }
+               retval = NULL;
+               goto done;
+       }
+
+ ready:
+       page->in_use++;
+       offset = page->offset;
+       page->offset = *(int *)(page->vaddr + offset);
+       retval = offset + page->vaddr;
+       *handle = offset + page->dma;
+#ifdef CONFIG_DEBUG_SLAB
+       memset(retval, POOL_POISON_ALLOCATED, pool->size);
+#endif
+ done:
+       spin_unlock_irqrestore(&pool->lock, flags);
+       return retval;
+}
+EXPORT_SYMBOL(dma_pool_alloc);
+
+static struct dma_page *pool_find_page(struct dma_pool *pool, dma_addr_t dma)
+{
+       unsigned long flags;
+       struct dma_page *page;
+
+       spin_lock_irqsave(&pool->lock, flags);
+       list_for_each_entry(page, &pool->page_list, page_list) {
+               if (dma < page->dma)
+                       continue;
+               if (dma < (page->dma + pool->allocation))
+                       goto done;
+       }
+       page = NULL;
+ done:
+       spin_unlock_irqrestore(&pool->lock, flags);
+       return page;
+}
+
+/**
+ * dma_pool_free - put block back into dma pool
+ * @pool: the dma pool holding the block
+ * @vaddr: virtual address of block
+ * @dma: dma address of block
+ *
+ * Caller promises neither device nor driver will again touch this block
+ * unless it is first re-allocated.
+ */
+void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma)
+{
+       struct dma_page *page;
+       unsigned long flags;
+       unsigned int offset;
+
+       page = pool_find_page(pool, dma);
+       if (!page) {
+               if (pool->dev)
+                       dev_err(pool->dev,
+                               "dma_pool_free %s, %p/%lx (bad dma)\n",
+                               pool->name, vaddr, (unsigned long)dma);
+               else
+                       printk(KERN_ERR "dma_pool_free %s, %p/%lx (bad dma)\n",
+                              pool->name, vaddr, (unsigned long)dma);
+               return;
+       }
+
+       offset = vaddr - page->vaddr;
+#ifdef CONFIG_DEBUG_SLAB
+       if ((dma - page->dma) != offset) {
+               if (pool->dev)
+                       dev_err(pool->dev,
+                               "dma_pool_free %s, %p (bad vaddr)/%Lx\n",
+                               pool->name, vaddr, (unsigned long long)dma);
+               else
+                       printk(KERN_ERR
+                              "dma_pool_free %s, %p (bad vaddr)/%Lx\n",
+                              pool->name, vaddr, (unsigned long long)dma);
+               return;
+       }
+       {
+               unsigned int chain = page->offset;
+               while (chain < pool->allocation) {
+                       if (chain != offset) {
+                               chain = *(int *)(page->vaddr + chain);
+                               continue;
+                       }
+                       if (pool->dev)
+                               dev_err(pool->dev, "dma_pool_free %s, dma %Lx "
+                                       "already free\n", pool->name,
+                                       (unsigned long long)dma);
+                       else
+                               printk(KERN_ERR "dma_pool_free %s, dma %Lx "
+                                       "already free\n", pool->name,
+                                       (unsigned long long)dma);
+                       return;
+               }
+       }
+       memset(vaddr, POOL_POISON_FREED, pool->size);
+#endif
+
+       spin_lock_irqsave(&pool->lock, flags);
+       page->in_use--;
+       *(int *)vaddr = page->offset;
+       page->offset = offset;
+       if (waitqueue_active(&pool->waitq))
+               wake_up_locked(&pool->waitq);
+       /*
+        * Resist a temptation to do
+        *    if (!is_page_busy(page)) pool_free_page(pool, page);
+        * Better have a few empty pages hang around.
+        */
+       spin_unlock_irqrestore(&pool->lock, flags);
+}
+EXPORT_SYMBOL(dma_pool_free);
+
+/*
+ * Managed DMA pool
+ */
+static void dmam_pool_release(struct device *dev, void *res)
+{
+       struct dma_pool *pool = *(struct dma_pool **)res;
+
+       dma_pool_destroy(pool);
+}
+
+static int dmam_pool_match(struct device *dev, void *res, void *match_data)
+{
+       return *(struct dma_pool **)res == match_data;
+}
+
+/**
+ * dmam_pool_create - Managed dma_pool_create()
+ * @name: name of pool, for diagnostics
+ * @dev: device that will be doing the DMA
+ * @size: size of the blocks in this pool.
+ * @align: alignment requirement for blocks; must be a power of two
+ * @allocation: returned blocks won't cross this boundary (or zero)
+ *
+ * Managed dma_pool_create().  DMA pool created with this function is
+ * automatically destroyed on driver detach.
+ */
+struct dma_pool *dmam_pool_create(const char *name, struct device *dev,
+                                 size_t size, size_t align, size_t allocation)
+{
+       struct dma_pool **ptr, *pool;
+
+       ptr = devres_alloc(dmam_pool_release, sizeof(*ptr), GFP_KERNEL);
+       if (!ptr)
+               return NULL;
+
+       pool = *ptr = dma_pool_create(name, dev, size, align, allocation);
+       if (pool)
+               devres_add(dev, ptr);
+       else
+               devres_free(ptr);
+
+       return pool;
+}
+EXPORT_SYMBOL(dmam_pool_create);
+
+/**
+ * dmam_pool_destroy - Managed dma_pool_destroy()
+ * @pool: dma pool that will be destroyed
+ *
+ * Managed dma_pool_destroy().
+ */
+void dmam_pool_destroy(struct dma_pool *pool)
+{
+       struct device *dev = pool->dev;
+
+       dma_pool_destroy(pool);
+       WARN_ON(devres_destroy(dev, dmam_pool_release, dmam_pool_match, pool));
+}
+EXPORT_SYMBOL(dmam_pool_destroy);
index 0df4c899e979ec1101cb629a660fc04b31e1095e..3c0f1e99f5e40ad90a116f62a39ca1e0ca3f5fa7 100644 (file)
@@ -49,9 +49,21 @@ asmlinkage long sys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)
                goto out;
        }
 
-       if (mapping->a_ops->get_xip_page)
-               /* no bad return value, but ignore advice */
+       if (mapping->a_ops->get_xip_page) {
+               switch (advice) {
+               case POSIX_FADV_NORMAL:
+               case POSIX_FADV_RANDOM:
+               case POSIX_FADV_SEQUENTIAL:
+               case POSIX_FADV_WILLNEED:
+               case POSIX_FADV_NOREUSE:
+               case POSIX_FADV_DONTNEED:
+                       /* no bad return value, but ignore advice */
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
                goto out;
+       }
 
        /* Careful about overflows. Len == 0 means "as much as possible" */
        endbyte = offset + len;
index 89ce6fe5f8be152e71218085af5396dcb72d315c..81fb9bff0d4f9022db02f9d3194ebc5ccd0c350e 100644 (file)
@@ -65,7 +65,6 @@ generic_file_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
  *    ->private_lock           (__free_pte->__set_page_dirty_buffers)
  *      ->swap_lock            (exclusive_swap_page, others)
  *        ->mapping->tree_lock
- *          ->zone.lock
  *
  *  ->i_mutex
  *    ->i_mmap_lock            (truncate->unmap_mapping_range)
@@ -528,7 +527,7 @@ static inline void wake_up_page(struct page *page, int bit)
        __wake_up_bit(page_waitqueue(page), &page->flags, bit);
 }
 
-void fastcall wait_on_page_bit(struct page *page, int bit_nr)
+void wait_on_page_bit(struct page *page, int bit_nr)
 {
        DEFINE_WAIT_BIT(wait, &page->flags, bit_nr);
 
@@ -552,7 +551,7 @@ EXPORT_SYMBOL(wait_on_page_bit);
  * the clear_bit and the read of the waitqueue (to avoid SMP races with a
  * parallel wait_on_page_locked()).
  */
-void fastcall unlock_page(struct page *page)
+void unlock_page(struct page *page)
 {
        smp_mb__before_clear_bit();
        if (!TestClearPageLocked(page))
@@ -586,7 +585,7 @@ EXPORT_SYMBOL(end_page_writeback);
  * chances are that on the second loop, the block layer's plug list is empty,
  * so sync_page() will then return in state TASK_UNINTERRUPTIBLE.
  */
-void fastcall __lock_page(struct page *page)
+void __lock_page(struct page *page)
 {
        DEFINE_WAIT_BIT(wait, &page->flags, PG_locked);
 
@@ -607,7 +606,7 @@ int fastcall __lock_page_killable(struct page *page)
  * Variant of lock_page that does not require the caller to hold a reference
  * on the page's mapping.
  */
-void fastcall __lock_page_nosync(struct page *page)
+void __lock_page_nosync(struct page *page)
 {
        DEFINE_WAIT_BIT(wait, &page->flags, PG_locked);
        __wait_on_bit_lock(page_waitqueue(page), &wait, __sleep_on_page_lock,
@@ -1277,7 +1276,7 @@ asmlinkage ssize_t sys_readahead(int fd, loff_t offset, size_t count)
  * This adds the requested page to the page cache if it isn't already there,
  * and schedules an I/O to read in its contents from disk.
  */
-static int fastcall page_cache_read(struct file * file, pgoff_t offset)
+static int page_cache_read(struct file *file, pgoff_t offset)
 {
        struct address_space *mapping = file->f_mapping;
        struct page *page; 
@@ -1750,7 +1749,11 @@ static void __iov_iter_advance_iov(struct iov_iter *i, size_t bytes)
                const struct iovec *iov = i->iov;
                size_t base = i->iov_offset;
 
-               while (bytes) {
+               /*
+                * The !iov->iov_len check ensures we skip over unlikely
+                * zero-length segments.
+                */
+               while (bytes || !iov->iov_len) {
                        int copy = min(bytes, iov->iov_len - base);
 
                        bytes -= copy;
@@ -2268,6 +2271,7 @@ again:
 
                cond_resched();
 
+               iov_iter_advance(i, copied);
                if (unlikely(copied == 0)) {
                        /*
                         * If we were unable to copy any data at all, we must
@@ -2281,7 +2285,6 @@ again:
                                                iov_iter_single_seg_count(i));
                        goto again;
                }
-               iov_iter_advance(i, copied);
                pos += copied;
                written += copied;
 
index f874ae818ad3812f7cd051972c823c743a154d33..0420a0292b0306425306b8db141b55b59f1010be 100644 (file)
@@ -431,7 +431,7 @@ xip_truncate_page(struct address_space *mapping, loff_t from)
                else
                        return PTR_ERR(page);
        }
-       zero_user_page(page, offset, length, KM_USER0);
+       zero_user(page, offset, length);
        return 0;
 }
 EXPORT_SYMBOL_GPL(xip_truncate_page);
index 14bd3bf7826edcecd2f61e6465b61078a84b2340..69a37c2bdf815ce5d7d14f90cca4c1185b65dff7 100644 (file)
@@ -190,10 +190,13 @@ asmlinkage long sys_remap_file_pages(unsigned long start, unsigned long size,
                 */
                if (mapping_cap_account_dirty(mapping)) {
                        unsigned long addr;
+                       struct file *file = vma->vm_file;
 
                        flags &= MAP_NONBLOCK;
-                       addr = mmap_region(vma->vm_file, start, size,
+                       get_file(file);
+                       addr = mmap_region(file, start, size,
                                        flags, vma->vm_flags, pgoff, 1);
+                       fput(file);
                        if (IS_ERR_VALUE(addr)) {
                                err = addr;
                        } else {
index 7a967bc351526d8f745fb2f3a9655a5151ed783f..35d47733cde43af70c61a996c78ef54ca5e20e02 100644 (file)
@@ -163,7 +163,7 @@ start:
        return vaddr;
 }
 
-void fastcall *kmap_high(struct page *page)
+void *kmap_high(struct page *page)
 {
        unsigned long vaddr;
 
@@ -185,7 +185,7 @@ void fastcall *kmap_high(struct page *page)
 
 EXPORT_SYMBOL(kmap_high);
 
-void fastcall kunmap_high(struct page *page)
+void kunmap_high(struct page *page)
 {
        unsigned long vaddr;
        unsigned long nr;
index db861d8b6c2824f460cc177f0d4008fd8850cc3e..1a5642074e342532f4a844ed0d2fdc86bd9b5de9 100644 (file)
@@ -813,6 +813,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
 
        spin_unlock(&mm->page_table_lock);
        copy_huge_page(new_page, old_page, address, vma);
+       __SetPageUptodate(new_page);
        spin_lock(&mm->page_table_lock);
 
        ptep = huge_pte_offset(mm, address & HPAGE_MASK);
@@ -858,6 +859,7 @@ retry:
                        goto out;
                }
                clear_huge_page(page, address);
+               __SetPageUptodate(page);
 
                if (vma->vm_flags & VM_SHARED) {
                        int err;
index 953f941ea8676a6f1768257428e8f917e75d7a2c..5a9a6200e034fb43aad09efe34ac1b2e49825509 100644 (file)
@@ -24,7 +24,7 @@ static inline void set_page_count(struct page *page, int v)
  */
 static inline void set_page_refcounted(struct page *page)
 {
-       VM_BUG_ON(PageCompound(page) && PageTail(page));
+       VM_BUG_ON(PageTail(page));
        VM_BUG_ON(atomic_read(&page->_count));
        set_page_count(page, 1);
 }
@@ -34,7 +34,7 @@ static inline void __put_page(struct page *page)
        atomic_dec(&page->_count);
 }
 
-extern void fastcall __init __free_pages_bootmem(struct page *page,
+extern void __init __free_pages_bootmem(struct page *page,
                                                unsigned int order);
 
 /*
index d902d0e25edc564862605d2c8c93209602e797cc..9d073fa0a2d02631f53ba3117e80b32efc2b9ae9 100644 (file)
@@ -82,7 +82,18 @@ void * high_memory;
 EXPORT_SYMBOL(num_physpages);
 EXPORT_SYMBOL(high_memory);
 
-int randomize_va_space __read_mostly = 1;
+/*
+ * Randomize the address space (stacks, mmaps, brk, etc.).
+ *
+ * ( When CONFIG_COMPAT_BRK=y we exclude brk from randomization,
+ *   as ancient (libc5 based) binaries can segfault. )
+ */
+int randomize_va_space __read_mostly =
+#ifdef CONFIG_COMPAT_BRK
+                                       1;
+#else
+                                       2;
+#endif
 
 static int __init disable_randmaps(char *s)
 {
@@ -305,7 +316,7 @@ int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
        spin_lock(&mm->page_table_lock);
        if (pmd_present(*pmd)) {        /* Another has populated it */
                pte_lock_deinit(new);
-               pte_free(new);
+               pte_free(mm, new);
        } else {
                mm->nr_ptes++;
                inc_zone_page_state(new, NR_PAGETABLE);
@@ -323,7 +334,7 @@ int __pte_alloc_kernel(pmd_t *pmd, unsigned long address)
 
        spin_lock(&init_mm.page_table_lock);
        if (pmd_present(*pmd))          /* Another has populated it */
-               pte_free_kernel(new);
+               pte_free_kernel(&init_mm, new);
        else
                pmd_populate_kernel(&init_mm, pmd, new);
        spin_unlock(&init_mm.page_table_lock);
@@ -1109,7 +1120,8 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 }
 EXPORT_SYMBOL(get_user_pages);
 
-pte_t * fastcall get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl)
+pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr,
+                       spinlock_t **ptl)
 {
        pgd_t * pgd = pgd_offset(mm, addr);
        pud_t * pud = pud_alloc(mm, pgd, addr);
@@ -1517,10 +1529,8 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
                        memset(kaddr, 0, PAGE_SIZE);
                kunmap_atomic(kaddr, KM_USER0);
                flush_dcache_page(dst);
-               return;
-
-       }
-       copy_user_highpage(dst, src, va, vma);
+       } else
+               copy_user_highpage(dst, src, va, vma);
 }
 
 /*
@@ -1629,6 +1639,7 @@ gotten:
        if (!new_page)
                goto oom;
        cow_user_page(new_page, old_page, address, vma);
+       __SetPageUptodate(new_page);
 
        /*
         * Re-check the pte - we dropped the lock
@@ -1909,50 +1920,49 @@ EXPORT_SYMBOL(unmap_mapping_range);
  */
 int vmtruncate(struct inode * inode, loff_t offset)
 {
-       struct address_space *mapping = inode->i_mapping;
-       unsigned long limit;
+       if (inode->i_size < offset) {
+               unsigned long limit;
 
-       if (inode->i_size < offset)
-               goto do_expand;
-       /*
-        * truncation of in-use swapfiles is disallowed - it would cause
-        * subsequent swapout to scribble on the now-freed blocks.
-        */
-       if (IS_SWAPFILE(inode))
-               goto out_busy;
-       i_size_write(inode, offset);
+               limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
+               if (limit != RLIM_INFINITY && offset > limit)
+                       goto out_sig;
+               if (offset > inode->i_sb->s_maxbytes)
+                       goto out_big;
+               i_size_write(inode, offset);
+       } else {
+               struct address_space *mapping = inode->i_mapping;
+
+               /*
+                * truncation of in-use swapfiles is disallowed - it would
+                * cause subsequent swapout to scribble on the now-freed
+                * blocks.
+                */
+               if (IS_SWAPFILE(inode))
+                       return -ETXTBSY;
+               i_size_write(inode, offset);
+
+               /*
+                * unmap_mapping_range is called twice, first simply for
+                * efficiency so that truncate_inode_pages does fewer
+                * single-page unmaps.  However after this first call, and
+                * before truncate_inode_pages finishes, it is possible for
+                * private pages to be COWed, which remain after
+                * truncate_inode_pages finishes, hence the second
+                * unmap_mapping_range call must be made for correctness.
+                */
+               unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
+               truncate_inode_pages(mapping, offset);
+               unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
+       }
 
-       /*
-        * unmap_mapping_range is called twice, first simply for efficiency
-        * so that truncate_inode_pages does fewer single-page unmaps. However
-        * after this first call, and before truncate_inode_pages finishes,
-        * it is possible for private pages to be COWed, which remain after
-        * truncate_inode_pages finishes, hence the second unmap_mapping_range
-        * call must be made for correctness.
-        */
-       unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
-       truncate_inode_pages(mapping, offset);
-       unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
-       goto out_truncate;
-
-do_expand:
-       limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
-       if (limit != RLIM_INFINITY && offset > limit)
-               goto out_sig;
-       if (offset > inode->i_sb->s_maxbytes)
-               goto out_big;
-       i_size_write(inode, offset);
-
-out_truncate:
        if (inode->i_op && inode->i_op->truncate)
                inode->i_op->truncate(inode);
        return 0;
+
 out_sig:
        send_sig(SIGXFSZ, current, 0);
 out_big:
        return -EFBIG;
-out_busy:
-       return -ETXTBSY;
 }
 EXPORT_SYMBOL(vmtruncate);
 
@@ -1980,67 +1990,6 @@ int vmtruncate_range(struct inode *inode, loff_t offset, loff_t end)
        return 0;
 }
 
-/**
- * swapin_readahead - swap in pages in hope we need them soon
- * @entry: swap entry of this memory
- * @addr: address to start
- * @vma: user vma this addresses belong to
- *
- * Primitive swap readahead code. We simply read an aligned block of
- * (1 << page_cluster) entries in the swap area. This method is chosen
- * because it doesn't cost us any seek time.  We also make sure to queue
- * the 'original' request together with the readahead ones...
- *
- * This has been extended to use the NUMA policies from the mm triggering
- * the readahead.
- *
- * Caller must hold down_read on the vma->vm_mm if vma is not NULL.
- */
-void swapin_readahead(swp_entry_t entry, unsigned long addr,struct vm_area_struct *vma)
-{
-#ifdef CONFIG_NUMA
-       struct vm_area_struct *next_vma = vma ? vma->vm_next : NULL;
-#endif
-       int i, num;
-       struct page *new_page;
-       unsigned long offset;
-
-       /*
-        * Get the number of handles we should do readahead io to.
-        */
-       num = valid_swaphandles(entry, &offset);
-       for (i = 0; i < num; offset++, i++) {
-               /* Ok, do the async read-ahead now */
-               new_page = read_swap_cache_async(swp_entry(swp_type(entry),
-                                                          offset), vma, addr);
-               if (!new_page)
-                       break;
-               page_cache_release(new_page);
-#ifdef CONFIG_NUMA
-               /*
-                * Find the next applicable VMA for the NUMA policy.
-                */
-               addr += PAGE_SIZE;
-               if (addr == 0)
-                       vma = NULL;
-               if (vma) {
-                       if (addr >= vma->vm_end) {
-                               vma = next_vma;
-                               next_vma = vma ? vma->vm_next : NULL;
-                       }
-                       if (vma && addr < vma->vm_start)
-                               vma = NULL;
-               } else {
-                       if (next_vma && addr >= next_vma->vm_start) {
-                               vma = next_vma;
-                               next_vma = vma->vm_next;
-                       }
-               }
-#endif
-       }
-       lru_add_drain();        /* Push any new pages onto the LRU now */
-}
-
 /*
  * We enter with non-exclusive mmap_sem (to exclude vma changes,
  * but allow concurrent faults), and pte mapped but not yet locked.
@@ -2068,8 +2017,8 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
        page = lookup_swap_cache(entry);
        if (!page) {
                grab_swap_token(); /* Contend for token _before_ read-in */
-               swapin_readahead(entry, address, vma);
-               page = read_swap_cache_async(entry, vma, address);
+               page = swapin_readahead(entry,
+                                       GFP_HIGHUSER_MOVABLE, vma, address);
                if (!page) {
                        /*
                         * Back out if somebody else faulted in this pte
@@ -2163,6 +2112,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
        page = alloc_zeroed_user_highpage_movable(vma, address);
        if (!page)
                goto oom;
+       __SetPageUptodate(page);
 
        entry = mk_pte(page, vma->vm_page_prot);
        entry = maybe_mkwrite(pte_mkdirty(entry), vma);
@@ -2263,6 +2213,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
                                goto out;
                        }
                        copy_user_highpage(page, vmf.page, address, vma);
+                       __SetPageUptodate(page);
                } else {
                        /*
                         * If the page will be shareable, see if the backing
@@ -2563,7 +2514,7 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
 
        spin_lock(&mm->page_table_lock);
        if (pgd_present(*pgd))          /* Another has populated it */
-               pud_free(new);
+               pud_free(mm, new);
        else
                pgd_populate(mm, pgd, new);
        spin_unlock(&mm->page_table_lock);
@@ -2585,12 +2536,12 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
        spin_lock(&mm->page_table_lock);
 #ifndef __ARCH_HAS_4LEVEL_HACK
        if (pud_present(*pud))          /* Another has populated it */
-               pmd_free(new);
+               pmd_free(mm, new);
        else
                pud_populate(mm, pud, new);
 #else
        if (pgd_present(*pud))          /* Another has populated it */
-               pmd_free(new);
+               pmd_free(mm, new);
        else
                pgd_populate(mm, pud, new);
 #endif /* __ARCH_HAS_4LEVEL_HACK */
@@ -2618,46 +2569,6 @@ int make_pages_present(unsigned long addr, unsigned long end)
        return ret == len ? 0 : -1;
 }
 
-/* 
- * Map a vmalloc()-space virtual address to the physical page.
- */
-struct page * vmalloc_to_page(void * vmalloc_addr)
-{
-       unsigned long addr = (unsigned long) vmalloc_addr;
-       struct page *page = NULL;
-       pgd_t *pgd = pgd_offset_k(addr);
-       pud_t *pud;
-       pmd_t *pmd;
-       pte_t *ptep, pte;
-  
-       if (!pgd_none(*pgd)) {
-               pud = pud_offset(pgd, addr);
-               if (!pud_none(*pud)) {
-                       pmd = pmd_offset(pud, addr);
-                       if (!pmd_none(*pmd)) {
-                               ptep = pte_offset_map(pmd, addr);
-                               pte = *ptep;
-                               if (pte_present(pte))
-                                       page = pte_page(pte);
-                               pte_unmap(ptep);
-                       }
-               }
-       }
-       return page;
-}
-
-EXPORT_SYMBOL(vmalloc_to_page);
-
-/*
- * Map a vmalloc()-space virtual address to the physical page frame number.
- */
-unsigned long vmalloc_to_pfn(void * vmalloc_addr)
-{
-       return page_to_pfn(vmalloc_to_page(vmalloc_addr));
-}
-
-EXPORT_SYMBOL(vmalloc_to_pfn);
-
 #if !defined(__HAVE_ARCH_GATE_AREA)
 
 #if defined(AT_SYSINFO_EHDR)
index 9512a544d0449ebcb789de665d9e8fc8ee0fdc8b..7469c503580dcf6402000cc339359175a9b417fc 100644 (file)
@@ -481,8 +481,6 @@ check_pages_isolated(unsigned long start_pfn, unsigned long end_pfn)
        return offlined;
 }
 
-extern void drain_all_local_pages(void);
-
 int offline_pages(unsigned long start_pfn,
                  unsigned long end_pfn, unsigned long timeout)
 {
@@ -540,7 +538,7 @@ repeat:
                lru_add_drain_all();
                flush_scheduled_work();
                cond_resched();
-               drain_all_local_pages();
+               drain_all_pages();
        }
 
        pfn = scan_lru_pages(start_pfn, end_pfn);
@@ -563,7 +561,7 @@ repeat:
        flush_scheduled_work();
        yield();
        /* drain pcp pages , this is synchrouns. */
-       drain_all_local_pages();
+       drain_all_pages();
        /* check again */
        offlined_pages = check_pages_isolated(start_pfn, end_pfn);
        if (offlined_pages < 0) {
index 6a207e8d17ea3f74f0e20511fc726fe80ac47fb1..857a987e36904a5850a4d663c6d9e41e494ffe1f 100644 (file)
@@ -115,11 +115,6 @@ int putback_lru_pages(struct list_head *l)
        return count;
 }
 
-static inline int is_swap_pte(pte_t pte)
-{
-       return !pte_none(pte) && !pte_present(pte) && !pte_file(pte);
-}
-
 /*
  * Restore a potential migration pte to a working pte entry
  */
@@ -645,15 +640,33 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
                rcu_read_lock();
                rcu_locked = 1;
        }
+
        /*
-        * This is a corner case handling.
-        * When a new swap-cache is read into, it is linked to LRU
-        * and treated as swapcache but has no rmap yet.
-        * Calling try_to_unmap() against a page->mapping==NULL page is
-        * BUG. So handle it here.
+        * Corner case handling:
+        * 1. When a new swap-cache page is read into, it is added to the LRU
+        * and treated as swapcache but it has no rmap yet.
+        * Calling try_to_unmap() against a page->mapping==NULL page will
+        * trigger a BUG.  So handle it here.
+        * 2. An orphaned page (see truncate_complete_page) might have
+        * fs-private metadata. The page can be picked up due to memory
+        * offlining.  Everywhere else except page reclaim, the page is
+        * invisible to the vm, so the page can not be migrated.  So try to
+        * free the metadata, so the page can be freed.
         */
-       if (!page->mapping)
+       if (!page->mapping) {
+               if (!PageAnon(page) && PagePrivate(page)) {
+                       /*
+                        * Go direct to try_to_free_buffers() here because
+                        * a) that's what try_to_release_page() would do anyway
+                        * b) we may be under rcu_read_lock() here, so we can't
+                        *    use GFP_KERNEL which is what try_to_release_page()
+                        *    needs to be effective.
+                        */
+                       try_to_free_buffers(page);
+               }
                goto rcu_unlock;
+       }
+
        /* Establish migration ptes or remove ptes */
        try_to_unmap(page, 1);
 
index d2b6d44962b7c7b28b89e20cdbf1af0b0c6ada31..ad6e4eaf34f81ae27a684935ed7ff76960f17761 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
 #define arch_mmap_check(addr, len, flags)      (0)
 #endif
 
+#ifndef arch_rebalance_pgtables
+#define arch_rebalance_pgtables(addr, len)             (addr)
+#endif
+
 static void unmap_region(struct mm_struct *mm,
                struct vm_area_struct *vma, struct vm_area_struct *prev,
                unsigned long start, unsigned long end);
@@ -241,7 +245,7 @@ asmlinkage unsigned long sys_brk(unsigned long brk)
 
        down_write(&mm->mmap_sem);
 
-       if (brk < mm->end_code)
+       if (brk < mm->start_brk)
                goto out;
 
        /*
@@ -1424,7 +1428,7 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
        if (addr & ~PAGE_MASK)
                return -EINVAL;
 
-       return addr;
+       return arch_rebalance_pgtables(addr, len);
 }
 
 EXPORT_SYMBOL(get_unmapped_area);
@@ -2216,7 +2220,7 @@ int install_special_mapping(struct mm_struct *mm,
        vma->vm_start = addr;
        vma->vm_end = addr + len;
 
-       vma->vm_flags = vm_flags | mm->def_flags;
+       vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
        vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
 
        vma->vm_ops = &special_mapping_vmops;
index b989cb928a7cf29ec5ad66ff519f80633bfe8129..5d8ae086f74e541a6e526288e072e87b665484ab 100644 (file)
@@ -10,6 +10,7 @@
  *  Copyright (c) 2000-2003 David McCullough <davidm@snapgear.com>
  *  Copyright (c) 2000-2001 D Jeff Dionne <jeff@uClinux.org>
  *  Copyright (c) 2002      Greg Ungerer <gerg@snapgear.com>
+ *  Copyright (c) 2007      Paul Mundt <lethal@linux-sh.org>
  */
 
 #include <linux/module.h>
@@ -167,7 +168,7 @@ EXPORT_SYMBOL(get_user_pages);
 DEFINE_RWLOCK(vmlist_lock);
 struct vm_struct *vmlist;
 
-void vfree(void *addr)
+void vfree(const void *addr)
 {
        kfree(addr);
 }
@@ -183,13 +184,33 @@ void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
 }
 EXPORT_SYMBOL(__vmalloc);
 
-struct page * vmalloc_to_page(void *addr)
+void *vmalloc_user(unsigned long size)
+{
+       void *ret;
+
+       ret = __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+                       PAGE_KERNEL);
+       if (ret) {
+               struct vm_area_struct *vma;
+
+               down_write(&current->mm->mmap_sem);
+               vma = find_vma(current->mm, (unsigned long)ret);
+               if (vma)
+                       vma->vm_flags |= VM_USERMAP;
+               up_write(&current->mm->mmap_sem);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(vmalloc_user);
+
+struct page *vmalloc_to_page(const void *addr)
 {
        return virt_to_page(addr);
 }
 EXPORT_SYMBOL(vmalloc_to_page);
 
-unsigned long vmalloc_to_pfn(void *addr)
+unsigned long vmalloc_to_pfn(const void *addr)
 {
        return page_to_pfn(virt_to_page(addr));
 }
@@ -253,10 +274,17 @@ EXPORT_SYMBOL(vmalloc_32);
  *
  * The resulting memory area is 32bit addressable and zeroed so it can be
  * mapped to userspace without leaking data.
+ *
+ * VM_USERMAP is set on the corresponding VMA so that subsequent calls to
+ * remap_vmalloc_range() are permissible.
  */
 void *vmalloc_32_user(unsigned long size)
 {
-       return __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
+       /*
+        * We'll have to sort out the ZONE_DMA bits for 64-bit,
+        * but for now this can simply use vmalloc_user() directly.
+        */
+       return vmalloc_user(size);
 }
 EXPORT_SYMBOL(vmalloc_32_user);
 
@@ -267,7 +295,7 @@ void *vmap(struct page **pages, unsigned int count, unsigned long flags, pgprot_
 }
 EXPORT_SYMBOL(vmap);
 
-void vunmap(void *addr)
+void vunmap(const void *addr)
 {
        BUG();
 }
@@ -1216,6 +1244,21 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
 }
 EXPORT_SYMBOL(remap_pfn_range);
 
+int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
+                       unsigned long pgoff)
+{
+       unsigned int size = vma->vm_end - vma->vm_start;
+
+       if (!(vma->vm_flags & VM_USERMAP))
+               return -EINVAL;
+
+       vma->vm_start = (unsigned long)(addr + (pgoff << PAGE_SHIFT));
+       vma->vm_end = vma->vm_start + size;
+
+       return 0;
+}
+EXPORT_SYMBOL(remap_vmalloc_range);
+
 void swap_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
 {
 }
index 96473b482099793384af969b8158e1306e2d4f58..c1850bf991cda9794f6985a7f6ebf595c6adac87 100644 (file)
@@ -125,8 +125,7 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
         * Superuser processes are usually more important, so we make it
         * less likely that we kill those.
         */
-       if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_ADMIN) ||
-                               p->uid == 0 || p->euid == 0)
+       if (__capable(p, CAP_SYS_ADMIN) || __capable(p, CAP_SYS_RESOURCE))
                points /= 4;
 
        /*
@@ -135,7 +134,7 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
         * tend to only have this flag set on applications they think
         * of as important.
         */
-       if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO))
+       if (__capable(p, CAP_SYS_RAWIO))
                points /= 4;
 
        /*
index 3d3848fa6324ee30c8bfa4f39ac867808af84627..5e00f1772c20fc6d9e4e70a087800e93b3ae3df2 100644 (file)
@@ -68,6 +68,12 @@ static inline long sync_writeback_pages(void)
  */
 int dirty_background_ratio = 5;
 
+/*
+ * free highmem will not be subtracted from the total free memory
+ * for calculating free ratios if vm_highmem_is_dirtyable is true
+ */
+int vm_highmem_is_dirtyable;
+
 /*
  * The generator of dirty data starts writeback at this percentage
  */
@@ -219,7 +225,7 @@ static inline void task_dirties_fraction(struct task_struct *tsk,
  *
  *   dirty -= (dirty/8) * p_{t}
  */
-void task_dirty_limit(struct task_struct *tsk, long *pdirty)
+static void task_dirty_limit(struct task_struct *tsk, long *pdirty)
 {
        long numerator, denominator;
        long dirty = *pdirty;
@@ -287,7 +293,10 @@ static unsigned long determine_dirtyable_memory(void)
        x = global_page_state(NR_FREE_PAGES)
                + global_page_state(NR_INACTIVE)
                + global_page_state(NR_ACTIVE);
-       x -= highmem_dirtyable_memory(x);
+
+       if (!vm_highmem_is_dirtyable)
+               x -= highmem_dirtyable_memory(x);
+
        return x + 1;   /* Ensure that we never return 0 */
 }
 
@@ -558,6 +567,7 @@ static void background_writeout(unsigned long _min_pages)
                        global_page_state(NR_UNSTABLE_NFS) < background_thresh
                                && min_pages <= 0)
                        break;
+               wbc.more_io = 0;
                wbc.encountered_congestion = 0;
                wbc.nr_to_write = MAX_WRITEBACK_PAGES;
                wbc.pages_skipped = 0;
@@ -565,8 +575,9 @@ static void background_writeout(unsigned long _min_pages)
                min_pages -= MAX_WRITEBACK_PAGES - wbc.nr_to_write;
                if (wbc.nr_to_write > 0 || wbc.pages_skipped > 0) {
                        /* Wrote less than expected */
-                       congestion_wait(WRITE, HZ/10);
-                       if (!wbc.encountered_congestion)
+                       if (wbc.encountered_congestion || wbc.more_io)
+                               congestion_wait(WRITE, HZ/10);
+                       else
                                break;
                }
        }
@@ -631,11 +642,12 @@ static void wb_kupdate(unsigned long arg)
                        global_page_state(NR_UNSTABLE_NFS) +
                        (inodes_stat.nr_inodes - inodes_stat.nr_unused);
        while (nr_to_write > 0) {
+               wbc.more_io = 0;
                wbc.encountered_congestion = 0;
                wbc.nr_to_write = MAX_WRITEBACK_PAGES;
                writeback_inodes(&wbc);
                if (wbc.nr_to_write > 0) {
-                       if (wbc.encountered_congestion)
+                       if (wbc.encountered_congestion || wbc.more_io)
                                congestion_wait(WRITE, HZ/10);
                        else
                                break;  /* All the old data is written */
@@ -1064,7 +1076,7 @@ static int __set_page_dirty(struct page *page)
        return 0;
 }
 
-int fastcall set_page_dirty(struct page *page)
+int set_page_dirty(struct page *page)
 {
        int ret = __set_page_dirty(page);
        if (ret)
index b2838c24e582c11b8e0680ca5d5b5f97389145ba..37576b822f06c98c2d3342af1cdecbe0e5a8f25b 100644 (file)
@@ -537,7 +537,7 @@ static void __free_pages_ok(struct page *page, unsigned int order)
 /*
  * permit the bootmem allocator to evade page validation on high-order frees
  */
-void fastcall __init __free_pages_bootmem(struct page *page, unsigned int order)
+void __init __free_pages_bootmem(struct page *page, unsigned int order)
 {
        if (order == 0) {
                __ClearPageReserved(page);
@@ -890,31 +890,51 @@ void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
 }
 #endif
 
-static void __drain_pages(unsigned int cpu)
+/*
+ * Drain pages of the indicated processor.
+ *
+ * The processor must either be the current processor and the
+ * thread pinned to the current processor or a processor that
+ * is not online.
+ */
+static void drain_pages(unsigned int cpu)
 {
        unsigned long flags;
        struct zone *zone;
-       int i;
 
        for_each_zone(zone) {
                struct per_cpu_pageset *pset;
+               struct per_cpu_pages *pcp;
 
                if (!populated_zone(zone))
                        continue;
 
                pset = zone_pcp(zone, cpu);
-               for (i = 0; i < ARRAY_SIZE(pset->pcp); i++) {
-                       struct per_cpu_pages *pcp;
-
-                       pcp = &pset->pcp[i];
-                       local_irq_save(flags);
-                       free_pages_bulk(zone, pcp->count, &pcp->list, 0);
-                       pcp->count = 0;
-                       local_irq_restore(flags);
-               }
+
+               pcp = &pset->pcp;
+               local_irq_save(flags);
+               free_pages_bulk(zone, pcp->count, &pcp->list, 0);
+               pcp->count = 0;
+               local_irq_restore(flags);
        }
 }
 
+/*
+ * Spill all of this CPU's per-cpu pages back into the buddy allocator.
+ */
+void drain_local_pages(void *arg)
+{
+       drain_pages(smp_processor_id());
+}
+
+/*
+ * Spill all the per-cpu pages from all CPUs back into the buddy allocator
+ */
+void drain_all_pages(void)
+{
+       on_each_cpu(drain_local_pages, NULL, 0, 1);
+}
+
 #ifdef CONFIG_HIBERNATION
 
 void mark_free_pages(struct zone *zone)
@@ -951,41 +971,10 @@ void mark_free_pages(struct zone *zone)
 }
 #endif /* CONFIG_PM */
 
-/*
- * Spill all of this CPU's per-cpu pages back into the buddy allocator.
- */
-void drain_local_pages(void)
-{
-       unsigned long flags;
-
-       local_irq_save(flags);  
-       __drain_pages(smp_processor_id());
-       local_irq_restore(flags);       
-}
-
-void smp_drain_local_pages(void *arg)
-{
-       drain_local_pages();
-}
-
-/*
- * Spill all the per-cpu pages from all CPUs back into the buddy allocator
- */
-void drain_all_local_pages(void)
-{
-       unsigned long flags;
-
-       local_irq_save(flags);
-       __drain_pages(smp_processor_id());
-       local_irq_restore(flags);
-
-       smp_call_function(smp_drain_local_pages, NULL, 0, 1);
-}
-
 /*
  * Free a 0-order page
  */
-static void fastcall free_hot_cold_page(struct page *page, int cold)
+static void free_hot_cold_page(struct page *page, int cold)
 {
        struct zone *zone = page_zone(page);
        struct per_cpu_pages *pcp;
@@ -1001,10 +990,13 @@ static void fastcall free_hot_cold_page(struct page *page, int cold)
        arch_free_page(page, 0);
        kernel_map_pages(page, 1, 0);
 
-       pcp = &zone_pcp(zone, get_cpu())->pcp[cold];
+       pcp = &zone_pcp(zone, get_cpu())->pcp;
        local_irq_save(flags);
        __count_vm_event(PGFREE);
-       list_add(&page->lru, &pcp->list);
+       if (cold)
+               list_add_tail(&page->lru, &pcp->list);
+       else
+               list_add(&page->lru, &pcp->list);
        set_page_private(page, get_pageblock_migratetype(page));
        pcp->count++;
        if (pcp->count >= pcp->high) {
@@ -1015,12 +1007,12 @@ static void fastcall free_hot_cold_page(struct page *page, int cold)
        put_cpu();
 }
 
-void fastcall free_hot_page(struct page *page)
+void free_hot_page(struct page *page)
 {
        free_hot_cold_page(page, 0);
 }
        
-void fastcall free_cold_page(struct page *page)
+void free_cold_page(struct page *page)
 {
        free_hot_cold_page(page, 1);
 }
@@ -1062,7 +1054,7 @@ again:
        if (likely(order == 0)) {
                struct per_cpu_pages *pcp;
 
-               pcp = &zone_pcp(zone, cpu)->pcp[cold];
+               pcp = &zone_pcp(zone, cpu)->pcp;
                local_irq_save(flags);
                if (!pcp->count) {
                        pcp->count = rmqueue_bulk(zone, 0,
@@ -1072,9 +1064,15 @@ again:
                }
 
                /* Find a page of the appropriate migrate type */
-               list_for_each_entry(page, &pcp->list, lru)
-                       if (page_private(page) == migratetype)
-                               break;
+               if (cold) {
+                       list_for_each_entry_reverse(page, &pcp->list, lru)
+                               if (page_private(page) == migratetype)
+                                       break;
+               } else {
+                       list_for_each_entry(page, &pcp->list, lru)
+                               if (page_private(page) == migratetype)
+                                       break;
+               }
 
                /* Allocate more to the pcp list if necessary */
                if (unlikely(&page->lru == &pcp->list)) {
@@ -1569,7 +1567,7 @@ nofail_alloc:
        cond_resched();
 
        if (order != 0)
-               drain_all_local_pages();
+               drain_all_pages();
 
        if (likely(did_some_progress)) {
                page = get_page_from_freelist(gfp_mask, order,
@@ -1643,7 +1641,7 @@ EXPORT_SYMBOL(__alloc_pages);
 /*
  * Common helper functions.
  */
-fastcall unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)
+unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)
 {
        struct page * page;
        page = alloc_pages(gfp_mask, order);
@@ -1654,7 +1652,7 @@ fastcall unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)
 
 EXPORT_SYMBOL(__get_free_pages);
 
-fastcall unsigned long get_zeroed_page(gfp_t gfp_mask)
+unsigned long get_zeroed_page(gfp_t gfp_mask)
 {
        struct page * page;
 
@@ -1680,7 +1678,7 @@ void __pagevec_free(struct pagevec *pvec)
                free_hot_cold_page(pvec->pages[i], pvec->cold);
 }
 
-fastcall void __free_pages(struct page *page, unsigned int order)
+void __free_pages(struct page *page, unsigned int order)
 {
        if (put_page_testzero(page)) {
                if (order == 0)
@@ -1692,7 +1690,7 @@ fastcall void __free_pages(struct page *page, unsigned int order)
 
 EXPORT_SYMBOL(__free_pages);
 
-fastcall void free_pages(unsigned long addr, unsigned int order)
+void free_pages(unsigned long addr, unsigned int order)
 {
        if (addr != 0) {
                VM_BUG_ON(!virt_addr_valid((void *)addr));
@@ -1801,12 +1799,9 @@ void show_free_areas(void)
 
                        pageset = zone_pcp(zone, cpu);
 
-                       printk("CPU %4d: Hot: hi:%5d, btch:%4d usd:%4d   "
-                              "Cold: hi:%5d, btch:%4d usd:%4d\n",
-                              cpu, pageset->pcp[0].high,
-                              pageset->pcp[0].batch, pageset->pcp[0].count,
-                              pageset->pcp[1].high, pageset->pcp[1].batch,
-                              pageset->pcp[1].count);
+                       printk("CPU %4d: hi:%5d, btch:%4d usd:%4d\n",
+                              cpu, pageset->pcp.high,
+                              pageset->pcp.batch, pageset->pcp.count);
                }
        }
 
@@ -1879,6 +1874,8 @@ void show_free_areas(void)
                printk("= %lukB\n", K(total));
        }
 
+       printk("%ld total pagecache pages\n", global_page_state(NR_FILE_PAGES));
+
        show_swap_cache_info();
 }
 
@@ -2551,8 +2548,7 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
        }
 }
 
-static void __meminit zone_init_free_lists(struct pglist_data *pgdat,
-                               struct zone *zone, unsigned long size)
+static void __meminit zone_init_free_lists(struct zone *zone)
 {
        int order, t;
        for_each_migratetype_order(order, t) {
@@ -2604,17 +2600,11 @@ inline void setup_pageset(struct per_cpu_pageset *p, unsigned long batch)
 
        memset(p, 0, sizeof(*p));
 
-       pcp = &p->pcp[0];               /* hot */
+       pcp = &p->pcp;
        pcp->count = 0;
        pcp->high = 6 * batch;
        pcp->batch = max(1UL, 1 * batch);
        INIT_LIST_HEAD(&pcp->list);
-
-       pcp = &p->pcp[1];               /* cold*/
-       pcp->count = 0;
-       pcp->high = 2 * batch;
-       pcp->batch = max(1UL, batch/2);
-       INIT_LIST_HEAD(&pcp->list);
 }
 
 /*
@@ -2627,7 +2617,7 @@ static void setup_pagelist_highmark(struct per_cpu_pageset *p,
 {
        struct per_cpu_pages *pcp;
 
-       pcp = &p->pcp[0]; /* hot list */
+       pcp = &p->pcp;
        pcp->high = high;
        pcp->batch = max(1UL, high/4);
        if ((high/4) > (PAGE_SHIFT * 8))
@@ -2831,7 +2821,7 @@ __meminit int init_currently_empty_zone(struct zone *zone,
 
        memmap_init(size, pgdat->node_id, zone_idx(zone), zone_start_pfn);
 
-       zone_init_free_lists(pgdat, zone, zone->spanned_pages);
+       zone_init_free_lists(zone);
 
        return 0;
 }
@@ -3978,10 +3968,23 @@ static int page_alloc_cpu_notify(struct notifier_block *self,
        int cpu = (unsigned long)hcpu;
 
        if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) {
-               local_irq_disable();
-               __drain_pages(cpu);
+               drain_pages(cpu);
+
+               /*
+                * Spill the event counters of the dead processor
+                * into the current processors event counters.
+                * This artificially elevates the count of the current
+                * processor.
+                */
                vm_events_fold_cpu(cpu);
-               local_irq_enable();
+
+               /*
+                * Zero the differential counters of the dead processor
+                * so that the vm statistics are consistent.
+                *
+                * This is only okay since the processor is dead and cannot
+                * race with what we are doing.
+                */
                refresh_cpu_vm_stats(cpu);
        }
        return NOTIFY_OK;
@@ -4480,7 +4483,7 @@ int set_migratetype_isolate(struct page *page)
 out:
        spin_unlock_irqrestore(&zone->lock, flags);
        if (!ret)
-               drain_all_local_pages();
+               drain_all_pages();
        return ret;
 }
 
index 3b97f68502733edba06e5697d56ecfeb7643b8c1..065c4480eaf0905c8631732540a118c002989f09 100644 (file)
@@ -126,7 +126,7 @@ int swap_readpage(struct file *file, struct page *page)
        int ret = 0;
 
        BUG_ON(!PageLocked(page));
-       ClearPageUptodate(page);
+       BUG_ON(PageUptodate(page));
        bio = get_swap_bio(GFP_KERNEL, page_private(page), page,
                                end_swap_bio_read);
        if (bio == NULL) {
diff --git a/mm/pagewalk.c b/mm/pagewalk.c
new file mode 100644 (file)
index 0000000..b4f27d2
--- /dev/null
@@ -0,0 +1,131 @@
+#include <linux/mm.h>
+#include <linux/highmem.h>
+#include <linux/sched.h>
+
+static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
+                         const struct mm_walk *walk, void *private)
+{
+       pte_t *pte;
+       int err = 0;
+
+       pte = pte_offset_map(pmd, addr);
+       do {
+               err = walk->pte_entry(pte, addr, addr + PAGE_SIZE, private);
+               if (err)
+                      break;
+       } while (pte++, addr += PAGE_SIZE, addr != end);
+
+       pte_unmap(pte);
+       return err;
+}
+
+static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
+                         const struct mm_walk *walk, void *private)
+{
+       pmd_t *pmd;
+       unsigned long next;
+       int err = 0;
+
+       pmd = pmd_offset(pud, addr);
+       do {
+               next = pmd_addr_end(addr, end);
+               if (pmd_none_or_clear_bad(pmd)) {
+                       if (walk->pte_hole)
+                               err = walk->pte_hole(addr, next, private);
+                       if (err)
+                               break;
+                       continue;
+               }
+               if (walk->pmd_entry)
+                       err = walk->pmd_entry(pmd, addr, next, private);
+               if (!err && walk->pte_entry)
+                       err = walk_pte_range(pmd, addr, next, walk, private);
+               if (err)
+                       break;
+       } while (pmd++, addr = next, addr != end);
+
+       return err;
+}
+
+static int walk_pud_range(pgd_t *pgd, unsigned long addr, unsigned long end,
+                         const struct mm_walk *walk, void *private)
+{
+       pud_t *pud;
+       unsigned long next;
+       int err = 0;
+
+       pud = pud_offset(pgd, addr);
+       do {
+               next = pud_addr_end(addr, end);
+               if (pud_none_or_clear_bad(pud)) {
+                       if (walk->pte_hole)
+                               err = walk->pte_hole(addr, next, private);
+                       if (err)
+                               break;
+                       continue;
+               }
+               if (walk->pud_entry)
+                       err = walk->pud_entry(pud, addr, next, private);
+               if (!err && (walk->pmd_entry || walk->pte_entry))
+                       err = walk_pmd_range(pud, addr, next, walk, private);
+               if (err)
+                       break;
+       } while (pud++, addr = next, addr != end);
+
+       return err;
+}
+
+/**
+ * walk_page_range - walk a memory map's page tables with a callback
+ * @mm - memory map to walk
+ * @addr - starting address
+ * @end - ending address
+ * @walk - set of callbacks to invoke for each level of the tree
+ * @private - private data passed to the callback function
+ *
+ * Recursively walk the page table for the memory area in a VMA,
+ * calling supplied callbacks. Callbacks are called in-order (first
+ * PGD, first PUD, first PMD, first PTE, second PTE... second PMD,
+ * etc.). If lower-level callbacks are omitted, walking depth is reduced.
+ *
+ * Each callback receives an entry pointer, the start and end of the
+ * associated range, and a caller-supplied private data pointer.
+ *
+ * No locks are taken, but the bottom level iterator will map PTE
+ * directories from highmem if necessary.
+ *
+ * If any callback returns a non-zero value, the walk is aborted and
+ * the return value is propagated back to the caller. Otherwise 0 is returned.
+ */
+int walk_page_range(const struct mm_struct *mm,
+                   unsigned long addr, unsigned long end,
+                   const struct mm_walk *walk, void *private)
+{
+       pgd_t *pgd;
+       unsigned long next;
+       int err = 0;
+
+       if (addr >= end)
+               return err;
+
+       pgd = pgd_offset(mm, addr);
+       do {
+               next = pgd_addr_end(addr, end);
+               if (pgd_none_or_clear_bad(pgd)) {
+                       if (walk->pte_hole)
+                               err = walk->pte_hole(addr, next, private);
+                       if (err)
+                               break;
+                       continue;
+               }
+               if (walk->pgd_entry)
+                       err = walk->pgd_entry(pgd, addr, next, private);
+               if (!err &&
+                   (walk->pud_entry || walk->pmd_entry || walk->pte_entry))
+                       err = walk_pud_range(pgd, addr, next, walk, private);
+               if (err)
+                       break;
+       } while (pgd++, addr = next, addr != end);
+
+       return err;
+}
index dbc2ca2057a54ff2c4a709de4b6e9a01694241bb..57ad276900c94903a2febd53e1c0d995958a38a9 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -36,7 +36,6 @@
  *                 mapping->tree_lock (widely used, in set_page_dirty,
  *                           in arch-dependent flush_dcache_mmap_lock,
  *                           within inode_lock in __sync_single_inode)
- *                   zone->lock (within radix tree node alloc)
  */
 
 #include <linux/mm.h>
@@ -284,7 +283,10 @@ static int page_referenced_one(struct page *page,
        if (!pte)
                goto out;
 
-       if (ptep_clear_flush_young(vma, address, pte))
+       if (vma->vm_flags & VM_LOCKED) {
+               referenced++;
+               *mapcount = 1;  /* break early from loop */
+       } else if (ptep_clear_flush_young(vma, address, pte))
                referenced++;
 
        /* Pretend the page is referenced if the task has the
index 51b3d6ccddab75ba33b7fded5ffaf75700770ccd..0f246c44a5744ec5aac0930c7896923e96bcb215 100644 (file)
 
 /* Flag allocation requirements to shmem_getpage and shmem_swp_alloc */
 enum sgp_type {
-       SGP_QUICK,      /* don't try more than file page cache lookup */
        SGP_READ,       /* don't exceed i_size, don't allocate page */
        SGP_CACHE,      /* don't exceed i_size, may allocate page */
+       SGP_DIRTY,      /* like SGP_CACHE, but set new page dirty */
        SGP_WRITE,      /* may exceed i_size, may allocate page */
-       SGP_FAULT,      /* same as SGP_CACHE, return with page locked */
 };
 
 static int shmem_getpage(struct inode *inode, unsigned long idx,
@@ -194,7 +193,7 @@ static struct backing_dev_info shmem_backing_dev_info  __read_mostly = {
 };
 
 static LIST_HEAD(shmem_swaplist);
-static DEFINE_SPINLOCK(shmem_swaplist_lock);
+static DEFINE_MUTEX(shmem_swaplist_mutex);
 
 static void shmem_free_blocks(struct inode *inode, long pages)
 {
@@ -207,6 +206,31 @@ static void shmem_free_blocks(struct inode *inode, long pages)
        }
 }
 
+static int shmem_reserve_inode(struct super_block *sb)
+{
+       struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
+       if (sbinfo->max_inodes) {
+               spin_lock(&sbinfo->stat_lock);
+               if (!sbinfo->free_inodes) {
+                       spin_unlock(&sbinfo->stat_lock);
+                       return -ENOSPC;
+               }
+               sbinfo->free_inodes--;
+               spin_unlock(&sbinfo->stat_lock);
+       }
+       return 0;
+}
+
+static void shmem_free_inode(struct super_block *sb)
+{
+       struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
+       if (sbinfo->max_inodes) {
+               spin_lock(&sbinfo->stat_lock);
+               sbinfo->free_inodes++;
+               spin_unlock(&sbinfo->stat_lock);
+       }
+}
+
 /*
  * shmem_recalc_inode - recalculate the size of an inode
  *
@@ -731,6 +755,8 @@ static int shmem_notify_change(struct dentry *dentry, struct iattr *attr)
                                (void) shmem_getpage(inode,
                                        attr->ia_size>>PAGE_CACHE_SHIFT,
                                                &page, SGP_READ, NULL);
+                               if (page)
+                                       unlock_page(page);
                        }
                        /*
                         * Reset SHMEM_PAGEIN flag so that shmem_truncate can
@@ -762,7 +788,6 @@ static int shmem_notify_change(struct dentry *dentry, struct iattr *attr)
 
 static void shmem_delete_inode(struct inode *inode)
 {
-       struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
        struct shmem_inode_info *info = SHMEM_I(inode);
 
        if (inode->i_op->truncate == shmem_truncate) {
@@ -771,17 +796,13 @@ static void shmem_delete_inode(struct inode *inode)
                inode->i_size = 0;
                shmem_truncate(inode);
                if (!list_empty(&info->swaplist)) {
-                       spin_lock(&shmem_swaplist_lock);
+                       mutex_lock(&shmem_swaplist_mutex);
                        list_del_init(&info->swaplist);
-                       spin_unlock(&shmem_swaplist_lock);
+                       mutex_unlock(&shmem_swaplist_mutex);
                }
        }
        BUG_ON(inode->i_blocks);
-       if (sbinfo->max_inodes) {
-               spin_lock(&sbinfo->stat_lock);
-               sbinfo->free_inodes++;
-               spin_unlock(&sbinfo->stat_lock);
-       }
+       shmem_free_inode(inode->i_sb);
        clear_inode(inode);
 }
 
@@ -807,19 +828,22 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s
        struct page *subdir;
        swp_entry_t *ptr;
        int offset;
+       int error;
 
        idx = 0;
        ptr = info->i_direct;
        spin_lock(&info->lock);
+       if (!info->swapped) {
+               list_del_init(&info->swaplist);
+               goto lost2;
+       }
        limit = info->next_index;
        size = limit;
        if (size > SHMEM_NR_DIRECT)
                size = SHMEM_NR_DIRECT;
        offset = shmem_find_swp(entry, ptr, ptr+size);
-       if (offset >= 0) {
-               shmem_swp_balance_unmap();
+       if (offset >= 0)
                goto found;
-       }
        if (!info->i_indirect)
                goto lost2;
 
@@ -829,6 +853,14 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s
        for (idx = SHMEM_NR_DIRECT; idx < limit; idx += ENTRIES_PER_PAGE, dir++) {
                if (unlikely(idx == stage)) {
                        shmem_dir_unmap(dir-1);
+                       if (cond_resched_lock(&info->lock)) {
+                               /* check it has not been truncated */
+                               if (limit > info->next_index) {
+                                       limit = info->next_index;
+                                       if (idx >= limit)
+                                               goto lost2;
+                               }
+                       }
                        dir = shmem_dir_map(info->i_indirect) +
                            ENTRIES_PER_PAGE/2 + idx/ENTRIES_PER_PAGEPAGE;
                        while (!*dir) {
@@ -849,11 +881,11 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s
                        if (size > ENTRIES_PER_PAGE)
                                size = ENTRIES_PER_PAGE;
                        offset = shmem_find_swp(entry, ptr, ptr+size);
+                       shmem_swp_unmap(ptr);
                        if (offset >= 0) {
                                shmem_dir_unmap(dir);
                                goto found;
                        }
-                       shmem_swp_unmap(ptr);
                }
        }
 lost1:
@@ -863,19 +895,63 @@ lost2:
        return 0;
 found:
        idx += offset;
-       inode = &info->vfs_inode;
-       if (move_from_swap_cache(page, idx, inode->i_mapping) == 0) {
-               info->flags |= SHMEM_PAGEIN;
-               shmem_swp_set(info, ptr + offset, 0);
-       }
-       shmem_swp_unmap(ptr);
+       inode = igrab(&info->vfs_inode);
        spin_unlock(&info->lock);
+
        /*
-        * Decrement swap count even when the entry is left behind:
-        * try_to_unuse will skip over mms, then reincrement count.
+        * Move _head_ to start search for next from here.
+        * But be careful: shmem_delete_inode checks list_empty without taking
+        * mutex, and there's an instant in list_move_tail when info->swaplist
+        * would appear empty, if it were the only one on shmem_swaplist.  We
+        * could avoid doing it if inode NULL; or use this minor optimization.
         */
-       swap_free(entry);
-       return 1;
+       if (shmem_swaplist.next != &info->swaplist)
+               list_move_tail(&shmem_swaplist, &info->swaplist);
+       mutex_unlock(&shmem_swaplist_mutex);
+
+       error = 1;
+       if (!inode)
+               goto out;
+       error = radix_tree_preload(GFP_KERNEL);
+       if (error)
+               goto out;
+       error = 1;
+
+       spin_lock(&info->lock);
+       ptr = shmem_swp_entry(info, idx, NULL);
+       if (ptr && ptr->val == entry.val)
+               error = add_to_page_cache(page, inode->i_mapping,
+                                               idx, GFP_NOWAIT);
+       if (error == -EEXIST) {
+               struct page *filepage = find_get_page(inode->i_mapping, idx);
+               error = 1;
+               if (filepage) {
+                       /*
+                        * There might be a more uptodate page coming down
+                        * from a stacked writepage: forget our swappage if so.
+                        */
+                       if (PageUptodate(filepage))
+                               error = 0;
+                       page_cache_release(filepage);
+               }
+       }
+       if (!error) {
+               delete_from_swap_cache(page);
+               set_page_dirty(page);
+               info->flags |= SHMEM_PAGEIN;
+               shmem_swp_set(info, ptr, 0);
+               swap_free(entry);
+               error = 1;      /* not an error, but entry was found */
+       }
+       if (ptr)
+               shmem_swp_unmap(ptr);
+       spin_unlock(&info->lock);
+       radix_tree_preload_end();
+out:
+       unlock_page(page);
+       page_cache_release(page);
+       iput(inode);            /* allows for NULL */
+       return error;
 }
 
 /*
@@ -887,20 +963,16 @@ int shmem_unuse(swp_entry_t entry, struct page *page)
        struct shmem_inode_info *info;
        int found = 0;
 
-       spin_lock(&shmem_swaplist_lock);
+       mutex_lock(&shmem_swaplist_mutex);
        list_for_each_safe(p, next, &shmem_swaplist) {
                info = list_entry(p, struct shmem_inode_info, swaplist);
-               if (!info->swapped)
-                       list_del_init(&info->swaplist);
-               else if (shmem_unuse_inode(info, entry, page)) {
-                       /* move head to start search for next from here */
-                       list_move_tail(&shmem_swaplist, &info->swaplist);
-                       found = 1;
-                       break;
-               }
+               found = shmem_unuse_inode(info, entry, page);
+               cond_resched();
+               if (found)
+                       goto out;
        }
-       spin_unlock(&shmem_swaplist_lock);
-       return found;
+       mutex_unlock(&shmem_swaplist_mutex);
+out:   return found;   /* 0 or 1 or -ENOMEM */
 }
 
 /*
@@ -915,54 +987,65 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
        struct inode *inode;
 
        BUG_ON(!PageLocked(page));
-       /*
-        * shmem_backing_dev_info's capabilities prevent regular writeback or
-        * sync from ever calling shmem_writepage; but a stacking filesystem
-        * may use the ->writepage of its underlying filesystem, in which case
-        * we want to do nothing when that underlying filesystem is tmpfs
-        * (writing out to swap is useful as a response to memory pressure, but
-        * of no use to stabilize the data) - just redirty the page, unlock it
-        * and claim success in this case.  AOP_WRITEPAGE_ACTIVATE, and the
-        * page_mapped check below, must be avoided unless we're in reclaim.
-        */
-       if (!wbc->for_reclaim) {
-               set_page_dirty(page);
-               unlock_page(page);
-               return 0;
-       }
-       BUG_ON(page_mapped(page));
-
        mapping = page->mapping;
        index = page->index;
        inode = mapping->host;
        info = SHMEM_I(inode);
        if (info->flags & VM_LOCKED)
                goto redirty;
-       swap = get_swap_page();
-       if (!swap.val)
+       if (!total_swap_pages)
                goto redirty;
 
+       /*
+        * shmem_backing_dev_info's capabilities prevent regular writeback or
+        * sync from ever calling shmem_writepage; but a stacking filesystem
+        * may use the ->writepage of its underlying filesystem, in which case
+        * tmpfs should write out to swap only in response to memory pressure,
+        * and not for pdflush or sync.  However, in those cases, we do still
+        * want to check if there's a redundant swappage to be discarded.
+        */
+       if (wbc->for_reclaim)
+               swap = get_swap_page();
+       else
+               swap.val = 0;
+
        spin_lock(&info->lock);
-       shmem_recalc_inode(inode);
        if (index >= info->next_index) {
                BUG_ON(!(info->flags & SHMEM_TRUNCATE));
                goto unlock;
        }
        entry = shmem_swp_entry(info, index, NULL);
-       BUG_ON(!entry);
-       BUG_ON(entry->val);
+       if (entry->val) {
+               /*
+                * The more uptodate page coming down from a stacked
+                * writepage should replace our old swappage.
+                */
+               free_swap_and_cache(*entry);
+               shmem_swp_set(info, entry, 0);
+       }
+       shmem_recalc_inode(inode);
 
-       if (move_to_swap_cache(page, swap) == 0) {
+       if (swap.val && add_to_swap_cache(page, swap, GFP_ATOMIC) == 0) {
+               remove_from_page_cache(page);
                shmem_swp_set(info, entry, swap.val);
                shmem_swp_unmap(entry);
+               if (list_empty(&info->swaplist))
+                       inode = igrab(inode);
+               else
+                       inode = NULL;
                spin_unlock(&info->lock);
-               if (list_empty(&info->swaplist)) {
-                       spin_lock(&shmem_swaplist_lock);
+               swap_duplicate(swap);
+               BUG_ON(page_mapped(page));
+               page_cache_release(page);       /* pagecache ref */
+               set_page_dirty(page);
+               unlock_page(page);
+               if (inode) {
+                       mutex_lock(&shmem_swaplist_mutex);
                        /* move instead of add in case we're racing */
                        list_move_tail(&info->swaplist, &shmem_swaplist);
-                       spin_unlock(&shmem_swaplist_lock);
+                       mutex_unlock(&shmem_swaplist_mutex);
+                       iput(inode);
                }
-               unlock_page(page);
                return 0;
        }
 
@@ -972,7 +1055,10 @@ unlock:
        swap_free(swap);
 redirty:
        set_page_dirty(page);
-       return AOP_WRITEPAGE_ACTIVATE;  /* Return with the page locked */
+       if (wbc->for_reclaim)
+               return AOP_WRITEPAGE_ACTIVATE;  /* Return with page locked */
+       unlock_page(page);
+       return 0;
 }
 
 #ifdef CONFIG_NUMA
@@ -1025,53 +1111,33 @@ out:
        return err;
 }
 
-static struct page *shmem_swapin_async(struct shared_policy *p,
-                                      swp_entry_t entry, unsigned long idx)
+static struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
+                       struct shmem_inode_info *info, unsigned long idx)
 {
-       struct page *page;
        struct vm_area_struct pvma;
+       struct page *page;
 
        /* Create a pseudo vma that just contains the policy */
-       memset(&pvma, 0, sizeof(struct vm_area_struct));
-       pvma.vm_end = PAGE_SIZE;
+       pvma.vm_start = 0;
        pvma.vm_pgoff = idx;
-       pvma.vm_policy = mpol_shared_policy_lookup(p, idx);
-       page = read_swap_cache_async(entry, &pvma, 0);
+       pvma.vm_ops = NULL;
+       pvma.vm_policy = mpol_shared_policy_lookup(&info->policy, idx);
+       page = swapin_readahead(entry, gfp, &pvma, 0);
        mpol_free(pvma.vm_policy);
        return page;
 }
 
-static struct page *shmem_swapin(struct shmem_inode_info *info,
-                                swp_entry_t entry, unsigned long idx)
-{
-       struct shared_policy *p = &info->policy;
-       int i, num;
-       struct page *page;
-       unsigned long offset;
-
-       num = valid_swaphandles(entry, &offset);
-       for (i = 0; i < num; offset++, i++) {
-               page = shmem_swapin_async(p,
-                               swp_entry(swp_type(entry), offset), idx);
-               if (!page)
-                       break;
-               page_cache_release(page);
-       }
-       lru_add_drain();        /* Push any new pages onto the LRU now */
-       return shmem_swapin_async(p, entry, idx);
-}
-
-static struct page *
-shmem_alloc_page(gfp_t gfp, struct shmem_inode_info *info,
-                unsigned long idx)
+static struct page *shmem_alloc_page(gfp_t gfp,
+                       struct shmem_inode_info *info, unsigned long idx)
 {
        struct vm_area_struct pvma;
        struct page *page;
 
-       memset(&pvma, 0, sizeof(struct vm_area_struct));
-       pvma.vm_policy = mpol_shared_policy_lookup(&info->policy, idx);
+       /* Create a pseudo vma that just contains the policy */
+       pvma.vm_start = 0;
        pvma.vm_pgoff = idx;
-       pvma.vm_end = PAGE_SIZE;
+       pvma.vm_ops = NULL;
+       pvma.vm_policy = mpol_shared_policy_lookup(&info->policy, idx);
        page = alloc_page_vma(gfp, &pvma, 0);
        mpol_free(pvma.vm_policy);
        return page;
@@ -1083,15 +1149,14 @@ static inline int shmem_parse_mpol(char *value, int *policy,
        return 1;
 }
 
-static inline struct page *
-shmem_swapin(struct shmem_inode_info *info,swp_entry_t entry,unsigned long idx)
+static inline struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
+                       struct shmem_inode_info *info, unsigned long idx)
 {
-       swapin_readahead(entry, 0, NULL);
-       return read_swap_cache_async(entry, NULL, 0);
+       return swapin_readahead(entry, gfp, NULL, 0);
 }
 
-static inline struct page *
-shmem_alloc_page(gfp_t gfp,struct shmem_inode_info *info, unsigned long idx)
+static inline struct page *shmem_alloc_page(gfp_t gfp,
+                       struct shmem_inode_info *info, unsigned long idx)
 {
        return alloc_page(gfp);
 }
@@ -1114,6 +1179,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
        struct page *swappage;
        swp_entry_t *entry;
        swp_entry_t swap;
+       gfp_t gfp;
        int error;
 
        if (idx >= SHMEM_MAX_INDEX)
@@ -1126,7 +1192,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
         * Normally, filepage is NULL on entry, and either found
         * uptodate immediately, or allocated and zeroed, or read
         * in under swappage, which is then assigned to filepage.
-        * But shmem_readpage and shmem_write_begin pass in a locked
+        * But shmem_readpage (required for splice) passes in a locked
         * filepage, which may be found not uptodate by other callers
         * too, and may need to be copied from the swappage read in.
         */
@@ -1136,8 +1202,17 @@ repeat:
        if (filepage && PageUptodate(filepage))
                goto done;
        error = 0;
-       if (sgp == SGP_QUICK)
-               goto failed;
+       gfp = mapping_gfp_mask(mapping);
+       if (!filepage) {
+               /*
+                * Try to preload while we can wait, to not make a habit of
+                * draining atomic reserves; but don't latch on to this cpu.
+                */
+               error = radix_tree_preload(gfp & ~__GFP_HIGHMEM);
+               if (error)
+                       goto failed;
+               radix_tree_preload_end();
+       }
 
        spin_lock(&info->lock);
        shmem_recalc_inode(inode);
@@ -1160,7 +1235,7 @@ repeat:
                                *type |= VM_FAULT_MAJOR;
                        }
                        spin_unlock(&info->lock);
-                       swappage = shmem_swapin(info, swap, idx);
+                       swappage = shmem_swapin(swap, gfp, info, idx);
                        if (!swappage) {
                                spin_lock(&info->lock);
                                entry = shmem_swp_alloc(info, idx, sgp);
@@ -1218,23 +1293,21 @@ repeat:
                        SetPageUptodate(filepage);
                        set_page_dirty(filepage);
                        swap_free(swap);
-               } else if (!(error = move_from_swap_cache(
-                               swappage, idx, mapping))) {
+               } else if (!(error = add_to_page_cache(
+                               swappage, mapping, idx, GFP_NOWAIT))) {
                        info->flags |= SHMEM_PAGEIN;
                        shmem_swp_set(info, entry, 0);
                        shmem_swp_unmap(entry);
+                       delete_from_swap_cache(swappage);
                        spin_unlock(&info->lock);
                        filepage = swappage;
+                       set_page_dirty(filepage);
                        swap_free(swap);
                } else {
                        shmem_swp_unmap(entry);
                        spin_unlock(&info->lock);
                        unlock_page(swappage);
                        page_cache_release(swappage);
-                       if (error == -ENOMEM) {
-                               /* let kswapd refresh zone for GFP_ATOMICs */
-                               congestion_wait(WRITE, HZ/50);
-                       }
                        goto repeat;
                }
        } else if (sgp == SGP_READ && !filepage) {
@@ -1272,9 +1345,7 @@ repeat:
 
                if (!filepage) {
                        spin_unlock(&info->lock);
-                       filepage = shmem_alloc_page(mapping_gfp_mask(mapping),
-                                                   info,
-                                                   idx);
+                       filepage = shmem_alloc_page(gfp, info, idx);
                        if (!filepage) {
                                shmem_unacct_blocks(info->flags, 1);
                                shmem_free_blocks(inode, 1);
@@ -1291,7 +1362,7 @@ repeat:
                                shmem_swp_unmap(entry);
                        }
                        if (error || swap.val || 0 != add_to_page_cache_lru(
-                                       filepage, mapping, idx, GFP_ATOMIC)) {
+                                       filepage, mapping, idx, GFP_NOWAIT)) {
                                spin_unlock(&info->lock);
                                page_cache_release(filepage);
                                shmem_unacct_blocks(info->flags, 1);
@@ -1309,14 +1380,11 @@ repeat:
                clear_highpage(filepage);
                flush_dcache_page(filepage);
                SetPageUptodate(filepage);
+               if (sgp == SGP_DIRTY)
+                       set_page_dirty(filepage);
        }
 done:
-       if (*pagep != filepage) {
-               *pagep = filepage;
-               if (sgp != SGP_FAULT)
-                       unlock_page(filepage);
-
-       }
+       *pagep = filepage;
        return 0;
 
 failed:
@@ -1336,7 +1404,7 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        if (((loff_t)vmf->pgoff << PAGE_CACHE_SHIFT) >= i_size_read(inode))
                return VM_FAULT_SIGBUS;
 
-       error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_FAULT, &ret);
+       error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
        if (error)
                return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
 
@@ -1399,15 +1467,8 @@ shmem_get_inode(struct super_block *sb, int mode, dev_t dev)
        struct shmem_inode_info *info;
        struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
 
-       if (sbinfo->max_inodes) {
-               spin_lock(&sbinfo->stat_lock);
-               if (!sbinfo->free_inodes) {
-                       spin_unlock(&sbinfo->stat_lock);
-                       return NULL;
-               }
-               sbinfo->free_inodes--;
-               spin_unlock(&sbinfo->stat_lock);
-       }
+       if (shmem_reserve_inode(sb))
+               return NULL;
 
        inode = new_inode(sb);
        if (inode) {
@@ -1451,11 +1512,8 @@ shmem_get_inode(struct super_block *sb, int mode, dev_t dev)
                                                NULL);
                        break;
                }
-       } else if (sbinfo->max_inodes) {
-               spin_lock(&sbinfo->stat_lock);
-               sbinfo->free_inodes++;
-               spin_unlock(&sbinfo->stat_lock);
-       }
+       } else
+               shmem_free_inode(sb);
        return inode;
 }
 
@@ -1494,123 +1552,30 @@ shmem_write_end(struct file *file, struct address_space *mapping,
 {
        struct inode *inode = mapping->host;
 
+       if (pos + copied > inode->i_size)
+               i_size_write(inode, pos + copied);
+
+       unlock_page(page);
        set_page_dirty(page);
        page_cache_release(page);
 
-       if (pos+copied > inode->i_size)
-               i_size_write(inode, pos+copied);
-
        return copied;
 }
 
-static ssize_t
-shmem_file_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
-{
-       struct inode    *inode = file->f_path.dentry->d_inode;
-       loff_t          pos;
-       unsigned long   written;
-       ssize_t         err;
-
-       if ((ssize_t) count < 0)
-               return -EINVAL;
-
-       if (!access_ok(VERIFY_READ, buf, count))
-               return -EFAULT;
-
-       mutex_lock(&inode->i_mutex);
-
-       pos = *ppos;
-       written = 0;
-
-       err = generic_write_checks(file, &pos, &count, 0);
-       if (err || !count)
-               goto out;
-
-       err = remove_suid(file->f_path.dentry);
-       if (err)
-               goto out;
-
-       inode->i_ctime = inode->i_mtime = CURRENT_TIME;
-
-       do {
-               struct page *page = NULL;
-               unsigned long bytes, index, offset;
-               char *kaddr;
-               int left;
-
-               offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
-               index = pos >> PAGE_CACHE_SHIFT;
-               bytes = PAGE_CACHE_SIZE - offset;
-               if (bytes > count)
-                       bytes = count;
-
-               /*
-                * We don't hold page lock across copy from user -
-                * what would it guard against? - so no deadlock here.
-                * But it still may be a good idea to prefault below.
-                */
-
-               err = shmem_getpage(inode, index, &page, SGP_WRITE, NULL);
-               if (err)
-                       break;
-
-               left = bytes;
-               if (PageHighMem(page)) {
-                       volatile unsigned char dummy;
-                       __get_user(dummy, buf);
-                       __get_user(dummy, buf + bytes - 1);
-
-                       kaddr = kmap_atomic(page, KM_USER0);
-                       left = __copy_from_user_inatomic(kaddr + offset,
-                                                       buf, bytes);
-                       kunmap_atomic(kaddr, KM_USER0);
-               }
-               if (left) {
-                       kaddr = kmap(page);
-                       left = __copy_from_user(kaddr + offset, buf, bytes);
-                       kunmap(page);
-               }
-
-               written += bytes;
-               count -= bytes;
-               pos += bytes;
-               buf += bytes;
-               if (pos > inode->i_size)
-                       i_size_write(inode, pos);
-
-               flush_dcache_page(page);
-               set_page_dirty(page);
-               mark_page_accessed(page);
-               page_cache_release(page);
-
-               if (left) {
-                       pos -= left;
-                       written -= left;
-                       err = -EFAULT;
-                       break;
-               }
-
-               /*
-                * Our dirty pages are not counted in nr_dirty,
-                * and we do not attempt to balance dirty pages.
-                */
-
-               cond_resched();
-       } while (count);
-
-       *ppos = pos;
-       if (written)
-               err = written;
-out:
-       mutex_unlock(&inode->i_mutex);
-       return err;
-}
-
 static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_actor_t actor)
 {
        struct inode *inode = filp->f_path.dentry->d_inode;
        struct address_space *mapping = inode->i_mapping;
        unsigned long index, offset;
+       enum sgp_type sgp = SGP_READ;
+
+       /*
+        * Might this read be for a stacking filesystem?  Then when reading
+        * holes of a sparse file, we actually need to allocate those pages,
+        * and even mark them dirty, so it cannot exceed the max_blocks limit.
+        */
+       if (segment_eq(get_fs(), KERNEL_DS))
+               sgp = SGP_DIRTY;
 
        index = *ppos >> PAGE_CACHE_SHIFT;
        offset = *ppos & ~PAGE_CACHE_MASK;
@@ -1629,12 +1594,14 @@ static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_
                                break;
                }
 
-               desc->error = shmem_getpage(inode, index, &page, SGP_READ, NULL);
+               desc->error = shmem_getpage(inode, index, &page, sgp, NULL);
                if (desc->error) {
                        if (desc->error == -EINVAL)
                                desc->error = 0;
                        break;
                }
+               if (page)
+                       unlock_page(page);
 
                /*
                 * We must evaluate after, since reads (unlike writes)
@@ -1798,22 +1765,16 @@ static int shmem_create(struct inode *dir, struct dentry *dentry, int mode,
 static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
 {
        struct inode *inode = old_dentry->d_inode;
-       struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
+       int ret;
 
        /*
         * No ordinary (disk based) filesystem counts links as inodes;
         * but each new link needs a new dentry, pinning lowmem, and
         * tmpfs dentries cannot be pruned until they are unlinked.
         */
-       if (sbinfo->max_inodes) {
-               spin_lock(&sbinfo->stat_lock);
-               if (!sbinfo->free_inodes) {
-                       spin_unlock(&sbinfo->stat_lock);
-                       return -ENOSPC;
-               }
-               sbinfo->free_inodes--;
-               spin_unlock(&sbinfo->stat_lock);
-       }
+       ret = shmem_reserve_inode(inode->i_sb);
+       if (ret)
+               goto out;
 
        dir->i_size += BOGO_DIRENT_SIZE;
        inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
@@ -1821,21 +1782,16 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr
        atomic_inc(&inode->i_count);    /* New dentry reference */
        dget(dentry);           /* Extra pinning count for the created dentry */
        d_instantiate(dentry, inode);
-       return 0;
+out:
+       return ret;
 }
 
 static int shmem_unlink(struct inode *dir, struct dentry *dentry)
 {
        struct inode *inode = dentry->d_inode;
 
-       if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode)) {
-               struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
-               if (sbinfo->max_inodes) {
-                       spin_lock(&sbinfo->stat_lock);
-                       sbinfo->free_inodes++;
-                       spin_unlock(&sbinfo->stat_lock);
-               }
-       }
+       if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode))
+               shmem_free_inode(inode->i_sb);
 
        dir->i_size -= BOGO_DIRENT_SIZE;
        inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
@@ -1924,6 +1880,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
                        iput(inode);
                        return error;
                }
+               unlock_page(page);
                inode->i_op = &shmem_symlink_inode_operations;
                kaddr = kmap_atomic(page, KM_USER0);
                memcpy(kaddr, symname, len);
@@ -1951,6 +1908,8 @@ static void *shmem_follow_link(struct dentry *dentry, struct nameidata *nd)
        struct page *page = NULL;
        int res = shmem_getpage(dentry->d_inode, 0, &page, SGP_READ, NULL);
        nd_set_link(nd, res ? ERR_PTR(res) : kmap(page));
+       if (page)
+               unlock_page(page);
        return page;
 }
 
@@ -1996,8 +1955,7 @@ static int shmem_xattr_security_get(struct inode *inode, const char *name,
 {
        if (strcmp(name, "") == 0)
                return -EINVAL;
-       return security_inode_getsecurity(inode, name, buffer, size,
-                                         -EOPNOTSUPP);
+       return xattr_getsecurity(inode, name, buffer, size);
 }
 
 static int shmem_xattr_security_set(struct inode *inode, const char *name,
@@ -2138,7 +2096,7 @@ static int shmem_parse_options(char *options, int *mode, uid_t *uid,
                        }
                        if (*rest)
                                goto bad_val;
-                       *blocks = size >> PAGE_CACHE_SHIFT;
+                       *blocks = DIV_ROUND_UP(size, PAGE_CACHE_SIZE);
                } else if (!strcmp(this_char,"nr_blocks")) {
                        *blocks = memparse(value,&rest);
                        if (*rest)
@@ -2375,7 +2333,8 @@ static const struct file_operations shmem_file_operations = {
 #ifdef CONFIG_TMPFS
        .llseek         = generic_file_llseek,
        .read           = shmem_file_read,
-       .write          = shmem_file_write,
+       .write          = do_sync_write,
+       .aio_write      = generic_file_aio_write,
        .fsync          = simple_sync_file,
        .splice_read    = generic_file_splice_read,
        .splice_write   = generic_file_splice_write,
index 773a7aa80ab5ce53883cd7ad4d07a6019a175fe0..e2c3c0ec546373857ba3c2132edde98cdf5e8bb0 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
  * allocator is as little as 2 bytes, however typically most architectures
  * will require 4 bytes on 32-bit and 8 bytes on 64-bit.
  *
- * The slob heap is a linked list of pages from alloc_pages(), and
- * within each page, there is a singly-linked list of free blocks (slob_t).
- * The heap is grown on demand and allocation from the heap is currently
- * first-fit.
+ * The slob heap is a set of linked list of pages from alloc_pages(),
+ * and within each page, there is a singly-linked list of free blocks
+ * (slob_t). The heap is grown on demand. To reduce fragmentation,
+ * heap pages are segregated into three lists, with objects less than
+ * 256 bytes, objects less than 1024 bytes, and all other objects.
+ *
+ * Allocation from heap involves first searching for a page with
+ * sufficient free blocks (using a next-fit-like approach) followed by
+ * a first-fit scan of the page. Deallocation inserts objects back
+ * into the free list in address order, so this is effectively an
+ * address-ordered first fit.
  *
  * Above this is an implementation of kmalloc/kfree. Blocks returned
  * from kmalloc are prepended with a 4-byte header with the kmalloc size.
@@ -110,9 +117,13 @@ static inline void free_slob_page(struct slob_page *sp)
 }
 
 /*
- * All (partially) free slob pages go on this list.
+ * All partially free slob pages go on these lists.
  */
-static LIST_HEAD(free_slob_pages);
+#define SLOB_BREAK1 256
+#define SLOB_BREAK2 1024
+static LIST_HEAD(free_slob_small);
+static LIST_HEAD(free_slob_medium);
+static LIST_HEAD(free_slob_large);
 
 /*
  * slob_page: True for all slob pages (false for bigblock pages)
@@ -140,9 +151,9 @@ static inline int slob_page_free(struct slob_page *sp)
        return test_bit(PG_private, &sp->flags);
 }
 
-static inline void set_slob_page_free(struct slob_page *sp)
+static void set_slob_page_free(struct slob_page *sp, struct list_head *list)
 {
-       list_add(&sp->list, &free_slob_pages);
+       list_add(&sp->list, list);
        __set_bit(PG_private, &sp->flags);
 }
 
@@ -294,12 +305,20 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
 {
        struct slob_page *sp;
        struct list_head *prev;
+       struct list_head *slob_list;
        slob_t *b = NULL;
        unsigned long flags;
 
+       if (size < SLOB_BREAK1)
+               slob_list = &free_slob_small;
+       else if (size < SLOB_BREAK2)
+               slob_list = &free_slob_medium;
+       else
+               slob_list = &free_slob_large;
+
        spin_lock_irqsave(&slob_lock, flags);
        /* Iterate through each partially free page, try to find room */
-       list_for_each_entry(sp, &free_slob_pages, list) {
+       list_for_each_entry(sp, slob_list, list) {
 #ifdef CONFIG_NUMA
                /*
                 * If there's a node specification, search for a partial
@@ -321,9 +340,9 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
                /* Improve fragment distribution and reduce our average
                 * search time by starting our next search here. (see
                 * Knuth vol 1, sec 2.5, pg 449) */
-               if (prev != free_slob_pages.prev &&
-                               free_slob_pages.next != prev->next)
-                       list_move_tail(&free_slob_pages, prev->next);
+               if (prev != slob_list->prev &&
+                               slob_list->next != prev->next)
+                       list_move_tail(slob_list, prev->next);
                break;
        }
        spin_unlock_irqrestore(&slob_lock, flags);
@@ -341,7 +360,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
                sp->free = b;
                INIT_LIST_HEAD(&sp->list);
                set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
-               set_slob_page_free(sp);
+               set_slob_page_free(sp, slob_list);
                b = slob_page_alloc(sp, size, align);
                BUG_ON(!b);
                spin_unlock_irqrestore(&slob_lock, flags);
@@ -387,7 +406,7 @@ static void slob_free(void *block, int size)
                set_slob(b, units,
                        (void *)((unsigned long)(b +
                                        SLOB_UNITS(PAGE_SIZE)) & PAGE_MASK));
-               set_slob_page_free(sp);
+               set_slob_page_free(sp, &free_slob_small);
                goto out;
        }
 
@@ -398,6 +417,10 @@ static void slob_free(void *block, int size)
        sp->units += units;
 
        if (b < sp->free) {
+               if (b + units == sp->free) {
+                       units += slob_units(sp->free);
+                       sp->free = slob_next(sp->free);
+               }
                set_slob(b, units, sp->free);
                sp->free = b;
        } else {
index 5cc4b7dddb505dc08a9a05bdfeb2cc1f91faf9c2..3f056677fa8fea56ef3a678cc8e9d8a8d27b2371 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -247,7 +247,10 @@ static void sysfs_slab_remove(struct kmem_cache *);
 static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; }
 static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p)
                                                        { return 0; }
-static inline void sysfs_slab_remove(struct kmem_cache *s) {}
+static inline void sysfs_slab_remove(struct kmem_cache *s)
+{
+       kfree(s);
+}
 #endif
 
 /********************************************************************
@@ -354,22 +357,22 @@ static void print_section(char *text, u8 *addr, unsigned int length)
                        printk(KERN_ERR "%8s 0x%p: ", text, addr + i);
                        newline = 0;
                }
-               printk(" %02x", addr[i]);
+               printk(KERN_CONT " %02x", addr[i]);
                offset = i % 16;
                ascii[offset] = isgraph(addr[i]) ? addr[i] : '.';
                if (offset == 15) {
-                       printk(" %s\n",ascii);
+                       printk(KERN_CONT " %s\n", ascii);
                        newline = 1;
                }
        }
        if (!newline) {
                i %= 16;
                while (i < 16) {
-                       printk("   ");
+                       printk(KERN_CONT "   ");
                        ascii[i] = ' ';
                        i++;
                }
-               printk(" %s\n", ascii);
+               printk(KERN_CONT " %s\n", ascii);
        }
 }
 
@@ -529,7 +532,7 @@ static void init_object(struct kmem_cache *s, void *object, int active)
 
        if (s->flags & __OBJECT_POISON) {
                memset(p, POISON_FREE, s->objsize - 1);
-               p[s->objsize -1] = POISON_END;
+               p[s->objsize - 1] = POISON_END;
        }
 
        if (s->flags & SLAB_RED_ZONE)
@@ -558,7 +561,7 @@ static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
 
 static int check_bytes_and_report(struct kmem_cache *s, struct page *page,
                        u8 *object, char *what,
-                       u8start, unsigned int value, unsigned int bytes)
+                       u8 *start, unsigned int value, unsigned int bytes)
 {
        u8 *fault;
        u8 *end;
@@ -692,7 +695,7 @@ static int check_object(struct kmem_cache *s, struct page *page,
                        (!check_bytes_and_report(s, page, p, "Poison", p,
                                        POISON_FREE, s->objsize - 1) ||
                         !check_bytes_and_report(s, page, p, "Poison",
-                               p + s->objsize -1, POISON_END, 1)))
+                               p + s->objsize - 1, POISON_END, 1)))
                        return 0;
                /*
                 * check_pad_bytes cleans up on its own.
@@ -900,8 +903,7 @@ static int free_debug_processing(struct kmem_cache *s, struct page *page,
                                "SLUB <none>: no slab for object 0x%p.\n",
                                                object);
                        dump_stack();
-               }
-               else
+               } else
                        object_err(s, page, object,
                                        "page slab pointer corrupt.");
                goto fail;
@@ -947,7 +949,7 @@ static int __init setup_slub_debug(char *str)
        /*
         * Determine which debug features should be switched on
         */
-       for ( ;*str && *str != ','; str++) {
+       for (*str && *str != ','; str++) {
                switch (tolower(*str)) {
                case 'f':
                        slub_debug |= SLAB_DEBUG_FREE;
@@ -966,7 +968,7 @@ static int __init setup_slub_debug(char *str)
                        break;
                default:
                        printk(KERN_ERR "slub_debug option '%c' "
-                               "unknown. skipped\n",*str);
+                               "unknown. skipped\n", *str);
                }
        }
 
@@ -1039,7 +1041,7 @@ static inline unsigned long kmem_cache_flags(unsigned long objsize,
  */
 static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
-       struct page * page;
+       struct page *page;
        int pages = 1 << s->order;
 
        if (s->order)
@@ -1135,7 +1137,7 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
        mod_zone_page_state(page_zone(page),
                (s->flags & SLAB_RECLAIM_ACCOUNT) ?
                NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
-               - pages);
+               -pages);
 
        __free_pages(page, s->order);
 }
@@ -1195,19 +1197,15 @@ static __always_inline int slab_trylock(struct page *page)
 /*
  * Management of partially allocated slabs
  */
-static void add_partial_tail(struct kmem_cache_node *n, struct page *page)
-{
-       spin_lock(&n->list_lock);
-       n->nr_partial++;
-       list_add_tail(&page->lru, &n->partial);
-       spin_unlock(&n->list_lock);
-}
-
-static void add_partial(struct kmem_cache_node *n, struct page *page)
+static void add_partial(struct kmem_cache_node *n,
+                               struct page *page, int tail)
 {
        spin_lock(&n->list_lock);
        n->nr_partial++;
-       list_add(&page->lru, &n->partial);
+       if (tail)
+               list_add_tail(&page->lru, &n->partial);
+       else
+               list_add(&page->lru, &n->partial);
        spin_unlock(&n->list_lock);
 }
 
@@ -1292,7 +1290,8 @@ static struct page *get_any_partial(struct kmem_cache *s, gfp_t flags)
         * expensive if we do it every time we are trying to find a slab
         * with available objects.
         */
-       if (!s->defrag_ratio || get_cycles() % 1024 > s->defrag_ratio)
+       if (!s->remote_node_defrag_ratio ||
+                       get_cycles() % 1024 > s->remote_node_defrag_ratio)
                return NULL;
 
        zonelist = &NODE_DATA(slab_node(current->mempolicy))
@@ -1335,7 +1334,7 @@ static struct page *get_partial(struct kmem_cache *s, gfp_t flags, int node)
  *
  * On exit the slab lock will have been dropped.
  */
-static void unfreeze_slab(struct kmem_cache *s, struct page *page)
+static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
 {
        struct kmem_cache_node *n = get_node(s, page_to_nid(page));
 
@@ -1343,7 +1342,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page)
        if (page->inuse) {
 
                if (page->freelist)
-                       add_partial(n, page);
+                       add_partial(n, page, tail);
                else if (SlabDebug(page) && (s->flags & SLAB_STORE_USER))
                        add_full(n, page);
                slab_unlock(page);
@@ -1358,7 +1357,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page)
                         * partial list stays small. kmem_cache_shrink can
                         * reclaim empty slabs from the partial list.
                         */
-                       add_partial_tail(n, page);
+                       add_partial(n, page, 1);
                        slab_unlock(page);
                } else {
                        slab_unlock(page);
@@ -1373,6 +1372,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page)
 static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
 {
        struct page *page = c->page;
+       int tail = 1;
        /*
         * Merge cpu freelist into freelist. Typically we get here
         * because both freelists are empty. So this is unlikely
@@ -1381,6 +1381,8 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
        while (unlikely(c->freelist)) {
                void **object;
 
+               tail = 0;       /* Hot objects. Put the slab first */
+
                /* Retrieve object from cpu_freelist */
                object = c->freelist;
                c->freelist = c->freelist[c->offset];
@@ -1391,7 +1393,7 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
                page->inuse--;
        }
        c->page = NULL;
-       unfreeze_slab(s, page);
+       unfreeze_slab(s, page, tail);
 }
 
 static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
@@ -1539,7 +1541,7 @@ debug:
  *
  * Otherwise we can simply pick the next object from the lockless free list.
  */
-static void __always_inline *slab_alloc(struct kmem_cache *s,
+static __always_inline void *slab_alloc(struct kmem_cache *s,
                gfp_t gfpflags, int node, void *addr)
 {
        void **object;
@@ -1613,7 +1615,7 @@ checks_ok:
         * then add it.
         */
        if (unlikely(!prior))
-               add_partial_tail(get_node(s, page_to_nid(page)), page);
+               add_partial(get_node(s, page_to_nid(page)), page, 1);
 
 out_unlock:
        slab_unlock(page);
@@ -1647,7 +1649,7 @@ debug:
  * If fastpath is not possible then fall back to __slab_free where we deal
  * with all sorts of special processing.
  */
-static void __always_inline slab_free(struct kmem_cache *s,
+static __always_inline void slab_free(struct kmem_cache *s,
                        struct page *page, void *x, void *addr)
 {
        void **object = (void *)x;
@@ -1997,6 +1999,7 @@ static struct kmem_cache_node *early_kmem_cache_node_alloc(gfp_t gfpflags,
 {
        struct page *page;
        struct kmem_cache_node *n;
+       unsigned long flags;
 
        BUG_ON(kmalloc_caches->size < sizeof(struct kmem_cache_node));
 
@@ -2021,7 +2024,14 @@ static struct kmem_cache_node *early_kmem_cache_node_alloc(gfp_t gfpflags,
 #endif
        init_kmem_cache_node(n);
        atomic_long_inc(&n->nr_slabs);
-       add_partial(n, page);
+       /*
+        * lockdep requires consistent irq usage for each lock
+        * so even though there cannot be a race this early in
+        * the boot sequence, we still disable irqs.
+        */
+       local_irq_save(flags);
+       add_partial(n, page, 0);
+       local_irq_restore(flags);
        return n;
 }
 
@@ -2206,7 +2216,7 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
 
        s->refcount = 1;
 #ifdef CONFIG_NUMA
-       s->defrag_ratio = 100;
+       s->remote_node_defrag_ratio = 100;
 #endif
        if (!init_kmem_cache_nodes(s, gfpflags & ~SLUB_DMA))
                goto error;
@@ -2228,7 +2238,7 @@ error:
  */
 int kmem_ptr_validate(struct kmem_cache *s, const void *object)
 {
-       struct page * page;
+       struct page *page;
 
        page = get_object_page(object);
 
@@ -2322,7 +2332,6 @@ void kmem_cache_destroy(struct kmem_cache *s)
                if (kmem_cache_close(s))
                        WARN_ON(1);
                sysfs_slab_remove(s);
-               kfree(s);
        } else
                up_write(&slub_lock);
 }
@@ -2341,7 +2350,7 @@ static struct kmem_cache *kmalloc_caches_dma[PAGE_SHIFT];
 
 static int __init setup_slub_min_order(char *str)
 {
-       get_option (&str, &slub_min_order);
+       get_option(&str, &slub_min_order);
 
        return 1;
 }
@@ -2350,7 +2359,7 @@ __setup("slub_min_order=", setup_slub_min_order);
 
 static int __init setup_slub_max_order(char *str)
 {
-       get_option (&str, &slub_max_order);
+       get_option(&str, &slub_max_order);
 
        return 1;
 }
@@ -2359,7 +2368,7 @@ __setup("slub_max_order=", setup_slub_max_order);
 
 static int __init setup_slub_min_objects(char *str)
 {
-       get_option (&str, &slub_min_objects);
+       get_option(&str, &slub_min_objects);
 
        return 1;
 }
@@ -2605,6 +2614,19 @@ void kfree(const void *x)
 }
 EXPORT_SYMBOL(kfree);
 
+static unsigned long count_partial(struct kmem_cache_node *n)
+{
+       unsigned long flags;
+       unsigned long x = 0;
+       struct page *page;
+
+       spin_lock_irqsave(&n->list_lock, flags);
+       list_for_each_entry(page, &n->partial, lru)
+               x += page->inuse;
+       spin_unlock_irqrestore(&n->list_lock, flags);
+       return x;
+}
+
 /*
  * kmem_cache_shrink removes empty slabs from the partial lists and sorts
  * the remaining slabs by the number of items in use. The slabs with the
@@ -2931,7 +2953,7 @@ static struct kmem_cache *find_mergeable(size_t size,
                 * Check if alignment is compatible.
                 * Courtesy of Adrian Drzewiecki
                 */
-               if ((s->size & ~(align -1)) != s->size)
+               if ((s->size & ~(align - 1)) != s->size)
                        continue;
 
                if (s->size - size >= sizeof(void *))
@@ -3040,8 +3062,9 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
        return NOTIFY_OK;
 }
 
-static struct notifier_block __cpuinitdata slab_notifier =
-       { &slab_cpuup_callback, NULL, 0 };
+static struct notifier_block __cpuinitdata slab_notifier = {
+       &slab_cpuup_callback, NULL, 0
+};
 
 #endif
 
@@ -3076,19 +3099,6 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
        return slab_alloc(s, gfpflags, node, caller);
 }
 
-static unsigned long count_partial(struct kmem_cache_node *n)
-{
-       unsigned long flags;
-       unsigned long x = 0;
-       struct page *page;
-
-       spin_lock_irqsave(&n->list_lock, flags);
-       list_for_each_entry(page, &n->partial, lru)
-               x += page->inuse;
-       spin_unlock_irqrestore(&n->list_lock, flags);
-       return x;
-}
-
 #if defined(CONFIG_SYSFS) && defined(CONFIG_SLUB_DEBUG)
 static int validate_slab(struct kmem_cache *s, struct page *page,
                                                unsigned long *map)
@@ -3390,7 +3400,7 @@ static void process_slab(struct loc_track *t, struct kmem_cache *s,
 static int list_locations(struct kmem_cache *s, char *buf,
                                        enum track_item alloc)
 {
-       int n = 0;
+       int len = 0;
        unsigned long i;
        struct loc_track t = { 0, 0, NULL };
        int node;
@@ -3421,54 +3431,54 @@ static int list_locations(struct kmem_cache *s, char *buf,
        for (i = 0; i < t.count; i++) {
                struct location *l = &t.loc[i];
 
-               if (n > PAGE_SIZE - 100)
+               if (len > PAGE_SIZE - 100)
                        break;
-               n += sprintf(buf + n, "%7ld ", l->count);
+               len += sprintf(buf + len, "%7ld ", l->count);
 
                if (l->addr)
-                       n += sprint_symbol(buf + n, (unsigned long)l->addr);
+                       len += sprint_symbol(buf + len, (unsigned long)l->addr);
                else
-                       n += sprintf(buf + n, "<not-available>");
+                       len += sprintf(buf + len, "<not-available>");
 
                if (l->sum_time != l->min_time) {
                        unsigned long remainder;
 
-                       n += sprintf(buf + n, " age=%ld/%ld/%ld",
+                       len += sprintf(buf + len, " age=%ld/%ld/%ld",
                        l->min_time,
                        div_long_long_rem(l->sum_time, l->count, &remainder),
                        l->max_time);
                } else
-                       n += sprintf(buf + n, " age=%ld",
+                       len += sprintf(buf + len, " age=%ld",
                                l->min_time);
 
                if (l->min_pid != l->max_pid)
-                       n += sprintf(buf + n, " pid=%ld-%ld",
+                       len += sprintf(buf + len, " pid=%ld-%ld",
                                l->min_pid, l->max_pid);
                else
-                       n += sprintf(buf + n, " pid=%ld",
+                       len += sprintf(buf + len, " pid=%ld",
                                l->min_pid);
 
                if (num_online_cpus() > 1 && !cpus_empty(l->cpus) &&
-                               n < PAGE_SIZE - 60) {
-                       n += sprintf(buf + n, " cpus=");
-                       n += cpulist_scnprintf(buf + n, PAGE_SIZE - n - 50,
+                               len < PAGE_SIZE - 60) {
+                       len += sprintf(buf + len, " cpus=");
+                       len += cpulist_scnprintf(buf + len, PAGE_SIZE - len - 50,
                                        l->cpus);
                }
 
                if (num_online_nodes() > 1 && !nodes_empty(l->nodes) &&
-                               n < PAGE_SIZE - 60) {
-                       n += sprintf(buf + n, " nodes=");
-                       n += nodelist_scnprintf(buf + n, PAGE_SIZE - n - 50,
+                               len < PAGE_SIZE - 60) {
+                       len += sprintf(buf + len, " nodes=");
+                       len += nodelist_scnprintf(buf + len, PAGE_SIZE - len - 50,
                                        l->nodes);
                }
 
-               n += sprintf(buf + n, "\n");
+               len += sprintf(buf + len, "\n");
        }
 
        free_loc_track(&t);
        if (!t.count)
-               n += sprintf(buf, "No data\n");
-       return n;
+               len += sprintf(buf, "No data\n");
+       return len;
 }
 
 enum slab_stat_type {
@@ -3498,7 +3508,6 @@ static unsigned long slab_objects(struct kmem_cache *s,
 
        for_each_possible_cpu(cpu) {
                struct page *page;
-               int node;
                struct kmem_cache_cpu *c = get_cpu_slab(s, cpu);
 
                if (!c)
@@ -3510,8 +3519,6 @@ static unsigned long slab_objects(struct kmem_cache *s,
                        continue;
                if (page) {
                        if (flags & SO_CPU) {
-                               int x = 0;
-
                                if (flags & SO_OBJECTS)
                                        x = page->inuse;
                                else
@@ -3848,24 +3855,24 @@ static ssize_t free_calls_show(struct kmem_cache *s, char *buf)
 SLAB_ATTR_RO(free_calls);
 
 #ifdef CONFIG_NUMA
-static ssize_t defrag_ratio_show(struct kmem_cache *s, char *buf)
+static ssize_t remote_node_defrag_ratio_show(struct kmem_cache *s, char *buf)
 {
-       return sprintf(buf, "%d\n", s->defrag_ratio / 10);
+       return sprintf(buf, "%d\n", s->remote_node_defrag_ratio / 10);
 }
 
-static ssize_t defrag_ratio_store(struct kmem_cache *s,
+static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s,
                                const char *buf, size_t length)
 {
        int n = simple_strtoul(buf, NULL, 10);
 
        if (n < 100)
-               s->defrag_ratio = n * 10;
+               s->remote_node_defrag_ratio = n * 10;
        return length;
 }
-SLAB_ATTR(defrag_ratio);
+SLAB_ATTR(remote_node_defrag_ratio);
 #endif
 
-static struct attribute * slab_attrs[] = {
+static struct attribute *slab_attrs[] = {
        &slab_size_attr.attr,
        &object_size_attr.attr,
        &objs_per_slab_attr.attr,
@@ -3893,7 +3900,7 @@ static struct attribute * slab_attrs[] = {
        &cache_dma_attr.attr,
 #endif
 #ifdef CONFIG_NUMA
-       &defrag_ratio_attr.attr,
+       &remote_node_defrag_ratio_attr.attr,
 #endif
        NULL
 };
@@ -3940,6 +3947,13 @@ static ssize_t slab_attr_store(struct kobject *kobj,
        return err;
 }
 
+static void kmem_cache_release(struct kobject *kobj)
+{
+       struct kmem_cache *s = to_slab(kobj);
+
+       kfree(s);
+}
+
 static struct sysfs_ops slab_sysfs_ops = {
        .show = slab_attr_show,
        .store = slab_attr_store,
@@ -3947,6 +3961,7 @@ static struct sysfs_ops slab_sysfs_ops = {
 
 static struct kobj_type slab_ktype = {
        .sysfs_ops = &slab_sysfs_ops,
+       .release = kmem_cache_release
 };
 
 static int uevent_filter(struct kset *kset, struct kobject *kobj)
@@ -4048,6 +4063,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
 {
        kobject_uevent(&s->kobj, KOBJ_REMOVE);
        kobject_del(&s->kobj);
+       kobject_put(&s->kobj);
 }
 
 /*
index a2183cb5d5242a0f05695f00b65d5f0f6d25715e..f6a43c09c322cdb39077392ec1c77e9904c52d82 100644 (file)
@@ -237,7 +237,7 @@ static unsigned long *__kmalloc_section_usemap(void)
 }
 #endif /* CONFIG_MEMORY_HOTPLUG */
 
-static unsigned long *sparse_early_usemap_alloc(unsigned long pnum)
+static unsigned long *__init sparse_early_usemap_alloc(unsigned long pnum)
 {
        unsigned long *usemap;
        struct mem_section *ms = __nr_to_section(pnum);
@@ -353,17 +353,9 @@ static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid,
        return __kmalloc_section_memmap(nr_pages);
 }
 
-static int vaddr_in_vmalloc_area(void *addr)
-{
-       if (addr >= (void *)VMALLOC_START &&
-           addr < (void *)VMALLOC_END)
-               return 1;
-       return 0;
-}
-
 static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
 {
-       if (vaddr_in_vmalloc_area(memmap))
+       if (is_vmalloc_addr(memmap))
                vfree(memmap);
        else
                free_pages((unsigned long)memmap,
index 9ac88323d237a82e9a6bf4a91fced71225a4e318..57b7e25a939c41112d20f4f08f22517fcb112580 100644 (file)
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -41,7 +41,7 @@ static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs) = { 0, };
  * This path almost never happens for VM activity - pages are normally
  * freed via pagevecs.  But it gets used by networking.
  */
-static void fastcall __page_cache_release(struct page *page)
+static void __page_cache_release(struct page *page)
 {
        if (PageLRU(page)) {
                unsigned long flags;
@@ -165,7 +165,7 @@ int rotate_reclaimable_page(struct page *page)
 /*
  * FIXME: speed this up?
  */
-void fastcall activate_page(struct page *page)
+void activate_page(struct page *page)
 {
        struct zone *zone = page_zone(page);
 
@@ -186,7 +186,7 @@ void fastcall activate_page(struct page *page)
  * inactive,referenced         ->      active,unreferenced
  * active,unreferenced         ->      active,referenced
  */
-void fastcall mark_page_accessed(struct page *page)
+void mark_page_accessed(struct page *page)
 {
        if (!PageActive(page) && PageReferenced(page) && PageLRU(page)) {
                activate_page(page);
@@ -202,7 +202,7 @@ EXPORT_SYMBOL(mark_page_accessed);
  * lru_cache_add: add a page to the page lists
  * @page: the page to add
  */
-void fastcall lru_cache_add(struct page *page)
+void lru_cache_add(struct page *page)
 {
        struct pagevec *pvec = &get_cpu_var(lru_add_pvecs);
 
@@ -212,7 +212,7 @@ void fastcall lru_cache_add(struct page *page)
        put_cpu_var(lru_add_pvecs);
 }
 
-void fastcall lru_cache_add_active(struct page *page)
+void lru_cache_add_active(struct page *page)
 {
        struct pagevec *pvec = &get_cpu_var(lru_add_active_pvecs);
 
index b52635601dfe0054ea4a4eddbba6317b71e93272..ec42f01a8d02669fb5bd2c73dcffefb5bb619f6c 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/mm.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
+#include <linux/swapops.h>
 #include <linux/init.h>
 #include <linux/pagemap.h>
 #include <linux/buffer_head.h>
@@ -51,26 +52,22 @@ static struct {
        unsigned long del_total;
        unsigned long find_success;
        unsigned long find_total;
-       unsigned long noent_race;
-       unsigned long exist_race;
 } swap_cache_info;
 
 void show_swap_cache_info(void)
 {
-       printk("Swap cache: add %lu, delete %lu, find %lu/%lu, race %lu+%lu\n",
+       printk("Swap cache: add %lu, delete %lu, find %lu/%lu\n",
                swap_cache_info.add_total, swap_cache_info.del_total,
-               swap_cache_info.find_success, swap_cache_info.find_total,
-               swap_cache_info.noent_race, swap_cache_info.exist_race);
+               swap_cache_info.find_success, swap_cache_info.find_total);
        printk("Free swap  = %lukB\n", nr_swap_pages << (PAGE_SHIFT - 10));
        printk("Total swap = %lukB\n", total_swap_pages << (PAGE_SHIFT - 10));
 }
 
 /*
- * __add_to_swap_cache resembles add_to_page_cache on swapper_space,
+ * add_to_swap_cache resembles add_to_page_cache on swapper_space,
  * but sets SwapCache flag and private instead of mapping and index.
  */
-static int __add_to_swap_cache(struct page *page, swp_entry_t entry,
-                              gfp_t gfp_mask)
+int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp_mask)
 {
        int error;
 
@@ -88,6 +85,7 @@ static int __add_to_swap_cache(struct page *page, swp_entry_t entry,
                        set_page_private(page, entry.val);
                        total_swapcache_pages++;
                        __inc_zone_page_state(page, NR_FILE_PAGES);
+                       INC_CACHE_INFO(add_total);
                }
                write_unlock_irq(&swapper_space.tree_lock);
                radix_tree_preload_end();
@@ -95,31 +93,6 @@ static int __add_to_swap_cache(struct page *page, swp_entry_t entry,
        return error;
 }
 
-static int add_to_swap_cache(struct page *page, swp_entry_t entry)
-{
-       int error;
-
-       BUG_ON(PageLocked(page));
-       if (!swap_duplicate(entry)) {
-               INC_CACHE_INFO(noent_race);
-               return -ENOENT;
-       }
-       SetPageLocked(page);
-       error = __add_to_swap_cache(page, entry, GFP_KERNEL);
-       /*
-        * Anon pages are already on the LRU, we don't run lru_cache_add here.
-        */
-       if (error) {
-               ClearPageLocked(page);
-               swap_free(entry);
-               if (error == -EEXIST)
-                       INC_CACHE_INFO(exist_race);
-               return error;
-       }
-       INC_CACHE_INFO(add_total);
-       return 0;
-}
-
 /*
  * This must be called only on pages that have
  * been verified to be in the swap cache.
@@ -152,6 +125,7 @@ int add_to_swap(struct page * page, gfp_t gfp_mask)
        int err;
 
        BUG_ON(!PageLocked(page));
+       BUG_ON(!PageUptodate(page));
 
        for (;;) {
                entry = get_swap_page();
@@ -169,18 +143,15 @@ int add_to_swap(struct page * page, gfp_t gfp_mask)
                /*
                 * Add it to the swap cache and mark it dirty
                 */
-               err = __add_to_swap_cache(page, entry,
+               err = add_to_swap_cache(page, entry,
                                gfp_mask|__GFP_NOMEMALLOC|__GFP_NOWARN);
 
                switch (err) {
                case 0:                         /* Success */
-                       SetPageUptodate(page);
                        SetPageDirty(page);
-                       INC_CACHE_INFO(add_total);
                        return 1;
                case -EEXIST:
                        /* Raced with "speculative" read_swap_cache_async */
-                       INC_CACHE_INFO(exist_race);
                        swap_free(entry);
                        continue;
                default:
@@ -211,40 +182,6 @@ void delete_from_swap_cache(struct page *page)
        page_cache_release(page);
 }
 
-/*
- * Strange swizzling function only for use by shmem_writepage
- */
-int move_to_swap_cache(struct page *page, swp_entry_t entry)
-{
-       int err = __add_to_swap_cache(page, entry, GFP_ATOMIC);
-       if (!err) {
-               remove_from_page_cache(page);
-               page_cache_release(page);       /* pagecache ref */
-               if (!swap_duplicate(entry))
-                       BUG();
-               SetPageDirty(page);
-               INC_CACHE_INFO(add_total);
-       } else if (err == -EEXIST)
-               INC_CACHE_INFO(exist_race);
-       return err;
-}
-
-/*
- * Strange swizzling function for shmem_getpage (and shmem_unuse)
- */
-int move_from_swap_cache(struct page *page, unsigned long index,
-               struct address_space *mapping)
-{
-       int err = add_to_page_cache(page, mapping, index, GFP_ATOMIC);
-       if (!err) {
-               delete_from_swap_cache(page);
-               /* shift page from clean_pages to dirty_pages list */
-               ClearPageDirty(page);
-               set_page_dirty(page);
-       }
-       return err;
-}
-
 /* 
  * If we are the only user, then try to free up the swap cache. 
  * 
@@ -317,7 +254,7 @@ struct page * lookup_swap_cache(swp_entry_t entry)
  * A failure return means that either the page allocation failed or that
  * the swap entry is no longer in use.
  */
-struct page *read_swap_cache_async(swp_entry_t entry,
+struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
                        struct vm_area_struct *vma, unsigned long addr)
 {
        struct page *found_page, *new_page = NULL;
@@ -337,23 +274,27 @@ struct page *read_swap_cache_async(swp_entry_t entry,
                 * Get a new page to read into from swap.
                 */
                if (!new_page) {
-                       new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE,
-                                                               vma, addr);
+                       new_page = alloc_page_vma(gfp_mask, vma, addr);
                        if (!new_page)
                                break;          /* Out of memory */
                }
 
+               /*
+                * Swap entry may have been freed since our caller observed it.
+                */
+               if (!swap_duplicate(entry))
+                       break;
+
                /*
                 * Associate the page with swap entry in the swap cache.
-                * May fail (-ENOENT) if swap entry has been freed since
-                * our caller observed it.  May fail (-EEXIST) if there
-                * is already a page associated with this entry in the
-                * swap cache: added by a racing read_swap_cache_async,
-                * or by try_to_swap_out (or shmem_writepage) re-using
-                * the just freed swap entry for an existing page.
+                * May fail (-EEXIST) if there is already a page associated
+                * with this entry in the swap cache: added by a racing
+                * read_swap_cache_async, or add_to_swap or shmem_writepage
+                * re-using the just freed swap entry for an existing page.
                 * May fail (-ENOMEM) if radix-tree node allocation failed.
                 */
-               err = add_to_swap_cache(new_page, entry);
+               SetPageLocked(new_page);
+               err = add_to_swap_cache(new_page, entry, gfp_mask & GFP_KERNEL);
                if (!err) {
                        /*
                         * Initiate read into locked page and return.
@@ -362,9 +303,57 @@ struct page *read_swap_cache_async(swp_entry_t entry,
                        swap_readpage(NULL, new_page);
                        return new_page;
                }
-       } while (err != -ENOENT && err != -ENOMEM);
+               ClearPageLocked(new_page);
+               swap_free(entry);
+       } while (err != -ENOMEM);
 
        if (new_page)
                page_cache_release(new_page);
        return found_page;
 }
+
+/**
+ * swapin_readahead - swap in pages in hope we need them soon
+ * @entry: swap entry of this memory
+ * @vma: user vma this address belongs to
+ * @addr: target address for mempolicy
+ *
+ * Returns the struct page for entry and addr, after queueing swapin.
+ *
+ * Primitive swap readahead code. We simply read an aligned block of
+ * (1 << page_cluster) entries in the swap area. This method is chosen
+ * because it doesn't cost us any seek time.  We also make sure to queue
+ * the 'original' request together with the readahead ones...
+ *
+ * This has been extended to use the NUMA policies from the mm triggering
+ * the readahead.
+ *
+ * Caller must hold down_read on the vma->vm_mm if vma is not NULL.
+ */
+struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask,
+                       struct vm_area_struct *vma, unsigned long addr)
+{
+       int nr_pages;
+       struct page *page;
+       unsigned long offset;
+       unsigned long end_offset;
+
+       /*
+        * Get starting offset for readaround, and number of pages to read.
+        * Adjust starting address by readbehind (for NUMA interleave case)?
+        * No, it's very unlikely that swap layout would follow vma layout,
+        * more likely that neighbouring swap pages came from the same node:
+        * so use the same "addr" to choose the same node for each swap read.
+        */
+       nr_pages = valid_swaphandles(entry, &offset);
+       for (end_offset = offset + nr_pages; offset < end_offset; offset++) {
+               /* Ok, do the async read-ahead now */
+               page = read_swap_cache_async(swp_entry(swp_type(entry), offset),
+                                               gfp_mask, vma, addr);
+               if (!page)
+                       break;
+               page_cache_release(page);
+       }
+       lru_add_drain();        /* Push any new pages onto the LRU now */
+       return read_swap_cache_async(entry, gfp_mask, vma, addr);
+}
index f071648e1360823d06e83b1951a77f1c53a5f998..eade24da9310d4cc4e7499e5580d52fbb929701c 100644 (file)
@@ -506,9 +506,19 @@ unsigned int count_swap_pages(int type, int free)
  * just let do_wp_page work it out if a write is requested later - to
  * force COW, vm_page_prot omits write permission from any private vma.
  */
-static void unuse_pte(struct vm_area_struct *vma, pte_t *pte,
+static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
                unsigned long addr, swp_entry_t entry, struct page *page)
 {
+       spinlock_t *ptl;
+       pte_t *pte;
+       int found = 1;
+
+       pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
+       if (unlikely(!pte_same(*pte, swp_entry_to_pte(entry)))) {
+               found = 0;
+               goto out;
+       }
+
        inc_mm_counter(vma->vm_mm, anon_rss);
        get_page(page);
        set_pte_at(vma->vm_mm, addr, pte,
@@ -520,6 +530,9 @@ static void unuse_pte(struct vm_area_struct *vma, pte_t *pte,
         * immediately swapped out again after swapon.
         */
        activate_page(page);
+out:
+       pte_unmap_unlock(pte, ptl);
+       return found;
 }
 
 static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
@@ -528,22 +541,33 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 {
        pte_t swp_pte = swp_entry_to_pte(entry);
        pte_t *pte;
-       spinlock_t *ptl;
        int found = 0;
 
-       pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
+       /*
+        * We don't actually need pte lock while scanning for swp_pte: since
+        * we hold page lock and mmap_sem, swp_pte cannot be inserted into the
+        * page table while we're scanning; though it could get zapped, and on
+        * some architectures (e.g. x86_32 with PAE) we might catch a glimpse
+        * of unmatched parts which look like swp_pte, so unuse_pte must
+        * recheck under pte lock.  Scanning without pte lock lets it be
+        * preemptible whenever CONFIG_PREEMPT but not CONFIG_HIGHPTE.
+        */
+       pte = pte_offset_map(pmd, addr);
        do {
                /*
                 * swapoff spends a _lot_ of time in this loop!
                 * Test inline before going to call unuse_pte.
                 */
                if (unlikely(pte_same(*pte, swp_pte))) {
-                       unuse_pte(vma, pte++, addr, entry, page);
-                       found = 1;
-                       break;
+                       pte_unmap(pte);
+                       found = unuse_pte(vma, pmd, addr, entry, page);
+                       if (found)
+                               goto out;
+                       pte = pte_offset_map(pmd, addr);
                }
        } while (pte++, addr += PAGE_SIZE, addr != end);
-       pte_unmap_unlock(pte - 1, ptl);
+       pte_unmap(pte - 1);
+out:
        return found;
 }
 
@@ -730,7 +754,8 @@ static int try_to_unuse(unsigned int type)
                 */
                swap_map = &si->swap_map[i];
                entry = swp_entry(type, i);
-               page = read_swap_cache_async(entry, NULL, 0);
+               page = read_swap_cache_async(entry,
+                                       GFP_HIGHUSER_MOVABLE, NULL, 0);
                if (!page) {
                        /*
                         * Either swap_duplicate() failed because entry
@@ -789,7 +814,7 @@ static int try_to_unuse(unsigned int type)
                        atomic_inc(&new_start_mm->mm_users);
                        atomic_inc(&prev_mm->mm_users);
                        spin_lock(&mmlist_lock);
-                       while (*swap_map > 1 && !retval &&
+                       while (*swap_map > 1 && !retval && !shmem &&
                                        (p = p->next) != &start_mm->mmlist) {
                                mm = list_entry(p, struct mm_struct, mmlist);
                                if (!atomic_inc_not_zero(&mm->mm_users))
@@ -821,6 +846,13 @@ static int try_to_unuse(unsigned int type)
                        mmput(start_mm);
                        start_mm = new_start_mm;
                }
+               if (shmem) {
+                       /* page has already been unlocked and released */
+                       if (shmem > 0)
+                               continue;
+                       retval = shmem;
+                       break;
+               }
                if (retval) {
                        unlock_page(page);
                        page_cache_release(page);
@@ -859,12 +891,6 @@ static int try_to_unuse(unsigned int type)
                 * read from disk into another page.  Splitting into two
                 * pages would be incorrect if swap supported "shared
                 * private" pages, but they are handled by tmpfs files.
-                *
-                * Note shmem_unuse already deleted a swappage from
-                * the swap cache, unless the move to filepage failed:
-                * in which case it left swappage in cache, lowered its
-                * swap count to pass quickly through the loops above,
-                * and now we must reincrement count to try again later.
                 */
                if ((*swap_map > 1) && PageDirty(page) && PageSwapCache(page)) {
                        struct writeback_control wbc = {
@@ -875,12 +901,8 @@ static int try_to_unuse(unsigned int type)
                        lock_page(page);
                        wait_on_page_writeback(page);
                }
-               if (PageSwapCache(page)) {
-                       if (shmem)
-                               swap_duplicate(entry);
-                       else
-                               delete_from_swap_cache(page);
-               }
+               if (PageSwapCache(page))
+                       delete_from_swap_cache(page);
 
                /*
                 * So we could skip searching mms once swap count went
@@ -1768,31 +1790,48 @@ get_swap_info_struct(unsigned type)
  */
 int valid_swaphandles(swp_entry_t entry, unsigned long *offset)
 {
+       struct swap_info_struct *si;
        int our_page_cluster = page_cluster;
-       int ret = 0, i = 1 << our_page_cluster;
-       unsigned long toff;
-       struct swap_info_struct *swapdev = swp_type(entry) + swap_info;
+       pgoff_t target, toff;
+       pgoff_t base, end;
+       int nr_pages = 0;
 
        if (!our_page_cluster)  /* no readahead */
                return 0;
-       toff = (swp_offset(entry) >> our_page_cluster) << our_page_cluster;
-       if (!toff)              /* first page is swap header */
-               toff++, i--;
-       *offset = toff;
+
+       si = &swap_info[swp_type(entry)];
+       target = swp_offset(entry);
+       base = (target >> our_page_cluster) << our_page_cluster;
+       end = base + (1 << our_page_cluster);
+       if (!base)              /* first page is swap header */
+               base++;
 
        spin_lock(&swap_lock);
-       do {
-               /* Don't read-ahead past the end of the swap area */
-               if (toff >= swapdev->max)
+       if (end > si->max)      /* don't go beyond end of map */
+               end = si->max;
+
+       /* Count contiguous allocated slots above our target */
+       for (toff = target; ++toff < end; nr_pages++) {
+               /* Don't read in free or bad pages */
+               if (!si->swap_map[toff])
+                       break;
+               if (si->swap_map[toff] == SWAP_MAP_BAD)
                        break;
+       }
+       /* Count contiguous allocated slots below our target */
+       for (toff = target; --toff >= base; nr_pages++) {
                /* Don't read in free or bad pages */
-               if (!swapdev->swap_map[toff])
+               if (!si->swap_map[toff])
                        break;
-               if (swapdev->swap_map[toff] == SWAP_MAP_BAD)
+               if (si->swap_map[toff] == SWAP_MAP_BAD)
                        break;
-               toff++;
-               ret++;
-       } while (--i);
+       }
        spin_unlock(&swap_lock);
-       return ret;
+
+       /*
+        * Indicate starting offset, and return number of pages to get:
+        * if only 1, say 0, since there's then no readahead to be done.
+        */
+       *offset = ++toff;
+       return nr_pages? ++nr_pages: 0;
 }
index d436a9c82db7739618dee05886c0088aaea7728a..702083638c16d9a4a6878048f999f58c889fdd92 100644 (file)
@@ -121,18 +121,6 @@ int shmem_unuse(swp_entry_t entry, struct page *page)
        return 0;
 }
 
-#if 0
-int shmem_mmap(struct file *file, struct vm_area_struct *vma)
-{
-       file_accessed(file);
-#ifndef CONFIG_MMU
-       return ramfs_nommu_mmap(file, vma);
-#else
-       return 0;
-#endif
-}
-#endif  /*  0  */
-
 #ifndef CONFIG_MMU
 unsigned long shmem_get_unmapped_area(struct file *file,
                                      unsigned long addr,
index cadc15653ddeeaa311c80f794b6a564ae2f36fc8..c35c49e54fb6527eae91cb02177fc2b05a00abad 100644 (file)
@@ -21,7 +21,7 @@
 
 
 /**
- * do_invalidatepage - invalidate part of all of a page
+ * do_invalidatepage - invalidate part or all of a page
  * @page: the page which is affected
  * @offset: the index of the truncation point
  *
@@ -48,7 +48,7 @@ void do_invalidatepage(struct page *page, unsigned long offset)
 
 static inline void truncate_partial_page(struct page *page, unsigned partial)
 {
-       zero_user_page(page, partial, PAGE_CACHE_SIZE - partial, KM_USER0);
+       zero_user_segment(page, partial, PAGE_CACHE_SIZE);
        if (PagePrivate(page))
                do_invalidatepage(page, partial);
 }
@@ -84,7 +84,7 @@ EXPORT_SYMBOL(cancel_dirty_page);
 
 /*
  * If truncate cannot remove the fs-private metadata from the page, the page
- * becomes anonymous.  It will be left on the LRU and may even be mapped into
+ * becomes orphaned.  It will be left on the LRU and may even be mapped into
  * user pagetables if we're racing with filemap_fault().
  *
  * We need to bale out if page->mapping is no longer equal to the original
@@ -98,11 +98,11 @@ truncate_complete_page(struct address_space *mapping, struct page *page)
        if (page->mapping != mapping)
                return;
 
-       cancel_dirty_page(page, PAGE_CACHE_SIZE);
-
        if (PagePrivate(page))
                do_invalidatepage(page, 0);
 
+       cancel_dirty_page(page, PAGE_CACHE_SIZE);
+
        remove_from_page_cache(page);
        ClearPageUptodate(page);
        ClearPageMappedToDisk(page);
index af77e171e339a357933d7eb6ba4b001efae5e390..0536dde139d1e1f6f28fc93ccd05a9fc337e2c7e 100644 (file)
@@ -166,6 +166,44 @@ int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page ***pages)
 }
 EXPORT_SYMBOL_GPL(map_vm_area);
 
+/*
+ * Map a vmalloc()-space virtual address to the physical page.
+ */
+struct page *vmalloc_to_page(const void *vmalloc_addr)
+{
+       unsigned long addr = (unsigned long) vmalloc_addr;
+       struct page *page = NULL;
+       pgd_t *pgd = pgd_offset_k(addr);
+       pud_t *pud;
+       pmd_t *pmd;
+       pte_t *ptep, pte;
+
+       if (!pgd_none(*pgd)) {
+               pud = pud_offset(pgd, addr);
+               if (!pud_none(*pud)) {
+                       pmd = pmd_offset(pud, addr);
+                       if (!pmd_none(*pmd)) {
+                               ptep = pte_offset_map(pmd, addr);
+                               pte = *ptep;
+                               if (pte_present(pte))
+                                       page = pte_page(pte);
+                               pte_unmap(ptep);
+                       }
+               }
+       }
+       return page;
+}
+EXPORT_SYMBOL(vmalloc_to_page);
+
+/*
+ * Map a vmalloc()-space virtual address to the physical page frame number.
+ */
+unsigned long vmalloc_to_pfn(const void *vmalloc_addr)
+{
+       return page_to_pfn(vmalloc_to_page(vmalloc_addr));
+}
+EXPORT_SYMBOL(vmalloc_to_pfn);
+
 static struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags,
                                            unsigned long start, unsigned long end,
                                            int node, gfp_t gfp_mask)
@@ -216,6 +254,10 @@ static struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long fl
                if (addr > end - size)
                        goto out;
        }
+       if ((size + addr) < addr)
+               goto out;
+       if (addr > end - size)
+               goto out;
 
 found:
        area->next = *p;
@@ -268,7 +310,7 @@ struct vm_struct *get_vm_area_node(unsigned long size, unsigned long flags,
 }
 
 /* Caller must hold vmlist_lock */
-static struct vm_struct *__find_vm_area(void *addr)
+static struct vm_struct *__find_vm_area(const void *addr)
 {
        struct vm_struct *tmp;
 
@@ -281,7 +323,7 @@ static struct vm_struct *__find_vm_area(void *addr)
 }
 
 /* Caller must hold vmlist_lock */
-static struct vm_struct *__remove_vm_area(void *addr)
+static struct vm_struct *__remove_vm_area(const void *addr)
 {
        struct vm_struct **p, *tmp;
 
@@ -310,7 +352,7 @@ found:
  *     This function returns the found VM area, but using it is NOT safe
  *     on SMP machines, except for its size or flags.
  */
-struct vm_struct *remove_vm_area(void *addr)
+struct vm_struct *remove_vm_area(const void *addr)
 {
        struct vm_struct *v;
        write_lock(&vmlist_lock);
@@ -319,7 +361,7 @@ struct vm_struct *remove_vm_area(void *addr)
        return v;
 }
 
-static void __vunmap(void *addr, int deallocate_pages)
+static void __vunmap(const void *addr, int deallocate_pages)
 {
        struct vm_struct *area;
 
@@ -346,8 +388,10 @@ static void __vunmap(void *addr, int deallocate_pages)
                int i;
 
                for (i = 0; i < area->nr_pages; i++) {
-                       BUG_ON(!area->pages[i]);
-                       __free_page(area->pages[i]);
+                       struct page *page = area->pages[i];
+
+                       BUG_ON(!page);
+                       __free_page(page);
                }
 
                if (area->flags & VM_VPAGES)
@@ -370,7 +414,7 @@ static void __vunmap(void *addr, int deallocate_pages)
  *
  *     Must not be called in interrupt context.
  */
-void vfree(void *addr)
+void vfree(const void *addr)
 {
        BUG_ON(in_interrupt());
        __vunmap(addr, 1);
@@ -386,7 +430,7 @@ EXPORT_SYMBOL(vfree);
  *
  *     Must not be called in interrupt context.
  */
-void vunmap(void *addr)
+void vunmap(const void *addr)
 {
        BUG_ON(in_interrupt());
        __vunmap(addr, 0);
@@ -423,8 +467,8 @@ void *vmap(struct page **pages, unsigned int count,
 }
 EXPORT_SYMBOL(vmap);
 
-void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
-                               pgprot_t prot, int node)
+static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
+                                pgprot_t prot, int node)
 {
        struct page **pages;
        unsigned int nr_pages, array_size, i;
@@ -451,15 +495,19 @@ void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
        }
 
        for (i = 0; i < area->nr_pages; i++) {
+               struct page *page;
+
                if (node < 0)
-                       area->pages[i] = alloc_page(gfp_mask);
+                       page = alloc_page(gfp_mask);
                else
-                       area->pages[i] = alloc_pages_node(node, gfp_mask, 0);
-               if (unlikely(!area->pages[i])) {
+                       page = alloc_pages_node(node, gfp_mask, 0);
+
+               if (unlikely(!page)) {
                        /* Successfully allocated i pages, free them in __vunmap() */
                        area->nr_pages = i;
                        goto fail;
                }
+               area->pages[i] = page;
        }
 
        if (map_vm_area(area, prot, &pages))
index e8d846f57774ee631adc5836aeaa6498b39736a0..422d960ffcd892ae63087b9179354832c14c1f20 100644 (file)
@@ -21,21 +21,14 @@ EXPORT_PER_CPU_SYMBOL(vm_event_states);
 
 static void sum_vm_events(unsigned long *ret, cpumask_t *cpumask)
 {
-       int cpu = 0;
+       int cpu;
        int i;
 
        memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long));
 
-       cpu = first_cpu(*cpumask);
-       while (cpu < NR_CPUS) {
+       for_each_cpu_mask(cpu, *cpumask) {
                struct vm_event_state *this = &per_cpu(vm_event_states, cpu);
 
-               cpu = next_cpu(cpu, *cpumask);
-
-               if (cpu < NR_CPUS)
-                       prefetch(&per_cpu(vm_event_states, cpu));
-
-
                for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
                        ret[i] += this->event[i];
        }
@@ -284,6 +277,10 @@ EXPORT_SYMBOL(dec_zone_page_state);
 /*
  * Update the zone counters for one cpu.
  *
+ * The cpu specified must be either the current cpu or a processor that
+ * is not online. If it is the current cpu then the execution thread must
+ * be pinned to the current cpu.
+ *
  * Note that refresh_cpu_vm_stats strives to only access
  * node local memory. The per cpu pagesets on remote zones are placed
  * in the memory local to the processor using that pageset. So the
@@ -299,7 +296,7 @@ void refresh_cpu_vm_stats(int cpu)
 {
        struct zone *zone;
        int i;
-       unsigned long flags;
+       int global_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, };
 
        for_each_zone(zone) {
                struct per_cpu_pageset *p;
@@ -311,15 +308,19 @@ void refresh_cpu_vm_stats(int cpu)
 
                for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
                        if (p->vm_stat_diff[i]) {
+                               unsigned long flags;
+                               int v;
+
                                local_irq_save(flags);
-                               zone_page_state_add(p->vm_stat_diff[i],
-                                       zone, i);
+                               v = p->vm_stat_diff[i];
                                p->vm_stat_diff[i] = 0;
+                               local_irq_restore(flags);
+                               atomic_long_add(v, &zone->vm_stat[i]);
+                               global_diff[i] += v;
 #ifdef CONFIG_NUMA
                                /* 3 seconds idle till flush */
                                p->expire = 3;
 #endif
-                               local_irq_restore(flags);
                        }
 #ifdef CONFIG_NUMA
                /*
@@ -329,7 +330,7 @@ void refresh_cpu_vm_stats(int cpu)
                 * Check if there are pages remaining in this pageset
                 * if not then there is nothing to expire.
                 */
-               if (!p->expire || (!p->pcp[0].count && !p->pcp[1].count))
+               if (!p->expire || !p->pcp.count)
                        continue;
 
                /*
@@ -344,13 +345,14 @@ void refresh_cpu_vm_stats(int cpu)
                if (p->expire)
                        continue;
 
-               if (p->pcp[0].count)
-                       drain_zone_pages(zone, p->pcp + 0);
-
-               if (p->pcp[1].count)
-                       drain_zone_pages(zone, p->pcp + 1);
+               if (p->pcp.count)
+                       drain_zone_pages(zone, &p->pcp);
 #endif
        }
+
+       for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
+               if (global_diff[i])
+                       atomic_long_add(global_diff[i], &vm_stat[i]);
 }
 
 #endif
@@ -681,20 +683,17 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
                   "\n  pagesets");
        for_each_online_cpu(i) {
                struct per_cpu_pageset *pageset;
-               int j;
 
                pageset = zone_pcp(zone, i);
-               for (j = 0; j < ARRAY_SIZE(pageset->pcp); j++) {
-                       seq_printf(m,
-                                  "\n    cpu: %i pcp: %i"
-                                  "\n              count: %i"
-                                  "\n              high:  %i"
-                                  "\n              batch: %i",
-                                  i, j,
-                                  pageset->pcp[j].count,
-                                  pageset->pcp[j].high,
-                                  pageset->pcp[j].batch);
-                       }
+               seq_printf(m,
+                          "\n    cpu: %i"
+                          "\n              count: %i"
+                          "\n              high:  %i"
+                          "\n              batch: %i",
+                          i,
+                          pageset->pcp.count,
+                          pageset->pcp.high,
+                          pageset->pcp.batch);
 #ifdef CONFIG_SMP
                seq_printf(m, "\n  vm stats threshold: %d",
                                pageset->stat_threshold);
index d3abb246ccab41af3b237945f0fd520e96e451fe..8a105110189830f5b527047ac4e299462f038710 100644 (file)
@@ -4,7 +4,6 @@ obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o
 
 9pnet-objs := \
        mod.o \
-       mux.o \
        client.o \
        conv.o \
        error.o \
index af9199364049becdb5fb3442e43581e485173cd9..84e087e2414606ce56a3903eaae048ec1a2066ef 100644 (file)
@@ -3,6 +3,7 @@
  *
  * 9P Client
  *
+ *  Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com>
  *  Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -25,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/poll.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
 #include <linux/sched.h>
 #include <net/9p/9p.h>
 #include <linux/parser.h>
 #include <net/9p/transport.h>
-#include <net/9p/conn.h>
 #include <net/9p/client.h>
 
 static struct p9_fid *p9_fid_create(struct p9_client *clnt);
 static void p9_fid_destroy(struct p9_fid *fid);
 static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu);
 
-struct p9_client *p9_client_create(struct p9_trans *trans, int msize,
-                                                                  int dotu)
+/*
+  * Client Option Parsing (code inspired by NFS code)
+  *  - a little lazy - parse all client options
+  */
+
+enum {
+       Opt_msize,
+       Opt_trans,
+       Opt_legacy,
+       Opt_err,
+};
+
+static match_table_t tokens = {
+       {Opt_msize, "msize=%u"},
+       {Opt_legacy, "noextend"},
+       {Opt_trans, "trans=%s"},
+       {Opt_err, NULL},
+};
+
+/**
+ * v9fs_parse_options - parse mount options into session structure
+ * @options: options string passed from mount
+ * @v9ses: existing v9fs session information
+ *
+ */
+
+static void parse_opts(char *options, struct p9_client *clnt)
+{
+       char *p;
+       substring_t args[MAX_OPT_ARGS];
+       int option;
+       int ret;
+
+       clnt->trans_mod = v9fs_default_trans();
+       clnt->dotu = 1;
+       clnt->msize = 8192;
+
+       if (!options)
+               return;
+
+       while ((p = strsep(&options, ",")) != NULL) {
+               int token;
+               if (!*p)
+                       continue;
+               token = match_token(p, tokens, args);
+               if (token < Opt_trans) {
+                       ret = match_int(&args[0], &option);
+                       if (ret < 0) {
+                               P9_DPRINTK(P9_DEBUG_ERROR,
+                                       "integer field, but no integer?\n");
+                               continue;
+                       }
+               }
+               switch (token) {
+               case Opt_msize:
+                       clnt->msize = option;
+                       break;
+               case Opt_trans:
+                       clnt->trans_mod = v9fs_match_trans(&args[0]);
+                       break;
+               case Opt_legacy:
+                       clnt->dotu = 0;
+                       break;
+               default:
+                       continue;
+               }
+       }
+}
+
+
+/**
+ * p9_client_rpc - sends 9P request and waits until a response is available.
+ *      The function can be interrupted.
+ * @c: client data
+ * @tc: request to be sent
+ * @rc: pointer where a pointer to the response is stored
+ */
+int
+p9_client_rpc(struct p9_client *c, struct p9_fcall *tc,
+       struct p9_fcall **rc)
+{
+       return c->trans->rpc(c->trans, tc, rc);
+}
+
+struct p9_client *p9_client_create(const char *dev_name, char *options)
 {
        int err, n;
        struct p9_client *clnt;
@@ -54,12 +138,7 @@ struct p9_client *p9_client_create(struct p9_trans *trans, int msize,
        if (!clnt)
                return ERR_PTR(-ENOMEM);
 
-       P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n",
-               clnt, trans, msize, dotu);
        spin_lock_init(&clnt->lock);
-       clnt->trans = trans;
-       clnt->msize = msize;
-       clnt->dotu = dotu;
        INIT_LIST_HEAD(&clnt->fidlist);
        clnt->fidpool = p9_idpool_create();
        if (!clnt->fidpool) {
@@ -68,13 +147,29 @@ struct p9_client *p9_client_create(struct p9_trans *trans, int msize,
                goto error;
        }
 
-       clnt->conn = p9_conn_create(clnt->trans, clnt->msize, &clnt->dotu);
-       if (IS_ERR(clnt->conn)) {
-               err = PTR_ERR(clnt->conn);
-               clnt->conn = NULL;
+       parse_opts(options, clnt);
+       if (clnt->trans_mod == NULL) {
+               err = -EPROTONOSUPPORT;
+               P9_DPRINTK(P9_DEBUG_ERROR,
+                               "No transport defined or default transport\n");
                goto error;
        }
 
+       P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n",
+               clnt, clnt->trans_mod, clnt->msize, clnt->dotu);
+
+
+       clnt->trans = clnt->trans_mod->create(dev_name, options, clnt->msize,
+                                                               clnt->dotu);
+       if (IS_ERR(clnt->trans)) {
+               err = PTR_ERR(clnt->trans);
+               clnt->trans = NULL;
+               goto error;
+       }
+
+       if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
+               clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
+
        tc = p9_create_tversion(clnt->msize, clnt->dotu?"9P2000.u":"9P2000");
        if (IS_ERR(tc)) {
                err = PTR_ERR(tc);
@@ -82,7 +177,7 @@ struct p9_client *p9_client_create(struct p9_trans *trans, int msize,
                goto error;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto error;
 
@@ -117,10 +212,6 @@ void p9_client_destroy(struct p9_client *clnt)
        struct p9_fid *fid, *fidptr;
 
        P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
-       if (clnt->conn) {
-               p9_conn_destroy(clnt->conn);
-               clnt->conn = NULL;
-       }
 
        if (clnt->trans) {
                clnt->trans->close(clnt->trans);
@@ -142,7 +233,6 @@ void p9_client_disconnect(struct p9_client *clnt)
 {
        P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
        clnt->trans->status = Disconnected;
-       p9_conn_cancel(clnt->conn, -EIO);
 }
 EXPORT_SYMBOL(p9_client_disconnect);
 
@@ -174,7 +264,7 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
                goto error;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto error;
 
@@ -219,7 +309,7 @@ struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname,
                goto error;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto error;
 
@@ -270,7 +360,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
                goto error;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err) {
                if (rc && rc->id == P9_RWALK)
                        goto clunk_fid;
@@ -305,7 +395,7 @@ clunk_fid:
                goto error;
        }
 
-       p9_conn_rpc(clnt->conn, tc, &rc);
+       p9_client_rpc(clnt, tc, &rc);
 
 error:
        kfree(tc);
@@ -339,7 +429,7 @@ int p9_client_open(struct p9_fid *fid, int mode)
                goto done;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto done;
 
@@ -378,7 +468,7 @@ int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
                goto done;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto done;
 
@@ -411,7 +501,7 @@ int p9_client_clunk(struct p9_fid *fid)
                goto done;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto done;
 
@@ -443,7 +533,7 @@ int p9_client_remove(struct p9_fid *fid)
                goto done;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto done;
 
@@ -485,7 +575,7 @@ int p9_client_read(struct p9_fid *fid, char *data, u64 offset, u32 count)
                        goto error;
                }
 
-               err = p9_conn_rpc(clnt->conn, tc, &rc);
+               err = p9_client_rpc(clnt, tc, &rc);
                if (err)
                        goto error;
 
@@ -542,7 +632,7 @@ int p9_client_write(struct p9_fid *fid, char *data, u64 offset, u32 count)
                        goto error;
                }
 
-               err = p9_conn_rpc(clnt->conn, tc, &rc);
+               err = p9_client_rpc(clnt, tc, &rc);
                if (err)
                        goto error;
 
@@ -596,7 +686,7 @@ p9_client_uread(struct p9_fid *fid, char __user *data, u64 offset, u32 count)
                        goto error;
                }
 
-               err = p9_conn_rpc(clnt->conn, tc, &rc);
+               err = p9_client_rpc(clnt, tc, &rc);
                if (err)
                        goto error;
 
@@ -660,7 +750,7 @@ p9_client_uwrite(struct p9_fid *fid, const char __user *data, u64 offset,
                        goto error;
                }
 
-               err = p9_conn_rpc(clnt->conn, tc, &rc);
+               err = p9_client_rpc(clnt, tc, &rc);
                if (err)
                        goto error;
 
@@ -731,7 +821,7 @@ struct p9_stat *p9_client_stat(struct p9_fid *fid)
                goto error;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
        if (err)
                goto error;
 
@@ -773,7 +863,7 @@ int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
                goto done;
        }
 
-       err = p9_conn_rpc(clnt->conn, tc, &rc);
+       err = p9_client_rpc(clnt, tc, &rc);
 
 done:
        kfree(tc);
@@ -830,7 +920,7 @@ struct p9_stat *p9_client_dirread(struct p9_fid *fid, u64 offset)
                                goto error;
                        }
 
-                       err = p9_conn_rpc(clnt->conn, tc, &rc);
+                       err = p9_client_rpc(clnt, tc, &rc);
                        if (err)
                                goto error;
 
@@ -901,16 +991,21 @@ static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu)
        memmove(ret, st, sizeof(struct p9_stat));
        p = ((char *) ret) + sizeof(struct p9_stat);
        memmove(p, st->name.str, st->name.len);
+       ret->name.str = p;
        p += st->name.len;
        memmove(p, st->uid.str, st->uid.len);
+       ret->uid.str = p;
        p += st->uid.len;
        memmove(p, st->gid.str, st->gid.len);
+       ret->gid.str = p;
        p += st->gid.len;
        memmove(p, st->muid.str, st->muid.len);
+       ret->muid.str = p;
        p += st->muid.len;
 
        if (dotu) {
                memmove(p, st->extension.str, st->extension.len);
+               ret->extension.str = p;
                p += st->extension.len;
        }
 
index b1ae8ec57d54e8e5dbcc277ebb4b0266bffa2c6e..40244fbd9b0d15d2f66eb70cc4ff8f5d0a1d9b59 100644 (file)
@@ -347,12 +347,12 @@ p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
 
        return ret;
 }
-
 #else
 int
 p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
 {
        return 0;
 }
-EXPORT_SYMBOL(p9_printfcall);
 #endif /* CONFIG_NET_9P_DEBUG */
+EXPORT_SYMBOL(p9_printfcall);
+
index 8f9763a9dc1296b54a2d889a6bae9402ccf6cd37..c285aab2af04ba78683e98f45175815f1aadbbab 100644 (file)
@@ -106,15 +106,10 @@ EXPORT_SYMBOL(v9fs_default_trans);
  */
 static int __init init_p9(void)
 {
-       int ret;
+       int ret = 0;
 
        p9_error_init();
        printk(KERN_INFO "Installing 9P2000 support\n");
-       ret = p9_mux_global_init();
-       if (ret) {
-               printk(KERN_WARNING "9p: starting mux failed\n");
-               return ret;
-       }
 
        return ret;
 }
@@ -126,7 +121,7 @@ static int __init init_p9(void)
 
 static void __exit exit_p9(void)
 {
-       p9_mux_global_exit();
+       printk(KERN_INFO "Unloading 9P2000 support\n");
 }
 
 module_init(init_p9)
diff --git a/net/9p/mux.c b/net/9p/mux.c
deleted file mode 100644 (file)
index c9f0805..0000000
+++ /dev/null
@@ -1,1060 +0,0 @@
-/*
- * net/9p/mux.c
- *
- * Protocol Multiplexer
- *
- *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
- *  Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2
- *  as published by the Free Software Foundation.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to:
- *  Free Software Foundation
- *  51 Franklin Street, Fifth Floor
- *  Boston, MA  02111-1301  USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/fs.h>
-#include <linux/poll.h>
-#include <linux/kthread.h>
-#include <linux/idr.h>
-#include <linux/mutex.h>
-#include <net/9p/9p.h>
-#include <linux/parser.h>
-#include <net/9p/transport.h>
-#include <net/9p/conn.h>
-
-#define ERREQFLUSH     1
-#define SCHED_TIMEOUT  10
-#define MAXPOLLWADDR   2
-
-enum {
-       Rworksched = 1,         /* read work scheduled or running */
-       Rpending = 2,           /* can read */
-       Wworksched = 4,         /* write work scheduled or running */
-       Wpending = 8,           /* can write */
-};
-
-enum {
-       None,
-       Flushing,
-       Flushed,
-};
-
-struct p9_mux_poll_task;
-
-struct p9_req {
-       spinlock_t lock; /* protect request structure */
-       int tag;
-       struct p9_fcall *tcall;
-       struct p9_fcall *rcall;
-       int err;
-       p9_conn_req_callback cb;
-       void *cba;
-       int flush;
-       struct list_head req_list;
-};
-
-struct p9_conn {
-       spinlock_t lock; /* protect lock structure */
-       struct list_head mux_list;
-       struct p9_mux_poll_task *poll_task;
-       int msize;
-       unsigned char *extended;
-       struct p9_trans *trans;
-       struct p9_idpool *tagpool;
-       int err;
-       wait_queue_head_t equeue;
-       struct list_head req_list;
-       struct list_head unsent_req_list;
-       struct p9_fcall *rcall;
-       int rpos;
-       char *rbuf;
-       int wpos;
-       int wsize;
-       char *wbuf;
-       wait_queue_t poll_wait[MAXPOLLWADDR];
-       wait_queue_head_t *poll_waddr[MAXPOLLWADDR];
-       poll_table pt;
-       struct work_struct rq;
-       struct work_struct wq;
-       unsigned long wsched;
-};
-
-struct p9_mux_poll_task {
-       struct task_struct *task;
-       struct list_head mux_list;
-       int muxnum;
-};
-
-struct p9_mux_rpc {
-       struct p9_conn *m;
-       int err;
-       struct p9_fcall *tcall;
-       struct p9_fcall *rcall;
-       wait_queue_head_t wqueue;
-};
-
-static int p9_poll_proc(void *);
-static void p9_read_work(struct work_struct *work);
-static void p9_write_work(struct work_struct *work);
-static void p9_pollwait(struct file *filp, wait_queue_head_t *wait_address,
-                         poll_table * p);
-static u16 p9_mux_get_tag(struct p9_conn *);
-static void p9_mux_put_tag(struct p9_conn *, u16);
-
-static DEFINE_MUTEX(p9_mux_task_lock);
-static struct workqueue_struct *p9_mux_wq;
-
-static int p9_mux_num;
-static int p9_mux_poll_task_num;
-static struct p9_mux_poll_task p9_mux_poll_tasks[100];
-
-int p9_mux_global_init(void)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++)
-               p9_mux_poll_tasks[i].task = NULL;
-
-       p9_mux_wq = create_workqueue("v9fs");
-       if (!p9_mux_wq) {
-               printk(KERN_WARNING "v9fs: mux: creating workqueue failed\n");
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-void p9_mux_global_exit(void)
-{
-       destroy_workqueue(p9_mux_wq);
-}
-
-/**
- * p9_mux_calc_poll_procs - calculates the number of polling procs
- * based on the number of mounted v9fs filesystems.
- *
- * The current implementation returns sqrt of the number of mounts.
- */
-static int p9_mux_calc_poll_procs(int muxnum)
-{
-       int n;
-
-       if (p9_mux_poll_task_num)
-               n = muxnum / p9_mux_poll_task_num +
-                   (muxnum % p9_mux_poll_task_num ? 1 : 0);
-       else
-               n = 1;
-
-       if (n > ARRAY_SIZE(p9_mux_poll_tasks))
-               n = ARRAY_SIZE(p9_mux_poll_tasks);
-
-       return n;
-}
-
-static int p9_mux_poll_start(struct p9_conn *m)
-{
-       int i, n;
-       struct p9_mux_poll_task *vpt, *vptlast;
-       struct task_struct *pproc;
-
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, p9_mux_num,
-               p9_mux_poll_task_num);
-       mutex_lock(&p9_mux_task_lock);
-
-       n = p9_mux_calc_poll_procs(p9_mux_num + 1);
-       if (n > p9_mux_poll_task_num) {
-               for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) {
-                       if (p9_mux_poll_tasks[i].task == NULL) {
-                               vpt = &p9_mux_poll_tasks[i];
-                               P9_DPRINTK(P9_DEBUG_MUX, "create proc %p\n",
-                                                                       vpt);
-                               pproc = kthread_create(p9_poll_proc, vpt,
-                                                               "v9fs-poll");
-
-                               if (!IS_ERR(pproc)) {
-                                       vpt->task = pproc;
-                                       INIT_LIST_HEAD(&vpt->mux_list);
-                                       vpt->muxnum = 0;
-                                       p9_mux_poll_task_num++;
-                                       wake_up_process(vpt->task);
-                               }
-                               break;
-                       }
-               }
-
-               if (i >= ARRAY_SIZE(p9_mux_poll_tasks))
-                       P9_DPRINTK(P9_DEBUG_ERROR,
-                                       "warning: no free poll slots\n");
-       }
-
-       n = (p9_mux_num + 1) / p9_mux_poll_task_num +
-           ((p9_mux_num + 1) % p9_mux_poll_task_num ? 1 : 0);
-
-       vptlast = NULL;
-       for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) {
-               vpt = &p9_mux_poll_tasks[i];
-               if (vpt->task != NULL) {
-                       vptlast = vpt;
-                       if (vpt->muxnum < n) {
-                               P9_DPRINTK(P9_DEBUG_MUX, "put in proc %d\n", i);
-                               list_add(&m->mux_list, &vpt->mux_list);
-                               vpt->muxnum++;
-                               m->poll_task = vpt;
-                               memset(&m->poll_waddr, 0,
-                                                       sizeof(m->poll_waddr));
-                               init_poll_funcptr(&m->pt, p9_pollwait);
-                               break;
-                       }
-               }
-       }
-
-       if (i >= ARRAY_SIZE(p9_mux_poll_tasks)) {
-               if (vptlast == NULL) {
-                       mutex_unlock(&p9_mux_task_lock);
-                       return -ENOMEM;
-               }
-
-               P9_DPRINTK(P9_DEBUG_MUX, "put in proc %d\n", i);
-               list_add(&m->mux_list, &vptlast->mux_list);
-               vptlast->muxnum++;
-               m->poll_task = vptlast;
-               memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
-               init_poll_funcptr(&m->pt, p9_pollwait);
-       }
-
-       p9_mux_num++;
-       mutex_unlock(&p9_mux_task_lock);
-
-       return 0;
-}
-
-static void p9_mux_poll_stop(struct p9_conn *m)
-{
-       int i;
-       struct p9_mux_poll_task *vpt;
-
-       mutex_lock(&p9_mux_task_lock);
-       vpt = m->poll_task;
-       list_del(&m->mux_list);
-       for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
-               if (m->poll_waddr[i] != NULL) {
-                       remove_wait_queue(m->poll_waddr[i], &m->poll_wait[i]);
-                       m->poll_waddr[i] = NULL;
-               }
-       }
-       vpt->muxnum--;
-       if (!vpt->muxnum) {
-               P9_DPRINTK(P9_DEBUG_MUX, "destroy proc %p\n", vpt);
-               kthread_stop(vpt->task);
-               vpt->task = NULL;
-               p9_mux_poll_task_num--;
-       }
-       p9_mux_num--;
-       mutex_unlock(&p9_mux_task_lock);
-}
-
-/**
- * p9_conn_create - allocate and initialize the per-session mux data
- * Creates the polling task if this is the first session.
- *
- * @trans - transport structure
- * @msize - maximum message size
- * @extended - pointer to the extended flag
- */
-struct p9_conn *p9_conn_create(struct p9_trans *trans, int msize,
-                                   unsigned char *extended)
-{
-       int i, n;
-       struct p9_conn *m, *mtmp;
-
-       P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans, msize);
-       m = kmalloc(sizeof(struct p9_conn), GFP_KERNEL);
-       if (!m)
-               return ERR_PTR(-ENOMEM);
-
-       spin_lock_init(&m->lock);
-       INIT_LIST_HEAD(&m->mux_list);
-       m->msize = msize;
-       m->extended = extended;
-       m->trans = trans;
-       m->tagpool = p9_idpool_create();
-       if (IS_ERR(m->tagpool)) {
-               mtmp = ERR_PTR(-ENOMEM);
-               kfree(m);
-               return mtmp;
-       }
-
-       m->err = 0;
-       init_waitqueue_head(&m->equeue);
-       INIT_LIST_HEAD(&m->req_list);
-       INIT_LIST_HEAD(&m->unsent_req_list);
-       m->rcall = NULL;
-       m->rpos = 0;
-       m->rbuf = NULL;
-       m->wpos = m->wsize = 0;
-       m->wbuf = NULL;
-       INIT_WORK(&m->rq, p9_read_work);
-       INIT_WORK(&m->wq, p9_write_work);
-       m->wsched = 0;
-       memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
-       m->poll_task = NULL;
-       n = p9_mux_poll_start(m);
-       if (n) {
-               kfree(m);
-               return ERR_PTR(n);
-       }
-
-       n = trans->poll(trans, &m->pt);
-       if (n & POLLIN) {
-               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
-               set_bit(Rpending, &m->wsched);
-       }
-
-       if (n & POLLOUT) {
-               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m);
-               set_bit(Wpending, &m->wsched);
-       }
-
-       for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
-               if (IS_ERR(m->poll_waddr[i])) {
-                       p9_mux_poll_stop(m);
-                       mtmp = (void *)m->poll_waddr;   /* the error code */
-                       kfree(m);
-                       m = mtmp;
-                       break;
-               }
-       }
-
-       return m;
-}
-EXPORT_SYMBOL(p9_conn_create);
-
-/**
- * p9_mux_destroy - cancels all pending requests and frees mux resources
- */
-void p9_conn_destroy(struct p9_conn *m)
-{
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m,
-               m->mux_list.prev, m->mux_list.next);
-       p9_conn_cancel(m, -ECONNRESET);
-
-       if (!list_empty(&m->req_list)) {
-               /* wait until all processes waiting on this session exit */
-               P9_DPRINTK(P9_DEBUG_MUX,
-                       "mux %p waiting for empty request queue\n", m);
-               wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000);
-               P9_DPRINTK(P9_DEBUG_MUX, "mux %p request queue empty: %d\n", m,
-                       list_empty(&m->req_list));
-       }
-
-       p9_mux_poll_stop(m);
-       m->trans = NULL;
-       p9_idpool_destroy(m->tagpool);
-       kfree(m);
-}
-EXPORT_SYMBOL(p9_conn_destroy);
-
-/**
- * p9_pollwait - called by files poll operation to add v9fs-poll task
- *     to files wait queue
- */
-static void
-p9_pollwait(struct file *filp, wait_queue_head_t *wait_address,
-             poll_table * p)
-{
-       int i;
-       struct p9_conn *m;
-
-       m = container_of(p, struct p9_conn, pt);
-       for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++)
-               if (m->poll_waddr[i] == NULL)
-                       break;
-
-       if (i >= ARRAY_SIZE(m->poll_waddr)) {
-               P9_DPRINTK(P9_DEBUG_ERROR, "not enough wait_address slots\n");
-               return;
-       }
-
-       m->poll_waddr[i] = wait_address;
-
-       if (!wait_address) {
-               P9_DPRINTK(P9_DEBUG_ERROR, "no wait_address\n");
-               m->poll_waddr[i] = ERR_PTR(-EIO);
-               return;
-       }
-
-       init_waitqueue_entry(&m->poll_wait[i], m->poll_task->task);
-       add_wait_queue(wait_address, &m->poll_wait[i]);
-}
-
-/**
- * p9_poll_mux - polls a mux and schedules read or write works if necessary
- */
-static void p9_poll_mux(struct p9_conn *m)
-{
-       int n;
-
-       if (m->err < 0)
-               return;
-
-       n = m->trans->poll(m->trans, NULL);
-       if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) {
-               P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n);
-               if (n >= 0)
-                       n = -ECONNRESET;
-               p9_conn_cancel(m, n);
-       }
-
-       if (n & POLLIN) {
-               set_bit(Rpending, &m->wsched);
-               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
-               if (!test_and_set_bit(Rworksched, &m->wsched)) {
-                       P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
-                       queue_work(p9_mux_wq, &m->rq);
-               }
-       }
-
-       if (n & POLLOUT) {
-               set_bit(Wpending, &m->wsched);
-               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m);
-               if ((m->wsize || !list_empty(&m->unsent_req_list))
-                   && !test_and_set_bit(Wworksched, &m->wsched)) {
-                       P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
-                       queue_work(p9_mux_wq, &m->wq);
-               }
-       }
-}
-
-/**
- * p9_poll_proc - polls all v9fs transports for new events and queues
- *     the appropriate work to the work queue
- */
-static int p9_poll_proc(void *a)
-{
-       struct p9_conn *m, *mtmp;
-       struct p9_mux_poll_task *vpt;
-
-       vpt = a;
-       P9_DPRINTK(P9_DEBUG_MUX, "start %p %p\n", current, vpt);
-       while (!kthread_should_stop()) {
-               set_current_state(TASK_INTERRUPTIBLE);
-
-               list_for_each_entry_safe(m, mtmp, &vpt->mux_list, mux_list) {
-                       p9_poll_mux(m);
-               }
-
-               P9_DPRINTK(P9_DEBUG_MUX, "sleeping...\n");
-               schedule_timeout(SCHED_TIMEOUT * HZ);
-       }
-
-       __set_current_state(TASK_RUNNING);
-       P9_DPRINTK(P9_DEBUG_MUX, "finish\n");
-       return 0;
-}
-
-/**
- * p9_write_work - called when a transport can send some data
- */
-static void p9_write_work(struct work_struct *work)
-{
-       int n, err;
-       struct p9_conn *m;
-       struct p9_req *req;
-
-       m = container_of(work, struct p9_conn, wq);
-
-       if (m->err < 0) {
-               clear_bit(Wworksched, &m->wsched);
-               return;
-       }
-
-       if (!m->wsize) {
-               if (list_empty(&m->unsent_req_list)) {
-                       clear_bit(Wworksched, &m->wsched);
-                       return;
-               }
-
-               spin_lock(&m->lock);
-again:
-               req = list_entry(m->unsent_req_list.next, struct p9_req,
-                              req_list);
-               list_move_tail(&req->req_list, &m->req_list);
-               if (req->err == ERREQFLUSH)
-                       goto again;
-
-               m->wbuf = req->tcall->sdata;
-               m->wsize = req->tcall->size;
-               m->wpos = 0;
-               spin_unlock(&m->lock);
-       }
-
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos,
-                                                               m->wsize);
-       clear_bit(Wpending, &m->wsched);
-       err = m->trans->write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos);
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err);
-       if (err == -EAGAIN) {
-               clear_bit(Wworksched, &m->wsched);
-               return;
-       }
-
-       if (err < 0)
-               goto error;
-       else if (err == 0) {
-               err = -EREMOTEIO;
-               goto error;
-       }
-
-       m->wpos += err;
-       if (m->wpos == m->wsize)
-               m->wpos = m->wsize = 0;
-
-       if (m->wsize == 0 && !list_empty(&m->unsent_req_list)) {
-               if (test_and_clear_bit(Wpending, &m->wsched))
-                       n = POLLOUT;
-               else
-                       n = m->trans->poll(m->trans, NULL);
-
-               if (n & POLLOUT) {
-                       P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
-                       queue_work(p9_mux_wq, &m->wq);
-               } else
-                       clear_bit(Wworksched, &m->wsched);
-       } else
-               clear_bit(Wworksched, &m->wsched);
-
-       return;
-
-error:
-       p9_conn_cancel(m, err);
-       clear_bit(Wworksched, &m->wsched);
-}
-
-static void process_request(struct p9_conn *m, struct p9_req *req)
-{
-       int ecode;
-       struct p9_str *ename;
-
-       if (!req->err && req->rcall->id == P9_RERROR) {
-               ecode = req->rcall->params.rerror.errno;
-               ename = &req->rcall->params.rerror.error;
-
-               P9_DPRINTK(P9_DEBUG_MUX, "Rerror %.*s\n", ename->len,
-                                                               ename->str);
-
-               if (*m->extended)
-                       req->err = -ecode;
-
-               if (!req->err) {
-                       req->err = p9_errstr2errno(ename->str, ename->len);
-
-                       if (!req->err) {        /* string match failed */
-                               PRINT_FCALL_ERROR("unknown error", req->rcall);
-                       }
-
-                       if (!req->err)
-                               req->err = -ESERVERFAULT;
-               }
-       } else if (req->tcall && req->rcall->id != req->tcall->id + 1) {
-               P9_DPRINTK(P9_DEBUG_ERROR,
-                               "fcall mismatch: expected %d, got %d\n",
-                               req->tcall->id + 1, req->rcall->id);
-               if (!req->err)
-                       req->err = -EIO;
-       }
-}
-
-/**
- * p9_read_work - called when there is some data to be read from a transport
- */
-static void p9_read_work(struct work_struct *work)
-{
-       int n, err;
-       struct p9_conn *m;
-       struct p9_req *req, *rptr, *rreq;
-       struct p9_fcall *rcall;
-       char *rbuf;
-
-       m = container_of(work, struct p9_conn, rq);
-
-       if (m->err < 0)
-               return;
-
-       rcall = NULL;
-       P9_DPRINTK(P9_DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos);
-
-       if (!m->rcall) {
-               m->rcall =
-                   kmalloc(sizeof(struct p9_fcall) + m->msize, GFP_KERNEL);
-               if (!m->rcall) {
-                       err = -ENOMEM;
-                       goto error;
-               }
-
-               m->rbuf = (char *)m->rcall + sizeof(struct p9_fcall);
-               m->rpos = 0;
-       }
-
-       clear_bit(Rpending, &m->wsched);
-       err = m->trans->read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos);
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err);
-       if (err == -EAGAIN) {
-               clear_bit(Rworksched, &m->wsched);
-               return;
-       }
-
-       if (err <= 0)
-               goto error;
-
-       m->rpos += err;
-       while (m->rpos > 4) {
-               n = le32_to_cpu(*(__le32 *) m->rbuf);
-               if (n >= m->msize) {
-                       P9_DPRINTK(P9_DEBUG_ERROR,
-                               "requested packet size too big: %d\n", n);
-                       err = -EIO;
-                       goto error;
-               }
-
-               if (m->rpos < n)
-                       break;
-
-               err =
-                   p9_deserialize_fcall(m->rbuf, n, m->rcall, *m->extended);
-               if (err < 0) {
-                       goto error;
-               }
-
-#ifdef CONFIG_NET_9P_DEBUG
-               if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
-                       char buf[150];
-
-                       p9_printfcall(buf, sizeof(buf), m->rcall,
-                               *m->extended);
-                       printk(KERN_NOTICE ">>> %p %s\n", m, buf);
-               }
-#endif
-
-               rcall = m->rcall;
-               rbuf = m->rbuf;
-               if (m->rpos > n) {
-                       m->rcall = kmalloc(sizeof(struct p9_fcall) + m->msize,
-                                          GFP_KERNEL);
-                       if (!m->rcall) {
-                               err = -ENOMEM;
-                               goto error;
-                       }
-
-                       m->rbuf = (char *)m->rcall + sizeof(struct p9_fcall);
-                       memmove(m->rbuf, rbuf + n, m->rpos - n);
-                       m->rpos -= n;
-               } else {
-                       m->rcall = NULL;
-                       m->rbuf = NULL;
-                       m->rpos = 0;
-               }
-
-               P9_DPRINTK(P9_DEBUG_MUX, "mux %p fcall id %d tag %d\n", m,
-                                                       rcall->id, rcall->tag);
-
-               req = NULL;
-               spin_lock(&m->lock);
-               list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) {
-                       if (rreq->tag == rcall->tag) {
-                               req = rreq;
-                               if (req->flush != Flushing)
-                                       list_del(&req->req_list);
-                               break;
-                       }
-               }
-               spin_unlock(&m->lock);
-
-               if (req) {
-                       req->rcall = rcall;
-                       process_request(m, req);
-
-                       if (req->flush != Flushing) {
-                               if (req->cb)
-                                       (*req->cb) (req, req->cba);
-                               else
-                                       kfree(req->rcall);
-
-                               wake_up(&m->equeue);
-                       }
-               } else {
-                       if (err >= 0 && rcall->id != P9_RFLUSH)
-                               P9_DPRINTK(P9_DEBUG_ERROR,
-                                 "unexpected response mux %p id %d tag %d\n",
-                                 m, rcall->id, rcall->tag);
-                       kfree(rcall);
-               }
-       }
-
-       if (!list_empty(&m->req_list)) {
-               if (test_and_clear_bit(Rpending, &m->wsched))
-                       n = POLLIN;
-               else
-                       n = m->trans->poll(m->trans, NULL);
-
-               if (n & POLLIN) {
-                       P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
-                       queue_work(p9_mux_wq, &m->rq);
-               } else
-                       clear_bit(Rworksched, &m->wsched);
-       } else
-               clear_bit(Rworksched, &m->wsched);
-
-       return;
-
-error:
-       p9_conn_cancel(m, err);
-       clear_bit(Rworksched, &m->wsched);
-}
-
-/**
- * p9_send_request - send 9P request
- * The function can sleep until the request is scheduled for sending.
- * The function can be interrupted. Return from the function is not
- * a guarantee that the request is sent successfully. Can return errors
- * that can be retrieved by PTR_ERR macros.
- *
- * @m: mux data
- * @tc: request to be sent
- * @cb: callback function to call when response is received
- * @cba: parameter to pass to the callback function
- */
-static struct p9_req *p9_send_request(struct p9_conn *m,
-                                         struct p9_fcall *tc,
-                                         p9_conn_req_callback cb, void *cba)
-{
-       int n;
-       struct p9_req *req;
-
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current,
-               tc, tc->id);
-       if (m->err < 0)
-               return ERR_PTR(m->err);
-
-       req = kmalloc(sizeof(struct p9_req), GFP_KERNEL);
-       if (!req)
-               return ERR_PTR(-ENOMEM);
-
-       if (tc->id == P9_TVERSION)
-               n = P9_NOTAG;
-       else
-               n = p9_mux_get_tag(m);
-
-       if (n < 0)
-               return ERR_PTR(-ENOMEM);
-
-       p9_set_tag(tc, n);
-
-#ifdef CONFIG_NET_9P_DEBUG
-       if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
-               char buf[150];
-
-               p9_printfcall(buf, sizeof(buf), tc, *m->extended);
-               printk(KERN_NOTICE "<<< %p %s\n", m, buf);
-       }
-#endif
-
-       spin_lock_init(&req->lock);
-       req->tag = n;
-       req->tcall = tc;
-       req->rcall = NULL;
-       req->err = 0;
-       req->cb = cb;
-       req->cba = cba;
-       req->flush = None;
-
-       spin_lock(&m->lock);
-       list_add_tail(&req->req_list, &m->unsent_req_list);
-       spin_unlock(&m->lock);
-
-       if (test_and_clear_bit(Wpending, &m->wsched))
-               n = POLLOUT;
-       else
-               n = m->trans->poll(m->trans, NULL);
-
-       if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
-               queue_work(p9_mux_wq, &m->wq);
-
-       return req;
-}
-
-static void p9_mux_free_request(struct p9_conn *m, struct p9_req *req)
-{
-       p9_mux_put_tag(m, req->tag);
-       kfree(req);
-}
-
-static void p9_mux_flush_cb(struct p9_req *freq, void *a)
-{
-       p9_conn_req_callback cb;
-       int tag;
-       struct p9_conn *m;
-       struct p9_req *req, *rreq, *rptr;
-
-       m = a;
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m,
-               freq->tcall, freq->rcall, freq->err,
-               freq->tcall->params.tflush.oldtag);
-
-       spin_lock(&m->lock);
-       cb = NULL;
-       tag = freq->tcall->params.tflush.oldtag;
-       req = NULL;
-       list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) {
-               if (rreq->tag == tag) {
-                       req = rreq;
-                       list_del(&req->req_list);
-                       break;
-               }
-       }
-       spin_unlock(&m->lock);
-
-       if (req) {
-               spin_lock(&req->lock);
-               req->flush = Flushed;
-               spin_unlock(&req->lock);
-
-               if (req->cb)
-                       (*req->cb) (req, req->cba);
-               else
-                       kfree(req->rcall);
-
-               wake_up(&m->equeue);
-       }
-
-       kfree(freq->tcall);
-       kfree(freq->rcall);
-       p9_mux_free_request(m, freq);
-}
-
-static int
-p9_mux_flush_request(struct p9_conn *m, struct p9_req *req)
-{
-       struct p9_fcall *fc;
-       struct p9_req *rreq, *rptr;
-
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p req %p tag %d\n", m, req, req->tag);
-
-       /* if a response was received for a request, do nothing */
-       spin_lock(&req->lock);
-       if (req->rcall || req->err) {
-               spin_unlock(&req->lock);
-               P9_DPRINTK(P9_DEBUG_MUX,
-                       "mux %p req %p response already received\n", m, req);
-               return 0;
-       }
-
-       req->flush = Flushing;
-       spin_unlock(&req->lock);
-
-       spin_lock(&m->lock);
-       /* if the request is not sent yet, just remove it from the list */
-       list_for_each_entry_safe(rreq, rptr, &m->unsent_req_list, req_list) {
-               if (rreq->tag == req->tag) {
-                       P9_DPRINTK(P9_DEBUG_MUX,
-                          "mux %p req %p request is not sent yet\n", m, req);
-                       list_del(&rreq->req_list);
-                       req->flush = Flushed;
-                       spin_unlock(&m->lock);
-                       if (req->cb)
-                               (*req->cb) (req, req->cba);
-                       return 0;
-               }
-       }
-       spin_unlock(&m->lock);
-
-       clear_thread_flag(TIF_SIGPENDING);
-       fc = p9_create_tflush(req->tag);
-       p9_send_request(m, fc, p9_mux_flush_cb, m);
-       return 1;
-}
-
-static void
-p9_conn_rpc_cb(struct p9_req *req, void *a)
-{
-       struct p9_mux_rpc *r;
-
-       P9_DPRINTK(P9_DEBUG_MUX, "req %p r %p\n", req, a);
-       r = a;
-       r->rcall = req->rcall;
-       r->err = req->err;
-
-       if (req->flush != None && !req->err)
-               r->err = -ERESTARTSYS;
-
-       wake_up(&r->wqueue);
-}
-
-/**
- * p9_mux_rpc - sends 9P request and waits until a response is available.
- *     The function can be interrupted.
- * @m: mux data
- * @tc: request to be sent
- * @rc: pointer where a pointer to the response is stored
- */
-int
-p9_conn_rpc(struct p9_conn *m, struct p9_fcall *tc,
-            struct p9_fcall **rc)
-{
-       int err, sigpending;
-       unsigned long flags;
-       struct p9_req *req;
-       struct p9_mux_rpc r;
-
-       r.err = 0;
-       r.tcall = tc;
-       r.rcall = NULL;
-       r.m = m;
-       init_waitqueue_head(&r.wqueue);
-
-       if (rc)
-               *rc = NULL;
-
-       sigpending = 0;
-       if (signal_pending(current)) {
-               sigpending = 1;
-               clear_thread_flag(TIF_SIGPENDING);
-       }
-
-       req = p9_send_request(m, tc, p9_conn_rpc_cb, &r);
-       if (IS_ERR(req)) {
-               err = PTR_ERR(req);
-               P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err);
-               return err;
-       }
-
-       err = wait_event_interruptible(r.wqueue, r.rcall != NULL || r.err < 0);
-       if (r.err < 0)
-               err = r.err;
-
-       if (err == -ERESTARTSYS && m->trans->status == Connected
-                                                       && m->err == 0) {
-               if (p9_mux_flush_request(m, req)) {
-                       /* wait until we get response of the flush message */
-                       do {
-                               clear_thread_flag(TIF_SIGPENDING);
-                               err = wait_event_interruptible(r.wqueue,
-                                       r.rcall || r.err);
-                       } while (!r.rcall && !r.err && err == -ERESTARTSYS &&
-                               m->trans->status == Connected && !m->err);
-
-                       err = -ERESTARTSYS;
-               }
-               sigpending = 1;
-       }
-
-       if (sigpending) {
-               spin_lock_irqsave(&current->sighand->siglock, flags);
-               recalc_sigpending();
-               spin_unlock_irqrestore(&current->sighand->siglock, flags);
-       }
-
-       if (rc)
-               *rc = r.rcall;
-       else
-               kfree(r.rcall);
-
-       p9_mux_free_request(m, req);
-       if (err > 0)
-               err = -EIO;
-
-       return err;
-}
-EXPORT_SYMBOL(p9_conn_rpc);
-
-#ifdef P9_NONBLOCK
-/**
- * p9_conn_rpcnb - sends 9P request without waiting for response.
- * @m: mux data
- * @tc: request to be sent
- * @cb: callback function to be called when response arrives
- * @cba: value to pass to the callback function
- */
-int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc,
-                  p9_conn_req_callback cb, void *a)
-{
-       int err;
-       struct p9_req *req;
-
-       req = p9_send_request(m, tc, cb, a);
-       if (IS_ERR(req)) {
-               err = PTR_ERR(req);
-               P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err);
-               return PTR_ERR(req);
-       }
-
-       P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p tag %d\n", m, tc, req->tag);
-       return 0;
-}
-EXPORT_SYMBOL(p9_conn_rpcnb);
-#endif /* P9_NONBLOCK */
-
-/**
- * p9_conn_cancel - cancel all pending requests with error
- * @m: mux data
- * @err: error code
- */
-void p9_conn_cancel(struct p9_conn *m, int err)
-{
-       struct p9_req *req, *rtmp;
-       LIST_HEAD(cancel_list);
-
-       P9_DPRINTK(P9_DEBUG_ERROR, "mux %p err %d\n", m, err);
-       m->err = err;
-       spin_lock(&m->lock);
-       list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
-               list_move(&req->req_list, &cancel_list);
-       }
-       list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) {
-               list_move(&req->req_list, &cancel_list);
-       }
-       spin_unlock(&m->lock);
-
-       list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) {
-               list_del(&req->req_list);
-               if (!req->err)
-                       req->err = err;
-
-               if (req->cb)
-                       (*req->cb) (req, req->cba);
-               else
-                       kfree(req->rcall);
-       }
-
-       wake_up(&m->equeue);
-}
-EXPORT_SYMBOL(p9_conn_cancel);
-
-static u16 p9_mux_get_tag(struct p9_conn *m)
-{
-       int tag;
-
-       tag = p9_idpool_get(m->tagpool);
-       if (tag < 0)
-               return P9_NOTAG;
-       else
-               return (u16) tag;
-}
-
-static void p9_mux_put_tag(struct p9_conn *m, u16 tag)
-{
-       if (tag != P9_NOTAG && p9_idpool_check(tag, m->tagpool))
-               p9_idpool_put(tag, m->tagpool);
-}
index 62332ed9da4afcd7e8b06577f0e4ec47d07ed171..1aa9d51753981c483b7778e28c0f9a026714c7c2 100644 (file)
@@ -5,7 +5,7 @@
  *
  *  Copyright (C) 2006 by Russ Cox <rsc@swtch.com>
  *  Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net>
- *  Copyright (C) 2004-2007 by Eric Van Hensbergen <ericvh@gmail.com>
+ *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
  *  Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -29,6 +29,7 @@
 #include <linux/module.h>
 #include <linux/net.h>
 #include <linux/ipv6.h>
+#include <linux/kthread.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/un.h>
@@ -42,7 +43,9 @@
 
 #define P9_PORT 564
 #define MAX_SOCK_BUF (64*1024)
-
+#define ERREQFLUSH     1
+#define SCHED_TIMEOUT  10
+#define MAXPOLLWADDR   2
 
 struct p9_fd_opts {
        int rfd;
@@ -53,6 +56,7 @@ struct p9_fd_opts {
 struct p9_trans_fd {
        struct file *rd;
        struct file *wr;
+       struct p9_conn *conn;
 };
 
 /*
@@ -72,6 +76,1028 @@ static match_table_t tokens = {
        {Opt_err, NULL},
 };
 
+enum {
+       Rworksched = 1,         /* read work scheduled or running */
+       Rpending = 2,           /* can read */
+       Wworksched = 4,         /* write work scheduled or running */
+       Wpending = 8,           /* can write */
+};
+
+enum {
+       None,
+       Flushing,
+       Flushed,
+};
+
+struct p9_req;
+
+typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a);
+struct p9_req {
+       spinlock_t lock; /* protect request structure */
+       int tag;
+       struct p9_fcall *tcall;
+       struct p9_fcall *rcall;
+       int err;
+       p9_conn_req_callback cb;
+       void *cba;
+       int flush;
+       struct list_head req_list;
+};
+
+struct p9_mux_poll_task;
+
+struct p9_conn {
+       spinlock_t lock; /* protect lock structure */
+       struct list_head mux_list;
+       struct p9_mux_poll_task *poll_task;
+       int msize;
+       unsigned char extended;
+       struct p9_trans *trans;
+       struct p9_idpool *tagpool;
+       int err;
+       wait_queue_head_t equeue;
+       struct list_head req_list;
+       struct list_head unsent_req_list;
+       struct p9_fcall *rcall;
+       int rpos;
+       char *rbuf;
+       int wpos;
+       int wsize;
+       char *wbuf;
+       wait_queue_t poll_wait[MAXPOLLWADDR];
+       wait_queue_head_t *poll_waddr[MAXPOLLWADDR];
+       poll_table pt;
+       struct work_struct rq;
+       struct work_struct wq;
+       unsigned long wsched;
+};
+
+struct p9_mux_poll_task {
+       struct task_struct *task;
+       struct list_head mux_list;
+       int muxnum;
+};
+
+struct p9_mux_rpc {
+       struct p9_conn *m;
+       int err;
+       struct p9_fcall *tcall;
+       struct p9_fcall *rcall;
+       wait_queue_head_t wqueue;
+};
+
+static int p9_poll_proc(void *);
+static void p9_read_work(struct work_struct *work);
+static void p9_write_work(struct work_struct *work);
+static void p9_pollwait(struct file *filp, wait_queue_head_t *wait_address,
+                                                               poll_table *p);
+static int p9_fd_write(struct p9_trans *trans, void *v, int len);
+static int p9_fd_read(struct p9_trans *trans, void *v, int len);
+
+static DEFINE_MUTEX(p9_mux_task_lock);
+static struct workqueue_struct *p9_mux_wq;
+
+static int p9_mux_num;
+static int p9_mux_poll_task_num;
+static struct p9_mux_poll_task p9_mux_poll_tasks[100];
+
+static void p9_conn_destroy(struct p9_conn *);
+static unsigned int p9_fd_poll(struct p9_trans *trans,
+                                               struct poll_table_struct *pt);
+
+#ifdef P9_NONBLOCK
+static int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc,
+       p9_conn_req_callback cb, void *a);
+#endif /* P9_NONBLOCK */
+
+static void p9_conn_cancel(struct p9_conn *m, int err);
+
+static int p9_mux_global_init(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++)
+               p9_mux_poll_tasks[i].task = NULL;
+
+       p9_mux_wq = create_workqueue("v9fs");
+       if (!p9_mux_wq) {
+               printk(KERN_WARNING "v9fs: mux: creating workqueue failed\n");
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+static u16 p9_mux_get_tag(struct p9_conn *m)
+{
+       int tag;
+
+       tag = p9_idpool_get(m->tagpool);
+       if (tag < 0)
+               return P9_NOTAG;
+       else
+               return (u16) tag;
+}
+
+static void p9_mux_put_tag(struct p9_conn *m, u16 tag)
+{
+       if (tag != P9_NOTAG && p9_idpool_check(tag, m->tagpool))
+               p9_idpool_put(tag, m->tagpool);
+}
+
+/**
+ * p9_mux_calc_poll_procs - calculates the number of polling procs
+ * based on the number of mounted v9fs filesystems.
+ *
+ * The current implementation returns sqrt of the number of mounts.
+ */
+static int p9_mux_calc_poll_procs(int muxnum)
+{
+       int n;
+
+       if (p9_mux_poll_task_num)
+               n = muxnum / p9_mux_poll_task_num +
+                   (muxnum % p9_mux_poll_task_num ? 1 : 0);
+       else
+               n = 1;
+
+       if (n > ARRAY_SIZE(p9_mux_poll_tasks))
+               n = ARRAY_SIZE(p9_mux_poll_tasks);
+
+       return n;
+}
+
+static int p9_mux_poll_start(struct p9_conn *m)
+{
+       int i, n;
+       struct p9_mux_poll_task *vpt, *vptlast;
+       struct task_struct *pproc;
+
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, p9_mux_num,
+               p9_mux_poll_task_num);
+       mutex_lock(&p9_mux_task_lock);
+
+       n = p9_mux_calc_poll_procs(p9_mux_num + 1);
+       if (n > p9_mux_poll_task_num) {
+               for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) {
+                       if (p9_mux_poll_tasks[i].task == NULL) {
+                               vpt = &p9_mux_poll_tasks[i];
+                               P9_DPRINTK(P9_DEBUG_MUX, "create proc %p\n",
+                                                                       vpt);
+                               pproc = kthread_create(p9_poll_proc, vpt,
+                                                               "v9fs-poll");
+
+                               if (!IS_ERR(pproc)) {
+                                       vpt->task = pproc;
+                                       INIT_LIST_HEAD(&vpt->mux_list);
+                                       vpt->muxnum = 0;
+                                       p9_mux_poll_task_num++;
+                                       wake_up_process(vpt->task);
+                               }
+                               break;
+                       }
+               }
+
+               if (i >= ARRAY_SIZE(p9_mux_poll_tasks))
+                       P9_DPRINTK(P9_DEBUG_ERROR,
+                                       "warning: no free poll slots\n");
+       }
+
+       n = (p9_mux_num + 1) / p9_mux_poll_task_num +
+           ((p9_mux_num + 1) % p9_mux_poll_task_num ? 1 : 0);
+
+       vptlast = NULL;
+       for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) {
+               vpt = &p9_mux_poll_tasks[i];
+               if (vpt->task != NULL) {
+                       vptlast = vpt;
+                       if (vpt->muxnum < n) {
+                               P9_DPRINTK(P9_DEBUG_MUX, "put in proc %d\n", i);
+                               list_add(&m->mux_list, &vpt->mux_list);
+                               vpt->muxnum++;
+                               m->poll_task = vpt;
+                               memset(&m->poll_waddr, 0,
+                                                       sizeof(m->poll_waddr));
+                               init_poll_funcptr(&m->pt, p9_pollwait);
+                               break;
+                       }
+               }
+       }
+
+       if (i >= ARRAY_SIZE(p9_mux_poll_tasks)) {
+               if (vptlast == NULL) {
+                       mutex_unlock(&p9_mux_task_lock);
+                       return -ENOMEM;
+               }
+
+               P9_DPRINTK(P9_DEBUG_MUX, "put in proc %d\n", i);
+               list_add(&m->mux_list, &vptlast->mux_list);
+               vptlast->muxnum++;
+               m->poll_task = vptlast;
+               memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
+               init_poll_funcptr(&m->pt, p9_pollwait);
+       }
+
+       p9_mux_num++;
+       mutex_unlock(&p9_mux_task_lock);
+
+       return 0;
+}
+
+static void p9_mux_poll_stop(struct p9_conn *m)
+{
+       int i;
+       struct p9_mux_poll_task *vpt;
+
+       mutex_lock(&p9_mux_task_lock);
+       vpt = m->poll_task;
+       list_del(&m->mux_list);
+       for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
+               if (m->poll_waddr[i] != NULL) {
+                       remove_wait_queue(m->poll_waddr[i], &m->poll_wait[i]);
+                       m->poll_waddr[i] = NULL;
+               }
+       }
+       vpt->muxnum--;
+       if (!vpt->muxnum) {
+               P9_DPRINTK(P9_DEBUG_MUX, "destroy proc %p\n", vpt);
+               kthread_stop(vpt->task);
+               vpt->task = NULL;
+               p9_mux_poll_task_num--;
+       }
+       p9_mux_num--;
+       mutex_unlock(&p9_mux_task_lock);
+}
+
+/**
+ * p9_conn_create - allocate and initialize the per-session mux data
+ * Creates the polling task if this is the first session.
+ *
+ * @trans - transport structure
+ * @msize - maximum message size
+ * @extended - extended flag
+ */
+static struct p9_conn *p9_conn_create(struct p9_trans *trans)
+{
+       int i, n;
+       struct p9_conn *m, *mtmp;
+
+       P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans,
+                                                               trans->msize);
+       m = kmalloc(sizeof(struct p9_conn), GFP_KERNEL);
+       if (!m)
+               return ERR_PTR(-ENOMEM);
+
+       spin_lock_init(&m->lock);
+       INIT_LIST_HEAD(&m->mux_list);
+       m->msize = trans->msize;
+       m->extended = trans->extended;
+       m->trans = trans;
+       m->tagpool = p9_idpool_create();
+       if (IS_ERR(m->tagpool)) {
+               mtmp = ERR_PTR(-ENOMEM);
+               kfree(m);
+               return mtmp;
+       }
+
+       m->err = 0;
+       init_waitqueue_head(&m->equeue);
+       INIT_LIST_HEAD(&m->req_list);
+       INIT_LIST_HEAD(&m->unsent_req_list);
+       m->rcall = NULL;
+       m->rpos = 0;
+       m->rbuf = NULL;
+       m->wpos = m->wsize = 0;
+       m->wbuf = NULL;
+       INIT_WORK(&m->rq, p9_read_work);
+       INIT_WORK(&m->wq, p9_write_work);
+       m->wsched = 0;
+       memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
+       m->poll_task = NULL;
+       n = p9_mux_poll_start(m);
+       if (n) {
+               kfree(m);
+               return ERR_PTR(n);
+       }
+
+       n = p9_fd_poll(trans, &m->pt);
+       if (n & POLLIN) {
+               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
+               set_bit(Rpending, &m->wsched);
+       }
+
+       if (n & POLLOUT) {
+               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m);
+               set_bit(Wpending, &m->wsched);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
+               if (IS_ERR(m->poll_waddr[i])) {
+                       p9_mux_poll_stop(m);
+                       mtmp = (void *)m->poll_waddr;   /* the error code */
+                       kfree(m);
+                       m = mtmp;
+                       break;
+               }
+       }
+
+       return m;
+}
+
+/**
+ * p9_mux_destroy - cancels all pending requests and frees mux resources
+ */
+static void p9_conn_destroy(struct p9_conn *m)
+{
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m,
+               m->mux_list.prev, m->mux_list.next);
+       p9_conn_cancel(m, -ECONNRESET);
+
+       if (!list_empty(&m->req_list)) {
+               /* wait until all processes waiting on this session exit */
+               P9_DPRINTK(P9_DEBUG_MUX,
+                       "mux %p waiting for empty request queue\n", m);
+               wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000);
+               P9_DPRINTK(P9_DEBUG_MUX, "mux %p request queue empty: %d\n", m,
+                       list_empty(&m->req_list));
+       }
+
+       p9_mux_poll_stop(m);
+       m->trans = NULL;
+       p9_idpool_destroy(m->tagpool);
+       kfree(m);
+}
+
+/**
+ * p9_pollwait - called by files poll operation to add v9fs-poll task
+ *     to files wait queue
+ */
+static void
+p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p)
+{
+       int i;
+       struct p9_conn *m;
+
+       m = container_of(p, struct p9_conn, pt);
+       for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++)
+               if (m->poll_waddr[i] == NULL)
+                       break;
+
+       if (i >= ARRAY_SIZE(m->poll_waddr)) {
+               P9_DPRINTK(P9_DEBUG_ERROR, "not enough wait_address slots\n");
+               return;
+       }
+
+       m->poll_waddr[i] = wait_address;
+
+       if (!wait_address) {
+               P9_DPRINTK(P9_DEBUG_ERROR, "no wait_address\n");
+               m->poll_waddr[i] = ERR_PTR(-EIO);
+               return;
+       }
+
+       init_waitqueue_entry(&m->poll_wait[i], m->poll_task->task);
+       add_wait_queue(wait_address, &m->poll_wait[i]);
+}
+
+/**
+ * p9_poll_mux - polls a mux and schedules read or write works if necessary
+ */
+static void p9_poll_mux(struct p9_conn *m)
+{
+       int n;
+
+       if (m->err < 0)
+               return;
+
+       n = p9_fd_poll(m->trans, NULL);
+       if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) {
+               P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n);
+               if (n >= 0)
+                       n = -ECONNRESET;
+               p9_conn_cancel(m, n);
+       }
+
+       if (n & POLLIN) {
+               set_bit(Rpending, &m->wsched);
+               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
+               if (!test_and_set_bit(Rworksched, &m->wsched)) {
+                       P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
+                       queue_work(p9_mux_wq, &m->rq);
+               }
+       }
+
+       if (n & POLLOUT) {
+               set_bit(Wpending, &m->wsched);
+               P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m);
+               if ((m->wsize || !list_empty(&m->unsent_req_list))
+                   && !test_and_set_bit(Wworksched, &m->wsched)) {
+                       P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
+                       queue_work(p9_mux_wq, &m->wq);
+               }
+       }
+}
+
+/**
+ * p9_poll_proc - polls all v9fs transports for new events and queues
+ *     the appropriate work to the work queue
+ */
+static int p9_poll_proc(void *a)
+{
+       struct p9_conn *m, *mtmp;
+       struct p9_mux_poll_task *vpt;
+
+       vpt = a;
+       P9_DPRINTK(P9_DEBUG_MUX, "start %p %p\n", current, vpt);
+       while (!kthread_should_stop()) {
+               set_current_state(TASK_INTERRUPTIBLE);
+
+               list_for_each_entry_safe(m, mtmp, &vpt->mux_list, mux_list) {
+                       p9_poll_mux(m);
+               }
+
+               P9_DPRINTK(P9_DEBUG_MUX, "sleeping...\n");
+               schedule_timeout(SCHED_TIMEOUT * HZ);
+       }
+
+       __set_current_state(TASK_RUNNING);
+       P9_DPRINTK(P9_DEBUG_MUX, "finish\n");
+       return 0;
+}
+
+/**
+ * p9_write_work - called when a transport can send some data
+ */
+static void p9_write_work(struct work_struct *work)
+{
+       int n, err;
+       struct p9_conn *m;
+       struct p9_req *req;
+
+       m = container_of(work, struct p9_conn, wq);
+
+       if (m->err < 0) {
+               clear_bit(Wworksched, &m->wsched);
+               return;
+       }
+
+       if (!m->wsize) {
+               if (list_empty(&m->unsent_req_list)) {
+                       clear_bit(Wworksched, &m->wsched);
+                       return;
+               }
+
+               spin_lock(&m->lock);
+again:
+               req = list_entry(m->unsent_req_list.next, struct p9_req,
+                              req_list);
+               list_move_tail(&req->req_list, &m->req_list);
+               if (req->err == ERREQFLUSH)
+                       goto again;
+
+               m->wbuf = req->tcall->sdata;
+               m->wsize = req->tcall->size;
+               m->wpos = 0;
+               spin_unlock(&m->lock);
+       }
+
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos,
+                                                               m->wsize);
+       clear_bit(Wpending, &m->wsched);
+       err = p9_fd_write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos);
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err);
+       if (err == -EAGAIN) {
+               clear_bit(Wworksched, &m->wsched);
+               return;
+       }
+
+       if (err < 0)
+               goto error;
+       else if (err == 0) {
+               err = -EREMOTEIO;
+               goto error;
+       }
+
+       m->wpos += err;
+       if (m->wpos == m->wsize)
+               m->wpos = m->wsize = 0;
+
+       if (m->wsize == 0 && !list_empty(&m->unsent_req_list)) {
+               if (test_and_clear_bit(Wpending, &m->wsched))
+                       n = POLLOUT;
+               else
+                       n = p9_fd_poll(m->trans, NULL);
+
+               if (n & POLLOUT) {
+                       P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
+                       queue_work(p9_mux_wq, &m->wq);
+               } else
+                       clear_bit(Wworksched, &m->wsched);
+       } else
+               clear_bit(Wworksched, &m->wsched);
+
+       return;
+
+error:
+       p9_conn_cancel(m, err);
+       clear_bit(Wworksched, &m->wsched);
+}
+
+static void process_request(struct p9_conn *m, struct p9_req *req)
+{
+       int ecode;
+       struct p9_str *ename;
+
+       if (!req->err && req->rcall->id == P9_RERROR) {
+               ecode = req->rcall->params.rerror.errno;
+               ename = &req->rcall->params.rerror.error;
+
+               P9_DPRINTK(P9_DEBUG_MUX, "Rerror %.*s\n", ename->len,
+                                                               ename->str);
+
+               if (m->extended)
+                       req->err = -ecode;
+
+               if (!req->err) {
+                       req->err = p9_errstr2errno(ename->str, ename->len);
+
+                       /* string match failed */
+                       if (!req->err) {
+                               PRINT_FCALL_ERROR("unknown error", req->rcall);
+                               req->err = -ESERVERFAULT;
+                       }
+               }
+       } else if (req->tcall && req->rcall->id != req->tcall->id + 1) {
+               P9_DPRINTK(P9_DEBUG_ERROR,
+                               "fcall mismatch: expected %d, got %d\n",
+                               req->tcall->id + 1, req->rcall->id);
+               if (!req->err)
+                       req->err = -EIO;
+       }
+}
+
+/**
+ * p9_read_work - called when there is some data to be read from a transport
+ */
+static void p9_read_work(struct work_struct *work)
+{
+       int n, err;
+       struct p9_conn *m;
+       struct p9_req *req, *rptr, *rreq;
+       struct p9_fcall *rcall;
+       char *rbuf;
+
+       m = container_of(work, struct p9_conn, rq);
+
+       if (m->err < 0)
+               return;
+
+       rcall = NULL;
+       P9_DPRINTK(P9_DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos);
+
+       if (!m->rcall) {
+               m->rcall =
+                   kmalloc(sizeof(struct p9_fcall) + m->msize, GFP_KERNEL);
+               if (!m->rcall) {
+                       err = -ENOMEM;
+                       goto error;
+               }
+
+               m->rbuf = (char *)m->rcall + sizeof(struct p9_fcall);
+               m->rpos = 0;
+       }
+
+       clear_bit(Rpending, &m->wsched);
+       err = p9_fd_read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos);
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err);
+       if (err == -EAGAIN) {
+               clear_bit(Rworksched, &m->wsched);
+               return;
+       }
+
+       if (err <= 0)
+               goto error;
+
+       m->rpos += err;
+       while (m->rpos > 4) {
+               n = le32_to_cpu(*(__le32 *) m->rbuf);
+               if (n >= m->msize) {
+                       P9_DPRINTK(P9_DEBUG_ERROR,
+                               "requested packet size too big: %d\n", n);
+                       err = -EIO;
+                       goto error;
+               }
+
+               if (m->rpos < n)
+                       break;
+
+               err =
+                   p9_deserialize_fcall(m->rbuf, n, m->rcall, m->extended);
+               if (err < 0)
+                       goto error;
+
+#ifdef CONFIG_NET_9P_DEBUG
+               if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
+                       char buf[150];
+
+                       p9_printfcall(buf, sizeof(buf), m->rcall,
+                               m->extended);
+                       printk(KERN_NOTICE ">>> %p %s\n", m, buf);
+               }
+#endif
+
+               rcall = m->rcall;
+               rbuf = m->rbuf;
+               if (m->rpos > n) {
+                       m->rcall = kmalloc(sizeof(struct p9_fcall) + m->msize,
+                                          GFP_KERNEL);
+                       if (!m->rcall) {
+                               err = -ENOMEM;
+                               goto error;
+                       }
+
+                       m->rbuf = (char *)m->rcall + sizeof(struct p9_fcall);
+                       memmove(m->rbuf, rbuf + n, m->rpos - n);
+                       m->rpos -= n;
+               } else {
+                       m->rcall = NULL;
+                       m->rbuf = NULL;
+                       m->rpos = 0;
+               }
+
+               P9_DPRINTK(P9_DEBUG_MUX, "mux %p fcall id %d tag %d\n", m,
+                                                       rcall->id, rcall->tag);
+
+               req = NULL;
+               spin_lock(&m->lock);
+               list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) {
+                       if (rreq->tag == rcall->tag) {
+                               req = rreq;
+                               if (req->flush != Flushing)
+                                       list_del(&req->req_list);
+                               break;
+                       }
+               }
+               spin_unlock(&m->lock);
+
+               if (req) {
+                       req->rcall = rcall;
+                       process_request(m, req);
+
+                       if (req->flush != Flushing) {
+                               if (req->cb)
+                                       (*req->cb) (req, req->cba);
+                               else
+                                       kfree(req->rcall);
+
+                               wake_up(&m->equeue);
+                       }
+               } else {
+                       if (err >= 0 && rcall->id != P9_RFLUSH)
+                               P9_DPRINTK(P9_DEBUG_ERROR,
+                                 "unexpected response mux %p id %d tag %d\n",
+                                 m, rcall->id, rcall->tag);
+                       kfree(rcall);
+               }
+       }
+
+       if (!list_empty(&m->req_list)) {
+               if (test_and_clear_bit(Rpending, &m->wsched))
+                       n = POLLIN;
+               else
+                       n = p9_fd_poll(m->trans, NULL);
+
+               if (n & POLLIN) {
+                       P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
+                       queue_work(p9_mux_wq, &m->rq);
+               } else
+                       clear_bit(Rworksched, &m->wsched);
+       } else
+               clear_bit(Rworksched, &m->wsched);
+
+       return;
+
+error:
+       p9_conn_cancel(m, err);
+       clear_bit(Rworksched, &m->wsched);
+}
+
+/**
+ * p9_send_request - send 9P request
+ * The function can sleep until the request is scheduled for sending.
+ * The function can be interrupted. Return from the function is not
+ * a guarantee that the request is sent successfully. Can return errors
+ * that can be retrieved by PTR_ERR macros.
+ *
+ * @m: mux data
+ * @tc: request to be sent
+ * @cb: callback function to call when response is received
+ * @cba: parameter to pass to the callback function
+ */
+static struct p9_req *p9_send_request(struct p9_conn *m,
+                                         struct p9_fcall *tc,
+                                         p9_conn_req_callback cb, void *cba)
+{
+       int n;
+       struct p9_req *req;
+
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current,
+               tc, tc->id);
+       if (m->err < 0)
+               return ERR_PTR(m->err);
+
+       req = kmalloc(sizeof(struct p9_req), GFP_KERNEL);
+       if (!req)
+               return ERR_PTR(-ENOMEM);
+
+       if (tc->id == P9_TVERSION)
+               n = P9_NOTAG;
+       else
+               n = p9_mux_get_tag(m);
+
+       if (n < 0)
+               return ERR_PTR(-ENOMEM);
+
+       p9_set_tag(tc, n);
+
+#ifdef CONFIG_NET_9P_DEBUG
+       if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
+               char buf[150];
+
+               p9_printfcall(buf, sizeof(buf), tc, m->extended);
+               printk(KERN_NOTICE "<<< %p %s\n", m, buf);
+       }
+#endif
+
+       spin_lock_init(&req->lock);
+       req->tag = n;
+       req->tcall = tc;
+       req->rcall = NULL;
+       req->err = 0;
+       req->cb = cb;
+       req->cba = cba;
+       req->flush = None;
+
+       spin_lock(&m->lock);
+       list_add_tail(&req->req_list, &m->unsent_req_list);
+       spin_unlock(&m->lock);
+
+       if (test_and_clear_bit(Wpending, &m->wsched))
+               n = POLLOUT;
+       else
+               n = p9_fd_poll(m->trans, NULL);
+
+       if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
+               queue_work(p9_mux_wq, &m->wq);
+
+       return req;
+}
+
+static void p9_mux_free_request(struct p9_conn *m, struct p9_req *req)
+{
+       p9_mux_put_tag(m, req->tag);
+       kfree(req);
+}
+
+static void p9_mux_flush_cb(struct p9_req *freq, void *a)
+{
+       p9_conn_req_callback cb;
+       int tag;
+       struct p9_conn *m;
+       struct p9_req *req, *rreq, *rptr;
+
+       m = a;
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m,
+               freq->tcall, freq->rcall, freq->err,
+               freq->tcall->params.tflush.oldtag);
+
+       spin_lock(&m->lock);
+       cb = NULL;
+       tag = freq->tcall->params.tflush.oldtag;
+       req = NULL;
+       list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) {
+               if (rreq->tag == tag) {
+                       req = rreq;
+                       list_del(&req->req_list);
+                       break;
+               }
+       }
+       spin_unlock(&m->lock);
+
+       if (req) {
+               spin_lock(&req->lock);
+               req->flush = Flushed;
+               spin_unlock(&req->lock);
+
+               if (req->cb)
+                       (*req->cb) (req, req->cba);
+               else
+                       kfree(req->rcall);
+
+               wake_up(&m->equeue);
+       }
+
+       kfree(freq->tcall);
+       kfree(freq->rcall);
+       p9_mux_free_request(m, freq);
+}
+
+static int
+p9_mux_flush_request(struct p9_conn *m, struct p9_req *req)
+{
+       struct p9_fcall *fc;
+       struct p9_req *rreq, *rptr;
+
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p req %p tag %d\n", m, req, req->tag);
+
+       /* if a response was received for a request, do nothing */
+       spin_lock(&req->lock);
+       if (req->rcall || req->err) {
+               spin_unlock(&req->lock);
+               P9_DPRINTK(P9_DEBUG_MUX,
+                       "mux %p req %p response already received\n", m, req);
+               return 0;
+       }
+
+       req->flush = Flushing;
+       spin_unlock(&req->lock);
+
+       spin_lock(&m->lock);
+       /* if the request is not sent yet, just remove it from the list */
+       list_for_each_entry_safe(rreq, rptr, &m->unsent_req_list, req_list) {
+               if (rreq->tag == req->tag) {
+                       P9_DPRINTK(P9_DEBUG_MUX,
+                          "mux %p req %p request is not sent yet\n", m, req);
+                       list_del(&rreq->req_list);
+                       req->flush = Flushed;
+                       spin_unlock(&m->lock);
+                       if (req->cb)
+                               (*req->cb) (req, req->cba);
+                       return 0;
+               }
+       }
+       spin_unlock(&m->lock);
+
+       clear_thread_flag(TIF_SIGPENDING);
+       fc = p9_create_tflush(req->tag);
+       p9_send_request(m, fc, p9_mux_flush_cb, m);
+       return 1;
+}
+
+static void
+p9_conn_rpc_cb(struct p9_req *req, void *a)
+{
+       struct p9_mux_rpc *r;
+
+       P9_DPRINTK(P9_DEBUG_MUX, "req %p r %p\n", req, a);
+       r = a;
+       r->rcall = req->rcall;
+       r->err = req->err;
+
+       if (req->flush != None && !req->err)
+               r->err = -ERESTARTSYS;
+
+       wake_up(&r->wqueue);
+}
+
+/**
+ * p9_fd_rpc- sends 9P request and waits until a response is available.
+ *     The function can be interrupted.
+ * @m: mux data
+ * @tc: request to be sent
+ * @rc: pointer where a pointer to the response is stored
+ */
+int
+p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
+{
+       struct p9_trans_fd *p = t->priv;
+       struct p9_conn *m = p->conn;
+       int err, sigpending;
+       unsigned long flags;
+       struct p9_req *req;
+       struct p9_mux_rpc r;
+
+       r.err = 0;
+       r.tcall = tc;
+       r.rcall = NULL;
+       r.m = m;
+       init_waitqueue_head(&r.wqueue);
+
+       if (rc)
+               *rc = NULL;
+
+       sigpending = 0;
+       if (signal_pending(current)) {
+               sigpending = 1;
+               clear_thread_flag(TIF_SIGPENDING);
+       }
+
+       req = p9_send_request(m, tc, p9_conn_rpc_cb, &r);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err);
+               return err;
+       }
+
+       err = wait_event_interruptible(r.wqueue, r.rcall != NULL || r.err < 0);
+       if (r.err < 0)
+               err = r.err;
+
+       if (err == -ERESTARTSYS && m->trans->status == Connected
+                                                       && m->err == 0) {
+               if (p9_mux_flush_request(m, req)) {
+                       /* wait until we get response of the flush message */
+                       do {
+                               clear_thread_flag(TIF_SIGPENDING);
+                               err = wait_event_interruptible(r.wqueue,
+                                       r.rcall || r.err);
+                       } while (!r.rcall && !r.err && err == -ERESTARTSYS &&
+                               m->trans->status == Connected && !m->err);
+
+                       err = -ERESTARTSYS;
+               }
+               sigpending = 1;
+       }
+
+       if (sigpending) {
+               spin_lock_irqsave(&current->sighand->siglock, flags);
+               recalc_sigpending();
+               spin_unlock_irqrestore(&current->sighand->siglock, flags);
+       }
+
+       if (rc)
+               *rc = r.rcall;
+       else
+               kfree(r.rcall);
+
+       p9_mux_free_request(m, req);
+       if (err > 0)
+               err = -EIO;
+
+       return err;
+}
+
+#ifdef P9_NONBLOCK
+/**
+ * p9_conn_rpcnb - sends 9P request without waiting for response.
+ * @m: mux data
+ * @tc: request to be sent
+ * @cb: callback function to be called when response arrives
+ * @cba: value to pass to the callback function
+ */
+int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc,
+                  p9_conn_req_callback cb, void *a)
+{
+       int err;
+       struct p9_req *req;
+
+       req = p9_send_request(m, tc, cb, a);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err);
+               return PTR_ERR(req);
+       }
+
+       P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p tag %d\n", m, tc, req->tag);
+       return 0;
+}
+#endif /* P9_NONBLOCK */
+
+/**
+ * p9_conn_cancel - cancel all pending requests with error
+ * @m: mux data
+ * @err: error code
+ */
+void p9_conn_cancel(struct p9_conn *m, int err)
+{
+       struct p9_req *req, *rtmp;
+       LIST_HEAD(cancel_list);
+
+       P9_DPRINTK(P9_DEBUG_ERROR, "mux %p err %d\n", m, err);
+       m->err = err;
+       spin_lock(&m->lock);
+       list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
+               list_move(&req->req_list, &cancel_list);
+       }
+       list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) {
+               list_move(&req->req_list, &cancel_list);
+       }
+       spin_unlock(&m->lock);
+
+       list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) {
+               list_del(&req->req_list);
+               if (!req->err)
+                       req->err = err;
+
+               if (req->cb)
+                       (*req->cb) (req, req->cba);
+               else
+                       kfree(req->rcall);
+       }
+
+       wake_up(&m->equeue);
+}
+
 /**
  * v9fs_parse_options - parse mount options into session structure
  * @options: options string passed from mount
@@ -268,7 +1294,7 @@ end:
 }
 
 /**
- * p9_sock_close - shutdown socket
+ * p9_fd_close - shutdown socket
  * @trans: private socket structure
  *
  */
@@ -284,6 +1310,8 @@ static void p9_fd_close(struct p9_trans *trans)
        if (!ts)
                return;
 
+       p9_conn_destroy(ts->conn);
+
        trans->status = Disconnected;
        if (ts->rd)
                fput(ts->rd);
@@ -292,13 +1320,15 @@ static void p9_fd_close(struct p9_trans *trans)
        kfree(ts);
 }
 
-static struct p9_trans *p9_trans_create_tcp(const char *addr, char *args)
+static struct p9_trans *
+p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu)
 {
        int err;
        struct p9_trans *trans;
        struct socket *csocket;
        struct sockaddr_in sin_server;
        struct p9_fd_opts opts;
+       struct p9_trans_fd *p;
 
        parse_opts(args, &opts);
 
@@ -306,11 +1336,10 @@ static struct p9_trans *p9_trans_create_tcp(const char *addr, char *args)
        trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
        if (!trans)
                return ERR_PTR(-ENOMEM);
-
-       trans->write = p9_fd_write;
-       trans->read = p9_fd_read;
+       trans->msize = msize;
+       trans->extended = dotu;
+       trans->rpc = p9_fd_rpc;
        trans->close = p9_fd_close;
-       trans->poll = p9_fd_poll;
 
        sin_server.sin_family = AF_INET;
        sin_server.sin_addr.s_addr = in_aton(addr);
@@ -337,6 +1366,14 @@ static struct p9_trans *p9_trans_create_tcp(const char *addr, char *args)
        if (err < 0)
                goto error;
 
+       p = (struct p9_trans_fd *) trans->priv;
+       p->conn = p9_conn_create(trans);
+       if (IS_ERR(p->conn)) {
+               err = PTR_ERR(p->conn);
+               p->conn = NULL;
+               goto error;
+       }
+
        return trans;
 
 error:
@@ -347,22 +1384,23 @@ error:
        return ERR_PTR(err);
 }
 
-static struct p9_trans *p9_trans_create_unix(const char *addr, char *args)
+static struct p9_trans *
+p9_trans_create_unix(const char *addr, char *args, int msize,
+                                                       unsigned char dotu)
 {
        int err;
        struct socket *csocket;
        struct sockaddr_un sun_server;
        struct p9_trans *trans;
+       struct p9_trans_fd *p;
 
        csocket = NULL;
        trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
        if (!trans)
                return ERR_PTR(-ENOMEM);
 
-       trans->write = p9_fd_write;
-       trans->read = p9_fd_read;
+       trans->rpc = p9_fd_rpc;
        trans->close = p9_fd_close;
-       trans->poll = p9_fd_poll;
 
        if (strlen(addr) > UNIX_PATH_MAX) {
                P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n",
@@ -387,6 +1425,16 @@ static struct p9_trans *p9_trans_create_unix(const char *addr, char *args)
        if (err < 0)
                goto error;
 
+       trans->msize = msize;
+       trans->extended = dotu;
+       p = (struct p9_trans_fd *) trans->priv;
+       p->conn = p9_conn_create(trans);
+       if (IS_ERR(p->conn)) {
+               err = PTR_ERR(p->conn);
+               p->conn = NULL;
+               goto error;
+       }
+
        return trans;
 
 error:
@@ -397,11 +1445,14 @@ error:
        return ERR_PTR(err);
 }
 
-static struct p9_trans *p9_trans_create_fd(const char *name, char *args)
+static struct p9_trans *
+p9_trans_create_fd(const char *name, char *args, int msize,
+                                                       unsigned char extended)
 {
        int err;
        struct p9_trans *trans;
        struct p9_fd_opts opts;
+       struct p9_trans_fd *p;
 
        parse_opts(args, &opts);
 
@@ -414,15 +1465,23 @@ static struct p9_trans *p9_trans_create_fd(const char *name, char *args)
        if (!trans)
                return ERR_PTR(-ENOMEM);
 
-       trans->write = p9_fd_write;
-       trans->read = p9_fd_read;
+       trans->rpc = p9_fd_rpc;
        trans->close = p9_fd_close;
-       trans->poll = p9_fd_poll;
 
        err = p9_fd_open(trans, opts.rfd, opts.wfd);
        if (err < 0)
                goto error;
 
+       trans->msize = msize;
+       trans->extended = extended;
+       p = (struct p9_trans_fd *) trans->priv;
+       p->conn = p9_conn_create(trans);
+       if (IS_ERR(p->conn)) {
+               err = PTR_ERR(p->conn);
+               p->conn = NULL;
+               goto error;
+       }
+
        return trans;
 
 error:
@@ -453,6 +1512,12 @@ static struct p9_trans_module p9_fd_trans = {
 
 static int __init p9_trans_fd_init(void)
 {
+       int ret = p9_mux_global_init();
+       if (ret) {
+               printk(KERN_WARNING "9p: starting mux failed\n");
+               return ret;
+       }
+
        v9fs_register_trans(&p9_tcp_trans);
        v9fs_register_trans(&p9_unix_trans);
        v9fs_register_trans(&p9_fd_trans);
@@ -460,13 +1525,7 @@ static int __init p9_trans_fd_init(void)
        return 1;
 }
 
-static void __exit p9_trans_fd_exit(void) {
-       printk(KERN_ERR "Removal of 9p transports not implemented\n");
-       BUG();
-}
-
 module_init(p9_trans_fd_init);
-module_exit(p9_trans_fd_exit);
 
 MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
 MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
index 40b71a29fc3faa11b8360ddab2d3fbcc6fe29276..0117b9fb8480d4a51830ff0e59a591a6ffeb2105 100644 (file)
@@ -1,17 +1,8 @@
 /*
  * The Guest 9p transport driver
  *
- * This is a trivial pipe-based transport driver based on the lguest console
- * code: we use lguest's DMA mechanism to send bytes out, and register a
- * DMA buffer to receive bytes in.  It is assumed to be present and available
- * from the very beginning of boot.
- *
- * This may be have been done by just instaniating another HVC console,
- * but HVC's blocksize of 16 bytes is annoying and painful to performance.
- *
- * A more efficient transport could be built based on the virtio block driver
- * but it requires some changes in the 9p transport model (which are in
- * progress)
+ * This is a block based transport driver based on the lguest block driver
+ * code.
  *
  */
 /*
 #include <linux/virtio.h>
 #include <linux/virtio_9p.h>
 
+#define VIRTQUEUE_NUM  128
+
 /* a single mutex to manage channel initialization and attachment */
 static DECLARE_MUTEX(virtio_9p_lock);
 /* global which tracks highest initialized channel */
 static int chan_index;
 
+#define P9_INIT_MAXTAG 16
+
+#define REQ_STATUS_IDLE        0
+#define REQ_STATUS_SENT 1
+#define REQ_STATUS_RCVD 2
+#define REQ_STATUS_FLSH 3
+
+struct p9_req_t {
+       int status;
+       wait_queue_head_t *wq;
+};
+
 /* We keep all per-channel information in a structure.
  * This structure is allocated within the devices dev->mem space.
  * A pointer to the structure will get put in the transport private.
@@ -68,148 +73,198 @@ static struct virtio_chan {
        bool initialized;               /* channel is initialized */
        bool inuse;                     /* channel is in use */
 
-       struct virtqueue *in_vq, *out_vq;
+       spinlock_t lock;
+
        struct virtio_device *vdev;
+       struct virtqueue *vq;
 
-       /* This is our input buffer, and how much data is left in it. */
-       unsigned int in_len;
-       char *in, *inbuf;
+       struct p9_idpool *tagpool;
+       struct p9_req_t *reqs;
+       int max_tag;
 
-       wait_queue_head_t wq;           /* waitq for buffer */
+       /* Scatterlist: can be too big for stack. */
+       struct scatterlist sg[VIRTQUEUE_NUM];
 } channels[MAX_9P_CHAN];
 
+/* Lookup requests by tag */
+static struct p9_req_t *p9_lookup_tag(struct virtio_chan *c, u16 tag)
+{
+       /* This looks up the original request by tag so we know which
+        * buffer to read the data into */
+       tag++;
+
+       while (tag >= c->max_tag) {
+               int old_max = c->max_tag;
+               int count;
+
+               if (c->max_tag)
+                       c->max_tag *= 2;
+               else
+                       c->max_tag = P9_INIT_MAXTAG;
+
+               c->reqs = krealloc(c->reqs, sizeof(struct p9_req_t)*c->max_tag,
+                                                               GFP_ATOMIC);
+               if (!c->reqs) {
+                       printk(KERN_ERR "Couldn't grow tag array\n");
+                       BUG();
+               }
+               for (count = old_max; count < c->max_tag; count++) {
+                       c->reqs[count].status = REQ_STATUS_IDLE;
+                       c->reqs[count].wq = kmalloc(sizeof(wait_queue_t),
+                                                               GFP_ATOMIC);
+                       if (!c->reqs[count].wq) {
+                               printk(KERN_ERR "Couldn't grow tag array\n");
+                               BUG();
+                       }
+                       init_waitqueue_head(c->reqs[count].wq);
+               }
+       }
+
+       return &c->reqs[tag];
+}
+
+
 /* How many bytes left in this page. */
 static unsigned int rest_of_page(void *data)
 {
        return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE);
 }
 
-static int p9_virtio_write(struct p9_trans *trans, void *buf, int count)
+static void p9_virtio_close(struct p9_trans *trans)
 {
-       struct virtio_chan *chan = (struct virtio_chan *) trans->priv;
-       struct virtqueue *out_vq = chan->out_vq;
-       struct scatterlist sg[1];
-       unsigned int len;
+       struct virtio_chan *chan = trans->priv;
+       int count;
+       unsigned int flags;
 
-       P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio write (%d)\n", count);
+       spin_lock_irqsave(&chan->lock, flags);
+       p9_idpool_destroy(chan->tagpool);
+       for (count = 0; count < chan->max_tag; count++)
+               kfree(chan->reqs[count].wq);
+       kfree(chan->reqs);
+       chan->max_tag = 0;
+       spin_unlock_irqrestore(&chan->lock, flags);
 
-       /* keep it simple - make sure we don't overflow a page */
-       if (rest_of_page(buf) < count)
-               count = rest_of_page(buf);
+       down(&virtio_9p_lock);
+       chan->inuse = false;
+       up(&virtio_9p_lock);
 
-       sg_init_one(sg, buf, count);
+       kfree(trans);
+}
 
-       /* add_buf wants a token to identify this buffer: we hand it any
-        * non-NULL pointer, since there's only ever one buffer. */
-       if (out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, (void *)1) == 0) {
-               /* Tell Host to go! */
-               out_vq->vq_ops->kick(out_vq);
-               /* Chill out until it's done with the buffer. */
-               while (!out_vq->vq_ops->get_buf(out_vq, &len))
-                       cpu_relax();
+static void req_done(struct virtqueue *vq)
+{
+       struct virtio_chan *chan = vq->vdev->priv;
+       struct p9_fcall *rc;
+       unsigned int len;
+       unsigned long flags;
+       struct p9_req_t *req;
+
+       spin_lock_irqsave(&chan->lock, flags);
+       while ((rc = chan->vq->vq_ops->get_buf(chan->vq, &len)) != NULL) {
+               req = p9_lookup_tag(chan, rc->tag);
+               req->status = REQ_STATUS_RCVD;
+               wake_up(req->wq);
        }
-
-       P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio wrote (%d)\n", count);
-
-       /* We're expected to return the amount of data we wrote: all of it. */
-       return count;
+       /* In case queue is stopped waiting for more buffers. */
+       spin_unlock_irqrestore(&chan->lock, flags);
 }
 
-/* Create a scatter-gather list representing our input buffer and put it in the
- * queue. */
-static void add_inbuf(struct virtio_chan *chan)
+static int
+pack_sg_list(struct scatterlist *sg, int start, int limit, char *data,
+                                                               int count)
 {
-       struct scatterlist sg[1];
-
-       sg_init_one(sg, chan->inbuf, PAGE_SIZE);
+       int s;
+       int index = start;
+
+       while (count) {
+               s = rest_of_page(data);
+               if (s > count)
+                       s = count;
+               sg_set_buf(&sg[index++], data, s);
+               count -= s;
+               data += s;
+               if (index > limit)
+                       BUG();
+       }
 
-       /* We should always be able to add one buffer to an empty queue. */
-       if (chan->in_vq->vq_ops->add_buf(chan->in_vq, sg, 0, 1, chan->inbuf))
-               BUG();
-       chan->in_vq->vq_ops->kick(chan->in_vq);
+       return index-start;
 }
 
-static int p9_virtio_read(struct p9_trans *trans, void *buf, int count)
+static int
+p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
 {
-       struct virtio_chan *chan = (struct virtio_chan *) trans->priv;
-       struct virtqueue *in_vq = chan->in_vq;
-
-       P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio read (%d)\n", count);
+       int in, out;
+       int n, err, size;
+       struct virtio_chan *chan = t->priv;
+       char *rdata;
+       struct p9_req_t *req;
+       unsigned long flags;
+
+       if (*rc == NULL) {
+               *rc = kmalloc(sizeof(struct p9_fcall) + t->msize, GFP_KERNEL);
+               if (!*rc)
+                       return -ENOMEM;
+       }
 
-       /* If we don't have an input queue yet, we can't get input. */
-       BUG_ON(!in_vq);
+       rdata = (char *)*rc+sizeof(struct p9_fcall);
 
-       /* No buffer?  Try to get one. */
-       if (!chan->in_len) {
-               chan->in = in_vq->vq_ops->get_buf(in_vq, &chan->in_len);
-               if (!chan->in)
-                       return 0;
+       n = P9_NOTAG;
+       if (tc->id != P9_TVERSION) {
+               n = p9_idpool_get(chan->tagpool);
+               if (n < 0)
+                       return -ENOMEM;
        }
 
-       /* You want more than we have to give?  Well, try wanting less! */
-       if (chan->in_len < count)
-               count = chan->in_len;
+       spin_lock_irqsave(&chan->lock, flags);
+       req = p9_lookup_tag(chan, n);
+       spin_unlock_irqrestore(&chan->lock, flags);
 
-       /* Copy across to their buffer and increment offset. */
-       memcpy(buf, chan->in, count);
-       chan->in += count;
-       chan->in_len -= count;
+       p9_set_tag(tc, n);
 
-       /* Finished?  Re-register buffer so Host will use it again. */
-       if (chan->in_len == 0)
-               add_inbuf(chan);
+       P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n);
 
-       P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio finished read (%d)\n",
-                                                                       count);
-
-       return count;
-}
+       out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size);
+       in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, t->msize);
 
-/* The poll function is used by 9p transports to determine if there
- * is there is activity available on a particular channel.  In our case
- * we use it to wait for a callback from the input routines.
- */
-static unsigned int
-p9_virtio_poll(struct p9_trans *trans, struct poll_table_struct *pt)
-{
-       struct virtio_chan *chan = (struct virtio_chan *)trans->priv;
-       struct virtqueue *in_vq = chan->in_vq;
-       int ret = POLLOUT; /* we can always handle more output */
+       req->status = REQ_STATUS_SENT;
 
-       poll_wait(NULL, &chan->wq, pt);
+       if (chan->vq->vq_ops->add_buf(chan->vq, chan->sg, out, in, tc)) {
+               P9_DPRINTK(P9_DEBUG_TRANS,
+                       "9p debug: virtio rpc add_buf returned failure");
+               return -EIO;
+       }
 
-       /* No buffer?  Try to get one. */
-       if (!chan->in_len)
-               chan->in = in_vq->vq_ops->get_buf(in_vq, &chan->in_len);
+       chan->vq->vq_ops->kick(chan->vq);
 
-       if (chan->in_len)
-               ret |= POLLIN;
+       wait_event(*req->wq, req->status == REQ_STATUS_RCVD);
 
-       return ret;
-}
+       size = le32_to_cpu(*(__le32 *) rdata);
 
-static void p9_virtio_close(struct p9_trans *trans)
-{
-       struct virtio_chan *chan = trans->priv;
+       err = p9_deserialize_fcall(rdata, size, *rc, t->extended);
+       if (err < 0) {
+               P9_DPRINTK(P9_DEBUG_TRANS,
+                       "9p debug: virtio rpc deserialize returned %d\n", err);
+               return err;
+       }
 
-       down(&virtio_9p_lock);
-       chan->inuse = false;
-       up(&virtio_9p_lock);
+#ifdef CONFIG_NET_9P_DEBUG
+       if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
+               char buf[150];
 
-       kfree(trans);
-}
+               p9_printfcall(buf, sizeof(buf), *rc, t->extended);
+               printk(KERN_NOTICE ">>> %p %s\n", t, buf);
+       }
+#endif
 
-static bool p9_virtio_intr(struct virtqueue *q)
-{
-       struct virtio_chan *chan = q->vdev->priv;
+       if (n != P9_NOTAG && p9_idpool_check(n, chan->tagpool))
+               p9_idpool_put(n, chan->tagpool);
 
-       P9_DPRINTK(P9_DEBUG_TRANS, "9p poll_wakeup: %p\n", &chan->wq);
-       wake_up_interruptible(&chan->wq);
+       req->status = REQ_STATUS_IDLE;
 
-       return true;
+       return 0;
 }
 
-static int p9_virtio_probe(struct virtio_device *dev)
+static int p9_virtio_probe(struct virtio_device *vdev)
 {
        int err;
        struct virtio_chan *chan;
@@ -223,44 +278,29 @@ static int p9_virtio_probe(struct virtio_device *dev)
        if (chan_index > MAX_9P_CHAN) {
                printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n");
                BUG();
-       }
-
-       chan->vdev = dev;
-
-       /* This is the scratch page we use to receive console input */
-       chan->inbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
-       if (!chan->inbuf) {
                err = -ENOMEM;
                goto fail;
        }
 
-       /* Find the input queue. */
-       dev->priv = chan;
-       chan->in_vq = dev->config->find_vq(dev, p9_virtio_intr);
-       if (IS_ERR(chan->in_vq)) {
-               err = PTR_ERR(chan->in_vq);
-               goto free;
-       }
+       chan->vdev = vdev;
 
-       chan->out_vq = dev->config->find_vq(dev, NULL);
-       if (IS_ERR(chan->out_vq)) {
-               err = PTR_ERR(chan->out_vq);
-               goto free_in_vq;
+       /* We expect one virtqueue, for requests. */
+       chan->vq = vdev->config->find_vq(vdev, 0, req_done);
+       if (IS_ERR(chan->vq)) {
+               err = PTR_ERR(chan->vq);
+               goto out_free_vq;
        }
+       chan->vq->vdev->priv = chan;
+       spin_lock_init(&chan->lock);
 
-       init_waitqueue_head(&chan->wq);
+       sg_init_table(chan->sg, VIRTQUEUE_NUM);
 
-       /* Register the input buffer the first time. */
-       add_inbuf(chan);
        chan->inuse = false;
        chan->initialized = true;
-
        return 0;
 
-free_in_vq:
-       dev->config->del_vq(chan->in_vq);
-free:
-       kfree(chan->inbuf);
+out_free_vq:
+       vdev->config->del_vq(chan->vq);
 fail:
        down(&virtio_9p_lock);
        chan_index--;
@@ -273,11 +313,13 @@ fail:
  * alternate channels by matching devname versus a virtio_config entry.
  * We use a simple reference count mechanism to ensure that only a single
  * mount has a channel open at a time. */
-static struct p9_trans *p9_virtio_create(const char *devname, char *args)
+static struct p9_trans *
+p9_virtio_create(const char *devname, char *args, int msize,
+                                                       unsigned char extended)
 {
        struct p9_trans *trans;
-       int index = 0;
        struct virtio_chan *chan = channels;
+       int index = 0;
 
        down(&virtio_9p_lock);
        while (index < MAX_9P_CHAN) {
@@ -292,25 +334,45 @@ static struct p9_trans *p9_virtio_create(const char *devname, char *args)
        up(&virtio_9p_lock);
 
        if (index >= MAX_9P_CHAN) {
-               printk(KERN_ERR "9p: virtio: couldn't find a free channel\n");
-               return NULL;
+               printk(KERN_ERR "9p: no channels available\n");
+               return ERR_PTR(-ENODEV);
        }
 
+       chan->tagpool = p9_idpool_create();
+       if (IS_ERR(chan->tagpool)) {
+               printk(KERN_ERR "9p: couldn't allocate tagpool\n");
+               return ERR_PTR(-ENOMEM);
+       }
+       p9_idpool_get(chan->tagpool); /* reserve tag 0 */
+       chan->max_tag = 0;
+       chan->reqs = NULL;
+
        trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
        if (!trans) {
                printk(KERN_ERR "9p: couldn't allocate transport\n");
                return ERR_PTR(-ENOMEM);
        }
-
-       trans->write = p9_virtio_write;
-       trans->read = p9_virtio_read;
+       trans->extended = extended;
+       trans->msize = msize;
        trans->close = p9_virtio_close;
-       trans->poll = p9_virtio_poll;
+       trans->rpc = p9_virtio_rpc;
        trans->priv = chan;
 
        return trans;
 }
 
+static void p9_virtio_remove(struct virtio_device *vdev)
+{
+       struct virtio_chan *chan = vdev->priv;
+
+       BUG_ON(chan->inuse);
+
+       if (chan->initialized) {
+               vdev->config->del_vq(chan->vq);
+               chan->initialized = false;
+       }
+}
+
 #define VIRTIO_ID_9P 9
 
 static struct virtio_device_id id_table[] = {
@@ -324,12 +386,13 @@ static struct virtio_driver p9_virtio_drv = {
        .driver.owner = THIS_MODULE,
        .id_table =     id_table,
        .probe =        p9_virtio_probe,
+       .remove =       p9_virtio_remove,
 };
 
 static struct p9_trans_module p9_virtio_trans = {
        .name = "virtio",
        .create = p9_virtio_create,
-       .maxsize = PAGE_SIZE,
+       .maxsize = PAGE_SIZE*16,
        .def = 0,
 };
 
@@ -345,7 +408,13 @@ static int __init p9_virtio_init(void)
        return register_virtio_driver(&p9_virtio_drv);
 }
 
+static void __exit p9_virtio_cleanup(void)
+{
+       unregister_virtio_driver(&p9_virtio_drv);
+}
+
 module_init(p9_virtio_init);
+module_exit(p9_virtio_cleanup);
 
 MODULE_DEVICE_TABLE(virtio, id_table);
 MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
index 22077b79395d377f7b4e54e189391531895a7d72..ef7215565d881de05e00c7214623f3a8fa759b8f 100644 (file)
@@ -33,7 +33,7 @@
 #include <net/9p/9p.h>
 
 struct p9_idpool {
-       struct semaphore lock;
+       spinlock_t lock;
        struct idr pool;
 };
 
@@ -45,7 +45,7 @@ struct p9_idpool *p9_idpool_create(void)
        if (!p)
                return ERR_PTR(-ENOMEM);
 
-       init_MUTEX(&p->lock);
+       spin_lock_init(&p->lock);
        idr_init(&p->pool);
 
        return p;
@@ -71,19 +71,17 @@ int p9_idpool_get(struct p9_idpool *p)
 {
        int i = 0;
        int error;
+       unsigned int flags;
 
 retry:
        if (idr_pre_get(&p->pool, GFP_KERNEL) == 0)
                return 0;
 
-       if (down_interruptible(&p->lock) == -EINTR) {
-               P9_EPRINTK(KERN_WARNING, "Interrupted while locking\n");
-               return -1;
-       }
+       spin_lock_irqsave(&p->lock, flags);
 
        /* no need to store exactly p, we just need something non-null */
        error = idr_get_new(&p->pool, p, &i);
-       up(&p->lock);
+       spin_unlock_irqrestore(&p->lock, flags);
 
        if (error == -EAGAIN)
                goto retry;
@@ -104,12 +102,10 @@ EXPORT_SYMBOL(p9_idpool_get);
 
 void p9_idpool_put(int id, struct p9_idpool *p)
 {
-       if (down_interruptible(&p->lock) == -EINTR) {
-               P9_EPRINTK(KERN_WARNING, "Interrupted while locking\n");
-               return;
-       }
+       unsigned int flags;
+       spin_lock_irqsave(&p->lock, flags);
        idr_remove(&p->pool, id);
-       up(&p->lock);
+       spin_unlock_irqrestore(&p->lock, flags);
 }
 EXPORT_SYMBOL(p9_idpool_put);
 
index 782a22602b86cb9bca1838ee7758adbfcd0984f6..519cdb920f936bb7882d8400bccb8105c5d0d4f5 100644 (file)
@@ -135,8 +135,8 @@ static void __hidp_copy_session(struct hidp_session *session, struct hidp_connin
        }
 }
 
-static inline int hidp_queue_event(struct hidp_session *session, struct input_dev *dev,
-                                       unsigned int type, unsigned int code, int value)
+static int hidp_queue_event(struct hidp_session *session, struct input_dev *dev,
+                               unsigned int type, unsigned int code, int value)
 {
        unsigned char newleds;
        struct sk_buff *skb;
@@ -243,7 +243,8 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
        input_sync(dev);
 }
 
-static inline int hidp_queue_report(struct hidp_session *session, unsigned char *data, int size)
+static int hidp_queue_report(struct hidp_session *session,
+                               unsigned char *data, int size)
 {
        struct sk_buff *skb;
 
@@ -287,7 +288,7 @@ static void hidp_idle_timeout(unsigned long arg)
        hidp_schedule(session);
 }
 
-static inline void hidp_set_timer(struct hidp_session *session)
+static void hidp_set_timer(struct hidp_session *session)
 {
        if (session->idle_to > 0)
                mod_timer(&session->timer, jiffies + HZ * session->idle_to);
@@ -332,7 +333,8 @@ static inline int hidp_send_ctrl_message(struct hidp_session *session,
        return err;
 }
 
-static inline void hidp_process_handshake(struct hidp_session *session, unsigned char param)
+static void hidp_process_handshake(struct hidp_session *session,
+                                       unsigned char param)
 {
        BT_DBG("session %p param 0x%02x", session, param);
 
@@ -365,38 +367,23 @@ static inline void hidp_process_handshake(struct hidp_session *session, unsigned
        }
 }
 
-static inline void hidp_process_hid_control(struct hidp_session *session, unsigned char param)
+static void hidp_process_hid_control(struct hidp_session *session,
+                                       unsigned char param)
 {
        BT_DBG("session %p param 0x%02x", session, param);
 
-       switch (param) {
-       case HIDP_CTRL_NOP:
-               break;
-
-       case HIDP_CTRL_VIRTUAL_CABLE_UNPLUG:
+       if (param == HIDP_CTRL_VIRTUAL_CABLE_UNPLUG) {
                /* Flush the transmit queues */
                skb_queue_purge(&session->ctrl_transmit);
                skb_queue_purge(&session->intr_transmit);
 
                /* Kill session thread */
                atomic_inc(&session->terminate);
-               break;
-
-       case HIDP_CTRL_HARD_RESET:
-       case HIDP_CTRL_SOFT_RESET:
-       case HIDP_CTRL_SUSPEND:
-       case HIDP_CTRL_EXIT_SUSPEND:
-               /* FIXME: We have to parse these and return no error */
-               break;
-
-       default:
-               __hidp_send_ctrl_message(session,
-                       HIDP_TRANS_HANDSHAKE | HIDP_HSHK_ERR_INVALID_PARAMETER, NULL, 0);
-               break;
        }
 }
 
-static inline void hidp_process_data(struct hidp_session *session, struct sk_buff *skb, unsigned char param)
+static void hidp_process_data(struct hidp_session *session, struct sk_buff *skb,
+                               unsigned char param)
 {
        BT_DBG("session %p skb %p len %d param 0x%02x", session, skb, skb->len, param);
 
@@ -423,7 +410,8 @@ static inline void hidp_process_data(struct hidp_session *session, struct sk_buf
        }
 }
 
-static inline void hidp_recv_ctrl_frame(struct hidp_session *session, struct sk_buff *skb)
+static void hidp_recv_ctrl_frame(struct hidp_session *session,
+                                       struct sk_buff *skb)
 {
        unsigned char hdr, type, param;
 
@@ -457,7 +445,8 @@ static inline void hidp_recv_ctrl_frame(struct hidp_session *session, struct sk_
        kfree_skb(skb);
 }
 
-static inline void hidp_recv_intr_frame(struct hidp_session *session, struct sk_buff *skb)
+static void hidp_recv_intr_frame(struct hidp_session *session,
+                               struct sk_buff *skb)
 {
        unsigned char hdr;
 
@@ -625,7 +614,8 @@ static struct device *hidp_get_device(struct hidp_session *session)
        return conn ? &conn->dev : NULL;
 }
 
-static inline int hidp_setup_input(struct hidp_session *session, struct hidp_connadd_req *req)
+static int hidp_setup_input(struct hidp_session *session,
+                               struct hidp_connadd_req *req)
 {
        struct input_dev *input = session->input;
        int i;
@@ -702,7 +692,8 @@ static void hidp_setup_quirks(struct hid_device *hid)
                        hid->quirks = hidp_blacklist[n].quirks;
 }
 
-static inline void hidp_setup_hid(struct hidp_session *session, struct hidp_connadd_req *req)
+static void hidp_setup_hid(struct hidp_session *session,
+                               struct hidp_connadd_req *req)
 {
        struct hid_device *hid = session->hid;
        struct hid_report *report;
index 788c70321858f39576867de05e4ec2c885d9445e..e4c779bb8d76e6cf9dfab3b82a3ae33f7276dc68 100644 (file)
@@ -429,7 +429,8 @@ static int rfcomm_release_dev(void __user *arg)
        if (dev->tty)
                tty_vhangup(dev->tty);
 
-       rfcomm_dev_del(dev);
+       if (!test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags))
+               rfcomm_dev_del(dev);
        rfcomm_dev_put(dev);
        return 0;
 }
index 26e941d912e8e68dd1e308e705fec2bbd92d37fc..7b660834a4c207a08b23ff6f63fa8ae719ca4fba 100644 (file)
@@ -287,7 +287,7 @@ EXPORT_SYMBOL_GPL(register_pernet_subsys);
  *     @ops: pernet operations structure to manipulate
  *
  *     Remove the pernet operations structure from the list to be
- *     used when network namespaces are created or destoryed.  In
+ *     used when network namespaces are created or destroyed.  In
  *     addition run the exit method for all existing network
  *     namespaces.
  */
@@ -335,7 +335,7 @@ EXPORT_SYMBOL_GPL(register_pernet_device);
  *     @ops: pernet operations structure to manipulate
  *
  *     Remove the pernet operations structure from the list to be
- *     used when network namespaces are created or destoryed.  In
+ *     used when network namespaces are created or destroyed.  In
  *     addition run the exit method for all existing network
  *     namespaces.
  */
index ddbdde82a700dcf46a81a05439c966182b851d8c..61ac8d06292ce32b2dbe46e92f69f50bd327c398 100644 (file)
@@ -82,32 +82,6 @@ int rtnl_trylock(void)
        return mutex_trylock(&rtnl_mutex);
 }
 
-int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len)
-{
-       memset(tb, 0, sizeof(struct rtattr*)*maxattr);
-
-       while (RTA_OK(rta, len)) {
-               unsigned flavor = rta->rta_type;
-               if (flavor && flavor <= maxattr)
-                       tb[flavor-1] = rta;
-               rta = RTA_NEXT(rta, len);
-       }
-       return 0;
-}
-
-int __rtattr_parse_nested_compat(struct rtattr *tb[], int maxattr,
-                                struct rtattr *rta, int len)
-{
-       if (RTA_PAYLOAD(rta) < len)
-               return -1;
-       if (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) {
-               rta = RTA_DATA(rta) + RTA_ALIGN(len);
-               return rtattr_parse_nested(tb, maxattr, rta);
-       }
-       memset(tb, 0, sizeof(struct rtattr *) * maxattr);
-       return 0;
-}
-
 static struct rtnl_link *rtnl_msg_handlers[NPROTO];
 
 static inline int rtm_msgindex(int msgtype)
@@ -442,21 +416,6 @@ void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data
        memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
 }
 
-size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size)
-{
-       size_t ret = RTA_PAYLOAD(rta);
-       char *src = RTA_DATA(rta);
-
-       if (ret > 0 && src[ret - 1] == '\0')
-               ret--;
-       if (size > 0) {
-               size_t len = (ret >= size) ? size - 1 : ret;
-               memset(dest, 0, size);
-               memcpy(dest, src, len);
-       }
-       return ret;
-}
-
 int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned group, int echo)
 {
        struct sock *rtnl = net->rtnl;
@@ -1411,9 +1370,6 @@ void __init rtnetlink_init(void)
 }
 
 EXPORT_SYMBOL(__rta_fill);
-EXPORT_SYMBOL(rtattr_strlcpy);
-EXPORT_SYMBOL(rtattr_parse);
-EXPORT_SYMBOL(__rtattr_parse_nested_compat);
 EXPORT_SYMBOL(rtnetlink_put_metrics);
 EXPORT_SYMBOL(rtnl_lock);
 EXPORT_SYMBOL(rtnl_trylock);
index 98420f9c4b6d3cf8e77ec27856ff0abbec10ea46..4e354221ec2338fb646bd68b19eddd956b769506 100644 (file)
@@ -2461,6 +2461,34 @@ int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)
        return elt;
 }
 
+/**
+ * skb_partial_csum_set - set up and verify partial csum values for packet
+ * @skb: the skb to set
+ * @start: the number of bytes after skb->data to start checksumming.
+ * @off: the offset from start to place the checksum.
+ *
+ * For untrusted partially-checksummed packets, we need to make sure the values
+ * for skb->csum_start and skb->csum_offset are valid so we don't oops.
+ *
+ * This function checks and sets those values and skb->ip_summed: if this
+ * returns false you should drop the packet.
+ */
+bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off)
+{
+       if (unlikely(start > skb->len - 2) ||
+           unlikely((int)start + off > skb->len - 2)) {
+               if (net_ratelimit())
+                       printk(KERN_WARNING
+                              "bad partial csum: csum=%u/%u len=%u\n",
+                              start, off, skb->len);
+               return false;
+       }
+       skb->ip_summed = CHECKSUM_PARTIAL;
+       skb->csum_start = skb_headroom(skb) + start;
+       skb->csum_offset = off;
+       return true;
+}
+
 EXPORT_SYMBOL(___pskb_trim);
 EXPORT_SYMBOL(__kfree_skb);
 EXPORT_SYMBOL(kfree_skb);
@@ -2497,3 +2525,4 @@ EXPORT_SYMBOL(skb_append_datato_frags);
 
 EXPORT_SYMBOL_GPL(skb_to_sgvec);
 EXPORT_SYMBOL_GPL(skb_cow_data);
+EXPORT_SYMBOL_GPL(skb_partial_csum_set);
index ebe59d98721a58a934b89ca1143c96b45d3dec9a..287a62bc2e0ffb40c741743026231f04b37ff176 100644 (file)
@@ -271,8 +271,6 @@ extern struct sk_buff       *dccp_make_response(struct sock *sk,
 
 extern int        dccp_connect(struct sock *sk);
 extern int        dccp_disconnect(struct sock *sk, int flags);
-extern void       dccp_hash(struct sock *sk);
-extern void       dccp_unhash(struct sock *sk);
 extern int        dccp_getsockopt(struct sock *sk, int level, int optname,
                                   char __user *optval, int __user *optlen);
 extern int        dccp_setsockopt(struct sock *sk, int level, int optname,
index c982ad88223dd6c5827116a7f362744c7e2ad3c0..474075adbde4d7c426fc960ef4079686cd185e2e 100644 (file)
  */
 static struct socket *dccp_v4_ctl_socket;
 
-static int dccp_v4_get_port(struct sock *sk, const unsigned short snum)
-{
-       return inet_csk_get_port(&dccp_hashinfo, sk, snum,
-                                inet_csk_bind_conflict);
-}
-
 int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 {
        struct inet_sock *inet = inet_sk(sk);
@@ -408,8 +402,8 @@ struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb,
 
        dccp_sync_mss(newsk, dst_mtu(dst));
 
-       __inet_hash_nolisten(&dccp_hashinfo, newsk);
-       __inet_inherit_port(&dccp_hashinfo, sk, newsk);
+       __inet_hash_nolisten(newsk);
+       __inet_inherit_port(sk, newsk);
 
        return newsk;
 
@@ -898,6 +892,7 @@ static struct inet_connection_sock_af_ops dccp_ipv4_af_ops = {
        .getsockopt        = ip_getsockopt,
        .addr2sockaddr     = inet_csk_addr2sockaddr,
        .sockaddr_len      = sizeof(struct sockaddr_in),
+       .bind_conflict     = inet_csk_bind_conflict,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_ip_setsockopt,
        .compat_getsockopt = compat_ip_getsockopt,
@@ -937,10 +932,10 @@ static struct proto dccp_v4_prot = {
        .sendmsg                = dccp_sendmsg,
        .recvmsg                = dccp_recvmsg,
        .backlog_rcv            = dccp_v4_do_rcv,
-       .hash                   = dccp_hash,
-       .unhash                 = dccp_unhash,
+       .hash                   = inet_hash,
+       .unhash                 = inet_unhash,
        .accept                 = inet_csk_accept,
-       .get_port               = dccp_v4_get_port,
+       .get_port               = inet_csk_get_port,
        .shutdown               = dccp_shutdown,
        .destroy                = dccp_destroy_sock,
        .orphan_count           = &dccp_orphan_count,
@@ -948,6 +943,7 @@ static struct proto dccp_v4_prot = {
        .obj_size               = sizeof(struct dccp_sock),
        .rsk_prot               = &dccp_request_sock_ops,
        .twsk_prot              = &dccp_timewait_sock_ops,
+       .hashinfo               = &dccp_hashinfo,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt      = compat_dccp_setsockopt,
        .compat_getsockopt      = compat_dccp_getsockopt,
index ed0a0053a797ffdf74d9e07b8f9fdfdabd04a62c..490333d47c7b04dda8a6660cab945988626a86ce 100644 (file)
@@ -39,21 +39,15 @@ static struct socket *dccp_v6_ctl_socket;
 static struct inet_connection_sock_af_ops dccp_ipv6_mapped;
 static struct inet_connection_sock_af_ops dccp_ipv6_af_ops;
 
-static int dccp_v6_get_port(struct sock *sk, unsigned short snum)
-{
-       return inet_csk_get_port(&dccp_hashinfo, sk, snum,
-                                inet6_csk_bind_conflict);
-}
-
 static void dccp_v6_hash(struct sock *sk)
 {
        if (sk->sk_state != DCCP_CLOSED) {
                if (inet_csk(sk)->icsk_af_ops == &dccp_ipv6_mapped) {
-                       dccp_hash(sk);
+                       inet_hash(sk);
                        return;
                }
                local_bh_disable();
-               __inet6_hash(&dccp_hashinfo, sk);
+               __inet6_hash(sk);
                local_bh_enable();
        }
 }
@@ -630,8 +624,8 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
 
        newinet->daddr = newinet->saddr = newinet->rcv_saddr = LOOPBACK4_IPV6;
 
-       __inet6_hash(&dccp_hashinfo, newsk);
-       inet_inherit_port(&dccp_hashinfo, sk, newsk);
+       __inet6_hash(newsk);
+       inet_inherit_port(sk, newsk);
 
        return newsk;
 
@@ -1054,6 +1048,7 @@ static struct inet_connection_sock_af_ops dccp_ipv6_af_ops = {
        .getsockopt        = ipv6_getsockopt,
        .addr2sockaddr     = inet6_csk_addr2sockaddr,
        .sockaddr_len      = sizeof(struct sockaddr_in6),
+       .bind_conflict     = inet6_csk_bind_conflict,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_ipv6_setsockopt,
        .compat_getsockopt = compat_ipv6_getsockopt,
@@ -1123,9 +1118,9 @@ static struct proto dccp_v6_prot = {
        .recvmsg           = dccp_recvmsg,
        .backlog_rcv       = dccp_v6_do_rcv,
        .hash              = dccp_v6_hash,
-       .unhash            = dccp_unhash,
+       .unhash            = inet_unhash,
        .accept            = inet_csk_accept,
-       .get_port          = dccp_v6_get_port,
+       .get_port          = inet_csk_get_port,
        .shutdown          = dccp_shutdown,
        .destroy           = dccp_v6_destroy_sock,
        .orphan_count      = &dccp_orphan_count,
@@ -1133,6 +1128,7 @@ static struct proto dccp_v6_prot = {
        .obj_size          = sizeof(struct dccp6_sock),
        .rsk_prot          = &dccp6_request_sock_ops,
        .twsk_prot         = &dccp6_timewait_sock_ops,
+       .hashinfo          = &dccp_hashinfo,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_dccp_setsockopt,
        .compat_getsockopt = compat_dccp_getsockopt,
index 0bed4a6095b7afd4f84ec179daefcf1285371a8c..e3f5d37b84be1817f2b69b0fe31c65e999ceb05d 100644 (file)
@@ -78,7 +78,7 @@ void dccp_set_state(struct sock *sk, const int state)
                sk->sk_prot->unhash(sk);
                if (inet_csk(sk)->icsk_bind_hash != NULL &&
                    !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
-                       inet_put_port(&dccp_hashinfo, sk);
+                       inet_put_port(sk);
                /* fall through */
        default:
                if (oldstate == DCCP_OPEN)
@@ -173,20 +173,6 @@ const char *dccp_state_name(const int state)
 
 EXPORT_SYMBOL_GPL(dccp_state_name);
 
-void dccp_hash(struct sock *sk)
-{
-       inet_hash(&dccp_hashinfo, sk);
-}
-
-EXPORT_SYMBOL_GPL(dccp_hash);
-
-void dccp_unhash(struct sock *sk)
-{
-       inet_unhash(&dccp_hashinfo, sk);
-}
-
-EXPORT_SYMBOL_GPL(dccp_unhash);
-
 int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
 {
        struct dccp_sock *dp = dccp_sk(sk);
@@ -268,7 +254,7 @@ int dccp_destroy_sock(struct sock *sk)
 
        /* Clean up a referenced DCCP bind bucket. */
        if (inet_csk(sk)->icsk_bind_hash != NULL)
-               inet_put_port(&dccp_hashinfo, sk);
+               inet_put_port(sk);
 
        kfree(dp->dccps_service_list);
        dp->dccps_service_list = NULL;
index a2241060113be3d47d9a3f88919e8b5b8c5a9f4a..8cd357f41283504f98e55d7a3ffe2d9090dbcd38 100644 (file)
@@ -547,8 +547,8 @@ int cipso_v4_doi_remove(u32 doi,
                rcu_read_lock();
                list_for_each_entry_rcu(dom_iter, &doi_def->dom_list, list)
                        if (dom_iter->valid)
-                               netlbl_domhsh_remove(dom_iter->domain,
-                                                    audit_info);
+                               netlbl_cfg_map_del(dom_iter->domain,
+                                                  audit_info);
                rcu_read_unlock();
                cipso_v4_cache_invalidate();
                call_rcu(&doi_def->rcu, callback);
index 35851c96bdfb2e6f00eb3681b4d9a090a0163a42..f5fba3f71c06e09283a29d48f2719bc9ad1be15b 100644 (file)
@@ -2431,8 +2431,7 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v)
                                           rtn_type(buf2, sizeof(buf2),
                                                    fa->fa_type));
                                if (fa->fa_tos)
-                                       seq_printf(seq, "tos =%d\n",
-                                                  fa->fa_tos);
+                                       seq_printf(seq, " tos=%d", fa->fa_tos);
                                seq_putc(seq, '\n');
                        }
                }
index a7321a82df6d24b3a1921d3918c23412b4271a4c..a13c074dac091e21fb1bb3cb1c77715ded13a5c2 100644 (file)
@@ -1015,7 +1015,8 @@ int icmp_rcv(struct sk_buff *skb)
                        goto error;
        }
 
-       __skb_pull(skb, sizeof(*icmph));
+       if (!pskb_pull(skb, sizeof(*icmph)))
+               goto error;
 
        icmph = icmp_hdr(skb);
 
index de5a41de191a675e69701fd5416bda497da62aaf..b189278c7bc180a882b1ebb30ecd19ca19010199 100644 (file)
@@ -78,11 +78,9 @@ EXPORT_SYMBOL_GPL(inet_csk_bind_conflict);
 /* Obtain a reference to a local port for the given sock,
  * if snum is zero it means select any available local port.
  */
-int inet_csk_get_port(struct inet_hashinfo *hashinfo,
-                     struct sock *sk, unsigned short snum,
-                     int (*bind_conflict)(const struct sock *sk,
-                                          const struct inet_bind_bucket *tb))
+int inet_csk_get_port(struct sock *sk, unsigned short snum)
 {
+       struct inet_hashinfo *hashinfo = sk->sk_prot->hashinfo;
        struct inet_bind_hashbucket *head;
        struct hlist_node *node;
        struct inet_bind_bucket *tb;
@@ -142,7 +140,7 @@ tb_found:
                        goto success;
                } else {
                        ret = 1;
-                       if (bind_conflict(sk, tb))
+                       if (inet_csk(sk)->icsk_af_ops->bind_conflict(sk, tb))
                                goto fail_unlock;
                }
        }
index 48d45008f749664699856fa9d7ee8b465f4377c2..9cac6c034abd98335fa2d8d43539d13bd4d627c9 100644 (file)
@@ -66,8 +66,9 @@ void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
 /*
  * Get rid of any references to a local port held by the given sock.
  */
-static void __inet_put_port(struct inet_hashinfo *hashinfo, struct sock *sk)
+static void __inet_put_port(struct sock *sk)
 {
+       struct inet_hashinfo *hashinfo = sk->sk_prot->hashinfo;
        const int bhash = inet_bhashfn(inet_sk(sk)->num, hashinfo->bhash_size);
        struct inet_bind_hashbucket *head = &hashinfo->bhash[bhash];
        struct inet_bind_bucket *tb;
@@ -81,10 +82,10 @@ static void __inet_put_port(struct inet_hashinfo *hashinfo, struct sock *sk)
        spin_unlock(&head->lock);
 }
 
-void inet_put_port(struct inet_hashinfo *hashinfo, struct sock *sk)
+void inet_put_port(struct sock *sk)
 {
        local_bh_disable();
-       __inet_put_port(hashinfo, sk);
+       __inet_put_port(sk);
        local_bh_enable();
 }
 
@@ -317,8 +318,9 @@ static inline u32 inet_sk_port_offset(const struct sock *sk)
                                          inet->dport);
 }
 
-void __inet_hash_nolisten(struct inet_hashinfo *hashinfo, struct sock *sk)
+void __inet_hash_nolisten(struct sock *sk)
 {
+       struct inet_hashinfo *hashinfo = sk->sk_prot->hashinfo;
        struct hlist_head *list;
        rwlock_t *lock;
        struct inet_ehash_bucket *head;
@@ -337,13 +339,14 @@ void __inet_hash_nolisten(struct inet_hashinfo *hashinfo, struct sock *sk)
 }
 EXPORT_SYMBOL_GPL(__inet_hash_nolisten);
 
-void __inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk)
+static void __inet_hash(struct sock *sk)
 {
+       struct inet_hashinfo *hashinfo = sk->sk_prot->hashinfo;
        struct hlist_head *list;
        rwlock_t *lock;
 
        if (sk->sk_state != TCP_LISTEN) {
-               __inet_hash_nolisten(hashinfo, sk);
+               __inet_hash_nolisten(sk);
                return;
        }
 
@@ -357,13 +360,48 @@ void __inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk)
        write_unlock(lock);
        wake_up(&hashinfo->lhash_wait);
 }
-EXPORT_SYMBOL_GPL(__inet_hash);
+
+void inet_hash(struct sock *sk)
+{
+       if (sk->sk_state != TCP_CLOSE) {
+               local_bh_disable();
+               __inet_hash(sk);
+               local_bh_enable();
+       }
+}
+EXPORT_SYMBOL_GPL(inet_hash);
+
+void inet_unhash(struct sock *sk)
+{
+       rwlock_t *lock;
+       struct inet_hashinfo *hashinfo = sk->sk_prot->hashinfo;
+
+       if (sk_unhashed(sk))
+               goto out;
+
+       if (sk->sk_state == TCP_LISTEN) {
+               local_bh_disable();
+               inet_listen_wlock(hashinfo);
+               lock = &hashinfo->lhash_lock;
+       } else {
+               lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
+               write_lock_bh(lock);
+       }
+
+       if (__sk_del_node_init(sk))
+               sock_prot_inuse_add(sk->sk_prot, -1);
+       write_unlock_bh(lock);
+out:
+       if (sk->sk_state == TCP_LISTEN)
+               wake_up(&hashinfo->lhash_wait);
+}
+EXPORT_SYMBOL_GPL(inet_unhash);
 
 int __inet_hash_connect(struct inet_timewait_death_row *death_row,
-               struct sock *sk,
+               struct sock *sk, u32 port_offset,
                int (*check_established)(struct inet_timewait_death_row *,
                        struct sock *, __u16, struct inet_timewait_sock **),
-               void (*hash)(struct inet_hashinfo *, struct sock *))
+               void (*hash)(struct sock *sk))
 {
        struct inet_hashinfo *hinfo = death_row->hashinfo;
        const unsigned short snum = inet_sk(sk)->num;
@@ -375,7 +413,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
        if (!snum) {
                int i, remaining, low, high, port;
                static u32 hint;
-               u32 offset = hint + inet_sk_port_offset(sk);
+               u32 offset = hint + port_offset;
                struct hlist_node *node;
                struct inet_timewait_sock *tw = NULL;
 
@@ -427,7 +465,7 @@ ok:
                inet_bind_hash(sk, tb, port);
                if (sk_unhashed(sk)) {
                        inet_sk(sk)->sport = htons(port);
-                       hash(hinfo, sk);
+                       hash(sk);
                }
                spin_unlock(&head->lock);
 
@@ -444,7 +482,7 @@ ok:
        tb  = inet_csk(sk)->icsk_bind_hash;
        spin_lock_bh(&head->lock);
        if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) {
-               hash(hinfo, sk);
+               hash(sk);
                spin_unlock_bh(&head->lock);
                return 0;
        } else {
@@ -464,7 +502,7 @@ EXPORT_SYMBOL_GPL(__inet_hash_connect);
 int inet_hash_connect(struct inet_timewait_death_row *death_row,
                      struct sock *sk)
 {
-       return __inet_hash_connect(death_row, sk,
+       return __inet_hash_connect(death_row, sk, inet_sk_port_offset(sk),
                        __inet_check_established, __inet_hash_nolisten);
 }
 
index 749fa044eca53cb6ecda61e8019045d04705973c..85c680add6dfd1fe23cc997265b68eb8ca9b309f 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/net.h>
 
 #include <net/ip_vs.h>
 
@@ -169,7 +170,7 @@ ip_vs_wrr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
                                 */
                                if (mark->cw == 0) {
                                        mark->cl = &svc->destinations;
-                                       IP_VS_INFO("ip_vs_wrr_schedule(): "
+                                       IP_VS_ERR_RL("ip_vs_wrr_schedule(): "
                                                   "no available servers\n");
                                        dest = NULL;
                                        goto out;
index a0d373bd906588276f2f8eef8aaab93a31d1fb31..071e83a894ad9c02081f24b9ba243c77f7ea8d7c 100644 (file)
@@ -1669,7 +1669,7 @@ void tcp_set_state(struct sock *sk, int state)
                sk->sk_prot->unhash(sk);
                if (inet_csk(sk)->icsk_bind_hash &&
                    !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
-                       inet_put_port(&tcp_hashinfo, sk);
+                       inet_put_port(sk);
                /* fall through */
        default:
                if (oldstate==TCP_ESTABLISHED)
index 77c1939a2b0d50b2dee673fa450a410cd82bc9c9..63414ea427c578d9a9b1cb527cd87e4cc53ef5f3 100644 (file)
@@ -108,22 +108,6 @@ struct inet_hashinfo __cacheline_aligned tcp_hashinfo = {
        .lhash_wait  = __WAIT_QUEUE_HEAD_INITIALIZER(tcp_hashinfo.lhash_wait),
 };
 
-static int tcp_v4_get_port(struct sock *sk, unsigned short snum)
-{
-       return inet_csk_get_port(&tcp_hashinfo, sk, snum,
-                                inet_csk_bind_conflict);
-}
-
-static void tcp_v4_hash(struct sock *sk)
-{
-       inet_hash(&tcp_hashinfo, sk);
-}
-
-void tcp_unhash(struct sock *sk)
-{
-       inet_unhash(&tcp_hashinfo, sk);
-}
-
 static inline __u32 tcp_v4_init_sequence(struct sk_buff *skb)
 {
        return secure_tcp_sequence_number(ip_hdr(skb)->daddr,
@@ -1478,8 +1462,8 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
        }
 #endif
 
-       __inet_hash_nolisten(&tcp_hashinfo, newsk);
-       __inet_inherit_port(&tcp_hashinfo, sk, newsk);
+       __inet_hash_nolisten(newsk);
+       __inet_inherit_port(sk, newsk);
 
        return newsk;
 
@@ -1827,6 +1811,7 @@ struct inet_connection_sock_af_ops ipv4_specific = {
        .getsockopt        = ip_getsockopt,
        .addr2sockaddr     = inet_csk_addr2sockaddr,
        .sockaddr_len      = sizeof(struct sockaddr_in),
+       .bind_conflict     = inet_csk_bind_conflict,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_ip_setsockopt,
        .compat_getsockopt = compat_ip_getsockopt,
@@ -1926,7 +1911,7 @@ int tcp_v4_destroy_sock(struct sock *sk)
 
        /* Clean up a referenced TCP bind bucket. */
        if (inet_csk(sk)->icsk_bind_hash)
-               inet_put_port(&tcp_hashinfo, sk);
+               inet_put_port(sk);
 
        /*
         * If sendmsg cached page exists, toss it.
@@ -2435,9 +2420,9 @@ struct proto tcp_prot = {
        .getsockopt             = tcp_getsockopt,
        .recvmsg                = tcp_recvmsg,
        .backlog_rcv            = tcp_v4_do_rcv,
-       .hash                   = tcp_v4_hash,
-       .unhash                 = tcp_unhash,
-       .get_port               = tcp_v4_get_port,
+       .hash                   = inet_hash,
+       .unhash                 = inet_unhash,
+       .get_port               = inet_csk_get_port,
        .enter_memory_pressure  = tcp_enter_memory_pressure,
        .sockets_allocated      = &tcp_sockets_allocated,
        .orphan_count           = &tcp_orphan_count,
@@ -2450,6 +2435,7 @@ struct proto tcp_prot = {
        .obj_size               = sizeof(struct tcp_sock),
        .twsk_prot              = &tcp_timewait_sock_ops,
        .rsk_prot               = &tcp_request_sock_ops,
+       .hashinfo               = &tcp_hashinfo,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt      = compat_tcp_setsockopt,
        .compat_getsockopt      = compat_tcp_getsockopt,
@@ -2467,7 +2453,6 @@ void __init tcp_v4_init(struct net_proto_family *ops)
 EXPORT_SYMBOL(ipv4_specific);
 EXPORT_SYMBOL(tcp_hashinfo);
 EXPORT_SYMBOL(tcp_prot);
-EXPORT_SYMBOL(tcp_unhash);
 EXPORT_SYMBOL(tcp_v4_conn_request);
 EXPORT_SYMBOL(tcp_v4_connect);
 EXPORT_SYMBOL(tcp_v4_do_rcv);
index e093a7b59e18af38cf918aed2754159cf68db8fd..b47030ba162bc97df715d11fc779f59df1db16e5 100644 (file)
@@ -102,7 +102,7 @@ static int xfrm4_beet_input(struct xfrm_state *x, struct sk_buff *skb)
 
                XFRM_MODE_SKB_CB(skb)->protocol = ph->nexthdr;
 
-               if (!pskb_may_pull(skb, phlen));
+               if (!pskb_may_pull(skb, phlen))
                        goto out;
                __skb_pull(skb, phlen);
        }
index cbb5b9cf84ad36eba8741bec98cb2409040d3c93..121d517bf91c9d16467c5aa85df47efdd0b6c58e 100644 (file)
@@ -683,7 +683,8 @@ static int icmpv6_rcv(struct sk_buff *skb)
                }
        }
 
-       __skb_pull(skb, sizeof(*hdr));
+       if (!pskb_pull(skb, sizeof(*hdr)))
+               goto discard_it;
 
        hdr = icmp6_hdr(skb);
 
index d325a995890911ec0f4418c2f00f0034231111e0..99fd25f7f005879ec28b78b6af51890c7abb5fd8 100644 (file)
@@ -22,9 +22,9 @@
 #include <net/inet6_hashtables.h>
 #include <net/ip.h>
 
-void __inet6_hash(struct inet_hashinfo *hashinfo,
-                               struct sock *sk)
+void __inet6_hash(struct sock *sk)
 {
+       struct inet_hashinfo *hashinfo = sk->sk_prot->hashinfo;
        struct hlist_head *list;
        rwlock_t *lock;
 
@@ -236,7 +236,7 @@ static inline u32 inet6_sk_port_offset(const struct sock *sk)
 int inet6_hash_connect(struct inet_timewait_death_row *death_row,
                       struct sock *sk)
 {
-       return __inet_hash_connect(death_row, sk,
+       return __inet_hash_connect(death_row, sk, inet6_sk_port_offset(sk),
                        __inet6_check_established, __inet6_hash);
 }
 
index 59d0029e93a7b3f6123a0a7353eee918e1bd425b..12750f2b05ab02ff6846b64a1d880cfd9402322e 100644 (file)
@@ -86,12 +86,6 @@ static struct tcp_sock_af_ops tcp_sock_ipv6_specific;
 static struct tcp_sock_af_ops tcp_sock_ipv6_mapped_specific;
 #endif
 
-static int tcp_v6_get_port(struct sock *sk, unsigned short snum)
-{
-       return inet_csk_get_port(&tcp_hashinfo, sk, snum,
-                                inet6_csk_bind_conflict);
-}
-
 static void tcp_v6_hash(struct sock *sk)
 {
        if (sk->sk_state != TCP_CLOSE) {
@@ -100,7 +94,7 @@ static void tcp_v6_hash(struct sock *sk)
                        return;
                }
                local_bh_disable();
-               __inet6_hash(&tcp_hashinfo, sk);
+               __inet6_hash(sk);
                local_bh_enable();
        }
 }
@@ -1504,8 +1498,8 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
        }
 #endif
 
-       __inet6_hash(&tcp_hashinfo, newsk);
-       inet_inherit_port(&tcp_hashinfo, sk, newsk);
+       __inet6_hash(newsk);
+       inet_inherit_port(sk, newsk);
 
        return newsk;
 
@@ -1833,6 +1827,7 @@ static struct inet_connection_sock_af_ops ipv6_specific = {
        .getsockopt        = ipv6_getsockopt,
        .addr2sockaddr     = inet6_csk_addr2sockaddr,
        .sockaddr_len      = sizeof(struct sockaddr_in6),
+       .bind_conflict     = inet6_csk_bind_conflict,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_ipv6_setsockopt,
        .compat_getsockopt = compat_ipv6_getsockopt,
@@ -1864,6 +1859,7 @@ static struct inet_connection_sock_af_ops ipv6_mapped = {
        .getsockopt        = ipv6_getsockopt,
        .addr2sockaddr     = inet6_csk_addr2sockaddr,
        .sockaddr_len      = sizeof(struct sockaddr_in6),
+       .bind_conflict     = inet6_csk_bind_conflict,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_ipv6_setsockopt,
        .compat_getsockopt = compat_ipv6_getsockopt,
@@ -2127,8 +2123,8 @@ struct proto tcpv6_prot = {
        .recvmsg                = tcp_recvmsg,
        .backlog_rcv            = tcp_v6_do_rcv,
        .hash                   = tcp_v6_hash,
-       .unhash                 = tcp_unhash,
-       .get_port               = tcp_v6_get_port,
+       .unhash                 = inet_unhash,
+       .get_port               = inet_csk_get_port,
        .enter_memory_pressure  = tcp_enter_memory_pressure,
        .sockets_allocated      = &tcp_sockets_allocated,
        .memory_allocated       = &tcp_memory_allocated,
@@ -2141,6 +2137,7 @@ struct proto tcpv6_prot = {
        .obj_size               = sizeof(struct tcp6_sock),
        .twsk_prot              = &tcp6_timewait_sock_ops,
        .rsk_prot               = &tcp6_request_sock_ops,
+       .hashinfo               = &tcp_hashinfo,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt      = compat_tcp_setsockopt,
        .compat_getsockopt      = compat_tcp_getsockopt,
index 09c255002e565dcba6606937d0c1a14409537212..45c7c0c3875e808beb1ad1085a213955d6ca8235 100644 (file)
@@ -1,6 +1,5 @@
 config MAC80211
        tristate "Generic IEEE 802.11 Networking Stack (mac80211)"
-       depends on EXPERIMENTAL
        select CRYPTO
        select CRYPTO_ECB
        select CRYPTO_ARC4
@@ -98,6 +97,18 @@ config MAC80211_DEBUGFS
 
          Say N unless you know you need this.
 
+config MAC80211_DEBUG_PACKET_ALIGNMENT
+       bool "Enable packet alignment debugging"
+       depends on MAC80211
+       help
+         This option is recommended for driver authors and strongly
+         discouraged for everybody else, it will trigger a warning
+         when a driver hands mac80211 a buffer that is aligned in
+         a way that will cause problems with the IP stack on some
+         architectures.
+
+         Say N unless you're writing a mac80211 based driver.
+
 config MAC80211_DEBUG
        bool "Enable debugging output"
        depends on MAC80211
index 5dcc2d61551fe2260f5a39e6fe323669b705323b..67b7c75c430d337e0ddfdc5e8a33dac498b60472 100644 (file)
@@ -1344,17 +1344,17 @@ static int __init ieee80211_init(void)
 
        ret = rc80211_simple_init();
        if (ret)
-               goto fail;
+               goto out;
 
        ret = rc80211_pid_init();
        if (ret)
-               goto fail_simple;
+               goto out_cleanup_simple;
 
        ret = ieee80211_wme_register();
        if (ret) {
                printk(KERN_DEBUG "ieee80211_init: failed to "
                       "initialize WME (err=%d)\n", ret);
-               goto fail_pid;
+               goto out_cleanup_pid;
        }
 
        ieee80211_debugfs_netdev_init();
@@ -1362,11 +1362,11 @@ static int __init ieee80211_init(void)
 
        return 0;
 
- fail_pid:
-       rc80211_simple_exit();
- fail_simple:
+ out_cleanup_pid:
        rc80211_pid_exit();
- fail:
+ out_cleanup_simple:
+       rc80211_simple_exit();
+ out:
        return ret;
 }
 
index 554c4baed6fbd3d4bdb164eaeea024fcf919bcfb..c339571632b2f102fdc8a81a8416fb71826ccf98 100644 (file)
@@ -538,7 +538,7 @@ int __init rc80211_pid_init(void)
        return ieee80211_rate_control_register(&mac80211_rcpid);
 }
 
-void __exit rc80211_pid_exit(void)
+void rc80211_pid_exit(void)
 {
        ieee80211_rate_control_unregister(&mac80211_rcpid);
 }
index 934676d687d6f9b674c837181603b91e4aad2a6f..9a78b116acffbdca0b00ba2df579ce87ec6cd2f2 100644 (file)
@@ -389,7 +389,7 @@ int __init rc80211_simple_init(void)
        return ieee80211_rate_control_register(&mac80211_rcsimple);
 }
 
-void __exit rc80211_simple_exit(void)
+void rc80211_simple_exit(void)
 {
        ieee80211_rate_control_unregister(&mac80211_rcsimple);
 }
index d44c87269bcb782d697e0370ef21fcc3c2ea15e4..535407d07fa40890a4731648f85157a00fb39dc8 100644 (file)
@@ -340,11 +340,15 @@ static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
        return load;
 }
 
+#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
 static ieee80211_txrx_result
 ieee80211_rx_h_verify_ip_alignment(struct ieee80211_txrx_data *rx)
 {
        int hdrlen;
 
+       if (!WLAN_FC_DATA_PRESENT(rx->fc))
+               return TXRX_CONTINUE;
+
        /*
         * Drivers are required to align the payload data in a way that
         * guarantees that the contained IP header is aligned to a four-
@@ -371,11 +375,14 @@ ieee80211_rx_h_verify_ip_alignment(struct ieee80211_txrx_data *rx)
 
        return TXRX_CONTINUE;
 }
+#endif
 
 ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
 {
        ieee80211_rx_h_parse_qos,
+#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
        ieee80211_rx_h_verify_ip_alignment,
+#endif
        NULL
 };
 
index becf91a952aeca035f0d060eac857850c854112e..c7ad64d664ad21a7dbe45f3ee539793329dce2f4 100644 (file)
@@ -90,7 +90,7 @@ static const struct nla_policy netlbl_cipsov4_genl_policy[NLBL_CIPSOV4_A_MAX + 1
  * safely.
  *
  */
-static void netlbl_cipsov4_doi_free(struct rcu_head *entry)
+void netlbl_cipsov4_doi_free(struct rcu_head *entry)
 {
        struct cipso_v4_doi *ptr;
 
index f03cf9b78286fe920c17e68dd0ebe02190979b3a..220cb9d06b496d315d30c1041a03525421b4a9e2 100644 (file)
@@ -163,4 +163,7 @@ enum {
 /* NetLabel protocol functions */
 int netlbl_cipsov4_genl_init(void);
 
+/* Free the memory associated with a CIPSOv4 DOI definition */
+void netlbl_cipsov4_doi_free(struct rcu_head *entry);
+
 #endif
index 3689956c34363242007d300b0865c53a0da867d5..8220990ceb967a0480421e82c465490fab3983b8 100644 (file)
@@ -61,6 +61,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,
                      struct netlbl_audit *audit_info);
 int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
                              struct netlbl_audit *audit_info);
+int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info);
 int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info);
 struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain);
 int netlbl_domhsh_walk(u32 *skip_bkt,
index c69e3e1f05c3957ab076a75bd84bc40a87a87578..39793a1a93aaba375a6bf7382081c245b197e38b 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <linux/init.h>
 #include <linux/types.h>
+#include <linux/audit.h>
 #include <net/ip.h>
 #include <net/netlabel.h>
 #include <net/cipso_ipv4.h>
 
 #include "netlabel_domainhash.h"
 #include "netlabel_unlabeled.h"
+#include "netlabel_cipso_v4.h"
 #include "netlabel_user.h"
 #include "netlabel_mgmt.h"
 
+/*
+ * Configuration Functions
+ */
+
+/**
+ * netlbl_cfg_map_del - Remove a NetLabel/LSM domain mapping
+ * @domain: the domain mapping to remove
+ * @audit_info: NetLabel audit information
+ *
+ * Description:
+ * Removes a NetLabel/LSM domain mapping.  A @domain value of NULL causes the
+ * default domain mapping to be removed.  Returns zero on success, negative
+ * values on failure.
+ *
+ */
+int netlbl_cfg_map_del(const char *domain, struct netlbl_audit *audit_info)
+{
+       return netlbl_domhsh_remove(domain, audit_info);
+}
+
+/**
+ * netlbl_cfg_unlbl_add_map - Add an unlabeled NetLabel/LSM domain mapping
+ * @domain: the domain mapping to add
+ * @audit_info: NetLabel audit information
+ *
+ * Description:
+ * Adds a new unlabeled NetLabel/LSM domain mapping.  A @domain value of NULL
+ * causes a new default domain mapping to be added.  Returns zero on success,
+ * negative values on failure.
+ *
+ */
+int netlbl_cfg_unlbl_add_map(const char *domain,
+                            struct netlbl_audit *audit_info)
+{
+       int ret_val = -ENOMEM;
+       struct netlbl_dom_map *entry;
+
+       entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
+       if (entry == NULL)
+               goto cfg_unlbl_add_map_failure;
+       if (domain != NULL) {
+               entry->domain = kstrdup(domain, GFP_ATOMIC);
+               if (entry->domain == NULL)
+                       goto cfg_unlbl_add_map_failure;
+       }
+       entry->type = NETLBL_NLTYPE_UNLABELED;
+
+       ret_val = netlbl_domhsh_add(entry, audit_info);
+       if (ret_val != 0)
+               goto cfg_unlbl_add_map_failure;
+
+       return 0;
+
+cfg_unlbl_add_map_failure:
+       if (entry != NULL)
+               kfree(entry->domain);
+       kfree(entry);
+       return ret_val;
+}
+
+/**
+ * netlbl_cfg_cipsov4_add - Add a new CIPSOv4 DOI definition
+ * @doi_def: the DOI definition
+ * @audit_info: NetLabel audit information
+ *
+ * Description:
+ * Add a new CIPSOv4 DOI definition to the NetLabel subsystem.  Returns zero on
+ * success, negative values on failure.
+ *
+ */
+int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def,
+                          struct netlbl_audit *audit_info)
+{
+       int ret_val;
+       const char *type_str;
+       struct audit_buffer *audit_buf;
+
+       ret_val = cipso_v4_doi_add(doi_def);
+
+       audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_ADD,
+                                             audit_info);
+       if (audit_buf != NULL) {
+               switch (doi_def->type) {
+               case CIPSO_V4_MAP_STD:
+                       type_str = "std";
+                       break;
+               case CIPSO_V4_MAP_PASS:
+                       type_str = "pass";
+                       break;
+               default:
+                       type_str = "(unknown)";
+               }
+               audit_log_format(audit_buf,
+                                " cipso_doi=%u cipso_type=%s res=%u",
+                                doi_def->doi,
+                                type_str,
+                                ret_val == 0 ? 1 : 0);
+               audit_log_end(audit_buf);
+       }
+
+       return ret_val;
+}
+
+/**
+ * netlbl_cfg_cipsov4_add_map - Add a new CIPSOv4 DOI definition and mapping
+ * @doi_def: the DOI definition
+ * @domain: the domain mapping to add
+ * @audit_info: NetLabel audit information
+ *
+ * Description:
+ * Add a new CIPSOv4 DOI definition and NetLabel/LSM domain mapping for this
+ * new DOI definition to the NetLabel subsystem.  A @domain value of NULL adds
+ * a new default domain mapping.  Returns zero on success, negative values on
+ * failure.
+ *
+ */
+int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def,
+                              const char *domain,
+                              struct netlbl_audit *audit_info)
+{
+       int ret_val = -ENOMEM;
+       struct netlbl_dom_map *entry;
+
+       entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
+       if (entry == NULL)
+               goto cfg_cipsov4_add_map_failure;
+       if (domain != NULL) {
+               entry->domain = kstrdup(domain, GFP_ATOMIC);
+               if (entry->domain == NULL)
+                       goto cfg_cipsov4_add_map_failure;
+       }
+       entry->type = NETLBL_NLTYPE_CIPSOV4;
+       entry->type_def.cipsov4 = doi_def;
+
+       /* Grab a RCU read lock here so nothing happens to the doi_def variable
+        * between adding it to the CIPSOv4 protocol engine and adding a
+        * domain mapping for it. */
+
+       rcu_read_lock();
+       ret_val = netlbl_cfg_cipsov4_add(doi_def, audit_info);
+       if (ret_val != 0)
+               goto cfg_cipsov4_add_map_failure_unlock;
+       ret_val = netlbl_domhsh_add(entry, audit_info);
+       if (ret_val != 0)
+               goto cfg_cipsov4_add_map_failure_remove_doi;
+       rcu_read_unlock();
+
+       return 0;
+
+cfg_cipsov4_add_map_failure_remove_doi:
+       cipso_v4_doi_remove(doi_def->doi, audit_info, netlbl_cipsov4_doi_free);
+cfg_cipsov4_add_map_failure_unlock:
+       rcu_read_unlock();
+cfg_cipsov4_add_map_failure:
+       if (entry != NULL)
+               kfree(entry->domain);
+       kfree(entry);
+       return ret_val;
+}
+
+/**
+ * netlbl_cfg_cipsov4_del - Removean existing CIPSOv4 DOI definition
+ * @doi: the CIPSO DOI value
+ * @audit_info: NetLabel audit information
+ *
+ * Description:
+ * Removes an existing CIPSOv4 DOI definition from the NetLabel subsystem.
+ * Returns zero on success, negative values on failure.
+ *
+ */
+int netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info)
+{
+       return cipso_v4_doi_remove(doi, audit_info, netlbl_cipsov4_doi_free);
+}
+
 /*
  * Security Attribute Functions
  */
index 6562f868e82f07d7ce70169ef2920c41c07c1ae6..1a47f5d1be17c42814d83f705bd375de497c2b80 100644 (file)
@@ -340,7 +340,7 @@ EXPORT_SYMBOL(rfkill_allocate);
  * rfkill_free - Mark rfkill structure for deletion
  * @rfkill: rfkill structure to be destroyed
  *
- * Decrements reference count of rfkill structure so it is destoryed.
+ * Decrements reference count of rfkill structure so it is destroyed.
  * Note that rfkill_free() should _not_ be called after rfkill_unregister().
  */
 void rfkill_free(struct rfkill *rfkill)
index 5a7f6a3060fc3a3ad4237c4bd0704e74b68d1b07..971b867e0484fd8d50ec0d60e56109e8f54b02f4 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/in.h>
 #include <linux/ip.h>
 #include <linux/ipv6.h>
+#include <linux/if_vlan.h>
 
 #include <net/pkt_cls.h>
 #include <net/ip.h>
@@ -270,6 +271,15 @@ static u32 flow_get_skgid(const struct sk_buff *skb)
        return 0;
 }
 
+static u32 flow_get_vlan_tag(const struct sk_buff *skb)
+{
+       u16 uninitialized_var(tag);
+
+       if (vlan_get_tag(skb, &tag) < 0)
+               return 0;
+       return tag & VLAN_VID_MASK;
+}
+
 static u32 flow_key_get(const struct sk_buff *skb, int key)
 {
        switch (key) {
@@ -305,6 +315,8 @@ static u32 flow_key_get(const struct sk_buff *skb, int key)
                return flow_get_skuid(skb);
        case FLOW_KEY_SKGID:
                return flow_get_skgid(skb);
+       case FLOW_KEY_VLAN_TAG:
+               return flow_get_vlan_tag(skb);
        default:
                WARN_ON(1);
                return 0;
@@ -402,12 +414,13 @@ static int flow_change(struct tcf_proto *tp, unsigned long base,
 
        if (tb[TCA_FLOW_KEYS]) {
                keymask = nla_get_u32(tb[TCA_FLOW_KEYS]);
-               if (fls(keymask) - 1 > FLOW_KEY_MAX)
-                       return -EOPNOTSUPP;
 
                nkeys = hweight32(keymask);
                if (nkeys == 0)
                        return -EINVAL;
+
+               if (fls(keymask) - 1 > FLOW_KEY_MAX)
+                       return -EOPNOTSUPP;
        }
 
        err = tcf_exts_validate(tp, tb, tca[TCA_RATE], &e, &flow_ext_map);
@@ -594,11 +607,11 @@ static int flow_dump(struct tcf_proto *tp, unsigned long fh,
 
        if (tcf_exts_dump(skb, &f->exts, &flow_ext_map) < 0)
                goto nla_put_failure;
-
+#ifdef CONFIG_NET_EMATCH
        if (f->ematches.hdr.nmatches &&
            tcf_em_tree_dump(skb, &f->ematches, TCA_FLOW_EMATCHES) < 0)
                goto nla_put_failure;
-
+#endif
        nla_nest_end(skb, nest);
 
        if (tcf_exts_dump_stats(skb, &f->exts, &flow_ext_map) < 0)
index a1e5619b1876c8477c85a07936f85806159ea290..2a7e648fbcf44edd7ce7944fee7627f3590d434a 100644 (file)
@@ -65,6 +65,7 @@
 #include <linux/string.h>
 #include <linux/skbuff.h>
 #include <linux/random.h>
+#include <linux/if_vlan.h>
 #include <linux/tc_ematch/tc_em_meta.h>
 #include <net/dst.h>
 #include <net/route.h>
@@ -169,6 +170,21 @@ META_COLLECTOR(var_dev)
        *err = var_dev(skb->dev, dst);
 }
 
+/**************************************************************************
+ * vlan tag
+ **************************************************************************/
+
+META_COLLECTOR(int_vlan_tag)
+{
+       unsigned short uninitialized_var(tag);
+       if (vlan_get_tag(skb, &tag) < 0)
+               *err = -1;
+       else
+               dst->value = tag;
+}
+
+
+
 /**************************************************************************
  * skb attributes
  **************************************************************************/
@@ -520,6 +536,7 @@ static struct meta_ops __meta_ops[TCF_META_TYPE_MAX+1][TCF_META_ID_MAX+1] = {
                [META_ID(SK_SNDTIMEO)]          = META_FUNC(int_sk_sndtimeo),
                [META_ID(SK_SENDMSG_OFF)]       = META_FUNC(int_sk_sendmsg_off),
                [META_ID(SK_WRITE_PENDING)]     = META_FUNC(int_sk_write_pend),
+               [META_ID(VLAN_TAG)]             = META_FUNC(int_vlan_tag),
        }
 };
 
index 97e6ebd145001e9b642fcf59d882714fa814e53e..ae367c82e51239101c915996643bd46638e3de73 100644 (file)
@@ -420,15 +420,15 @@ struct sctp_shared_key *sctp_auth_get_shkey(
                                const struct sctp_association *asoc,
                                __u16 key_id)
 {
-       struct sctp_shared_key *key = NULL;
+       struct sctp_shared_key *key;
 
        /* First search associations set of endpoint pair shared keys */
        key_for_each(key, &asoc->endpoint_shared_keys) {
                if (key->key_id == key_id)
-                       break;
+                       return key;
        }
 
-       return key;
+       return NULL;
 }
 
 /*
index 61cbd5a8dd0c4954c212cacaf7f46f403ca1408b..f98658782d4fc6cf26759c3a55de11caa71b274a 100644 (file)
@@ -537,7 +537,7 @@ sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
                 *
                 * This means that if we only want to abort associations
                 * in an authenticated way (i.e AUTH+ABORT), then we
-                * can't destory this association just becuase the packet
+                * can't destroy this association just becuase the packet
                 * was malformed.
                 */
                if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
@@ -3865,6 +3865,10 @@ sctp_disposition_t sctp_sf_eat_auth(const struct sctp_endpoint *ep,
        struct sctp_chunk *err_chunk;
        sctp_ierror_t error;
 
+       /* Make sure that the peer has AUTH capable */
+       if (!asoc->peer.auth_capable)
+               return sctp_sf_unk_chunk(ep, asoc, type, arg, commands);
+
        if (!sctp_vtag_verify(chunk, asoc)) {
                sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
                                SCTP_NULL());
@@ -4130,7 +4134,7 @@ static sctp_disposition_t sctp_sf_abort_violation(
         *
         * This means that if we only want to abort associations
         * in an authenticated way (i.e AUTH+ABORT), then we
-        * can't destory this association just becuase the packet
+        * can't destroy this association just becuase the packet
         * was malformed.
         */
        if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
index 5c69a725e530b825b9cef83cbbd495b309c184b0..92e1dbe50947adb5d2612f1070362cc6f30d352e 100644 (file)
@@ -11,6 +11,7 @@ sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \
            auth.o auth_null.o auth_unix.o \
            svc.o svcsock.o svcauth.o svcauth_unix.o \
            rpcb_clnt.o timer.o xdr.o \
-           sunrpc_syms.o cache.o rpc_pipe.o
+           sunrpc_syms.o cache.o rpc_pipe.o \
+           svc_xprt.o
 sunrpc-$(CONFIG_PROC_FS) += stats.o
 sunrpc-$(CONFIG_SYSCTL) += sysctl.o
index 73940df6c460c210d15e9f3c42c3a7b52a2694c7..481f984e9a22278bc9ef1993bc3064c77fc65a51 100644 (file)
@@ -224,38 +224,34 @@ static int rsi_parse(struct cache_detail *cd,
 
        /* major/minor */
        len = qword_get(&mesg, buf, mlen);
-       if (len < 0)
+       if (len <= 0)
                goto out;
-       if (len == 0) {
+       rsii.major_status = simple_strtoul(buf, &ep, 10);
+       if (*ep)
+               goto out;
+       len = qword_get(&mesg, buf, mlen);
+       if (len <= 0)
+               goto out;
+       rsii.minor_status = simple_strtoul(buf, &ep, 10);
+       if (*ep)
                goto out;
-       } else {
-               rsii.major_status = simple_strtoul(buf, &ep, 10);
-               if (*ep)
-                       goto out;
-               len = qword_get(&mesg, buf, mlen);
-               if (len <= 0)
-                       goto out;
-               rsii.minor_status = simple_strtoul(buf, &ep, 10);
-               if (*ep)
-                       goto out;
 
-               /* out_handle */
-               len = qword_get(&mesg, buf, mlen);
-               if (len < 0)
-                       goto out;
-               status = -ENOMEM;
-               if (dup_to_netobj(&rsii.out_handle, buf, len))
-                       goto out;
+       /* out_handle */
+       len = qword_get(&mesg, buf, mlen);
+       if (len < 0)
+               goto out;
+       status = -ENOMEM;
+       if (dup_to_netobj(&rsii.out_handle, buf, len))
+               goto out;
 
-               /* out_token */
-               len = qword_get(&mesg, buf, mlen);
-               status = -EINVAL;
-               if (len < 0)
-                       goto out;
-               status = -ENOMEM;
-               if (dup_to_netobj(&rsii.out_token, buf, len))
-                       goto out;
-       }
+       /* out_token */
+       len = qword_get(&mesg, buf, mlen);
+       status = -EINVAL;
+       if (len < 0)
+               goto out;
+       status = -ENOMEM;
+       if (dup_to_netobj(&rsii.out_token, buf, len))
+               goto out;
        rsii.h.expiry_time = expiry;
        rsip = rsi_update(&rsii, rsip);
        status = 0;
@@ -975,6 +971,7 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
        struct kvec *resv = &rqstp->rq_res.head[0];
        struct xdr_netobj tmpobj;
        struct rsi *rsip, rsikey;
+       int ret;
 
        /* Read the verifier; should be NULL: */
        *authp = rpc_autherr_badverf;
@@ -1014,23 +1011,27 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
                /* No upcall result: */
                return SVC_DROP;
        case 0:
+               ret = SVC_DROP;
                /* Got an answer to the upcall; use it: */
                if (gss_write_init_verf(rqstp, rsip))
-                       return SVC_DROP;
+                       goto out;
                if (resv->iov_len + 4 > PAGE_SIZE)
-                       return SVC_DROP;
+                       goto out;
                svc_putnl(resv, RPC_SUCCESS);
                if (svc_safe_putnetobj(resv, &rsip->out_handle))
-                       return SVC_DROP;
+                       goto out;
                if (resv->iov_len + 3 * 4 > PAGE_SIZE)
-                       return SVC_DROP;
+                       goto out;
                svc_putnl(resv, rsip->major_status);
                svc_putnl(resv, rsip->minor_status);
                svc_putnl(resv, GSS_SEQ_WIN);
                if (svc_safe_putnetobj(resv, &rsip->out_token))
-                       return SVC_DROP;
+                       goto out;
        }
-       return SVC_COMPLETE;
+       ret = SVC_COMPLETE;
+out:
+       cache_put(&rsip->h, &rsi_cache);
+       return ret;
 }
 
 /*
@@ -1125,6 +1126,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)
        case RPC_GSS_PROC_DESTROY:
                if (gss_write_verf(rqstp, rsci->mechctx, gc->gc_seq))
                        goto auth_err;
+               rsci->h.expiry_time = get_seconds();
                set_bit(CACHE_NEGATIVE, &rsci->h.flags);
                if (resv->iov_len + 4 > PAGE_SIZE)
                        goto drop;
@@ -1386,19 +1388,26 @@ int
 gss_svc_init(void)
 {
        int rv = svc_auth_register(RPC_AUTH_GSS, &svcauthops_gss);
-       if (rv == 0) {
-               cache_register(&rsc_cache);
-               cache_register(&rsi_cache);
-       }
+       if (rv)
+               return rv;
+       rv = cache_register(&rsc_cache);
+       if (rv)
+               goto out1;
+       rv = cache_register(&rsi_cache);
+       if (rv)
+               goto out2;
+       return 0;
+out2:
+       cache_unregister(&rsc_cache);
+out1:
+       svc_auth_unregister(RPC_AUTH_GSS);
        return rv;
 }
 
 void
 gss_svc_shutdown(void)
 {
-       if (cache_unregister(&rsc_cache))
-               printk(KERN_ERR "auth_rpcgss: failed to unregister rsc cache\n");
-       if (cache_unregister(&rsi_cache))
-               printk(KERN_ERR "auth_rpcgss: failed to unregister rsi cache\n");
+       cache_unregister(&rsc_cache);
+       cache_unregister(&rsi_cache);
        svc_auth_unregister(RPC_AUTH_GSS);
 }
index 73f053d0cc7a4f7eee6d65954f5383cb6d6fa18e..636c8e04e0bebb0fff9b33e34a23bd8e40941dfc 100644 (file)
@@ -245,6 +245,7 @@ int cache_check(struct cache_detail *detail,
                cache_put(h, detail);
        return rv;
 }
+EXPORT_SYMBOL(cache_check);
 
 /*
  * caches need to be periodically cleaned.
@@ -290,44 +291,78 @@ static const struct file_operations cache_flush_operations;
 static void do_cache_clean(struct work_struct *work);
 static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean);
 
-void cache_register(struct cache_detail *cd)
+static void remove_cache_proc_entries(struct cache_detail *cd)
 {
-       cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc);
-       if (cd->proc_ent) {
-               struct proc_dir_entry *p;
-               cd->proc_ent->owner = cd->owner;
-               cd->channel_ent = cd->content_ent = NULL;
+       if (cd->proc_ent == NULL)
+               return;
+       if (cd->flush_ent)
+               remove_proc_entry("flush", cd->proc_ent);
+       if (cd->channel_ent)
+               remove_proc_entry("channel", cd->proc_ent);
+       if (cd->content_ent)
+               remove_proc_entry("content", cd->proc_ent);
+       cd->proc_ent = NULL;
+       remove_proc_entry(cd->name, proc_net_rpc);
+}
 
-               p = create_proc_entry("flush", S_IFREG|S_IRUSR|S_IWUSR,
-                                     cd->proc_ent);
-               cd->flush_ent =  p;
-               if (p) {
-                       p->proc_fops = &cache_flush_operations;
-                       p->owner = cd->owner;
-                       p->data = cd;
-               }
+#ifdef CONFIG_PROC_FS
+static int create_cache_proc_entries(struct cache_detail *cd)
+{
+       struct proc_dir_entry *p;
 
-               if (cd->cache_request || cd->cache_parse) {
-                       p = create_proc_entry("channel", S_IFREG|S_IRUSR|S_IWUSR,
-                                             cd->proc_ent);
-                       cd->channel_ent = p;
-                       if (p) {
-                               p->proc_fops = &cache_file_operations;
-                               p->owner = cd->owner;
-                               p->data = cd;
-                       }
-               }
-               if (cd->cache_show) {
-                       p = create_proc_entry("content", S_IFREG|S_IRUSR|S_IWUSR,
-                                             cd->proc_ent);
-                       cd->content_ent = p;
-                       if (p) {
-                               p->proc_fops = &content_file_operations;
-                               p->owner = cd->owner;
-                               p->data = cd;
-                       }
-               }
+       cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc);
+       if (cd->proc_ent == NULL)
+               goto out_nomem;
+       cd->proc_ent->owner = cd->owner;
+       cd->channel_ent = cd->content_ent = NULL;
+
+       p = create_proc_entry("flush", S_IFREG|S_IRUSR|S_IWUSR, cd->proc_ent);
+       cd->flush_ent = p;
+       if (p == NULL)
+               goto out_nomem;
+       p->proc_fops = &cache_flush_operations;
+       p->owner = cd->owner;
+       p->data = cd;
+
+       if (cd->cache_request || cd->cache_parse) {
+               p = create_proc_entry("channel", S_IFREG|S_IRUSR|S_IWUSR,
+                                     cd->proc_ent);
+               cd->channel_ent = p;
+               if (p == NULL)
+                       goto out_nomem;
+               p->proc_fops = &cache_file_operations;
+               p->owner = cd->owner;
+               p->data = cd;
        }
+       if (cd->cache_show) {
+               p = create_proc_entry("content", S_IFREG|S_IRUSR|S_IWUSR,
+                                     cd->proc_ent);
+               cd->content_ent = p;
+               if (p == NULL)
+                       goto out_nomem;
+               p->proc_fops = &content_file_operations;
+               p->owner = cd->owner;
+               p->data = cd;
+       }
+       return 0;
+out_nomem:
+       remove_cache_proc_entries(cd);
+       return -ENOMEM;
+}
+#else /* CONFIG_PROC_FS */
+static int create_cache_proc_entries(struct cache_detail *cd)
+{
+       return 0;
+}
+#endif
+
+int cache_register(struct cache_detail *cd)
+{
+       int ret;
+
+       ret = create_cache_proc_entries(cd);
+       if (ret)
+               return ret;
        rwlock_init(&cd->hash_lock);
        INIT_LIST_HEAD(&cd->queue);
        spin_lock(&cache_list_lock);
@@ -341,9 +376,11 @@ void cache_register(struct cache_detail *cd)
 
        /* start the cleaning process */
        schedule_delayed_work(&cache_cleaner, 0);
+       return 0;
 }
+EXPORT_SYMBOL(cache_register);
 
-int cache_unregister(struct cache_detail *cd)
+void cache_unregister(struct cache_detail *cd)
 {
        cache_purge(cd);
        spin_lock(&cache_list_lock);
@@ -351,30 +388,23 @@ int cache_unregister(struct cache_detail *cd)
        if (cd->entries || atomic_read(&cd->inuse)) {
                write_unlock(&cd->hash_lock);
                spin_unlock(&cache_list_lock);
-               return -EBUSY;
+               goto out;
        }
        if (current_detail == cd)
                current_detail = NULL;
        list_del_init(&cd->others);
        write_unlock(&cd->hash_lock);
        spin_unlock(&cache_list_lock);
-       if (cd->proc_ent) {
-               if (cd->flush_ent)
-                       remove_proc_entry("flush", cd->proc_ent);
-               if (cd->channel_ent)
-                       remove_proc_entry("channel", cd->proc_ent);
-               if (cd->content_ent)
-                       remove_proc_entry("content", cd->proc_ent);
-
-               cd->proc_ent = NULL;
-               remove_proc_entry(cd->name, proc_net_rpc);
-       }
+       remove_cache_proc_entries(cd);
        if (list_empty(&cache_list)) {
                /* module must be being unloaded so its safe to kill the worker */
                cancel_delayed_work_sync(&cache_cleaner);
        }
-       return 0;
+       return;
+out:
+       printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name);
 }
+EXPORT_SYMBOL(cache_unregister);
 
 /* clean cache tries to find something to clean
  * and cleans it.
@@ -489,6 +519,7 @@ void cache_flush(void)
        while (cache_clean() != -1)
                cond_resched();
 }
+EXPORT_SYMBOL(cache_flush);
 
 void cache_purge(struct cache_detail *detail)
 {
@@ -497,7 +528,7 @@ void cache_purge(struct cache_detail *detail)
        cache_flush();
        detail->flush_time = 1;
 }
-
+EXPORT_SYMBOL(cache_purge);
 
 
 /*
@@ -634,13 +665,13 @@ void cache_clean_deferred(void *owner)
 /*
  * communicate with user-space
  *
- * We have a magic /proc file - /proc/sunrpc/cache
- * On read, you get a full request, or block
- * On write, an update request is processed
- * Poll works if anything to read, and always allows write
+ * We have a magic /proc file - /proc/sunrpc/<cachename>/channel.
+ * On read, you get a full request, or block.
+ * On write, an update request is processed.
+ * Poll works if anything to read, and always allows write.
  *
  * Implemented by linked list of requests.  Each open file has
- * a ->private that also exists in this list.  New request are added
+ * a ->private that also exists in this list.  New requests are added
  * to the end and may wakeup and preceding readers.
  * New readers are added to the head.  If, on read, an item is found with
  * CACHE_UPCALLING clear, we free it from the list.
@@ -963,6 +994,7 @@ void qword_add(char **bpp, int *lp, char *str)
        *bpp = bp;
        *lp = len;
 }
+EXPORT_SYMBOL(qword_add);
 
 void qword_addhex(char **bpp, int *lp, char *buf, int blen)
 {
@@ -991,6 +1023,7 @@ void qword_addhex(char **bpp, int *lp, char *buf, int blen)
        *bpp = bp;
        *lp = len;
 }
+EXPORT_SYMBOL(qword_addhex);
 
 static void warn_no_listener(struct cache_detail *detail)
 {
@@ -1113,6 +1146,7 @@ int qword_get(char **bpp, char *dest, int bufsize)
        *dest = '\0';
        return len;
 }
+EXPORT_SYMBOL(qword_get);
 
 
 /*
@@ -1244,18 +1278,18 @@ static ssize_t read_flush(struct file *file, char __user *buf,
        struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data;
        char tbuf[20];
        unsigned long p = *ppos;
-       int len;
+       size_t len;
 
        sprintf(tbuf, "%lu\n", cd->flush_time);
        len = strlen(tbuf);
        if (p >= len)
                return 0;
        len -= p;
-       if (len > count) len = count;
+       if (len > count)
+               len = count;
        if (copy_to_user(buf, (void*)(tbuf+p), len))
-               len = -EFAULT;
-       else
-               *ppos += len;
+               return -EFAULT;
+       *ppos += len;
        return len;
 }
 
index 74df2d358e61ba5eb77a806a2cb1d58e163dd7de..5a16875f5ac8b0686ccdf5e9448dac850aab7064 100644 (file)
@@ -33,7 +33,7 @@ struct proc_dir_entry *proc_net_rpc = NULL;
 static int rpc_proc_show(struct seq_file *seq, void *v) {
        const struct rpc_stat   *statp = seq->private;
        const struct rpc_program *prog = statp->program;
-       int             i, j;
+       unsigned int i, j;
 
        seq_printf(seq,
                "net %u %u %u %u\n",
@@ -81,7 +81,7 @@ void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) {
        const struct svc_program *prog = statp->program;
        const struct svc_procedure *proc;
        const struct svc_version *vers;
-       int             i, j;
+       unsigned int i, j;
 
        seq_printf(seq,
                "net %u %u %u %u\n",
@@ -106,6 +106,7 @@ void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) {
                seq_putc(seq, '\n');
        }
 }
+EXPORT_SYMBOL(svc_seq_show);
 
 /**
  * rpc_alloc_iostats - allocate an rpc_iostats structure
@@ -255,12 +256,14 @@ svc_proc_register(struct svc_stat *statp, const struct file_operations *fops)
 {
        return do_register(statp->program->pg_name, statp, fops);
 }
+EXPORT_SYMBOL(svc_proc_register);
 
 void
 svc_proc_unregister(const char *name)
 {
        remove_proc_entry(name, proc_net_rpc);
 }
+EXPORT_SYMBOL(svc_proc_unregister);
 
 void
 rpc_proc_init(void)
index 1a7e309d008bcd9624dff48195c8052c515a3791..843629f557630d07b0b4b0e29eb5a6f9feddce88 100644 (file)
 #include <linux/sunrpc/rpc_pipe_fs.h>
 #include <linux/sunrpc/xprtsock.h>
 
-/* RPC server stuff */
-EXPORT_SYMBOL(svc_create);
-EXPORT_SYMBOL(svc_create_thread);
-EXPORT_SYMBOL(svc_create_pooled);
-EXPORT_SYMBOL(svc_set_num_threads);
-EXPORT_SYMBOL(svc_exit_thread);
-EXPORT_SYMBOL(svc_destroy);
-EXPORT_SYMBOL(svc_drop);
-EXPORT_SYMBOL(svc_process);
-EXPORT_SYMBOL(svc_recv);
-EXPORT_SYMBOL(svc_wake_up);
-EXPORT_SYMBOL(svc_makesock);
-EXPORT_SYMBOL(svc_reserve);
-EXPORT_SYMBOL(svc_auth_register);
-EXPORT_SYMBOL(auth_domain_lookup);
-EXPORT_SYMBOL(svc_authenticate);
-EXPORT_SYMBOL(svc_set_client);
-
-/* RPC statistics */
-#ifdef CONFIG_PROC_FS
-EXPORT_SYMBOL(svc_proc_register);
-EXPORT_SYMBOL(svc_proc_unregister);
-EXPORT_SYMBOL(svc_seq_show);
-#endif
-
-/* caching... */
-EXPORT_SYMBOL(auth_domain_find);
-EXPORT_SYMBOL(auth_domain_put);
-EXPORT_SYMBOL(auth_unix_add_addr);
-EXPORT_SYMBOL(auth_unix_forget_old);
-EXPORT_SYMBOL(auth_unix_lookup);
-EXPORT_SYMBOL(cache_check);
-EXPORT_SYMBOL(cache_flush);
-EXPORT_SYMBOL(cache_purge);
-EXPORT_SYMBOL(cache_register);
-EXPORT_SYMBOL(cache_unregister);
-EXPORT_SYMBOL(qword_add);
-EXPORT_SYMBOL(qword_addhex);
-EXPORT_SYMBOL(qword_get);
-EXPORT_SYMBOL(svcauth_unix_purge);
-EXPORT_SYMBOL(unix_domain_find);
-
 extern struct cache_detail ip_map_cache, unix_gid_cache;
 
 static int __init
@@ -85,7 +43,8 @@ init_sunrpc(void)
 #endif
        cache_register(&ip_map_cache);
        cache_register(&unix_gid_cache);
-       init_socket_xprt();
+       svc_init_xprt_sock();   /* svc sock transport */
+       init_socket_xprt();     /* clnt sock transport */
        rpcauth_init_module();
 out:
        return err;
@@ -96,12 +55,11 @@ cleanup_sunrpc(void)
 {
        rpcauth_remove_module();
        cleanup_socket_xprt();
+       svc_cleanup_xprt_sock();
        unregister_rpc_pipefs();
        rpc_destroy_mempool();
-       if (cache_unregister(&ip_map_cache))
-               printk(KERN_ERR "sunrpc: failed to unregister ip_map cache\n");
-       if (cache_unregister(&unix_gid_cache))
-             printk(KERN_ERR "sunrpc: failed to unregister unix_gid cache\n");
+       cache_unregister(&ip_map_cache);
+       cache_unregister(&unix_gid_cache);
 #ifdef RPC_DEBUG
        rpc_unregister_sysctl();
 #endif
index 4ad5fbbb18b48df0d2ad9a0b457212a6c764330d..a290e1523297783da4e491ad547e17cdeb5da675 100644 (file)
@@ -364,7 +364,7 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
           void (*shutdown)(struct svc_serv *serv))
 {
        struct svc_serv *serv;
-       int vers;
+       unsigned int vers;
        unsigned int xdrsize;
        unsigned int i;
 
@@ -433,6 +433,7 @@ svc_create(struct svc_program *prog, unsigned int bufsize,
 {
        return __svc_create(prog, bufsize, /*npools*/1, shutdown);
 }
+EXPORT_SYMBOL(svc_create);
 
 struct svc_serv *
 svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
@@ -452,6 +453,7 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
 
        return serv;
 }
+EXPORT_SYMBOL(svc_create_pooled);
 
 /*
  * Destroy an RPC service.  Should be called with the BKL held
@@ -459,9 +461,6 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
 void
 svc_destroy(struct svc_serv *serv)
 {
-       struct svc_sock *svsk;
-       struct svc_sock *tmp;
-
        dprintk("svc: svc_destroy(%s, %d)\n",
                                serv->sv_program->pg_name,
                                serv->sv_nrthreads);
@@ -476,14 +475,12 @@ svc_destroy(struct svc_serv *serv)
 
        del_timer_sync(&serv->sv_temptimer);
 
-       list_for_each_entry_safe(svsk, tmp, &serv->sv_tempsocks, sk_list)
-               svc_force_close_socket(svsk);
+       svc_close_all(&serv->sv_tempsocks);
 
        if (serv->sv_shutdown)
                serv->sv_shutdown(serv);
 
-       list_for_each_entry_safe(svsk, tmp, &serv->sv_permsocks, sk_list)
-               svc_force_close_socket(svsk);
+       svc_close_all(&serv->sv_permsocks);
 
        BUG_ON(!list_empty(&serv->sv_permsocks));
        BUG_ON(!list_empty(&serv->sv_tempsocks));
@@ -498,6 +495,7 @@ svc_destroy(struct svc_serv *serv)
        kfree(serv->sv_pools);
        kfree(serv);
 }
+EXPORT_SYMBOL(svc_destroy);
 
 /*
  * Allocate an RPC server's buffer space.
@@ -536,31 +534,17 @@ svc_release_buffer(struct svc_rqst *rqstp)
                        put_page(rqstp->rq_pages[i]);
 }
 
-/*
- * Create a thread in the given pool.  Caller must hold BKL.
- * On a NUMA or SMP machine, with a multi-pool serv, the thread
- * will be restricted to run on the cpus belonging to the pool.
- */
-static int
-__svc_create_thread(svc_thread_fn func, struct svc_serv *serv,
-                   struct svc_pool *pool)
+struct svc_rqst *
+svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool)
 {
        struct svc_rqst *rqstp;
-       int             error = -ENOMEM;
-       int             have_oldmask = 0;
-       cpumask_t       oldmask;
 
        rqstp = kzalloc(sizeof(*rqstp), GFP_KERNEL);
        if (!rqstp)
-               goto out;
+               goto out_enomem;
 
        init_waitqueue_head(&rqstp->rq_wait);
 
-       if (!(rqstp->rq_argp = kmalloc(serv->sv_xdrsize, GFP_KERNEL))
-        || !(rqstp->rq_resp = kmalloc(serv->sv_xdrsize, GFP_KERNEL))
-        || !svc_init_buffer(rqstp, serv->sv_max_mesg))
-               goto out_thread;
-
        serv->sv_nrthreads++;
        spin_lock_bh(&pool->sp_lock);
        pool->sp_nrthreads++;
@@ -569,6 +553,45 @@ __svc_create_thread(svc_thread_fn func, struct svc_serv *serv,
        rqstp->rq_server = serv;
        rqstp->rq_pool = pool;
 
+       rqstp->rq_argp = kmalloc(serv->sv_xdrsize, GFP_KERNEL);
+       if (!rqstp->rq_argp)
+               goto out_thread;
+
+       rqstp->rq_resp = kmalloc(serv->sv_xdrsize, GFP_KERNEL);
+       if (!rqstp->rq_resp)
+               goto out_thread;
+
+       if (!svc_init_buffer(rqstp, serv->sv_max_mesg))
+               goto out_thread;
+
+       return rqstp;
+out_thread:
+       svc_exit_thread(rqstp);
+out_enomem:
+       return ERR_PTR(-ENOMEM);
+}
+EXPORT_SYMBOL(svc_prepare_thread);
+
+/*
+ * Create a thread in the given pool.  Caller must hold BKL.
+ * On a NUMA or SMP machine, with a multi-pool serv, the thread
+ * will be restricted to run on the cpus belonging to the pool.
+ */
+static int
+__svc_create_thread(svc_thread_fn func, struct svc_serv *serv,
+                   struct svc_pool *pool)
+{
+       struct svc_rqst *rqstp;
+       int             error = -ENOMEM;
+       int             have_oldmask = 0;
+       cpumask_t       oldmask;
+
+       rqstp = svc_prepare_thread(serv, pool);
+       if (IS_ERR(rqstp)) {
+               error = PTR_ERR(rqstp);
+               goto out;
+       }
+
        if (serv->sv_nrpools > 1)
                have_oldmask = svc_pool_map_set_cpumask(pool->sp_id, &oldmask);
 
@@ -597,6 +620,7 @@ svc_create_thread(svc_thread_fn func, struct svc_serv *serv)
 {
        return __svc_create_thread(func, serv, &serv->sv_pools[0]);
 }
+EXPORT_SYMBOL(svc_create_thread);
 
 /*
  * Choose a pool in which to create a new thread, for svc_set_num_threads
@@ -700,6 +724,7 @@ svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 
        return error;
 }
+EXPORT_SYMBOL(svc_set_num_threads);
 
 /*
  * Called from a server thread as it's exiting.  Caller must hold BKL.
@@ -726,6 +751,7 @@ svc_exit_thread(struct svc_rqst *rqstp)
        if (serv)
                svc_destroy(serv);
 }
+EXPORT_SYMBOL(svc_exit_thread);
 
 /*
  * Register an RPC service with the local portmapper.
@@ -737,7 +763,8 @@ svc_register(struct svc_serv *serv, int proto, unsigned short port)
 {
        struct svc_program      *progp;
        unsigned long           flags;
-       int                     i, error = 0, dummy;
+       unsigned int            i;
+       int                     error = 0, dummy;
 
        if (!port)
                clear_thread_flag(TIF_SIGPENDING);
@@ -840,9 +867,9 @@ svc_process(struct svc_rqst *rqstp)
        rqstp->rq_res.tail[0].iov_len = 0;
        /* Will be turned off only in gss privacy case: */
        rqstp->rq_splice_ok = 1;
-       /* tcp needs a space for the record length... */
-       if (rqstp->rq_prot == IPPROTO_TCP)
-               svc_putnl(resv, 0);
+
+       /* Setup reply header */
+       rqstp->rq_xprt->xpt_ops->xpo_prep_reply_hdr(rqstp);
 
        rqstp->rq_xid = svc_getu32(argv);
        svc_putu32(resv, rqstp->rq_xid);
@@ -1049,16 +1076,15 @@ err_bad:
        svc_putnl(resv, ntohl(rpc_stat));
        goto sendit;
 }
+EXPORT_SYMBOL(svc_process);
 
 /*
  * Return (transport-specific) limit on the rpc payload.
  */
 u32 svc_max_payload(const struct svc_rqst *rqstp)
 {
-       int max = RPCSVC_MAXPAYLOAD_TCP;
+       u32 max = rqstp->rq_xprt->xpt_class->xcl_max_payload;
 
-       if (rqstp->rq_sock->sk_sock->type == SOCK_DGRAM)
-               max = RPCSVC_MAXPAYLOAD_UDP;
        if (rqstp->rq_server->sv_max_payload < max)
                max = rqstp->rq_server->sv_max_payload;
        return max;
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
new file mode 100644 (file)
index 0000000..ea377e0
--- /dev/null
@@ -0,0 +1,1055 @@
+/*
+ * linux/net/sunrpc/svc_xprt.c
+ *
+ * Author: Tom Tucker <tom@opengridcomputing.com>
+ */
+
+#include <linux/sched.h>
+#include <linux/errno.h>
+#include <linux/fcntl.h>
+#include <linux/net.h>
+#include <linux/in.h>
+#include <linux/inet.h>
+#include <linux/udp.h>
+#include <linux/tcp.h>
+#include <linux/unistd.h>
+#include <linux/slab.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/file.h>
+#include <linux/freezer.h>
+#include <net/sock.h>
+#include <net/checksum.h>
+#include <net/ip.h>
+#include <net/ipv6.h>
+#include <net/tcp_states.h>
+#include <linux/uaccess.h>
+#include <asm/ioctls.h>
+
+#include <linux/sunrpc/types.h>
+#include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/xdr.h>
+#include <linux/sunrpc/stats.h>
+#include <linux/sunrpc/svc_xprt.h>
+
+#define RPCDBG_FACILITY        RPCDBG_SVCXPRT
+
+static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt);
+static int svc_deferred_recv(struct svc_rqst *rqstp);
+static struct cache_deferred_req *svc_defer(struct cache_req *req);
+static void svc_age_temp_xprts(unsigned long closure);
+
+/* apparently the "standard" is that clients close
+ * idle connections after 5 minutes, servers after
+ * 6 minutes
+ *   http://www.connectathon.org/talks96/nfstcp.pdf
+ */
+static int svc_conn_age_period = 6*60;
+
+/* List of registered transport classes */
+static DEFINE_SPINLOCK(svc_xprt_class_lock);
+static LIST_HEAD(svc_xprt_class_list);
+
+/* SMP locking strategy:
+ *
+ *     svc_pool->sp_lock protects most of the fields of that pool.
+ *     svc_serv->sv_lock protects sv_tempsocks, sv_permsocks, sv_tmpcnt.
+ *     when both need to be taken (rare), svc_serv->sv_lock is first.
+ *     BKL protects svc_serv->sv_nrthread.
+ *     svc_sock->sk_lock protects the svc_sock->sk_deferred list
+ *             and the ->sk_info_authunix cache.
+ *
+ *     The XPT_BUSY bit in xprt->xpt_flags prevents a transport being
+ *     enqueued multiply. During normal transport processing this bit
+ *     is set by svc_xprt_enqueue and cleared by svc_xprt_received.
+ *     Providers should not manipulate this bit directly.
+ *
+ *     Some flags can be set to certain values at any time
+ *     providing that certain rules are followed:
+ *
+ *     XPT_CONN, XPT_DATA:
+ *             - Can be set or cleared at any time.
+ *             - After a set, svc_xprt_enqueue must be called to enqueue
+ *               the transport for processing.
+ *             - After a clear, the transport must be read/accepted.
+ *               If this succeeds, it must be set again.
+ *     XPT_CLOSE:
+ *             - Can set at any time. It is never cleared.
+ *      XPT_DEAD:
+ *             - Can only be set while XPT_BUSY is held which ensures
+ *               that no other thread will be using the transport or will
+ *               try to set XPT_DEAD.
+ */
+
+int svc_reg_xprt_class(struct svc_xprt_class *xcl)
+{
+       struct svc_xprt_class *cl;
+       int res = -EEXIST;
+
+       dprintk("svc: Adding svc transport class '%s'\n", xcl->xcl_name);
+
+       INIT_LIST_HEAD(&xcl->xcl_list);
+       spin_lock(&svc_xprt_class_lock);
+       /* Make sure there isn't already a class with the same name */
+       list_for_each_entry(cl, &svc_xprt_class_list, xcl_list) {
+               if (strcmp(xcl->xcl_name, cl->xcl_name) == 0)
+                       goto out;
+       }
+       list_add_tail(&xcl->xcl_list, &svc_xprt_class_list);
+       res = 0;
+out:
+       spin_unlock(&svc_xprt_class_lock);
+       return res;
+}
+EXPORT_SYMBOL_GPL(svc_reg_xprt_class);
+
+void svc_unreg_xprt_class(struct svc_xprt_class *xcl)
+{
+       dprintk("svc: Removing svc transport class '%s'\n", xcl->xcl_name);
+       spin_lock(&svc_xprt_class_lock);
+       list_del_init(&xcl->xcl_list);
+       spin_unlock(&svc_xprt_class_lock);
+}
+EXPORT_SYMBOL_GPL(svc_unreg_xprt_class);
+
+/*
+ * Format the transport list for printing
+ */
+int svc_print_xprts(char *buf, int maxlen)
+{
+       struct list_head *le;
+       char tmpstr[80];
+       int len = 0;
+       buf[0] = '\0';
+
+       spin_lock(&svc_xprt_class_lock);
+       list_for_each(le, &svc_xprt_class_list) {
+               int slen;
+               struct svc_xprt_class *xcl =
+                       list_entry(le, struct svc_xprt_class, xcl_list);
+
+               sprintf(tmpstr, "%s %d\n", xcl->xcl_name, xcl->xcl_max_payload);
+               slen = strlen(tmpstr);
+               if (len + slen > maxlen)
+                       break;
+               len += slen;
+               strcat(buf, tmpstr);
+       }
+       spin_unlock(&svc_xprt_class_lock);
+
+       return len;
+}
+
+static void svc_xprt_free(struct kref *kref)
+{
+       struct svc_xprt *xprt =
+               container_of(kref, struct svc_xprt, xpt_ref);
+       struct module *owner = xprt->xpt_class->xcl_owner;
+       if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags)
+           && xprt->xpt_auth_cache != NULL)
+               svcauth_unix_info_release(xprt->xpt_auth_cache);
+       xprt->xpt_ops->xpo_free(xprt);
+       module_put(owner);
+}
+
+void svc_xprt_put(struct svc_xprt *xprt)
+{
+       kref_put(&xprt->xpt_ref, svc_xprt_free);
+}
+EXPORT_SYMBOL_GPL(svc_xprt_put);
+
+/*
+ * Called by transport drivers to initialize the transport independent
+ * portion of the transport instance.
+ */
+void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt,
+                  struct svc_serv *serv)
+{
+       memset(xprt, 0, sizeof(*xprt));
+       xprt->xpt_class = xcl;
+       xprt->xpt_ops = xcl->xcl_ops;
+       kref_init(&xprt->xpt_ref);
+       xprt->xpt_server = serv;
+       INIT_LIST_HEAD(&xprt->xpt_list);
+       INIT_LIST_HEAD(&xprt->xpt_ready);
+       INIT_LIST_HEAD(&xprt->xpt_deferred);
+       mutex_init(&xprt->xpt_mutex);
+       spin_lock_init(&xprt->xpt_lock);
+       set_bit(XPT_BUSY, &xprt->xpt_flags);
+}
+EXPORT_SYMBOL_GPL(svc_xprt_init);
+
+int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,
+                   int flags)
+{
+       struct svc_xprt_class *xcl;
+       struct sockaddr_in sin = {
+               .sin_family             = AF_INET,
+               .sin_addr.s_addr        = INADDR_ANY,
+               .sin_port               = htons(port),
+       };
+       dprintk("svc: creating transport %s[%d]\n", xprt_name, port);
+       spin_lock(&svc_xprt_class_lock);
+       list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) {
+               struct svc_xprt *newxprt;
+
+               if (strcmp(xprt_name, xcl->xcl_name))
+                       continue;
+
+               if (!try_module_get(xcl->xcl_owner))
+                       goto err;
+
+               spin_unlock(&svc_xprt_class_lock);
+               newxprt = xcl->xcl_ops->
+                       xpo_create(serv, (struct sockaddr *)&sin, sizeof(sin),
+                                  flags);
+               if (IS_ERR(newxprt)) {
+                       module_put(xcl->xcl_owner);
+                       return PTR_ERR(newxprt);
+               }
+
+               clear_bit(XPT_TEMP, &newxprt->xpt_flags);
+               spin_lock_bh(&serv->sv_lock);
+               list_add(&newxprt->xpt_list, &serv->sv_permsocks);
+               spin_unlock_bh(&serv->sv_lock);
+               clear_bit(XPT_BUSY, &newxprt->xpt_flags);
+               return svc_xprt_local_port(newxprt);
+       }
+ err:
+       spin_unlock(&svc_xprt_class_lock);
+       dprintk("svc: transport %s not found\n", xprt_name);
+       return -ENOENT;
+}
+EXPORT_SYMBOL_GPL(svc_create_xprt);
+
+/*
+ * Copy the local and remote xprt addresses to the rqstp structure
+ */
+void svc_xprt_copy_addrs(struct svc_rqst *rqstp, struct svc_xprt *xprt)
+{
+       struct sockaddr *sin;
+
+       memcpy(&rqstp->rq_addr, &xprt->xpt_remote, xprt->xpt_remotelen);
+       rqstp->rq_addrlen = xprt->xpt_remotelen;
+
+       /*
+        * Destination address in request is needed for binding the
+        * source address in RPC replies/callbacks later.
+        */
+       sin = (struct sockaddr *)&xprt->xpt_local;
+       switch (sin->sa_family) {
+       case AF_INET:
+               rqstp->rq_daddr.addr = ((struct sockaddr_in *)sin)->sin_addr;
+               break;
+       case AF_INET6:
+               rqstp->rq_daddr.addr6 = ((struct sockaddr_in6 *)sin)->sin6_addr;
+               break;
+       }
+}
+EXPORT_SYMBOL_GPL(svc_xprt_copy_addrs);
+
+/**
+ * svc_print_addr - Format rq_addr field for printing
+ * @rqstp: svc_rqst struct containing address to print
+ * @buf: target buffer for formatted address
+ * @len: length of target buffer
+ *
+ */
+char *svc_print_addr(struct svc_rqst *rqstp, char *buf, size_t len)
+{
+       return __svc_print_addr(svc_addr(rqstp), buf, len);
+}
+EXPORT_SYMBOL_GPL(svc_print_addr);
+
+/*
+ * Queue up an idle server thread.  Must have pool->sp_lock held.
+ * Note: this is really a stack rather than a queue, so that we only
+ * use as many different threads as we need, and the rest don't pollute
+ * the cache.
+ */
+static void svc_thread_enqueue(struct svc_pool *pool, struct svc_rqst *rqstp)
+{
+       list_add(&rqstp->rq_list, &pool->sp_threads);
+}
+
+/*
+ * Dequeue an nfsd thread.  Must have pool->sp_lock held.
+ */
+static void svc_thread_dequeue(struct svc_pool *pool, struct svc_rqst *rqstp)
+{
+       list_del(&rqstp->rq_list);
+}
+
+/*
+ * Queue up a transport with data pending. If there are idle nfsd
+ * processes, wake 'em up.
+ *
+ */
+void svc_xprt_enqueue(struct svc_xprt *xprt)
+{
+       struct svc_serv *serv = xprt->xpt_server;
+       struct svc_pool *pool;
+       struct svc_rqst *rqstp;
+       int cpu;
+
+       if (!(xprt->xpt_flags &
+             ((1<<XPT_CONN)|(1<<XPT_DATA)|(1<<XPT_CLOSE)|(1<<XPT_DEFERRED))))
+               return;
+       if (test_bit(XPT_DEAD, &xprt->xpt_flags))
+               return;
+
+       cpu = get_cpu();
+       pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
+       put_cpu();
+
+       spin_lock_bh(&pool->sp_lock);
+
+       if (!list_empty(&pool->sp_threads) &&
+           !list_empty(&pool->sp_sockets))
+               printk(KERN_ERR
+                      "svc_xprt_enqueue: "
+                      "threads and transports both waiting??\n");
+
+       if (test_bit(XPT_DEAD, &xprt->xpt_flags)) {
+               /* Don't enqueue dead transports */
+               dprintk("svc: transport %p is dead, not enqueued\n", xprt);
+               goto out_unlock;
+       }
+
+       /* Mark transport as busy. It will remain in this state until
+        * the provider calls svc_xprt_received. We update XPT_BUSY
+        * atomically because it also guards against trying to enqueue
+        * the transport twice.
+        */
+       if (test_and_set_bit(XPT_BUSY, &xprt->xpt_flags)) {
+               /* Don't enqueue transport while already enqueued */
+               dprintk("svc: transport %p busy, not enqueued\n", xprt);
+               goto out_unlock;
+       }
+       BUG_ON(xprt->xpt_pool != NULL);
+       xprt->xpt_pool = pool;
+
+       /* Handle pending connection */
+       if (test_bit(XPT_CONN, &xprt->xpt_flags))
+               goto process;
+
+       /* Handle close in-progress */
+       if (test_bit(XPT_CLOSE, &xprt->xpt_flags))
+               goto process;
+
+       /* Check if we have space to reply to a request */
+       if (!xprt->xpt_ops->xpo_has_wspace(xprt)) {
+               /* Don't enqueue while not enough space for reply */
+               dprintk("svc: no write space, transport %p  not enqueued\n",
+                       xprt);
+               xprt->xpt_pool = NULL;
+               clear_bit(XPT_BUSY, &xprt->xpt_flags);
+               goto out_unlock;
+       }
+
+ process:
+       if (!list_empty(&pool->sp_threads)) {
+               rqstp = list_entry(pool->sp_threads.next,
+                                  struct svc_rqst,
+                                  rq_list);
+               dprintk("svc: transport %p served by daemon %p\n",
+                       xprt, rqstp);
+               svc_thread_dequeue(pool, rqstp);
+               if (rqstp->rq_xprt)
+                       printk(KERN_ERR
+                               "svc_xprt_enqueue: server %p, rq_xprt=%p!\n",
+                               rqstp, rqstp->rq_xprt);
+               rqstp->rq_xprt = xprt;
+               svc_xprt_get(xprt);
+               rqstp->rq_reserved = serv->sv_max_mesg;
+               atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved);
+               BUG_ON(xprt->xpt_pool != pool);
+               wake_up(&rqstp->rq_wait);
+       } else {
+               dprintk("svc: transport %p put into queue\n", xprt);
+               list_add_tail(&xprt->xpt_ready, &pool->sp_sockets);
+               BUG_ON(xprt->xpt_pool != pool);
+       }
+
+out_unlock:
+       spin_unlock_bh(&pool->sp_lock);
+}
+EXPORT_SYMBOL_GPL(svc_xprt_enqueue);
+
+/*
+ * Dequeue the first transport.  Must be called with the pool->sp_lock held.
+ */
+static struct svc_xprt *svc_xprt_dequeue(struct svc_pool *pool)
+{
+       struct svc_xprt *xprt;
+
+       if (list_empty(&pool->sp_sockets))
+               return NULL;
+
+       xprt = list_entry(pool->sp_sockets.next,
+                         struct svc_xprt, xpt_ready);
+       list_del_init(&xprt->xpt_ready);
+
+       dprintk("svc: transport %p dequeued, inuse=%d\n",
+               xprt, atomic_read(&xprt->xpt_ref.refcount));
+
+       return xprt;
+}
+
+/*
+ * svc_xprt_received conditionally queues the transport for processing
+ * by another thread. The caller must hold the XPT_BUSY bit and must
+ * not thereafter touch transport data.
+ *
+ * Note: XPT_DATA only gets cleared when a read-attempt finds no (or
+ * insufficient) data.
+ */
+void svc_xprt_received(struct svc_xprt *xprt)
+{
+       BUG_ON(!test_bit(XPT_BUSY, &xprt->xpt_flags));
+       xprt->xpt_pool = NULL;
+       clear_bit(XPT_BUSY, &xprt->xpt_flags);
+       svc_xprt_enqueue(xprt);
+}
+EXPORT_SYMBOL_GPL(svc_xprt_received);
+
+/**
+ * svc_reserve - change the space reserved for the reply to a request.
+ * @rqstp:  The request in question
+ * @space: new max space to reserve
+ *
+ * Each request reserves some space on the output queue of the transport
+ * to make sure the reply fits.  This function reduces that reserved
+ * space to be the amount of space used already, plus @space.
+ *
+ */
+void svc_reserve(struct svc_rqst *rqstp, int space)
+{
+       space += rqstp->rq_res.head[0].iov_len;
+
+       if (space < rqstp->rq_reserved) {
+               struct svc_xprt *xprt = rqstp->rq_xprt;
+               atomic_sub((rqstp->rq_reserved - space), &xprt->xpt_reserved);
+               rqstp->rq_reserved = space;
+
+               svc_xprt_enqueue(xprt);
+       }
+}
+EXPORT_SYMBOL(svc_reserve);
+
+static void svc_xprt_release(struct svc_rqst *rqstp)
+{
+       struct svc_xprt *xprt = rqstp->rq_xprt;
+
+       rqstp->rq_xprt->xpt_ops->xpo_release_rqst(rqstp);
+
+       svc_free_res_pages(rqstp);
+       rqstp->rq_res.page_len = 0;
+       rqstp->rq_res.page_base = 0;
+
+       /* Reset response buffer and release
+        * the reservation.
+        * But first, check that enough space was reserved
+        * for the reply, otherwise we have a bug!
+        */
+       if ((rqstp->rq_res.len) >  rqstp->rq_reserved)
+               printk(KERN_ERR "RPC request reserved %d but used %d\n",
+                      rqstp->rq_reserved,
+                      rqstp->rq_res.len);
+
+       rqstp->rq_res.head[0].iov_len = 0;
+       svc_reserve(rqstp, 0);
+       rqstp->rq_xprt = NULL;
+
+       svc_xprt_put(xprt);
+}
+
+/*
+ * External function to wake up a server waiting for data
+ * This really only makes sense for services like lockd
+ * which have exactly one thread anyway.
+ */
+void svc_wake_up(struct svc_serv *serv)
+{
+       struct svc_rqst *rqstp;
+       unsigned int i;
+       struct svc_pool *pool;
+
+       for (i = 0; i < serv->sv_nrpools; i++) {
+               pool = &serv->sv_pools[i];
+
+               spin_lock_bh(&pool->sp_lock);
+               if (!list_empty(&pool->sp_threads)) {
+                       rqstp = list_entry(pool->sp_threads.next,
+                                          struct svc_rqst,
+                                          rq_list);
+                       dprintk("svc: daemon %p woken up.\n", rqstp);
+                       /*
+                       svc_thread_dequeue(pool, rqstp);
+                       rqstp->rq_xprt = NULL;
+                        */
+                       wake_up(&rqstp->rq_wait);
+               }
+               spin_unlock_bh(&pool->sp_lock);
+       }
+}
+EXPORT_SYMBOL(svc_wake_up);
+
+int svc_port_is_privileged(struct sockaddr *sin)
+{
+       switch (sin->sa_family) {
+       case AF_INET:
+               return ntohs(((struct sockaddr_in *)sin)->sin_port)
+                       < PROT_SOCK;
+       case AF_INET6:
+               return ntohs(((struct sockaddr_in6 *)sin)->sin6_port)
+                       < PROT_SOCK;
+       default:
+               return 0;
+       }
+}
+
+/*
+ * Make sure that we don't have too many active connections.  If we
+ * have, something must be dropped.
+ *
+ * There's no point in trying to do random drop here for DoS
+ * prevention. The NFS clients does 1 reconnect in 15 seconds. An
+ * attacker can easily beat that.
+ *
+ * The only somewhat efficient mechanism would be if drop old
+ * connections from the same IP first. But right now we don't even
+ * record the client IP in svc_sock.
+ */
+static void svc_check_conn_limits(struct svc_serv *serv)
+{
+       if (serv->sv_tmpcnt > (serv->sv_nrthreads+3)*20) {
+               struct svc_xprt *xprt = NULL;
+               spin_lock_bh(&serv->sv_lock);
+               if (!list_empty(&serv->sv_tempsocks)) {
+                       if (net_ratelimit()) {
+                               /* Try to help the admin */
+                               printk(KERN_NOTICE "%s: too many open  "
+                                      "connections, consider increasing the "
+                                      "number of nfsd threads\n",
+                                      serv->sv_name);
+                       }
+                       /*
+                        * Always select the oldest connection. It's not fair,
+                        * but so is life
+                        */
+                       xprt = list_entry(serv->sv_tempsocks.prev,
+                                         struct svc_xprt,
+                                         xpt_list);
+                       set_bit(XPT_CLOSE, &xprt->xpt_flags);
+                       svc_xprt_get(xprt);
+               }
+               spin_unlock_bh(&serv->sv_lock);
+
+               if (xprt) {
+                       svc_xprt_enqueue(xprt);
+                       svc_xprt_put(xprt);
+               }
+       }
+}
+
+/*
+ * Receive the next request on any transport.  This code is carefully
+ * organised not to touch any cachelines in the shared svc_serv
+ * structure, only cachelines in the local svc_pool.
+ */
+int svc_recv(struct svc_rqst *rqstp, long timeout)
+{
+       struct svc_xprt         *xprt = NULL;
+       struct svc_serv         *serv = rqstp->rq_server;
+       struct svc_pool         *pool = rqstp->rq_pool;
+       int                     len, i;
+       int                     pages;
+       struct xdr_buf          *arg;
+       DECLARE_WAITQUEUE(wait, current);
+
+       dprintk("svc: server %p waiting for data (to = %ld)\n",
+               rqstp, timeout);
+
+       if (rqstp->rq_xprt)
+               printk(KERN_ERR
+                       "svc_recv: service %p, transport not NULL!\n",
+                        rqstp);
+       if (waitqueue_active(&rqstp->rq_wait))
+               printk(KERN_ERR
+                       "svc_recv: service %p, wait queue active!\n",
+                        rqstp);
+
+       /* now allocate needed pages.  If we get a failure, sleep briefly */
+       pages = (serv->sv_max_mesg + PAGE_SIZE) / PAGE_SIZE;
+       for (i = 0; i < pages ; i++)
+               while (rqstp->rq_pages[i] == NULL) {
+                       struct page *p = alloc_page(GFP_KERNEL);
+                       if (!p) {
+                               int j = msecs_to_jiffies(500);
+                               schedule_timeout_uninterruptible(j);
+                       }
+                       rqstp->rq_pages[i] = p;
+               }
+       rqstp->rq_pages[i++] = NULL; /* this might be seen in nfs_read_actor */
+       BUG_ON(pages >= RPCSVC_MAXPAGES);
+
+       /* Make arg->head point to first page and arg->pages point to rest */
+       arg = &rqstp->rq_arg;
+       arg->head[0].iov_base = page_address(rqstp->rq_pages[0]);
+       arg->head[0].iov_len = PAGE_SIZE;
+       arg->pages = rqstp->rq_pages + 1;
+       arg->page_base = 0;
+       /* save at least one page for response */
+       arg->page_len = (pages-2)*PAGE_SIZE;
+       arg->len = (pages-1)*PAGE_SIZE;
+       arg->tail[0].iov_len = 0;
+
+       try_to_freeze();
+       cond_resched();
+       if (signalled())
+               return -EINTR;
+
+       spin_lock_bh(&pool->sp_lock);
+       xprt = svc_xprt_dequeue(pool);
+       if (xprt) {
+               rqstp->rq_xprt = xprt;
+               svc_xprt_get(xprt);
+               rqstp->rq_reserved = serv->sv_max_mesg;
+               atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved);
+       } else {
+               /* No data pending. Go to sleep */
+               svc_thread_enqueue(pool, rqstp);
+
+               /*
+                * We have to be able to interrupt this wait
+                * to bring down the daemons ...
+                */
+               set_current_state(TASK_INTERRUPTIBLE);
+               add_wait_queue(&rqstp->rq_wait, &wait);
+               spin_unlock_bh(&pool->sp_lock);
+
+               schedule_timeout(timeout);
+
+               try_to_freeze();
+
+               spin_lock_bh(&pool->sp_lock);
+               remove_wait_queue(&rqstp->rq_wait, &wait);
+
+               xprt = rqstp->rq_xprt;
+               if (!xprt) {
+                       svc_thread_dequeue(pool, rqstp);
+                       spin_unlock_bh(&pool->sp_lock);
+                       dprintk("svc: server %p, no data yet\n", rqstp);
+                       return signalled()? -EINTR : -EAGAIN;
+               }
+       }
+       spin_unlock_bh(&pool->sp_lock);
+
+       len = 0;
+       if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) {
+               dprintk("svc_recv: found XPT_CLOSE\n");
+               svc_delete_xprt(xprt);
+       } else if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) {
+               struct svc_xprt *newxpt;
+               newxpt = xprt->xpt_ops->xpo_accept(xprt);
+               if (newxpt) {
+                       /*
+                        * We know this module_get will succeed because the
+                        * listener holds a reference too
+                        */
+                       __module_get(newxpt->xpt_class->xcl_owner);
+                       svc_check_conn_limits(xprt->xpt_server);
+                       spin_lock_bh(&serv->sv_lock);
+                       set_bit(XPT_TEMP, &newxpt->xpt_flags);
+                       list_add(&newxpt->xpt_list, &serv->sv_tempsocks);
+                       serv->sv_tmpcnt++;
+                       if (serv->sv_temptimer.function == NULL) {
+                               /* setup timer to age temp transports */
+                               setup_timer(&serv->sv_temptimer,
+                                           svc_age_temp_xprts,
+                                           (unsigned long)serv);
+                               mod_timer(&serv->sv_temptimer,
+                                         jiffies + svc_conn_age_period * HZ);
+                       }
+                       spin_unlock_bh(&serv->sv_lock);
+                       svc_xprt_received(newxpt);
+               }
+               svc_xprt_received(xprt);
+       } else {
+               dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n",
+                       rqstp, pool->sp_id, xprt,
+                       atomic_read(&xprt->xpt_ref.refcount));
+               rqstp->rq_deferred = svc_deferred_dequeue(xprt);
+               if (rqstp->rq_deferred) {
+                       svc_xprt_received(xprt);
+                       len = svc_deferred_recv(rqstp);
+               } else
+                       len = xprt->xpt_ops->xpo_recvfrom(rqstp);
+               dprintk("svc: got len=%d\n", len);
+       }
+
+       /* No data, incomplete (TCP) read, or accept() */
+       if (len == 0 || len == -EAGAIN) {
+               rqstp->rq_res.len = 0;
+               svc_xprt_release(rqstp);
+               return -EAGAIN;
+       }
+       clear_bit(XPT_OLD, &xprt->xpt_flags);
+
+       rqstp->rq_secure = svc_port_is_privileged(svc_addr(rqstp));
+       rqstp->rq_chandle.defer = svc_defer;
+
+       if (serv->sv_stats)
+               serv->sv_stats->netcnt++;
+       return len;
+}
+EXPORT_SYMBOL(svc_recv);
+
+/*
+ * Drop request
+ */
+void svc_drop(struct svc_rqst *rqstp)
+{
+       dprintk("svc: xprt %p dropped request\n", rqstp->rq_xprt);
+       svc_xprt_release(rqstp);
+}
+EXPORT_SYMBOL(svc_drop);
+
+/*
+ * Return reply to client.
+ */
+int svc_send(struct svc_rqst *rqstp)
+{
+       struct svc_xprt *xprt;
+       int             len;
+       struct xdr_buf  *xb;
+
+       xprt = rqstp->rq_xprt;
+       if (!xprt)
+               return -EFAULT;
+
+       /* release the receive skb before sending the reply */
+       rqstp->rq_xprt->xpt_ops->xpo_release_rqst(rqstp);
+
+       /* calculate over-all length */
+       xb = &rqstp->rq_res;
+       xb->len = xb->head[0].iov_len +
+               xb->page_len +
+               xb->tail[0].iov_len;
+
+       /* Grab mutex to serialize outgoing data. */
+       mutex_lock(&xprt->xpt_mutex);
+       if (test_bit(XPT_DEAD, &xprt->xpt_flags))
+               len = -ENOTCONN;
+       else
+               len = xprt->xpt_ops->xpo_sendto(rqstp);
+       mutex_unlock(&xprt->xpt_mutex);
+       svc_xprt_release(rqstp);
+
+       if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN)
+               return 0;
+       return len;
+}
+
+/*
+ * Timer function to close old temporary transports, using
+ * a mark-and-sweep algorithm.
+ */
+static void svc_age_temp_xprts(unsigned long closure)
+{
+       struct svc_serv *serv = (struct svc_serv *)closure;
+       struct svc_xprt *xprt;
+       struct list_head *le, *next;
+       LIST_HEAD(to_be_aged);
+
+       dprintk("svc_age_temp_xprts\n");
+
+       if (!spin_trylock_bh(&serv->sv_lock)) {
+               /* busy, try again 1 sec later */
+               dprintk("svc_age_temp_xprts: busy\n");
+               mod_timer(&serv->sv_temptimer, jiffies + HZ);
+               return;
+       }
+
+       list_for_each_safe(le, next, &serv->sv_tempsocks) {
+               xprt = list_entry(le, struct svc_xprt, xpt_list);
+
+               /* First time through, just mark it OLD. Second time
+                * through, close it. */
+               if (!test_and_set_bit(XPT_OLD, &xprt->xpt_flags))
+                       continue;
+               if (atomic_read(&xprt->xpt_ref.refcount) > 1
+                   || test_bit(XPT_BUSY, &xprt->xpt_flags))
+                       continue;
+               svc_xprt_get(xprt);
+               list_move(le, &to_be_aged);
+               set_bit(XPT_CLOSE, &xprt->xpt_flags);
+               set_bit(XPT_DETACHED, &xprt->xpt_flags);
+       }
+       spin_unlock_bh(&serv->sv_lock);
+
+       while (!list_empty(&to_be_aged)) {
+               le = to_be_aged.next;
+               /* fiddling the xpt_list node is safe 'cos we're XPT_DETACHED */
+               list_del_init(le);
+               xprt = list_entry(le, struct svc_xprt, xpt_list);
+
+               dprintk("queuing xprt %p for closing\n", xprt);
+
+               /* a thread will dequeue and close it soon */
+               svc_xprt_enqueue(xprt);
+               svc_xprt_put(xprt);
+       }
+
+       mod_timer(&serv->sv_temptimer, jiffies + svc_conn_age_period * HZ);
+}
+
+/*
+ * Remove a dead transport
+ */
+void svc_delete_xprt(struct svc_xprt *xprt)
+{
+       struct svc_serv *serv = xprt->xpt_server;
+
+       dprintk("svc: svc_delete_xprt(%p)\n", xprt);
+       xprt->xpt_ops->xpo_detach(xprt);
+
+       spin_lock_bh(&serv->sv_lock);
+       if (!test_and_set_bit(XPT_DETACHED, &xprt->xpt_flags))
+               list_del_init(&xprt->xpt_list);
+       /*
+        * We used to delete the transport from whichever list
+        * it's sk_xprt.xpt_ready node was on, but we don't actually
+        * need to.  This is because the only time we're called
+        * while still attached to a queue, the queue itself
+        * is about to be destroyed (in svc_destroy).
+        */
+       if (!test_and_set_bit(XPT_DEAD, &xprt->xpt_flags)) {
+               BUG_ON(atomic_read(&xprt->xpt_ref.refcount) < 2);
+               if (test_bit(XPT_TEMP, &xprt->xpt_flags))
+                       serv->sv_tmpcnt--;
+               svc_xprt_put(xprt);
+       }
+       spin_unlock_bh(&serv->sv_lock);
+}
+
+void svc_close_xprt(struct svc_xprt *xprt)
+{
+       set_bit(XPT_CLOSE, &xprt->xpt_flags);
+       if (test_and_set_bit(XPT_BUSY, &xprt->xpt_flags))
+               /* someone else will have to effect the close */
+               return;
+
+       svc_xprt_get(xprt);
+       svc_delete_xprt(xprt);
+       clear_bit(XPT_BUSY, &xprt->xpt_flags);
+       svc_xprt_put(xprt);
+}
+EXPORT_SYMBOL_GPL(svc_close_xprt);
+
+void svc_close_all(struct list_head *xprt_list)
+{
+       struct svc_xprt *xprt;
+       struct svc_xprt *tmp;
+
+       list_for_each_entry_safe(xprt, tmp, xprt_list, xpt_list) {
+               set_bit(XPT_CLOSE, &xprt->xpt_flags);
+               if (test_bit(XPT_BUSY, &xprt->xpt_flags)) {
+                       /* Waiting to be processed, but no threads left,
+                        * So just remove it from the waiting list
+                        */
+                       list_del_init(&xprt->xpt_ready);
+                       clear_bit(XPT_BUSY, &xprt->xpt_flags);
+               }
+               svc_close_xprt(xprt);
+       }
+}
+
+/*
+ * Handle defer and revisit of requests
+ */
+
+static void svc_revisit(struct cache_deferred_req *dreq, int too_many)
+{
+       struct svc_deferred_req *dr =
+               container_of(dreq, struct svc_deferred_req, handle);
+       struct svc_xprt *xprt = dr->xprt;
+
+       if (too_many) {
+               svc_xprt_put(xprt);
+               kfree(dr);
+               return;
+       }
+       dprintk("revisit queued\n");
+       dr->xprt = NULL;
+       spin_lock(&xprt->xpt_lock);
+       list_add(&dr->handle.recent, &xprt->xpt_deferred);
+       spin_unlock(&xprt->xpt_lock);
+       set_bit(XPT_DEFERRED, &xprt->xpt_flags);
+       svc_xprt_enqueue(xprt);
+       svc_xprt_put(xprt);
+}
+
+/*
+ * Save the request off for later processing. The request buffer looks
+ * like this:
+ *
+ * <xprt-header><rpc-header><rpc-pagelist><rpc-tail>
+ *
+ * This code can only handle requests that consist of an xprt-header
+ * and rpc-header.
+ */
+static struct cache_deferred_req *svc_defer(struct cache_req *req)
+{
+       struct svc_rqst *rqstp = container_of(req, struct svc_rqst, rq_chandle);
+       struct svc_deferred_req *dr;
+
+       if (rqstp->rq_arg.page_len)
+               return NULL; /* if more than a page, give up FIXME */
+       if (rqstp->rq_deferred) {
+               dr = rqstp->rq_deferred;
+               rqstp->rq_deferred = NULL;
+       } else {
+               size_t skip;
+               size_t size;
+               /* FIXME maybe discard if size too large */
+               size = sizeof(struct svc_deferred_req) + rqstp->rq_arg.len;
+               dr = kmalloc(size, GFP_KERNEL);
+               if (dr == NULL)
+                       return NULL;
+
+               dr->handle.owner = rqstp->rq_server;
+               dr->prot = rqstp->rq_prot;
+               memcpy(&dr->addr, &rqstp->rq_addr, rqstp->rq_addrlen);
+               dr->addrlen = rqstp->rq_addrlen;
+               dr->daddr = rqstp->rq_daddr;
+               dr->argslen = rqstp->rq_arg.len >> 2;
+               dr->xprt_hlen = rqstp->rq_xprt_hlen;
+
+               /* back up head to the start of the buffer and copy */
+               skip = rqstp->rq_arg.len - rqstp->rq_arg.head[0].iov_len;
+               memcpy(dr->args, rqstp->rq_arg.head[0].iov_base - skip,
+                      dr->argslen << 2);
+       }
+       svc_xprt_get(rqstp->rq_xprt);
+       dr->xprt = rqstp->rq_xprt;
+
+       dr->handle.revisit = svc_revisit;
+       return &dr->handle;
+}
+
+/*
+ * recv data from a deferred request into an active one
+ */
+static int svc_deferred_recv(struct svc_rqst *rqstp)
+{
+       struct svc_deferred_req *dr = rqstp->rq_deferred;
+
+       /* setup iov_base past transport header */
+       rqstp->rq_arg.head[0].iov_base = dr->args + (dr->xprt_hlen>>2);
+       /* The iov_len does not include the transport header bytes */
+       rqstp->rq_arg.head[0].iov_len = (dr->argslen<<2) - dr->xprt_hlen;
+       rqstp->rq_arg.page_len = 0;
+       /* The rq_arg.len includes the transport header bytes */
+       rqstp->rq_arg.len     = dr->argslen<<2;
+       rqstp->rq_prot        = dr->prot;
+       memcpy(&rqstp->rq_addr, &dr->addr, dr->addrlen);
+       rqstp->rq_addrlen     = dr->addrlen;
+       /* Save off transport header len in case we get deferred again */
+       rqstp->rq_xprt_hlen   = dr->xprt_hlen;
+       rqstp->rq_daddr       = dr->daddr;
+       rqstp->rq_respages    = rqstp->rq_pages;
+       return (dr->argslen<<2) - dr->xprt_hlen;
+}
+
+
+static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt)
+{
+       struct svc_deferred_req *dr = NULL;
+
+       if (!test_bit(XPT_DEFERRED, &xprt->xpt_flags))
+               return NULL;
+       spin_lock(&xprt->xpt_lock);
+       clear_bit(XPT_DEFERRED, &xprt->xpt_flags);
+       if (!list_empty(&xprt->xpt_deferred)) {
+               dr = list_entry(xprt->xpt_deferred.next,
+                               struct svc_deferred_req,
+                               handle.recent);
+               list_del_init(&dr->handle.recent);
+               set_bit(XPT_DEFERRED, &xprt->xpt_flags);
+       }
+       spin_unlock(&xprt->xpt_lock);
+       return dr;
+}
+
+/*
+ * Return the transport instance pointer for the endpoint accepting
+ * connections/peer traffic from the specified transport class,
+ * address family and port.
+ *
+ * Specifying 0 for the address family or port is effectively a
+ * wild-card, and will result in matching the first transport in the
+ * service's list that has a matching class name.
+ */
+struct svc_xprt *svc_find_xprt(struct svc_serv *serv, char *xcl_name,
+                              int af, int port)
+{
+       struct svc_xprt *xprt;
+       struct svc_xprt *found = NULL;
+
+       /* Sanity check the args */
+       if (!serv || !xcl_name)
+               return found;
+
+       spin_lock_bh(&serv->sv_lock);
+       list_for_each_entry(xprt, &serv->sv_permsocks, xpt_list) {
+               if (strcmp(xprt->xpt_class->xcl_name, xcl_name))
+                       continue;
+               if (af != AF_UNSPEC && af != xprt->xpt_local.ss_family)
+                       continue;
+               if (port && port != svc_xprt_local_port(xprt))
+                       continue;
+               found = xprt;
+               svc_xprt_get(xprt);
+               break;
+       }
+       spin_unlock_bh(&serv->sv_lock);
+       return found;
+}
+EXPORT_SYMBOL_GPL(svc_find_xprt);
+
+/*
+ * Format a buffer with a list of the active transports. A zero for
+ * the buflen parameter disables target buffer overflow checking.
+ */
+int svc_xprt_names(struct svc_serv *serv, char *buf, int buflen)
+{
+       struct svc_xprt *xprt;
+       char xprt_str[64];
+       int totlen = 0;
+       int len;
+
+       /* Sanity check args */
+       if (!serv)
+               return 0;
+
+       spin_lock_bh(&serv->sv_lock);
+       list_for_each_entry(xprt, &serv->sv_permsocks, xpt_list) {
+               len = snprintf(xprt_str, sizeof(xprt_str),
+                              "%s %d\n", xprt->xpt_class->xcl_name,
+                              svc_xprt_local_port(xprt));
+               /* If the string was truncated, replace with error string */
+               if (len >= sizeof(xprt_str))
+                       strcpy(xprt_str, "name-too-long\n");
+               /* Don't overflow buffer */
+               len = strlen(xprt_str);
+               if (buflen && (len + totlen >= buflen))
+                       break;
+               strcpy(buf+totlen, xprt_str);
+               totlen += len;
+       }
+       spin_unlock_bh(&serv->sv_lock);
+       return totlen;
+}
+EXPORT_SYMBOL_GPL(svc_xprt_names);
index af7c5f05c6e11b3d5d734d1ee2143e54c71517bb..8a73cbb16052397b0455070cfc670a931ff2ec8f 100644 (file)
@@ -57,11 +57,13 @@ svc_authenticate(struct svc_rqst *rqstp, __be32 *authp)
        rqstp->rq_authop = aops;
        return aops->accept(rqstp, authp);
 }
+EXPORT_SYMBOL(svc_authenticate);
 
 int svc_set_client(struct svc_rqst *rqstp)
 {
        return rqstp->rq_authop->set_client(rqstp);
 }
+EXPORT_SYMBOL(svc_set_client);
 
 /* A request, which was authenticated, has now executed.
  * Time to finalise the credentials and verifier
@@ -93,6 +95,7 @@ svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops)
        spin_unlock(&authtab_lock);
        return rv;
 }
+EXPORT_SYMBOL(svc_auth_register);
 
 void
 svc_auth_unregister(rpc_authflavor_t flavor)
@@ -129,6 +132,7 @@ void auth_domain_put(struct auth_domain *dom)
                spin_unlock(&auth_domain_lock);
        }
 }
+EXPORT_SYMBOL(auth_domain_put);
 
 struct auth_domain *
 auth_domain_lookup(char *name, struct auth_domain *new)
@@ -153,8 +157,10 @@ auth_domain_lookup(char *name, struct auth_domain *new)
        spin_unlock(&auth_domain_lock);
        return new;
 }
+EXPORT_SYMBOL(auth_domain_lookup);
 
 struct auth_domain *auth_domain_find(char *name)
 {
        return auth_domain_lookup(name, NULL);
 }
+EXPORT_SYMBOL(auth_domain_find);
index 411479411b21052a3e138c5109880abd881b77b4..3c64051e455533aeb11df479f3c72877838e4483 100644 (file)
@@ -63,6 +63,7 @@ struct auth_domain *unix_domain_find(char *name)
                rv = auth_domain_lookup(name, &new->h);
        }
 }
+EXPORT_SYMBOL(unix_domain_find);
 
 static void svcauth_unix_domain_release(struct auth_domain *dom)
 {
@@ -340,6 +341,7 @@ int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom)
        else
                return -ENOMEM;
 }
+EXPORT_SYMBOL(auth_unix_add_addr);
 
 int auth_unix_forget_old(struct auth_domain *dom)
 {
@@ -351,6 +353,7 @@ int auth_unix_forget_old(struct auth_domain *dom)
        udom->addr_changes++;
        return 0;
 }
+EXPORT_SYMBOL(auth_unix_forget_old);
 
 struct auth_domain *auth_unix_lookup(struct in_addr addr)
 {
@@ -375,50 +378,56 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr)
        cache_put(&ipm->h, &ip_map_cache);
        return rv;
 }
+EXPORT_SYMBOL(auth_unix_lookup);
 
 void svcauth_unix_purge(void)
 {
        cache_purge(&ip_map_cache);
 }
+EXPORT_SYMBOL(svcauth_unix_purge);
 
 static inline struct ip_map *
 ip_map_cached_get(struct svc_rqst *rqstp)
 {
-       struct ip_map *ipm;
-       struct svc_sock *svsk = rqstp->rq_sock;
-       spin_lock(&svsk->sk_lock);
-       ipm = svsk->sk_info_authunix;
-       if (ipm != NULL) {
-               if (!cache_valid(&ipm->h)) {
-                       /*
-                        * The entry has been invalidated since it was
-                        * remembered, e.g. by a second mount from the
-                        * same IP address.
-                        */
-                       svsk->sk_info_authunix = NULL;
-                       spin_unlock(&svsk->sk_lock);
-                       cache_put(&ipm->h, &ip_map_cache);
-                       return NULL;
+       struct ip_map *ipm = NULL;
+       struct svc_xprt *xprt = rqstp->rq_xprt;
+
+       if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags)) {
+               spin_lock(&xprt->xpt_lock);
+               ipm = xprt->xpt_auth_cache;
+               if (ipm != NULL) {
+                       if (!cache_valid(&ipm->h)) {
+                               /*
+                                * The entry has been invalidated since it was
+                                * remembered, e.g. by a second mount from the
+                                * same IP address.
+                                */
+                               xprt->xpt_auth_cache = NULL;
+                               spin_unlock(&xprt->xpt_lock);
+                               cache_put(&ipm->h, &ip_map_cache);
+                               return NULL;
+                       }
+                       cache_get(&ipm->h);
                }
-               cache_get(&ipm->h);
+               spin_unlock(&xprt->xpt_lock);
        }
-       spin_unlock(&svsk->sk_lock);
        return ipm;
 }
 
 static inline void
 ip_map_cached_put(struct svc_rqst *rqstp, struct ip_map *ipm)
 {
-       struct svc_sock *svsk = rqstp->rq_sock;
+       struct svc_xprt *xprt = rqstp->rq_xprt;
 
-       spin_lock(&svsk->sk_lock);
-       if (svsk->sk_sock->type == SOCK_STREAM &&
-           svsk->sk_info_authunix == NULL) {
-               /* newly cached, keep the reference */
-               svsk->sk_info_authunix = ipm;
-               ipm = NULL;
+       if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags)) {
+               spin_lock(&xprt->xpt_lock);
+               if (xprt->xpt_auth_cache == NULL) {
+                       /* newly cached, keep the reference */
+                       xprt->xpt_auth_cache = ipm;
+                       ipm = NULL;
+               }
+               spin_unlock(&xprt->xpt_lock);
        }
-       spin_unlock(&svsk->sk_lock);
        if (ipm)
                cache_put(&ipm->h, &ip_map_cache);
 }
index c75bffeb89eb705831585ba1447c0ba77dd06a9c..1d3e5fcc2cc4d0728f4d99c39d28ecd1fb9a2d80 100644 (file)
@@ -5,7 +5,7 @@
  *
  * The server scheduling algorithm does not always distribute the load
  * evenly when servicing a single client. May need to modify the
- * svc_sock_enqueue procedure...
+ * svc_xprt_enqueue procedure...
  *
  * TCP support is largely untested and may be a little slow. The problem
  * is that we currently do two separate recvfrom's, one for the 4-byte
 #include <linux/sunrpc/svcsock.h>
 #include <linux/sunrpc/stats.h>
 
-/* SMP locking strategy:
- *
- *     svc_pool->sp_lock protects most of the fields of that pool.
- *     svc_serv->sv_lock protects sv_tempsocks, sv_permsocks, sv_tmpcnt.
- *     when both need to be taken (rare), svc_serv->sv_lock is first.
- *     BKL protects svc_serv->sv_nrthread.
- *     svc_sock->sk_lock protects the svc_sock->sk_deferred list
- *             and the ->sk_info_authunix cache.
- *     svc_sock->sk_flags.SK_BUSY prevents a svc_sock being enqueued multiply.
- *
- *     Some flags can be set to certain values at any time
- *     providing that certain rules are followed:
- *
- *     SK_CONN, SK_DATA, can be set or cleared at any time.
- *             after a set, svc_sock_enqueue must be called.
- *             after a clear, the socket must be read/accepted
- *              if this succeeds, it must be set again.
- *     SK_CLOSE can set at any time. It is never cleared.
- *      sk_inuse contains a bias of '1' until SK_DEAD is set.
- *             so when sk_inuse hits zero, we know the socket is dead
- *             and no-one is using it.
- *      SK_DEAD can only be set while SK_BUSY is held which ensures
- *             no other thread will be using the socket or will try to
- *            set SK_DEAD.
- *
- */
-
-#define RPCDBG_FACILITY        RPCDBG_SVCSOCK
+#define RPCDBG_FACILITY        RPCDBG_SVCXPRT
 
 
 static struct svc_sock *svc_setup_socket(struct svc_serv *, struct socket *,
                                         int *errp, int flags);
-static void            svc_delete_socket(struct svc_sock *svsk);
 static void            svc_udp_data_ready(struct sock *, int);
 static int             svc_udp_recvfrom(struct svc_rqst *);
 static int             svc_udp_sendto(struct svc_rqst *);
-static void            svc_close_socket(struct svc_sock *svsk);
-
-static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk);
-static int svc_deferred_recv(struct svc_rqst *rqstp);
-static struct cache_deferred_req *svc_defer(struct cache_req *req);
-
-/* apparently the "standard" is that clients close
- * idle connections after 5 minutes, servers after
- * 6 minutes
- *   http://www.connectathon.org/talks96/nfstcp.pdf
- */
-static int svc_conn_age_period = 6*60;
+static void            svc_sock_detach(struct svc_xprt *);
+static void            svc_sock_free(struct svc_xprt *);
 
+static struct svc_xprt *svc_create_socket(struct svc_serv *, int,
+                                         struct sockaddr *, int, int);
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 static struct lock_class_key svc_key[2];
 static struct lock_class_key svc_slock_key[2];
 
-static inline void svc_reclassify_socket(struct socket *sock)
+static void svc_reclassify_socket(struct socket *sock)
 {
        struct sock *sk = sock->sk;
        BUG_ON(sock_owned_by_user(sk));
        switch (sk->sk_family) {
        case AF_INET:
                sock_lock_init_class_and_name(sk, "slock-AF_INET-NFSD",
-                   &svc_slock_key[0], "sk_lock-AF_INET-NFSD", &svc_key[0]);
+                                             &svc_slock_key[0],
+                                             "sk_xprt.xpt_lock-AF_INET-NFSD",
+                                             &svc_key[0]);
                break;
 
        case AF_INET6:
                sock_lock_init_class_and_name(sk, "slock-AF_INET6-NFSD",
-                   &svc_slock_key[1], "sk_lock-AF_INET6-NFSD", &svc_key[1]);
+                                             &svc_slock_key[1],
+                                             "sk_xprt.xpt_lock-AF_INET6-NFSD",
+                                             &svc_key[1]);
                break;
 
        default:
@@ -121,81 +89,26 @@ static inline void svc_reclassify_socket(struct socket *sock)
        }
 }
 #else
-static inline void svc_reclassify_socket(struct socket *sock)
+static void svc_reclassify_socket(struct socket *sock)
 {
 }
 #endif
 
-static char *__svc_print_addr(struct sockaddr *addr, char *buf, size_t len)
-{
-       switch (addr->sa_family) {
-       case AF_INET:
-               snprintf(buf, len, "%u.%u.%u.%u, port=%u",
-                       NIPQUAD(((struct sockaddr_in *) addr)->sin_addr),
-                       ntohs(((struct sockaddr_in *) addr)->sin_port));
-               break;
-
-       case AF_INET6:
-               snprintf(buf, len, "%x:%x:%x:%x:%x:%x:%x:%x, port=%u",
-                       NIP6(((struct sockaddr_in6 *) addr)->sin6_addr),
-                       ntohs(((struct sockaddr_in6 *) addr)->sin6_port));
-               break;
-
-       default:
-               snprintf(buf, len, "unknown address type: %d", addr->sa_family);
-               break;
-       }
-       return buf;
-}
-
-/**
- * svc_print_addr - Format rq_addr field for printing
- * @rqstp: svc_rqst struct containing address to print
- * @buf: target buffer for formatted address
- * @len: length of target buffer
- *
- */
-char *svc_print_addr(struct svc_rqst *rqstp, char *buf, size_t len)
-{
-       return __svc_print_addr(svc_addr(rqstp), buf, len);
-}
-EXPORT_SYMBOL_GPL(svc_print_addr);
-
-/*
- * Queue up an idle server thread.  Must have pool->sp_lock held.
- * Note: this is really a stack rather than a queue, so that we only
- * use as many different threads as we need, and the rest don't pollute
- * the cache.
- */
-static inline void
-svc_thread_enqueue(struct svc_pool *pool, struct svc_rqst *rqstp)
-{
-       list_add(&rqstp->rq_list, &pool->sp_threads);
-}
-
-/*
- * Dequeue an nfsd thread.  Must have pool->sp_lock held.
- */
-static inline void
-svc_thread_dequeue(struct svc_pool *pool, struct svc_rqst *rqstp)
-{
-       list_del(&rqstp->rq_list);
-}
-
 /*
  * Release an skbuff after use
  */
-static inline void
-svc_release_skb(struct svc_rqst *rqstp)
+static void svc_release_skb(struct svc_rqst *rqstp)
 {
-       struct sk_buff *skb = rqstp->rq_skbuff;
+       struct sk_buff *skb = rqstp->rq_xprt_ctxt;
        struct svc_deferred_req *dr = rqstp->rq_deferred;
 
        if (skb) {
-               rqstp->rq_skbuff = NULL;
+               struct svc_sock *svsk =
+                       container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+               rqstp->rq_xprt_ctxt = NULL;
 
                dprintk("svc: service %p, releasing skb %p\n", rqstp, skb);
-               skb_free_datagram(rqstp->rq_sock->sk_sk, skb);
+               skb_free_datagram(svsk->sk_sk, skb);
        }
        if (dr) {
                rqstp->rq_deferred = NULL;
@@ -203,253 +116,6 @@ svc_release_skb(struct svc_rqst *rqstp)
        }
 }
 
-/*
- * Any space to write?
- */
-static inline unsigned long
-svc_sock_wspace(struct svc_sock *svsk)
-{
-       int wspace;
-
-       if (svsk->sk_sock->type == SOCK_STREAM)
-               wspace = sk_stream_wspace(svsk->sk_sk);
-       else
-               wspace = sock_wspace(svsk->sk_sk);
-
-       return wspace;
-}
-
-/*
- * Queue up a socket with data pending. If there are idle nfsd
- * processes, wake 'em up.
- *
- */
-static void
-svc_sock_enqueue(struct svc_sock *svsk)
-{
-       struct svc_serv *serv = svsk->sk_server;
-       struct svc_pool *pool;
-       struct svc_rqst *rqstp;
-       int cpu;
-
-       if (!(svsk->sk_flags &
-             ( (1<<SK_CONN)|(1<<SK_DATA)|(1<<SK_CLOSE)|(1<<SK_DEFERRED)) ))
-               return;
-       if (test_bit(SK_DEAD, &svsk->sk_flags))
-               return;
-
-       cpu = get_cpu();
-       pool = svc_pool_for_cpu(svsk->sk_server, cpu);
-       put_cpu();
-
-       spin_lock_bh(&pool->sp_lock);
-
-       if (!list_empty(&pool->sp_threads) &&
-           !list_empty(&pool->sp_sockets))
-               printk(KERN_ERR
-                       "svc_sock_enqueue: threads and sockets both waiting??\n");
-
-       if (test_bit(SK_DEAD, &svsk->sk_flags)) {
-               /* Don't enqueue dead sockets */
-               dprintk("svc: socket %p is dead, not enqueued\n", svsk->sk_sk);
-               goto out_unlock;
-       }
-
-       /* Mark socket as busy. It will remain in this state until the
-        * server has processed all pending data and put the socket back
-        * on the idle list.  We update SK_BUSY atomically because
-        * it also guards against trying to enqueue the svc_sock twice.
-        */
-       if (test_and_set_bit(SK_BUSY, &svsk->sk_flags)) {
-               /* Don't enqueue socket while already enqueued */
-               dprintk("svc: socket %p busy, not enqueued\n", svsk->sk_sk);
-               goto out_unlock;
-       }
-       BUG_ON(svsk->sk_pool != NULL);
-       svsk->sk_pool = pool;
-
-       set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
-       if (((atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg)*2
-            > svc_sock_wspace(svsk))
-           && !test_bit(SK_CLOSE, &svsk->sk_flags)
-           && !test_bit(SK_CONN, &svsk->sk_flags)) {
-               /* Don't enqueue while not enough space for reply */
-               dprintk("svc: socket %p  no space, %d*2 > %ld, not enqueued\n",
-                       svsk->sk_sk, atomic_read(&svsk->sk_reserved)+serv->sv_max_mesg,
-                       svc_sock_wspace(svsk));
-               svsk->sk_pool = NULL;
-               clear_bit(SK_BUSY, &svsk->sk_flags);
-               goto out_unlock;
-       }
-       clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
-
-
-       if (!list_empty(&pool->sp_threads)) {
-               rqstp = list_entry(pool->sp_threads.next,
-                                  struct svc_rqst,
-                                  rq_list);
-               dprintk("svc: socket %p served by daemon %p\n",
-                       svsk->sk_sk, rqstp);
-               svc_thread_dequeue(pool, rqstp);
-               if (rqstp->rq_sock)
-                       printk(KERN_ERR
-                               "svc_sock_enqueue: server %p, rq_sock=%p!\n",
-                               rqstp, rqstp->rq_sock);
-               rqstp->rq_sock = svsk;
-               atomic_inc(&svsk->sk_inuse);
-               rqstp->rq_reserved = serv->sv_max_mesg;
-               atomic_add(rqstp->rq_reserved, &svsk->sk_reserved);
-               BUG_ON(svsk->sk_pool != pool);
-               wake_up(&rqstp->rq_wait);
-       } else {
-               dprintk("svc: socket %p put into queue\n", svsk->sk_sk);
-               list_add_tail(&svsk->sk_ready, &pool->sp_sockets);
-               BUG_ON(svsk->sk_pool != pool);
-       }
-
-out_unlock:
-       spin_unlock_bh(&pool->sp_lock);
-}
-
-/*
- * Dequeue the first socket.  Must be called with the pool->sp_lock held.
- */
-static inline struct svc_sock *
-svc_sock_dequeue(struct svc_pool *pool)
-{
-       struct svc_sock *svsk;
-
-       if (list_empty(&pool->sp_sockets))
-               return NULL;
-
-       svsk = list_entry(pool->sp_sockets.next,
-                         struct svc_sock, sk_ready);
-       list_del_init(&svsk->sk_ready);
-
-       dprintk("svc: socket %p dequeued, inuse=%d\n",
-               svsk->sk_sk, atomic_read(&svsk->sk_inuse));
-
-       return svsk;
-}
-
-/*
- * Having read something from a socket, check whether it
- * needs to be re-enqueued.
- * Note: SK_DATA only gets cleared when a read-attempt finds
- * no (or insufficient) data.
- */
-static inline void
-svc_sock_received(struct svc_sock *svsk)
-{
-       svsk->sk_pool = NULL;
-       clear_bit(SK_BUSY, &svsk->sk_flags);
-       svc_sock_enqueue(svsk);
-}
-
-
-/**
- * svc_reserve - change the space reserved for the reply to a request.
- * @rqstp:  The request in question
- * @space: new max space to reserve
- *
- * Each request reserves some space on the output queue of the socket
- * to make sure the reply fits.  This function reduces that reserved
- * space to be the amount of space used already, plus @space.
- *
- */
-void svc_reserve(struct svc_rqst *rqstp, int space)
-{
-       space += rqstp->rq_res.head[0].iov_len;
-
-       if (space < rqstp->rq_reserved) {
-               struct svc_sock *svsk = rqstp->rq_sock;
-               atomic_sub((rqstp->rq_reserved - space), &svsk->sk_reserved);
-               rqstp->rq_reserved = space;
-
-               svc_sock_enqueue(svsk);
-       }
-}
-
-/*
- * Release a socket after use.
- */
-static inline void
-svc_sock_put(struct svc_sock *svsk)
-{
-       if (atomic_dec_and_test(&svsk->sk_inuse)) {
-               BUG_ON(! test_bit(SK_DEAD, &svsk->sk_flags));
-
-               dprintk("svc: releasing dead socket\n");
-               if (svsk->sk_sock->file)
-                       sockfd_put(svsk->sk_sock);
-               else
-                       sock_release(svsk->sk_sock);
-               if (svsk->sk_info_authunix != NULL)
-                       svcauth_unix_info_release(svsk->sk_info_authunix);
-               kfree(svsk);
-       }
-}
-
-static void
-svc_sock_release(struct svc_rqst *rqstp)
-{
-       struct svc_sock *svsk = rqstp->rq_sock;
-
-       svc_release_skb(rqstp);
-
-       svc_free_res_pages(rqstp);
-       rqstp->rq_res.page_len = 0;
-       rqstp->rq_res.page_base = 0;
-
-
-       /* Reset response buffer and release
-        * the reservation.
-        * But first, check that enough space was reserved
-        * for the reply, otherwise we have a bug!
-        */
-       if ((rqstp->rq_res.len) >  rqstp->rq_reserved)
-               printk(KERN_ERR "RPC request reserved %d but used %d\n",
-                      rqstp->rq_reserved,
-                      rqstp->rq_res.len);
-
-       rqstp->rq_res.head[0].iov_len = 0;
-       svc_reserve(rqstp, 0);
-       rqstp->rq_sock = NULL;
-
-       svc_sock_put(svsk);
-}
-
-/*
- * External function to wake up a server waiting for data
- * This really only makes sense for services like lockd
- * which have exactly one thread anyway.
- */
-void
-svc_wake_up(struct svc_serv *serv)
-{
-       struct svc_rqst *rqstp;
-       unsigned int i;
-       struct svc_pool *pool;
-
-       for (i = 0; i < serv->sv_nrpools; i++) {
-               pool = &serv->sv_pools[i];
-
-               spin_lock_bh(&pool->sp_lock);
-               if (!list_empty(&pool->sp_threads)) {
-                       rqstp = list_entry(pool->sp_threads.next,
-                                          struct svc_rqst,
-                                          rq_list);
-                       dprintk("svc: daemon %p woken up.\n", rqstp);
-                       /*
-                       svc_thread_dequeue(pool, rqstp);
-                       rqstp->rq_sock = NULL;
-                        */
-                       wake_up(&rqstp->rq_wait);
-               }
-               spin_unlock_bh(&pool->sp_lock);
-       }
-}
-
 union svc_pktinfo_u {
        struct in_pktinfo pkti;
        struct in6_pktinfo pkti6;
@@ -459,7 +125,9 @@ union svc_pktinfo_u {
 
 static void svc_set_cmsg_data(struct svc_rqst *rqstp, struct cmsghdr *cmh)
 {
-       switch (rqstp->rq_sock->sk_sk->sk_family) {
+       struct svc_sock *svsk =
+               container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+       switch (svsk->sk_sk->sk_family) {
        case AF_INET: {
                        struct in_pktinfo *pki = CMSG_DATA(cmh);
 
@@ -489,10 +157,10 @@ static void svc_set_cmsg_data(struct svc_rqst *rqstp, struct cmsghdr *cmh)
 /*
  * Generic sendto routine
  */
-static int
-svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
+static int svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
 {
-       struct svc_sock *svsk = rqstp->rq_sock;
+       struct svc_sock *svsk =
+               container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
        struct socket   *sock = svsk->sk_sock;
        int             slen;
        union {
@@ -565,7 +233,7 @@ svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
        }
 out:
        dprintk("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %s)\n",
-               rqstp->rq_sock, xdr->head[0].iov_base, xdr->head[0].iov_len,
+               svsk, xdr->head[0].iov_base, xdr->head[0].iov_len,
                xdr->len, len, svc_print_addr(rqstp, buf, sizeof(buf)));
 
        return len;
@@ -602,7 +270,7 @@ svc_sock_names(char *buf, struct svc_serv *serv, char *toclose)
        if (!serv)
                return 0;
        spin_lock_bh(&serv->sv_lock);
-       list_for_each_entry(svsk, &serv->sv_permsocks, sk_list) {
+       list_for_each_entry(svsk, &serv->sv_permsocks, sk_xprt.xpt_list) {
                int onelen = one_sock_name(buf+len, svsk);
                if (toclose && strcmp(toclose, buf+len) == 0)
                        closesk = svsk;
@@ -614,7 +282,7 @@ svc_sock_names(char *buf, struct svc_serv *serv, char *toclose)
                /* Should unregister with portmap, but you cannot
                 * unregister just one protocol...
                 */
-               svc_close_socket(closesk);
+               svc_close_xprt(&closesk->sk_xprt);
        else if (toclose)
                return -ENOENT;
        return len;
@@ -624,8 +292,7 @@ EXPORT_SYMBOL(svc_sock_names);
 /*
  * Check input queue length
  */
-static int
-svc_recv_available(struct svc_sock *svsk)
+static int svc_recv_available(struct svc_sock *svsk)
 {
        struct socket   *sock = svsk->sk_sock;
        int             avail, err;
@@ -638,48 +305,31 @@ svc_recv_available(struct svc_sock *svsk)
 /*
  * Generic recvfrom routine.
  */
-static int
-svc_recvfrom(struct svc_rqst *rqstp, struct kvec *iov, int nr, int buflen)
+static int svc_recvfrom(struct svc_rqst *rqstp, struct kvec *iov, int nr,
+                       int buflen)
 {
-       struct svc_sock *svsk = rqstp->rq_sock;
+       struct svc_sock *svsk =
+               container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
        struct msghdr msg = {
                .msg_flags      = MSG_DONTWAIT,
        };
-       struct sockaddr *sin;
        int len;
 
+       rqstp->rq_xprt_hlen = 0;
+
        len = kernel_recvmsg(svsk->sk_sock, &msg, iov, nr, buflen,
                                msg.msg_flags);
 
-       /* sock_recvmsg doesn't fill in the name/namelen, so we must..
-        */
-       memcpy(&rqstp->rq_addr, &svsk->sk_remote, svsk->sk_remotelen);
-       rqstp->rq_addrlen = svsk->sk_remotelen;
-
-       /* Destination address in request is needed for binding the
-        * source address in RPC callbacks later.
-        */
-       sin = (struct sockaddr *)&svsk->sk_local;
-       switch (sin->sa_family) {
-       case AF_INET:
-               rqstp->rq_daddr.addr = ((struct sockaddr_in *)sin)->sin_addr;
-               break;
-       case AF_INET6:
-               rqstp->rq_daddr.addr6 = ((struct sockaddr_in6 *)sin)->sin6_addr;
-               break;
-       }
-
        dprintk("svc: socket %p recvfrom(%p, %Zu) = %d\n",
                svsk, iov[0].iov_base, iov[0].iov_len, len);
-
        return len;
 }
 
 /*
  * Set socket snd and rcv buffer lengths
  */
-static inline void
-svc_sock_setbufsize(struct socket *sock, unsigned int snd, unsigned int rcv)
+static void svc_sock_setbufsize(struct socket *sock, unsigned int snd,
+                               unsigned int rcv)
 {
 #if 0
        mm_segment_t    oldfs;
@@ -704,16 +354,16 @@ svc_sock_setbufsize(struct socket *sock, unsigned int snd, unsigned int rcv)
 /*
  * INET callback when data has been received on the socket.
  */
-static void
-svc_udp_data_ready(struct sock *sk, int count)
+static void svc_udp_data_ready(struct sock *sk, int count)
 {
        struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
 
        if (svsk) {
                dprintk("svc: socket %p(inet %p), count=%d, busy=%d\n",
-                       svsk, sk, count, test_bit(SK_BUSY, &svsk->sk_flags));
-               set_bit(SK_DATA, &svsk->sk_flags);
-               svc_sock_enqueue(svsk);
+                       svsk, sk, count,
+                       test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags));
+               set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
+               svc_xprt_enqueue(&svsk->sk_xprt);
        }
        if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
                wake_up_interruptible(sk->sk_sleep);
@@ -722,15 +372,14 @@ svc_udp_data_ready(struct sock *sk, int count)
 /*
  * INET callback when space is newly available on the socket.
  */
-static void
-svc_write_space(struct sock *sk)
+static void svc_write_space(struct sock *sk)
 {
        struct svc_sock *svsk = (struct svc_sock *)(sk->sk_user_data);
 
        if (svsk) {
                dprintk("svc: socket %p(inet %p), write_space busy=%d\n",
-                       svsk, sk, test_bit(SK_BUSY, &svsk->sk_flags));
-               svc_sock_enqueue(svsk);
+                       svsk, sk, test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags));
+               svc_xprt_enqueue(&svsk->sk_xprt);
        }
 
        if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) {
@@ -740,10 +389,19 @@ svc_write_space(struct sock *sk)
        }
 }
 
-static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
-                                           struct cmsghdr *cmh)
+/*
+ * Copy the UDP datagram's destination address to the rqstp structure.
+ * The 'destination' address in this case is the address to which the
+ * peer sent the datagram, i.e. our local address. For multihomed
+ * hosts, this can change from msg to msg. Note that only the IP
+ * address changes, the port number should remain the same.
+ */
+static void svc_udp_get_dest_address(struct svc_rqst *rqstp,
+                                    struct cmsghdr *cmh)
 {
-       switch (rqstp->rq_sock->sk_sk->sk_family) {
+       struct svc_sock *svsk =
+               container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+       switch (svsk->sk_sk->sk_family) {
        case AF_INET: {
                struct in_pktinfo *pki = CMSG_DATA(cmh);
                rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
@@ -760,11 +418,11 @@ static inline void svc_udp_get_dest_address(struct svc_rqst *rqstp,
 /*
  * Receive a datagram from a UDP socket.
  */
-static int
-svc_udp_recvfrom(struct svc_rqst *rqstp)
+static int svc_udp_recvfrom(struct svc_rqst *rqstp)
 {
-       struct svc_sock *svsk = rqstp->rq_sock;
-       struct svc_serv *serv = svsk->sk_server;
+       struct svc_sock *svsk =
+               container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+       struct svc_serv *serv = svsk->sk_xprt.xpt_server;
        struct sk_buff  *skb;
        union {
                struct cmsghdr  hdr;
@@ -779,7 +437,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
                .msg_flags = MSG_DONTWAIT,
        };
 
-       if (test_and_clear_bit(SK_CHNGBUF, &svsk->sk_flags))
+       if (test_and_clear_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags))
            /* udp sockets need large rcvbuf as all pending
             * requests are still in that buffer.  sndbuf must
             * also be large enough that there is enough space
@@ -792,17 +450,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
                                (serv->sv_nrthreads+3) * serv->sv_max_mesg,
                                (serv->sv_nrthreads+3) * serv->sv_max_mesg);
 
-       if ((rqstp->rq_deferred = svc_deferred_dequeue(svsk))) {
-               svc_sock_received(svsk);
-               return svc_deferred_recv(rqstp);
-       }
-
-       if (test_bit(SK_CLOSE, &svsk->sk_flags)) {
-               svc_delete_socket(svsk);
-               return 0;
-       }
-
-       clear_bit(SK_DATA, &svsk->sk_flags);
+       clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
        skb = NULL;
        err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
                             0, 0, MSG_PEEK | MSG_DONTWAIT);
@@ -813,24 +461,27 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
                if (err != -EAGAIN) {
                        /* possibly an icmp error */
                        dprintk("svc: recvfrom returned error %d\n", -err);
-                       set_bit(SK_DATA, &svsk->sk_flags);
+                       set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
                }
-               svc_sock_received(svsk);
+               svc_xprt_received(&svsk->sk_xprt);
                return -EAGAIN;
        }
-       rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
+       len = svc_addr_len(svc_addr(rqstp));
+       if (len < 0)
+               return len;
+       rqstp->rq_addrlen = len;
        if (skb->tstamp.tv64 == 0) {
                skb->tstamp = ktime_get_real();
                /* Don't enable netstamp, sunrpc doesn't
                   need that much accuracy */
        }
        svsk->sk_sk->sk_stamp = skb->tstamp;
-       set_bit(SK_DATA, &svsk->sk_flags); /* there may be more data... */
+       set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); /* there may be more data... */
 
        /*
         * Maybe more packets - kick another thread ASAP.
         */
-       svc_sock_received(svsk);
+       svc_xprt_received(&svsk->sk_xprt);
 
        len  = skb->len - sizeof(struct udphdr);
        rqstp->rq_arg.len = len;
@@ -861,13 +512,14 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
                skb_free_datagram(svsk->sk_sk, skb);
        } else {
                /* we can use it in-place */
-               rqstp->rq_arg.head[0].iov_base = skb->data + sizeof(struct udphdr);
+               rqstp->rq_arg.head[0].iov_base = skb->data +
+                       sizeof(struct udphdr);
                rqstp->rq_arg.head[0].iov_len = len;
                if (skb_checksum_complete(skb)) {
                        skb_free_datagram(svsk->sk_sk, skb);
                        return 0;
                }
-               rqstp->rq_skbuff = skb;
+               rqstp->rq_xprt_ctxt = skb;
        }
 
        rqstp->rq_arg.page_base = 0;
@@ -900,27 +552,81 @@ svc_udp_sendto(struct svc_rqst *rqstp)
        return error;
 }
 
-static void
-svc_udp_init(struct svc_sock *svsk)
+static void svc_udp_prep_reply_hdr(struct svc_rqst *rqstp)
+{
+}
+
+static int svc_udp_has_wspace(struct svc_xprt *xprt)
+{
+       struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
+       struct svc_serv *serv = xprt->xpt_server;
+       unsigned long required;
+
+       /*
+        * Set the SOCK_NOSPACE flag before checking the available
+        * sock space.
+        */
+       set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
+       required = atomic_read(&svsk->sk_xprt.xpt_reserved) + serv->sv_max_mesg;
+       if (required*2 > sock_wspace(svsk->sk_sk))
+               return 0;
+       clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
+       return 1;
+}
+
+static struct svc_xprt *svc_udp_accept(struct svc_xprt *xprt)
+{
+       BUG();
+       return NULL;
+}
+
+static struct svc_xprt *svc_udp_create(struct svc_serv *serv,
+                                      struct sockaddr *sa, int salen,
+                                      int flags)
+{
+       return svc_create_socket(serv, IPPROTO_UDP, sa, salen, flags);
+}
+
+static struct svc_xprt_ops svc_udp_ops = {
+       .xpo_create = svc_udp_create,
+       .xpo_recvfrom = svc_udp_recvfrom,
+       .xpo_sendto = svc_udp_sendto,
+       .xpo_release_rqst = svc_release_skb,
+       .xpo_detach = svc_sock_detach,
+       .xpo_free = svc_sock_free,
+       .xpo_prep_reply_hdr = svc_udp_prep_reply_hdr,
+       .xpo_has_wspace = svc_udp_has_wspace,
+       .xpo_accept = svc_udp_accept,
+};
+
+static struct svc_xprt_class svc_udp_class = {
+       .xcl_name = "udp",
+       .xcl_owner = THIS_MODULE,
+       .xcl_ops = &svc_udp_ops,
+       .xcl_max_payload = RPCSVC_MAXPAYLOAD_UDP,
+};
+
+static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)
 {
        int one = 1;
        mm_segment_t oldfs;
 
+       svc_xprt_init(&svc_udp_class, &svsk->sk_xprt, serv);
+       clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags);
        svsk->sk_sk->sk_data_ready = svc_udp_data_ready;
        svsk->sk_sk->sk_write_space = svc_write_space;
-       svsk->sk_recvfrom = svc_udp_recvfrom;
-       svsk->sk_sendto = svc_udp_sendto;
 
        /* initialise setting must have enough space to
         * receive and respond to one request.
         * svc_udp_recvfrom will re-adjust if necessary
         */
        svc_sock_setbufsize(svsk->sk_sock,
-                           3 * svsk->sk_server->sv_max_mesg,
-                           3 * svsk->sk_server->sv_max_mesg);
+                           3 * svsk->sk_xprt.xpt_server->sv_max_mesg,
+                           3 * svsk->sk_xprt.xpt_server->sv_max_mesg);
 
-       set_bit(SK_DATA, &svsk->sk_flags); /* might have come in before data_ready set up */
-       set_bit(SK_CHNGBUF, &svsk->sk_flags);
+       /* data might have come in before data_ready set up */
+       set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
+       set_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags);
 
        oldfs = get_fs();
        set_fs(KERNEL_DS);
@@ -934,8 +640,7 @@ svc_udp_init(struct svc_sock *svsk)
  * A data_ready event on a listening socket means there's a connection
  * pending. Do not use state_change as a substitute for it.
  */
-static void
-svc_tcp_listen_data_ready(struct sock *sk, int count_unused)
+static void svc_tcp_listen_data_ready(struct sock *sk, int count_unused)
 {
        struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
 
@@ -954,8 +659,8 @@ svc_tcp_listen_data_ready(struct sock *sk, int count_unused)
         */
        if (sk->sk_state == TCP_LISTEN) {
                if (svsk) {
-                       set_bit(SK_CONN, &svsk->sk_flags);
-                       svc_sock_enqueue(svsk);
+                       set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags);
+                       svc_xprt_enqueue(&svsk->sk_xprt);
                } else
                        printk("svc: socket %p: no user data\n", sk);
        }
@@ -967,8 +672,7 @@ svc_tcp_listen_data_ready(struct sock *sk, int count_unused)
 /*
  * A state change on a connected socket means it's dying or dead.
  */
-static void
-svc_tcp_state_change(struct sock *sk)
+static void svc_tcp_state_change(struct sock *sk)
 {
        struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
 
@@ -978,51 +682,36 @@ svc_tcp_state_change(struct sock *sk)
        if (!svsk)
                printk("svc: socket %p: no user data\n", sk);
        else {
-               set_bit(SK_CLOSE, &svsk->sk_flags);
-               svc_sock_enqueue(svsk);
+               set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
+               svc_xprt_enqueue(&svsk->sk_xprt);
        }
        if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
                wake_up_interruptible_all(sk->sk_sleep);
 }
 
-static void
-svc_tcp_data_ready(struct sock *sk, int count)
+static void svc_tcp_data_ready(struct sock *sk, int count)
 {
        struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
 
        dprintk("svc: socket %p TCP data ready (svsk %p)\n",
                sk, sk->sk_user_data);
        if (svsk) {
-               set_bit(SK_DATA, &svsk->sk_flags);
-               svc_sock_enqueue(svsk);
+               set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
+               svc_xprt_enqueue(&svsk->sk_xprt);
        }
        if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
                wake_up_interruptible(sk->sk_sleep);
 }
 
-static inline int svc_port_is_privileged(struct sockaddr *sin)
-{
-       switch (sin->sa_family) {
-       case AF_INET:
-               return ntohs(((struct sockaddr_in *)sin)->sin_port)
-                       < PROT_SOCK;
-       case AF_INET6:
-               return ntohs(((struct sockaddr_in6 *)sin)->sin6_port)
-                       < PROT_SOCK;
-       default:
-               return 0;
-       }
-}
-
 /*
  * Accept a TCP connection
  */
-static void
-svc_tcp_accept(struct svc_sock *svsk)
+static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt)
 {
+       struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
        struct sockaddr_storage addr;
        struct sockaddr *sin = (struct sockaddr *) &addr;
-       struct svc_serv *serv = svsk->sk_server;
+       struct svc_serv *serv = svsk->sk_xprt.xpt_server;
        struct socket   *sock = svsk->sk_sock;
        struct socket   *newsock;
        struct svc_sock *newsvsk;
@@ -1031,9 +720,9 @@ svc_tcp_accept(struct svc_sock *svsk)
 
        dprintk("svc: tcp_accept %p sock %p\n", svsk, sock);
        if (!sock)
-               return;
+               return NULL;
 
-       clear_bit(SK_CONN, &svsk->sk_flags);
+       clear_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags);
        err = kernel_accept(sock, &newsock, O_NONBLOCK);
        if (err < 0) {
                if (err == -ENOMEM)
@@ -1042,11 +731,9 @@ svc_tcp_accept(struct svc_sock *svsk)
                else if (err != -EAGAIN && net_ratelimit())
                        printk(KERN_WARNING "%s: accept failed (err %d)!\n",
                                   serv->sv_name, -err);
-               return;
+               return NULL;
        }
-
-       set_bit(SK_CONN, &svsk->sk_flags);
-       svc_sock_enqueue(svsk);
+       set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags);
 
        err = kernel_getpeername(newsock, sin, &slen);
        if (err < 0) {
@@ -1077,106 +764,42 @@ svc_tcp_accept(struct svc_sock *svsk)
        if (!(newsvsk = svc_setup_socket(serv, newsock, &err,
                                 (SVC_SOCK_ANONYMOUS | SVC_SOCK_TEMPORARY))))
                goto failed;
-       memcpy(&newsvsk->sk_remote, sin, slen);
-       newsvsk->sk_remotelen = slen;
+       svc_xprt_set_remote(&newsvsk->sk_xprt, sin, slen);
        err = kernel_getsockname(newsock, sin, &slen);
        if (unlikely(err < 0)) {
                dprintk("svc_tcp_accept: kernel_getsockname error %d\n", -err);
                slen = offsetof(struct sockaddr, sa_data);
        }
-       memcpy(&newsvsk->sk_local, sin, slen);
-
-       svc_sock_received(newsvsk);
-
-       /* make sure that we don't have too many active connections.
-        * If we have, something must be dropped.
-        *
-        * There's no point in trying to do random drop here for
-        * DoS prevention. The NFS clients does 1 reconnect in 15
-        * seconds. An attacker can easily beat that.
-        *
-        * The only somewhat efficient mechanism would be if drop
-        * old connections from the same IP first. But right now
-        * we don't even record the client IP in svc_sock.
-        */
-       if (serv->sv_tmpcnt > (serv->sv_nrthreads+3)*20) {
-               struct svc_sock *svsk = NULL;
-               spin_lock_bh(&serv->sv_lock);
-               if (!list_empty(&serv->sv_tempsocks)) {
-                       if (net_ratelimit()) {
-                               /* Try to help the admin */
-                               printk(KERN_NOTICE "%s: too many open TCP "
-                                       "sockets, consider increasing the "
-                                       "number of nfsd threads\n",
-                                                  serv->sv_name);
-                               printk(KERN_NOTICE
-                                      "%s: last TCP connect from %s\n",
-                                      serv->sv_name, __svc_print_addr(sin,
-                                                       buf, sizeof(buf)));
-                       }
-                       /*
-                        * Always select the oldest socket. It's not fair,
-                        * but so is life
-                        */
-                       svsk = list_entry(serv->sv_tempsocks.prev,
-                                         struct svc_sock,
-                                         sk_list);
-                       set_bit(SK_CLOSE, &svsk->sk_flags);
-                       atomic_inc(&svsk->sk_inuse);
-               }
-               spin_unlock_bh(&serv->sv_lock);
-
-               if (svsk) {
-                       svc_sock_enqueue(svsk);
-                       svc_sock_put(svsk);
-               }
-
-       }
+       svc_xprt_set_local(&newsvsk->sk_xprt, sin, slen);
 
        if (serv->sv_stats)
                serv->sv_stats->nettcpconn++;
 
-       return;
+       return &newsvsk->sk_xprt;
 
 failed:
        sock_release(newsock);
-       return;
+       return NULL;
 }
 
 /*
  * Receive data from a TCP socket.
  */
-static int
-svc_tcp_recvfrom(struct svc_rqst *rqstp)
+static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
 {
-       struct svc_sock *svsk = rqstp->rq_sock;
-       struct svc_serv *serv = svsk->sk_server;
+       struct svc_sock *svsk =
+               container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
+       struct svc_serv *serv = svsk->sk_xprt.xpt_server;
        int             len;
        struct kvec *vec;
        int pnum, vlen;
 
        dprintk("svc: tcp_recv %p data %d conn %d close %d\n",
-               svsk, test_bit(SK_DATA, &svsk->sk_flags),
-               test_bit(SK_CONN, &svsk->sk_flags),
-               test_bit(SK_CLOSE, &svsk->sk_flags));
+               svsk, test_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags),
+               test_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags),
+               test_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags));
 
-       if ((rqstp->rq_deferred = svc_deferred_dequeue(svsk))) {
-               svc_sock_received(svsk);
-               return svc_deferred_recv(rqstp);
-       }
-
-       if (test_bit(SK_CLOSE, &svsk->sk_flags)) {
-               svc_delete_socket(svsk);
-               return 0;
-       }
-
-       if (svsk->sk_sk->sk_state == TCP_LISTEN) {
-               svc_tcp_accept(svsk);
-               svc_sock_received(svsk);
-               return 0;
-       }
-
-       if (test_and_clear_bit(SK_CHNGBUF, &svsk->sk_flags))
+       if (test_and_clear_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags))
                /* sndbuf needs to have room for one request
                 * per thread, otherwise we can stall even when the
                 * network isn't a bottleneck.
@@ -1193,7 +816,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
                                    (serv->sv_nrthreads+3) * serv->sv_max_mesg,
                                    3 * serv->sv_max_mesg);
 
-       clear_bit(SK_DATA, &svsk->sk_flags);
+       clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
 
        /* Receive data. If we haven't got the record length yet, get
         * the next four bytes. Otherwise try to gobble up as much as
@@ -1212,7 +835,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
                if (len < want) {
                        dprintk("svc: short recvfrom while reading record length (%d of %lu)\n",
                                len, want);
-                       svc_sock_received(svsk);
+                       svc_xprt_received(&svsk->sk_xprt);
                        return -EAGAIN; /* record header not complete */
                }
 
@@ -1248,11 +871,11 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
        if (len < svsk->sk_reclen) {
                dprintk("svc: incomplete TCP record (%d of %d)\n",
                        len, svsk->sk_reclen);
-               svc_sock_received(svsk);
+               svc_xprt_received(&svsk->sk_xprt);
                return -EAGAIN; /* record not complete */
        }
        len = svsk->sk_reclen;
-       set_bit(SK_DATA, &svsk->sk_flags);
+       set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
 
        vec = rqstp->rq_vec;
        vec[0] = rqstp->rq_arg.head[0];
@@ -1281,30 +904,31 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
                rqstp->rq_arg.page_len = len - rqstp->rq_arg.head[0].iov_len;
        }
 
-       rqstp->rq_skbuff      = NULL;
+       rqstp->rq_xprt_ctxt   = NULL;
        rqstp->rq_prot        = IPPROTO_TCP;
 
        /* Reset TCP read info */
        svsk->sk_reclen = 0;
        svsk->sk_tcplen = 0;
 
-       svc_sock_received(svsk);
+       svc_xprt_copy_addrs(rqstp, &svsk->sk_xprt);
+       svc_xprt_received(&svsk->sk_xprt);
        if (serv->sv_stats)
                serv->sv_stats->nettcpcnt++;
 
        return len;
 
  err_delete:
-       svc_delete_socket(svsk);
+       set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
        return -EAGAIN;
 
  error:
        if (len == -EAGAIN) {
                dprintk("RPC: TCP recvfrom got EAGAIN\n");
-               svc_sock_received(svsk);
+               svc_xprt_received(&svsk->sk_xprt);
        } else {
                printk(KERN_NOTICE "%s: recvfrom returned errno %d\n",
-                                       svsk->sk_server->sv_name, -len);
+                      svsk->sk_xprt.xpt_server->sv_name, -len);
                goto err_delete;
        }
 
@@ -1314,8 +938,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
 /*
  * Send out data on TCP socket.
  */
-static int
-svc_tcp_sendto(struct svc_rqst *rqstp)
+static int svc_tcp_sendto(struct svc_rqst *rqstp)
 {
        struct xdr_buf  *xbufp = &rqstp->rq_res;
        int sent;
@@ -1328,35 +951,109 @@ svc_tcp_sendto(struct svc_rqst *rqstp)
        reclen = htonl(0x80000000|((xbufp->len ) - 4));
        memcpy(xbufp->head[0].iov_base, &reclen, 4);
 
-       if (test_bit(SK_DEAD, &rqstp->rq_sock->sk_flags))
+       if (test_bit(XPT_DEAD, &rqstp->rq_xprt->xpt_flags))
                return -ENOTCONN;
 
        sent = svc_sendto(rqstp, &rqstp->rq_res);
        if (sent != xbufp->len) {
-               printk(KERN_NOTICE "rpc-srv/tcp: %s: %s %d when sending %d bytes - shutting down socket\n",
-                      rqstp->rq_sock->sk_server->sv_name,
+               printk(KERN_NOTICE
+                      "rpc-srv/tcp: %s: %s %d when sending %d bytes "
+                      "- shutting down socket\n",
+                      rqstp->rq_xprt->xpt_server->sv_name,
                       (sent<0)?"got error":"sent only",
                       sent, xbufp->len);
-               set_bit(SK_CLOSE, &rqstp->rq_sock->sk_flags);
-               svc_sock_enqueue(rqstp->rq_sock);
+               set_bit(XPT_CLOSE, &rqstp->rq_xprt->xpt_flags);
+               svc_xprt_enqueue(rqstp->rq_xprt);
                sent = -EAGAIN;
        }
        return sent;
 }
 
-static void
-svc_tcp_init(struct svc_sock *svsk)
+/*
+ * Setup response header. TCP has a 4B record length field.
+ */
+static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp)
+{
+       struct kvec *resv = &rqstp->rq_res.head[0];
+
+       /* tcp needs a space for the record length... */
+       svc_putnl(resv, 0);
+}
+
+static int svc_tcp_has_wspace(struct svc_xprt *xprt)
+{
+       struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
+       struct svc_serv *serv = svsk->sk_xprt.xpt_server;
+       int required;
+       int wspace;
+
+       /*
+        * Set the SOCK_NOSPACE flag before checking the available
+        * sock space.
+        */
+       set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
+       required = atomic_read(&svsk->sk_xprt.xpt_reserved) + serv->sv_max_mesg;
+       wspace = sk_stream_wspace(svsk->sk_sk);
+
+       if (wspace < sk_stream_min_wspace(svsk->sk_sk))
+               return 0;
+       if (required * 2 > wspace)
+               return 0;
+
+       clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
+       return 1;
+}
+
+static struct svc_xprt *svc_tcp_create(struct svc_serv *serv,
+                                      struct sockaddr *sa, int salen,
+                                      int flags)
+{
+       return svc_create_socket(serv, IPPROTO_TCP, sa, salen, flags);
+}
+
+static struct svc_xprt_ops svc_tcp_ops = {
+       .xpo_create = svc_tcp_create,
+       .xpo_recvfrom = svc_tcp_recvfrom,
+       .xpo_sendto = svc_tcp_sendto,
+       .xpo_release_rqst = svc_release_skb,
+       .xpo_detach = svc_sock_detach,
+       .xpo_free = svc_sock_free,
+       .xpo_prep_reply_hdr = svc_tcp_prep_reply_hdr,
+       .xpo_has_wspace = svc_tcp_has_wspace,
+       .xpo_accept = svc_tcp_accept,
+};
+
+static struct svc_xprt_class svc_tcp_class = {
+       .xcl_name = "tcp",
+       .xcl_owner = THIS_MODULE,
+       .xcl_ops = &svc_tcp_ops,
+       .xcl_max_payload = RPCSVC_MAXPAYLOAD_TCP,
+};
+
+void svc_init_xprt_sock(void)
+{
+       svc_reg_xprt_class(&svc_tcp_class);
+       svc_reg_xprt_class(&svc_udp_class);
+}
+
+void svc_cleanup_xprt_sock(void)
+{
+       svc_unreg_xprt_class(&svc_tcp_class);
+       svc_unreg_xprt_class(&svc_udp_class);
+}
+
+static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv)
 {
        struct sock     *sk = svsk->sk_sk;
        struct tcp_sock *tp = tcp_sk(sk);
 
-       svsk->sk_recvfrom = svc_tcp_recvfrom;
-       svsk->sk_sendto = svc_tcp_sendto;
-
+       svc_xprt_init(&svc_tcp_class, &svsk->sk_xprt, serv);
+       set_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags);
        if (sk->sk_state == TCP_LISTEN) {
                dprintk("setting up TCP socket for listening\n");
+               set_bit(XPT_LISTENER, &svsk->sk_xprt.xpt_flags);
                sk->sk_data_ready = svc_tcp_listen_data_ready;
-               set_bit(SK_CONN, &svsk->sk_flags);
+               set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags);
        } else {
                dprintk("setting up TCP socket for reading\n");
                sk->sk_state_change = svc_tcp_state_change;
@@ -1373,18 +1070,17 @@ svc_tcp_init(struct svc_sock *svsk)
                 * svc_tcp_recvfrom will re-adjust if necessary
                 */
                svc_sock_setbufsize(svsk->sk_sock,
-                                   3 * svsk->sk_server->sv_max_mesg,
-                                   3 * svsk->sk_server->sv_max_mesg);
+                                   3 * svsk->sk_xprt.xpt_server->sv_max_mesg,
+                                   3 * svsk->sk_xprt.xpt_server->sv_max_mesg);
 
-               set_bit(SK_CHNGBUF, &svsk->sk_flags);
-               set_bit(SK_DATA, &svsk->sk_flags);
+               set_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags);
+               set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
                if (sk->sk_state != TCP_ESTABLISHED)
-                       set_bit(SK_CLOSE, &svsk->sk_flags);
+                       set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
        }
 }
 
-void
-svc_sock_update_bufs(struct svc_serv *serv)
+void svc_sock_update_bufs(struct svc_serv *serv)
 {
        /*
         * The number of server threads has changed. Update
@@ -1395,231 +1091,17 @@ svc_sock_update_bufs(struct svc_serv *serv)
        spin_lock_bh(&serv->sv_lock);
        list_for_each(le, &serv->sv_permsocks) {
                struct svc_sock *svsk =
-                       list_entry(le, struct svc_sock, sk_list);
-               set_bit(SK_CHNGBUF, &svsk->sk_flags);
+                       list_entry(le, struct svc_sock, sk_xprt.xpt_list);
+               set_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags);
        }
        list_for_each(le, &serv->sv_tempsocks) {
                struct svc_sock *svsk =
-                       list_entry(le, struct svc_sock, sk_list);
-               set_bit(SK_CHNGBUF, &svsk->sk_flags);
+                       list_entry(le, struct svc_sock, sk_xprt.xpt_list);
+               set_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags);
        }
        spin_unlock_bh(&serv->sv_lock);
 }
 
-/*
- * Receive the next request on any socket.  This code is carefully
- * organised not to touch any cachelines in the shared svc_serv
- * structure, only cachelines in the local svc_pool.
- */
-int
-svc_recv(struct svc_rqst *rqstp, long timeout)
-{
-       struct svc_sock         *svsk = NULL;
-       struct svc_serv         *serv = rqstp->rq_server;
-       struct svc_pool         *pool = rqstp->rq_pool;
-       int                     len, i;
-       int                     pages;
-       struct xdr_buf          *arg;
-       DECLARE_WAITQUEUE(wait, current);
-
-       dprintk("svc: server %p waiting for data (to = %ld)\n",
-               rqstp, timeout);
-
-       if (rqstp->rq_sock)
-               printk(KERN_ERR
-                       "svc_recv: service %p, socket not NULL!\n",
-                        rqstp);
-       if (waitqueue_active(&rqstp->rq_wait))
-               printk(KERN_ERR
-                       "svc_recv: service %p, wait queue active!\n",
-                        rqstp);
-
-
-       /* now allocate needed pages.  If we get a failure, sleep briefly */
-       pages = (serv->sv_max_mesg + PAGE_SIZE) / PAGE_SIZE;
-       for (i=0; i < pages ; i++)
-               while (rqstp->rq_pages[i] == NULL) {
-                       struct page *p = alloc_page(GFP_KERNEL);
-                       if (!p)
-                               schedule_timeout_uninterruptible(msecs_to_jiffies(500));
-                       rqstp->rq_pages[i] = p;
-               }
-       rqstp->rq_pages[i++] = NULL; /* this might be seen in nfs_read_actor */
-       BUG_ON(pages >= RPCSVC_MAXPAGES);
-
-       /* Make arg->head point to first page and arg->pages point to rest */
-       arg = &rqstp->rq_arg;
-       arg->head[0].iov_base = page_address(rqstp->rq_pages[0]);
-       arg->head[0].iov_len = PAGE_SIZE;
-       arg->pages = rqstp->rq_pages + 1;
-       arg->page_base = 0;
-       /* save at least one page for response */
-       arg->page_len = (pages-2)*PAGE_SIZE;
-       arg->len = (pages-1)*PAGE_SIZE;
-       arg->tail[0].iov_len = 0;
-
-       try_to_freeze();
-       cond_resched();
-       if (signalled())
-               return -EINTR;
-
-       spin_lock_bh(&pool->sp_lock);
-       if ((svsk = svc_sock_dequeue(pool)) != NULL) {
-               rqstp->rq_sock = svsk;
-               atomic_inc(&svsk->sk_inuse);
-               rqstp->rq_reserved = serv->sv_max_mesg;
-               atomic_add(rqstp->rq_reserved, &svsk->sk_reserved);
-       } else {
-               /* No data pending. Go to sleep */
-               svc_thread_enqueue(pool, rqstp);
-
-               /*
-                * We have to be able to interrupt this wait
-                * to bring down the daemons ...
-                */
-               set_current_state(TASK_INTERRUPTIBLE);
-               add_wait_queue(&rqstp->rq_wait, &wait);
-               spin_unlock_bh(&pool->sp_lock);
-
-               schedule_timeout(timeout);
-
-               try_to_freeze();
-
-               spin_lock_bh(&pool->sp_lock);
-               remove_wait_queue(&rqstp->rq_wait, &wait);
-
-               if (!(svsk = rqstp->rq_sock)) {
-                       svc_thread_dequeue(pool, rqstp);
-                       spin_unlock_bh(&pool->sp_lock);
-                       dprintk("svc: server %p, no data yet\n", rqstp);
-                       return signalled()? -EINTR : -EAGAIN;
-               }
-       }
-       spin_unlock_bh(&pool->sp_lock);
-
-       dprintk("svc: server %p, pool %u, socket %p, inuse=%d\n",
-                rqstp, pool->sp_id, svsk, atomic_read(&svsk->sk_inuse));
-       len = svsk->sk_recvfrom(rqstp);
-       dprintk("svc: got len=%d\n", len);
-
-       /* No data, incomplete (TCP) read, or accept() */
-       if (len == 0 || len == -EAGAIN) {
-               rqstp->rq_res.len = 0;
-               svc_sock_release(rqstp);
-               return -EAGAIN;
-       }
-       svsk->sk_lastrecv = get_seconds();
-       clear_bit(SK_OLD, &svsk->sk_flags);
-
-       rqstp->rq_secure = svc_port_is_privileged(svc_addr(rqstp));
-       rqstp->rq_chandle.defer = svc_defer;
-
-       if (serv->sv_stats)
-               serv->sv_stats->netcnt++;
-       return len;
-}
-
-/*
- * Drop request
- */
-void
-svc_drop(struct svc_rqst *rqstp)
-{
-       dprintk("svc: socket %p dropped request\n", rqstp->rq_sock);
-       svc_sock_release(rqstp);
-}
-
-/*
- * Return reply to client.
- */
-int
-svc_send(struct svc_rqst *rqstp)
-{
-       struct svc_sock *svsk;
-       int             len;
-       struct xdr_buf  *xb;
-
-       if ((svsk = rqstp->rq_sock) == NULL) {
-               printk(KERN_WARNING "NULL socket pointer in %s:%d\n",
-                               __FILE__, __LINE__);
-               return -EFAULT;
-       }
-
-       /* release the receive skb before sending the reply */
-       svc_release_skb(rqstp);
-
-       /* calculate over-all length */
-       xb = & rqstp->rq_res;
-       xb->len = xb->head[0].iov_len +
-               xb->page_len +
-               xb->tail[0].iov_len;
-
-       /* Grab svsk->sk_mutex to serialize outgoing data. */
-       mutex_lock(&svsk->sk_mutex);
-       if (test_bit(SK_DEAD, &svsk->sk_flags))
-               len = -ENOTCONN;
-       else
-               len = svsk->sk_sendto(rqstp);
-       mutex_unlock(&svsk->sk_mutex);
-       svc_sock_release(rqstp);
-
-       if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN)
-               return 0;
-       return len;
-}
-
-/*
- * Timer function to close old temporary sockets, using
- * a mark-and-sweep algorithm.
- */
-static void
-svc_age_temp_sockets(unsigned long closure)
-{
-       struct svc_serv *serv = (struct svc_serv *)closure;
-       struct svc_sock *svsk;
-       struct list_head *le, *next;
-       LIST_HEAD(to_be_aged);
-
-       dprintk("svc_age_temp_sockets\n");
-
-       if (!spin_trylock_bh(&serv->sv_lock)) {
-               /* busy, try again 1 sec later */
-               dprintk("svc_age_temp_sockets: busy\n");
-               mod_timer(&serv->sv_temptimer, jiffies + HZ);
-               return;
-       }
-
-       list_for_each_safe(le, next, &serv->sv_tempsocks) {
-               svsk = list_entry(le, struct svc_sock, sk_list);
-
-               if (!test_and_set_bit(SK_OLD, &svsk->sk_flags))
-                       continue;
-               if (atomic_read(&svsk->sk_inuse) > 1 || test_bit(SK_BUSY, &svsk->sk_flags))
-                       continue;
-               atomic_inc(&svsk->sk_inuse);
-               list_move(le, &to_be_aged);
-               set_bit(SK_CLOSE, &svsk->sk_flags);
-               set_bit(SK_DETACHED, &svsk->sk_flags);
-       }
-       spin_unlock_bh(&serv->sv_lock);
-
-       while (!list_empty(&to_be_aged)) {
-               le = to_be_aged.next;
-               /* fiddling the sk_list node is safe 'cos we're SK_DETACHED */
-               list_del_init(le);
-               svsk = list_entry(le, struct svc_sock, sk_list);
-
-               dprintk("queuing svsk %p for closing, %lu seconds old\n",
-                       svsk, get_seconds() - svsk->sk_lastrecv);
-
-               /* a thread will dequeue and close it soon */
-               svc_sock_enqueue(svsk);
-               svc_sock_put(svsk);
-       }
-
-       mod_timer(&serv->sv_temptimer, jiffies + svc_conn_age_period * HZ);
-}
-
 /*
  * Initialize socket for RPC use and create svc_sock struct
  * XXX: May want to setsockopt SO_SNDBUF and SO_RCVBUF.
@@ -1631,7 +1113,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
        struct svc_sock *svsk;
        struct sock     *inet;
        int             pmap_register = !(flags & SVC_SOCK_ANONYMOUS);
-       int             is_temporary = flags & SVC_SOCK_TEMPORARY;
 
        dprintk("svc: svc_setup_socket %p\n", sock);
        if (!(svsk = kzalloc(sizeof(*svsk), GFP_KERNEL))) {
@@ -1651,44 +1132,18 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
                return NULL;
        }
 
-       set_bit(SK_BUSY, &svsk->sk_flags);
        inet->sk_user_data = svsk;
        svsk->sk_sock = sock;
        svsk->sk_sk = inet;
        svsk->sk_ostate = inet->sk_state_change;
        svsk->sk_odata = inet->sk_data_ready;
        svsk->sk_owspace = inet->sk_write_space;
-       svsk->sk_server = serv;
-       atomic_set(&svsk->sk_inuse, 1);
-       svsk->sk_lastrecv = get_seconds();
-       spin_lock_init(&svsk->sk_lock);
-       INIT_LIST_HEAD(&svsk->sk_deferred);
-       INIT_LIST_HEAD(&svsk->sk_ready);
-       mutex_init(&svsk->sk_mutex);
 
        /* Initialize the socket */
        if (sock->type == SOCK_DGRAM)
-               svc_udp_init(svsk);
+               svc_udp_init(svsk, serv);
        else
-               svc_tcp_init(svsk);
-
-       spin_lock_bh(&serv->sv_lock);
-       if (is_temporary) {
-               set_bit(SK_TEMP, &svsk->sk_flags);
-               list_add(&svsk->sk_list, &serv->sv_tempsocks);
-               serv->sv_tmpcnt++;
-               if (serv->sv_temptimer.function == NULL) {
-                       /* setup timer to age temp sockets */
-                       setup_timer(&serv->sv_temptimer, svc_age_temp_sockets,
-                                       (unsigned long)serv);
-                       mod_timer(&serv->sv_temptimer,
-                                       jiffies + svc_conn_age_period * HZ);
-               }
-       } else {
-               clear_bit(SK_TEMP, &svsk->sk_flags);
-               list_add(&svsk->sk_list, &serv->sv_permsocks);
-       }
-       spin_unlock_bh(&serv->sv_lock);
+               svc_tcp_init(svsk, serv);
 
        dprintk("svc: svc_setup_socket created %p (inet %p)\n",
                                svsk, svsk->sk_sk);
@@ -1717,7 +1172,16 @@ int svc_addsock(struct svc_serv *serv,
        else {
                svsk = svc_setup_socket(serv, so, &err, SVC_SOCK_DEFAULTS);
                if (svsk) {
-                       svc_sock_received(svsk);
+                       struct sockaddr_storage addr;
+                       struct sockaddr *sin = (struct sockaddr *)&addr;
+                       int salen;
+                       if (kernel_getsockname(svsk->sk_sock, sin, &salen) == 0)
+                               svc_xprt_set_local(&svsk->sk_xprt, sin, salen);
+                       clear_bit(XPT_TEMP, &svsk->sk_xprt.xpt_flags);
+                       spin_lock_bh(&serv->sv_lock);
+                       list_add(&svsk->sk_xprt.xpt_list, &serv->sv_permsocks);
+                       spin_unlock_bh(&serv->sv_lock);
+                       svc_xprt_received(&svsk->sk_xprt);
                        err = 0;
                }
        }
@@ -1733,14 +1197,19 @@ EXPORT_SYMBOL_GPL(svc_addsock);
 /*
  * Create socket for RPC service.
  */
-static int svc_create_socket(struct svc_serv *serv, int protocol,
-                               struct sockaddr *sin, int len, int flags)
+static struct svc_xprt *svc_create_socket(struct svc_serv *serv,
+                                         int protocol,
+                                         struct sockaddr *sin, int len,
+                                         int flags)
 {
        struct svc_sock *svsk;
        struct socket   *sock;
        int             error;
        int             type;
        char            buf[RPC_MAX_ADDRBUFLEN];
+       struct sockaddr_storage addr;
+       struct sockaddr *newsin = (struct sockaddr *)&addr;
+       int             newlen;
 
        dprintk("svc: svc_create_socket(%s, %d, %s)\n",
                        serv->sv_program->pg_name, protocol,
@@ -1749,13 +1218,13 @@ static int svc_create_socket(struct svc_serv *serv, int protocol,
        if (protocol != IPPROTO_UDP && protocol != IPPROTO_TCP) {
                printk(KERN_WARNING "svc: only UDP and TCP "
                                "sockets supported\n");
-               return -EINVAL;
+               return ERR_PTR(-EINVAL);
        }
        type = (protocol == IPPROTO_UDP)? SOCK_DGRAM : SOCK_STREAM;
 
        error = sock_create_kern(sin->sa_family, type, protocol, &sock);
        if (error < 0)
-               return error;
+               return ERR_PTR(error);
 
        svc_reclassify_socket(sock);
 
@@ -1765,203 +1234,55 @@ static int svc_create_socket(struct svc_serv *serv, int protocol,
        if (error < 0)
                goto bummer;
 
+       newlen = len;
+       error = kernel_getsockname(sock, newsin, &newlen);
+       if (error < 0)
+               goto bummer;
+
        if (protocol == IPPROTO_TCP) {
                if ((error = kernel_listen(sock, 64)) < 0)
                        goto bummer;
        }
 
        if ((svsk = svc_setup_socket(serv, sock, &error, flags)) != NULL) {
-               svc_sock_received(svsk);
-               return ntohs(inet_sk(svsk->sk_sk)->sport);
+               svc_xprt_set_local(&svsk->sk_xprt, newsin, newlen);
+               return (struct svc_xprt *)svsk;
        }
 
 bummer:
        dprintk("svc: svc_create_socket error = %d\n", -error);
        sock_release(sock);
-       return error;
+       return ERR_PTR(error);
 }
 
 /*
- * Remove a dead socket
+ * Detach the svc_sock from the socket so that no
+ * more callbacks occur.
  */
-static void
-svc_delete_socket(struct svc_sock *svsk)
+static void svc_sock_detach(struct svc_xprt *xprt)
 {
-       struct svc_serv *serv;
-       struct sock     *sk;
-
-       dprintk("svc: svc_delete_socket(%p)\n", svsk);
+       struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
+       struct sock *sk = svsk->sk_sk;
 
-       serv = svsk->sk_server;
-       sk = svsk->sk_sk;
+       dprintk("svc: svc_sock_detach(%p)\n", svsk);
 
+       /* put back the old socket callbacks */
        sk->sk_state_change = svsk->sk_ostate;
        sk->sk_data_ready = svsk->sk_odata;
        sk->sk_write_space = svsk->sk_owspace;
-
-       spin_lock_bh(&serv->sv_lock);
-
-       if (!test_and_set_bit(SK_DETACHED, &svsk->sk_flags))
-               list_del_init(&svsk->sk_list);
-       /*
-        * We used to delete the svc_sock from whichever list
-        * it's sk_ready node was on, but we don't actually
-        * need to.  This is because the only time we're called
-        * while still attached to a queue, the queue itself
-        * is about to be destroyed (in svc_destroy).
-        */
-       if (!test_and_set_bit(SK_DEAD, &svsk->sk_flags)) {
-               BUG_ON(atomic_read(&svsk->sk_inuse)<2);
-               atomic_dec(&svsk->sk_inuse);
-               if (test_bit(SK_TEMP, &svsk->sk_flags))
-                       serv->sv_tmpcnt--;
-       }
-
-       spin_unlock_bh(&serv->sv_lock);
-}
-
-static void svc_close_socket(struct svc_sock *svsk)
-{
-       set_bit(SK_CLOSE, &svsk->sk_flags);
-       if (test_and_set_bit(SK_BUSY, &svsk->sk_flags))
-               /* someone else will have to effect the close */
-               return;
-
-       atomic_inc(&svsk->sk_inuse);
-       svc_delete_socket(svsk);
-       clear_bit(SK_BUSY, &svsk->sk_flags);
-       svc_sock_put(svsk);
-}
-
-void svc_force_close_socket(struct svc_sock *svsk)
-{
-       set_bit(SK_CLOSE, &svsk->sk_flags);
-       if (test_bit(SK_BUSY, &svsk->sk_flags)) {
-               /* Waiting to be processed, but no threads left,
-                * So just remove it from the waiting list
-                */
-               list_del_init(&svsk->sk_ready);
-               clear_bit(SK_BUSY, &svsk->sk_flags);
-       }
-       svc_close_socket(svsk);
-}
-
-/**
- * svc_makesock - Make a socket for nfsd and lockd
- * @serv: RPC server structure
- * @protocol: transport protocol to use
- * @port: port to use
- * @flags: requested socket characteristics
- *
- */
-int svc_makesock(struct svc_serv *serv, int protocol, unsigned short port,
-                       int flags)
-{
-       struct sockaddr_in sin = {
-               .sin_family             = AF_INET,
-               .sin_addr.s_addr        = INADDR_ANY,
-               .sin_port               = htons(port),
-       };
-
-       dprintk("svc: creating socket proto = %d\n", protocol);
-       return svc_create_socket(serv, protocol, (struct sockaddr *) &sin,
-                                                       sizeof(sin), flags);
 }
 
 /*
- * Handle defer and revisit of requests
+ * Free the svc_sock's socket resources and the svc_sock itself.
  */
-
-static void svc_revisit(struct cache_deferred_req *dreq, int too_many)
+static void svc_sock_free(struct svc_xprt *xprt)
 {
-       struct svc_deferred_req *dr = container_of(dreq, struct svc_deferred_req, handle);
-       struct svc_sock *svsk;
+       struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
+       dprintk("svc: svc_sock_free(%p)\n", svsk);
 
-       if (too_many) {
-               svc_sock_put(dr->svsk);
-               kfree(dr);
-               return;
-       }
-       dprintk("revisit queued\n");
-       svsk = dr->svsk;
-       dr->svsk = NULL;
-       spin_lock(&svsk->sk_lock);
-       list_add(&dr->handle.recent, &svsk->sk_deferred);
-       spin_unlock(&svsk->sk_lock);
-       set_bit(SK_DEFERRED, &svsk->sk_flags);
-       svc_sock_enqueue(svsk);
-       svc_sock_put(svsk);
-}
-
-static struct cache_deferred_req *
-svc_defer(struct cache_req *req)
-{
-       struct svc_rqst *rqstp = container_of(req, struct svc_rqst, rq_chandle);
-       int size = sizeof(struct svc_deferred_req) + (rqstp->rq_arg.len);
-       struct svc_deferred_req *dr;
-
-       if (rqstp->rq_arg.page_len)
-               return NULL; /* if more than a page, give up FIXME */
-       if (rqstp->rq_deferred) {
-               dr = rqstp->rq_deferred;
-               rqstp->rq_deferred = NULL;
-       } else {
-               int skip  = rqstp->rq_arg.len - rqstp->rq_arg.head[0].iov_len;
-               /* FIXME maybe discard if size too large */
-               dr = kmalloc(size, GFP_KERNEL);
-               if (dr == NULL)
-                       return NULL;
-
-               dr->handle.owner = rqstp->rq_server;
-               dr->prot = rqstp->rq_prot;
-               memcpy(&dr->addr, &rqstp->rq_addr, rqstp->rq_addrlen);
-               dr->addrlen = rqstp->rq_addrlen;
-               dr->daddr = rqstp->rq_daddr;
-               dr->argslen = rqstp->rq_arg.len >> 2;
-               memcpy(dr->args, rqstp->rq_arg.head[0].iov_base-skip, dr->argslen<<2);
-       }
-       atomic_inc(&rqstp->rq_sock->sk_inuse);
-       dr->svsk = rqstp->rq_sock;
-
-       dr->handle.revisit = svc_revisit;
-       return &dr->handle;
-}
-
-/*
- * recv data from a deferred request into an active one
- */
-static int svc_deferred_recv(struct svc_rqst *rqstp)
-{
-       struct svc_deferred_req *dr = rqstp->rq_deferred;
-
-       rqstp->rq_arg.head[0].iov_base = dr->args;
-       rqstp->rq_arg.head[0].iov_len = dr->argslen<<2;
-       rqstp->rq_arg.page_len = 0;
-       rqstp->rq_arg.len = dr->argslen<<2;
-       rqstp->rq_prot        = dr->prot;
-       memcpy(&rqstp->rq_addr, &dr->addr, dr->addrlen);
-       rqstp->rq_addrlen     = dr->addrlen;
-       rqstp->rq_daddr       = dr->daddr;
-       rqstp->rq_respages    = rqstp->rq_pages;
-       return dr->argslen<<2;
-}
-
-
-static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk)
-{
-       struct svc_deferred_req *dr = NULL;
-
-       if (!test_bit(SK_DEFERRED, &svsk->sk_flags))
-               return NULL;
-       spin_lock(&svsk->sk_lock);
-       clear_bit(SK_DEFERRED, &svsk->sk_flags);
-       if (!list_empty(&svsk->sk_deferred)) {
-               dr = list_entry(svsk->sk_deferred.next,
-                               struct svc_deferred_req,
-                               handle.recent);
-               list_del_init(&dr->handle.recent);
-               set_bit(SK_DEFERRED, &svsk->sk_flags);
-       }
-       spin_unlock(&svsk->sk_lock);
-       return dr;
+       if (svsk->sk_sock->file)
+               sockfd_put(svsk->sk_sock);
+       else
+               sock_release(svsk->sk_sock);
+       kfree(svsk);
 }
index bada7de0c2fcd6a216f44817cb67e03f43b736b5..0f8c439b848a1eab04f0f21f2ea763863e424b2f 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/sunrpc/types.h>
 #include <linux/sunrpc/sched.h>
 #include <linux/sunrpc/stats.h>
+#include <linux/sunrpc/svc_xprt.h>
 
 /*
  * Declare the debug flags here
@@ -55,6 +56,30 @@ rpc_unregister_sysctl(void)
        }
 }
 
+static int proc_do_xprt(ctl_table *table, int write, struct file *file,
+                       void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+       char tmpbuf[256];
+       int len;
+       if ((*ppos && !write) || !*lenp) {
+               *lenp = 0;
+               return 0;
+       }
+       if (write)
+               return -EINVAL;
+       else {
+               len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
+               if (!access_ok(VERIFY_WRITE, buffer, len))
+                       return -EFAULT;
+
+               if (__copy_to_user(buffer, tmpbuf, len))
+                       return -EFAULT;
+       }
+       *lenp -= len;
+       *ppos += len;
+       return 0;
+}
+
 static int
 proc_dodebug(ctl_table *table, int write, struct file *file,
                                void __user *buffer, size_t *lenp, loff_t *ppos)
@@ -147,6 +172,12 @@ static ctl_table debug_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dodebug
        },
+       {
+               .procname       = "transports",
+               .maxlen         = 256,
+               .mode           = 0444,
+               .proc_handler   = &proc_do_xprt,
+       },
        { .ctl_name = 0 }
 };
 
index 54264062ea695d59f85da1d712f53cd0ff45952a..995c3fdc16c27821d2e97887a6bdba002a086321 100644 (file)
@@ -96,11 +96,13 @@ xdr_encode_string(__be32 *p, const char *string)
 EXPORT_SYMBOL(xdr_encode_string);
 
 __be32 *
-xdr_decode_string_inplace(__be32 *p, char **sp, int *lenp, int maxlen)
+xdr_decode_string_inplace(__be32 *p, char **sp,
+                         unsigned int *lenp, unsigned int maxlen)
 {
-       unsigned int    len;
+       u32 len;
 
-       if ((len = ntohl(*p++)) > maxlen)
+       len = ntohl(*p++);
+       if (len > maxlen)
                return NULL;
        *lenp = len;
        *sp = (char *) p;
index 264f0feeb513e24b8d4b3cfef9e6850b1a0fcff1..5a8f268bdd30c5dedfcb73dc6b071c1263553875 100644 (file)
@@ -1,3 +1,8 @@
 obj-$(CONFIG_SUNRPC_XPRT_RDMA) += xprtrdma.o
 
 xprtrdma-y := transport.o rpc_rdma.o verbs.o
+
+obj-$(CONFIG_SUNRPC_XPRT_RDMA) += svcrdma.o
+
+svcrdma-y := svc_rdma.o svc_rdma_transport.o \
+       svc_rdma_marshal.o svc_rdma_sendto.o svc_rdma_recvfrom.o
diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
new file mode 100644 (file)
index 0000000..88c0ca2
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the BSD-type
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *      Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ *      Neither the name of the Network Appliance, Inc. nor the names of
+ *      its contributors may be used to endorse or promote products
+ *      derived from this software without specific prior written
+ *      permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Tom Tucker <tom@opengridcomputing.com>
+ */
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/sysctl.h>
+#include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/sched.h>
+#include <linux/sunrpc/svc_rdma.h>
+
+#define RPCDBG_FACILITY        RPCDBG_SVCXPRT
+
+/* RPC/RDMA parameters */
+unsigned int svcrdma_ord = RPCRDMA_ORD;
+static unsigned int min_ord = 1;
+static unsigned int max_ord = 4096;
+unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS;
+static unsigned int min_max_requests = 4;
+static unsigned int max_max_requests = 16384;
+unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
+static unsigned int min_max_inline = 4096;
+static unsigned int max_max_inline = 65536;
+
+atomic_t rdma_stat_recv;
+atomic_t rdma_stat_read;
+atomic_t rdma_stat_write;
+atomic_t rdma_stat_sq_starve;
+atomic_t rdma_stat_rq_starve;
+atomic_t rdma_stat_rq_poll;
+atomic_t rdma_stat_rq_prod;
+atomic_t rdma_stat_sq_poll;
+atomic_t rdma_stat_sq_prod;
+
+/*
+ * This function implements reading and resetting an atomic_t stat
+ * variable through read/write to a proc file. Any write to the file
+ * resets the associated statistic to zero. Any read returns it's
+ * current value.
+ */
+static int read_reset_stat(ctl_table *table, int write,
+                          struct file *filp, void __user *buffer, size_t *lenp,
+                          loff_t *ppos)
+{
+       atomic_t *stat = (atomic_t *)table->data;
+
+       if (!stat)
+               return -EINVAL;
+
+       if (write)
+               atomic_set(stat, 0);
+       else {
+               char str_buf[32];
+               char *data;
+               int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
+               if (len >= 32)
+                       return -EFAULT;
+               len = strlen(str_buf);
+               if (*ppos > len) {
+                       *lenp = 0;
+                       return 0;
+               }
+               data = &str_buf[*ppos];
+               len -= *ppos;
+               if (len > *lenp)
+                       len = *lenp;
+               if (len && copy_to_user(buffer, str_buf, len))
+                       return -EFAULT;
+               *lenp = len;
+               *ppos += len;
+       }
+       return 0;
+}
+
+static struct ctl_table_header *svcrdma_table_header;
+static ctl_table svcrdma_parm_table[] = {
+       {
+               .procname       = "max_requests",
+               .data           = &svcrdma_max_requests,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec_minmax,
+               .strategy       = &sysctl_intvec,
+               .extra1         = &min_max_requests,
+               .extra2         = &max_max_requests
+       },
+       {
+               .procname       = "max_req_size",
+               .data           = &svcrdma_max_req_size,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec_minmax,
+               .strategy       = &sysctl_intvec,
+               .extra1         = &min_max_inline,
+               .extra2         = &max_max_inline
+       },
+       {
+               .procname       = "max_outbound_read_requests",
+               .data           = &svcrdma_ord,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec_minmax,
+               .strategy       = &sysctl_intvec,
+               .extra1         = &min_ord,
+               .extra2         = &max_ord,
+       },
+
+       {
+               .procname       = "rdma_stat_read",
+               .data           = &rdma_stat_read,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_recv",
+               .data           = &rdma_stat_recv,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_write",
+               .data           = &rdma_stat_write,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_sq_starve",
+               .data           = &rdma_stat_sq_starve,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_rq_starve",
+               .data           = &rdma_stat_rq_starve,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_rq_poll",
+               .data           = &rdma_stat_rq_poll,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_rq_prod",
+               .data           = &rdma_stat_rq_prod,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_sq_poll",
+               .data           = &rdma_stat_sq_poll,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .procname       = "rdma_stat_sq_prod",
+               .data           = &rdma_stat_sq_prod,
+               .maxlen         = sizeof(atomic_t),
+               .mode           = 0644,
+               .proc_handler   = &read_reset_stat,
+       },
+       {
+               .ctl_name = 0,
+       },
+};
+
+static ctl_table svcrdma_table[] = {
+       {
+               .procname       = "svc_rdma",
+               .mode           = 0555,
+               .child          = svcrdma_parm_table
+       },
+       {
+               .ctl_name = 0,
+       },
+};
+
+static ctl_table svcrdma_root_table[] = {
+       {
+               .ctl_name       = CTL_SUNRPC,
+               .procname       = "sunrpc",
+               .mode           = 0555,
+               .child          = svcrdma_table
+       },
+       {
+               .ctl_name = 0,
+       },
+};
+
+void svc_rdma_cleanup(void)
+{
+       dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
+       if (svcrdma_table_header) {
+               unregister_sysctl_table(svcrdma_table_header);
+               svcrdma_table_header = NULL;
+       }
+       svc_unreg_xprt_class(&svc_rdma_class);
+}
+
+int svc_rdma_init(void)
+{
+       dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
+       dprintk("\tsvcrdma_ord      : %d\n", svcrdma_ord);
+       dprintk("\tmax_requests     : %d\n", svcrdma_max_requests);
+       dprintk("\tsq_depth         : %d\n",
+               svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT);
+       dprintk("\tmax_inline       : %d\n", svcrdma_max_req_size);
+       if (!svcrdma_table_header)
+               svcrdma_table_header =
+                       register_sysctl_table(svcrdma_root_table);
+
+       /* Register RDMA with the SVC transport switch */
+       svc_reg_xprt_class(&svc_rdma_class);
+       return 0;
+}
+MODULE_AUTHOR("Tom Tucker <tom@opengridcomputing.com>");
+MODULE_DESCRIPTION("SVC RDMA Transport");
+MODULE_LICENSE("Dual BSD/GPL");
+module_init(svc_rdma_init);
+module_exit(svc_rdma_cleanup);
diff --git a/net/sunrpc/xprtrdma/svc_rdma_marshal.c b/net/sunrpc/xprtrdma/svc_rdma_marshal.c
new file mode 100644 (file)
index 0000000..9530ef2
--- /dev/null
@@ -0,0 +1,412 @@
+/*
+ * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the BSD-type
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *      Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ *      Neither the name of the Network Appliance, Inc. nor the names of
+ *      its contributors may be used to endorse or promote products
+ *      derived from this software without specific prior written
+ *      permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Tom Tucker <tom@opengridcomputing.com>
+ */
+
+#include <linux/sunrpc/xdr.h>
+#include <linux/sunrpc/debug.h>
+#include <asm/unaligned.h>
+#include <linux/sunrpc/rpc_rdma.h>
+#include <linux/sunrpc/svc_rdma.h>
+
+#define RPCDBG_FACILITY        RPCDBG_SVCXPRT
+
+/*
+ * Decodes a read chunk list. The expected format is as follows:
+ *    descrim  : xdr_one
+ *    position : u32 offset into XDR stream
+ *    handle   : u32 RKEY
+ *    . . .
+ *  end-of-list: xdr_zero
+ */
+static u32 *decode_read_list(u32 *va, u32 *vaend)
+{
+       struct rpcrdma_read_chunk *ch = (struct rpcrdma_read_chunk *)va;
+
+       while (ch->rc_discrim != xdr_zero) {
+               u64 ch_offset;
+
+               if (((unsigned long)ch + sizeof(struct rpcrdma_read_chunk)) >
+                   (unsigned long)vaend) {
+                       dprintk("svcrdma: vaend=%p, ch=%p\n", vaend, ch);
+                       return NULL;
+               }
+
+               ch->rc_discrim = ntohl(ch->rc_discrim);
+               ch->rc_position = ntohl(ch->rc_position);
+               ch->rc_target.rs_handle = ntohl(ch->rc_target.rs_handle);
+               ch->rc_target.rs_length = ntohl(ch->rc_target.rs_length);
+               va = (u32 *)&ch->rc_target.rs_offset;
+               xdr_decode_hyper(va, &ch_offset);
+               put_unaligned(ch_offset, (u64 *)va);
+               ch++;
+       }
+       return (u32 *)&ch->rc_position;
+}
+
+/*
+ * Determine number of chunks and total bytes in chunk list. The chunk
+ * list has already been verified to fit within the RPCRDMA header.
+ */
+void svc_rdma_rcl_chunk_counts(struct rpcrdma_read_chunk *ch,
+                              int *ch_count, int *byte_count)
+{
+       /* compute the number of bytes represented by read chunks */
+       *byte_count = 0;
+       *ch_count = 0;
+       for (; ch->rc_discrim != 0; ch++) {
+               *byte_count = *byte_count + ch->rc_target.rs_length;
+               *ch_count = *ch_count + 1;
+       }
+}
+
+/*
+ * Decodes a write chunk list. The expected format is as follows:
+ *    descrim  : xdr_one
+ *    nchunks  : <count>
+ *       handle   : u32 RKEY              ---+
+ *       length   : u32 <len of segment>     |
+ *       offset   : remove va                + <count>
+ *       . . .                               |
+ *                                        ---+
+ */
+static u32 *decode_write_list(u32 *va, u32 *vaend)
+{
+       int ch_no;
+       struct rpcrdma_write_array *ary =
+               (struct rpcrdma_write_array *)va;
+
+       /* Check for not write-array */
+       if (ary->wc_discrim == xdr_zero)
+               return (u32 *)&ary->wc_nchunks;
+
+       if ((unsigned long)ary + sizeof(struct rpcrdma_write_array) >
+           (unsigned long)vaend) {
+               dprintk("svcrdma: ary=%p, vaend=%p\n", ary, vaend);
+               return NULL;
+       }
+       ary->wc_discrim = ntohl(ary->wc_discrim);
+       ary->wc_nchunks = ntohl(ary->wc_nchunks);
+       if (((unsigned long)&ary->wc_array[0] +
+            (sizeof(struct rpcrdma_write_chunk) * ary->wc_nchunks)) >
+           (unsigned long)vaend) {
+               dprintk("svcrdma: ary=%p, wc_nchunks=%d, vaend=%p\n",
+                       ary, ary->wc_nchunks, vaend);
+               return NULL;
+       }
+       for (ch_no = 0; ch_no < ary->wc_nchunks; ch_no++) {
+               u64 ch_offset;
+
+               ary->wc_array[ch_no].wc_target.rs_handle =
+                       ntohl(ary->wc_array[ch_no].wc_target.rs_handle);
+               ary->wc_array[ch_no].wc_target.rs_length =
+                       ntohl(ary->wc_array[ch_no].wc_target.rs_length);
+               va = (u32 *)&ary->wc_array[ch_no].wc_target.rs_offset;
+               xdr_decode_hyper(va, &ch_offset);
+               put_unaligned(ch_offset, (u64 *)va);
+       }
+
+       /*
+        * rs_length is the 2nd 4B field in wc_target and taking its
+        * address skips the list terminator
+        */
+       return (u32 *)&ary->wc_array[ch_no].wc_target.rs_length;
+}
+
+static u32 *decode_reply_array(u32 *va, u32 *vaend)
+{
+       int ch_no;
+       struct rpcrdma_write_array *ary =
+               (struct rpcrdma_write_array *)va;
+
+       /* Check for no reply-array */
+       if (ary->wc_discrim == xdr_zero)
+               return (u32 *)&ary->wc_nchunks;
+
+       if ((unsigned long)ary + sizeof(struct rpcrdma_write_array) >
+           (unsigned long)vaend) {
+               dprintk("svcrdma: ary=%p, vaend=%p\n", ary, vaend);
+               return NULL;
+       }
+       ary->wc_discrim = ntohl(ary->wc_discrim);
+       ary->wc_nchunks = ntohl(ary->wc_nchunks);
+       if (((unsigned long)&ary->wc_array[0] +
+            (sizeof(struct rpcrdma_write_chunk) * ary->wc_nchunks)) >
+           (unsigned long)vaend) {
+               dprintk("svcrdma: ary=%p, wc_nchunks=%d, vaend=%p\n",
+                       ary, ary->wc_nchunks, vaend);
+               return NULL;
+       }
+       for (ch_no = 0; ch_no < ary->wc_nchunks; ch_no++) {
+               u64 ch_offset;
+
+               ary->wc_array[ch_no].wc_target.rs_handle =
+                       ntohl(ary->wc_array[ch_no].wc_target.rs_handle);
+               ary->wc_array[ch_no].wc_target.rs_length =
+                       ntohl(ary->wc_array[ch_no].wc_target.rs_length);
+               va = (u32 *)&ary->wc_array[ch_no].wc_target.rs_offset;
+               xdr_decode_hyper(va, &ch_offset);
+               put_unaligned(ch_offset, (u64 *)va);
+       }
+
+       return (u32 *)&ary->wc_array[ch_no];
+}
+
+int svc_rdma_xdr_decode_req(struct rpcrdma_msg **rdma_req,
+                           struct svc_rqst *rqstp)
+{
+       struct rpcrdma_msg *rmsgp = NULL;
+       u32 *va;
+       u32 *vaend;
+       u32 hdr_len;
+
+       rmsgp = (struct rpcrdma_msg *)rqstp->rq_arg.head[0].iov_base;
+
+       /* Verify that there's enough bytes for header + something */
+       if (rqstp->rq_arg.len <= RPCRDMA_HDRLEN_MIN) {
+               dprintk("svcrdma: header too short = %d\n",
+                       rqstp->rq_arg.len);
+               return -EINVAL;
+       }
+
+       /* Decode the header */
+       rmsgp->rm_xid = ntohl(rmsgp->rm_xid);
+       rmsgp->rm_vers = ntohl(rmsgp->rm_vers);
+       rmsgp->rm_credit = ntohl(rmsgp->rm_credit);
+       rmsgp->rm_type = ntohl(rmsgp->rm_type);
+
+       if (rmsgp->rm_vers != RPCRDMA_VERSION)
+               return -ENOSYS;
+
+       /* Pull in the extra for the padded case and bump our pointer */
+       if (rmsgp->rm_type == RDMA_MSGP) {
+               int hdrlen;
+               rmsgp->rm_body.rm_padded.rm_align =
+                       ntohl(rmsgp->rm_body.rm_padded.rm_align);
+               rmsgp->rm_body.rm_padded.rm_thresh =
+                       ntohl(rmsgp->rm_body.rm_padded.rm_thresh);
+
+               va = &rmsgp->rm_body.rm_padded.rm_pempty[4];
+               rqstp->rq_arg.head[0].iov_base = va;
+               hdrlen = (u32)((unsigned long)va - (unsigned long)rmsgp);
+               rqstp->rq_arg.head[0].iov_len -= hdrlen;
+               if (hdrlen > rqstp->rq_arg.len)
+                       return -EINVAL;
+               return hdrlen;
+       }
+
+       /* The chunk list may contain either a read chunk list or a write
+        * chunk list and a reply chunk list.
+        */
+       va = &rmsgp->rm_body.rm_chunks[0];
+       vaend = (u32 *)((unsigned long)rmsgp + rqstp->rq_arg.len);
+       va = decode_read_list(va, vaend);
+       if (!va)
+               return -EINVAL;
+       va = decode_write_list(va, vaend);
+       if (!va)
+               return -EINVAL;
+       va = decode_reply_array(va, vaend);
+       if (!va)
+               return -EINVAL;
+
+       rqstp->rq_arg.head[0].iov_base = va;
+       hdr_len = (unsigned long)va - (unsigned long)rmsgp;
+       rqstp->rq_arg.head[0].iov_len -= hdr_len;
+
+       *rdma_req = rmsgp;
+       return hdr_len;
+}
+
+int svc_rdma_xdr_decode_deferred_req(struct svc_rqst *rqstp)
+{
+       struct rpcrdma_msg *rmsgp = NULL;
+       struct rpcrdma_read_chunk *ch;
+       struct rpcrdma_write_array *ary;
+       u32 *va;
+       u32 hdrlen;
+
+       dprintk("svcrdma: processing deferred RDMA header on rqstp=%p\n",
+               rqstp);
+       rmsgp = (struct rpcrdma_msg *)rqstp->rq_arg.head[0].iov_base;
+
+       /* Pull in the extra for the padded case and bump our pointer */
+       if (rmsgp->rm_type == RDMA_MSGP) {
+               va = &rmsgp->rm_body.rm_padded.rm_pempty[4];
+               rqstp->rq_arg.head[0].iov_base = va;
+               hdrlen = (u32)((unsigned long)va - (unsigned long)rmsgp);
+               rqstp->rq_arg.head[0].iov_len -= hdrlen;
+               return hdrlen;
+       }
+
+       /*
+        * Skip all chunks to find RPC msg. These were previously processed
+        */
+       va = &rmsgp->rm_body.rm_chunks[0];
+
+       /* Skip read-list */
+       for (ch = (struct rpcrdma_read_chunk *)va;
+            ch->rc_discrim != xdr_zero; ch++);
+       va = (u32 *)&ch->rc_position;
+
+       /* Skip write-list */
+       ary = (struct rpcrdma_write_array *)va;
+       if (ary->wc_discrim == xdr_zero)
+               va = (u32 *)&ary->wc_nchunks;
+       else
+               /*
+                * rs_length is the 2nd 4B field in wc_target and taking its
+                * address skips the list terminator
+                */
+               va = (u32 *)&ary->wc_array[ary->wc_nchunks].wc_target.rs_length;
+
+       /* Skip reply-array */
+       ary = (struct rpcrdma_write_array *)va;
+       if (ary->wc_discrim == xdr_zero)
+               va = (u32 *)&ary->wc_nchunks;
+       else
+               va = (u32 *)&ary->wc_array[ary->wc_nchunks];
+
+       rqstp->rq_arg.head[0].iov_base = va;
+       hdrlen = (unsigned long)va - (unsigned long)rmsgp;
+       rqstp->rq_arg.head[0].iov_len -= hdrlen;
+
+       return hdrlen;
+}
+
+int svc_rdma_xdr_encode_error(struct svcxprt_rdma *xprt,
+                             struct rpcrdma_msg *rmsgp,
+                             enum rpcrdma_errcode err, u32 *va)
+{
+       u32 *startp = va;
+
+       *va++ = htonl(rmsgp->rm_xid);
+       *va++ = htonl(rmsgp->rm_vers);
+       *va++ = htonl(xprt->sc_max_requests);
+       *va++ = htonl(RDMA_ERROR);
+       *va++ = htonl(err);
+       if (err == ERR_VERS) {
+               *va++ = htonl(RPCRDMA_VERSION);
+               *va++ = htonl(RPCRDMA_VERSION);
+       }
+
+       return (int)((unsigned long)va - (unsigned long)startp);
+}
+
+int svc_rdma_xdr_get_reply_hdr_len(struct rpcrdma_msg *rmsgp)
+{
+       struct rpcrdma_write_array *wr_ary;
+
+       /* There is no read-list in a reply */
+
+       /* skip write list */
+       wr_ary = (struct rpcrdma_write_array *)
+               &rmsgp->rm_body.rm_chunks[1];
+       if (wr_ary->wc_discrim)
+               wr_ary = (struct rpcrdma_write_array *)
+                       &wr_ary->wc_array[ntohl(wr_ary->wc_nchunks)].
+                       wc_target.rs_length;
+       else
+               wr_ary = (struct rpcrdma_write_array *)
+                       &wr_ary->wc_nchunks;
+
+       /* skip reply array */
+       if (wr_ary->wc_discrim)
+               wr_ary = (struct rpcrdma_write_array *)
+                       &wr_ary->wc_array[ntohl(wr_ary->wc_nchunks)];
+       else
+               wr_ary = (struct rpcrdma_write_array *)
+                       &wr_ary->wc_nchunks;
+
+       return (unsigned long) wr_ary - (unsigned long) rmsgp;
+}
+
+void svc_rdma_xdr_encode_write_list(struct rpcrdma_msg *rmsgp, int chunks)
+{
+       struct rpcrdma_write_array *ary;
+
+       /* no read-list */
+       rmsgp->rm_body.rm_chunks[0] = xdr_zero;
+
+       /* write-array discrim */
+       ary = (struct rpcrdma_write_array *)
+               &rmsgp->rm_body.rm_chunks[1];
+       ary->wc_discrim = xdr_one;
+       ary->wc_nchunks = htonl(chunks);
+
+       /* write-list terminator */
+       ary->wc_array[chunks].wc_target.rs_handle = xdr_zero;
+
+       /* reply-array discriminator */
+       ary->wc_array[chunks].wc_target.rs_length = xdr_zero;
+}
+
+void svc_rdma_xdr_encode_reply_array(struct rpcrdma_write_array *ary,
+                                int chunks)
+{
+       ary->wc_discrim = xdr_one;
+       ary->wc_nchunks = htonl(chunks);
+}
+
+void svc_rdma_xdr_encode_array_chunk(struct rpcrdma_write_array *ary,
+                                    int chunk_no,
+                                    u32 rs_handle, u64 rs_offset,
+                                    u32 write_len)
+{
+       struct rpcrdma_segment *seg = &ary->wc_array[chunk_no].wc_target;
+       seg->rs_handle = htonl(rs_handle);
+       seg->rs_length = htonl(write_len);
+       xdr_encode_hyper((u32 *) &seg->rs_offset, rs_offset);
+}
+
+void svc_rdma_xdr_encode_reply_header(struct svcxprt_rdma *xprt,
+                                 struct rpcrdma_msg *rdma_argp,
+                                 struct rpcrdma_msg *rdma_resp,
+                                 enum rpcrdma_proc rdma_type)
+{
+       rdma_resp->rm_xid = htonl(rdma_argp->rm_xid);
+       rdma_resp->rm_vers = htonl(rdma_argp->rm_vers);
+       rdma_resp->rm_credit = htonl(xprt->sc_max_requests);
+       rdma_resp->rm_type = htonl(rdma_type);
+
+       /* Encode <nul> chunks lists */
+       rdma_resp->rm_body.rm_chunks[0] = xdr_zero;
+       rdma_resp->rm_body.rm_chunks[1] = xdr_zero;
+       rdma_resp->rm_body.rm_chunks[2] = xdr_zero;
+}
diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
new file mode 100644 (file)
index 0000000..ab54a73
--- /dev/null
@@ -0,0 +1,586 @@
+/*
+ * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the BSD-type
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *      Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ *      Neither the name of the Network Appliance, Inc. nor the names of
+ *      its contributors may be used to endorse or promote products
+ *      derived from this software without specific prior written
+ *      permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Tom Tucker <tom@opengridcomputing.com>
+ */
+
+#include <linux/sunrpc/debug.h>
+#include <linux/sunrpc/rpc_rdma.h>
+#include <linux/spinlock.h>
+#include <asm/unaligned.h>
+#include <rdma/ib_verbs.h>
+#include <rdma/rdma_cm.h>
+#include <linux/sunrpc/svc_rdma.h>
+
+#define RPCDBG_FACILITY        RPCDBG_SVCXPRT
+
+/*
+ * Replace the pages in the rq_argpages array with the pages from the SGE in
+ * the RDMA_RECV completion. The SGL should contain full pages up until the
+ * last one.
+ */
+static void rdma_build_arg_xdr(struct svc_rqst *rqstp,
+                              struct svc_rdma_op_ctxt *ctxt,
+                              u32 byte_count)
+{
+       struct page *page;
+       u32 bc;
+       int sge_no;
+
+       /* Swap the page in the SGE with the page in argpages */
+       page = ctxt->pages[0];
+       put_page(rqstp->rq_pages[0]);
+       rqstp->rq_pages[0] = page;
+
+       /* Set up the XDR head */
+       rqstp->rq_arg.head[0].iov_base = page_address(page);
+       rqstp->rq_arg.head[0].iov_len = min(byte_count, ctxt->sge[0].length);
+       rqstp->rq_arg.len = byte_count;
+       rqstp->rq_arg.buflen = byte_count;
+
+       /* Compute bytes past head in the SGL */
+       bc = byte_count - rqstp->rq_arg.head[0].iov_len;
+
+       /* If data remains, store it in the pagelist */
+       rqstp->rq_arg.page_len = bc;
+       rqstp->rq_arg.page_base = 0;
+       rqstp->rq_arg.pages = &rqstp->rq_pages[1];
+       sge_no = 1;
+       while (bc && sge_no < ctxt->count) {
+               page = ctxt->pages[sge_no];
+               put_page(rqstp->rq_pages[sge_no]);
+               rqstp->rq_pages[sge_no] = page;
+               bc -= min(bc, ctxt->sge[sge_no].length);
+               rqstp->rq_arg.buflen += ctxt->sge[sge_no].length;
+               sge_no++;
+       }
+       rqstp->rq_respages = &rqstp->rq_pages[sge_no];
+
+       /* We should never run out of SGE because the limit is defined to
+        * support the max allowed RPC data length
+        */
+       BUG_ON(bc && (sge_no == ctxt->count));
+       BUG_ON((rqstp->rq_arg.head[0].iov_len + rqstp->rq_arg.page_len)
+              != byte_count);
+       BUG_ON(rqstp->rq_arg.len != byte_count);
+
+       /* If not all pages were used from the SGL, free the remaining ones */
+       bc = sge_no;
+       while (sge_no < ctxt->count) {
+               page = ctxt->pages[sge_no++];
+               put_page(page);
+       }
+       ctxt->count = bc;
+
+       /* Set up tail */
+       rqstp->rq_arg.tail[0].iov_base = NULL;
+       rqstp->rq_arg.tail[0].iov_len = 0;
+}
+
+struct chunk_sge {
+       int start;              /* sge no for this chunk */
+       int count;              /* sge count for this chunk */
+};
+
+/* Encode a read-chunk-list as an array of IB SGE
+ *
+ * Assumptions:
+ * - chunk[0]->position points to pages[0] at an offset of 0
+ * - pages[] is not physically or virtually contigous and consists of
+ *   PAGE_SIZE elements.
+ *
+ * Output:
+ * - sge array pointing into pages[] array.
+ * - chunk_sge array specifying sge index and count for each
+ *   chunk in the read list
+ *
+ */
+static int rdma_rcl_to_sge(struct svcxprt_rdma *xprt,
+                          struct svc_rqst *rqstp,
+                          struct svc_rdma_op_ctxt *head,
+                          struct rpcrdma_msg *rmsgp,
+                          struct ib_sge *sge,
+                          struct chunk_sge *ch_sge_ary,
+                          int ch_count,
+                          int byte_count)
+{
+       int sge_no;
+       int sge_bytes;
+       int page_off;
+       int page_no;
+       int ch_bytes;
+       int ch_no;
+       struct rpcrdma_read_chunk *ch;
+
+       sge_no = 0;
+       page_no = 0;
+       page_off = 0;
+       ch = (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0];
+       ch_no = 0;
+       ch_bytes = ch->rc_target.rs_length;
+       head->arg.head[0] = rqstp->rq_arg.head[0];
+       head->arg.tail[0] = rqstp->rq_arg.tail[0];
+       head->arg.pages = &head->pages[head->count];
+       head->sge[0].length = head->count; /* save count of hdr pages */
+       head->arg.page_base = 0;
+       head->arg.page_len = ch_bytes;
+       head->arg.len = rqstp->rq_arg.len + ch_bytes;
+       head->arg.buflen = rqstp->rq_arg.buflen + ch_bytes;
+       head->count++;
+       ch_sge_ary[0].start = 0;
+       while (byte_count) {
+               sge_bytes = min_t(int, PAGE_SIZE-page_off, ch_bytes);
+               sge[sge_no].addr =
+                       ib_dma_map_page(xprt->sc_cm_id->device,
+                                       rqstp->rq_arg.pages[page_no],
+                                       page_off, sge_bytes,
+                                       DMA_FROM_DEVICE);
+               sge[sge_no].length = sge_bytes;
+               sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
+               /*
+                * Don't bump head->count here because the same page
+                * may be used by multiple SGE.
+                */
+               head->arg.pages[page_no] = rqstp->rq_arg.pages[page_no];
+               rqstp->rq_respages = &rqstp->rq_arg.pages[page_no+1];
+
+               byte_count -= sge_bytes;
+               ch_bytes -= sge_bytes;
+               sge_no++;
+               /*
+                * If all bytes for this chunk have been mapped to an
+                * SGE, move to the next SGE
+                */
+               if (ch_bytes == 0) {
+                       ch_sge_ary[ch_no].count =
+                               sge_no - ch_sge_ary[ch_no].start;
+                       ch_no++;
+                       ch++;
+                       ch_sge_ary[ch_no].start = sge_no;
+                       ch_bytes = ch->rc_target.rs_length;
+                       /* If bytes remaining account for next chunk */
+                       if (byte_count) {
+                               head->arg.page_len += ch_bytes;
+                               head->arg.len += ch_bytes;
+                               head->arg.buflen += ch_bytes;
+                       }
+               }
+               /*
+                * If this SGE consumed all of the page, move to the
+                * next page
+                */
+               if ((sge_bytes + page_off) == PAGE_SIZE) {
+                       page_no++;
+                       page_off = 0;
+                       /*
+                        * If there are still bytes left to map, bump
+                        * the page count
+                        */
+                       if (byte_count)
+                               head->count++;
+               } else
+                       page_off += sge_bytes;
+       }
+       BUG_ON(byte_count != 0);
+       return sge_no;
+}
+
+static void rdma_set_ctxt_sge(struct svc_rdma_op_ctxt *ctxt,
+                             struct ib_sge *sge,
+                             u64 *sgl_offset,
+                             int count)
+{
+       int i;
+
+       ctxt->count = count;
+       for (i = 0; i < count; i++) {
+               ctxt->sge[i].addr = sge[i].addr;
+               ctxt->sge[i].length = sge[i].length;
+               *sgl_offset = *sgl_offset + sge[i].length;
+       }
+}
+
+static int rdma_read_max_sge(struct svcxprt_rdma *xprt, int sge_count)
+{
+#ifdef RDMA_TRANSPORT_IWARP
+       if ((RDMA_TRANSPORT_IWARP ==
+            rdma_node_get_transport(xprt->sc_cm_id->
+                                    device->node_type))
+           && sge_count > 1)
+               return 1;
+       else
+#endif
+               return min_t(int, sge_count, xprt->sc_max_sge);
+}
+
+/*
+ * Use RDMA_READ to read data from the advertised client buffer into the
+ * XDR stream starting at rq_arg.head[0].iov_base.
+ * Each chunk in the array
+ * contains the following fields:
+ * discrim      - '1', This isn't used for data placement
+ * position     - The xdr stream offset (the same for every chunk)
+ * handle       - RMR for client memory region
+ * length       - data transfer length
+ * offset       - 64 bit tagged offset in remote memory region
+ *
+ * On our side, we need to read into a pagelist. The first page immediately
+ * follows the RPC header.
+ *
+ * This function returns 1 to indicate success. The data is not yet in
+ * the pagelist and therefore the RPC request must be deferred. The
+ * I/O completion will enqueue the transport again and
+ * svc_rdma_recvfrom will complete the request.
+ *
+ * NOTE: The ctxt must not be touched after the last WR has been posted
+ * because the I/O completion processing may occur on another
+ * processor and free / modify the context. Ne touche pas!
+ */
+static int rdma_read_xdr(struct svcxprt_rdma *xprt,
+                        struct rpcrdma_msg *rmsgp,
+                        struct svc_rqst *rqstp,
+                        struct svc_rdma_op_ctxt *hdr_ctxt)
+{
+       struct ib_send_wr read_wr;
+       int err = 0;
+       int ch_no;
+       struct ib_sge *sge;
+       int ch_count;
+       int byte_count;
+       int sge_count;
+       u64 sgl_offset;
+       struct rpcrdma_read_chunk *ch;
+       struct svc_rdma_op_ctxt *ctxt = NULL;
+       struct svc_rdma_op_ctxt *head;
+       struct svc_rdma_op_ctxt *tmp_sge_ctxt;
+       struct svc_rdma_op_ctxt *tmp_ch_ctxt;
+       struct chunk_sge *ch_sge_ary;
+
+       /* If no read list is present, return 0 */
+       ch = svc_rdma_get_read_chunk(rmsgp);
+       if (!ch)
+               return 0;
+
+       /* Allocate temporary contexts to keep SGE */
+       BUG_ON(sizeof(struct ib_sge) < sizeof(struct chunk_sge));
+       tmp_sge_ctxt = svc_rdma_get_context(xprt);
+       sge = tmp_sge_ctxt->sge;
+       tmp_ch_ctxt = svc_rdma_get_context(xprt);
+       ch_sge_ary = (struct chunk_sge *)tmp_ch_ctxt->sge;
+
+       svc_rdma_rcl_chunk_counts(ch, &ch_count, &byte_count);
+       sge_count = rdma_rcl_to_sge(xprt, rqstp, hdr_ctxt, rmsgp,
+                                   sge, ch_sge_ary,
+                                   ch_count, byte_count);
+       head = svc_rdma_get_context(xprt);
+       sgl_offset = 0;
+       ch_no = 0;
+
+       for (ch = (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0];
+            ch->rc_discrim != 0; ch++, ch_no++) {
+next_sge:
+               if (!ctxt)
+                       ctxt = head;
+               else {
+                       ctxt->next = svc_rdma_get_context(xprt);
+                       ctxt = ctxt->next;
+               }
+               ctxt->next = NULL;
+               ctxt->direction = DMA_FROM_DEVICE;
+               clear_bit(RDMACTXT_F_READ_DONE, &ctxt->flags);
+               clear_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags);
+               if ((ch+1)->rc_discrim == 0) {
+                       /*
+                        * Checked in sq_cq_reap to see if we need to
+                        * be enqueued
+                        */
+                       set_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags);
+                       ctxt->next = hdr_ctxt;
+                       hdr_ctxt->next = head;
+               }
+
+               /* Prepare READ WR */
+               memset(&read_wr, 0, sizeof read_wr);
+               ctxt->wr_op = IB_WR_RDMA_READ;
+               read_wr.wr_id = (unsigned long)ctxt;
+               read_wr.opcode = IB_WR_RDMA_READ;
+               read_wr.send_flags = IB_SEND_SIGNALED;
+               read_wr.wr.rdma.rkey = ch->rc_target.rs_handle;
+               read_wr.wr.rdma.remote_addr =
+                       get_unaligned(&(ch->rc_target.rs_offset)) +
+                       sgl_offset;
+               read_wr.sg_list = &sge[ch_sge_ary[ch_no].start];
+               read_wr.num_sge =
+                       rdma_read_max_sge(xprt, ch_sge_ary[ch_no].count);
+               rdma_set_ctxt_sge(ctxt, &sge[ch_sge_ary[ch_no].start],
+                                 &sgl_offset,
+                                 read_wr.num_sge);
+
+               /* Post the read */
+               err = svc_rdma_send(xprt, &read_wr);
+               if (err) {
+                       printk(KERN_ERR "svcrdma: Error posting send = %d\n",
+                              err);
+                       /*
+                        * Break the circular list so free knows when
+                        * to stop if the error happened to occur on
+                        * the last read
+                        */
+                       ctxt->next = NULL;
+                       goto out;
+               }
+               atomic_inc(&rdma_stat_read);
+
+               if (read_wr.num_sge < ch_sge_ary[ch_no].count) {
+                       ch_sge_ary[ch_no].count -= read_wr.num_sge;
+                       ch_sge_ary[ch_no].start += read_wr.num_sge;
+                       goto next_sge;
+               }
+               sgl_offset = 0;
+               err = 0;
+       }
+
+ out:
+       svc_rdma_put_context(tmp_sge_ctxt, 0);
+       svc_rdma_put_context(tmp_ch_ctxt, 0);
+
+       /* Detach arg pages. svc_recv will replenish them */
+       for (ch_no = 0; &rqstp->rq_pages[ch_no] < rqstp->rq_respages; ch_no++)
+               rqstp->rq_pages[ch_no] = NULL;
+
+       /*
+        * Detach res pages. svc_release must see a resused count of
+        * zero or it will attempt to put them.
+        */
+       while (rqstp->rq_resused)
+               rqstp->rq_respages[--rqstp->rq_resused] = NULL;
+
+       if (err) {
+               printk(KERN_ERR "svcrdma : RDMA_READ error = %d\n", err);
+               set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
+               /* Free the linked list of read contexts */
+               while (head != NULL) {
+                       ctxt = head->next;
+                       svc_rdma_put_context(head, 1);
+                       head = ctxt;
+               }
+               return 0;
+       }
+
+       return 1;
+}
+
+static int rdma_read_complete(struct svc_rqst *rqstp,
+                             struct svc_rdma_op_ctxt *data)
+{
+       struct svc_rdma_op_ctxt *head = data->next;
+       int page_no;
+       int ret;
+
+       BUG_ON(!head);
+
+       /* Copy RPC pages */
+       for (page_no = 0; page_no < head->count; page_no++) {
+               put_page(rqstp->rq_pages[page_no]);
+               rqstp->rq_pages[page_no] = head->pages[page_no];
+       }
+       /* Point rq_arg.pages past header */
+       rqstp->rq_arg.pages = &rqstp->rq_pages[head->sge[0].length];
+       rqstp->rq_arg.page_len = head->arg.page_len;
+       rqstp->rq_arg.page_base = head->arg.page_base;
+
+       /* rq_respages starts after the last arg page */
+       rqstp->rq_respages = &rqstp->rq_arg.pages[page_no];
+       rqstp->rq_resused = 0;
+
+       /* Rebuild rq_arg head and tail. */
+       rqstp->rq_arg.head[0] = head->arg.head[0];
+       rqstp->rq_arg.tail[0] = head->arg.tail[0];
+       rqstp->rq_arg.len = head->arg.len;
+       rqstp->rq_arg.buflen = head->arg.buflen;
+
+       /* XXX: What should this be? */
+       rqstp->rq_prot = IPPROTO_MAX;
+
+       /*
+        * Free the contexts we used to build the RDMA_READ. We have
+        * to be careful here because the context list uses the same
+        * next pointer used to chain the contexts associated with the
+        * RDMA_READ
+        */
+       data->next = NULL;      /* terminate circular list */
+       do {
+               data = head->next;
+               svc_rdma_put_context(head, 0);
+               head = data;
+       } while (head != NULL);
+
+       ret = rqstp->rq_arg.head[0].iov_len
+               + rqstp->rq_arg.page_len
+               + rqstp->rq_arg.tail[0].iov_len;
+       dprintk("svcrdma: deferred read ret=%d, rq_arg.len =%d, "
+               "rq_arg.head[0].iov_base=%p, rq_arg.head[0].iov_len = %zd\n",
+               ret, rqstp->rq_arg.len, rqstp->rq_arg.head[0].iov_base,
+               rqstp->rq_arg.head[0].iov_len);
+
+       /* Indicate that we've consumed an RQ credit */
+       rqstp->rq_xprt_ctxt = rqstp->rq_xprt;
+       svc_xprt_received(rqstp->rq_xprt);
+       return ret;
+}
+
+/*
+ * Set up the rqstp thread context to point to the RQ buffer. If
+ * necessary, pull additional data from the client with an RDMA_READ
+ * request.
+ */
+int svc_rdma_recvfrom(struct svc_rqst *rqstp)
+{
+       struct svc_xprt *xprt = rqstp->rq_xprt;
+       struct svcxprt_rdma *rdma_xprt =
+               container_of(xprt, struct svcxprt_rdma, sc_xprt);
+       struct svc_rdma_op_ctxt *ctxt = NULL;
+       struct rpcrdma_msg *rmsgp;
+       int ret = 0;
+       int len;
+
+       dprintk("svcrdma: rqstp=%p\n", rqstp);
+
+       /*
+        * The rq_xprt_ctxt indicates if we've consumed an RQ credit
+        * or not. It is used in the rdma xpo_release_rqst function to
+        * determine whether or not to return an RQ WQE to the RQ.
+        */
+       rqstp->rq_xprt_ctxt = NULL;
+
+       spin_lock_bh(&rdma_xprt->sc_read_complete_lock);
+       if (!list_empty(&rdma_xprt->sc_read_complete_q)) {
+               ctxt = list_entry(rdma_xprt->sc_read_complete_q.next,
+                                 struct svc_rdma_op_ctxt,
+                                 dto_q);
+               list_del_init(&ctxt->dto_q);
+       }
+       spin_unlock_bh(&rdma_xprt->sc_read_complete_lock);
+       if (ctxt)
+               return rdma_read_complete(rqstp, ctxt);
+
+       spin_lock_bh(&rdma_xprt->sc_rq_dto_lock);
+       if (!list_empty(&rdma_xprt->sc_rq_dto_q)) {
+               ctxt = list_entry(rdma_xprt->sc_rq_dto_q.next,
+                                 struct svc_rdma_op_ctxt,
+                                 dto_q);
+               list_del_init(&ctxt->dto_q);
+       } else {
+               atomic_inc(&rdma_stat_rq_starve);
+               clear_bit(XPT_DATA, &xprt->xpt_flags);
+               ctxt = NULL;
+       }
+       spin_unlock_bh(&rdma_xprt->sc_rq_dto_lock);
+       if (!ctxt) {
+               /* This is the EAGAIN path. The svc_recv routine will
+                * return -EAGAIN, the nfsd thread will go to call into
+                * svc_recv again and we shouldn't be on the active
+                * transport list
+                */
+               if (test_bit(XPT_CLOSE, &xprt->xpt_flags))
+                       goto close_out;
+
+               BUG_ON(ret);
+               goto out;
+       }
+       dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
+               ctxt, rdma_xprt, rqstp, ctxt->wc_status);
+       BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
+       atomic_inc(&rdma_stat_recv);
+
+       /* Build up the XDR from the receive buffers. */
+       rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
+
+       /* Decode the RDMA header. */
+       len = svc_rdma_xdr_decode_req(&rmsgp, rqstp);
+       rqstp->rq_xprt_hlen = len;
+
+       /* If the request is invalid, reply with an error */
+       if (len < 0) {
+               if (len == -ENOSYS)
+                       (void)svc_rdma_send_error(rdma_xprt, rmsgp, ERR_VERS);
+               goto close_out;
+       }
+
+       /* Read read-list data. If we would need to wait, defer
+        * it. Not that in this case, we don't return the RQ credit
+        * until after the read completes.
+        */
+       if (rdma_read_xdr(rdma_xprt, rmsgp, rqstp, ctxt)) {
+               svc_xprt_received(xprt);
+               return 0;
+       }
+
+       /* Indicate we've consumed an RQ credit */
+       rqstp->rq_xprt_ctxt = rqstp->rq_xprt;
+
+       ret = rqstp->rq_arg.head[0].iov_len
+               + rqstp->rq_arg.page_len
+               + rqstp->rq_arg.tail[0].iov_len;
+       svc_rdma_put_context(ctxt, 0);
+ out:
+       dprintk("svcrdma: ret = %d, rq_arg.len =%d, "
+               "rq_arg.head[0].iov_base=%p, rq_arg.head[0].iov_len = %zd\n",
+               ret, rqstp->rq_arg.len,
+               rqstp->rq_arg.head[0].iov_base,
+               rqstp->rq_arg.head[0].iov_len);
+       rqstp->rq_prot = IPPROTO_MAX;
+       svc_xprt_copy_addrs(rqstp, xprt);
+       svc_xprt_received(xprt);
+       return ret;
+
+ close_out:
+       if (ctxt) {
+               svc_rdma_put_context(ctxt, 1);
+               /* Indicate we've consumed an RQ credit */
+               rqstp->rq_xprt_ctxt = rqstp->rq_xprt;
+       }
+       dprintk("svcrdma: transport %p is closing\n", xprt);
+       /*
+        * Set the close bit and enqueue it. svc_recv will see the
+        * close bit and call svc_xprt_delete
+        */
+       set_bit(XPT_CLOSE, &xprt->xpt_flags);
+       svc_xprt_received(xprt);
+       return 0;
+}
diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
new file mode 100644 (file)
index 0000000..3e32194
--- /dev/null
@@ -0,0 +1,520 @@
+/*
+ * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the BSD-type
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *      Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ *      Neither the name of the Network Appliance, Inc. nor the names of
+ *      its contributors may be used to endorse or promote products
+ *      derived from this software without specific prior written
+ *      permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Tom Tucker <tom@opengridcomputing.com>
+ */
+
+#include <linux/sunrpc/debug.h>
+#include <linux/sunrpc/rpc_rdma.h>
+#include <linux/spinlock.h>
+#include <asm/unaligned.h>
+#include <rdma/ib_verbs.h>
+#include <rdma/rdma_cm.h>
+#include <linux/sunrpc/svc_rdma.h>
+
+#define RPCDBG_FACILITY        RPCDBG_SVCXPRT
+
+/* Encode an XDR as an array of IB SGE
+ *
+ * Assumptions:
+ * - head[0] is physically contiguous.
+ * - tail[0] is physically contiguous.
+ * - pages[] is not physically or virtually contigous and consists of
+ *   PAGE_SIZE elements.
+ *
+ * Output:
+ * SGE[0]              reserved for RCPRDMA header
+ * SGE[1]              data from xdr->head[]
+ * SGE[2..sge_count-2] data from xdr->pages[]
+ * SGE[sge_count-1]    data from xdr->tail.
+ *
+ */
+static struct ib_sge *xdr_to_sge(struct svcxprt_rdma *xprt,
+                                struct xdr_buf *xdr,
+                                struct ib_sge *sge,
+                                int *sge_count)
+{
+       /* Max we need is the length of the XDR / pagesize + one for
+        * head + one for tail + one for RPCRDMA header
+        */
+       int sge_max = (xdr->len+PAGE_SIZE-1) / PAGE_SIZE + 3;
+       int sge_no;
+       u32 byte_count = xdr->len;
+       u32 sge_bytes;
+       u32 page_bytes;
+       int page_off;
+       int page_no;
+
+       /* Skip the first sge, this is for the RPCRDMA header */
+       sge_no = 1;
+
+       /* Head SGE */
+       sge[sge_no].addr = ib_dma_map_single(xprt->sc_cm_id->device,
+                                            xdr->head[0].iov_base,
+                                            xdr->head[0].iov_len,
+                                            DMA_TO_DEVICE);
+       sge_bytes = min_t(u32, byte_count, xdr->head[0].iov_len);
+       byte_count -= sge_bytes;
+       sge[sge_no].length = sge_bytes;
+       sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
+       sge_no++;
+
+       /* pages SGE */
+       page_no = 0;
+       page_bytes = xdr->page_len;
+       page_off = xdr->page_base;
+       while (byte_count && page_bytes) {
+               sge_bytes = min_t(u32, byte_count, (PAGE_SIZE-page_off));
+               sge[sge_no].addr =
+                       ib_dma_map_page(xprt->sc_cm_id->device,
+                                       xdr->pages[page_no], page_off,
+                                       sge_bytes, DMA_TO_DEVICE);
+               sge_bytes = min(sge_bytes, page_bytes);
+               byte_count -= sge_bytes;
+               page_bytes -= sge_bytes;
+               sge[sge_no].length = sge_bytes;
+               sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
+
+               sge_no++;
+               page_no++;
+               page_off = 0; /* reset for next time through loop */
+       }
+
+       /* Tail SGE */
+       if (byte_count && xdr->tail[0].iov_len) {
+               sge[sge_no].addr =
+                       ib_dma_map_single(xprt->sc_cm_id->device,
+                                         xdr->tail[0].iov_base,
+                                         xdr->tail[0].iov_len,
+                                         DMA_TO_DEVICE);
+               sge_bytes = min_t(u32, byte_count, xdr->tail[0].iov_len);
+               byte_count -= sge_bytes;
+               sge[sge_no].length = sge_bytes;
+               sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
+               sge_no++;
+       }
+
+       BUG_ON(sge_no > sge_max);
+       BUG_ON(byte_count != 0);
+
+       *sge_count = sge_no;
+       return sge;
+}
+
+
+/* Assumptions:
+ * - The specified write_len can be represented in sc_max_sge * PAGE_SIZE
+ */
+static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
+                     u32 rmr, u64 to,
+                     u32 xdr_off, int write_len,
+                     struct ib_sge *xdr_sge, int sge_count)
+{
+       struct svc_rdma_op_ctxt *tmp_sge_ctxt;
+       struct ib_send_wr write_wr;
+       struct ib_sge *sge;
+       int xdr_sge_no;
+       int sge_no;
+       int sge_bytes;
+       int sge_off;
+       int bc;
+       struct svc_rdma_op_ctxt *ctxt;
+       int ret = 0;
+
+       BUG_ON(sge_count >= 32);
+       dprintk("svcrdma: RDMA_WRITE rmr=%x, to=%llx, xdr_off=%d, "
+               "write_len=%d, xdr_sge=%p, sge_count=%d\n",
+               rmr, to, xdr_off, write_len, xdr_sge, sge_count);
+
+       ctxt = svc_rdma_get_context(xprt);
+       ctxt->count = 0;
+       tmp_sge_ctxt = svc_rdma_get_context(xprt);
+       sge = tmp_sge_ctxt->sge;
+
+       /* Find the SGE associated with xdr_off */
+       for (bc = xdr_off, xdr_sge_no = 1; bc && xdr_sge_no < sge_count;
+            xdr_sge_no++) {
+               if (xdr_sge[xdr_sge_no].length > bc)
+                       break;
+               bc -= xdr_sge[xdr_sge_no].length;
+       }
+
+       sge_off = bc;
+       bc = write_len;
+       sge_no = 0;
+
+       /* Copy the remaining SGE */
+       while (bc != 0 && xdr_sge_no < sge_count) {
+               sge[sge_no].addr = xdr_sge[xdr_sge_no].addr + sge_off;
+               sge[sge_no].lkey = xdr_sge[xdr_sge_no].lkey;
+               sge_bytes = min((size_t)bc,
+                               (size_t)(xdr_sge[xdr_sge_no].length-sge_off));
+               sge[sge_no].length = sge_bytes;
+
+               sge_off = 0;
+               sge_no++;
+               xdr_sge_no++;
+               bc -= sge_bytes;
+       }
+
+       BUG_ON(bc != 0);
+       BUG_ON(xdr_sge_no > sge_count);
+
+       /* Prepare WRITE WR */
+       memset(&write_wr, 0, sizeof write_wr);
+       ctxt->wr_op = IB_WR_RDMA_WRITE;
+       write_wr.wr_id = (unsigned long)ctxt;
+       write_wr.sg_list = &sge[0];
+       write_wr.num_sge = sge_no;
+       write_wr.opcode = IB_WR_RDMA_WRITE;
+       write_wr.send_flags = IB_SEND_SIGNALED;
+       write_wr.wr.rdma.rkey = rmr;
+       write_wr.wr.rdma.remote_addr = to;
+
+       /* Post It */
+       atomic_inc(&rdma_stat_write);
+       if (svc_rdma_send(xprt, &write_wr)) {
+               svc_rdma_put_context(ctxt, 1);
+               /* Fatal error, close transport */
+               ret = -EIO;
+       }
+       svc_rdma_put_context(tmp_sge_ctxt, 0);
+       return ret;
+}
+
+static int send_write_chunks(struct svcxprt_rdma *xprt,
+                            struct rpcrdma_msg *rdma_argp,
+                            struct rpcrdma_msg *rdma_resp,
+                            struct svc_rqst *rqstp,
+                            struct ib_sge *sge,
+                            int sge_count)
+{
+       u32 xfer_len = rqstp->rq_res.page_len + rqstp->rq_res.tail[0].iov_len;
+       int write_len;
+       int max_write;
+       u32 xdr_off;
+       int chunk_off;
+       int chunk_no;
+       struct rpcrdma_write_array *arg_ary;
+       struct rpcrdma_write_array *res_ary;
+       int ret;
+
+       arg_ary = svc_rdma_get_write_array(rdma_argp);
+       if (!arg_ary)
+               return 0;
+       res_ary = (struct rpcrdma_write_array *)
+               &rdma_resp->rm_body.rm_chunks[1];
+
+       max_write = xprt->sc_max_sge * PAGE_SIZE;
+
+       /* Write chunks start at the pagelist */
+       for (xdr_off = rqstp->rq_res.head[0].iov_len, chunk_no = 0;
+            xfer_len && chunk_no < arg_ary->wc_nchunks;
+            chunk_no++) {
+               struct rpcrdma_segment *arg_ch;
+               u64 rs_offset;
+
+               arg_ch = &arg_ary->wc_array[chunk_no].wc_target;
+               write_len = min(xfer_len, arg_ch->rs_length);
+
+               /* Prepare the response chunk given the length actually
+                * written */
+               rs_offset = get_unaligned(&(arg_ch->rs_offset));
+               svc_rdma_xdr_encode_array_chunk(res_ary, chunk_no,
+                                           arg_ch->rs_handle,
+                                           rs_offset,
+                                           write_len);
+               chunk_off = 0;
+               while (write_len) {
+                       int this_write;
+                       this_write = min(write_len, max_write);
+                       ret = send_write(xprt, rqstp,
+                                        arg_ch->rs_handle,
+                                        rs_offset + chunk_off,
+                                        xdr_off,
+                                        this_write,
+                                        sge,
+                                        sge_count);
+                       if (ret) {
+                               dprintk("svcrdma: RDMA_WRITE failed, ret=%d\n",
+                                       ret);
+                               return -EIO;
+                       }
+                       chunk_off += this_write;
+                       xdr_off += this_write;
+                       xfer_len -= this_write;
+                       write_len -= this_write;
+               }
+       }
+       /* Update the req with the number of chunks actually used */
+       svc_rdma_xdr_encode_write_list(rdma_resp, chunk_no);
+
+       return rqstp->rq_res.page_len + rqstp->rq_res.tail[0].iov_len;
+}
+
+static int send_reply_chunks(struct svcxprt_rdma *xprt,
+                            struct rpcrdma_msg *rdma_argp,
+                            struct rpcrdma_msg *rdma_resp,
+                            struct svc_rqst *rqstp,
+                            struct ib_sge *sge,
+                            int sge_count)
+{
+       u32 xfer_len = rqstp->rq_res.len;
+       int write_len;
+       int max_write;
+       u32 xdr_off;
+       int chunk_no;
+       int chunk_off;
+       struct rpcrdma_segment *ch;
+       struct rpcrdma_write_array *arg_ary;
+       struct rpcrdma_write_array *res_ary;
+       int ret;
+
+       arg_ary = svc_rdma_get_reply_array(rdma_argp);
+       if (!arg_ary)
+               return 0;
+       /* XXX: need to fix when reply lists occur with read-list and or
+        * write-list */
+       res_ary = (struct rpcrdma_write_array *)
+               &rdma_resp->rm_body.rm_chunks[2];
+
+       max_write = xprt->sc_max_sge * PAGE_SIZE;
+
+       /* xdr offset starts at RPC message */
+       for (xdr_off = 0, chunk_no = 0;
+            xfer_len && chunk_no < arg_ary->wc_nchunks;
+            chunk_no++) {
+               u64 rs_offset;
+               ch = &arg_ary->wc_array[chunk_no].wc_target;
+               write_len = min(xfer_len, ch->rs_length);
+
+
+               /* Prepare the reply chunk given the length actually
+                * written */
+               rs_offset = get_unaligned(&(ch->rs_offset));
+               svc_rdma_xdr_encode_array_chunk(res_ary, chunk_no,
+                                           ch->rs_handle, rs_offset,
+                                           write_len);
+               chunk_off = 0;
+               while (write_len) {
+                       int this_write;
+
+                       this_write = min(write_len, max_write);
+                       ret = send_write(xprt, rqstp,
+                                        ch->rs_handle,
+                                        rs_offset + chunk_off,
+                                        xdr_off,
+                                        this_write,
+                                        sge,
+                                        sge_count);
+                       if (ret) {
+                               dprintk("svcrdma: RDMA_WRITE failed, ret=%d\n",
+                                       ret);
+                               return -EIO;
+                       }
+                       chunk_off += this_write;
+                       xdr_off += this_write;
+                       xfer_len -= this_write;
+                       write_len -= this_write;
+               }
+       }
+       /* Update the req with the number of chunks actually used */
+       svc_rdma_xdr_encode_reply_array(res_ary, chunk_no);
+
+       return rqstp->rq_res.len;
+}
+
+/* This function prepares the portion of the RPCRDMA message to be
+ * sent in the RDMA_SEND. This function is called after data sent via
+ * RDMA has already been transmitted. There are three cases:
+ * - The RPCRDMA header, RPC header, and payload are all sent in a
+ *   single RDMA_SEND. This is the "inline" case.
+ * - The RPCRDMA header and some portion of the RPC header and data
+ *   are sent via this RDMA_SEND and another portion of the data is
+ *   sent via RDMA.
+ * - The RPCRDMA header [NOMSG] is sent in this RDMA_SEND and the RPC
+ *   header and data are all transmitted via RDMA.
+ * In all three cases, this function prepares the RPCRDMA header in
+ * sge[0], the 'type' parameter indicates the type to place in the
+ * RPCRDMA header, and the 'byte_count' field indicates how much of
+ * the XDR to include in this RDMA_SEND.
+ */
+static int send_reply(struct svcxprt_rdma *rdma,
+                     struct svc_rqst *rqstp,
+                     struct page *page,
+                     struct rpcrdma_msg *rdma_resp,
+                     struct svc_rdma_op_ctxt *ctxt,
+                     int sge_count,
+                     int byte_count)
+{
+       struct ib_send_wr send_wr;
+       int sge_no;
+       int sge_bytes;
+       int page_no;
+       int ret;
+
+       /* Prepare the context */
+       ctxt->pages[0] = page;
+       ctxt->count = 1;
+
+       /* Prepare the SGE for the RPCRDMA Header */
+       ctxt->sge[0].addr =
+               ib_dma_map_page(rdma->sc_cm_id->device,
+                               page, 0, PAGE_SIZE, DMA_TO_DEVICE);
+       ctxt->direction = DMA_TO_DEVICE;
+       ctxt->sge[0].length = svc_rdma_xdr_get_reply_hdr_len(rdma_resp);
+       ctxt->sge[0].lkey = rdma->sc_phys_mr->lkey;
+
+       /* Determine how many of our SGE are to be transmitted */
+       for (sge_no = 1; byte_count && sge_no < sge_count; sge_no++) {
+               sge_bytes = min((size_t)ctxt->sge[sge_no].length,
+                               (size_t)byte_count);
+               byte_count -= sge_bytes;
+       }
+       BUG_ON(byte_count != 0);
+
+       /* Save all respages in the ctxt and remove them from the
+        * respages array. They are our pages until the I/O
+        * completes.
+        */
+       for (page_no = 0; page_no < rqstp->rq_resused; page_no++) {
+               ctxt->pages[page_no+1] = rqstp->rq_respages[page_no];
+               ctxt->count++;
+               rqstp->rq_respages[page_no] = NULL;
+       }
+
+       BUG_ON(sge_no > rdma->sc_max_sge);
+       memset(&send_wr, 0, sizeof send_wr);
+       ctxt->wr_op = IB_WR_SEND;
+       send_wr.wr_id = (unsigned long)ctxt;
+       send_wr.sg_list = ctxt->sge;
+       send_wr.num_sge = sge_no;
+       send_wr.opcode = IB_WR_SEND;
+       send_wr.send_flags =  IB_SEND_SIGNALED;
+
+       ret = svc_rdma_send(rdma, &send_wr);
+       if (ret)
+               svc_rdma_put_context(ctxt, 1);
+
+       return ret;
+}
+
+void svc_rdma_prep_reply_hdr(struct svc_rqst *rqstp)
+{
+}
+
+/*
+ * Return the start of an xdr buffer.
+ */
+static void *xdr_start(struct xdr_buf *xdr)
+{
+       return xdr->head[0].iov_base -
+               (xdr->len -
+                xdr->page_len -
+                xdr->tail[0].iov_len -
+                xdr->head[0].iov_len);
+}
+
+int svc_rdma_sendto(struct svc_rqst *rqstp)
+{
+       struct svc_xprt *xprt = rqstp->rq_xprt;
+       struct svcxprt_rdma *rdma =
+               container_of(xprt, struct svcxprt_rdma, sc_xprt);
+       struct rpcrdma_msg *rdma_argp;
+       struct rpcrdma_msg *rdma_resp;
+       struct rpcrdma_write_array *reply_ary;
+       enum rpcrdma_proc reply_type;
+       int ret;
+       int inline_bytes;
+       struct ib_sge *sge;
+       int sge_count = 0;
+       struct page *res_page;
+       struct svc_rdma_op_ctxt *ctxt;
+
+       dprintk("svcrdma: sending response for rqstp=%p\n", rqstp);
+
+       /* Get the RDMA request header. */
+       rdma_argp = xdr_start(&rqstp->rq_arg);
+
+       /* Build an SGE for the XDR */
+       ctxt = svc_rdma_get_context(rdma);
+       ctxt->direction = DMA_TO_DEVICE;
+       sge = xdr_to_sge(rdma, &rqstp->rq_res, ctxt->sge, &sge_count);
+
+       inline_bytes = rqstp->rq_res.len;
+
+       /* Create the RDMA response header */
+       res_page = svc_rdma_get_page();
+       rdma_resp = page_address(res_page);
+       reply_ary = svc_rdma_get_reply_array(rdma_argp);
+       if (reply_ary)
+               reply_type = RDMA_NOMSG;
+       else
+               reply_type = RDMA_MSG;
+       svc_rdma_xdr_encode_reply_header(rdma, rdma_argp,
+                                        rdma_resp, reply_type);
+
+       /* Send any write-chunk data and build resp write-list */
+       ret = send_write_chunks(rdma, rdma_argp, rdma_resp,
+                               rqstp, sge, sge_count);
+       if (ret < 0) {
+               printk(KERN_ERR "svcrdma: failed to send write chunks, rc=%d\n",
+                      ret);
+               goto error;
+       }
+       inline_bytes -= ret;
+
+       /* Send any reply-list data and update resp reply-list */
+       ret = send_reply_chunks(rdma, rdma_argp, rdma_resp,
+                               rqstp, sge, sge_count);
+       if (ret < 0) {
+               printk(KERN_ERR "svcrdma: failed to send reply chunks, rc=%d\n",
+                      ret);
+               goto error;
+       }
+       inline_bytes -= ret;
+
+       ret = send_reply(rdma, rqstp, res_page, rdma_resp, ctxt, sge_count,
+                        inline_bytes);
+       dprintk("svcrdma: send_reply returns %d\n", ret);
+       return ret;
+ error:
+       svc_rdma_put_context(ctxt, 0);
+       put_page(res_page);
+       return ret;
+}
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
new file mode 100644 (file)
index 0000000..f09444c
--- /dev/null
@@ -0,0 +1,1080 @@
+/*
+ * Copyright (c) 2005-2007 Network Appliance, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the BSD-type
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *      Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ *      Neither the name of the Network Appliance, Inc. nor the names of
+ *      its contributors may be used to endorse or promote products
+ *      derived from this software without specific prior written
+ *      permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Tom Tucker <tom@opengridcomputing.com>
+ */
+
+#include <linux/sunrpc/svc_xprt.h>
+#include <linux/sunrpc/debug.h>
+#include <linux/sunrpc/rpc_rdma.h>
+#include <linux/spinlock.h>
+#include <rdma/ib_verbs.h>
+#include <rdma/rdma_cm.h>
+#include <linux/sunrpc/svc_rdma.h>
+
+#define RPCDBG_FACILITY        RPCDBG_SVCXPRT
+
+static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
+                                       struct sockaddr *sa, int salen,
+                                       int flags);
+static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt);
+static void svc_rdma_release_rqst(struct svc_rqst *);
+static void rdma_destroy_xprt(struct svcxprt_rdma *xprt);
+static void dto_tasklet_func(unsigned long data);
+static void svc_rdma_detach(struct svc_xprt *xprt);
+static void svc_rdma_free(struct svc_xprt *xprt);
+static int svc_rdma_has_wspace(struct svc_xprt *xprt);
+static void rq_cq_reap(struct svcxprt_rdma *xprt);
+static void sq_cq_reap(struct svcxprt_rdma *xprt);
+
+DECLARE_TASKLET(dto_tasklet, dto_tasklet_func, 0UL);
+static DEFINE_SPINLOCK(dto_lock);
+static LIST_HEAD(dto_xprt_q);
+
+static struct svc_xprt_ops svc_rdma_ops = {
+       .xpo_create = svc_rdma_create,
+       .xpo_recvfrom = svc_rdma_recvfrom,
+       .xpo_sendto = svc_rdma_sendto,
+       .xpo_release_rqst = svc_rdma_release_rqst,
+       .xpo_detach = svc_rdma_detach,
+       .xpo_free = svc_rdma_free,
+       .xpo_prep_reply_hdr = svc_rdma_prep_reply_hdr,
+       .xpo_has_wspace = svc_rdma_has_wspace,
+       .xpo_accept = svc_rdma_accept,
+};
+
+struct svc_xprt_class svc_rdma_class = {
+       .xcl_name = "rdma",
+       .xcl_owner = THIS_MODULE,
+       .xcl_ops = &svc_rdma_ops,
+       .xcl_max_payload = RPCSVC_MAXPAYLOAD_TCP,
+};
+
+static int rdma_bump_context_cache(struct svcxprt_rdma *xprt)
+{
+       int target;
+       int at_least_one = 0;
+       struct svc_rdma_op_ctxt *ctxt;
+
+       target = min(xprt->sc_ctxt_cnt + xprt->sc_ctxt_bump,
+                    xprt->sc_ctxt_max);
+
+       spin_lock_bh(&xprt->sc_ctxt_lock);
+       while (xprt->sc_ctxt_cnt < target) {
+               xprt->sc_ctxt_cnt++;
+               spin_unlock_bh(&xprt->sc_ctxt_lock);
+
+               ctxt = kmalloc(sizeof(*ctxt), GFP_KERNEL);
+
+               spin_lock_bh(&xprt->sc_ctxt_lock);
+               if (ctxt) {
+                       at_least_one = 1;
+                       ctxt->next = xprt->sc_ctxt_head;
+                       xprt->sc_ctxt_head = ctxt;
+               } else {
+                       /* kmalloc failed...give up for now */
+                       xprt->sc_ctxt_cnt--;
+                       break;
+               }
+       }
+       spin_unlock_bh(&xprt->sc_ctxt_lock);
+       dprintk("svcrdma: sc_ctxt_max=%d, sc_ctxt_cnt=%d\n",
+               xprt->sc_ctxt_max, xprt->sc_ctxt_cnt);
+       return at_least_one;
+}
+
+struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *xprt)
+{
+       struct svc_rdma_op_ctxt *ctxt;
+
+       while (1) {
+               spin_lock_bh(&xprt->sc_ctxt_lock);
+               if (unlikely(xprt->sc_ctxt_head == NULL)) {
+                       /* Try to bump my cache. */
+                       spin_unlock_bh(&xprt->sc_ctxt_lock);
+
+                       if (rdma_bump_context_cache(xprt))
+                               continue;
+
+                       printk(KERN_INFO "svcrdma: sleeping waiting for "
+                              "context memory on xprt=%p\n",
+                              xprt);
+                       schedule_timeout_uninterruptible(msecs_to_jiffies(500));
+                       continue;
+               }
+               ctxt = xprt->sc_ctxt_head;
+               xprt->sc_ctxt_head = ctxt->next;
+               spin_unlock_bh(&xprt->sc_ctxt_lock);
+               ctxt->xprt = xprt;
+               INIT_LIST_HEAD(&ctxt->dto_q);
+               ctxt->count = 0;
+               break;
+       }
+       return ctxt;
+}
+
+void svc_rdma_put_context(struct svc_rdma_op_ctxt *ctxt, int free_pages)
+{
+       struct svcxprt_rdma *xprt;
+       int i;
+
+       BUG_ON(!ctxt);
+       xprt = ctxt->xprt;
+       if (free_pages)
+               for (i = 0; i < ctxt->count; i++)
+                       put_page(ctxt->pages[i]);
+
+       for (i = 0; i < ctxt->count; i++)
+               dma_unmap_single(xprt->sc_cm_id->device->dma_device,
+                                ctxt->sge[i].addr,
+                                ctxt->sge[i].length,
+                                ctxt->direction);
+       spin_lock_bh(&xprt->sc_ctxt_lock);
+       ctxt->next = xprt->sc_ctxt_head;
+       xprt->sc_ctxt_head = ctxt;
+       spin_unlock_bh(&xprt->sc_ctxt_lock);
+}
+
+/* ib_cq event handler */
+static void cq_event_handler(struct ib_event *event, void *context)
+{
+       struct svc_xprt *xprt = context;
+       dprintk("svcrdma: received CQ event id=%d, context=%p\n",
+               event->event, context);
+       set_bit(XPT_CLOSE, &xprt->xpt_flags);
+}
+
+/* QP event handler */
+static void qp_event_handler(struct ib_event *event, void *context)
+{
+       struct svc_xprt *xprt = context;
+
+       switch (event->event) {
+       /* These are considered benign events */
+       case IB_EVENT_PATH_MIG:
+       case IB_EVENT_COMM_EST:
+       case IB_EVENT_SQ_DRAINED:
+       case IB_EVENT_QP_LAST_WQE_REACHED:
+               dprintk("svcrdma: QP event %d received for QP=%p\n",
+                       event->event, event->element.qp);
+               break;
+       /* These are considered fatal events */
+       case IB_EVENT_PATH_MIG_ERR:
+       case IB_EVENT_QP_FATAL:
+       case IB_EVENT_QP_REQ_ERR:
+       case IB_EVENT_QP_ACCESS_ERR:
+       case IB_EVENT_DEVICE_FATAL:
+       default:
+               dprintk("svcrdma: QP ERROR event %d received for QP=%p, "
+                       "closing transport\n",
+                       event->event, event->element.qp);
+               set_bit(XPT_CLOSE, &xprt->xpt_flags);
+               break;
+       }
+}
+
+/*
+ * Data Transfer Operation Tasklet
+ *
+ * Walks a list of transports with I/O pending, removing entries as
+ * they are added to the server's I/O pending list. Two bits indicate
+ * if SQ, RQ, or both have I/O pending. The dto_lock is an irqsave
+ * spinlock that serializes access to the transport list with the RQ
+ * and SQ interrupt handlers.
+ */
+static void dto_tasklet_func(unsigned long data)
+{
+       struct svcxprt_rdma *xprt;
+       unsigned long flags;
+
+       spin_lock_irqsave(&dto_lock, flags);
+       while (!list_empty(&dto_xprt_q)) {
+               xprt = list_entry(dto_xprt_q.next,
+                                 struct svcxprt_rdma, sc_dto_q);
+               list_del_init(&xprt->sc_dto_q);
+               spin_unlock_irqrestore(&dto_lock, flags);
+
+               if (test_and_clear_bit(RDMAXPRT_RQ_PENDING, &xprt->sc_flags)) {
+                       ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
+                       rq_cq_reap(xprt);
+                       set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
+                       /*
+                        * If data arrived before established event,
+                        * don't enqueue. This defers RPC I/O until the
+                        * RDMA connection is complete.
+                        */
+                       if (!test_bit(RDMAXPRT_CONN_PENDING, &xprt->sc_flags))
+                               svc_xprt_enqueue(&xprt->sc_xprt);
+               }
+
+               if (test_and_clear_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags)) {
+                       ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
+                       sq_cq_reap(xprt);
+               }
+
+               spin_lock_irqsave(&dto_lock, flags);
+       }
+       spin_unlock_irqrestore(&dto_lock, flags);
+}
+
+/*
+ * Receive Queue Completion Handler
+ *
+ * Since an RQ completion handler is called on interrupt context, we
+ * need to defer the handling of the I/O to a tasklet
+ */
+static void rq_comp_handler(struct ib_cq *cq, void *cq_context)
+{
+       struct svcxprt_rdma *xprt = cq_context;
+       unsigned long flags;
+
+       /*
+        * Set the bit regardless of whether or not it's on the list
+        * because it may be on the list already due to an SQ
+        * completion.
+       */
+       set_bit(RDMAXPRT_RQ_PENDING, &xprt->sc_flags);
+
+       /*
+        * If this transport is not already on the DTO transport queue,
+        * add it
+        */
+       spin_lock_irqsave(&dto_lock, flags);
+       if (list_empty(&xprt->sc_dto_q))
+               list_add_tail(&xprt->sc_dto_q, &dto_xprt_q);
+       spin_unlock_irqrestore(&dto_lock, flags);
+
+       /* Tasklet does all the work to avoid irqsave locks. */
+       tasklet_schedule(&dto_tasklet);
+}
+
+/*
+ * rq_cq_reap - Process the RQ CQ.
+ *
+ * Take all completing WC off the CQE and enqueue the associated DTO
+ * context on the dto_q for the transport.
+ */
+static void rq_cq_reap(struct svcxprt_rdma *xprt)
+{
+       int ret;
+       struct ib_wc wc;
+       struct svc_rdma_op_ctxt *ctxt = NULL;
+
+       atomic_inc(&rdma_stat_rq_poll);
+
+       spin_lock_bh(&xprt->sc_rq_dto_lock);
+       while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
+               ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
+               ctxt->wc_status = wc.status;
+               ctxt->byte_len = wc.byte_len;
+               if (wc.status != IB_WC_SUCCESS) {
+                       /* Close the transport */
+                       set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
+                       svc_rdma_put_context(ctxt, 1);
+                       continue;
+               }
+               list_add_tail(&ctxt->dto_q, &xprt->sc_rq_dto_q);
+       }
+       spin_unlock_bh(&xprt->sc_rq_dto_lock);
+
+       if (ctxt)
+               atomic_inc(&rdma_stat_rq_prod);
+}
+
+/*
+ * Send Queue Completion Handler - potentially called on interrupt context.
+ */
+static void sq_cq_reap(struct svcxprt_rdma *xprt)
+{
+       struct svc_rdma_op_ctxt *ctxt = NULL;
+       struct ib_wc wc;
+       struct ib_cq *cq = xprt->sc_sq_cq;
+       int ret;
+
+       atomic_inc(&rdma_stat_sq_poll);
+       while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
+               ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
+               xprt = ctxt->xprt;
+
+               if (wc.status != IB_WC_SUCCESS)
+                       /* Close the transport */
+                       set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
+
+               /* Decrement used SQ WR count */
+               atomic_dec(&xprt->sc_sq_count);
+               wake_up(&xprt->sc_send_wait);
+
+               switch (ctxt->wr_op) {
+               case IB_WR_SEND:
+               case IB_WR_RDMA_WRITE:
+                       svc_rdma_put_context(ctxt, 1);
+                       break;
+
+               case IB_WR_RDMA_READ:
+                       if (test_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags)) {
+                               set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
+                               set_bit(RDMACTXT_F_READ_DONE, &ctxt->flags);
+                               spin_lock_bh(&xprt->sc_read_complete_lock);
+                               list_add_tail(&ctxt->dto_q,
+                                             &xprt->sc_read_complete_q);
+                               spin_unlock_bh(&xprt->sc_read_complete_lock);
+                               svc_xprt_enqueue(&xprt->sc_xprt);
+                       }
+                       break;
+
+               default:
+                       printk(KERN_ERR "svcrdma: unexpected completion type, "
+                              "opcode=%d, status=%d\n",
+                              wc.opcode, wc.status);
+                       break;
+               }
+       }
+
+       if (ctxt)
+               atomic_inc(&rdma_stat_sq_prod);
+}
+
+static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
+{
+       struct svcxprt_rdma *xprt = cq_context;
+       unsigned long flags;
+
+       /*
+        * Set the bit regardless of whether or not it's on the list
+        * because it may be on the list already due to an RQ
+        * completion.
+       */
+       set_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags);
+
+       /*
+        * If this transport is not already on the DTO transport queue,
+        * add it
+        */
+       spin_lock_irqsave(&dto_lock, flags);
+       if (list_empty(&xprt->sc_dto_q))
+               list_add_tail(&xprt->sc_dto_q, &dto_xprt_q);
+       spin_unlock_irqrestore(&dto_lock, flags);
+
+       /* Tasklet does all the work to avoid irqsave locks. */
+       tasklet_schedule(&dto_tasklet);
+}
+
+static void create_context_cache(struct svcxprt_rdma *xprt,
+                                int ctxt_count, int ctxt_bump, int ctxt_max)
+{
+       struct svc_rdma_op_ctxt *ctxt;
+       int i;
+
+       xprt->sc_ctxt_max = ctxt_max;
+       xprt->sc_ctxt_bump = ctxt_bump;
+       xprt->sc_ctxt_cnt = 0;
+       xprt->sc_ctxt_head = NULL;
+       for (i = 0; i < ctxt_count; i++) {
+               ctxt = kmalloc(sizeof(*ctxt), GFP_KERNEL);
+               if (ctxt) {
+                       ctxt->next = xprt->sc_ctxt_head;
+                       xprt->sc_ctxt_head = ctxt;
+                       xprt->sc_ctxt_cnt++;
+               }
+       }
+}
+
+static void destroy_context_cache(struct svc_rdma_op_ctxt *ctxt)
+{
+       struct svc_rdma_op_ctxt *next;
+       if (!ctxt)
+               return;
+
+       do {
+               next = ctxt->next;
+               kfree(ctxt);
+               ctxt = next;
+       } while (next);
+}
+
+static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *serv,
+                                            int listener)
+{
+       struct svcxprt_rdma *cma_xprt = kzalloc(sizeof *cma_xprt, GFP_KERNEL);
+
+       if (!cma_xprt)
+               return NULL;
+       svc_xprt_init(&svc_rdma_class, &cma_xprt->sc_xprt, serv);
+       INIT_LIST_HEAD(&cma_xprt->sc_accept_q);
+       INIT_LIST_HEAD(&cma_xprt->sc_dto_q);
+       INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
+       INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
+       init_waitqueue_head(&cma_xprt->sc_send_wait);
+
+       spin_lock_init(&cma_xprt->sc_lock);
+       spin_lock_init(&cma_xprt->sc_read_complete_lock);
+       spin_lock_init(&cma_xprt->sc_ctxt_lock);
+       spin_lock_init(&cma_xprt->sc_rq_dto_lock);
+
+       cma_xprt->sc_ord = svcrdma_ord;
+
+       cma_xprt->sc_max_req_size = svcrdma_max_req_size;
+       cma_xprt->sc_max_requests = svcrdma_max_requests;
+       cma_xprt->sc_sq_depth = svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT;
+       atomic_set(&cma_xprt->sc_sq_count, 0);
+
+       if (!listener) {
+               int reqs = cma_xprt->sc_max_requests;
+               create_context_cache(cma_xprt,
+                                    reqs << 1, /* starting size */
+                                    reqs,      /* bump amount */
+                                    reqs +
+                                    cma_xprt->sc_sq_depth +
+                                    RPCRDMA_MAX_THREADS + 1); /* max */
+               if (!cma_xprt->sc_ctxt_head) {
+                       kfree(cma_xprt);
+                       return NULL;
+               }
+               clear_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
+       } else
+               set_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
+
+       return cma_xprt;
+}
+
+struct page *svc_rdma_get_page(void)
+{
+       struct page *page;
+
+       while ((page = alloc_page(GFP_KERNEL)) == NULL) {
+               /* If we can't get memory, wait a bit and try again */
+               printk(KERN_INFO "svcrdma: out of memory...retrying in 1000 "
+                      "jiffies.\n");
+               schedule_timeout_uninterruptible(msecs_to_jiffies(1000));
+       }
+       return page;
+}
+
+int svc_rdma_post_recv(struct svcxprt_rdma *xprt)
+{
+       struct ib_recv_wr recv_wr, *bad_recv_wr;
+       struct svc_rdma_op_ctxt *ctxt;
+       struct page *page;
+       unsigned long pa;
+       int sge_no;
+       int buflen;
+       int ret;
+
+       ctxt = svc_rdma_get_context(xprt);
+       buflen = 0;
+       ctxt->direction = DMA_FROM_DEVICE;
+       for (sge_no = 0; buflen < xprt->sc_max_req_size; sge_no++) {
+               BUG_ON(sge_no >= xprt->sc_max_sge);
+               page = svc_rdma_get_page();
+               ctxt->pages[sge_no] = page;
+               pa = ib_dma_map_page(xprt->sc_cm_id->device,
+                                    page, 0, PAGE_SIZE,
+                                    DMA_FROM_DEVICE);
+               ctxt->sge[sge_no].addr = pa;
+               ctxt->sge[sge_no].length = PAGE_SIZE;
+               ctxt->sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
+               buflen += PAGE_SIZE;
+       }
+       ctxt->count = sge_no;
+       recv_wr.next = NULL;
+       recv_wr.sg_list = &ctxt->sge[0];
+       recv_wr.num_sge = ctxt->count;
+       recv_wr.wr_id = (u64)(unsigned long)ctxt;
+
+       ret = ib_post_recv(xprt->sc_qp, &recv_wr, &bad_recv_wr);
+       return ret;
+}
+
+/*
+ * This function handles the CONNECT_REQUEST event on a listening
+ * endpoint. It is passed the cma_id for the _new_ connection. The context in
+ * this cma_id is inherited from the listening cma_id and is the svc_xprt
+ * structure for the listening endpoint.
+ *
+ * This function creates a new xprt for the new connection and enqueues it on
+ * the accept queue for the listent xprt. When the listen thread is kicked, it
+ * will call the recvfrom method on the listen xprt which will accept the new
+ * connection.
+ */
+static void handle_connect_req(struct rdma_cm_id *new_cma_id)
+{
+       struct svcxprt_rdma *listen_xprt = new_cma_id->context;
+       struct svcxprt_rdma *newxprt;
+
+       /* Create a new transport */
+       newxprt = rdma_create_xprt(listen_xprt->sc_xprt.xpt_server, 0);
+       if (!newxprt) {
+               dprintk("svcrdma: failed to create new transport\n");
+               return;
+       }
+       newxprt->sc_cm_id = new_cma_id;
+       new_cma_id->context = newxprt;
+       dprintk("svcrdma: Creating newxprt=%p, cm_id=%p, listenxprt=%p\n",
+               newxprt, newxprt->sc_cm_id, listen_xprt);
+
+       /*
+        * Enqueue the new transport on the accept queue of the listening
+        * transport
+        */
+       spin_lock_bh(&listen_xprt->sc_lock);
+       list_add_tail(&newxprt->sc_accept_q, &listen_xprt->sc_accept_q);
+       spin_unlock_bh(&listen_xprt->sc_lock);
+
+       /*
+        * Can't use svc_xprt_received here because we are not on a
+        * rqstp thread
+       */
+       set_bit(XPT_CONN, &listen_xprt->sc_xprt.xpt_flags);
+       svc_xprt_enqueue(&listen_xprt->sc_xprt);
+}
+
+/*
+ * Handles events generated on the listening endpoint. These events will be
+ * either be incoming connect requests or adapter removal  events.
+ */
+static int rdma_listen_handler(struct rdma_cm_id *cma_id,
+                              struct rdma_cm_event *event)
+{
+       struct svcxprt_rdma *xprt = cma_id->context;
+       int ret = 0;
+
+       switch (event->event) {
+       case RDMA_CM_EVENT_CONNECT_REQUEST:
+               dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, "
+                       "event=%d\n", cma_id, cma_id->context, event->event);
+               handle_connect_req(cma_id);
+               break;
+
+       case RDMA_CM_EVENT_ESTABLISHED:
+               /* Accept complete */
+               dprintk("svcrdma: Connection completed on LISTEN xprt=%p, "
+                       "cm_id=%p\n", xprt, cma_id);
+               break;
+
+       case RDMA_CM_EVENT_DEVICE_REMOVAL:
+               dprintk("svcrdma: Device removal xprt=%p, cm_id=%p\n",
+                       xprt, cma_id);
+               if (xprt)
+                       set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
+               break;
+
+       default:
+               dprintk("svcrdma: Unexpected event on listening endpoint %p, "
+                       "event=%d\n", cma_id, event->event);
+               break;
+       }
+
+       return ret;
+}
+
+static int rdma_cma_handler(struct rdma_cm_id *cma_id,
+                           struct rdma_cm_event *event)
+{
+       struct svc_xprt *xprt = cma_id->context;
+       struct svcxprt_rdma *rdma =
+               container_of(xprt, struct svcxprt_rdma, sc_xprt);
+       switch (event->event) {
+       case RDMA_CM_EVENT_ESTABLISHED:
+               /* Accept complete */
+               dprintk("svcrdma: Connection completed on DTO xprt=%p, "
+                       "cm_id=%p\n", xprt, cma_id);
+               clear_bit(RDMAXPRT_CONN_PENDING, &rdma->sc_flags);
+               svc_xprt_enqueue(xprt);
+               break;
+       case RDMA_CM_EVENT_DISCONNECTED:
+               dprintk("svcrdma: Disconnect on DTO xprt=%p, cm_id=%p\n",
+                       xprt, cma_id);
+               if (xprt) {
+                       set_bit(XPT_CLOSE, &xprt->xpt_flags);
+                       svc_xprt_enqueue(xprt);
+               }
+               break;
+       case RDMA_CM_EVENT_DEVICE_REMOVAL:
+               dprintk("svcrdma: Device removal cma_id=%p, xprt = %p, "
+                       "event=%d\n", cma_id, xprt, event->event);
+               if (xprt) {
+                       set_bit(XPT_CLOSE, &xprt->xpt_flags);
+                       svc_xprt_enqueue(xprt);
+               }
+               break;
+       default:
+               dprintk("svcrdma: Unexpected event on DTO endpoint %p, "
+                       "event=%d\n", cma_id, event->event);
+               break;
+       }
+       return 0;
+}
+
+/*
+ * Create a listening RDMA service endpoint.
+ */
+static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
+                                       struct sockaddr *sa, int salen,
+                                       int flags)
+{
+       struct rdma_cm_id *listen_id;
+       struct svcxprt_rdma *cma_xprt;
+       struct svc_xprt *xprt;
+       int ret;
+
+       dprintk("svcrdma: Creating RDMA socket\n");
+
+       cma_xprt = rdma_create_xprt(serv, 1);
+       if (!cma_xprt)
+               return ERR_PTR(ENOMEM);
+       xprt = &cma_xprt->sc_xprt;
+
+       listen_id = rdma_create_id(rdma_listen_handler, cma_xprt, RDMA_PS_TCP);
+       if (IS_ERR(listen_id)) {
+               rdma_destroy_xprt(cma_xprt);
+               dprintk("svcrdma: rdma_create_id failed = %ld\n",
+                       PTR_ERR(listen_id));
+               return (void *)listen_id;
+       }
+       ret = rdma_bind_addr(listen_id, sa);
+       if (ret) {
+               rdma_destroy_xprt(cma_xprt);
+               rdma_destroy_id(listen_id);
+               dprintk("svcrdma: rdma_bind_addr failed = %d\n", ret);
+               return ERR_PTR(ret);
+       }
+       cma_xprt->sc_cm_id = listen_id;
+
+       ret = rdma_listen(listen_id, RPCRDMA_LISTEN_BACKLOG);
+       if (ret) {
+               rdma_destroy_id(listen_id);
+               rdma_destroy_xprt(cma_xprt);
+               dprintk("svcrdma: rdma_listen failed = %d\n", ret);
+       }
+
+       /*
+        * We need to use the address from the cm_id in case the
+        * caller specified 0 for the port number.
+        */
+       sa = (struct sockaddr *)&cma_xprt->sc_cm_id->route.addr.src_addr;
+       svc_xprt_set_local(&cma_xprt->sc_xprt, sa, salen);
+
+       return &cma_xprt->sc_xprt;
+}
+
+/*
+ * This is the xpo_recvfrom function for listening endpoints. Its
+ * purpose is to accept incoming connections. The CMA callback handler
+ * has already created a new transport and attached it to the new CMA
+ * ID.
+ *
+ * There is a queue of pending connections hung on the listening
+ * transport. This queue contains the new svc_xprt structure. This
+ * function takes svc_xprt structures off the accept_q and completes
+ * the connection.
+ */
+static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
+{
+       struct svcxprt_rdma *listen_rdma;
+       struct svcxprt_rdma *newxprt = NULL;
+       struct rdma_conn_param conn_param;
+       struct ib_qp_init_attr qp_attr;
+       struct ib_device_attr devattr;
+       struct sockaddr *sa;
+       int ret;
+       int i;
+
+       listen_rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt);
+       clear_bit(XPT_CONN, &xprt->xpt_flags);
+       /* Get the next entry off the accept list */
+       spin_lock_bh(&listen_rdma->sc_lock);
+       if (!list_empty(&listen_rdma->sc_accept_q)) {
+               newxprt = list_entry(listen_rdma->sc_accept_q.next,
+                                    struct svcxprt_rdma, sc_accept_q);
+               list_del_init(&newxprt->sc_accept_q);
+       }
+       if (!list_empty(&listen_rdma->sc_accept_q))
+               set_bit(XPT_CONN, &listen_rdma->sc_xprt.xpt_flags);
+       spin_unlock_bh(&listen_rdma->sc_lock);
+       if (!newxprt)
+               return NULL;
+
+       dprintk("svcrdma: newxprt from accept queue = %p, cm_id=%p\n",
+               newxprt, newxprt->sc_cm_id);
+
+       ret = ib_query_device(newxprt->sc_cm_id->device, &devattr);
+       if (ret) {
+               dprintk("svcrdma: could not query device attributes on "
+                       "device %p, rc=%d\n", newxprt->sc_cm_id->device, ret);
+               goto errout;
+       }
+
+       /* Qualify the transport resource defaults with the
+        * capabilities of this particular device */
+       newxprt->sc_max_sge = min((size_t)devattr.max_sge,
+                                 (size_t)RPCSVC_MAXPAGES);
+       newxprt->sc_max_requests = min((size_t)devattr.max_qp_wr,
+                                  (size_t)svcrdma_max_requests);
+       newxprt->sc_sq_depth = RPCRDMA_SQ_DEPTH_MULT * newxprt->sc_max_requests;
+
+       newxprt->sc_ord =  min((size_t)devattr.max_qp_rd_atom,
+                              (size_t)svcrdma_ord);
+
+       newxprt->sc_pd = ib_alloc_pd(newxprt->sc_cm_id->device);
+       if (IS_ERR(newxprt->sc_pd)) {
+               dprintk("svcrdma: error creating PD for connect request\n");
+               goto errout;
+       }
+       newxprt->sc_sq_cq = ib_create_cq(newxprt->sc_cm_id->device,
+                                        sq_comp_handler,
+                                        cq_event_handler,
+                                        newxprt,
+                                        newxprt->sc_sq_depth,
+                                        0);
+       if (IS_ERR(newxprt->sc_sq_cq)) {
+               dprintk("svcrdma: error creating SQ CQ for connect request\n");
+               goto errout;
+       }
+       newxprt->sc_rq_cq = ib_create_cq(newxprt->sc_cm_id->device,
+                                        rq_comp_handler,
+                                        cq_event_handler,
+                                        newxprt,
+                                        newxprt->sc_max_requests,
+                                        0);
+       if (IS_ERR(newxprt->sc_rq_cq)) {
+               dprintk("svcrdma: error creating RQ CQ for connect request\n");
+               goto errout;
+       }
+
+       memset(&qp_attr, 0, sizeof qp_attr);
+       qp_attr.event_handler = qp_event_handler;
+       qp_attr.qp_context = &newxprt->sc_xprt;
+       qp_attr.cap.max_send_wr = newxprt->sc_sq_depth;
+       qp_attr.cap.max_recv_wr = newxprt->sc_max_requests;
+       qp_attr.cap.max_send_sge = newxprt->sc_max_sge;
+       qp_attr.cap.max_recv_sge = newxprt->sc_max_sge;
+       qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
+       qp_attr.qp_type = IB_QPT_RC;
+       qp_attr.send_cq = newxprt->sc_sq_cq;
+       qp_attr.recv_cq = newxprt->sc_rq_cq;
+       dprintk("svcrdma: newxprt->sc_cm_id=%p, newxprt->sc_pd=%p\n"
+               "    cm_id->device=%p, sc_pd->device=%p\n"
+               "    cap.max_send_wr = %d\n"
+               "    cap.max_recv_wr = %d\n"
+               "    cap.max_send_sge = %d\n"
+               "    cap.max_recv_sge = %d\n",
+               newxprt->sc_cm_id, newxprt->sc_pd,
+               newxprt->sc_cm_id->device, newxprt->sc_pd->device,
+               qp_attr.cap.max_send_wr,
+               qp_attr.cap.max_recv_wr,
+               qp_attr.cap.max_send_sge,
+               qp_attr.cap.max_recv_sge);
+
+       ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd, &qp_attr);
+       if (ret) {
+               /*
+                * XXX: This is a hack. We need a xx_request_qp interface
+                * that will adjust the qp_attr's with a best-effort
+                * number
+                */
+               qp_attr.cap.max_send_sge -= 2;
+               qp_attr.cap.max_recv_sge -= 2;
+               ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd,
+                                    &qp_attr);
+               if (ret) {
+                       dprintk("svcrdma: failed to create QP, ret=%d\n", ret);
+                       goto errout;
+               }
+               newxprt->sc_max_sge = qp_attr.cap.max_send_sge;
+               newxprt->sc_max_sge = qp_attr.cap.max_recv_sge;
+               newxprt->sc_sq_depth = qp_attr.cap.max_send_wr;
+               newxprt->sc_max_requests = qp_attr.cap.max_recv_wr;
+       }
+       newxprt->sc_qp = newxprt->sc_cm_id->qp;
+
+       /* Register all of physical memory */
+       newxprt->sc_phys_mr = ib_get_dma_mr(newxprt->sc_pd,
+                                           IB_ACCESS_LOCAL_WRITE |
+                                           IB_ACCESS_REMOTE_WRITE);
+       if (IS_ERR(newxprt->sc_phys_mr)) {
+               dprintk("svcrdma: Failed to create DMA MR ret=%d\n", ret);
+               goto errout;
+       }
+
+       /* Post receive buffers */
+       for (i = 0; i < newxprt->sc_max_requests; i++) {
+               ret = svc_rdma_post_recv(newxprt);
+               if (ret) {
+                       dprintk("svcrdma: failure posting receive buffers\n");
+                       goto errout;
+               }
+       }
+
+       /* Swap out the handler */
+       newxprt->sc_cm_id->event_handler = rdma_cma_handler;
+
+       /* Accept Connection */
+       set_bit(RDMAXPRT_CONN_PENDING, &newxprt->sc_flags);
+       memset(&conn_param, 0, sizeof conn_param);
+       conn_param.responder_resources = 0;
+       conn_param.initiator_depth = newxprt->sc_ord;
+       ret = rdma_accept(newxprt->sc_cm_id, &conn_param);
+       if (ret) {
+               dprintk("svcrdma: failed to accept new connection, ret=%d\n",
+                      ret);
+               goto errout;
+       }
+
+       dprintk("svcrdma: new connection %p accepted with the following "
+               "attributes:\n"
+               "    local_ip        : %d.%d.%d.%d\n"
+               "    local_port      : %d\n"
+               "    remote_ip       : %d.%d.%d.%d\n"
+               "    remote_port     : %d\n"
+               "    max_sge         : %d\n"
+               "    sq_depth        : %d\n"
+               "    max_requests    : %d\n"
+               "    ord             : %d\n",
+               newxprt,
+               NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id->
+                        route.addr.src_addr)->sin_addr.s_addr),
+               ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
+                      route.addr.src_addr)->sin_port),
+               NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id->
+                        route.addr.dst_addr)->sin_addr.s_addr),
+               ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
+                      route.addr.dst_addr)->sin_port),
+               newxprt->sc_max_sge,
+               newxprt->sc_sq_depth,
+               newxprt->sc_max_requests,
+               newxprt->sc_ord);
+
+       /* Set the local and remote addresses in the transport */
+       sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
+       svc_xprt_set_remote(&newxprt->sc_xprt, sa, svc_addr_len(sa));
+       sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
+       svc_xprt_set_local(&newxprt->sc_xprt, sa, svc_addr_len(sa));
+
+       ib_req_notify_cq(newxprt->sc_sq_cq, IB_CQ_NEXT_COMP);
+       ib_req_notify_cq(newxprt->sc_rq_cq, IB_CQ_NEXT_COMP);
+       return &newxprt->sc_xprt;
+
+ errout:
+       dprintk("svcrdma: failure accepting new connection rc=%d.\n", ret);
+       rdma_destroy_id(newxprt->sc_cm_id);
+       rdma_destroy_xprt(newxprt);
+       return NULL;
+}
+
+/*
+ * Post an RQ WQE to the RQ when the rqst is being released. This
+ * effectively returns an RQ credit to the client. The rq_xprt_ctxt
+ * will be null if the request is deferred due to an RDMA_READ or the
+ * transport had no data ready (EAGAIN). Note that an RPC deferred in
+ * svc_process will still return the credit, this is because the data
+ * is copied and no longer consume a WQE/WC.
+ */
+static void svc_rdma_release_rqst(struct svc_rqst *rqstp)
+{
+       int err;
+       struct svcxprt_rdma *rdma =
+               container_of(rqstp->rq_xprt, struct svcxprt_rdma, sc_xprt);
+       if (rqstp->rq_xprt_ctxt) {
+               BUG_ON(rqstp->rq_xprt_ctxt != rdma);
+               err = svc_rdma_post_recv(rdma);
+               if (err)
+                       dprintk("svcrdma: failed to post an RQ WQE error=%d\n",
+                               err);
+       }
+       rqstp->rq_xprt_ctxt = NULL;
+}
+
+/* Disable data ready events for this connection */
+static void svc_rdma_detach(struct svc_xprt *xprt)
+{
+       struct svcxprt_rdma *rdma =
+               container_of(xprt, struct svcxprt_rdma, sc_xprt);
+       unsigned long flags;
+
+       dprintk("svc: svc_rdma_detach(%p)\n", xprt);
+       /*
+        * Shutdown the connection. This will ensure we don't get any
+        * more events from the provider.
+        */
+       rdma_disconnect(rdma->sc_cm_id);
+       rdma_destroy_id(rdma->sc_cm_id);
+
+       /* We may already be on the DTO list */
+       spin_lock_irqsave(&dto_lock, flags);
+       if (!list_empty(&rdma->sc_dto_q))
+               list_del_init(&rdma->sc_dto_q);
+       spin_unlock_irqrestore(&dto_lock, flags);
+}
+
+static void svc_rdma_free(struct svc_xprt *xprt)
+{
+       struct svcxprt_rdma *rdma = (struct svcxprt_rdma *)xprt;
+       dprintk("svcrdma: svc_rdma_free(%p)\n", rdma);
+       rdma_destroy_xprt(rdma);
+       kfree(rdma);
+}
+
+static void rdma_destroy_xprt(struct svcxprt_rdma *xprt)
+{
+       if (xprt->sc_qp && !IS_ERR(xprt->sc_qp))
+               ib_destroy_qp(xprt->sc_qp);
+
+       if (xprt->sc_sq_cq && !IS_ERR(xprt->sc_sq_cq))
+               ib_destroy_cq(xprt->sc_sq_cq);
+
+       if (xprt->sc_rq_cq && !IS_ERR(xprt->sc_rq_cq))
+               ib_destroy_cq(xprt->sc_rq_cq);
+
+       if (xprt->sc_phys_mr && !IS_ERR(xprt->sc_phys_mr))
+               ib_dereg_mr(xprt->sc_phys_mr);
+
+       if (xprt->sc_pd && !IS_ERR(xprt->sc_pd))
+               ib_dealloc_pd(xprt->sc_pd);
+
+       destroy_context_cache(xprt->sc_ctxt_head);
+}
+
+static int svc_rdma_has_wspace(struct svc_xprt *xprt)
+{
+       struct svcxprt_rdma *rdma =
+               container_of(xprt, struct svcxprt_rdma, sc_xprt);
+
+       /*
+        * If there are fewer SQ WR available than required to send a
+        * simple response, return false.
+        */
+       if ((rdma->sc_sq_depth - atomic_read(&rdma->sc_sq_count) < 3))
+               return 0;
+
+       /*
+        * ...or there are already waiters on the SQ,
+        * return false.
+        */
+       if (waitqueue_active(&rdma->sc_send_wait))
+               return 0;
+
+       /* Otherwise return true. */
+       return 1;
+}
+
+int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
+{
+       struct ib_send_wr *bad_wr;
+       int ret;
+
+       if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
+               return 0;
+
+       BUG_ON(wr->send_flags != IB_SEND_SIGNALED);
+       BUG_ON(((struct svc_rdma_op_ctxt *)(unsigned long)wr->wr_id)->wr_op !=
+               wr->opcode);
+       /* If the SQ is full, wait until an SQ entry is available */
+       while (1) {
+               spin_lock_bh(&xprt->sc_lock);
+               if (xprt->sc_sq_depth == atomic_read(&xprt->sc_sq_count)) {
+                       spin_unlock_bh(&xprt->sc_lock);
+                       atomic_inc(&rdma_stat_sq_starve);
+                       /* See if we can reap some SQ WR */
+                       sq_cq_reap(xprt);
+
+                       /* Wait until SQ WR available if SQ still full */
+                       wait_event(xprt->sc_send_wait,
+                                  atomic_read(&xprt->sc_sq_count) <
+                                  xprt->sc_sq_depth);
+                       continue;
+               }
+               /* Bumped used SQ WR count and post */
+               ret = ib_post_send(xprt->sc_qp, wr, &bad_wr);
+               if (!ret)
+                       atomic_inc(&xprt->sc_sq_count);
+               else
+                       dprintk("svcrdma: failed to post SQ WR rc=%d, "
+                              "sc_sq_count=%d, sc_sq_depth=%d\n",
+                              ret, atomic_read(&xprt->sc_sq_count),
+                              xprt->sc_sq_depth);
+               spin_unlock_bh(&xprt->sc_lock);
+               break;
+       }
+       return ret;
+}
+
+int svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,
+                       enum rpcrdma_errcode err)
+{
+       struct ib_send_wr err_wr;
+       struct ib_sge sge;
+       struct page *p;
+       struct svc_rdma_op_ctxt *ctxt;
+       u32 *va;
+       int length;
+       int ret;
+
+       p = svc_rdma_get_page();
+       va = page_address(p);
+
+       /* XDR encode error */
+       length = svc_rdma_xdr_encode_error(xprt, rmsgp, err, va);
+
+       /* Prepare SGE for local address */
+       sge.addr = ib_dma_map_page(xprt->sc_cm_id->device,
+                                  p, 0, PAGE_SIZE, DMA_FROM_DEVICE);
+       sge.lkey = xprt->sc_phys_mr->lkey;
+       sge.length = length;
+
+       ctxt = svc_rdma_get_context(xprt);
+       ctxt->count = 1;
+       ctxt->pages[0] = p;
+
+       /* Prepare SEND WR */
+       memset(&err_wr, 0, sizeof err_wr);
+       ctxt->wr_op = IB_WR_SEND;
+       err_wr.wr_id = (unsigned long)ctxt;
+       err_wr.sg_list = &sge;
+       err_wr.num_sge = 1;
+       err_wr.opcode = IB_WR_SEND;
+       err_wr.send_flags = IB_SEND_SIGNALED;
+
+       /* Post It */
+       ret = svc_rdma_send(xprt, &err_wr);
+       if (ret) {
+               dprintk("svcrdma: Error posting send = %d\n", ret);
+               svc_rdma_put_context(ctxt, 1);
+       }
+
+       return ret;
+}
index d716b76098bb670d76abff1eeff9830ff88ebfbc..340ad6920511aa08a52f5360c54836c682e2deed 100755 (executable)
@@ -2,7 +2,7 @@
 
 #      Check the stack usage of functions
 #
-#      Copyright Joern Engel <joern@wh.fh-wedel.de>
+#      Copyright Joern Engel <joern@lazybastard.org>
 #      Inspired by Linus Torvalds
 #      Original idea maybe from Keith Owens
 #      s390 port and big speedup by Arnd Bergmann <arnd@bergmann-dalldorf.de>
index 1f11d848532a0474b342ca462a905af4f044b2f6..c912137f80e247d0b8076e32f7386005127889a0 100644 (file)
 
 #define KSYM_NAME_LEN          128
 
-
 struct sym_entry {
        unsigned long long addr;
        unsigned int len;
+       unsigned int start_pos;
        unsigned char *sym;
 };
 
-
 static struct sym_entry *table;
 static unsigned int table_size, table_cnt;
-static unsigned long long _text, _stext, _etext, _sinittext, _einittext, _sextratext, _eextratext;
+static unsigned long long _text, _stext, _etext, _sinittext, _einittext;
 static int all_symbols = 0;
 static char symbol_prefix_char = '\0';
 
@@ -99,10 +98,6 @@ static int read_symbol(FILE *in, struct sym_entry *s)
                _sinittext = s->addr;
        else if (strcmp(sym, "_einittext") == 0)
                _einittext = s->addr;
-       else if (strcmp(sym, "_sextratext") == 0)
-               _sextratext = s->addr;
-       else if (strcmp(sym, "_eextratext") == 0)
-               _eextratext = s->addr;
        else if (toupper(stype) == 'A')
        {
                /* Keep these useful absolute symbols */
@@ -165,18 +160,18 @@ static int symbol_valid(struct sym_entry *s)
         * and inittext sections are discarded */
        if (!all_symbols) {
                if ((s->addr < _stext || s->addr > _etext)
-                   && (s->addr < _sinittext || s->addr > _einittext)
-                   && (s->addr < _sextratext || s->addr > _eextratext))
+                   && (s->addr < _sinittext || s->addr > _einittext))
                        return 0;
                /* Corner case.  Discard any symbols with the same value as
-                * _etext _einittext or _eextratext; they can move between pass
-                * 1 and 2 when the kallsyms data are added.  If these symbols
-                * move then they may get dropped in pass 2, which breaks the
-                * kallsyms rules.
+                * _etext _einittext; they can move between pass 1 and 2 when
+                * the kallsyms data are added.  If these symbols move then
+                * they may get dropped in pass 2, which breaks the kallsyms
+                * rules.
                 */
-               if ((s->addr == _etext && strcmp((char*)s->sym + offset, "_etext")) ||
-                   (s->addr == _einittext && strcmp((char*)s->sym + offset, "_einittext")) ||
-                   (s->addr == _eextratext && strcmp((char*)s->sym + offset, "_eextratext")))
+               if ((s->addr == _etext &&
+                               strcmp((char *)s->sym + offset, "_etext")) ||
+                   (s->addr == _einittext &&
+                               strcmp((char *)s->sym + offset, "_einittext")))
                        return 0;
        }
 
@@ -202,8 +197,10 @@ static void read_map(FILE *in)
                                exit (1);
                        }
                }
-               if (read_symbol(in, &table[table_cnt]) == 0)
+               if (read_symbol(in, &table[table_cnt]) == 0) {
+                       table[table_cnt].start_pos = table_cnt;
                        table_cnt++;
+               }
        }
 }
 
@@ -506,6 +503,35 @@ static void optimize_token_table(void)
        optimize_result();
 }
 
+static int compare_symbols(const void *a, const void *b)
+{
+       const struct sym_entry *sa;
+       const struct sym_entry *sb;
+       int wa, wb;
+
+       sa = a;
+       sb = b;
+
+       /* sort by address first */
+       if (sa->addr > sb->addr)
+               return 1;
+       if (sa->addr < sb->addr)
+               return -1;
+
+       /* sort by "weakness" type */
+       wa = (sa->sym[0] == 'w') || (sa->sym[0] == 'W');
+       wb = (sb->sym[0] == 'w') || (sb->sym[0] == 'W');
+       if (wa != wb)
+               return wa - wb;
+
+       /* sort by initial order, so that other symbols are left undisturbed */
+       return sa->start_pos - sb->start_pos;
+}
+
+static void sort_symbols(void)
+{
+       qsort(table, table_cnt, sizeof(struct sym_entry), compare_symbols);
+}
 
 int main(int argc, char **argv)
 {
@@ -527,6 +553,7 @@ int main(int argc, char **argv)
                usage();
 
        read_map(stdin);
+       sort_symbols();
        optimize_token_table();
        write_src();
 
index 50e61c411bc0f89d8f9c5ec9d7c7ea6992a43371..734cf4f3131e69b36c26ee23ee36dfe0a59496ff 100644 (file)
@@ -821,6 +821,7 @@ static void conf_load(void)
                                return;
                        if (!conf_read(dialog_input_result)) {
                                set_config_filename(dialog_input_result);
+                               sym_set_change_count(1);
                                return;
                        }
                        show_textbox(NULL, _("File does not exist!"), 5, 38);
index fdad17367f612428d61ab78e8ebb0df864672454..606ceb9e746ec3b9649fd534c50f16e95f73f69f 100644 (file)
@@ -203,12 +203,9 @@ void sym_check_prop(struct symbol *sym)
                                prop_warn(prop,
                                    "config symbol '%s' uses select, but is "
                                    "not boolean or tristate", sym->name);
-                       else if (sym2->type == S_UNKNOWN)
-                               prop_warn(prop,
-                                   "'select' used by config symbol '%s' "
-                                   "refers to undefined symbol '%s'",
-                                   sym->name, sym2->name);
-                       else if (sym2->type != S_BOOLEAN && sym2->type != S_TRISTATE)
+                       else if (sym2->type != S_UNKNOWN &&
+                                sym2->type != S_BOOLEAN &&
+                                sym2->type != S_TRISTATE)
                                prop_warn(prop,
                                    "'%s' has wrong type. 'select' only "
                                    "accept arguments of boolean and "
index d802b5afae89254f3b3131f7552e9eb60f7e07a7..9ddf944cce290b7d38fc2982b852bc93d4c50001 100644 (file)
@@ -155,7 +155,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
         * Some modules (visor) have empty slots as placeholder for
         * run-time specification that results in catch-all alias
         */
-       if (!(id->idVendor | id->bDeviceClass | id->bInterfaceClass))
+       if (!(id->idVendor | id->idProduct | id->bDeviceClass | id->bInterfaceClass))
                return;
 
        /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
index f8efc93eb7004c9ee0004c979acd617ca7d2e8f8..5d546466e6b1f8d2e700fa0ef846ebe6a14569cd 100644 (file)
@@ -870,7 +870,7 @@ const struct sectioncheck sectioncheck[] = {
 /* Do not export init/exit functions or data */
 {
        .fromsec = { "__ksymtab*", NULL },
-       .tosec   = { ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL },
+       .tosec   = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
        .mismatch = EXPORT_TO_INIT_EXIT
 }
 };
@@ -1125,15 +1125,15 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
        to = to_is_func ? "function" : "variable";
        to_p = to_is_func ? "()" : "";
 
+       sec_mismatch_count++;
+       if (!sec_mismatch_verbose)
+               return;
+
        fprintf(stderr, "WARNING: %s(%s+0x%llx): Section mismatch in"
                        " reference from the %s %s%s to the %s %s:%s%s\n",
                         modname, fromsec, fromaddr, from, fromsym, from_p,
                        to, tosec, tosym, to_p);
 
-       sec_mismatch_count++;
-       if (!sec_mismatch_verbose)
-               return;
-
        switch (mismatch) {
        case TEXT_TO_INIT:
                fprintf(stderr,
@@ -1939,10 +1939,9 @@ int main(int argc, char **argv)
                write_dump(dump_write);
        if (sec_mismatch_count && !sec_mismatch_verbose)
                fprintf(stderr, "modpost: Found %d section mismatch(es).\n"
-                       "To see additional details select \"Enable full "
-                       "Section mismatch analysis\"\n"
-                       "in the Kernel Hacking menu "
-                       "(CONFIG_SECTION_MISMATCH).\n", sec_mismatch_count);
+                       "To see full details build your kernel with:\n"
+                       "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n",
+                       sec_mismatch_count);
 
        return err;
 }
old mode 100644 (file)
new mode 100755 (executable)
index 52f032e..1c1bdaf
@@ -45,3 +45,19 @@ if hgid=`hg id 2>/dev/null`; then
        # All done with mercurial
        exit
 fi
+
+# Check for svn and a svn repo.
+if rev=`svn info 2>/dev/null | grep '^Revision'`; then
+       rev=`echo $rev | awk '{print $NF}'`
+       changes=`svn status 2>/dev/null | grep '^[AMD]' | wc -l`
+
+       # Are there uncommitted changes?
+       if [ $changes != 0 ]; then
+               printf -- '-svn%s%s%s' "$rev" -dirty "$changes"
+       else
+               printf -- '-svn%s' "$rev"
+       fi
+
+       # All done with svn
+       exit
+fi
index 389e151e3b68e832d7b63b9623e10098d6d2e03b..5dfc206748cfbd76f2e1f3114515aba7294cf67c 100644 (file)
@@ -104,7 +104,26 @@ config SECURITY_ROOTPLUG
          
          If you are unsure how to answer this question, answer N.
 
+config SECURITY_DEFAULT_MMAP_MIN_ADDR
+        int "Low address space to protect from user allocation"
+        depends on SECURITY
+        default 0
+        help
+         This is the portion of low virtual memory which should be protected
+         from userspace allocation.  Keeping a user from writing to low pages
+         can help reduce the impact of kernel NULL pointer bugs.
+
+         For most users with lots of address space a value of 65536 is
+         reasonable and should cause no problems.  Programs which use vm86
+         functionality would either need additional permissions from either
+         the LSM or the capabilities module or have this protection disabled.
+
+         This value can be changed after boot using the
+         /proc/sys/vm/mmap_min_addr tunable.
+
+
 source security/selinux/Kconfig
+source security/smack/Kconfig
 
 endmenu
 
index ef87df2f50a454ac0f9c5aedeb235b347a2706b4..9e8b025250144ce739e80583a095b3059d89110c 100644 (file)
@@ -4,6 +4,7 @@
 
 obj-$(CONFIG_KEYS)                     += keys/
 subdir-$(CONFIG_SECURITY_SELINUX)      += selinux
+subdir-$(CONFIG_SECURITY_SMACK)                += smack
 
 # if we don't select a security model, use the default capabilities
 ifneq ($(CONFIG_SECURITY),y)
@@ -14,5 +15,6 @@ endif
 obj-$(CONFIG_SECURITY)                 += security.o dummy.o inode.o
 # Must precede capability.o in order to stack properly.
 obj-$(CONFIG_SECURITY_SELINUX)         += selinux/built-in.o
+obj-$(CONFIG_SECURITY_SMACK)           += commoncap.o smack/built-in.o
 obj-$(CONFIG_SECURITY_CAPABILITIES)    += commoncap.o capability.o
 obj-$(CONFIG_SECURITY_ROOTPLUG)                += commoncap.o root_plug.o
index ea61bc73f6d3c4d1ecfe9d81964342b8cd306d74..5aba82679a0bb9e5506628c9190846a1134707e7 100644 (file)
@@ -1,4 +1,4 @@
-/* Common capabilities, needed by capability.o and root_plug.o 
+/* Common capabilities, needed by capability.o and root_plug.o
  *
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
 #include <linux/mount.h>
 #include <linux/sched.h>
 
-#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
-/*
- * Because of the reduced scope of CAP_SETPCAP when filesystem
- * capabilities are in effect, it is safe to allow this capability to
- * be available in the default configuration.
- */
-# define CAP_INIT_BSET  CAP_FULL_SET
-#else /* ie. ndef CONFIG_SECURITY_FILE_CAPABILITIES */
-# define CAP_INIT_BSET  CAP_INIT_EFF_SET
-#endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
-
-kernel_cap_t cap_bset = CAP_INIT_BSET;    /* systemwide capability bound */
-EXPORT_SYMBOL(cap_bset);
-
 /* Global security state */
 
 unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
@@ -93,9 +79,9 @@ int cap_capget (struct task_struct *target, kernel_cap_t *effective,
                kernel_cap_t *inheritable, kernel_cap_t *permitted)
 {
        /* Derived from kernel/capability.c:sys_capget. */
-       *effective = cap_t (target->cap_effective);
-       *inheritable = cap_t (target->cap_inheritable);
-       *permitted = cap_t (target->cap_permitted);
+       *effective = target->cap_effective;
+       *inheritable = target->cap_inheritable;
+       *permitted = target->cap_permitted;
        return 0;
 }
 
@@ -140,6 +126,12 @@ int cap_capset_check (struct task_struct *target, kernel_cap_t *effective,
                /* incapable of using this inheritable set */
                return -EPERM;
        }
+       if (!cap_issubset(*inheritable,
+                          cap_combine(target->cap_inheritable,
+                                      current->cap_bset))) {
+               /* no new pI capabilities outside bounding set */
+               return -EPERM;
+       }
 
        /* verify restrictions on target's new Permitted set */
        if (!cap_issubset (*permitted,
@@ -198,28 +190,50 @@ int cap_inode_killpriv(struct dentry *dentry)
 }
 
 static inline int cap_from_disk(struct vfs_cap_data *caps,
-                               struct linux_binprm *bprm,
-                               int size)
+                               struct linux_binprm *bprm, unsigned size)
 {
        __u32 magic_etc;
+       unsigned tocopy, i;
 
-       if (size != XATTR_CAPS_SZ)
+       if (size < sizeof(magic_etc))
                return -EINVAL;
 
        magic_etc = le32_to_cpu(caps->magic_etc);
 
        switch ((magic_etc & VFS_CAP_REVISION_MASK)) {
-       case VFS_CAP_REVISION:
-               if (magic_etc & VFS_CAP_FLAGS_EFFECTIVE)
-                       bprm->cap_effective = true;
-               else
-                       bprm->cap_effective = false;
-               bprm->cap_permitted = to_cap_t(le32_to_cpu(caps->permitted));
-               bprm->cap_inheritable = to_cap_t(le32_to_cpu(caps->inheritable));
-               return 0;
+       case VFS_CAP_REVISION_1:
+               if (size != XATTR_CAPS_SZ_1)
+                       return -EINVAL;
+               tocopy = VFS_CAP_U32_1;
+               break;
+       case VFS_CAP_REVISION_2:
+               if (size != XATTR_CAPS_SZ_2)
+                       return -EINVAL;
+               tocopy = VFS_CAP_U32_2;
+               break;
        default:
                return -EINVAL;
        }
+
+       if (magic_etc & VFS_CAP_FLAGS_EFFECTIVE) {
+               bprm->cap_effective = true;
+       } else {
+               bprm->cap_effective = false;
+       }
+
+       for (i = 0; i < tocopy; ++i) {
+               bprm->cap_permitted.cap[i] =
+                       le32_to_cpu(caps->data[i].permitted);
+               bprm->cap_inheritable.cap[i] =
+                       le32_to_cpu(caps->data[i].inheritable);
+       }
+       while (i < VFS_CAP_U32) {
+               bprm->cap_permitted.cap[i] = 0;
+               bprm->cap_inheritable.cap[i] = 0;
+               i++;
+       }
+
+       return 0;
 }
 
 /* Locate any VFS capabilities: */
@@ -227,7 +241,7 @@ static int get_file_caps(struct linux_binprm *bprm)
 {
        struct dentry *dentry;
        int rc = 0;
-       struct vfs_cap_data incaps;
+       struct vfs_cap_data vcaps;
        struct inode *inode;
 
        if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) {
@@ -240,14 +254,8 @@ static int get_file_caps(struct linux_binprm *bprm)
        if (!inode->i_op || !inode->i_op->getxattr)
                goto out;
 
-       rc = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, NULL, 0);
-       if (rc > 0) {
-               if (rc == XATTR_CAPS_SZ)
-                       rc = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS,
-                                               &incaps, XATTR_CAPS_SZ);
-               else
-                       rc = -EINVAL;
-       }
+       rc = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, &vcaps,
+                                  XATTR_CAPS_SZ);
        if (rc == -ENODATA || rc == -EOPNOTSUPP) {
                /* no data, that's ok */
                rc = 0;
@@ -256,7 +264,7 @@ static int get_file_caps(struct linux_binprm *bprm)
        if (rc < 0)
                goto out;
 
-       rc = cap_from_disk(&incaps, bprm, rc);
+       rc = cap_from_disk(&vcaps, bprm, rc);
        if (rc)
                printk(KERN_NOTICE "%s: cap_from_disk returned %d for %s\n",
                        __FUNCTION__, rc, bprm->filename);
@@ -321,10 +329,11 @@ void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
        /* Derived from fs/exec.c:compute_creds. */
        kernel_cap_t new_permitted, working;
 
-       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
-       working = cap_intersect (bprm->cap_inheritable,
+       new_permitted = cap_intersect(bprm->cap_permitted,
+                                current->cap_bset);
+       working = cap_intersect(bprm->cap_inheritable,
                                 current->cap_inheritable);
-       new_permitted = cap_combine (new_permitted, working);
+       new_permitted = cap_combine(new_permitted, working);
 
        if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
            !cap_issubset (new_permitted, current->cap_permitted)) {
@@ -351,8 +360,10 @@ void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
         * capability rules */
        if (!is_global_init(current)) {
                current->cap_permitted = new_permitted;
-               current->cap_effective = bprm->cap_effective ?
-                               new_permitted : 0;
+               if (bprm->cap_effective)
+                       current->cap_effective = new_permitted;
+               else
+                       cap_clear(current->cap_effective);
        }
 
        /* AUD: Audit candidate if current->cap_effective is set */
@@ -474,13 +485,15 @@ int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid,
 
                        if (!issecure (SECURE_NO_SETUID_FIXUP)) {
                                if (old_fsuid == 0 && current->fsuid != 0) {
-                                       cap_t (current->cap_effective) &=
-                                           ~CAP_FS_MASK;
+                                       current->cap_effective =
+                                               cap_drop_fs_set(
+                                                   current->cap_effective);
                                }
                                if (old_fsuid != 0 && current->fsuid == 0) {
-                                       cap_t (current->cap_effective) |=
-                                           (cap_t (current->cap_permitted) &
-                                            CAP_FS_MASK);
+                                       current->cap_effective =
+                                               cap_raise_fs_set(
+                                                   current->cap_effective,
+                                                   current->cap_permitted);
                                }
                        }
                        break;
@@ -561,6 +574,23 @@ int cap_task_kill(struct task_struct *p, struct siginfo *info,
 
        return -EPERM;
 }
+
+/*
+ * called from kernel/sys.c for prctl(PR_CABSET_DROP)
+ * done without task_capability_lock() because it introduces
+ * no new races - i.e. only another task doing capget() on
+ * this task could get inconsistent info.  There can be no
+ * racing writer bc a task can only change its own caps.
+ */
+long cap_prctl_drop(unsigned long cap)
+{
+       if (!capable(CAP_SETPCAP))
+               return -EPERM;
+       if (!cap_valid(cap))
+               return -EINVAL;
+       cap_lower(current->cap_bset, cap);
+       return 0;
+}
 #else
 int cap_task_setscheduler (struct task_struct *p, int policy,
                           struct sched_param *lp)
@@ -584,9 +614,9 @@ int cap_task_kill(struct task_struct *p, struct siginfo *info,
 
 void cap_task_reparent_to_init (struct task_struct *p)
 {
-       p->cap_effective = CAP_INIT_EFF_SET;
-       p->cap_inheritable = CAP_INIT_INH_SET;
-       p->cap_permitted = CAP_FULL_SET;
+       cap_set_init_eff(p->cap_effective);
+       cap_clear(p->cap_inheritable);
+       cap_set_full(p->cap_permitted);
        p->keep_capabilities = 0;
        return;
 }
index 48d4b0a52737b2e28a8fb2e32d589af2db2463f9..649326bf64ea37e82afe63901560f96c687a468b 100644 (file)
@@ -36,14 +36,19 @@ static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
 static int dummy_capget (struct task_struct *target, kernel_cap_t * effective,
                         kernel_cap_t * inheritable, kernel_cap_t * permitted)
 {
-       *effective = *inheritable = *permitted = 0;
        if (target->euid == 0) {
-               *permitted |= (~0 & ~CAP_FS_MASK);
-               *effective |= (~0 & ~CAP_TO_MASK(CAP_SETPCAP) & ~CAP_FS_MASK);
+               cap_set_full(*permitted);
+               cap_set_init_eff(*effective);
+       } else {
+               cap_clear(*permitted);
+               cap_clear(*effective);
        }
-       if (target->fsuid == 0) {
-               *permitted |= CAP_FS_MASK;
-               *effective |= CAP_FS_MASK;
+
+       cap_clear(*inheritable);
+
+       if (target->fsuid != 0) {
+               *permitted = cap_drop_fs_set(*permitted);
+               *effective = cap_drop_fs_set(*effective);
        }
        return 0;
 }
@@ -402,7 +407,7 @@ static int dummy_inode_killpriv(struct dentry *dentry)
        return 0;
 }
 
-static int dummy_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err)
+static int dummy_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
 {
        return -EOPNOTSUPP;
 }
index ca475ca206e4b3afe51ad7bdee1c30fe8398c892..d15e56cbaadeea25c550cfc985de2dbbfbf410fa 100644 (file)
@@ -23,7 +23,9 @@ extern struct security_operations dummy_security_ops;
 extern void security_fixup_ops(struct security_operations *ops);
 
 struct security_operations *security_ops;      /* Initialized to NULL */
-unsigned long mmap_min_addr;           /* 0 means no protection */
+
+/* amount of vm to protect from userspace access */
+unsigned long mmap_min_addr = CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR;
 
 static inline int verify(struct security_operations *ops)
 {
@@ -493,11 +495,11 @@ int security_inode_killpriv(struct dentry *dentry)
        return security_ops->inode_killpriv(dentry);
 }
 
-int security_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err)
+int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
 {
        if (unlikely(IS_PRIVATE(inode)))
                return 0;
-       return security_ops->inode_getsecurity(inode, name, buffer, size, err);
+       return security_ops->inode_getsecurity(inode, name, buffer, alloc);
 }
 
 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
index be6de0b8734fd9eb950d8f8ca9e2306621764420..e5ed07510309edb0da10a151095cd3529bf41442 100644 (file)
@@ -136,32 +136,6 @@ static DEFINE_SPINLOCK(sb_security_lock);
 
 static struct kmem_cache *sel_inode_cache;
 
-/* Return security context for a given sid or just the context 
-   length if the buffer is null or length is 0 */
-static int selinux_getsecurity(u32 sid, void *buffer, size_t size)
-{
-       char *context;
-       unsigned len;
-       int rc;
-
-       rc = security_sid_to_context(sid, &context, &len);
-       if (rc)
-               return rc;
-
-       if (!buffer || !size)
-               goto getsecurity_exit;
-
-       if (size < len) {
-               len = -ERANGE;
-               goto getsecurity_exit;
-       }
-       memcpy(buffer, context, len);
-
-getsecurity_exit:
-       kfree(context);
-       return len;
-}
-
 /**
  * selinux_secmark_enabled - Check to see if SECMARK is currently enabled
  *
@@ -2675,14 +2649,27 @@ static int selinux_inode_removexattr (struct dentry *dentry, char *name)
  *
  * Permission check is handled by selinux_inode_getxattr hook.
  */
-static int selinux_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err)
+static int selinux_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
 {
+       u32 size;
+       int error;
+       char *context = NULL;
        struct inode_security_struct *isec = inode->i_security;
 
        if (strcmp(name, XATTR_SELINUX_SUFFIX))
                return -EOPNOTSUPP;
 
-       return selinux_getsecurity(isec->sid, buffer, size);
+       error = security_sid_to_context(isec->sid, &context, &size);
+       if (error)
+               return error;
+       error = size;
+       if (alloc) {
+               *buffer = context;
+               goto out_nofree;
+       }
+       kfree(context);
+out_nofree:
+       return error;
 }
 
 static int selinux_inode_setsecurity(struct inode *inode, const char *name,
index 23137c17f917a0727dd79a99bcad900c308c387a..837ce420d2f64ff810c4e96b7b7ce9a1ca695328 100644 (file)
@@ -107,7 +107,6 @@ int security_get_classes(char ***classes, int *nclasses);
 int security_get_permissions(char *class, char ***perms, int *nperms);
 int security_get_reject_unknown(void);
 int security_get_allow_unknown(void);
-int security_get_policycaps(int *len, int **values);
 
 #define SECURITY_FS_USE_XATTR          1 /* use xattr */
 #define SECURITY_FS_USE_TRANS          2 /* use transition SIDs, e.g. devpts/tmpfs */
index fced6bccee760b87d98df5b0a26133b6ae0b655c..f374186012151e42ba197ac80391a147fb3821f7 100644 (file)
@@ -2245,39 +2245,6 @@ int security_get_allow_unknown(void)
        return policydb.allow_unknown;
 }
 
-/**
- * security_get_policycaps - Query the loaded policy for its capabilities
- * @len: the number of capability bits
- * @values: the capability bit array
- *
- * Description:
- * Get an array of the policy capabilities in @values where each entry in
- * @values is either true (1) or false (0) depending the policy's support of
- * that feature.  The policy capabilities are defined by the
- * POLICYDB_CAPABILITY_* enums.  The size of the array is stored in @len and it
- * is up to the caller to free the array in @values.  Returns zero on success,
- * negative values on failure.
- *
- */
-int security_get_policycaps(int *len, int **values)
-{
-       int rc = -ENOMEM;
-       unsigned int iter;
-
-       POLICY_RDLOCK;
-
-       *values = kcalloc(POLICYDB_CAPABILITY_MAX, sizeof(int), GFP_ATOMIC);
-       if (*values == NULL)
-               goto out;
-       for (iter = 0; iter < POLICYDB_CAPABILITY_MAX; iter++)
-               (*values)[iter] = ebitmap_get_bit(&policydb.policycaps, iter);
-       *len = POLICYDB_CAPABILITY_MAX;
-
-out:
-       POLICY_RDUNLOCK;
-       return rc;
-}
-
 /**
  * security_policycap_supported - Check for a specific policy capability
  * @req_cap: capability
diff --git a/security/smack/Kconfig b/security/smack/Kconfig
new file mode 100644 (file)
index 0000000..603b087
--- /dev/null
@@ -0,0 +1,10 @@
+config SECURITY_SMACK
+       bool "Simplified Mandatory Access Control Kernel Support"
+       depends on NETLABEL && SECURITY_NETWORK
+       default n
+       help
+         This selects the Simplified Mandatory Access Control Kernel.
+         Smack is useful for sensitivity, integrity, and a variety
+         of other mandatory security schemes.
+         If you are unsure how to answer this question, answer N.
+
diff --git a/security/smack/Makefile b/security/smack/Makefile
new file mode 100644 (file)
index 0000000..67a63aa
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# Makefile for the SMACK LSM
+#
+
+obj-$(CONFIG_SECURITY_SMACK) := smack.o
+
+smack-y := smack_lsm.o smack_access.o smackfs.o
diff --git a/security/smack/smack.h b/security/smack/smack.h
new file mode 100644 (file)
index 0000000..a21a0e9
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, version 2.
+ *
+ * Author:
+ *      Casey Schaufler <casey@schaufler-ca.com>
+ *
+ */
+
+#ifndef _SECURITY_SMACK_H
+#define _SECURITY_SMACK_H
+
+#include <linux/capability.h>
+#include <linux/spinlock.h>
+#include <net/netlabel.h>
+
+/*
+ * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
+ * bigger than can be used, and 24 is the next lower multiple
+ * of 8, and there are too many issues if there isn't space set
+ * aside for the terminating null byte.
+ */
+#define SMK_MAXLEN     23
+#define SMK_LABELLEN   (SMK_MAXLEN+1)
+
+/*
+ * How many kinds of access are there?
+ * Here's your answer.
+ */
+#define SMK_ACCESSDASH '-'
+#define SMK_ACCESSLOW  "rwxa"
+#define SMK_ACCESSKINDS        (sizeof(SMK_ACCESSLOW) - 1)
+
+struct superblock_smack {
+       char            *smk_root;
+       char            *smk_floor;
+       char            *smk_hat;
+       char            *smk_default;
+       int             smk_initialized;
+       spinlock_t      smk_sblock;     /* for initialization */
+};
+
+struct socket_smack {
+       char            *smk_out;                       /* outbound label */
+       char            *smk_in;                        /* inbound label */
+       char            smk_packet[SMK_LABELLEN];       /* TCP peer label */
+};
+
+/*
+ * Inode smack data
+ */
+struct inode_smack {
+       char            *smk_inode;     /* label of the fso */
+       struct mutex    smk_lock;       /* initialization lock */
+       int             smk_flags;      /* smack inode flags */
+};
+
+#define        SMK_INODE_INSTANT       0x01    /* inode is instantiated */
+
+/*
+ * A label access rule.
+ */
+struct smack_rule {
+       char    *smk_subject;
+       char    *smk_object;
+       int     smk_access;
+};
+
+/*
+ * An entry in the table of permitted label accesses.
+ */
+struct smk_list_entry {
+       struct smk_list_entry   *smk_next;
+       struct smack_rule       smk_rule;
+};
+
+/*
+ * An entry in the table mapping smack values to
+ * CIPSO level/category-set values.
+ */
+struct smack_cipso {
+       int     smk_level;
+       char    smk_catset[SMK_LABELLEN];
+};
+
+/*
+ * This is the repository for labels seen so that it is
+ * not necessary to keep allocating tiny chuncks of memory
+ * and so that they can be shared.
+ *
+ * Labels are never modified in place. Anytime a label
+ * is imported (e.g. xattrset on a file) the list is checked
+ * for it and it is added if it doesn't exist. The address
+ * is passed out in either case. Entries are added, but
+ * never deleted.
+ *
+ * Since labels are hanging around anyway it doesn't
+ * hurt to maintain a secid for those awkward situations
+ * where kernel components that ought to use LSM independent
+ * interfaces don't. The secid should go away when all of
+ * these components have been repaired.
+ *
+ * If there is a cipso value associated with the label it
+ * gets stored here, too. This will most likely be rare as
+ * the cipso direct mapping in used internally.
+ */
+struct smack_known {
+       struct smack_known      *smk_next;
+       char                    smk_known[SMK_LABELLEN];
+       u32                     smk_secid;
+       struct smack_cipso      *smk_cipso;
+       spinlock_t              smk_cipsolock; /* for changing cipso map */
+};
+
+/*
+ * Mount options
+ */
+#define SMK_FSDEFAULT  "smackfsdef="
+#define SMK_FSFLOOR    "smackfsfloor="
+#define SMK_FSHAT      "smackfshat="
+#define SMK_FSROOT     "smackfsroot="
+
+/*
+ * xattr names
+ */
+#define XATTR_SMACK_SUFFIX     "SMACK64"
+#define XATTR_SMACK_IPIN       "SMACK64IPIN"
+#define XATTR_SMACK_IPOUT      "SMACK64IPOUT"
+#define XATTR_NAME_SMACK       XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
+#define XATTR_NAME_SMACKIPIN   XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
+#define XATTR_NAME_SMACKIPOUT  XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
+
+/*
+ * smackfs macic number
+ */
+#define SMACK_MAGIC    0x43415d53 /* "SMAC" */
+
+/*
+ * A limit on the number of entries in the lists
+ * makes some of the list administration easier.
+ */
+#define SMACK_LIST_MAX 10000
+
+/*
+ * CIPSO defaults.
+ */
+#define SMACK_CIPSO_DOI_DEFAULT                3       /* Historical */
+#define SMACK_CIPSO_DIRECT_DEFAULT     250     /* Arbitrary */
+#define SMACK_CIPSO_MAXCATVAL          63      /* Bigger gets harder */
+#define SMACK_CIPSO_MAXLEVEL            255     /* CIPSO 2.2 standard */
+#define SMACK_CIPSO_MAXCATNUM           239     /* CIPSO 2.2 standard */
+
+/*
+ * Just to make the common cases easier to deal with
+ */
+#define MAY_ANY                (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
+#define MAY_ANYREAD    (MAY_READ | MAY_EXEC)
+#define MAY_ANYWRITE   (MAY_WRITE | MAY_APPEND)
+#define MAY_READWRITE  (MAY_READ | MAY_WRITE)
+#define MAY_NOT                0
+
+/*
+ * These functions are in smack_lsm.c
+ */
+struct inode_smack *new_inode_smack(char *);
+
+/*
+ * These functions are in smack_access.c
+ */
+int smk_access(char *, char *, int);
+int smk_curacc(char *, u32);
+int smack_to_cipso(const char *, struct smack_cipso *);
+void smack_from_cipso(u32, char *, char *);
+char *smack_from_secid(const u32);
+char *smk_import(const char *, int);
+struct smack_known *smk_import_entry(const char *, int);
+u32 smack_to_secid(const char *);
+
+/*
+ * Shared data.
+ */
+extern int smack_cipso_direct;
+extern int smack_net_nltype;
+extern char *smack_net_ambient;
+
+extern struct smack_known *smack_known;
+extern struct smack_known smack_known_floor;
+extern struct smack_known smack_known_hat;
+extern struct smack_known smack_known_huh;
+extern struct smack_known smack_known_invalid;
+extern struct smack_known smack_known_star;
+extern struct smack_known smack_known_unset;
+
+extern struct smk_list_entry *smack_list;
+
+/*
+ * Stricly for CIPSO level manipulation.
+ * Set the category bit number in a smack label sized buffer.
+ */
+static inline void smack_catset_bit(int cat, char *catsetp)
+{
+       if (cat > SMK_LABELLEN * 8)
+               return;
+
+       catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
+}
+
+/*
+ * Present a pointer to the smack label in an inode blob.
+ */
+static inline char *smk_of_inode(const struct inode *isp)
+{
+       struct inode_smack *sip = isp->i_security;
+       return sip->smk_inode;
+}
+
+#endif  /* _SECURITY_SMACK_H */
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
new file mode 100644 (file)
index 0000000..f6b5f6e
--- /dev/null
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, version 2.
+ *
+ * Author:
+ *      Casey Schaufler <casey@schaufler-ca.com>
+ *
+ */
+
+#include <linux/types.h>
+#include <linux/fs.h>
+#include <linux/sched.h>
+#include "smack.h"
+
+struct smack_known smack_known_unset = {
+       .smk_next       = NULL,
+       .smk_known      = "UNSET",
+       .smk_secid      = 1,
+       .smk_cipso      = NULL,
+};
+
+struct smack_known smack_known_huh = {
+       .smk_next       = &smack_known_unset,
+       .smk_known      = "?",
+       .smk_secid      = 2,
+       .smk_cipso      = NULL,
+};
+
+struct smack_known smack_known_hat = {
+       .smk_next       = &smack_known_huh,
+       .smk_known      = "^",
+       .smk_secid      = 3,
+       .smk_cipso      = NULL,
+};
+
+struct smack_known smack_known_star = {
+       .smk_next       = &smack_known_hat,
+       .smk_known      = "*",
+       .smk_secid      = 4,
+       .smk_cipso      = NULL,
+};
+
+struct smack_known smack_known_floor = {
+       .smk_next       = &smack_known_star,
+       .smk_known      = "_",
+       .smk_secid      = 5,
+       .smk_cipso      = NULL,
+};
+
+struct smack_known smack_known_invalid = {
+       .smk_next       = &smack_known_floor,
+       .smk_known      = "",
+       .smk_secid      = 6,
+       .smk_cipso      = NULL,
+};
+
+struct smack_known *smack_known = &smack_known_invalid;
+
+/*
+ * The initial value needs to be bigger than any of the
+ * known values above.
+ */
+static u32 smack_next_secid = 10;
+
+/**
+ * smk_access - determine if a subject has a specific access to an object
+ * @subject_label: a pointer to the subject's Smack label
+ * @object_label: a pointer to the object's Smack label
+ * @request: the access requested, in "MAY" format
+ *
+ * This function looks up the subject/object pair in the
+ * access rule list and returns 0 if the access is permitted,
+ * non zero otherwise.
+ *
+ * Even though Smack labels are usually shared on smack_list
+ * labels that come in off the network can't be imported
+ * and added to the list for locking reasons.
+ *
+ * Therefore, it is necessary to check the contents of the labels,
+ * not just the pointer values. Of course, in most cases the labels
+ * will be on the list, so checking the pointers may be a worthwhile
+ * optimization.
+ */
+int smk_access(char *subject_label, char *object_label, int request)
+{
+       u32 may = MAY_NOT;
+       struct smk_list_entry *sp;
+       struct smack_rule *srp;
+
+       /*
+        * Hardcoded comparisons.
+        *
+        * A star subject can't access any object.
+        */
+       if (subject_label == smack_known_star.smk_known ||
+           strcmp(subject_label, smack_known_star.smk_known) == 0)
+               return -EACCES;
+       /*
+        * A star object can be accessed by any subject.
+        */
+       if (object_label == smack_known_star.smk_known ||
+           strcmp(object_label, smack_known_star.smk_known) == 0)
+               return 0;
+       /*
+        * An object can be accessed in any way by a subject
+        * with the same label.
+        */
+       if (subject_label == object_label ||
+           strcmp(subject_label, object_label) == 0)
+               return 0;
+       /*
+        * A hat subject can read any object.
+        * A floor object can be read by any subject.
+        */
+       if ((request & MAY_ANYREAD) == request) {
+               if (object_label == smack_known_floor.smk_known ||
+                   strcmp(object_label, smack_known_floor.smk_known) == 0)
+                       return 0;
+               if (subject_label == smack_known_hat.smk_known ||
+                   strcmp(subject_label, smack_known_hat.smk_known) == 0)
+                       return 0;
+       }
+       /*
+        * Beyond here an explicit relationship is required.
+        * If the requested access is contained in the available
+        * access (e.g. read is included in readwrite) it's
+        * good.
+        */
+       for (sp = smack_list; sp != NULL; sp = sp->smk_next) {
+               srp = &sp->smk_rule;
+
+               if (srp->smk_subject == subject_label ||
+                   strcmp(srp->smk_subject, subject_label) == 0) {
+                       if (srp->smk_object == object_label ||
+                           strcmp(srp->smk_object, object_label) == 0) {
+                               may = srp->smk_access;
+                               break;
+                       }
+               }
+       }
+       /*
+        * This is a bit map operation.
+        */
+       if ((request & may) == request)
+               return 0;
+
+       return -EACCES;
+}
+
+/**
+ * smk_curacc - determine if current has a specific access to an object
+ * @object_label: a pointer to the object's Smack label
+ * @request: the access requested, in "MAY" format
+ *
+ * This function checks the current subject label/object label pair
+ * in the access rule list and returns 0 if the access is permitted,
+ * non zero otherwise. It allows that current my have the capability
+ * to override the rules.
+ */
+int smk_curacc(char *obj_label, u32 mode)
+{
+       int rc;
+
+       rc = smk_access(current->security, obj_label, mode);
+       if (rc == 0)
+               return 0;
+
+       if (capable(CAP_MAC_OVERRIDE))
+               return 0;
+
+       return rc;
+}
+
+static DEFINE_MUTEX(smack_known_lock);
+
+/**
+ * smk_import_entry - import a label, return the list entry
+ * @string: a text string that might be a Smack label
+ * @len: the maximum size, or zero if it is NULL terminated.
+ *
+ * Returns a pointer to the entry in the label list that
+ * matches the passed string, adding it if necessary.
+ */
+struct smack_known *smk_import_entry(const char *string, int len)
+{
+       struct smack_known *skp;
+       char smack[SMK_LABELLEN];
+       int found;
+       int i;
+
+       if (len <= 0 || len > SMK_MAXLEN)
+               len = SMK_MAXLEN;
+
+       for (i = 0, found = 0; i < SMK_LABELLEN; i++) {
+               if (found)
+                       smack[i] = '\0';
+               else if (i >= len || string[i] > '~' || string[i] <= ' ' ||
+                        string[i] == '/') {
+                       smack[i] = '\0';
+                       found = 1;
+               } else
+                       smack[i] = string[i];
+       }
+
+       if (smack[0] == '\0')
+               return NULL;
+
+       mutex_lock(&smack_known_lock);
+
+       for (skp = smack_known; skp != NULL; skp = skp->smk_next)
+               if (strncmp(skp->smk_known, smack, SMK_MAXLEN) == 0)
+                       break;
+
+       if (skp == NULL) {
+               skp = kzalloc(sizeof(struct smack_known), GFP_KERNEL);
+               if (skp != NULL) {
+                       skp->smk_next = smack_known;
+                       strncpy(skp->smk_known, smack, SMK_MAXLEN);
+                       skp->smk_secid = smack_next_secid++;
+                       skp->smk_cipso = NULL;
+                       spin_lock_init(&skp->smk_cipsolock);
+                       /*
+                        * Make sure that the entry is actually
+                        * filled before putting it on the list.
+                        */
+                       smp_mb();
+                       smack_known = skp;
+               }
+       }
+
+       mutex_unlock(&smack_known_lock);
+
+       return skp;
+}
+
+/**
+ * smk_import - import a smack label
+ * @string: a text string that might be a Smack label
+ * @len: the maximum size, or zero if it is NULL terminated.
+ *
+ * Returns a pointer to the label in the label list that
+ * matches the passed string, adding it if necessary.
+ */
+char *smk_import(const char *string, int len)
+{
+       struct smack_known *skp;
+
+       skp = smk_import_entry(string, len);
+       if (skp == NULL)
+               return NULL;
+       return skp->smk_known;
+}
+
+/**
+ * smack_from_secid - find the Smack label associated with a secid
+ * @secid: an integer that might be associated with a Smack label
+ *
+ * Returns a pointer to the appropraite Smack label if there is one,
+ * otherwise a pointer to the invalid Smack label.
+ */
+char *smack_from_secid(const u32 secid)
+{
+       struct smack_known *skp;
+
+       for (skp = smack_known; skp != NULL; skp = skp->smk_next)
+               if (skp->smk_secid == secid)
+                       return skp->smk_known;
+
+       /*
+        * If we got this far someone asked for the translation
+        * of a secid that is not on the list.
+        */
+       return smack_known_invalid.smk_known;
+}
+
+/**
+ * smack_to_secid - find the secid associated with a Smack label
+ * @smack: the Smack label
+ *
+ * Returns the appropriate secid if there is one,
+ * otherwise 0
+ */
+u32 smack_to_secid(const char *smack)
+{
+       struct smack_known *skp;
+
+       for (skp = smack_known; skp != NULL; skp = skp->smk_next)
+               if (strncmp(skp->smk_known, smack, SMK_MAXLEN) == 0)
+                       return skp->smk_secid;
+       return 0;
+}
+
+/**
+ * smack_from_cipso - find the Smack label associated with a CIPSO option
+ * @level: Bell & LaPadula level from the network
+ * @cp: Bell & LaPadula categories from the network
+ * @result: where to put the Smack value
+ *
+ * This is a simple lookup in the label table.
+ *
+ * This is an odd duck as far as smack handling goes in that
+ * it sends back a copy of the smack label rather than a pointer
+ * to the master list. This is done because it is possible for
+ * a foreign host to send a smack label that is new to this
+ * machine and hence not on the list. That would not be an
+ * issue except that adding an entry to the master list can't
+ * be done at that point.
+ */
+void smack_from_cipso(u32 level, char *cp, char *result)
+{
+       struct smack_known *kp;
+       char *final = NULL;
+
+       for (kp = smack_known; final == NULL && kp != NULL; kp = kp->smk_next) {
+               if (kp->smk_cipso == NULL)
+                       continue;
+
+               spin_lock_bh(&kp->smk_cipsolock);
+
+               if (kp->smk_cipso->smk_level == level &&
+                   memcmp(kp->smk_cipso->smk_catset, cp, SMK_LABELLEN) == 0)
+                       final = kp->smk_known;
+
+               spin_unlock_bh(&kp->smk_cipsolock);
+       }
+       if (final == NULL)
+               final = smack_known_huh.smk_known;
+       strncpy(result, final, SMK_MAXLEN);
+       return;
+}
+
+/**
+ * smack_to_cipso - find the CIPSO option to go with a Smack label
+ * @smack: a pointer to the smack label in question
+ * @cp: where to put the result
+ *
+ * Returns zero if a value is available, non-zero otherwise.
+ */
+int smack_to_cipso(const char *smack, struct smack_cipso *cp)
+{
+       struct smack_known *kp;
+
+       for (kp = smack_known; kp != NULL; kp = kp->smk_next)
+               if (kp->smk_known == smack ||
+                   strcmp(kp->smk_known, smack) == 0)
+                       break;
+
+       if (kp == NULL || kp->smk_cipso == NULL)
+               return -ENOENT;
+
+       memcpy(cp, kp->smk_cipso, sizeof(struct smack_cipso));
+       return 0;
+}
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
new file mode 100644 (file)
index 0000000..1c11e42
--- /dev/null
@@ -0,0 +1,2518 @@
+/*
+ *  Simplified MAC Kernel (smack) security module
+ *
+ *  This file contains the smack hook function implementations.
+ *
+ *  Author:
+ *     Casey Schaufler <casey@schaufler-ca.com>
+ *
+ *  Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License version 2,
+ *      as published by the Free Software Foundation.
+ */
+
+#include <linux/xattr.h>
+#include <linux/pagemap.h>
+#include <linux/mount.h>
+#include <linux/stat.h>
+#include <linux/ext2_fs.h>
+#include <linux/kd.h>
+#include <asm/ioctls.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
+#include <linux/mutex.h>
+#include <linux/pipe_fs_i.h>
+#include <net/netlabel.h>
+#include <net/cipso_ipv4.h>
+
+#include "smack.h"
+
+/*
+ * I hope these are the hokeyist lines of code in the module. Casey.
+ */
+#define DEVPTS_SUPER_MAGIC     0x1cd1
+#define SOCKFS_MAGIC           0x534F434B
+#define TMPFS_MAGIC            0x01021994
+
+/**
+ * smk_fetch - Fetch the smack label from a file.
+ * @ip: a pointer to the inode
+ * @dp: a pointer to the dentry
+ *
+ * Returns a pointer to the master list entry for the Smack label
+ * or NULL if there was no label to fetch.
+ */
+static char *smk_fetch(struct inode *ip, struct dentry *dp)
+{
+       int rc;
+       char in[SMK_LABELLEN];
+
+       if (ip->i_op->getxattr == NULL)
+               return NULL;
+
+       rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
+       if (rc < 0)
+               return NULL;
+
+       return smk_import(in, rc);
+}
+
+/**
+ * new_inode_smack - allocate an inode security blob
+ * @smack: a pointer to the Smack label to use in the blob
+ *
+ * Returns the new blob or NULL if there's no memory available
+ */
+struct inode_smack *new_inode_smack(char *smack)
+{
+       struct inode_smack *isp;
+
+       isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
+       if (isp == NULL)
+               return NULL;
+
+       isp->smk_inode = smack;
+       isp->smk_flags = 0;
+       mutex_init(&isp->smk_lock);
+
+       return isp;
+}
+
+/*
+ * LSM hooks.
+ * We he, that is fun!
+ */
+
+/**
+ * smack_ptrace - Smack approval on ptrace
+ * @ptp: parent task pointer
+ * @ctp: child task pointer
+ *
+ * Returns 0 if access is OK, an error code otherwise
+ *
+ * Do the capability checks, and require read and write.
+ */
+static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp)
+{
+       int rc;
+
+       rc = cap_ptrace(ptp, ctp);
+       if (rc != 0)
+               return rc;
+
+       rc = smk_access(ptp->security, ctp->security, MAY_READWRITE);
+       if (rc != 0 && __capable(ptp, CAP_MAC_OVERRIDE))
+               return 0;
+
+       return rc;
+}
+
+/**
+ * smack_syslog - Smack approval on syslog
+ * @type: message type
+ *
+ * Require that the task has the floor label
+ *
+ * Returns 0 on success, error code otherwise.
+ */
+static int smack_syslog(int type)
+{
+       int rc;
+       char *sp = current->security;
+
+       rc = cap_syslog(type);
+       if (rc != 0)
+               return rc;
+
+       if (capable(CAP_MAC_OVERRIDE))
+               return 0;
+
+        if (sp != smack_known_floor.smk_known)
+               rc = -EACCES;
+
+       return rc;
+}
+
+
+/*
+ * Superblock Hooks.
+ */
+
+/**
+ * smack_sb_alloc_security - allocate a superblock blob
+ * @sb: the superblock getting the blob
+ *
+ * Returns 0 on success or -ENOMEM on error.
+ */
+static int smack_sb_alloc_security(struct super_block *sb)
+{
+       struct superblock_smack *sbsp;
+
+       sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
+
+       if (sbsp == NULL)
+               return -ENOMEM;
+
+       sbsp->smk_root = smack_known_floor.smk_known;
+       sbsp->smk_default = smack_known_floor.smk_known;
+       sbsp->smk_floor = smack_known_floor.smk_known;
+       sbsp->smk_hat = smack_known_hat.smk_known;
+       sbsp->smk_initialized = 0;
+       spin_lock_init(&sbsp->smk_sblock);
+
+       sb->s_security = sbsp;
+
+       return 0;
+}
+
+/**
+ * smack_sb_free_security - free a superblock blob
+ * @sb: the superblock getting the blob
+ *
+ */
+static void smack_sb_free_security(struct super_block *sb)
+{
+       kfree(sb->s_security);
+       sb->s_security = NULL;
+}
+
+/**
+ * smack_sb_copy_data - copy mount options data for processing
+ * @type: file system type
+ * @orig: where to start
+ * @smackopts
+ *
+ * Returns 0 on success or -ENOMEM on error.
+ *
+ * Copy the Smack specific mount options out of the mount
+ * options list.
+ */
+static int smack_sb_copy_data(struct file_system_type *type, void *orig,
+                             void *smackopts)
+{
+       char *cp, *commap, *otheropts, *dp;
+
+       /* Binary mount data: just copy */
+       if (type->fs_flags & FS_BINARY_MOUNTDATA) {
+               copy_page(smackopts, orig);
+               return 0;
+       }
+
+       otheropts = (char *)get_zeroed_page(GFP_KERNEL);
+       if (otheropts == NULL)
+               return -ENOMEM;
+
+       for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
+               if (strstr(cp, SMK_FSDEFAULT) == cp)
+                       dp = smackopts;
+               else if (strstr(cp, SMK_FSFLOOR) == cp)
+                       dp = smackopts;
+               else if (strstr(cp, SMK_FSHAT) == cp)
+                       dp = smackopts;
+               else if (strstr(cp, SMK_FSROOT) == cp)
+                       dp = smackopts;
+               else
+                       dp = otheropts;
+
+               commap = strchr(cp, ',');
+               if (commap != NULL)
+                       *commap = '\0';
+
+               if (*dp != '\0')
+                       strcat(dp, ",");
+               strcat(dp, cp);
+       }
+
+       strcpy(orig, otheropts);
+       free_page((unsigned long)otheropts);
+
+       return 0;
+}
+
+/**
+ * smack_sb_kern_mount - Smack specific mount processing
+ * @sb: the file system superblock
+ * @data: the smack mount options
+ *
+ * Returns 0 on success, an error code on failure
+ */
+static int smack_sb_kern_mount(struct super_block *sb, void *data)
+{
+       struct dentry *root = sb->s_root;
+       struct inode *inode = root->d_inode;
+       struct superblock_smack *sp = sb->s_security;
+       struct inode_smack *isp;
+       char *op;
+       char *commap;
+       char *nsp;
+
+       spin_lock(&sp->smk_sblock);
+       if (sp->smk_initialized != 0) {
+               spin_unlock(&sp->smk_sblock);
+               return 0;
+       }
+       sp->smk_initialized = 1;
+       spin_unlock(&sp->smk_sblock);
+
+       for (op = data; op != NULL; op = commap) {
+               commap = strchr(op, ',');
+               if (commap != NULL)
+                       *commap++ = '\0';
+
+               if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
+                       op += strlen(SMK_FSHAT);
+                       nsp = smk_import(op, 0);
+                       if (nsp != NULL)
+                               sp->smk_hat = nsp;
+               } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
+                       op += strlen(SMK_FSFLOOR);
+                       nsp = smk_import(op, 0);
+                       if (nsp != NULL)
+                               sp->smk_floor = nsp;
+               } else if (strncmp(op, SMK_FSDEFAULT,
+                                  strlen(SMK_FSDEFAULT)) == 0) {
+                       op += strlen(SMK_FSDEFAULT);
+                       nsp = smk_import(op, 0);
+                       if (nsp != NULL)
+                               sp->smk_default = nsp;
+               } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
+                       op += strlen(SMK_FSROOT);
+                       nsp = smk_import(op, 0);
+                       if (nsp != NULL)
+                               sp->smk_root = nsp;
+               }
+       }
+
+       /*
+        * Initialize the root inode.
+        */
+       isp = inode->i_security;
+       if (isp == NULL)
+               inode->i_security = new_inode_smack(sp->smk_root);
+       else
+               isp->smk_inode = sp->smk_root;
+
+       return 0;
+}
+
+/**
+ * smack_sb_statfs - Smack check on statfs
+ * @dentry: identifies the file system in question
+ *
+ * Returns 0 if current can read the floor of the filesystem,
+ * and error code otherwise
+ */
+static int smack_sb_statfs(struct dentry *dentry)
+{
+       struct superblock_smack *sbp = dentry->d_sb->s_security;
+
+       return smk_curacc(sbp->smk_floor, MAY_READ);
+}
+
+/**
+ * smack_sb_mount - Smack check for mounting
+ * @dev_name: unused
+ * @nd: mount point
+ * @type: unused
+ * @flags: unused
+ * @data: unused
+ *
+ * Returns 0 if current can write the floor of the filesystem
+ * being mounted on, an error code otherwise.
+ */
+static int smack_sb_mount(char *dev_name, struct nameidata *nd,
+                         char *type, unsigned long flags, void *data)
+{
+       struct superblock_smack *sbp = nd->mnt->mnt_sb->s_security;
+
+       return smk_curacc(sbp->smk_floor, MAY_WRITE);
+}
+
+/**
+ * smack_sb_umount - Smack check for unmounting
+ * @mnt: file system to unmount
+ * @flags: unused
+ *
+ * Returns 0 if current can write the floor of the filesystem
+ * being unmounted, an error code otherwise.
+ */
+static int smack_sb_umount(struct vfsmount *mnt, int flags)
+{
+       struct superblock_smack *sbp;
+
+       sbp = mnt->mnt_sb->s_security;
+
+       return smk_curacc(sbp->smk_floor, MAY_WRITE);
+}
+
+/*
+ * Inode hooks
+ */
+
+/**
+ * smack_inode_alloc_security - allocate an inode blob
+ * @inode - the inode in need of a blob
+ *
+ * Returns 0 if it gets a blob, -ENOMEM otherwise
+ */
+static int smack_inode_alloc_security(struct inode *inode)
+{
+       inode->i_security = new_inode_smack(current->security);
+       if (inode->i_security == NULL)
+               return -ENOMEM;
+       return 0;
+}
+
+/**
+ * smack_inode_free_security - free an inode blob
+ * @inode - the inode with a blob
+ *
+ * Clears the blob pointer in inode
+ */
+static void smack_inode_free_security(struct inode *inode)
+{
+       kfree(inode->i_security);
+       inode->i_security = NULL;
+}
+
+/**
+ * smack_inode_init_security - copy out the smack from an inode
+ * @inode: the inode
+ * @dir: unused
+ * @name: where to put the attribute name
+ * @value: where to put the attribute value
+ * @len: where to put the length of the attribute
+ *
+ * Returns 0 if it all works out, -ENOMEM if there's no memory
+ */
+static int smack_inode_init_security(struct inode *inode, struct inode *dir,
+                                    char **name, void **value, size_t *len)
+{
+       char *isp = smk_of_inode(inode);
+
+       if (name) {
+               *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
+               if (*name == NULL)
+                       return -ENOMEM;
+       }
+
+       if (value) {
+               *value = kstrdup(isp, GFP_KERNEL);
+               if (*value == NULL)
+                       return -ENOMEM;
+       }
+
+       if (len)
+               *len = strlen(isp) + 1;
+
+       return 0;
+}
+
+/**
+ * smack_inode_link - Smack check on link
+ * @old_dentry: the existing object
+ * @dir: unused
+ * @new_dentry: the new object
+ *
+ * Returns 0 if access is permitted, an error code otherwise
+ */
+static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
+                           struct dentry *new_dentry)
+{
+       int rc;
+       char *isp;
+
+       isp = smk_of_inode(old_dentry->d_inode);
+       rc = smk_curacc(isp, MAY_WRITE);
+
+       if (rc == 0 && new_dentry->d_inode != NULL) {
+               isp = smk_of_inode(new_dentry->d_inode);
+               rc = smk_curacc(isp, MAY_WRITE);
+       }
+
+       return rc;
+}
+
+/**
+ * smack_inode_unlink - Smack check on inode deletion
+ * @dir: containing directory object
+ * @dentry: file to unlink
+ *
+ * Returns 0 if current can write the containing directory
+ * and the object, error code otherwise
+ */
+static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
+{
+       struct inode *ip = dentry->d_inode;
+       int rc;
+
+       /*
+        * You need write access to the thing you're unlinking
+        */
+       rc = smk_curacc(smk_of_inode(ip), MAY_WRITE);
+       if (rc == 0)
+               /*
+                * You also need write access to the containing directory
+                */
+               rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
+
+       return rc;
+}
+
+/**
+ * smack_inode_rmdir - Smack check on directory deletion
+ * @dir: containing directory object
+ * @dentry: directory to unlink
+ *
+ * Returns 0 if current can write the containing directory
+ * and the directory, error code otherwise
+ */
+static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
+{
+       int rc;
+
+       /*
+        * You need write access to the thing you're removing
+        */
+       rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
+       if (rc == 0)
+               /*
+                * You also need write access to the containing directory
+                */
+               rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
+
+       return rc;
+}
+
+/**
+ * smack_inode_rename - Smack check on rename
+ * @old_inode: the old directory
+ * @old_dentry: unused
+ * @new_inode: the new directory
+ * @new_dentry: unused
+ *
+ * Read and write access is required on both the old and
+ * new directories.
+ *
+ * Returns 0 if access is permitted, an error code otherwise
+ */
+static int smack_inode_rename(struct inode *old_inode,
+                             struct dentry *old_dentry,
+                             struct inode *new_inode,
+                             struct dentry *new_dentry)
+{
+       int rc;
+       char *isp;
+
+       isp = smk_of_inode(old_dentry->d_inode);
+       rc = smk_curacc(isp, MAY_READWRITE);
+
+       if (rc == 0 && new_dentry->d_inode != NULL) {
+               isp = smk_of_inode(new_dentry->d_inode);
+               rc = smk_curacc(isp, MAY_READWRITE);
+       }
+
+       return rc;
+}
+
+/**
+ * smack_inode_permission - Smack version of permission()
+ * @inode: the inode in question
+ * @mask: the access requested
+ * @nd: unused
+ *
+ * This is the important Smack hook.
+ *
+ * Returns 0 if access is permitted, -EACCES otherwise
+ */
+static int smack_inode_permission(struct inode *inode, int mask,
+                                 struct nameidata *nd)
+{
+       /*
+        * No permission to check. Existence test. Yup, it's there.
+        */
+       if (mask == 0)
+               return 0;
+
+       return smk_curacc(smk_of_inode(inode), mask);
+}
+
+/**
+ * smack_inode_setattr - Smack check for setting attributes
+ * @dentry: the object
+ * @iattr: for the force flag
+ *
+ * Returns 0 if access is permitted, an error code otherwise
+ */
+static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
+{
+       /*
+        * Need to allow for clearing the setuid bit.
+        */
+       if (iattr->ia_valid & ATTR_FORCE)
+               return 0;
+
+       return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
+}
+
+/**
+ * smack_inode_getattr - Smack check for getting attributes
+ * @mnt: unused
+ * @dentry: the object
+ *
+ * Returns 0 if access is permitted, an error code otherwise
+ */
+static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
+{
+       return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
+}
+
+/**
+ * smack_inode_setxattr - Smack check for setting xattrs
+ * @dentry: the object
+ * @name: name of the attribute
+ * @value: unused
+ * @size: unused
+ * @flags: unused
+ *
+ * This protects the Smack attribute explicitly.
+ *
+ * Returns 0 if access is permitted, an error code otherwise
+ */
+static int smack_inode_setxattr(struct dentry *dentry, char *name,
+                               void *value, size_t size, int flags)
+{
+       if (!capable(CAP_MAC_ADMIN)) {
+               if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
+                   strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
+                   strcmp(name, XATTR_NAME_SMACKIPOUT) == 0)
+                       return -EPERM;
+       }
+
+       return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
+}
+
+/**
+ * smack_inode_post_setxattr - Apply the Smack update approved above
+ * @dentry: object
+ * @name: attribute name
+ * @value: attribute value
+ * @size: attribute size
+ * @flags: unused
+ *
+ * Set the pointer in the inode blob to the entry found
+ * in the master label list.
+ */
+static void smack_inode_post_setxattr(struct dentry *dentry, char *name,
+                                     void *value, size_t size, int flags)
+{
+       struct inode_smack *isp;
+       char *nsp;
+
+       /*
+        * Not SMACK
+        */
+       if (strcmp(name, XATTR_NAME_SMACK))
+               return;
+
+       if (size >= SMK_LABELLEN)
+               return;
+
+       isp = dentry->d_inode->i_security;
+
+       /*
+        * No locking is done here. This is a pointer
+        * assignment.
+        */
+       nsp = smk_import(value, size);
+       if (nsp != NULL)
+               isp->smk_inode = nsp;
+       else
+               isp->smk_inode = smack_known_invalid.smk_known;
+
+       return;
+}
+
+/*
+ * smack_inode_getxattr - Smack check on getxattr
+ * @dentry: the object
+ * @name: unused
+ *
+ * Returns 0 if access is permitted, an error code otherwise
+ */
+static int smack_inode_getxattr(struct dentry *dentry, char *name)
+{
+       return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
+}
+
+/*
+ * smack_inode_removexattr - Smack check on removexattr
+ * @dentry: the object
+ * @name: name of the attribute
+ *
+ * Removing the Smack attribute requires CAP_MAC_ADMIN
+ *
+ * Returns 0 if access is permitted, an error code otherwise
+ */
+static int smack_inode_removexattr(struct dentry *dentry, char *name)
+{
+       if (strcmp(name, XATTR_NAME_SMACK) == 0 && !capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
+}
+
+/**
+ * smack_inode_getsecurity - get smack xattrs
+ * @inode: the object
+ * @name: attribute name
+ * @buffer: where to put the result
+ * @size: size of the buffer
+ * @err: unused
+ *
+ * Returns the size of the attribute or an error code
+ */
+static int smack_inode_getsecurity(const struct inode *inode,
+                                  const char *name, void **buffer,
+                                  bool alloc)
+{
+       struct socket_smack *ssp;
+       struct socket *sock;
+       struct super_block *sbp;
+       struct inode *ip = (struct inode *)inode;
+       char *isp;
+       int ilen;
+       int rc = 0;
+
+       if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
+               isp = smk_of_inode(inode);
+               ilen = strlen(isp) + 1;
+               *buffer = isp;
+               return ilen;
+       }
+
+       /*
+        * The rest of the Smack xattrs are only on sockets.
+        */
+       sbp = ip->i_sb;
+       if (sbp->s_magic != SOCKFS_MAGIC)
+               return -EOPNOTSUPP;
+
+       sock = SOCKET_I(ip);
+       if (sock == NULL)
+               return -EOPNOTSUPP;
+
+       ssp = sock->sk->sk_security;
+
+       if (strcmp(name, XATTR_SMACK_IPIN) == 0)
+               isp = ssp->smk_in;
+       else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
+               isp = ssp->smk_out;
+       else
+               return -EOPNOTSUPP;
+
+       ilen = strlen(isp) + 1;
+       if (rc == 0) {
+               *buffer = isp;
+               rc = ilen;
+       }
+
+       return rc;
+}
+
+
+/**
+ * smack_inode_listsecurity - list the Smack attributes
+ * @inode: the object
+ * @buffer: where they go
+ * @buffer_size: size of buffer
+ *
+ * Returns 0 on success, -EINVAL otherwise
+ */
+static int smack_inode_listsecurity(struct inode *inode, char *buffer,
+                                   size_t buffer_size)
+{
+       int len = strlen(XATTR_NAME_SMACK);
+
+       if (buffer != NULL && len <= buffer_size) {
+               memcpy(buffer, XATTR_NAME_SMACK, len);
+               return len;
+       }
+       return -EINVAL;
+}
+
+/*
+ * File Hooks
+ */
+
+/**
+ * smack_file_permission - Smack check on file operations
+ * @file: unused
+ * @mask: unused
+ *
+ * Returns 0
+ *
+ * Should access checks be done on each read or write?
+ * UNICOS and SELinux say yes.
+ * Trusted Solaris, Trusted Irix, and just about everyone else says no.
+ *
+ * I'll say no for now. Smack does not do the frequent
+ * label changing that SELinux does.
+ */
+static int smack_file_permission(struct file *file, int mask)
+{
+       return 0;
+}
+
+/**
+ * smack_file_alloc_security - assign a file security blob
+ * @file: the object
+ *
+ * The security blob for a file is a pointer to the master
+ * label list, so no allocation is done.
+ *
+ * Returns 0
+ */
+static int smack_file_alloc_security(struct file *file)
+{
+       file->f_security = current->security;
+       return 0;
+}
+
+/**
+ * smack_file_free_security - clear a file security blob
+ * @file: the object
+ *
+ * The security blob for a file is a pointer to the master
+ * label list, so no memory is freed.
+ */
+static void smack_file_free_security(struct file *file)
+{
+       file->f_security = NULL;
+}
+
+/**
+ * smack_file_ioctl - Smack check on ioctls
+ * @file: the object
+ * @cmd: what to do
+ * @arg: unused
+ *
+ * Relies heavily on the correct use of the ioctl command conventions.
+ *
+ * Returns 0 if allowed, error code otherwise
+ */
+static int smack_file_ioctl(struct file *file, unsigned int cmd,
+                           unsigned long arg)
+{
+       int rc = 0;
+
+       if (_IOC_DIR(cmd) & _IOC_WRITE)
+               rc = smk_curacc(file->f_security, MAY_WRITE);
+
+       if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
+               rc = smk_curacc(file->f_security, MAY_READ);
+
+       return rc;
+}
+
+/**
+ * smack_file_lock - Smack check on file locking
+ * @file: the object
+ * @cmd unused
+ *
+ * Returns 0 if current has write access, error code otherwise
+ */
+static int smack_file_lock(struct file *file, unsigned int cmd)
+{
+       return smk_curacc(file->f_security, MAY_WRITE);
+}
+
+/**
+ * smack_file_fcntl - Smack check on fcntl
+ * @file: the object
+ * @cmd: what action to check
+ * @arg: unused
+ *
+ * Returns 0 if current has access, error code otherwise
+ */
+static int smack_file_fcntl(struct file *file, unsigned int cmd,
+                           unsigned long arg)
+{
+       int rc;
+
+       switch (cmd) {
+       case F_DUPFD:
+       case F_GETFD:
+       case F_GETFL:
+       case F_GETLK:
+       case F_GETOWN:
+       case F_GETSIG:
+               rc = smk_curacc(file->f_security, MAY_READ);
+               break;
+       case F_SETFD:
+       case F_SETFL:
+       case F_SETLK:
+       case F_SETLKW:
+       case F_SETOWN:
+       case F_SETSIG:
+               rc = smk_curacc(file->f_security, MAY_WRITE);
+               break;
+       default:
+               rc = smk_curacc(file->f_security, MAY_READWRITE);
+       }
+
+       return rc;
+}
+
+/**
+ * smack_file_set_fowner - set the file security blob value
+ * @file: object in question
+ *
+ * Returns 0
+ * Further research may be required on this one.
+ */
+static int smack_file_set_fowner(struct file *file)
+{
+       file->f_security = current->security;
+       return 0;
+}
+
+/**
+ * smack_file_send_sigiotask - Smack on sigio
+ * @tsk: The target task
+ * @fown: the object the signal come from
+ * @signum: unused
+ *
+ * Allow a privileged task to get signals even if it shouldn't
+ *
+ * Returns 0 if a subject with the object's smack could
+ * write to the task, an error code otherwise.
+ */
+static int smack_file_send_sigiotask(struct task_struct *tsk,
+                                    struct fown_struct *fown, int signum)
+{
+       struct file *file;
+       int rc;
+
+       /*
+        * struct fown_struct is never outside the context of a struct file
+        */
+       file = container_of(fown, struct file, f_owner);
+       rc = smk_access(file->f_security, tsk->security, MAY_WRITE);
+       if (rc != 0 && __capable(tsk, CAP_MAC_OVERRIDE))
+               return 0;
+       return rc;
+}
+
+/**
+ * smack_file_receive - Smack file receive check
+ * @file: the object
+ *
+ * Returns 0 if current has access, error code otherwise
+ */
+static int smack_file_receive(struct file *file)
+{
+       int may = 0;
+
+       /*
+        * This code relies on bitmasks.
+        */
+       if (file->f_mode & FMODE_READ)
+               may = MAY_READ;
+       if (file->f_mode & FMODE_WRITE)
+               may |= MAY_WRITE;
+
+       return smk_curacc(file->f_security, may);
+}
+
+/*
+ * Task hooks
+ */
+
+/**
+ * smack_task_alloc_security - "allocate" a task blob
+ * @tsk: the task in need of a blob
+ *
+ * Smack isn't using copies of blobs. Everyone
+ * points to an immutable list. No alloc required.
+ * No data copy required.
+ *
+ * Always returns 0
+ */
+static int smack_task_alloc_security(struct task_struct *tsk)
+{
+       tsk->security = current->security;
+
+       return 0;
+}
+
+/**
+ * smack_task_free_security - "free" a task blob
+ * @task: the task with the blob
+ *
+ * Smack isn't using copies of blobs. Everyone
+ * points to an immutable list. The blobs never go away.
+ * There is no leak here.
+ */
+static void smack_task_free_security(struct task_struct *task)
+{
+       task->security = NULL;
+}
+
+/**
+ * smack_task_setpgid - Smack check on setting pgid
+ * @p: the task object
+ * @pgid: unused
+ *
+ * Return 0 if write access is permitted
+ */
+static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
+{
+       return smk_curacc(p->security, MAY_WRITE);
+}
+
+/**
+ * smack_task_getpgid - Smack access check for getpgid
+ * @p: the object task
+ *
+ * Returns 0 if current can read the object task, error code otherwise
+ */
+static int smack_task_getpgid(struct task_struct *p)
+{
+       return smk_curacc(p->security, MAY_READ);
+}
+
+/**
+ * smack_task_getsid - Smack access check for getsid
+ * @p: the object task
+ *
+ * Returns 0 if current can read the object task, error code otherwise
+ */
+static int smack_task_getsid(struct task_struct *p)
+{
+       return smk_curacc(p->security, MAY_READ);
+}
+
+/**
+ * smack_task_getsecid - get the secid of the task
+ * @p: the object task
+ * @secid: where to put the result
+ *
+ * Sets the secid to contain a u32 version of the smack label.
+ */
+static void smack_task_getsecid(struct task_struct *p, u32 *secid)
+{
+       *secid = smack_to_secid(p->security);
+}
+
+/**
+ * smack_task_setnice - Smack check on setting nice
+ * @p: the task object
+ * @nice: unused
+ *
+ * Return 0 if write access is permitted
+ */
+static int smack_task_setnice(struct task_struct *p, int nice)
+{
+       return smk_curacc(p->security, MAY_WRITE);
+}
+
+/**
+ * smack_task_setioprio - Smack check on setting ioprio
+ * @p: the task object
+ * @ioprio: unused
+ *
+ * Return 0 if write access is permitted
+ */
+static int smack_task_setioprio(struct task_struct *p, int ioprio)
+{
+       return smk_curacc(p->security, MAY_WRITE);
+}
+
+/**
+ * smack_task_getioprio - Smack check on reading ioprio
+ * @p: the task object
+ *
+ * Return 0 if read access is permitted
+ */
+static int smack_task_getioprio(struct task_struct *p)
+{
+       return smk_curacc(p->security, MAY_READ);
+}
+
+/**
+ * smack_task_setscheduler - Smack check on setting scheduler
+ * @p: the task object
+ * @policy: unused
+ * @lp: unused
+ *
+ * Return 0 if read access is permitted
+ */
+static int smack_task_setscheduler(struct task_struct *p, int policy,
+                                  struct sched_param *lp)
+{
+       return smk_curacc(p->security, MAY_WRITE);
+}
+
+/**
+ * smack_task_getscheduler - Smack check on reading scheduler
+ * @p: the task object
+ *
+ * Return 0 if read access is permitted
+ */
+static int smack_task_getscheduler(struct task_struct *p)
+{
+       return smk_curacc(p->security, MAY_READ);
+}
+
+/**
+ * smack_task_movememory - Smack check on moving memory
+ * @p: the task object
+ *
+ * Return 0 if write access is permitted
+ */
+static int smack_task_movememory(struct task_struct *p)
+{
+       return smk_curacc(p->security, MAY_WRITE);
+}
+
+/**
+ * smack_task_kill - Smack check on signal delivery
+ * @p: the task object
+ * @info: unused
+ * @sig: unused
+ * @secid: identifies the smack to use in lieu of current's
+ *
+ * Return 0 if write access is permitted
+ *
+ * The secid behavior is an artifact of an SELinux hack
+ * in the USB code. Someday it may go away.
+ */
+static int smack_task_kill(struct task_struct *p, struct siginfo *info,
+                          int sig, u32 secid)
+{
+       /*
+        * Special cases where signals really ought to go through
+        * in spite of policy. Stephen Smalley suggests it may
+        * make sense to change the caller so that it doesn't
+        * bother with the LSM hook in these cases.
+        */
+       if (info != SEND_SIG_NOINFO &&
+           (is_si_special(info) || SI_FROMKERNEL(info)))
+               return 0;
+       /*
+        * Sending a signal requires that the sender
+        * can write the receiver.
+        */
+       if (secid == 0)
+               return smk_curacc(p->security, MAY_WRITE);
+       /*
+        * If the secid isn't 0 we're dealing with some USB IO
+        * specific behavior. This is not clean. For one thing
+        * we can't take privilege into account.
+        */
+       return smk_access(smack_from_secid(secid), p->security, MAY_WRITE);
+}
+
+/**
+ * smack_task_wait - Smack access check for waiting
+ * @p: task to wait for
+ *
+ * Returns 0 if current can wait for p, error code otherwise
+ */
+static int smack_task_wait(struct task_struct *p)
+{
+       int rc;
+
+       rc = smk_access(current->security, p->security, MAY_WRITE);
+       if (rc == 0)
+               return 0;
+
+       /*
+        * Allow the operation to succeed if either task
+        * has privilege to perform operations that might
+        * account for the smack labels having gotten to
+        * be different in the first place.
+        *
+        * This breaks the strict subjet/object access
+        * control ideal, taking the object's privilege
+        * state into account in the decision as well as
+        * the smack value.
+        */
+       if (capable(CAP_MAC_OVERRIDE) || __capable(p, CAP_MAC_OVERRIDE))
+               return 0;
+
+       return rc;
+}
+
+/**
+ * smack_task_to_inode - copy task smack into the inode blob
+ * @p: task to copy from
+ * inode: inode to copy to
+ *
+ * Sets the smack pointer in the inode security blob
+ */
+static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
+{
+       struct inode_smack *isp = inode->i_security;
+       isp->smk_inode = p->security;
+}
+
+/*
+ * Socket hooks.
+ */
+
+/**
+ * smack_sk_alloc_security - Allocate a socket blob
+ * @sk: the socket
+ * @family: unused
+ * @priority: memory allocation priority
+ *
+ * Assign Smack pointers to current
+ *
+ * Returns 0 on success, -ENOMEM is there's no memory
+ */
+static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
+{
+       char *csp = current->security;
+       struct socket_smack *ssp;
+
+       ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
+       if (ssp == NULL)
+               return -ENOMEM;
+
+       ssp->smk_in = csp;
+       ssp->smk_out = csp;
+       ssp->smk_packet[0] = '\0';
+
+       sk->sk_security = ssp;
+
+       return 0;
+}
+
+/**
+ * smack_sk_free_security - Free a socket blob
+ * @sk: the socket
+ *
+ * Clears the blob pointer
+ */
+static void smack_sk_free_security(struct sock *sk)
+{
+       kfree(sk->sk_security);
+}
+
+/**
+ * smack_set_catset - convert a capset to netlabel mls categories
+ * @catset: the Smack categories
+ * @sap: where to put the netlabel categories
+ *
+ * Allocates and fills attr.mls.cat
+ */
+static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
+{
+       unsigned char *cp;
+       unsigned char m;
+       int cat;
+       int rc;
+       int byte;
+
+       if (catset == 0)
+               return;
+
+       sap->flags |= NETLBL_SECATTR_MLS_CAT;
+       sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
+       sap->attr.mls.cat->startbit = 0;
+
+       for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
+               for (m = 0x80; m != 0; m >>= 1, cat++) {
+                       if ((m & *cp) == 0)
+                               continue;
+                       rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
+                                                         cat, GFP_ATOMIC);
+               }
+}
+
+/**
+ * smack_to_secattr - fill a secattr from a smack value
+ * @smack: the smack value
+ * @nlsp: where the result goes
+ *
+ * Casey says that CIPSO is good enough for now.
+ * It can be used to effect.
+ * It can also be abused to effect when necessary.
+ * Appologies to the TSIG group in general and GW in particular.
+ */
+static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
+{
+       struct smack_cipso cipso;
+       int rc;
+
+       switch (smack_net_nltype) {
+       case NETLBL_NLTYPE_CIPSOV4:
+               nlsp->domain = NULL;
+               nlsp->flags = NETLBL_SECATTR_DOMAIN;
+               nlsp->flags |= NETLBL_SECATTR_MLS_LVL;
+
+               rc = smack_to_cipso(smack, &cipso);
+               if (rc == 0) {
+                       nlsp->attr.mls.lvl = cipso.smk_level;
+                       smack_set_catset(cipso.smk_catset, nlsp);
+               } else {
+                       nlsp->attr.mls.lvl = smack_cipso_direct;
+                       smack_set_catset(smack, nlsp);
+               }
+               break;
+       default:
+               break;
+       }
+}
+
+/**
+ * smack_netlabel - Set the secattr on a socket
+ * @sk: the socket
+ *
+ * Convert the outbound smack value (smk_out) to a
+ * secattr and attach it to the socket.
+ *
+ * Returns 0 on success or an error code
+ */
+static int smack_netlabel(struct sock *sk)
+{
+       struct socket_smack *ssp = sk->sk_security;
+       struct netlbl_lsm_secattr secattr;
+       int rc = 0;
+
+       netlbl_secattr_init(&secattr);
+       smack_to_secattr(ssp->smk_out, &secattr);
+       if (secattr.flags != NETLBL_SECATTR_NONE)
+               rc = netlbl_sock_setattr(sk, &secattr);
+
+       netlbl_secattr_destroy(&secattr);
+       return rc;
+}
+
+/**
+ * smack_inode_setsecurity - set smack xattrs
+ * @inode: the object
+ * @name: attribute name
+ * @value: attribute value
+ * @size: size of the attribute
+ * @flags: unused
+ *
+ * Sets the named attribute in the appropriate blob
+ *
+ * Returns 0 on success, or an error code
+ */
+static int smack_inode_setsecurity(struct inode *inode, const char *name,
+                                  const void *value, size_t size, int flags)
+{
+       char *sp;
+       struct inode_smack *nsp = inode->i_security;
+       struct socket_smack *ssp;
+       struct socket *sock;
+
+       if (value == NULL || size > SMK_LABELLEN)
+               return -EACCES;
+
+       sp = smk_import(value, size);
+       if (sp == NULL)
+               return -EINVAL;
+
+       if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
+               nsp->smk_inode = sp;
+               return 0;
+       }
+       /*
+        * The rest of the Smack xattrs are only on sockets.
+        */
+       if (inode->i_sb->s_magic != SOCKFS_MAGIC)
+               return -EOPNOTSUPP;
+
+       sock = SOCKET_I(inode);
+       if (sock == NULL)
+               return -EOPNOTSUPP;
+
+       ssp = sock->sk->sk_security;
+
+       if (strcmp(name, XATTR_SMACK_IPIN) == 0)
+               ssp->smk_in = sp;
+       else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
+               ssp->smk_out = sp;
+               return smack_netlabel(sock->sk);
+       } else
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
+/**
+ * smack_socket_post_create - finish socket setup
+ * @sock: the socket
+ * @family: protocol family
+ * @type: unused
+ * @protocol: unused
+ * @kern: unused
+ *
+ * Sets the netlabel information on the socket
+ *
+ * Returns 0 on success, and error code otherwise
+ */
+static int smack_socket_post_create(struct socket *sock, int family,
+                                   int type, int protocol, int kern)
+{
+       if (family != PF_INET)
+               return 0;
+       /*
+        * Set the outbound netlbl.
+        */
+       return smack_netlabel(sock->sk);
+}
+
+/**
+ * smack_flags_to_may - convert S_ to MAY_ values
+ * @flags: the S_ value
+ *
+ * Returns the equivalent MAY_ value
+ */
+static int smack_flags_to_may(int flags)
+{
+       int may = 0;
+
+       if (flags & S_IRUGO)
+               may |= MAY_READ;
+       if (flags & S_IWUGO)
+               may |= MAY_WRITE;
+       if (flags & S_IXUGO)
+               may |= MAY_EXEC;
+
+       return may;
+}
+
+/**
+ * smack_msg_msg_alloc_security - Set the security blob for msg_msg
+ * @msg: the object
+ *
+ * Returns 0
+ */
+static int smack_msg_msg_alloc_security(struct msg_msg *msg)
+{
+       msg->security = current->security;
+       return 0;
+}
+
+/**
+ * smack_msg_msg_free_security - Clear the security blob for msg_msg
+ * @msg: the object
+ *
+ * Clears the blob pointer
+ */
+static void smack_msg_msg_free_security(struct msg_msg *msg)
+{
+       msg->security = NULL;
+}
+
+/**
+ * smack_of_shm - the smack pointer for the shm
+ * @shp: the object
+ *
+ * Returns a pointer to the smack value
+ */
+static char *smack_of_shm(struct shmid_kernel *shp)
+{
+       return (char *)shp->shm_perm.security;
+}
+
+/**
+ * smack_shm_alloc_security - Set the security blob for shm
+ * @shp: the object
+ *
+ * Returns 0
+ */
+static int smack_shm_alloc_security(struct shmid_kernel *shp)
+{
+       struct kern_ipc_perm *isp = &shp->shm_perm;
+
+       isp->security = current->security;
+       return 0;
+}
+
+/**
+ * smack_shm_free_security - Clear the security blob for shm
+ * @shp: the object
+ *
+ * Clears the blob pointer
+ */
+static void smack_shm_free_security(struct shmid_kernel *shp)
+{
+       struct kern_ipc_perm *isp = &shp->shm_perm;
+
+       isp->security = NULL;
+}
+
+/**
+ * smack_shm_associate - Smack access check for shm
+ * @shp: the object
+ * @shmflg: access requested
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
+{
+       char *ssp = smack_of_shm(shp);
+       int may;
+
+       may = smack_flags_to_may(shmflg);
+       return smk_curacc(ssp, may);
+}
+
+/**
+ * smack_shm_shmctl - Smack access check for shm
+ * @shp: the object
+ * @cmd: what it wants to do
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
+{
+       char *ssp = smack_of_shm(shp);
+       int may;
+
+       switch (cmd) {
+       case IPC_STAT:
+       case SHM_STAT:
+               may = MAY_READ;
+               break;
+       case IPC_SET:
+       case SHM_LOCK:
+       case SHM_UNLOCK:
+       case IPC_RMID:
+               may = MAY_READWRITE;
+               break;
+       case IPC_INFO:
+       case SHM_INFO:
+               /*
+                * System level information.
+                */
+               return 0;
+       default:
+               return -EINVAL;
+       }
+
+       return smk_curacc(ssp, may);
+}
+
+/**
+ * smack_shm_shmat - Smack access for shmat
+ * @shp: the object
+ * @shmaddr: unused
+ * @shmflg: access requested
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
+                          int shmflg)
+{
+       char *ssp = smack_of_shm(shp);
+       int may;
+
+       may = smack_flags_to_may(shmflg);
+       return smk_curacc(ssp, may);
+}
+
+/**
+ * smack_of_sem - the smack pointer for the sem
+ * @sma: the object
+ *
+ * Returns a pointer to the smack value
+ */
+static char *smack_of_sem(struct sem_array *sma)
+{
+       return (char *)sma->sem_perm.security;
+}
+
+/**
+ * smack_sem_alloc_security - Set the security blob for sem
+ * @sma: the object
+ *
+ * Returns 0
+ */
+static int smack_sem_alloc_security(struct sem_array *sma)
+{
+       struct kern_ipc_perm *isp = &sma->sem_perm;
+
+       isp->security = current->security;
+       return 0;
+}
+
+/**
+ * smack_sem_free_security - Clear the security blob for sem
+ * @sma: the object
+ *
+ * Clears the blob pointer
+ */
+static void smack_sem_free_security(struct sem_array *sma)
+{
+       struct kern_ipc_perm *isp = &sma->sem_perm;
+
+       isp->security = NULL;
+}
+
+/**
+ * smack_sem_associate - Smack access check for sem
+ * @sma: the object
+ * @semflg: access requested
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_sem_associate(struct sem_array *sma, int semflg)
+{
+       char *ssp = smack_of_sem(sma);
+       int may;
+
+       may = smack_flags_to_may(semflg);
+       return smk_curacc(ssp, may);
+}
+
+/**
+ * smack_sem_shmctl - Smack access check for sem
+ * @sma: the object
+ * @cmd: what it wants to do
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_sem_semctl(struct sem_array *sma, int cmd)
+{
+       char *ssp = smack_of_sem(sma);
+       int may;
+
+       switch (cmd) {
+       case GETPID:
+       case GETNCNT:
+       case GETZCNT:
+       case GETVAL:
+       case GETALL:
+       case IPC_STAT:
+       case SEM_STAT:
+               may = MAY_READ;
+               break;
+       case SETVAL:
+       case SETALL:
+       case IPC_RMID:
+       case IPC_SET:
+               may = MAY_READWRITE;
+               break;
+       case IPC_INFO:
+       case SEM_INFO:
+               /*
+                * System level information
+                */
+               return 0;
+       default:
+               return -EINVAL;
+       }
+
+       return smk_curacc(ssp, may);
+}
+
+/**
+ * smack_sem_semop - Smack checks of semaphore operations
+ * @sma: the object
+ * @sops: unused
+ * @nsops: unused
+ * @alter: unused
+ *
+ * Treated as read and write in all cases.
+ *
+ * Returns 0 if access is allowed, error code otherwise
+ */
+static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
+                          unsigned nsops, int alter)
+{
+       char *ssp = smack_of_sem(sma);
+
+       return smk_curacc(ssp, MAY_READWRITE);
+}
+
+/**
+ * smack_msg_alloc_security - Set the security blob for msg
+ * @msq: the object
+ *
+ * Returns 0
+ */
+static int smack_msg_queue_alloc_security(struct msg_queue *msq)
+{
+       struct kern_ipc_perm *kisp = &msq->q_perm;
+
+       kisp->security = current->security;
+       return 0;
+}
+
+/**
+ * smack_msg_free_security - Clear the security blob for msg
+ * @msq: the object
+ *
+ * Clears the blob pointer
+ */
+static void smack_msg_queue_free_security(struct msg_queue *msq)
+{
+       struct kern_ipc_perm *kisp = &msq->q_perm;
+
+       kisp->security = NULL;
+}
+
+/**
+ * smack_of_msq - the smack pointer for the msq
+ * @msq: the object
+ *
+ * Returns a pointer to the smack value
+ */
+static char *smack_of_msq(struct msg_queue *msq)
+{
+       return (char *)msq->q_perm.security;
+}
+
+/**
+ * smack_msg_queue_associate - Smack access check for msg_queue
+ * @msq: the object
+ * @msqflg: access requested
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
+{
+       char *msp = smack_of_msq(msq);
+       int may;
+
+       may = smack_flags_to_may(msqflg);
+       return smk_curacc(msp, may);
+}
+
+/**
+ * smack_msg_queue_msgctl - Smack access check for msg_queue
+ * @msq: the object
+ * @cmd: what it wants to do
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
+{
+       char *msp = smack_of_msq(msq);
+       int may;
+
+       switch (cmd) {
+       case IPC_STAT:
+       case MSG_STAT:
+               may = MAY_READ;
+               break;
+       case IPC_SET:
+       case IPC_RMID:
+               may = MAY_READWRITE;
+               break;
+       case IPC_INFO:
+       case MSG_INFO:
+               /*
+                * System level information
+                */
+               return 0;
+       default:
+               return -EINVAL;
+       }
+
+       return smk_curacc(msp, may);
+}
+
+/**
+ * smack_msg_queue_msgsnd - Smack access check for msg_queue
+ * @msq: the object
+ * @msg: unused
+ * @msqflg: access requested
+ *
+ * Returns 0 if current has the requested access, error code otherwise
+ */
+static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
+                                 int msqflg)
+{
+       char *msp = smack_of_msq(msq);
+       int rc;
+
+       rc = smack_flags_to_may(msqflg);
+       return smk_curacc(msp, rc);
+}
+
+/**
+ * smack_msg_queue_msgsnd - Smack access check for msg_queue
+ * @msq: the object
+ * @msg: unused
+ * @target: unused
+ * @type: unused
+ * @mode: unused
+ *
+ * Returns 0 if current has read and write access, error code otherwise
+ */
+static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
+                       struct task_struct *target, long type, int mode)
+{
+       char *msp = smack_of_msq(msq);
+
+       return smk_curacc(msp, MAY_READWRITE);
+}
+
+/**
+ * smack_ipc_permission - Smack access for ipc_permission()
+ * @ipp: the object permissions
+ * @flag: access requested
+ *
+ * Returns 0 if current has read and write access, error code otherwise
+ */
+static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
+{
+       char *isp = ipp->security;
+       int may;
+
+       may = smack_flags_to_may(flag);
+       return smk_curacc(isp, may);
+}
+
+/**
+ * smack_d_instantiate - Make sure the blob is correct on an inode
+ * @opt_dentry: unused
+ * @inode: the object
+ *
+ * Set the inode's security blob if it hasn't been done already.
+ */
+static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
+{
+       struct super_block *sbp;
+       struct superblock_smack *sbsp;
+       struct inode_smack *isp;
+       char *csp = current->security;
+       char *fetched;
+       char *final;
+       struct dentry *dp;
+
+       if (inode == NULL)
+               return;
+
+       isp = inode->i_security;
+
+       mutex_lock(&isp->smk_lock);
+       /*
+        * If the inode is already instantiated
+        * take the quick way out
+        */
+       if (isp->smk_flags & SMK_INODE_INSTANT)
+               goto unlockandout;
+
+       sbp = inode->i_sb;
+       sbsp = sbp->s_security;
+       /*
+        * We're going to use the superblock default label
+        * if there's no label on the file.
+        */
+       final = sbsp->smk_default;
+
+       /*
+        * This is pretty hackish.
+        * Casey says that we shouldn't have to do
+        * file system specific code, but it does help
+        * with keeping it simple.
+        */
+       switch (sbp->s_magic) {
+       case SMACK_MAGIC:
+               /*
+                * Casey says that it's a little embarassing
+                * that the smack file system doesn't do
+                * extended attributes.
+                */
+               final = smack_known_star.smk_known;
+               break;
+       case PIPEFS_MAGIC:
+               /*
+                * Casey says pipes are easy (?)
+                */
+               final = smack_known_star.smk_known;
+               break;
+       case DEVPTS_SUPER_MAGIC:
+               /*
+                * devpts seems content with the label of the task.
+                * Programs that change smack have to treat the
+                * pty with respect.
+                */
+               final = csp;
+               break;
+       case SOCKFS_MAGIC:
+               /*
+                * Casey says sockets get the smack of the task.
+                */
+               final = csp;
+               break;
+       case PROC_SUPER_MAGIC:
+               /*
+                * Casey says procfs appears not to care.
+                * The superblock default suffices.
+                */
+               break;
+       case TMPFS_MAGIC:
+               /*
+                * Device labels should come from the filesystem,
+                * but watch out, because they're volitile,
+                * getting recreated on every reboot.
+                */
+               final = smack_known_star.smk_known;
+               /*
+                * No break.
+                *
+                * If a smack value has been set we want to use it,
+                * but since tmpfs isn't giving us the opportunity
+                * to set mount options simulate setting the
+                * superblock default.
+                */
+       default:
+               /*
+                * This isn't an understood special case.
+                * Get the value from the xattr.
+                *
+                * No xattr support means, alas, no SMACK label.
+                * Use the aforeapplied default.
+                * It would be curious if the label of the task
+                * does not match that assigned.
+                */
+               if (inode->i_op->getxattr == NULL)
+                       break;
+               /*
+                * Get the dentry for xattr.
+                */
+               if (opt_dentry == NULL) {
+                       dp = d_find_alias(inode);
+                       if (dp == NULL)
+                               break;
+               } else {
+                       dp = dget(opt_dentry);
+                       if (dp == NULL)
+                               break;
+               }
+
+               fetched = smk_fetch(inode, dp);
+               if (fetched != NULL)
+                       final = fetched;
+
+               dput(dp);
+               break;
+       }
+
+       if (final == NULL)
+               isp->smk_inode = csp;
+       else
+               isp->smk_inode = final;
+
+       isp->smk_flags |= SMK_INODE_INSTANT;
+
+unlockandout:
+       mutex_unlock(&isp->smk_lock);
+       return;
+}
+
+/**
+ * smack_getprocattr - Smack process attribute access
+ * @p: the object task
+ * @name: the name of the attribute in /proc/.../attr
+ * @value: where to put the result
+ *
+ * Places a copy of the task Smack into value
+ *
+ * Returns the length of the smack label or an error code
+ */
+static int smack_getprocattr(struct task_struct *p, char *name, char **value)
+{
+       char *cp;
+       int slen;
+
+       if (strcmp(name, "current") != 0)
+               return -EINVAL;
+
+       cp = kstrdup(p->security, GFP_KERNEL);
+       if (cp == NULL)
+               return -ENOMEM;
+
+       slen = strlen(cp);
+       *value = cp;
+       return slen;
+}
+
+/**
+ * smack_setprocattr - Smack process attribute setting
+ * @p: the object task
+ * @name: the name of the attribute in /proc/.../attr
+ * @value: the value to set
+ * @size: the size of the value
+ *
+ * Sets the Smack value of the task. Only setting self
+ * is permitted and only with privilege
+ *
+ * Returns the length of the smack label or an error code
+ */
+static int smack_setprocattr(struct task_struct *p, char *name,
+                            void *value, size_t size)
+{
+       char *newsmack;
+
+       if (!__capable(p, CAP_MAC_ADMIN))
+               return -EPERM;
+
+       /*
+        * Changing another process' Smack value is too dangerous
+        * and supports no sane use case.
+        */
+       if (p != current)
+               return -EPERM;
+
+       if (value == NULL || size == 0 || size >= SMK_LABELLEN)
+               return -EINVAL;
+
+       if (strcmp(name, "current") != 0)
+               return -EINVAL;
+
+       newsmack = smk_import(value, size);
+       if (newsmack == NULL)
+               return -EINVAL;
+
+       p->security = newsmack;
+       return size;
+}
+
+/**
+ * smack_unix_stream_connect - Smack access on UDS
+ * @sock: one socket
+ * @other: the other socket
+ * @newsk: unused
+ *
+ * Return 0 if a subject with the smack of sock could access
+ * an object with the smack of other, otherwise an error code
+ */
+static int smack_unix_stream_connect(struct socket *sock,
+                                    struct socket *other, struct sock *newsk)
+{
+       struct inode *sp = SOCK_INODE(sock);
+       struct inode *op = SOCK_INODE(other);
+
+       return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_READWRITE);
+}
+
+/**
+ * smack_unix_may_send - Smack access on UDS
+ * @sock: one socket
+ * @other: the other socket
+ *
+ * Return 0 if a subject with the smack of sock could access
+ * an object with the smack of other, otherwise an error code
+ */
+static int smack_unix_may_send(struct socket *sock, struct socket *other)
+{
+       struct inode *sp = SOCK_INODE(sock);
+       struct inode *op = SOCK_INODE(other);
+
+       return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE);
+}
+
+/**
+ * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat
+ *     pair to smack
+ * @sap: netlabel secattr
+ * @sip: where to put the result
+ *
+ * Copies a smack label into sip
+ */
+static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
+{
+       char smack[SMK_LABELLEN];
+       int pcat;
+
+       if ((sap->flags & NETLBL_SECATTR_MLS_LVL) == 0) {
+               /*
+                * If there are flags but no level netlabel isn't
+                * behaving the way we expect it to.
+                *
+                * Without guidance regarding the smack value
+                * for the packet fall back on the network
+                * ambient value.
+                */
+               strncpy(sip, smack_net_ambient, SMK_MAXLEN);
+               return;
+       }
+       /*
+        * Get the categories, if any
+        */
+       memset(smack, '\0', SMK_LABELLEN);
+       if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
+               for (pcat = -1;;) {
+                       pcat = netlbl_secattr_catmap_walk(sap->attr.mls.cat,
+                                                         pcat + 1);
+                       if (pcat < 0)
+                               break;
+                       smack_catset_bit(pcat, smack);
+               }
+       /*
+        * If it is CIPSO using smack direct mapping
+        * we are already done. WeeHee.
+        */
+       if (sap->attr.mls.lvl == smack_cipso_direct) {
+               memcpy(sip, smack, SMK_MAXLEN);
+               return;
+       }
+       /*
+        * Look it up in the supplied table if it is not a direct mapping.
+        */
+       smack_from_cipso(sap->attr.mls.lvl, smack, sip);
+       return;
+}
+
+/**
+ * smack_socket_sock_rcv_skb - Smack packet delivery access check
+ * @sk: socket
+ * @skb: packet
+ *
+ * Returns 0 if the packet should be delivered, an error code otherwise
+ */
+static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
+{
+       struct netlbl_lsm_secattr secattr;
+       struct socket_smack *ssp = sk->sk_security;
+       char smack[SMK_LABELLEN];
+       int rc;
+
+       if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
+               return 0;
+
+       /*
+        * Translate what netlabel gave us.
+        */
+       memset(smack, '\0', SMK_LABELLEN);
+       netlbl_secattr_init(&secattr);
+       rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
+       if (rc == 0)
+               smack_from_secattr(&secattr, smack);
+       else
+               strncpy(smack, smack_net_ambient, SMK_MAXLEN);
+       netlbl_secattr_destroy(&secattr);
+       /*
+        * Receiving a packet requires that the other end
+        * be able to write here. Read access is not required.
+        * This is the simplist possible security model
+        * for networking.
+        */
+       return smk_access(smack, ssp->smk_in, MAY_WRITE);
+}
+
+/**
+ * smack_socket_getpeersec_stream - pull in packet label
+ * @sock: the socket
+ * @optval: user's destination
+ * @optlen: size thereof
+ * @len: max thereoe
+ *
+ * returns zero on success, an error code otherwise
+ */
+static int smack_socket_getpeersec_stream(struct socket *sock,
+                                         char __user *optval,
+                                         int __user *optlen, unsigned len)
+{
+       struct socket_smack *ssp;
+       int slen;
+       int rc = 0;
+
+       ssp = sock->sk->sk_security;
+       slen = strlen(ssp->smk_packet) + 1;
+
+       if (slen > len)
+               rc = -ERANGE;
+       else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
+               rc = -EFAULT;
+
+       if (put_user(slen, optlen) != 0)
+               rc = -EFAULT;
+
+       return rc;
+}
+
+
+/**
+ * smack_socket_getpeersec_dgram - pull in packet label
+ * @sock: the socket
+ * @skb: packet data
+ * @secid: pointer to where to put the secid of the packet
+ *
+ * Sets the netlabel socket state on sk from parent
+ */
+static int smack_socket_getpeersec_dgram(struct socket *sock,
+                                        struct sk_buff *skb, u32 *secid)
+
+{
+       struct netlbl_lsm_secattr secattr;
+       struct sock *sk;
+       char smack[SMK_LABELLEN];
+       int family = PF_INET;
+       u32 s;
+       int rc;
+
+       /*
+        * Only works for families with packets.
+        */
+       if (sock != NULL) {
+               sk = sock->sk;
+               if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
+                       return 0;
+               family = sk->sk_family;
+       }
+       /*
+        * Translate what netlabel gave us.
+        */
+       memset(smack, '\0', SMK_LABELLEN);
+       netlbl_secattr_init(&secattr);
+       rc = netlbl_skbuff_getattr(skb, family, &secattr);
+       if (rc == 0)
+               smack_from_secattr(&secattr, smack);
+       netlbl_secattr_destroy(&secattr);
+
+       /*
+        * Give up if we couldn't get anything
+        */
+       if (rc != 0)
+               return rc;
+
+       s = smack_to_secid(smack);
+       if (s == 0)
+               return -EINVAL;
+
+       *secid = s;
+       return 0;
+}
+
+/**
+ * smack_sock_graft - graft access state between two sockets
+ * @sk: fresh sock
+ * @parent: donor socket
+ *
+ * Sets the netlabel socket state on sk from parent
+ */
+static void smack_sock_graft(struct sock *sk, struct socket *parent)
+{
+       struct socket_smack *ssp;
+       int rc;
+
+       if (sk == NULL)
+               return;
+
+       if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
+               return;
+
+       ssp = sk->sk_security;
+       ssp->smk_in = current->security;
+       ssp->smk_out = current->security;
+       ssp->smk_packet[0] = '\0';
+
+       rc = smack_netlabel(sk);
+}
+
+/**
+ * smack_inet_conn_request - Smack access check on connect
+ * @sk: socket involved
+ * @skb: packet
+ * @req: unused
+ *
+ * Returns 0 if a task with the packet label could write to
+ * the socket, otherwise an error code
+ */
+static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
+                                  struct request_sock *req)
+{
+       struct netlbl_lsm_secattr skb_secattr;
+       struct socket_smack *ssp = sk->sk_security;
+       char smack[SMK_LABELLEN];
+       int rc;
+
+       if (skb == NULL)
+               return -EACCES;
+
+       memset(smack, '\0', SMK_LABELLEN);
+       netlbl_secattr_init(&skb_secattr);
+       rc = netlbl_skbuff_getattr(skb, sk->sk_family, &skb_secattr);
+       if (rc == 0)
+               smack_from_secattr(&skb_secattr, smack);
+       else
+               strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
+       netlbl_secattr_destroy(&skb_secattr);
+       /*
+        * Receiving a packet requires that the other end
+        * be able to write here. Read access is not required.
+        *
+        * If the request is successful save the peer's label
+        * so that SO_PEERCRED can report it.
+        */
+       rc = smk_access(smack, ssp->smk_in, MAY_WRITE);
+       if (rc == 0)
+               strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
+
+       return rc;
+}
+
+/*
+ * Key management security hooks
+ *
+ * Casey has not tested key support very heavily.
+ * The permission check is most likely too restrictive.
+ * If you care about keys please have a look.
+ */
+#ifdef CONFIG_KEYS
+
+/**
+ * smack_key_alloc - Set the key security blob
+ * @key: object
+ * @tsk: the task associated with the key
+ * @flags: unused
+ *
+ * No allocation required
+ *
+ * Returns 0
+ */
+static int smack_key_alloc(struct key *key, struct task_struct *tsk,
+                          unsigned long flags)
+{
+       key->security = tsk->security;
+       return 0;
+}
+
+/**
+ * smack_key_free - Clear the key security blob
+ * @key: the object
+ *
+ * Clear the blob pointer
+ */
+static void smack_key_free(struct key *key)
+{
+       key->security = NULL;
+}
+
+/*
+ * smack_key_permission - Smack access on a key
+ * @key_ref: gets to the object
+ * @context: task involved
+ * @perm: unused
+ *
+ * Return 0 if the task has read and write to the object,
+ * an error code otherwise
+ */
+static int smack_key_permission(key_ref_t key_ref,
+                               struct task_struct *context, key_perm_t perm)
+{
+       struct key *keyp;
+
+       keyp = key_ref_to_ptr(key_ref);
+       if (keyp == NULL)
+               return -EINVAL;
+       /*
+        * If the key hasn't been initialized give it access so that
+        * it may do so.
+        */
+       if (keyp->security == NULL)
+               return 0;
+       /*
+        * This should not occur
+        */
+       if (context->security == NULL)
+               return -EACCES;
+
+       return smk_access(context->security, keyp->security, MAY_READWRITE);
+}
+#endif /* CONFIG_KEYS */
+
+/*
+ * smack_secid_to_secctx - return the smack label for a secid
+ * @secid: incoming integer
+ * @secdata: destination
+ * @seclen: how long it is
+ *
+ * Exists for networking code.
+ */
+static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
+{
+       char *sp = smack_from_secid(secid);
+
+       *secdata = sp;
+       *seclen = strlen(sp);
+       return 0;
+}
+
+/*
+ * smack_release_secctx - don't do anything.
+ * @key_ref: unused
+ * @context: unused
+ * @perm: unused
+ *
+ * Exists to make sure nothing gets done, and properly
+ */
+static void smack_release_secctx(char *secdata, u32 seclen)
+{
+}
+
+static struct security_operations smack_ops = {
+       .ptrace =                       smack_ptrace,
+       .capget =                       cap_capget,
+       .capset_check =                 cap_capset_check,
+       .capset_set =                   cap_capset_set,
+       .capable =                      cap_capable,
+       .syslog =                       smack_syslog,
+       .settime =                      cap_settime,
+       .vm_enough_memory =             cap_vm_enough_memory,
+
+       .bprm_apply_creds =             cap_bprm_apply_creds,
+       .bprm_set_security =            cap_bprm_set_security,
+       .bprm_secureexec =              cap_bprm_secureexec,
+
+       .sb_alloc_security =            smack_sb_alloc_security,
+       .sb_free_security =             smack_sb_free_security,
+       .sb_copy_data =                 smack_sb_copy_data,
+       .sb_kern_mount =                smack_sb_kern_mount,
+       .sb_statfs =                    smack_sb_statfs,
+       .sb_mount =                     smack_sb_mount,
+       .sb_umount =                    smack_sb_umount,
+
+       .inode_alloc_security =         smack_inode_alloc_security,
+       .inode_free_security =          smack_inode_free_security,
+       .inode_init_security =          smack_inode_init_security,
+       .inode_link =                   smack_inode_link,
+       .inode_unlink =                 smack_inode_unlink,
+       .inode_rmdir =                  smack_inode_rmdir,
+       .inode_rename =                 smack_inode_rename,
+       .inode_permission =             smack_inode_permission,
+       .inode_setattr =                smack_inode_setattr,
+       .inode_getattr =                smack_inode_getattr,
+       .inode_setxattr =               smack_inode_setxattr,
+       .inode_post_setxattr =          smack_inode_post_setxattr,
+       .inode_getxattr =               smack_inode_getxattr,
+       .inode_removexattr =            smack_inode_removexattr,
+       .inode_getsecurity =            smack_inode_getsecurity,
+       .inode_setsecurity =            smack_inode_setsecurity,
+       .inode_listsecurity =           smack_inode_listsecurity,
+
+       .file_permission =              smack_file_permission,
+       .file_alloc_security =          smack_file_alloc_security,
+       .file_free_security =           smack_file_free_security,
+       .file_ioctl =                   smack_file_ioctl,
+       .file_lock =                    smack_file_lock,
+       .file_fcntl =                   smack_file_fcntl,
+       .file_set_fowner =              smack_file_set_fowner,
+       .file_send_sigiotask =          smack_file_send_sigiotask,
+       .file_receive =                 smack_file_receive,
+
+       .task_alloc_security =          smack_task_alloc_security,
+       .task_free_security =           smack_task_free_security,
+       .task_post_setuid =             cap_task_post_setuid,
+       .task_setpgid =                 smack_task_setpgid,
+       .task_getpgid =                 smack_task_getpgid,
+       .task_getsid =                  smack_task_getsid,
+       .task_getsecid =                smack_task_getsecid,
+       .task_setnice =                 smack_task_setnice,
+       .task_setioprio =               smack_task_setioprio,
+       .task_getioprio =               smack_task_getioprio,
+       .task_setscheduler =            smack_task_setscheduler,
+       .task_getscheduler =            smack_task_getscheduler,
+       .task_movememory =              smack_task_movememory,
+       .task_kill =                    smack_task_kill,
+       .task_wait =                    smack_task_wait,
+       .task_reparent_to_init =        cap_task_reparent_to_init,
+       .task_to_inode =                smack_task_to_inode,
+
+       .ipc_permission =               smack_ipc_permission,
+
+       .msg_msg_alloc_security =       smack_msg_msg_alloc_security,
+       .msg_msg_free_security =        smack_msg_msg_free_security,
+
+       .msg_queue_alloc_security =     smack_msg_queue_alloc_security,
+       .msg_queue_free_security =      smack_msg_queue_free_security,
+       .msg_queue_associate =          smack_msg_queue_associate,
+       .msg_queue_msgctl =             smack_msg_queue_msgctl,
+       .msg_queue_msgsnd =             smack_msg_queue_msgsnd,
+       .msg_queue_msgrcv =             smack_msg_queue_msgrcv,
+
+       .shm_alloc_security =           smack_shm_alloc_security,
+       .shm_free_security =            smack_shm_free_security,
+       .shm_associate =                smack_shm_associate,
+       .shm_shmctl =                   smack_shm_shmctl,
+       .shm_shmat =                    smack_shm_shmat,
+
+       .sem_alloc_security =           smack_sem_alloc_security,
+       .sem_free_security =            smack_sem_free_security,
+       .sem_associate =                smack_sem_associate,
+       .sem_semctl =                   smack_sem_semctl,
+       .sem_semop =                    smack_sem_semop,
+
+       .netlink_send =                 cap_netlink_send,
+       .netlink_recv =                 cap_netlink_recv,
+
+       .d_instantiate =                smack_d_instantiate,
+
+       .getprocattr =                  smack_getprocattr,
+       .setprocattr =                  smack_setprocattr,
+
+       .unix_stream_connect =          smack_unix_stream_connect,
+       .unix_may_send =                smack_unix_may_send,
+
+       .socket_post_create =           smack_socket_post_create,
+       .socket_sock_rcv_skb =          smack_socket_sock_rcv_skb,
+       .socket_getpeersec_stream =     smack_socket_getpeersec_stream,
+       .socket_getpeersec_dgram =      smack_socket_getpeersec_dgram,
+       .sk_alloc_security =            smack_sk_alloc_security,
+       .sk_free_security =             smack_sk_free_security,
+       .sock_graft =                   smack_sock_graft,
+       .inet_conn_request =            smack_inet_conn_request,
+ /* key management security hooks */
+#ifdef CONFIG_KEYS
+       .key_alloc =                    smack_key_alloc,
+       .key_free =                     smack_key_free,
+       .key_permission =               smack_key_permission,
+#endif /* CONFIG_KEYS */
+       .secid_to_secctx =              smack_secid_to_secctx,
+       .release_secctx =               smack_release_secctx,
+};
+
+/**
+ * smack_init - initialize the smack system
+ *
+ * Returns 0
+ */
+static __init int smack_init(void)
+{
+       printk(KERN_INFO "Smack:  Initializing.\n");
+
+       /*
+        * Set the security state for the initial task.
+        */
+       current->security = &smack_known_floor.smk_known;
+
+       /*
+        * Initialize locks
+        */
+       spin_lock_init(&smack_known_unset.smk_cipsolock);
+       spin_lock_init(&smack_known_huh.smk_cipsolock);
+       spin_lock_init(&smack_known_hat.smk_cipsolock);
+       spin_lock_init(&smack_known_star.smk_cipsolock);
+       spin_lock_init(&smack_known_floor.smk_cipsolock);
+       spin_lock_init(&smack_known_invalid.smk_cipsolock);
+
+       /*
+        * Register with LSM
+        */
+       if (register_security(&smack_ops))
+               panic("smack: Unable to register with kernel.\n");
+
+       return 0;
+}
+
+/*
+ * Smack requires early initialization in order to label
+ * all processes and objects when they are created.
+ */
+security_initcall(smack_init);
+
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
new file mode 100644 (file)
index 0000000..15aa37f
--- /dev/null
@@ -0,0 +1,981 @@
+/*
+ * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation, version 2.
+ *
+ * Authors:
+ *     Casey Schaufler <casey@schaufler-ca.com>
+ *     Ahmed S. Darwish <darwish.07@gmail.com>
+ *
+ * Special thanks to the authors of selinuxfs.
+ *
+ *     Karl MacMillan <kmacmillan@tresys.com>
+ *     James Morris <jmorris@redhat.com>
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/vmalloc.h>
+#include <linux/security.h>
+#include <linux/mutex.h>
+#include <net/netlabel.h>
+#include <net/cipso_ipv4.h>
+#include <linux/seq_file.h>
+#include <linux/ctype.h>
+#include "smack.h"
+
+/*
+ * smackfs pseudo filesystem.
+ */
+
+enum smk_inos {
+       SMK_ROOT_INO    = 2,
+       SMK_LOAD        = 3,    /* load policy */
+       SMK_CIPSO       = 4,    /* load label -> CIPSO mapping */
+       SMK_DOI         = 5,    /* CIPSO DOI */
+       SMK_DIRECT      = 6,    /* CIPSO level indicating direct label */
+       SMK_AMBIENT     = 7,    /* internet ambient label */
+       SMK_NLTYPE      = 8,    /* label scheme to use by default */
+};
+
+/*
+ * List locks
+ */
+static DEFINE_MUTEX(smack_list_lock);
+static DEFINE_MUTEX(smack_cipso_lock);
+
+/*
+ * This is the "ambient" label for network traffic.
+ * If it isn't somehow marked, use this.
+ * It can be reset via smackfs/ambient
+ */
+char *smack_net_ambient = smack_known_floor.smk_known;
+
+/*
+ * This is the default packet marking scheme for network traffic.
+ * It can be reset via smackfs/nltype
+ */
+int smack_net_nltype = NETLBL_NLTYPE_CIPSOV4;
+
+/*
+ * This is the level in a CIPSO header that indicates a
+ * smack label is contained directly in the category set.
+ * It can be reset via smackfs/direct
+ */
+int smack_cipso_direct = SMACK_CIPSO_DIRECT_DEFAULT;
+
+static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
+struct smk_list_entry *smack_list;
+
+#define        SEQ_READ_FINISHED       1
+
+/*
+ * Disable concurrent writing open() operations
+ */
+static struct semaphore smack_write_sem;
+
+/*
+ * Values for parsing cipso rules
+ * SMK_DIGITLEN: Length of a digit field in a rule.
+ * SMK_CIPSOMEN: Minimum possible cipso rule length.
+ */
+#define SMK_DIGITLEN 4
+#define SMK_CIPSOMIN (SMK_MAXLEN + 2 * SMK_DIGITLEN)
+
+/*
+ * Seq_file read operations for /smack/load
+ */
+
+static void *load_seq_start(struct seq_file *s, loff_t *pos)
+{
+       if (*pos == SEQ_READ_FINISHED)
+               return NULL;
+
+       return smack_list;
+}
+
+static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+       struct smk_list_entry *skp = ((struct smk_list_entry *) v)->smk_next;
+
+       if (skp == NULL)
+               *pos = SEQ_READ_FINISHED;
+
+       return skp;
+}
+
+static int load_seq_show(struct seq_file *s, void *v)
+{
+       struct smk_list_entry *slp = (struct smk_list_entry *) v;
+       struct smack_rule *srp = &slp->smk_rule;
+
+       seq_printf(s, "%s %s", (char *)srp->smk_subject,
+                  (char *)srp->smk_object);
+
+       seq_putc(s, ' ');
+
+       if (srp->smk_access & MAY_READ)
+               seq_putc(s, 'r');
+       if (srp->smk_access & MAY_WRITE)
+               seq_putc(s, 'w');
+       if (srp->smk_access & MAY_EXEC)
+               seq_putc(s, 'x');
+       if (srp->smk_access & MAY_APPEND)
+               seq_putc(s, 'a');
+       if (srp->smk_access == 0)
+               seq_putc(s, '-');
+
+       seq_putc(s, '\n');
+
+       return 0;
+}
+
+static void load_seq_stop(struct seq_file *s, void *v)
+{
+       /* No-op */
+}
+
+static struct seq_operations load_seq_ops = {
+       .start = load_seq_start,
+       .next  = load_seq_next,
+       .show  = load_seq_show,
+       .stop  = load_seq_stop,
+};
+
+/**
+ * smk_open_load - open() for /smack/load
+ * @inode: inode structure representing file
+ * @file: "load" file pointer
+ *
+ * For reading, use load_seq_* seq_file reading operations.
+ */
+static int smk_open_load(struct inode *inode, struct file *file)
+{
+       if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+               return seq_open(file, &load_seq_ops);
+
+       if (down_interruptible(&smack_write_sem))
+               return -ERESTARTSYS;
+
+       return 0;
+}
+
+/**
+ * smk_release_load - release() for /smack/load
+ * @inode: inode structure representing file
+ * @file: "load" file pointer
+ *
+ * For a reading session, use the seq_file release
+ * implementation.
+ * Otherwise, we are at the end of a writing session so
+ * clean everything up.
+ */
+static int smk_release_load(struct inode *inode, struct file *file)
+{
+       if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+               return seq_release(inode, file);
+
+       up(&smack_write_sem);
+       return 0;
+}
+
+/**
+ * smk_set_access - add a rule to the rule list
+ * @srp: the new rule to add
+ *
+ * Looks through the current subject/object/access list for
+ * the subject/object pair and replaces the access that was
+ * there. If the pair isn't found add it with the specified
+ * access.
+ */
+static void smk_set_access(struct smack_rule *srp)
+{
+       struct smk_list_entry *sp;
+       struct smk_list_entry *newp;
+
+       mutex_lock(&smack_list_lock);
+
+       for (sp = smack_list; sp != NULL; sp = sp->smk_next)
+               if (sp->smk_rule.smk_subject == srp->smk_subject &&
+                   sp->smk_rule.smk_object == srp->smk_object) {
+                       sp->smk_rule.smk_access = srp->smk_access;
+                       break;
+               }
+
+       if (sp == NULL) {
+               newp = kzalloc(sizeof(struct smk_list_entry), GFP_KERNEL);
+               newp->smk_rule = *srp;
+               newp->smk_next = smack_list;
+               smack_list = newp;
+       }
+
+       mutex_unlock(&smack_list_lock);
+
+       return;
+}
+
+/**
+ * smk_write_load - write() for /smack/load
+ * @filp: file pointer, not actually used
+ * @buf: where to get the data from
+ * @count: bytes sent
+ * @ppos: where to start - must be 0
+ *
+ * Get one smack access rule from above.
+ * The format is exactly:
+ *     char subject[SMK_LABELLEN]
+ *     char object[SMK_LABELLEN]
+ *     char access[SMK_ACCESSKINDS]
+ *
+ *     Anything following is commentary and ignored.
+ *
+ * writes must be SMK_LABELLEN+SMK_LABELLEN+4 bytes.
+ */
+#define MINIMUM_LOAD (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSKINDS)
+
+static ssize_t smk_write_load(struct file *file, const char __user *buf,
+                             size_t count, loff_t *ppos)
+{
+       struct smack_rule rule;
+       char *data;
+       int rc = -EINVAL;
+
+       /*
+        * Must have privilege.
+        * No partial writes.
+        * Enough data must be present.
+        */
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       if (*ppos != 0)
+               return -EINVAL;
+       if (count < MINIMUM_LOAD)
+               return -EINVAL;
+
+       data = kzalloc(count, GFP_KERNEL);
+       if (data == NULL)
+               return -ENOMEM;
+
+       if (copy_from_user(data, buf, count) != 0) {
+               rc = -EFAULT;
+               goto out;
+       }
+
+       rule.smk_subject = smk_import(data, 0);
+       if (rule.smk_subject == NULL)
+               goto out;
+
+       rule.smk_object = smk_import(data + SMK_LABELLEN, 0);
+       if (rule.smk_object == NULL)
+               goto out;
+
+       rule.smk_access = 0;
+
+       switch (data[SMK_LABELLEN + SMK_LABELLEN]) {
+       case '-':
+               break;
+       case 'r':
+       case 'R':
+               rule.smk_access |= MAY_READ;
+               break;
+       default:
+               goto out;
+       }
+
+       switch (data[SMK_LABELLEN + SMK_LABELLEN + 1]) {
+       case '-':
+               break;
+       case 'w':
+       case 'W':
+               rule.smk_access |= MAY_WRITE;
+               break;
+       default:
+               goto out;
+       }
+
+       switch (data[SMK_LABELLEN + SMK_LABELLEN + 2]) {
+       case '-':
+               break;
+       case 'x':
+       case 'X':
+               rule.smk_access |= MAY_EXEC;
+               break;
+       default:
+               goto out;
+       }
+
+       switch (data[SMK_LABELLEN + SMK_LABELLEN + 3]) {
+       case '-':
+               break;
+       case 'a':
+       case 'A':
+               rule.smk_access |= MAY_READ;
+               break;
+       default:
+               goto out;
+       }
+
+       smk_set_access(&rule);
+       rc = count;
+
+out:
+       kfree(data);
+       return rc;
+}
+
+static const struct file_operations smk_load_ops = {
+       .open           = smk_open_load,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .write          = smk_write_load,
+       .release        = smk_release_load,
+};
+
+/**
+ * smk_cipso_doi - initialize the CIPSO domain
+ */
+void smk_cipso_doi(void)
+{
+       int rc;
+       struct cipso_v4_doi *doip;
+       struct netlbl_audit audit_info;
+
+       rc = netlbl_cfg_map_del(NULL, &audit_info);
+       if (rc != 0)
+               printk(KERN_WARNING "%s:%d remove rc = %d\n",
+                      __func__, __LINE__, rc);
+
+       doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL);
+       if (doip == NULL)
+               panic("smack:  Failed to initialize cipso DOI.\n");
+       doip->map.std = NULL;
+       doip->doi = smk_cipso_doi_value;
+       doip->type = CIPSO_V4_MAP_PASS;
+       doip->tags[0] = CIPSO_V4_TAG_RBITMAP;
+       for (rc = 1; rc < CIPSO_V4_TAG_MAXCNT; rc++)
+               doip->tags[rc] = CIPSO_V4_TAG_INVALID;
+
+       rc = netlbl_cfg_cipsov4_add_map(doip, NULL, &audit_info);
+       if (rc != 0)
+               printk(KERN_WARNING "%s:%d add rc = %d\n",
+                      __func__, __LINE__, rc);
+}
+
+/*
+ * Seq_file read operations for /smack/cipso
+ */
+
+static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
+{
+       if (*pos == SEQ_READ_FINISHED)
+               return NULL;
+
+       return smack_known;
+}
+
+static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+       struct smack_known *skp = ((struct smack_known *) v)->smk_next;
+
+       /*
+        * Omit labels with no associated cipso value
+        */
+       while (skp != NULL && !skp->smk_cipso)
+               skp = skp->smk_next;
+
+       if (skp == NULL)
+               *pos = SEQ_READ_FINISHED;
+
+       return skp;
+}
+
+/*
+ * Print cipso labels in format:
+ * label level[/cat[,cat]]
+ */
+static int cipso_seq_show(struct seq_file *s, void *v)
+{
+       struct smack_known *skp = (struct smack_known *) v;
+       struct smack_cipso *scp = skp->smk_cipso;
+       char *cbp;
+       char sep = '/';
+       int cat = 1;
+       int i;
+       unsigned char m;
+
+       if (scp == NULL)
+               return 0;
+
+       seq_printf(s, "%s %3d", (char *)&skp->smk_known, scp->smk_level);
+
+       cbp = scp->smk_catset;
+       for (i = 0; i < SMK_LABELLEN; i++)
+               for (m = 0x80; m != 0; m >>= 1) {
+                       if (m & cbp[i]) {
+                               seq_printf(s, "%c%d", sep, cat);
+                               sep = ',';
+                       }
+                       cat++;
+               }
+
+       seq_putc(s, '\n');
+
+       return 0;
+}
+
+static void cipso_seq_stop(struct seq_file *s, void *v)
+{
+       /* No-op */
+}
+
+static struct seq_operations cipso_seq_ops = {
+       .start = cipso_seq_start,
+       .stop  = cipso_seq_stop,
+       .next  = cipso_seq_next,
+       .show  = cipso_seq_show,
+};
+
+/**
+ * smk_open_cipso - open() for /smack/cipso
+ * @inode: inode structure representing file
+ * @file: "cipso" file pointer
+ *
+ * Connect our cipso_seq_* operations with /smack/cipso
+ * file_operations
+ */
+static int smk_open_cipso(struct inode *inode, struct file *file)
+{
+       return seq_open(file, &cipso_seq_ops);
+}
+
+/**
+ * smk_write_cipso - write() for /smack/cipso
+ * @filp: file pointer, not actually used
+ * @buf: where to get the data from
+ * @count: bytes sent
+ * @ppos: where to start
+ *
+ * Accepts only one cipso rule per write call.
+ * Returns number of bytes written or error code, as appropriate
+ */
+static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
+                              size_t count, loff_t *ppos)
+{
+       struct smack_known *skp;
+       struct smack_cipso *scp = NULL;
+       char mapcatset[SMK_LABELLEN];
+       int maplevel;
+       int cat;
+       int catlen;
+       ssize_t rc = -EINVAL;
+       char *data = NULL;
+       char *rule;
+       int ret;
+       int i;
+
+       /*
+        * Must have privilege.
+        * No partial writes.
+        * Enough data must be present.
+        */
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       if (*ppos != 0)
+               return -EINVAL;
+       if (count <= SMK_CIPSOMIN)
+               return -EINVAL;
+
+       data = kzalloc(count + 1, GFP_KERNEL);
+       if (data == NULL)
+               return -ENOMEM;
+
+       if (copy_from_user(data, buf, count) != 0) {
+               rc = -EFAULT;
+               goto unlockedout;
+       }
+
+       data[count] = '\0';
+       rule = data;
+       /*
+        * Only allow one writer at a time. Writes should be
+        * quite rare and small in any case.
+        */
+       mutex_lock(&smack_cipso_lock);
+
+       skp = smk_import_entry(rule, 0);
+       if (skp == NULL)
+               goto out;
+
+       rule += SMK_LABELLEN;;
+       ret = sscanf(rule, "%d", &maplevel);
+       if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
+               goto out;
+
+       rule += SMK_DIGITLEN;
+       ret = sscanf(rule, "%d", &catlen);
+       if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
+               goto out;
+
+       if (count <= (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
+               goto out;
+
+       memset(mapcatset, 0, sizeof(mapcatset));
+
+       for (i = 0; i < catlen; i++) {
+               rule += SMK_DIGITLEN;
+               ret = sscanf(rule, "%d", &cat);
+               if (ret != 1 || cat > SMACK_CIPSO_MAXCATVAL)
+                       goto out;
+
+               smack_catset_bit(cat, mapcatset);
+       }
+
+       if (skp->smk_cipso == NULL) {
+               scp = kzalloc(sizeof(struct smack_cipso), GFP_KERNEL);
+               if (scp == NULL) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
+       }
+
+       spin_lock_bh(&skp->smk_cipsolock);
+
+       if (scp == NULL)
+               scp = skp->smk_cipso;
+       else
+               skp->smk_cipso = scp;
+
+       scp->smk_level = maplevel;
+       memcpy(scp->smk_catset, mapcatset, sizeof(mapcatset));
+
+       spin_unlock_bh(&skp->smk_cipsolock);
+
+       rc = count;
+out:
+       mutex_unlock(&smack_cipso_lock);
+unlockedout:
+       kfree(data);
+       return rc;
+}
+
+static const struct file_operations smk_cipso_ops = {
+       .open           = smk_open_cipso,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .write          = smk_write_cipso,
+       .release        = seq_release,
+};
+
+/**
+ * smk_read_doi - read() for /smack/doi
+ * @filp: file pointer, not actually used
+ * @buf: where to put the result
+ * @count: maximum to send along
+ * @ppos: where to start
+ *
+ * Returns number of bytes read or error code, as appropriate
+ */
+static ssize_t smk_read_doi(struct file *filp, char __user *buf,
+                           size_t count, loff_t *ppos)
+{
+       char temp[80];
+       ssize_t rc;
+
+       if (*ppos != 0)
+               return 0;
+
+       sprintf(temp, "%d", smk_cipso_doi_value);
+       rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
+
+       return rc;
+}
+
+/**
+ * smk_write_doi - write() for /smack/doi
+ * @filp: file pointer, not actually used
+ * @buf: where to get the data from
+ * @count: bytes sent
+ * @ppos: where to start
+ *
+ * Returns number of bytes written or error code, as appropriate
+ */
+static ssize_t smk_write_doi(struct file *file, const char __user *buf,
+                            size_t count, loff_t *ppos)
+{
+       char temp[80];
+       int i;
+
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (count >= sizeof(temp) || count == 0)
+               return -EINVAL;
+
+       if (copy_from_user(temp, buf, count) != 0)
+               return -EFAULT;
+
+       temp[count] = '\0';
+
+       if (sscanf(temp, "%d", &i) != 1)
+               return -EINVAL;
+
+       smk_cipso_doi_value = i;
+
+       smk_cipso_doi();
+
+       return count;
+}
+
+static const struct file_operations smk_doi_ops = {
+       .read           = smk_read_doi,
+       .write          = smk_write_doi,
+};
+
+/**
+ * smk_read_direct - read() for /smack/direct
+ * @filp: file pointer, not actually used
+ * @buf: where to put the result
+ * @count: maximum to send along
+ * @ppos: where to start
+ *
+ * Returns number of bytes read or error code, as appropriate
+ */
+static ssize_t smk_read_direct(struct file *filp, char __user *buf,
+                              size_t count, loff_t *ppos)
+{
+       char temp[80];
+       ssize_t rc;
+
+       if (*ppos != 0)
+               return 0;
+
+       sprintf(temp, "%d", smack_cipso_direct);
+       rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
+
+       return rc;
+}
+
+/**
+ * smk_write_direct - write() for /smack/direct
+ * @filp: file pointer, not actually used
+ * @buf: where to get the data from
+ * @count: bytes sent
+ * @ppos: where to start
+ *
+ * Returns number of bytes written or error code, as appropriate
+ */
+static ssize_t smk_write_direct(struct file *file, const char __user *buf,
+                               size_t count, loff_t *ppos)
+{
+       char temp[80];
+       int i;
+
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (count >= sizeof(temp) || count == 0)
+               return -EINVAL;
+
+       if (copy_from_user(temp, buf, count) != 0)
+               return -EFAULT;
+
+       temp[count] = '\0';
+
+       if (sscanf(temp, "%d", &i) != 1)
+               return -EINVAL;
+
+       smack_cipso_direct = i;
+
+       return count;
+}
+
+static const struct file_operations smk_direct_ops = {
+       .read           = smk_read_direct,
+       .write          = smk_write_direct,
+};
+
+/**
+ * smk_read_ambient - read() for /smack/ambient
+ * @filp: file pointer, not actually used
+ * @buf: where to put the result
+ * @cn: maximum to send along
+ * @ppos: where to start
+ *
+ * Returns number of bytes read or error code, as appropriate
+ */
+static ssize_t smk_read_ambient(struct file *filp, char __user *buf,
+                               size_t cn, loff_t *ppos)
+{
+       ssize_t rc;
+       char out[SMK_LABELLEN];
+       int asize;
+
+       if (*ppos != 0)
+               return 0;
+       /*
+        * Being careful to avoid a problem in the case where
+        * smack_net_ambient gets changed in midstream.
+        * Since smack_net_ambient is always set with a value
+        * from the label list, including initially, and those
+        * never get freed, the worst case is that the pointer
+        * gets changed just after this strncpy, in which case
+        * the value passed up is incorrect. Locking around
+        * smack_net_ambient wouldn't be any better than this
+        * copy scheme as by the time the caller got to look
+        * at the ambient value it would have cleared the lock
+        * and been changed.
+        */
+       strncpy(out, smack_net_ambient, SMK_LABELLEN);
+       asize = strlen(out) + 1;
+
+       if (cn < asize)
+               return -EINVAL;
+
+       rc = simple_read_from_buffer(buf, cn, ppos, out, asize);
+
+       return rc;
+}
+
+/**
+ * smk_write_ambient - write() for /smack/ambient
+ * @filp: file pointer, not actually used
+ * @buf: where to get the data from
+ * @count: bytes sent
+ * @ppos: where to start
+ *
+ * Returns number of bytes written or error code, as appropriate
+ */
+static ssize_t smk_write_ambient(struct file *file, const char __user *buf,
+                                size_t count, loff_t *ppos)
+{
+       char in[SMK_LABELLEN];
+       char *smack;
+
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (count >= SMK_LABELLEN)
+               return -EINVAL;
+
+       if (copy_from_user(in, buf, count) != 0)
+               return -EFAULT;
+
+       smack = smk_import(in, count);
+       if (smack == NULL)
+               return -EINVAL;
+
+       smack_net_ambient = smack;
+
+       return count;
+}
+
+static const struct file_operations smk_ambient_ops = {
+       .read           = smk_read_ambient,
+       .write          = smk_write_ambient,
+};
+
+struct option_names {
+       int     o_number;
+       char    *o_name;
+       char    *o_alias;
+};
+
+static struct option_names netlbl_choices[] = {
+       { NETLBL_NLTYPE_RIPSO,
+               NETLBL_NLTYPE_RIPSO_NAME,       "ripso" },
+       { NETLBL_NLTYPE_CIPSOV4,
+               NETLBL_NLTYPE_CIPSOV4_NAME,     "cipsov4" },
+       { NETLBL_NLTYPE_CIPSOV4,
+               NETLBL_NLTYPE_CIPSOV4_NAME,     "cipso" },
+       { NETLBL_NLTYPE_CIPSOV6,
+               NETLBL_NLTYPE_CIPSOV6_NAME,     "cipsov6" },
+       { NETLBL_NLTYPE_UNLABELED,
+               NETLBL_NLTYPE_UNLABELED_NAME,   "unlabeled" },
+};
+
+/**
+ * smk_read_nltype - read() for /smack/nltype
+ * @filp: file pointer, not actually used
+ * @buf: where to put the result
+ * @count: maximum to send along
+ * @ppos: where to start
+ *
+ * Returns number of bytes read or error code, as appropriate
+ */
+static ssize_t smk_read_nltype(struct file *filp, char __user *buf,
+                              size_t count, loff_t *ppos)
+{
+       char bound[40];
+       ssize_t rc;
+       int i;
+
+       if (count < SMK_LABELLEN)
+               return -EINVAL;
+
+       if (*ppos != 0)
+               return 0;
+
+       sprintf(bound, "unknown");
+
+       for (i = 0; i < ARRAY_SIZE(netlbl_choices); i++)
+               if (smack_net_nltype == netlbl_choices[i].o_number) {
+                       sprintf(bound, "%s", netlbl_choices[i].o_name);
+                       break;
+               }
+
+       rc = simple_read_from_buffer(buf, count, ppos, bound, strlen(bound));
+
+       return rc;
+}
+
+/**
+ * smk_write_nltype - write() for /smack/nltype
+ * @filp: file pointer, not actually used
+ * @buf: where to get the data from
+ * @count: bytes sent
+ * @ppos: where to start
+ *
+ * Returns number of bytes written or error code, as appropriate
+ */
+static ssize_t smk_write_nltype(struct file *file, const char __user *buf,
+                               size_t count, loff_t *ppos)
+{
+       char bound[40];
+       char *cp;
+       int i;
+
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (count >= 40)
+               return -EINVAL;
+
+       if (copy_from_user(bound, buf, count) != 0)
+               return -EFAULT;
+
+       bound[count] = '\0';
+       cp = strchr(bound, ' ');
+       if (cp != NULL)
+               *cp = '\0';
+       cp = strchr(bound, '\n');
+       if (cp != NULL)
+               *cp = '\0';
+
+       for (i = 0; i < ARRAY_SIZE(netlbl_choices); i++)
+               if (strcmp(bound, netlbl_choices[i].o_name) == 0 ||
+                   strcmp(bound, netlbl_choices[i].o_alias) == 0) {
+                       smack_net_nltype = netlbl_choices[i].o_number;
+                       return count;
+               }
+       /*
+        * Not a valid choice.
+        */
+       return -EINVAL;
+}
+
+static const struct file_operations smk_nltype_ops = {
+       .read           = smk_read_nltype,
+       .write          = smk_write_nltype,
+};
+
+/**
+ * smk_fill_super - fill the /smackfs superblock
+ * @sb: the empty superblock
+ * @data: unused
+ * @silent: unused
+ *
+ * Fill in the well known entries for /smack
+ *
+ * Returns 0 on success, an error code on failure
+ */
+static int smk_fill_super(struct super_block *sb, void *data, int silent)
+{
+       int rc;
+       struct inode *root_inode;
+
+       static struct tree_descr smack_files[] = {
+               [SMK_LOAD]      =
+                       {"load", &smk_load_ops, S_IRUGO|S_IWUSR},
+               [SMK_CIPSO]     =
+                       {"cipso", &smk_cipso_ops, S_IRUGO|S_IWUSR},
+               [SMK_DOI]       =
+                       {"doi", &smk_doi_ops, S_IRUGO|S_IWUSR},
+               [SMK_DIRECT]    =
+                       {"direct", &smk_direct_ops, S_IRUGO|S_IWUSR},
+               [SMK_AMBIENT]   =
+                       {"ambient", &smk_ambient_ops, S_IRUGO|S_IWUSR},
+               [SMK_NLTYPE]    =
+                       {"nltype", &smk_nltype_ops, S_IRUGO|S_IWUSR},
+               /* last one */ {""}
+       };
+
+       rc = simple_fill_super(sb, SMACK_MAGIC, smack_files);
+       if (rc != 0) {
+               printk(KERN_ERR "%s failed %d while creating inodes\n",
+                       __func__, rc);
+               return rc;
+       }
+
+       root_inode = sb->s_root->d_inode;
+       root_inode->i_security = new_inode_smack(smack_known_floor.smk_known);
+
+       return 0;
+}
+
+/**
+ * smk_get_sb - get the smackfs superblock
+ * @fs_type: passed along without comment
+ * @flags: passed along without comment
+ * @dev_name: passed along without comment
+ * @data: passed along without comment
+ * @mnt: passed along without comment
+ *
+ * Just passes everything along.
+ *
+ * Returns what the lower level code does.
+ */
+static int smk_get_sb(struct file_system_type *fs_type,
+                     int flags, const char *dev_name, void *data,
+                     struct vfsmount *mnt)
+{
+       return get_sb_single(fs_type, flags, data, smk_fill_super, mnt);
+}
+
+static struct file_system_type smk_fs_type = {
+       .name           = "smackfs",
+       .get_sb         = smk_get_sb,
+       .kill_sb        = kill_litter_super,
+};
+
+static struct vfsmount *smackfs_mount;
+
+/**
+ * init_smk_fs - get the smackfs superblock
+ *
+ * register the smackfs
+ *
+ * Returns 0 unless the registration fails.
+ */
+static int __init init_smk_fs(void)
+{
+       int err;
+
+       err = register_filesystem(&smk_fs_type);
+       if (!err) {
+               smackfs_mount = kern_mount(&smk_fs_type);
+               if (IS_ERR(smackfs_mount)) {
+                       printk(KERN_ERR "smackfs:  could not mount!\n");
+                       err = PTR_ERR(smackfs_mount);
+                       smackfs_mount = NULL;
+               }
+       }
+
+       sema_init(&smack_write_sem, 1);
+       smk_cipso_doi();
+
+       return err;
+}
+
+__initcall(init_smk_fs);
index 62449117ee14f6a13cc0f76d5bba6624df3596b9..61f5d425b6305660e8cd3bf514664c1f9b225c58 100644 (file)
@@ -23,7 +23,7 @@
 #include <linux/file.h>
 #include <linux/slab.h>
 #include <linux/time.h>
-#include <linux/latency.h>
+#include <linux/pm_qos_params.h>
 #include <linux/uio.h>
 #include <sound/core.h>
 #include <sound/control.h>
@@ -443,9 +443,11 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
        snd_pcm_timer_resolution_change(substream);
        runtime->status->state = SNDRV_PCM_STATE_SETUP;
 
-       remove_acceptable_latency(substream->latency_id);
+       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY,
+                               substream->latency_id);
        if ((usecs = period_to_usecs(runtime)) >= 0)
-               set_acceptable_latency(substream->latency_id, usecs);
+               pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY,
+                                       substream->latency_id, usecs);
        return 0;
  _error:
        /* hardware might be unuseable from this time,
@@ -505,7 +507,8 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
        if (substream->ops->hw_free)
                result = substream->ops->hw_free(substream);
        runtime->status->state = SNDRV_PCM_STATE_OPEN;
-       remove_acceptable_latency(substream->latency_id);
+       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY,
+               substream->latency_id);
        return result;
 }
 
index f883c4b676abaed9ca308376b032d8fbdbd37903..1f86299fae409a297154737002f4466782cc597f 100644 (file)
@@ -6,7 +6,6 @@
 # Each configuration option enables a list of files.
 
 obj-$(CONFIG_SOUND_OSS)                += sound.o
-obj-$(CONFIG_SOUND_CS4232)     += cs4232.o ad1848.o 
 
 # Please leave it as is, cause the link order is significant !
 
@@ -16,7 +15,6 @@ obj-$(CONFIG_SOUND_AEDSP16)   += aedsp16.o
 obj-$(CONFIG_SOUND_PSS)                += pss.o ad1848.o mpu401.o
 obj-$(CONFIG_SOUND_TRIX)       += trix.o ad1848.o sb_lib.o uart401.o
 obj-$(CONFIG_SOUND_SSCAPE)     += sscape.o ad1848.o mpu401.o
-obj-$(CONFIG_SOUND_CS4232)     += cs4232.o uart401.o
 obj-$(CONFIG_SOUND_MSS)                += ad1848.o
 obj-$(CONFIG_SOUND_PAS)                += pas2.o sb.o sb_lib.o uart401.o
 obj-$(CONFIG_SOUND_SB)         += sb.o sb_lib.o uart401.o
@@ -27,19 +25,12 @@ obj-$(CONFIG_SOUND_YM3812)  += opl3.o
 obj-$(CONFIG_SOUND_VMIDI)      += v_midi.o
 obj-$(CONFIG_SOUND_VIDC)       += vidc_mod.o
 obj-$(CONFIG_SOUND_WAVEARTIST) += waveartist.o
-
-obj-$(CONFIG_SOUND_VIA82CXXX)  += via82cxxx_audio.o ac97_codec.o
-ifeq ($(CONFIG_MIDI_VIA82CXXX),y)
-  obj-$(CONFIG_SOUND_VIA82CXXX) += sound.o uart401.o
-endif
 obj-$(CONFIG_SOUND_MSNDCLAS)   += msnd.o msnd_classic.o
 obj-$(CONFIG_SOUND_MSNDPIN)    += msnd.o msnd_pinnacle.o
 obj-$(CONFIG_SOUND_VWSND)      += vwsnd.o
-obj-$(CONFIG_SOUND_ICH)                += i810_audio.o ac97_codec.o
 obj-$(CONFIG_SOUND_AU1550_AC97)        += au1550_ac97.o ac97_codec.o
 obj-$(CONFIG_SOUND_TRIDENT)    += trident.o ac97_codec.o
 obj-$(CONFIG_SOUND_BCM_CS4297A)        += swarm_cs4297a.o
-obj-$(CONFIG_SOUND_BT878)      += btaudio.o
 
 obj-$(CONFIG_SOUND_WM97XX)     += ac97_plugin_wm97xx.o
 
index fef56cac06c832650db596299af04185dc9919dc..87a672680761305330366b68091877db6cdbc544 100644 (file)
@@ -189,42 +189,6 @@ static const struct {
        {0x57454301, "Winbond 83971D",          &null_ops},
 };
 
-static const char *ac97_stereo_enhancements[] =
-{
-       /*   0 */ "No 3D Stereo Enhancement",
-       /*   1 */ "Analog Devices Phat Stereo",
-       /*   2 */ "Creative Stereo Enhancement",
-       /*   3 */ "National Semi 3D Stereo Enhancement",
-       /*   4 */ "YAMAHA Ymersion",
-       /*   5 */ "BBE 3D Stereo Enhancement",
-       /*   6 */ "Crystal Semi 3D Stereo Enhancement",
-       /*   7 */ "Qsound QXpander",
-       /*   8 */ "Spatializer 3D Stereo Enhancement",
-       /*   9 */ "SRS 3D Stereo Enhancement",
-       /*  10 */ "Platform Tech 3D Stereo Enhancement",
-       /*  11 */ "AKM 3D Audio",
-       /*  12 */ "Aureal Stereo Enhancement",
-       /*  13 */ "Aztech 3D Enhancement",
-       /*  14 */ "Binaura 3D Audio Enhancement",
-       /*  15 */ "ESS Technology Stereo Enhancement",
-       /*  16 */ "Harman International VMAx",
-       /*  17 */ "Nvidea 3D Stereo Enhancement",
-       /*  18 */ "Philips Incredible Sound",
-       /*  19 */ "Texas Instruments 3D Stereo Enhancement",
-       /*  20 */ "VLSI Technology 3D Stereo Enhancement",
-       /*  21 */ "TriTech 3D Stereo Enhancement",
-       /*  22 */ "Realtek 3D Stereo Enhancement",
-       /*  23 */ "Samsung 3D Stereo Enhancement",
-       /*  24 */ "Wolfson Microelectronics 3D Enhancement",
-       /*  25 */ "Delta Integration 3D Enhancement",
-       /*  26 */ "SigmaTel 3D Enhancement",
-       /*  27 */ "Winbond 3D Stereo Enhancement",
-       /*  28 */ "Rockwell 3D Stereo Enhancement",
-       /*  29 */ "Reserved 29",
-       /*  30 */ "Reserved 30",
-       /*  31 */ "Reserved 31"
-};
-
 /* this table has default mixer values for all OSS mixers. */
 static struct mixer_defaults {
        int mixer;
@@ -614,83 +578,6 @@ static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned
        return -EINVAL;
 }
 
-/* entry point for /proc/driver/controller_vendor/ac97/%d */
-int ac97_read_proc (char *page, char **start, off_t off,
-                   int count, int *eof, void *data)
-{
-       int len = 0, cap, extid, val, id1, id2;
-       struct ac97_codec *codec;
-       int is_ac97_20 = 0;
-
-       if ((codec = data) == NULL)
-               return -ENODEV;
-
-       id1 = codec->codec_read(codec, AC97_VENDOR_ID1);
-       id2 = codec->codec_read(codec, AC97_VENDOR_ID2);
-       len += sprintf (page+len, "Vendor name      : %s\n", codec->name);
-       len += sprintf (page+len, "Vendor id        : %04X %04X\n", id1, id2);
-
-       extid = codec->codec_read(codec, AC97_EXTENDED_ID);
-       extid &= ~((1<<2)|(1<<4)|(1<<5)|(1<<10)|(1<<11)|(1<<12)|(1<<13));
-       len += sprintf (page+len, "AC97 Version     : %s\n",
-                       extid ? "2.0 or later" : "1.0");
-       if (extid) is_ac97_20 = 1;
-
-       cap = codec->codec_read(codec, AC97_RESET);
-       len += sprintf (page+len, "Capabilities     :%s%s%s%s%s%s\n",
-                       cap & 0x0001 ? " -dedicated MIC PCM IN channel-" : "",
-                       cap & 0x0002 ? " -reserved1-" : "",
-                       cap & 0x0004 ? " -bass & treble-" : "",
-                       cap & 0x0008 ? " -simulated stereo-" : "",
-                       cap & 0x0010 ? " -headphone out-" : "",
-                       cap & 0x0020 ? " -loudness-" : "");
-       val = cap & 0x00c0;
-       len += sprintf (page+len, "DAC resolutions  :%s%s%s\n",
-                       " -16-bit-",
-                       val & 0x0040 ? " -18-bit-" : "",
-                       val & 0x0080 ? " -20-bit-" : "");
-       val = cap & 0x0300;
-       len += sprintf (page+len, "ADC resolutions  :%s%s%s\n",
-                       " -16-bit-",
-                       val & 0x0100 ? " -18-bit-" : "",
-                       val & 0x0200 ? " -20-bit-" : "");
-       len += sprintf (page+len, "3D enhancement   : %s\n",
-                       ac97_stereo_enhancements[(cap >> 10) & 0x1f]);
-
-       val = codec->codec_read(codec, AC97_GENERAL_PURPOSE);
-       len += sprintf (page+len, "POP path         : %s 3D\n"
-                       "Sim. stereo      : %s\n"
-                       "3D enhancement   : %s\n"
-                       "Loudness         : %s\n"
-                       "Mono output      : %s\n"
-                       "MIC select       : %s\n"
-                       "ADC/DAC loopback : %s\n",
-                       val & 0x8000 ? "post" : "pre",
-                       val & 0x4000 ? "on" : "off",
-                       val & 0x2000 ? "on" : "off",
-                       val & 0x1000 ? "on" : "off",
-                       val & 0x0200 ? "MIC" : "MIX",
-                       val & 0x0100 ? "MIC2" : "MIC1",
-                       val & 0x0080 ? "on" : "off");
-
-       extid = codec->codec_read(codec, AC97_EXTENDED_ID);
-       cap = extid;
-       len += sprintf (page+len, "Ext Capabilities :%s%s%s%s%s%s%s\n",
-                       cap & 0x0001 ? " -var rate PCM audio-" : "",
-                       cap & 0x0002 ? " -2x PCM audio out-" : "",
-                       cap & 0x0008 ? " -var rate MIC in-" : "",
-                       cap & 0x0040 ? " -PCM center DAC-" : "",
-                       cap & 0x0080 ? " -PCM surround DAC-" : "",
-                       cap & 0x0100 ? " -PCM LFE DAC-" : "",
-                       cap & 0x0200 ? " -slot/DAC mappings-" : "");
-       if (is_ac97_20) {
-               len += sprintf (page+len, "Front DAC rate   : %d\n",
-                               codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE));
-       }
-
-       return len;
-}
-
 /**
  *     codec_id        -  Turn id1/id2 into a PnP string
  *     @id1: Vendor ID1
@@ -1313,176 +1200,5 @@ static int pt101_init(struct ac97_codec * codec)
 #endif
        
 
-EXPORT_SYMBOL(ac97_read_proc);
 EXPORT_SYMBOL(ac97_probe_codec);
 
-/*
- *     AC97 library support routines
- */    
-/**
- *     ac97_set_dac_rate       -       set codec rate adaption
- *     @codec: ac97 code
- *     @rate: rate in hertz
- *
- *     Set the DAC rate. Assumes the codec supports VRA. The caller is
- *     expected to have checked this little detail.
- */
-unsigned int ac97_set_dac_rate(struct ac97_codec *codec, unsigned int rate)
-{
-       unsigned int new_rate = rate;
-       u32 dacp;
-       u32 mast_vol, phone_vol, mono_vol, pcm_vol;
-       u32 mute_vol = 0x8000;  /* The mute volume? */
-
-       if(rate != codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE))
-       {
-               /* Mute several registers */
-               mast_vol = codec->codec_read(codec, AC97_MASTER_VOL_STEREO);
-               mono_vol = codec->codec_read(codec, AC97_MASTER_VOL_MONO);
-               phone_vol = codec->codec_read(codec, AC97_HEADPHONE_VOL);
-               pcm_vol = codec->codec_read(codec, AC97_PCMOUT_VOL);
-               codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mute_vol);
-               codec->codec_write(codec, AC97_MASTER_VOL_MONO, mute_vol);
-               codec->codec_write(codec, AC97_HEADPHONE_VOL, mute_vol);
-               codec->codec_write(codec, AC97_PCMOUT_VOL, mute_vol);
-               
-               /* Power down the DAC */
-               dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
-               codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0200);
-               /* Load the rate and read the effective rate */
-               codec->codec_write(codec, AC97_PCM_FRONT_DAC_RATE, rate);
-               new_rate=codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE);
-               /* Power it back up */
-               codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
-
-               /* Restore volumes */
-               codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mast_vol);
-               codec->codec_write(codec, AC97_MASTER_VOL_MONO, mono_vol);
-               codec->codec_write(codec, AC97_HEADPHONE_VOL, phone_vol);
-               codec->codec_write(codec, AC97_PCMOUT_VOL, pcm_vol);
-       }
-       return new_rate;
-}
-
-EXPORT_SYMBOL(ac97_set_dac_rate);
-
-/**
- *     ac97_set_adc_rate       -       set codec rate adaption
- *     @codec: ac97 code
- *     @rate: rate in hertz
- *
- *     Set the ADC rate. Assumes the codec supports VRA. The caller is
- *     expected to have checked this little detail.
- */
-
-unsigned int ac97_set_adc_rate(struct ac97_codec *codec, unsigned int rate)
-{
-       unsigned int new_rate = rate;
-       u32 dacp;
-
-       if(rate != codec->codec_read(codec, AC97_PCM_LR_ADC_RATE))
-       {
-               /* Power down the ADC */
-               dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
-               codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0100);
-               /* Load the rate and read the effective rate */
-               codec->codec_write(codec, AC97_PCM_LR_ADC_RATE, rate);
-               new_rate=codec->codec_read(codec, AC97_PCM_LR_ADC_RATE);
-               /* Power it back up */
-               codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
-       }
-       return new_rate;
-}
-
-EXPORT_SYMBOL(ac97_set_adc_rate);
-
-static int swap_headphone(int remove_master)
-{
-       struct list_head *l;
-       struct ac97_codec *c;
-       
-       if (remove_master) {
-               mutex_lock(&codec_mutex);
-               list_for_each(l, &codecs)
-               {
-                       c = list_entry(l, struct ac97_codec, list);
-                       if (supported_mixer(c, SOUND_MIXER_PHONEOUT))
-                               c->supported_mixers &= ~SOUND_MASK_PHONEOUT;
-               }
-               mutex_unlock(&codec_mutex);
-       } else
-               ac97_hw[SOUND_MIXER_PHONEOUT].offset = AC97_MASTER_VOL_STEREO;
-
-       /* Scale values already match */
-       ac97_hw[SOUND_MIXER_VOLUME].offset = AC97_MASTER_VOL_MONO;
-       return 0;
-}
-
-static int apply_quirk(int quirk)
-{
-       switch (quirk) {
-       case AC97_TUNE_NONE:
-               return 0;
-       case AC97_TUNE_HP_ONLY:
-               return swap_headphone(1);
-       case AC97_TUNE_SWAP_HP:
-               return swap_headphone(0);
-       case AC97_TUNE_SWAP_SURROUND:
-               return -ENOSYS; /* not yet implemented */
-       case AC97_TUNE_AD_SHARING:
-               return -ENOSYS; /* not yet implemented */
-       case AC97_TUNE_ALC_JACK:
-               return -ENOSYS; /* not yet implemented */
-       }
-       return -EINVAL;
-}
-
-/**
- *     ac97_tune_hardware - tune up the hardware
- *     @pdev: pci_dev pointer
- *     @quirk: quirk list
- *     @override: explicit quirk value (overrides if not AC97_TUNE_DEFAULT)
- *
- *     Do some workaround for each pci device, such as renaming of the
- *     headphone (true line-out) control as "Master".
- *     The quirk-list must be terminated with a zero-filled entry.
- *
- *     Returns zero if successful, or a negative error code on failure.
- */
-
-int ac97_tune_hardware(struct pci_dev *pdev, struct ac97_quirk *quirk, int override)
-{
-       int result;
-
-       if (!quirk)
-               return -EINVAL;
-
-       if (override != AC97_TUNE_DEFAULT) {
-               result = apply_quirk(override);
-               if (result < 0)
-                       printk(KERN_ERR "applying quirk type %d failed (%d)\n", override, result);
-               return result;
-       }
-
-       for (; quirk->vendor; quirk++) {
-               if (quirk->vendor != pdev->subsystem_vendor)
-                       continue;
-               if ((! quirk->mask && quirk->device == pdev->subsystem_device) ||
-                   quirk->device == (quirk->mask & pdev->subsystem_device)) {
-#ifdef DEBUG
-                       printk("ac97 quirk for %s (%04x:%04x)\n", quirk->name, ac97->subsystem_vendor, pdev->subsystem_device);
-#endif
-                       result = apply_quirk(quirk->type);
-                       if (result < 0)
-                               printk(KERN_ERR "applying quirk type %d for %s failed (%d)\n", quirk->type, quirk->name, result);
-                       return result;
-               }
-       }
-       return 0;
-}
-
-EXPORT_SYMBOL_GPL(ac97_tune_hardware);
-
-MODULE_LICENSE("GPL");
diff --git a/sound/oss/btaudio.c b/sound/oss/btaudio.c
deleted file mode 100644 (file)
index 4d5cf05..0000000
+++ /dev/null
@@ -1,1139 +0,0 @@
-/*
-    btaudio - bt878 audio dma driver for linux 2.4.x
-
-    (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/pci.h>
-#include <linux/sched.h>
-#include <linux/signal.h>
-#include <linux/types.h>
-#include <linux/interrupt.h>
-#include <linux/init.h>
-#include <linux/poll.h>
-#include <linux/sound.h>
-#include <linux/soundcard.h>
-#include <linux/slab.h>
-#include <linux/kdev_t.h>
-#include <linux/mutex.h>
-
-#include <asm/uaccess.h>
-#include <asm/io.h>
-
-
-/* mmio access */
-#define btwrite(dat,adr)    writel((dat), (bta->mmio+(adr)))
-#define btread(adr)         readl(bta->mmio+(adr))
-
-#define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
-#define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
-#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
-
-/* registers (shifted because bta->mmio is long) */
-#define REG_INT_STAT      (0x100 >> 2)
-#define REG_INT_MASK      (0x104 >> 2)
-#define REG_GPIO_DMA_CTL  (0x10c >> 2)
-#define REG_PACKET_LEN    (0x110 >> 2)
-#define REG_RISC_STRT_ADD (0x114 >> 2)
-#define REG_RISC_COUNT    (0x120 >> 2)
-
-/* IRQ bits - REG_INT_(STAT|MASK) */
-#define IRQ_SCERR         (1 << 19)
-#define IRQ_OCERR         (1 << 18)
-#define IRQ_PABORT        (1 << 17)
-#define IRQ_RIPERR        (1 << 16)
-#define IRQ_PPERR         (1 << 15)
-#define IRQ_FDSR          (1 << 14)
-#define IRQ_FTRGT         (1 << 13)
-#define IRQ_FBUS          (1 << 12)
-#define IRQ_RISCI         (1 << 11)
-#define IRQ_OFLOW         (1 <<  3)
-
-#define IRQ_BTAUDIO       (IRQ_SCERR | IRQ_OCERR | IRQ_PABORT | IRQ_RIPERR |\
-                          IRQ_PPERR | IRQ_FDSR  | IRQ_FTRGT  | IRQ_FBUS   |\
-                          IRQ_RISCI)
-
-/* REG_GPIO_DMA_CTL bits */
-#define DMA_CTL_A_PWRDN   (1 << 26)
-#define DMA_CTL_DA_SBR    (1 << 14)
-#define DMA_CTL_DA_ES2    (1 << 13)
-#define DMA_CTL_ACAP_EN   (1 <<  4)
-#define DMA_CTL_RISC_EN   (1 <<  1)
-#define DMA_CTL_FIFO_EN   (1 <<  0)
-
-/* RISC instructions */
-#define RISC_WRITE        (0x01 << 28)
-#define RISC_JUMP         (0x07 << 28)
-#define RISC_SYNC         (0x08 << 28)
-
-/* RISC bits */
-#define RISC_WR_SOL       (1 << 27)
-#define RISC_WR_EOL       (1 << 26)
-#define RISC_IRQ          (1 << 24)
-#define RISC_SYNC_RESYNC  (1 << 15)
-#define RISC_SYNC_FM1     0x06
-#define RISC_SYNC_VRO     0x0c
-
-#define HWBASE_AD (448000)
-
-/* -------------------------------------------------------------- */
-
-struct btaudio {
-       /* linked list */
-       struct btaudio *next;
-
-       /* device info */
-       int            dsp_digital;
-       int            dsp_analog;
-       int            mixer_dev;
-       struct pci_dev *pci;
-       unsigned int   irq;
-       unsigned long  mem;
-       unsigned long  __iomem *mmio;
-
-       /* locking */
-       int            users;
-       struct mutex lock;
-
-       /* risc instructions */
-       unsigned int   risc_size;
-       unsigned long  *risc_cpu;
-       dma_addr_t     risc_dma;
-
-       /* audio data */
-       unsigned int   buf_size;
-       unsigned char  *buf_cpu;
-       dma_addr_t     buf_dma;
-
-       /* buffer setup */
-       int line_bytes;
-       int line_count;
-       int block_bytes;
-       int block_count;
-
-       /* read fifo management */
-       int recording;
-       int dma_block;
-       int read_offset;
-       int read_count;
-       wait_queue_head_t readq;
-
-       /* settings */
-       int gain[3];
-       int source;
-       int bits;
-       int decimation;
-       int mixcount;
-       int sampleshift;
-       int channels;
-       int analog;
-       int rate;
-};
-
-struct cardinfo {
-       char *name;
-       int rate;
-};
-
-static struct btaudio *btaudios;
-static unsigned int debug;
-static unsigned int irq_debug;
-
-/* -------------------------------------------------------------- */
-
-#define BUF_DEFAULT 128*1024
-#define BUF_MIN         8192
-
-static int alloc_buffer(struct btaudio *bta)
-{
-       if (NULL == bta->buf_cpu) {
-               for (bta->buf_size = BUF_DEFAULT; bta->buf_size >= BUF_MIN;
-                    bta->buf_size = bta->buf_size >> 1) {
-                       bta->buf_cpu = pci_alloc_consistent
-                               (bta->pci, bta->buf_size, &bta->buf_dma);
-                       if (NULL != bta->buf_cpu)
-                               break;
-               }
-               if (NULL == bta->buf_cpu)
-                       return -ENOMEM;
-               memset(bta->buf_cpu,0,bta->buf_size);
-       }
-       if (NULL == bta->risc_cpu) {
-               bta->risc_size = PAGE_SIZE;
-               bta->risc_cpu = pci_alloc_consistent
-                       (bta->pci, bta->risc_size, &bta->risc_dma);
-               if (NULL == bta->risc_cpu) {
-                       pci_free_consistent(bta->pci, bta->buf_size, bta->buf_cpu, bta->buf_dma);
-                       bta->buf_cpu = NULL;
-                       return -ENOMEM;
-               }
-       }
-       return 0;
-}
-
-static void free_buffer(struct btaudio *bta)
-{
-       if (NULL != bta->buf_cpu) {
-               pci_free_consistent(bta->pci, bta->buf_size,
-                                   bta->buf_cpu, bta->buf_dma);
-               bta->buf_cpu = NULL;
-       }
-       if (NULL != bta->risc_cpu) {
-               pci_free_consistent(bta->pci, bta->risc_size,
-                                   bta->risc_cpu, bta->risc_dma);
-               bta->risc_cpu = NULL;
-       }
-}
-
-static int make_risc(struct btaudio *bta)
-{
-       int rp, bp, line, block;
-       unsigned long risc;
-
-       bta->block_bytes = bta->buf_size >> 4;
-       bta->block_count = 1 << 4;
-       bta->line_bytes  = bta->block_bytes;
-       bta->line_count  = bta->block_count;
-       while (bta->line_bytes > 4095) {
-               bta->line_bytes >>= 1;
-               bta->line_count <<= 1;
-       }
-       if (bta->line_count > 255)
-               return -EINVAL;
-       if (debug)
-               printk(KERN_DEBUG
-                      "btaudio: bufsize=%d - bs=%d bc=%d - ls=%d, lc=%d\n",
-                      bta->buf_size,bta->block_bytes,bta->block_count,
-                      bta->line_bytes,bta->line_count);
-        rp = 0; bp = 0;
-       block = 0;
-       bta->risc_cpu[rp++] = cpu_to_le32(RISC_SYNC|RISC_SYNC_FM1);
-       bta->risc_cpu[rp++] = cpu_to_le32(0);
-       for (line = 0; line < bta->line_count; line++) {
-               risc  = RISC_WRITE | RISC_WR_SOL | RISC_WR_EOL;
-               risc |= bta->line_bytes;
-               if (0 == (bp & (bta->block_bytes-1))) {
-                       risc |= RISC_IRQ;
-                       risc |= (block  & 0x0f) << 16;
-                       risc |= (~block & 0x0f) << 20;
-                       block++;
-               }
-               bta->risc_cpu[rp++] = cpu_to_le32(risc);
-               bta->risc_cpu[rp++] = cpu_to_le32(bta->buf_dma + bp);
-               bp += bta->line_bytes;
-       }
-       bta->risc_cpu[rp++] = cpu_to_le32(RISC_SYNC|RISC_SYNC_VRO);
-       bta->risc_cpu[rp++] = cpu_to_le32(0);
-       bta->risc_cpu[rp++] = cpu_to_le32(RISC_JUMP); 
-       bta->risc_cpu[rp++] = cpu_to_le32(bta->risc_dma);
-       return 0;
-}
-
-static int start_recording(struct btaudio *bta)
-{
-       int ret;
-
-       if (0 != (ret = alloc_buffer(bta)))
-               return ret;
-       if (0 != (ret = make_risc(bta)))
-               return ret;
-
-       btwrite(bta->risc_dma, REG_RISC_STRT_ADD);
-       btwrite((bta->line_count << 16) | bta->line_bytes,
-               REG_PACKET_LEN);
-       btwrite(IRQ_BTAUDIO, REG_INT_MASK);
-       if (bta->analog) {
-               btwrite(DMA_CTL_ACAP_EN |
-                       DMA_CTL_RISC_EN |
-                       DMA_CTL_FIFO_EN |
-                       DMA_CTL_DA_ES2  |
-                       ((bta->bits == 8) ? DMA_CTL_DA_SBR : 0) |
-                       (bta->gain[bta->source] << 28) |
-                       (bta->source            << 24) |
-                       (bta->decimation        <<  8),
-                       REG_GPIO_DMA_CTL);
-       } else {
-               btwrite(DMA_CTL_ACAP_EN |
-                       DMA_CTL_RISC_EN |
-                       DMA_CTL_FIFO_EN |
-                       DMA_CTL_DA_ES2  |
-                       DMA_CTL_A_PWRDN |
-                       (1 << 6)   |
-                       ((bta->bits == 8) ? DMA_CTL_DA_SBR : 0) |
-                       (bta->gain[bta->source] << 28) |
-                       (bta->source            << 24) |
-                       (bta->decimation        <<  8),
-                       REG_GPIO_DMA_CTL);
-       }
-       bta->dma_block = 0;
-       bta->read_offset = 0;
-       bta->read_count = 0;
-       bta->recording = 1;
-       if (debug)
-               printk(KERN_DEBUG "btaudio: recording started\n");
-       return 0;
-}
-
-static void stop_recording(struct btaudio *bta)
-{
-        btand(~15, REG_GPIO_DMA_CTL);
-       bta->recording = 0;
-       if (debug)
-               printk(KERN_DEBUG "btaudio: recording stopped\n");
-}
-
-
-/* -------------------------------------------------------------- */
-
-static int btaudio_mixer_open(struct inode *inode, struct file *file)
-{
-       int minor = iminor(inode);
-       struct btaudio *bta;
-
-       for (bta = btaudios; bta != NULL; bta = bta->next)
-               if (bta->mixer_dev == minor)
-                       break;
-       if (NULL == bta)
-               return -ENODEV;
-
-       if (debug)
-               printk("btaudio: open mixer [%d]\n",minor);
-       file->private_data = bta;
-       return 0;
-}
-
-static int btaudio_mixer_release(struct inode *inode, struct file *file)
-{
-       return 0;
-}
-
-static int btaudio_mixer_ioctl(struct inode *inode, struct file *file,
-                              unsigned int cmd, unsigned long arg)
-{
-       struct btaudio *bta = file->private_data;
-       int ret,val=0,i=0;
-       void __user *argp = (void __user *)arg;
-
-       if (cmd == SOUND_MIXER_INFO) {
-               mixer_info info;
-               memset(&info,0,sizeof(info));
-                strlcpy(info.id,"bt878",sizeof(info.id));
-                strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
-                info.modify_counter = bta->mixcount;
-                if (copy_to_user(argp, &info, sizeof(info)))
-                        return -EFAULT;
-               return 0;
-       }
-       if (cmd == SOUND_OLD_MIXER_INFO) {
-               _old_mixer_info info;
-               memset(&info,0,sizeof(info));
-                strlcpy(info.id, "bt878", sizeof(info.id));
-                strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
-                if (copy_to_user(argp, &info, sizeof(info)))
-                        return -EFAULT;
-               return 0;
-       }
-       if (cmd == OSS_GETVERSION)
-               return put_user(SOUND_VERSION, (int __user *)argp);
-
-       /* read */
-       if (_SIOC_DIR(cmd) & _SIOC_WRITE)
-               if (get_user(val, (int __user *)argp))
-                       return -EFAULT;
-
-       switch (cmd) {
-       case MIXER_READ(SOUND_MIXER_CAPS):
-               ret = SOUND_CAP_EXCL_INPUT;
-               break;
-       case MIXER_READ(SOUND_MIXER_STEREODEVS):
-               ret = 0;
-               break;
-       case MIXER_READ(SOUND_MIXER_RECMASK):
-       case MIXER_READ(SOUND_MIXER_DEVMASK):
-               ret = SOUND_MASK_LINE1|SOUND_MASK_LINE2|SOUND_MASK_LINE3;
-               break;
-
-       case MIXER_WRITE(SOUND_MIXER_RECSRC):
-               if (val & SOUND_MASK_LINE1 && bta->source != 0)
-                       bta->source = 0;
-               else if (val & SOUND_MASK_LINE2 && bta->source != 1)
-                       bta->source = 1;
-               else if (val & SOUND_MASK_LINE3 && bta->source != 2)
-                       bta->source = 2;
-               btaor((bta->gain[bta->source] << 28) |
-                     (bta->source            << 24),
-                     0x0cffffff, REG_GPIO_DMA_CTL);
-       case MIXER_READ(SOUND_MIXER_RECSRC):
-               switch (bta->source) {
-               case 0:  ret = SOUND_MASK_LINE1; break;
-               case 1:  ret = SOUND_MASK_LINE2; break;
-               case 2:  ret = SOUND_MASK_LINE3; break;
-               default: ret = 0;
-               }
-               break;
-
-       case MIXER_WRITE(SOUND_MIXER_LINE1):
-       case MIXER_WRITE(SOUND_MIXER_LINE2):
-       case MIXER_WRITE(SOUND_MIXER_LINE3):
-               if (MIXER_WRITE(SOUND_MIXER_LINE1) == cmd)
-                       i = 0;
-               if (MIXER_WRITE(SOUND_MIXER_LINE2) == cmd)
-                       i = 1;
-               if (MIXER_WRITE(SOUND_MIXER_LINE3) == cmd)
-                       i = 2;
-               bta->gain[i] = (val & 0xff) * 15 / 100;
-               if (bta->gain[i] > 15) bta->gain[i] = 15;
-               if (bta->gain[i] <  0) bta->gain[i] =  0;
-               if (i == bta->source)
-                       btaor((bta->gain[bta->source]<<28),
-                             0x0fffffff, REG_GPIO_DMA_CTL);
-               ret  = bta->gain[i] * 100 / 15;
-               ret |= ret << 8;
-               break;
-
-       case MIXER_READ(SOUND_MIXER_LINE1):
-       case MIXER_READ(SOUND_MIXER_LINE2):
-       case MIXER_READ(SOUND_MIXER_LINE3):
-               if (MIXER_READ(SOUND_MIXER_LINE1) == cmd)
-                       i = 0;
-               if (MIXER_READ(SOUND_MIXER_LINE2) == cmd)
-                       i = 1;
-               if (MIXER_READ(SOUND_MIXER_LINE3) == cmd)
-                       i = 2;
-               ret  = bta->gain[i] * 100 / 15;
-               ret |= ret << 8;
-               break;
-
-       default:
-               return -EINVAL;
-       }
-       if (put_user(ret, (int __user *)argp))
-               return -EFAULT;
-       return 0;
-}
-
-static const struct file_operations btaudio_mixer_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .open           = btaudio_mixer_open,
-       .release        = btaudio_mixer_release,
-       .ioctl          = btaudio_mixer_ioctl,
-};
-
-/* -------------------------------------------------------------- */
-
-static int btaudio_dsp_open(struct inode *inode, struct file *file,
-                           struct btaudio *bta, int analog)
-{
-       mutex_lock(&bta->lock);
-       if (bta->users)
-               goto busy;
-       bta->users++;
-       file->private_data = bta;
-
-       bta->analog = analog;
-       bta->dma_block = 0;
-       bta->read_offset = 0;
-       bta->read_count = 0;
-       bta->sampleshift = 0;
-
-       mutex_unlock(&bta->lock);
-       return 0;
-
- busy:
-       mutex_unlock(&bta->lock);
-       return -EBUSY;
-}
-
-static int btaudio_dsp_open_digital(struct inode *inode, struct file *file)
-{
-       int minor = iminor(inode);
-       struct btaudio *bta;
-
-       for (bta = btaudios; bta != NULL; bta = bta->next)
-               if (bta->dsp_digital == minor)
-                       break;
-       if (NULL == bta)
-               return -ENODEV;
-       
-       if (debug)
-               printk("btaudio: open digital dsp [%d]\n",minor);
-       return btaudio_dsp_open(inode,file,bta,0);
-}
-
-static int btaudio_dsp_open_analog(struct inode *inode, struct file *file)
-{
-       int minor = iminor(inode);
-       struct btaudio *bta;
-
-       for (bta = btaudios; bta != NULL; bta = bta->next)
-               if (bta->dsp_analog == minor)
-                       break;
-       if (NULL == bta)
-               return -ENODEV;
-
-       if (debug)
-               printk("btaudio: open analog dsp [%d]\n",minor);
-       return btaudio_dsp_open(inode,file,bta,1);
-}
-
-static int btaudio_dsp_release(struct inode *inode, struct file *file)
-{
-       struct btaudio *bta = file->private_data;
-
-       mutex_lock(&bta->lock);
-       if (bta->recording)
-               stop_recording(bta);
-       bta->users--;
-       mutex_unlock(&bta->lock);
-       return 0;
-}
-
-static ssize_t btaudio_dsp_read(struct file *file, char __user *buffer,
-                               size_t swcount, loff_t *ppos)
-{
-       struct btaudio *bta = file->private_data;
-       int hwcount = swcount << bta->sampleshift;
-       int nsrc, ndst, err, ret = 0;
-       DECLARE_WAITQUEUE(wait, current);
-
-       add_wait_queue(&bta->readq, &wait);
-       mutex_lock(&bta->lock);
-       while (swcount > 0) {
-               if (0 == bta->read_count) {
-                       if (!bta->recording) {
-                               if (0 != (err = start_recording(bta))) {
-                                       if (0 == ret)
-                                               ret = err;
-                                       break;
-                               }
-                       }
-                       if (file->f_flags & O_NONBLOCK) {
-                               if (0 == ret)
-                                       ret = -EAGAIN;
-                               break;
-                       }
-                       mutex_unlock(&bta->lock);
-                       current->state = TASK_INTERRUPTIBLE;
-                       schedule();
-                       mutex_lock(&bta->lock);
-                       if(signal_pending(current)) {
-                               if (0 == ret)
-                                       ret = -EINTR;
-                               break;
-                       }
-               }
-               nsrc = (bta->read_count < hwcount) ? bta->read_count : hwcount;
-               if (nsrc > bta->buf_size - bta->read_offset)
-                       nsrc = bta->buf_size - bta->read_offset;
-               ndst = nsrc >> bta->sampleshift;
-               
-               if ((bta->analog  && 0 == bta->sampleshift) ||
-                   (!bta->analog && 2 == bta->channels)) {
-                       /* just copy */
-                       if (copy_to_user(buffer + ret, bta->buf_cpu + bta->read_offset, nsrc)) {
-                               if (0 == ret)
-                                       ret = -EFAULT;
-                               break;
-                       }
-
-               } else if (!bta->analog) {
-                       /* stereo => mono (digital audio) */
-                       __s16 *src = (__s16*)(bta->buf_cpu + bta->read_offset);
-                       __s16 __user *dst = (__s16 __user *)(buffer + ret);
-                       __s16 avg;
-                       int n = ndst>>1;
-                       if (!access_ok(VERIFY_WRITE, dst, ndst)) {
-                               if (0 == ret)
-                                       ret = -EFAULT;
-                               break;
-                       }
-                       for (; n; n--, dst++) {
-                               avg  = (__s16)le16_to_cpu(*src) / 2; src++;
-                               avg += (__s16)le16_to_cpu(*src) / 2; src++;
-                               __put_user(cpu_to_le16(avg),dst);
-                       }
-
-               } else if (8 == bta->bits) {
-                       /* copy + byte downsampling (audio A/D) */
-                       __u8 *src = bta->buf_cpu + bta->read_offset;
-                       __u8 __user *dst = buffer + ret;
-                       int n = ndst;
-                       if (!access_ok(VERIFY_WRITE, dst, ndst)) {
-                               if (0 == ret)
-                                       ret = -EFAULT;
-                               break;
-                       }
-                       for (; n; n--, src += (1 << bta->sampleshift), dst++)
-                               __put_user(*src, dst);
-
-               } else {
-                       /* copy + word downsampling (audio A/D) */
-                       __u16 *src = (__u16*)(bta->buf_cpu + bta->read_offset);
-                       __u16 __user *dst = (__u16 __user *)(buffer + ret);
-                       int n = ndst>>1;
-                       if (!access_ok(VERIFY_WRITE,dst,ndst)) {
-                               if (0 == ret)
-                                       ret = -EFAULT;
-                               break;
-                       }
-                       for (; n; n--, src += (1 << bta->sampleshift), dst++)
-                               __put_user(*src, dst);
-               }
-
-               ret     += ndst;
-               swcount -= ndst;
-               hwcount -= nsrc;
-               bta->read_count  -= nsrc;
-               bta->read_offset += nsrc;
-               if (bta->read_offset == bta->buf_size)
-                       bta->read_offset = 0;
-       }
-       mutex_unlock(&bta->lock);
-       remove_wait_queue(&bta->readq, &wait);
-       current->state = TASK_RUNNING;
-       return ret;
-}
-
-static ssize_t btaudio_dsp_write(struct file *file, const char __user *buffer,
-                                size_t count, loff_t *ppos)
-{
-       return -EINVAL;
-}
-
-static int btaudio_dsp_ioctl(struct inode *inode, struct file *file,
-                            unsigned int cmd, unsigned long arg)
-{
-       struct btaudio *bta = file->private_data;
-       int s, i, ret, val = 0;
-       void __user *argp = (void __user *)arg;
-       int __user *p = argp;
-       
-        switch (cmd) {
-        case OSS_GETVERSION:
-                return put_user(SOUND_VERSION, p);
-        case SNDCTL_DSP_GETCAPS:
-               return 0;
-
-        case SNDCTL_DSP_SPEED:
-               if (get_user(val, p))
-                       return -EFAULT;
-               if (bta->analog) {
-                       for (s = 0; s < 16; s++)
-                               if (val << s >= HWBASE_AD*4/15)
-                                       break;
-                       for (i = 15; i >= 5; i--)
-                               if (val << s <= HWBASE_AD*4/i)
-                                       break;
-                       bta->sampleshift = s;
-                       bta->decimation  = i;
-                       if (debug)
-                               printk(KERN_DEBUG "btaudio: rate: req=%d  "
-                                      "dec=%d shift=%d hwrate=%d swrate=%d\n",
-                                      val,i,s,(HWBASE_AD*4/i),(HWBASE_AD*4/i)>>s);
-               } else {
-                       bta->sampleshift = (bta->channels == 2) ? 0 : 1;
-                       bta->decimation  = 0;
-               }
-               if (bta->recording) {
-                       mutex_lock(&bta->lock);
-                       stop_recording(bta);
-                       start_recording(bta);
-                       mutex_unlock(&bta->lock);
-               }
-               /* fall through */
-        case SOUND_PCM_READ_RATE:
-               if (bta->analog) {
-                       return put_user(HWBASE_AD*4/bta->decimation>>bta->sampleshift, p);
-               } else {
-                       return put_user(bta->rate, p);
-               }
-
-        case SNDCTL_DSP_STEREO:
-               if (!bta->analog) {
-                       if (get_user(val, p))
-                               return -EFAULT;
-                       bta->channels    = (val > 0) ? 2 : 1;
-                       bta->sampleshift = (bta->channels == 2) ? 0 : 1;
-                       if (debug)
-                               printk(KERN_INFO
-                                      "btaudio: stereo=%d channels=%d\n",
-                                      val,bta->channels);
-               } else {
-                       if (val == 1)
-                               return -EFAULT;
-                       else {
-                               bta->channels = 1;
-                               if (debug)
-                                       printk(KERN_INFO
-                                              "btaudio: stereo=0 channels=1\n");
-                       }
-               }
-               return put_user((bta->channels)-1, p);
-
-        case SNDCTL_DSP_CHANNELS:
-               if (!bta->analog) {
-                       if (get_user(val, p))
-                               return -EFAULT;
-                       bta->channels    = (val > 1) ? 2 : 1;
-                       bta->sampleshift = (bta->channels == 2) ? 0 : 1;
-                       if (debug)
-                               printk(KERN_DEBUG
-                                      "btaudio: val=%d channels=%d\n",
-                                      val,bta->channels);
-               }
-               /* fall through */
-        case SOUND_PCM_READ_CHANNELS:
-               return put_user(bta->channels, p);
-               
-        case SNDCTL_DSP_GETFMTS: /* Returns a mask */
-               if (bta->analog)
-                       return put_user(AFMT_S16_LE|AFMT_S8, p);
-               else
-                       return put_user(AFMT_S16_LE, p);
-
-        case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
-               if (get_user(val, p))
-                       return -EFAULT;
-                if (val != AFMT_QUERY) {
-                       if (bta->analog)
-                               bta->bits = (val == AFMT_S8) ? 8 : 16;
-                       else
-                               bta->bits = 16;
-                       if (bta->recording) {
-                               mutex_lock(&bta->lock);
-                               stop_recording(bta);
-                               start_recording(bta);
-                               mutex_unlock(&bta->lock);
-                       }
-               }
-               if (debug)
-                       printk(KERN_DEBUG "btaudio: fmt: bits=%d\n",bta->bits);
-                return put_user((bta->bits==16) ? AFMT_S16_LE : AFMT_S8,
-                               p);
-               break;
-        case SOUND_PCM_READ_BITS:
-               return put_user(bta->bits, p);
-
-        case SNDCTL_DSP_NONBLOCK:
-                file->f_flags |= O_NONBLOCK;
-                return 0;
-
-        case SNDCTL_DSP_RESET:
-               if (bta->recording) {
-                       mutex_lock(&bta->lock);
-                       stop_recording(bta);
-                       mutex_unlock(&bta->lock);
-               }
-               return 0;
-        case SNDCTL_DSP_GETBLKSIZE:
-               if (!bta->recording) {
-                       if (0 != (ret = alloc_buffer(bta)))
-                               return ret;
-                       if (0 != (ret = make_risc(bta)))
-                               return ret;
-               }
-               return put_user(bta->block_bytes>>bta->sampleshift,p);
-
-        case SNDCTL_DSP_SYNC:
-               /* NOP */
-               return 0;
-       case SNDCTL_DSP_GETISPACE:
-       {
-               audio_buf_info info;
-               if (!bta->recording)
-                       return -EINVAL;
-               info.fragsize = bta->block_bytes>>bta->sampleshift;
-               info.fragstotal = bta->block_count;
-               info.bytes = bta->read_count;
-               info.fragments = info.bytes / info.fragsize;
-               if (debug)
-                       printk(KERN_DEBUG "btaudio: SNDCTL_DSP_GETISPACE "
-                              "returns %d/%d/%d/%d\n",
-                              info.fragsize, info.fragstotal,
-                              info.bytes, info.fragments);
-               if (copy_to_user(argp, &info, sizeof(info)))
-                       return -EFAULT;
-               return 0;
-       }
-#if 0 /* TODO */
-        case SNDCTL_DSP_GETTRIGGER:
-        case SNDCTL_DSP_SETTRIGGER:
-        case SNDCTL_DSP_SETFRAGMENT:
-#endif
-       default:
-               return -EINVAL;
-       }
-}
-
-static unsigned int btaudio_dsp_poll(struct file *file, struct poll_table_struct *wait)
-{
-       struct btaudio *bta = file->private_data;
-       unsigned int mask = 0;
-
-       poll_wait(file, &bta->readq, wait);
-
-       if (0 != bta->read_count)
-               mask |= (POLLIN | POLLRDNORM);
-
-       return mask;
-}
-
-static const struct file_operations btaudio_digital_dsp_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .open           = btaudio_dsp_open_digital,
-       .release        = btaudio_dsp_release,
-       .read           = btaudio_dsp_read,
-       .write          = btaudio_dsp_write,
-       .ioctl          = btaudio_dsp_ioctl,
-       .poll           = btaudio_dsp_poll,
-};
-
-static const struct file_operations btaudio_analog_dsp_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .open           = btaudio_dsp_open_analog,
-       .release        = btaudio_dsp_release,
-       .read           = btaudio_dsp_read,
-       .write          = btaudio_dsp_write,
-       .ioctl          = btaudio_dsp_ioctl,
-       .poll           = btaudio_dsp_poll,
-};
-
-/* -------------------------------------------------------------- */
-
-static char *irq_name[] = { "", "", "", "OFLOW", "", "", "", "", "", "", "",
-                           "RISCI", "FBUS", "FTRGT", "FDSR", "PPERR",
-                           "RIPERR", "PABORT", "OCERR", "SCERR" };
-
-static irqreturn_t btaudio_irq(int irq, void *dev_id)
-{
-       int count = 0;
-       u32 stat,astat;
-       struct btaudio *bta = dev_id;
-       int handled = 0;
-
-       for (;;) {
-               count++;
-               stat  = btread(REG_INT_STAT);
-               astat = stat & btread(REG_INT_MASK);
-               if (!astat)
-                       return IRQ_RETVAL(handled);
-               handled = 1;
-               btwrite(astat,REG_INT_STAT);
-
-               if (irq_debug) {
-                       int i;
-                       printk(KERN_DEBUG "btaudio: irq loop=%d risc=%x, bits:",
-                              count, stat>>28);
-                       for (i = 0; i < (sizeof(irq_name)/sizeof(char*)); i++) {
-                               if (stat & (1 << i))
-                                       printk(" %s",irq_name[i]);
-                               if (astat & (1 << i))
-                                       printk("*");
-                       }
-                       printk("\n");
-               }
-               if (stat & IRQ_RISCI) {
-                       int blocks;
-                       blocks = (stat >> 28) - bta->dma_block;
-                       if (blocks < 0)
-                               blocks += bta->block_count;
-                       bta->dma_block = stat >> 28;
-                       if (bta->read_count + 2*bta->block_bytes > bta->buf_size) {
-                               stop_recording(bta);
-                               printk(KERN_INFO "btaudio: buffer overrun\n");
-                       }
-                       if (blocks > 0) {
-                               bta->read_count += blocks * bta->block_bytes;
-                               wake_up_interruptible(&bta->readq);
-                       }
-               }
-               if (count > 10) {
-                       printk(KERN_WARNING
-                              "btaudio: Oops - irq mask cleared\n");
-                       btwrite(0, REG_INT_MASK);
-               }
-       }
-       return IRQ_NONE;
-}
-
-/* -------------------------------------------------------------- */
-
-static unsigned int dsp1 = -1;
-static unsigned int dsp2 = -1;
-static unsigned int mixer = -1;
-static int latency = -1;
-static int digital = 1;
-static int analog = 1;
-static int rate;
-
-#define BTA_OSPREY200 1
-
-static struct cardinfo cards[] = {
-       [0] = {
-               .name   = "default",
-               .rate   = 32000,
-       },
-       [BTA_OSPREY200] = {
-               .name   = "Osprey 200",
-               .rate   = 44100,
-       },
-};
-
-static int __devinit btaudio_probe(struct pci_dev *pci_dev,
-                                  const struct pci_device_id *pci_id)
-{
-       struct btaudio *bta;
-       struct cardinfo *card = &cards[pci_id->driver_data];
-       unsigned char revision,lat;
-       int rc = -EBUSY;
-
-       if (pci_enable_device(pci_dev))
-               return -EIO;
-       if (!request_mem_region(pci_resource_start(pci_dev,0),
-                               pci_resource_len(pci_dev,0),
-                               "btaudio")) {
-               return -EBUSY;
-       }
-
-       bta = kzalloc(sizeof(*bta),GFP_ATOMIC);
-       if (!bta) {
-               rc = -ENOMEM;
-               goto fail0;
-       }
-
-       bta->pci  = pci_dev;
-       bta->irq  = pci_dev->irq;
-       bta->mem  = pci_resource_start(pci_dev,0);
-       bta->mmio = ioremap(pci_resource_start(pci_dev,0),
-                           pci_resource_len(pci_dev,0));
-
-       bta->source     = 1;
-       bta->bits       = 8;
-       bta->channels   = 1;
-       if (bta->analog) {
-               bta->decimation  = 15;
-       } else {
-               bta->decimation  = 0;
-               bta->sampleshift = 1;
-       }
-
-       /* sample rate */
-       bta->rate = card->rate;
-       if (rate)
-               bta->rate = rate;
-       
-       mutex_init(&bta->lock);
-        init_waitqueue_head(&bta->readq);
-
-       if (-1 != latency) {
-               printk(KERN_INFO "btaudio: setting pci latency timer to %d\n",
-                      latency);
-               pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
-       }
-        pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &revision);
-        pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &lat);
-        printk(KERN_INFO "btaudio: Bt%x (rev %d) at %02x:%02x.%x, ",
-              pci_dev->device,revision,pci_dev->bus->number,
-              PCI_SLOT(pci_dev->devfn),PCI_FUNC(pci_dev->devfn));
-        printk("irq: %d, latency: %d, mmio: 0x%lx\n",
-              bta->irq, lat, bta->mem);
-       printk("btaudio: using card config \"%s\"\n", card->name);
-
-       /* init hw */
-        btwrite(0, REG_GPIO_DMA_CTL);
-        btwrite(0, REG_INT_MASK);
-        btwrite(~0U, REG_INT_STAT);
-       pci_set_master(pci_dev);
-
-       if ((rc = request_irq(bta->irq, btaudio_irq, IRQF_SHARED|IRQF_DISABLED,
-                             "btaudio",(void *)bta)) < 0) {
-               printk(KERN_WARNING
-                      "btaudio: can't request irq (rc=%d)\n",rc);
-               goto fail1;
-       }
-
-       /* register devices */
-       if (digital) {
-               rc = bta->dsp_digital =
-                       register_sound_dsp(&btaudio_digital_dsp_fops,dsp1);
-               if (rc < 0) {
-                       printk(KERN_WARNING
-                              "btaudio: can't register digital dsp (rc=%d)\n",rc);
-                       goto fail2;
-               }
-               printk(KERN_INFO "btaudio: registered device dsp%d [digital]\n",
-                      bta->dsp_digital >> 4);
-       }
-       if (analog) {
-               rc = bta->dsp_analog =
-                       register_sound_dsp(&btaudio_analog_dsp_fops,dsp2);
-               if (rc < 0) {
-                       printk(KERN_WARNING
-                              "btaudio: can't register analog dsp (rc=%d)\n",rc);
-                       goto fail3;
-               }
-               printk(KERN_INFO "btaudio: registered device dsp%d [analog]\n",
-                      bta->dsp_analog >> 4);
-               rc = bta->mixer_dev = register_sound_mixer(&btaudio_mixer_fops,mixer);
-               if (rc < 0) {
-                       printk(KERN_WARNING
-                              "btaudio: can't register mixer (rc=%d)\n",rc);
-                       goto fail4;
-               }
-               printk(KERN_INFO "btaudio: registered device mixer%d\n",
-                      bta->mixer_dev >> 4);
-       }
-
-       /* hook into linked list */
-       bta->next = btaudios;
-       btaudios = bta;
-
-       pci_set_drvdata(pci_dev,bta);
-        return 0;
-
- fail4:
-       unregister_sound_dsp(bta->dsp_analog);
- fail3:
-       if (digital)
-               unregister_sound_dsp(bta->dsp_digital);
- fail2:
-        free_irq(bta->irq,bta);        
- fail1:
-       iounmap(bta->mmio);
-       kfree(bta);
- fail0:
-       release_mem_region(pci_resource_start(pci_dev,0),
-                          pci_resource_len(pci_dev,0));
-       return rc;
-}
-
-static void __devexit btaudio_remove(struct pci_dev *pci_dev)
-{
-       struct btaudio *bta = pci_get_drvdata(pci_dev);
-       struct btaudio *walk;
-
-       /* turn off all DMA / IRQs */
-        btand(~15, REG_GPIO_DMA_CTL);
-        btwrite(0, REG_INT_MASK);
-        btwrite(~0U, REG_INT_STAT);
-
-       /* unregister devices */
-       if (digital) {
-               unregister_sound_dsp(bta->dsp_digital);
-       }
-       if (analog) {
-               unregister_sound_dsp(bta->dsp_analog);
-               unregister_sound_mixer(bta->mixer_dev);
-       }
-
-       /* free resources */
-       free_buffer(bta);
-        free_irq(bta->irq,bta);
-       release_mem_region(pci_resource_start(pci_dev,0),
-                          pci_resource_len(pci_dev,0));
-       iounmap(bta->mmio);
-
-       /* remove from linked list */
-       if (bta == btaudios) {
-               btaudios = NULL;
-       } else {
-               for (walk = btaudios; walk->next != bta; walk = walk->next)
-                       ; /* if (NULL == walk->next) BUG(); */
-               walk->next = bta->next;
-       }
-
-       pci_set_drvdata(pci_dev, NULL);
-       kfree(bta);
-       return;
-}
-
-/* -------------------------------------------------------------- */
-
-static struct pci_device_id btaudio_pci_tbl[] = {
-        {
-               .vendor         = PCI_VENDOR_ID_BROOKTREE,
-               .device         = 0x0878,
-               .subvendor      = 0x0070,
-               .subdevice      = 0xff01,
-               .driver_data    = BTA_OSPREY200,
-       },{
-               .vendor         = PCI_VENDOR_ID_BROOKTREE,
-               .device         = 0x0878,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-       },{
-               .vendor         = PCI_VENDOR_ID_BROOKTREE,
-               .device         = 0x0878,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-        },{
-               /* --- end of list --- */
-       }
-};
-
-static struct pci_driver btaudio_pci_driver = {
-        .name          = "btaudio",
-        .id_table      = btaudio_pci_tbl,
-        .probe         = btaudio_probe,
-        .remove                =  __devexit_p(btaudio_remove),
-};
-
-static int btaudio_init_module(void)
-{
-       printk(KERN_INFO "btaudio: driver version 0.7 loaded [%s%s%s]\n",
-              digital ? "digital" : "",
-              analog && digital ? "+" : "",
-              analog ? "analog" : "");
-       return pci_register_driver(&btaudio_pci_driver);
-}
-
-static void btaudio_cleanup_module(void)
-{
-       pci_unregister_driver(&btaudio_pci_driver);
-       return;
-}
-
-module_init(btaudio_init_module);
-module_exit(btaudio_cleanup_module);
-
-module_param(dsp1, int, S_IRUGO);
-module_param(dsp2, int, S_IRUGO);
-module_param(mixer, int, S_IRUGO);
-module_param(debug, int, S_IRUGO | S_IWUSR);
-module_param(irq_debug, int, S_IRUGO | S_IWUSR);
-module_param(digital, int, S_IRUGO);
-module_param(analog, int, S_IRUGO);
-module_param(rate, int, S_IRUGO);
-module_param(latency, int, S_IRUGO);
-MODULE_PARM_DESC(latency,"pci latency timer");
-
-MODULE_DEVICE_TABLE(pci, btaudio_pci_tbl);
-MODULE_DESCRIPTION("bt878 audio dma driver");
-MODULE_AUTHOR("Gerd Knorr");
-MODULE_LICENSE("GPL");
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
diff --git a/sound/oss/cs4232.c b/sound/oss/cs4232.c
deleted file mode 100644 (file)
index de40e21..0000000
+++ /dev/null
@@ -1,526 +0,0 @@
-/*
- * Copyright (C) by Hannu Savolainen 1993-1997
- *
- *     cs4232.c
- *
- * The low level driver for Crystal CS4232 based cards. The CS4232 is
- * a PnP compatible chip which contains a CS4231A codec, SB emulation,
- * a MPU401 compatible MIDI port, joystick and synthesizer and IDE CD-ROM 
- * interfaces. This is just a temporary driver until full PnP support
- * gets implemented. Just the WSS codec, FM synth and the MIDI ports are
- * supported. Other interfaces are left uninitialized.
- *
- * ifdef ...WAVEFRONT...
- * 
- *   Support is provided for initializing the WaveFront synth
- *   interface as well, which is logical device #4. Note that if
- *   you have a Tropez+ card, you probably don't need to setup
- *   the CS4232-supported MIDI interface, since it corresponds to
- *   the internal 26-pin header that's hard to access. Using this
- *   requires an additional IRQ, a resource none too plentiful in
- *   this environment. Just don't set module parameters mpuio and
- *   mpuirq, and the MIDI port will be left uninitialized. You can
- *   still use the ICS2115 hosted MIDI interface which corresponds
- *   to the 9-pin D connector on the back of the card.
- *
- * endif  ...WAVEFRONT...
- *
- * Supported chips are:
- *      CS4232
- *      CS4236
- *      CS4236B
- *
- * Note: You will need a PnP config setup to initialise some CS4232 boards
- * anyway.
- *
- * Changes
- *      John Rood               Added Bose Sound System Support.
- *      Toshio Spoor
- *     Alan Cox                Modularisation, Basic cleanups.
- *      Paul Barton-Davis      Separated MPU configuration, added
- *                                       Tropez+ (WaveFront) support
- *     Christoph Hellwig       Adapted to module_init/module_exit,
- *                                     simple cleanups
- *     Arnaldo C. de Melo      got rid of attach_uart401
- *     Bartlomiej Zolnierkiewicz
- *                             Added some __init/__initdata/__exit
- *     Marcus Meissner         Added ISA PnP support.
- */
-
-#include <linux/pnp.h>
-#include <linux/module.h>
-#include <linux/init.h>
-
-#include "sound_config.h"
-
-#include "ad1848.h"
-#include "mpu401.h"
-
-#define KEY_PORT       0x279   /* Same as LPT1 status port */
-#define CSN_NUM                0x99    /* Just a random number */
-#define INDEX_ADDRESS   0x00    /* (R0) Index Address Register */
-#define INDEX_DATA      0x01    /* (R1) Indexed Data Register */
-#define PIN_CONTROL     0x0a    /* (I10) Pin Control */
-#define ENABLE_PINS     0xc0    /* XCTRL0/XCTRL1 enable */
-
-static void CS_OUT(unsigned char a)
-{
-       outb(a, KEY_PORT);
-}
-
-#define CS_OUT2(a, b)          {CS_OUT(a);CS_OUT(b);}
-#define CS_OUT3(a, b, c)       {CS_OUT(a);CS_OUT(b);CS_OUT(c);}
-
-static int __initdata bss       = 0;
-static int mpu_base, mpu_irq;
-static int synth_base, synth_irq;
-static int mpu_detected;
-
-static int probe_cs4232_mpu(struct address_info *hw_config)
-{
-       /*
-        *      Just write down the config values.
-        */
-
-       mpu_base = hw_config->io_base;
-       mpu_irq = hw_config->irq;
-
-       return 1;
-}
-
-static unsigned char crystal_key[] =   /* A 32 byte magic key sequence */
-{
-       0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc,
-       0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2,
-       0xf1, 0xf8, 0x7c, 0x3e, 0x9f, 0x4f, 0x27, 0x13,
-       0x09, 0x84, 0x42, 0xa1, 0xd0, 0x68, 0x34, 0x1a
-};
-
-static void sleep(unsigned howlong)
-{
-       current->state = TASK_INTERRUPTIBLE;
-       schedule_timeout(howlong);
-}
-
-static void enable_xctrl(int baseio)
-{
-        unsigned char regd;
-                
-        /*
-         * Some IBM Aptiva's have the Bose Sound System. By default
-         * the Bose Amplifier is disabled. The amplifier will be 
-         * activated, by setting the XCTRL0 and XCTRL1 bits.
-         * Volume of the monitor bose speakers/woofer, can then
-         * be set by changing the PCM volume.
-         *
-         */
-                
-        printk("cs4232: enabling Bose Sound System Amplifier.\n");
-        
-        /* Switch to Pin Control Address */                   
-        regd = inb(baseio + INDEX_ADDRESS) & 0xe0;
-        outb(((unsigned char) (PIN_CONTROL | regd)), baseio + INDEX_ADDRESS );
-        
-        /* Activate the XCTRL0 and XCTRL1 Pins */
-        regd = inb(baseio + INDEX_DATA);
-        outb(((unsigned char) (ENABLE_PINS | regd)), baseio + INDEX_DATA );
-}
-
-static int __init probe_cs4232(struct address_info *hw_config, int isapnp_configured)
-{
-       int i, n;
-       int base = hw_config->io_base, irq = hw_config->irq;
-       int dma1 = hw_config->dma, dma2 = hw_config->dma2;
-       struct resource *ports;
-
-       if (base == -1 || irq == -1 || dma1 == -1) {
-               printk(KERN_ERR "cs4232: dma, irq and io must be set.\n");
-               return 0;
-       }
-
-       /*
-        * Verify that the I/O port range is free.
-        */
-
-       ports = request_region(base, 4, "ad1848");
-       if (!ports) {
-               printk(KERN_ERR "cs4232.c: I/O port 0x%03x not free\n", base);
-               return 0;
-       }
-       if (ad1848_detect(ports, NULL, hw_config->osp)) {
-               goto got_it;    /* The card is already active */
-       }
-       if (isapnp_configured) {
-               printk(KERN_ERR "cs4232.c: ISA PnP configured, but not detected?\n");
-               goto fail;
-       }
-
-       /*
-        * This version of the driver doesn't use the PnP method when configuring
-        * the card but a simplified method defined by Crystal. This means that
-        * just one CS4232 compatible device can exist on the system. Also this
-        * method conflicts with possible PnP support in the OS. For this reason 
-        * driver is just a temporary kludge.
-        *
-        * Also the Cirrus/Crystal method doesn't always work. Try ISA PnP first ;)
-        */
-
-       /*
-        * Repeat initialization few times since it doesn't always succeed in
-        * first time.
-        */
-
-       for (n = 0; n < 4; n++)
-       {       
-               /*
-                *      Wake up the card by sending a 32 byte Crystal key to the key port.
-                */
-               
-               for (i = 0; i < 32; i++)
-                       CS_OUT(crystal_key[i]);
-
-               sleep(HZ / 10);
-
-               /*
-                *      Now set the CSN (Card Select Number).
-                */
-
-               CS_OUT2(0x06, CSN_NUM);
-
-               /*
-                *      Then set some config bytes. First logical device 0 
-                */
-
-               CS_OUT2(0x15, 0x00);    /* Select logical device 0 (WSS/SB/FM) */
-               CS_OUT3(0x47, (base >> 8) & 0xff, base & 0xff); /* WSS base */
-
-               if (!request_region(0x388, 4, "FM"))    /* Not free */
-                       CS_OUT3(0x48, 0x00, 0x00)       /* FM base off */
-               else {
-                       release_region(0x388, 4);
-                       CS_OUT3(0x48, 0x03, 0x88);      /* FM base 0x388 */
-               }
-
-               CS_OUT3(0x42, 0x00, 0x00);      /* SB base off */
-               CS_OUT2(0x22, irq);             /* SB+WSS IRQ */
-               CS_OUT2(0x2a, dma1);            /* SB+WSS DMA */
-
-               if (dma2 != -1)
-                       CS_OUT2(0x25, dma2)     /* WSS DMA2 */
-               else
-                       CS_OUT2(0x25, 4);       /* No WSS DMA2 */
-
-               CS_OUT2(0x33, 0x01);    /* Activate logical dev 0 */
-
-               sleep(HZ / 10);
-
-               /*
-                * Initialize logical device 3 (MPU)
-                */
-
-               if (mpu_base != 0 && mpu_irq != 0)
-               {
-                       CS_OUT2(0x15, 0x03);    /* Select logical device 3 (MPU) */
-                       CS_OUT3(0x47, (mpu_base >> 8) & 0xff, mpu_base & 0xff); /* MPU base */
-                       CS_OUT2(0x22, mpu_irq); /* MPU IRQ */
-                       CS_OUT2(0x33, 0x01);    /* Activate logical dev 3 */
-               }
-
-               if(synth_base != 0)
-               {
-                   CS_OUT2 (0x15, 0x04);               /* logical device 4 (WaveFront) */
-                   CS_OUT3 (0x47, (synth_base >> 8) & 0xff,
-                            synth_base & 0xff);        /* base */
-                   CS_OUT2 (0x22, synth_irq);          /* IRQ */
-                   CS_OUT2 (0x33, 0x01);               /* Activate logical dev 4 */
-               }
-
-               /*
-                * Finally activate the chip
-                */
-               
-               CS_OUT(0x79);
-
-               sleep(HZ / 5);
-
-               /*
-                * Then try to detect the codec part of the chip
-                */
-
-               if (ad1848_detect(ports, NULL, hw_config->osp))
-                       goto got_it;
-               
-               sleep(HZ);
-       }
-fail:
-       release_region(base, 4);
-       return 0;
-
-got_it:
-       if (dma2 == -1)
-               dma2 = dma1;
-
-       hw_config->slots[0] = ad1848_init("Crystal audio controller", ports,
-                                         irq,
-                                         dma1,         /* Playback DMA */
-                                         dma2,         /* Capture DMA */
-                                         0,
-                                         hw_config->osp,
-                                         THIS_MODULE);
-
-       if (hw_config->slots[0] != -1 &&
-               audio_devs[hw_config->slots[0]]->mixer_dev!=-1)
-       {       
-               /* Assume the mixer map is as suggested in the CS4232 databook */
-               AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE);
-               AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
-               AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH);           /* FM synth */
-       }
-       if (mpu_base != 0 && mpu_irq != 0)
-       {
-               static struct address_info hw_config2 = {
-                       0
-               };              /* Ensure it's initialized */
-
-               hw_config2.io_base = mpu_base;
-               hw_config2.irq = mpu_irq;
-               hw_config2.dma = -1;
-               hw_config2.dma2 = -1;
-               hw_config2.always_detect = 0;
-               hw_config2.name = NULL;
-               hw_config2.driver_use_1 = 0;
-               hw_config2.driver_use_2 = 0;
-               hw_config2.card_subtype = 0;
-
-               if (probe_uart401(&hw_config2, THIS_MODULE))
-               {
-                       mpu_detected = 1;
-               }
-               else
-               {
-                       mpu_base = mpu_irq = 0;
-               }
-               hw_config->slots[1] = hw_config2.slots[1];
-       }
-       
-       if (bss)
-               enable_xctrl(base);
-
-       return 1;
-}
-
-static void __devexit unload_cs4232(struct address_info *hw_config)
-{
-       int base = hw_config->io_base, irq = hw_config->irq;
-       int dma1 = hw_config->dma, dma2 = hw_config->dma2;
-
-       if (dma2 == -1)
-               dma2 = dma1;
-
-       ad1848_unload(base,
-                     irq,
-                     dma1,     /* Playback DMA */
-                     dma2,     /* Capture DMA */
-                     0);
-
-       sound_unload_audiodev(hw_config->slots[0]);
-       if (mpu_base != 0 && mpu_irq != 0 && mpu_detected)
-       {
-               static struct address_info hw_config2 =
-               {
-                       0
-               };              /* Ensure it's initialized */
-
-               hw_config2.io_base = mpu_base;
-               hw_config2.irq = mpu_irq;
-               hw_config2.dma = -1;
-               hw_config2.dma2 = -1;
-               hw_config2.always_detect = 0;
-               hw_config2.name = NULL;
-               hw_config2.driver_use_1 = 0;
-               hw_config2.driver_use_2 = 0;
-               hw_config2.card_subtype = 0;
-               hw_config2.slots[1] = hw_config->slots[1];
-
-               unload_uart401(&hw_config2);
-       }
-}
-
-static struct address_info cfg;
-static struct address_info cfg_mpu;
-
-static int __initdata io       = -1;
-static int __initdata irq      = -1;
-static int __initdata dma      = -1;
-static int __initdata dma2     = -1;
-static int __initdata mpuio    = -1;
-static int __initdata mpuirq   = -1;
-static int __initdata synthio  = -1;
-static int __initdata synthirq = -1;
-static int __initdata isapnp   = 1;
-
-static unsigned int cs4232_devices;
-
-MODULE_DESCRIPTION("CS4232 based soundcard driver"); 
-MODULE_AUTHOR("Hannu Savolainen, Paul Barton-Davis"); 
-MODULE_LICENSE("GPL");
-
-module_param(io, int, 0);
-MODULE_PARM_DESC(io,"base I/O port for AD1848");
-module_param(irq, int, 0);
-MODULE_PARM_DESC(irq,"IRQ for AD1848 chip");
-module_param(dma, int, 0);
-MODULE_PARM_DESC(dma,"8 bit DMA for AD1848 chip");
-module_param(dma2, int, 0);
-MODULE_PARM_DESC(dma2,"16 bit DMA for AD1848 chip");
-module_param(mpuio, int, 0);
-MODULE_PARM_DESC(mpuio,"MPU 401 base address");
-module_param(mpuirq, int, 0);
-MODULE_PARM_DESC(mpuirq,"MPU 401 IRQ");
-module_param(synthio, int, 0);
-MODULE_PARM_DESC(synthio,"Maui WaveTable base I/O port");
-module_param(synthirq, int, 0);
-MODULE_PARM_DESC(synthirq,"Maui WaveTable IRQ");
-module_param(isapnp, bool, 0);
-MODULE_PARM_DESC(isapnp,"Enable ISAPnP probing (default 1)");
-module_param(bss, bool, 0);
-MODULE_PARM_DESC(bss,"Enable Bose Sound System Support (default 0)");
-
-/*
- *     Install a CS4232 based card. Need to have ad1848 and mpu401
- *     loaded ready.
- */
-
-/* All cs4232 based cards have the main ad1848 card either as CSC0000 or
- * CSC0100. */
-static const struct pnp_device_id cs4232_pnp_table[] = {
-       { .id = "CSC0100", .driver_data = 0 },
-       { .id = "CSC0000", .driver_data = 0 },
-       /* Guillemot Turtlebeach something appears to be cs4232 compatible
-        * (untested) */
-       { .id = "GIM0100", .driver_data = 0 },
-       { .id = ""}
-};
-
-MODULE_DEVICE_TABLE(pnp, cs4232_pnp_table);
-
-static int __init cs4232_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
-{
-       struct address_info *isapnpcfg;
-
-       isapnpcfg = kmalloc(sizeof(*isapnpcfg),GFP_KERNEL);
-       if (!isapnpcfg)
-               return -ENOMEM;
-
-       isapnpcfg->irq          = pnp_irq(dev, 0);
-       isapnpcfg->dma          = pnp_dma(dev, 0);
-       isapnpcfg->dma2         = pnp_dma(dev, 1);
-       isapnpcfg->io_base      = pnp_port_start(dev, 0);
-       if (probe_cs4232(isapnpcfg,TRUE) == 0) {
-               printk(KERN_ERR "cs4232: ISA PnP card found, but not detected?\n");
-               kfree(isapnpcfg);
-               return -ENODEV;
-       }
-       pnp_set_drvdata(dev,isapnpcfg);
-       cs4232_devices++;
-       return 0;
-}
-
-static void __devexit cs4232_pnp_remove(struct pnp_dev *dev)
-{
-       struct address_info *cfg = pnp_get_drvdata(dev);
-       if (cfg) {
-               unload_cs4232(cfg);
-               kfree(cfg);
-       }
-}
-
-static struct pnp_driver cs4232_driver = {
-       .name           = "cs4232",
-       .id_table       = cs4232_pnp_table,
-       .probe          = cs4232_pnp_probe,
-       .remove         = __devexit_p(cs4232_pnp_remove),
-};
-
-static int __init init_cs4232(void)
-{
-#ifdef CONFIG_SOUND_WAVEFRONT_MODULE
-       if(synthio == -1)
-               printk(KERN_INFO "cs4232: set synthio and synthirq to use the wavefront facilities.\n");
-       else {
-               synth_base = synthio;
-               synth_irq =  synthirq;
-       }
-#else
-       if(synthio != -1)
-               printk(KERN_WARNING "cs4232: wavefront support not enabled in this driver.\n");
-#endif
-       cfg.irq = -1;
-
-       if (isapnp) {
-               pnp_register_driver(&cs4232_driver);
-               if (cs4232_devices)
-                       return 0;
-       }
-
-       if(io==-1||irq==-1||dma==-1)
-       {
-               printk(KERN_ERR "cs4232: Must set io, irq and dma.\n");
-               return -ENODEV;
-       }
-
-       cfg.io_base = io;
-       cfg.irq = irq;
-       cfg.dma = dma;
-       cfg.dma2 = dma2;
-
-       cfg_mpu.io_base = -1;
-       cfg_mpu.irq = -1;
-
-       if (mpuio != -1 && mpuirq != -1) {
-               cfg_mpu.io_base = mpuio;
-               cfg_mpu.irq = mpuirq;
-               probe_cs4232_mpu(&cfg_mpu); /* Bug always returns 0 not OK -- AC */
-       }
-
-       if (probe_cs4232(&cfg,FALSE) == 0)
-               return -ENODEV;
-
-       return 0;
-}
-
-static void __exit cleanup_cs4232(void)
-{
-       pnp_unregister_driver(&cs4232_driver);
-        if (cfg.irq != -1)
-               unload_cs4232(&cfg); /* Unloads global MPU as well, if needed */
-}
-
-module_init(init_cs4232);
-module_exit(cleanup_cs4232);
-
-#ifndef MODULE
-static int __init setup_cs4232(char *str)
-{
-       /* io, irq, dma, dma2 mpuio, mpuirq*/
-       int ints[7];
-
-       /* If we have isapnp cards, no need for options */
-       pnp_register_driver(&cs4232_driver);
-       if (cs4232_devices)
-               return 1;
-       
-       str = get_options(str, ARRAY_SIZE(ints), ints);
-       
-       io      = ints[1];
-       irq     = ints[2];
-       dma     = ints[3];
-       dma2    = ints[4];
-       mpuio   = ints[5];
-       mpuirq  = ints[6];
-
-       return 1;
-}
-
-__setup("cs4232=", setup_cs4232);
-#endif
index 71b313479f8331c8ce8e0b0c3e91f19a7699bdaf..3eb782720e58e3a00ffbabb11fb63bfbd38bf5ae 100644 (file)
@@ -14,7 +14,7 @@ config DMASOUND_ATARI
 
 config DMASOUND_PAULA
        tristate "Amiga DMA sound support"
-       depends on (AMIGA || APUS) && SOUND
+       depends on AMIGA && SOUND
        select DMASOUND
        help
          If you want to use the internal audio of your Amiga in Linux, answer
index 90fc058e1159a60b7bd6c52917a061a24d1e9c49..202e8103dc4da39bffe0d740ae56bef1de2a2ceb 100644 (file)
@@ -91,10 +91,6 @@ static irqreturn_t AmiInterrupt(int irq, void *dummy);
      *  power LED are controlled by the same line.
      */
 
-#ifdef CONFIG_APUS
-#define mach_heartbeat ppc_md.heartbeat
-#endif
-
 static void (*saved_heartbeat)(int) = NULL;
 
 static inline void disable_heartbeat(void)
diff --git a/sound/oss/i810_audio.c b/sound/oss/i810_audio.c
deleted file mode 100644 (file)
index f5e31f1..0000000
+++ /dev/null
@@ -1,3656 +0,0 @@
-/*
- *     Intel i810 and friends ICH driver for Linux
- *     Alan Cox <alan@redhat.com>
- *
- *  Built from:
- *     Low level code:  Zach Brown (original nonworking i810 OSS driver)
- *                      Jaroslav Kysela <perex@suse.cz> (working ALSA driver)
- *
- *     Framework: Thomas Sailer <sailer@ife.ee.ethz.ch>
- *     Extended by: Zach Brown <zab@redhat.com>  
- *                     and others..
- *
- *  Hardware Provided By:
- *     Analog Devices (A major AC97 codec maker)
- *     Intel Corp  (you've probably heard of them already)
- *
- *  AC97 clues and assistance provided by
- *     Analog Devices
- *     Zach 'Fufu' Brown
- *     Jeff Garzik
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- *     Intel 810 theory of operation
- *
- *     The chipset provides three DMA channels that talk to an AC97
- *     CODEC (AC97 is a digital/analog mixer standard). At its simplest
- *     you get 48Khz audio with basic volume and mixer controls. At the
- *     best you get rate adaption in the codec. We set the card up so
- *     that we never take completion interrupts but instead keep the card
- *     chasing its tail around a ring buffer. This is needed for mmap
- *     mode audio and happens to work rather well for non-mmap modes too.
- *
- *     The board has one output channel for PCM audio (supported) and
- *     a stereo line in and mono microphone input. Again these are normally
- *     locked to 48Khz only. Right now recording is not finished.
- *
- *     There is no midi support, no synth support. Use timidity. To get
- *     esd working you need to use esd -r 48000 as it won't probe 48KHz
- *     by default. mpg123 can't handle 48Khz only audio so use xmms.
- *
- *     Fix The Sound On Dell
- *
- *     Not everyone uses 48KHz. We know of no way to detect this reliably
- *     and certainly not to get the right data. If your i810 audio sounds
- *     stupid you may need to investigate other speeds. According to Analog
- *     they tend to use a 14.318MHz clock which gives you a base rate of
- *     41194Hz.
- *
- *     This is available via the 'ftsodell=1' option. 
- *
- *     If you need to force a specific rate set the clocking= option
- *
- *     This driver is cursed. (Ben LaHaise)
- *
- *  ICH 3 caveats
- *     Intel errata #7 for ICH3 IO. We need to disable SMI stuff
- *     when codec probing. [Not Yet Done]
- *
- *  ICH 4 caveats
- *
- *     The ICH4 has the feature, that the codec ID doesn't have to be 
- *     congruent with the IO connection.
- * 
- *     Therefore, from driver version 0.23 on, there is a "codec ID" <->
- *     "IO register base offset" mapping (card->ac97_id_map) field.
- *   
- *     Juergen "George" Sawinski (jsaw) 
- */
-#include <linux/module.h>
-#include <linux/string.h>
-#include <linux/ctype.h>
-#include <linux/ioport.h>
-#include <linux/sched.h>
-#include <linux/delay.h>
-#include <linux/sound.h>
-#include <linux/slab.h>
-#include <linux/soundcard.h>
-#include <linux/pci.h>
-#include <linux/interrupt.h>
-#include <asm/io.h>
-#include <asm/dma.h>
-#include <linux/init.h>
-#include <linux/poll.h>
-#include <linux/spinlock.h>
-#include <linux/smp_lock.h>
-#include <linux/ac97_codec.h>
-#include <linux/bitops.h>
-#include <linux/mutex.h>
-#include <linux/mm.h>
-
-#include <asm/uaccess.h>
-
-#define DRIVER_VERSION "1.01"
-
-#define MODULOP2(a, b) ((a) & ((b) - 1))
-#define MASKP2(a, b) ((a) & ~((b) - 1))
-
-static int ftsodell;
-static int strict_clocking;
-static unsigned int clocking;
-static int spdif_locked;
-static int ac97_quirk = AC97_TUNE_DEFAULT;
-
-//#define DEBUG
-//#define DEBUG2
-//#define DEBUG_INTERRUPTS
-//#define DEBUG_MMAP
-//#define DEBUG_MMIO
-
-#define ADC_RUNNING    1
-#define DAC_RUNNING    2
-
-#define I810_FMT_16BIT 1
-#define I810_FMT_STEREO        2
-#define I810_FMT_MASK  3
-
-#define SPDIF_ON       0x0004
-#define SURR_ON                0x0010
-#define CENTER_LFE_ON  0x0020
-#define VOL_MUTED      0x8000
-
-/* the 810's array of pointers to data buffers */
-
-struct sg_item {
-#define BUSADDR_MASK   0xFFFFFFFE
-       u32 busaddr;    
-#define CON_IOC        0x80000000 /* interrupt on completion */
-#define CON_BUFPAD     0x40000000 /* pad underrun with last sample, else 0 */
-#define CON_BUFLEN_MASK        0x0000ffff /* buffer length in samples */
-       u32 control;
-};
-
-/* an instance of the i810 channel */
-#define SG_LEN 32
-struct i810_channel 
-{
-       /* these sg guys should probably be allocated
-          separately as nocache. Must be 8 byte aligned */
-       struct sg_item sg[SG_LEN];      /* 32*8 */
-       u32 offset;                     /* 4 */
-       u32 port;                       /* 4 */
-       u32 used;
-       u32 num;
-};
-
-/*
- * we have 3 separate dma engines.  pcm in, pcm out, and mic.
- * each dma engine has controlling registers.  These goofy
- * names are from the datasheet, but make it easy to write
- * code while leafing through it.
- *
- * ICH4 has 6 dma engines, pcm in, pcm out, mic, pcm in 2, 
- * mic in 2, s/pdif.   Of special interest is the fact that
- * the upper 3 DMA engines on the ICH4 *must* be accessed
- * via mmio access instead of pio access.
- */
-
-#define ENUM_ENGINE(PRE,DIG)                                                                   \
-enum {                                                                                         \
-       PRE##_BASE =    0x##DIG##0,             /* Base Address */                              \
-       PRE##_BDBAR =   0x##DIG##0,             /* Buffer Descriptor list Base Address */       \
-       PRE##_CIV =     0x##DIG##4,             /* Current Index Value */                       \
-       PRE##_LVI =     0x##DIG##5,             /* Last Valid Index */                          \
-       PRE##_SR =      0x##DIG##6,             /* Status Register */                           \
-       PRE##_PICB =    0x##DIG##8,             /* Position In Current Buffer */                \
-       PRE##_PIV =     0x##DIG##a,             /* Prefetched Index Value */                    \
-       PRE##_CR =      0x##DIG##b              /* Control Register */                          \
-}
-
-ENUM_ENGINE(OFF,0);    /* Offsets */
-ENUM_ENGINE(PI,0);     /* PCM In */
-ENUM_ENGINE(PO,1);     /* PCM Out */
-ENUM_ENGINE(MC,2);     /* Mic In */
-
-enum {
-       GLOB_CNT =      0x2c,                   /* Global Control */
-       GLOB_STA =      0x30,                   /* Global Status */
-       CAS      =      0x34                    /* Codec Write Semaphore Register */
-};
-
-ENUM_ENGINE(MC2,4);     /* Mic In 2 */
-ENUM_ENGINE(PI2,5);     /* PCM In 2 */
-ENUM_ENGINE(SP,6);      /* S/PDIF */
-
-enum {
-       SDM =           0x80                    /* SDATA_IN Map Register */
-};
-
-/* interrupts for a dma engine */
-#define DMA_INT_FIFO           (1<<4)  /* fifo under/over flow */
-#define DMA_INT_COMPLETE       (1<<3)  /* buffer read/write complete and ioc set */
-#define DMA_INT_LVI            (1<<2)  /* last valid done */
-#define DMA_INT_CELV           (1<<1)  /* last valid is current */
-#define DMA_INT_DCH            (1)     /* DMA Controller Halted (happens on LVI interrupts) */
-#define DMA_INT_MASK (DMA_INT_FIFO|DMA_INT_COMPLETE|DMA_INT_LVI)
-
-/* interrupts for the whole chip */
-#define INT_SEC                (1<<11)
-#define INT_PRI                (1<<10)
-#define INT_MC         (1<<7)
-#define INT_PO         (1<<6)
-#define INT_PI         (1<<5)
-#define INT_MO         (1<<2)
-#define INT_NI         (1<<1)
-#define INT_GPI                (1<<0)
-#define INT_MASK (INT_SEC|INT_PRI|INT_MC|INT_PO|INT_PI|INT_MO|INT_NI|INT_GPI)
-
-/* magic numbers to protect our data structures */
-#define I810_CARD_MAGIC                0x5072696E /* "Prin" */
-#define I810_STATE_MAGIC       0x63657373 /* "cess" */
-#define I810_DMA_MASK          0xffffffff /* DMA buffer mask for pci_alloc_consist */
-#define NR_HW_CH               3
-
-/* maxinum number of AC97 codecs connected, AC97 2.0 defined 4 */
-#define NR_AC97                 4
-
-/* Please note that an 8bit mono stream is not valid on this card, you must have a 16bit */
-/* stream at a minimum for this card to be happy */
-static const unsigned sample_size[] = { 1, 2, 2, 4 };
-/* Samples are 16bit values, so we are shifting to a word, not to a byte, hence shift */
-/* values are one less than might be expected */
-static const unsigned sample_shift[] = { -1, 0, 0, 1 };
-
-enum {
-       ICH82801AA = 0,
-       ICH82901AB,
-       INTEL440MX,
-       INTELICH2,
-       INTELICH3,
-       INTELICH4,
-       INTELICH5,
-       SI7012,
-       NVIDIA_NFORCE,
-       AMD768,
-       AMD8111
-};
-
-static char * card_names[] = {
-       "Intel ICH 82801AA",
-       "Intel ICH 82901AB",
-       "Intel 440MX",
-       "Intel ICH2",
-       "Intel ICH3",
-       "Intel ICH4",
-       "Intel ICH5",
-       "SiS 7012",
-       "NVIDIA nForce Audio",
-       "AMD 768",
-       "AMD-8111 IOHub"
-};
-
-/* These are capabilities (and bugs) the chipsets _can_ have */
-static struct {
-       int16_t      nr_ac97;
-#define CAP_MMIO                 0x0001
-#define CAP_20BIT_AUDIO_SUPPORT  0x0002
-       u_int16_t flags;
-} card_cap[] = {
-       {  1, 0x0000 }, /* ICH82801AA */
-       {  1, 0x0000 }, /* ICH82901AB */
-       {  1, 0x0000 }, /* INTEL440MX */
-       {  1, 0x0000 }, /* INTELICH2 */
-       {  2, 0x0000 }, /* INTELICH3 */
-       {  3, 0x0003 }, /* INTELICH4 */
-       {  3, 0x0003 }, /* INTELICH5 */
-       /*@FIXME to be verified*/       {  2, 0x0000 }, /* SI7012 */
-       /*@FIXME to be verified*/       {  2, 0x0000 }, /* NVIDIA_NFORCE */
-       /*@FIXME to be verified*/       {  2, 0x0000 }, /* AMD768 */
-       /*@FIXME to be verified*/       {  3, 0x0001 }, /* AMD8111 */
-};
-
-static struct pci_device_id i810_pci_tbl [] = {
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_5,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, ICH82801AA},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_5,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, ICH82901AB},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_440MX,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTEL440MX},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_4,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH2},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_5,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH3},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_5,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_5,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH5},
-       {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7012,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, SI7012},
-       {PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
-       {PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
-       {PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
-       {PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_OPUS_7445,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD768},
-       {PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_AUDIO,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD8111},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_5,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_18,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
-       {PCI_VENDOR_ID_NVIDIA,  PCI_DEVICE_ID_NVIDIA_CK804_AUDIO,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
-       {0,}
-};
-
-MODULE_DEVICE_TABLE (pci, i810_pci_tbl);
-
-#ifdef CONFIG_PM
-#define PM_SUSPENDED(card) (card->pm_suspended)
-#else
-#define PM_SUSPENDED(card) (0)
-#endif
-
-/* "software" or virtual channel, an instance of opened /dev/dsp */
-struct i810_state {
-       unsigned int magic;
-       struct i810_card *card; /* Card info */
-
-       /* single open lock mechanism, only used for recording */
-       struct mutex open_mutex;
-       wait_queue_head_t open_wait;
-
-       /* file mode */
-       mode_t open_mode;
-
-       /* virtual channel number */
-       int virt;
-
-#ifdef CONFIG_PM
-       unsigned int pm_saved_dac_rate,pm_saved_adc_rate;
-#endif
-       struct dmabuf {
-               /* wave sample stuff */
-               unsigned int rate;
-               unsigned char fmt, enable, trigger;
-
-               /* hardware channel */
-               struct i810_channel *read_channel;
-               struct i810_channel *write_channel;
-
-               /* OSS buffer management stuff */
-               void *rawbuf;
-               dma_addr_t dma_handle;
-               unsigned buforder;
-               unsigned numfrag;
-               unsigned fragshift;
-
-               /* our buffer acts like a circular ring */
-               unsigned hwptr;         /* where dma last started, updated by update_ptr */
-               unsigned swptr;         /* where driver last clear/filled, updated by read/write */
-               int count;              /* bytes to be consumed or been generated by dma machine */
-               unsigned total_bytes;   /* total bytes dmaed by hardware */
-
-               unsigned error;         /* number of over/underruns */
-               wait_queue_head_t wait; /* put process on wait queue when no more space in buffer */
-
-               /* redundant, but makes calculations easier */
-               /* what the hardware uses */
-               unsigned dmasize;
-               unsigned fragsize;
-               unsigned fragsamples;
-
-               /* what we tell the user to expect */
-               unsigned userfrags;
-               unsigned userfragsize;
-
-               /* OSS stuff */
-               unsigned mapped:1;
-               unsigned ready:1;
-               unsigned update_flag;
-               unsigned ossfragsize;
-               unsigned ossmaxfrags;
-               unsigned subdivision;
-       } dmabuf;
-};
-
-
-struct i810_card {
-       unsigned int magic;
-
-       /* We keep i810 cards in a linked list */
-       struct i810_card *next;
-
-       /* The i810 has a certain amount of cross channel interaction
-          so we use a single per card lock */
-       spinlock_t lock;
-       
-       /* Control AC97 access serialization */
-       spinlock_t ac97_lock;
-
-       /* PCI device stuff */
-       struct pci_dev * pci_dev;
-       u16 pci_id;
-       u16 pci_id_internal; /* used to access card_cap[] */
-#ifdef CONFIG_PM       
-       u16 pm_suspended;
-       int pm_saved_mixer_settings[SOUND_MIXER_NRDEVICES][NR_AC97];
-#endif
-       /* soundcore stuff */
-       int dev_audio;
-
-       /* structures for abstraction of hardware facilities, codecs, banks and channels*/
-       u16    ac97_id_map[NR_AC97];
-       struct ac97_codec *ac97_codec[NR_AC97];
-       struct i810_state *states[NR_HW_CH];
-       struct i810_channel *channel;   /* 1:1 to states[] but diff. lifetime */
-       dma_addr_t chandma;
-
-       u16 ac97_features;
-       u16 ac97_status;
-       u16 channels;
-       
-       /* hardware resources */
-       unsigned long ac97base;
-       unsigned long iobase;
-       u32 irq;
-
-       unsigned long ac97base_mmio_phys;
-       unsigned long iobase_mmio_phys;
-       u_int8_t __iomem *ac97base_mmio;
-       u_int8_t __iomem *iobase_mmio;
-
-       int           use_mmio;
-       
-       /* Function support */
-       struct i810_channel *(*alloc_pcm_channel)(struct i810_card *);
-       struct i810_channel *(*alloc_rec_pcm_channel)(struct i810_card *);
-       struct i810_channel *(*alloc_rec_mic_channel)(struct i810_card *);
-       void (*free_pcm_channel)(struct i810_card *, int chan);
-
-       /* We have a *very* long init time possibly, so use this to block */
-       /* attempts to open our devices before we are ready (stops oops'es) */
-       int initializing;
-};
-
-/* extract register offset from codec struct */
-#define IO_REG_OFF(codec) (((struct i810_card *) codec->private_data)->ac97_id_map[codec->id])
-
-#define I810_IOREAD(size, type, card, off)                             \
-({                                                                     \
-       type val;                                                       \
-       if (card->use_mmio)                                             \
-               val=read##size(card->iobase_mmio+off);                  \
-       else                                                            \
-               val=in##size(card->iobase+off);                         \
-       val;                                                            \
-})
-
-#define I810_IOREADL(card, off)                I810_IOREAD(l, u32, card, off)
-#define I810_IOREADW(card, off)                I810_IOREAD(w, u16, card, off)
-#define I810_IOREADB(card, off)                I810_IOREAD(b, u8,  card, off)
-
-#define I810_IOWRITE(size, val, card, off)                             \
-({                                                                     \
-       if (card->use_mmio)                                             \
-               write##size(val, card->iobase_mmio+off);                \
-       else                                                            \
-               out##size(val, card->iobase+off);                       \
-})
-
-#define I810_IOWRITEL(val, card, off)  I810_IOWRITE(l, val, card, off)
-#define I810_IOWRITEW(val, card, off)  I810_IOWRITE(w, val, card, off)
-#define I810_IOWRITEB(val, card, off)  I810_IOWRITE(b, val, card, off)
-
-#define GET_CIV(card, port) MODULOP2(I810_IOREADB((card), (port) + OFF_CIV), SG_LEN)
-#define GET_LVI(card, port) MODULOP2(I810_IOREADB((card), (port) + OFF_LVI), SG_LEN)
-
-/* set LVI from CIV */
-#define CIV_TO_LVI(card, port, off) \
-       I810_IOWRITEB(MODULOP2(GET_CIV((card), (port)) + (off), SG_LEN), (card), (port) + OFF_LVI)
-
-static struct ac97_quirk ac97_quirks[] __devinitdata = {
-       {
-               .vendor = 0x0e11,
-               .device = 0x00b8,
-               .name = "Compaq Evo D510C",
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x1028,
-               .device = 0x00d8,
-               .name = "Dell Precision 530",   /* AD1885 */
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x1028,
-               .device = 0x0126,
-               .name = "Dell Optiplex GX260",  /* AD1981A */
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x1028,
-               .device = 0x012d,
-               .name = "Dell Precision 450",   /* AD1981B*/
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {       /* FIXME: which codec? */
-               .vendor = 0x103c,
-               .device = 0x00c3,
-               .name = "Hewlett-Packard onboard",
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x103c,
-               .device = 0x12f1,
-               .name = "HP xw8200",    /* AD1981B*/
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x103c,
-               .device = 0x3008,
-               .name = "HP xw4200",    /* AD1981B*/
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x10f1,
-               .device = 0x2665,
-               .name = "Fujitsu-Siemens Celsius",      /* AD1981? */
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x10f1,
-               .device = 0x2885,
-               .name = "AMD64 Mobo",   /* ALC650 */
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x110a,
-               .device = 0x0056,
-               .name = "Fujitsu-Siemens Scenic",       /* AD1981? */
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x11d4,
-               .device = 0x5375,
-               .name = "ADI AD1985 (discrete)",
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x1462,
-               .device = 0x5470,
-               .name = "MSI P4 ATX 645 Ultra",
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x1734,
-               .device = 0x0088,
-               .name = "Fujitsu-Siemens D1522",        /* AD1981 */
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x8086,
-               .device = 0x4856,
-               .name = "Intel D845WN (82801BA)",
-               .type = AC97_TUNE_SWAP_HP
-       },
-       {
-               .vendor = 0x8086,
-               .device = 0x4d44,
-               .name = "Intel D850EMV2",       /* AD1885 */
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x8086,
-               .device = 0x4d56,
-               .name = "Intel ICH/AD1885",
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x1028,
-               .device = 0x012d,
-               .name = "Dell Precision 450",   /* AD1981B*/
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x103c,
-               .device = 0x3008,
-               .name = "HP xw4200",    /* AD1981B*/
-               .type = AC97_TUNE_HP_ONLY
-       },
-       {
-               .vendor = 0x103c,
-               .device = 0x12f1,
-               .name = "HP xw8200",    /* AD1981B*/
-               .type = AC97_TUNE_HP_ONLY
-       },
-       { } /* terminator */
-};
-
-static struct i810_card *devs = NULL;
-
-static int i810_open_mixdev(struct inode *inode, struct file *file);
-static int i810_ioctl_mixdev(struct inode *inode, struct file *file,
-                            unsigned int cmd, unsigned long arg);
-static u16 i810_ac97_get(struct ac97_codec *dev, u8 reg);
-static void i810_ac97_set(struct ac97_codec *dev, u8 reg, u16 data);
-static u16 i810_ac97_get_mmio(struct ac97_codec *dev, u8 reg);
-static void i810_ac97_set_mmio(struct ac97_codec *dev, u8 reg, u16 data);
-static u16 i810_ac97_get_io(struct ac97_codec *dev, u8 reg);
-static void i810_ac97_set_io(struct ac97_codec *dev, u8 reg, u16 data);
-
-static struct i810_channel *i810_alloc_pcm_channel(struct i810_card *card)
-{
-       if(card->channel[1].used==1)
-               return NULL;
-       card->channel[1].used=1;
-       return &card->channel[1];
-}
-
-static struct i810_channel *i810_alloc_rec_pcm_channel(struct i810_card *card)
-{
-       if(card->channel[0].used==1)
-               return NULL;
-       card->channel[0].used=1;
-       return &card->channel[0];
-}
-
-static struct i810_channel *i810_alloc_rec_mic_channel(struct i810_card *card)
-{
-       if(card->channel[2].used==1)
-               return NULL;
-       card->channel[2].used=1;
-       return &card->channel[2];
-}
-
-static void i810_free_pcm_channel(struct i810_card *card, int channel)
-{
-       card->channel[channel].used=0;
-}
-
-static int i810_valid_spdif_rate ( struct ac97_codec *codec, int rate )
-{
-       unsigned long id = 0L;
-
-       id = (i810_ac97_get(codec, AC97_VENDOR_ID1) << 16);
-       id |= i810_ac97_get(codec, AC97_VENDOR_ID2) & 0xffff;
-#ifdef DEBUG
-       printk ( "i810_audio: codec = %s, codec_id = 0x%08lx\n", codec->name, id);
-#endif
-       switch ( id ) {
-               case 0x41445361: /* AD1886 */
-                       if (rate == 48000) {
-                               return 1;
-                       }
-                       break;
-               default: /* all other codecs, until we know otherwiae */
-                       if (rate == 48000 || rate == 44100 || rate == 32000) {
-                               return 1;
-                       }
-                       break;
-       }
-       return (0);
-}
-
-/* i810_set_spdif_output
- * 
- *  Configure the S/PDIF output transmitter. When we turn on
- *  S/PDIF, we turn off the analog output. This may not be
- *  the right thing to do.
- *
- *  Assumptions:
- *     The DSP sample rate must already be set to a supported
- *     S/PDIF rate (32kHz, 44.1kHz, or 48kHz) or we abort.
- */
-static int i810_set_spdif_output(struct i810_state *state, int slots, int rate)
-{
-       int     vol;
-       int     aud_reg;
-       int     r = 0;
-       struct ac97_codec *codec = state->card->ac97_codec[0];
-
-       if(!codec->codec_ops->digital) {
-               state->card->ac97_status &= ~SPDIF_ON;
-       } else {
-               if ( slots == -1 ) { /* Turn off S/PDIF */
-                       codec->codec_ops->digital(codec, 0, 0, 0);
-                       /* If the volume wasn't muted before we turned on S/PDIF, unmute it */
-                       if ( !(state->card->ac97_status & VOL_MUTED) ) {
-                               aud_reg = i810_ac97_get(codec, AC97_MASTER_VOL_STEREO);
-                               i810_ac97_set(codec, AC97_MASTER_VOL_STEREO, (aud_reg & ~VOL_MUTED));
-                       }
-                       state->card->ac97_status &= ~(VOL_MUTED | SPDIF_ON);
-                       return 0;
-               }
-
-               vol = i810_ac97_get(codec, AC97_MASTER_VOL_STEREO);
-               state->card->ac97_status = vol & VOL_MUTED;
-               
-               r = codec->codec_ops->digital(codec, slots, rate, 0);
-
-               if(r)
-                       state->card->ac97_status |= SPDIF_ON;
-               else
-                       state->card->ac97_status &= ~SPDIF_ON;
-
-               /* Mute the analog output */
-               /* Should this only mute the PCM volume??? */
-               i810_ac97_set(codec, AC97_MASTER_VOL_STEREO, (vol | VOL_MUTED));
-       }
-       return r;
-}
-
-/* i810_set_dac_channels
- *
- *  Configure the codec's multi-channel DACs
- *
- *  The logic is backwards. Setting the bit to 1 turns off the DAC. 
- *
- *  What about the ICH? We currently configure it using the
- *  SNDCTL_DSP_CHANNELS ioctl.  If we're turnning on the DAC, 
- *  does that imply that we want the ICH set to support
- *  these channels?
- *  
- *  TODO:
- *    vailidate that the codec really supports these DACs
- *    before turning them on. 
- */
-static void i810_set_dac_channels(struct i810_state *state, int channel)
-{
-       int     aud_reg;
-       struct ac97_codec *codec = state->card->ac97_codec[0];
-       
-       /* No codec, no setup */
-       
-       if(codec == NULL)
-               return;
-
-       aud_reg = i810_ac97_get(codec, AC97_EXTENDED_STATUS);
-       aud_reg |= AC97_EA_PRI | AC97_EA_PRJ | AC97_EA_PRK;
-       state->card->ac97_status &= ~(SURR_ON | CENTER_LFE_ON);
-
-       switch ( channel ) {
-               case 2: /* always enabled */
-                       break;
-               case 4:
-                       aud_reg &= ~AC97_EA_PRJ;
-                       state->card->ac97_status |= SURR_ON;
-                       break;
-               case 6:
-                       aud_reg &= ~(AC97_EA_PRJ | AC97_EA_PRI | AC97_EA_PRK);
-                       state->card->ac97_status |= SURR_ON | CENTER_LFE_ON;
-                       break;
-               default:
-                       break;
-       }
-       i810_ac97_set(codec, AC97_EXTENDED_STATUS, aud_reg);
-
-}
-
-
-/* set playback sample rate */
-static unsigned int i810_set_dac_rate(struct i810_state * state, unsigned int rate)
-{      
-       struct dmabuf *dmabuf = &state->dmabuf;
-       u32 new_rate;
-       struct ac97_codec *codec=state->card->ac97_codec[0];
-       
-       if(!(state->card->ac97_features&0x0001))
-       {
-               dmabuf->rate = clocking;
-#ifdef DEBUG
-               printk("Asked for %d Hz, but ac97_features says we only do %dHz.  Sorry!\n",
-                      rate,clocking);
-#endif                
-               return clocking;
-       }
-                       
-       if (rate > 48000)
-               rate = 48000;
-       if (rate < 8000)
-               rate = 8000;
-       dmabuf->rate = rate;
-               
-       /*
-        *      Adjust for misclocked crap
-        */
-       rate = ( rate * clocking)/48000;
-       if(strict_clocking && rate < 8000) {
-               rate = 8000;
-               dmabuf->rate = (rate * 48000)/clocking;
-       }
-
-        new_rate=ac97_set_dac_rate(codec, rate);
-       if(new_rate != rate) {
-               dmabuf->rate = (new_rate * 48000)/clocking;
-       }
-#ifdef DEBUG
-       printk("i810_audio: called i810_set_dac_rate : asked for %d, got %d\n", rate, dmabuf->rate);
-#endif
-       rate = new_rate;
-       return dmabuf->rate;
-}
-
-/* set recording sample rate */
-static unsigned int i810_set_adc_rate(struct i810_state * state, unsigned int rate)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       u32 new_rate;
-       struct ac97_codec *codec=state->card->ac97_codec[0];
-       
-       if(!(state->card->ac97_features&0x0001))
-       {
-               dmabuf->rate = clocking;
-               return clocking;
-       }
-                       
-       if (rate > 48000)
-               rate = 48000;
-       if (rate < 8000)
-               rate = 8000;
-       dmabuf->rate = rate;
-
-       /*
-        *      Adjust for misclocked crap
-        */
-        
-       rate = ( rate * clocking)/48000;
-       if(strict_clocking && rate < 8000) {
-               rate = 8000;
-               dmabuf->rate = (rate * 48000)/clocking;
-       }
-
-       new_rate = ac97_set_adc_rate(codec, rate);
-       
-       if(new_rate != rate) {
-               dmabuf->rate = (new_rate * 48000)/clocking;
-               rate = new_rate;
-       }
-#ifdef DEBUG
-       printk("i810_audio: called i810_set_adc_rate : rate = %d/%d\n", dmabuf->rate, rate);
-#endif
-       return dmabuf->rate;
-}
-
-/* get current playback/recording dma buffer pointer (byte offset from LBA),
-   called with spinlock held! */
-   
-static inline unsigned i810_get_dma_addr(struct i810_state *state, int rec)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       unsigned int civ, offset, port, port_picb, bytes = 2;
-       
-       if (!dmabuf->enable)
-               return 0;
-
-       if (rec)
-               port = dmabuf->read_channel->port;
-       else
-               port = dmabuf->write_channel->port;
-
-       if(state->card->pci_id == PCI_DEVICE_ID_SI_7012) {
-               port_picb = port + OFF_SR;
-               bytes = 1;
-       } else
-               port_picb = port + OFF_PICB;
-
-       do {
-               civ = GET_CIV(state->card, port);
-               offset = I810_IOREADW(state->card, port_picb);
-               /* Must have a delay here! */ 
-               if(offset == 0)
-                       udelay(1);
-               /* Reread both registers and make sure that that total
-                * offset from the first reading to the second is 0.
-                * There is an issue with SiS hardware where it will count
-                * picb down to 0, then update civ to the next value,
-                * then set the new picb to fragsize bytes.  We can catch
-                * it between the civ update and the picb update, making
-                * it look as though we are 1 fragsize ahead of where we
-                * are.  The next to we get the address though, it will
-                * be back in the right place, and we will suddenly think
-                * we just went forward dmasize - fragsize bytes, causing
-                * totally stupid *huge* dma overrun messages.  We are
-                * assuming that the 1us delay is more than long enough
-                * that we won't have to worry about the chip still being
-                * out of sync with reality ;-)
-                */
-       } while (civ != GET_CIV(state->card, port) || offset != I810_IOREADW(state->card, port_picb));
-                
-       return (((civ + 1) * dmabuf->fragsize - (bytes * offset))
-               % dmabuf->dmasize);
-}
-
-/* Stop recording (lock held) */
-static inline void __stop_adc(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       struct i810_card *card = state->card;
-
-       dmabuf->enable &= ~ADC_RUNNING;
-       I810_IOWRITEB(0, card, PI_CR);
-       // wait for the card to acknowledge shutdown
-       while( I810_IOREADB(card, PI_CR) != 0 ) ;
-       // now clear any latent interrupt bits (like the halt bit)
-       if(card->pci_id == PCI_DEVICE_ID_SI_7012)
-               I810_IOWRITEB( I810_IOREADB(card, PI_PICB), card, PI_PICB );
-       else
-               I810_IOWRITEB( I810_IOREADB(card, PI_SR), card, PI_SR );
-       I810_IOWRITEL( I810_IOREADL(card, GLOB_STA) & INT_PI, card, GLOB_STA);
-}
-
-static void stop_adc(struct i810_state *state)
-{
-       struct i810_card *card = state->card;
-       unsigned long flags;
-
-       spin_lock_irqsave(&card->lock, flags);
-       __stop_adc(state);
-       spin_unlock_irqrestore(&card->lock, flags);
-}
-
-static inline void __start_adc(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-
-       if (dmabuf->count < dmabuf->dmasize && dmabuf->ready && !dmabuf->enable &&
-           (dmabuf->trigger & PCM_ENABLE_INPUT)) {
-               dmabuf->enable |= ADC_RUNNING;
-               // Interrupt enable, LVI enable, DMA enable
-               I810_IOWRITEB(0x10 | 0x04 | 0x01, state->card, PI_CR);
-       }
-}
-
-static void start_adc(struct i810_state *state)
-{
-       struct i810_card *card = state->card;
-       unsigned long flags;
-
-       spin_lock_irqsave(&card->lock, flags);
-       __start_adc(state);
-       spin_unlock_irqrestore(&card->lock, flags);
-}
-
-/* stop playback (lock held) */
-static inline void __stop_dac(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       struct i810_card *card = state->card;
-
-       dmabuf->enable &= ~DAC_RUNNING;
-       I810_IOWRITEB(0, card, PO_CR);
-       // wait for the card to acknowledge shutdown
-       while( I810_IOREADB(card, PO_CR) != 0 ) ;
-       // now clear any latent interrupt bits (like the halt bit)
-       if(card->pci_id == PCI_DEVICE_ID_SI_7012)
-               I810_IOWRITEB( I810_IOREADB(card, PO_PICB), card, PO_PICB );
-       else
-               I810_IOWRITEB( I810_IOREADB(card, PO_SR), card, PO_SR );
-       I810_IOWRITEL( I810_IOREADL(card, GLOB_STA) & INT_PO, card, GLOB_STA);
-}
-
-static void stop_dac(struct i810_state *state)
-{
-       struct i810_card *card = state->card;
-       unsigned long flags;
-
-       spin_lock_irqsave(&card->lock, flags);
-       __stop_dac(state);
-       spin_unlock_irqrestore(&card->lock, flags);
-}      
-
-static inline void __start_dac(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-
-       if (dmabuf->count > 0 && dmabuf->ready && !dmabuf->enable &&
-           (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
-               dmabuf->enable |= DAC_RUNNING;
-               // Interrupt enable, LVI enable, DMA enable
-               I810_IOWRITEB(0x10 | 0x04 | 0x01, state->card, PO_CR);
-       }
-}
-static void start_dac(struct i810_state *state)
-{
-       struct i810_card *card = state->card;
-       unsigned long flags;
-
-       spin_lock_irqsave(&card->lock, flags);
-       __start_dac(state);
-       spin_unlock_irqrestore(&card->lock, flags);
-}
-
-#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
-#define DMABUF_MINORDER 1
-
-/* allocate DMA buffer, playback and recording buffer should be allocated separately */
-static int alloc_dmabuf(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       void *rawbuf= NULL;
-       int order, size;
-       struct page *page, *pend;
-
-       /* If we don't have any oss frag params, then use our default ones */
-       if(dmabuf->ossmaxfrags == 0)
-               dmabuf->ossmaxfrags = 4;
-       if(dmabuf->ossfragsize == 0)
-               dmabuf->ossfragsize = (PAGE_SIZE<<DMABUF_DEFAULTORDER)/dmabuf->ossmaxfrags;
-       size = dmabuf->ossfragsize * dmabuf->ossmaxfrags;
-
-       if(dmabuf->rawbuf && (PAGE_SIZE << dmabuf->buforder) == size)
-               return 0;
-       /* alloc enough to satisfy the oss params */
-       for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--) {
-               if ( (PAGE_SIZE<<order) > size )
-                       continue;
-               if ((rawbuf = pci_alloc_consistent(state->card->pci_dev,
-                                                  PAGE_SIZE << order,
-                                                  &dmabuf->dma_handle)))
-                       break;
-       }
-       if (!rawbuf)
-               return -ENOMEM;
-
-
-#ifdef DEBUG
-       printk("i810_audio: allocated %ld (order = %d) bytes at %p\n",
-              PAGE_SIZE << order, order, rawbuf);
-#endif
-
-       dmabuf->ready  = dmabuf->mapped = 0;
-       dmabuf->rawbuf = rawbuf;
-       dmabuf->buforder = order;
-       
-       /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
-       pend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1);
-       for (page = virt_to_page(rawbuf); page <= pend; page++)
-               SetPageReserved(page);
-
-       return 0;
-}
-
-/* free DMA buffer */
-static void dealloc_dmabuf(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       struct page *page, *pend;
-
-       if (dmabuf->rawbuf) {
-               /* undo marking the pages as reserved */
-               pend = virt_to_page(dmabuf->rawbuf + (PAGE_SIZE << dmabuf->buforder) - 1);
-               for (page = virt_to_page(dmabuf->rawbuf); page <= pend; page++)
-                       ClearPageReserved(page);
-               pci_free_consistent(state->card->pci_dev, PAGE_SIZE << dmabuf->buforder,
-                                   dmabuf->rawbuf, dmabuf->dma_handle);
-       }
-       dmabuf->rawbuf = NULL;
-       dmabuf->mapped = dmabuf->ready = 0;
-}
-
-static int prog_dmabuf(struct i810_state *state, unsigned rec)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       struct i810_channel *c;
-       struct sg_item *sg;
-       unsigned long flags;
-       int ret;
-       unsigned fragint;
-       int i;
-
-       spin_lock_irqsave(&state->card->lock, flags);
-       if(dmabuf->enable & DAC_RUNNING)
-               __stop_dac(state);
-       if(dmabuf->enable & ADC_RUNNING)
-               __stop_adc(state);
-       dmabuf->total_bytes = 0;
-       dmabuf->count = dmabuf->error = 0;
-       dmabuf->swptr = dmabuf->hwptr = 0;
-       spin_unlock_irqrestore(&state->card->lock, flags);
-
-       /* allocate DMA buffer, let alloc_dmabuf determine if we are already
-        * allocated well enough or if we should replace the current buffer
-        * (assuming one is already allocated, if it isn't, then allocate it).
-        */
-       if ((ret = alloc_dmabuf(state)))
-               return ret;
-
-       /* FIXME: figure out all this OSS fragment stuff */
-       /* I did, it now does what it should according to the OSS API.  DL */
-       /* We may not have realloced our dmabuf, but the fragment size to
-        * fragment number ratio may have changed, so go ahead and reprogram
-        * things
-        */
-       dmabuf->dmasize = PAGE_SIZE << dmabuf->buforder;
-       dmabuf->numfrag = SG_LEN;
-       dmabuf->fragsize = dmabuf->dmasize/dmabuf->numfrag;
-       dmabuf->fragsamples = dmabuf->fragsize >> 1;
-       dmabuf->fragshift = ffs(dmabuf->fragsize) - 1;
-       dmabuf->userfragsize = dmabuf->ossfragsize;
-       dmabuf->userfrags = dmabuf->dmasize/dmabuf->ossfragsize;
-
-       memset(dmabuf->rawbuf, 0, dmabuf->dmasize);
-
-       if(dmabuf->ossmaxfrags == 4) {
-               fragint = 8;
-       } else if (dmabuf->ossmaxfrags == 8) {
-               fragint = 4;
-       } else if (dmabuf->ossmaxfrags == 16) {
-               fragint = 2;
-       } else {
-               fragint = 1;
-       }
-       /*
-        *      Now set up the ring 
-        */
-       if(dmabuf->read_channel)
-               c = dmabuf->read_channel;
-       else
-               c = dmabuf->write_channel;
-       while(c != NULL) {
-               sg=&c->sg[0];
-               /*
-                *      Load up 32 sg entries and take an interrupt at half
-                *      way (we might want more interrupts later..) 
-                */
-         
-               for(i=0;i<dmabuf->numfrag;i++)
-               {
-                       sg->busaddr=(u32)dmabuf->dma_handle+dmabuf->fragsize*i;
-                       // the card will always be doing 16bit stereo
-                       sg->control=dmabuf->fragsamples;
-                       if(state->card->pci_id == PCI_DEVICE_ID_SI_7012)
-                               sg->control <<= 1;
-                       sg->control|=CON_BUFPAD;
-                       // set us up to get IOC interrupts as often as needed to
-                       // satisfy numfrag requirements, no more
-                       if( ((i+1) % fragint) == 0) {
-                               sg->control|=CON_IOC;
-                       }
-                       sg++;
-               }
-               spin_lock_irqsave(&state->card->lock, flags);
-               I810_IOWRITEB(2, state->card, c->port+OFF_CR);   /* reset DMA machine */
-               while( I810_IOREADB(state->card, c->port+OFF_CR) & 0x02 ) ;
-               I810_IOWRITEL((u32)state->card->chandma +
-                   c->num*sizeof(struct i810_channel),
-                   state->card, c->port+OFF_BDBAR);
-               CIV_TO_LVI(state->card, c->port, 0);
-
-               spin_unlock_irqrestore(&state->card->lock, flags);
-
-               if(c != dmabuf->write_channel)
-                       c = dmabuf->write_channel;
-               else
-                       c = NULL;
-       }
-       
-       /* set the ready flag for the dma buffer */
-       dmabuf->ready = 1;
-
-#ifdef DEBUG
-       printk("i810_audio: prog_dmabuf, sample rate = %d, format = %d,\n\tnumfrag = %d, "
-              "fragsize = %d dmasize = %d\n",
-              dmabuf->rate, dmabuf->fmt, dmabuf->numfrag,
-              dmabuf->fragsize, dmabuf->dmasize);
-#endif
-
-       return 0;
-}
-
-static void __i810_update_lvi(struct i810_state *state, int rec)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       int x, port;
-       int trigger;
-       int count, fragsize;
-       void (*start)(struct i810_state *);
-
-       count = dmabuf->count;
-       if (rec) {
-               port = dmabuf->read_channel->port;
-               trigger = PCM_ENABLE_INPUT;
-               start = __start_adc;
-               count = dmabuf->dmasize - count;
-       } else {
-               port = dmabuf->write_channel->port;
-               trigger = PCM_ENABLE_OUTPUT;
-               start = __start_dac;
-       }
-
-       /* Do not process partial fragments. */
-       fragsize = dmabuf->fragsize;
-       if (count < fragsize)
-               return;
-
-       /* if we are currently stopped, then our CIV is actually set to our
-        * *last* sg segment and we are ready to wrap to the next.  However,
-        * if we set our LVI to the last sg segment, then it won't wrap to
-        * the next sg segment, it won't even get a start.  So, instead, when
-        * we are stopped, we set both the LVI value and also we increment
-        * the CIV value to the next sg segment to be played so that when
-        * we call start, things will operate properly.  Since the CIV can't
-        * be written to directly for this purpose, we set the LVI to CIV + 1
-        * temporarily.  Once the engine has started we set the LVI to its
-        * final value.
-        */
-       if (!dmabuf->enable && dmabuf->ready) {
-               if (!(dmabuf->trigger & trigger))
-                       return;
-
-               CIV_TO_LVI(state->card, port, 1);
-
-               start(state);
-               while (!(I810_IOREADB(state->card, port + OFF_CR) & ((1<<4) | (1<<2))))
-                       ;
-       }
-
-       /* MASKP2(swptr, fragsize) - 1 is the tail of our transfer */
-       x = MODULOP2(MASKP2(dmabuf->swptr, fragsize) - 1, dmabuf->dmasize);
-       x >>= dmabuf->fragshift;
-       I810_IOWRITEB(x, state->card, port + OFF_LVI);
-}
-
-static void i810_update_lvi(struct i810_state *state, int rec)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       unsigned long flags;
-
-       if(!dmabuf->ready)
-               return;
-       spin_lock_irqsave(&state->card->lock, flags);
-       __i810_update_lvi(state, rec);
-       spin_unlock_irqrestore(&state->card->lock, flags);
-}
-
-/* update buffer manangement pointers, especially, dmabuf->count and dmabuf->hwptr */
-static void i810_update_ptr(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       unsigned hwptr;
-       unsigned fragmask, dmamask;
-       int diff;
-
-       fragmask = MASKP2(~0, dmabuf->fragsize);
-       dmamask = MODULOP2(~0, dmabuf->dmasize);
-
-       /* error handling and process wake up for ADC */
-       if (dmabuf->enable == ADC_RUNNING) {
-               /* update hardware pointer */
-               hwptr = i810_get_dma_addr(state, 1) & fragmask;
-               diff = (hwptr - dmabuf->hwptr) & dmamask;
-#if defined(DEBUG_INTERRUPTS) || defined(DEBUG_MMAP)
-               printk("ADC HWP %d,%d,%d\n", hwptr, dmabuf->hwptr, diff);
-#endif
-               dmabuf->hwptr = hwptr;
-               dmabuf->total_bytes += diff;
-               dmabuf->count += diff;
-               if (dmabuf->count > dmabuf->dmasize) {
-                       /* buffer underrun or buffer overrun */
-                       /* this is normal for the end of a read */
-                       /* only give an error if we went past the */
-                       /* last valid sg entry */
-                       if (GET_CIV(state->card, PI_BASE) !=
-                           GET_LVI(state->card, PI_BASE)) {
-                               printk(KERN_WARNING "i810_audio: DMA overrun on read\n");
-                               dmabuf->error++;
-                       }
-               }
-               if (diff)
-                       wake_up(&dmabuf->wait);
-       }
-       /* error handling and process wake up for DAC */
-       if (dmabuf->enable == DAC_RUNNING) {
-               /* update hardware pointer */
-               hwptr = i810_get_dma_addr(state, 0) & fragmask;
-               diff = (hwptr - dmabuf->hwptr) & dmamask;
-#if defined(DEBUG_INTERRUPTS) || defined(DEBUG_MMAP)
-               printk("DAC HWP %d,%d,%d\n", hwptr, dmabuf->hwptr, diff);
-#endif
-               dmabuf->hwptr = hwptr;
-               dmabuf->total_bytes += diff;
-               dmabuf->count -= diff;
-               if (dmabuf->count < 0) {
-                       /* buffer underrun or buffer overrun */
-                       /* this is normal for the end of a write */
-                       /* only give an error if we went past the */
-                       /* last valid sg entry */
-                       if (GET_CIV(state->card, PO_BASE) !=
-                           GET_LVI(state->card, PO_BASE)) {
-                               printk(KERN_WARNING "i810_audio: DMA overrun on write\n");
-                               printk("i810_audio: CIV %d, LVI %d, hwptr %x, "
-                                       "count %d\n",
-                                       GET_CIV(state->card, PO_BASE),
-                                       GET_LVI(state->card, PO_BASE),
-                                       dmabuf->hwptr, dmabuf->count);
-                               dmabuf->error++;
-                       }
-               }
-               if (diff)
-                       wake_up(&dmabuf->wait);
-       }
-}
-
-static inline int i810_get_free_write_space(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       int free;
-
-       i810_update_ptr(state);
-       // catch underruns during playback
-       if (dmabuf->count < 0) {
-               dmabuf->count = 0;
-               dmabuf->swptr = dmabuf->hwptr;
-       }
-       free = dmabuf->dmasize - dmabuf->count;
-       if(free < 0)
-               return(0);
-       return(free);
-}
-
-static inline int i810_get_available_read_data(struct i810_state *state)
-{
-       struct dmabuf *dmabuf = &state->dmabuf;
-       int avail;
-
-       i810_update_ptr(state);
-       // catch overruns during record
-       if (dmabuf->count > dmabuf->dmasize) {
-               dmabuf->count = dmabuf->dmasize;
-               dmabuf->swptr = dmabuf->hwptr;
-       }
-       avail = dmabuf->count;
-       if(avail < 0)
-               return(0);
-       return(avail);
-}
-
-static inline void fill_partial_frag(struct dmabuf *dmabuf)
-{
-       unsigned fragsize;
-       unsigned swptr, len;
-
-       fragsize = dmabuf->fragsize;
-       swptr = dmabuf->swptr;
-       len = fragsize - MODULOP2(dmabuf->swptr, fragsize);
-       if (len == fragsize)
-               return;
-
-       memset(dmabuf->rawbuf + swptr, '\0', len);
-       dmabuf->swptr = MODULOP2(swptr + len, dmabuf->dmasize);
-       dmabuf->count += len;
-}
-
-static int drain_dac(struct i810_state *state, int signals_allowed)
-{
-       DECLARE_WAITQUEUE(wait, current);
-       struct dmabuf *dmabuf = &state->dmabuf;
-       unsigned long flags;
-       unsigned long tmo;
-       int count;
-
-       if (!dmabuf->ready)
-               return 0;
-       if(dmabuf->mapped) {
-               stop_dac(state);
-               return 0;
-       }
-
-       spin_lock_irqsave(&state->card->lock, flags);
-
-       fill_partial_frag(dmabuf);
-
-       /* 
-        * This will make sure that our LVI is correct, that our
-        * pointer is updated, and that the DAC is running.  We
-        * have to force the setting of dmabuf->trigger to avoid
-        * any possible deadlocks.
-        */
-       dmabuf->trigger = PCM_ENABLE_OUTPUT;
-       __i810_update_lvi(state, 0);
-
-       spin_unlock_irqrestore(&state->card->lock, flags);
-
-       add_wait_queue(&dmabuf->wait, &wait);
-       for (;;) {
-
-               spin_lock_irqsave(&state->card->lock, flags);
-               i810_update_ptr(state);
-               count = dmabuf->count;
-
-               /* It seems that we have to set the current state to
-                * TASK_INTERRUPTIBLE every time to make the process
-                * really go to sleep.  This also has to be *after* the
-                * update_ptr() call because update_ptr is likely to
-                * do a wake_up() which will unset this before we ever
-                * try to sleep, resuling in a tight loop in this code
-                * instead of actually sleeping and waiting for an
-                * interrupt to wake us up!
-                */
-               __set_current_state(signals_allowed ?
-                                   TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
-               spin_unlock_irqrestore(&state->card->lock, flags);
-
-               if (count <= 0)
-                       break;
-
-                if (signal_pending(current) && signals_allowed) {
-                        break;
-                }
-
-               /*
-                * set the timeout to significantly longer than it *should*
-                * take for the DAC to drain the DMA buffer
-                */
-               tmo = (count * HZ) / (dmabuf->rate);
-               if (!schedule_timeout(tmo >= 2 ? tmo : 2)){
-                       printk(KERN_ERR "i810_audio: drain_dac, dma timeout?\n");
-                       count = 0;
-                       break;
-               }
-       }
-       set_current_state(TASK_RUNNING);
-       remove_wait_queue(&dmabuf->wait, &wait);
-       if(count > 0 && signal_pending(current) && signals_allowed)
-               return -ERESTARTSYS;
-       stop_dac(state);
-       return 0;
-}
-
-static void i810_channel_interrupt(struct i810_card *card)
-{
-       int i, count;
-       
-#ifdef DEBUG_INTERRUPTS
-       printk("CHANNEL ");
-#endif
-       for(i=0;i<NR_HW_CH;i++)
-       {
-               struct i810_state *state = card->states[i];
-               struct i810_channel *c;
-               struct dmabuf *dmabuf;
-               unsigned long port;
-               u16 status;
-               
-               if(!state)
-                       continue;
-               if(!state->dmabuf.ready)
-                       continue;
-               dmabuf = &state->dmabuf;
-               if(dmabuf->enable & DAC_RUNNING) {
-                       c=dmabuf->write_channel;
-               } else if(dmabuf->enable & ADC_RUNNING) {
-                       c=dmabuf->read_channel;
-               } else  /* This can occur going from R/W to close */
-                       continue;
-               
-               port = c->port;
-
-               if(card->pci_id == PCI_DEVICE_ID_SI_7012)
-                       status = I810_IOREADW(card, port + OFF_PICB);
-               else
-                       status = I810_IOREADW(card, port + OFF_SR);
-
-#ifdef DEBUG_INTERRUPTS
-               printk("NUM %d PORT %X IRQ ( ST%d ", c->num, c->port, status);
-#endif
-               if(status & DMA_INT_COMPLETE)
-               {
-                       /* only wake_up() waiters if this interrupt signals
-                        * us being beyond a userfragsize of data open or
-                        * available, and i810_update_ptr() does that for
-                        * us
-                        */
-                       i810_update_ptr(state);
-#ifdef DEBUG_INTERRUPTS
-                       printk("COMP %d ", dmabuf->hwptr /
-                                       dmabuf->fragsize);
-#endif
-               }
-               if(status & (DMA_INT_LVI | DMA_INT_DCH))
-               {
-                       /* wake_up() unconditionally on LVI and DCH */
-                       i810_update_ptr(state);
-                       wake_up(&dmabuf->wait);
-#ifdef DEBUG_INTERRUPTS
-                       if(status & DMA_INT_LVI)
-                               printk("LVI ");
-                       if(status & DMA_INT_DCH)
-                               printk("DCH -");
-#endif
-                       count = dmabuf->count;
-                       if(dmabuf->enable & ADC_RUNNING)
-                               count = dmabuf->dmasize - count;
-                       if (count >= (int)dmabuf->fragsize) {
-                               I810_IOWRITEB(I810_IOREADB(card, port+OFF_CR) | 1, card, port+OFF_CR);
-#ifdef DEBUG_INTERRUPTS
-                               printk(" CONTINUE ");
-#endif
-                       } else {
-                               if (dmabuf->enable & DAC_RUNNING)
-                                       __stop_dac(state);
-                               if (dmabuf->enable & ADC_RUNNING)
-                                       __stop_adc(state);
-                               dmabuf->enable = 0;
-#ifdef DEBUG_INTERRUPTS
-                               printk(" STOP ");
-#endif
-                       }
-               }
-               if(card->pci_id == PCI_DEVICE_ID_SI_7012)
-                       I810_IOWRITEW(status & DMA_INT_MASK, card, port + OFF_PICB);
-               else
-                       I810_IOWRITEW(status & DMA_INT_MASK, card, port + OFF_SR);
-       }
-#ifdef DEBUG_INTERRUPTS
-       printk(")\n");
-#endif
-}
-
-static irqreturn_t i810_interrupt(int irq, void *dev_id)
-{
-       struct i810_card *card = dev_id;
-       u32 status;
-
-       spin_lock(&card->lock);
-
-       status = I810_IOREADL(card, GLOB_STA);
-
-       if(!(status & INT_MASK)) 
-       {
-               spin_unlock(&card->lock);
-               return IRQ_NONE;  /* not for us */
-       }
-
-       if(status & (INT_PO|INT_PI|INT_MC))
-               i810_channel_interrupt(card);
-
-       /* clear 'em */
-       I810_IOWRITEL(status & INT_MASK, card, GLOB_STA);
-       spin_unlock(&card->lock);
-       return IRQ_HANDLED;
-}
-
-/* in this loop, dmabuf.count signifies the amount of data that is
-   waiting to be copied to the user's buffer.  It is filled by the dma
-   machine and drained by this loop. */
-
-static ssize_t i810_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
-{
-       struct i810_state *state = (struct i810_state *)file->private_data;
-       struct i810_card *card=state ? state->card : NULL;
-       struct dmabuf *dmabuf = &state->dmabuf;
-       ssize_t ret;
-       unsigned long flags;
-       unsigned int swptr;
-       int cnt;
-       int pending;
-        DECLARE_WAITQUEUE(waita, current);
-
-#ifdef DEBUG2
-       printk("i810_audio: i810_read called, count = %d\n", count);
-#endif
-
-       if (dmabuf->mapped)
-               return -ENXIO;
-       if (dmabuf->enable & DAC_RUNNING)
-               return -ENODEV;
-       if (!dmabuf->read_channel) {
-               dmabuf->ready = 0;
-               dmabuf->read_channel = card->alloc_rec_pcm_channel(card);
-               if (!dmabuf->read_channel) {
-                       return -EBUSY;
-               }
-       }
-       if (!dmabuf->ready && (ret = prog_dmabuf(state, 1)))
-               return ret;
-       if (!access_ok(VERIFY_WRITE, buffer, count))
-               return -EFAULT;
-       ret = 0;
-
-       pending = 0;
-
-        add_wait_queue(&dmabuf->wait, &waita);
-       while (count > 0) {
-               set_current_state(TASK_INTERRUPTIBLE);
-               spin_lock_irqsave(&card->lock, flags);
-                if (PM_SUSPENDED(card)) {
-                        spin_unlock_irqrestore(&card->lock, flags);
-                        schedule();
-                        if (signal_pending(current)) {
-                                if (!ret) ret = -EAGAIN;
-                                break;
-                        }
-                        continue;
-                }
-               cnt = i810_get_available_read_data(state);
-               swptr = dmabuf->swptr;
-               // this is to make the copy_to_user simpler below
-               if(cnt > (dmabuf->dmasize - swptr))
-                       cnt = dmabuf->dmasize - swptr;
-               spin_unlock_irqrestore(&card->lock, flags);
-
-               if (cnt > count)
-                       cnt = count;
-               if (cnt <= 0) {
-                       unsigned long tmo;
-                       /*
-                        * Don't let us deadlock.  The ADC won't start if
-                        * dmabuf->trigger isn't set.  A call to SETTRIGGER
-                        * could have turned it off after we set it to on
-                        * previously.
-                        */
-                       dmabuf->trigger = PCM_ENABLE_INPUT;
-                       /*
-                        * This does three things.  Updates LVI to be correct,
-                        * makes sure the ADC is running, and updates the
-                        * hwptr.
-                        */
-                       i810_update_lvi(state,1);
-                       if (file->f_flags & O_NONBLOCK) {
-                               if (!ret) ret = -EAGAIN;
-                               goto done;
-                       }
-                       /* Set the timeout to how long it would take to fill
-                        * two of our buffers.  If we haven't been woke up
-                        * by then, then we know something is wrong.
-                        */
-                       tmo = (dmabuf->dmasize * HZ * 2) / (dmabuf->rate * 4);
-                       /* There are two situations when sleep_on_timeout returns, one is when
-                          the interrupt is serviced correctly and the process is waked up by
-                          ISR ON TIME. Another is when timeout is expired, which means that
-                          either interrupt is NOT serviced correctly (pending interrupt) or it
-                          is TOO LATE for the process to be scheduled to run (scheduler latency)
-                          which results in a (potential) buffer overrun. And worse, there is
-                          NOTHING we can do to prevent it. */
-                       if (!schedule_timeout(tmo >= 2 ? tmo : 2)) {
-#ifdef DEBUG
-                               printk(KERN_ERR "i810_audio: recording schedule timeout, "
-                                      "dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
-                                      dmabuf->dmasize, dmabuf->fragsize, dmabuf->count,
-                                      dmabuf->hwptr, dmabuf->swptr);
-#endif
-                               /* a buffer overrun, we delay the recovery until next time the
-                                  while loop begin and we REALLY have space to record */
-                       }
-                       if (signal_pending(current)) {
-                               ret = ret ? ret : -ERESTARTSYS;
-                               goto done;
-                       }
-                       continue;
-               }
-
-               if (copy_to_user(buffer, dmabuf->rawbuf + swptr, cnt)) {
-                       if (!ret) ret = -EFAULT;
-                       goto done;
-               }
-
-               swptr = MODULOP2(swptr + cnt, dmabuf->dmasize);
-
-               spin_lock_irqsave(&card->lock, flags);
-
-                if (PM_SUSPENDED(card)) {
-                        spin_unlock_irqrestore(&card->lock, flags);
-                        continue;
-                }
-               dmabuf->swptr = swptr;
-               pending = dmabuf->count -= cnt;
-               spin_unlock_irqrestore(&card->lock, flags);
-
-               count -= cnt;
-               buffer += cnt;
-               ret += cnt;
-       }
- done:
-       pending = dmabuf->dmasize - pending;
-       if (dmabuf->enable || pending >= dmabuf->userfragsize)
-               i810_update_lvi(state, 1);
-        set_current_state(TASK_RUNNING);
-        remove_wait_queue(&dmabuf->wait, &waita);
-
-       return ret;
-}
-
-/* in this loop, dmabuf.count signifies the amount of data that is waiting to be dma to
-   the soundcard.  it is drained by the dma machine and filled by this loop. */
-static ssize_t i810_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
-{
-       struct i810_state *state = (struct i810_state *)file->private_data;
-       struct i810_card *card=state ? state->card : NULL;
-       struct dmabuf *dmabuf = &state->dmabuf;
-       ssize_t ret;
-       unsigned long flags;
-       unsigned int swptr = 0;
-       int pending;
-       int cnt;
-        DECLARE_WAITQUEUE(waita, current);
-
-#ifdef DEBUG2
-       printk("i810_audio: i810_write called, count = %d\n", count);
-#endif
-
-       if (dmabuf->mapped)
-               return -ENXIO;
-       if (dmabuf->enable & ADC_RUNNING)
-               return -ENODEV;
-       if (!dmabuf->write_channel) {
-               dmabuf->ready = 0;
-               dmabuf->write_channel = card->alloc_pcm_channel(card);
-               if(!dmabuf->write_channel)
-                       return -EBUSY;
-       }
-       if (!dmabuf->ready && (ret = prog_dmabuf(state, 0)))
-               return ret;
-       if (!access_ok(VERIFY_READ, buffer, count))
-               return -EFAULT;
-       ret = 0;
-
-       pending = 0;
-
-        add_wait_queue(&dmabuf->wait, &waita);
-       while (count > 0) {
-               set_current_state(TASK_INTERRUPTIBLE);
-               spin_lock_irqsave(&state->card->lock, flags);
-                if (PM_SUSPENDED(card)) {
-                        spin_unlock_irqrestore(&card->lock, flags);
-                        schedule();
-                        if (signal_pending(current)) {
-                                if (!ret) ret = -EAGAIN;
-                                break;
-                        }
-                        continue;
-                }
-
-               cnt = i810_get_free_write_space(state);
-               swptr = dmabuf->swptr;
-               /* Bound the maximum size to how much we can copy to the
-                * dma buffer before we hit the end.  If we have more to
-                * copy then it will get done in a second pass of this
-                * loop starting from the beginning of the buffer.
-                */
-               if(cnt > (dmabuf->dmasize - swptr))
-                       cnt = dmabuf->dmasize - swptr;
-               spin_unlock_irqrestore(&state->card->lock, flags);
-
-#ifdef DEBUG2
-               printk(KERN_INFO "i810_audio: i810_write: %d bytes available space\n", cnt);
-#endif
-               if (cnt > count)
-                       cnt = count;
-               if (cnt <= 0) {
-                       unsigned long tmo;
-                       // There is data waiting to be played
-                       /*
-                        * Force the trigger setting since we would
-                        * deadlock with it set any other way
-                        */
-                       dmabuf->trigger = PCM_ENABLE_OUTPUT;
-                       i810_update_lvi(state,0);
-                       if (file->f_flags & O_NONBLOCK) {
-                               if (!ret) ret = -EAGAIN;
-                               goto ret;
-                       }
-                       /* Not strictly correct but works */
-                       tmo = (dmabuf->dmasize * HZ * 2) / (dmabuf->rate * 4);
-                       /* There are two situations when sleep_on_timeout returns, one is when
-                          the interrupt is serviced correctly and the process is waked up by
-                          ISR ON TIME. Another is when timeout is expired, which means that
-                          either interrupt is NOT serviced correctly (pending interrupt) or it
-                          is TOO LATE for the process to be scheduled to run (scheduler latency)
-                          which results in a (potential) buffer underrun. And worse, there is
-                          NOTHING we can do to prevent it. */
-                       if (!schedule_timeout(tmo >= 2 ? tmo : 2)) {
-#ifdef DEBUG
-                               printk(KERN_ERR "i810_audio: playback schedule timeout, "
-                                      "dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
-                                      dmabuf->dmasize, dmabuf->fragsize, dmabuf->count,
-                                      dmabuf->hwptr, dmabuf->swptr);
-#endif
-                               /* a buffer underrun, we delay the recovery until next time the
-                                  while loop begin and we REALLY have data to play */
-                               //return ret;
-                       }
-                       if (signal_pending(current)) {
-                               if (!ret) ret = -ERESTARTSYS;
-                               goto ret;
-                       }
-                       continue;
-               }
-               if (copy_from_user(dmabuf->rawbuf+swptr,buffer,cnt)) {
-                       if (!ret) ret = -EFAULT;
-                       goto ret;
-               }
-
-               swptr = MODULOP2(swptr + cnt, dmabuf->dmasize);
-
-               spin_lock_irqsave(&state->card->lock, flags);
-                if (PM_SUSPENDED(card)) {
-                        spin_unlock_irqrestore(&card->lock, flags);
-                        continue;
-                }
-
-               dmabuf->swptr = swptr;
-               pending = dmabuf->count += cnt;
-
-               count -= cnt;
-               buffer += cnt;
-               ret += cnt;
-               spin_unlock_irqrestore(&state->card->lock, flags);
-       }
-ret:
-       if (dmabuf->enable || pending >= dmabuf->userfragsize)
-               i810_update_lvi(state, 0);
-        set_current_state(TASK_RUNNING);
-        remove_wait_queue(&dmabuf->wait, &waita);
-
-       return ret;
-}
-
-/* No kernel lock - we have our own spinlock */
-static unsigned int i810_poll(struct file *file, struct poll_table_struct *wait)
-{
-       struct i810_state *state = (struct i810_state *)file->private_data;
-       struct dmabuf *dmabuf = &state->dmabuf;
-       unsigned long flags;
-       unsigned int mask = 0;
-
-       if(!dmabuf->ready)
-               return 0;
-       poll_wait(file, &dmabuf->wait, wait);
-       spin_lock_irqsave(&state->card->lock, flags);
-       if (dmabuf->enable & ADC_RUNNING ||
-           dmabuf->trigger & PCM_ENABLE_INPUT) {
-               if (i810_get_available_read_data(state) >= 
-                   (signed)dmabuf->userfragsize)
-                       mask |= POLLIN | POLLRDNORM;
-       }
-       if (dmabuf->enable & DAC_RUNNING ||
-           dmabuf->trigger & PCM_ENABLE_OUTPUT) {
-               if (i810_get_free_write_space(state) >=
-                   (signed)dmabuf->userfragsize)
-                       mask |= POLLOUT | POLLWRNORM;
-       }
-       spin_unlock_irqrestore(&state->card->lock, flags);
-       return mask;
-}
-
-static int i810_mmap(struct file *file, struct vm_area_struct *vma)
-{
-       struct i810_state *state = (struct i810_state *)file->private_data;
-       struct dmabuf *dmabuf = &state->dmabuf;
-       int ret = -EINVAL;
-       unsigned long size;
-
-       lock_kernel();
-       if (vma->vm_flags & VM_WRITE) {
-               if (!dmabuf->write_channel &&
-                   (dmabuf->write_channel =
-                    state->card->alloc_pcm_channel(state->card)) == NULL) {
-                       ret = -EBUSY;
-                       goto out;
-               }
-       }
-       if (vma->vm_flags & VM_READ) {
-               if (!dmabuf->read_channel &&
-                   (dmabuf->read_channel = 
-                    state->card->alloc_rec_pcm_channel(state->card)) == NULL) {
-                       ret = -EBUSY;
-                       goto out;
-               }
-       }
-       if ((ret = prog_dmabuf(state, 0)) != 0)
-               goto out;
-
-       ret = -EINVAL;
-       if (vma->vm_pgoff != 0)
-               goto out;
-       size = vma->vm_end - vma->vm_start;
-       if (size > (PAGE_SIZE << dmabuf->buforder))
-               goto out;
-       ret = -EAGAIN;
-       if (remap_pfn_range(vma, vma->vm_start,
-                            virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT,
-                            size, vma->vm_page_prot))
-               goto out;
-       dmabuf->mapped = 1;
-       dmabuf->trigger = 0;
-       ret = 0;
-#ifdef DEBUG_MMAP
-       printk("i810_audio: mmap'ed %ld bytes of data space\n", size);
-#endif
-out:
-       unlock_kernel();
-       return ret;
-}
-
-static int i810_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-{
-       struct i810_state *state = (struct i810_state *)file->private_data;
-       struct i810_channel *c = NULL;
-       struct dmabuf *dmabuf = &state->dmabuf;
-       unsigned long flags;
-       audio_buf_info abinfo;
-       count_info cinfo;
-       unsigned int i_glob_cnt;
-       int val = 0, ret;
-       struct ac97_codec *codec = state->card->ac97_codec[0];
-       void __user *argp = (void __user *)arg;
-       int __user *p = argp;
-
-#ifdef DEBUG
-       printk("i810_audio: i810_ioctl, arg=0x%x, cmd=", arg ? *p : 0);
-#endif
-
-       switch (cmd) 
-       {
-       case OSS_GETVERSION:
-#ifdef DEBUG
-               printk("OSS_GETVERSION\n");
-#endif
-               return put_user(SOUND_VERSION, p);
-
-       case SNDCTL_DSP_RESET:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_RESET\n");
-#endif
-               spin_lock_irqsave(&state->card->lock, flags);
-               if (dmabuf->enable == DAC_RUNNING) {
-                       c = dmabuf->write_channel;
-                       __stop_dac(state);
-               }
-               if (dmabuf->enable == ADC_RUNNING) {
-                       c = dmabuf->read_channel;
-                       __stop_adc(state);
-               }
-               if (c != NULL) {
-                       I810_IOWRITEB(2, state->card, c->port+OFF_CR);   /* reset DMA machine */
-                       while ( I810_IOREADB(state->card, c->port+OFF_CR) & 2 )
-                               cpu_relax();
-                       I810_IOWRITEL((u32)state->card->chandma +
-                           c->num*sizeof(struct i810_channel),
-                           state->card, c->port+OFF_BDBAR);
-                       CIV_TO_LVI(state->card, c->port, 0);
-               }
-
-               spin_unlock_irqrestore(&state->card->lock, flags);
-               synchronize_irq(state->card->pci_dev->irq);
-               dmabuf->ready = 0;
-               dmabuf->swptr = dmabuf->hwptr = 0;
-               dmabuf->count = dmabuf->total_bytes = 0;
-               return 0;
-
-       case SNDCTL_DSP_SYNC:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_SYNC\n");
-#endif
-               if (dmabuf->enable != DAC_RUNNING || file->f_flags & O_NONBLOCK)
-                       return 0;
-               if((val = drain_dac(state, 1)))
-                       return val;
-               dmabuf->total_bytes = 0;
-               return 0;
-
-       case SNDCTL_DSP_SPEED: /* set smaple rate */
-#ifdef DEBUG
-               printk("SNDCTL_DSP_SPEED\n");
-#endif
-               if (get_user(val, p))
-                       return -EFAULT;
-               if (val >= 0) {
-                       if (file->f_mode & FMODE_WRITE) {
-                               if ( (state->card->ac97_status & SPDIF_ON) ) {  /* S/PDIF Enabled */
-                                       /* AD1886 only supports 48000, need to check that */
-                                       if ( i810_valid_spdif_rate ( codec, val ) ) {
-                                               /* Set DAC rate */
-                                               i810_set_spdif_output ( state, -1, 0 );
-                                               stop_dac(state);
-                                               dmabuf->ready = 0;
-                                               spin_lock_irqsave(&state->card->lock, flags);
-                                               i810_set_dac_rate(state, val);
-                                               spin_unlock_irqrestore(&state->card->lock, flags);
-                                               /* Set S/PDIF transmitter rate. */
-                                               i810_set_spdif_output ( state, AC97_EA_SPSA_3_4, val );
-                                               if ( ! (state->card->ac97_status & SPDIF_ON) ) {
-                                                       val = dmabuf->rate;
-                                               }
-                                       } else { /* Not a valid rate for S/PDIF, ignore it */
-                                               val = dmabuf->rate;
-                                       }
-                               } else {
-                                       stop_dac(state);
-                                       dmabuf->ready = 0;
-                                       spin_lock_irqsave(&state->card->lock, flags);
-                                       i810_set_dac_rate(state, val);
-                                       spin_unlock_irqrestore(&state->card->lock, flags);
-                               }
-                       }
-                       if (file->f_mode & FMODE_READ) {
-                               stop_adc(state);
-                               dmabuf->ready = 0;
-                               spin_lock_irqsave(&state->card->lock, flags);
-                               i810_set_adc_rate(state, val);
-                               spin_unlock_irqrestore(&state->card->lock, flags);
-                       }
-               }
-               return put_user(dmabuf->rate, p);
-
-       case SNDCTL_DSP_STEREO: /* set stereo or mono channel */
-#ifdef DEBUG
-               printk("SNDCTL_DSP_STEREO\n");
-#endif
-               if (dmabuf->enable & DAC_RUNNING) {
-                       stop_dac(state);
-               }
-               if (dmabuf->enable & ADC_RUNNING) {
-                       stop_adc(state);
-               }
-               return put_user(1, p);
-
-       case SNDCTL_DSP_GETBLKSIZE:
-               if (file->f_mode & FMODE_WRITE) {
-                       if (!dmabuf->ready && (val = prog_dmabuf(state, 0)))
-                               return val;
-               }
-               if (file->f_mode & FMODE_READ) {
-                       if (!dmabuf->ready && (val = prog_dmabuf(state, 1)))
-                               return val;
-               }
-#ifdef DEBUG
-               printk("SNDCTL_DSP_GETBLKSIZE %d\n", dmabuf->userfragsize);
-#endif
-               return put_user(dmabuf->userfragsize, p);
-
-       case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format*/
-#ifdef DEBUG
-               printk("SNDCTL_DSP_GETFMTS\n");
-#endif
-               return put_user(AFMT_S16_LE, p);
-
-       case SNDCTL_DSP_SETFMT: /* Select sample format */
-#ifdef DEBUG
-               printk("SNDCTL_DSP_SETFMT\n");
-#endif
-               return put_user(AFMT_S16_LE, p);
-
-       case SNDCTL_DSP_CHANNELS:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_CHANNELS\n");
-#endif
-               if (get_user(val, p))
-                       return -EFAULT;
-
-               if (val > 0) {
-                       if (dmabuf->enable & DAC_RUNNING) {
-                               stop_dac(state);
-                       }
-                       if (dmabuf->enable & ADC_RUNNING) {
-                               stop_adc(state);
-                       }
-               } else {
-                       return put_user(state->card->channels, p);
-               }
-
-               /* ICH and ICH0 only support 2 channels */
-               if ( state->card->pci_id == PCI_DEVICE_ID_INTEL_82801AA_5
-                    || state->card->pci_id == PCI_DEVICE_ID_INTEL_82801AB_5) 
-                       return put_user(2, p);
-       
-               /* Multi-channel support was added with ICH2. Bits in */
-               /* Global Status and Global Control register are now  */
-               /* used to indicate this.                             */
-
-                i_glob_cnt = I810_IOREADL(state->card, GLOB_CNT);
-
-               /* Current # of channels enabled */
-               if ( i_glob_cnt & 0x0100000 )
-                       ret = 4;
-               else if ( i_glob_cnt & 0x0200000 )
-                       ret = 6;
-               else
-                       ret = 2;
-
-               switch ( val ) {
-                       case 2: /* 2 channels is always supported */
-                               I810_IOWRITEL(i_glob_cnt & 0xffcfffff,
-                                    state->card, GLOB_CNT);
-                               /* Do we need to change mixer settings????  */
-                               break;
-                       case 4: /* Supported on some chipsets, better check first */
-                               if ( state->card->channels >= 4 ) {
-                                       I810_IOWRITEL((i_glob_cnt & 0xffcfffff) | 0x100000,
-                                             state->card, GLOB_CNT);
-                                       /* Do we need to change mixer settings??? */
-                               } else {
-                                       val = ret;
-                               }
-                               break;
-                       case 6: /* Supported on some chipsets, better check first */
-                               if ( state->card->channels >= 6 ) {
-                                       I810_IOWRITEL((i_glob_cnt & 0xffcfffff) | 0x200000,
-                                             state->card, GLOB_CNT);
-                                       /* Do we need to change mixer settings??? */
-                               } else {
-                                       val = ret;
-                               }
-                               break;
-                       default: /* nothing else is ever supported by the chipset */
-                               val = ret;
-                               break;
-               }
-
-               return put_user(val, p);
-
-       case SNDCTL_DSP_POST: /* the user has sent all data and is notifying us */
-               /* we update the swptr to the end of the last sg segment then return */
-#ifdef DEBUG
-               printk("SNDCTL_DSP_POST\n");
-#endif
-               if(!dmabuf->ready || (dmabuf->enable != DAC_RUNNING))
-                       return 0;
-               if((dmabuf->swptr % dmabuf->fragsize) != 0) {
-                       val = dmabuf->fragsize - (dmabuf->swptr % dmabuf->fragsize);
-                       dmabuf->swptr += val;
-                       dmabuf->count += val;
-               }
-               return 0;
-
-       case SNDCTL_DSP_SUBDIVIDE:
-               if (dmabuf->subdivision)
-                       return -EINVAL;
-               if (get_user(val, p))
-                       return -EFAULT;
-               if (val != 1 && val != 2 && val != 4)
-                       return -EINVAL;
-#ifdef DEBUG
-               printk("SNDCTL_DSP_SUBDIVIDE %d\n", val);
-#endif
-               dmabuf->subdivision = val;
-               dmabuf->ready = 0;
-               return 0;
-
-       case SNDCTL_DSP_SETFRAGMENT:
-               if (get_user(val, p))
-                       return -EFAULT;
-
-               dmabuf->ossfragsize = 1<<(val & 0xffff);
-               dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
-               if (!dmabuf->ossfragsize || !dmabuf->ossmaxfrags)
-                       return -EINVAL;
-               /*
-                * Bound the frag size into our allowed range of 256 - 4096
-                */
-               if (dmabuf->ossfragsize < 256)
-                       dmabuf->ossfragsize = 256;
-               else if (dmabuf->ossfragsize > 4096)
-                       dmabuf->ossfragsize = 4096;
-               /*
-                * The numfrags could be something reasonable, or it could
-                * be 0xffff meaning "Give me as much as possible".  So,
-                * we check the numfrags * fragsize doesn't exceed our
-                * 64k buffer limit, nor is it less than our 8k minimum.
-                * If it fails either one of these checks, then adjust the
-                * number of fragments, not the size of them.  It's OK if
-                * our number of fragments doesn't equal 32 or anything
-                * like our hardware based number now since we are using
-                * a different frag count for the hardware.  Before we get
-                * into this though, bound the maxfrags to avoid overflow
-                * issues.  A reasonable bound would be 64k / 256 since our
-                * maximum buffer size is 64k and our minimum frag size is
-                * 256.  On the other end, our minimum buffer size is 8k and
-                * our maximum frag size is 4k, so the lower bound should
-                * be 2.
-                */
-
-               if(dmabuf->ossmaxfrags > 256)
-                       dmabuf->ossmaxfrags = 256;
-               else if (dmabuf->ossmaxfrags < 2)
-                       dmabuf->ossmaxfrags = 2;
-
-               val = dmabuf->ossfragsize * dmabuf->ossmaxfrags;
-               while (val < 8192) {
-                   val <<= 1;
-                   dmabuf->ossmaxfrags <<= 1;
-               }
-               while (val > 65536) {
-                   val >>= 1;
-                   dmabuf->ossmaxfrags >>= 1;
-               }
-               dmabuf->ready = 0;
-#ifdef DEBUG
-               printk("SNDCTL_DSP_SETFRAGMENT 0x%x, %d, %d\n", val,
-                       dmabuf->ossfragsize, dmabuf->ossmaxfrags);
-#endif
-
-               return 0;
-
-       case SNDCTL_DSP_GETOSPACE:
-               if (!(file->f_mode & FMODE_WRITE))
-                       return -EINVAL;
-               if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
-                       return val;
-               spin_lock_irqsave(&state->card->lock, flags);
-               i810_update_ptr(state);
-               abinfo.fragsize = dmabuf->userfragsize;
-               abinfo.fragstotal = dmabuf->userfrags;
-               if (dmabuf->mapped)
-                       abinfo.bytes = dmabuf->dmasize;
-               else
-                       abinfo.bytes = i810_get_free_write_space(state);
-               abinfo.fragments = abinfo.bytes / dmabuf->userfragsize;
-               spin_unlock_irqrestore(&state->card->lock, flags);
-#if defined(DEBUG) || defined(DEBUG_MMAP)
-               printk("SNDCTL_DSP_GETOSPACE %d, %d, %d, %d\n", abinfo.bytes,
-                       abinfo.fragsize, abinfo.fragments, abinfo.fragstotal);
-#endif
-               return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
-
-       case SNDCTL_DSP_GETOPTR:
-               if (!(file->f_mode & FMODE_WRITE))
-                       return -EINVAL;
-               if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
-                       return val;
-               spin_lock_irqsave(&state->card->lock, flags);
-               val = i810_get_free_write_space(state);
-               cinfo.bytes = dmabuf->total_bytes;
-               cinfo.ptr = dmabuf->hwptr;
-               cinfo.blocks = val/dmabuf->userfragsize;
-               if (dmabuf->mapped && (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
-                       dmabuf->count += val;
-                       dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
-                       __i810_update_lvi(state, 0);
-               }
-               spin_unlock_irqrestore(&state->card->lock, flags);
-#if defined(DEBUG) || defined(DEBUG_MMAP)
-               printk("SNDCTL_DSP_GETOPTR %d, %d, %d, %d\n", cinfo.bytes,
-                       cinfo.blocks, cinfo.ptr, dmabuf->count);
-#endif
-               return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
-
-       case SNDCTL_DSP_GETISPACE:
-               if (!(file->f_mode & FMODE_READ))
-                       return -EINVAL;
-               if (!dmabuf->ready && (val = prog_dmabuf(state, 1)) != 0)
-                       return val;
-               spin_lock_irqsave(&state->card->lock, flags);
-               abinfo.bytes = i810_get_available_read_data(state);
-               abinfo.fragsize = dmabuf->userfragsize;
-               abinfo.fragstotal = dmabuf->userfrags;
-               abinfo.fragments = abinfo.bytes / dmabuf->userfragsize;
-               spin_unlock_irqrestore(&state->card->lock, flags);
-#if defined(DEBUG) || defined(DEBUG_MMAP)
-               printk("SNDCTL_DSP_GETISPACE %d, %d, %d, %d\n", abinfo.bytes,
-                       abinfo.fragsize, abinfo.fragments, abinfo.fragstotal);
-#endif
-               return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
-
-       case SNDCTL_DSP_GETIPTR:
-               if (!(file->f_mode & FMODE_READ))
-                       return -EINVAL;
-               if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
-                       return val;
-               spin_lock_irqsave(&state->card->lock, flags);
-               val = i810_get_available_read_data(state);
-               cinfo.bytes = dmabuf->total_bytes;
-               cinfo.blocks = val/dmabuf->userfragsize;
-               cinfo.ptr = dmabuf->hwptr;
-               if (dmabuf->mapped && (dmabuf->trigger & PCM_ENABLE_INPUT)) {
-                       dmabuf->count -= val;
-                       dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
-                       __i810_update_lvi(state, 1);
-               }
-               spin_unlock_irqrestore(&state->card->lock, flags);
-#if defined(DEBUG) || defined(DEBUG_MMAP)
-               printk("SNDCTL_DSP_GETIPTR %d, %d, %d, %d\n", cinfo.bytes,
-                       cinfo.blocks, cinfo.ptr, dmabuf->count);
-#endif
-               return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
-
-       case SNDCTL_DSP_NONBLOCK:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_NONBLOCK\n");
-#endif
-               file->f_flags |= O_NONBLOCK;
-               return 0;
-
-       case SNDCTL_DSP_GETCAPS:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_GETCAPS\n");
-#endif
-           return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP|DSP_CAP_BIND,
-                           p);
-
-       case SNDCTL_DSP_GETTRIGGER:
-               val = 0;
-#ifdef DEBUG
-               printk("SNDCTL_DSP_GETTRIGGER 0x%x\n", dmabuf->trigger);
-#endif
-               return put_user(dmabuf->trigger, p);
-
-       case SNDCTL_DSP_SETTRIGGER:
-               if (get_user(val, p))
-                       return -EFAULT;
-#if defined(DEBUG) || defined(DEBUG_MMAP)
-               printk("SNDCTL_DSP_SETTRIGGER 0x%x\n", val);
-#endif
-               /* silently ignore invalid PCM_ENABLE_xxx bits,
-                * like the other drivers do
-                */
-               if (!(file->f_mode & FMODE_READ ))
-                       val &= ~PCM_ENABLE_INPUT;
-               if (!(file->f_mode & FMODE_WRITE ))
-                       val &= ~PCM_ENABLE_OUTPUT;
-               if((file->f_mode & FMODE_READ) && !(val & PCM_ENABLE_INPUT) && dmabuf->enable == ADC_RUNNING) {
-                       stop_adc(state);
-               }
-               if((file->f_mode & FMODE_WRITE) && !(val & PCM_ENABLE_OUTPUT) && dmabuf->enable == DAC_RUNNING) {
-                       stop_dac(state);
-               }
-               dmabuf->trigger = val;
-               if((val & PCM_ENABLE_OUTPUT) && !(dmabuf->enable & DAC_RUNNING)) {
-                       if (!dmabuf->write_channel) {
-                               dmabuf->ready = 0;
-                               dmabuf->write_channel = state->card->alloc_pcm_channel(state->card);
-                               if (!dmabuf->write_channel)
-                                       return -EBUSY;
-                       }
-                       if (!dmabuf->ready && (ret = prog_dmabuf(state, 0)))
-                               return ret;
-                       if (dmabuf->mapped) {
-                               spin_lock_irqsave(&state->card->lock, flags);
-                               i810_update_ptr(state);
-                               dmabuf->count = 0;
-                               dmabuf->swptr = dmabuf->hwptr;
-                               dmabuf->count = i810_get_free_write_space(state);
-                               dmabuf->swptr = (dmabuf->swptr + dmabuf->count) % dmabuf->dmasize;
-                               spin_unlock_irqrestore(&state->card->lock, flags);
-                       }
-                       i810_update_lvi(state, 0);
-                       start_dac(state);
-               }
-               if((val & PCM_ENABLE_INPUT) && !(dmabuf->enable & ADC_RUNNING)) {
-                       if (!dmabuf->read_channel) {
-                               dmabuf->ready = 0;
-                               dmabuf->read_channel = state->card->alloc_rec_pcm_channel(state->card);
-                               if (!dmabuf->read_channel)
-                                       return -EBUSY;
-                       }
-                       if (!dmabuf->ready && (ret = prog_dmabuf(state, 1)))
-                               return ret;
-                       if (dmabuf->mapped) {
-                               spin_lock_irqsave(&state->card->lock, flags);
-                               i810_update_ptr(state);
-                               dmabuf->swptr = dmabuf->hwptr;
-                               dmabuf->count = 0;
-                               spin_unlock_irqrestore(&state->card->lock, flags);
-                       }
-                       i810_update_lvi(state, 1);
-                       start_adc(state);
-               }
-               return 0;
-
-       case SNDCTL_DSP_SETDUPLEX:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_SETDUPLEX\n");
-#endif
-               return -EINVAL;
-
-       case SNDCTL_DSP_GETODELAY:
-               if (!(file->f_mode & FMODE_WRITE))
-                       return -EINVAL;
-               spin_lock_irqsave(&state->card->lock, flags);
-               i810_update_ptr(state);
-               val = dmabuf->count;
-               spin_unlock_irqrestore(&state->card->lock, flags);
-#ifdef DEBUG
-               printk("SNDCTL_DSP_GETODELAY %d\n", dmabuf->count);
-#endif
-               return put_user(val, p);
-
-       case SOUND_PCM_READ_RATE:
-#ifdef DEBUG
-               printk("SOUND_PCM_READ_RATE %d\n", dmabuf->rate);
-#endif
-               return put_user(dmabuf->rate, p);
-
-       case SOUND_PCM_READ_CHANNELS:
-#ifdef DEBUG
-               printk("SOUND_PCM_READ_CHANNELS\n");
-#endif
-               return put_user(2, p);
-
-       case SOUND_PCM_READ_BITS:
-#ifdef DEBUG
-               printk("SOUND_PCM_READ_BITS\n");
-#endif
-               return put_user(AFMT_S16_LE, p);
-
-       case SNDCTL_DSP_SETSPDIF: /* Set S/PDIF Control register */
-#ifdef DEBUG
-               printk("SNDCTL_DSP_SETSPDIF\n");
-#endif
-               if (get_user(val, p))
-                       return -EFAULT;
-
-               /* Check to make sure the codec supports S/PDIF transmitter */
-
-               if((state->card->ac97_features & 4)) {
-                       /* mask out the transmitter speed bits so the user can't set them */
-                       val &= ~0x3000;
-
-                       /* Add the current transmitter speed bits to the passed value */
-                       ret = i810_ac97_get(codec, AC97_SPDIF_CONTROL);
-                       val |= (ret & 0x3000);
-
-                       i810_ac97_set(codec, AC97_SPDIF_CONTROL, val);
-                       if(i810_ac97_get(codec, AC97_SPDIF_CONTROL) != val ) {
-                               printk(KERN_ERR "i810_audio: Unable to set S/PDIF configuration to 0x%04x.\n", val);
-                               return -EFAULT;
-                       }
-               }
-#ifdef DEBUG
-               else 
-                       printk(KERN_WARNING "i810_audio: S/PDIF transmitter not avalible.\n");
-#endif
-               return put_user(val, p);
-
-       case SNDCTL_DSP_GETSPDIF: /* Get S/PDIF Control register */
-#ifdef DEBUG
-               printk("SNDCTL_DSP_GETSPDIF\n");
-#endif
-               if (get_user(val, p))
-                       return -EFAULT;
-
-               /* Check to make sure the codec supports S/PDIF transmitter */
-
-               if(!(state->card->ac97_features & 4)) {
-#ifdef DEBUG
-                       printk(KERN_WARNING "i810_audio: S/PDIF transmitter not avalible.\n");
-#endif
-                       val = 0;
-               } else {
-                       val = i810_ac97_get(codec, AC97_SPDIF_CONTROL);
-               }
-               //return put_user((val & 0xcfff), p);
-               return put_user(val, p);
-                       
-       case SNDCTL_DSP_GETCHANNELMASK:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_GETCHANNELMASK\n");
-#endif
-               if (get_user(val, p))
-                       return -EFAULT;
-               
-               /* Based on AC'97 DAC support, not ICH hardware */
-               val = DSP_BIND_FRONT;
-               if ( state->card->ac97_features & 0x0004 )
-                       val |= DSP_BIND_SPDIF;
-
-               if ( state->card->ac97_features & 0x0080 )
-                       val |= DSP_BIND_SURR;
-               if ( state->card->ac97_features & 0x0140 )
-                       val |= DSP_BIND_CENTER_LFE;
-
-               return put_user(val, p);
-
-       case SNDCTL_DSP_BIND_CHANNEL:
-#ifdef DEBUG
-               printk("SNDCTL_DSP_BIND_CHANNEL\n");
-#endif
-               if (get_user(val, p))
-                       return -EFAULT;
-               if ( val == DSP_BIND_QUERY ) {
-                       val = DSP_BIND_FRONT; /* Always report this as being enabled */
-                       if ( state->card->ac97_status & SPDIF_ON ) 
-                               val |= DSP_BIND_SPDIF;
-                       else {
-                               if ( state->card->ac97_status & SURR_ON )
-                                       val |= DSP_BIND_SURR;
-                               if ( state->card->ac97_status & CENTER_LFE_ON )
-                                       val |= DSP_BIND_CENTER_LFE;
-                       }
-               } else {  /* Not a query, set it */
-                       if (!(file->f_mode & FMODE_WRITE))
-                               return -EINVAL;
-                       if ( dmabuf->enable == DAC_RUNNING ) {
-                               stop_dac(state);
-                       }
-                       if ( val & DSP_BIND_SPDIF ) {  /* Turn on SPDIF */
-                               /*  Ok, this should probably define what slots
-                                *  to use. For now, we'll only set it to the
-                                *  defaults:
-                                * 
-                                *   non multichannel codec maps to slots 3&4
-                                *   2 channel codec maps to slots 7&8
-                                *   4 channel codec maps to slots 6&9
-                                *   6 channel codec maps to slots 10&11
-                                *
-                                *  there should be some way for the app to
-                                *  select the slot assignment.
-                                */
-       
-                               i810_set_spdif_output ( state, AC97_EA_SPSA_3_4, dmabuf->rate );
-                               if ( !(state->card->ac97_status & SPDIF_ON) )
-                                       val &= ~DSP_BIND_SPDIF;
-                       } else {
-                               int mask;
-                               int channels;
-
-                               /* Turn off S/PDIF if it was on */
-                               if ( state->card->ac97_status & SPDIF_ON ) 
-                                       i810_set_spdif_output ( state, -1, 0 );
-                               
-                               mask = val & (DSP_BIND_FRONT | DSP_BIND_SURR | DSP_BIND_CENTER_LFE);
-                               switch (mask) {
-                                       case DSP_BIND_FRONT:
-                                               channels = 2;
-                                               break;
-                                       case DSP_BIND_FRONT|DSP_BIND_SURR:
-                                               channels = 4;
-                                               break;
-                                       case DSP_BIND_FRONT|DSP_BIND_SURR|DSP_BIND_CENTER_LFE:
-                                               channels = 6;
-                                               break;
-                                       default:
-                                               val = DSP_BIND_FRONT;
-                                               channels = 2;
-                                               break;
-                               }
-                               i810_set_dac_channels ( state, channels );
-
-                               /* check that they really got turned on */
-                               if (!(state->card->ac97_status & SURR_ON))
-                                       val &= ~DSP_BIND_SURR;
-                               if (!(state->card->ac97_status & CENTER_LFE_ON))
-                                       val &= ~DSP_BIND_CENTER_LFE;
-                       }
-               }
-               return put_user(val, p);
-               
-       case SNDCTL_DSP_MAPINBUF:
-       case SNDCTL_DSP_MAPOUTBUF:
-       case SNDCTL_DSP_SETSYNCRO:
-       case SOUND_PCM_WRITE_FILTER:
-       case SOUND_PCM_READ_FILTER:
-#ifdef DEBUG
-               printk("SNDCTL_* -EINVAL\n");
-#endif
-               return -EINVAL;
-       }
-       return -EINVAL;
-}
-
-static int i810_open(struct inode *inode, struct file *file)
-{
-       int i = 0;
-       struct i810_card *card = devs;
-       struct i810_state *state = NULL;
-       struct dmabuf *dmabuf = NULL;
-
-       /* find an avaiable virtual channel (instance of /dev/dsp) */
-       while (card != NULL) {
-               /*
-                * If we are initializing and then fail, card could go
-                * away unuexpectedly while we are in the for() loop.
-                * So, check for card on each iteration before we check
-                * for card->initializing to avoid a possible oops.
-                * This usually only matters for times when the driver is
-                * autoloaded by kmod.
-                */
-               for (i = 0; i < 50 && card && card->initializing; i++) {
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(HZ/20);
-               }
-               for (i = 0; i < NR_HW_CH && card && !card->initializing; i++) {
-                       if (card->states[i] == NULL) {
-                               state = card->states[i] = (struct i810_state *)
-                                       kzalloc(sizeof(struct i810_state), GFP_KERNEL);
-                               if (state == NULL)
-                                       return -ENOMEM;
-                               dmabuf = &state->dmabuf;
-                               goto found_virt;
-                       }
-               }
-               card = card->next;
-       }
-       /* no more virtual channel avaiable */
-       if (!state)
-               return -ENODEV;
-
-found_virt:
-       /* initialize the virtual channel */
-       state->virt = i;
-       state->card = card;
-       state->magic = I810_STATE_MAGIC;
-       init_waitqueue_head(&dmabuf->wait);
-       mutex_init(&state->open_mutex);
-       file->private_data = state;
-       dmabuf->trigger = 0;
-
-       /* allocate hardware channels */
-       if(file->f_mode & FMODE_READ) {
-               if((dmabuf->read_channel = card->alloc_rec_pcm_channel(card)) == NULL) {
-                       kfree (card->states[i]);
-                       card->states[i] = NULL;
-                       return -EBUSY;
-               }
-               dmabuf->trigger |= PCM_ENABLE_INPUT;
-               i810_set_adc_rate(state, 8000);
-       }
-       if(file->f_mode & FMODE_WRITE) {
-               if((dmabuf->write_channel = card->alloc_pcm_channel(card)) == NULL) {
-                       /* make sure we free the record channel allocated above */
-                       if(file->f_mode & FMODE_READ)
-                               card->free_pcm_channel(card,dmabuf->read_channel->num);
-                       kfree (card->states[i]);
-                       card->states[i] = NULL;
-                       return -EBUSY;
-               }
-               /* Initialize to 8kHz?  What if we don't support 8kHz? */
-               /*  Let's change this to check for S/PDIF stuff */
-       
-               dmabuf->trigger |= PCM_ENABLE_OUTPUT;
-               if ( spdif_locked ) {
-                       i810_set_dac_rate(state, spdif_locked);
-                       i810_set_spdif_output(state, AC97_EA_SPSA_3_4, spdif_locked);
-               } else {
-                       i810_set_dac_rate(state, 8000);
-                       /* Put the ACLink in 2 channel mode by default */
-                       i = I810_IOREADL(card, GLOB_CNT);
-                       I810_IOWRITEL(i & 0xffcfffff, card, GLOB_CNT);
-               }
-       }
-               
-       /* set default sample format. According to OSS Programmer's Guide  /dev/dsp
-          should be default to unsigned 8-bits, mono, with sample rate 8kHz and
-          /dev/dspW will accept 16-bits sample, but we don't support those so we
-          set it immediately to stereo and 16bit, which is all we do support */
-       dmabuf->fmt |= I810_FMT_16BIT | I810_FMT_STEREO;
-       dmabuf->ossfragsize = 0;
-       dmabuf->ossmaxfrags  = 0;
-       dmabuf->subdivision  = 0;
-
-       state->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
-
-       return nonseekable_open(inode, file);
-}
-
-static int i810_release(struct inode *inode, struct file *file)
-{
-       struct i810_state *state = (struct i810_state *)file->private_data;
-       struct i810_card *card = state->card;
-       struct dmabuf *dmabuf = &state->dmabuf;
-       unsigned long flags;
-
-       lock_kernel();
-
-       /* stop DMA state machine and free DMA buffers/channels */
-       if(dmabuf->trigger & PCM_ENABLE_OUTPUT) {
-               drain_dac(state, 0);
-       }
-       if(dmabuf->trigger & PCM_ENABLE_INPUT) {
-               stop_adc(state);
-       }
-       spin_lock_irqsave(&card->lock, flags);
-       dealloc_dmabuf(state);
-       if (file->f_mode & FMODE_WRITE) {
-               state->card->free_pcm_channel(state->card, dmabuf->write_channel->num);
-       }
-       if (file->f_mode & FMODE_READ) {
-               state->card->free_pcm_channel(state->card, dmabuf->read_channel->num);
-       }
-
-       state->card->states[state->virt] = NULL;
-       kfree(state);
-       spin_unlock_irqrestore(&card->lock, flags);
-       unlock_kernel();
-
-       return 0;
-}
-
-static /*const*/ struct file_operations i810_audio_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .read           = i810_read,
-       .write          = i810_write,
-       .poll           = i810_poll,
-       .ioctl          = i810_ioctl,
-       .mmap           = i810_mmap,
-       .open           = i810_open,
-       .release        = i810_release,
-};
-
-/* Write AC97 codec registers */
-
-static u16 i810_ac97_get_mmio(struct ac97_codec *dev, u8 reg)
-{
-       struct i810_card *card = dev->private_data;
-       int count = 100;
-       u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
-       
-       while(count-- && (readb(card->iobase_mmio + CAS) & 1)) 
-               udelay(1);
-       
-#ifdef DEBUG_MMIO
-       {
-               u16 ans = readw(card->ac97base_mmio + reg_set);
-               printk(KERN_DEBUG "i810_audio: ac97_get_mmio(%d) -> 0x%04X\n", ((int) reg_set) & 0xffff, (u32) ans);
-               return ans;
-       }
-#else
-       return readw(card->ac97base_mmio + reg_set);
-#endif
-}
-
-static u16 i810_ac97_get_io(struct ac97_codec *dev, u8 reg)
-{
-       struct i810_card *card = dev->private_data;
-       int count = 100;
-       u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
-       
-       while(count-- && (I810_IOREADB(card, CAS) & 1)) 
-               udelay(1);
-       
-       return inw(card->ac97base + reg_set);
-}
-
-static void i810_ac97_set_mmio(struct ac97_codec *dev, u8 reg, u16 data)
-{
-       struct i810_card *card = dev->private_data;
-       int count = 100;
-       u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
-       
-       while(count-- && (readb(card->iobase_mmio + CAS) & 1)) 
-               udelay(1);
-       
-       writew(data, card->ac97base_mmio + reg_set);
-
-#ifdef DEBUG_MMIO
-       printk(KERN_DEBUG "i810_audio: ac97_set_mmio(0x%04X, %d)\n", (u32) data, ((int) reg_set) & 0xffff);
-#endif
-}
-
-static void i810_ac97_set_io(struct ac97_codec *dev, u8 reg, u16 data)
-{
-       struct i810_card *card = dev->private_data;
-       int count = 100;
-       u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
-       
-       while(count-- && (I810_IOREADB(card, CAS) & 1)) 
-               udelay(1);
-       
-        outw(data, card->ac97base + reg_set);
-}
-
-static u16 i810_ac97_get(struct ac97_codec *dev, u8 reg)
-{
-       struct i810_card *card = dev->private_data;
-       u16 ret;
-       
-       spin_lock(&card->ac97_lock);
-       if (card->use_mmio) {
-               ret = i810_ac97_get_mmio(dev, reg);
-       }
-       else {
-               ret = i810_ac97_get_io(dev, reg);
-       }
-       spin_unlock(&card->ac97_lock);
-       
-       return ret;
-}
-
-static void i810_ac97_set(struct ac97_codec *dev, u8 reg, u16 data)
-{
-       struct i810_card *card = dev->private_data;
-       
-       spin_lock(&card->ac97_lock);
-       if (card->use_mmio) {
-               i810_ac97_set_mmio(dev, reg, data);
-       }
-       else {
-               i810_ac97_set_io(dev, reg, data);
-       }
-       spin_unlock(&card->ac97_lock);
-}
-
-
-/* OSS /dev/mixer file operation methods */
-
-static int i810_open_mixdev(struct inode *inode, struct file *file)
-{
-       int i;
-       int minor = iminor(inode);
-       struct i810_card *card = devs;
-
-       for (card = devs; card != NULL; card = card->next) {
-               /*
-                * If we are initializing and then fail, card could go
-                * away unuexpectedly while we are in the for() loop.
-                * So, check for card on each iteration before we check
-                * for card->initializing to avoid a possible oops.
-                * This usually only matters for times when the driver is
-                * autoloaded by kmod.
-                */
-               for (i = 0; i < 50 && card && card->initializing; i++) {
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(HZ/20);
-               }
-               for (i = 0; i < NR_AC97 && card && !card->initializing; i++) 
-                       if (card->ac97_codec[i] != NULL &&
-                           card->ac97_codec[i]->dev_mixer == minor) {
-                               file->private_data = card->ac97_codec[i];
-                               return nonseekable_open(inode, file);
-                       }
-       }
-       return -ENODEV;
-}
-
-static int i810_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       struct ac97_codec *codec = (struct ac97_codec *)file->private_data;
-
-       return codec->mixer_ioctl(codec, cmd, arg);
-}
-
-static /*const*/ struct file_operations i810_mixer_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .ioctl          = i810_ioctl_mixdev,
-       .open           = i810_open_mixdev,
-};
-
-/* AC97 codec initialisation.  These small functions exist so we don't
-   duplicate code between module init and apm resume */
-
-static inline int i810_ac97_exists(struct i810_card *card, int ac97_number)
-{
-       u32 reg = I810_IOREADL(card, GLOB_STA);
-       switch (ac97_number) {
-       case 0:
-               return reg & (1<<8);
-       case 1: 
-               return reg & (1<<9);
-       case 2:
-               return reg & (1<<28);
-       }
-       return 0;
-}
-
-static inline int i810_ac97_enable_variable_rate(struct ac97_codec *codec)
-{
-       i810_ac97_set(codec, AC97_EXTENDED_STATUS, 9);
-       i810_ac97_set(codec,AC97_EXTENDED_STATUS,
-                     i810_ac97_get(codec, AC97_EXTENDED_STATUS)|0xE800);
-       
-       return (i810_ac97_get(codec, AC97_EXTENDED_STATUS)&1);
-}
-
-
-static int i810_ac97_probe_and_powerup(struct i810_card *card,struct ac97_codec *codec)
-{
-       /* Returns 0 on failure */
-       int i;
-
-       if (ac97_probe_codec(codec) == 0) return 0;
-       
-       /* power it all up */
-       i810_ac97_set(codec, AC97_POWER_CONTROL,
-                     i810_ac97_get(codec, AC97_POWER_CONTROL) & ~0x7f00);
-
-       /* wait for analog ready */
-       for (i=100; i && ((i810_ac97_get(codec, AC97_POWER_CONTROL) & 0xf) != 0xf); i--)
-       {
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(HZ/20);
-       } 
-       return i;
-}
-
-static int is_new_ich(u16 pci_id)
-{
-       switch (pci_id) {
-       case PCI_DEVICE_ID_INTEL_82801DB_5:
-       case PCI_DEVICE_ID_INTEL_82801EB_5:
-       case PCI_DEVICE_ID_INTEL_ESB_5:
-       case PCI_DEVICE_ID_INTEL_ICH6_18:
-               return 1;
-       default:
-               break;
-       }
-
-       return 0;
-}
-
-static inline int ich_use_mmio(struct i810_card *card)
-{
-       return is_new_ich(card->pci_id) && card->use_mmio;
-}
-
-/**
- *     i810_ac97_power_up_bus  -       bring up AC97 link
- *     @card : ICH audio device to power up
- *
- *     Bring up the ACLink AC97 codec bus
- */
-static int i810_ac97_power_up_bus(struct i810_card *card)
-{      
-       u32 reg = I810_IOREADL(card, GLOB_CNT);
-       int i;
-       int primary_codec_id = 0;
-
-       if((reg&2)==0)  /* Cold required */
-               reg|=2;
-       else
-               reg|=4; /* Warm */
-               
-       reg&=~8;        /* ACLink on */
-       
-       /* At this point we deassert AC_RESET # */
-       I810_IOWRITEL(reg , card, GLOB_CNT);
-
-       /* We must now allow time for the Codec initialisation.
-          600mS is the specified time */
-               
-       for(i=0;i<10;i++)
-       {
-               if((I810_IOREADL(card, GLOB_CNT)&4)==0)
-                       break;
-
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(HZ/20);
-       }
-       if(i==10)
-       {
-               printk(KERN_ERR "i810_audio: AC'97 reset failed.\n");
-               return 0;
-       }
-
-       set_current_state(TASK_UNINTERRUPTIBLE);
-       schedule_timeout(HZ/2);
-
-       /*
-        *      See if the primary codec comes ready. This must happen
-        *      before we start doing DMA stuff
-        */     
-       /* see i810_ac97_init for the next 10 lines (jsaw) */
-       if (card->use_mmio)
-               readw(card->ac97base_mmio);
-       else
-               inw(card->ac97base);
-       if (ich_use_mmio(card)) {
-               primary_codec_id = (int) readl(card->iobase_mmio + SDM) & 0x3;
-               printk(KERN_INFO "i810_audio: Primary codec has ID %d\n",
-                      primary_codec_id);
-       }
-
-       if(! i810_ac97_exists(card, primary_codec_id))
-       {
-               printk(KERN_INFO "i810_audio: Codec not ready.. wait.. ");
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(HZ);   /* actually 600mS by the spec */
-
-               if(i810_ac97_exists(card, primary_codec_id))
-                       printk("OK\n");
-               else 
-                       printk("no response.\n");
-       }
-       if (card->use_mmio)
-               readw(card->ac97base_mmio);
-       else
-               inw(card->ac97base);
-       return 1;
-}
-
-static int __devinit i810_ac97_init(struct i810_card *card)
-{
-       int num_ac97 = 0;
-       int ac97_id;
-       int total_channels = 0;
-       int nr_ac97_max = card_cap[card->pci_id_internal].nr_ac97;
-       struct ac97_codec *codec;
-       u16 eid;
-       u32 reg;
-
-       if(!i810_ac97_power_up_bus(card)) return 0;
-
-       /* Number of channels supported */
-       /* What about the codec?  Just because the ICH supports */
-       /* multiple channels doesn't mean the codec does.       */
-       /* we'll have to modify this in the codec section below */
-       /* to reflect what the codec has.                       */
-       /* ICH and ICH0 only support 2 channels so don't bother */
-       /* to check....                                         */
-
-       card->channels = 2;
-       reg = I810_IOREADL(card, GLOB_STA);
-       if ( reg & 0x0200000 )
-               card->channels = 6;
-       else if ( reg & 0x0100000 )
-               card->channels = 4;
-       printk(KERN_INFO "i810_audio: Audio Controller supports %d channels.\n", card->channels);
-       printk(KERN_INFO "i810_audio: Defaulting to base 2 channel mode.\n");
-       reg = I810_IOREADL(card, GLOB_CNT);
-       I810_IOWRITEL(reg & 0xffcfffff, card, GLOB_CNT);
-               
-       for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) 
-               card->ac97_codec[num_ac97] = NULL;
-
-       /*@FIXME I don't know, if I'm playing to safe here... (jsaw) */
-       if ((nr_ac97_max > 2) && !card->use_mmio) nr_ac97_max = 2;
-
-       for (num_ac97 = 0; num_ac97 < nr_ac97_max; num_ac97++) {
-               /* codec reset */
-               printk(KERN_INFO "i810_audio: Resetting connection %d\n", num_ac97);
-               if (card->use_mmio)
-                       readw(card->ac97base_mmio + 0x80*num_ac97);
-               else
-                       inw(card->ac97base + 0x80*num_ac97);
-
-               /* If we have the SDATA_IN Map Register, as on ICH4, we
-                  do not loop thru all possible codec IDs but thru all 
-                  possible IO channels. Bit 0:1 of SDM then holds the 
-                  last codec ID spoken to. 
-               */
-               if (ich_use_mmio(card)) {
-                       ac97_id = (int) readl(card->iobase_mmio + SDM) & 0x3;
-                       printk(KERN_INFO "i810_audio: Connection %d with codec id %d\n",
-                              num_ac97, ac97_id);
-               }
-               else {
-                       ac97_id = num_ac97;
-               }
-
-               /* The ICH programmer's reference says you should   */
-               /* check the ready status before probing. So we chk */
-               /*   What do we do if it's not ready?  Wait and try */
-               /*   again, or abort?                               */
-               if (!i810_ac97_exists(card, ac97_id)) {
-                       if(num_ac97 == 0)
-                               printk(KERN_ERR "i810_audio: Primary codec not ready.\n");
-               }
-               
-               if ((codec = ac97_alloc_codec()) == NULL)
-                       return -ENOMEM;
-
-               /* initialize some basic codec information, other fields will be filled
-                  in ac97_probe_codec */
-               codec->private_data = card;
-               codec->id = ac97_id;
-               card->ac97_id_map[ac97_id] = num_ac97 * 0x80;
-
-               if (card->use_mmio) {   
-                       codec->codec_read = i810_ac97_get_mmio;
-                       codec->codec_write = i810_ac97_set_mmio;
-               }
-               else {
-                       codec->codec_read = i810_ac97_get_io;
-                       codec->codec_write = i810_ac97_set_io;
-               }
-       
-               if(!i810_ac97_probe_and_powerup(card,codec)) {
-                       printk(KERN_ERR "i810_audio: timed out waiting for codec %d analog ready.\n", ac97_id);
-                       ac97_release_codec(codec);
-                       break;  /* it didn't work */
-               }
-               /* Store state information about S/PDIF transmitter */
-               card->ac97_status = 0;
-               
-               /* Don't attempt to get eid until powerup is complete */
-               eid = i810_ac97_get(codec, AC97_EXTENDED_ID);
-
-               if(eid==0xFFFF)
-               {
-                       printk(KERN_WARNING "i810_audio: no codec attached ?\n");
-                       ac97_release_codec(codec);
-                       break;
-               }
-               
-               /* Check for an AC97 1.0 soft modem (ID1) */
-               
-               if(codec->modem)
-               {
-                       printk(KERN_WARNING "i810_audio: codec %d is a softmodem - skipping.\n", ac97_id);
-                       ac97_release_codec(codec);
-                       continue;
-               }
-               
-               card->ac97_features = eid;
-
-               /* Now check the codec for useful features to make up for
-                  the dumbness of the 810 hardware engine */
-
-               if(!(eid&0x0001))
-                       printk(KERN_WARNING "i810_audio: only 48Khz playback available.\n");
-               else
-               {
-                       if(!i810_ac97_enable_variable_rate(codec)) {
-                               printk(KERN_WARNING "i810_audio: Codec refused to allow VRA, using 48Khz only.\n");
-                               card->ac97_features&=~1;
-                       }                       
-               }
-               
-               /* Turn on the amplifier */
-
-               codec->codec_write(codec, AC97_POWER_CONTROL, 
-                        codec->codec_read(codec, AC97_POWER_CONTROL) & ~0x8000);
-                               
-               /* Determine how many channels the codec(s) support   */
-               /*   - The primary codec always supports 2            */
-               /*   - If the codec supports AMAP, surround DACs will */
-               /*     automaticlly get assigned to slots.            */
-               /*     * Check for surround DACs and increment if     */
-               /*       found.                                       */
-               /*   - Else check if the codec is revision 2.2        */
-               /*     * If surround DACs exist, assign them to slots */
-               /*       and increment channel count.                 */
-
-               /* All of this only applies to ICH2 and above. ICH    */
-               /* and ICH0 only support 2 channels.  ICH2 will only  */
-               /* support multiple codecs in a "split audio" config. */
-               /* as described above.                                */
-
-               /* TODO: Remove all the debugging messages!           */
-
-               if((eid & 0xc000) == 0) /* primary codec */
-                       total_channels += 2; 
-
-               if(eid & 0x200) { /* GOOD, AMAP support */
-                       if (eid & 0x0080) /* L/R Surround channels */
-                               total_channels += 2;
-                       if (eid & 0x0140) /* LFE and Center channels */
-                               total_channels += 2;
-                       printk("i810_audio: AC'97 codec %d supports AMAP, total channels = %d\n", ac97_id, total_channels);
-               } else if (eid & 0x0400) {  /* this only works on 2.2 compliant codecs */
-                       eid &= 0xffcf;
-                       if((eid & 0xc000) != 0) {
-                               switch ( total_channels ) {
-                                       case 2:
-                                               /* Set dsa1, dsa0 to 01 */
-                                               eid |= 0x0010;
-                                               break;
-                                       case 4:
-                                               /* Set dsa1, dsa0 to 10 */
-                                               eid |= 0x0020;
-                                               break;
-                                       case 6:
-                                               /* Set dsa1, dsa0 to 11 */
-                                               eid |= 0x0030;
-                                               break;
-                               }
-                               total_channels += 2;
-                       }
-                       i810_ac97_set(codec, AC97_EXTENDED_ID, eid);
-                       eid = i810_ac97_get(codec, AC97_EXTENDED_ID);
-                       printk("i810_audio: AC'97 codec %d, new EID value = 0x%04x\n", ac97_id, eid);
-                       if (eid & 0x0080) /* L/R Surround channels */
-                               total_channels += 2;
-                       if (eid & 0x0140) /* LFE and Center channels */
-                               total_channels += 2;
-                       printk("i810_audio: AC'97 codec %d, DAC map configured, total channels = %d\n", ac97_id, total_channels);
-               } else {
-                       printk("i810_audio: AC'97 codec %d Unable to map surround DAC's (or DAC's not present), total channels = %d\n", ac97_id, total_channels);
-               }
-
-               if ((codec->dev_mixer = register_sound_mixer(&i810_mixer_fops, -1)) < 0) {
-                       printk(KERN_ERR "i810_audio: couldn't register mixer!\n");
-                       ac97_release_codec(codec);
-                       break;
-               }
-
-               card->ac97_codec[num_ac97] = codec;
-       }
-
-       /* tune up the primary codec */
-       ac97_tune_hardware(card->pci_dev, ac97_quirks, ac97_quirk);
-
-       /* pick the minimum of channels supported by ICHx or codec(s) */
-       card->channels = (card->channels > total_channels)?total_channels:card->channels;
-
-       return num_ac97;
-}
-
-static void __devinit i810_configure_clocking (void)
-{
-       struct i810_card *card;
-       struct i810_state *state;
-       struct dmabuf *dmabuf;
-       unsigned int i, offset, new_offset;
-       unsigned long flags;
-
-       card = devs;
-       /* We could try to set the clocking for multiple cards, but can you even have
-        * more than one i810 in a machine?  Besides, clocking is global, so unless
-        * someone actually thinks more than one i810 in a machine is possible and
-        * decides to rewrite that little bit, setting the rate for more than one card
-        * is a waste of time.
-        */
-       if(card != NULL) {
-               state = card->states[0] = (struct i810_state *)
-                                       kzalloc(sizeof(struct i810_state), GFP_KERNEL);
-               if (state == NULL)
-                       return;
-               dmabuf = &state->dmabuf;
-
-               dmabuf->write_channel = card->alloc_pcm_channel(card);
-               state->virt = 0;
-               state->card = card;
-               state->magic = I810_STATE_MAGIC;
-               init_waitqueue_head(&dmabuf->wait);
-               mutex_init(&state->open_mutex);
-               dmabuf->fmt = I810_FMT_STEREO | I810_FMT_16BIT;
-               dmabuf->trigger = PCM_ENABLE_OUTPUT;
-               i810_set_spdif_output(state, -1, 0);
-               i810_set_dac_channels(state, 2);
-               i810_set_dac_rate(state, 48000);
-               if(prog_dmabuf(state, 0) != 0) {
-                       goto config_out_nodmabuf;
-               }
-               if(dmabuf->dmasize < 16384) {
-                       goto config_out;
-               }
-               dmabuf->count = dmabuf->dmasize;
-               CIV_TO_LVI(card, dmabuf->write_channel->port, -1);
-               local_irq_save(flags);
-               start_dac(state);
-               offset = i810_get_dma_addr(state, 0);
-               mdelay(50);
-               new_offset = i810_get_dma_addr(state, 0);
-               stop_dac(state);
-               local_irq_restore(flags);
-               i = new_offset - offset;
-#ifdef DEBUG_INTERRUPTS
-               printk("i810_audio: %d bytes in 50 milliseconds\n", i);
-#endif
-               if(i == 0)
-                       goto config_out;
-               i = i / 4 * 20;
-               if (i > 48500 || i < 47500) {
-                       clocking = clocking * clocking / i;
-                       printk("i810_audio: setting clocking to %d\n", clocking);
-               }
-config_out:
-               dealloc_dmabuf(state);
-config_out_nodmabuf:
-               state->card->free_pcm_channel(state->card,state->dmabuf.write_channel->num);
-               kfree(state);
-               card->states[0] = NULL;
-       }
-}
-
-/* install the driver, we do not allocate hardware channel nor DMA buffer now, they are defered 
-   until "ACCESS" time (in prog_dmabuf called by open/read/write/ioctl/mmap) */
-   
-static int __devinit i810_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
-{
-       struct i810_card *card;
-
-       if (pci_enable_device(pci_dev))
-               return -EIO;
-
-       if (pci_set_dma_mask(pci_dev, I810_DMA_MASK)) {
-               printk(KERN_ERR "i810_audio: architecture does not support"
-                      " 32bit PCI busmaster DMA\n");
-               return -ENODEV;
-       }
-       
-       if ((card = kzalloc(sizeof(struct i810_card), GFP_KERNEL)) == NULL) {
-               printk(KERN_ERR "i810_audio: out of memory\n");
-               return -ENOMEM;
-       }
-
-       card->initializing = 1;
-       card->pci_dev = pci_dev;
-       card->pci_id = pci_id->device;
-       card->ac97base = pci_resource_start (pci_dev, 0);
-       card->iobase = pci_resource_start (pci_dev, 1);
-
-       if (!(card->ac97base) || !(card->iobase)) {
-               card->ac97base = 0;
-               card->iobase = 0;
-       }
-
-       /* if chipset could have mmio capability, check it */ 
-       if (card_cap[pci_id->driver_data].flags & CAP_MMIO) {
-               card->ac97base_mmio_phys = pci_resource_start (pci_dev, 2);
-               card->iobase_mmio_phys = pci_resource_start (pci_dev, 3);
-
-               if ((card->ac97base_mmio_phys) && (card->iobase_mmio_phys)) {
-                       card->use_mmio = 1;
-               }
-               else {
-                       card->ac97base_mmio_phys = 0;
-                       card->iobase_mmio_phys = 0;
-               }
-       }
-
-       if (!(card->use_mmio) && (!(card->iobase) || !(card->ac97base))) {
-               printk(KERN_ERR "i810_audio: No I/O resources available.\n");
-               goto out_mem;
-       }
-
-       card->irq = pci_dev->irq;
-       card->next = devs;
-       card->magic = I810_CARD_MAGIC;
-#ifdef CONFIG_PM
-       card->pm_suspended=0;
-#endif
-       spin_lock_init(&card->lock);
-       spin_lock_init(&card->ac97_lock);
-       devs = card;
-
-       pci_set_master(pci_dev);
-
-       printk(KERN_INFO "i810: %s found at IO 0x%04lx and 0x%04lx, "
-              "MEM 0x%04lx and 0x%04lx, IRQ %d\n",
-              card_names[pci_id->driver_data], 
-              card->iobase, card->ac97base, 
-              card->ac97base_mmio_phys, card->iobase_mmio_phys,
-              card->irq);
-
-       card->alloc_pcm_channel = i810_alloc_pcm_channel;
-       card->alloc_rec_pcm_channel = i810_alloc_rec_pcm_channel;
-       card->alloc_rec_mic_channel = i810_alloc_rec_mic_channel;
-       card->free_pcm_channel = i810_free_pcm_channel;
-
-       if ((card->channel = pci_alloc_consistent(pci_dev,
-           sizeof(struct i810_channel)*NR_HW_CH, &card->chandma)) == NULL) {
-               printk(KERN_ERR "i810: cannot allocate channel DMA memory\n");
-               goto out_mem;
-       }
-
-       { /* We may dispose of this altogether some time soon, so... */
-               struct i810_channel *cp = card->channel;
-
-               cp[0].offset = 0;
-               cp[0].port = 0x00;
-               cp[0].num = 0;
-               cp[1].offset = 0;
-               cp[1].port = 0x10;
-               cp[1].num = 1;
-               cp[2].offset = 0;
-               cp[2].port = 0x20;
-               cp[2].num = 2;
-       }
-
-       /* claim our iospace and irq */
-       if (!request_region(card->iobase, 64, card_names[pci_id->driver_data])) {
-               printk(KERN_ERR "i810_audio: unable to allocate region %lx\n", card->iobase);
-               goto out_region1;
-       }
-       if (!request_region(card->ac97base, 256, card_names[pci_id->driver_data])) {
-               printk(KERN_ERR "i810_audio: unable to allocate region %lx\n", card->ac97base);
-               goto out_region2;
-       }
-
-       if (card->use_mmio) {
-               if (request_mem_region(card->ac97base_mmio_phys, 512, "ich_audio MMBAR")) {
-                       if ((card->ac97base_mmio = ioremap(card->ac97base_mmio_phys, 512))) { /*@FIXME can ioremap fail? don't know (jsaw) */
-                               if (request_mem_region(card->iobase_mmio_phys, 256, "ich_audio MBBAR")) {
-                                       if ((card->iobase_mmio = ioremap(card->iobase_mmio_phys, 256))) {
-                                               printk(KERN_INFO "i810: %s mmio at 0x%04lx and 0x%04lx\n",
-                                                      card_names[pci_id->driver_data], 
-                                                      (unsigned long) card->ac97base_mmio, 
-                                                      (unsigned long) card->iobase_mmio); 
-                                       }
-                                       else {
-                                               iounmap(card->ac97base_mmio);
-                                               release_mem_region(card->ac97base_mmio_phys, 512);
-                                               release_mem_region(card->iobase_mmio_phys, 512);
-                                               card->use_mmio = 0;
-                                       }
-                               }
-                               else {
-                                       iounmap(card->ac97base_mmio);
-                                       release_mem_region(card->ac97base_mmio_phys, 512);
-                                       card->use_mmio = 0;
-                               }
-                       }
-               }
-               else {
-                       card->use_mmio = 0;
-               }
-       }
-
-       /* initialize AC97 codec and register /dev/mixer */
-       if (i810_ac97_init(card) <= 0)
-               goto out_iospace;
-       pci_set_drvdata(pci_dev, card);
-
-       if(clocking == 0) {
-               clocking = 48000;
-               i810_configure_clocking();
-       }
-
-       /* register /dev/dsp */
-       if ((card->dev_audio = register_sound_dsp(&i810_audio_fops, -1)) < 0) {
-               int i;
-               printk(KERN_ERR "i810_audio: couldn't register DSP device!\n");
-               for (i = 0; i < NR_AC97; i++)
-               if (card->ac97_codec[i] != NULL) {
-                       unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
-                       ac97_release_codec(card->ac97_codec[i]);
-               }
-               goto out_iospace;
-       }
-
-       if (request_irq(card->irq, &i810_interrupt, IRQF_SHARED,
-                       card_names[pci_id->driver_data], card)) {
-               printk(KERN_ERR "i810_audio: unable to allocate irq %d\n", card->irq);
-               goto out_iospace;
-       }
-
-
-       card->initializing = 0;
-       return 0;
-
-out_iospace:
-       if (card->use_mmio) {
-               iounmap(card->ac97base_mmio);
-               iounmap(card->iobase_mmio);
-               release_mem_region(card->ac97base_mmio_phys, 512);
-               release_mem_region(card->iobase_mmio_phys, 256);
-       }
-       release_region(card->ac97base, 256);
-out_region2:
-       release_region(card->iobase, 64);
-out_region1:
-       pci_free_consistent(pci_dev, sizeof(struct i810_channel)*NR_HW_CH,
-           card->channel, card->chandma);
-out_mem:
-       kfree(card);
-       return -ENODEV;
-}
-
-static void __devexit i810_remove(struct pci_dev *pci_dev)
-{
-       int i;
-       struct i810_card *card = pci_get_drvdata(pci_dev);
-       /* free hardware resources */
-       free_irq(card->irq, devs);
-       release_region(card->iobase, 64);
-       release_region(card->ac97base, 256);
-       pci_free_consistent(pci_dev, sizeof(struct i810_channel)*NR_HW_CH,
-                           card->channel, card->chandma);
-       if (card->use_mmio) {
-               iounmap(card->ac97base_mmio);
-               iounmap(card->iobase_mmio);
-               release_mem_region(card->ac97base_mmio_phys, 512);
-               release_mem_region(card->iobase_mmio_phys, 256);
-       }
-
-       /* unregister audio devices */
-       for (i = 0; i < NR_AC97; i++)
-               if (card->ac97_codec[i] != NULL) {
-                       unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
-                       ac97_release_codec(card->ac97_codec[i]);
-                       card->ac97_codec[i] = NULL;
-               }
-       unregister_sound_dsp(card->dev_audio);
-       kfree(card);
-}
-
-#ifdef CONFIG_PM
-static int i810_pm_suspend(struct pci_dev *dev, pm_message_t pm_state)
-{
-        struct i810_card *card = pci_get_drvdata(dev);
-        struct i810_state *state;
-       unsigned long flags;
-       struct dmabuf *dmabuf;
-       int i,num_ac97;
-#ifdef DEBUG
-       printk("i810_audio: i810_pm_suspend called\n");
-#endif
-       if(!card) return 0;
-       spin_lock_irqsave(&card->lock, flags);
-       card->pm_suspended=1;
-       for(i=0;i<NR_HW_CH;i++) {
-               state = card->states[i];
-               if(!state) continue;
-               /* this happens only if there are open files */
-               dmabuf = &state->dmabuf;
-               if(dmabuf->enable & DAC_RUNNING ||
-                  (dmabuf->count && (dmabuf->trigger & PCM_ENABLE_OUTPUT))) {
-                       state->pm_saved_dac_rate=dmabuf->rate;
-                       stop_dac(state);
-               } else {
-                       state->pm_saved_dac_rate=0;
-               }
-               if(dmabuf->enable & ADC_RUNNING) {
-                       state->pm_saved_adc_rate=dmabuf->rate;  
-                       stop_adc(state);
-               } else {
-                       state->pm_saved_adc_rate=0;
-               }
-               dmabuf->ready = 0;
-               dmabuf->swptr = dmabuf->hwptr = 0;
-               dmabuf->count = dmabuf->total_bytes = 0;
-       }
-
-       spin_unlock_irqrestore(&card->lock, flags);
-
-       /* save mixer settings */
-       for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
-               struct ac97_codec *codec = card->ac97_codec[num_ac97];
-               if(!codec) continue;
-               for(i=0;i< SOUND_MIXER_NRDEVICES ;i++) {
-                       if((supported_mixer(codec,i)) &&
-                          (codec->read_mixer)) {
-                               card->pm_saved_mixer_settings[i][num_ac97]=
-                                       codec->read_mixer(codec,i);
-                       }
-               }
-       }
-       pci_save_state(dev); /* XXX do we need this? */
-       pci_disable_device(dev); /* disable busmastering */
-       pci_set_power_state(dev,3); /* Zzz. */
-
-       return 0;
-}
-
-
-static int i810_pm_resume(struct pci_dev *dev)
-{
-       int num_ac97,i=0;
-       struct i810_card *card=pci_get_drvdata(dev);
-       pci_enable_device(dev);
-       pci_restore_state (dev);
-
-       /* observation of a toshiba portege 3440ct suggests that the 
-          hardware has to be more or less completely reinitialized from
-          scratch after an apm suspend.  Works For Me.   -dan */
-
-       i810_ac97_power_up_bus(card);
-
-       for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
-               struct ac97_codec *codec = card->ac97_codec[num_ac97];
-               /* check they haven't stolen the hardware while we were
-                  away */
-               if(!codec || !i810_ac97_exists(card,num_ac97)) {
-                       if(num_ac97) continue;
-                       else BUG();
-               }
-               if(!i810_ac97_probe_and_powerup(card,codec)) BUG();
-               
-               if((card->ac97_features&0x0001)) {
-                       /* at probe time we found we could do variable
-                          rates, but APM suspend has made it forget
-                          its magical powers */
-                       if(!i810_ac97_enable_variable_rate(codec)) BUG();
-               }
-               /* we lost our mixer settings, so restore them */
-               for(i=0;i< SOUND_MIXER_NRDEVICES ;i++) {
-                       if(supported_mixer(codec,i)){
-                               int val=card->
-                                       pm_saved_mixer_settings[i][num_ac97];
-                               codec->mixer_state[i]=val;
-                               codec->write_mixer(codec,i,
-                                                  (val  & 0xff) ,
-                                                  ((val >> 8)  & 0xff) );
-                       }
-               }
-       }
-
-       /* we need to restore the sample rate from whatever it was */
-       for(i=0;i<NR_HW_CH;i++) {
-               struct i810_state * state=card->states[i];
-               if(state) {
-                       if(state->pm_saved_adc_rate)
-                               i810_set_adc_rate(state,state->pm_saved_adc_rate);
-                       if(state->pm_saved_dac_rate)
-                               i810_set_dac_rate(state,state->pm_saved_dac_rate);
-               }
-       }
-
-       
-        card->pm_suspended = 0;
-
-       /* any processes that were reading/writing during the suspend
-          probably ended up here */
-       for(i=0;i<NR_HW_CH;i++) {
-               struct i810_state *state = card->states[i];
-               if(state) wake_up(&state->dmabuf.wait);
-        }
-
-       return 0;
-}      
-#endif /* CONFIG_PM */
-
-MODULE_AUTHOR("The Linux kernel team");
-MODULE_DESCRIPTION("Intel 810 audio support");
-MODULE_LICENSE("GPL");
-module_param(ftsodell, int, 0444);
-module_param(clocking, uint, 0444);
-module_param(strict_clocking, int, 0444);
-module_param(spdif_locked, int, 0444);
-
-#define I810_MODULE_NAME "i810_audio"
-
-static struct pci_driver i810_pci_driver = {
-       .name           = I810_MODULE_NAME,
-       .id_table       = i810_pci_tbl,
-       .probe          = i810_probe,
-       .remove         = __devexit_p(i810_remove),
-#ifdef CONFIG_PM
-       .suspend        = i810_pm_suspend,
-       .resume         = i810_pm_resume,
-#endif /* CONFIG_PM */
-};
-
-
-static int __init i810_init_module (void)
-{
-       int retval;
-
-       printk(KERN_INFO "Intel 810 + AC97 Audio, version "
-              DRIVER_VERSION ", " __TIME__ " " __DATE__ "\n");
-
-       retval = pci_register_driver(&i810_pci_driver);
-       if (retval)
-               return retval;
-
-       if(ftsodell != 0) {
-               printk("i810_audio: ftsodell is now a deprecated option.\n");
-       }
-       if(spdif_locked > 0 ) {
-               if(spdif_locked == 32000 || spdif_locked == 44100 || spdif_locked == 48000) {
-                       printk("i810_audio: Enabling S/PDIF at sample rate %dHz.\n", spdif_locked);
-               } else {
-                       printk("i810_audio: S/PDIF can only be locked to 32000, 44100, or 48000Hz.\n");
-                       spdif_locked = 0;
-               }
-       }
-       
-       return 0;
-}
-
-static void __exit i810_cleanup_module (void)
-{
-       pci_unregister_driver(&i810_pci_driver);
-}
-
-module_init(i810_init_module);
-module_exit(i810_cleanup_module);
-
-/*
-Local Variables:
-c-basic-offset: 8
-End:
-*/
index ece428b2ba9fef34319670b25039bf5783c5bfe6..16ed06950dc1b5c363d4740009b0d1bc5fa3c194 100644 (file)
@@ -232,14 +232,12 @@ static int set_irq(pss_confdata * devc, int dev, int irq)
        return 1;
 }
 
-static int set_io_base(pss_confdata * devc, int dev, int base)
+static void set_io_base(pss_confdata * devc, int dev, int base)
 {
        unsigned short  tmp = inw(REG(dev)) & 0x003f;
        unsigned short  bits = (base & 0x0ffc) << 4;
 
        outw(bits | tmp, REG(dev));
-
-       return 1;
 }
 
 static int set_dma(pss_confdata * devc, int dev, int dma)
@@ -673,20 +671,12 @@ static void configure_nonsound_components(void)
 
        /* Configure CDROM port */
 
-       if(pss_cdrom_port == -1)        /* If cdrom port enablation wasn't requested */
-       {
+       if (pss_cdrom_port == -1) {     /* If cdrom port enablation wasn't requested */
                printk(KERN_INFO "PSS: CDROM port not enabled.\n");
-       }
-       else if(check_region(pss_cdrom_port, 2))
-       {
+       } else if (check_region(pss_cdrom_port, 2)) {
                printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
-       }
-       else if(!set_io_base(devc, CONF_CDROM, pss_cdrom_port))
-       {
-               printk(KERN_ERR "PSS: CDROM I/O port could not be set.\n");
-       }
-       else                                    /* CDROM port successfully configured */
-       {
+       } else {
+               set_io_base(devc, CONF_CDROM, pss_cdrom_port);
                printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
        }
 }
@@ -758,10 +748,7 @@ static int __init probe_pss_mpu(struct address_info *hw_config)
                printk(KERN_ERR "PSS: MPU I/O port conflict\n");
                return 0;
        }
-       if (!set_io_base(devc, CONF_MIDI, hw_config->io_base)) {
-               printk(KERN_ERR "PSS: MIDI base could not be set.\n");
-               goto fail;
-       }
+       set_io_base(devc, CONF_MIDI, hw_config->io_base);
        if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
                printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
                goto fail;
@@ -1057,10 +1044,7 @@ static int __init probe_pss_mss(struct address_info *hw_config)
                release_region(hw_config->io_base, 4);
                return 0;
        }
-       if (!set_io_base(devc, CONF_WSS, hw_config->io_base)) {
-               printk("PSS: WSS base not settable.\n");
-               goto fail;
-       }
+       set_io_base(devc, CONF_WSS, hw_config->io_base);
        if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
                printk("PSS: WSS IRQ allocation error.\n");
                goto fail;
index 07cbacf63824602d3a2763984efc3368c5c0f4ad..77d0e5efda76a9bcd2138f878b2e0a442f137137 100644 (file)
@@ -1228,7 +1228,8 @@ int probe_sbmpu(struct address_info *hw_config, struct module *owner)
                }
                attach_mpu401(hw_config, owner);
                if (last_sb->irq == -hw_config->irq)
-                       last_sb->midi_irq_cookie=(void *)hw_config->slots[1];
+                       last_sb->midi_irq_cookie =
+                               (void *)(long) hw_config->slots[1];
                return 1;
        }
 #endif
index 96adc47917aa538b57c60ac67ef7f11fe6deb881..6959ee1bd17f46cf41965fb295361c410370fd13 100644 (file)
@@ -2935,7 +2935,7 @@ trident_ac97_set(struct ac97_codec *codec, u8 reg, u16 val)
        do {
                if ((inw(TRID_REG(card, address)) & busy) == 0)
                        break;
-       } while (count--);
+       } while (--count);
 
        data |= (mask | (reg & AC97_REG_ADDR));
 
@@ -2996,7 +2996,7 @@ trident_ac97_get(struct ac97_codec *codec, u8 reg)
                data = inl(TRID_REG(card, address));
                if ((data & busy) == 0)
                        break;
-       } while (count--);
+       } while (--count);
        spin_unlock_irqrestore(&card->lock, flags);
 
        if (count == 0) {
diff --git a/sound/oss/via82cxxx_audio.c b/sound/oss/via82cxxx_audio.c
deleted file mode 100644 (file)
index 5d3c037..0000000
+++ /dev/null
@@ -1,3618 +0,0 @@
-/*
- * Support for VIA 82Cxxx Audio Codecs
- * Copyright 1999,2000 Jeff Garzik
- *
- * Updated to support the VIA 8233/8235 audio subsystem
- * Alan Cox <alan@redhat.com> (C) Copyright 2002, 2003 Red Hat Inc
- *
- * Distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2.
- * See the "COPYING" file distributed with this software for more info.
- * NO WARRANTY
- *
- * For a list of known bugs (errata) and documentation,
- * see via-audio.pdf in Documentation/DocBook.
- * If this documentation does not exist, run "make pdfdocs".
- */
-
-
-#define VIA_VERSION    "1.9.1-ac4-2.5"
-
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/fs.h>
-#include <linux/mm.h>
-#include <linux/pci.h>
-#include <linux/poison.h>
-#include <linux/init.h>
-#include <linux/interrupt.h>
-#include <linux/proc_fs.h>
-#include <linux/spinlock.h>
-#include <linux/sound.h>
-#include <linux/poll.h>
-#include <linux/soundcard.h>
-#include <linux/ac97_codec.h>
-#include <linux/ioport.h>
-#include <linux/delay.h>
-#include <linux/dma-mapping.h>
-#include <asm/io.h>
-#include <asm/uaccess.h>
-#include <linux/mutex.h>
-
-#include "sound_config.h"
-#include "dev_table.h"
-#include "mpu401.h"
-
-
-#undef VIA_DEBUG       /* define to enable debugging output and checks */
-#ifdef VIA_DEBUG
-/* note: prints function name for you */
-#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
-#else
-#define DPRINTK(fmt, args...)
-#endif
-
-#undef VIA_NDEBUG      /* define to disable lightweight runtime checks */
-#ifdef VIA_NDEBUG
-#define assert(expr)
-#else
-#define assert(expr) \
-        if(!(expr)) {                                  \
-        printk( "Assertion failed! %s,%s,%s,line=%d\n",        \
-        #expr,__FILE__,__FUNCTION__,__LINE__);         \
-        }
-#endif
-
-#define VIA_SUPPORT_MMAP 1 /* buggy, for now... */
-
-#define MAX_CARDS      1
-
-#define VIA_CARD_NAME  "VIA 82Cxxx Audio driver " VIA_VERSION
-#define VIA_MODULE_NAME "via82cxxx"
-#define PFX            VIA_MODULE_NAME ": "
-
-#define VIA_COUNTER_LIMIT      100000
-
-/* size of DMA buffers */
-#define VIA_MAX_BUFFER_DMA_PAGES       32
-
-/* buffering default values in ms */
-#define VIA_DEFAULT_FRAG_TIME          20
-#define VIA_DEFAULT_BUFFER_TIME                500
-
-/* the hardware has a 256 fragment limit */
-#define VIA_MIN_FRAG_NUMBER            2
-#define VIA_MAX_FRAG_NUMBER            128
-
-#define VIA_MAX_FRAG_SIZE              PAGE_SIZE
-#define VIA_MIN_FRAG_SIZE              (VIA_MAX_BUFFER_DMA_PAGES * PAGE_SIZE / VIA_MAX_FRAG_NUMBER)
-
-
-/* 82C686 function 5 (audio codec) PCI configuration registers */
-#define VIA_ACLINK_STATUS      0x40
-#define VIA_ACLINK_CTRL                0x41
-#define VIA_FUNC_ENABLE                0x42
-#define VIA_PNP_CONTROL                0x43
-#define VIA_FM_NMI_CTRL                0x48
-
-/*
- * controller base 0 (scatter-gather) registers
- *
- * NOTE: Via datasheet lists first channel as "read"
- * channel and second channel as "write" channel.
- * I changed the naming of the constants to be more
- * clear than I felt the datasheet to be.
- */
-
-#define VIA_BASE0_PCM_OUT_CHAN 0x00 /* output PCM to user */
-#define VIA_BASE0_PCM_OUT_CHAN_STATUS 0x00
-#define VIA_BASE0_PCM_OUT_CHAN_CTRL    0x01
-#define VIA_BASE0_PCM_OUT_CHAN_TYPE    0x02
-
-#define VIA_BASE0_PCM_IN_CHAN          0x10 /* input PCM from user */
-#define VIA_BASE0_PCM_IN_CHAN_STATUS   0x10
-#define VIA_BASE0_PCM_IN_CHAN_CTRL     0x11
-#define VIA_BASE0_PCM_IN_CHAN_TYPE     0x12
-
-/* offsets from base */
-#define VIA_PCM_STATUS                 0x00
-#define VIA_PCM_CONTROL                        0x01
-#define VIA_PCM_TYPE                   0x02
-#define VIA_PCM_LEFTVOL                        0x02
-#define VIA_PCM_RIGHTVOL               0x03
-#define VIA_PCM_TABLE_ADDR             0x04
-#define VIA_PCM_STOPRATE               0x08    /* 8233+ */
-#define VIA_PCM_BLOCK_COUNT            0x0C
-
-/* XXX unused DMA channel for FM PCM data */
-#define VIA_BASE0_FM_OUT_CHAN          0x20
-#define VIA_BASE0_FM_OUT_CHAN_STATUS   0x20
-#define VIA_BASE0_FM_OUT_CHAN_CTRL     0x21
-#define VIA_BASE0_FM_OUT_CHAN_TYPE     0x22
-
-/* Six channel audio output on 8233 */
-#define VIA_BASE0_MULTI_OUT_CHAN               0x40
-#define VIA_BASE0_MULTI_OUT_CHAN_STATUS                0x40
-#define VIA_BASE0_MULTI_OUT_CHAN_CTRL          0x41
-#define VIA_BASE0_MULTI_OUT_CHAN_TYPE          0x42
-
-#define VIA_BASE0_AC97_CTRL            0x80
-#define VIA_BASE0_SGD_STATUS_SHADOW    0x84
-#define VIA_BASE0_GPI_INT_ENABLE       0x8C
-#define VIA_INTR_OUT                   ((1<<0) |  (1<<4) |  (1<<8))
-#define VIA_INTR_IN                    ((1<<1) |  (1<<5) |  (1<<9))
-#define VIA_INTR_FM                    ((1<<2) |  (1<<6) | (1<<10))
-#define VIA_INTR_MASK          (VIA_INTR_OUT | VIA_INTR_IN | VIA_INTR_FM)
-
-/* Newer VIA we need to monitor the low 3 bits of each channel. This
-   mask covers the channels we don't yet use as well 
- */
-#define VIA_NEW_INTR_MASK              0x77077777UL
-
-/* VIA_BASE0_AUDIO_xxx_CHAN_TYPE bits */
-#define VIA_IRQ_ON_FLAG                        (1<<0)  /* int on each flagged scatter block */
-#define VIA_IRQ_ON_EOL                 (1<<1)  /* int at end of scatter list */
-#define VIA_INT_SEL_PCI_LAST_LINE_READ (0)     /* int at PCI read of last line */
-#define VIA_INT_SEL_LAST_SAMPLE_SENT   (1<<2)  /* int at last sample sent */
-#define VIA_INT_SEL_ONE_LINE_LEFT      (1<<3)  /* int at less than one line to send */
-#define VIA_PCM_FMT_STEREO             (1<<4)  /* PCM stereo format (bit clear == mono) */
-#define VIA_PCM_FMT_16BIT              (1<<5)  /* PCM 16-bit format (bit clear == 8-bit) */
-#define VIA_PCM_REC_FIFO               (1<<6)  /* PCM Recording FIFO */
-#define VIA_RESTART_SGD_ON_EOL         (1<<7)  /* restart scatter-gather at EOL */
-#define VIA_PCM_FMT_MASK               (VIA_PCM_FMT_STEREO|VIA_PCM_FMT_16BIT)
-#define VIA_CHAN_TYPE_MASK             (VIA_RESTART_SGD_ON_EOL | \
-                                        VIA_IRQ_ON_FLAG | \
-                                        VIA_IRQ_ON_EOL)
-#define VIA_CHAN_TYPE_INT_SELECT       (VIA_INT_SEL_LAST_SAMPLE_SENT)
-
-/* PCI configuration register bits and masks */
-#define VIA_CR40_AC97_READY    0x01
-#define VIA_CR40_AC97_LOW_POWER        0x02
-#define VIA_CR40_SECONDARY_READY 0x04
-
-#define VIA_CR41_AC97_ENABLE   0x80 /* enable AC97 codec */
-#define VIA_CR41_AC97_RESET    0x40 /* clear bit to reset AC97 */
-#define VIA_CR41_AC97_WAKEUP   0x20 /* wake up from power-down mode */
-#define VIA_CR41_AC97_SDO      0x10 /* force Serial Data Out (SDO) high */
-#define VIA_CR41_VRA           0x08 /* enable variable sample rate */
-#define VIA_CR41_PCM_ENABLE    0x04 /* AC Link SGD Read Channel PCM Data Output */
-#define VIA_CR41_FM_PCM_ENABLE 0x02 /* AC Link FM Channel PCM Data Out */
-#define VIA_CR41_SB_PCM_ENABLE 0x01 /* AC Link SB PCM Data Output */
-#define VIA_CR41_BOOT_MASK     (VIA_CR41_AC97_ENABLE | \
-                                VIA_CR41_AC97_WAKEUP | \
-                                VIA_CR41_AC97_SDO)
-#define VIA_CR41_RUN_MASK      (VIA_CR41_AC97_ENABLE | \
-                                VIA_CR41_AC97_RESET | \
-                                VIA_CR41_VRA | \
-                                VIA_CR41_PCM_ENABLE)
-
-#define VIA_CR42_SB_ENABLE     0x01
-#define VIA_CR42_MIDI_ENABLE   0x02
-#define VIA_CR42_FM_ENABLE     0x04
-#define VIA_CR42_GAME_ENABLE   0x08
-#define VIA_CR42_MIDI_IRQMASK   0x40
-#define VIA_CR42_MIDI_PNP      0x80
-
-#define VIA_CR44_SECOND_CODEC_SUPPORT  (1 << 6)
-#define VIA_CR44_AC_LINK_ACCESS                (1 << 7)
-
-#define VIA_CR48_FM_TRAP_TO_NMI                (1 << 2)
-
-/* controller base 0 register bitmasks */
-#define VIA_INT_DISABLE_MASK           (~(0x01|0x02))
-#define VIA_SGD_STOPPED                        (1 << 2)
-#define VIA_SGD_PAUSED                 (1 << 6)
-#define VIA_SGD_ACTIVE                 (1 << 7)
-#define VIA_SGD_TERMINATE              (1 << 6)
-#define VIA_SGD_FLAG                   (1 << 0)
-#define VIA_SGD_EOL                    (1 << 1)
-#define VIA_SGD_START                  (1 << 7)
-
-#define VIA_CR80_FIRST_CODEC           0
-#define VIA_CR80_SECOND_CODEC          (1 << 30)
-#define VIA_CR80_FIRST_CODEC_VALID     (1 << 25)
-#define VIA_CR80_VALID                 (1 << 25)
-#define VIA_CR80_SECOND_CODEC_VALID    (1 << 27)
-#define VIA_CR80_BUSY                  (1 << 24)
-#define VIA_CR83_BUSY                  (1)
-#define VIA_CR83_FIRST_CODEC_VALID     (1 << 1)
-#define VIA_CR80_READ                  (1 << 23)
-#define VIA_CR80_WRITE_MODE            0
-#define VIA_CR80_REG_IDX(idx)          ((((idx) & 0xFF) >> 1) << 16)
-
-/* capabilities we announce */
-#ifdef VIA_SUPPORT_MMAP
-#define VIA_DSP_CAP (DSP_CAP_REVISION | DSP_CAP_DUPLEX | DSP_CAP_MMAP | \
-                    DSP_CAP_TRIGGER | DSP_CAP_REALTIME)
-#else
-#define VIA_DSP_CAP (DSP_CAP_REVISION | DSP_CAP_DUPLEX | \
-                    DSP_CAP_TRIGGER | DSP_CAP_REALTIME)
-#endif
-
-/* scatter-gather DMA table entry, exactly as passed to hardware */
-struct via_sgd_table {
-       u32 addr;
-       u32 count;      /* includes additional VIA_xxx bits also */
-};
-
-#define VIA_EOL (1 << 31)
-#define VIA_FLAG (1 << 30)
-#define VIA_STOP (1 << 29)
-
-
-enum via_channel_states {
-       sgd_stopped = 0,
-       sgd_in_progress = 1,
-};
-
-
-struct via_buffer_pgtbl {
-       dma_addr_t handle;
-       void *cpuaddr;
-};
-
-
-struct via_channel {
-       atomic_t n_frags;
-       atomic_t hw_ptr;
-       wait_queue_head_t wait;
-
-       unsigned int sw_ptr;
-       unsigned int slop_len;
-       unsigned int n_irqs;
-       int bytes;
-
-       unsigned is_active : 1;
-       unsigned is_record : 1;
-       unsigned is_mapped : 1;
-       unsigned is_enabled : 1;
-       unsigned is_multi: 1;   /* 8233 6 channel */
-       u8 pcm_fmt;             /* VIA_PCM_FMT_xxx */
-       u8 channels;            /* Channel count */
-
-       unsigned rate;          /* sample rate */
-       unsigned int frag_size;
-       unsigned int frag_number;
-       
-       unsigned char intmask;
-
-       volatile struct via_sgd_table *sgtable;
-       dma_addr_t sgt_handle;
-
-       unsigned int page_number;
-       struct via_buffer_pgtbl pgtbl[VIA_MAX_BUFFER_DMA_PAGES];
-
-       long iobase;
-
-       const char *name;
-};
-
-
-/* data stored for each chip */
-struct via_info {
-       struct pci_dev *pdev;
-       long baseaddr;
-
-       struct ac97_codec *ac97;
-       spinlock_t ac97_lock;
-       spinlock_t lock;
-       int card_num;           /* unique card number, from 0 */
-
-       int dev_dsp;            /* /dev/dsp index from register_sound_dsp() */
-
-       unsigned rev_h : 1;
-       unsigned legacy: 1;     /* Has legacy ports */
-       unsigned intmask: 1;    /* Needs int bits */
-       unsigned sixchannel: 1; /* 8233/35 with 6 channel support */
-       unsigned volume: 1;
-
-       unsigned locked_rate : 1;
-       
-       int mixer_vol;          /* 8233/35 volume  - not yet implemented */
-
-       struct mutex syscall_mutex;
-       struct mutex open_mutex;
-
-       /* The 8233/8235 have 4 DX audio channels, two record and
-          one six channel out. We bind ch_in to DX 1, ch_out to multichannel
-          and ch_fm to DX 2. DX 3 and REC0/REC1 are unused at the
-          moment */
-          
-       struct via_channel ch_in;
-       struct via_channel ch_out;
-       struct via_channel ch_fm;
-
-#ifdef CONFIG_MIDI_VIA82CXXX
-        void *midi_devc;
-        struct address_info midi_info;
-#endif
-};
-
-
-/* number of cards, used for assigning unique numbers to cards */
-static unsigned via_num_cards;
-
-
-
-/****************************************************************
- *
- * prototypes
- *
- *
- */
-
-static int via_init_one (struct pci_dev *dev, const struct pci_device_id *id);
-static void __devexit via_remove_one (struct pci_dev *pdev);
-
-static ssize_t via_dsp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos);
-static ssize_t via_dsp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos);
-static unsigned int via_dsp_poll(struct file *file, struct poll_table_struct *wait);
-static int via_dsp_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
-static int via_dsp_open (struct inode *inode, struct file *file);
-static int via_dsp_release(struct inode *inode, struct file *file);
-static int via_dsp_mmap(struct file *file, struct vm_area_struct *vma);
-
-static u16 via_ac97_read_reg (struct ac97_codec *codec, u8 reg);
-static void via_ac97_write_reg (struct ac97_codec *codec, u8 reg, u16 value);
-static u8 via_ac97_wait_idle (struct via_info *card);
-
-static void via_chan_free (struct via_info *card, struct via_channel *chan);
-static void via_chan_clear (struct via_info *card, struct via_channel *chan);
-static void via_chan_pcm_fmt (struct via_channel *chan, int reset);
-static void via_chan_buffer_free (struct via_info *card, struct via_channel *chan);
-
-
-/****************************************************************
- *
- * Various data the driver needs
- *
- *
- */
-
-
-static struct pci_device_id via_pci_tbl[] = {
-       { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
-       { 0, }
-};
-MODULE_DEVICE_TABLE(pci,via_pci_tbl);
-
-
-static struct pci_driver via_driver = {
-       .name           = VIA_MODULE_NAME,
-       .id_table       = via_pci_tbl,
-       .probe          = via_init_one,
-       .remove         = __devexit_p(via_remove_one),
-};
-
-
-/****************************************************************
- *
- * Low-level base 0 register read/write helpers
- *
- *
- */
-
-/**
- *     via_chan_stop - Terminate DMA on specified PCM channel
- *     @iobase: PCI base address for SGD channel registers
- *
- *     Terminate scatter-gather DMA operation for given
- *     channel (derived from @iobase), if DMA is active.
- *
- *     Note that @iobase is not the PCI base address,
- *     but the PCI base address plus an offset to
- *     one of three PCM channels supported by the chip.
- *
- */
-
-static inline void via_chan_stop (long iobase)
-{
-       if (inb (iobase + VIA_PCM_STATUS) & VIA_SGD_ACTIVE)
-               outb (VIA_SGD_TERMINATE, iobase + VIA_PCM_CONTROL);
-}
-
-
-/**
- *     via_chan_status_clear - Clear status flags on specified DMA channel
- *     @iobase: PCI base address for SGD channel registers
- *
- *     Clear any pending status flags for the given
- *     DMA channel (derived from @iobase), if any
- *     flags are asserted.
- *
- *     Note that @iobase is not the PCI base address,
- *     but the PCI base address plus an offset to
- *     one of three PCM channels supported by the chip.
- *
- */
-
-static inline void via_chan_status_clear (long iobase)
-{
-       u8 tmp = inb (iobase + VIA_PCM_STATUS);
-
-       if (tmp != 0)
-               outb (tmp, iobase + VIA_PCM_STATUS);
-}
-
-
-/**
- *     sg_begin - Begin recording or playback on a PCM channel
- *     @chan: Channel for which DMA operation shall begin
- *
- *     Start scatter-gather DMA for the given channel.
- *
- */
-
-static inline void sg_begin (struct via_channel *chan)
-{
-       DPRINTK("Start with intmask %d\n", chan->intmask);
-       DPRINTK("About to start from %d to %d\n", 
-               inl(chan->iobase + VIA_PCM_BLOCK_COUNT),
-               inb(chan->iobase + VIA_PCM_STOPRATE + 3));
-       outb (VIA_SGD_START|chan->intmask, chan->iobase + VIA_PCM_CONTROL);
-       DPRINTK("Status is now %02X\n", inb(chan->iobase + VIA_PCM_STATUS));
-       DPRINTK("Control is now %02X\n", inb(chan->iobase + VIA_PCM_CONTROL));
-}
-
-
-static int sg_active (long iobase)
-{
-       u8 tmp = inb (iobase + VIA_PCM_STATUS);
-       if ((tmp & VIA_SGD_STOPPED) || (tmp & VIA_SGD_PAUSED)) {
-               printk(KERN_WARNING "via82cxxx warning: SG stopped or paused\n");
-               return 0;
-       }
-       if (tmp & VIA_SGD_ACTIVE)
-               return 1;
-       return 0;
-}
-
-static int via_sg_offset(struct via_channel *chan)
-{
-       return inl (chan->iobase + VIA_PCM_BLOCK_COUNT) & 0x00FFFFFF;
-}
-
-/****************************************************************
- *
- * Miscellaneous debris
- *
- *
- */
-
-
-/**
- *     via_syscall_down - down the card-specific syscell semaphore
- *     @card: Private info for specified board
- *     @nonblock: boolean, non-zero if O_NONBLOCK is set
- *
- *     Encapsulates standard method of acquiring the syscall sem.
- *
- *     Returns negative errno on error, or zero for success.
- */
-
-static inline int via_syscall_down (struct via_info *card, int nonblock)
-{
-       /* Thomas Sailer:
-        * EAGAIN is supposed to be used if IO is pending,
-        * not if there is contention on some internal
-        * synchronization primitive which should be
-        * held only for a short time anyway
-        */
-       nonblock = 0;
-
-       if (nonblock) {
-               if (!mutex_trylock(&card->syscall_mutex))
-                       return -EAGAIN;
-       } else {
-               if (mutex_lock_interruptible(&card->syscall_mutex))
-                       return -ERESTARTSYS;
-       }
-
-       return 0;
-}
-
-
-/**
- *     via_stop_everything - Stop all audio operations
- *     @card: Private info for specified board
- *
- *     Stops all DMA operations and interrupts, and clear
- *     any pending status bits resulting from those operations.
- */
-
-static void via_stop_everything (struct via_info *card)
-{
-       u8 tmp, new_tmp;
-
-       DPRINTK ("ENTER\n");
-
-       assert (card != NULL);
-
-       /*
-        * terminate any existing operations on audio read/write channels
-        */
-       via_chan_stop (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN);
-       via_chan_stop (card->baseaddr + VIA_BASE0_PCM_IN_CHAN);
-       via_chan_stop (card->baseaddr + VIA_BASE0_FM_OUT_CHAN);
-       if(card->sixchannel)
-               via_chan_stop (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN);
-
-       /*
-        * clear any existing stops / flags (sanity check mainly)
-        */
-       via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN);
-       via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_IN_CHAN);
-       via_chan_status_clear (card->baseaddr + VIA_BASE0_FM_OUT_CHAN);
-       if(card->sixchannel)
-               via_chan_status_clear (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN);
-
-       /*
-        * clear any enabled interrupt bits
-        */
-       tmp = inb (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN_TYPE);
-       new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
-       if (tmp != new_tmp)
-               outb (0, card->baseaddr + VIA_BASE0_PCM_OUT_CHAN_TYPE);
-
-       tmp = inb (card->baseaddr + VIA_BASE0_PCM_IN_CHAN_TYPE);
-       new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
-       if (tmp != new_tmp)
-               outb (0, card->baseaddr + VIA_BASE0_PCM_IN_CHAN_TYPE);
-
-       tmp = inb (card->baseaddr + VIA_BASE0_FM_OUT_CHAN_TYPE);
-       new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
-       if (tmp != new_tmp)
-               outb (0, card->baseaddr + VIA_BASE0_FM_OUT_CHAN_TYPE);
-
-       if(card->sixchannel)
-       {
-               tmp = inb (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN_TYPE);
-               new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
-               if (tmp != new_tmp)
-                       outb (0, card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN_TYPE);
-       }
-
-       udelay(10);
-
-       /*
-        * clear any existing flags
-        */
-       via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN);
-       via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_IN_CHAN);
-       via_chan_status_clear (card->baseaddr + VIA_BASE0_FM_OUT_CHAN);
-
-       DPRINTK ("EXIT\n");
-}
-
-
-/**
- *     via_set_rate - Set PCM rate for given channel
- *     @ac97: Pointer to generic codec info struct
- *     @chan: Private info for specified channel
- *     @rate: Desired PCM sample rate, in Khz
- *
- *     Sets the PCM sample rate for a channel.
- *
- *     Values for @rate are clamped to a range of 4000 Khz through 48000 Khz,
- *     due to hardware constraints.
- */
-
-static int via_set_rate (struct ac97_codec *ac97,
-                        struct via_channel *chan, unsigned rate)
-{
-       struct via_info *card = ac97->private_data;
-       int rate_reg;
-       u32 dacp;
-       u32 mast_vol, phone_vol, mono_vol, pcm_vol;
-       u32 mute_vol = 0x8000;  /* The mute volume? -- Seems to work! */
-
-       DPRINTK ("ENTER, rate = %d\n", rate);
-
-       if (chan->rate == rate)
-               goto out;
-       if (card->locked_rate) {
-               chan->rate = 48000;
-               goto out;
-       }
-
-       if (rate > 48000)               rate = 48000;
-       if (rate < 4000)                rate = 4000;
-
-       rate_reg = chan->is_record ? AC97_PCM_LR_ADC_RATE :
-                           AC97_PCM_FRONT_DAC_RATE;
-
-       /* Save current state */
-       dacp=via_ac97_read_reg(ac97, AC97_POWER_CONTROL);
-       mast_vol = via_ac97_read_reg(ac97, AC97_MASTER_VOL_STEREO);
-       mono_vol = via_ac97_read_reg(ac97, AC97_MASTER_VOL_MONO);
-       phone_vol = via_ac97_read_reg(ac97, AC97_HEADPHONE_VOL);
-       pcm_vol = via_ac97_read_reg(ac97, AC97_PCMOUT_VOL);
-       /* Mute - largely reduces popping */
-       via_ac97_write_reg(ac97, AC97_MASTER_VOL_STEREO, mute_vol);
-       via_ac97_write_reg(ac97, AC97_MASTER_VOL_MONO, mute_vol);
-       via_ac97_write_reg(ac97, AC97_HEADPHONE_VOL, mute_vol);
-               via_ac97_write_reg(ac97, AC97_PCMOUT_VOL, mute_vol);
-       /* Power down the DAC */
-       via_ac97_write_reg(ac97, AC97_POWER_CONTROL, dacp|0x0200);
-
-        /* Set new rate */
-       via_ac97_write_reg (ac97, rate_reg, rate);
-
-       /* Power DAC back up */
-       via_ac97_write_reg(ac97, AC97_POWER_CONTROL, dacp);
-       udelay (200); /* reduces popping */
-
-       /* Restore volumes */
-       via_ac97_write_reg(ac97, AC97_MASTER_VOL_STEREO, mast_vol);
-       via_ac97_write_reg(ac97, AC97_MASTER_VOL_MONO, mono_vol);
-       via_ac97_write_reg(ac97, AC97_HEADPHONE_VOL, phone_vol);
-       via_ac97_write_reg(ac97, AC97_PCMOUT_VOL, pcm_vol);
-
-       /* the hardware might return a value different than what we
-        * passed to it, so read the rate value back from hardware
-        * to see what we came up with
-        */
-       chan->rate = via_ac97_read_reg (ac97, rate_reg);
-
-       if (chan->rate == 0) {
-               card->locked_rate = 1;
-               chan->rate = 48000;
-               printk (KERN_WARNING PFX "Codec rate locked at 48Khz\n");
-       }
-
-out:
-       DPRINTK ("EXIT, returning rate %d Hz\n", chan->rate);
-       return chan->rate;
-}
-
-
-/****************************************************************
- *
- * Channel-specific operations
- *
- *
- */
-
-
-/**
- *     via_chan_init_defaults - Initialize a struct via_channel
- *     @card: Private audio chip info
- *     @chan: Channel to be initialized
- *
- *     Zero @chan, and then set all static defaults for the structure.
- */
-
-static void via_chan_init_defaults (struct via_info *card, struct via_channel *chan)
-{
-       memset (chan, 0, sizeof (*chan));
-
-       if(card->intmask)
-               chan->intmask = 0x23;   /* Turn on the IRQ bits */
-               
-       if (chan == &card->ch_out) {
-               chan->name = "PCM-OUT";
-               if(card->sixchannel)
-               {
-                       chan->iobase = card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN;
-                       chan->is_multi = 1;
-                       DPRINTK("Using multichannel for pcm out\n");
-               }
-               else
-                       chan->iobase = card->baseaddr + VIA_BASE0_PCM_OUT_CHAN;
-       } else if (chan == &card->ch_in) {
-               chan->name = "PCM-IN";
-               chan->iobase = card->baseaddr + VIA_BASE0_PCM_IN_CHAN;
-               chan->is_record = 1;
-       } else if (chan == &card->ch_fm) {
-               chan->name = "PCM-OUT-FM";
-               chan->iobase = card->baseaddr + VIA_BASE0_FM_OUT_CHAN;
-       } else {
-               BUG();
-       }
-
-       init_waitqueue_head (&chan->wait);
-
-       chan->pcm_fmt = VIA_PCM_FMT_MASK;
-       chan->is_enabled = 1;
-
-       chan->frag_number = 0;
-        chan->frag_size = 0;
-       atomic_set(&chan->n_frags, 0);
-       atomic_set (&chan->hw_ptr, 0);
-}
-
-/**
- *      via_chan_init - Initialize PCM channel
- *      @card: Private audio chip info
- *      @chan: Channel to be initialized
- *
- *      Performs some of the preparations necessary to begin
- *      using a PCM channel.
- *
- *      Currently the preparations consist of
- *      setting the PCM channel to a known state.
- */
-
-
-static void via_chan_init (struct via_info *card, struct via_channel *chan)
-{
-
-        DPRINTK ("ENTER\n");
-
-       /* bzero channel structure, and init members to defaults */
-        via_chan_init_defaults (card, chan);
-
-        /* stop any existing channel output */
-        via_chan_clear (card, chan);
-        via_chan_status_clear (chan->iobase);
-        via_chan_pcm_fmt (chan, 1);
-
-       DPRINTK ("EXIT\n");
-}
-
-/**
- *     via_chan_buffer_init - Initialize PCM channel buffer
- *     @card: Private audio chip info
- *     @chan: Channel to be initialized
- *
- *     Performs some of the preparations necessary to begin
- *     using a PCM channel.
- *
- *     Currently the preparations include allocating the
- *     scatter-gather DMA table and buffers,
- *     and passing the
- *     address of the DMA table to the hardware.
- *
- *     Note that special care is taken when passing the
- *     DMA table address to hardware, because it was found
- *     during driver development that the hardware did not
- *     always "take" the address.
- */
-
-static int via_chan_buffer_init (struct via_info *card, struct via_channel *chan)
-{
-       int page, offset;
-       int i;
-
-       DPRINTK ("ENTER\n");
-
-
-       chan->intmask = 0;
-       if(card->intmask)
-               chan->intmask = 0x23;   /* Turn on the IRQ bits */
-               
-       if (chan->sgtable != NULL) {
-               DPRINTK ("EXIT\n");
-               return 0;
-       }
-
-       /* alloc DMA-able memory for scatter-gather table */
-       chan->sgtable = pci_alloc_consistent (card->pdev,
-               (sizeof (struct via_sgd_table) * chan->frag_number),
-               &chan->sgt_handle);
-       if (!chan->sgtable) {
-               printk (KERN_ERR PFX "DMA table alloc fail, aborting\n");
-               DPRINTK ("EXIT\n");
-               return -ENOMEM;
-       }
-
-       memset ((void*)chan->sgtable, 0,
-               (sizeof (struct via_sgd_table) * chan->frag_number));
-
-       /* alloc DMA-able memory for scatter-gather buffers */
-
-       chan->page_number = (chan->frag_number * chan->frag_size) / PAGE_SIZE +
-                           (((chan->frag_number * chan->frag_size) % PAGE_SIZE) ? 1 : 0);
-
-       for (i = 0; i < chan->page_number; i++) {
-               chan->pgtbl[i].cpuaddr = pci_alloc_consistent (card->pdev, PAGE_SIZE,
-                                             &chan->pgtbl[i].handle);
-
-               if (!chan->pgtbl[i].cpuaddr) {
-                       chan->page_number = i;
-                       goto err_out_nomem;
-               }
-
-#ifndef VIA_NDEBUG
-                memset (chan->pgtbl[i].cpuaddr, 0xBC, chan->frag_size);
-#endif
-
-#if 1
-                DPRINTK ("dmabuf_pg #%d (h=%lx, v2p=%lx, a=%p)\n",
-                       i, (long)chan->pgtbl[i].handle,
-                       virt_to_phys(chan->pgtbl[i].cpuaddr),
-                       chan->pgtbl[i].cpuaddr);
-#endif
-       }
-
-       for (i = 0; i < chan->frag_number; i++) {
-
-               page = i / (PAGE_SIZE / chan->frag_size);
-               offset = (i % (PAGE_SIZE / chan->frag_size)) * chan->frag_size;
-
-               chan->sgtable[i].count = cpu_to_le32 (chan->frag_size | VIA_FLAG);
-               chan->sgtable[i].addr = cpu_to_le32 (chan->pgtbl[page].handle + offset);
-
-#if 1
-               DPRINTK ("dmabuf #%d (32(h)=%lx)\n",
-                        i,
-                        (long)chan->sgtable[i].addr);
-#endif
-       }
-
-       /* overwrite the last buffer information */
-       chan->sgtable[chan->frag_number - 1].count = cpu_to_le32 (chan->frag_size | VIA_EOL);
-
-       /* set location of DMA-able scatter-gather info table */
-       DPRINTK ("outl (0x%X, 0x%04lX)\n",
-               chan->sgt_handle, chan->iobase + VIA_PCM_TABLE_ADDR);
-
-       via_ac97_wait_idle (card);
-       outl (chan->sgt_handle, chan->iobase + VIA_PCM_TABLE_ADDR);
-       udelay (20);
-       via_ac97_wait_idle (card);
-       /* load no rate adaption, stereo 16bit, set up ring slots */
-       if(card->sixchannel)
-       {
-               if(!chan->is_multi)
-               {
-                       outl (0xFFFFF | (0x3 << 20) | (chan->frag_number << 24), chan->iobase + VIA_PCM_STOPRATE);
-                       udelay (20);
-                       via_ac97_wait_idle (card);
-               }
-       }
-
-       DPRINTK ("inl (0x%lX) = %x\n",
-               chan->iobase + VIA_PCM_TABLE_ADDR,
-               inl(chan->iobase + VIA_PCM_TABLE_ADDR));
-
-       DPRINTK ("EXIT\n");
-       return 0;
-
-err_out_nomem:
-       printk (KERN_ERR PFX "DMA buffer alloc fail, aborting\n");
-       via_chan_buffer_free (card, chan);
-       DPRINTK ("EXIT\n");
-       return -ENOMEM;
-}
-
-
-/**
- *     via_chan_free - Release a PCM channel
- *     @card: Private audio chip info
- *     @chan: Channel to be released
- *
- *     Performs all the functions necessary to clean up
- *     an initialized channel.
- *
- *     Currently these functions include disabled any
- *     active DMA operations, setting the PCM channel
- *     back to a known state, and releasing any allocated
- *     sound buffers.
- */
-
-static void via_chan_free (struct via_info *card, struct via_channel *chan)
-{
-       DPRINTK ("ENTER\n");
-
-       spin_lock_irq (&card->lock);
-
-       /* stop any existing channel output */
-       via_chan_status_clear (chan->iobase);
-       via_chan_stop (chan->iobase);
-       via_chan_status_clear (chan->iobase);
-
-       spin_unlock_irq (&card->lock);
-
-       synchronize_irq(card->pdev->irq);
-
-       DPRINTK ("EXIT\n");
-}
-
-static void via_chan_buffer_free (struct via_info *card, struct via_channel *chan)
-{
-       int i;
-
-        DPRINTK ("ENTER\n");
-
-       /* zero location of DMA-able scatter-gather info table */
-       via_ac97_wait_idle(card);
-       outl (0, chan->iobase + VIA_PCM_TABLE_ADDR);
-
-       for (i = 0; i < chan->page_number; i++)
-               if (chan->pgtbl[i].cpuaddr) {
-                       pci_free_consistent (card->pdev, PAGE_SIZE,
-                                            chan->pgtbl[i].cpuaddr,
-                                            chan->pgtbl[i].handle);
-                       chan->pgtbl[i].cpuaddr = NULL;
-                       chan->pgtbl[i].handle = 0;
-               }
-
-       chan->page_number = 0;
-
-       if (chan->sgtable) {
-               pci_free_consistent (card->pdev,
-                       (sizeof (struct via_sgd_table) * chan->frag_number),
-                       (void*)chan->sgtable, chan->sgt_handle);
-               chan->sgtable = NULL;
-       }
-
-       DPRINTK ("EXIT\n");
-}
-
-
-/**
- *     via_chan_pcm_fmt - Update PCM channel settings
- *     @chan: Channel to be updated
- *     @reset: Boolean.  If non-zero, channel will be reset
- *             to 8-bit mono mode.
- *
- *     Stores the settings of the current PCM format,
- *     8-bit or 16-bit, and mono/stereo, into the
- *     hardware settings for the specified channel.
- *     If @reset is non-zero, the channel is reset
- *     to 8-bit mono mode.  Otherwise, the channel
- *     is set to the values stored in the channel
- *     information struct @chan.
- */
-
-static void via_chan_pcm_fmt (struct via_channel *chan, int reset)
-{
-       DPRINTK ("ENTER, pcm_fmt=0x%02X, reset=%s\n",
-                chan->pcm_fmt, reset ? "yes" : "no");
-
-       assert (chan != NULL);
-
-       if (reset)
-       {
-               /* reset to 8-bit mono mode */
-               chan->pcm_fmt = 0;
-               chan->channels = 1;
-       }
-
-       /* enable interrupts on FLAG and EOL */
-       chan->pcm_fmt |= VIA_CHAN_TYPE_MASK;
-
-       /* if we are recording, enable recording fifo bit */
-       if (chan->is_record)
-               chan->pcm_fmt |= VIA_PCM_REC_FIFO;
-       /* set interrupt select bits where applicable (PCM in & out channels) */
-       if (!chan->is_record)
-               chan->pcm_fmt |= VIA_CHAN_TYPE_INT_SELECT;
-       
-       DPRINTK("SET FMT - %02x %02x\n", chan->intmask , chan->is_multi);
-       
-       if(chan->intmask)
-       {
-               u32 m;
-
-               /*
-                *      Channel 0x4 is up to 6 x 16bit and has to be
-                *      programmed differently 
-                */
-                               
-               if(chan->is_multi)
-               {
-                       u8 c = 0;
-                       
-                       /*
-                        *      Load the type bit for num channels
-                        *      and 8/16bit
-                        */
-                        
-                       if(chan->pcm_fmt & VIA_PCM_FMT_16BIT)
-                               c = 1 << 7;
-                       if(chan->pcm_fmt & VIA_PCM_FMT_STEREO)
-                               c |= (2<<4);
-                       else
-                               c |= (1<<4);
-                               
-                       outb(c, chan->iobase + VIA_PCM_TYPE);
-                       
-                       /*
-                        *      Set the channel steering
-                        *      Mono
-                        *              Channel 0 to slot 3
-                        *              Channel 0 to slot 4
-                        *      Stereo
-                        *              Channel 0 to slot 3
-                        *              Channel 1 to slot 4
-                        */
-                        
-                       switch(chan->channels)
-                       {
-                               case 1:
-                                       outl(0xFF000000 | (1<<0) | (1<<4) , chan->iobase + VIA_PCM_STOPRATE);
-                                       break;
-                               case 2:
-                                       outl(0xFF000000 | (1<<0) | (2<<4) , chan->iobase + VIA_PCM_STOPRATE);
-                                       break;
-                               case 4:
-                                       outl(0xFF000000 | (1<<0) | (2<<4) | (3<<8) | (4<<12), chan->iobase + VIA_PCM_STOPRATE);
-                                       break;
-                               case 6:
-                                       outl(0xFF000000 | (1<<0) | (2<<4) | (5<<8) | (6<<12) | (3<<16) | (4<<20), chan->iobase + VIA_PCM_STOPRATE);
-                                       break;
-                       }                               
-               }
-               else
-               {
-                       /*
-                        *      New style, turn off channel volume
-                        *      control, set bits in the right register
-                        */     
-                       outb(0x0, chan->iobase + VIA_PCM_LEFTVOL);
-                       outb(0x0, chan->iobase + VIA_PCM_RIGHTVOL);
-
-                       m = inl(chan->iobase + VIA_PCM_STOPRATE);
-                       m &= ~(3<<20);
-                       if(chan->pcm_fmt & VIA_PCM_FMT_STEREO)
-                               m |= (1 << 20);
-                       if(chan->pcm_fmt & VIA_PCM_FMT_16BIT)
-                               m |= (1 << 21);
-                       outl(m, chan->iobase + VIA_PCM_STOPRATE);
-               }               
-       }
-       else
-               outb (chan->pcm_fmt, chan->iobase + VIA_PCM_TYPE);
-
-
-       DPRINTK ("EXIT, pcm_fmt = 0x%02X, reg = 0x%02X\n",
-                chan->pcm_fmt,
-                inb (chan->iobase + VIA_PCM_TYPE));
-}
-
-
-/**
- *     via_chan_clear - Stop DMA channel operation, and reset pointers
- *     @card: the chip to accessed
- *     @chan: Channel to be cleared
- *
- *     Call via_chan_stop to halt DMA operations, and then resets
- *     all software pointers which track DMA operation.
- */
-
-static void via_chan_clear (struct via_info *card, struct via_channel *chan)
-{
-       DPRINTK ("ENTER\n");
-       via_chan_stop (chan->iobase);
-       via_chan_buffer_free(card, chan);
-       chan->is_active = 0;
-       chan->is_mapped = 0;
-       chan->is_enabled = 1;
-       chan->slop_len = 0;
-       chan->sw_ptr = 0;
-       chan->n_irqs = 0;
-       atomic_set (&chan->hw_ptr, 0);
-       DPRINTK ("EXIT\n");
-}
-
-
-/**
- *     via_chan_set_speed - Set PCM sample rate for given channel
- *     @card: Private info for specified board
- *     @chan: Channel whose sample rate will be adjusted
- *     @val: New sample rate, in Khz
- *
- *     Helper function for the %SNDCTL_DSP_SPEED ioctl.  OSS semantics
- *     demand that all audio operations halt (if they are not already
- *     halted) when the %SNDCTL_DSP_SPEED is given.
- *
- *     This function halts all audio operations for the given channel
- *     @chan, and then calls via_set_rate to set the audio hardware
- *     to the new rate.
- */
-
-static int via_chan_set_speed (struct via_info *card,
-                              struct via_channel *chan, int val)
-{
-       DPRINTK ("ENTER, requested rate = %d\n", val);
-
-       via_chan_clear (card, chan);
-
-       val = via_set_rate (card->ac97, chan, val);
-
-       DPRINTK ("EXIT, returning %d\n", val);
-       return val;
-}
-
-
-/**
- *     via_chan_set_fmt - Set PCM sample size for given channel
- *     @card: Private info for specified board
- *     @chan: Channel whose sample size will be adjusted
- *     @val: New sample size, use the %AFMT_xxx constants
- *
- *     Helper function for the %SNDCTL_DSP_SETFMT ioctl.  OSS semantics
- *     demand that all audio operations halt (if they are not already
- *     halted) when the %SNDCTL_DSP_SETFMT is given.
- *
- *     This function halts all audio operations for the given channel
- *     @chan, and then calls via_chan_pcm_fmt to set the audio hardware
- *     to the new sample size, either 8-bit or 16-bit.
- */
-
-static int via_chan_set_fmt (struct via_info *card,
-                            struct via_channel *chan, int val)
-{
-       DPRINTK ("ENTER, val=%s\n",
-                val == AFMT_U8 ? "AFMT_U8" :
-                val == AFMT_S16_LE ? "AFMT_S16_LE" :
-                "unknown");
-
-       via_chan_clear (card, chan);
-
-       assert (val != AFMT_QUERY); /* this case is handled elsewhere */
-
-       switch (val) {
-       case AFMT_S16_LE:
-               if ((chan->pcm_fmt & VIA_PCM_FMT_16BIT) == 0) {
-                       chan->pcm_fmt |= VIA_PCM_FMT_16BIT;
-                       via_chan_pcm_fmt (chan, 0);
-               }
-               break;
-
-       case AFMT_U8:
-               if (chan->pcm_fmt & VIA_PCM_FMT_16BIT) {
-                       chan->pcm_fmt &= ~VIA_PCM_FMT_16BIT;
-                       via_chan_pcm_fmt (chan, 0);
-               }
-               break;
-
-       default:
-               DPRINTK ("unknown AFMT: 0x%X\n", val);
-               val = AFMT_S16_LE;
-       }
-
-       DPRINTK ("EXIT\n");
-       return val;
-}
-
-
-/**
- *     via_chan_set_stereo - Enable or disable stereo for a DMA channel
- *     @card: Private info for specified board
- *     @chan: Channel whose stereo setting will be adjusted
- *     @val: New sample size, use the %AFMT_xxx constants
- *
- *     Helper function for the %SNDCTL_DSP_CHANNELS and %SNDCTL_DSP_STEREO ioctls.  OSS semantics
- *     demand that all audio operations halt (if they are not already
- *     halted) when %SNDCTL_DSP_CHANNELS or SNDCTL_DSP_STEREO is given.
- *
- *     This function halts all audio operations for the given channel
- *     @chan, and then calls via_chan_pcm_fmt to set the audio hardware
- *     to enable or disable stereo.
- */
-
-static int via_chan_set_stereo (struct via_info *card,
-                               struct via_channel *chan, int val)
-{
-       DPRINTK ("ENTER, channels = %d\n", val);
-
-       via_chan_clear (card, chan);
-
-       switch (val) {
-
-       /* mono */
-       case 1:
-               chan->pcm_fmt &= ~VIA_PCM_FMT_STEREO;
-               chan->channels = 1;
-               via_chan_pcm_fmt (chan, 0);
-               break;
-
-       /* stereo */
-       case 2:
-               chan->pcm_fmt |= VIA_PCM_FMT_STEREO;
-               chan->channels = 2;
-               via_chan_pcm_fmt (chan, 0);
-               break;
-
-       case 4:
-       case 6:
-               if(chan->is_multi)
-               {
-                       chan->pcm_fmt |= VIA_PCM_FMT_STEREO;
-                       chan->channels = val;
-                       break;
-               }
-       /* unknown */
-       default:
-               val = -EINVAL;
-               break;
-       }
-
-       DPRINTK ("EXIT, returning %d\n", val);
-       return val;
-}
-
-static int via_chan_set_buffering (struct via_info *card,
-                                struct via_channel *chan, int val)
-{
-       int shift;
-
-        DPRINTK ("ENTER\n");
-
-       /* in both cases the buffer cannot be changed */
-       if (chan->is_active || chan->is_mapped) {
-               DPRINTK ("EXIT\n");
-               return -EINVAL;
-       }
-
-       /* called outside SETFRAGMENT */
-       /* set defaults or do nothing */
-       if (val < 0) {
-
-               if (chan->frag_size && chan->frag_number)
-                       goto out;
-
-               DPRINTK ("\n");
-
-               chan->frag_size = (VIA_DEFAULT_FRAG_TIME * chan->rate * chan->channels
-                                  * ((chan->pcm_fmt & VIA_PCM_FMT_16BIT) ? 2 : 1)) / 1000 - 1;
-
-               shift = 0;
-               while (chan->frag_size) {
-                       chan->frag_size >>= 1;
-                       shift++;
-               }
-               chan->frag_size = 1 << shift;
-
-               chan->frag_number = (VIA_DEFAULT_BUFFER_TIME / VIA_DEFAULT_FRAG_TIME);
-
-               DPRINTK ("setting default values %d %d\n", chan->frag_size, chan->frag_number);
-       } else {
-               chan->frag_size = 1 << (val & 0xFFFF);
-               chan->frag_number = (val >> 16) & 0xFFFF;
-
-               DPRINTK ("using user values %d %d\n", chan->frag_size, chan->frag_number);
-       }
-
-       /* quake3 wants frag_number to be a power of two */
-       shift = 0;
-       while (chan->frag_number) {
-               chan->frag_number >>= 1;
-               shift++;
-       }
-       chan->frag_number = 1 << shift;
-
-       if (chan->frag_size > VIA_MAX_FRAG_SIZE)
-               chan->frag_size = VIA_MAX_FRAG_SIZE;
-       else if (chan->frag_size < VIA_MIN_FRAG_SIZE)
-               chan->frag_size = VIA_MIN_FRAG_SIZE;
-
-       if (chan->frag_number < VIA_MIN_FRAG_NUMBER)
-                chan->frag_number = VIA_MIN_FRAG_NUMBER;
-        if (chan->frag_number > VIA_MAX_FRAG_NUMBER)
-               chan->frag_number = VIA_MAX_FRAG_NUMBER;
-
-       if ((chan->frag_number * chan->frag_size) / PAGE_SIZE > VIA_MAX_BUFFER_DMA_PAGES)
-               chan->frag_number = (VIA_MAX_BUFFER_DMA_PAGES * PAGE_SIZE) / chan->frag_size;
-
-out:
-       if (chan->is_record)
-               atomic_set (&chan->n_frags, 0);
-       else
-               atomic_set (&chan->n_frags, chan->frag_number);
-
-       DPRINTK ("EXIT\n");
-
-       return 0;
-}
-
-#ifdef VIA_CHAN_DUMP_BUFS
-/**
- *     via_chan_dump_bufs - Display DMA table contents
- *     @chan: Channel whose DMA table will be displayed
- *
- *     Debugging function which displays the contents of the
- *     scatter-gather DMA table for the given channel @chan.
- */
-
-static void via_chan_dump_bufs (struct via_channel *chan)
-{
-       int i;
-
-       for (i = 0; i < chan->frag_number; i++) {
-               DPRINTK ("#%02d: addr=%x, count=%u, flag=%d, eol=%d\n",
-                        i, chan->sgtable[i].addr,
-                        chan->sgtable[i].count & 0x00FFFFFF,
-                        chan->sgtable[i].count & VIA_FLAG ? 1 : 0,
-                        chan->sgtable[i].count & VIA_EOL ? 1 : 0);
-       }
-       DPRINTK ("buf_in_use = %d, nextbuf = %d\n",
-                atomic_read (&chan->buf_in_use),
-                atomic_read (&chan->sw_ptr));
-}
-#endif /* VIA_CHAN_DUMP_BUFS */
-
-
-/**
- *     via_chan_flush_frag - Flush partially-full playback buffer to hardware
- *     @chan: Channel whose DMA table will be flushed
- *
- *     Flushes partially-full playback buffer to hardware.
- */
-
-static void via_chan_flush_frag (struct via_channel *chan)
-{
-       DPRINTK ("ENTER\n");
-
-       assert (chan->slop_len > 0);
-
-       if (chan->sw_ptr == (chan->frag_number - 1))
-               chan->sw_ptr = 0;
-       else
-               chan->sw_ptr++;
-
-       chan->slop_len = 0;
-
-       assert (atomic_read (&chan->n_frags) > 0);
-       atomic_dec (&chan->n_frags);
-
-       DPRINTK ("EXIT\n");
-}
-
-
-
-/**
- *     via_chan_maybe_start - Initiate audio hardware DMA operation
- *     @chan: Channel whose DMA is to be started
- *
- *     Initiate DMA operation, if the DMA engine for the given
- *     channel @chan is not already active.
- */
-
-static inline void via_chan_maybe_start (struct via_channel *chan)
-{
-       assert (chan->is_active == sg_active(chan->iobase));
-
-       DPRINTK ("MAYBE START %s\n", chan->name);
-       if (!chan->is_active && chan->is_enabled) {
-               chan->is_active = 1;
-               sg_begin (chan);
-               DPRINTK ("starting channel %s\n", chan->name);
-       }
-}
-
-
-/****************************************************************
- *
- * Interface to ac97-codec module
- *
- *
- */
-
-/**
- *     via_ac97_wait_idle - Wait until AC97 codec is not busy
- *     @card: Private info for specified board
- *
- *     Sleep until the AC97 codec is no longer busy.
- *     Returns the final value read from the SGD
- *     register being polled.
- */
-
-static u8 via_ac97_wait_idle (struct via_info *card)
-{
-       u8 tmp8;
-       int counter = VIA_COUNTER_LIMIT;
-
-       DPRINTK ("ENTER/EXIT\n");
-
-       assert (card != NULL);
-       assert (card->pdev != NULL);
-
-       do {
-               udelay (15);
-
-               tmp8 = inb (card->baseaddr + 0x83);
-       } while ((tmp8 & VIA_CR83_BUSY) && (counter-- > 0));
-
-       if (tmp8 & VIA_CR83_BUSY)
-               printk (KERN_WARNING PFX "timeout waiting on AC97 codec\n");
-       return tmp8;
-}
-
-
-/**
- *     via_ac97_read_reg - Read AC97 standard register
- *     @codec: Pointer to generic AC97 codec info
- *     @reg: Index of AC97 register to be read
- *
- *     Read the value of a single AC97 codec register,
- *     as defined by the Intel AC97 specification.
- *
- *     Defines the standard AC97 read-register operation
- *     required by the kernel's ac97_codec interface.
- *
- *     Returns the 16-bit value stored in the specified
- *     register.
- */
-
-static u16 via_ac97_read_reg (struct ac97_codec *codec, u8 reg)
-{
-       unsigned long data;
-       struct via_info *card;
-       int counter;
-
-       DPRINTK ("ENTER\n");
-
-       assert (codec != NULL);
-       assert (codec->private_data != NULL);
-
-       card = codec->private_data;
-       
-       spin_lock(&card->ac97_lock);
-
-       /* Every time we write to register 80 we cause a transaction.
-          The only safe way to clear the valid bit is to write it at
-          the same time as the command */
-       data = (reg << 16) | VIA_CR80_READ | VIA_CR80_VALID;
-
-       outl (data, card->baseaddr + VIA_BASE0_AC97_CTRL);
-       udelay (20);
-
-       for (counter = VIA_COUNTER_LIMIT; counter > 0; counter--) {
-               udelay (1);
-               if ((((data = inl(card->baseaddr + VIA_BASE0_AC97_CTRL)) &
-                     (VIA_CR80_VALID|VIA_CR80_BUSY)) == VIA_CR80_VALID))
-                       goto out;
-       }
-
-       printk (KERN_WARNING PFX "timeout while reading AC97 codec (0x%lX)\n", data);
-       goto err_out;
-
-out:
-       /* Once the valid bit has become set, we must wait a complete AC97
-          frame before the data has settled. */
-       udelay(25);
-       data = (unsigned long) inl (card->baseaddr + VIA_BASE0_AC97_CTRL);
-
-       outb (0x02, card->baseaddr + 0x83);
-
-       if (((data & 0x007F0000) >> 16) == reg) {
-               DPRINTK ("EXIT, success, data=0x%lx, retval=0x%lx\n",
-                        data, data & 0x0000FFFF);
-               spin_unlock(&card->ac97_lock);
-               return data & 0x0000FFFF;
-       }
-
-       printk (KERN_WARNING "via82cxxx_audio: not our index: reg=0x%x, newreg=0x%lx\n",
-               reg, ((data & 0x007F0000) >> 16));
-
-err_out:
-       spin_unlock(&card->ac97_lock);
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-}
-
-
-/**
- *     via_ac97_write_reg - Write AC97 standard register
- *     @codec: Pointer to generic AC97 codec info
- *     @reg: Index of AC97 register to be written
- *     @value: Value to be written to AC97 register
- *
- *     Write the value of a single AC97 codec register,
- *     as defined by the Intel AC97 specification.
- *
- *     Defines the standard AC97 write-register operation
- *     required by the kernel's ac97_codec interface.
- */
-
-static void via_ac97_write_reg (struct ac97_codec *codec, u8 reg, u16 value)
-{
-       u32 data;
-       struct via_info *card;
-       int counter;
-
-       DPRINTK ("ENTER\n");
-
-       assert (codec != NULL);
-       assert (codec->private_data != NULL);
-
-       card = codec->private_data;
-
-       spin_lock(&card->ac97_lock);
-       
-       data = (reg << 16) + value;
-       outl (data, card->baseaddr + VIA_BASE0_AC97_CTRL);
-       udelay (10);
-
-       for (counter = VIA_COUNTER_LIMIT; counter > 0; counter--) {
-               if ((inb (card->baseaddr + 0x83) & VIA_CR83_BUSY) == 0)
-                       goto out;
-
-               udelay (15);
-       }
-
-       printk (KERN_WARNING PFX "timeout after AC97 codec write (0x%X, 0x%X)\n", reg, value);
-
-out:
-       spin_unlock(&card->ac97_lock);
-       DPRINTK ("EXIT\n");
-}
-
-
-static int via_mixer_open (struct inode *inode, struct file *file)
-{
-       int minor = iminor(inode);
-       struct via_info *card;
-       struct pci_dev *pdev = NULL;
-       struct pci_driver *drvr;
-
-       DPRINTK ("ENTER\n");
-
-       while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
-               drvr = pci_dev_driver (pdev);
-               if (drvr == &via_driver) {
-                       assert (pci_get_drvdata (pdev) != NULL);
-
-                       card = pci_get_drvdata (pdev);
-                       if (card->ac97->dev_mixer == minor)
-                               goto match;
-               }
-       }
-
-       DPRINTK ("EXIT, returning -ENODEV\n");
-       return -ENODEV;
-
-match:
-       pci_dev_put(pdev);
-       file->private_data = card->ac97;
-
-       DPRINTK ("EXIT, returning 0\n");
-       return nonseekable_open(inode, file);
-}
-
-static int via_mixer_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
-                           unsigned long arg)
-{
-       struct ac97_codec *codec = file->private_data;
-       struct via_info *card;
-       int nonblock = (file->f_flags & O_NONBLOCK);
-       int rc;
-
-       DPRINTK ("ENTER\n");
-
-       assert (codec != NULL);
-       card = codec->private_data;
-       assert (card != NULL);
-
-       rc = via_syscall_down (card, nonblock);
-       if (rc) goto out;
-       
-#if 0
-       /*
-        *      Intercept volume control on 8233 and 8235
-        */
-       if(card->volume)
-       {
-               switch(cmd)
-               {
-                       case SOUND_MIXER_READ_VOLUME:
-                               return card->mixer_vol;
-                       case SOUND_MIXER_WRITE_VOLUME:
-                       {
-                               int v;
-                               if(get_user(v, (int *)arg))
-                               {
-                                       rc = -EFAULT;
-                                       goto out;
-                               }
-                               card->mixer_vol = v;
-                       }
-               }
-       }               
-#endif
-       rc = codec->mixer_ioctl(codec, cmd, arg);
-
-       mutex_unlock(&card->syscall_mutex);
-
-out:
-       DPRINTK ("EXIT, returning %d\n", rc);
-       return rc;
-}
-
-
-static const struct file_operations via_mixer_fops = {
-       .owner          = THIS_MODULE,
-       .open           = via_mixer_open,
-       .llseek         = no_llseek,
-       .ioctl          = via_mixer_ioctl,
-};
-
-
-static int __devinit via_ac97_reset (struct via_info *card)
-{
-       struct pci_dev *pdev = card->pdev;
-       u8 tmp8;
-       u16 tmp16;
-
-       DPRINTK ("ENTER\n");
-
-       assert (pdev != NULL);
-
-#ifndef NDEBUG
-       {
-               u8 r40,r41,r42,r43,r44,r48;
-               pci_read_config_byte (card->pdev, 0x40, &r40);
-               pci_read_config_byte (card->pdev, 0x41, &r41);
-               pci_read_config_byte (card->pdev, 0x42, &r42);
-               pci_read_config_byte (card->pdev, 0x43, &r43);
-               pci_read_config_byte (card->pdev, 0x44, &r44);
-               pci_read_config_byte (card->pdev, 0x48, &r48);
-               DPRINTK ("PCI config: %02X %02X %02X %02X %02X %02X\n",
-                       r40,r41,r42,r43,r44,r48);
-
-               spin_lock_irq (&card->lock);
-               DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
-                        inb (card->baseaddr + 0x00),
-                        inb (card->baseaddr + 0x01),
-                        inb (card->baseaddr + 0x02),
-                        inl (card->baseaddr + 0x04),
-                        inl (card->baseaddr + 0x0C),
-                        inl (card->baseaddr + 0x80),
-                        inl (card->baseaddr + 0x84));
-               spin_unlock_irq (&card->lock);
-
-       }
-#endif
-
-        /*
-         * Reset AC97 controller: enable, disable, enable,
-         * pausing after each command for good luck.  Only
-        * do this if the codec is not ready, because it causes
-        * loud pops and such due to such a hard codec reset.
-         */
-       pci_read_config_byte (pdev, VIA_ACLINK_STATUS, &tmp8);
-       if ((tmp8 & VIA_CR40_AC97_READY) == 0) {
-               pci_write_config_byte (pdev, VIA_ACLINK_CTRL,
-                                      VIA_CR41_AC97_ENABLE |
-                                      VIA_CR41_AC97_RESET |
-                                      VIA_CR41_AC97_WAKEUP);
-               udelay (100);
-
-               pci_write_config_byte (pdev, VIA_ACLINK_CTRL, 0);
-               udelay (100);
-
-               pci_write_config_byte (pdev, VIA_ACLINK_CTRL,
-                                      VIA_CR41_AC97_ENABLE |
-                                      VIA_CR41_PCM_ENABLE |
-                                      VIA_CR41_VRA | VIA_CR41_AC97_RESET);
-               udelay (100);
-       }
-
-       /* Make sure VRA is enabled, in case we didn't do a
-        * complete codec reset, above
-        */
-       pci_read_config_byte (pdev, VIA_ACLINK_CTRL, &tmp8);
-       if (((tmp8 & VIA_CR41_VRA) == 0) ||
-           ((tmp8 & VIA_CR41_AC97_ENABLE) == 0) ||
-           ((tmp8 & VIA_CR41_PCM_ENABLE) == 0) ||
-           ((tmp8 & VIA_CR41_AC97_RESET) == 0)) {
-               pci_write_config_byte (pdev, VIA_ACLINK_CTRL,
-                                      VIA_CR41_AC97_ENABLE |
-                                      VIA_CR41_PCM_ENABLE |
-                                      VIA_CR41_VRA | VIA_CR41_AC97_RESET);
-               udelay (100);
-       }
-
-       if(card->legacy)
-       {
-#if 0 /* this breaks on K7M */
-               /* disable legacy stuff */
-               pci_write_config_byte (pdev, 0x42, 0x00);
-               udelay(10);
-#endif
-
-               /* route FM trap to IRQ, disable FM trap */
-               pci_write_config_byte (pdev, 0x48, 0x05);
-               udelay(10);
-       }
-       
-       /* disable all codec GPI interrupts */
-       outl (0, pci_resource_start (pdev, 0) + 0x8C);
-
-       /* WARNING: this line is magic.  Remove this
-        * and things break. */
-       /* enable variable rate */
-       tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
-       if ((tmp16 & 1) == 0)
-               via_ac97_write_reg (card->ac97, AC97_EXTENDED_STATUS, tmp16 | 1);
-
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-}
-
-
-static void via_ac97_codec_wait (struct ac97_codec *codec)
-{
-       assert (codec->private_data != NULL);
-       via_ac97_wait_idle (codec->private_data);
-}
-
-
-static int __devinit via_ac97_init (struct via_info *card)
-{
-       int rc;
-       u16 tmp16;
-
-       DPRINTK ("ENTER\n");
-
-       assert (card != NULL);
-
-       card->ac97 = ac97_alloc_codec();
-       if(card->ac97 == NULL)
-               return -ENOMEM;
-               
-       card->ac97->private_data = card;
-       card->ac97->codec_read = via_ac97_read_reg;
-       card->ac97->codec_write = via_ac97_write_reg;
-       card->ac97->codec_wait = via_ac97_codec_wait;
-
-       card->ac97->dev_mixer = register_sound_mixer (&via_mixer_fops, -1);
-       if (card->ac97->dev_mixer < 0) {
-               printk (KERN_ERR PFX "unable to register AC97 mixer, aborting\n");
-               DPRINTK ("EXIT, returning -EIO\n");
-               ac97_release_codec(card->ac97);
-               return -EIO;
-       }
-
-       rc = via_ac97_reset (card);
-       if (rc) {
-               printk (KERN_ERR PFX "unable to reset AC97 codec, aborting\n");
-               goto err_out;
-       }
-       
-       mdelay(10);
-       
-       if (ac97_probe_codec (card->ac97) == 0) {
-               printk (KERN_ERR PFX "unable to probe AC97 codec, aborting\n");
-               rc = -EIO;
-               goto err_out;
-       }
-
-       /* enable variable rate */
-       tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
-       via_ac97_write_reg (card->ac97, AC97_EXTENDED_STATUS, tmp16 | 1);
-
-       /*
-        * If we cannot enable VRA, we have a locked-rate codec.
-        * We try again to enable VRA before assuming so, however.
-        */
-       tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
-       if ((tmp16 & 1) == 0) {
-               via_ac97_write_reg (card->ac97, AC97_EXTENDED_STATUS, tmp16 | 1);
-               tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
-               if ((tmp16 & 1) == 0) {
-                       card->locked_rate = 1;
-                       printk (KERN_WARNING PFX "Codec rate locked at 48Khz\n");
-               }
-       }
-
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-
-err_out:
-       unregister_sound_mixer (card->ac97->dev_mixer);
-       DPRINTK ("EXIT, returning %d\n", rc);
-       ac97_release_codec(card->ac97);
-       return rc;
-}
-
-
-static void via_ac97_cleanup (struct via_info *card)
-{
-       DPRINTK ("ENTER\n");
-
-       assert (card != NULL);
-       assert (card->ac97->dev_mixer >= 0);
-
-       unregister_sound_mixer (card->ac97->dev_mixer);
-       ac97_release_codec(card->ac97);
-
-       DPRINTK ("EXIT\n");
-}
-
-
-
-/****************************************************************
- *
- * Interrupt-related code
- *
- */
-
-/**
- *     via_intr_channel - handle an interrupt for a single channel
- *      @card: unused
- *     @chan: handle interrupt for this channel
- *
- *     This is the "meat" of the interrupt handler,
- *     containing the actions taken each time an interrupt
- *     occurs.  All communication and coordination with
- *     userspace takes place here.
- *
- *     Locking: inside card->lock
- */
-
-static void via_intr_channel (struct via_info *card, struct via_channel *chan)
-{
-       u8 status;
-       int n;
-       
-       /* check pertinent bits of status register for action bits */
-       status = inb (chan->iobase) & (VIA_SGD_FLAG | VIA_SGD_EOL | VIA_SGD_STOPPED);
-       if (!status)
-               return;
-
-       /* acknowledge any flagged bits ASAP */
-       outb (status, chan->iobase);
-
-       if (!chan->sgtable) /* XXX: temporary solution */
-               return;
-
-       /* grab current h/w ptr value */
-       n = atomic_read (&chan->hw_ptr);
-
-       /* sanity check: make sure our h/w ptr doesn't have a weird value */
-       assert (n >= 0);
-       assert (n < chan->frag_number);
-
-       
-       /* reset SGD data structure in memory to reflect a full buffer,
-        * and advance the h/w ptr, wrapping around to zero if needed
-        */
-       if (n == (chan->frag_number - 1)) {
-               chan->sgtable[n].count = cpu_to_le32(chan->frag_size | VIA_EOL);
-               atomic_set (&chan->hw_ptr, 0);
-       } else {
-               chan->sgtable[n].count = cpu_to_le32(chan->frag_size | VIA_FLAG);
-               atomic_inc (&chan->hw_ptr);
-       }
-
-       /* accounting crap for SNDCTL_DSP_GETxPTR */
-       chan->n_irqs++;
-       chan->bytes += chan->frag_size;
-       /* FIXME - signed overflow is undefined */
-       if (chan->bytes < 0) /* handle overflow of 31-bit value */
-               chan->bytes = chan->frag_size;
-       /* all following checks only occur when not in mmap(2) mode */
-       if (!chan->is_mapped)
-       {
-               /* If we are recording, then n_frags represents the number
-                * of fragments waiting to be handled by userspace.
-                * If we are playback, then n_frags represents the number
-                * of fragments remaining to be filled by userspace.
-                * We increment here.  If we reach max number of fragments,
-                * this indicates an underrun/overrun.  For this case under OSS,
-                * we stop the record/playback process.
-                */
-               if (atomic_read (&chan->n_frags) < chan->frag_number)
-                       atomic_inc (&chan->n_frags);
-               assert (atomic_read (&chan->n_frags) <= chan->frag_number);
-               if (atomic_read (&chan->n_frags) == chan->frag_number) {
-                       chan->is_active = 0;
-                       via_chan_stop (chan->iobase);
-               }
-       }
-       /* wake up anyone listening to see when interrupts occur */
-       wake_up_all (&chan->wait);
-
-       DPRINTK ("%s intr, status=0x%02X, hwptr=0x%lX, chan->hw_ptr=%d\n",
-                chan->name, status, (long) inl (chan->iobase + 0x04),
-                atomic_read (&chan->hw_ptr));
-
-       DPRINTK ("%s intr, channel n_frags == %d, missed %d\n", chan->name,
-                atomic_read (&chan->n_frags), missed);
-}
-
-
-static irqreturn_t  via_interrupt(int irq, void *dev_id)
-{
-       struct via_info *card = dev_id;
-       u32 status32;
-
-       /* to minimize interrupt sharing costs, we use the SGD status
-        * shadow register to check the status of all inputs and
-        * outputs with a single 32-bit bus read.  If no interrupt
-        * conditions are flagged, we exit immediately
-        */
-       status32 = inl (card->baseaddr + VIA_BASE0_SGD_STATUS_SHADOW);
-       if (!(status32 & VIA_INTR_MASK))
-        {
-#ifdef CONFIG_MIDI_VIA82CXXX
-                if (card->midi_devc)
-                       uart401intr(irq, card->midi_devc);
-#endif
-               return IRQ_HANDLED;
-       }
-       DPRINTK ("intr, status32 == 0x%08X\n", status32);
-
-       /* synchronize interrupt handling under SMP.  this spinlock
-        * goes away completely on UP
-        */
-       spin_lock (&card->lock);
-
-       if (status32 & VIA_INTR_OUT)
-               via_intr_channel (card, &card->ch_out);
-       if (status32 & VIA_INTR_IN)
-               via_intr_channel (card, &card->ch_in);
-       if (status32 & VIA_INTR_FM)
-               via_intr_channel (card, &card->ch_fm);
-
-       spin_unlock (&card->lock);
-       
-       return IRQ_HANDLED;
-}
-
-static irqreturn_t via_new_interrupt(int irq, void *dev_id)
-{
-       struct via_info *card = dev_id;
-       u32 status32;
-
-       /* to minimize interrupt sharing costs, we use the SGD status
-        * shadow register to check the status of all inputs and
-        * outputs with a single 32-bit bus read.  If no interrupt
-        * conditions are flagged, we exit immediately
-        */
-       status32 = inl (card->baseaddr + VIA_BASE0_SGD_STATUS_SHADOW);
-       if (!(status32 & VIA_NEW_INTR_MASK))
-               return IRQ_NONE;
-       /*
-        * goes away completely on UP
-        */
-       spin_lock (&card->lock);
-
-       via_intr_channel (card, &card->ch_out);
-       via_intr_channel (card, &card->ch_in);
-       via_intr_channel (card, &card->ch_fm);
-
-       spin_unlock (&card->lock);
-       return IRQ_HANDLED;
-}
-
-
-/**
- *     via_interrupt_init - Initialize interrupt handling
- *     @card: Private info for specified board
- *
- *     Obtain and reserve IRQ for using in handling audio events.
- *     Also, disable any IRQ-generating resources, to make sure
- *     we don't get interrupts before we want them.
- */
-
-static int via_interrupt_init (struct via_info *card)
-{
-       u8 tmp8;
-
-       DPRINTK ("ENTER\n");
-
-       assert (card != NULL);
-       assert (card->pdev != NULL);
-
-       /* check for sane IRQ number. can this ever happen? */
-       if (card->pdev->irq < 2) {
-               printk (KERN_ERR PFX "insane IRQ %d, aborting\n",
-                       card->pdev->irq);
-               DPRINTK ("EXIT, returning -EIO\n");
-               return -EIO;
-       }
-
-       /* VIA requires this is done */
-       pci_write_config_byte(card->pdev, PCI_INTERRUPT_LINE, card->pdev->irq);
-       
-       if(card->legacy)
-       {
-               /* make sure FM irq is not routed to us */
-               pci_read_config_byte (card->pdev, VIA_FM_NMI_CTRL, &tmp8);
-               if ((tmp8 & VIA_CR48_FM_TRAP_TO_NMI) == 0) {
-                       tmp8 |= VIA_CR48_FM_TRAP_TO_NMI;
-                       pci_write_config_byte (card->pdev, VIA_FM_NMI_CTRL, tmp8);
-               }
-               if (request_irq (card->pdev->irq, via_interrupt, IRQF_SHARED, VIA_MODULE_NAME, card)) {
-                       printk (KERN_ERR PFX "unable to obtain IRQ %d, aborting\n",
-                               card->pdev->irq);
-                       DPRINTK ("EXIT, returning -EBUSY\n");
-                       return -EBUSY;
-               }
-       }
-       else 
-       {
-               if (request_irq (card->pdev->irq, via_new_interrupt, IRQF_SHARED, VIA_MODULE_NAME, card)) {
-                       printk (KERN_ERR PFX "unable to obtain IRQ %d, aborting\n",
-                               card->pdev->irq);
-                       DPRINTK ("EXIT, returning -EBUSY\n");
-                       return -EBUSY;
-               }
-       }
-
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-}
-
-
-/****************************************************************
- *
- * OSS DSP device
- *
- */
-
-static const struct file_operations via_dsp_fops = {
-       .owner          = THIS_MODULE,
-       .open           = via_dsp_open,
-       .release        = via_dsp_release,
-       .read           = via_dsp_read,
-       .write          = via_dsp_write,
-       .poll           = via_dsp_poll,
-       .llseek         = no_llseek,
-       .ioctl          = via_dsp_ioctl,
-       .mmap           = via_dsp_mmap,
-};
-
-
-static int __devinit via_dsp_init (struct via_info *card)
-{
-       u8 tmp8;
-
-       DPRINTK ("ENTER\n");
-
-       assert (card != NULL);
-
-       if(card->legacy)
-       {
-               /* turn off legacy features, if not already */
-               pci_read_config_byte (card->pdev, VIA_FUNC_ENABLE, &tmp8);
-               if (tmp8 & (VIA_CR42_SB_ENABLE |  VIA_CR42_FM_ENABLE)) {
-                       tmp8 &= ~(VIA_CR42_SB_ENABLE | VIA_CR42_FM_ENABLE);
-                       pci_write_config_byte (card->pdev, VIA_FUNC_ENABLE, tmp8);
-               }
-       }
-
-       via_stop_everything (card);
-
-       card->dev_dsp = register_sound_dsp (&via_dsp_fops, -1);
-       if (card->dev_dsp < 0) {
-               DPRINTK ("EXIT, returning -ENODEV\n");
-               return -ENODEV;
-       }
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-}
-
-
-static void via_dsp_cleanup (struct via_info *card)
-{
-       DPRINTK ("ENTER\n");
-
-       assert (card != NULL);
-       assert (card->dev_dsp >= 0);
-
-       via_stop_everything (card);
-
-       unregister_sound_dsp (card->dev_dsp);
-
-       DPRINTK ("EXIT\n");
-}
-
-
-static struct page * via_mm_nopage (struct vm_area_struct * vma,
-                                   unsigned long address, int *type)
-{
-       struct via_info *card = vma->vm_private_data;
-       struct via_channel *chan = &card->ch_out;
-       struct page *dmapage;
-       unsigned long pgoff;
-       int rd, wr;
-
-       DPRINTK ("ENTER, start %lXh, ofs %lXh, pgoff %ld, addr %lXh\n",
-                vma->vm_start,
-                address - vma->vm_start,
-                (address - vma->vm_start) >> PAGE_SHIFT,
-                address);
-
-        if (address > vma->vm_end) {
-               DPRINTK ("EXIT, returning NOPAGE_SIGBUS\n");
-               return NOPAGE_SIGBUS; /* Disallow mremap */
-       }
-        if (!card) {
-               DPRINTK ("EXIT, returning NOPAGE_SIGBUS\n");
-               return NOPAGE_SIGBUS;   /* Nothing allocated */
-       }
-
-       pgoff = vma->vm_pgoff + ((address - vma->vm_start) >> PAGE_SHIFT);
-       rd = card->ch_in.is_mapped;
-       wr = card->ch_out.is_mapped;
-
-#ifndef VIA_NDEBUG
-       {
-       unsigned long max_bufs = chan->frag_number;
-       if (rd && wr) max_bufs *= 2;
-       /* via_dsp_mmap() should ensure this */
-       assert (pgoff < max_bufs);
-       }
-#endif
-
-       /* if full-duplex (read+write) and we have two sets of bufs,
-        * then the playback buffers come first, sez soundcard.c */
-       if (pgoff >= chan->page_number) {
-               pgoff -= chan->page_number;
-               chan = &card->ch_in;
-       } else if (!wr)
-               chan = &card->ch_in;
-
-       assert ((((unsigned long)chan->pgtbl[pgoff].cpuaddr) % PAGE_SIZE) == 0);
-
-       dmapage = virt_to_page (chan->pgtbl[pgoff].cpuaddr);
-       DPRINTK ("EXIT, returning page %p for cpuaddr %lXh\n",
-                dmapage, (unsigned long) chan->pgtbl[pgoff].cpuaddr);
-       get_page (dmapage);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return dmapage;
-}
-
-
-#ifndef VM_RESERVED
-static int via_mm_swapout (struct page *page, struct file *filp)
-{
-       return 0;
-}
-#endif /* VM_RESERVED */
-
-
-static struct vm_operations_struct via_mm_ops = {
-       .nopage         = via_mm_nopage,
-
-#ifndef VM_RESERVED
-       .swapout        = via_mm_swapout,
-#endif
-};
-
-
-static int via_dsp_mmap(struct file *file, struct vm_area_struct *vma)
-{
-       struct via_info *card;
-       int nonblock = (file->f_flags & O_NONBLOCK);
-       int rc = -EINVAL, rd=0, wr=0;
-       unsigned long max_size, size, start, offset;
-
-       assert (file != NULL);
-       assert (vma != NULL);
-       card = file->private_data;
-       assert (card != NULL);
-
-       DPRINTK ("ENTER, start %lXh, size %ld, pgoff %ld\n",
-                vma->vm_start,
-                vma->vm_end - vma->vm_start,
-                vma->vm_pgoff);
-
-       max_size = 0;
-       if (vma->vm_flags & VM_READ) {
-               rd = 1;
-               via_chan_set_buffering(card, &card->ch_in, -1);
-               via_chan_buffer_init (card, &card->ch_in);
-               max_size += card->ch_in.page_number << PAGE_SHIFT;
-       }
-       if (vma->vm_flags & VM_WRITE) {
-               wr = 1;
-               via_chan_set_buffering(card, &card->ch_out, -1);
-               via_chan_buffer_init (card, &card->ch_out);
-               max_size += card->ch_out.page_number << PAGE_SHIFT;
-       }
-
-       start = vma->vm_start;
-       offset = (vma->vm_pgoff << PAGE_SHIFT);
-       size = vma->vm_end - vma->vm_start;
-
-       /* some basic size/offset sanity checks */
-       if (size > max_size)
-               goto out;
-       if (offset > max_size - size)
-               goto out;
-
-       rc = via_syscall_down (card, nonblock);
-       if (rc) goto out;
-
-       vma->vm_ops = &via_mm_ops;
-       vma->vm_private_data = card;
-
-#ifdef VM_RESERVED
-       vma->vm_flags |= VM_RESERVED;
-#endif
-
-       if (rd)
-               card->ch_in.is_mapped = 1;
-       if (wr)
-               card->ch_out.is_mapped = 1;
-
-       mutex_unlock(&card->syscall_mutex);
-       rc = 0;
-
-out:
-       DPRINTK ("EXIT, returning %d\n", rc);
-       return rc;
-}
-
-
-static ssize_t via_dsp_do_read (struct via_info *card,
-                               char __user *userbuf, size_t count,
-                               int nonblock)
-{
-        DECLARE_WAITQUEUE(wait, current);
-       const char __user *orig_userbuf = userbuf;
-       struct via_channel *chan = &card->ch_in;
-       size_t size;
-       int n, tmp;
-       ssize_t ret = 0;
-
-       /* if SGD has not yet been started, start it */
-       via_chan_maybe_start (chan);
-
-handle_one_block:
-       /* just to be a nice neighbor */
-       /* Thomas Sailer:
-        * But also to ourselves, release semaphore if we do so */
-       if (need_resched()) {
-               mutex_unlock(&card->syscall_mutex);
-               schedule ();
-               ret = via_syscall_down (card, nonblock);
-               if (ret)
-                       goto out;
-       }
-
-       /* grab current channel software pointer.  In the case of
-        * recording, this is pointing to the next buffer that
-        * will receive data from the audio hardware.
-        */
-       n = chan->sw_ptr;
-
-       /* n_frags represents the number of fragments waiting
-        * to be copied to userland.  sleep until at least
-        * one buffer has been read from the audio hardware.
-        */
-       add_wait_queue(&chan->wait, &wait);
-       for (;;) {
-               __set_current_state(TASK_INTERRUPTIBLE);
-               tmp = atomic_read (&chan->n_frags);
-               assert (tmp >= 0);
-               assert (tmp <= chan->frag_number);
-               if (tmp)
-                       break;
-               if (nonblock || !chan->is_active) {
-                       ret = -EAGAIN;
-                       break;
-               }
-
-               mutex_unlock(&card->syscall_mutex);
-
-               DPRINTK ("Sleeping on block %d\n", n);
-               schedule();
-
-               ret = via_syscall_down (card, nonblock);
-               if (ret)
-                       break;
-
-               if (signal_pending (current)) {
-                       ret = -ERESTARTSYS;
-                       break;
-               }
-       }
-       set_current_state(TASK_RUNNING);
-       remove_wait_queue(&chan->wait, &wait);
-       if (ret)
-               goto out;
-
-       /* Now that we have a buffer we can read from, send
-        * as much as sample data possible to userspace.
-        */
-       while ((count > 0) && (chan->slop_len < chan->frag_size)) {
-               size_t slop_left = chan->frag_size - chan->slop_len;
-               void *base = chan->pgtbl[n / (PAGE_SIZE / chan->frag_size)].cpuaddr;
-               unsigned ofs = (n % (PAGE_SIZE / chan->frag_size)) * chan->frag_size;
-
-               size = (count < slop_left) ? count : slop_left;
-               if (copy_to_user (userbuf,
-                                 base + ofs + chan->slop_len,
-                                 size)) {
-                       ret = -EFAULT;
-                       goto out;
-               }
-
-               count -= size;
-               chan->slop_len += size;
-               userbuf += size;
-       }
-
-       /* If we didn't copy the buffer completely to userspace,
-        * stop now.
-        */
-       if (chan->slop_len < chan->frag_size)
-               goto out;
-
-       /*
-        * If we get to this point, we copied one buffer completely
-        * to userspace, give the buffer back to the hardware.
-        */
-
-       /* advance channel software pointer to point to
-        * the next buffer from which we will copy
-        */
-       if (chan->sw_ptr == (chan->frag_number - 1))
-               chan->sw_ptr = 0;
-       else
-               chan->sw_ptr++;
-
-       /* mark one less buffer waiting to be processed */
-       assert (atomic_read (&chan->n_frags) > 0);
-       atomic_dec (&chan->n_frags);
-
-       /* we are at a block boundary, there is no fragment data */
-       chan->slop_len = 0;
-
-       DPRINTK ("Flushed block %u, sw_ptr now %u, n_frags now %d\n",
-               n, chan->sw_ptr, atomic_read (&chan->n_frags));
-
-       DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
-                inb (card->baseaddr + 0x00),
-                inb (card->baseaddr + 0x01),
-                inb (card->baseaddr + 0x02),
-                inl (card->baseaddr + 0x04),
-                inl (card->baseaddr + 0x0C),
-                inl (card->baseaddr + 0x80),
-                inl (card->baseaddr + 0x84));
-
-       if (count > 0)
-               goto handle_one_block;
-
-out:
-       return (userbuf != orig_userbuf) ? (userbuf - orig_userbuf) : ret;
-}
-
-
-static ssize_t via_dsp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
-{
-       struct via_info *card;
-       int nonblock = (file->f_flags & O_NONBLOCK);
-       int rc;
-
-       DPRINTK ("ENTER, file=%p, buffer=%p, count=%u, ppos=%lu\n",
-                file, buffer, count, ppos ? ((unsigned long)*ppos) : 0);
-
-       assert (file != NULL);
-       card = file->private_data;
-       assert (card != NULL);
-
-       rc = via_syscall_down (card, nonblock);
-       if (rc) goto out;
-
-       if (card->ch_in.is_mapped) {
-               rc = -ENXIO;
-               goto out_up;
-       }
-
-       via_chan_set_buffering(card, &card->ch_in, -1);
-        rc = via_chan_buffer_init (card, &card->ch_in);
-
-       if (rc)
-               goto out_up;
-
-       rc = via_dsp_do_read (card, buffer, count, nonblock);
-
-out_up:
-       mutex_unlock(&card->syscall_mutex);
-out:
-       DPRINTK ("EXIT, returning %ld\n",(long) rc);
-       return rc;
-}
-
-
-static ssize_t via_dsp_do_write (struct via_info *card,
-                                const char __user *userbuf, size_t count,
-                                int nonblock)
-{
-        DECLARE_WAITQUEUE(wait, current);
-       const char __user *orig_userbuf = userbuf;
-       struct via_channel *chan = &card->ch_out;
-       volatile struct via_sgd_table *sgtable = chan->sgtable;
-       size_t size;
-       int n, tmp;
-       ssize_t ret = 0;
-
-handle_one_block:
-       /* just to be a nice neighbor */
-       /* Thomas Sailer:
-        * But also to ourselves, release semaphore if we do so */
-       if (need_resched()) {
-               mutex_unlock(&card->syscall_mutex);
-               schedule ();
-               ret = via_syscall_down (card, nonblock);
-               if (ret)
-                       goto out;
-       }
-
-       /* grab current channel fragment pointer.  In the case of
-        * playback, this is pointing to the next fragment that
-        * should receive data from userland.
-        */
-       n = chan->sw_ptr;
-
-       /* n_frags represents the number of fragments remaining
-        * to be filled by userspace.  Sleep until
-        * at least one fragment is available for our use.
-        */
-       add_wait_queue(&chan->wait, &wait);
-       for (;;) {
-               __set_current_state(TASK_INTERRUPTIBLE);
-               tmp = atomic_read (&chan->n_frags);
-               assert (tmp >= 0);
-               assert (tmp <= chan->frag_number);
-               if (tmp)
-                       break;
-               if (nonblock || !chan->is_active) {
-                       ret = -EAGAIN;
-                       break;
-               }
-
-               mutex_unlock(&card->syscall_mutex);
-
-               DPRINTK ("Sleeping on page %d, tmp==%d, ir==%d\n", n, tmp, chan->is_record);
-               schedule();
-
-               ret = via_syscall_down (card, nonblock);
-               if (ret)
-                       break;
-
-               if (signal_pending (current)) {
-                       ret = -ERESTARTSYS;
-                       break;
-               }
-       }
-       set_current_state(TASK_RUNNING);
-       remove_wait_queue(&chan->wait, &wait);
-       if (ret)
-               goto out;
-
-       /* Now that we have at least one fragment we can write to, fill the buffer
-        * as much as possible with data from userspace.
-        */
-       while ((count > 0) && (chan->slop_len < chan->frag_size)) {
-               size_t slop_left = chan->frag_size - chan->slop_len;
-
-               size = (count < slop_left) ? count : slop_left;
-               if (copy_from_user (chan->pgtbl[n / (PAGE_SIZE / chan->frag_size)].cpuaddr + (n % (PAGE_SIZE / chan->frag_size)) * chan->frag_size + chan->slop_len,
-                                   userbuf, size)) {
-                       ret = -EFAULT;
-                       goto out;
-               }
-
-               count -= size;
-               chan->slop_len += size;
-               userbuf += size;
-       }
-
-       /* If we didn't fill up the buffer with data, stop now.
-         * Put a 'stop' marker in the DMA table too, to tell the
-         * audio hardware to stop if it gets here.
-         */
-       if (chan->slop_len < chan->frag_size) {
-               sgtable[n].count = cpu_to_le32 (chan->slop_len | VIA_EOL | VIA_STOP);
-               goto out;
-       }
-
-       /*
-         * If we get to this point, we have filled a buffer with
-         * audio data, flush the buffer to audio hardware.
-         */
-
-       /* Record the true size for the audio hardware to notice */
-        if (n == (chan->frag_number - 1))
-                sgtable[n].count = cpu_to_le32 (chan->frag_size | VIA_EOL);
-        else
-                sgtable[n].count = cpu_to_le32 (chan->frag_size | VIA_FLAG);
-
-       /* advance channel software pointer to point to
-        * the next buffer we will fill with data
-        */
-       if (chan->sw_ptr == (chan->frag_number - 1))
-               chan->sw_ptr = 0;
-       else
-               chan->sw_ptr++;
-
-       /* mark one less buffer as being available for userspace consumption */
-       assert (atomic_read (&chan->n_frags) > 0);
-       atomic_dec (&chan->n_frags);
-
-       /* we are at a block boundary, there is no fragment data */
-       chan->slop_len = 0;
-
-       /* if SGD has not yet been started, start it */
-       via_chan_maybe_start (chan);
-
-       DPRINTK ("Flushed block %u, sw_ptr now %u, n_frags now %d\n",
-               n, chan->sw_ptr, atomic_read (&chan->n_frags));
-
-       DPRINTK ("regs==S=%02X C=%02X TP=%02X BP=%08X RT=%08X SG=%08X CC=%08X SS=%08X\n",
-                inb (card->baseaddr + 0x00),
-                inb (card->baseaddr + 0x01),
-                inb (card->baseaddr + 0x02),
-                inl (card->baseaddr + 0x04),
-                inl (card->baseaddr + 0x08),
-                inl (card->baseaddr + 0x0C),
-                inl (card->baseaddr + 0x80),
-                inl (card->baseaddr + 0x84));
-
-       if (count > 0)
-               goto handle_one_block;
-
-out:
-       if (userbuf - orig_userbuf)
-               return userbuf - orig_userbuf;
-       else
-               return ret;
-}
-
-
-static ssize_t via_dsp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
-{
-       struct via_info *card;
-       ssize_t rc;
-       int nonblock = (file->f_flags & O_NONBLOCK);
-
-       DPRINTK ("ENTER, file=%p, buffer=%p, count=%u, ppos=%lu\n",
-                file, buffer, count, ppos ? ((unsigned long)*ppos) : 0);
-
-       assert (file != NULL);
-       card = file->private_data;
-       assert (card != NULL);
-
-       rc = via_syscall_down (card, nonblock);
-       if (rc) goto out;
-
-       if (card->ch_out.is_mapped) {
-               rc = -ENXIO;
-               goto out_up;
-       }
-
-       via_chan_set_buffering(card, &card->ch_out, -1);
-       rc = via_chan_buffer_init (card, &card->ch_out);
-
-       if (rc)
-               goto out_up;
-
-       rc = via_dsp_do_write (card, buffer, count, nonblock);
-
-out_up:
-       mutex_unlock(&card->syscall_mutex);
-out:
-       DPRINTK ("EXIT, returning %ld\n",(long) rc);
-       return rc;
-}
-
-
-static unsigned int via_dsp_poll(struct file *file, struct poll_table_struct *wait)
-{
-       struct via_info *card;
-       struct via_channel *chan;
-       unsigned int mask = 0;
-
-       DPRINTK ("ENTER\n");
-
-       assert (file != NULL);
-       card = file->private_data;
-       assert (card != NULL);
-
-       if (file->f_mode & FMODE_READ) {
-               chan = &card->ch_in;
-               if (sg_active (chan->iobase))
-                       poll_wait(file, &chan->wait, wait);
-               if (atomic_read (&chan->n_frags) > 0)
-                       mask |= POLLIN | POLLRDNORM;
-       }
-
-       if (file->f_mode & FMODE_WRITE) {
-               chan = &card->ch_out;
-               if (sg_active (chan->iobase))
-                       poll_wait(file, &chan->wait, wait);
-               if (atomic_read (&chan->n_frags) > 0)
-                       mask |= POLLOUT | POLLWRNORM;
-       }
-
-       DPRINTK ("EXIT, returning %u\n", mask);
-       return mask;
-}
-
-
-/**
- *     via_dsp_drain_playback - sleep until all playback samples are flushed
- *     @card: Private info for specified board
- *     @chan: Channel to drain
- *     @nonblock: boolean, non-zero if O_NONBLOCK is set
- *
- *     Sleeps until all playback has been flushed to the audio
- *     hardware.
- *
- *     Locking: inside card->syscall_mutex
- */
-
-static int via_dsp_drain_playback (struct via_info *card,
-                                  struct via_channel *chan, int nonblock)
-{
-        DECLARE_WAITQUEUE(wait, current);
-       int ret = 0;
-
-       DPRINTK ("ENTER, nonblock = %d\n", nonblock);
-
-       if (chan->slop_len > 0)
-               via_chan_flush_frag (chan);
-
-       if (atomic_read (&chan->n_frags) == chan->frag_number)
-               goto out;
-
-       via_chan_maybe_start (chan);
-
-       add_wait_queue(&chan->wait, &wait);
-       for (;;) {
-               DPRINTK ("FRAGS %d FRAGNUM %d\n", atomic_read(&chan->n_frags), chan->frag_number);
-               __set_current_state(TASK_INTERRUPTIBLE);
-               if (atomic_read (&chan->n_frags) >= chan->frag_number)
-                       break;
-
-               if (nonblock) {
-                       DPRINTK ("EXIT, returning -EAGAIN\n");
-                       ret = -EAGAIN;
-                       break;
-               }
-
-#ifdef VIA_DEBUG
-               {
-               u8 r40,r41,r42,r43,r44,r48;
-               pci_read_config_byte (card->pdev, 0x40, &r40);
-               pci_read_config_byte (card->pdev, 0x41, &r41);
-               pci_read_config_byte (card->pdev, 0x42, &r42);
-               pci_read_config_byte (card->pdev, 0x43, &r43);
-               pci_read_config_byte (card->pdev, 0x44, &r44);
-               pci_read_config_byte (card->pdev, 0x48, &r48);
-               DPRINTK ("PCI config: %02X %02X %02X %02X %02X %02X\n",
-                       r40,r41,r42,r43,r44,r48);
-
-               DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
-                        inb (card->baseaddr + 0x00),
-                        inb (card->baseaddr + 0x01),
-                        inb (card->baseaddr + 0x02),
-                        inl (card->baseaddr + 0x04),
-                        inl (card->baseaddr + 0x0C),
-                        inl (card->baseaddr + 0x80),
-                        inl (card->baseaddr + 0x84));
-               }
-
-               if (!chan->is_active)
-                       printk (KERN_ERR "sleeping but not active\n");
-#endif
-
-               mutex_unlock(&card->syscall_mutex);
-
-               DPRINTK ("sleeping, nbufs=%d\n", atomic_read (&chan->n_frags));
-               schedule();
-
-               if ((ret = via_syscall_down (card, nonblock)))
-                       break;
-
-               if (signal_pending (current)) {
-                       DPRINTK ("EXIT, returning -ERESTARTSYS\n");
-                       ret = -ERESTARTSYS;
-                       break;
-               }
-       }
-       set_current_state(TASK_RUNNING);
-       remove_wait_queue(&chan->wait, &wait);
-
-#ifdef VIA_DEBUG
-       {
-               u8 r40,r41,r42,r43,r44,r48;
-               pci_read_config_byte (card->pdev, 0x40, &r40);
-               pci_read_config_byte (card->pdev, 0x41, &r41);
-               pci_read_config_byte (card->pdev, 0x42, &r42);
-               pci_read_config_byte (card->pdev, 0x43, &r43);
-               pci_read_config_byte (card->pdev, 0x44, &r44);
-               pci_read_config_byte (card->pdev, 0x48, &r48);
-               DPRINTK ("PCI config: %02X %02X %02X %02X %02X %02X\n",
-                       r40,r41,r42,r43,r44,r48);
-
-               DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
-                        inb (card->baseaddr + 0x00),
-                        inb (card->baseaddr + 0x01),
-                        inb (card->baseaddr + 0x02),
-                        inl (card->baseaddr + 0x04),
-                        inl (card->baseaddr + 0x0C),
-                        inl (card->baseaddr + 0x80),
-                        inl (card->baseaddr + 0x84));
-
-               DPRINTK ("final nbufs=%d\n", atomic_read (&chan->n_frags));
-       }
-#endif
-
-out:
-       DPRINTK ("EXIT, returning %d\n", ret);
-       return ret;
-}
-
-
-/**
- *     via_dsp_ioctl_space - get information about channel buffering
- *     @card: Private info for specified board
- *     @chan: pointer to channel-specific info
- *     @arg: user buffer for returned information
- *
- *     Handles SNDCTL_DSP_GETISPACE and SNDCTL_DSP_GETOSPACE.
- *
- *     Locking: inside card->syscall_mutex
- */
-
-static int via_dsp_ioctl_space (struct via_info *card,
-                               struct via_channel *chan,
-                               void __user *arg)
-{
-       audio_buf_info info;
-
-       via_chan_set_buffering(card, chan, -1);
-
-       info.fragstotal = chan->frag_number;
-       info.fragsize = chan->frag_size;
-
-       /* number of full fragments we can read/write without blocking */
-       info.fragments = atomic_read (&chan->n_frags);
-
-       if ((chan->slop_len % chan->frag_size > 0) && (info.fragments > 0))
-               info.fragments--;
-
-       /* number of bytes that can be read or written immediately
-        * without blocking.
-        */
-       info.bytes = (info.fragments * chan->frag_size);
-       if (chan->slop_len % chan->frag_size > 0)
-               info.bytes += chan->frag_size - (chan->slop_len % chan->frag_size);
-
-       DPRINTK ("EXIT, returning fragstotal=%d, fragsize=%d, fragments=%d, bytes=%d\n",
-               info.fragstotal,
-               info.fragsize,
-               info.fragments,
-               info.bytes);
-
-       return copy_to_user (arg, &info, sizeof (info))?-EFAULT:0;
-}
-
-
-/**
- *     via_dsp_ioctl_ptr - get information about hardware buffer ptr
- *     @card: Private info for specified board
- *     @chan: pointer to channel-specific info
- *     @arg: user buffer for returned information
- *
- *     Handles SNDCTL_DSP_GETIPTR and SNDCTL_DSP_GETOPTR.
- *
- *     Locking: inside card->syscall_mutex
- */
-
-static int via_dsp_ioctl_ptr (struct via_info *card,
-                               struct via_channel *chan,
-                               void __user *arg)
-{
-       count_info info;
-
-       spin_lock_irq (&card->lock);
-
-       info.bytes = chan->bytes;
-       info.blocks = chan->n_irqs;
-       chan->n_irqs = 0;
-
-       spin_unlock_irq (&card->lock);
-
-       if (chan->is_active) {
-               unsigned long extra;
-               info.ptr = atomic_read (&chan->hw_ptr) * chan->frag_size;
-               extra = chan->frag_size - via_sg_offset(chan);
-               info.ptr += extra;
-               info.bytes += extra;
-       } else {
-               info.ptr = 0;
-       }
-
-       DPRINTK ("EXIT, returning bytes=%d, blocks=%d, ptr=%d\n",
-               info.bytes,
-               info.blocks,
-               info.ptr);
-
-       return copy_to_user (arg, &info, sizeof (info))?-EFAULT:0;
-}
-
-
-static int via_dsp_ioctl_trigger (struct via_channel *chan, int val)
-{
-       int enable, do_something;
-
-       if (chan->is_record)
-               enable = (val & PCM_ENABLE_INPUT);
-       else
-               enable = (val & PCM_ENABLE_OUTPUT);
-
-       if (!chan->is_enabled && enable) {
-               do_something = 1;
-       } else if (chan->is_enabled && !enable) {
-               do_something = -1;
-       } else {
-               do_something = 0;
-       }
-
-       DPRINTK ("enable=%d, do_something=%d\n",
-                enable, do_something);
-
-       if (chan->is_active && do_something)
-               return -EINVAL;
-
-       if (do_something == 1) {
-               chan->is_enabled = 1;
-               via_chan_maybe_start (chan);
-               DPRINTK ("Triggering input\n");
-       }
-
-       else if (do_something == -1) {
-               chan->is_enabled = 0;
-               DPRINTK ("Setup input trigger\n");
-       }
-
-       return 0;
-}
-
-
-static int via_dsp_ioctl (struct inode *inode, struct file *file,
-                         unsigned int cmd, unsigned long arg)
-{
-       int rc, rd=0, wr=0, val=0;
-       struct via_info *card;
-       struct via_channel *chan;
-       int nonblock = (file->f_flags & O_NONBLOCK);
-       int __user *ip = (int __user *)arg;
-       void __user *p = (void __user *)arg;
-
-       assert (file != NULL);
-       card = file->private_data;
-       assert (card != NULL);
-
-       if (file->f_mode & FMODE_WRITE)
-               wr = 1;
-       if (file->f_mode & FMODE_READ)
-               rd = 1;
-
-       rc = via_syscall_down (card, nonblock);
-       if (rc)
-               return rc;
-       rc = -EINVAL;
-
-       switch (cmd) {
-
-       /* OSS API version.  XXX unverified */
-       case OSS_GETVERSION:
-               DPRINTK ("ioctl OSS_GETVERSION, EXIT, returning SOUND_VERSION\n");
-               rc = put_user (SOUND_VERSION, ip);
-               break;
-
-       /* list of supported PCM data formats */
-       case SNDCTL_DSP_GETFMTS:
-               DPRINTK ("DSP_GETFMTS, EXIT, returning AFMT U8|S16_LE\n");
-                rc = put_user (AFMT_U8 | AFMT_S16_LE, ip);
-               break;
-
-       /* query or set current channel's PCM data format */
-       case SNDCTL_DSP_SETFMT:
-               if (get_user(val, ip)) {
-                       rc = -EFAULT;
-                       break;
-               }
-               DPRINTK ("DSP_SETFMT, val==%d\n", val);
-               if (val != AFMT_QUERY) {
-                       rc = 0;
-
-                       if (rd)
-                               rc = via_chan_set_fmt (card, &card->ch_in, val);
-
-                       if (rc >= 0 && wr)
-                               rc = via_chan_set_fmt (card, &card->ch_out, val);
-
-                       if (rc < 0)
-                               break;
-
-                       val = rc;
-               } else {
-                       if ((rd && (card->ch_in.pcm_fmt & VIA_PCM_FMT_16BIT)) ||
-                           (wr && (card->ch_out.pcm_fmt & VIA_PCM_FMT_16BIT)))
-                               val = AFMT_S16_LE;
-                       else
-                               val = AFMT_U8;
-               }
-               DPRINTK ("SETFMT EXIT, returning %d\n", val);
-                rc = put_user (val, ip);
-               break;
-
-       /* query or set number of channels (1=mono, 2=stereo, 4/6 for multichannel) */
-        case SNDCTL_DSP_CHANNELS:
-               if (get_user(val, ip)) {
-                       rc = -EFAULT;
-                       break;
-               }
-               DPRINTK ("DSP_CHANNELS, val==%d\n", val);
-               if (val != 0) {
-                       rc = 0;
-
-                       if (rd)
-                               rc = via_chan_set_stereo (card, &card->ch_in, val);
-
-                       if (rc >= 0 && wr)
-                               rc = via_chan_set_stereo (card, &card->ch_out, val);
-
-                       if (rc < 0)
-                               break;
-
-                       val = rc;
-               } else {
-                       if (rd)
-                               val = card->ch_in.channels;
-                       else
-                               val = card->ch_out.channels;
-               }
-               DPRINTK ("CHANNELS EXIT, returning %d\n", val);
-                rc = put_user (val, ip);
-               break;
-
-       /* enable (val is not zero) or disable (val == 0) stereo */
-        case SNDCTL_DSP_STEREO:
-               if (get_user(val, ip)) {
-                       rc = -EFAULT;
-                       break;
-               }
-               DPRINTK ("DSP_STEREO, val==%d\n", val);
-               rc = 0;
-
-               if (rd)
-                       rc = via_chan_set_stereo (card, &card->ch_in, val ? 2 : 1);
-               if (rc >= 0 && wr)
-                       rc = via_chan_set_stereo (card, &card->ch_out, val ? 2 : 1);
-
-               if (rc < 0)
-                       break;
-
-               val = rc - 1;
-
-               DPRINTK ("STEREO EXIT, returning %d\n", val);
-               rc = put_user(val, ip);
-               break;
-
-       /* query or set sampling rate */
-        case SNDCTL_DSP_SPEED:
-               if (get_user(val, ip)) {
-                       rc = -EFAULT;
-                       break;
-               }
-               DPRINTK ("DSP_SPEED, val==%d\n", val);
-               if (val < 0) {
-                       rc = -EINVAL;
-                       break;
-               }
-               if (val > 0) {
-                       rc = 0;
-
-                       if (rd)
-                               rc = via_chan_set_speed (card, &card->ch_in, val);
-                       if (rc >= 0 && wr)
-                               rc = via_chan_set_speed (card, &card->ch_out, val);
-
-                       if (rc < 0)
-                               break;
-
-                       val = rc;
-               } else {
-                       if (rd)
-                               val = card->ch_in.rate;
-                       else if (wr)
-                               val = card->ch_out.rate;
-                       else
-                               val = 0;
-               }
-               DPRINTK ("SPEED EXIT, returning %d\n", val);
-                rc = put_user (val, ip);
-               break;
-
-       /* wait until all buffers have been played, and then stop device */
-       case SNDCTL_DSP_SYNC:
-               DPRINTK ("DSP_SYNC\n");
-               rc = 0;
-               if (wr) {
-                       DPRINTK ("SYNC EXIT (after calling via_dsp_drain_playback)\n");
-                       rc = via_dsp_drain_playback (card, &card->ch_out, nonblock);
-               }
-               break;
-
-       /* stop recording/playback immediately */
-        case SNDCTL_DSP_RESET:
-               DPRINTK ("DSP_RESET\n");
-               if (rd) {
-                       via_chan_clear (card, &card->ch_in);
-                       card->ch_in.frag_number = 0;
-                       card->ch_in.frag_size = 0;
-                       atomic_set(&card->ch_in.n_frags, 0);
-               }
-
-               if (wr) {
-                       via_chan_clear (card, &card->ch_out);
-                       card->ch_out.frag_number = 0;
-                       card->ch_out.frag_size = 0;
-                       atomic_set(&card->ch_out.n_frags, 0);
-               }
-
-               rc = 0;
-               break;
-
-       case SNDCTL_DSP_NONBLOCK:
-               file->f_flags |= O_NONBLOCK;
-               rc = 0;
-               break;
-
-       /* obtain bitmask of device capabilities, such as mmap, full duplex, etc. */
-       case SNDCTL_DSP_GETCAPS:
-               DPRINTK ("DSP_GETCAPS\n");
-               rc = put_user(VIA_DSP_CAP, ip);
-               break;
-
-       /* obtain buffer fragment size */
-       case SNDCTL_DSP_GETBLKSIZE:
-               DPRINTK ("DSP_GETBLKSIZE\n");
-
-               if (rd) {
-                       via_chan_set_buffering(card, &card->ch_in, -1);
-                       rc = put_user(card->ch_in.frag_size, ip);
-               } else if (wr) {
-                       via_chan_set_buffering(card, &card->ch_out, -1);
-                       rc = put_user(card->ch_out.frag_size, ip);
-               }
-               break;
-
-       /* obtain information about input buffering */
-       case SNDCTL_DSP_GETISPACE:
-               DPRINTK ("DSP_GETISPACE\n");
-               if (rd)
-                       rc = via_dsp_ioctl_space (card, &card->ch_in, p);
-               break;
-
-       /* obtain information about output buffering */
-       case SNDCTL_DSP_GETOSPACE:
-               DPRINTK ("DSP_GETOSPACE\n");
-               if (wr)
-                       rc = via_dsp_ioctl_space (card, &card->ch_out, p);
-               break;
-
-       /* obtain information about input hardware pointer */
-       case SNDCTL_DSP_GETIPTR:
-               DPRINTK ("DSP_GETIPTR\n");
-               if (rd)
-                       rc = via_dsp_ioctl_ptr (card, &card->ch_in, p);
-               break;
-
-       /* obtain information about output hardware pointer */
-       case SNDCTL_DSP_GETOPTR:
-               DPRINTK ("DSP_GETOPTR\n");
-               if (wr)
-                       rc = via_dsp_ioctl_ptr (card, &card->ch_out, p);
-               break;
-
-       /* return number of bytes remaining to be played by DMA engine */
-       case SNDCTL_DSP_GETODELAY:
-               {
-               DPRINTK ("DSP_GETODELAY\n");
-
-               chan = &card->ch_out;
-
-               if (!wr)
-                       break;
-
-               if (chan->is_active) {
-
-                       val = chan->frag_number - atomic_read (&chan->n_frags);
-
-                       assert(val >= 0);
-                               
-                       if (val > 0) {
-                               val *= chan->frag_size;
-                               val -= chan->frag_size - via_sg_offset(chan);
-                       }
-                       val += chan->slop_len % chan->frag_size;
-               } else
-                       val = 0;
-
-               assert (val <= (chan->frag_size * chan->frag_number));
-
-               DPRINTK ("GETODELAY EXIT, val = %d bytes\n", val);
-                rc = put_user (val, ip);
-               break;
-               }
-
-       /* handle the quick-start of a channel,
-        * or the notification that a quick-start will
-        * occur in the future
-        */
-       case SNDCTL_DSP_SETTRIGGER:
-               if (get_user(val, ip)) {
-                       rc = -EFAULT;
-                       break;
-               }
-               DPRINTK ("DSP_SETTRIGGER, rd=%d, wr=%d, act=%d/%d, en=%d/%d\n",
-                       rd, wr, card->ch_in.is_active, card->ch_out.is_active,
-                       card->ch_in.is_enabled, card->ch_out.is_enabled);
-
-               rc = 0;
-
-               if (rd)
-                       rc = via_dsp_ioctl_trigger (&card->ch_in, val);
-
-               if (!rc && wr)
-                       rc = via_dsp_ioctl_trigger (&card->ch_out, val);
-
-               break;
-
-       case SNDCTL_DSP_GETTRIGGER:
-               val = 0;
-               if ((file->f_mode & FMODE_READ) && card->ch_in.is_enabled)
-                       val |= PCM_ENABLE_INPUT;
-               if ((file->f_mode & FMODE_WRITE) && card->ch_out.is_enabled)
-                       val |= PCM_ENABLE_OUTPUT;
-               rc = put_user(val, ip);
-               break;
-
-       /* Enable full duplex.  Since we do this as soon as we are opened
-        * with O_RDWR, this is mainly a no-op that always returns success.
-        */
-       case SNDCTL_DSP_SETDUPLEX:
-               DPRINTK ("DSP_SETDUPLEX\n");
-               if (!rd || !wr)
-                       break;
-               rc = 0;
-               break;
-
-       /* set fragment size.  implemented as a successful no-op for now */
-       case SNDCTL_DSP_SETFRAGMENT:
-               if (get_user(val, ip)) {
-                       rc = -EFAULT;
-                       break;
-               }
-               DPRINTK ("DSP_SETFRAGMENT, val==%d\n", val);
-
-               if (rd)
-                       rc = via_chan_set_buffering(card, &card->ch_in, val);
-
-               if (wr)
-                       rc = via_chan_set_buffering(card, &card->ch_out, val);
-
-               DPRINTK ("SNDCTL_DSP_SETFRAGMENT (fragshift==0x%04X (%d), maxfrags==0x%04X (%d))\n",
-                        val & 0xFFFF,
-                        val & 0xFFFF,
-                        (val >> 16) & 0xFFFF,
-                        (val >> 16) & 0xFFFF);
-
-               rc = 0;
-               break;
-
-       /* inform device of an upcoming pause in input (or output). */
-       case SNDCTL_DSP_POST:
-               DPRINTK ("DSP_POST\n");
-               if (wr) {
-                       if (card->ch_out.slop_len > 0)
-                               via_chan_flush_frag (&card->ch_out);
-                       via_chan_maybe_start (&card->ch_out);
-               }
-
-               rc = 0;
-               break;
-
-       /* not implemented */
-       default:
-               DPRINTK ("unhandled ioctl, cmd==%u, arg==%p\n",
-                        cmd, p);
-               break;
-       }
-
-       mutex_unlock(&card->syscall_mutex);
-       DPRINTK ("EXIT, returning %d\n", rc);
-       return rc;
-}
-
-
-static int via_dsp_open (struct inode *inode, struct file *file)
-{
-       int minor = iminor(inode);
-       struct via_info *card;
-       struct pci_dev *pdev = NULL;
-       struct via_channel *chan;
-       struct pci_driver *drvr;
-       int nonblock = (file->f_flags & O_NONBLOCK);
-
-       DPRINTK ("ENTER, minor=%d, file->f_mode=0x%x\n", minor, file->f_mode);
-
-       if (!(file->f_mode & (FMODE_READ | FMODE_WRITE))) {
-               DPRINTK ("EXIT, returning -EINVAL\n");
-               return -EINVAL;
-       }
-
-       card = NULL;
-       while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
-               drvr = pci_dev_driver (pdev);
-               if (drvr == &via_driver) {
-                       assert (pci_get_drvdata (pdev) != NULL);
-
-                       card = pci_get_drvdata (pdev);
-                       DPRINTK ("dev_dsp = %d, minor = %d, assn = %d\n",
-                                card->dev_dsp, minor,
-                                (card->dev_dsp ^ minor) & ~0xf);
-
-                       if (((card->dev_dsp ^ minor) & ~0xf) == 0)
-                               goto match;
-               }
-       }
-
-       DPRINTK ("no matching %s found\n", card ? "minor" : "driver");
-       return -ENODEV;
-
-match:
-       pci_dev_put(pdev);
-       if (nonblock) {
-               if (!mutex_trylock(&card->open_mutex)) {
-                       DPRINTK ("EXIT, returning -EAGAIN\n");
-                       return -EAGAIN;
-               }
-       } else {
-               if (mutex_lock_interruptible(&card->open_mutex)) {
-                       DPRINTK ("EXIT, returning -ERESTARTSYS\n");
-                       return -ERESTARTSYS;
-               }
-       }
-
-       file->private_data = card;
-       DPRINTK ("file->f_mode == 0x%x\n", file->f_mode);
-
-       /* handle input from analog source */
-       if (file->f_mode & FMODE_READ) {
-               chan = &card->ch_in;
-
-               via_chan_init (card, chan);
-
-               /* why is this forced to 16-bit stereo in all drivers? */
-               chan->pcm_fmt = VIA_PCM_FMT_16BIT | VIA_PCM_FMT_STEREO;
-               chan->channels = 2;
-
-               // TO DO - use FIFO: via_capture_fifo(card, 1);
-               via_chan_pcm_fmt (chan, 0);
-               via_set_rate (card->ac97, chan, 44100);
-       }
-
-       /* handle output to analog source */
-       if (file->f_mode & FMODE_WRITE) {
-               chan = &card->ch_out;
-
-               via_chan_init (card, chan);
-
-               if (file->f_mode & FMODE_READ) {
-                       /* if in duplex mode make the recording and playback channels
-                          have the same settings */
-                       chan->pcm_fmt = VIA_PCM_FMT_16BIT | VIA_PCM_FMT_STEREO;
-                       chan->channels = 2;
-                       via_chan_pcm_fmt (chan, 0);
-                        via_set_rate (card->ac97, chan, 44100);
-               } else {
-                        if ((minor & 0xf) == SND_DEV_DSP16) {
-                               chan->pcm_fmt = VIA_PCM_FMT_16BIT;
-                               via_chan_pcm_fmt (chan, 0);
-                               via_set_rate (card->ac97, chan, 44100);
-                       } else {
-                               via_chan_pcm_fmt (chan, 1);
-                               via_set_rate (card->ac97, chan, 8000);
-                       }
-               }
-       }
-
-       DPRINTK ("EXIT, returning 0\n");
-       return nonseekable_open(inode, file);
-}
-
-
-static int via_dsp_release(struct inode *inode, struct file *file)
-{
-       struct via_info *card;
-       int nonblock = (file->f_flags & O_NONBLOCK);
-       int rc;
-
-       DPRINTK ("ENTER\n");
-
-       assert (file != NULL);
-       card = file->private_data;
-       assert (card != NULL);
-
-       rc = via_syscall_down (card, nonblock);
-       if (rc) {
-               DPRINTK ("EXIT (syscall_down error), rc=%d\n", rc);
-               return rc;
-       }
-
-       if (file->f_mode & FMODE_WRITE) {
-               rc = via_dsp_drain_playback (card, &card->ch_out, nonblock);
-               if (rc && rc != -ERESTARTSYS)   /* Nobody needs to know about ^C */
-                       printk (KERN_DEBUG "via_audio: ignoring drain playback error %d\n", rc);
-
-               via_chan_free (card, &card->ch_out);
-               via_chan_buffer_free(card, &card->ch_out);
-       }
-
-       if (file->f_mode & FMODE_READ) {
-               via_chan_free (card, &card->ch_in);
-               via_chan_buffer_free (card, &card->ch_in);
-       }
-
-       mutex_unlock(&card->syscall_mutex);
-       mutex_unlock(&card->open_mutex);
-
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-}
-
-
-/****************************************************************
- *
- * Chip setup and kernel registration
- *
- *
- */
-
-static int __devinit via_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
-{
-#ifdef CONFIG_MIDI_VIA82CXXX
-       u8 r42;
-#endif
-       int rc;
-       struct via_info *card;
-       static int printed_version;
-
-       DPRINTK ("ENTER\n");
-
-       if (printed_version++ == 0)
-               printk (KERN_INFO "Via 686a/8233/8235 audio driver " VIA_VERSION "\n");
-
-       rc = pci_enable_device (pdev);
-       if (rc)
-               goto err_out;
-
-       rc = pci_request_regions (pdev, "via82cxxx_audio");
-       if (rc)
-               goto err_out_disable;
-
-       rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
-       if (rc)
-               goto err_out_res;
-       rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
-       if (rc)
-               goto err_out_res;
-
-       card = kmalloc (sizeof (*card), GFP_KERNEL);
-       if (!card) {
-               printk (KERN_ERR PFX "out of memory, aborting\n");
-               rc = -ENOMEM;
-               goto err_out_res;
-       }
-
-       pci_set_drvdata (pdev, card);
-
-       memset (card, 0, sizeof (*card));
-       card->pdev = pdev;
-       card->baseaddr = pci_resource_start (pdev, 0);
-       card->card_num = via_num_cards++;
-       spin_lock_init (&card->lock);
-       spin_lock_init (&card->ac97_lock);
-       mutex_init(&card->syscall_mutex);
-       mutex_init(&card->open_mutex);
-
-       /* we must init these now, in case the intr handler needs them */
-       via_chan_init_defaults (card, &card->ch_out);
-       via_chan_init_defaults (card, &card->ch_in);
-       via_chan_init_defaults (card, &card->ch_fm);
-
-       /* if BAR 2 is present, chip is Rev H or later,
-        * which means it has a few extra features */
-       if (pci_resource_start (pdev, 2) > 0)
-               card->rev_h = 1;
-               
-       /* Overkill for now, but more flexible done right */
-       
-       card->intmask = id->driver_data;
-       card->legacy = !card->intmask;
-       card->sixchannel = id->driver_data;
-       
-       if(card->sixchannel)
-               printk(KERN_INFO PFX "Six channel audio available\n");
-       if (pdev->irq < 1) {
-               printk (KERN_ERR PFX "invalid PCI IRQ %d, aborting\n", pdev->irq);
-               rc = -ENODEV;
-               goto err_out_kfree;
-       }
-
-       if (!(pci_resource_flags (pdev, 0) & IORESOURCE_IO)) {
-               printk (KERN_ERR PFX "unable to locate I/O resources, aborting\n");
-               rc = -ENODEV;
-               goto err_out_kfree;
-       }
-
-       pci_set_master(pdev);
-       
-       /*
-        * init AC97 mixer and codec
-        */
-       rc = via_ac97_init (card);
-       if (rc) {
-               printk (KERN_ERR PFX "AC97 init failed, aborting\n");
-               goto err_out_kfree;
-       }
-
-       /*
-        * init DSP device
-        */
-       rc = via_dsp_init (card);
-       if (rc) {
-               printk (KERN_ERR PFX "DSP device init failed, aborting\n");
-               goto err_out_have_mixer;
-       }
-
-       /*
-        * init and turn on interrupts, as the last thing we do
-        */
-       rc = via_interrupt_init (card);
-       if (rc) {
-               printk (KERN_ERR PFX "interrupt init failed, aborting\n");
-               goto err_out_have_dsp;
-       }
-
-       printk (KERN_INFO PFX "board #%d at 0x%04lX, IRQ %d\n",
-               card->card_num + 1, card->baseaddr, pdev->irq);
-
-#ifdef CONFIG_MIDI_VIA82CXXX
-       /* Disable by default */
-       card->midi_info.io_base = 0;
-
-       if(card->legacy)
-       {
-               pci_read_config_byte (pdev, 0x42, &r42);
-               /* Disable MIDI interrupt */
-               pci_write_config_byte (pdev, 0x42, r42 | VIA_CR42_MIDI_IRQMASK);
-               if (r42 & VIA_CR42_MIDI_ENABLE)
-               {
-                       if (r42 & VIA_CR42_MIDI_PNP) /* Address selected by iobase 2 - not tested */
-                               card->midi_info.io_base = pci_resource_start (pdev, 2);
-                       else /* Address selected by byte 0x43 */
-                       {
-                               u8 r43;
-                               pci_read_config_byte (pdev, 0x43, &r43);
-                               card->midi_info.io_base = 0x300 + ((r43 & 0x0c) << 2);
-                       }
-
-                       card->midi_info.irq = -pdev->irq;
-                       if (probe_uart401(& card->midi_info, THIS_MODULE))
-                       {
-                               card->midi_devc=midi_devs[card->midi_info.slots[4]]->devc;
-                               pci_write_config_byte(pdev, 0x42, r42 & ~VIA_CR42_MIDI_IRQMASK);
-                               printk("Enabled Via MIDI\n");
-                       }
-               }
-       }
-#endif
-
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-
-err_out_have_dsp:
-       via_dsp_cleanup (card);
-
-err_out_have_mixer:
-       via_ac97_cleanup (card);
-
-err_out_kfree:
-#ifndef VIA_NDEBUG
-       memset (card, OSS_POISON_FREE, sizeof (*card)); /* poison memory */
-#endif
-       kfree (card);
-
-err_out_res:
-       pci_release_regions (pdev);
-
-err_out_disable:
-       pci_disable_device (pdev);
-
-err_out:
-       pci_set_drvdata (pdev, NULL);
-       DPRINTK ("EXIT - returning %d\n", rc);
-       return rc;
-}
-
-
-static void __devexit via_remove_one (struct pci_dev *pdev)
-{
-       struct via_info *card;
-
-       DPRINTK ("ENTER\n");
-
-       assert (pdev != NULL);
-       card = pci_get_drvdata (pdev);
-       assert (card != NULL);
-
-#ifdef CONFIG_MIDI_VIA82CXXX
-       if (card->midi_info.io_base)
-               unload_uart401(&card->midi_info);
-#endif
-
-       free_irq (card->pdev->irq, card);
-       via_dsp_cleanup (card);
-       via_ac97_cleanup (card);
-
-#ifndef VIA_NDEBUG
-       memset (card, OSS_POISON_FREE, sizeof (*card)); /* poison memory */
-#endif
-       kfree (card);
-
-       pci_set_drvdata (pdev, NULL);
-
-       pci_release_regions (pdev);
-       pci_disable_device (pdev);
-       pci_set_power_state (pdev, 3); /* ...zzzzzz */
-
-       DPRINTK ("EXIT\n");
-       return;
-}
-
-
-/****************************************************************
- *
- * Driver initialization and cleanup
- *
- *
- */
-
-static int __init init_via82cxxx_audio(void)
-{
-       int rc;
-
-       DPRINTK ("ENTER\n");
-
-       rc = pci_register_driver (&via_driver);
-       if (rc) {
-               DPRINTK ("EXIT, returning %d\n", rc);
-               return rc;
-       }
-
-       DPRINTK ("EXIT, returning 0\n");
-       return 0;
-}
-
-
-static void __exit cleanup_via82cxxx_audio(void)
-{
-       DPRINTK ("ENTER\n");
-
-       pci_unregister_driver (&via_driver);
-
-       DPRINTK ("EXIT\n");
-}
-
-
-module_init(init_via82cxxx_audio);
-module_exit(cleanup_via82cxxx_audio);
-
-MODULE_AUTHOR("Jeff Garzik");
-MODULE_DESCRIPTION("DSP audio and mixer driver for Via 82Cxxx audio devices");
-MODULE_LICENSE("GPL");
-
index 6495534e5bf61ad11698764f6c592c67cfcbbd16..1558a5c4094faebb589c9822a37182c837867c39 100644 (file)
@@ -84,7 +84,7 @@ static int snd_us428ctls_mmap(struct snd_hwdep * hw, struct file *filp, struct v
                us428->us428ctls_sharedmem->CtlSnapShotLast = -2;
        }
        area->vm_ops = &us428ctls_vm_ops;
-       area->vm_flags |= VM_RESERVED;
+       area->vm_flags |= VM_RESERVED | VM_DONTEXPAND;
        area->vm_private_data = hw->private_data;
        return 0;
 }
index 800b5cecfc8054ce38026e954a17f67b481ebfc8..117946f2debb3a04891d87de9327c16d8f27f7fe 100644 (file)
@@ -722,7 +722,7 @@ static int snd_usX2Y_hwdep_pcm_mmap(struct snd_hwdep * hw, struct file *filp, st
                return -ENODEV;
        }
        area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops;
-       area->vm_flags |= VM_RESERVED;
+       area->vm_flags |= VM_RESERVED | VM_DONTEXPAND;
        area->vm_private_data = hw->private_data;
        return 0;
 }